Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
2.4 KiB
PHP
Raw Permalink Normal View History

2016-03-15 22:16:08 +10:00
<?php
/*
* create-service.inc.php
2016-03-15 22:16:08 +10:00
*
* -Description-
2016-03-15 22:16:08 +10:00
*
* 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 <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2016 Aaron Daniels
* @author Aaron Daniels <aaron@daniels.id.au>
2016-03-15 22:16:08 +10:00
*/
if (! Auth::user()->hasGlobalAdmin()) {
2016-03-15 22:16:08 +10:00
exit('ERROR: You need to be admin');
}
2022-02-13 20:23:07 +01:00
foreach (['desc', 'name'] as $varname) {
//sanitize description and name
if (isset($vars[$varname])) {
$$varname = strip_tags($vars[$varname]);
$update['service_' . $varname] = $$varname;
}
}
foreach (['ip', 'ignore', 'disabled', 'param', '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];
}
}
2016-03-15 22:16:08 +10:00
if (is_numeric($service_id) && $service_id > 0) {
// Need to edit.
2018-10-17 10:46:07 -05:00
if (is_numeric(edit_service($update, $service_id))) {
2024-01-05 05:39:12 +01:00
$status = ['status' => 0, 'message' => 'Modified Service: <i>' . $service_id . ': ' . $stype . '</i>'];
2016-08-18 20:28:22 -05:00
} else {
2024-01-05 05:39:12 +01:00
$status = ['status' => 1, 'message' => 'ERROR: Failed to modify service: <i>' . $service_id . '</i>'];
2016-03-15 22:16:08 +10:00
}
2016-08-18 20:28:22 -05:00
} else {
2016-03-15 22:16:08 +10:00
// Need to add.
$service_id = add_service($device_id, $stype, $desc, $ip, $param, $ignore, $disabled, 0, $name);
2016-03-15 22:16:08 +10:00
if ($service_id == false) {
2024-01-05 05:39:12 +01:00
$status = ['status' => 1, 'message' => 'ERROR: Failed to add Service: <i>' . $stype . '</i>'];
2016-08-18 20:28:22 -05:00
} else {
2024-01-05 05:39:12 +01:00
$status = ['status' => 0, 'message' => 'Added Service: <i>' . $service_id . ': ' . $stype . '</i>'];
2016-03-15 22:16:08 +10:00
}
}
header('Content-Type: application/json');
2021-03-04 07:55:41 -06:00
echo json_encode($status, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);