Files
librenms-librenms/adduser.php
T

38 lines
956 B
PHP
Raw Normal View History

2010-09-03 18:26:59 +00:00
#!/usr/bin/env php
<?php
2015-07-13 20:10:26 +02:00
/*
* LibreNMS
*
* This file is part of LibreNMS.
*
* @package LibreNMS
* @subpackage cli
* @copyright (C) 2006 - 2012 Adam Armstrong
*
*/
2018-09-11 07:51:35 -05:00
use LibreNMS\Authentication\LegacyAuth;
2020-09-21 14:54:51 +02:00
$init_modules = [];
if (php_sapi_name() != 'cli') {
$init_modules[] = 'auth';
2011-03-17 11:12:32 +00:00
}
require __DIR__ . '/includes/init.php';
2011-03-17 11:12:32 +00:00
2018-09-11 07:51:35 -05:00
if (LegacyAuth::get()->canManageUsers()) {
2015-07-13 20:10:26 +02:00
if (isset($argv[1]) && isset($argv[2]) && isset($argv[3])) {
2020-09-21 14:54:51 +02:00
if (! LegacyAuth::get()->userExists($argv[1])) {
2018-09-11 07:51:35 -05:00
if (LegacyAuth::get()->addUser($argv[1], $argv[2], $argv[3], @$argv[4])) {
2020-09-21 14:54:51 +02:00
echo 'User ' . $argv[1] . " added successfully\n";
2015-07-13 20:10:26 +02:00
}
2016-08-28 17:32:55 -05:00
} else {
2020-09-21 14:54:51 +02:00
echo 'User ' . $argv[1] . " already exists!\n";
2015-07-13 20:10:26 +02:00
}
2016-08-28 17:32:55 -05:00
} else {
2015-07-13 20:10:26 +02:00
echo "Add User Tool\nUsage: ./adduser.php <username> <password> <level 1-10> [email]\n";
}
2016-08-28 17:32:55 -05:00
} else {
2015-07-13 20:10:26 +02:00
echo "Auth module does not allow adding users!\n";
}//end if