FILTER_VALIDATE_INT, "rawpasswd" => FILTER_UNSAFE_RAW, "rawpasswd2" => FILTER_UNSAFE_RAW, "svnpasswd" => FILTER_SANITIZE_STRIPPED, "cvsaccess" => ["filter" => FILTER_CALLBACK, "options" => function($v) { if ($v == "on") { return true; } return false; }], "enable" => ["filter" => FILTER_CALLBACK, "options" => function($v) { if ($v == "on") { return true; } return false; }], "spamprotect" => ["filter" => FILTER_CALLBACK, "options" => function($v) { if ($v == "on") { return true; } return false; }], "greylist" => ["filter" => FILTER_CALLBACK, "options" => function($v) { if ($v == "on") { return true; } return false; }], "verified" => FILTER_VALIDATE_INT, "use_sa" => FILTER_VALIDATE_INT, "email" => FILTER_SANITIZE_EMAIL, "name" => FILTER_SANITIZE_SPECIAL_CHARS, "sshkey" => FILTER_SANITIZE_SPECIAL_CHARS, "purpose" => FILTER_SANITIZE_SPECIAL_CHARS, "profile_markdown" => FILTER_UNSAFE_RAW, ]; $rawin = filter_input_array(INPUT_POST) ?: []; $in = isset($rawin["in"]) ? filter_var_array($rawin["in"], $indesc, false) : []; $id = filter_input(INPUT_GET, "id", FILTER_VALIDATE_INT) ?: 0; $username = filter_input(INPUT_GET, "username", FILTER_SANITIZE_STRIPPED) ?: 0; head("user administration"); db_connect(); # ?username=whatever will look up 'whatever' by email or username if ($username) { $query = "SELECT userid FROM users" . " WHERE username=? OR email=?"; $res = db_query_safe($query, [$username, $username]); if (!($id = @mysql_result($res, 0))) { warn("wasn't able to find user matching '$username'"); } } if ($id) { $query = "SELECT * FROM users WHERE users.userid=?"; $res = db_query_safe($query, [$id]); $userdata = mysql_fetch_array($res); if (!$userdata) { warn("Can't find user#$id"); } } $action = filter_input(INPUT_POST, "action", FILTER_CALLBACK, ["options" => "validateAction"]); if ($id && $action) { csrf_validate($_SESSION, $action); if (!is_admin($_SESSION["username"])) { warn("you're not allowed to take actions on users."); exit; } switch ($action) { case 'approve': user_approve((int)$id); break; case 'remove': user_remove((int)$id); break; default: warn("that action ('$action') is not understood."); } } if ($in) { csrf_validate($_SESSION, "useredit"); if (!can_modify($_SESSION["username"],$id)) { warn("you're not allowed to modify this user."); } else { if ($error = invalid_input($in)) { warn($error); } else { if (!empty($in['rawpasswd'])) { $userinfo = fetch_user($id); $in['svnpasswd'] = gen_svn_pass($userinfo["username"], $in['rawpasswd']); } $cvsaccess = empty($in['cvsaccess']) ? 0 : 1; $enable = empty($in['enable']) ? 0 : 1; $spamprotect = empty($in['spamprotect']) ? 0 : 1; $use_sa = empty($in['use_sa']) ? 0 : (int)$in['use_sa']; $greylist = empty($in['greylist']) ? 0 : 1; if ($id) { # update main table data if (!empty($in['email']) && !empty($in['name'])) { $query = new Query("UPDATE users SET name=?,email=?", [$in['name'], $in['email']]); if (!empty($in['svnpasswd'])) { $query->add(',svnpasswd=?', [$in['svnpasswd']]); } if (!empty($in['sshkey'])) { $query->add(',ssh_keys=?', [html_entity_decode($in['sshkey'],ENT_QUOTES)]); } if (is_admin($_SESSION["username"]) && !empty($in['username'])) { $query->add(',username=?', [$in['username']]); } if (is_admin($_SESSION["username"])) { $query->add(',cvsaccess=?', [$cvsaccess]); } $query->add( ',spamprotect=?, enable=?, use_sa=?, greylist=?', [$spamprotect, $enable, $use_sa, $greylist]); if (!empty($in['rawpasswd'])) { $query->add(',pchanged=?', [$ts]); } $query->add(' WHERE userid=?', [$id]); if (!empty($in['passwd'])) { // Kill the session data after updates :) $_SERVER["credentials"] = []; } db_query($query); if(!empty($in['purpose'])) { $purpose = hsc($in['purpose']); $query = "INSERT INTO users_note (userid, note, entered) VALUES (?, ?, NOW())"; db_query_safe($query, [$id, $purpose]); } if(!empty($in['profile_markdown'])) { $profile_markdown = $in['profile_markdown']; $profile_html = Markdown($profile_markdown); $query = "INSERT INTO users_profile (userid, markdown, html) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE markdown=?, html=?"; db_query_safe($query, [$id, $profile_markdown, $profile_html, $profile_markdown, $profile_html]); } } warn("record $id updated"); $id = false; } } } } if ($id) { ?>
!$unapproved]);?>">; | "username"]);?>">username | "name"]);?>">name | "email"]);?>">email | "email"]);?>">email | "note"]);?>">note | ||
---|---|---|---|---|---|---|---|
">edit |