From eab63ea220b4d643d176478f825fbe824ce480b5 Mon Sep 17 00:00:00 2001 From: PipoCanaja <38363551+PipoCanaja@users.noreply.github.com> Date: Thu, 22 Apr 2021 19:13:39 +0200 Subject: [PATCH] webui - Services bootstrap enable + status (#12736) * Services bootstrap enable + status * style * copyright * generic create-service.inc.php to allow updates of some fields only * generic create-service.inc.php to allow updates of some fields only --- includes/html/forms/create-service.inc.php | 56 ++++++++------ includes/html/modal/new_service.inc.php | 14 +++- includes/html/pages/services.inc.php | 86 ++++++++++++++++++++-- 3 files changed, 124 insertions(+), 32 deletions(-) diff --git a/includes/html/forms/create-service.inc.php b/includes/html/forms/create-service.inc.php index 745ce2fed1..5b30a87a91 100644 --- a/includes/html/forms/create-service.inc.php +++ b/includes/html/forms/create-service.inc.php @@ -1,47 +1,59 @@ + * -Description- * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2016 Aaron Daniels + * @author Aaron Daniels */ if (! Auth::user()->hasGlobalAdmin()) { exit('ERROR: You need to be admin'); } -$service_id = $vars['service_id']; -$type = $vars['stype']; -$desc = $vars['desc']; -$ip = $vars['ip']; -$param = $vars['param']; -$ignore = isset($vars['ignore']) ? 1 : 0; -$disabled = isset($vars['disabled']) ? 1 : 0; -$device_id = $vars['device_id']; -$template_id = $vars['template_id']; -$name = $vars['name']; +foreach (['desc', 'ip', 'ignore', 'disabled', 'param', 'name', 'template_id'] as $varname) { + if (isset($vars[$varname])) { + $update['service_' . $varname] = $vars[$varname]; + $$varname = $vars[$varname]; + } +} +foreach (['stype', 'device_id', 'service_id'] as $varname) { + if (isset($vars[$varname])) { + $$varname = $vars[$varname]; + } +} if (is_numeric($service_id) && $service_id > 0) { // Need to edit. - $update = ['service_desc' => $desc, 'service_ip' => $ip, 'service_param' => $param, 'service_ignore' => $ignore, 'service_disabled' => $disabled, 'service_template_id' => $template_id, 'service_name' => $name]; if (is_numeric(edit_service($update, $service_id))) { - $status = ['status' =>0, 'message' => 'Modified Service: ' . $service_id . ': ' . $type . '']; + $status = ['status' =>0, 'message' => 'Modified Service: ' . $service_id . ': ' . $stype . '']; } else { $status = ['status' =>1, 'message' => 'ERROR: Failed to modify service: ' . $service_id . '']; } } else { // Need to add. - $service_id = add_service($device_id, $type, $desc, $ip, $param, $ignore, $disabled, 0, $name); + $service_id = add_service($device_id, $stype, $desc, $ip, $param, $ignore, $disabled, 0, $name); if ($service_id == false) { - $status = ['status' =>1, 'message' => 'ERROR: Failed to add Service: ' . $type . '']; + $status = ['status' =>1, 'message' => 'ERROR: Failed to add Service: ' . $stype . '']; } else { - $status = ['status' =>0, 'message' => 'Added Service: ' . $service_id . ': ' . $type . '']; + $status = ['status' =>0, 'message' => 'Added Service: ' . $service_id . ': ' . $stype . '']; } } header('Content-Type: application/json'); diff --git a/includes/html/modal/new_service.inc.php b/includes/html/modal/new_service.inc.php index 2ddd165efb..3501f791f5 100644 --- a/includes/html/modal/new_service.inc.php +++ b/includes/html/modal/new_service.inc.php @@ -96,13 +96,15 @@ if (Auth::user()->hasGlobalAdmin()) {
- + +
- + +

@@ -127,7 +129,9 @@ $('#create-service').on('hide.bs.modal', function (event) { $('#desc').val(''); $('#param').val(''); $('#ignore').val(''); + $('#ignore_box').val(''); $('#disabled').val(''); + $('#disabled_box').val(''); $('#service_template_id').val(''); $('#name').val(''); $('#service_template_name').val(''); @@ -152,11 +156,13 @@ $('#create-service').on('show.bs.modal', function (e) { $('#param').val(output['param']); $('#ignore').val(output['ignore']); $('#disabled').val(output['disabled']); + $('#ignore_box').val(output['ignore']); + $('#disabled_box').val(output['disabled']); if ($('#ignore').attr('value') == 1) { - $('#ignore').prop("checked", true); + $('#ignore_box').prop("checked", true); } if ($('#disabled').attr('value') == 1) { - $('#disabled').prop("checked", true); + $('#disabled_box').prop("checked", true); } $('#service_template_id').val(output['service_template_id']); $('#name').val(output['name']); diff --git a/includes/html/pages/services.inc.php b/includes/html/pages/services.inc.php index d11756101b..0207a176de 100644 --- a/includes/html/pages/services.inc.php +++ b/includes/html/pages/services.inc.php @@ -177,11 +177,11 @@ require_once 'includes/html/modal/delete_service.inc.php'; echo 'Check Type'; echo 'Remote Host'; echo 'Message'; - echo 'Description'; + echo 'Description'; echo 'Last Changed'; - echo 'Ignored'; - echo 'Disabled'; - echo ''; + echo 'Alert'; + echo 'Status'; + echo ''; echo ''; } @@ -195,8 +195,37 @@ require_once 'includes/html/modal/delete_service.inc.php'; echo '' . nl2br(\LibreNMS\Util\Clean::html($service['service_message'], [])) . ''; echo '' . nl2br(\LibreNMS\Util\Clean::html($service['service_desc'], [])) . ''; echo '' . \LibreNMS\Util\Time::formatInterval(time() - $service['service_changed']) . ''; - echo '' . nl2br(\LibreNMS\Util\Clean::html($service['service_ignore'], [])) . ''; - echo '' . nl2br(\LibreNMS\Util\Clean::html($service['service_disabled'], [])) . ''; + + $service_checked = ''; + $ico = 'pause'; + if ($service['service_ignore'] && $service['service_disabled']) { + $color = 'default'; + $orig_colour = 'danger'; + $orig_ico = $ico; + } elseif (! $service['service_ignore'] && ! $service['service_disabled']) { + $ico = 'check'; + $color = 'success'; + $orig_colour = $color; + $orig_ico = $ico; + $service_checked = 'checked'; + } elseif (! $service['service_ignore'] && $service['service_disabled']) { + $color = 'default'; + $orig_colour = 'success'; + $orig_ico = 'check'; + } elseif ($service['service_ignore'] && ! $service['service_disabled']) { + $color = 'danger'; + $orig_colour = $color; + $orig_ico = $ico; + $service_checked = 'checked'; + } + $service_id = $service['service_id']; + $service_name = \LibreNMS\Util\Clean::html($service['service_name']); + + echo '' . ''; + + echo "
"; + echo ""; + echo '
'; if (Auth::user()->hasGlobalAdmin()) { echo " @@ -223,3 +252,48 @@ require_once 'includes/html/modal/delete_service.inc.php'; + +