Issues (2963)

includes/html/pages/device/edit/services.inc.php (1 issue)

1
<?php
2
3
if (Auth::user()->hasGlobalRead()) {
4
    if ($vars['addsrv']) {
5
        if (Auth::user()->hasGlobalAdmin()) {
6
            $updated = '1';
7
8
            $service_id = add_service($vars['device'], $vars['type'], $vars['descr'], $vars['ip'], $vars['params'], $vars['ignore'], $vars['disabled'], 0, $vars['name']);
9
            if ($service_id) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $service_id of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
10
                $message .= $message_break . 'Service added (' . $service_id . ')!';
11
                $message_break .= '<br />';
12
            }
13
        }
14
    }
15
16
    // Build the types list.
17
    foreach (scandir(\LibreNMS\Config::get('nagios_plugins')) as $file) {
18
        if (substr($file, 0, 6) === 'check_') {
19
            $check_name = substr($file, 6);
20
            $servicesform .= "<option value='$check_name'>$check_name</option>";
21
        }
22
    }
23
24
    $dev = device_by_id_cache($device['device_id']);
25
    $devicesform = "<option value='" . $dev['device_id'] . "'>" . $dev['hostname'] . '</option>';
26
27
    if ($updated) {
28
        print_message('Device Settings Saved');
29
    }
30
31
    echo '<div class="col-sm-6 col-sm-offset-3">';
32
33
    include_once 'includes/html/print-service-add.inc.php';
34
} else {
35
    include 'includes/html/error-no-perm.inc.php';
36
}
37