| File inc/keys.inc.php changed (mode: 100644) (index 92fd4d2..ddb0b09) |
| 2 |
2 |
require_once($INC . "/db.inc.php"); |
require_once($INC . "/db.inc.php"); |
| 3 |
3 |
require_once($INC . "/state.inc.php"); |
require_once($INC . "/state.inc.php"); |
| 4 |
4 |
|
|
| 5 |
|
$keys_error = ""; |
|
|
5 |
|
$rg_keys_error = ""; |
| 6 |
6 |
|
|
| 7 |
|
function keys_set_error($str) |
|
|
7 |
|
function rg_keys_set_error($str) |
| 8 |
8 |
{ |
{ |
| 9 |
|
global $keys_error; |
|
|
9 |
|
global $rg_keys_error; |
| 10 |
10 |
|
|
| 11 |
|
xlog("\tError: $str"); |
|
| 12 |
|
$keys_error = $str; |
|
|
11 |
|
rg_log("\tError: $str"); |
|
12 |
|
$rg_keys_error = $str; |
| 13 |
13 |
} |
} |
| 14 |
14 |
|
|
| 15 |
|
function keys_error() |
|
|
15 |
|
function rg_keys_error() |
| 16 |
16 |
{ |
{ |
| 17 |
|
global $keys_error; |
|
| 18 |
|
return $keys_error; |
|
|
17 |
|
global $rg_keys_error; |
|
18 |
|
return $rg_keys_error; |
| 19 |
19 |
} |
} |
| 20 |
20 |
|
|
| 21 |
21 |
/* |
/* |
| 22 |
|
* Generates the fingerprint of a key |
|
|
22 |
|
* Validate key |
| 23 |
23 |
*/ |
*/ |
| 24 |
|
function keys_fingerprint($key) |
|
|
24 |
|
function rg_keys_valid($s) |
| 25 |
25 |
{ |
{ |
| 26 |
|
$v = explode(" ", $key); |
|
|
26 |
|
$v = explode(" ", $s); |
|
27 |
|
if (!isset($v[1])) { |
|
28 |
|
rg_keys_set_error("Malformed input (missing fields)"); |
|
29 |
|
return FALSE; |
|
30 |
|
} |
| 27 |
31 |
|
|
| 28 |
32 |
$decoded = base64_decode(trim($v[1])); |
$decoded = base64_decode(trim($v[1])); |
|
33 |
|
if ($decoded === FALSE) { |
|
34 |
|
rg_keys_set_error("Malformed input (base64 failed)"); |
|
35 |
|
return FALSE; |
|
36 |
|
} |
|
37 |
|
|
|
38 |
|
return $decoded; |
|
39 |
|
} |
|
40 |
|
|
|
41 |
|
/* |
|
42 |
|
* Generates the fingerprint of a key |
|
43 |
|
*/ |
|
44 |
|
function rg_keys_fingerprint($key) |
|
45 |
|
{ |
|
46 |
|
$decoded = rg_keys_valid($key); |
|
47 |
|
if ($decoded === FALSE) |
|
48 |
|
return rg_keys_error(); |
|
49 |
|
|
| 29 |
50 |
$digest = md5($decoded); |
$digest = md5($decoded); |
| 30 |
51 |
|
|
| 31 |
52 |
$a = array(); |
$a = array(); |
| |
| ... |
... |
function keys_fingerprint($key) |
| 38 |
59 |
/* |
/* |
| 39 |
60 |
* Remove a key from database |
* Remove a key from database |
| 40 |
61 |
*/ |
*/ |
| 41 |
|
function keys_remove($db, $uid, $key_id) |
|
|
62 |
|
function rg_keys_remove($db, $rg_ui, $key_id) |
| 42 |
63 |
{ |
{ |
| 43 |
64 |
// mark dirty |
// mark dirty |
| 44 |
|
state_set($db, "authorized_keys", 1); |
|
|
65 |
|
rg_state_set($db, "authorized_keys", 1); |
| 45 |
66 |
|
|
| 46 |
|
$e_uid = sprintf("%u", $uid); |
|
|
67 |
|
// TODO: move this to caller? |
| 47 |
68 |
$e_key_id = sprintf("%u", $key_id); |
$e_key_id = sprintf("%u", $key_id); |
| 48 |
69 |
|
|
| 49 |
70 |
$sql = "DELETE FROM keys" |
$sql = "DELETE FROM keys" |
| 50 |
|
. " WHERE uid = $e_uid" |
|
|
71 |
|
. " WHERE uid = " . $rg_ui['uid'] |
| 51 |
72 |
. " AND key_id = $e_key_id"; |
. " AND key_id = $e_key_id"; |
| 52 |
|
$res = sql_query($db, $sql); |
|
|
73 |
|
$res = rg_sql_query($db, $sql); |
| 53 |
74 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 54 |
|
keys_set_error("Cannot delete key $key_id (" . sql_error() . ")"); |
|
|
75 |
|
rg_keys_set_error("Cannot delete key $key_id (" . rg_sql_error() . ")"); |
| 55 |
76 |
return FALSE; |
return FALSE; |
| 56 |
77 |
} |
} |
| 57 |
|
sql_free_result($res); |
|
|
78 |
|
rg_sql_free_result($res); |
| 58 |
79 |
|
|
| 59 |
80 |
return TRUE; |
return TRUE; |
| 60 |
81 |
} |
} |
| |
| ... |
... |
function keys_remove($db, $uid, $key_id) |
| 63 |
84 |
* Add a key |
* Add a key |
| 64 |
85 |
* Returns the key_id of the key. |
* Returns the key_id of the key. |
| 65 |
86 |
*/ |
*/ |
| 66 |
|
function keys_add($db, $uid, $key) |
|
|
87 |
|
function rg_keys_add($db, $rg_ui, $key) |
| 67 |
88 |
{ |
{ |
| 68 |
89 |
$itime = time(); |
$itime = time(); |
| 69 |
|
$e_uid = sprintf("%u", $uid); |
|
| 70 |
|
$e_key = sql_escape($db, $key); |
|
|
90 |
|
$e_key = rg_sql_escape($db, $key); |
|
91 |
|
|
|
92 |
|
if (rg_keys_valid($key) === FALSE) |
|
93 |
|
return FALSE; |
| 71 |
94 |
|
|
| 72 |
95 |
// set dirty |
// set dirty |
| 73 |
|
if (state_set($db, "authorized_keys", 1) === FALSE) |
|
|
96 |
|
if (rg_state_set($db, "authorized_keys", 1) === FALSE) |
| 74 |
97 |
return FALSE; |
return FALSE; |
| 75 |
98 |
|
|
| 76 |
99 |
$sql = "INSERT INTO keys (itime, uid, key)" |
$sql = "INSERT INTO keys (itime, uid, key)" |
| 77 |
|
. " VALUES ($itime, $e_uid, '$e_key')"; |
|
| 78 |
|
$res = sql_query($db, $sql); |
|
|
100 |
|
. " VALUES ($itime, " . $rg_ui['uid'] . ", '$e_key')"; |
|
101 |
|
$res = rg_sql_query($db, $sql); |
| 79 |
102 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 80 |
|
keys_set_error("Cannot insert key (" . sql_error() . ")"); |
|
|
103 |
|
rg_keys_set_error("Cannot insert key (" . rg_sql_error() . ")"); |
| 81 |
104 |
return FALSE; |
return FALSE; |
| 82 |
105 |
} |
} |
| 83 |
|
sql_free_result($res); |
|
|
106 |
|
rg_sql_free_result($res); |
| 84 |
107 |
|
|
| 85 |
|
return sql_last_id($db); |
|
|
108 |
|
return rg_sql_last_id($db); |
| 86 |
109 |
} |
} |
| 87 |
110 |
|
|
| 88 |
111 |
/* |
/* |
| 89 |
112 |
* Regenerates authorized_keys files |
* Regenerates authorized_keys files |
| 90 |
113 |
*/ |
*/ |
| 91 |
|
function keys_regen($db) |
|
|
114 |
|
function rg_keys_regen($db) |
| 92 |
115 |
{ |
{ |
| 93 |
|
global $gg_keys_file; |
|
| 94 |
|
global $gg_scripts; |
|
|
116 |
|
global $rg_keys_file; |
|
117 |
|
global $rg_scripts; |
| 95 |
118 |
|
|
| 96 |
|
$dirty = state_get($db, "authorized_keys"); |
|
|
119 |
|
$dirty = rg_state_get($db, "authorized_keys"); |
| 97 |
120 |
if ($dirty == 0) |
if ($dirty == 0) |
| 98 |
121 |
return TRUE; |
return TRUE; |
| 99 |
122 |
|
|
| 100 |
|
$tmp = $gg_keys_file . ".tmp"; |
|
|
123 |
|
$tmp = $rg_keys_file . ".tmp"; |
| 101 |
124 |
$f = @fopen($tmp, "w"); |
$f = @fopen($tmp, "w"); |
| 102 |
125 |
if ($f === FALSE) { |
if ($f === FALSE) { |
| 103 |
|
keys_set_error("Cannot open file $tmp ($php_errormsg)!"); |
|
|
126 |
|
rg_keys_set_error("Cannot open file $tmp ($php_errormsg)!"); |
| 104 |
127 |
return FALSE; |
return FALSE; |
| 105 |
128 |
} |
} |
| 106 |
129 |
|
|
| 107 |
130 |
if (chmod($tmp, 0600) === FALSE) { |
if (chmod($tmp, 0600) === FALSE) { |
| 108 |
|
keys_set_error("Cannot chmod tmp file ($php_errmsg)!"); |
|
|
131 |
|
rg_keys_set_error("Cannot chmod tmp file ($php_errmsg)!"); |
| 109 |
132 |
return FALSE; |
return FALSE; |
| 110 |
133 |
} |
} |
| 111 |
134 |
|
|
| 112 |
135 |
$sql = "SELECT uid, key FROM keys"; |
$sql = "SELECT uid, key FROM keys"; |
| 113 |
|
$res = sql_query($db, $sql); |
|
|
136 |
|
$res = rg_sql_query($db, $sql); |
| 114 |
137 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 115 |
|
keys_set_error("Cannot query (" . sql_error() . ")"); |
|
|
138 |
|
rg_keys_set_error("Cannot query (" . rg_sql_error() . ")"); |
| 116 |
139 |
return FALSE; |
return FALSE; |
| 117 |
140 |
} |
} |
| 118 |
|
while (($row = sql_fetch_array($res))) { |
|
| 119 |
|
$buf = "command=\"/usr/bin/php " . $gg_scripts . "/ssh.php " . $row['uid'] . "\"" |
|
|
141 |
|
while (($row = rg_sql_fetch_array($res))) { |
|
142 |
|
$buf = "command=\"/usr/bin/php " . $rg_scripts . "/ssh.php " . $row['uid'] . "\"" |
| 120 |
143 |
. ",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty" |
. ",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty" |
| 121 |
144 |
. " " . $row['key'] . "\n"; |
. " " . $row['key'] . "\n"; |
| 122 |
145 |
if (@fwrite($f, $buf) === FALSE) { |
if (@fwrite($f, $buf) === FALSE) { |
| 123 |
|
keys_set_error("Cannot write. Disk space problems? ($php_errormsg)"); |
|
|
146 |
|
rg_keys_set_error("Cannot write. Disk space problems? ($php_errormsg)"); |
| 124 |
147 |
fclose($f); |
fclose($f); |
| 125 |
148 |
unlink($tmp); |
unlink($tmp); |
| 126 |
|
sql_free_result($res); |
|
|
149 |
|
rg_sql_free_result($res); |
| 127 |
150 |
return FALSE; |
return FALSE; |
| 128 |
151 |
} |
} |
| 129 |
152 |
} |
} |
| 130 |
|
sql_free_result($res); |
|
|
153 |
|
rg_sql_free_result($res); |
| 131 |
154 |
|
|
| 132 |
155 |
fclose($f); |
fclose($f); |
| 133 |
156 |
|
|
| 134 |
|
if (@rename($tmp, $gg_keys_file) === FALSE) { |
|
| 135 |
|
keys_set_error("Cannot rename $tmp to $gg_keys_file ($php_errormsg)!"); |
|
|
157 |
|
if (@rename($tmp, $rg_keys_file) === FALSE) { |
|
158 |
|
rg_keys_set_error("Cannot rename $tmp to $rg_keys_file ($php_errormsg)!"); |
| 136 |
159 |
unlink($tmp); |
unlink($tmp); |
| 137 |
160 |
return FALSE; |
return FALSE; |
| 138 |
161 |
} |
} |
| 139 |
162 |
|
|
| 140 |
163 |
// mark file as clean |
// mark file as clean |
| 141 |
|
state_set($db, "authorized_keys", 0); |
|
|
164 |
|
rg_state_set($db, "authorized_keys", 0); |
| 142 |
165 |
|
|
| 143 |
166 |
return TRUE; |
return TRUE; |
| 144 |
167 |
} |
} |
| |
| ... |
... |
function keys_regen($db) |
| 146 |
169 |
/* |
/* |
| 147 |
170 |
* List keys |
* List keys |
| 148 |
171 |
*/ |
*/ |
| 149 |
|
function keys_list($db, $uid, $url) |
|
|
172 |
|
function rg_keys_list($db, $rg_ui, $url) |
| 150 |
173 |
{ |
{ |
| 151 |
|
xlog("keys_list: uid=$uid, url=$url..."); |
|
|
174 |
|
rg_log("keys_list: rg_uid=" . $rg_ui['uid'] . ", url=$url..."); |
| 152 |
175 |
|
|
| 153 |
|
$sql = "SELECT * FROM keys WHERE uid = $uid"; |
|
| 154 |
|
$res = sql_query($db, $sql); |
|
|
176 |
|
$sql = "SELECT * FROM keys WHERE uid = " . $rg_ui['uid']; |
|
177 |
|
$res = rg_sql_query($db, $sql); |
| 155 |
178 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 156 |
|
keys_set_error("Cannot query (" . sql_error() . ")"); |
|
|
179 |
|
rg_keys_set_error("Cannot query (" . rg_sql_error() . ")"); |
| 157 |
180 |
return FALSE; |
return FALSE; |
| 158 |
181 |
} |
} |
| 159 |
182 |
|
|
| |
| ... |
... |
function keys_list($db, $uid, $url) |
| 163 |
186 |
$ret .= " <th>Fingerprint</th>\n"; |
$ret .= " <th>Fingerprint</th>\n"; |
| 164 |
187 |
$ret .= " <th>Operations</th>\n"; |
$ret .= " <th>Operations</th>\n"; |
| 165 |
188 |
$ret .= "</tr>\n"; |
$ret .= "</tr>\n"; |
| 166 |
|
while (($row = sql_fetch_array($res))) { |
|
|
189 |
|
while (($row = rg_sql_fetch_array($res))) { |
| 167 |
190 |
$ret .= "<tr>\n"; |
$ret .= "<tr>\n"; |
| 168 |
191 |
$ret .= " <td>" . gmdate("Y-m-d H:i:s", $row['itime']) . "</td>\n"; |
$ret .= " <td>" . gmdate("Y-m-d H:i:s", $row['itime']) . "</td>\n"; |
| 169 |
|
$ret .= " <td>" . keys_fingerprint($row['key']) . "</td>\n"; |
|
|
192 |
|
$ret .= " <td>" . rg_keys_fingerprint($row['key']) . "</td>\n"; |
| 170 |
193 |
|
|
| 171 |
194 |
$oper = ""; |
$oper = ""; |
| 172 |
195 |
$oper = "[<a href=\"$url&key_id=" . $row['key_id'] |
$oper = "[<a href=\"$url&key_id=" . $row['key_id'] |
| |
| ... |
... |
function keys_list($db, $uid, $url) |
| 175 |
198 |
$ret .= "</tr>\n"; |
$ret .= "</tr>\n"; |
| 176 |
199 |
} |
} |
| 177 |
200 |
$ret .= "</table>\n"; |
$ret .= "</table>\n"; |
| 178 |
|
sql_free_result($res); |
|
|
201 |
|
rg_sql_free_result($res); |
| 179 |
202 |
|
|
| 180 |
203 |
return $ret; |
return $ret; |
| 181 |
204 |
} |
} |
| File inc/repo.inc.php changed (mode: 100644) (index bd1ce29..c641892) |
| 1 |
1 |
<?php |
<?php |
| 2 |
2 |
require_once($INC . "/util.inc.php"); |
require_once($INC . "/util.inc.php"); |
| 3 |
|
require_once($INC . "/xlog.inc.php"); |
|
|
3 |
|
require_once($INC . "/log.inc.php"); |
| 4 |
4 |
require_once($INC . "/db.inc.php"); |
require_once($INC . "/db.inc.php"); |
| 5 |
5 |
require_once($INC . "/user.inc.php"); |
require_once($INC . "/user.inc.php"); |
| 6 |
6 |
require_once($INC . "/git.inc.php"); |
require_once($INC . "/git.inc.php"); |
| 7 |
7 |
|
|
| 8 |
|
$gg_repo_error = ""; |
|
|
8 |
|
$rg_repo_error = ""; |
| 9 |
9 |
|
|
| 10 |
|
$gg_repo_rights = array("A" => "Admin", |
|
|
10 |
|
$rg_repo_rights = array("A" => "Admin", |
| 11 |
11 |
"F" => "Fetch", |
"F" => "Fetch", |
| 12 |
12 |
"P" => "Push", |
"P" => "Push", |
| 13 |
13 |
"D" => "Delete branch"); |
"D" => "Delete branch"); |
| 14 |
14 |
|
|
| 15 |
|
function gg_repo_set_error($str) |
|
|
15 |
|
function rg_repo_set_error($str) |
| 16 |
16 |
{ |
{ |
| 17 |
|
global $gg_repo_error; |
|
|
17 |
|
global $rg_repo_error; |
| 18 |
18 |
|
|
| 19 |
|
xlog("\tError: $str"); |
|
| 20 |
|
$gg_repo_error = $str; |
|
|
19 |
|
rg_log("\tError: $str"); |
|
20 |
|
$rg_repo_error = $str; |
| 21 |
21 |
} |
} |
| 22 |
22 |
|
|
| 23 |
|
function gg_repo_error() |
|
|
23 |
|
function rg_repo_error() |
| 24 |
24 |
{ |
{ |
| 25 |
|
global $gg_repo_error; |
|
| 26 |
|
return $gg_repo_error; |
|
|
25 |
|
global $rg_repo_error; |
|
26 |
|
return $rg_repo_error; |
|
27 |
|
} |
|
28 |
|
|
|
29 |
|
/* |
|
30 |
|
* Enforce name |
|
31 |
|
*/ |
|
32 |
|
function rg_repo_ok($repo) |
|
33 |
|
{ |
|
34 |
|
global $rg_repo_allow; |
|
35 |
|
global $rg_repo_max_len; |
|
36 |
|
|
|
37 |
|
if (rg_chars_allow($repo, $rg_repo_allow) === FALSE) { |
|
38 |
|
rg_repo_set_error("Invalid repository name"); |
|
39 |
|
return FALSE; |
|
40 |
|
} |
|
41 |
|
|
|
42 |
|
if (preg_match('/\.\./', $repo)) { |
|
43 |
|
rg_repo_set_error("Invalid repository name"); |
|
44 |
|
return FALSE; |
|
45 |
|
} |
|
46 |
|
|
|
47 |
|
if (strlen($repo) > $rg_repo_max_len) { |
|
48 |
|
rg_repo_set_error("Repository name is too long"); |
|
49 |
|
return FALSE; |
|
50 |
|
} |
|
51 |
|
|
|
52 |
|
return TRUE; |
| 27 |
53 |
} |
} |
| 28 |
54 |
|
|
| 29 |
55 |
/* |
/* |
| 30 |
56 |
* Returns the path to a repository based on repo_id |
* Returns the path to a repository based on repo_id |
| 31 |
57 |
*/ |
*/ |
| 32 |
|
function repo_id2base($repo_id) |
|
|
58 |
|
function rg_repo_id2base($repo_id) |
| 33 |
59 |
{ |
{ |
| 34 |
|
global $gg_base_repo; |
|
|
60 |
|
global $rg_base_repo; |
| 35 |
61 |
|
|
| 36 |
62 |
$r3 = sprintf("%03u", $repo_id % 1000); |
$r3 = sprintf("%03u", $repo_id % 1000); |
| 37 |
63 |
|
|
| 38 |
|
return $gg_base_repo . "/" |
|
|
64 |
|
return $rg_base_repo . "/" |
| 39 |
65 |
. $r3[0] . "/" . $r3[1] . "/" . $r3[2] . "/"; |
. $r3[0] . "/" . $r3[1] . "/" . $r3[2] . "/"; |
| 40 |
66 |
} |
} |
| 41 |
67 |
|
|
| 42 |
68 |
/* |
/* |
| 43 |
69 |
* Return info about a repo |
* Return info about a repo |
| 44 |
70 |
*/ |
*/ |
| 45 |
|
function repo_info($db, $repo_id, $repo) |
|
|
71 |
|
function rg_repo_info($db, $repo_id, $repo) |
| 46 |
72 |
{ |
{ |
| 47 |
|
xlog("repo_info: repo_id=$repo_id, repo=$repo..."); |
|
|
73 |
|
rg_log("repo_info: repo_id=$repo_id, repo=$repo..."); |
| 48 |
74 |
|
|
| 49 |
75 |
$ret['ok'] = 0; |
$ret['ok'] = 0; |
| 50 |
76 |
$ret['exists'] = 0; |
$ret['exists'] = 0; |
| |
| ... |
... |
function repo_info($db, $repo_id, $repo) |
| 52 |
78 |
if ($repo_id > 0) { |
if ($repo_id > 0) { |
| 53 |
79 |
$add = " AND repo_id = $repo_id"; |
$add = " AND repo_id = $repo_id"; |
| 54 |
80 |
} else if (!empty($repo)) { |
} else if (!empty($repo)) { |
| 55 |
|
$e_repo = sql_escape($db, $repo); |
|
|
81 |
|
$e_repo = rg_sql_escape($db, $repo); |
| 56 |
82 |
$add = " AND name = '$e_repo'"; |
$add = " AND name = '$e_repo'"; |
| 57 |
83 |
} else { |
} else { |
| 58 |
84 |
$ret['errmsg'] = "No repo_id or name specified!"; |
$ret['errmsg'] = "No repo_id or name specified!"; |
| |
| ... |
... |
function repo_info($db, $repo_id, $repo) |
| 60 |
86 |
} |
} |
| 61 |
87 |
|
|
| 62 |
88 |
$sql = "SELECT * FROM repos WHERE 1 = 1" . $add; |
$sql = "SELECT * FROM repos WHERE 1 = 1" . $add; |
| 63 |
|
$res = sql_query($db, $sql); |
|
|
89 |
|
$res = rg_sql_query($db, $sql); |
| 64 |
90 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 65 |
|
$ret['errmsg'] = "Cannot query (" . sql_error() . ")"; |
|
| 66 |
|
xlog("\t" . $ret['errmsg']); |
|
|
91 |
|
$ret['errmsg'] = "Cannot query (" . rg_sql_error() . ")"; |
|
92 |
|
rg_log("\t" . $ret['errmsg']); |
| 67 |
93 |
return $ret; |
return $ret; |
| 68 |
94 |
} |
} |
| 69 |
95 |
$ret['ok'] = 1; |
$ret['ok'] = 1; |
| 70 |
|
$row = sql_fetch_array($res); |
|
| 71 |
|
sql_free_result($res); |
|
|
96 |
|
$row = rg_sql_fetch_array($res); |
|
97 |
|
rg_sql_free_result($res); |
| 72 |
98 |
if (!isset($row['repo_id'])) { |
if (!isset($row['repo_id'])) { |
| 73 |
|
xlog("\tRepo not found!"); |
|
|
99 |
|
rg_log("\tRepo not found!"); |
| 74 |
100 |
return $ret; |
return $ret; |
| 75 |
101 |
} |
} |
| 76 |
102 |
|
|
| |
| ... |
... |
function repo_info($db, $repo_id, $repo) |
| 82 |
108 |
/* |
/* |
| 83 |
109 |
* Check if a uid has access to repository |
* Check if a uid has access to repository |
| 84 |
110 |
*/ |
*/ |
| 85 |
|
function repo_allow($db, $ri, $uid, $needed_rights) |
|
|
111 |
|
function rg_repo_allow($db, $ri, $rg_ui, $needed_rights) |
| 86 |
112 |
{ |
{ |
| 87 |
|
xlog("repo_allow: uid=$uid, needed_rights=$needed_rights..."); |
|
|
113 |
|
rg_log("repo_allow: rg_uid=" . $rg_ui['uid'] |
|
114 |
|
. ", needed_rights=$needed_rights..."); |
|
115 |
|
|
|
116 |
|
if ($rg_ui['is_admin'] == 1) |
|
117 |
|
return TRUE; |
| 88 |
118 |
|
|
| 89 |
119 |
if (empty($needed_rights)) { |
if (empty($needed_rights)) { |
| 90 |
|
xlog("\tNo perms passed!"); |
|
|
120 |
|
rg_log("\tNo perms passed!"); |
| 91 |
121 |
return FALSE; |
return FALSE; |
| 92 |
122 |
} |
} |
| 93 |
123 |
|
|
| 94 |
|
$rr = gg_repo_rights_get($db, $ri, $uid); |
|
|
124 |
|
$rr = rg_repo_rights_get($db, $ri, $rg_ui['uid']); |
| 95 |
125 |
if ($rr['ok'] != 1) { |
if ($rr['ok'] != 1) { |
| 96 |
|
gg_repo_set_error("No access!"); |
|
|
126 |
|
rg_repo_set_error("No access!"); |
| 97 |
127 |
return FALSE; |
return FALSE; |
| 98 |
128 |
} |
} |
| 99 |
|
xlog("\tdb rights: " . $rr['rights']); |
|
|
129 |
|
rg_log("\tdb rights: " . $rr['rights']); |
| 100 |
130 |
|
|
| 101 |
131 |
$len = strlen($needed_rights); |
$len = strlen($needed_rights); |
| 102 |
132 |
for ($i = 0; $i < $len; $i++) { |
for ($i = 0; $i < $len; $i++) { |
| 103 |
133 |
if (!strstr($rr['rights'], $needed_rights[$i])) { |
if (!strstr($rr['rights'], $needed_rights[$i])) { |
| 104 |
|
gg_repo_set_error("No rights (" . $needed_rights[$i] . ")"); |
|
|
134 |
|
rg_repo_set_error("No rights (" . $needed_rights[$i] . ")"); |
| 105 |
135 |
return FALSE; |
return FALSE; |
| 106 |
136 |
} |
} |
| 107 |
137 |
} |
} |
| 108 |
138 |
|
|
| 109 |
|
xlog("\tAllow access!"); |
|
|
139 |
|
rg_log("\tAllow access!"); |
| 110 |
140 |
|
|
| 111 |
141 |
return TRUE; |
return TRUE; |
| 112 |
142 |
} |
} |
| |
| ... |
... |
function repo_allow($db, $ri, $uid, $needed_rights) |
| 114 |
144 |
/* |
/* |
| 115 |
145 |
* Add a repository |
* Add a repository |
| 116 |
146 |
* @master - makes sense only for clones - who is the master. |
* @master - makes sense only for clones - who is the master. |
|
147 |
|
* TODO: put all fields into an array! |
| 117 |
148 |
*/ |
*/ |
| 118 |
|
function repo_create($db, $master, $gg_uid, $name, $max_commit_size, $desc, |
|
|
149 |
|
function rg_repo_create($db, $master, $rg_ui, $name, $max_commit_size, $desc, |
| 119 |
150 |
$rights) |
$rights) |
| 120 |
151 |
{ |
{ |
| 121 |
152 |
// TODO: reorder parameters - are not logical |
// TODO: reorder parameters - are not logical |
| 122 |
|
xlog("repo_create: gg_uid=$gg_uid, name=[$name], master=$master" |
|
|
153 |
|
rg_log("repo_create: rg_uid=" . $rg_ui['uid'] |
|
154 |
|
. ", name=[$name], master=$master" |
| 123 |
155 |
. ", max_commit_size=$max_commit_size, desc=[$desc]" |
. ", max_commit_size=$max_commit_size, desc=[$desc]" |
| 124 |
156 |
. ", rights=$rights..."); |
. ", rights=$rights..."); |
| 125 |
157 |
|
|
|
158 |
|
if (rg_repo_ok($name) === FALSE) |
|
159 |
|
return FALSE; |
|
160 |
|
|
| 126 |
161 |
// First, test if it already exists |
// First, test if it already exists |
| 127 |
|
$ri = repo_info($db, 0, $name); |
|
|
162 |
|
$ri = rg_repo_info($db, 0, $name); |
| 128 |
163 |
if ($ri['ok'] != 1) |
if ($ri['ok'] != 1) |
| 129 |
164 |
return FALSE; |
return FALSE; |
| 130 |
165 |
if ($ri['exists'] == 1) { |
if ($ri['exists'] == 1) { |
| 131 |
|
gg_repo_set_error("Repository already exists."); |
|
|
166 |
|
rg_repo_set_error("Repository already exists."); |
| 132 |
167 |
return FALSE; |
return FALSE; |
| 133 |
168 |
} |
} |
| 134 |
169 |
|
|
| 135 |
|
// XSS protection |
|
| 136 |
|
$name = gg_xss($name); |
|
| 137 |
|
$desc = gg_xss($desc); |
|
|
170 |
|
// XSS protection - TODO: be more specific |
|
171 |
|
$name = rg_xss($name); |
|
172 |
|
$desc = rg_xss($desc); |
| 138 |
173 |
|
|
| 139 |
|
$e_name = sql_escape($db, $name); |
|
| 140 |
|
$e_desc = sql_escape($db, $desc); |
|
|
174 |
|
$e_name = rg_sql_escape($db, $name); |
|
175 |
|
$e_desc = rg_sql_escape($db, $desc); |
| 141 |
176 |
|
|
| 142 |
177 |
$itime = time(); |
$itime = time(); |
| 143 |
178 |
|
|
| 144 |
179 |
$sql = "INSERT INTO repos (uid, master, name, itime" |
$sql = "INSERT INTO repos (uid, master, name, itime" |
| 145 |
180 |
. ", max_commit_size, desc, git_dir_done, default_rights)" |
. ", max_commit_size, desc, git_dir_done, default_rights)" |
| 146 |
|
. " VALUES ($gg_uid, $master, '$e_name', $itime" |
|
|
181 |
|
. " VALUES (" . $rg_ui['uid'] . ", $master, '$e_name', $itime" |
| 147 |
182 |
. ", $max_commit_size, '$e_desc', 0, '$rights')"; |
. ", $max_commit_size, '$e_desc', 0, '$rights')"; |
| 148 |
|
$res = sql_query($db, $sql); |
|
|
183 |
|
$res = rg_sql_query($db, $sql); |
| 149 |
184 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 150 |
|
gg_repo_set_error("Cannot insert (" . sql_error() . ")"); |
|
|
185 |
|
rg_repo_set_error("Cannot insert (" . rg_sql_error() . ")"); |
| 151 |
186 |
return FALSE; |
return FALSE; |
| 152 |
187 |
} |
} |
| 153 |
|
sql_free_result($res); |
|
|
188 |
|
rg_sql_free_result($res); |
| 154 |
189 |
|
|
| 155 |
190 |
// git repo creation will be delayed for serialization reasons |
// git repo creation will be delayed for serialization reasons |
| 156 |
191 |
// and for permission reasons (we are apache here) |
// and for permission reasons (we are apache here) |
| |
| ... |
... |
function repo_create($db, $master, $gg_uid, $name, $max_commit_size, $desc, |
| 161 |
196 |
/* |
/* |
| 162 |
197 |
* Delete a repo |
* Delete a repo |
| 163 |
198 |
*/ |
*/ |
| 164 |
|
function gg_repo_delete($db, $repo_id, $gg_uid) |
|
|
199 |
|
function rg_repo_delete($db, $repo_id, $rg_ui) |
| 165 |
200 |
{ |
{ |
| 166 |
|
xlog("repo_delete: gg_uid=$gg_uid, repo_id=$repo_id"); |
|
|
201 |
|
rg_log("repo_delete: rg_uid=" . $rg_ui['uid'] . ", repo_id=$repo_id"); |
| 167 |
202 |
|
|
| 168 |
203 |
// TODO: Check rights |
// TODO: Check rights |
| 169 |
204 |
|
|
| 170 |
205 |
// Only mark it as such, deletion will happen in background |
// Only mark it as such, deletion will happen in background |
| 171 |
206 |
$sql = "UPDATE repos SET deleted = 1 WHERE repo_id = $repo_id"; |
$sql = "UPDATE repos SET deleted = 1 WHERE repo_id = $repo_id"; |
| 172 |
|
$res = sql_query($db, $sql); |
|
|
207 |
|
$res = rg_sql_query($db, $sql); |
| 173 |
208 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 174 |
|
gg_repo_set_error("Cannot delete (" . sql_error() . ")"); |
|
|
209 |
|
rg_repo_set_error("Cannot delete (" . rg_sql_error() . ")"); |
| 175 |
210 |
return FALSE; |
return FALSE; |
| 176 |
211 |
} |
} |
| 177 |
|
sql_free_result($res); |
|
|
212 |
|
rg_sql_free_result($res); |
| 178 |
213 |
|
|
| 179 |
214 |
return TRUE; |
return TRUE; |
| 180 |
215 |
} |
} |
| |
| ... |
... |
function gg_repo_delete($db, $repo_id, $gg_uid) |
| 183 |
218 |
* Update a repository |
* Update a repository |
| 184 |
219 |
* TODO: check rights - also for create? |
* TODO: check rights - also for create? |
| 185 |
220 |
*/ |
*/ |
| 186 |
|
function gg_repo_update($db, $repo_id, $gg_uid, $name, $max_commit_size, $desc, |
|
| 187 |
|
$rights) |
|
|
221 |
|
function rg_repo_update($db, &$new) |
| 188 |
222 |
{ |
{ |
| 189 |
|
xlog("repo_update: repo_id=$repo_id, gg_uid=$gg_uid, name=[$name]" |
|
| 190 |
|
. ", max_commit_size=$max_commit_size, desc=[$desc]" |
|
| 191 |
|
. ", rights=$rights..."); |
|
|
223 |
|
rg_log("repo_update: repo_id=" . $new['repo_id'] |
|
224 |
|
. ", name=[" . $new['name'] . "]" |
|
225 |
|
. ", max_commit_size=" . $new['max_commit_size'] |
|
226 |
|
. ", desc=[" . $new['desc'] . "]" |
|
227 |
|
. ", default_rights=" . $new['default_rights']); |
|
228 |
|
|
|
229 |
|
if (rg_repo_ok($new['name']) === FALSE) |
|
230 |
|
return FALSE; |
| 192 |
231 |
|
|
| 193 |
232 |
// First, test if it already exists |
// First, test if it already exists |
| 194 |
|
$ri = repo_info($db, 0, $name); |
|
|
233 |
|
$ri = rg_repo_info($db, 0, $new['name']); |
| 195 |
234 |
if ($ri['ok'] != 1) |
if ($ri['ok'] != 1) |
| 196 |
235 |
return FALSE; |
return FALSE; |
| 197 |
|
if (($ri['exists'] == 1) && ($ri['repo_id'] != $repo_id)) { |
|
| 198 |
|
gg_repo_set_error("Name already taken."); |
|
|
236 |
|
if (($ri['exists'] == 1) && ($ri['repo_id'] != $new['repo_id'])) { |
|
237 |
|
rg_repo_set_error("Name already taken."); |
| 199 |
238 |
return FALSE; |
return FALSE; |
| 200 |
239 |
} |
} |
| 201 |
240 |
|
|
| 202 |
|
// Second, test if we repo_id is valid |
|
| 203 |
|
$ri = repo_info($db, $repo_id, ""); |
|
|
241 |
|
// Second, test if repo_id is valid |
|
242 |
|
$ri = rg_repo_info($db, $new['repo_id'], ""); |
| 204 |
243 |
if ($ri['ok'] != 1) |
if ($ri['ok'] != 1) |
| 205 |
244 |
return FALSE; |
return FALSE; |
| 206 |
245 |
if ($ri['exists'] == 0) { |
if ($ri['exists'] == 0) { |
| 207 |
|
gg_repo_set_error("Repo $repo_id does not eists."); |
|
|
246 |
|
rg_repo_set_error("Repo " . $new['repo_id'] . " does not exists."); |
| 208 |
247 |
return FALSE; |
return FALSE; |
| 209 |
248 |
} |
} |
| 210 |
249 |
|
|
| 211 |
|
// XSS protection |
|
| 212 |
|
$name = gg_xss($name); |
|
| 213 |
|
$desc = gg_xss($desc); |
|
|
250 |
|
// XSS protection - TODO: move this to the caller! |
|
251 |
|
$new['name'] = rg_xss($new['name']); |
|
252 |
|
$new['desc'] = rg_xss($new['desc']); |
| 214 |
253 |
|
|
| 215 |
|
$e_name = sql_escape($db, $name); |
|
| 216 |
|
$e_desc = sql_escape($db, $desc); |
|
|
254 |
|
$e_name = rg_sql_escape($db, $new['name']); |
|
255 |
|
$e_desc = rg_sql_escape($db, $new['desc']); |
| 217 |
256 |
|
|
| 218 |
257 |
$sql = "UPDATE repos SET name = '$e_name'" |
$sql = "UPDATE repos SET name = '$e_name'" |
| 219 |
|
. ", max_commit_size = $max_commit_size" |
|
|
258 |
|
. ", max_commit_size = " . $new['max_commit_size'] |
| 220 |
259 |
. ", desc = '$e_desc'" |
. ", desc = '$e_desc'" |
| 221 |
|
. ", default_rights = '$rights'" |
|
| 222 |
|
. " WHERE repo_id = $repo_id"; |
|
| 223 |
|
$res = sql_query($db, $sql); |
|
|
260 |
|
. ", default_rights = '" . $new['default_rights'] . "'" |
|
261 |
|
. " WHERE repo_id = " . $new['repo_id']; |
|
262 |
|
$res = rg_sql_query($db, $sql); |
| 224 |
263 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 225 |
|
gg_repo_set_error("Cannot update (" . sql_error() . ")"); |
|
|
264 |
|
rg_repo_set_error("Cannot update (" . rg_sql_error() . ")"); |
| 226 |
265 |
return FALSE; |
return FALSE; |
| 227 |
266 |
} |
} |
| 228 |
|
sql_free_result($res); |
|
|
267 |
|
rg_sql_free_result($res); |
| 229 |
268 |
|
|
| 230 |
269 |
return TRUE; |
return TRUE; |
| 231 |
270 |
} |
} |
| |
| ... |
... |
function gg_repo_update($db, $repo_id, $gg_uid, $name, $max_commit_size, $desc, |
| 233 |
272 |
/* |
/* |
| 234 |
273 |
* List repositories |
* List repositories |
| 235 |
274 |
*/ |
*/ |
| 236 |
|
function repo_list_query($db, $url, $sql) |
|
|
275 |
|
function rg_repo_list_query($db, $url, $sql) |
| 237 |
276 |
{ |
{ |
| 238 |
|
xlog("repo_list_query: url=$url, sql=$sql..."); |
|
|
277 |
|
rg_log("repo_list_query: url=$url, sql=$sql..."); |
| 239 |
278 |
|
|
| 240 |
|
$res = sql_query($db, $sql); |
|
|
279 |
|
$res = rg_sql_query($db, $sql); |
| 241 |
280 |
if ($res === FALSE) |
if ($res === FALSE) |
| 242 |
281 |
return FALSE; |
return FALSE; |
| 243 |
282 |
|
|
| |
| ... |
... |
function repo_list_query($db, $url, $sql) |
| 251 |
290 |
$ret .= " <th>Disk current/max</th>\n"; |
$ret .= " <th>Disk current/max</th>\n"; |
| 252 |
291 |
$ret .= " <th>Max commit size</th>\n"; |
$ret .= " <th>Max commit size</th>\n"; |
| 253 |
292 |
$ret .= "</tr>\n"; |
$ret .= "</tr>\n"; |
| 254 |
|
while (($row = sql_fetch_array($res))) { |
|
|
293 |
|
while (($row = rg_sql_fetch_array($res))) { |
| 255 |
294 |
$ret .= "<tr>\n"; |
$ret .= "<tr>\n"; |
| 256 |
|
$ret .= " <td><a href=\"" . $_SERVER['PHP_SELF'] . "?op=10&repo_id=" . $row['repo_id'] . "\">" . $row['name'] . "</a></td>\n"; |
|
|
295 |
|
$_link = rg_re_repopage($row['repo_id'], $row['name']); |
|
296 |
|
$ret .= " <td><a href=\"$_link\">" . $row['name'] . "</a></td>\n"; |
| 257 |
297 |
$ret .= " <td><small>" . nl2br($row['desc']) . "</small></td>\n"; |
$ret .= " <td><small>" . nl2br($row['desc']) . "</small></td>\n"; |
| 258 |
298 |
if ($row['master'] > 0) { |
if ($row['master'] > 0) { |
| 259 |
299 |
$master_repo = "?"; |
$master_repo = "?"; |
| 260 |
|
$_mi = repo_info($db, $row['master'], ""); |
|
|
300 |
|
$_mi = rg_repo_info($db, $row['master'], ""); |
| 261 |
301 |
if ($_mi['exists'] = 1) |
if ($_mi['exists'] = 1) |
| 262 |
302 |
$master_repo = $_mi['name']; |
$master_repo = $_mi['name']; |
| 263 |
303 |
} |
} |
| |
| ... |
... |
function repo_list_query($db, $url, $sql) |
| 265 |
305 |
$ret .= " <td>" . gmdate("Y-m-d H:i:s", $row['itime']) . "</td>\n"; |
$ret .= " <td>" . gmdate("Y-m-d H:i:s", $row['itime']) . "</td>\n"; |
| 266 |
306 |
|
|
| 267 |
307 |
// rights |
// rights |
| 268 |
|
$_r = implode(", ", gg_repo_rights_text($row['default_rights'])); |
|
|
308 |
|
$_r = implode(", ", rg_repo_rights_text($row['default_rights'])); |
| 269 |
309 |
$ret .= " <td>" . $_r . "</td>\n"; |
$ret .= " <td>" . $_r . "</td>\n"; |
| 270 |
310 |
|
|
| 271 |
311 |
$_max = "ulimited"; |
$_max = "ulimited"; |
| 272 |
312 |
if ($row['disk_quota_mb'] > 0) |
if ($row['disk_quota_mb'] > 0) |
| 273 |
|
$_max = gg_1024($row['disk_quota_mb']); |
|
|
313 |
|
$_max = rg_1024($row['disk_quota_mb']); |
| 274 |
314 |
$ret .= " <td>" . $row['disk_mb'] . "/" . $_max . "</td>\n"; |
$ret .= " <td>" . $row['disk_mb'] . "/" . $_max . "</td>\n"; |
| 275 |
315 |
|
|
| 276 |
316 |
$_v = "ulimited"; |
$_v = "ulimited"; |
| 277 |
317 |
if ($row['max_commit_size'] > 0) |
if ($row['max_commit_size'] > 0) |
| 278 |
|
$_v = gg_1024($row['max_commit_size']); |
|
|
318 |
|
$_v = rg_1024($row['max_commit_size']); |
| 279 |
319 |
$ret .= " <td>" . $_v . "</td>\n"; |
$ret .= " <td>" . $_v . "</td>\n"; |
| 280 |
320 |
|
|
| 281 |
321 |
$ret .= "</tr>\n"; |
$ret .= "</tr>\n"; |
| 282 |
322 |
} |
} |
| 283 |
323 |
$ret .= "</table>\n"; |
$ret .= "</table>\n"; |
| 284 |
|
sql_free_result($res); |
|
|
324 |
|
rg_sql_free_result($res); |
| 285 |
325 |
|
|
| 286 |
326 |
return $ret; |
return $ret; |
| 287 |
327 |
} |
} |
| |
| ... |
... |
function repo_list_query($db, $url, $sql) |
| 289 |
329 |
/* |
/* |
| 290 |
330 |
* |
* |
| 291 |
331 |
*/ |
*/ |
| 292 |
|
function repo_list($db, $url, $uid) |
|
|
332 |
|
function rg_repo_list($db, $url, $rg_ui) |
| 293 |
333 |
{ |
{ |
| 294 |
|
xlog("repo_list: url=$url, uid=$uid..."); |
|
|
334 |
|
rg_log("repo_list: url=$url, rg_uid=" . $rg_ui['uid']); |
| 295 |
335 |
|
|
| 296 |
336 |
$add = ""; |
$add = ""; |
| 297 |
|
if ($uid > 0) |
|
| 298 |
|
$add = " AND uid = $uid"; |
|
|
337 |
|
if ($rg_ui['uid'] > 0) |
|
338 |
|
$add = " AND uid = " . $rg_ui['uid']; |
| 299 |
339 |
|
|
| 300 |
340 |
$sql = "SELECT * FROM repos" |
$sql = "SELECT * FROM repos" |
| 301 |
341 |
. " WHERE deleted = 0" |
. " WHERE deleted = 0" |
| 302 |
342 |
. $add |
. $add |
| 303 |
343 |
. " ORDER BY name"; |
. " ORDER BY name"; |
| 304 |
344 |
|
|
| 305 |
|
return repo_list_query($db, $url, $sql); |
|
|
345 |
|
return rg_repo_list_query($db, $url, $sql); |
| 306 |
346 |
} |
} |
| 307 |
347 |
|
|
| 308 |
348 |
/* |
/* |
| 309 |
349 |
* |
* |
| 310 |
350 |
*/ |
*/ |
| 311 |
|
function repo_search($db, $q, $masters) |
|
|
351 |
|
function rg_repo_search($db, $q, $masters) |
| 312 |
352 |
{ |
{ |
| 313 |
|
xlog("repo_search: q=$q, masters=$masters..."); |
|
|
353 |
|
rg_log("repo_search: q=$q, masters=$masters..."); |
| 314 |
354 |
|
|
| 315 |
355 |
$add = ""; |
$add = ""; |
| 316 |
356 |
if ($masters == 1) |
if ($masters == 1) |
| 317 |
357 |
$add = " AND master = 0"; |
$add = " AND master = 0"; |
| 318 |
358 |
|
|
| 319 |
|
$e_q = sql_escape($db, $q); |
|
|
359 |
|
$e_q = rg_sql_escape($db, $q); |
| 320 |
360 |
|
|
| 321 |
361 |
$sql = "SELECT * FROM repos" |
$sql = "SELECT * FROM repos" |
| 322 |
362 |
. " WHERE deleted = 0" |
. " WHERE deleted = 0" |
| |
| ... |
... |
function repo_search($db, $q, $masters) |
| 325 |
365 |
. " ORDER BY name" |
. " ORDER BY name" |
| 326 |
366 |
. " LIMIT 10"; |
. " LIMIT 10"; |
| 327 |
367 |
|
|
| 328 |
|
return repo_list_query($db, "", $sql); |
|
|
368 |
|
return rg_repo_list_query($db, "", $sql); |
| 329 |
369 |
} |
} |
| 330 |
370 |
|
|
| 331 |
371 |
/* |
/* |
| 332 |
372 |
* Computes the size of a repository |
* Computes the size of a repository |
| 333 |
373 |
*/ |
*/ |
| 334 |
|
function repo_disk_mb($path) |
|
|
374 |
|
function rg_repo_disk_mb($path) |
| 335 |
375 |
{ |
{ |
| 336 |
|
xlog("repo_disk_mb: path=$path..."); |
|
|
376 |
|
rg_log("repo_disk_mb: path=$path..."); |
| 337 |
377 |
|
|
| 338 |
378 |
// TODO |
// TODO |
| 339 |
379 |
|
|
| |
| ... |
... |
function repo_disk_mb($path) |
| 343 |
383 |
/* |
/* |
| 344 |
384 |
* Mark a git repo as done |
* Mark a git repo as done |
| 345 |
385 |
*/ |
*/ |
| 346 |
|
function repo_git_done($db, $repo_id) |
|
|
386 |
|
function rg_repo_git_done($db, $repo_id) |
| 347 |
387 |
{ |
{ |
| 348 |
|
xlog("repo_git_done: repo_id=$repo_id..."); |
|
|
388 |
|
rg_log("repo_git_done: repo_id=$repo_id..."); |
| 349 |
389 |
|
|
| 350 |
390 |
$sql = "UPDATE repos SET git_dir_done = 1" |
$sql = "UPDATE repos SET git_dir_done = 1" |
| 351 |
391 |
. " WHERE repo_id = $repo_id"; |
. " WHERE repo_id = $repo_id"; |
| 352 |
|
$res = sql_query($db, $sql); |
|
|
392 |
|
$res = rg_sql_query($db, $sql); |
| 353 |
393 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 354 |
|
gg_repo_set_error("Cannot query (" . sql_error() . ")"); |
|
|
394 |
|
rg_repo_set_error("Cannot query (" . rg_sql_error() . ")"); |
| 355 |
395 |
return FALSE; |
return FALSE; |
| 356 |
396 |
} |
} |
| 357 |
|
sql_free_result($res); |
|
|
397 |
|
rg_sql_free_result($res); |
| 358 |
398 |
|
|
| 359 |
399 |
return TRUE; |
return TRUE; |
| 360 |
400 |
} |
} |
| |
| ... |
... |
function repo_git_done($db, $repo_id) |
| 365 |
405 |
/* |
/* |
| 366 |
406 |
* Combine two repo rights strings |
* Combine two repo rights strings |
| 367 |
407 |
*/ |
*/ |
| 368 |
|
function gg_repo_rights_combine($a, $b) |
|
|
408 |
|
function rg_repo_rights_combine($a, $b) |
| 369 |
409 |
{ |
{ |
| 370 |
410 |
$len = strlen($b); |
$len = strlen($b); |
| 371 |
411 |
for ($i = 0; $i < $len; $i++) |
for ($i = 0; $i < $len; $i++) |
| |
| ... |
... |
function gg_repo_rights_combine($a, $b) |
| 378 |
418 |
/* |
/* |
| 379 |
419 |
* Get rights for a user |
* Get rights for a user |
| 380 |
420 |
*/ |
*/ |
| 381 |
|
function gg_repo_rights_get($db, $ri, $uid) |
|
|
421 |
|
function rg_repo_rights_get($db, $ri, $uid) |
| 382 |
422 |
{ |
{ |
| 383 |
|
global $gg_repo_rights; |
|
|
423 |
|
global $rg_repo_rights; |
| 384 |
424 |
|
|
| 385 |
|
xlog("gg_repo_rights_get: repo_id=" . $ri['repo_id'] . ", uid=$uid..."); |
|
|
425 |
|
rg_log("rg_repo_rights_get: repo_id=" . $ri['repo_id'] . ", uid=$uid..."); |
| 386 |
426 |
|
|
| 387 |
427 |
$ret = array(); |
$ret = array(); |
| 388 |
428 |
$ret['ok'] = 0; |
$ret['ok'] = 0; |
| |
| ... |
... |
function gg_repo_rights_get($db, $ri, $uid) |
| 390 |
430 |
$ret['rights'] = ""; |
$ret['rights'] = ""; |
| 391 |
431 |
|
|
| 392 |
432 |
$repo_id = $ri['repo_id']; |
$repo_id = $ri['repo_id']; |
| 393 |
|
$dr = $ri['default_rights']; |
|
| 394 |
433 |
|
|
| 395 |
434 |
// Give all rights to owner |
// Give all rights to owner |
|
435 |
|
$dr = $ri['default_rights']; |
| 396 |
436 |
if ($ri['uid'] == $uid) { |
if ($ri['uid'] == $uid) { |
| 397 |
|
foreach ($gg_repo_rights as $letter => $junk) |
|
| 398 |
|
$dr = gg_repo_rights_combine($dr, $letter); |
|
|
437 |
|
foreach ($rg_repo_rights as $letter => $junk) |
|
438 |
|
$dr = rg_repo_rights_combine($dr, $letter); |
| 399 |
439 |
} |
} |
| 400 |
440 |
|
|
| 401 |
441 |
$sql = "SELECT rights FROM repo_rights" |
$sql = "SELECT rights FROM repo_rights" |
| 402 |
442 |
. " WHERE repo_id = $repo_id" |
. " WHERE repo_id = $repo_id" |
| 403 |
443 |
. " AND uid = $uid" |
. " AND uid = $uid" |
| 404 |
444 |
. " LIMIT 1"; |
. " LIMIT 1"; |
| 405 |
|
$res = sql_query($db, $sql); |
|
|
445 |
|
$res = rg_sql_query($db, $sql); |
| 406 |
446 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 407 |
|
gg_repo_set_error("Cannot get info (" . sql_error() . ")!"); |
|
|
447 |
|
rg_repo_set_error("Cannot get info (" . rg_sql_error() . ")!"); |
| 408 |
448 |
return $ret; |
return $ret; |
| 409 |
449 |
} |
} |
| 410 |
450 |
|
|
| 411 |
451 |
$ret['ok'] = 1; |
$ret['ok'] = 1; |
| 412 |
|
$row = sql_fetch_array($res); |
|
| 413 |
|
sql_free_result($res); |
|
|
452 |
|
$row = rg_sql_fetch_array($res); |
|
453 |
|
rg_sql_free_result($res); |
| 414 |
454 |
if (isset($row['rights'])) { |
if (isset($row['rights'])) { |
| 415 |
455 |
$ret['rights'] = $row['rights']; |
$ret['rights'] = $row['rights']; |
| 416 |
456 |
$ret['exists'] = 1; |
$ret['exists'] = 1; |
| 417 |
457 |
} |
} |
| 418 |
458 |
|
|
| 419 |
|
$ret['rights'] = gg_repo_rights_combine($dr, $ret['rights']); |
|
|
459 |
|
$ret['rights'] = rg_repo_rights_combine($dr, $ret['rights']); |
|
460 |
|
rg_log("\tDEBUG rights=" . $ret['rights']); |
| 420 |
461 |
|
|
| 421 |
462 |
return $ret; |
return $ret; |
| 422 |
463 |
} |
} |
| |
| ... |
... |
function gg_repo_rights_get($db, $ri, $uid) |
| 424 |
465 |
/* |
/* |
| 425 |
466 |
* Add rights for a repo |
* Add rights for a repo |
| 426 |
467 |
*/ |
*/ |
| 427 |
|
function gg_repo_rights_set($db, $ri, $uid, $rights) |
|
|
468 |
|
function rg_repo_rights_set($db, $ri, $uid, $rights) |
| 428 |
469 |
{ |
{ |
| 429 |
|
xlog("gg_repo_rights_set: repo_id=" . $ri['repo_id'] |
|
|
470 |
|
rg_log("rg_repo_rights_set: repo_id=" . $ri['repo_id'] |
| 430 |
471 |
. ", uid=$uid, rights=$rights..."); |
. ", uid=$uid, rights=$rights..."); |
| 431 |
472 |
|
|
| 432 |
473 |
$repo_id = $ri['repo_id']; |
$repo_id = $ri['repo_id']; |
| |
| ... |
... |
function gg_repo_rights_set($db, $ri, $uid, $rights) |
| 436 |
477 |
. " WHERE repo_id = $repo_id" |
. " WHERE repo_id = $repo_id" |
| 437 |
478 |
. " AND uid = $uid"; |
. " AND uid = $uid"; |
| 438 |
479 |
} else { |
} else { |
| 439 |
|
$e_rights = sql_escape($db, $rights); |
|
|
480 |
|
$e_rights = rg_sql_escape($db, $rights); |
| 440 |
481 |
|
|
| 441 |
|
$rr = gg_repo_rights_get($db, $ri, $repo_id); |
|
| 442 |
|
if ($rr === FALSE) |
|
|
482 |
|
$rr = rg_repo_rights_get($db, $ri, $uid); |
|
483 |
|
if ($rr === FALSE) |
| 443 |
484 |
return $rr; |
return $rr; |
|
485 |
|
rg_log("rr: " . print_r($rr, TRUE)); |
| 444 |
486 |
|
|
| 445 |
487 |
if ($rr['exists'] == 1) { |
if ($rr['exists'] == 1) { |
| 446 |
488 |
$sql = "UPDATE repo_rights" |
$sql = "UPDATE repo_rights" |
| |
| ... |
... |
function gg_repo_rights_set($db, $ri, $uid, $rights) |
| 457 |
499 |
} |
} |
| 458 |
500 |
} |
} |
| 459 |
501 |
|
|
| 460 |
|
$res = sql_query($db, $sql); |
|
|
502 |
|
$res = rg_sql_query($db, $sql); |
| 461 |
503 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 462 |
|
gg_repo_set_error("Cannot alter rights (" . sql_error() . ")!"); |
|
|
504 |
|
rg_repo_set_error("Cannot alter rights (" . rg_sql_error() . ")!"); |
| 463 |
505 |
return FALSE; |
return FALSE; |
| 464 |
506 |
} |
} |
| 465 |
|
sql_free_result($res); |
|
|
507 |
|
rg_sql_free_result($res); |
| 466 |
508 |
|
|
| 467 |
509 |
return TRUE; |
return TRUE; |
| 468 |
510 |
} |
} |
| |
| ... |
... |
function gg_repo_rights_set($db, $ri, $uid, $rights) |
| 470 |
512 |
/* |
/* |
| 471 |
513 |
* List rights for a repo |
* List rights for a repo |
| 472 |
514 |
*/ |
*/ |
| 473 |
|
function gg_repo_rights_list($db, $repo_id) |
|
|
515 |
|
function rg_repo_rights_list($db, $repo_id, $url) |
| 474 |
516 |
{ |
{ |
| 475 |
|
xlog("gg_repo_rights: repo_id=$repo_id"); |
|
|
517 |
|
rg_log("rg_repo_rights_list: repo_id=$repo_id url=$url"); |
| 476 |
518 |
|
|
| 477 |
519 |
$ret = ""; |
$ret = ""; |
| 478 |
520 |
|
|
| 479 |
521 |
$sql = "SELECT * FROM repo_rights WHERE repo_id = $repo_id"; |
$sql = "SELECT * FROM repo_rights WHERE repo_id = $repo_id"; |
| 480 |
|
$res = sql_query($db, $sql); |
|
|
522 |
|
$res = rg_sql_query($db, $sql); |
| 481 |
523 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 482 |
|
gg_repo_set_error("Cannot get info (" . sql_error() . ")!"); |
|
|
524 |
|
rg_repo_set_error("Cannot get info (" . rg_sql_error() . ")!"); |
| 483 |
525 |
return FALSE; |
return FALSE; |
| 484 |
526 |
} |
} |
| 485 |
527 |
|
|
| |
| ... |
... |
function gg_repo_rights_list($db, $repo_id) |
| 489 |
531 |
$ret .= " <th>Rights</th>\n"; |
$ret .= " <th>Rights</th>\n"; |
| 490 |
532 |
$ret .= " <th>Operations</th>\n"; |
$ret .= " <th>Operations</th>\n"; |
| 491 |
533 |
$ret .= "</tr>\n"; |
$ret .= "</tr>\n"; |
| 492 |
|
while (($row = sql_fetch_array($res))) { |
|
|
534 |
|
while (($row = rg_sql_fetch_array($res))) { |
| 493 |
535 |
$ret .= "<tr>\n"; |
$ret .= "<tr>\n"; |
| 494 |
536 |
|
|
| 495 |
537 |
$_u = $row['uid']; |
$_u = $row['uid']; |
| 496 |
|
$_ui = user_info($db, $row['uid'], "", ""); |
|
|
538 |
|
$_ui = rg_user_info($db, $row['uid'], "", ""); |
| 497 |
539 |
if ($_ui['exists'] == 1) |
if ($_ui['exists'] == 1) |
| 498 |
540 |
$_u = $_ui['user']; |
$_u = $_ui['user']; |
| 499 |
541 |
|
|
| 500 |
542 |
$ret .= " <td>" . $_u . "</td>\n"; |
$ret .= " <td>" . $_u . "</td>\n"; |
| 501 |
543 |
|
|
| 502 |
|
$_r = gg_repo_rights_text($row['rights']); |
|
|
544 |
|
$_r = rg_repo_rights_text($row['rights']); |
| 503 |
545 |
$_r = implode("<br />\n", $_r); |
$_r = implode("<br />\n", $_r); |
| 504 |
546 |
$ret .= " <td>" . $_r . "</td>\n"; |
$ret .= " <td>" . $_r . "</td>\n"; |
| 505 |
547 |
|
|
| 506 |
548 |
// operations |
// operations |
| 507 |
|
// suspend |
|
|
549 |
|
// remove |
| 508 |
550 |
$ret .= " <td>"; |
$ret .= " <td>"; |
| 509 |
|
/*TODO |
|
| 510 |
|
$_url = $url . "&xuid=" . $row['uid']; |
|
| 511 |
|
$v = 1; $t = "Suspend"; |
|
| 512 |
|
if ($row['suspended'] > 0) { |
|
| 513 |
|
$t = "Unsuspend"; |
|
| 514 |
|
$v = 0; |
|
| 515 |
|
} |
|
| 516 |
|
$ret .= "[<a href=\"$_url&suspend=$v\">$t</a>]"; |
|
| 517 |
|
// admin |
|
| 518 |
|
$v = 1; $t = "Admin"; |
|
| 519 |
|
if ($row['is_admin'] == 1) { |
|
| 520 |
|
$t = "Remove admin"; |
|
| 521 |
|
$v = 0; |
|
| 522 |
|
} |
|
| 523 |
|
$ret .= "[<a href=\"$_url&admin=$v\">$t</a>]"; |
|
| 524 |
|
*/ |
|
|
551 |
|
$_url = $url . "&subop=2"; |
|
552 |
|
$v = $row['uid']; |
|
553 |
|
$ret .= "[<a href=\"$_url&remove_uid=$v\">Remove</a>]"; |
| 525 |
554 |
$ret .= " </td>"; |
$ret .= " </td>"; |
| 526 |
555 |
$ret .= "</tr>\n"; |
$ret .= "</tr>\n"; |
| 527 |
556 |
} |
} |
| 528 |
557 |
$ret .= "</table>\n"; |
$ret .= "</table>\n"; |
| 529 |
|
sql_free_result($res); |
|
|
558 |
|
rg_sql_free_result($res); |
| 530 |
559 |
|
|
| 531 |
560 |
return $ret; |
return $ret; |
| 532 |
561 |
} |
} |
| |
| ... |
... |
function gg_repo_rights_list($db, $repo_id) |
| 534 |
563 |
/* |
/* |
| 535 |
564 |
* Rights -> form |
* Rights -> form |
| 536 |
565 |
*/ |
*/ |
| 537 |
|
function gg_repo_rights_checkboxes($def_rights) |
|
|
566 |
|
function rg_repo_rights_checkboxes($def_rights) |
| 538 |
567 |
{ |
{ |
| 539 |
|
global $gg_repo_rights; |
|
|
568 |
|
global $rg_repo_rights; |
| 540 |
569 |
|
|
| 541 |
570 |
$ret = ""; |
$ret = ""; |
| 542 |
|
foreach ($gg_repo_rights as $right => $info) { |
|
|
571 |
|
foreach ($rg_repo_rights as $right => $info) { |
| 543 |
572 |
$add = ""; |
$add = ""; |
| 544 |
573 |
if (strstr($def_rights, $right)) |
if (strstr($def_rights, $right)) |
| 545 |
574 |
$add = " checked"; |
$add = " checked"; |
| |
| ... |
... |
function gg_repo_rights_checkboxes($def_rights) |
| 553 |
582 |
/* |
/* |
| 554 |
583 |
* List rights as text |
* List rights as text |
| 555 |
584 |
*/ |
*/ |
| 556 |
|
function gg_repo_rights_text($rights) |
|
|
585 |
|
function rg_repo_rights_text($rights) |
| 557 |
586 |
{ |
{ |
| 558 |
|
global $gg_repo_rights; |
|
|
587 |
|
global $rg_repo_rights; |
| 559 |
588 |
|
|
| 560 |
589 |
$ret = array(); |
$ret = array(); |
| 561 |
590 |
|
|
| |
| ... |
... |
function gg_repo_rights_text($rights) |
| 564 |
593 |
return array("None"); |
return array("None"); |
| 565 |
594 |
|
|
| 566 |
595 |
for ($i = 0; $i < $len; $i++) { |
for ($i = 0; $i < $len; $i++) { |
| 567 |
|
if (isset($gg_repo_rights[$rights[$i]])) |
|
| 568 |
|
$ret[] = $gg_repo_rights[$rights[$i]]; |
|
|
596 |
|
if (isset($rg_repo_rights[$rights[$i]])) |
|
597 |
|
$ret[] = $rg_repo_rights[$rights[$i]]; |
| 569 |
598 |
else |
else |
| 570 |
599 |
$ret[] = "?" . $rights[$i] . "?"; |
$ret[] = "?" . $rights[$i] . "?"; |
| 571 |
600 |
} |
} |
| |
| ... |
... |
function gg_repo_rights_text($rights) |
| 576 |
605 |
/* |
/* |
| 577 |
606 |
* Transforms rights array into a string |
* Transforms rights array into a string |
| 578 |
607 |
*/ |
*/ |
| 579 |
|
function gg_repo_rights_a2s($a) |
|
|
608 |
|
function rg_repo_rights_a2s($a) |
| 580 |
609 |
{ |
{ |
| 581 |
610 |
$rights = ""; |
$rights = ""; |
| 582 |
611 |
|
|
| File inc/repo/repo_page.php changed (mode: 100644) (index a7f40ec..9fb21c7) |
| 1 |
1 |
<?php |
<?php |
| 2 |
|
xlog("/inc/repo/repo_page.php"); |
|
| 3 |
|
|
|
| 4 |
|
$repo_id = @intval($_REQUEST['repo_id']); |
|
| 5 |
|
|
|
| 6 |
|
$subop = @intval($_REQUEST['subop']); |
|
| 7 |
|
$name = @$_REQUEST['name']; |
|
| 8 |
|
$max_commit_size = @intval($_REQUEST['max_commit_size']); |
|
| 9 |
|
$desc = @$_REQUEST['desc']; |
|
| 10 |
|
$rights = @$_REQUEST['rights']; |
|
| 11 |
|
$rights = gg_repo_rights_a2s($rights); |
|
| 12 |
|
$user = @gg_user_fix($_REQUEST['user']); |
|
|
2 |
|
rg_log("/inc/repo/repo_page.php"); |
|
3 |
|
|
|
4 |
|
$repo = rg_var_str("repo"); |
|
5 |
|
$repo_id = rg_var_uint("repo_id"); |
|
6 |
|
$name = rg_var_str("name"); |
|
7 |
|
$max_commit_size = rg_var_uint("max_commit_size"); |
|
8 |
|
$desc = rg_var_str("desc"); |
|
9 |
|
$rights = @rg_repo_rights_a2s($_REQUEST['rights']); |
|
10 |
|
$user = rg_user_fix(rg_var_str("user")); |
| 13 |
11 |
$master_repo_id = 0; |
$master_repo_id = 0; |
| 14 |
12 |
|
|
| 15 |
13 |
// menu |
// menu |
| 16 |
|
$_url = $_SERVER['PHP_SELF'] . "?op=$op&repo_id=$repo_id"; |
|
|
14 |
|
$_url = rg_re_repopage($repo_id, $repo); |
| 17 |
15 |
$_menu = ""; |
$_menu = ""; |
| 18 |
16 |
$_menu .= "[<a href=\"$_url&subop=1\">Edit</a>]"; |
$_menu .= "[<a href=\"$_url&subop=1\">Edit</a>]"; |
| 19 |
17 |
$_menu .= " [<a href=\"$_url&subop=2\">Rights</a>]"; |
$_menu .= " [<a href=\"$_url&subop=2\">Rights</a>]"; |
| |
| ... |
... |
$_menu .= "<br />\n"; |
| 23 |
21 |
|
|
| 24 |
22 |
$_body = ""; |
$_body = ""; |
| 25 |
23 |
|
|
| 26 |
|
$ri = repo_info($db, $repo_id, ""); |
|
|
24 |
|
$ri = rg_repo_info($db, $repo_id, $repo); |
| 27 |
25 |
if (($ri['ok'] != 1) || ($ri['deleted'] == 1)) { |
if (($ri['ok'] != 1) || ($ri['deleted'] == 1)) { |
| 28 |
26 |
$_body .= "Invalid repository!"; |
$_body .= "Invalid repository!"; |
| 29 |
27 |
// force subop 0 |
// force subop 0 |
| 30 |
28 |
$subop = 0; |
$subop = 0; |
| 31 |
29 |
} |
} |
|
30 |
|
// we need it in forms |
|
31 |
|
$repo_id = $ri['repo_id']; |
| 32 |
32 |
|
|
| 33 |
|
$_body .= "Repo <b>" . $ri['name'] . "</b><br />\n"; |
|
| 34 |
|
if (!empty($ri['desc'])) |
|
| 35 |
|
$_body .= "<small>" . $ri['desc'] . "</small><br />\n"; |
|
| 36 |
|
$_dr = gg_repo_rights_text($ri['default_rights']); |
|
| 37 |
|
$_body .= "Default rights: " . implode(", ", $_dr) . "<br /><br />\n"; |
|
| 38 |
|
$_body .= "Maxim commit size: " . gg_1024($ri['max_commit_size']) . "<br />\n"; |
|
| 39 |
|
$_body .= "<br />\n"; |
|
| 40 |
|
|
|
|
33 |
|
$show_repo_info = 1; |
| 41 |
34 |
switch ($subop) { |
switch ($subop) { |
| 42 |
35 |
case 1: // edit |
case 1: // edit |
| 43 |
36 |
if ($doit == 1) { |
if ($doit == 1) { |
| 44 |
|
$_r = gg_repo_update($db, $repo_id, $gg_uid, $name, |
|
| 45 |
|
$max_commit_size, $desc, $rights); |
|
| 46 |
|
if ($_r === FALSE) |
|
| 47 |
|
$_body .= gg_repo_error(); |
|
| 48 |
|
else |
|
|
37 |
|
while (1) { |
|
38 |
|
if (rg_repo_allow($db, $ri, $rg_ui, "A") === FALSE) { |
|
39 |
|
$_body .= "Not allowed!<br />\n"; |
|
40 |
|
break; |
|
41 |
|
} |
|
42 |
|
|
|
43 |
|
$ri['name'] = $name; // TODO: filter name! |
|
44 |
|
$ri['max_commit_size'] = $max_commit_size; |
|
45 |
|
$ri['desc'] = $desc; // TODO: filter |
|
46 |
|
$ri['default_rights'] = $rights; // TODO: filter |
|
47 |
|
$_r = rg_repo_update($db, $ri); |
|
48 |
|
if ($_r === FALSE) { |
|
49 |
|
$_body .= rg_repo_error(); |
|
50 |
|
break; |
|
51 |
|
} |
|
52 |
|
|
| 49 |
53 |
$_body .= "OK!"; |
$_body .= "OK!"; |
|
54 |
|
break; |
|
55 |
|
} |
| 50 |
56 |
} else { |
} else { |
| 51 |
57 |
// load variables |
// load variables |
| 52 |
58 |
$name = $ri['name']; |
$name = $ri['name']; |
| |
| ... |
... |
case 1: // edit |
| 61 |
67 |
break; |
break; |
| 62 |
68 |
|
|
| 63 |
69 |
case 2: // rights |
case 2: // rights |
| 64 |
|
$errmsg = ""; |
|
| 65 |
|
$_errors = 0; |
|
|
70 |
|
$errmsg = array(); |
|
71 |
|
|
|
72 |
|
$remove_uid = rg_var_uint("remove_uid"); |
|
73 |
|
rg_log("\tDEBUG remove_uid=$remove_uid"); |
|
74 |
|
|
|
75 |
|
if ($remove_uid + $doit > 0) { |
|
76 |
|
if (rg_repo_allow($db, $ri, $rg_ui, "A") === FALSE) { |
|
77 |
|
$errmsg[] = "Not allowed!"; |
|
78 |
|
// cancel further checking |
|
79 |
|
$doit = 0; |
|
80 |
|
$remove_uid = 0; |
|
81 |
|
} |
|
82 |
|
} |
|
83 |
|
|
|
84 |
|
while ($remove_uid > 0) { |
|
85 |
|
$e = rg_repo_rights_set($db, $ri, $remove_uid, ""); |
|
86 |
|
if ($e === FALSE) { |
|
87 |
|
$errmsg[] = rg_repo_error(); |
|
88 |
|
break; |
|
89 |
|
} |
|
90 |
|
|
|
91 |
|
break; |
|
92 |
|
} |
| 66 |
93 |
|
|
| 67 |
94 |
while ($doit == 1) { |
while ($doit == 1) { |
| 68 |
95 |
// lookup user |
// lookup user |
| 69 |
|
$_ui = user_info($db, 0, $user, ""); |
|
|
96 |
|
$_ui = rg_user_info($db, 0, $user, ""); |
| 70 |
97 |
if ($_ui['exists'] != 1) { |
if ($_ui['exists'] != 1) { |
| 71 |
|
$errmsg .= "User does not exists!"; |
|
| 72 |
|
$_errors++; |
|
|
98 |
|
$errmsg[] = "User <b>$user</b> does not exists!"; |
| 73 |
99 |
break; |
break; |
| 74 |
100 |
} |
} |
| 75 |
101 |
|
|
| 76 |
|
// TODO: Check if user is allowed to give rights |
|
| 77 |
|
|
|
| 78 |
|
$e = gg_repo_rights_set($db, $ri, $_ui['uid'], $rights); |
|
|
102 |
|
$e = rg_repo_rights_set($db, $ri, $_ui['uid'], $rights); |
| 79 |
103 |
if ($e === FALSE) { |
if ($e === FALSE) { |
| 80 |
|
$errmsg .= gg_repo_error(); |
|
| 81 |
|
$_errors++; |
|
|
104 |
|
$errmsg[] = rg_repo_error(); |
| 82 |
105 |
break; |
break; |
| 83 |
106 |
} |
} |
| 84 |
107 |
|
|
| |
| ... |
... |
case 2: // rights |
| 86 |
109 |
} |
} |
| 87 |
110 |
|
|
| 88 |
111 |
// list rights |
// list rights |
| 89 |
|
$_body .= gg_repo_rights_list($db, $repo_id); |
|
|
112 |
|
$_url = rg_re_repopage($ri['repo_id'], $ri['name']); |
|
113 |
|
$_body .= rg_repo_rights_list($db, $repo_id, $_url); |
| 90 |
114 |
|
|
| 91 |
|
// give rights form |
|
| 92 |
115 |
$_body .= "<br />\n"; |
$_body .= "<br />\n"; |
| 93 |
116 |
|
|
| 94 |
117 |
include($INC . "/repo/rights.form.php"); |
include($INC . "/repo/rights.form.php"); |
| 95 |
118 |
$_body .= $_form; |
$_body .= $_form; |
| 96 |
119 |
break; |
break; |
| 97 |
120 |
|
|
| 98 |
|
case 3: //delete |
|
| 99 |
|
$r = gg_repo_delete($db, $repo_id, $gg_uid); |
|
| 100 |
|
if ($r === FALSE) { |
|
| 101 |
|
$_body .= "Error: " . gg_repo_error(); |
|
|
121 |
|
case 3: // delete |
|
122 |
|
$errmsg = array(); |
|
123 |
|
|
|
124 |
|
while (1) { |
|
125 |
|
if (rg_repo_allow($db, $ri, $rg_ui, "A") === FALSE) { |
|
126 |
|
$errmsg[] = "Not allowed!"; |
|
127 |
|
break; |
|
128 |
|
} |
|
129 |
|
|
|
130 |
|
$r = rg_repo_delete($db, $repo_id, $rg_ui); |
|
131 |
|
if ($r === FALSE) { |
|
132 |
|
$errmsg[] = "Error: " . rg_repo_error(); |
|
133 |
|
break; |
|
134 |
|
} |
|
135 |
|
|
|
136 |
|
break; |
|
137 |
|
} |
|
138 |
|
|
|
139 |
|
$_err = implode("<br />\n", $errmsg); |
|
140 |
|
if (!empty($_err)) { |
|
141 |
|
$_body .= $_err; |
| 102 |
142 |
} else { |
} else { |
| 103 |
|
$_body .= "OK!"; |
|
|
143 |
|
$_body .= "OK"; |
|
144 |
|
$show_repo_info = 0; |
| 104 |
145 |
} |
} |
| 105 |
146 |
|
|
| 106 |
147 |
break; |
break; |
| 107 |
148 |
} |
} |
| 108 |
149 |
|
|
| 109 |
|
$_repo = $_menu . $_body; |
|
|
150 |
|
$_rt = ""; |
|
151 |
|
if ($show_repo_info == 1) { |
|
152 |
|
$_rt = "Repo <b>" . $ri['name'] . "</b><br />\n"; |
|
153 |
|
if (!empty($ri['desc'])) |
|
154 |
|
$_rt .= "<small>" . $ri['desc'] . "</small><br />\n"; |
|
155 |
|
$_rt .= "<br />\n"; |
|
156 |
|
$_dr = rg_repo_rights_text($ri['default_rights']); |
|
157 |
|
$_rt .= "Default rights: " . implode(", ", $_dr) . "<br />\n"; |
|
158 |
|
$_rt .= "Maxim commit size: " . rg_1024($ri['max_commit_size']) . "<br />\n"; |
|
159 |
|
$_rt .= "Git URL: git://" . $_SERVER['HTTP_HOST'] . "/" . $ri['name'] . ".git<br />\n"; |
|
160 |
|
$_rt .= "<br />\n"; |
|
161 |
|
} |
|
162 |
|
|
|
163 |
|
$_repo = $_menu . $_rt . $_body; |
| 110 |
164 |
?> |
?> |
| File inc/user.inc.php changed (mode: 100644) (index 4fd43cb..eea1ece) |
| 1 |
1 |
<?php |
<?php |
| 2 |
2 |
require_once($INC . "/util.inc.php"); |
require_once($INC . "/util.inc.php"); |
| 3 |
|
require_once($INC . "/xlog.inc.php"); |
|
|
3 |
|
require_once($INC . "/log.inc.php"); |
| 4 |
4 |
require_once($INC . "/db.inc.php"); |
require_once($INC . "/db.inc.php"); |
| 5 |
5 |
require_once($INC . "/sess.inc.php"); |
require_once($INC . "/sess.inc.php"); |
| 6 |
6 |
|
|
| 7 |
|
function gg_user_set_error($str) |
|
|
7 |
|
function rg_user_set_error($str) |
| 8 |
8 |
{ |
{ |
| 9 |
|
global $_gg_user_error; |
|
|
9 |
|
global $_rg_user_error; |
| 10 |
10 |
|
|
| 11 |
|
xlog("\tError: $str"); |
|
| 12 |
|
$_gg_user_error = $str; |
|
|
11 |
|
rg_log("\tError: $str"); |
|
12 |
|
$_rg_user_error = $str; |
| 13 |
13 |
} |
} |
| 14 |
14 |
|
|
| 15 |
|
function gg_user_error() |
|
|
15 |
|
function rg_user_error() |
| 16 |
16 |
{ |
{ |
| 17 |
|
global $_gg_user_error; |
|
| 18 |
|
return $_gg_user_error; |
|
|
17 |
|
global $_rg_user_error; |
|
18 |
|
return $_rg_user_error; |
|
19 |
|
} |
|
20 |
|
|
|
21 |
|
/* |
|
22 |
|
* Returns true if the user is ok |
|
23 |
|
*/ |
|
24 |
|
function rg_user_ok($user) |
|
25 |
|
{ |
|
26 |
|
global $rg_user_allow; |
|
27 |
|
global $rg_user_max_len; |
|
28 |
|
|
|
29 |
|
if (rg_chars_allow($user, $rg_user_allow) === FALSE) { |
|
30 |
|
rg_user_set_error("Invalid user name"); |
|
31 |
|
return FALSE; |
|
32 |
|
} |
|
33 |
|
|
|
34 |
|
if (strlen($user) > $rg_user_max_len) { |
|
35 |
|
rg_user_set_error("User name too long"); |
|
36 |
|
return FALSE; |
|
37 |
|
} |
|
38 |
|
|
|
39 |
|
return TRUE; |
| 19 |
40 |
} |
} |
| 20 |
41 |
|
|
| 21 |
42 |
/* |
/* |
| 22 |
43 |
* Add a user |
* Add a user |
| 23 |
44 |
*/ |
*/ |
| 24 |
|
function user_add($db, $user, $pass, $email, $is_admin) |
|
|
45 |
|
function rg_user_add($db, $user, $pass, $email, $is_admin) |
| 25 |
46 |
{ |
{ |
| 26 |
|
global $gg_session_time; |
|
|
47 |
|
global $rg_session_time; |
| 27 |
48 |
|
|
| 28 |
|
xlog("user_add: user=$user, pass=$pass, email=$email, is_admin=$is_admin..."); |
|
|
49 |
|
rg_log("user_add: user=$user, pass=$pass, email=$email, is_admin=$is_admin..."); |
|
50 |
|
|
|
51 |
|
if (rg_user_ok($user) === FALSE) |
|
52 |
|
return FALSE; |
| 29 |
53 |
|
|
| 30 |
54 |
$itime = time(); |
$itime = time(); |
| 31 |
|
$e_salt = gg_id(40); |
|
|
55 |
|
$e_salt = rg_id(40); |
| 32 |
56 |
$e_sha1pass = sha1($e_salt . "===" . $pass); |
$e_sha1pass = sha1($e_salt . "===" . $pass); |
| 33 |
|
$session_time = $gg_session_time; |
|
|
57 |
|
$session_time = $rg_session_time; |
| 34 |
58 |
|
|
| 35 |
|
$e_user = sql_escape($db, $user); |
|
| 36 |
|
$e_email = sql_escape($db, $email); |
|
|
59 |
|
$e_user = rg_sql_escape($db, $user); |
|
60 |
|
$e_email = rg_sql_escape($db, $email); |
| 37 |
61 |
|
|
| 38 |
62 |
$sql = "INSERT INTO users (user, salt, pass, email, itime, is_admin, session_time)" |
$sql = "INSERT INTO users (user, salt, pass, email, itime, is_admin, session_time)" |
| 39 |
63 |
. " VALUES ('$e_user', '$e_salt', '$e_sha1pass', '$e_email'" |
. " VALUES ('$e_user', '$e_salt', '$e_sha1pass', '$e_email'" |
| 40 |
64 |
. ", $itime, $is_admin, $session_time)"; |
. ", $itime, $is_admin, $session_time)"; |
| 41 |
|
$res = sql_query($db, $sql); |
|
|
65 |
|
$res = rg_sql_query($db, $sql); |
| 42 |
66 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 43 |
|
gg_user_set_error("Cannot insert user (" . sql_error() . ")!"); |
|
|
67 |
|
rg_user_set_error("Cannot insert user (" . rg_sql_error() . ")!"); |
| 44 |
68 |
return FALSE; |
return FALSE; |
| 45 |
69 |
} |
} |
| 46 |
|
sql_free_result($res); |
|
|
70 |
|
rg_sql_free_result($res); |
| 47 |
71 |
|
|
| 48 |
72 |
return TRUE; |
return TRUE; |
| 49 |
73 |
} |
} |
| |
| ... |
... |
function user_add($db, $user, $pass, $email, $is_admin) |
| 51 |
75 |
/* |
/* |
| 52 |
76 |
* Delete a user |
* Delete a user |
| 53 |
77 |
*/ |
*/ |
| 54 |
|
function user_remove($db, $uid) |
|
|
78 |
|
function rg_user_remove($db, $uid) |
| 55 |
79 |
{ |
{ |
| 56 |
80 |
$uid = sprintf("%u", $uid); |
$uid = sprintf("%u", $uid); |
| 57 |
81 |
|
|
| 58 |
82 |
$sql = "DELETE FROM users WHERE uid = $uid"; |
$sql = "DELETE FROM users WHERE uid = $uid"; |
| 59 |
|
$res = sql_query($db, $sql); |
|
|
83 |
|
$res = rg_sql_query($db, $sql); |
| 60 |
84 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 61 |
|
gg_user_set_error("Cannot remove user $uid (" . sql_error() . ")!"); |
|
|
85 |
|
rg_user_set_error("Cannot remove user $uid (" . rg_sql_error() . ")!"); |
| 62 |
86 |
return FALSE; |
return FALSE; |
| 63 |
87 |
} |
} |
| 64 |
|
sql_free_result($res); |
|
|
88 |
|
rg_sql_free_result($res); |
| 65 |
89 |
|
|
| 66 |
90 |
return TRUE; |
return TRUE; |
| 67 |
91 |
} |
} |
| 68 |
92 |
|
|
| 69 |
93 |
/* |
/* |
| 70 |
|
* Returns info about a user (by uid or user fields) |
|
|
94 |
|
* Returns info about a user (by uid, user or e-mail) |
| 71 |
95 |
*/ |
*/ |
| 72 |
|
function user_info($db, $uid, $user, $email) |
|
|
96 |
|
function rg_user_info($db, $uid, $user, $email) |
| 73 |
97 |
{ |
{ |
| 74 |
|
xlog("user_info: uid=[$uid], user=[$user], email=[$email]..."); |
|
|
98 |
|
rg_log("user_info: uid=[$uid], user=[$user], email=[$email]..."); |
| 75 |
99 |
|
|
| 76 |
100 |
$ret = array(); |
$ret = array(); |
| 77 |
101 |
$ret['ok'] = 0; |
$ret['ok'] = 0; |
| 78 |
102 |
$ret['exists'] = 0; |
$ret['exists'] = 0; |
|
103 |
|
$ret['uid'] = 0; |
|
104 |
|
$ret['is_admin'] = 0; |
| 79 |
105 |
|
|
| 80 |
106 |
if ($uid > 0) { |
if ($uid > 0) { |
| 81 |
107 |
$add = " AND uid = " . sprintf("%u", $uid); |
$add = " AND uid = " . sprintf("%u", $uid); |
| 82 |
108 |
} else if (!empty($user)) { |
} else if (!empty($user)) { |
| 83 |
|
$e_user = sql_escape($db, $user); |
|
|
109 |
|
$e_user = rg_sql_escape($db, $user); |
| 84 |
110 |
$add = " AND user = '$e_user'"; |
$add = " AND user = '$e_user'"; |
| 85 |
111 |
} else if (!empty($email)) { |
} else if (!empty($email)) { |
| 86 |
|
$e_email = sql_escape($db, $email); |
|
|
112 |
|
$e_email = rg_sql_escape($db, $email); |
| 87 |
113 |
$add = " AND email = '$e_email'"; |
$add = " AND email = '$e_email'"; |
| 88 |
114 |
} else { |
} else { |
| 89 |
115 |
return FALSE; |
return FALSE; |
| 90 |
116 |
} |
} |
| 91 |
117 |
|
|
| 92 |
118 |
$sql = "SELECT * FROM users WHERE 1 = 1" . $add; |
$sql = "SELECT * FROM users WHERE 1 = 1" . $add; |
| 93 |
|
$res = sql_query($db, $sql); |
|
|
119 |
|
$res = rg_sql_query($db, $sql); |
| 94 |
120 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 95 |
|
gg_user_set_error("Cannot get info (" . sql_error() . ")!"); |
|
|
121 |
|
rg_user_set_error("Cannot get info (" . rg_sql_error() . ")!"); |
| 96 |
122 |
return $ret; |
return $ret; |
| 97 |
123 |
} |
} |
| 98 |
124 |
|
|
| 99 |
125 |
$ret['ok'] = 1; |
$ret['ok'] = 1; |
| 100 |
|
$row = sql_fetch_array($res); |
|
| 101 |
|
sql_free_result($res); |
|
|
126 |
|
$row = rg_sql_fetch_array($res); |
|
127 |
|
rg_sql_free_result($res); |
| 102 |
128 |
if (!isset($row['user'])) { |
if (!isset($row['user'])) { |
| 103 |
|
gg_user_set_error("User not found!"); |
|
|
129 |
|
rg_user_set_error("User not found!"); |
| 104 |
130 |
return $ret; |
return $ret; |
| 105 |
131 |
} |
} |
| 106 |
132 |
|
|
| 107 |
133 |
$row['ok'] = 1; |
$row['ok'] = 1; |
| 108 |
134 |
$row['exists'] = 1; |
$row['exists'] = 1; |
|
135 |
|
rg_log("\tUser found."); |
| 109 |
136 |
return $row; |
return $row; |
| 110 |
137 |
} |
} |
| 111 |
138 |
|
|
| 112 |
139 |
/* |
/* |
| 113 |
|
* Test if login is OK |
|
|
140 |
|
* Loads rg_ui based on sid, if possible |
| 114 |
141 |
*/ |
*/ |
| 115 |
|
function user_login($db, $sid, &$ui) |
|
|
142 |
|
function rg_user_login_by_sid($db, $sid, &$rg_ui) |
| 116 |
143 |
{ |
{ |
| 117 |
|
xlog("user_login: sid=$sid..."); |
|
|
144 |
|
rg_log("user_login_by_sid: sid=$sid..."); |
| 118 |
145 |
|
|
| 119 |
|
if (($uid = sess_valid($db, $sid))) { |
|
| 120 |
|
$ui = user_info($db, $uid, "", ""); |
|
| 121 |
|
sess_update($db, $sid); |
|
| 122 |
|
return $uid; |
|
| 123 |
|
} |
|
|
146 |
|
// Make sure it is not passed by client |
|
147 |
|
$rg_ui = array(); |
|
148 |
|
$rg_ui['uid'] = 0; |
|
149 |
|
$rg_ui['is_admin'] = 0; |
|
150 |
|
|
|
151 |
|
if (empty($sid)) |
|
152 |
|
return FALSE; |
| 124 |
153 |
|
|
| 125 |
|
xlog("No sid! Try with user..."); |
|
| 126 |
|
$user = @$_REQUEST['user']; |
|
| 127 |
|
$pass = @$_REQUEST['pass']; |
|
| 128 |
|
if (empty($user) || empty($pass)) |
|
|
154 |
|
$uid = rg_sess_valid($db, $sid); |
|
155 |
|
if ($uid == 0) |
| 129 |
156 |
return FALSE; |
return FALSE; |
| 130 |
157 |
|
|
| 131 |
|
$ui = user_info($db, 0, $user, ""); |
|
| 132 |
|
if ($ui['ok'] == 0) { |
|
| 133 |
|
gg_user_set_error("Internal error"); |
|
|
158 |
|
$rg_ui = rg_user_info($db, $uid, "", ""); |
|
159 |
|
if ($rg_ui['exists'] != 1) |
|
160 |
|
rg_user_set_error("Invalid uid!"); |
|
161 |
|
return FALSE; |
|
162 |
|
rg_sess_update($db, $sid); |
|
163 |
|
return TRUE; |
|
164 |
|
} |
|
165 |
|
|
|
166 |
|
/* |
|
167 |
|
* Test if login is OK |
|
168 |
|
*/ |
|
169 |
|
function rg_user_login_by_user_pass($db, $user, $pass, &$rg_ui) |
|
170 |
|
{ |
|
171 |
|
rg_log("user_login: user=$user, pass=$pass..."); |
|
172 |
|
|
|
173 |
|
$rg_ui = array(); |
|
174 |
|
$rg_ui['uid'] = 0; |
|
175 |
|
$rg_ui['is_admin'] = 0; |
|
176 |
|
|
|
177 |
|
if (empty($user) || empty($pass)) { |
|
178 |
|
rg_user_set_error("Invalid user or pass!"); |
| 134 |
179 |
return FALSE; |
return FALSE; |
| 135 |
180 |
} |
} |
| 136 |
181 |
|
|
| 137 |
|
if ($ui['exists'] == 0) { |
|
| 138 |
|
gg_user_set_error("Invalid user or pass!"); |
|
|
182 |
|
$rg_ui = rg_user_info($db, 0, $user, ""); |
|
183 |
|
if ($rg_ui['exists'] != 1) { |
|
184 |
|
rg_user_set_error("Invalid user or pass!"); |
| 139 |
185 |
return FALSE; |
return FALSE; |
| 140 |
186 |
} |
} |
| 141 |
|
xlog("\tui: " . print_r($ui, TRUE)); |
|
|
187 |
|
rg_log("\trg_ui: " . print_r($rg_ui, TRUE)); |
| 142 |
188 |
|
|
| 143 |
|
$sha1pass = sha1($ui['salt'] . "===" . $pass); |
|
| 144 |
|
if (strcmp($sha1pass, $ui['pass']) != 0) { |
|
| 145 |
|
gg_user_set_error("Invalid user or pass!"); |
|
|
189 |
|
$sha1pass = sha1($rg_ui['salt'] . "===" . $pass); |
|
190 |
|
if (strcmp($sha1pass, $rg_ui['pass']) != 0) { |
|
191 |
|
rg_user_set_error("Invalid user or pass!"); |
| 146 |
192 |
return FALSE; |
return FALSE; |
| 147 |
193 |
} |
} |
| 148 |
194 |
|
|
| 149 |
|
$sid = gg_id(40); |
|
| 150 |
|
sess_add($db, $ui['uid'], $sid, $ui['session_time']); |
|
|
195 |
|
$sid = rg_id(40); |
|
196 |
|
rg_sess_add($db, $rg_ui['uid'], $sid, $rg_ui['session_time']); |
| 151 |
197 |
setcookie("sid", $sid, 0); |
setcookie("sid", $sid, 0); |
| 152 |
198 |
|
|
| 153 |
|
return $ui['uid']; |
|
|
199 |
|
return TRUE; |
| 154 |
200 |
} |
} |
| 155 |
201 |
|
|
| 156 |
202 |
/* |
/* |
| 157 |
203 |
* Suspend an account |
* Suspend an account |
| 158 |
204 |
* 1=suspend, 0=unsuspend |
* 1=suspend, 0=unsuspend |
| 159 |
205 |
*/ |
*/ |
| 160 |
|
function user_suspend($db, $uid, $op) |
|
|
206 |
|
function rg_user_suspend($db, $uid, $op) |
| 161 |
207 |
{ |
{ |
| 162 |
|
xlog("user_suspend: uid=$uid, op=$op"); |
|
|
208 |
|
rg_log("user_suspend: uid=$uid, op=$op"); |
| 163 |
209 |
|
|
| 164 |
210 |
$now = time(); |
$now = time(); |
| 165 |
211 |
|
|
| |
| ... |
... |
function user_suspend($db, $uid, $op) |
| 169 |
215 |
$v = 0; |
$v = 0; |
| 170 |
216 |
|
|
| 171 |
217 |
$sql = "UPDATE users SET suspended = $v WHERE uid = $uid"; |
$sql = "UPDATE users SET suspended = $v WHERE uid = $uid"; |
| 172 |
|
$res = sql_query($db, $sql); |
|
|
218 |
|
$res = rg_sql_query($db, $sql); |
| 173 |
219 |
if ($res === FALSE) |
if ($res === FALSE) |
| 174 |
220 |
return FALSE; |
return FALSE; |
| 175 |
|
sql_free_result($res); |
|
|
221 |
|
rg_sql_free_result($res); |
| 176 |
222 |
|
|
| 177 |
223 |
return TRUE; |
return TRUE; |
| 178 |
224 |
} |
} |
| |
| ... |
... |
function user_suspend($db, $uid, $op) |
| 181 |
227 |
* Make/remove admin |
* Make/remove admin |
| 182 |
228 |
* 1=make, 0=remove |
* 1=make, 0=remove |
| 183 |
229 |
*/ |
*/ |
| 184 |
|
function user_admin($db, $uid, $op) |
|
|
230 |
|
function rg_user_admin($db, $uid, $op) |
| 185 |
231 |
{ |
{ |
| 186 |
|
xlog("user_admin: uid=$uid, op=$op"); |
|
|
232 |
|
rg_log("user_admin: uid=$uid, op=$op"); |
| 187 |
233 |
|
|
| 188 |
234 |
$now = time(); |
$now = time(); |
| 189 |
235 |
|
|
| 190 |
236 |
$sql = "UPDATE users SET is_admin = $op WHERE uid = $uid"; |
$sql = "UPDATE users SET is_admin = $op WHERE uid = $uid"; |
| 191 |
|
$res = sql_query($db, $sql); |
|
|
237 |
|
$res = rg_sql_query($db, $sql); |
| 192 |
238 |
if ($res === FALSE) |
if ($res === FALSE) |
| 193 |
239 |
return FALSE; |
return FALSE; |
| 194 |
|
sql_free_result($res); |
|
|
240 |
|
rg_sql_free_result($res); |
| 195 |
241 |
|
|
| 196 |
242 |
return TRUE; |
return TRUE; |
| 197 |
243 |
} |
} |
| |
| ... |
... |
function user_admin($db, $uid, $op) |
| 199 |
245 |
/* |
/* |
| 200 |
246 |
* List users |
* List users |
| 201 |
247 |
*/ |
*/ |
| 202 |
|
function user_list($db, $url) |
|
|
248 |
|
function rg_user_list($db, $url) |
| 203 |
249 |
{ |
{ |
| 204 |
|
xlog("user_list, url=$url..."); |
|
|
250 |
|
rg_log("user_list, url=$url..."); |
| 205 |
251 |
|
|
| 206 |
252 |
$ret = ""; |
$ret = ""; |
| 207 |
253 |
|
|
| 208 |
|
$xuid = sprintf("%u", @$_REQUEST['xuid']); |
|
|
254 |
|
$xuid = rg_var_uint("xuid"); |
| 209 |
255 |
|
|
| 210 |
|
if (isset($_REQUEST['suspend'])) { |
|
| 211 |
|
if (!user_suspend($db, $xuid, $_REQUEST['suspend'])) |
|
|
256 |
|
$suspend = rg_var_uint("suspend"); |
|
257 |
|
if ($suspend == 1) { |
|
258 |
|
if (!rg_user_suspend($db, $xuid, 1)) |
| 212 |
259 |
$ret .= "<font color=red>Cannot suspend!</font><br />"; |
$ret .= "<font color=red>Cannot suspend!</font><br />"; |
| 213 |
260 |
} |
} |
| 214 |
261 |
|
|
| 215 |
|
if (isset($_REQUEST['admin'])) { |
|
| 216 |
|
if (!user_admin($db, $xuid, $_REQUEST['admin'])) |
|
|
262 |
|
$unsuspend = rg_var_uint("unsuspend"); |
|
263 |
|
if ($unsuspend == 1) { |
|
264 |
|
if (!rg_user_suspend($db, $xuid, 0)) |
|
265 |
|
$ret .= "<font color=red>Cannot unsuspend!</font><br />"; |
|
266 |
|
} |
|
267 |
|
|
|
268 |
|
$make_admin = rg_var_uint("make_admin"); |
|
269 |
|
if ($make_admin == 1) { |
|
270 |
|
if (!rg_user_admin($db, $xuid, 1)) |
| 217 |
271 |
$ret .= "<font color=red>Cannot make admin!</font><br />"; |
$ret .= "<font color=red>Cannot make admin!</font><br />"; |
| 218 |
272 |
} |
} |
| 219 |
273 |
|
|
| 220 |
|
if (isset($_REQUEST['remove'])) { |
|
| 221 |
|
if (!user_remove($db, $xuid)) |
|
|
274 |
|
$remove_admin = rg_var_uint("remove_admin"); |
|
275 |
|
if ($remove_admin == 1) { |
|
276 |
|
if (!rg_user_admin($db, $xuid, 0)) |
|
277 |
|
$ret .= "<font color=red>Cannot remove admin!</font><br />"; |
|
278 |
|
} |
|
279 |
|
|
|
280 |
|
$remove = rg_var_uint("remove"); |
|
281 |
|
if ($remove > 0) { |
|
282 |
|
if (!rg_user_remove($db, $xuid)) |
| 222 |
283 |
$ret .= "<font color=red>Cannot remove!</font><br />"; |
$ret .= "<font color=red>Cannot remove!</font><br />"; |
| 223 |
284 |
} |
} |
| 224 |
285 |
|
|
| 225 |
286 |
$sql = "SELECT * FROM users ORDER BY user"; |
$sql = "SELECT * FROM users ORDER BY user"; |
| 226 |
|
$res = sql_query($db, $sql); |
|
|
287 |
|
$res = rg_sql_query($db, $sql); |
| 227 |
288 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 228 |
|
gg_user_set_error("Cannot get info (" . sql_error() . ")!"); |
|
|
289 |
|
rg_user_set_error("Cannot get info (" . rg_sql_error() . ")!"); |
| 229 |
290 |
return FALSE; |
return FALSE; |
| 230 |
291 |
} |
} |
| 231 |
292 |
|
|
| |
| ... |
... |
function user_list($db, $url) |
| 241 |
302 |
$ret .= " <th>Last seen (UTC)</th>\n"; |
$ret .= " <th>Last seen (UTC)</th>\n"; |
| 242 |
303 |
$ret .= " <th>Operations</th>\n"; |
$ret .= " <th>Operations</th>\n"; |
| 243 |
304 |
$ret .= "</tr>\n"; |
$ret .= "</tr>\n"; |
| 244 |
|
while (($row = sql_fetch_array($res))) { |
|
|
305 |
|
while (($row = rg_sql_fetch_array($res))) { |
| 245 |
306 |
$ret .= "<tr>\n"; |
$ret .= "<tr>\n"; |
| 246 |
307 |
$ret .= " <td>" . $row['user'] . "</td>\n"; |
$ret .= " <td>" . $row['user'] . "</td>\n"; |
| 247 |
308 |
$ret .= " <td>" . $row['email'] . "</td>\n"; |
$ret .= " <td>" . $row['email'] . "</td>\n"; |
| |
| ... |
... |
function user_list($db, $url) |
| 249 |
310 |
$ret .= " <td>" . gmdate("Y-m-d H:i:s", $row['itime']) . "</td>\n"; |
$ret .= " <td>" . gmdate("Y-m-d H:i:s", $row['itime']) . "</td>\n"; |
| 250 |
311 |
$_v = "unlimited"; |
$_v = "unlimited"; |
| 251 |
312 |
if ($row['disk_quota_mb'] > 0) |
if ($row['disk_quota_mb'] > 0) |
| 252 |
|
$_v = gg_1024($row['disk_quota_mb']); |
|
|
313 |
|
$_v = rg_1024($row['disk_quota_mb']); |
| 253 |
314 |
$ret .= " <td>" . $_v . "</td>\n"; |
$ret .= " <td>" . $_v . "</td>\n"; |
| 254 |
315 |
$ret .= " <td>" . ($row['suspended'] == 0 ? "No" : "Yes") . "</th>\n"; |
$ret .= " <td>" . ($row['suspended'] == 0 ? "No" : "Yes") . "</th>\n"; |
| 255 |
316 |
$ret .= " <td>" . $row['session_time'] . "s</td>\n"; |
$ret .= " <td>" . $row['session_time'] . "s</td>\n"; |
| |
| ... |
... |
function user_list($db, $url) |
| 258 |
319 |
// suspend |
// suspend |
| 259 |
320 |
$ret .= " <td>"; |
$ret .= " <td>"; |
| 260 |
321 |
$_url = $url . "&xuid=" . $row['uid']; |
$_url = $url . "&xuid=" . $row['uid']; |
| 261 |
|
$v = 1; $t = "Suspend"; |
|
|
322 |
|
$v = "suspend=1"; $t = "Suspend"; |
| 262 |
323 |
if ($row['suspended'] > 0) { |
if ($row['suspended'] > 0) { |
| 263 |
324 |
$t = "Unsuspend"; |
$t = "Unsuspend"; |
| 264 |
|
$v = 0; |
|
|
325 |
|
$v = "unsuspend=1"; |
| 265 |
326 |
} |
} |
| 266 |
|
$ret .= "[<a href=\"$_url&suspend=$v\">$t</a>]"; |
|
|
327 |
|
$ret .= "[<a href=\"$_url&$v\">$t</a>]"; |
| 267 |
328 |
// admin |
// admin |
| 268 |
|
$v = 1; $t = "Admin"; |
|
|
329 |
|
$v = "make_admin=1"; $t = "Make admin"; |
| 269 |
330 |
if ($row['is_admin'] == 1) { |
if ($row['is_admin'] == 1) { |
| 270 |
331 |
$t = "Remove admin"; |
$t = "Remove admin"; |
| 271 |
|
$v = 0; |
|
|
332 |
|
$v = "remove_admin=1"; |
| 272 |
333 |
} |
} |
| 273 |
|
$ret .= "[<a href=\"$_url&admin=$v\">$t</a>]"; |
|
|
334 |
|
$ret .= "[<a href=\"$_url&$v\">$t</a>]"; |
| 274 |
335 |
// remove |
// remove |
| 275 |
336 |
if ($row['suspended'] > 0) |
if ($row['suspended'] > 0) |
| 276 |
337 |
$ret .= "[<a href=\"$_url&remove=1\">Remove!</a>]"; |
$ret .= "[<a href=\"$_url&remove=1\">Remove!</a>]"; |
| |
| ... |
... |
function user_list($db, $url) |
| 278 |
339 |
$ret .= "</tr>\n"; |
$ret .= "</tr>\n"; |
| 279 |
340 |
} |
} |
| 280 |
341 |
$ret .= "</table>\n"; |
$ret .= "</table>\n"; |
| 281 |
|
sql_free_result($res); |
|
|
342 |
|
rg_sql_free_result($res); |
| 282 |
343 |
|
|
| 283 |
344 |
return $ret; |
return $ret; |
| 284 |
345 |
} |
} |
| |
| ... |
... |
function user_list($db, $url) |
| 286 |
347 |
/* |
/* |
| 287 |
348 |
* Returns uid by token, if not expired |
* Returns uid by token, if not expired |
| 288 |
349 |
*/ |
*/ |
| 289 |
|
function user_forgot_pass_uid($db, $token) |
|
|
350 |
|
function rg_user_forgot_pass_uid($db, $token) |
| 290 |
351 |
{ |
{ |
| 291 |
352 |
$ret = array(); |
$ret = array(); |
| 292 |
353 |
$ret['ok'] = 0; |
$ret['ok'] = 0; |
| 293 |
354 |
$ret['uid'] = 0; |
$ret['uid'] = 0; |
| 294 |
355 |
|
|
| 295 |
|
xlog("user_forgot_pass_uid: token=$token"); |
|
|
356 |
|
rg_log("user_forgot_pass_uid: token=$token"); |
| 296 |
357 |
|
|
| 297 |
358 |
$now = time(); |
$now = time(); |
| 298 |
|
$e_token = sql_escape($db, $token); |
|
|
359 |
|
$e_token = rg_sql_escape($db, $token); |
| 299 |
360 |
|
|
| 300 |
361 |
$sql = "SELECT uid FROM forgot_pass" |
$sql = "SELECT uid FROM forgot_pass" |
| 301 |
362 |
. " WHERE token = '$e_token'" |
. " WHERE token = '$e_token'" |
| 302 |
363 |
. " AND expire > $now"; |
. " AND expire > $now"; |
| 303 |
|
$res = sql_query($db, $sql); |
|
|
364 |
|
$res = rg_sql_query($db, $sql); |
| 304 |
365 |
if ($res === FALSE) |
if ($res === FALSE) |
| 305 |
366 |
return $ret; |
return $ret; |
| 306 |
367 |
|
|
| 307 |
368 |
$ret['ok'] = 1; |
$ret['ok'] = 1; |
| 308 |
369 |
|
|
| 309 |
|
$row = sql_fetch_array($res); |
|
| 310 |
|
sql_free_result($res); |
|
|
370 |
|
$row = rg_sql_fetch_array($res); |
|
371 |
|
rg_sql_free_result($res); |
| 311 |
372 |
if (!isset($row['uid'])) |
if (!isset($row['uid'])) |
| 312 |
373 |
return $ret; |
return $ret; |
| 313 |
374 |
|
|
| |
| ... |
... |
function user_forgot_pass_uid($db, $token) |
| 319 |
380 |
/* |
/* |
| 320 |
381 |
* Reset password function (send mail) |
* Reset password function (send mail) |
| 321 |
382 |
*/ |
*/ |
| 322 |
|
function user_forgot_pass_mail($db, $email) |
|
|
383 |
|
function rg_user_forgot_pass_mail($db, $email) |
| 323 |
384 |
{ |
{ |
| 324 |
|
xlog("user_forgot_pass_mail: email=$email"); |
|
|
385 |
|
rg_log("user_forgot_pass_mail: email=$email"); |
| 325 |
386 |
|
|
| 326 |
387 |
$expire = time() + 24 * 3600; |
$expire = time() + 24 * 3600; |
| 327 |
|
$token = gg_id(40); |
|
|
388 |
|
$token = rg_id(40); |
| 328 |
389 |
|
|
| 329 |
|
$r = user_info($db, 0, "", $email); |
|
|
390 |
|
$r = rg_user_info($db, 0, "", $email); |
| 330 |
391 |
if ($r['ok'] == 0) |
if ($r['ok'] == 0) |
| 331 |
392 |
return FALSE; |
return FALSE; |
| 332 |
393 |
if ($r['exists'] == 0) |
if ($r['exists'] == 0) |
| |
| ... |
... |
function user_forgot_pass_mail($db, $email) |
| 336 |
397 |
// store token in database |
// store token in database |
| 337 |
398 |
$sql = "INSERT INTO forgot_pass (token, uid, expire)" |
$sql = "INSERT INTO forgot_pass (token, uid, expire)" |
| 338 |
399 |
. " VALUES ('$token', $uid, $expire)"; |
. " VALUES ('$token', $uid, $expire)"; |
| 339 |
|
$res = sql_query($db, $sql); |
|
|
400 |
|
$res = rg_sql_query($db, $sql); |
| 340 |
401 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 341 |
|
gg_user_set_error("Cannot query!"); |
|
|
402 |
|
rg_user_set_error("Cannot query!"); |
| 342 |
403 |
return FALSE; |
return FALSE; |
| 343 |
404 |
} |
} |
| 344 |
|
sql_free_result($res); |
|
|
405 |
|
rg_sql_free_result($res); |
| 345 |
406 |
|
|
| 346 |
407 |
if (!mail($email, "Forgot password", |
if (!mail($email, "Forgot password", |
| 347 |
408 |
"Hello!\nIf you want to reset the password, follow:\n" |
"Hello!\nIf you want to reset the password, follow:\n" |
| 348 |
409 |
. "http://" . $_SERVER['SERVER_NAME'] . "/" . $_SERVER['PHP_SELF'] . "?op=6&token=$token")) { |
. "http://" . $_SERVER['SERVER_NAME'] . "/" . $_SERVER['PHP_SELF'] . "?op=6&token=$token")) { |
| 349 |
|
gg_user_set_error("Cannot send mail!"); |
|
|
410 |
|
rg_user_set_error("Cannot send mail!"); |
| 350 |
411 |
return FALSE; |
return FALSE; |
| 351 |
412 |
} |
} |
| 352 |
413 |
|
|
| |
| ... |
... |
function user_forgot_pass_mail($db, $email) |
| 356 |
417 |
/* |
/* |
| 357 |
418 |
* After reseting the pass, we have to destroy all 'reset pass' requests |
* After reseting the pass, we have to destroy all 'reset pass' requests |
| 358 |
419 |
*/ |
*/ |
| 359 |
|
function user_forgot_pass_destroy($db, $uid) |
|
|
420 |
|
function rg_user_forgot_pass_destroy($db, $uid) |
| 360 |
421 |
{ |
{ |
| 361 |
|
xlog("user_forgot_pass_destroy: token=$token"); |
|
|
422 |
|
rg_log("user_forgot_pass_destroy: token=$token"); |
| 362 |
423 |
|
|
| 363 |
424 |
$sql = "DELETE FROM forgot_pass WHERE uid = $uid"; |
$sql = "DELETE FROM forgot_pass WHERE uid = $uid"; |
| 364 |
|
$res = sql_query($db, $sql); |
|
|
425 |
|
$res = rg_sql_query($db, $sql); |
| 365 |
426 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 366 |
|
gg_user_set_error("Cannot query!"); |
|
|
427 |
|
rg_user_set_error("Cannot query!"); |
| 367 |
428 |
return FALSE; |
return FALSE; |
| 368 |
429 |
} |
} |
| 369 |
|
sql_free_result($res); |
|
|
430 |
|
rg_sql_free_result($res); |
| 370 |
431 |
|
|
| 371 |
432 |
return TRUE; |
return TRUE; |
| 372 |
433 |
} |
} |
| 373 |
434 |
|
|
| 374 |
|
function user_set_pass($db, $uid, $pass) |
|
|
435 |
|
function rg_user_set_pass($db, $uid, $pass) |
| 375 |
436 |
{ |
{ |
| 376 |
|
xlog("user_set_pass..."); |
|
|
437 |
|
rg_log("user_set_pass..."); |
| 377 |
438 |
|
|
| 378 |
|
$e_salt = gg_id(40); |
|
|
439 |
|
$e_salt = rg_id(40); |
| 379 |
440 |
$e_sha1pass = sha1($e_salt . "===" . $pass); |
$e_sha1pass = sha1($e_salt . "===" . $pass); |
| 380 |
441 |
|
|
| 381 |
442 |
$sql = "UPDATE users SET" |
$sql = "UPDATE users SET" |
| 382 |
443 |
." salt = '$e_salt'" |
." salt = '$e_salt'" |
| 383 |
444 |
. ", pass = '$e_sha1pass'" |
. ", pass = '$e_sha1pass'" |
| 384 |
445 |
. " WHERE uid = " . $uid; |
. " WHERE uid = " . $uid; |
| 385 |
|
$res = sql_query($db, $sql); |
|
|
446 |
|
$res = rg_sql_query($db, $sql); |
| 386 |
447 |
if ($res === FALSE) |
if ($res === FALSE) |
| 387 |
448 |
return FALSE; |
return FALSE; |
| 388 |
|
sql_free_result($res); |
|
|
449 |
|
rg_sql_free_result($res); |
| 389 |
450 |
|
|
| 390 |
451 |
return TRUE; |
return TRUE; |
| 391 |
452 |
} |
} |
| 392 |
453 |
|
|
| 393 |
|
/* |
|
| 394 |
|
* Remove forbidden chars |
|
| 395 |
|
*/ |
|
| 396 |
|
function gg_user_fix($user) |
|
| 397 |
|
{ |
|
| 398 |
|
return preg_replace("/[^A-Za-z0-9_.-]/", "", $user); |
|
| 399 |
|
} |
|
| 400 |
|
|
|
| 401 |
454 |
?> |
?> |
| File root/index.php changed (mode: 100644) (index 4c64719..33792ef) |
| 1 |
1 |
<?php |
<?php |
| 2 |
2 |
error_reporting(E_ALL); |
error_reporting(E_ALL); |
|
3 |
|
//phpinfo(); |
| 3 |
4 |
|
|
| 4 |
5 |
$_s = microtime(TRUE); |
$_s = microtime(TRUE); |
| 5 |
6 |
|
|
| |
| ... |
... |
$ROOT = dirname(__FILE__); |
| 8 |
9 |
|
|
| 9 |
10 |
$THEME = $ROOT . "/themes/default"; |
$THEME = $ROOT . "/themes/default"; |
| 10 |
11 |
|
|
| 11 |
|
require_once("/etc/gg/config.php"); |
|
| 12 |
|
require_once($INC . "/xlog.inc.php"); |
|
|
12 |
|
require_once("/etc/rg/config.php"); |
|
13 |
|
require_once($INC . "/log.inc.php"); |
| 13 |
14 |
include_once($INC . "/db.inc.php"); |
include_once($INC . "/db.inc.php"); |
| 14 |
15 |
include_once($INC . "/user.inc.php"); |
include_once($INC . "/user.inc.php"); |
| 15 |
16 |
include_once($INC . "/repo.inc.php"); |
include_once($INC . "/repo.inc.php"); |
| 16 |
17 |
include_once($INC . "/keys.inc.php"); |
include_once($INC . "/keys.inc.php"); |
| 17 |
18 |
|
|
| 18 |
|
xlog_set_file("/tmp/gg_web.log"); |
|
|
19 |
|
rg_log_set_file("/tmp/rg_web.log"); |
| 19 |
20 |
|
|
| 20 |
|
$sql_debug = $gg_db_debug; |
|
|
21 |
|
$rg_sql_debug = $rg_db_debug; |
| 21 |
22 |
|
|
| 22 |
|
$op = 0; |
|
| 23 |
|
if (isset($_REQUEST['op'])) |
|
| 24 |
|
$op = intval($_REQUEST['op']); |
|
| 25 |
|
$doit = @intval($_REQUEST['doit']); |
|
| 26 |
|
$sid = @$_COOKIE['sid']; |
|
| 27 |
|
if (empty($sid)) |
|
| 28 |
|
$sid = @$_REQUEST['sid']; |
|
|
23 |
|
// TODO: make subop and subsubop as strings |
|
24 |
|
$op = rg_var_str("op"); |
|
25 |
|
$subop = rg_var_uint("subop"); |
|
26 |
|
$subsubop = rg_var_uint("subsubop"); |
|
27 |
|
$doit = rg_var_uint("doit"); |
|
28 |
|
$sid = rg_var_str("sid"); |
| 29 |
29 |
|
|
| 30 |
|
xlog("IP: " . @$_SERVER['REMOTE_ADDR']); |
|
| 31 |
|
xlog("_REQUEST: " . print_r($_REQUEST, TRUE)); |
|
| 32 |
|
xlog("_COOKIE: " . print_r($_COOKIE, TRUE)); |
|
| 33 |
|
xlog("Start! op=$op, doit=$doit, sid=$sid..."); |
|
|
30 |
|
rg_log("IP: " . @$_SERVER['REMOTE_ADDR']); |
|
31 |
|
rg_log("_REQUEST: " . trim(print_r($_REQUEST, TRUE))); |
|
32 |
|
rg_log("_COOKIE: " . trim(print_r($_COOKIE, TRUE))); |
|
33 |
|
rg_log("Start! op=$op/$subop/$subsubop, doit=$doit, sid=$sid..."); |
| 34 |
34 |
|
|
| 35 |
35 |
|
|
| 36 |
36 |
$head = ""; |
$head = ""; |
| |
| ... |
... |
$head .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"" |
| 38 |
38 |
. " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
. " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
| 39 |
39 |
$head .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"; |
$head .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"; |
| 40 |
40 |
$head .= "<head>\n"; |
$head .= "<head>\n"; |
| 41 |
|
$head .= " <title>GG</title>\n"; |
|
|
41 |
|
$head .= " <title>RocketGit</title>\n"; |
| 42 |
42 |
$head .= " <meta content=\"text/html; charset=UTF-8\" http-equiv=\"content-type\" />\n"; |
$head .= " <meta content=\"text/html; charset=UTF-8\" http-equiv=\"content-type\" />\n"; |
| 43 |
43 |
$css = preg_replace("/\n/", " ", @file_get_contents($THEME . "/main.css")); |
$css = preg_replace("/\n/", " ", @file_get_contents($THEME . "/main.css")); |
| 44 |
44 |
$head .= " <style type=\"text/css\">" . $css . "</style>\n"; |
$head .= " <style type=\"text/css\">" . $css . "</style>\n"; |
| |
| ... |
... |
$head .= "<body>\n"; |
| 47 |
47 |
|
|
| 48 |
48 |
|
|
| 49 |
49 |
// database connection |
// database connection |
| 50 |
|
$db = sql_open($gg_db); |
|
|
50 |
|
$db = rg_sql_open($rg_db); |
| 51 |
51 |
if ($db === FALSE) |
if ($db === FALSE) |
| 52 |
52 |
die("Cannot open database!"); |
die("Cannot open database!"); |
| 53 |
53 |
|
|
| 54 |
|
// deal with login |
|
| 55 |
|
$gg_uid = user_login($db, $sid, $gg_ui); |
|
| 56 |
|
if (($op == 1) && ($doit == 1) && ($gg_uid > 0)) |
|
| 57 |
|
$op = 0; |
|
|
54 |
|
rg_user_login_by_sid($db, $sid, $rg_ui); |
|
55 |
|
rg_log("After login_by_sid, rg_ui=" . print_r($rg_ui, TRUE)); |
| 58 |
56 |
|
|
| 59 |
|
// deal with logout |
|
| 60 |
|
if ($op == 9) { |
|
| 61 |
|
sess_destroy($db, $sid); |
|
| 62 |
|
$gg_uid = 0; |
|
| 63 |
|
$gg_ui = FALSE; |
|
| 64 |
|
} |
|
|
57 |
|
$body = ""; |
|
58 |
|
// Chain dispatching |
|
59 |
|
do { |
|
60 |
|
include($INC . "/dispatch/dispatch.php"); |
|
61 |
|
} while (strcmp($op, "") != 0); |
| 65 |
62 |
|
|
| 66 |
|
// auto-login user by forgot-pass token |
|
| 67 |
|
if ($op == 6) { |
|
| 68 |
|
// TODO |
|
| 69 |
|
} |
|
|
63 |
|
$tail = "</body>\n"; |
|
64 |
|
$tail .= "</html>\n"; |
| 70 |
65 |
|
|
| 71 |
|
// menu |
|
| 72 |
|
$url = $_SERVER['PHP_SELF'] . "?a=1"; |
|
| 73 |
|
$menu = ""; |
|
| 74 |
|
$menu .= "[<a href=\"$url&op=1\">Login</a>]"; |
|
| 75 |
|
if (isset($gg_ui['user'])) { |
|
| 76 |
|
$menu .= " [<a href=\"$url&op=4\">Keys</a>]\n"; |
|
| 77 |
|
$menu .= " [<a href=\"$url&op=2\">My repositories</a>]\n"; |
|
| 78 |
|
if ($gg_ui['is_admin'] == 1) |
|
| 79 |
|
$menu .= " [<a href=\"$url&op=3\">Admin</a>]\n"; |
|
| 80 |
66 |
|
|
| 81 |
|
$menu .= " [<a href=\"$url&op=9\">Logout</a>]\n"; |
|
|
67 |
|
// menu |
|
68 |
|
$amenu = array( |
|
69 |
|
"login" => array("text" => "Login"), |
|
70 |
|
"repo" => array("text" => "My repositories"), |
|
71 |
|
"keys" => array("text" => "SSH keys"), |
|
72 |
|
"admin" => array("text" => "Admin", "needs_admin" => 1), |
|
73 |
|
"logout" => array("text" => "Logout") |
|
74 |
|
); |
| 82 |
75 |
|
|
| 83 |
|
$menu .= " [" . $gg_ui['user'] . "]\n"; |
|
|
76 |
|
$menu = ""; |
|
77 |
|
$add = ""; |
|
78 |
|
foreach ($amenu as $_op => $_info) { |
|
79 |
|
if (isset($_info['needs_admin']) && ($rg_ui['is_admin'] == 0)) |
|
80 |
|
continue; |
|
81 |
|
|
|
82 |
|
$_text = $_info['text']; |
|
83 |
|
if (strcmp($_op, $op) == 0) { |
|
84 |
|
$menu .= $add . "[$_text]\n"; |
|
85 |
|
} else { |
|
86 |
|
$menu .= $add . "[<a href=\"" |
|
87 |
|
. rg_re_url($_op) . "\">$_text</a>]\n"; |
|
88 |
|
} |
|
89 |
|
$add = " "; |
| 84 |
90 |
} |
} |
| 85 |
|
$menu .= "<br />\n"; |
|
| 86 |
|
|
|
| 87 |
91 |
|
|
| 88 |
|
$body = ""; |
|
| 89 |
|
switch ($op) { |
|
| 90 |
|
case 1: |
|
| 91 |
|
include($INC . "/login/login.php"); |
|
| 92 |
|
$body .= $_login; |
|
| 93 |
|
break; |
|
| 94 |
|
|
|
| 95 |
|
case 2: |
|
| 96 |
|
include($INC . "/repo/repo.php"); |
|
| 97 |
|
$body .= $_repo; |
|
| 98 |
|
break; |
|
| 99 |
|
|
|
| 100 |
|
case 3: |
|
| 101 |
|
include($INC . "/admin/admin.php"); |
|
| 102 |
|
$body .= $_admin; |
|
| 103 |
|
break; |
|
| 104 |
|
|
|
| 105 |
|
case 4: // keys |
|
| 106 |
|
include($INC . "/keys/keys.php"); |
|
| 107 |
|
$body .= $_keys; |
|
| 108 |
|
break; |
|
| 109 |
|
|
|
| 110 |
|
case 6: // forgot pass link |
|
| 111 |
|
include($INC . "/user/forgot.php"); |
|
| 112 |
|
$body .= $_forgot; |
|
| 113 |
|
break; |
|
| 114 |
|
|
|
| 115 |
|
case 7: // forgot pass - send mail |
|
| 116 |
|
include($INC . "/user/forgot_mail.php"); |
|
| 117 |
|
$body .= $_forgot; |
|
| 118 |
|
break; |
|
| 119 |
|
|
|
| 120 |
|
case 10: // repo page |
|
| 121 |
|
include($INC . "/repo/repo_page.php"); |
|
| 122 |
|
$body .= $_repo; |
|
| 123 |
|
break; |
|
| 124 |
|
} |
|
|
92 |
|
if (isset($rg_ui['user'])) |
|
93 |
|
$menu .= " [" . $rg_ui['user'] . "]\n"; |
|
94 |
|
$menu .= "<br />\n"; |
| 125 |
95 |
|
|
| 126 |
|
$body .= "</body>\n"; |
|
| 127 |
|
$body .= "</html>\n"; |
|
| 128 |
96 |
|
|
| 129 |
|
echo $head . $menu . $body; |
|
|
97 |
|
echo $head . $menu . $body . $tail; |
| 130 |
98 |
|
|
| 131 |
99 |
$_diff = sprintf("%u", (microtime(TRUE) - $_s) * 1000); |
$_diff = sprintf("%u", (microtime(TRUE) - $_s) * 1000); |
| 132 |
|
xlog("Done in $_diff ms."); |
|
|
100 |
|
rg_log("Done in $_diff ms."); |
| 133 |
101 |
?> |
?> |
| File scripts/ssh.php changed (mode: 100644) (index c5d1555..06ee476) |
| ... |
... |
ini_set("track_errors", "On"); |
| 5 |
5 |
|
|
| 6 |
6 |
$_start = microtime(TRUE); |
$_start = microtime(TRUE); |
| 7 |
7 |
|
|
| 8 |
|
require_once("/etc/gg/config.php"); |
|
|
8 |
|
require_once("/etc/rg/config.php"); |
| 9 |
9 |
|
|
| 10 |
10 |
$INC = dirname(__FILE__) . "/../inc"; |
$INC = dirname(__FILE__) . "/../inc"; |
| 11 |
11 |
require_once($INC . "/util.inc.php"); |
require_once($INC . "/util.inc.php"); |
| 12 |
|
require_once($INC . "/xlog.inc.php"); |
|
|
12 |
|
require_once($INC . "/log.inc.php"); |
| 13 |
13 |
require_once($INC . "/db.inc.php"); |
require_once($INC . "/db.inc.php"); |
| 14 |
14 |
require_once($INC . "/repo.inc.php"); |
require_once($INC . "/repo.inc.php"); |
| 15 |
15 |
|
|
| 16 |
|
$sql_debug = $gg_db_debug; |
|
|
16 |
|
$rg_sql_debug = $rg_db_debug; |
| 17 |
17 |
|
|
| 18 |
18 |
function fatal($str) |
function fatal($str) |
| 19 |
19 |
{ |
{ |
| 20 |
20 |
global $access_type; |
global $access_type; |
| 21 |
21 |
|
|
| 22 |
|
xlog("Sending error: " . $str); |
|
|
22 |
|
rg_log("Sending error: " . $str); |
| 23 |
23 |
$str2 = "FATAL ERROR: " . $str . "\n"; |
$str2 = "FATAL ERROR: " . $str . "\n"; |
| 24 |
|
if ($access_type == 2) { //git |
|
|
24 |
|
if ($access_type == 2) { // git |
| 25 |
25 |
$str3 = "\n" . $str2; |
$str3 = "\n" . $str2; |
| 26 |
26 |
$len = strlen($str3) + 4; |
$len = strlen($str3) + 4; |
| 27 |
27 |
$str4 = sprintf("%04x", $len) . $str3; |
$str4 = sprintf("%04x", $len) . $str3; |
| |
| ... |
... |
function fatal($str) |
| 32 |
32 |
exit(1); |
exit(1); |
| 33 |
33 |
} |
} |
| 34 |
34 |
|
|
| 35 |
|
xlog("Start: euid=" . posix_geteuid() . "..."); |
|
| 36 |
|
//xlog("_SERVER: " . print_r($_SERVER, TRUE)); |
|
|
35 |
|
rg_log("Start: euid=" . posix_geteuid() . "..."); |
|
36 |
|
//rg_log("_SERVER: " . print_r($_SERVER, TRUE)); |
| 37 |
37 |
|
|
| 38 |
38 |
umask(0022); |
umask(0022); |
| 39 |
39 |
|
|
| 40 |
40 |
if (isset($_SERVER['SSH_CONNECTION'])) { |
if (isset($_SERVER['SSH_CONNECTION'])) { |
| 41 |
|
xlog("SSH connection: " . @$_SERVER['SSH_CONNECTION']); |
|
|
41 |
|
rg_log("SSH connection: " . @$_SERVER['SSH_CONNECTION']); |
| 42 |
42 |
$access_type = 1; |
$access_type = 1; |
| 43 |
43 |
|
|
| 44 |
44 |
// we do not have host info |
// we do not have host info |
| |
| ... |
... |
if (isset($_SERVER['SSH_CONNECTION'])) { |
| 48 |
48 |
$uid = @$_SERVER['argv'][1]; |
$uid = @$_SERVER['argv'][1]; |
| 49 |
49 |
if (empty($uid)) |
if (empty($uid)) |
| 50 |
50 |
fatal("uid not provided!"); |
fatal("uid not provided!"); |
| 51 |
|
xlog("\tuid is $uid."); |
|
|
51 |
|
rg_log("\tuid is $uid."); |
| 52 |
52 |
|
|
| 53 |
53 |
$cmd_repo = trim(@$_SERVER['SSH_ORIGINAL_COMMAND']); |
$cmd_repo = trim(@$_SERVER['SSH_ORIGINAL_COMMAND']); |
| 54 |
54 |
if (empty($cmd_repo)) |
if (empty($cmd_repo)) |
| 55 |
55 |
fatal("No SSH_ORIGINAL_COMMAND provided!"); |
fatal("No SSH_ORIGINAL_COMMAND provided!"); |
| 56 |
56 |
} else { |
} else { |
| 57 |
|
xlog("git-daemon connection..."); |
|
|
57 |
|
rg_log("git-daemon connection..."); |
| 58 |
58 |
$access_type = 2; |
$access_type = 2; |
| 59 |
59 |
|
|
| 60 |
60 |
// we have no client info |
// we have no client info |
| |
| ... |
... |
$repo = trim($repo, "' "); |
| 99 |
99 |
$repo = ltrim($repo, "/"); |
$repo = ltrim($repo, "/"); |
| 100 |
100 |
$repo = preg_replace('/\.git$/' , '', $repo); |
$repo = preg_replace('/\.git$/' , '', $repo); |
| 101 |
101 |
|
|
| 102 |
|
xlog("host=[$host] cmd=[$cmd] repo=[$repo] perms=[$perms]."); |
|
|
102 |
|
rg_log("host=[$host] cmd=[$cmd] repo=[$repo] perms=[$perms]."); |
| 103 |
103 |
|
|
| 104 |
104 |
// validity/security checks |
// validity/security checks |
| 105 |
105 |
if (empty($repo)) |
if (empty($repo)) |
| |
| ... |
... |
if (preg_match('/\.\./', $repo)) |
| 109 |
109 |
if (preg_match('/\//', $repo)) |
if (preg_match('/\//', $repo)) |
| 110 |
110 |
fatal("Repo must not contain [/]!"); |
fatal("Repo must not contain [/]!"); |
| 111 |
111 |
|
|
| 112 |
|
$db = sql_open($gg_db); |
|
|
112 |
|
$db = rg_sql_open($rg_db); |
| 113 |
113 |
if ($db === FALSE) |
if ($db === FALSE) |
| 114 |
114 |
fatal("Internal error (db)!"); |
fatal("Internal error (db)!"); |
| 115 |
115 |
|
|
| 116 |
116 |
// load info about the repository |
// load info about the repository |
| 117 |
|
$ri = repo_info($db, 0, $repo); |
|
|
117 |
|
$ri = rg_repo_info($db, 0, $repo); |
| 118 |
118 |
if ($ri['ok'] != 1) |
if ($ri['ok'] != 1) |
| 119 |
119 |
fatal("Temporary error!"); |
fatal("Temporary error!"); |
| 120 |
120 |
if ($ri['exists'] != 1) |
if ($ri['exists'] != 1) |
| |
| ... |
... |
if ($ri['exists'] != 1) |
| 122 |
122 |
if ($ri['deleted'] == 1) |
if ($ri['deleted'] == 1) |
| 123 |
123 |
fatal("Repo was deleted!"); |
fatal("Repo was deleted!"); |
| 124 |
124 |
|
|
| 125 |
|
if (!repo_allow($db, $ri, $uid, $perms)) |
|
|
125 |
|
if (!rg_repo_allow($db, $ri, $uid, $perms)) |
| 126 |
126 |
fatal("You do not have this type of access to this repository!"); |
fatal("You do not have this type of access to this repository!"); |
| 127 |
127 |
|
|
| 128 |
128 |
// TODO: limit per connection |
// TODO: limit per connection |
| 129 |
129 |
|
|
| 130 |
130 |
// TODO: limit time and/or cpu |
// TODO: limit time and/or cpu |
| 131 |
131 |
|
|
| 132 |
|
$repo_base = repo_id2base($ri['repo_id']); |
|
|
132 |
|
$repo_base = rg_repo_id2base($ri['repo_id']); |
| 133 |
133 |
$repo_path = $repo_base . $repo . ".git"; |
$repo_path = $repo_base . $repo . ".git"; |
| 134 |
|
xlog("repo_path=$repo_path."); |
|
|
134 |
|
rg_log("repo_path=$repo_path."); |
| 135 |
135 |
|
|
| 136 |
136 |
$run = "git-shell -c \"" . $cmd . " '" . escapeshellcmd($repo_path) . "'\""; |
$run = "git-shell -c \"" . $cmd . " '" . escapeshellcmd($repo_path) . "'\""; |
| 137 |
|
xlog("Running [$run]..."); |
|
|
137 |
|
rg_log("Running [$run]..."); |
| 138 |
138 |
passthru($run, $ret); |
passthru($run, $ret); |
| 139 |
|
xlog("[$run] returned $ret."); |
|
|
139 |
|
rg_log("[$run] returned $ret."); |
| 140 |
140 |
|
|
| 141 |
141 |
$diff = sprintf("%u", (microtime(TRUE) - $_start) * 1000); |
$diff = sprintf("%u", (microtime(TRUE) - $_start) * 1000); |
| 142 |
|
xlog("Took " . $diff . "ms."); |
|
|
142 |
|
rg_log("Took " . $diff . "ms."); |
| 143 |
143 |
|
|
| 144 |
|
@file_put_contents($repo_path . "/gg/last_access", |
|
|
144 |
|
@file_put_contents($repo_path . "/rg/last_access", |
| 145 |
145 |
"repo: " . $repo . " ($repo_path)" |
"repo: " . $repo . " ($repo_path)" |
| 146 |
146 |
. "\nat: " . sprintf("%u", $_start) |
. "\nat: " . sprintf("%u", $_start) |
| 147 |
147 |
. "\nuid: " . $uid |
. "\nuid: " . $uid |
| |
| ... |
... |
xlog("Took " . $diff . "ms."); |
| 151 |
151 |
|
|
| 152 |
152 |
// Mark repository dirty for disk statistics and other stuff |
// Mark repository dirty for disk statistics and other stuff |
| 153 |
153 |
if (strcmp($cmd, "git-receive-pack") == 0) |
if (strcmp($cmd, "git-receive-pack") == 0) |
| 154 |
|
@file_put_contents($gg_path . "/dirty", ""); |
|
|
154 |
|
@file_put_contents($rg_path . "/dirty", ""); |
| 155 |
155 |
?> |
?> |