Issues (2963)

adduser.php (1 issue)

1
#!/usr/bin/env php
2
<?php
3
4
/*
5
 * LibreNMS
6
 *
7
 *   This file is part of LibreNMS.
8
 *
9
 * @package    LibreNMS
10
 * @subpackage cli
11
 * @copyright  (C) 2006 - 2012 Adam Armstrong
12
 *
13
 */
14
15
use LibreNMS\Authentication\LegacyAuth;
16
17
$init_modules = [];
18
if (php_sapi_name() != 'cli') {
19
    $init_modules[] = 'auth';
20
}
21
require __DIR__ . '/includes/init.php';
22
23
if (LegacyAuth::get()->canManageUsers()) {
24
    if (isset($argv[1]) && isset($argv[2]) && isset($argv[3])) {
25
        if (! LegacyAuth::get()->userExists($argv[1])) {
26
            if (LegacyAuth::get()->addUser($argv[1], $argv[2], $argv[3], @$argv[4])) {
0 ignored issues
show
Bug Best Practice introduced by
The expression LibreNMS\Authentication\...], $argv[3], @$argv[4]) of type false|integer is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== false 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...
27
                echo 'User ' . $argv[1] . " added successfully\n";
28
            }
29
        } else {
30
            echo 'User ' . $argv[1] . " already exists!\n";
31
        }
32
    } else {
33
        echo "Add User Tool\nUsage: ./adduser.php <username> <password> <level 1-10> [email]\n";
34
    }
35
} else {
36
    echo "Auth module does not allow adding users!\n";
37
}//end if
38