function adduser($username, $password, $level, $email = "", $realname = "", $can_modify_passwd = '1', $description = "") { if (!auth_user_exists($username)) { $encrypted = crypt($password, '$1$' . generateSalt(8) . '$'); return dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname, 'can_modify_passwd' => $can_modify_passwd, 'descr' => $description), 'users'); } else { return FALSE; } }
function auth_user() { $user = false; if (isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) { $un = $_SERVER['PHP_AUTH_USER']; $pw = $_SERVER['PHP_AUTH_PW']; if (auth_user_exists($un) && auth_test_pw($un, $pw)) { $user = auth_user_exists($un); if (!isset($user->un)) { $user->un = $un; } } else { $user = false; } } return $user; }
print_message("%g" . OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION . "\n%WAdd User%n\n", 'color'); if (OBS_DEBUG) { print_versions(); } $auth_file = $config['html_dir'] . '/includes/authentication/' . $config['auth_mechanism'] . '.inc.php'; if (is_file($auth_file)) { include $auth_file; // Include base auth functions calls include $config['html_dir'] . '/includes/authenticate-functions.inc.php'; } else { print_error("ERROR: no valid auth_mechanism defined."); exit; } if (auth_usermanagement()) { if (isset($argv[1]) && isset($argv[2]) && isset($argv[3])) { if (!auth_user_exists($argv[1])) { if (adduser($argv[1], $argv[2], $argv[3], @$argv[4])) { print_success("User " . $argv[1] . " added successfully."); } else { print_error("User " . $argv[1] . " creation failed!"); } } else { print_warning("User " . $argv[1] . " already exists!"); } } else { $msg = "%n\nUSAGE:\n{$scriptname} <username> <password> <level 1-10> [email]\n\nEXAMPLE:\n%WADMIN%n: {$scriptname} <username> <password> 10 [email]\n\nUSER LEVELS:" . PHP_EOL; foreach ($GLOBALS['config']['user_level'] as $level => $entry) { $msg .= ' ' . $level . ' - %W' . $entry['name'] . '%n (' . $entry['subtext'] . ')' . PHP_EOL; } $msg .= PHP_EOL . "%rInvalid arguments!%n"; print_message($msg, 'color', FALSE);
* @author Adam Armstrong <*****@*****.**> * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ // Global write permissions required. if ($_SESSION['userlevel'] < 10) { print_error_permission(); return; } include $config['html_dir'] . "/pages/usermenu.inc.php"; register_html_title("Add User"); if (auth_usermanagement()) { if ($vars['submit'] == 'add_user') { if ($vars['new_username']) { $vars['new_username'] = strip_tags($vars['new_username']); if (!auth_user_exists($vars['new_username'])) { if (isset($vars['can_modify_passwd'])) { $vars['can_modify_passwd'] = 1; } else { $vars['can_modify_passwd'] = 0; } if (!$vars['new_password']) { print_warning("Please enter a password!"); } else { if (adduser($vars['new_username'], $vars['new_password'], $vars['new_level'], $vars['new_email'], $vars['new_realname'], $vars['can_modify_passwd'], $vars['new_description'])) { print_success('User ' . escape_html($vars['new_username']) . ' added!'); } } } else { print_error('User with this name already exists!'); }
* @subpackage webui * @author Adam Armstrong <*****@*****.**> * @copyright (C) 2006-2014 Adam Armstrong * */ ?> <h2>用户管理: 添加用户</h2> <?php include "usermenu.inc.php"; if ($_SESSION['userlevel'] == '10') { $pagetitle[] = "添加用户"; $errors = array(); if (auth_usermanagement()) { if ($_POST['action'] == "add") { if ($_POST['new_username']) { if (!auth_user_exists($_POST['new_username'])) { if (isset($_POST['can_modify_passwd'])) { $_POST['can_modify_passwd'] = 1; } else { $_POST['can_modify_passwd'] = 0; } if (adduser($_POST['new_username'], $_POST['new_password'], $_POST['new_level'], $_POST['new_email'], $_POST['new_realname'], $_POST['can_modify_passwd'], $_POST['new_description'])) { echo "<span class=info>User " . $_POST['username'] . " added!</span>"; } } else { echo '<div class="alert alert-error">该名称的用户已存在!</div>'; } } else { $errors["username"] = "******"help-inline\">请输入用户名!</span>"; } if (!$_POST['new_password']) {