getServerInfo(); $userdata = $data->getUser($server_info['username']); $_REQUEST['user'] = $server_info['username']; $misc->printTrail('user'); $misc->printTabs('server','account'); $misc->printMsg($msg); if ($userdata->recordCount() > 0) { $userdata->fields['usesuper'] = $data->phpBool($userdata->fields['usesuper']); $userdata->fields['usecreatedb'] = $data->phpBool($userdata->fields['usecreatedb']); echo "
{$lang['strusername']} | {$lang['strsuper']} | {$lang['strcreatedb']} | {$lang['strexpires']} | "; echo "{$lang['strsessiondefaults']} | "; echo "
---|---|---|---|---|
", $misc->printVal($userdata->fields['usename']), " | \n"; echo "\t", $misc->printVal($userdata->fields['usesuper'], 'yesno'), " | \n"; echo "\t", $misc->printVal($userdata->fields['usecreatedb'], 'yesno'), " | \n"; echo "\t", ($userdata->fields['useexpires'] == 'infinity' || is_null($userdata->fields['useexpires']) ? $lang['strnever'] : $misc->printVal($userdata->fields['useexpires'])), " | \n"; echo "\t", $misc->printVal($userdata->fields['useconfig']), " | \n"; echo "
{$lang['strnodata']}
\n"; echo "href}\">{$lang['strchangepassword']}
\n"; } /** * Show confirmation of change password and actually change password */ function doChangePassword($confirm, $msg = '') { global $data, $misc; global $lang, $conf; $server_info = $misc->getServerInfo(); if ($confirm) { $_REQUEST['user'] = $server_info['username']; $misc->printTrail('user'); $misc->printTitle($lang['strchangepassword'],'pg.user.alter'); $misc->printMsg($msg); if (!isset($_POST['password'])) $_POST['password'] = ''; if (!isset($_POST['confirm'])) $_POST['confirm'] = ''; echo "\n"; } else { // Check that password is minimum length if (strlen($_POST['password']) < $conf['min_password_length']) doChangePassword(true, $lang['strpasswordshort']); // Check that password matches confirmation password elseif ($_POST['password'] != $_POST['confirm']) doChangePassword(true, $lang['strpasswordconfirm']); else { $status = $data->changePassword($server_info['username'], $_POST['password']); if ($status == 0) doAccount($lang['strpasswordchanged']); else doAccount($lang['strpasswordchangedbad']); } } } /** * Function to allow editing of a user */ function doEdit($msg = '') { global $data, $misc; global $lang; $misc->printTrail('user'); $misc->printTitle($lang['stralter'],'pg.user.alter'); $misc->printMsg($msg); $userdata = $data->getUser($_REQUEST['username']); if ($userdata->recordCount() > 0) { $server_info = $misc->getServerInfo(); $canRename = $data->hasUserRename() && ($_REQUEST['username'] != $server_info['username']); $userdata->fields['usesuper'] = $data->phpBool($userdata->fields['usesuper']); $userdata->fields['usecreatedb'] = $data->phpBool($userdata->fields['usecreatedb']); if (!isset($_POST['formExpires'])){ if ($canRename) $_POST['newname'] = $userdata->fields['usename']; if ($userdata->fields['usesuper']) $_POST['formSuper'] = ''; if ($userdata->fields['usecreatedb']) $_POST['formCreateDB'] = ''; $_POST['formExpires'] = $userdata->fields['useexpires'] == 'infinity' ? '' : $userdata->fields['useexpires']; $_POST['formPassword'] = ''; } echo "\n"; } else echo "{$lang['strnodata']}
\n"; } /** * Function to save after editing a user */ function doSaveEdit() { global $data, $lang; // Check name and password if (isset($_POST['newname']) && $_POST['newname'] == '') doEdit($lang['struserneedsname']); else if ($_POST['formPassword'] != $_POST['formConfirm']) doEdit($lang['strpasswordconfirm']); else { if (isset($_POST['newname'])) $status = $data->setRenameUser($_POST['username'], $_POST['formPassword'], isset($_POST['formCreateDB']), isset($_POST['formSuper']), $_POST['formExpires'], $_POST['newname']); else $status = $data->setUser($_POST['username'], $_POST['formPassword'], isset($_POST['formCreateDB']), isset($_POST['formSuper']), $_POST['formExpires']); if ($status == 0) doDefault($lang['struserupdated']); else doEdit($lang['struserupdatedbad']); } } /** * Show confirmation of drop and perform actual drop */ function doDrop($confirm) { global $data, $misc; global $lang; if ($confirm) { $misc->printTrail('user'); $misc->printTitle($lang['strdrop'],'pg.user.drop'); echo "", sprintf($lang['strconfdropuser'], $misc->printVal($_REQUEST['username'])), "
\n"; echo "\n"; } else { $status = $data->dropUser($_REQUEST['username']); if ($status == 0) doDefault($lang['struserdropped']); else doDefault($lang['struserdroppedbad']); } } /** * Displays a screen where they can enter a new user */ function doCreate($msg = '') { global $data, $misc, $username; global $lang; if (!isset($_POST['formUsername'])) $_POST['formUsername'] = ''; if (!isset($_POST['formPassword'])) $_POST['formPassword'] = ''; if (!isset($_POST['formConfirm'])) $_POST['formConfirm'] = ''; if (!isset($_POST['formExpires'])) $_POST['formExpires'] = ''; $misc->printTrail('server'); $misc->printTitle($lang['strcreateuser'],'pg.user.create'); $misc->printMsg($msg); echo "\n"; } /** * Actually creates the new user in the database */ function doSaveCreate() { global $data; global $lang; // Check data if ($_POST['formUsername'] == '') doCreate($lang['struserneedsname']); else if ($_POST['formPassword'] != $_POST['formConfirm']) doCreate($lang['strpasswordconfirm']); else { $status = $data->createUser($_POST['formUsername'], $_POST['formPassword'], isset($_POST['formCreateDB']), isset($_POST['formSuper']), $_POST['formExpires'], array()); if ($status == 0) doDefault($lang['strusercreated']); else doCreate($lang['strusercreatedbad']); } } /** * Show default list of users in the database */ function doDefault($msg = '') { global $data, $misc; global $lang; function renderUseExpires($val) { global $lang; return $val == 'infinity' ? $lang['strnever'] : htmlspecialchars($val); } $misc->printTrail('server'); $misc->printTabs('server','users'); $misc->printMsg($msg); $users = $data->getUsers(); $columns = array( 'user' => array( 'title' => $lang['strusername'], 'field' => field('usename'), ), 'superuser' => array( 'title' => $lang['strsuper'], 'field' => field('usesuper'), 'type' => 'yesno', ), 'createdb' => array( 'title' => $lang['strcreatedb'], 'field' => field('usecreatedb'), 'type' => 'yesno', ), 'expires' => array( 'title' => $lang['strexpires'], 'field' => field('useexpires'), 'type' => 'callback', 'params'=> array('function' => 'renderUseExpires', 'null' => $lang['strnever']), ), 'defaults' => array( 'title' => $lang['strsessiondefaults'], 'field' => field('useconfig'), ), 'actions' => array( 'title' => $lang['stractions'], ), ); $actions = array( 'alter' => array( 'title' => $lang['stralter'], 'url' => "users.php?action=edit&{$misc->href}&", 'vars' => array('username' => 'usename'), ), 'drop' => array( 'title' => $lang['strdrop'], 'url' => "users.php?action=confirm_drop&{$misc->href}&", 'vars' => array('username' => 'usename'), ), ); $misc->printTable($users, $columns, $actions, $lang['strnousers']); echo "\n"; } $misc->printHeader($lang['strusers']); $misc->printBody(); switch ($action) { case 'changepassword': if (isset($_REQUEST['ok'])) doChangePassword(false); else doAccount(); break; case 'confchangepassword': doChangePassword(true); break; case 'account': doAccount(); break; case 'save_create': if (isset($_REQUEST['cancel'])) doDefault(); else doSaveCreate(); break; case 'create': doCreate(); break; case 'drop': if (isset($_REQUEST['cancel'])) doDefault(); else doDrop(false); break; case 'confirm_drop': doDrop(true); break; case 'save_edit': if (isset($_REQUEST['cancel'])) doDefault(); else doSaveEdit(); break; case 'edit': doEdit(); break; default: doDefault(); break; } $misc->printFooter(); ?>