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()) {