Issues (2963)

includes/html/forms/create-service.inc.php (1 issue)

1
<?php
2
3
/*
4
 * create-service.inc.php
5
 *
6
 * -Description-
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 * @package    LibreNMS
22
 * @link       http://librenms.org
23
 * @copyright  2016 Aaron Daniels
24
 * @author     Aaron Daniels <[email protected]>
25
 */
26
27
if (! Auth::user()->hasGlobalAdmin()) {
28
    exit('ERROR: You need to be admin');
29
}
30
31
foreach (['desc', 'ip', 'ignore', 'disabled', 'param', 'name', 'template_id'] as $varname) {
32
    if (isset($vars[$varname])) {
33
        $update['service_' . $varname] = $vars[$varname];
34
        $$varname = $vars[$varname];
35
    }
36
}
37
foreach (['stype', 'device_id', 'service_id'] as $varname) {
38
    if (isset($vars[$varname])) {
39
        $$varname = $vars[$varname];
40
    }
41
}
42
43
if (is_numeric($service_id) && $service_id > 0) {
44
    // Need to edit.
45
    if (is_numeric(edit_service($update, $service_id))) {
46
        $status = ['status' =>0, 'message' => 'Modified Service: <i>' . $service_id . ': ' . $stype . '</i>'];
47
    } else {
48
        $status = ['status' =>1, 'message' => 'ERROR: Failed to modify service: <i>' . $service_id . '</i>'];
49
    }
50
} else {
51
    // Need to add.
52
    $service_id = add_service($device_id, $stype, $desc, $ip, $param, $ignore, $disabled, 0, $name);
53
    if ($service_id == false) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $service_id of type integer|null against false; this is ambiguous if the integer can be zero. Consider using a strict comparison === instead.
Loading history...
54
        $status = ['status' =>1, 'message' => 'ERROR: Failed to add Service: <i>' . $stype . '</i>'];
55
    } else {
56
        $status = ['status' =>0, 'message' => 'Added Service: <i>' . $service_id . ': ' . $stype . '</i>'];
57
    }
58
}
59
header('Content-Type: application/json');
60
echo json_encode($status, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
61