File inc/git.inc.php changed (mode: 100644) (index 4c7d1d2..80497b2) |
1 |
1 |
<?php |
<?php |
2 |
2 |
require_once($INC . "/util.inc.php"); |
require_once($INC . "/util.inc.php"); |
3 |
3 |
require_once($INC . "/log.inc.php"); |
require_once($INC . "/log.inc.php"); |
|
4 |
|
require_once($INC . "/prof.inc.php"); |
4 |
5 |
|
|
5 |
6 |
$rg_git_zero = "0000000000000000000000000000000000000000"; |
$rg_git_zero = "0000000000000000000000000000000000000000"; |
6 |
7 |
|
|
|
... |
... |
function rg_git_install_hooks($dst) |
24 |
25 |
{ |
{ |
25 |
26 |
global $rg_scripts; |
global $rg_scripts; |
26 |
27 |
|
|
|
28 |
|
rg_prof_start("git_install_hooks"); |
|
29 |
|
|
27 |
30 |
rg_log("git_install_hooks: dst=$dst..."); |
rg_log("git_install_hooks: dst=$dst..."); |
28 |
31 |
|
|
29 |
32 |
if (file_exists($dst . "/hooks")) { |
if (file_exists($dst . "/hooks")) { |
|
... |
... |
function rg_git_install_hooks($dst) |
48 |
51 |
return FALSE; |
return FALSE; |
49 |
52 |
} |
} |
50 |
53 |
|
|
|
54 |
|
rg_prof_end("git_install_hooks"); |
|
55 |
|
|
51 |
56 |
return TRUE; |
return TRUE; |
52 |
57 |
} |
} |
53 |
58 |
|
|
54 |
59 |
function rg_git_init($dst) |
function rg_git_init($dst) |
55 |
60 |
{ |
{ |
|
61 |
|
rg_prof_start("git_init"); |
|
62 |
|
|
56 |
63 |
rg_log("git_init: dst=$dst..."); |
rg_log("git_init: dst=$dst..."); |
57 |
64 |
|
|
58 |
65 |
$dir = dirname($dst); |
$dir = dirname($dst); |
|
... |
... |
function rg_git_init($dst) |
81 |
88 |
if (rg_git_install_hooks($dst) !== TRUE) |
if (rg_git_install_hooks($dst) !== TRUE) |
82 |
89 |
return FALSE; |
return FALSE; |
83 |
90 |
|
|
|
91 |
|
rg_prof_end("git_init"); |
|
92 |
|
|
84 |
93 |
return TRUE; |
return TRUE; |
85 |
94 |
} |
} |
86 |
95 |
|
|
87 |
96 |
function rg_git_clone($src, $dst) |
function rg_git_clone($src, $dst) |
88 |
97 |
{ |
{ |
|
98 |
|
rg_prof_start("git_clone"); |
|
99 |
|
|
89 |
100 |
rg_log("git_clone: src=$src, dst=$dst..."); |
rg_log("git_clone: src=$src, dst=$dst..."); |
90 |
101 |
|
|
91 |
102 |
$dir = dirname($dst); |
$dir = dirname($dst); |
|
... |
... |
function rg_git_clone($src, $dst) |
115 |
126 |
if (rg_git_install_hooks($dst) !== TRUE) |
if (rg_git_install_hooks($dst) !== TRUE) |
116 |
127 |
return FALSE; |
return FALSE; |
117 |
128 |
|
|
|
129 |
|
rg_prof_end("git_clone"); |
|
130 |
|
|
118 |
131 |
return TRUE; |
return TRUE; |
119 |
132 |
} |
} |
120 |
133 |
|
|
|
... |
... |
function rg_git_type($obj) |
138 |
151 |
*/ |
*/ |
139 |
152 |
function rg_git_content($obj) |
function rg_git_content($obj) |
140 |
153 |
{ |
{ |
|
154 |
|
rg_prof_start("git_content"); |
|
155 |
|
|
141 |
156 |
$cmd = "git cat-file -p '" . $obj . "'"; |
$cmd = "git cat-file -p '" . $obj . "'"; |
142 |
157 |
$a = rg_exec($cmd); |
$a = rg_exec($cmd); |
143 |
158 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
|
... |
... |
function rg_git_content($obj) |
145 |
160 |
return FALSE; |
return FALSE; |
146 |
161 |
} |
} |
147 |
162 |
|
|
|
163 |
|
rg_prof_end("git_content"); |
|
164 |
|
|
148 |
165 |
return $a['data']; |
return $a['data']; |
149 |
166 |
} |
} |
150 |
167 |
|
|
|
... |
... |
function rg_git_reference($refname) |
171 |
188 |
// TODO: Unit testing |
// TODO: Unit testing |
172 |
189 |
function rg_git_rev_ok($rev) |
function rg_git_rev_ok($rev) |
173 |
190 |
{ |
{ |
|
191 |
|
rg_prof_start("git_rev_ok"); |
|
192 |
|
|
174 |
193 |
$cmd = "git rev-parse --verify --quiet '" . $rev . "'"; |
$cmd = "git rev-parse --verify --quiet '" . $rev . "'"; |
175 |
194 |
$a = rg_exec($cmd); |
$a = rg_exec($cmd); |
176 |
195 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
|
... |
... |
function rg_git_rev_ok($rev) |
178 |
197 |
return FALSE; |
return FALSE; |
179 |
198 |
} |
} |
180 |
199 |
|
|
|
200 |
|
rg_prof_end("git_rev_ok"); |
|
201 |
|
|
181 |
202 |
return TRUE; |
return TRUE; |
182 |
203 |
} |
} |
183 |
204 |
|
|
|
... |
... |
function rg_git_rev_ok($rev) |
187 |
208 |
*/ |
*/ |
188 |
209 |
function rg_git_whitespace_ok($old, $new) |
function rg_git_whitespace_ok($old, $new) |
189 |
210 |
{ |
{ |
|
211 |
|
rg_prof_start("git_whitespace_ok"); |
|
212 |
|
|
190 |
213 |
$cmd = "git diff --check " . $old . " " . $new; |
$cmd = "git diff --check " . $old . " " . $new; |
191 |
214 |
$a = rg_exec($cmd); |
$a = rg_exec($cmd); |
192 |
215 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
|
... |
... |
function rg_git_whitespace_ok($old, $new) |
194 |
217 |
return FALSE; |
return FALSE; |
195 |
218 |
} |
} |
196 |
219 |
|
|
|
220 |
|
rg_prof_end("git_whitespace_ok"); |
|
221 |
|
|
197 |
222 |
return TRUE; |
return TRUE; |
198 |
223 |
} |
} |
199 |
224 |
|
|
200 |
225 |
// TODO: Unit testing |
// TODO: Unit testing |
201 |
226 |
function rg_git_merge_base($old, $new) |
function rg_git_merge_base($old, $new) |
202 |
227 |
{ |
{ |
|
228 |
|
rg_prof_start("git_merge_base"); |
|
229 |
|
|
203 |
230 |
$cmd = "git merge-base " . $old . " " . $new; |
$cmd = "git merge-base " . $old . " " . $new; |
204 |
231 |
$a = rg_exec($cmd); |
$a = rg_exec($cmd); |
205 |
232 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
|
... |
... |
function rg_git_merge_base($old, $new) |
207 |
234 |
return FALSE; |
return FALSE; |
208 |
235 |
} |
} |
209 |
236 |
|
|
|
237 |
|
rg_prof_end("git_merge_base"); |
|
238 |
|
|
210 |
239 |
return trim($a['data']); |
return trim($a['data']); |
211 |
240 |
} |
} |
212 |
241 |
|
|
|
... |
... |
function rg_git_merge_base($old, $new) |
215 |
244 |
*/ |
*/ |
216 |
245 |
function rg_git_ls_tree($tree) |
function rg_git_ls_tree($tree) |
217 |
246 |
{ |
{ |
|
247 |
|
rg_prof_start("git_ls_tree"); |
|
248 |
|
|
218 |
249 |
rg_log("rg_git_ls_tree: tree=$tree"); |
rg_log("rg_git_ls_tree: tree=$tree"); |
219 |
250 |
|
|
220 |
251 |
$ret = array(); |
$ret = array(); |
|
... |
... |
function rg_git_ls_tree($tree) |
247 |
278 |
$ret[] = $_y; |
$ret[] = $_y; |
248 |
279 |
} |
} |
249 |
280 |
|
|
|
281 |
|
rg_prof_end("git_ls_tree"); |
|
282 |
|
|
250 |
283 |
return $ret; |
return $ret; |
251 |
284 |
} |
} |
252 |
285 |
|
|
|
... |
... |
function rg_git_ls_tree($tree) |
255 |
288 |
*/ |
*/ |
256 |
289 |
function rg_git_diff2array($diff) |
function rg_git_diff2array($diff) |
257 |
290 |
{ |
{ |
|
291 |
|
rg_prof_start("git_diff2array"); |
|
292 |
|
|
258 |
293 |
$ret = array(); |
$ret = array(); |
259 |
294 |
|
|
260 |
295 |
$lines = explode("\n", $diff); |
$lines = explode("\n", $diff); |
|
... |
... |
function rg_git_diff2array($diff) |
351 |
386 |
exit(0); |
exit(0); |
352 |
387 |
} |
} |
353 |
388 |
|
|
|
389 |
|
rg_prof_end("git_diff2array"); |
|
390 |
|
|
354 |
391 |
return $ret; |
return $ret; |
355 |
392 |
} |
} |
356 |
393 |
|
|
|
... |
... |
function rg_git_diff2array($diff) |
360 |
397 |
*/ |
*/ |
361 |
398 |
function rg_git_log($max, $from, $to, $also_patch) |
function rg_git_log($max, $from, $to, $also_patch) |
362 |
399 |
{ |
{ |
|
400 |
|
rg_prof_start("git_log"); |
|
401 |
|
|
363 |
402 |
rg_log("git_log: max=$max"); |
rg_log("git_log: max=$max"); |
364 |
403 |
|
|
365 |
404 |
$max_count = ($max == 0) ? "" : " --max-count=$max"; |
$max_count = ($max == 0) ? "" : " --max-count=$max"; |
|
... |
... |
function rg_git_log($max, $from, $to, $also_patch) |
453 |
492 |
$ret[] = $y; |
$ret[] = $y; |
454 |
493 |
} |
} |
455 |
494 |
|
|
|
495 |
|
rg_prof_end("git_log"); |
|
496 |
|
|
456 |
497 |
return $ret; |
return $ret; |
457 |
498 |
} |
} |
458 |
499 |
|
|
File inc/keys.inc.php changed (mode: 100644) (index 301af61..bfda859) |
1 |
1 |
<?php |
<?php |
2 |
2 |
require_once($INC . "/sql.inc.php"); |
require_once($INC . "/sql.inc.php"); |
3 |
3 |
require_once($INC . "/state.inc.php"); |
require_once($INC . "/state.inc.php"); |
|
4 |
|
require_once($INC . "/prof.inc.php"); |
4 |
5 |
|
|
5 |
6 |
$rg_keys_error = ""; |
$rg_keys_error = ""; |
6 |
7 |
|
|
|
... |
... |
function rg_keys_fingerprint($key) |
61 |
62 |
*/ |
*/ |
62 |
63 |
function rg_keys_remove($db, $rg_ui, $key_id) |
function rg_keys_remove($db, $rg_ui, $key_id) |
63 |
64 |
{ |
{ |
|
65 |
|
rg_prof_start("keys_remove"); |
|
66 |
|
|
64 |
67 |
// mark dirty |
// mark dirty |
65 |
68 |
if (rg_state_set($db, "authorized_keys", 1) === FALSE) { |
if (rg_state_set($db, "authorized_keys", 1) === FALSE) { |
66 |
69 |
rg_keys_set_error("Cannot make state dirty (" . rg_state_error() . ")!"); |
rg_keys_set_error("Cannot make state dirty (" . rg_state_error() . ")!"); |
|
... |
... |
function rg_keys_remove($db, $rg_ui, $key_id) |
80 |
83 |
} |
} |
81 |
84 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
82 |
85 |
|
|
|
86 |
|
rg_prof_end("keys_remove"); |
|
87 |
|
|
83 |
88 |
return TRUE; |
return TRUE; |
84 |
89 |
} |
} |
85 |
90 |
|
|
|
... |
... |
function rg_keys_remove($db, $rg_ui, $key_id) |
88 |
93 |
*/ |
*/ |
89 |
94 |
function rg_keys_count($db, $uid) |
function rg_keys_count($db, $uid) |
90 |
95 |
{ |
{ |
|
96 |
|
rg_prof_start("keys_count"); |
|
97 |
|
|
91 |
98 |
$sql = "SELECT COUNT(*) AS count FROM keys WHERE uid = $uid"; |
$sql = "SELECT COUNT(*) AS count FROM keys WHERE uid = $uid"; |
92 |
99 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
93 |
100 |
if ($res === FALSE) { |
if ($res === FALSE) { |
|
... |
... |
function rg_keys_count($db, $uid) |
97 |
104 |
$row = rg_sql_fetch_array($res); |
$row = rg_sql_fetch_array($res); |
98 |
105 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
99 |
106 |
|
|
|
107 |
|
rg_prof_end("keys_count"); |
|
108 |
|
|
100 |
109 |
return $row['count']; |
return $row['count']; |
101 |
110 |
} |
} |
102 |
111 |
|
|
|
... |
... |
function rg_keys_add($db, $rg_ui, $key) |
108 |
117 |
{ |
{ |
109 |
118 |
global $rg_max_ssh_keys; |
global $rg_max_ssh_keys; |
110 |
119 |
|
|
|
120 |
|
rg_prof_start("keys_add"); |
|
121 |
|
|
111 |
122 |
$itime = time(); |
$itime = time(); |
112 |
123 |
$e_key = rg_sql_escape($db, $key); |
$e_key = rg_sql_escape($db, $key); |
113 |
124 |
|
|
|
... |
... |
function rg_keys_add($db, $rg_ui, $key) |
142 |
153 |
} |
} |
143 |
154 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
144 |
155 |
|
|
145 |
|
return rg_sql_last_id($db); |
|
|
156 |
|
$id = rg_sql_last_id($db); |
|
157 |
|
|
|
158 |
|
rg_prof_end("keys_add"); |
|
159 |
|
|
|
160 |
|
return $id; |
146 |
161 |
} |
} |
147 |
162 |
|
|
148 |
163 |
/* |
/* |
|
... |
... |
function rg_keys_regen($db) |
154 |
169 |
global $rg_scripts; |
global $rg_scripts; |
155 |
170 |
global $rg_ssh_paras; |
global $rg_ssh_paras; |
156 |
171 |
|
|
|
172 |
|
rg_prof_start("keys_regen"); |
|
173 |
|
|
157 |
174 |
$dirty = rg_state_get($db, "authorized_keys"); |
$dirty = rg_state_get($db, "authorized_keys"); |
158 |
175 |
if ($dirty == 0) { |
if ($dirty == 0) { |
159 |
176 |
// Skip generation because is not dirty |
// Skip generation because is not dirty |
|
... |
... |
function rg_keys_regen($db) |
215 |
232 |
// mark file as clean |
// mark file as clean |
216 |
233 |
rg_state_set($db, "authorized_keys", 0); |
rg_state_set($db, "authorized_keys", 0); |
217 |
234 |
|
|
|
235 |
|
rg_prof_end("keys_regen"); |
|
236 |
|
|
218 |
237 |
return TRUE; |
return TRUE; |
219 |
238 |
} |
} |
220 |
239 |
|
|
|
... |
... |
function rg_keys_regen($db) |
223 |
242 |
*/ |
*/ |
224 |
243 |
function rg_keys_list($db, $rg_ui, $url) |
function rg_keys_list($db, $rg_ui, $url) |
225 |
244 |
{ |
{ |
|
245 |
|
rg_prof_start("keys_list"); |
|
246 |
|
|
226 |
247 |
rg_log("keys_list: rg_uid=" . $rg_ui['uid'] . ", url=$url..."); |
rg_log("keys_list: rg_uid=" . $rg_ui['uid'] . ", url=$url..."); |
227 |
248 |
|
|
228 |
249 |
$sql = "SELECT * FROM keys WHERE uid = " . $rg_ui['uid']; |
$sql = "SELECT * FROM keys WHERE uid = " . $rg_ui['uid']; |
|
... |
... |
function rg_keys_list($db, $rg_ui, $url) |
254 |
275 |
$ret .= "</div>\n"; |
$ret .= "</div>\n"; |
255 |
276 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
256 |
277 |
|
|
|
278 |
|
rg_prof_end("keys_list"); |
|
279 |
|
|
257 |
280 |
return $ret; |
return $ret; |
258 |
281 |
} |
} |
|
282 |
|
|
259 |
283 |
?> |
?> |
File inc/prof.inc.php changed (mode: 100644) (index a4e8d77..2aab39c) |
2 |
2 |
// Profiling functions |
// Profiling functions |
3 |
3 |
|
|
4 |
4 |
$rg_prof_main = array(); |
$rg_prof_main = array(); |
5 |
|
$rg_prof_start = array(); |
|
|
5 |
|
$rg_prof_state = array(); |
|
6 |
|
$rg_prof_tmp = array(); |
|
7 |
|
|
|
8 |
|
/* |
|
9 |
|
* This will be called by submodules like git and db |
|
10 |
|
*/ |
|
11 |
|
function rg_prof_set($data) |
|
12 |
|
{ |
|
13 |
|
global $rg_prof_state; |
|
14 |
|
|
|
15 |
|
foreach ($data as $k => $v) { |
|
16 |
|
if (isset($rg_prof_state[$k])) |
|
17 |
|
$rg_prof_state[$k] += $v; |
|
18 |
|
else |
|
19 |
|
$rg_prof_state[$k] = $v; |
|
20 |
|
} |
|
21 |
|
} |
6 |
22 |
|
|
7 |
23 |
function rg_prof_start($label) |
function rg_prof_start($label) |
8 |
24 |
{ |
{ |
9 |
25 |
global $rg_prof_tmp; |
global $rg_prof_tmp; |
10 |
26 |
global $rg_prof_state; |
global $rg_prof_state; |
11 |
27 |
|
|
12 |
|
if (isset($rg_prof_tmp[$label])) |
|
13 |
|
return; |
|
14 |
|
|
|
15 |
28 |
$rg_prof_tmp[$label] = $rg_prof_state; |
$rg_prof_tmp[$label] = $rg_prof_state; |
16 |
|
$rg_prof_tmp[$label]['_ts'] = microtime(TRUE); |
|
|
29 |
|
$rg_prof_tmp[$label]['time_ms'] = sprintf("%u", microtime(TRUE) * 1000); |
|
30 |
|
$rg_prof_tmp[$label]['mem'] = memory_get_usage(); |
|
31 |
|
$rg_prof_tmp[$label]['real_mem'] = memory_get_usage(TRUE); |
17 |
32 |
} |
} |
18 |
33 |
|
|
19 |
34 |
function rg_prof_end($label) |
function rg_prof_end($label) |
|
... |
... |
function rg_prof_end($label) |
25 |
40 |
if (!isset($rg_prof_tmp[$label])) |
if (!isset($rg_prof_tmp[$label])) |
26 |
41 |
return; |
return; |
27 |
42 |
|
|
|
43 |
|
$start = $rg_prof_tmp[$label]; |
|
44 |
|
|
28 |
45 |
$c = $rg_prof_state; |
$c = $rg_prof_state; |
29 |
|
$c['time'] = microtime(TRUE) - $rg_prof_tmp[$label]['_ts']; unset($c['_ts']); |
|
|
46 |
|
$c['time_ms'] = sprintf("%u", microtime(TRUE) * 1000); |
30 |
47 |
$c['runs'] = 1; |
$c['runs'] = 1; |
|
48 |
|
$c['mem'] = memory_get_usage(); |
|
49 |
|
$c['real_mem'] = memory_get_usage(TRUE); |
31 |
50 |
|
|
32 |
|
foreach ($rg_prof_tmp[$label] as $key => $val) |
|
|
51 |
|
// we remove what was before start |
|
52 |
|
foreach ($start as $key => $val) |
33 |
53 |
$c[$key] -= $val; |
$c[$key] -= $val; |
34 |
54 |
|
|
35 |
55 |
// add to main label |
// add to main label |
|
... |
... |
function rg_prof_end($label) |
40 |
60 |
$rg_prof_main[$label][$key] += $val; |
$rg_prof_main[$label][$key] += $val; |
41 |
61 |
} |
} |
42 |
62 |
|
|
43 |
|
unset($rg_state_tmp[$label]); |
|
|
63 |
|
unset($rg_prof_tmp[$label]); |
44 |
64 |
} |
} |
45 |
65 |
|
|
46 |
66 |
function rg_prof_get() |
function rg_prof_get() |
|
... |
... |
function rg_prof_get() |
50 |
70 |
return $rg_prof_main; |
return $rg_prof_main; |
51 |
71 |
} |
} |
52 |
72 |
|
|
53 |
|
function rg_prof_get_total() |
|
|
73 |
|
function rg_prof_log() |
54 |
74 |
{ |
{ |
55 |
75 |
global $rg_prof_main; |
global $rg_prof_main; |
56 |
76 |
|
|
57 |
|
$t = array(); |
|
|
77 |
|
rg_log("prof_log"); |
58 |
78 |
|
|
59 |
|
$ret = ""; |
|
60 |
79 |
foreach ($rg_prof_main as $label => $per_label) { |
foreach ($rg_prof_main as $label => $per_label) { |
|
80 |
|
$line = $label . ":"; |
|
81 |
|
|
61 |
82 |
foreach ($per_label as $k => $v) { |
foreach ($per_label as $k => $v) { |
62 |
|
if ($isset($t[$k])) |
|
63 |
|
$t[$k] = $v; |
|
|
83 |
|
if ($v > 0) |
|
84 |
|
$line .= " $k=$v"; |
|
85 |
|
} |
|
86 |
|
rg_log($line); |
|
87 |
|
} |
|
88 |
|
} |
|
89 |
|
|
|
90 |
|
function rg_prof_html() |
|
91 |
|
{ |
|
92 |
|
global $rg_prof_main; |
|
93 |
|
|
|
94 |
|
// get all possible variables |
|
95 |
|
$vars = array(); |
|
96 |
|
foreach ($rg_prof_main as $label => $per_label) |
|
97 |
|
foreach ($per_label as $k => $v) |
|
98 |
|
$vars[$k] = 1; |
|
99 |
|
|
|
100 |
|
$ret = "<table>"; |
|
101 |
|
$ret .= "<tr>"; |
|
102 |
|
$ret .= "<td>Label</td>"; |
|
103 |
|
foreach ($vars as $var => $junk) |
|
104 |
|
$ret .= "<td>" . $var . "</td>"; |
|
105 |
|
$ret .= "</tr>"; |
|
106 |
|
|
|
107 |
|
foreach ($rg_prof_main as $label => $per_label) { |
|
108 |
|
$ret .= "<tr>"; |
|
109 |
|
|
|
110 |
|
$ret .= "<td>" . $label . "</td>"; |
|
111 |
|
|
|
112 |
|
foreach ($vars as $k => $junk) { |
|
113 |
|
if (!isset($per_label[$k])) |
|
114 |
|
$v = 0; |
64 |
115 |
else |
else |
65 |
|
$t[$k] += $v; |
|
|
116 |
|
$v = $per_label[$k]; |
|
117 |
|
$ret .= "<td>" . $v . "</td>"; |
66 |
118 |
} |
} |
|
119 |
|
|
|
120 |
|
$ret .= "</tr>"; |
67 |
121 |
} |
} |
68 |
122 |
|
|
69 |
|
return $t; |
|
70 |
|
} |
|
|
123 |
|
$ret .= "</table>\n"; |
71 |
124 |
|
|
|
125 |
|
return $ret; |
|
126 |
|
} |
72 |
127 |
?> |
?> |
File inc/repo.inc.php changed (mode: 100644) (index 10267db..2b98344) |
... |
... |
require_once($INC . "/sql.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 |
require_once($INC . "/rights.inc.php"); |
require_once($INC . "/rights.inc.php"); |
|
8 |
|
require_once($INC . "/prof.inc.php"); |
8 |
9 |
|
|
9 |
10 |
$rg_repo_empty = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"; |
$rg_repo_empty = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"; |
10 |
11 |
|
|
|
... |
... |
function rg_repo_name2base($rr) |
98 |
99 |
*/ |
*/ |
99 |
100 |
function rg_repo_info($db, $rr) |
function rg_repo_info($db, $rr) |
100 |
101 |
{ |
{ |
|
102 |
|
rg_prof_start("repo_info"); |
|
103 |
|
|
101 |
104 |
rg_log("repo_info: rr:" . implode("|", $rr)); |
rg_log("repo_info: rr:" . implode("|", $rr)); |
102 |
105 |
|
|
103 |
106 |
$repo_id = isset($rr['repo_id']) ? $rr['repo_id'] : 0; |
$repo_id = isset($rr['repo_id']) ? $rr['repo_id'] : 0; |
|
... |
... |
function rg_repo_info($db, $rr) |
138 |
141 |
|
|
139 |
142 |
$row['exists'] = 1; |
$row['exists'] = 1; |
140 |
143 |
$row['ok'] = 1; |
$row['ok'] = 1; |
|
144 |
|
|
|
145 |
|
rg_prof_end("repo_info"); |
|
146 |
|
|
141 |
147 |
return $row; |
return $row; |
142 |
148 |
} |
} |
143 |
149 |
|
|
|
... |
... |
function rg_repo_info($db, $rr) |
146 |
152 |
*/ |
*/ |
147 |
153 |
function rg_repo_allow($db, $ri, $rg_ui, $needed_rights) |
function rg_repo_allow($db, $ri, $rg_ui, $needed_rights) |
148 |
154 |
{ |
{ |
|
155 |
|
rg_prof_start("repo_allow"); |
|
156 |
|
|
149 |
157 |
rg_log("repo_allow: repo_id=" . $ri['repo_id'] |
rg_log("repo_allow: repo_id=" . $ri['repo_id'] |
150 |
158 |
. " rg_uid=" . $rg_ui['uid'] |
. " rg_uid=" . $rg_ui['uid'] |
151 |
159 |
. ", needed_rights=$needed_rights..."); |
. ", needed_rights=$needed_rights..."); |
|
... |
... |
function rg_repo_allow($db, $ri, $rg_ui, $needed_rights) |
180 |
188 |
|
|
181 |
189 |
rg_log("\tAllow access!"); |
rg_log("\tAllow access!"); |
182 |
190 |
|
|
|
191 |
|
rg_prof_end("repo_allow"); |
|
192 |
|
|
183 |
193 |
return TRUE; |
return TRUE; |
184 |
194 |
} |
} |
185 |
195 |
|
|
|
... |
... |
function rg_repo_allow($db, $ri, $rg_ui, $needed_rights) |
191 |
201 |
function rg_repo_create($db, $master, $rg_ui, $name, $max_commit_size, |
function rg_repo_create($db, $master, $rg_ui, $name, $max_commit_size, |
192 |
202 |
$description, $rights, $max_users) |
$description, $rights, $max_users) |
193 |
203 |
{ |
{ |
|
204 |
|
rg_prof_start("repo_create"); |
|
205 |
|
|
194 |
206 |
// TODO: reorder parameters - are not logical |
// TODO: reorder parameters - are not logical |
195 |
207 |
rg_log("repo_create: rg_uid=" . $rg_ui['uid'] |
rg_log("repo_create: rg_uid=" . $rg_ui['uid'] |
196 |
208 |
. ", name=[$name], master=$master" |
. ", name=[$name], master=$master" |
|
... |
... |
function rg_repo_create($db, $master, $rg_ui, $name, $max_commit_size, |
233 |
245 |
// git repo creation will be delayed for serialization reasons |
// git repo creation will be delayed for serialization reasons |
234 |
246 |
// and for permission reasons (we are apache here) |
// and for permission reasons (we are apache here) |
235 |
247 |
|
|
|
248 |
|
rg_prof_end("repo_create"); |
|
249 |
|
|
236 |
250 |
return TRUE; |
return TRUE; |
237 |
251 |
} |
} |
238 |
252 |
|
|
|
... |
... |
function rg_repo_create($db, $master, $rg_ui, $name, $max_commit_size, |
241 |
255 |
*/ |
*/ |
242 |
256 |
function rg_repo_delete($db, $repo_id, $rg_ui) |
function rg_repo_delete($db, $repo_id, $rg_ui) |
243 |
257 |
{ |
{ |
|
258 |
|
rg_prof_start("repo_delete"); |
|
259 |
|
|
244 |
260 |
rg_log("repo_delete: rg_uid=" . $rg_ui['uid'] . ", repo_id=$repo_id"); |
rg_log("repo_delete: rg_uid=" . $rg_ui['uid'] . ", repo_id=$repo_id"); |
245 |
261 |
|
|
246 |
262 |
// TODO: Check rights |
// TODO: Check rights |
|
... |
... |
function rg_repo_delete($db, $repo_id, $rg_ui) |
254 |
270 |
} |
} |
255 |
271 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
256 |
272 |
|
|
|
273 |
|
rg_prof_end("repo_delete"); |
|
274 |
|
|
257 |
275 |
return TRUE; |
return TRUE; |
258 |
276 |
} |
} |
259 |
277 |
|
|
|
... |
... |
function rg_repo_delete($db, $repo_id, $rg_ui) |
263 |
281 |
*/ |
*/ |
264 |
282 |
function rg_repo_update($db, &$new) |
function rg_repo_update($db, &$new) |
265 |
283 |
{ |
{ |
|
284 |
|
rg_prof_start("repo_update"); |
|
285 |
|
|
266 |
286 |
rg_log("repo_update: repo_id=" . $new['repo_id'] |
rg_log("repo_update: repo_id=" . $new['repo_id'] |
267 |
287 |
. ", name=[" . $new['name'] . "]" |
. ", name=[" . $new['name'] . "]" |
268 |
288 |
. ", max_commit_size=" . $new['max_commit_size'] |
. ", max_commit_size=" . $new['max_commit_size'] |
|
... |
... |
function rg_repo_update($db, &$new) |
307 |
327 |
} |
} |
308 |
328 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
309 |
329 |
|
|
|
330 |
|
rg_prof_end("repo_update"); |
|
331 |
|
|
310 |
332 |
return TRUE; |
return TRUE; |
311 |
333 |
} |
} |
312 |
334 |
|
|
|
... |
... |
function rg_repo_list_query($db, $url, $sql) |
317 |
339 |
{ |
{ |
318 |
340 |
global $THEME; |
global $THEME; |
319 |
341 |
|
|
|
342 |
|
rg_prof_start("repo_list_query"); |
|
343 |
|
|
320 |
344 |
rg_log("repo_list_query: url=$url, sql=$sql..."); |
rg_log("repo_list_query: url=$url, sql=$sql..."); |
321 |
345 |
|
|
322 |
346 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
|
... |
... |
function rg_repo_list_query($db, $url, $sql) |
378 |
402 |
} |
} |
379 |
403 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
380 |
404 |
|
|
|
405 |
|
rg_prof_end("repo_list_query"); |
|
406 |
|
|
381 |
407 |
return rg_template_table($THEME . "/repo/list", $d, array()); |
return rg_template_table($THEME . "/repo/list", $d, array()); |
382 |
408 |
} |
} |
383 |
409 |
|
|
|
... |
... |
function rg_repo_disk_mb($path) |
440 |
466 |
*/ |
*/ |
441 |
467 |
function rg_repo_git_done($db, $repo_id) |
function rg_repo_git_done($db, $repo_id) |
442 |
468 |
{ |
{ |
|
469 |
|
rg_prof_start("repo_git_done"); |
|
470 |
|
|
443 |
471 |
rg_log("repo_git_done: repo_id=$repo_id..."); |
rg_log("repo_git_done: repo_id=$repo_id..."); |
444 |
472 |
|
|
445 |
473 |
$sql = "UPDATE repos SET git_dir_done = 1" |
$sql = "UPDATE repos SET git_dir_done = 1" |
|
... |
... |
function rg_repo_git_done($db, $repo_id) |
451 |
479 |
} |
} |
452 |
480 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
453 |
481 |
|
|
|
482 |
|
rg_prof_end("repo_git_done"); |
|
483 |
|
|
454 |
484 |
return TRUE; |
return TRUE; |
455 |
485 |
} |
} |
456 |
486 |
|
|
|
... |
... |
function rg_repo_git_done($db, $repo_id) |
459 |
489 |
*/ |
*/ |
460 |
490 |
function rg_repo_rights_get($db, $ri, $uid, $flags) |
function rg_repo_rights_get($db, $ri, $uid, $flags) |
461 |
491 |
{ |
{ |
|
492 |
|
rg_prof_start("repo_rights_get"); |
|
493 |
|
|
462 |
494 |
rg_log("rg_repo_rights_get: repo_id=" . $ri['repo_id'] . ", uid=$uid" |
rg_log("rg_repo_rights_get: repo_id=" . $ri['repo_id'] . ", uid=$uid" |
463 |
495 |
. " flags=$flags..."); |
. " flags=$flags..."); |
464 |
496 |
|
|
|
... |
... |
function rg_repo_rights_get($db, $ri, $uid, $flags) |
495 |
527 |
. $r['rights'] . ")=" . $ret['rights']); |
. $r['rights'] . ")=" . $ret['rights']); |
496 |
528 |
$ret['ok'] = 1; |
$ret['ok'] = 1; |
497 |
529 |
|
|
|
530 |
|
rg_prof_end("repo_rights_get"); |
|
531 |
|
|
498 |
532 |
return $ret; |
return $ret; |
499 |
533 |
} |
} |
500 |
534 |
|
|
File inc/sess.inc.php changed (mode: 100644) (index 5646012..4a0164d) |
2 |
2 |
require_once($INC . "/log.inc.php"); |
require_once($INC . "/log.inc.php"); |
3 |
3 |
require_once($INC . "/sql.inc.php"); |
require_once($INC . "/sql.inc.php"); |
4 |
4 |
require_once($INC . "/token.inc.php"); |
require_once($INC . "/token.inc.php"); |
|
5 |
|
require_once($INC . "/prof.inc.php"); |
5 |
6 |
|
|
6 |
7 |
/* |
/* |
7 |
8 |
* Add a session |
* Add a session |
8 |
9 |
*/ |
*/ |
9 |
10 |
function rg_sess_add($db, $uid, $sid, $session_time) |
function rg_sess_add($db, $uid, $sid, $session_time) |
10 |
11 |
{ |
{ |
|
12 |
|
rg_prof_start("sess_add"); |
|
13 |
|
|
11 |
14 |
rg_log("sess_add: uid=$uid, sid=$sid, session_time=$session_time."); |
rg_log("sess_add: uid=$uid, sid=$sid, session_time=$session_time."); |
12 |
15 |
|
|
13 |
16 |
$ip = @$_SERVER['REMOTE_ADDR']; |
$ip = @$_SERVER['REMOTE_ADDR']; |
|
... |
... |
function rg_sess_add($db, $uid, $sid, $session_time) |
23 |
26 |
} |
} |
24 |
27 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
25 |
28 |
|
|
|
29 |
|
rg_prof_end("sess_add"); |
|
30 |
|
|
26 |
31 |
return TRUE; |
return TRUE; |
27 |
32 |
} |
} |
28 |
33 |
|
|
|
... |
... |
function rg_sess_add($db, $uid, $sid, $session_time) |
31 |
36 |
*/ |
*/ |
32 |
37 |
function rg_sess_valid($db, $sid) |
function rg_sess_valid($db, $sid) |
33 |
38 |
{ |
{ |
|
39 |
|
rg_prof_start("sess_valid"); |
|
40 |
|
|
34 |
41 |
rg_log("sess_valid: sid=$sid..."); |
rg_log("sess_valid: sid=$sid..."); |
35 |
42 |
|
|
36 |
43 |
$uid = FALSE; |
$uid = FALSE; |
|
... |
... |
function rg_sess_valid($db, $sid) |
57 |
64 |
rg_log("\tSession not found!"); |
rg_log("\tSession not found!"); |
58 |
65 |
} |
} |
59 |
66 |
|
|
|
67 |
|
rg_prof_end("sess_valid"); |
|
68 |
|
|
60 |
69 |
return $uid; |
return $uid; |
61 |
70 |
} |
} |
62 |
71 |
|
|
|
... |
... |
function rg_sess_valid($db, $sid) |
65 |
74 |
*/ |
*/ |
66 |
75 |
function rg_sess_update($db, $sid) |
function rg_sess_update($db, $sid) |
67 |
76 |
{ |
{ |
|
77 |
|
rg_prof_start("sess_update"); |
|
78 |
|
|
68 |
79 |
rg_log("sess_update: sid=$sid..."); |
rg_log("sess_update: sid=$sid..."); |
69 |
80 |
|
|
70 |
81 |
$e_sid = rg_sql_escape($db, $sid); |
$e_sid = rg_sql_escape($db, $sid); |
|
... |
... |
function rg_sess_update($db, $sid) |
78 |
89 |
} |
} |
79 |
90 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
80 |
91 |
|
|
|
92 |
|
rg_prof_end("sess_update"); |
|
93 |
|
|
81 |
94 |
return TRUE; |
return TRUE; |
82 |
95 |
} |
} |
83 |
96 |
|
|
|
... |
... |
function rg_sess_update($db, $sid) |
86 |
99 |
*/ |
*/ |
87 |
100 |
function rg_sess_destroy($db, $sid, &$rg_ui) |
function rg_sess_destroy($db, $sid, &$rg_ui) |
88 |
101 |
{ |
{ |
|
102 |
|
rg_prof_start("sess_destroy"); |
|
103 |
|
|
89 |
104 |
rg_log("sess_destroy: sid=$sid..."); |
rg_log("sess_destroy: sid=$sid..."); |
90 |
105 |
|
|
91 |
106 |
$e_sid = rg_sql_escape($db, $sid); |
$e_sid = rg_sql_escape($db, $sid); |
|
... |
... |
function rg_sess_destroy($db, $sid, &$rg_ui) |
105 |
120 |
$rg_ui['uid'] = 0; |
$rg_ui['uid'] = 0; |
106 |
121 |
$rg_ui['is_admin'] = 0; |
$rg_ui['is_admin'] = 0; |
107 |
122 |
|
|
|
123 |
|
rg_prof_end("sess_destroy"); |
|
124 |
|
|
108 |
125 |
return TRUE; |
return TRUE; |
109 |
126 |
} |
} |
|
127 |
|
|
110 |
128 |
?> |
?> |
File inc/sql.inc.php changed (mode: 100644) (index 4e855f0..0236cd2) |
1 |
1 |
<?php |
<?php |
2 |
2 |
require_once($INC . "/log.inc.php"); |
require_once($INC . "/log.inc.php"); |
|
3 |
|
require_once($INC . "/prof.inc.php"); |
3 |
4 |
|
|
4 |
5 |
$rg_sql_error = ""; |
$rg_sql_error = ""; |
5 |
6 |
|
|
|
... |
... |
function rg_sql_open($str) |
34 |
35 |
if ($rg_sql_debug > 0) |
if ($rg_sql_debug > 0) |
35 |
36 |
rg_log("DB: opening [$str]..."); |
rg_log("DB: opening [$str]..."); |
36 |
37 |
|
|
|
38 |
|
rg_prof_set(array("db_conn" => 1)); |
|
39 |
|
|
|
40 |
|
$_s = microtime(TRUE); |
37 |
41 |
$db = @pg_pconnect($str); |
$db = @pg_pconnect($str); |
|
42 |
|
$diff = sprintf("%u", (microtime(TRUE) - $_s) * 1000); |
|
43 |
|
rg_prof_set(array("db_conn_time_ms" => $diff)); |
38 |
44 |
if ($db === FALSE) { |
if ($db === FALSE) { |
39 |
45 |
rg_sql_set_error("cannot connect to database (" . $php_errormsg . ")"); |
rg_sql_set_error("cannot connect to database (" . $php_errormsg . ")"); |
|
46 |
|
rg_prof_set(array("db_conn_errors" => 1)); |
40 |
47 |
return FALSE; |
return FALSE; |
41 |
48 |
} |
} |
42 |
49 |
|
|
|
... |
... |
function rg_sql_query($db, $sql) |
58 |
65 |
{ |
{ |
59 |
66 |
global $rg_sql_debug; |
global $rg_sql_debug; |
60 |
67 |
|
|
61 |
|
if ($rg_sql_debug > 0) { |
|
|
68 |
|
$_s = microtime(TRUE); |
|
69 |
|
|
|
70 |
|
if ($rg_sql_debug > 0) |
62 |
71 |
rg_log("\tDB: running [$sql]..."); |
rg_log("\tDB: running [$sql]..."); |
63 |
|
$_s = microtime(TRUE); |
|
64 |
|
} |
|
65 |
72 |
|
|
66 |
73 |
$res = @pg_query($db, $sql); |
$res = @pg_query($db, $sql); |
67 |
74 |
if ($res === FALSE) { |
if ($res === FALSE) { |
68 |
75 |
rg_sql_set_error("$sql: " . @pg_last_error($db)); |
rg_sql_set_error("$sql: " . @pg_last_error($db)); |
|
76 |
|
rg_prof_set(array("query_errors" => 1)); |
69 |
77 |
return FALSE; |
return FALSE; |
70 |
78 |
} |
} |
71 |
79 |
|
|
72 |
|
if ($rg_sql_debug > 0) { |
|
73 |
|
$diff = sprintf("%u", (microtime(TRUE) - $_s) * 1000); |
|
74 |
|
$rows = rg_sql_num_rows($res); |
|
|
80 |
|
$diff = sprintf("%u", (microtime(TRUE) - $_s) * 1000); |
|
81 |
|
$rows = rg_sql_num_rows($res); |
|
82 |
|
if ($rows == 0) |
75 |
83 |
$arows = rg_sql_affected_rows($res); |
$arows = rg_sql_affected_rows($res); |
|
84 |
|
else |
|
85 |
|
$arows = 0; |
|
86 |
|
|
|
87 |
|
if ($rg_sql_debug > 0) |
76 |
88 |
rg_log("\tDB: Took " . $diff . "ms, $rows row(s), $arows affected"); |
rg_log("\tDB: Took " . $diff . "ms, $rows row(s), $arows affected"); |
77 |
|
} |
|
|
89 |
|
|
|
90 |
|
rg_prof_set(array("queries" => 1, |
|
91 |
|
"rows" => $rows, |
|
92 |
|
"affected rows" => $arows, |
|
93 |
|
"query_time_ms" => $diff)); |
78 |
94 |
|
|
79 |
95 |
return $res; |
return $res; |
80 |
96 |
} |
} |