| File | Lines added | Lines deleted |
|---|---|---|
| TODO | 4 | 1 |
| admin/sql.php | 3 | 2 |
| inc/admin/admin.php | 12 | 0 |
| inc/admin/repos/repos.php | 23 | 0 |
| inc/admin/users/add.form.php | 44 | 0 |
| inc/admin/users/add.php | 33 | 0 |
| inc/admin/users/users.php | 10 | 4 |
| inc/login/login.form.php | 1 | 0 |
| inc/login/login.php | 1 | 1 |
| inc/repo.inc.php | 7 | 3 |
| inc/repo/repo.form.php | 1 | 0 |
| inc/repo/repo.php | 1 | 1 |
| inc/sess.inc.php | 8 | 3 |
| inc/user.inc.php | 113 | 13 |
| root/index.php | 10 | 8 |
| File TODO changed (mode: 100644) (index 1192868..27052f2) | |||
| 3 | 3 | [ ] Allow to configure the limit of the patch size to prevent abuses. | [ ] Allow to configure the limit of the patch size to prevent abuses. |
| 4 | 4 | [ ] Allow to configure to refuse binary files. | [ ] Allow to configure to refuse binary files. |
| 5 | 5 | [ ] Allow to configure to refuse commits with broken spcaes/tab mixes. | [ ] Allow to configure to refuse commits with broken spcaes/tab mixes. |
| 6 | [ ] | ||
| 6 | [ ] Add a repo_prop_set/get function that will set/get a file in .git folder. THis way we can | ||
| 7 | speed up some lookups (no need for database). Hm. | ||
| 8 | [ ] When we delete an repository, we will do repo_prop_set(repo, disabled) and we will | ||
| 9 | return OK, in the background we will do the removing. Do not forget to also remove clones. Hm. | ||
| File admin/sql.php changed (mode: 100644) (index cbbf521..afdd9d0) | |||
| ... | ... | $res = sql_query($db, $sql); | |
| 38 | 38 | if ($res === FALSE) | if ($res === FALSE) |
| 39 | 39 | echo "WARN: Cannot create 'keys' table!\n"; | echo "WARN: Cannot create 'keys' table!\n"; |
| 40 | 40 | ||
| 41 | $sql = "CREATE TABLE users (uid INT PRIMARY KEY, user TEXT, salt TEXT" | ||
| 41 | $sql = "CREATE TABLE users (uid INTEGER PRIMARY KEY, user TEXT, salt TEXT" | ||
| 42 | 42 | . ", pass TEXT, email TEXT, itime INTEGER" | . ", pass TEXT, email TEXT, itime INTEGER" |
| 43 | 43 | . ", suspended INTEGER" | . ", suspended INTEGER" |
| 44 | 44 | . ", session_time INTEGER" | . ", session_time INTEGER" |
| 45 | . ", last_seen INTEGER)"; | ||
| 45 | . ", last_seen INTEGER" | ||
| 46 | . ", is_admin INTEGER)"; | ||
| 46 | 47 | $res = sql_query($db, $sql); | $res = sql_query($db, $sql); |
| 47 | 48 | if ($res === FALSE) | if ($res === FALSE) |
| 48 | 49 | echo "WARN: Cannot create 'users' table!\n"; | echo "WARN: Cannot create 'users' table!\n"; |
| File inc/admin/admin.php changed (mode: 100644) (index f8a6d58..e206e85) | |||
| 1 | 1 | <?php | <?php |
| 2 | xlog("/admin"); | ||
| 3 | |||
| 4 | if ($gg_ui['is_admin'] != 1) { | ||
| 5 | $_admin = "You do not have access here!"; | ||
| 6 | return; | ||
| 7 | } | ||
| 8 | |||
| 2 | 9 | $subop = @intval($_REQUEST['subop']); | $subop = @intval($_REQUEST['subop']); |
| 3 | 10 | ||
| 4 | 11 | // menu | // menu |
| ... | ... | case 1: // users | |
| 15 | 22 | include($INC . "/admin/users/users.php"); | include($INC . "/admin/users/users.php"); |
| 16 | 23 | $_admin_body .= $_admin_users; | $_admin_body .= $_admin_users; |
| 17 | 24 | break; | break; |
| 25 | |||
| 26 | case 2: // repos | ||
| 27 | include($INC . "/admin/repos/repos.php"); | ||
| 28 | $_admin_body .= $_admin_repos; | ||
| 29 | break; | ||
| 18 | 30 | } | } |
| 19 | 31 | ||
| 20 | 32 | $_admin = $_admin_menu . $_admin_body; | $_admin = $_admin_menu . $_admin_body; |
| File inc/admin/repos/repos.php added (mode: 100644) (index 0000000..4a0e298) | |||
| 1 | <?php | ||
| 2 | xlog("/admin/repos"); | ||
| 3 | |||
| 4 | $subsubop = @intval($_REQUEST['subsubop']); | ||
| 5 | |||
| 6 | // menu | ||
| 7 | $_admin_repos_url = $_admin_url . "&subop=$subop"; | ||
| 8 | $_admin_repos_menu = ""; | ||
| 9 | $_admin_repos_menu .= "[<a href=\"$_admin_repos_url&subsubop=1\">List</a>]"; | ||
| 10 | //$_admin_repos_menu .= " [<a href=\"$_admin_repos_url&subsubop=2\">Add</a>]"; | ||
| 11 | $_admin_repos_menu .= "<br />\n"; | ||
| 12 | $_admin_repos_menu .= "<br />\n"; | ||
| 13 | |||
| 14 | $_admin_repos_body = ""; | ||
| 15 | |||
| 16 | switch ($subsubop) { | ||
| 17 | case 1: // list | ||
| 18 | $_admin_repos_body .= repo_list($db, $_admin_repos_url . "&subsubop=$subsubop", 0); | ||
| 19 | break; | ||
| 20 | } | ||
| 21 | |||
| 22 | $_admin_repos = $_admin_repos_menu . $_admin_repos_body; | ||
| 23 | ?> | ||
| File inc/admin/users/add.form.php added (mode: 100644) (index 0000000..e42bdc2) | |||
| 1 | <?php | ||
| 2 | |||
| 3 | $_form = ' | ||
| 4 | <form type="post" action="' . $_SERVER['PHP_SELF'] . '"> | ||
| 5 | <input type="hidden" name="op" value="' . $op . '"> | ||
| 6 | <input type="hidden" name="subop" value="' . $subop . '"> | ||
| 7 | <input type="hidden" name="subsubop" value="' . $subsubop . '"> | ||
| 8 | <input type="hidden" name="doit" value="1"> | ||
| 9 | |||
| 10 | <table> | ||
| 11 | <tr> | ||
| 12 | <td>Name:</td> | ||
| 13 | <td><input type="text" name="xuser" value="' . $xuser . '"/></td> | ||
| 14 | </tr> | ||
| 15 | |||
| 16 | <tr> | ||
| 17 | <td>E-mail:</td> | ||
| 18 | <td><input type="text" name="email" value="' . $email . '"/></td> | ||
| 19 | </tr> | ||
| 20 | |||
| 21 | <tr> | ||
| 22 | <td>Password:</td> | ||
| 23 | <td><input type="password" name="xpass" value="' . $xpass . '"/></td> | ||
| 24 | </tr> | ||
| 25 | |||
| 26 | <tr> | ||
| 27 | <td>Admin?</td> | ||
| 28 | <td> | ||
| 29 | <select name="is_admin"> | ||
| 30 | <option value="0">No</option> | ||
| 31 | <option value="1">Yes</option> | ||
| 32 | </select> | ||
| 33 | </td> | ||
| 34 | </tr> | ||
| 35 | |||
| 36 | <tr> | ||
| 37 | <td colspan="2"><input type="submit" value="Go!"/></td> | ||
| 38 | </tr> | ||
| 39 | </table> | ||
| 40 | </form> | ||
| 41 | '; | ||
| 42 | |||
| 43 | |||
| 44 | ?> | ||
| File inc/admin/users/add.php added (mode: 100644) (index 0000000..bd02e82) | |||
| 1 | <?php | ||
| 2 | xlog("/admin/users/add"); | ||
| 3 | |||
| 4 | $_user_add = ""; | ||
| 5 | |||
| 6 | if ($doit == 1) { | ||
| 7 | $xuser = @$_REQUEST['xuser']; | ||
| 8 | $email = @$_REQUEST['email']; | ||
| 9 | $xpass = @$_REQUEST['xpass']; | ||
| 10 | xlog("xxx: " . print_r($_REQUEST, TRUE)); | ||
| 11 | $is_admin = @intval($_REQUEST['is_admin']); | ||
| 12 | |||
| 13 | $_ui = user_info($db, 0, $xuser); | ||
| 14 | if ($_ui['ok'] == 0) { | ||
| 15 | $_user_add .= "Error: Internal error!"; | ||
| 16 | } else if ($_ui['exists'] == 0) { | ||
| 17 | if (user_add($db, $xuser, $xpass, $email, $is_admin)) { | ||
| 18 | $_user_add .= "OK!<br />"; | ||
| 19 | } | ||
| 20 | } else { | ||
| 21 | xlog("User already in use!"); | ||
| 22 | $_user_add .= "Error: User already taken!"; | ||
| 23 | } | ||
| 24 | } else { | ||
| 25 | $xuser = ""; | ||
| 26 | $email = ""; | ||
| 27 | $xpass = ""; | ||
| 28 | } | ||
| 29 | |||
| 30 | include($INC . "/admin/users/add.form.php"); | ||
| 31 | $_user_add .= $_form; | ||
| 32 | |||
| 33 | ?> | ||
| File inc/admin/users/users.php changed (mode: 100644) (index d98ec17..ef85c8a) | |||
| 1 | 1 | <?php | <?php |
| 2 | xlog("/admin/users"); | ||
| 3 | |||
| 2 | 4 | $subsubop = @intval($_REQUEST['subsubop']); | $subsubop = @intval($_REQUEST['subsubop']); |
| 3 | 5 | ||
| 4 | 6 | // menu | // menu |
| 5 | $_admin_users_url = $_SERVER['PHP_SELF'] . "?op=$op&subop=$subop"; | ||
| 7 | $_admin_users_url = $_admin_url . "&subop=$subop"; | ||
| 6 | 8 | $_admin_users_menu = ""; | $_admin_users_menu = ""; |
| 7 | 9 | $_admin_users_menu .= "[<a href=\"$_admin_users_url&subsubop=1\">List</a>]"; | $_admin_users_menu .= "[<a href=\"$_admin_users_url&subsubop=1\">List</a>]"; |
| 8 | 10 | $_admin_users_menu .= " [<a href=\"$_admin_users_url&subsubop=2\">Add</a>]"; | $_admin_users_menu .= " [<a href=\"$_admin_users_url&subsubop=2\">Add</a>]"; |
| ... | ... | $_admin_users_menu .= "<br />\n"; | |
| 11 | 13 | ||
| 12 | 14 | $_admin_users_body = ""; | $_admin_users_body = ""; |
| 13 | 15 | ||
| 14 | switch ($subop) { | ||
| 15 | case 1: // users | ||
| 16 | $_admin_users_body .= user_list($db); | ||
| 16 | switch ($subsubop) { | ||
| 17 | case 1: // list | ||
| 18 | $_admin_users_body .= user_list($db, $_admin_users_url . "&subsubop=$subsubop"); | ||
| 17 | 19 | break; | break; |
| 20 | |||
| 21 | case 2: //add | ||
| 22 | include($INC . "/admin/users/add.php"); | ||
| 23 | $_admin_users_body .= $_user_add; | ||
| 18 | 24 | } | } |
| 19 | 25 | ||
| 20 | 26 | $_admin_users = $_admin_users_menu . $_admin_users_body; | $_admin_users = $_admin_users_menu . $_admin_users_body; |
| File inc/login/login.form.php changed (mode: 100644) (index 9c0c8a9..182216f) | |||
| ... | ... | $_form = ' | |
| 8 | 8 | User: <input type="text" name="user" value="' . $user . '"><br /> | User: <input type="text" name="user" value="' . $user . '"><br /> |
| 9 | 9 | Password: <input type="password" name="pass" value="' . $pass . '"><br /> | Password: <input type="password" name="pass" value="' . $pass . '"><br /> |
| 10 | 10 | <input type="submit" value="Go!"> | <input type="submit" value="Go!"> |
| 11 | </form> | ||
| 11 | 12 | '; | '; |
| 12 | 13 | ||
| 13 | 14 | ||
| File inc/login/login.php changed (mode: 100644) (index c832fb0..267d01d) | |||
| ... | ... | $doit = @intval($_REQUEST['doit']); | |
| 4 | 4 | $user = @$_COOKIE['user']; | $user = @$_COOKIE['user']; |
| 5 | 5 | $pass = ""; | $pass = ""; |
| 6 | 6 | ||
| 7 | $_login = ""; | ||
| 7 | $_login = "<br />\n"; | ||
| 8 | 8 | ||
| 9 | 9 | if ($doit == 0) { | if ($doit == 0) { |
| 10 | 10 | include($INC . "/login/login.form.php"); | include($INC . "/login/login.form.php"); |
| File inc/repo.inc.php changed (mode: 100644) (index b730482..9463070) | |||
| ... | ... | function repo_create($db, $uid, $name, $public) | |
| 83 | 83 | /* | /* |
| 84 | 84 | * List repositories | * List repositories |
| 85 | 85 | */ | */ |
| 86 | function repo_list($db, $uid) | ||
| 86 | function repo_list($db, $url, $uid) | ||
| 87 | 87 | { | { |
| 88 | xlog("repo_list: uid=$uid..."); | ||
| 88 | xlog("repo_list: url=$url, uid=$uid..."); | ||
| 89 | 89 | ||
| 90 | $sql = "SELECT * FROM repos WHERE uid = $uid"; | ||
| 90 | $add = ""; | ||
| 91 | if ($uid > 0) | ||
| 92 | $add = " AND uid = $uid"; | ||
| 93 | |||
| 94 | $sql = "SELECT * FROM repos WHERE 1 = 1" . $add; | ||
| 91 | 95 | $res = sql_query($db, $sql); | $res = sql_query($db, $sql); |
| 92 | 96 | if ($res === FALSE) | if ($res === FALSE) |
| 93 | 97 | return FALSE; | return FALSE; |
| File inc/repo/repo.form.php changed (mode: 100644) (index 5a5f4f9..ab8add9) | |||
| ... | ... | $_form = ' | |
| 29 | 29 | </tr> | </tr> |
| 30 | 30 | ||
| 31 | 31 | </table> | </table> |
| 32 | </form> | ||
| 32 | 33 | '; | '; |
| 33 | 34 | ||
| 34 | 35 | ||
| File inc/repo/repo.php changed (mode: 100644) (index fda7752..3d10172) | |||
| ... | ... | case 1: // create | |
| 25 | 25 | break; | break; |
| 26 | 26 | ||
| 27 | 27 | case 2: //list | case 2: //list |
| 28 | $_body .= repo_list($db, $uid); | ||
| 28 | $_body .= repo_list($db, "", $uid); | ||
| 29 | 29 | break; | break; |
| 30 | 30 | } | } |
| 31 | 31 | ||
| File inc/sess.inc.php changed (mode: 100644) (index d5ad020..c22be6b) | |||
| ... | ... | function sess_valid($db, $sid) | |
| 33 | 33 | if (empty($sid)) | if (empty($sid)) |
| 34 | 34 | return FALSE; | return FALSE; |
| 35 | 35 | ||
| 36 | $now = time(); | ||
| 36 | 37 | $uid = FALSE; | $uid = FALSE; |
| 37 | 38 | ||
| 38 | 39 | $e_sid = sql_escape($db, $sid); | $e_sid = sql_escape($db, $sid); |
| 39 | 40 | ||
| 40 | $sql = "SELECT uid FROM sess WHERE sid = '$e_sid'"; | ||
| 41 | $sql = "SELECT uid, expire FROM sess WHERE sid = '$e_sid'"; | ||
| 41 | 42 | $res = sql_query($db, $sql); | $res = sql_query($db, $sql); |
| 42 | 43 | if ($res === FALSE) { | if ($res === FALSE) { |
| 43 | 44 | xlog("\tCannot select (" . sql_error() . ")!"); | xlog("\tCannot select (" . sql_error() . ")!"); |
| ... | ... | function sess_valid($db, $sid) | |
| 45 | 46 | } | } |
| 46 | 47 | $row = sql_fetch_array($res); | $row = sql_fetch_array($res); |
| 47 | 48 | sql_free_result($res); | sql_free_result($res); |
| 48 | if (isset($row['uid'])) | ||
| 49 | $uid = $row['uid']; | ||
| 49 | if (isset($row['uid'])) { | ||
| 50 | if ($row['expire'] >= $now) | ||
| 51 | $uid = $row['uid']; | ||
| 52 | else | ||
| 53 | xlog("\tSession too old (" . ($now - $row['expire']) . "s)"); | ||
| 54 | } | ||
| 50 | 55 | ||
| 51 | 56 | xlog("\tuid=$uid."); | xlog("\tuid=$uid."); |
| 52 | 57 | ||
| File inc/user.inc.php changed (mode: 100644) (index ab17c87..ead7291) | |||
| ... | ... | function gg_user_error() | |
| 20 | 20 | /* | /* |
| 21 | 21 | * Add a user | * Add a user |
| 22 | 22 | */ | */ |
| 23 | function user_add($db, $user, $pass, $email) | ||
| 23 | function user_add($db, $user, $pass, $email, $is_admin) | ||
| 24 | 24 | { | { |
| 25 | xlog("user_add: user=$user, pass=$pass, email=$email..."); | ||
| 25 | xlog("user_add: user=$user, pass=$pass, email=$email, is_admin=$is_admin..."); | ||
| 26 | 26 | ||
| 27 | 27 | $itime = time(); | $itime = time(); |
| 28 | 28 | $e_salt = sha1(mt_rand() . microtime(TRUE)); | $e_salt = sha1(mt_rand() . microtime(TRUE)); |
| ... | ... | function user_add($db, $user, $pass, $email) | |
| 31 | 31 | $e_user = sql_escape($db, $user); | $e_user = sql_escape($db, $user); |
| 32 | 32 | $e_email = sql_escape($db, $email); | $e_email = sql_escape($db, $email); |
| 33 | 33 | ||
| 34 | $sql = "INSERT INTO users (user, salt, pass, email, itime)" | ||
| 34 | $sql = "INSERT INTO users (user, salt, pass, email, itime, is_admin)" | ||
| 35 | 35 | . " VALUES ('$e_user', '$e_salt', '$e_sha1pass', '$e_email'" | . " VALUES ('$e_user', '$e_salt', '$e_sha1pass', '$e_email'" |
| 36 | . ", $time)"; | ||
| 36 | . ", $itime, $is_admin)"; | ||
| 37 | 37 | $res = sql_query($db, $sql); | $res = sql_query($db, $sql); |
| 38 | 38 | if ($res === FALSE) { | if ($res === FALSE) { |
| 39 | 39 | gg_user_set_error("Cannot insert user (" . sql_error() . ")!"); | gg_user_set_error("Cannot insert user (" . sql_error() . ")!"); |
| ... | ... | function user_info($db, $uid, $user) | |
| 69 | 69 | { | { |
| 70 | 70 | xlog("user_info: uid=[$uid], user=[$user]..."); | xlog("user_info: uid=[$uid], user=[$user]..."); |
| 71 | 71 | ||
| 72 | $ret = array(); | ||
| 73 | $ret['ok'] = 0; | ||
| 74 | $ret['exists'] = 0; | ||
| 75 | |||
| 72 | 76 | if ($uid > 0) { | if ($uid > 0) { |
| 73 | 77 | $add = " AND uid = " . sprintf("%u", $uid); | $add = " AND uid = " . sprintf("%u", $uid); |
| 74 | 78 | } else { | } else { |
| ... | ... | function user_info($db, $uid, $user) | |
| 76 | 80 | $add = " AND user = '$e_user'"; | $add = " AND user = '$e_user'"; |
| 77 | 81 | } | } |
| 78 | 82 | ||
| 79 | $sql = "SELECT * FROM users WHERE suspended = 0" . $add; | ||
| 83 | $sql = "SELECT * FROM users WHERE 1 = 1" . $add; | ||
| 80 | 84 | $res = sql_query($db, $sql); | $res = sql_query($db, $sql); |
| 81 | 85 | if ($res === FALSE) { | if ($res === FALSE) { |
| 82 | 86 | gg_user_set_error("Cannot get info (" . sql_error() . ")!"); | gg_user_set_error("Cannot get info (" . sql_error() . ")!"); |
| 83 | return FALSE; | ||
| 87 | return $ret; | ||
| 84 | 88 | } | } |
| 89 | |||
| 90 | $ret['ok'] = 1; | ||
| 85 | 91 | $row = sql_fetch_array($res); | $row = sql_fetch_array($res); |
| 86 | 92 | sql_free_result($res); | sql_free_result($res); |
| 87 | 93 | if (!isset($row['user'])) { | if (!isset($row['user'])) { |
| 88 | gg_user_set_error("User not found (" . sql_error() . ")!"); | ||
| 89 | return FALSE; | ||
| 94 | gg_user_set_error("User not found!"); | ||
| 95 | return $ret; | ||
| 90 | 96 | } | } |
| 91 | 97 | ||
| 98 | $row['ok'] = 1; | ||
| 99 | $row['exists'] = 1; | ||
| 92 | 100 | return $row; | return $row; |
| 93 | 101 | } | } |
| 94 | 102 | ||
| 95 | 103 | /* | /* |
| 96 | 104 | * Test if login is OK | * Test if login is OK |
| 97 | 105 | */ | */ |
| 98 | function user_login($db, $sid) | ||
| 106 | function user_login($db, $sid, &$ui) | ||
| 99 | 107 | { | { |
| 100 | 108 | xlog("user_login: sid=$sid..."); | xlog("user_login: sid=$sid..."); |
| 101 | 109 | ||
| 102 | 110 | if (($uid = sess_valid($db, $sid))) { | if (($uid = sess_valid($db, $sid))) { |
| 111 | $ui = user_info($db, $uid, ""); | ||
| 103 | 112 | sess_update($db, $sid); | sess_update($db, $sid); |
| 104 | 113 | return $uid; | return $uid; |
| 105 | 114 | } | } |
| ... | ... | function user_login($db, $sid) | |
| 111 | 120 | return FALSE; | return FALSE; |
| 112 | 121 | ||
| 113 | 122 | $ui = user_info($db, 0, $user); | $ui = user_info($db, 0, $user); |
| 114 | if ($ui === FALSE) { | ||
| 123 | if ($ui['ok'] == 0) { | ||
| 124 | gg_user_set_error("Internal error"); | ||
| 125 | return FALSE; | ||
| 126 | } | ||
| 127 | |||
| 128 | if ($ui['exists'] == 0) { | ||
| 115 | 129 | gg_user_set_error("Invalid user or pass!"); | gg_user_set_error("Invalid user or pass!"); |
| 116 | 130 | return FALSE; | return FALSE; |
| 117 | 131 | } | } |
| ... | ... | function user_login($db, $sid) | |
| 130 | 144 | return $ui['uid']; | return $ui['uid']; |
| 131 | 145 | } | } |
| 132 | 146 | ||
| 147 | /* | ||
| 148 | * Suspend an account | ||
| 149 | * 1=suspend, 0=unsuspend | ||
| 150 | */ | ||
| 151 | function user_suspend($db, $uid, $op) | ||
| 152 | { | ||
| 153 | xlog("user_suspend: uid=$uid, op=$op"); | ||
| 154 | |||
| 155 | $now = time(); | ||
| 156 | |||
| 157 | if ($op == 1) | ||
| 158 | $v = $now; | ||
| 159 | else | ||
| 160 | $v = 0; | ||
| 161 | |||
| 162 | $sql = "UPDATE users SET suspended = $v WHERE uid = $uid"; | ||
| 163 | $res = sql_query($db, $sql); | ||
| 164 | if ($res === FALSE) | ||
| 165 | return FALSE; | ||
| 166 | sql_free_result($res); | ||
| 167 | |||
| 168 | return TRUE; | ||
| 169 | } | ||
| 170 | |||
| 171 | /* | ||
| 172 | * Make/remove admin | ||
| 173 | * 1=make, 0=remove | ||
| 174 | */ | ||
| 175 | function user_admin($db, $uid, $op) | ||
| 176 | { | ||
| 177 | xlog("user_admin: uid=$uid, op=$op"); | ||
| 178 | |||
| 179 | $now = time(); | ||
| 180 | |||
| 181 | $sql = "UPDATE users SET is_admin = $op WHERE uid = $uid"; | ||
| 182 | $res = sql_query($db, $sql); | ||
| 183 | if ($res === FALSE) | ||
| 184 | return FALSE; | ||
| 185 | sql_free_result($res); | ||
| 186 | |||
| 187 | return TRUE; | ||
| 188 | } | ||
| 189 | |||
| 133 | 190 | /* | /* |
| 134 | 191 | * List users | * List users |
| 135 | 192 | */ | */ |
| 136 | function user_list($db) | ||
| 193 | function user_list($db, $url) | ||
| 137 | 194 | { | { |
| 138 | xlog("user_list..."); | ||
| 195 | xlog("user_list, url=$url..."); | ||
| 196 | |||
| 197 | $ret = ""; | ||
| 198 | |||
| 199 | $xuid = sprintf("%u", @$_REQUEST['xuid']); | ||
| 200 | |||
| 201 | if (isset($_REQUEST['suspend'])) { | ||
| 202 | if (!user_suspend($db, $xuid, $_REQUEST['suspend'])) | ||
| 203 | $ret .= "<font color=red>Cannot suspend!</font><br />"; | ||
| 204 | } | ||
| 205 | |||
| 206 | if (isset($_REQUEST['admin'])) { | ||
| 207 | if (!user_admin($db, $xuid, $_REQUEST['admin'])) | ||
| 208 | $ret .= "<font color=red>Cannot make admin!</font><br />"; | ||
| 209 | } | ||
| 210 | |||
| 211 | if (isset($_REQUEST['remove'])) { | ||
| 212 | if (!user_remove($db, $xuid)) | ||
| 213 | $ret .= "<font color=red>Cannot remove!</font><br />"; | ||
| 214 | } | ||
| 139 | 215 | ||
| 140 | 216 | $sql = "SELECT * FROM users ORDER BY user"; | $sql = "SELECT * FROM users ORDER BY user"; |
| 141 | 217 | $res = sql_query($db, $sql); | $res = sql_query($db, $sql); |
| ... | ... | function user_list($db) | |
| 144 | 220 | return FALSE; | return FALSE; |
| 145 | 221 | } | } |
| 146 | 222 | ||
| 147 | $ret = "<table>\n"; | ||
| 223 | $ret .= "<table>\n"; | ||
| 148 | 224 | $ret .= "<tr>\n"; | $ret .= "<tr>\n"; |
| 149 | 225 | $ret .= " <th>Name</th>\n"; | $ret .= " <th>Name</th>\n"; |
| 150 | 226 | $ret .= " <th>E-mail</th>\n"; | $ret .= " <th>E-mail</th>\n"; |
| 227 | $ret .= " <th>Admin</th>\n"; | ||
| 151 | 228 | $ret .= " <th>Creation date</th>\n"; | $ret .= " <th>Creation date</th>\n"; |
| 152 | 229 | $ret .= " <th>Suspended?</th>\n"; | $ret .= " <th>Suspended?</th>\n"; |
| 153 | 230 | $ret .= " <th>Session time</th>\n"; | $ret .= " <th>Session time</th>\n"; |
| 154 | 231 | $ret .= " <th>Last seen</th>\n"; | $ret .= " <th>Last seen</th>\n"; |
| 232 | $ret .= " <th>Operations</th>\n"; | ||
| 155 | 233 | $ret .= "</tr>\n"; | $ret .= "</tr>\n"; |
| 156 | 234 | while (($row = sql_fetch_array($res))) { | while (($row = sql_fetch_array($res))) { |
| 157 | 235 | $ret .= "<tr>\n"; | $ret .= "<tr>\n"; |
| 158 | 236 | $ret .= " <td>" . $row['user'] . "</td>\n"; | $ret .= " <td>" . $row['user'] . "</td>\n"; |
| 159 | 237 | $ret .= " <td>" . $row['email'] . "</td>\n"; | $ret .= " <td>" . $row['email'] . "</td>\n"; |
| 238 | $ret .= " <td>" . ($row['is_admin'] == 1 ? "Yes" : "No") . "</td>\n"; | ||
| 160 | 239 | $ret .= " <td>" . date("Y-m-d H:i:s", $row['itime']) . "</td>\n"; | $ret .= " <td>" . date("Y-m-d H:i:s", $row['itime']) . "</td>\n"; |
| 161 | 240 | $ret .= " <td>" . ($row['suspended'] == 0 ? "No" : "Yes") . "</th>\n"; | $ret .= " <td>" . ($row['suspended'] == 0 ? "No" : "Yes") . "</th>\n"; |
| 162 | 241 | $ret .= " <td>" . $row['session_time'] . "s</td>\n"; | $ret .= " <td>" . $row['session_time'] . "s</td>\n"; |
| 163 | 242 | $ret .= " <td>" . date("Y-m-d H:i:s", $row['last_seen']) . "</td>\n"; | $ret .= " <td>" . date("Y-m-d H:i:s", $row['last_seen']) . "</td>\n"; |
| 243 | // operations | ||
| 244 | // suspend | ||
| 245 | $ret .= " <td>"; | ||
| 246 | $_url = $url . "&xuid=" . $row['uid']; | ||
| 247 | $v = 1; $t = "Suspend"; | ||
| 248 | if ($row['suspended'] > 0) { | ||
| 249 | $t = "Unsuspend"; | ||
| 250 | $v = 0; | ||
| 251 | } | ||
| 252 | $ret .= "[<a href=\"$_url&suspend=$v\">$t</a>]"; | ||
| 253 | // admin | ||
| 254 | $v = 1; $t = "Make admin"; | ||
| 255 | if ($row['is_admin'] == 1) { | ||
| 256 | $t = "Remove admin"; | ||
| 257 | $v = 0; | ||
| 258 | } | ||
| 259 | $ret .= "[<a href=\"$_url&admin=$v\">$t</a>]"; | ||
| 260 | // remove | ||
| 261 | if ($row['suspended'] > 0) | ||
| 262 | $ret .= "[<a href=\"$_url&remove=1\">Remove!</a>]"; | ||
| 263 | $ret .= " </td>"; | ||
| 164 | 264 | $ret .= "</tr>\n"; | $ret .= "</tr>\n"; |
| 165 | 265 | } | } |
| 166 | 266 | $ret .= "</table>\n"; | $ret .= "</table>\n"; |
| File root/index.php changed (mode: 100644) (index 0363c36..0398183) | |||
| ... | ... | $sid = @$_COOKIE['sid']; | |
| 24 | 24 | if (empty($sid)) | if (empty($sid)) |
| 25 | 25 | $sid = @$_REQUEST['sid']; | $sid = @$_REQUEST['sid']; |
| 26 | 26 | ||
| 27 | xlog("_REQUEST: " . print_r($_REQUEST, TRUE)); | ||
| 28 | xlog("_COOKIE: " . print_r($_COOKIE, TRUE)); | ||
| 27 | 29 | xlog("Start! op=$op, doit=$doit, sid=$sid..."); | xlog("Start! op=$op, doit=$doit, sid=$sid..."); |
| 28 | 30 | ||
| 29 | 31 | ||
| ... | ... | if ($db === FALSE) | |
| 46 | 48 | die("Cannot open database!"); | die("Cannot open database!"); |
| 47 | 49 | ||
| 48 | 50 | // deal with login | // deal with login |
| 49 | $uid = user_login($db, $sid); | ||
| 51 | $uid = user_login($db, $sid, $gg_ui); | ||
| 50 | 52 | if (($op == 1) && ($doit == 1) && ($uid == 0)) | if (($op == 1) && ($doit == 1) && ($uid == 0)) |
| 51 | 53 | $op = 0; | $op = 0; |
| 52 | 54 | ||
| 53 | 55 | // deal with logout | // deal with logout |
| 54 | 56 | if ($op == 9) { | if ($op == 9) { |
| 55 | 57 | sess_destroy($db, $sid); | sess_destroy($db, $sid); |
| 56 | $uid = ""; | ||
| 58 | $uid = 0; | ||
| 59 | $gg_ui = FALSE; | ||
| 57 | 60 | } | } |
| 58 | 61 | ||
| 59 | 62 | // menu | // menu |
| 60 | 63 | $url = $_SERVER['PHP_SELF'] . "?a=1"; | $url = $_SERVER['PHP_SELF'] . "?a=1"; |
| 61 | 64 | $menu = ""; | $menu = ""; |
| 62 | $ui = user_info($db, $uid); | ||
| 63 | if ($ui === FALSE) | ||
| 64 | $u = "Not logged in"; | ||
| 65 | else | ||
| 66 | $u = $ui['user']; | ||
| 65 | $u = "Not logged in"; | ||
| 66 | if (isset($gg_ui['user'])) | ||
| 67 | $u = $gg_ui['user']; | ||
| 67 | 68 | $menu .= "[$u]<br />\n"; | $menu .= "[$u]<br />\n"; |
| 68 | 69 | $menu .= "[<a href=\"$url&op=1\">Login</a>]"; | $menu .= "[<a href=\"$url&op=1\">Login</a>]"; |
| 69 | 70 | $menu .= " [<a href=\"$url&op=2\">Repositories</a>]"; | $menu .= " [<a href=\"$url&op=2\">Repositories</a>]"; |
| 70 | $menu .= " [<a href=\"$url&op=3\">Admin</a>]"; | ||
| 71 | if ($gg_ui['is_admin'] == 1) | ||
| 72 | $menu .= " [<a href=\"$url&op=3\">Admin</a>]"; | ||
| 71 | 73 | $menu .= " [<a href=\"$url&op=9\">Logout</a>]"; | $menu .= " [<a href=\"$url&op=9\">Logout</a>]"; |
| 72 | 74 | ||
| 73 | 75 | ||