xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
Commit af5c3e9e60264219565f682fa909b9f829e0fa9d

Checkpoint
Author: Catalin(ux) M. BOIE
Author date (UTC): 2014-10-23 19:50
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2014-10-23 19:50
Parent(s): c4115b92bd328d7b6931d2854f63d0fe7e685aad
Signing key:
Tree: bc7deee35ee9c437267859478e91748b43c29e58
File Lines added Lines deleted
TODO 45 19
TODO-plans 1 5
docs/rights.txt 1 1
hooks/post-receive 1 1
hooks/pre-receive 2 2
hooks/update 6 4
inc/bug.inc.php 109 96
inc/cache.inc.php 134 56
inc/fixes.inc.php 105 72
inc/git.inc.php 45 19
inc/init.inc.php 3 0
inc/log.inc.php 38 7
inc/plan.inc.php 29 19
inc/repo.inc.php 147 150
inc/rights.inc.php 235 137
inc/sess.inc.php 3 6
inc/sql.inc.php 68 45
inc/state.inc.php 11 6
inc/struct.inc.php 54 29
inc/user.inc.php 357 284
inc/user/repo-page.php 4 7
inc/util.inc.php 13 10
root/themes/default/mail/user/repo/update.body.txt 2 2
root/themes/default/user/repo/rights/form_repo.html 3 3
root/themes/default/user/repo/rights/form_repo_path.html 3 3
root/themes/default/user/repo/rights/form_repo_refs.html 3 3
root/themes/default/user/repo/rights/list_repo/line.html 1 1
root/themes/default/user/repo/rights/list_repo_path/line.html 1 1
root/themes/default/user/repo/rights/list_repo_refs/line.html 1 1
samples/config.php 2 2
scripts/cache.php 31 10
scripts/remote.php 7 7
tests/bug.php 13 11
tests/cache.php 15 14
tests/common.php 5 2
tests/email.php 3 0
tests/event.php 2 1
tests/git.php 2 1
tests/git2.php 2 1
tests/keys.php 2 1
tests/log.php 2 1
tests/prof.php 2 1
tests/repo.php 45 55
tests/rights.php 19 4
tests/sql.php 2 1
tests/state.php 2 1
tests/user.php 3 1
tests/util.php 20 1
File TODO changed (mode: 100644) (index ab5038b..92734f4)
1 1 == Where I stopped last time == == Where I stopped last time ==
2 [ ] rg_git_files
2 [ ] Use can_be_deleted when showing delete checkboxes for rights.
3 [ ] For delete, do not show checkboxes for injected items.
4 [ ] We should pass 'owner' to rg_rights_get/rg_repo_rights_inject
5 [ ] Add unit test for inject functions.
6 [ ] When changing rights, invalidate/update cache.
7 [ ] Retest repo rename. Better, add an unit test.
8 [ ] who_text or other name?
9 [ ] We have big races for cache. But, the same with the database.
10 [ ] Maybe we should model memory cache after network cache, so we can
11 invalidate whole trees of stuff. Right now, we cannot because we build
12 a string with '|' delimiter. It is already done, we should get rid of
13 custom caches in all files!
14 [ ] See, for regular expressions we need to output them in browser as
15 html escaped. The rest of the variables must be stored escaped in db.
16 Strange.
3 17 [ ] We must test in HL functions if we have rights, not in rg_user_remove & co. [ ] We must test in HL functions if we have rights, not in rg_user_remove & co.
4 [ ] For repo_refs, we must test also the ref. Sometime, we do not have it,
5 so, test it for FALSE.
6 [ ] Not clear what uid we have in:
7 "$a['uid'] = @sprintf("%u", getenv("ROCKETGIT_UID"));"
8 [ ] I should set 'display_errors' to OFF.
9 [ ] remote.php: what rights need to check?
10 ROCKETGIT_REPO_RIGHTS is gone. We must use rg_repo_allow (a['rights'])
11 Probably all hooks need db connection and loading rights.
12 18 [ ] The caller of rg_user_make_admin must check rights for administering repo. [ ] The caller of rg_user_make_admin must check rights for administering repo.
13 [ ] What right is "Access repo"?!
19 [ ] What right is "Access repo"?! I think is for web. Not clear. Check.
20 Seems is used on repo-page.php to give access or not to the repo.
21 But I should only check if is public.
14 22 [ ] We must return error if a user tries to drop 'fetch' for a public repo. [ ] We must return error if a user tries to drop 'fetch' for a public repo.
15 23 But if the user switch it to be private repo? It's the user problem. But if the user switch it to be private repo? It's the user problem.
16 24 [ ] Special case: rights are empty and repo is public. Should I test [ ] Special case: rights are empty and repo is public. Should I test
17 25 default rights only? Same with private repos. default rights only? Same with private repos.
18 26 [ ] Remove rg_menu stuff (replaced with templates). [ ] Remove rg_menu stuff (replaced with templates).
19 [ ] The rights stuff is a mess. Redesign it.
20 [ ] Still checking rights stuff of a simple user for a repo.
21 27 [ ] Run hook_update.sh test. It not passes anymore. [ ] Run hook_update.sh test. It not passes anymore.
22 [ ] In progress of adding 'public' to repo and removing 'default_rights'.
23 28 [ ] I have to define what means a 'public' repo: fetch + see bugtracker? [ ] I have to define what means a 'public' repo: fetch + see bugtracker?
24 29 [ ] In the process to remove 'ri.rights_text' and replace by 'public'. [ ] In the process to remove 'ri.rights_text' and replace by 'public'.
25 30 [ ] How to prevent a user to cut his access from an IP? Maybe admin should not [ ] How to prevent a user to cut his access from an IP? Maybe admin should not
26 31 filter by IP. filter by IP.
27 [ ] Entering an IP for rights: must allow multiple IPs, comma/enter separated.
28 32 [ ] If a project is private and the admin gives "Access repo" to a user, [ ] If a project is private and the admin gives "Access repo" to a user,
29 33 that user sees the repo as public. that user sees the repo as public.
34
35 == BEFORE NEXT RELEASE ==
36 [ ] Add 'desc' to rights.
37 [ ] We should not show delete checkboxes/buttons if a user is not allowed
38 to delete items.
39 [ ] In cache, what if a var has \n in it?
40 [ ] Purge deleted bugs (and notes) in backgrou.nd
41 [ ] Event for bug delete.
42 [ ] CIneva sterge un bug, si apoi altcineva apasa "delete" pe acelasi bug.
43 Va da eroare, dar nu ar trebui sa fie fatala... Eventual sa afisam
44 si cine a sters acel bug.
45 [ ] No expiration for cache?!
46 [ ] rg_rights_load and rg_rights_get do the same thing. Remove _load.
47 [ ] Maybe I should disconnect from cache if a "generation number" does not match
48 per connection. Think about setting/unsetting a key that fails
49 and then issue a get...
50 [ ] rights_delete_list must invalidate cache.
51 [ ] Somewhere we must have a section to define the groups and allow rights
52 for groups.
53 [ ] We may allow a list of paths/refs for rights, not only a single one.
54 [ ] Audit all regular expressions (at least /D). Especially in conf file.
55 [ ] I should set 'display_errors' to OFF.
30 56 [ ] Maybe add db.users.last_ip_failed? Or the history is enough? [ ] Maybe add db.users.last_ip_failed? Or the history is enough?
31 57 [ ] db.users.last_ip is used for last IP used for login? [ ] db.users.last_ip is used for last IP used for login?
32 58 [ ] repos.disk_quota_mb must be dropped and do a lookup in plan. [ ] repos.disk_quota_mb must be dropped and do a lookup in plan.
 
37 63 [ ] Check with owasp about html escaping. I do now htmlspecialchars -> [ ] Check with owasp about html escaping. I do now htmlspecialchars ->
38 64 db -> HTML:nl2br() db -> HTML:nl2br()
39 65 [ ] When we will switch to C, check UTF-8 validation. [ ] When we will switch to C, check UTF-8 validation.
40 [ ] Log also the last IP used. Where? For push? This will be in history.
41 66 [ ] Check http://blog.wikichoon.com/2014/04/github-doesnt-support-pull-request.html [ ] Check http://blog.wikichoon.com/2014/04/github-doesnt-support-pull-request.html
42
43 == BEFORE NEXT RELEASE ==
67 [ ] If path for repo_path rights starts with /, it is anchored.
68 Else, can match anywhere.
69 [ ] refs: if it does not start with refs/, it is assumed that is refs/heads/
70 Also, it must be anchored at the begin of the string.
71 Really anchored? Why?
44 72 [ ] Implement a basic regular expression parser. [ ] Implement a basic regular expression parser.
45 73 [ ] Use an 'indent' string per repo and (optionally) enforce it. [ ] Use an 'indent' string per repo and (optionally) enforce it.
46 74 [ ] Should we use a more restrictive umask? [ ] Should we use a more restrictive umask?
 
189 217 do a lookup in cache/db anyway. Or, compute correct rights (take in do a lookup in cache/db anyway. Or, compute correct rights (take in
190 218 account IP/time/etc.). No, because we need paths. account IP/time/etc.). No, because we need paths.
191 219 [ ] 'rg_rights_allow' needs a first parameter that is the set. [ ] 'rg_rights_allow' needs a first parameter that is the set.
192 [ ] 'default_rights' must disappear. If repo is public, give basic rights.
193 Else, none. Must disappear only because we have two sets of rights now.
194 220 [ ] Repo rights were split in two. Check all rights checks! Maybe in check [ ] Repo rights were split in two. Check all rights checks! Maybe in check
195 221 function, verify that there is a possible right and if not internal_error. function, verify that there is a possible right and if not internal_error.
196 222 [ ] Tree rights are a mess. User/Repo mixed rights. [ ] Tree rights are a mess. User/Repo mixed rights.
File TODO-plans changed (mode: 100644) (index 5faef51..f22911e)
1 1 == Another plan == == Another plan ==
2 2 Create repo: no right, only Public/Private. Public means at least 'Fetch', Create repo: no right, only Public/Private. Public means at least 'Fetch',
3 3 and will be available for search, browse source etc. and will be available for search, browse source etc.
4 Then, we have the rights tab, where we can give rights.
5 So, we:
6 - drop repos.default_rights.
7 - add repos.public, boolean, default private
4 Then, we have the rights tabs, where we can give rights.
8 5
9 6 == Plans for repo redesign == == Plans for repo redesign ==
10 7 Because we can have a project without a repository, for example only with Because we can have a project without a repository, for example only with
 
... ... and/or a mailing list.
16 13 We need rights to admin/create/delete/grant_rights against repo/bugtracker/mailing list. We need rights to admin/create/delete/grant_rights against repo/bugtracker/mailing list.
17 14 Pay attention. A project has an owner. Without "admin" rights, you cannot Pay attention. A project has an owner. Without "admin" rights, you cannot
18 15 deal with the rest of deal with the rest of
19 A project is public/private.
20 16 A repository/bt/ml link with a project. A repository/bt/ml link with a project.
21 17
22 18 We begin with an admin user. We have no projects, so no repo/bt/ml. We begin with an admin user. We have no projects, so no repo/bt/ml.
File docs/rights.txt changed (mode: 100644) (index 8108f52..4f6db73)
... ... We have some function to manage the rights:
22 22 Loads all rights for an object, identified by Loads all rights for an object, identified by
23 23 type and obj_id; type may be '*' for all rights type. type and obj_id; type may be '*' for all rights type.
24 24
25 - rg_rights_delete_list($db, $obj_id, $list)
25 - rg_rights_delete_list($db, $type, $obj_id, $list)
26 26 Deletes a list of rights, Deletes a list of rights,
27 27 obtained by selecting them in the form. obtained by selecting them in the form.
File hooks/post-receive changed (mode: 100755) (index 45cc7a2..e91550b)
... ... fclose($f);
66 66 $a = array( $a = array(
67 67 "op" => "push", "op" => "push",
68 68 "itime" => getenv("ROCKETGIT_ITIME"), "itime" => getenv("ROCKETGIT_ITIME"),
69 "uid" => getenv("ROCKETGIT_UID"),
69 "uid" => getenv("ROCKETGIT_LOGIN_UID"),
70 70 "repo_id" => getenv("ROCKETGIT_REPO_ID"), "repo_id" => getenv("ROCKETGIT_REPO_ID"),
71 71 "old_rev" => $old_rev, "old_rev" => $old_rev,
72 72 "new_rev" => $new_rev, "new_rev" => $new_rev,
File hooks/pre-receive changed (mode: 100755) (index 3fcbce3..8e0397a)
... ... require_once($INC . "/repo.inc.php");
28 28 rg_log_set_file($rg_log_dir . "/hook_pre-receive.log"); rg_log_set_file($rg_log_dir . "/hook_pre-receive.log");
29 29
30 30 $repo_path = getenv("ROCKETGIT_REPO_PATH"); $repo_path = getenv("ROCKETGIT_REPO_PATH");
31 $uid = etenv("ROCKETGIT_UID");
31 $login_uid = etenv("ROCKETGIT_LOGIN_UID");
32 32
33 33 rg_log("Start"); rg_log("Start");
34 34 rg_log("_SERVER: " . rg_array2string($_SERVER)); rg_log("_SERVER: " . rg_array2string($_SERVER));
 
... ... rg_log("Took " . $diff . "ms.");
66 66 @file_put_contents($repo_path . "/rocketgit/hook-pre-receive", @file_put_contents($repo_path . "/rocketgit/hook-pre-receive",
67 67 "repo: " . $repo . " ($repo_path)" "repo: " . $repo . " ($repo_path)"
68 68 . "\nat: " . sprintf("%u", $_start) . "\nat: " . sprintf("%u", $_start)
69 . "\nuid: " . $uid
69 . "\nuid: " . $login_uid
70 70 . "\npara: $refname $old_rev $new_rev" . "\npara: $refname $old_rev $new_rev"
71 71 . "\nTook: " . $diff . "ms" . "\nTook: " . $diff . "ms"
72 72 . "\n_SERVER: " . rg_array2string($_SERVER)); . "\n_SERVER: " . rg_array2string($_SERVER));
File hooks/update changed (mode: 100755) (index 068029b..9a3dd1d)
... ... $db = rg_sql_open($rg_sql);
36 36
37 37 $a = array(); $a = array();
38 38
39 $a['uid'] = @sprintf("%u", getenv("ROCKETGIT_UID"));
39 $a['login_uid'] = @sprintf("%u", getenv("ROCKETGIT_LOGIN_UID"));
40 40 $a['repo_id'] = getenv("ROCKETGIT_REPO_ID"); $a['repo_id'] = getenv("ROCKETGIT_REPO_ID");
41 41 $a['ip'] = getenv("ROCKETGIT_IP"); $a['ip'] = getenv("ROCKETGIT_IP");
42 42 $a['namespace'] = getenv("GIT_NAMESPACE"); $a['namespace'] = getenv("GIT_NAMESPACE");
 
... ... $ri = rg_repo_info($db, $a['repo_id'], 0, "");
68 68 if ($ri['ok'] != 1) if ($ri['ok'] != 1)
69 69 rg_git_fatal("Internal error (repo). Try again later."); rg_git_fatal("Internal error (repo). Try again later.");
70 70
71 $r = rg_repo_rights_get($db, "repo_refs", $ri, $a['uid']);
71 $r = rg_rights_get($db, $ri['repo_id'], "repo_refs", $ri['uid'],
72 $a['login_uid'], 0);
72 73 if ($r['ok'] != 1) if ($r['ok'] != 1)
73 74 rg_git_fatal("Internal error (refs rights). Try again later."); rg_git_fatal("Internal error (refs rights). Try again later.");
74 75 $a['refs_rights'] = $r['list']; $a['refs_rights'] = $r['list'];
75 76
76 $r = rg_repo_rights_get($db, "repo_path", $ri, $a['uid']);
77 $r = rg_rights_get($db, $ri['repo_id'], "repo_path", $ri['uid'],
78 $a['login_uid'], 0);
77 79 if ($r['ok'] != 1) if ($r['ok'] != 1)
78 80 rg_git_fatal("Internal error (path rights). Try again later."); rg_git_fatal("Internal error (path rights). Try again later.");
79 81 $a['repo_path'] = $r['list']; $a['repo_path'] = $r['list'];
 
... ... if (strncmp($a['refname'], "refs/tags/", 10) == 0) {
92 94 @file_put_contents($a['repo_path'] . "/rocketgit/hook-update", @file_put_contents($a['repo_path'] . "/rocketgit/hook-update",
93 95 "repo: " . $a['repo_path'] "repo: " . $a['repo_path']
94 96 . "\nat: " . sprintf("%u", $_start) . "\nat: " . sprintf("%u", $_start)
95 . "\nuid: " . $a['uid']
97 . "\nuid: " . $a['login_uid']
96 98 . "\npara: " . $a['refname'] . " " . $a['old_rev'] . " " . $a['new_rev'] . "\npara: " . $a['refname'] . " " . $a['old_rev'] . " " . $a['new_rev']
97 99 . "\nProfiling:\n" . rg_prof_text() . "\nProfiling:\n" . rg_prof_text()
98 100 . "\n_SERVER: " . rg_array2string($_SERVER)); . "\n_SERVER: " . rg_array2string($_SERVER));
File inc/bug.inc.php changed (mode: 100644) (index 3bc5292..90ee6d2)
... ... rg_event_register_functions($rg_bug_functions);
45 45 */ */
46 46 function rg_bug_event_add_one($db, $event) function rg_bug_event_add_one($db, $event)
47 47 { {
48 rg_log("DEBUG: bug_event_add_one event=" . rg_array2string($event));
48 rg_log_enter("DEBUG: bug_event_add_one event=" . rg_array2string($event));
49 49
50 50 $ret = FALSE; $ret = FALSE;
51 do {
51 while (1) {
52 52 // lookup user email // lookup user email
53 $ui = rg_user_info($db, $event['target_uid'], "", "");
53 $ui = rg_user_info($db, $event['uid'], "", "");
54 54 if ($ui['exists'] != 1) { if ($ui['exists'] != 1) {
55 55 rg_internal_error("User does not exists!"); rg_internal_error("User does not exists!");
56 56 break; break;
 
... ... function rg_bug_event_add_one($db, $event)
60 60 $event['ui.email'] = $ui['email']; $event['ui.email'] = $ui['email'];
61 61 $r = rg_mail("mail/user/repo/bug/new", $event); $r = rg_mail("mail/user/repo/bug/new", $event);
62 62 if ($r === FALSE) if ($r === FALSE)
63 return FALSE;
64 } while (0);
63 break;
65 64
66 return array();
65 $ret = array();
66 break;
67 }
68
69 rg_log_exit();
70 return $ret;
67 71 } }
68 72
69 73 /* /*
 
... ... function rg_bug_event_add_one($db, $event)
72 76 function rg_bug_event_add_all($db, $event) function rg_bug_event_add_all($db, $event)
73 77 { {
74 78 rg_prof_start("bug_event_add"); rg_prof_start("bug_event_add");
79
75 80 $ret = array(); $ret = array();
76 81
77 82 $x = $event; $x = $event;
 
... ... function rg_bug_event_add_all($db, $event)
84 89 return FALSE; return FALSE;
85 90 if (!empty($r)) { if (!empty($r)) {
86 91 foreach ($r as $index => $uid) { foreach ($r as $index => $uid) {
87 $x['target_uid'] = $uid;
92 $x['uid'] = $uid;
88 93 $ret[] = $x; $ret[] = $x;
89 94 } }
90 95 } }
 
... ... function rg_bug_event_add_all($db, $event)
96 101 return FALSE; return FALSE;
97 102 if (!empty($r)) { if (!empty($r)) {
98 103 foreach ($r as $index => $uid) { foreach ($r as $index => $uid) {
99 $x['target_uid'] = $uid;
104 $x['uid'] = $uid;
100 105 $ret[] = $x; $ret[] = $x;
101 106 } }
102 107 } }
 
... ... function rg_bug_event_note_add_one($db, $event)
116 121
117 122 do { do {
118 123 // lookup user email // lookup user email
119 $ui = rg_user_info($db, $event['target_uid'], "", "");
124 $ui = rg_user_info($db, $event['uid'], "", "");
120 125 if ($ui['exists'] != 1) { if ($ui['exists'] != 1) {
121 126 rg_internal_error("User does not exists!"); rg_internal_error("User does not exists!");
122 127 break; break;
 
... ... function rg_bug_event_note_add_all($db, $event)
151 156 return FALSE; return FALSE;
152 157 if (!empty($r)) { if (!empty($r)) {
153 158 foreach ($r as $index => $uid) { foreach ($r as $index => $uid) {
154 $x['target_uid'] = $uid;
159 $x['uid'] = $uid;
155 160 $ret[] = $x; $ret[] = $x;
156 161 } }
157 162 } }
 
... ... function rg_bug_state_select($value, $exclude)
205 210 function rg_bug_next_id($db, $repo_id) function rg_bug_next_id($db, $repo_id)
206 211 { {
207 212 rg_prof_start("bug_next_id"); rg_prof_start("bug_next_id");
208 rg_log("bug_next_id: repo_id=$repo_id");
213 rg_log_enter("bug_next_id: repo_id=$repo_id");
209 214
210 215 $next_bug_id = FALSE; $next_bug_id = FALSE;
211 216 while (1) { while (1) {
 
... ... function rg_bug_next_id($db, $repo_id)
223 228 $next_bug_id = $row['next_bug_id']; $next_bug_id = $row['next_bug_id'];
224 229 rg_sql_free_result($res); rg_sql_free_result($res);
225 230 break; break;
226 };
231 }
227 232
228 233 rg_log("\tDEBUG: next_bug_id=" . $next_bug_id); rg_log("\tDEBUG: next_bug_id=" . $next_bug_id);
229 234
235 rg_log_exit();
230 236 rg_prof_end("bug_next_id"); rg_prof_end("bug_next_id");
231 237 return $next_bug_id; return $next_bug_id;
232 238 } }
 
... ... function rg_bug_cosmetic($db, &$row)
301 307 $row['state_text'] = rg_bug_state($row['state']); $row['state_text'] = rg_bug_state($row['state']);
302 308 } }
303 309
304 /*
305 * Invalidate bug cache
306 * TODO: really use it! And update it in bug_edit!
307 */
308 function rg_bug_invalidate_cache($repo_id, $bug_id)
309 {
310 global $rg_bug_info_cache;
311
312 $key = $repo_id . " " . $bug_id;
313 if (isset($rg_bug_info_cache[$key]))
314 unset($rg_bug_info_cache[$key]);
315 }
316
317 310 /* /*
318 311 * Return info about a bug * Return info about a bug
319 312 */ */
320 $rg_bug_info_cache = array();
321 313 function rg_bug_info($db, $repo_id, $bug_id) function rg_bug_info($db, $repo_id, $bug_id)
322 314 { {
323 global $rg_bug_info_cache;
324
325 315 rg_prof_start("bug_info"); rg_prof_start("bug_info");
326 rg_log("rg_bug_info: repo_id=$repo_id bug_id=$bug_id");
316 rg_log_enter("bug_info: repo_id=$repo_id bug_id=$bug_id");
327 317
328 318 $ret = array(); $ret = array();
329 319 $ret['ok'] = 0; $ret['ok'] = 0;
330 320 $ret['exists'] = 0; $ret['exists'] = 0;
331 do {
332 $key = $repo_id . " " . $bug_id;
333 if (isset($rg_bug_info_cache[$key])) {
334 $ret = $rg_bug_info_cache[$key];
321 while (1) {
322 $key = $repo_id . "::bugs::" . $bug_id;
323 $ret = rg_cache_get($key);
324 if ($ret !== FALSE)
335 325 break; break;
336 }
337 326
338 327 $params = array("repo_id" => $repo_id, $params = array("repo_id" => $repo_id,
339 328 "bug_id" => $bug_id); "bug_id" => $bug_id);
 
... ... function rg_bug_info($db, $repo_id, $bug_id)
353 342 rg_sql_free_result($res); rg_sql_free_result($res);
354 343
355 344 $ret['exists'] = $rows; $ret['exists'] = $rows;
356 if ($ret['exists'] == 0)
357 break;
358
359 rg_bug_cosmetic($db, $ret);
345 if ($ret['exists'] == 1)
346 rg_bug_cosmetic($db, $ret);
360 347
361 $rg_bug_info_cache[$key] = $ret;
362 } while (0);
348 // We set the cache even on non-existent bug
349 rg_cache_set($key, $ret);
350 break;
351 }
363 352
353 rg_log_exit();
364 354 rg_prof_end("bug_info"); rg_prof_end("bug_info");
365 355 return $ret; return $ret;
366 356 } }
 
... ... function rg_bug_info($db, $repo_id, $bug_id)
371 361 */ */
372 362 function rg_bug_edit($db, $login_ui, $ri, $data) function rg_bug_edit($db, $login_ui, $ri, $data)
373 363 { {
374 global $rg_bug_info_cache;
375
376 364 rg_prof_start("bug_edit"); rg_prof_start("bug_edit");
377 rg_log("bug_edit: data: " . rg_array2string($data));
365 rg_log_enter("bug_edit: data: " . rg_array2string($data));
378 366
379 367 $data['labels'] = isset($data['labels']) ? $data['labels'] : ""; $data['labels'] = isset($data['labels']) ? $data['labels'] : "";
380 368
 
... ... function rg_bug_edit($db, $login_ui, $ri, $data)
383 371
384 372 $ret = FALSE; $ret = FALSE;
385 373 $rollback = 0; $rollback = 0;
386 do {
374 while (1) {
387 375 if (empty($data['title'])) { if (empty($data['title'])) {
388 376 rg_bug_set_error("title cannot be empty"); rg_bug_set_error("title cannot be empty");
389 377 break; break;
 
... ... function rg_bug_edit($db, $login_ui, $ri, $data)
504 492 } }
505 493
506 494 // update cache // update cache
507 $key = $ri['repo_id'] . " " . $data['bug_id'];
495 $key = $ri['repo_id'] . "::bugs::" . $data['bug_id'];
508 496 rg_bug_cosmetic($db, $data); rg_bug_cosmetic($db, $data);
509 $rg_bug_info_cache[$key] = $data;
497 rg_cache_set($key, $data);
510 498
511 499 $ret = $data['bug_id']; $ret = $data['bug_id'];
512 500 $rollback = 0; $rollback = 0;
513 } while (0);
501 break;
502 }
514 503
515 504 if ($rollback == 1) if ($rollback == 1)
516 505 rg_sql_rollback($db); rg_sql_rollback($db);
517 506
507 rg_log_exit();
518 508 rg_prof_end("bug_edit"); rg_prof_end("bug_edit");
519 509 return $ret; return $ret;
520 510 } }
 
... ... function rg_bug_edit($db, $login_ui, $ri, $data)
525 515 */ */
526 516 function rg_bug_delete_undelete($db, $who, $repo_id, $bug_id, $op) function rg_bug_delete_undelete($db, $who, $repo_id, $bug_id, $op)
527 517 { {
528 global $rg_bug_info_cache;
529
530 518 rg_prof_start("bug_delete"); rg_prof_start("bug_delete");
531 rg_log("bug_delete_undelete: who=$who repo_id=$repo_id bug_id=$bug_id op=$op");
519 rg_log_enter("bug_delete_undelete: who=$who repo_id=$repo_id bug_id=$bug_id op=$op");
532 520
533 521 $ret = FALSE; $ret = FALSE;
534 do {
522 while (1) {
535 523 $now = time(); $now = time();
536 524 if ($op == 1) if ($op == 1)
537 525 $deleted = $now; $deleted = $now;
 
... ... function rg_bug_delete_undelete($db, $who, $repo_id, $bug_id, $op)
557 545 rg_sql_free_result($res); rg_sql_free_result($res);
558 546
559 547 // update cache // update cache
560 $key = $repo_id . " " . $bug_id;
561 $new = $rg_bug_info_cache[$key];
548 $key = $repo_id . "::bugs::" . $bug_id;
549 $new = array();
562 550 $new['deleted'] = $deleted; $new['deleted'] = $deleted;
563 $new['deleted_who'] = $who;
564 551 $new['utime'] = $now; $new['utime'] = $now;
552 $new['deleted_who'] = $who;
565 553 rg_bug_cosmetic($db, $new); rg_bug_cosmetic($db, $new);
566 $rg_bug_info_cache[$key] = $new;
554 rg_cache_merge($key, $new);
567 555
568 556 $ret = TRUE; $ret = TRUE;
569 } while (0);
557 break;
558 }
570 559
560 rg_log_exit();
571 561 rg_prof_end("bug_delete"); rg_prof_end("bug_delete");
572 562 return $ret; return $ret;
573 563 } }
 
... ... function rg_bug_delete_undelete($db, $who, $repo_id, $bug_id, $op)
578 568 function rg_bug_list_query($db, $sql, $params) function rg_bug_list_query($db, $sql, $params)
579 569 { {
580 570 rg_prof_start("bug_list_query"); rg_prof_start("bug_list_query");
581 rg_log("bug_list_query: sql=$sql...");
571 rg_log_enter("bug_list_query: sql=$sql...");
582 572
583 573 $ret = FALSE; $ret = FALSE;
584 do {
574 while (1) {
585 575 $res = rg_sql_query_params($db, $sql, $params); $res = rg_sql_query_params($db, $sql, $params);
586 576 if ($res === FALSE) { if ($res === FALSE) {
587 577 rg_bug_set_error("cannot list by query (" . rg_sql_error() . ")"); rg_bug_set_error("cannot list by query (" . rg_sql_error() . ")");
 
... ... function rg_bug_list_query($db, $sql, $params)
594 584 $ret[] = array("bug" => $row); $ret[] = array("bug" => $row);
595 585 } }
596 586 rg_sql_free_result($res); rg_sql_free_result($res);
597 } while (0);
587 break;
588 }
598 589
599 590 rg_log("DEBUG: list_query return " . rg_array2string($ret)); rg_log("DEBUG: list_query return " . rg_array2string($ret));
591 rg_log_exit();
600 592 rg_prof_end("bug_list_query"); rg_prof_end("bug_list_query");
601 593 return $ret; return $ret;
602 594 } }
 
... ... function rg_bug_list_query($db, $sql, $params)
607 599 function rg_bug_search_load_all($db, $repo_id, $uid) function rg_bug_search_load_all($db, $repo_id, $uid)
608 600 { {
609 601 rg_prof_start("bug_search_load_all"); rg_prof_start("bug_search_load_all");
610 rg_log("bug_search_load_all: repo_id=$repo_id uid=$uid");
602 rg_log_enter("bug_search_load_all: repo_id=$repo_id uid=$uid");
611 603
612 604 $ret = FALSE; $ret = FALSE;
613 do {
605 while (1) {
614 606 $params = array("repo_id" => $repo_id, "uid" => $uid); $params = array("repo_id" => $repo_id, "uid" => $uid);
615 607 $sql = "SELECT name FROM bug_search" $sql = "SELECT name FROM bug_search"
616 608 . " WHERE (repo_id = @@repo_id@@ OR repo_id = 0)" . " WHERE (repo_id = @@repo_id@@ OR repo_id = 0)"
 
... ... function rg_bug_search_load_all($db, $repo_id, $uid)
638 630 $ret[] = array("name" => $name); $ret[] = array("name" => $name);
639 631
640 632 rg_sql_free_result($res); rg_sql_free_result($res);
641 } while (0);
633 break;
634 }
642 635
636 rg_log_exit();
643 637 rg_prof_end("bug_search_load_all"); rg_prof_end("bug_search_load_all");
644 638 return $ret; return $ret;
645 639 } }
 
... ... function rg_bug_search_load_all($db, $repo_id, $uid)
650 644 function rg_bug_search_load($db, $repo_id, $uid, $name) function rg_bug_search_load($db, $repo_id, $uid, $name)
651 645 { {
652 646 rg_prof_start("bug_search_load"); rg_prof_start("bug_search_load");
653 rg_log("bug_search_load: repo_id=$repo_id uid=$uid name=$name");
647 rg_log_enter("bug_search_load: repo_id=$repo_id uid=$uid name=$name");
654 648
655 649 $ret = FALSE; $ret = FALSE;
656 do {
650 while (1) {
657 651 $template = array( $template = array(
658 652 "name" => $name, "name" => $name,
659 653 "reported_by" => 0, "reported_by" => 0,
 
... ... function rg_bug_search_load($db, $repo_id, $uid, $name)
718 712 $ret = array(); $ret = array();
719 713 } }
720 714 rg_sql_free_result($res); rg_sql_free_result($res);
721 } while (0);
715 break;
716 }
722 717
718 rg_log_exit();
723 719 rg_prof_end("bug_search_load"); rg_prof_end("bug_search_load");
724 720 return $ret; return $ret;
725 721 } }
 
... ... function rg_bug_search_load($db, $repo_id, $uid, $name)
731 727 function rg_bug_search_save($db, $repo_id, $uid, $q) function rg_bug_search_save($db, $repo_id, $uid, $q)
732 728 { {
733 729 rg_prof_start("bug_search_save"); rg_prof_start("bug_search_save");
734 rg_log("rg_bug_search_save: repo_id=$repo_id uid=$uid"
730 rg_log_enter("rg_bug_search_save: repo_id=$repo_id uid=$uid"
735 731 . " q=" . rg_array2string($q)); . " q=" . rg_array2string($q));
736 732
737 733 $ret = FALSE; $ret = FALSE;
738 do {
734 while (1) {
739 735 $name = $q['name']; $name = $q['name'];
740 736 unset($q['name']); unset($q['name']);
741 737
 
... ... function rg_bug_search_save($db, $repo_id, $uid, $q)
785 781 } }
786 782 rg_sql_free_result($res); rg_sql_free_result($res);
787 783 $ret = TRUE; $ret = TRUE;
788 } while (0);
784 break;
785 }
789 786
787 rg_log_exit();
790 788 rg_prof_end("bug_search_save"); rg_prof_end("bug_search_save");
791 789 return $ret; return $ret;
792 790 } }
 
... ... function rg_bug_search_save($db, $repo_id, $uid, $q)
797 795 function rg_bug_search($db, $repo_id, $uid, $q) function rg_bug_search($db, $repo_id, $uid, $q)
798 796 { {
799 797 rg_prof_start("bug_search"); rg_prof_start("bug_search");
800 rg_log("bug_search: repo_id=$repo_id uid=$uid"
798 rg_log_enter("bug_search: repo_id=$repo_id uid=$uid"
801 799 . " q=" . rg_array2string($q)); . " q=" . rg_array2string($q));
802 800
803 801 $params = array("repo_id" => $repo_id); $params = array("repo_id" => $repo_id);
804 802 $add = array(); $add = array();
805 803 $limit = 25; $limit = 25;
806 804 $ret = FALSE; $ret = FALSE;
807 do {
805 while (1) {
808 806 // reported_by // reported_by
809 807 if (!empty($q['reported_by'])) { if (!empty($q['reported_by'])) {
810 808 $_ui = rg_user_info($db, "", $q['reported_by'], "", ""); $_ui = rg_user_info($db, "", $q['reported_by'], "", "");
 
... ... function rg_bug_search($db, $repo_id, $uid, $q)
888 886 // TODO: order // TODO: order
889 887
890 888 $ret = rg_bug_list_query($db, $sql, $params); $ret = rg_bug_list_query($db, $sql, $params);
891 if ($ret === FALSE)
892 break;
893 } while (0);
889 break;
890 }
894 891
892 rg_log_exit();
895 893 rg_prof_end("bug_search"); rg_prof_end("bug_search");
896 894 return $ret; return $ret;
897 895 } }
 
... ... function rg_bug_search($db, $repo_id, $uid, $q)
903 901 function rg_bug_search_remove($db, $repo_id, $uid, $name) function rg_bug_search_remove($db, $repo_id, $uid, $name)
904 902 { {
905 903 rg_prof_start("bug_search_delete"); rg_prof_start("bug_search_delete");
906 rg_log("bug_search_remove: repo_id=$repo_id uid=$uid name=$name");
904 rg_log_enter("bug_search_remove: repo_id=$repo_id uid=$uid name=$name");
907 905
908 906 $ret = FALSE; $ret = FALSE;
909 do {
907 while (1) {
910 908 $params = array("repo_id" => $repo_id, $params = array("repo_id" => $repo_id,
911 909 "uid" => $uid, "uid" => $uid,
912 910 "name" => $name); "name" => $name);
 
... ... function rg_bug_search_remove($db, $repo_id, $uid, $name)
921 919 } }
922 920 rg_sql_free_result($res); rg_sql_free_result($res);
923 921 $ret = TRUE; $ret = TRUE;
924 } while (0);
922 break;
923 }
925 924
925 rg_log_exit();
926 926 rg_prof_end("bug_search_delete"); rg_prof_end("bug_search_delete");
927 927 return $ret; return $ret;
928 928 } }
 
... ... function rg_bug_search_remove($db, $repo_id, $uid, $name)
935 935 function rg_bug_note_add($db, $repo_id, $bug_id, $login_uid, $data) function rg_bug_note_add($db, $repo_id, $bug_id, $login_uid, $data)
936 936 { {
937 937 rg_prof_start("bug_note_add"); rg_prof_start("bug_note_add");
938 rg_log("bug_note_add: repo_id=$repo_id bug_id=$bug_id"
938 rg_log_enter("bug_note_add: repo_id=$repo_id bug_id=$bug_id"
939 939 . " login_uid=$login_uid data: " . rg_array2string($data)); . " login_uid=$login_uid data: " . rg_array2string($data));
940 940
941 941 $ret = FALSE; $ret = FALSE;
942 do {
942 while (1) {
943 943 // TODO: test if user is allowed to add a note // TODO: test if user is allowed to add a note
944 944
945 945 $itime = time(); $itime = time();
 
... ... function rg_bug_note_add($db, $repo_id, $bug_id, $login_uid, $data)
1001 1001 } }
1002 1002
1003 1003 $ret = TRUE; $ret = TRUE;
1004 } while (0);
1004 break;
1005 }
1005 1006
1007 rg_log_exit();
1006 1008 rg_prof_end("bug_note_add"); rg_prof_end("bug_note_add");
1007 1009 return $ret; return $ret;
1008 1010 } }
 
... ... function rg_bug_note_add($db, $repo_id, $bug_id, $login_uid, $data)
1013 1015 function rg_bug_note_list($db, $repo_id, $bug_id, $offset) function rg_bug_note_list($db, $repo_id, $bug_id, $offset)
1014 1016 { {
1015 1017 rg_prof_start("bug_note_list"); rg_prof_start("bug_note_list");
1016 rg_log("bug_note_list: repo_id=$repo_id bug_id=$bug_id");
1018 rg_log_enter("bug_note_list: repo_id=$repo_id bug_id=$bug_id");
1017 1019
1018 1020 $ret = FALSE; $ret = FALSE;
1019 do {
1021 while (1) {
1020 1022 // TODO: test if user is allowed to see a note // TODO: test if user is allowed to see a note
1021 1023
1022 1024 $params = array("repo_id" => $repo_id, $params = array("repo_id" => $repo_id,
 
... ... function rg_bug_note_list($db, $repo_id, $bug_id, $offset)
1048 1050 $ret[] = $row; $ret[] = $row;
1049 1051 } }
1050 1052 rg_sql_free_result($res); rg_sql_free_result($res);
1051 } while (0);
1053 break;
1054 }
1052 1055
1056 rg_log_exit();
1053 1057 rg_prof_end("bug_note_list"); rg_prof_end("bug_note_list");
1054 1058 return $ret; return $ret;
1055 1059 } }
 
... ... function rg_bug_label_diff($a, $b)
1111 1115 function rg_bug_label_get($db, $repo_id, $bug_id) function rg_bug_label_get($db, $repo_id, $bug_id)
1112 1116 { {
1113 1117 rg_prof_start("bug_label_get"); rg_prof_start("bug_label_get");
1114 rg_log("bug_label_get: repo_id=$repo_id bug_id=$bug_id");
1118 rg_log_enter("bug_label_get: repo_id=$repo_id bug_id=$bug_id");
1115 1119
1116 1120 $ret = FALSE; $ret = FALSE;
1117 do {
1121 while (1) {
1118 1122 $params = array("repo_id" => $repo_id, $params = array("repo_id" => $repo_id,
1119 1123 "bug_id" => $bug_id); "bug_id" => $bug_id);
1120 1124 $sql = "SELECT DISTINCT label FROM bug_labels" $sql = "SELECT DISTINCT label FROM bug_labels"
 
... ... function rg_bug_label_get($db, $repo_id, $bug_id)
1130 1134 while (($row = rg_sql_fetch_array($res))) while (($row = rg_sql_fetch_array($res)))
1131 1135 $ret[] = $row['label']; $ret[] = $row['label'];
1132 1136 rg_sql_free_result($res); rg_sql_free_result($res);
1133 } while(0);
1137 break;
1138 }
1134 1139
1140 rg_log_exit();
1135 1141 rg_prof_end("bug_label_get"); rg_prof_end("bug_label_get");
1136 1142 return $ret; return $ret;
1137 1143 } }
 
... ... function rg_bug_label_get($db, $repo_id, $bug_id)
1142 1148 function rg_bug_label_insert($db, $repo_id, $bug_id, $labels) function rg_bug_label_insert($db, $repo_id, $bug_id, $labels)
1143 1149 { {
1144 1150 rg_prof_start("bug_label_insert"); rg_prof_start("bug_label_insert");
1145 rg_log("bug_label_insert: repo_id=$repo_id bug_id=$bug_id labels=$labels");
1151 rg_log_enter("bug_label_insert: repo_id=$repo_id bug_id=$bug_id labels=$labels");
1146 1152
1147 1153 $ret = FALSE; $ret = FALSE;
1148 do {
1154 while (1) {
1149 1155 $labels = rg_bug_label_string2array($labels); $labels = rg_bug_label_string2array($labels);
1150 1156 rg_log("DEBUG: labels: " . rg_array2string($labels)); rg_log("DEBUG: labels: " . rg_array2string($labels));
1151 1157 if (empty($labels)) { if (empty($labels)) {
 
... ... function rg_bug_label_insert($db, $repo_id, $bug_id, $labels)
1183 1189 } }
1184 1190 rg_sql_free_result($res); rg_sql_free_result($res);
1185 1191 $ret = TRUE; $ret = TRUE;
1186 } while (0);
1192 break;
1193 }
1187 1194
1195 rg_log_exit();
1188 1196 rg_prof_end("bug_label_insert"); rg_prof_end("bug_label_insert");
1189 1197 return $ret; return $ret;
1190 1198 } }
 
... ... function rg_bug_label_html($db, $labels)
1215 1223 */ */
1216 1224 function rg_bug_edit_high_level($db, $rg) function rg_bug_edit_high_level($db, $rg)
1217 1225 { {
1218 rg_log("rg_bug_edit_high_level");
1219 //rg_log_ml("rg[bug]=" . print_r($rg['bug'], TRUE));
1220
1221 if (rg_repo_allow($db, "repo", $rg['ri'], $rg['login_ui'], "B", $rg['ip'], "") !== TRUE)
1222 return rg_template("repo/bug/deny_edit.html", $rg);
1226 rg_log_enter("rg_bug_edit_high_level");
1223 1227
1224 1228 $ret = ""; $ret = "";
1225 1229
1226 1230 $errmsg = array(); $errmsg = array();
1227 $show_form = TRUE;
1228 do {
1231 $show_form = FALSE;
1232 while (1) {
1233 if (rg_repo_allow($db, "repo", $rg['ri'], $rg['login_ui'], "B", $rg['ip'], "") !== TRUE) {
1234 $ret .= rg_template("repo/bug/deny_edit.html", $rg);
1235 break;
1236 }
1237
1238 $show_form = TRUE;
1239
1229 1240 if ($rg['doit'] == 0) { if ($rg['doit'] == 0) {
1230 1241 if ($rg['bug']['bug_id'] == 0) if ($rg['bug']['bug_id'] == 0)
1231 1242 $rg['bug'] = rg_bug_vars_defaults(); $rg['bug'] = rg_bug_vars_defaults();
 
... ... function rg_bug_edit_high_level($db, $rg)
1252 1263 rg_redirect($url); rg_redirect($url);
1253 1264
1254 1265 $show_form = FALSE; $show_form = FALSE;
1255 } while (0);
1266 break;
1267 }
1256 1268
1257 1269 if ($show_form) { if ($show_form) {
1258 1270 $rg['HTML:errmsg'] = rg_template_errmsg($errmsg); $rg['HTML:errmsg'] = rg_template_errmsg($errmsg);
 
... ... function rg_bug_edit_high_level($db, $rg)
1269 1281 $ret .= rg_template("repo/bug/bug_add_edit.html", $rg); $ret .= rg_template("repo/bug/bug_add_edit.html", $rg);
1270 1282 } }
1271 1283
1284 rg_log_exit();
1272 1285 return $ret; return $ret;
1273 1286 } }
1274 1287
File inc/cache.inc.php changed (mode: 100644) (index 3bbeb44..fadce23)
... ... $rg_cache_timeout = 100;
15 15 if (!isset($rg_cache_socket)) if (!isset($rg_cache_socket))
16 16 $rg_cache_socket = "/var/lib/rocketgit/sockets/cache.sock"; $rg_cache_socket = "/var/lib/rocketgit/sockets/cache.sock";
17 17
18 $rg_cache = array(
19 "normal" => array()
20 );
18 $rg_cache = array();
21 19
22 20 $rg_cache_error = ""; $rg_cache_error = "";
23 21
 
... ... function rg_cache_error()
36 34 /* /*
37 35 * Dump all tables * Dump all tables
38 36 */ */
39 function rg_cache_server_dump()
37 function rg_cache_core_dump()
40 38 { {
41 39 global $rg_cache; global $rg_cache;
42 40
 
... ... function rg_cache_server_dump()
47 45 * Sets a variable * Sets a variable
48 46 * TODO: Prevent cache to grow and grow. * TODO: Prevent cache to grow and grow.
49 47 */ */
50 function rg_cache_server_set($ns_var, $value)
48 function rg_cache_core_set($ns_var, $value)
51 49 { {
52 50 global $rg_cache; global $rg_cache;
53 51
52 rg_log_ml("cache_core_set: $ns_var = " . print_r($value, TRUE));
53
54 54 $tree = &$rg_cache; $tree = &$rg_cache;
55 55 $t = explode("::", $ns_var); $t = explode("::", $ns_var);
56 56 $var = array_pop($t); $var = array_pop($t);
 
... ... function rg_cache_server_set($ns_var, $value)
64 64 $tree[$var] = $value; $tree[$var] = $value;
65 65 } }
66 66
67 /*
68 * Merges some items into a variable
69 */
70 function rg_cache_core_merge($ns_var, $list)
71 {
72 global $rg_cache;
73
74 rg_log_ml("cache_core_merge: $ns_var = " . print_r($list, TRUE));
75
76 $tree = &$rg_cache;
77 $t = explode("::", $ns_var);
78 foreach ($t as $token) {
79 if (!isset($tree[$token]))
80 $tree[$token] = array();
81
82 $tree = &$tree[$token];
83 }
84
85 foreach ($list as $k => $v)
86 $tree[$k] = $v;
87 }
88
67 89 /* /*
68 90 * Increments a variable * Increments a variable
69 91 */ */
70 function rg_cache_server_inc($ns_var)
92 function rg_cache_core_inc($ns_var)
71 93 { {
72 94 global $rg_cache; global $rg_cache;
73 95
 
... ... function rg_cache_server_inc($ns_var)
94 116 /* /*
95 117 * Retrieve a variable from cache * Retrieve a variable from cache
96 118 */ */
97 function rg_cache_server_get($ns_var)
119 function rg_cache_core_get($ns_var)
98 120 { {
99 121 global $rg_cache; global $rg_cache;
100 122
123 rg_log("cache_core_get: $ns_var");
124
101 125 $tree = &$rg_cache; $tree = &$rg_cache;
102 126 $t = explode("::", $ns_var); $t = explode("::", $ns_var);
103 127 $var = array_pop($t); $var = array_pop($t);
104 128 foreach ($t as $token) { foreach ($t as $token) {
105 if (!isset($tree[$token]))
129 if (!isset($tree[$token])) {
130 rg_log("CHECK: cache_core_get: token '$token' not found, return false");
106 131 return FALSE; return FALSE;
132 }
107 133
108 134 $tree = &$tree[$token]; $tree = &$tree[$token];
109 135 } }
110 136
111 if (isset($tree[$var]))
137 if (isset($tree[$var])) {
138 rg_log_ml("CHECK: cache_core_get: found key in cache: $ns_var = " . print_r($tree[$var], TRUE));
112 139 return $tree[$var]; return $tree[$var];
140 }
113 141
142 rg_log_ml("CHECK: cache_core_get: [$ns_var] not found in rg_cache. rg_cache: " . print_r($rg_cache, TRUE));
114 143 return FALSE; return FALSE;
115 144 } }
116 145
 
... ... function rg_cache_server_get($ns_var)
118 147 * Unset a variable in cache * Unset a variable in cache
119 148 * Returns FALSE if not found, else TRUE. * Returns FALSE if not found, else TRUE.
120 149 */ */
121 function rg_cache_server_unset($ns_var)
150 function rg_cache_core_unset($ns_var)
122 151 { {
123 152 global $rg_cache; global $rg_cache;
124 153
 
... ... function rg_cache_server_unset($ns_var)
126 155 $t = explode("::", $ns_var); $t = explode("::", $ns_var);
127 156 $var = array_pop($t); $var = array_pop($t);
128 157 foreach ($t as $token) { foreach ($t as $token) {
129 if (!isset($tree[$token]))
158 if (!isset($tree[$token])) {
159 rg_log("CHECK: cache_core_unset: token [$token] not found");
130 160 return FALSE; return FALSE;
161 }
131 162
132 163 $tree = &$tree[$token]; $tree = &$tree[$token];
133 164 } }
134 165
135 166 if (isset($tree[$var])) { if (isset($tree[$var])) {
136 167 unset($tree[$var]); unset($tree[$var]);
168 rg_log_ml("CHECK: cache_core_unset: rg_cache=" . print_r($rg_cache, TRUE));
137 169 return TRUE; return TRUE;
138 170 } }
139 171
172 rg_log("CHECK: cache_core_unset: key [$var] not found");
140 173 return FALSE; return FALSE;
141 174 } }
142 175
143 176 /* /*
144 177 * Push a variable in a queue * Push a variable in a queue
145 178 */ */
146 function rg_cache_server_apush($ns_var, $value)
179 function rg_cache_core_apush($ns_var, $value)
147 180 { {
148 181 global $rg_cache; global $rg_cache;
149 182
 
... ... function rg_cache_server_apush($ns_var, $value)
166 199 /* /*
167 200 * Pop a variable from the end of a queue * Pop a variable from the end of a queue
168 201 */ */
169 function rg_cache_server_apop($ns_var)
202 function rg_cache_core_apop($ns_var)
170 203 { {
171 204 global $rg_cache; global $rg_cache;
172 205
 
... ... function rg_cache_server_apop($ns_var)
192 225 /* /*
193 226 * Pop a variable from the begining of a queue * Pop a variable from the begining of a queue
194 227 */ */
195 function rg_cache_server_ashift($ns_var)
228 function rg_cache_core_ashift($ns_var)
196 229 { {
197 230 global $rg_cache; global $rg_cache;
198 231
 
... ... function rg_cache_server_ashift($ns_var)
218 251 /* /*
219 252 * Dumps a queue * Dumps a queue
220 253 */ */
221 function rg_cache_server_adump($ns_var)
254 function rg_cache_core_adump($ns_var)
222 255 { {
223 256 global $rg_cache; global $rg_cache;
224 257
 
... ... function rg_cache_server_adump($ns_var)
241 274
242 275 /********************************* Client side functions */ /********************************* Client side functions */
243 276
244 /*
245 * This is used as another cache layer, local to script
246 */
247 $rg_cache_local = array();
248
249 277 /* /*
250 278 * Returns a variable from the cache daemon * Returns a variable from the cache daemon
251 279 * @timeout_in_ms is the connection timeout not variable timeout. * @timeout_in_ms is the connection timeout not variable timeout.
 
... ... function rg_cache_get($ns_var)
254 282 { {
255 283 global $rg_cache_socket; global $rg_cache_socket;
256 284 global $rg_cache_timeout; global $rg_cache_timeout;
257 global $rg_cache_local;
258 285 global $rg_cache_enable; global $rg_cache_enable;
259 286
260 if ($rg_cache_enable === FALSE)
261 return FALSE;
262
263 287 rg_prof_start("cache_get"); rg_prof_start("cache_get");
288 rg_log_enter("cache_get($ns_var)");
264 289
265 290 $ret = FALSE; $ret = FALSE;
266 do {
267 if (isset($rg_cache_local[$ns_var])) {
268 $ret = $rg_cache_local[$ns_var];
291 while (1) {
292 $ret = rg_cache_core_get($ns_var);
293 if ($ret !== FALSE)
294 break;
295
296 if ($rg_cache_enable === FALSE)
269 297 break; break;
270 }
271 298
272 299 $c = rg_socket($rg_cache_socket, $c = rg_socket($rg_cache_socket,
273 300 "GET " . $ns_var . "\n", $rg_cache_timeout); "GET " . $ns_var . "\n", $rg_cache_timeout);
 
... ... function rg_cache_get($ns_var)
278 305 if (strcmp($t[0], "OK") != 0) if (strcmp($t[0], "OK") != 0)
279 306 break; break;
280 307
281 if (isset($t[1]))
282 $ret = trim($t[1]);
283 else
284 $ret = "";
285 $rg_cache_local[$ns_var] = $ret;
286 } while (0);
308 if (!isset($t[1]))
309 break;
310
311 $ret = @unserialize(trim($t[1]));
312 if ($ret === FALSE)
313 break;
314
315 rg_cache_core_set($ns_var, $ret);
316
317 break;
318 }
287 319
320 rg_log_exit();
288 321 rg_prof_end("cache_get"); rg_prof_end("cache_get");
289 322 return $ret; return $ret;
290 323 } }
 
... ... function rg_cache_set($ns_var, $value)
296 329 { {
297 330 global $rg_cache_socket; global $rg_cache_socket;
298 331 global $rg_cache_timeout; global $rg_cache_timeout;
299 global $rg_cache_local;
300 332 global $rg_cache_enable; global $rg_cache_enable;
301 333
302 if ($rg_cache_enable === FALSE)
303 return FALSE;
304
305 334 rg_prof_start("cache_set"); rg_prof_start("cache_set");
335 rg_log_ml_enter("cache_set: $ns_var = " . print_r($value, TRUE));
306 336
307 337 $ret = FALSE; $ret = FALSE;
308 do {
338 while (1) {
339 rg_cache_core_set($ns_var, $value);
340
341 if ($rg_cache_enable === FALSE)
342 break;
343
309 344 $c = rg_socket($rg_cache_socket, $c = rg_socket($rg_cache_socket,
310 "SET " . $ns_var . "=" . $value . "\n", $rg_cache_timeout);
345 "SET " . $ns_var . "=" . serialize($value) . "\n", $rg_cache_timeout);
311 346 if ($c === FALSE) if ($c === FALSE)
312 347 break; break;
313 348
314 349 if (strncmp($c, "OK", 2) != 0) if (strncmp($c, "OK", 2) != 0)
315 350 break; break;
316 351
317 $rg_cache_local[$ns_var] = $value;
318 352 $ret = TRUE; $ret = TRUE;
319 } while (0);
353 break;
354 }
320 355
356 rg_log_exit();
321 357 rg_prof_end("cache_set"); rg_prof_end("cache_set");
322 358 return $ret; return $ret;
323 359 } }
 
... ... function rg_cache_inc($ns_var)
329 365 { {
330 366 global $rg_cache_socket; global $rg_cache_socket;
331 367 global $rg_cache_timeout; global $rg_cache_timeout;
332 global $rg_cache_local;
333 368 global $rg_cache_enable; global $rg_cache_enable;
334 369
335 if ($rg_cache_enable === FALSE)
336 return FALSE;
337
338 370 rg_prof_start("cache_inc"); rg_prof_start("cache_inc");
371 rg_log_enter("cache_inc($ns_var)");
339 372
340 373 $ret = FALSE; $ret = FALSE;
341 do {
374 while (1) {
375 rg_cache_core_inc($vs_var);
376
377 if ($rg_cache_enable === FALSE)
378 break;
379
342 380 $c = rg_socket($rg_cache_socket, $c = rg_socket($rg_cache_socket,
343 381 "INC " . $ns_var . "\n", $rg_cache_timeout); "INC " . $ns_var . "\n", $rg_cache_timeout);
344 382 if ($c === FALSE) if ($c === FALSE)
 
... ... function rg_cache_inc($ns_var)
352 390 break; break;
353 391
354 392 $ret = intval($v); $ret = intval($v);
355 } while (0);
393 break;
394 }
356 395
396 rg_log_exit();
357 397 rg_prof_end("cache_inc"); rg_prof_end("cache_inc");
358 398 return $ret; return $ret;
359 399 } }
 
... ... function rg_cache_unset($ns_var)
365 405 { {
366 406 global $rg_cache_socket; global $rg_cache_socket;
367 407 global $rg_cache_timeout; global $rg_cache_timeout;
368 global $rg_cache_local;
369 408 global $rg_cache_enable; global $rg_cache_enable;
370 409
371 if ($rg_cache_enable === FALSE)
372 return FALSE;
373
374 410 rg_prof_start("cache_unset"); rg_prof_start("cache_unset");
375
376 unset($rg_cache_local[$ns_var]);
411 rg_log_enter("cache_unset($ns_var)");
377 412
378 413 $ret = FALSE; $ret = FALSE;
379 do {
414 while (1) {
415 rg_cache_core_unset($ns_var);
416
417 if ($rg_cache_enable === FALSE)
418 break;
419
380 420 $ret = rg_socket($rg_cache_socket, $ret = rg_socket($rg_cache_socket,
381 421 "UNSET " . $ns_var . "\n", $rg_cache_timeout); "UNSET " . $ns_var . "\n", $rg_cache_timeout);
382 422 if ($ret === FALSE) if ($ret === FALSE)
 
... ... function rg_cache_unset($ns_var)
387 427 break; break;
388 428
389 429 $ret = TRUE; $ret = TRUE;
390 } while (0);
430 break;
431 }
391 432
433 rg_log_exit();
392 434 rg_prof_end("cache_unset"); rg_prof_end("cache_unset");
393 435 return $ret; return $ret;
394 436 } }
395 437
438 /*
439 * Merge some k=v pairs into an existing cache
440 */
441 function rg_cache_merge($ns_var, $list)
442 {
443 global $rg_cache_socket;
444 global $rg_cache_timeout;
445 global $rg_cache_enable;
446
447 rg_prof_start("cache_merge");
448 rg_log_ml_enter("cache_merge: $ns_var = " . print_r($list, TRUE));
449
450 $ret = FALSE;
451 while (1) {
452 rg_cache_core_merge($ns_var, $list);
453
454 if ($rg_cache_enable === FALSE)
455 break;
456
457 $c = rg_socket($rg_cache_socket,
458 "MERGE " . $ns_var . "=" . serialize($list) . "\n", $rg_cache_timeout);
459 if ($c === FALSE)
460 break;
461
462 if (strncmp($c, "OK", 2) != 0)
463 break;
464
465 $ret = TRUE;
466 break;
467 }
468
469 rg_log_exit();
470 rg_prof_end("cache_merge");
471 return $ret;
472 }
473
396 474 ?> ?>
File inc/fixes.inc.php changed (mode: 100644) (index 4ed3a9b..023bb12)
... ... $rg_fixes_ver = count($rg_fixes);
25 25 */ */
26 26 function rg_fixes_repos_last_bug_id($db) function rg_fixes_repos_last_bug_id($db)
27 27 { {
28 rg_log("rg_fixes_repos_last_bug_id");
29
30 $res = rg_sql_begin($db);
31 if (!$res)
32 return FALSE;
33
34 $sql = "SELECT * FROM bugs_max";
35 $res = rg_sql_query($db, $sql);
36 if (!$res)
37 return FALSE;
38
39 while (($row = rg_sql_fetch_array($res))) {
40 $repo_id = $row['repo_id'];
41 $last = $row['last_bug_id'];
42
43 $params = array("repo_id" => $repo_id, "last" => $last);
44 $sql = "UPDATE repos SET last_bug_id = @@last@@"
45 . " WHERE repo_id = @@repo_id@@";
46 $res2 = rg_sql_query_params($db, $sql, $params);
47 if (!$res2)
48 return FALSE;
49 rg_sql_free_result($res2);
50 }
51 rg_sql_free_result($res);
28 rg_log_enter("rg_fixes_repos_last_bug_id");
52 29
53 $sql = "DROP TABLE bugs_max";
54 $res = rg_sql_query($db, $sql);
55 if (!$res)
56 return FALSE;
30 $ret = FALSE;
31 while (1) {
32 $res = rg_sql_begin($db);
33 if (!$res)
34 break;
57 35
58 $res = rg_sql_commit($db);
59 if (!$res)
60 return FALSE;
36 $sql = "SELECT * FROM bugs_max";
37 $res = rg_sql_query($db, $sql);
38 if (!$res)
39 break;
61 40
62 rg_log("Done!");
63 return TRUE;
41 $error = FALSE;
42 while (($row = rg_sql_fetch_array($res))) {
43 $repo_id = $row['repo_id'];
44 $last = $row['last_bug_id'];
45
46 $params = array("repo_id" => $repo_id, "last" => $last);
47 $sql = "UPDATE repos SET last_bug_id = @@last@@"
48 . " WHERE repo_id = @@repo_id@@";
49 $res2 = rg_sql_query_params($db, $sql, $params);
50 if (!$res2) {
51 $error = TRUE;
52 break;
53 }
54
55 rg_sql_free_result($res2);
56 }
57 rg_sql_free_result($res);
58
59 if ($error)
60 break;
61
62 $sql = "DROP TABLE bugs_max";
63 $res = rg_sql_query($db, $sql);
64 if (!$res)
65 break;
66
67 $res = rg_sql_commit($db);
68 if (!$res)
69 break;
70
71 $ret = TRUE;
72 break;
73 }
74
75 rg_log_exit();
76 return $ret;
64 77 } }
65 78
66 79 /* /*
 
... ... function rg_fixes_repos_last_bug_id($db)
68 81 */ */
69 82 function rg_fixes_keys_regen($db) function rg_fixes_keys_regen($db)
70 83 { {
71 rg_log("fixes_keys_regen");
84 rg_log_enter("fixes_keys_regen");
72 85 $ret = rg_keys_regen($db); $ret = rg_keys_regen($db);
73 if ($ret === FALSE) {
86 if ($ret === FALSE)
74 87 rg_log("Could not regenerate keys: " . rg_keys_error() . "!"); rg_log("Could not regenerate keys: " . rg_keys_error() . "!");
75 }
76 88
89 rg_log_exit();
77 90 return $ret; return $ret;
78 91 } }
79 92
 
... ... function rg_fixes_keys_regen($db)
82 95 */ */
83 96 function rg_fixes_repo_index_by_id_one($uid, $repo_id, $repo_name) function rg_fixes_repo_index_by_id_one($uid, $repo_id, $repo_name)
84 97 { {
85 rg_log("fixes_repo_index_by_id_one:"
98 rg_log_enter("fixes_repo_index_by_id_one:"
86 99 . " uid=$uid repo_id=$repo_id repo_name=$repo_name"); . " uid=$uid repo_id=$repo_id repo_name=$repo_name");
87 100
88 101 $ret = FALSE; $ret = FALSE;
89 do {
102 while (1) {
90 103 // we expect to have a folder .../repos/by_id // we expect to have a folder .../repos/by_id
91 104 $by_id = rg_repo_path_by_id($uid, $repo_id); $by_id = rg_repo_path_by_id($uid, $repo_id);
92 105 $p = dirname($by_id); $p = dirname($by_id);
 
... ... function rg_fixes_repo_index_by_id_one($uid, $repo_id, $repo_name)
125 138 } }
126 139
127 140 $ret = TRUE; $ret = TRUE;
128 } while (0);
141 break;
142 }
129 143
144 rg_log_exit();
130 145 return $ret; return $ret;
131 146 } }
132 147
133 148 /* /*
134 149 * Reindex repos by id so we can rename repos easier. * Reindex repos by id so we can rename repos easier.
135 * And is more normal to index them by the unique id.
150 * And is more natural to index them by the unique id.
136 151 */ */
137 152 function rg_fixes_repo_index_by_id($db) function rg_fixes_repo_index_by_id($db)
138 153 { {
139 154 rg_prof_start("fixes_repo_index_by_id"); rg_prof_start("fixes_repo_index_by_id");
155 rg_log_enter("fixes_repo_index_by_id");
140 156
141 157 $ret = FALSE; $ret = FALSE;
142 do {
158 while (1) {
143 159 $sql = "SELECT uid, repo_id, name FROM repos" $sql = "SELECT uid, repo_id, name FROM repos"
144 160 . " WHERE git_dir_done > 0"; . " WHERE git_dir_done > 0";
145 161 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
 
... ... function rg_fixes_repo_index_by_id($db)
161 177 break; break;
162 178
163 179 $ret = TRUE; $ret = TRUE;
164 } while (0);
180 break;
181 }
165 182
183 rg_log_exit();
166 184 rg_prof_end("fixes_repo_index_by_id"); rg_prof_end("fixes_repo_index_by_id");
167 185 return $ret; return $ret;
168 186 } }
 
... ... function rg_fixes_user_index_by_id_one($uid, $username)
174 192 { {
175 193 global $rg_repos; global $rg_repos;
176 194
177 rg_log("Fix user path: uid=$uid username=$username");
195 rg_log_enter("fixes_user_index_by_id_one: uid=$uid username=$username");
178 196
179 197 $ret = FALSE; $ret = FALSE;
180 do {
198 while (1) {
181 199 $user_path_uid = rg_user_path_by_id($uid); $user_path_uid = rg_user_path_by_id($uid);
182 200 $user_path_name = rg_user_path_by_name($username); $user_path_name = rg_user_path_by_name($username);
183 201 rg_log("\tuser_path=[$user_path_uid][$user_path_name]"); rg_log("\tuser_path=[$user_path_uid][$user_path_name]");
 
... ... function rg_fixes_user_index_by_id_one($uid, $username)
224 242 } }
225 243
226 244 $ret = TRUE; $ret = TRUE;
227 } while (0);
245 break;
246 }
228 247
248 rg_log_exit();
229 249 return $ret; return $ret;
230 250 } }
231 251
232 252 /* /*
233 253 * Reindex users by id so we can rename users easier. * Reindex users by id so we can rename users easier.
234 * And is more normal to index them by the unique id.
254 * And is more natural to index them by the unique id.
235 255 */ */
236 256 function rg_fixes_user_index_by_id($db) function rg_fixes_user_index_by_id($db)
237 257 { {
238 258 global $rg_repos; global $rg_repos;
239 259
240 260 rg_prof_start("fixes_user_index_by_id"); rg_prof_start("fixes_user_index_by_id");
261 rg_log_enter("fixes_user_index_by_id");
241 262
242 263 $ret = FALSE; $ret = FALSE;
243 do {
264 while (1) {
244 265 $sql = "SELECT uid, username FROM users"; $sql = "SELECT uid, username FROM users";
245 266 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
246 267 if ($res === FALSE) if ($res === FALSE)
 
... ... function rg_fixes_user_index_by_id($db)
269 290 } }
270 291
271 292 $ret = TRUE; $ret = TRUE;
272 } while (0);
293 break;
294 }
273 295
296 rg_log_exit();
274 297 rg_prof_end("fixes_user_index_by_id"); rg_prof_end("fixes_user_index_by_id");
275 298 return $ret; return $ret;
276 299 } }
 
... ... function rg_fixes_needed($db)
308 331 { {
309 332 global $rg_fixes_ver; global $rg_fixes_ver;
310 333
311 rg_log("fixes_needed:");
334 rg_log_enter("fixes_needed");
312 335
313 $old = rg_state_get($db, "fixes_version");
314 if ($old === FALSE) {
315 //TODO: error rg_log("\tDEBUG: schema is up to date!");
316 return FALSE;
317 }
336 $ret = FALSE;
337 while (1) {
338 $old = rg_state_get($db, "fixes_version");
339 if ($old === FALSE) {
340 //TODO: error rg_log("\tDEBUG: schema is up to date!");
341 break;
342 }
318 343
319 if (empty($old))
320 $old = 0;
344 if (empty($old))
345 $old = 0;
321 346
322 rg_log("\tDEBUG: old=$old new=$rg_fixes_ver");
323 if ($old == $rg_fixes_ver) {
324 rg_log("\tDEBUG: fixes are up to date!");
325 return FALSE;
347 rg_log("DEBUG: old=$old new=$rg_fixes_ver");
348 if ($old == $rg_fixes_ver) {
349 rg_log("DEBUG: fixes are up to date!");
350 break;
351 }
352
353 $ret = TRUE;
354 break;
326 355 } }
327 356
328 return $old;
357 rg_log_exit();
358 return $ret;
329 359 } }
330 360
331 361 /* /*
 
... ... function rg_fixes_update($db)
337 367 { {
338 368 global $rg_fixes_ver; global $rg_fixes_ver;
339 369
340 rg_log("fixes_update:");
370 rg_log_enter("fixes_update");
341 371
342 $old = rg_fixes_needed($db);
343 if ($old === FALSE)
344 return TRUE;
372 $ret = FALSE;
373 while (1) {
374 $old = rg_fixes_needed($db);
375 if ($old === FALSE) {
376 $ret = TRUE;
377 break;
378 }
345 379
346 // If we cannot lock, return error
347 if (rg_lock("fixes.lock") === FALSE)
348 return FALSE;
380 // If we cannot lock, return error
381 if (rg_lock("fixes.lock") === FALSE)
382 break;
349 383
350 $ret = FALSE;
351 $rollback = 0;
352 do {
353 384 $r = rg_fixes_run($db, $old); $r = rg_fixes_run($db, $old);
354 385 if ($r !== TRUE) { if ($r !== TRUE) {
355 386 rg_internal_error("Cannot apply fixes."); rg_internal_error("Cannot apply fixes.");
 
... ... function rg_fixes_update($db)
363 394 } }
364 395
365 396 $ret = TRUE; $ret = TRUE;
366 } while (0);
397 break;
398 }
367 399
368 400 rg_unlock("fixes.lock"); rg_unlock("fixes.lock");
369 401
402 rg_log_exit();
370 403 return $ret; return $ret;
371 404 } }
372 405
File inc/git.inc.php changed (mode: 100644) (index 59e7a1b..65abdab)
... ... function rg_git_rev($rev)
249 249 */ */
250 250 function rg_git_reference($refname) function rg_git_reference($refname)
251 251 { {
252 if (!preg_match("/[a-zA-Z0-9^~\/_]/", $refname))
252 if (!preg_match('/^[a-zA-Z0-9^~\/_]$/D', $refname))
253 253 return ""; return "";
254 254
255 255 return $refname; return $refname;
 
... ... function rg_git_stats($log)
738 738 function rg_git_files($old, $new) function rg_git_files($old, $new)
739 739 { {
740 740 rg_log("rg_git_files old=$old new=$new"); rg_log("rg_git_files old=$old new=$new");
741 rg_prof_start("git_files");
741 742
742 743 // TODO: Here we can deny non ascii file names. Move to update_branch? // TODO: Here we can deny non ascii file names. Move to update_branch?
743 744 // git diff --cached --name-only --diff-filter=A -z $against | LC_ALL=C tr -d '[ -~]\0') // git diff --cached --name-only --diff-filter=A -z $against | LC_ALL=C tr -d '[ -~]\0')
744 745
745 $cmd = "git diff --name-only " . escapeshellarg($old) . " " . escapeshellarg($new);
746 rg_log("DEBUG: cmd=$cmd");
747 $a = rg_exec($cmd);
748 if ($a['ok'] != 1) {
749 rg_git_set_error("error on ls-tree (" . $a['errmsg'] . ")");
750 break;
751 }
746 $ret = FALSE;
747 while (1) {
748 $cmd = "git diff --name-only " . escapeshellarg($old) . " " . escapeshellarg($new);
749 $a = rg_exec($cmd);
750 if ($a['ok'] != 1) {
751 rg_git_set_error("error on ls-tree (" . $a['errmsg'] . ")");
752 break;
753 }
754
755 if (empty($a['data'])) {
756 rg_git_set_error("error on ls-tree: empty answer");
757 break;
758 }
752 759
753 if (empty($a['data'])) {
754 rg_git_set_error("error on ls-tree: empty answer");
760 $ret = explode("\n", trim($a['data']));
755 761 break; break;
756 762 } }
757 763
758 $output = explode("\n", trim($a['data']));
759 $ret = array();
760 foreach ($output as $line) {
761 rg_log("FILE: $line");
762 }
764 rg_prof_end("git_files");
765 return $ret;
763 766 } }
764 767
765 768 /* /*
 
... ... function rg_git_files($old, $new)
771 774 function rg_git_diff($a, $template_file) function rg_git_diff($a, $template_file)
772 775 { {
773 776 //rg_log("DEBUG: git_diff: a: " . rg_array2string($a)); //rg_log("DEBUG: git_diff: a: " . rg_array2string($a));
777 rg_prof_start("git_diff");
774 778
775 779 $ret = "<div class=\"diff\">\n"; $ret = "<div class=\"diff\">\n";
776 780
 
... ... function rg_git_diff($a, $template_file)
856 860 } }
857 861 $ret .= "</div>\n"; $ret .= "</div>\n";
858 862
863 rg_prof_end("git_diff");
859 864 return $ret; return $ret;
860 865 } }
861 866
 
... ... function rg_git_update_tag($a)
884 889 { {
885 890 global $rg_git_zero; global $rg_git_zero;
886 891
892 rg_prof_start("git_update_tag");
887 893 rg_log("git_update_tag: " . rg_array2string($a)); rg_log("git_update_tag: " . rg_array2string($a));
888 894
889 895 $ip = $a['ip']; $ip = $a['ip'];
 
... ... function rg_git_update_tag($a)
933 939
934 940 // We can clean now the namespace - TODO // We can clean now the namespace - TODO
935 941 } }
942
943 rg_prof_end("git_update_tag");
936 944 } }
937 945
938 946 /* /*
 
... ... function rg_git_update_branch($a)
942 950 { {
943 951 global $rg_git_zero; global $rg_git_zero;
944 952
953 rg_prof_start("git_update_branch");
945 954 rg_log("git_update_branch: " . rg_array2string($a)); rg_log("git_update_branch: " . rg_array2string($a));
946 955
947 956 $ip = $a['ip']; $ip = $a['ip'];
 
... ... function rg_git_update_branch($a)
987 996
988 997 // Check for bad whitespace // Check for bad whitespace
989 998 if (!rg_rights_allow($a['refs_rights'], "W", $ip, $a['refname'])) { if (!rg_rights_allow($a['refs_rights'], "W", $ip, $a['refname'])) {
999 // TODO: add caching because we may check again below
990 1000 $w = rg_git_whitespace_ok($a['old_rev'], $a['new_rev']); $w = rg_git_whitespace_ok($a['old_rev'], $a['new_rev']);
991 1001 if ($w !== TRUE) if ($w !== TRUE)
992 1002 rg_git_fatal($a['refname'] rg_git_fatal($a['refname']
 
... ... function rg_git_update_branch($a)
996 1006
997 1007 // Check repo_path rights TODO // Check repo_path rights TODO
998 1008 $r = rg_git_files($a['old_rev'], $a['new_rev']); $r = rg_git_files($a['old_rev'], $a['new_rev']);
1009 if ($r === FALSE)
1010 rg_git_fatal($a['refname'] . "\nInternal error, try again later\n");
1011 foreach ($r as $file) {
1012 if (rg_rights_allow($a['repo_path'], "P", $ip, $file) !== TRUE) {
1013 rg_git_fatal($a['refname']
1014 . "\nNo rights to push file [$path]\n");
1015 }
1016
1017 if (!rg_rights_allow($a['repo_path'], "W", $ip, $a['refname'])) {
1018 $w = rg_git_whitespace_ok($a['old_rev'], $a['new_rev']);
1019 if ($w !== TRUE) {
1020 rg_git_fatal($a['refname']
1021 . "\nNo rights to push bad whitespace on path [$file]:"
1022 . "\n" . $w);
1023 }
1024 }
1025 }
999 1026
1000 1027 if (rg_rights_allow($a['refs_rights'], "P", $ip, $a['refname']) !== TRUE) { if (rg_rights_allow($a['refs_rights'], "P", $ip, $a['refname']) !== TRUE) {
1001 1028 rg_log("\tPush is not allowed, let's see the anon one"); rg_log("\tPush is not allowed, let's see the anon one");
 
... ... function rg_git_update_branch($a)
1041 1068 // We can clean now the namespace - TODO // We can clean now the namespace - TODO
1042 1069 } }
1043 1070 } }
1071
1072 rg_prof_end("git_update_branch");
1044 1073 } }
1045 1074
1046 1075 /* /*
 
... ... function rg_git_parse_ref(&$paras)
1150 1179 function rg_git_diff_tree($tree1, $tree2) function rg_git_diff_tree($tree1, $tree2)
1151 1180 { {
1152 1181 rg_prof_start("git_diff_tree"); rg_prof_start("git_diff_tree");
1153
1154 1182 rg_log("rg_git_diff_tree: tree1=$tree1 tree2=$tree2"); rg_log("rg_git_diff_tree: tree1=$tree1 tree2=$tree2");
1155 1183
1156 1184 $ret = array(); $ret = array();
1157 1185
1158 1186 $cmd = "git diff-tree -r " . escapeshellarg($tree1) $cmd = "git diff-tree -r " . escapeshellarg($tree1)
1159 1187 . " " . escapeshellarg($tree2); . " " . escapeshellarg($tree2);
1160 rg_log("DEBUG: cmd=$cmd");
1161 1188 $a = rg_exec($cmd); $a = rg_exec($cmd);
1162 1189 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
1163 1190 rg_git_set_error("error on diff-tree (" . $a['errmsg'] . ")"); rg_git_set_error("error on diff-tree (" . $a['errmsg'] . ")");
 
... ... function rg_git_diff_tree($tree1, $tree2)
1179 1206 $ret[] = $_y; $ret[] = $_y;
1180 1207 } }
1181 1208
1182 rg_prof_end("git_diff_tree");
1183
1184 1209 rg_log("DEBUG: diff-tree: " . rg_array2string($ret)); rg_log("DEBUG: diff-tree: " . rg_array2string($ret));
1185 1210
1211 rg_prof_end("git_diff_tree");
1186 1212 return $ret; return $ret;
1187 1213 } }
1188 1214 ?> ?>
File inc/init.inc.php changed (mode: 100644) (index d7f2495..1919431)
... ... $rg['rg_ssh_port'] = $rg_ssh_port;
18 18
19 19 $rg['rg_version'] = $rocketgit_version; $rg['rg_version'] = $rocketgit_version;
20 20
21 if (!isset($rg_scripts))
22 $rg_scripts = dirname(__FILE__) . "/..";
23
21 24 if (!isset($rg_theme_dir)) if (!isset($rg_theme_dir))
22 25 $rg_theme_dir = $rg_scripts . "/root/themes"; $rg_theme_dir = $rg_scripts . "/root/themes";
23 26
File inc/log.inc.php changed (mode: 100644) (index 3beda30..098c2e6)
... ... if (!isset($rg_log_dir))
8 8 if (!isset($rg_web_log_dir)) if (!isset($rg_web_log_dir))
9 9 $rg_web_log_dir = "/var/log/rocketgit-web"; $rg_web_log_dir = "/var/log/rocketgit-web";
10 10
11 if (isset($_SERVER['REMOTE_ADDR']))
12 $rg_log_file = $rg_web_log_dir . "/fallback.log";
13 else
14 $rg_log_file = $rg_log_dir . "/fallback.log";
11 if (!isset($rg_log_file)) {
12 if (isset($_SERVER['REMOTE_ADDR']))
13 $rg_log_file = $rg_web_log_dir . "/fallback.log";
14 else
15 $rg_log_file = $rg_log_dir . "/fallback.log";
16 }
15 17 $rg_log_fd = FALSE; $rg_log_fd = FALSE;
16 18 $rg_log_sid = rg_id(6); $rg_log_sid = rg_id(6);
17 19 $rg_log_buf = ""; $rg_log_buf = "";
18 20 $rg_log_last_date = ""; $rg_log_last_date = "";
21 $rg_log_level = 0;
19 22
20 23 /* /*
21 24 * Clears 'rg_log_buf' to not send a big log in case of errors * Clears 'rg_log_buf' to not send a big log in case of errors
 
... ... function rg_log_set_file($file)
55 58
56 59 function rg_log($str) function rg_log($str)
57 60 { {
61 global $rg_log_level;
58 62 global $rg_log_file; global $rg_log_file;
59 63 global $rg_log_fd; global $rg_log_fd;
60 64 global $rg_log_sid; global $rg_log_sid;
 
... ... function rg_log($str)
86 90 } }
87 91 } }
88 92
93 // We insert some spaces based on backtrace len
94 $spaces = "";
95 for ($i = 0; $i < $rg_log_level; $i++)
96 $spaces .= " ";
97
89 98 $t = gettimeofday(); $t = gettimeofday();
90 99
91 100 $buf0 = gmdate("Y-m-d H:i:s", $t['sec']) . "." . sprintf("%03u", $t['usec'] / 1000); $buf0 = gmdate("Y-m-d H:i:s", $t['sec']) . "." . sprintf("%03u", $t['usec'] / 1000);
 
... ... function rg_log($str)
93 102 $buf0 .= " " . $rg_log_sid; $buf0 .= " " . $rg_log_sid;
94 103 $buf = ""; $buf = "";
95 104 $str = preg_replace_callback('/[^\pL\pN\pP\pS \t]/uU', "rg_callback_hexa", $str); $str = preg_replace_callback('/[^\pL\pN\pP\pS \t]/uU', "rg_callback_hexa", $str);
96 $buf .= $buf0 . " " . $str . "\n";
105 $buf .= $buf0 . " " . $spaces . $str . "\n";
97 106
98 107 $rg_log_buf .= $buf; $rg_log_buf .= $buf;
99 108
100 if ($rg_log_fd !== NULL)
101 fwrite($rg_log_fd, $buf);
109 fwrite($rg_log_fd, $buf);
102 110 } }
103 111
104 112 /* /*
 
... ... function rg_security_violation($msg)
223 231 exit(1); exit(1);
224 232 } }
225 233
234 function rg_log_enter($a)
235 {
236 global $rg_log_level;
237
238 $rg_log_level++;
239 rg_log($a);
240 }
241
242 function rg_log_ml_enter($a)
243 {
244 global $rg_log_level;
245
246 $rg_log_level++;
247 rg_log_ml($a);
248 }
249
250 function rg_log_exit()
251 {
252 global $rg_log_level;
253
254 $rg_log_level--;
255 }
256
226 257 ?> ?>
File inc/plan.inc.php changed (mode: 100644) (index 989312b..5ee27fc)
... ... function rg_plan_ok($name)
37 37 function rg_plan_edit($db, $d) function rg_plan_edit($db, $d)
38 38 { {
39 39 rg_prof_start("plan_edit"); rg_prof_start("plan_edit");
40 rg_log("plan_edit: d: " . rg_array2string($d));
40 rg_log_enter("plan_edit: d: " . rg_array2string($d));
41 41
42 42 $ret = FALSE; $ret = FALSE;
43 do {
43 while (1) {
44 44 if (rg_plan_ok($d['name']) !== TRUE) if (rg_plan_ok($d['name']) !== TRUE)
45 45 break; break;
46 46
 
... ... function rg_plan_edit($db, $d)
83 83 rg_cache_unset("plan::list"); rg_cache_unset("plan::list");
84 84
85 85 $ret = $row['id']; $ret = $row['id'];
86 } while (0);
86 break;
87 }
87 88
89 rg_log_exit();
88 90 rg_prof_end("plan_edit"); rg_prof_end("plan_edit");
89 91 return $ret; return $ret;
90 92 } }
 
... ... function rg_plan_edit($db, $d)
95 97 function rg_plan_remove($db, $list) function rg_plan_remove($db, $list)
96 98 { {
97 99 rg_prof_start("plan_remove"); rg_prof_start("plan_remove");
98 rg_log("plan_remove: list=" . rg_array2string($list));
100 rg_log_enter("plan_remove: list=" . rg_array2string($list));
99 101
100 102 $ret = FALSE; $ret = FALSE;
101 do {
103 while (1) {
102 104 $my_list = array(); $my_list = array();
103 105 foreach ($list as $id => $junk) foreach ($list as $id => $junk)
104 106 $my_list[] = sprintf("%u", $id); $my_list[] = sprintf("%u", $id);
 
... ... function rg_plan_remove($db, $list)
117 119 rg_cache_unset("plan::list"); rg_cache_unset("plan::list");
118 120
119 121 $ret = TRUE; $ret = TRUE;
120 } while (0);
122 break;
123 }
121 124
125 rg_log_exit();
122 126 rg_prof_end("plan_remove"); rg_prof_end("plan_remove");
123 127 return $ret; return $ret;
124 128 } }
 
... ... function rg_plan_remove($db, $list)
129 133 function rg_plan_list($db) function rg_plan_list($db)
130 134 { {
131 135 rg_prof_start("plan_list"); rg_prof_start("plan_list");
136 rg_log_enter("plan_list");
132 137
133 138 $ret = FALSE; $ret = FALSE;
134 do {
135 $c = rg_cache_get("plan::list");
136 if ($c !== FALSE) {
137 $ret = unserialize($c);
139 while (1) {
140 $ret = rg_cache_get("plan::list");
141 if ($ret !== FALSE)
138 142 break; break;
139 }
140 143
141 144 $sql = "SELECT * FROM plans ORDER BY position"; $sql = "SELECT * FROM plans ORDER BY position";
142 145 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
 
... ... function rg_plan_list($db)
159 162 } }
160 163 rg_sql_free_result($res); rg_sql_free_result($res);
161 164
162 rg_cache_set("plan::list", serialize($ret));
163 } while (0);
165 rg_cache_set("plan::list", $ret);
166 break;
167 }
164 168
169 rg_log_exit();
165 170 rg_prof_end("plan_list"); rg_prof_end("plan_list");
166 171 return $ret; return $ret;
167 172 } }
 
... ... function rg_plan_list($db)
172 177 function rg_plan_info($db, $id) function rg_plan_info($db, $id)
173 178 { {
174 179 rg_prof_start("plan_info"); rg_prof_start("plan_info");
180 rg_log_enter("plan_info: id=$id");
175 181
176 182 $ret = array(); $ret = array();
177 183 $ret['ok'] = 0; $ret['ok'] = 0;
178 184 $ret['exists'] = 0; $ret['exists'] = 0;
179 185
180 do {
186 while (1) {
181 187 $list = rg_plan_list($db); $list = rg_plan_list($db);
182 188 if ($list === FALSE) { if ($list === FALSE) {
183 189 rg_plan_set_error("cannot load plans" rg_plan_set_error("cannot load plans"
 
... ... function rg_plan_info($db, $id)
192 198 break; break;
193 199
194 200 $ret = array_merge($ret, $list[$id]); $ret = array_merge($ret, $list[$id]);
195 } while (0);
201 break;
202 }
196 203
204 rg_log_exit();
197 205 rg_prof_end("plan_info"); rg_prof_end("plan_info");
198 206 return $ret; return $ret;
199 207 } }
 
... ... function rg_plan_list_high_level($db, $rg)
233 241 $del_errmsg = array(); $del_errmsg = array();
234 242
235 243 $delete = rg_var_uint("delete"); $delete = rg_var_uint("delete");
236 do {
244 while (1) {
237 245 if ($delete != 1) if ($delete != 1)
238 246 break; break;
239 247
 
... ... function rg_plan_list_high_level($db, $rg)
249 257 $del_errmsg[] = rg_template("admin/plans/delete_err.html", $rg); $del_errmsg[] = rg_template("admin/plans/delete_err.html", $rg);
250 258 break; break;
251 259 } }
252 } while (0);
260 break;
261 }
253 262
254 263 $list = rg_plan_list($db); $list = rg_plan_list($db);
255 264 if ($list === FALSE) { if ($list === FALSE) {
 
... ... function rg_plan_edit_high_level($db, $rg)
299 308
300 309 $errmsg = array(); $errmsg = array();
301 310 $load_form = TRUE; $load_form = TRUE;
302 do {
311 while (1) {
303 312 if ($rg['doit'] != 1) if ($rg['doit'] != 1)
304 313 break; break;
305 314
 
... ... function rg_plan_edit_high_level($db, $rg)
328 337
329 338 $ret .= rg_template("admin/plans/add_ok.html", $rg); $ret .= rg_template("admin/plans/add_ok.html", $rg);
330 339 $load_form = FALSE; $load_form = FALSE;
331 } while (0);
340 break;
341 }
332 342
333 343 if ($load_form) { if ($load_form) {
334 344 $rg['pi'] = $pi; $rg['pi'] = $pi;
File inc/repo.inc.php changed (mode: 100644) (index 2af0cee..093908b)
... ... $rg_repo_rights = array(
44 44 // TODO: default rights should go into conf file? // TODO: default rights should go into conf file?
45 45 // TODO: better move all config to database (modulo db conn info)? // TODO: better move all config to database (modulo db conn info)?
46 46
47 rg_rights_register("repo_refs", $rg_repo_refs_rights, "FMH");
48 rg_rights_register("repo_path", $rg_repo_path_rights, "P");
49 rg_rights_register("repo", $rg_repo_rights, "AB");
47 rg_rights_register("repo_refs", $rg_repo_refs_rights, "FMH", "rg_repo_compare_refs", "rg_repo_rights_inject");
48 rg_rights_register("repo_path", $rg_repo_path_rights, "P", "rg_repo_compare_paths", "rg_repo_rights_inject");
49 rg_rights_register("repo", $rg_repo_rights, "AB", FALSE, "rg_repo_rights_inject");
50 50
51 /*
52 * Function used to inject rights for a obj_id/type combination
53 * It will be called from rg_rights_get
54 * @out - the output array where we want to put rights
55 */
56 function rg_repo_rights_inject($db, $obj_id, $type, $owner, $uid)
57 {
58 $ret = array();
59
60 while (1) {
61 $ui = rg_user_info($db, $uid, "", "");
62 if ($ui['exists'] != 1)
63 break;
64
65 $a = array();
66 $a['type'] = $type;
67 $a['obj_id'] = $obj_id;
68 $a['uid'] = 0; // TODO: not clear here what to put!
69 $a['itime'] = 0;
70 $a['misc'] = "";
71 $a['prio'] = 0;
72 $a['who'] = $owner;
73 $a['right_id'] = 0;
74 $a['ip'] = "";
75 $a['can_be_deleted'] = 0;
76 $a['desc'] = "Autogenerated";
77
78 if ($ui['is_admin'] == 1) {
79 $a['rights'] = rg_rights_all($type);
80 $ret[] = $a;
81 }
82
83 $ri = rg_repo_info($db, $obj_id, 0, "");
84 if ($ri['exists'] != 1)
85 break;
86
87 // No rights to inject if is not public
88 if ($ri['public'] != 1)
89 break;
90
91 if (strcmp($type, "repo") == 0)
92 $a['rights'] = "A"; // access
93 else if (strcmp($type, "repo_refs") == 0)
94 $a['rights'] = "F"; // fetch
95 else
96 break;
97
98 $ret[] = $a;
99 break;
100 }
101
102 return $ret;
103 }
104
105 /*
106 * Bring a ref to a canonical format (refs/x/name)
107 * TODO: move to git.inc?
108 */
109 function rg_repo_ref_canon($ref)
110 {
111 if (strncmp($ref, "refs/", 5) == 0) {
112 // do nothing
113 } else if (strncmp($ref, "/refs/", 6) == 0) {
114 $ref = substr($ref, 1);
115 } else {
116 $ref = "refs/heads/" . $ref;
117 }
118
119 return $ref;
120 }
121
122 /*
123 * Compare function for refs
124 */
125 function rg_repo_compare_refs($misc, $ref)
126 {
127 rg_prof_start("repo_compare_refs");
128
129 $misc = rg_repo_ref_canon($misc);
130 $ref = rg_repo_ref_canon($ref);
131
132 $ret = preg_match('/^' . $misc . '/uD', $ref);
133 rg_log("repo_compare_refs: misc=$misc ref=$ref => " . ($ret ? "T" : "F"));
134
135 rg_prof_end("repo_compare_refs");
136 return $ret;
137 }
138
139 /*
140 * Compare function for paths
141 */
142 function rg_repo_compare_paths($misc, $path)
143 {
144 rg_prof_start("repo_compare_paths");
145
146 $ret = preg_match('/' . $misc . '/uD', $path);
147 rg_log("repo_compare_paths: misc=$misc path=$path => " . ($ret ? "T" : "F"));
148
149 rg_prof_end("repo_compare_paths");
150 return $ret;
151 }
152
153 /*
154 * Remove "refs/heads/" when showing rights on web
155 * TODO: don't know where to call it. Maybe in rg_rights_load?
156 * TODO: also, register this kind of function.
157 */
158 function rg_repo_ref_nice($ref)
159 {
160 if (strncmp($ref, "refs/heads/", 11) == 0)
161 $ref = substr($ref, 11);
162 return $ref;
163 }
51 164
52 165 // Repo history categories // Repo history categories
53 166 define('REPO_CAT_CREATE', 1); define('REPO_CAT_CREATE', 1);
 
... ... function rg_repo_ok($repo)
390 503 global $rg_repo_max_len; global $rg_repo_max_len;
391 504
392 505 if (empty($repo)) { if (empty($repo)) {
393 rg_repo_set_error("Invalid repository name (empty)");
506 rg_repo_set_error("invalid repository name (empty)");
394 507 return FALSE; return FALSE;
395 508 } }
396 509
397 510 if (rg_chars_allow($repo, $rg_repo_allow) === FALSE) { if (rg_chars_allow($repo, $rg_repo_allow) === FALSE) {
398 rg_repo_set_error("Invalid repository name (invalid chars)");
511 rg_repo_set_error("invalid repository name (invalid chars)");
399 512 return FALSE; return FALSE;
400 513 } }
401 514
402 515 if (preg_match('/\.\./', $repo) > 0) { if (preg_match('/\.\./', $repo) > 0) {
403 rg_repo_set_error("Invalid repository name (..)");
516 rg_repo_set_error("invalid repository name (..)");
404 517 return FALSE; return FALSE;
405 518 } }
406 519
 
... ... function rg_repo_info($db, $repo_id, $uid, $repo_name)
529 642 return $ret; return $ret;
530 643 } }
531 644
532 /*
533 * Check if a user has access to a repository
534 * @ui - most of the time is the logged in user
535 */
536 $rg_repo_allow_cache = array();
537 function rg_repo_allow($db, $type, $ri, $ui, $needed_rights, $ip, $misc)
538 {
539 global $rg_repo_allow_cache;
540
541 if (empty($needed_rights))
542 return TRUE;
543
544 if ($misc === FALSE)
545 $kmisc = ""; // TODO: not clear if good enough - security wise
546 else
547 $kmisc = $misc;
548
549 $key = $type ."|" . $ri['repo_id'] . "|" . $ui['uid']
550 . "|" . $needed_rights . "|" . $ip . "|" . $kmisc;
551
552 if (isset($rg_repo_allow_cache[$key])) {
553 rg_log("CHECK: repo_allow got data from cache");
554 return $rg_repo_allow_cache[$key];
555 }
556
557 rg_prof_start("repo_allow");
558 rg_log("repo_allow: type=$type repo_id=" . $ri['repo_id']
559 . " repo_owner=" . $ri['uid']
560 . " uid=" . $ui['uid']
561 . " needed_rights=$needed_rights ip=$ip misc=$misc");
562
563 $ret = FALSE;
564 while (1) {
565 if ($ui['is_admin'] == 1) {
566 rg_log("\tUser is admin, allow.");
567 $ret = TRUE;
568 break;
569 }
570
571 if ($ri['uid'] == $ui['uid']) {
572 rg_log("\tUser is the owner, allow.");
573 $ret = TRUE;
574 break;
575 }
576
577 if ($ui['uid'] > 0) {
578 $rr = rg_repo_rights_get($db, $type, $ri, $ui['uid']);
579 if ($rr['ok'] != 1) {
580 rg_repo_set_error("cannot get rights from db");
581 break;
582 }
583 $db_rights = $rr['list'];
584 } else {
585 // anonymous acess (git://...)
586 $db_rights = array();
587 }
588
589 rg_log("\tdb_rights: " . rg_array2string($db_rights));
590
591 if (rg_rights_allow($db_rights, $type, $needed_rights, $ip, $misc) === TRUE) {
592 $ret = TRUE;
593 break;
594 }
595
596 break;
597 }
598 $rg_repo_allow_cache[$key] = $ret;
599
600 rg_prof_end("repo_allow");
601 return $ret;
602 }
603
604 645 /* /*
605 646 * Delete a repo * Delete a repo
606 647 */ */
 
... ... function rg_repo_insert_rename($db, $uid, $repo_id, $old_name)
737 778 * TODO: check rights - also for create? * TODO: check rights - also for create?
738 779 * TODO: where do we validate if the user has enough public/private slots? * TODO: where do we validate if the user has enough public/private slots?
739 780 */ */
740 function rg_repo_edit($db, $login_ui, $new)
781 function rg_repo_edit($db, $login_ui, &$new)
741 782 { {
742 783 rg_prof_start("repo_edit"); rg_prof_start("repo_edit");
743 rg_log("repo_edit: login_uid=" . $login_ui['uid']
784 rg_log_enter("repo_edit: login_uid=" . $login_ui['uid']
744 785 . " new=" . rg_array2string($new)); . " new=" . rg_array2string($new));
745 786
746 787 // TODO: test if user is allowed to add a repository // TODO: test if user is allowed to add a repository
747 788 // TODO: test if user did not cross the limit for number of repos // TODO: test if user did not cross the limit for number of repos
748 789
749 790 $ret = FALSE; $ret = FALSE;
750 do {
791 while (1) {
751 792 if (rg_repo_ok($new['name']) !== TRUE) if (rg_repo_ok($new['name']) !== TRUE)
752 793 break; break;
753 794
 
... ... function rg_repo_edit($db, $login_ui, $new)
855 896 break; break;
856 897 } }
857 898
858 $ret = array("renamed" => $renamed);
859 } while (0);
899 $ret = TRUE;
900 break;
901 }
860 902
903 rg_log_exit();
861 904 rg_prof_end("repo_edit"); rg_prof_end("repo_edit");
862 905 return $ret; return $ret;
863 906 } }
 
... ... function rg_repo_git_done($db, $repo_id)
1055 1098 return $ret; return $ret;
1056 1099 } }
1057 1100
1058 /*
1059 * Get rights for a user
1060 */
1061 function rg_repo_rights_get($db, $type, $ri, $uid)
1062 {
1063 rg_prof_start("repo_rights_get");
1064 rg_log("rg_repo_rights_get: type=$type repo_id=" . $ri['repo_id']
1065 . ", uid=$uid");
1066
1067 $ret = array();
1068 $ret['ok'] = 0;
1069 $ret['rights'] = "";
1070
1071 $repo_id = $ri['repo_id'];
1072
1073 while (1) {
1074 // Give all rights to owner
1075 if ($ri['uid'] == $uid) {
1076 rg_log("\tuid $uid is the owner.");
1077 $a = array();
1078 $a['rights'] = rg_rights_all($type);
1079 $a['rights_text'] = implode(", ",
1080 rg_rights_text($type, $a['rights']));
1081 $a['ip'] = "0.0.0.0/0 ::/0";
1082 $ret['list'][] = $a;
1083 $ret['ok'] = 1;
1084 break;
1085 }
1086
1087 $r = rg_rights_get($db, $type, $repo_id, $uid, 0);
1088 if ($r['ok'] !== 1) {
1089 rg_repo_set_error("cannot get rights (" . rg_rights_error() . ")!");
1090 break;
1091 }
1092
1093 rg_log_ml("rights: " . print_r($r, TRUE));
1094 $ret['list'] = $r['list'];
1095 $ret['ok'] = 1;
1096 break;
1097 }
1098
1099 rg_prof_end("repo_rights_get");
1100 return $ret;
1101 }
1102
1103 1101 /* /*
1104 1102 * Add in queue a statistic file * Add in queue a statistic file
1105 1103 */ */
 
... ... function rg_repo_stats_push2file($a)
1132 1130 */ */
1133 1131 function rg_repo_rights_cosmetic($db, &$a) function rg_repo_rights_cosmetic($db, &$a)
1134 1132 { {
1135 if (isset($a['target_user'])) {
1136 if (strcmp($a['target_user'], "*") == 0) {
1133 if (isset($a['username'])) {
1134 if (strcmp($a['username'], "*") == 0) {
1137 1135 $a['uid'] = 0; $a['uid'] = 0;
1138 } else {
1139 $ui = rg_user_info($db, 0, $a['target_user'], "");
1136 } else if (!isset($a['uid'])) {
1137 $ui = rg_user_info($db, 0, $a['username'], "");
1140 1138 if ($ui['exists'] != 1) if ($ui['exists'] != 1)
1141 1139 $a['uid'] = "?"; $a['uid'] = "?";
1142 1140 else else
1143 1141 $a['uid'] = $ui['uid']; $a['uid'] = $ui['uid'];
1144 1142 } }
1145 } else {
1146 if ($a['target_uid'] == 0) {
1147 $a['target_user'] = "*";
1148 } else {
1149 $ui = rg_user_info($db, $a['target_uid'], "", "");
1150 if ($ui['exists'] != 1)
1151 $a['target_user'] = "?" . $a['target_uid'] . "?";
1152 else
1153 $a['target_user'] = $ui['username'];
1154 }
1155 1143 } }
1156 1144
1157 if (isset($a['who'])) {
1145 if ($a['uid'] == 0) {
1146 $a['username'] = "*";
1147 } else if (!isset($a['username'])) {
1148 $ui = rg_user_info($db, $a['uid'], "", "");
1149 if ($ui['exists'] != 1)
1150 $a['username'] = "?" . $a['uid'] . "?";
1151 else
1152 $a['username'] = $ui['username'];
1153 }
1154
1155 if (!isset($a['who_name'])) {
1158 1156 $ui = rg_user_info($db, $a['who'], "", ""); $ui = rg_user_info($db, $a['who'], "", "");
1159 1157 if ($ui['exists'] != 1) if ($ui['exists'] != 1)
1160 1158 $a['who_name'] = "?" . $a['who'] . "?"; $a['who_name'] = "?" . $a['who'] . "?";
 
... ... function rg_repo_admin_rights($db, $rg, $type)
1214 1212 $a = array(); $a = array();
1215 1213 $a['right_id'] = rg_var_uint("right_id"); $a['right_id'] = rg_var_uint("right_id");
1216 1214 $a['edit_id'] = rg_var_uint("edit_id"); $a['edit_id'] = rg_var_uint("edit_id");
1217 $a['target_user'] = rg_var_str("target_user");
1215 $a['username'] = rg_var_str("username");
1218 1216 $a['rights'] = rg_rights_a2s(rg_var_str("rights")); $a['rights'] = rg_rights_a2s(rg_var_str("rights"));
1219 1217 $a['misc'] = rg_var_str("misc"); $a['misc'] = rg_var_str("misc");
1220 1218 $a['ip'] = rg_var_str("ip"); $a['ip'] = rg_var_str("ip");
 
... ... function rg_repo_admin_rights($db, $rg, $type)
1238 1236 foreach ($list as $k => $junk) foreach ($list as $k => $junk)
1239 1237 $my_list[] = $k; $my_list[] = $k;
1240 1238
1241 $r = rg_rights_delete_list($db, $rg['ri']['repo_id'], $my_list);
1239 $r = rg_rights_delete_list($db, $type, $rg['ri']['repo_id'], $my_list);
1242 1240 if ($r !== TRUE) { if ($r !== TRUE) {
1243 1241 $list_errmsg[] = "cannot delete rights: " . rg_rights_error(); $list_errmsg[] = "cannot delete rights: " . rg_rights_error();
1244 1242 break; break;
 
... ... function rg_repo_admin_rights($db, $rg, $type)
1252 1250 while ($a['edit_id'] > 0) { while ($a['edit_id'] > 0) {
1253 1251 // TODO: check rights // TODO: check rights
1254 1252
1255 $r = rg_rights_get($db, $type, $rg['ri']['repo_id'],
1256 $rg['login_ui']['uid'], $a['edit_id']);
1253 $owner = $rg['ri']['uid'];
1254 $r = rg_rights_get($db, $rg['ri']['repo_id'], $type,
1255 $owner, $rg['login_ui']['uid'], $a['edit_id']);
1257 1256 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
1258 1257 $list_errmsg[] = "cannot load rights: " . rg_rights_error(); $list_errmsg[] = "cannot load rights: " . rg_rights_error();
1259 1258 break; break;
 
... ... function rg_repo_admin_rights($db, $rg, $type)
1266 1265
1267 1266 $a = $r['list'][0]; $a = $r['list'][0];
1268 1267
1269 // fill 'target_user' field
1270 1268 rg_repo_rights_cosmetic($db, $a); rg_repo_rights_cosmetic($db, $a);
1271 1269
1272 1270 $load_defaults = 0; $load_defaults = 0;
 
... ... function rg_repo_admin_rights($db, $rg, $type)
1307 1305
1308 1306 if ($load_defaults == 1) { if ($load_defaults == 1) {
1309 1307 $rg['right_id'] = $a['right_id']; $rg['right_id'] = $a['right_id'];
1310 $rg['target_user'] = "";
1308 $rg['username'] = "";
1311 1309 $rg['rights'] = rg_rights_default($type); $rg['rights'] = rg_rights_default($type);
1312 1310 $rg['misc'] = ""; $rg['misc'] = "";
1313 1311 $rg['ip'] = ""; $rg['ip'] = "";
 
... ... function rg_repo_edit_high_level($db, $rg)
1440 1438 $errmsg[] = rg_repo_error(); $errmsg[] = rg_repo_error();
1441 1439 break; break;
1442 1440 } }
1443 $rg['ri.renamed'] = $r['renamed'];
1444 1441
1445 1442 $rg['ri']['home'] = rg_re_repopage($rg['login_ui'], $rg['ri']['home'] = rg_re_repopage($rg['login_ui'],
1446 1443 $rg['ri']['name']); $rg['ri']['name']);
File inc/rights.inc.php changed (mode: 100644) (index 6101110..ff0be6f)
... ... require_once($INC . "/git.inc.php");
7 7
8 8 $rg_rights = array(); $rg_rights = array();
9 9 $rg_rights_default = array(); $rg_rights_default = array();
10 $rg_rights_cmp_func = array();
11 $rg_rights_inject = array();
10 12
11 13 $rg_rights_error = ""; $rg_rights_error = "";
12 14
 
... ... function rg_rights_error()
25 27 /* /*
26 28 * Register a set of rights * Register a set of rights
27 29 */ */
28 function rg_rights_register($type, $rights, $default_rights)
30 function rg_rights_register($type, $rights, $default_rights, $cmp_func,
31 $inject_func)
29 32 { {
30 33 global $rg_rights; global $rg_rights;
31 34 global $rg_rights_default; global $rg_rights_default;
35 global $rg_rights_cmp_func;
36 global $rg_rights_inject;
32 37
33 38 $rg_rights[$type] = $rights; $rg_rights[$type] = $rights;
34 39 $rg_rights_default[$type] = $default_rights; $rg_rights_default[$type] = $default_rights;
40 $rg_rights_cmp_func[$type] = $cmp_func;
41 if ($inject_func !== FALSE)
42 $rg_rights_inject[$type] = $inject_func;
35 43 } }
36 44
37 45 /* /*
 
... ... function rg_rights_a2s($a)
158 166 return rg_rights_fix($rights); return rg_rights_fix($rights);
159 167 } }
160 168
169 /*
170 * Improves a little bit the items of a right
171 */
172 function rg_rights_cosmetic($db, &$row)
173 {
174 if ($row['uid'] == 0) {
175 $row['username'] = "*";
176 } else {
177 $_ui = rg_user_info($db, $row['uid'], "", "");
178 if ($_ui['exists'] == 1)
179 $row['username'] = $_ui['username'];
180 else
181 $row['username'] = "?";
182 }
183
184 if ($row['who'] == 0) {
185 $row['who_name'] = "*";
186 } else {
187 $_ui = rg_user_info($db, $row['who'], "", "");
188 if ($_ui['exists'] == 1)
189 $row['who_name'] = $_ui['username'];
190 else
191 $row['who_name'] = "?";
192 }
193
194 $_r = rg_rights_text($row['type'], $row['rights']);
195 $row['rights_text'] = implode(", ", $_r);
196
197 $row['itime_text'] = gmdate("Y-m-d H:i", $row['itime']);
198 }
199
161 200 /* /*
162 201 * Get rights for an object * Get rights for an object
163 202 * @uid - the uid of the (normally) logged in user. * @uid - the uid of the (normally) logged in user.
164 203 * @right_id - optional id (used by edit) * @right_id - optional id (used by edit)
165 204 */ */
166 $rg_rights_get_cache = array();
167 function rg_rights_get($db, $type, $obj_id, $uid, $right_id)
205 function rg_rights_get($db, $obj_id, $type, $owner, $uid, $right_id)
168 206 { {
169 207 global $rg_rights; global $rg_rights;
170 global $rg_rights_get_cache;
171
172 $key = $type . "|" . $obj_id . "|" . $uid . "|" . $right_id;
173 if (isset($rg_rights_get_cache[$key])) {
174 rg_log("CHECK: rights returned from cache for key $key");
175 return $rg_rights_get_cache[$key];
176 }
208 global $rg_rights_inject;
177 209
178 rg_log("rg_rights_get: type=$type obj_id=$obj_id uid=$uid...");
179 210 rg_prof_start("rights_get"); rg_prof_start("rights_get");
211 rg_log_enter("rg_rights_get: obj_id=$obj_id type=$type owner=$owner"
212 . " uid=$uid right_id=$right_id");
180 213
181 214 $ret = array(); $ret = array();
182 215 $ret['ok'] = 0; $ret['ok'] = 0;
183 216 $ret['list'] = array(); $ret['list'] = array();
184 do {
185 // No rights possible for not logged in user
186 if ($uid == 0) {
187 $ret['ok'] = 1;
188 break;
189 }
217 while (1) {
218 $key = "rights_by_obj_id::$obj_id::$type";
219 $r = rg_cache_get($key);
220 if ($r === FALSE) {
221 rg_log("CHECK: rights_get: key not found in cache! Search in DB.");
222
223 $r = array();
224
225 // Inject rights for owner
226 if ($owner == $uid) {
227 $a = array();
228 $a['type'] = $type;
229 $a['obj_id'] = $obj_id;
230 $a['uid'] = $owner;
231 $a['itime'] = 0;
232 $a['misc'] = "";
233 $a['prio'] = 0;
234 $a['who'] = $owner;
235 $a['right_id'] = 0;
236 $a['ip'] = "";
237 $a['can_be_deleted'] = 0;
238 $a['rights'] = rg_rights_all($type);
239 $a['desc'] = "Autogenerated";
240 rg_rights_cosmetic($db, $a);
241
242 $r[] = $a;
243 }
190 244
191 $add = "";
192 if ($right_id > 0)
193 $add = " AND right_id = @@right_id@@";
194 else
195 $add = " AND (uid = @@uid@@ OR uid = 0)";
245 // Inject specific rights
246 if (isset($rg_rights_inject[$type])) {
247 $rows = $rg_rights_inject($db, $obj_id, $type, $owner, $uid);
248 foreach ($rows as $row) {
249 rg_rights_cosmetic($db, $row);
250 $r[] = $row;
251 }
252 }
196 253
197 $params = array("type" => $type,
198 "uid" => $uid,
199 "obj_id" => $obj_id,
200 "right_id" => $right_id);
201 $sql = "SELECT * FROM rights"
202 . " WHERE type = @@type@@"
203 . " AND obj_id = @@obj_id@@"
204 . $add
205 . " ORDER BY prio";
206 $res = rg_sql_query_params($db, $sql, $params);
207 if ($res === FALSE) {
208 rg_rights_set_error("cannot get info (" . rg_sql_error() . ")!");
209 break;
210 }
254 $params = array("type" => $type, "obj_id" => $obj_id);
255 $sql = "SELECT * FROM rights"
256 . " WHERE type = @@type@@"
257 . " AND obj_id = @@obj_id@@"
258 . " ORDER BY prio";
259 $res = rg_sql_query_params($db, $sql, $params);
260 if ($res === FALSE) {
261 rg_rights_set_error("cannot get info (" . rg_sql_error() . ")!");
262 break;
263 }
211 264
212 while (($row = rg_sql_fetch_array($res))) {
213 $row['target_uid'] = $row['uid']; unset($row['uid']);
214 $row['rights_text'] = implode(", ",
215 rg_rights_text($type, $row['rights']));
216 $ret['list'][] = $row;
265 while (($row = rg_sql_fetch_array($res))) {
266 rg_rights_cosmetic($db, $row);
267 $row['can_be_deleted'] = 1;
268 $r[] = $row;
269 }
270 rg_sql_free_result($res);
271 $from_cache = FALSE;
272 } else {
273 rg_log("CHECK: rights returned from cache for key $key");
274 $from_cache = TRUE;
217 275 } }
218 rg_sql_free_result($res);
219 276
277 // now, filter by uid and right_id
278 foreach ($r as $k => $v) {
279 if (($right_id > 0) && ($v['right_id'] == $right_id)) {
280 $ret['list'][] = $v;
281 break;
282 }
283
284 if (($v['uid'] == $uid) || ($v['uid'] == 0))
285 $ret['list'][] = $v;
286 }
220 287 $ret['ok'] = 1; $ret['ok'] = 1;
221 $rg_rights_get_cache[$key] = $ret;
222 } while (0);
223 288
224 rg_log("\tdb rights: " . rg_array2string($ret['list']));
289 // We store the big list
290 if (!$from_cache)
291 rg_cache_set($key, $r);
292 break;
293 }
294
295 rg_log("rights_get: rights=" . rg_array2string($ret['list']));
225 296
297 rg_log_exit();
226 298 rg_prof_end("rights_get"); rg_prof_end("rights_get");
227 299 return $ret; return $ret;
228 300 } }
 
... ... function rg_rights_get($db, $type, $obj_id, $uid, $right_id)
232 304 */ */
233 305 function rg_rights_set($db, $type, $a) function rg_rights_set($db, $type, $a)
234 306 { {
235 rg_log("rg_rights_set: type=$type paras=" . rg_array2string($a));
236
237 $a['type'] = $type;
238 $a['now'] = time();
239 if ($a['right_id'] > 0)
240 $sql = "UPDATE rights SET"
241 . " type = @@type@@"
242 . ", uid = @@uid@@"
243 . ", obj_id = @@obj_id@@"
244 . ", rights = @@rights@@"
245 . ", misc = @@misc@@"
246 . ", ip = @@ip@@"
247 . ", prio = @@prio@@"
248 . ", itime = @@now@@"
249 . ", who = @@who@@"
250 . " WHERE right_id = @@right_id@@";
251 else
252 $sql = "INSERT INTO rights (type, uid, obj_id, rights"
253 . ", misc, ip, prio, itime, who)"
254 . " VALUES (@@type@@, @@uid@@, @@obj_id@@, @@rights@@"
255 . ", @@misc@@, @@ip@@, @@prio@@, @@now@@, @@who@@)";
256 $res = rg_sql_query_params($db, $sql, $a);
257 if ($res === FALSE) {
258 rg_rights_set_error("cannot alter rights (" . rg_sql_error() . ")!");
259 return FALSE;
307 rg_prof_start("rights_set");
308 rg_log_enter("rg_rights_set: type=$type a=" . rg_array2string($a));
309
310 while (1) {
311 if ($a['prio'] < 10) {
312 rg_rights_set_error("prio must be at least 10");
313 break;
314 }
315
316 $a['type'] = $type;
317 $a['now'] = time();
318 if ($a['right_id'] > 0)
319 $sql = "UPDATE rights SET"
320 . " type = @@type@@"
321 . ", uid = @@uid@@"
322 . ", obj_id = @@obj_id@@"
323 . ", rights = @@rights@@"
324 . ", misc = @@misc@@"
325 . ", ip = @@ip@@"
326 . ", prio = @@prio@@"
327 . ", itime = @@now@@"
328 . ", who = @@who@@"
329 . " WHERE right_id = @@right_id@@";
330 else
331 $sql = "INSERT INTO rights (type, uid, obj_id, rights"
332 . ", misc, ip, prio, itime, who)"
333 . " VALUES (@@type@@, @@uid@@, @@obj_id@@, @@rights@@"
334 . ", @@misc@@, @@ip@@, @@prio@@, @@now@@, @@who@@)";
335 $res = rg_sql_query_params($db, $sql, $a);
336 if ($res === FALSE) {
337 rg_rights_set_error("cannot alter rights (" . rg_sql_error() . ")!");
338 break;
339 }
340 rg_sql_free_result($res);
341
342 // invalidate cache (TODO: optimize by inserting in list and reorder)
343 $key = "rights_by_obj_id::" . $a['obj_id'] . "::" . $a['type'];
344 rg_cache_unset($key);
345
346 break;
260 347 } }
261 rg_sql_free_result($res);
262 348
349 rg_log_exit();
350 rg_prof_end("rights_set");
263 351 return TRUE; return TRUE;
264 352 } }
265 353
266 354 /* /*
267 355 * Returns an array with the rights, for all users * Returns an array with the rights, for all users
268 * TODO: we have a circular depenedncy on user.inc. Remove the lookup and brake
356 * TODO: we have a circular dependency on user.inc. Remove the lookup and break
269 357 * the dependency. * the dependency.
358 * TODO: We have a similar query in rights_get!
270 359 */ */
271 360 function rg_rights_load($db, $type, $obj_id) function rg_rights_load($db, $type, $obj_id)
272 361 { {
273 362 global $rg_rights; global $rg_rights;
274 363
275 364 rg_prof_start("rights_list"); rg_prof_start("rights_list");
276 rg_log("rg_rights_list: type=$type obj_id=$obj_id");
365 rg_log_enter("rg_rights_list: type=$type obj_id=$obj_id");
277 366
278 367 $ret = FALSE; $ret = FALSE;
279 do {
368 while (1) {
280 369 $params = array("obj_id" => $obj_id, $params = array("obj_id" => $obj_id,
281 370 "type" => $type); "type" => $type);
282 371
 
... ... function rg_rights_load($db, $type, $obj_id)
294 383
295 384 $ret = array(); $ret = array();
296 385 while (($row = rg_sql_fetch_array($res))) { while (($row = rg_sql_fetch_array($res))) {
297 if ($row['uid'] == 0) {
298 $row['username'] = "*";
299 } else {
300 $_ui = rg_user_info($db, $row['uid'], "", "");
301 if ($_ui['exists'] == 1)
302 $row['username'] = $_ui['username'];
303 else
304 $row['username'] = "?";
305 }
306
307 $_r = rg_rights_text($row['type'], $row['rights']);
308 $row['rights_text'] = implode(", ", $_r);
309
310 $row['itime_text'] = gmdate("Y-m-d H:i", $row['itime']);
311
312 // To avoid confusion
313 $row['target_uid'] = $row['uid']; unset($row['uid']);
314
386 rg_rights_cosmetic($db, $row);
315 387 $ret[] = $row; $ret[] = $row;
316 388 } }
317 389 rg_sql_free_result($res); rg_sql_free_result($res);
318 } while (0);
319 390
391 break;
392 }
393
394 rg_log_exit();
320 395 rg_prof_end("rights_list"); rg_prof_end("rights_list");
321 396 return $ret; return $ret;
322 397 } }
 
... ... function rg_rights_split_ip($ip)
353 428 $ip2 = $ip; $ip2 = $ip;
354 429 } }
355 430
356 if (preg_match('/^[a-fA-F0-9:]*$/', $ip2)) { /* ipv6 */
431 if (preg_match('/^[a-fA-F0-9:]*$/D', $ip2)) { /* ipv6 */
357 432 if ($ret['prefix_len'] == -1) { if ($ret['prefix_len'] == -1) {
358 433 $ret['prefix_len'] = 128; $ret['prefix_len'] = 128;
359 434 } else if (($ret['prefix_len'] < 0) || ($ret['prefix_len'] > 128)) { } else if (($ret['prefix_len'] < 0) || ($ret['prefix_len'] > 128)) {
 
... ... function rg_rights_split_ip($ip)
421 496 $new[$k] = sprintf("%x", $p); $new[$k] = sprintf("%x", $p);
422 497 $ret['ip'] = implode(":", $new); $ret['ip'] = implode(":", $new);
423 498 $ret['type'] = "ipv6"; $ret['type'] = "ipv6";
424 } else if (preg_match('/^[0-9\.]*$/', $ip2)) { /* ipv4 */
499 } else if (preg_match('/^[0-9\.]*$/D', $ip2)) { /* ipv4 */
425 500 if ($ret['prefix_len'] == -1) { if ($ret['prefix_len'] == -1) {
426 501 $ret['prefix_len'] = 32; $ret['prefix_len'] = 32;
427 502 } else if (($ret['prefix_len'] < 0) || ($ret['prefix_len'] > 32)) { } else if (($ret['prefix_len'] < 0) || ($ret['prefix_len'] > 32)) {
 
... ... function rg_rights_test_ip($list, $ip)
535 610 */ */
536 611 function rg_rights_allow($list, $needed_rights, $ip, $misc) function rg_rights_allow($list, $needed_rights, $ip, $misc)
537 612 { {
538 rg_log("rg_rights_allow: needed_rights=$needed_rights ip=$ip"
613 global $rg_rights_cmp_func;
614
615 rg_log_enter("rg_rights_allow: needed_rights=$needed_rights ip=$ip"
539 616 . " misc=$misc list:" . rg_array2string($list)); . " misc=$misc list:" . rg_array2string($list));
540 617
541 618 $ret = FALSE; $ret = FALSE;
542
543 if (!is_array($list)) {
544 rg_rights_set_error("list is not array");
545 return $ret;
546 }
547
548 if (empty($needed_rights))
549 return TRUE;
550
551 $needed = explode("|", $needed_rights);
552
553 foreach ($list as $k => $v) {
554 // Test IP
555 if (rg_rights_test_ip($v['ip'], $ip) !== TRUE) {
556 rg_log("CHECK: ip does not match with " . $v['ip']);
557 continue;
619 while (1) {
620 if (!is_array($list)) {
621 rg_rights_set_error("list is not array");
622 break;
558 623 } }
559 624
560 foreach ($needed as $needed1) {
561 $r = rg_rights_mask($v['rights'], $needed1);
562 if (strcmp($r, $needed1) != 0) {
563 rg_log("rights_allow: [$r] != [$needed1]! Continue.");
564 continue;
565 }
566 rg_log("rights_allow: [$r] = [$needed1]! Allow.");
625 if (empty($needed_rights)) {
567 626 $ret = TRUE; $ret = TRUE;
568 627 break; break;
569 628 } }
570 629
571 if ($ret === FALSE)
572 continue;
630 $needed = explode("|", $needed_rights);
631
632 foreach ($list as $k => $v) {
633 // Test IP
634 if (rg_rights_test_ip($v['ip'], $ip) !== TRUE) {
635 rg_log("CHECK: ip does not match with [" . $v['ip'] . "]");
636 continue;
637 }
573 638
574 // Test 'misc' match
575 if ($misc !== FALSE) {
576 if (empty($v['misc']))
639 foreach ($needed as $needed1) {
640 $r = rg_rights_mask($v['rights'], $needed1);
641 if (strcmp($r, $needed1) != 0) {
642 rg_log("rights_allow: [$r] != [$needed1]! Continue.");
643 continue;
644 }
645 rg_log("rights_allow: [$r] = [$needed1]! Allow.");
646 $ret = TRUE;
577 647 break; break;
648 }
578 649
579 rg_log("Check misc [$misc] against [" . $v['misc'] . "]");
580 if (!stristr($misc, $v['misc']))
650 if ($ret === FALSE)
581 651 continue; continue;
652
653 // Test 'misc' match
654 if ($misc !== FALSE) {
655 if (empty($v['misc']))
656 break;
657
658 $cmp_func = $rg_rights_cmp_func[$v['type']];
659 $r = $cmp_func($v['misc'], $misc);
660 if (!$r)
661 continue;
662 }
663
664 break;
582 665 } }
583 666
584 667 break; break;
585 668 } }
586 669
670 rg_log_exit();
587 671 return $ret; return $ret;
588 672 } }
589 673
 
... ... function rg_rights_allow($list, $needed_rights, $ip, $misc)
591 675 * Delete a list of rights * Delete a list of rights
592 676 * Caller must be sure that the user is allowed to operate on 'obj_id'. * Caller must be sure that the user is allowed to operate on 'obj_id'.
593 677 */ */
594 function rg_rights_delete_list($db, $obj_id, $list)
678 function rg_rights_delete_list($db, $type, $obj_id, $list)
595 679 { {
596 $db_list = implode(",", $list);
597
598 $params = array("obj_id" => $obj_id);
599 $sql = "DELETE FROM rights"
600 . " WHERE obj_id = @@obj_id@@"
601 . " AND right_id IN (" . $db_list . ")";
602 $res = rg_sql_query_params($db, $sql, $params);
603 if ($res === FALSE) {
604 rg_rights_set_error("cannot mass delete (" . rg_sql_error() . ")!");
605 return FALSE;
680 rg_prof_start("rights_delete_list");
681 rg_log_enter("rights_delete_list: type=$type obj_id=$obj_id"
682 . " list=" . rg_array2string($list));
683
684 $ret = FALSE;
685 while (1) {
686 $db_list = implode(",", $list);
687
688 $params = array("obj_id" => $obj_id);
689 $sql = "DELETE FROM rights"
690 . " WHERE obj_id = @@obj_id@@"
691 . " AND right_id IN (" . $db_list . ")";
692 $res = rg_sql_query_params($db, $sql, $params);
693 if ($res === FALSE) {
694 rg_rights_set_error("cannot mass delete (" . rg_sql_error() . ")!");
695 break;
696 }
697
698 // invalidate cache; TODO: this is the best way?
699 rg_cache_unset("rights_by_obj_id::$obj_id::$type");
700
701 break;
606 702 } }
607 703
704 rg_log_exit();
705 rg_prof_end("rights_delete_list");
608 706 return TRUE; return TRUE;
609 707 } }
610 708
File inc/sess.inc.php changed (mode: 100644) (index 59ef247..aa33aef)
... ... function rg_sess_add($db, $uid, $sid, $session_time, $lock_ip)
37 37 rg_sql_free_result($res); rg_sql_free_result($res);
38 38
39 39 $params['last_db_write'] = $now; $params['last_db_write'] = $now;
40 rg_cache_set("sess::" . $sid, serialize($params));
40 rg_cache_set("sess::" . $sid, $params);
41 41
42 42 $ret = TRUE; $ret = TRUE;
43 43 } while (0); } while (0);
 
... ... function rg_sess_valid($db, $sid)
58 58 $ret = FALSE; $ret = FALSE;
59 59 do { do {
60 60 $r = rg_cache_get("sess::" . $sid); $r = rg_cache_get("sess::" . $sid);
61 if ($r !== FALSE)
62 $r = unserialize($r);
63
64 61 if ($r === FALSE) { if ($r === FALSE) {
65 62 $params = array("sid" => $sid); $params = array("sid" => $sid);
66 63 $sql = "SELECT * FROM sess WHERE sid = @@sid@@"; $sql = "SELECT * FROM sess WHERE sid = @@sid@@";
 
... ... function rg_sess_valid($db, $sid)
73 70 if ($rows > 0) { if ($rows > 0) {
74 71 $r = rg_sql_fetch_array($res); $r = rg_sql_fetch_array($res);
75 72 $r['last_db_write'] = $r['expire'] - $r['session_time']; $r['last_db_write'] = $r['expire'] - $r['session_time'];
76 rg_cache_set("sess::" . $sid, serialize($r));
73 rg_cache_set("sess::" . $sid, $r);
77 74 } }
78 75 rg_sql_free_result($res); rg_sql_free_result($res);
79 76 } }
 
... ... function rg_sess_update($db, $sess)
139 136 rg_sql_free_result($res); rg_sql_free_result($res);
140 137 } }
141 138
142 rg_cache_set("sess::" . $sess['sid'], serialize($sess));
139 rg_cache_set("sess::" . $sess['sid'], $sess);
143 140
144 141 $ret = TRUE; $ret = TRUE;
145 142 } while (0); } while (0);
File inc/sql.inc.php changed (mode: 100644) (index 606263e..37b10b6)
... ... function rg_sql_open_nodelay($h)
32 32 global $rg_sql_debug; global $rg_sql_debug;
33 33 global $rg_sql_conn; global $rg_sql_conn;
34 34
35 rg_prof_start("sql_open_nodelay");
36
35 37 $ret = FALSE; $ret = FALSE;
36 38 do { do {
37 39 if (!isset($rg_sql_conn[$h])) { if (!isset($rg_sql_conn[$h])) {
 
... ... function rg_sql_open_nodelay($h)
78 80 $ret = $db; $ret = $db;
79 81 } while (0); } while (0);
80 82
83 rg_prof_end("sql_open_nodelay");
81 84 return $ret; return $ret;
82 85 } }
83 86
 
... ... function rg_sql_query0($db, $sql, $res, $_s)
116 119 { {
117 120 global $rg_sql_debug; global $rg_sql_debug;
118 121
119 if ($res === FALSE) {
120 rg_sql_set_error("$sql: " . @pg_last_error($db));
121 rg_prof_set(array("query_errors" => 1));
122 return FALSE;
123 }
122 while (1) {
123 if ($res === FALSE) {
124 rg_sql_set_error("$sql: " . @pg_last_error($db));
125 rg_prof_set(array("query_errors" => 1));
126 break;
127 }
124 128
125 $diff = sprintf("%u", (microtime(TRUE) - $_s) * 1000);
126 $rows = rg_sql_num_rows($res);
127 if ($rows == 0)
128 $arows = rg_sql_affected_rows($res);
129 else
130 $arows = 0;
129 $diff = sprintf("%u", (microtime(TRUE) - $_s) * 1000);
130 $rows = rg_sql_num_rows($res);
131 if ($rows == 0)
132 $arows = rg_sql_affected_rows($res);
133 else
134 $arows = 0;
131 135
132 if ($rg_sql_debug > 0)
133 rg_log("\tDB: Took " . $diff . "ms, $rows row(s), $arows affected");
136 if ($rg_sql_debug > 0)
137 rg_log("DB: Took " . $diff . "ms, $rows row(s), $arows affected");
134 138
135 rg_prof_set(array("queries" => 1,
136 "rows" => $rows,
137 "affected_rows" => $arows,
138 "query_time_ms" => $diff));
139 rg_prof_set(array("queries" => 1,
140 "rows" => $rows,
141 "affected_rows" => $arows,
142 "query_time_ms" => $diff));
143 break;
144 }
139 145
140 146 return $res; return $res;
141 147
 
... ... function rg_sql_query($h, $sql)
149 155 global $rg_sql_debug; global $rg_sql_debug;
150 156
151 157 if ($rg_sql_debug > 0) if ($rg_sql_debug > 0)
152 rg_log("\tDB: running [$sql]...");
158 rg_log_enter("sql_query: sql=$sql");
153 159
154 $db = rg_sql_open_nodelay($h);
155 if ($db === FALSE)
156 return FALSE;
160 $ret = FALSE;
161 while (1) {
162 $db = rg_sql_open_nodelay($h);
163 if ($db === FALSE)
164 break;
165
166 $_s = microtime(TRUE);
167 $res = @pg_query($db, $sql);
168 $ret = rg_sql_query0($db, $sql, $res, $_s);
169 break;
170 }
157 171
158 $_s = microtime(TRUE);
159 $res = @pg_query($db, $sql);
160 return rg_sql_query0($db, $sql, $res, $_s);
172 if ($rg_sql_debug > 0)
173 rg_log_exit();
174 return $ret;
161 175 } }
162 176
163 177 /* /*
 
... ... function rg_sql_query_params($h, $sql, $params)
172 186 global $rg_sql_debug; global $rg_sql_debug;
173 187
174 188 if ($rg_sql_debug > 0) if ($rg_sql_debug > 0)
175 rg_log("\tDB: running [$sql] with [" . rg_array2string($params) . "]...");
189 rg_log_enter("query_params: running [$sql] with [" . rg_array2string($params) . "]");
176 190
177 $db = rg_sql_open_nodelay($h);
178 if ($db === FALSE)
179 return FALSE;
191 $ret = FALSE;
192 while (1) {
193 $db = rg_sql_open_nodelay($h);
194 if ($db === FALSE)
195 break;
180 196
181 // Transforms @params into $x system
182 $params2 = array();
183 $i = 1;
184 foreach ($params as $k => $v) {
185 $what = "/@@" . $k . "@@/";
186 $value = "\\$" . $i;
187 $sql = preg_replace($what, $value, $sql, -1, $count);
188
189 //rg_log("rg_sql_query_params: k=[$k] value=$value count=$count");
190 if ($count > 0) {
191 $params2[] = $v;
192 $i++;
197 // Transforms @params into $x system
198 $params2 = array();
199 $i = 1;
200 foreach ($params as $k => $v) {
201 $what = "/@@" . $k . "@@/";
202 $value = "\\$" . $i;
203 $sql = preg_replace($what, $value, $sql, -1, $count);
204
205 //rg_log("rg_sql_query_params: k=[$k] value=$value count=$count");
206 if ($count > 0) {
207 $params2[] = $v;
208 $i++;
209 }
193 210 } }
211 //rg_log("new sql: $sql");
212 //rg_log("params2: " . rg_array2string($params2));
213
214 $_s = microtime(TRUE);
215 $res = @pg_query_params($db, $sql, $params2);
216 break;
194 217 } }
195 //rg_log("new sql: $sql");
196 //rg_log("params2: " . rg_array2string($params2));
197 218
198 $_s = microtime(TRUE);
199 $res = @pg_query_params($db, $sql, $params2);
200 return rg_sql_query0($db, $sql, $res, $_s);
219 $ret = rg_sql_query0($db, $sql, $res, $_s);
220
221 if ($rg_sql_debug > 0)
222 rg_log_exit();
223 return $ret;
201 224 } }
202 225
203 226 /* /*
File inc/state.inc.php changed (mode: 100644) (index 14e5d73..1127eac)
... ... function rg_state_error()
24 24 function rg_state_get($db, $var) function rg_state_get($db, $var)
25 25 { {
26 26 rg_prof_start("state_get"); rg_prof_start("state_get");
27 rg_log_enter("state_get: var=$var");
27 28
28 29 $ret = FALSE; $ret = FALSE;
29 do {
30 while (1) {
30 31 // Try cache first // Try cache first
31 32 $r = rg_cache_get("state::" . $var); $r = rg_cache_get("state::" . $var);
32 33 if ($r !== FALSE) { if ($r !== FALSE) {
 
... ... function rg_state_get($db, $var)
48 49 } else { } else {
49 50 $row = rg_sql_fetch_array($res); $row = rg_sql_fetch_array($res);
50 51 $ret = $row['value']; $ret = $row['value'];
52 rg_cache_set("state::" . $var, $ret);
51 53 } }
52 54 rg_sql_free_result($res); rg_sql_free_result($res);
55 break;
56 }
53 57
54 rg_cache_set("state::" . $var, $ret);
55 } while (0);
56
58 rg_log_exit();
57 59 rg_prof_end("state_get"); rg_prof_end("state_get");
58 60 return $ret; return $ret;
59 61 } }
 
... ... function rg_state_get_uint($db, $var)
76 78 function rg_state_set($db, $var, $value) function rg_state_set($db, $var, $value)
77 79 { {
78 80 rg_prof_start("state_set"); rg_prof_start("state_set");
81 rg_log_enter("state_set: $var = $value");
79 82
80 83 $ret = FALSE; $ret = FALSE;
81 do {
84 while (1) {
82 85 $params = array("var" => $var, "value" => $value); $params = array("var" => $var, "value" => $value);
83 86 if (rg_state_get($db, $var) === "") { if (rg_state_get($db, $var) === "") {
84 87 $sql = "INSERT INTO state (var, value)" $sql = "INSERT INTO state (var, value)"
 
... ... function rg_state_set($db, $var, $value)
97 100 rg_cache_set("state::" . $var, $value); rg_cache_set("state::" . $var, $value);
98 101
99 102 $ret = TRUE; $ret = TRUE;
100 } while (0);
103 break;
104 }
101 105
106 rg_log_exit();
102 107 rg_prof_end("state_set"); rg_prof_end("state_set");
103 108 return $ret; return $ret;
104 109 } }
File inc/struct.inc.php changed (mode: 100644) (index 32c3b7d..0b5a0b0)
... ... function rg_sql_struct_run($db, $flags, $old_schema_ver)
401 401 $ignore_errors = ($flags & RG_IGNORE_ERRORS) ? TRUE : FALSE; $ignore_errors = ($flags & RG_IGNORE_ERRORS) ? TRUE : FALSE;
402 402 $drop_tables = ($flags & RG_DROP_TABLES) ? TRUE : FALSE; $drop_tables = ($flags & RG_DROP_TABLES) ? TRUE : FALSE;
403 403
404 rg_log("sql_struct_run: flags=$flags"
404 rg_log_enter("sql_struct_run: flags=$flags"
405 405 . " ignore_errors=" . ($ignore_errors ? "Yes" : "No") . " ignore_errors=" . ($ignore_errors ? "Yes" : "No")
406 406 . " drop_tables=" . ($drop_tables ? "Yes" : "No") . " drop_tables=" . ($drop_tables ? "Yes" : "No")
407 407 . " old_schema_ver=$old_schema_ver..."); . " old_schema_ver=$old_schema_ver...");
408 408
409 $ret = TRUE;
409 410 for ($i = $old_schema_ver + 1; $i <= $rg_sql_schema_ver; $i++) { for ($i = $old_schema_ver + 1; $i <= $rg_sql_schema_ver; $i++) {
410 411 foreach ($rg_sql_struct[$i] as $type => $sqls) { foreach ($rg_sql_struct[$i] as $type => $sqls) {
411 412 if (count($sqls) == 0) if (count($sqls) == 0)
 
... ... function rg_sql_struct_run($db, $flags, $old_schema_ver)
421 422 $res = rg_sql_query($db, $sql2); $res = rg_sql_query($db, $sql2);
422 423 if ($res === FALSE) { if ($res === FALSE) {
423 424 rg_log("WARN: Cannot run sql ($sql2) (" . rg_sql_error() . ")!"); rg_log("WARN: Cannot run sql ($sql2) (" . rg_sql_error() . ")!");
424 if (!$ignore_errors)
425 return FALSE;
425 if (!$ignore_errors) {
426 $ret = FALSE;
427 break;
428 }
426 429 } }
427 430 rg_sql_free_result($res); rg_sql_free_result($res);
428 431 } }
 
... ... function rg_sql_struct_run($db, $flags, $old_schema_ver)
431 434 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
432 435 if ($res === FALSE) { if ($res === FALSE) {
433 436 rg_log("WARN: Cannot run sql ($sql) (" . rg_sql_error() . ")!"); rg_log("WARN: Cannot run sql ($sql) (" . rg_sql_error() . ")!");
434 if (!$ignore_errors)
435 return FALSE;
437 if (!$ignore_errors) {
438 $ret = FALSE;
439 break;
440 }
436 441 } }
437 442
438 443 rg_sql_free_result($res); rg_sql_free_result($res);
439 444 } }
445
446 if (!$ret)
447 break;
440 448 } }
449
450 if (!$ret)
451 break;
441 452 } }
442 453
443 return TRUE;
454
455 rg_log_exit();
456 return $ret;
444 457 } }
445 458
446 459 /* /*
 
... ... function rg_sql_struct_get_current_ver($db)
450 463 { {
451 464 global $rg_sql_schema_ver; global $rg_sql_schema_ver;
452 465
453 rg_log("sql_struct_get_current_ver:");
466 rg_log_enter("sql_struct_get_current_ver:");
454 467
455 $old = rg_state_get($db, "schema_version");
456 if ($old === FALSE)
457 return FALSE;
468 $ret = FALSE;
469 while (1) {
470 $ret = rg_state_get($db, "schema_version");
471 if ($ret === FALSE)
472 break;
458 473
459 if (empty($old))
460 $old = 0;
474 if (empty($ret))
475 $ret = 0;
476
477 break;
478 }
461 479
462 return $old;
480 rg_log_exit();
481 return $ret;
463 482 } }
464 483
465 484 /* /*
 
... ... function rg_sql_struct_update($db, $flags)
489 508 { {
490 509 global $rg_sql_schema_ver; global $rg_sql_schema_ver;
491 510
492 rg_log("sql_struct_update: flags=$flags");
511 rg_log_enter("sql_struct_update: flags=$flags");
493 512
494 $old = rg_sql_struct_get_current_ver($db);
495 if ($old === FALSE)
496 return FALSE;
513 $ret = FALSE;
514 $rollback = 0;
515 while (1) {
516 $old = rg_sql_struct_get_current_ver($db);
517 if ($old === FALSE)
518 break;
497 519
498 if ($rg_sql_schema_ver == $old)
499 return TRUE;
520 if ($rg_sql_schema_ver == $old) {
521 $ret = TRUE;
522 break;
523 }
500 524
501 // If we cannot lock, return error
502 if (rg_lock("schema_update.lock") === FALSE)
503 return FALSE;
525 // If we cannot lock, return error
526 if (rg_lock("schema_update.lock") === FALSE)
527 break;
504 528
505 $ret = FALSE;
506 $rollback = 0;
507 do {
508 529 if (rg_sql_begin($db) !== TRUE) if (rg_sql_begin($db) !== TRUE)
509 530 break; break;
510 531
 
... ... function rg_sql_struct_update($db, $flags)
527 548
528 549 $rollback = 0; $rollback = 0;
529 550 $ret = TRUE; $ret = TRUE;
530 } while (0);
551 break;
552 }
531 553
532 554 if ($rollback == 1) if ($rollback == 1)
533 555 rg_sql_rollback($db); rg_sql_rollback($db);
534 556
535 557 rg_unlock("schema_update.lock"); rg_unlock("schema_update.lock");
536 558
559 rg_log_exit();
537 560 return $ret; return $ret;
538 561 } }
539 562
 
... ... function rg_sql_struct_slaves_update($db)
546 569 global $rg_sql_struct_slaves; global $rg_sql_struct_slaves;
547 570
548 571 rg_prof_start("sql_struct_slaves_update"); rg_prof_start("sql_struct_slaves_update");
549 rg_log("sql_struct_slaves_update");
572 rg_log_enter("sql_struct_slaves_update");
550 573
551 574 $ret = FALSE; $ret = FALSE;
552 575 $rollback = 0; $rollback = 0;
553 576 $locked = FALSE; $locked = FALSE;
554 do {
577 while (1) {
555 578 if (empty($rg_sql_struct_slaves)) { if (empty($rg_sql_struct_slaves)) {
556 579 $ret = TRUE; $ret = TRUE;
557 580 break; break;
 
... ... function rg_sql_struct_slaves_update($db)
633 656
634 657 $rollback = 0; $rollback = 0;
635 658 $ret = TRUE; $ret = TRUE;
636 } while (0);
659 break;
660 }
637 661
638 662 if ($rollback == 1) if ($rollback == 1)
639 663 rg_sql_rollback($db); rg_sql_rollback($db);
 
... ... function rg_sql_struct_slaves_update($db)
641 665 if ($locked === TRUE) if ($locked === TRUE)
642 666 rg_unlock("slave_create.lock"); rg_unlock("slave_create.lock");
643 667
668 rg_log_exit();
644 669 rg_prof_end("sql_struct_slaves_update"); rg_prof_end("sql_struct_slaves_update");
645 670 return $ret; return $ret;
646 671 } }
File inc/user.inc.php changed (mode: 100644) (index 0123c0b..b00c65c)
... ... $rg_user_rights = array(
14 14 "E" => "Edit user", "E" => "Edit user",
15 15 "R" => "Remove user", "R" => "Remove user",
16 16 "S" => "Suspend user", "S" => "Suspend user",
17 "G" => "Grant rights"
17 "G" => "Grant rights",
18 "M" => "Give admin rights"
18 19 ); );
19 20
20 rg_rights_register("user", $rg_user_rights, "");
21 /* We do not have defaults rights and no compare function for misc */
22 rg_rights_register("user", $rg_user_rights, "", FALSE, FALSE);
21 23
22 24 $rg_user_error = ""; $rg_user_error = "";
23 25
 
... ... function rg_user_ok($user)
234 236 function rg_user_lookup_by_old_name($db, $old_name) function rg_user_lookup_by_old_name($db, $old_name)
235 237 { {
236 238 rg_prof_start("user_lookup_by_old_name"); rg_prof_start("user_lookup_by_old_name");
237 rg_log("user_lookup_by_old_name: old_name=$old_name");
239 rg_log_enter("user_lookup_by_old_name: old_name=$old_name");
238 240
239 241 $ret = FALSE; $ret = FALSE;
240 do {
242 while (1) {
241 243 $x = rg_cache_get("old_name::" . $old_name); $x = rg_cache_get("old_name::" . $old_name);
242 244 if ($x !== FALSE) { if ($x !== FALSE) {
243 245 $ret = $x; $ret = $x;
 
... ... function rg_user_lookup_by_old_name($db, $old_name)
263 265 $ret = $row['uid']; $ret = $row['uid'];
264 266
265 267 rg_cache_set("old_name::" . $old_name, $ret); rg_cache_set("old_name::" . $old_name, $ret);
266 } while (0);
268 break;
269 }
267 270
271 rg_log_exit();
268 272 rg_prof_end("user_lookup_by_old_name"); rg_prof_end("user_lookup_by_old_name");
269 273 return $ret; return $ret;
270 274 } }
 
... ... function rg_user_lookup_by_old_name($db, $old_name)
275 279 function rg_user_insert_rename($db, $uid, $old_name) function rg_user_insert_rename($db, $uid, $old_name)
276 280 { {
277 281 rg_prof_start("user_insert_rename"); rg_prof_start("user_insert_rename");
278 rg_log("user_insert_rename: uid=$uid old_name=$old_name");
282 rg_log_enter("user_insert_rename: uid=$uid old_name=$old_name");
279 283
280 284 $ret = FALSE; $ret = FALSE;
281 do {
285 while(1) {
282 286 // Check if already exists in the database // Check if already exists in the database
283 287 $r = rg_user_lookup_by_old_name($db, $old_name); $r = rg_user_lookup_by_old_name($db, $old_name);
284 288 if ($r === FALSE) if ($r === FALSE)
 
... ... function rg_user_insert_rename($db, $uid, $old_name)
307 311 rg_cache_set("old_name::" . $old_name, $uid); rg_cache_set("old_name::" . $old_name, $uid);
308 312
309 313 $ret = TRUE; $ret = TRUE;
310 } while (0);
314 break;
315 }
311 316
317 rg_log_exit();
312 318 rg_prof_end("user_insert_rename"); rg_prof_end("user_insert_rename");
313 319 return $ret; return $ret;
314 320 } }
 
... ... function rg_user_insert_rename($db, $uid, $old_name)
320 326 function rg_user_rename($db, $ui, $new_name) function rg_user_rename($db, $ui, $new_name)
321 327 { {
322 328 rg_prof_start("user_rename"); rg_prof_start("user_rename");
323 rg_log("user_rename: from=[" . $ui['username'] . "]"
329 rg_log_enter("user_rename: from=[" . $ui['username'] . "]"
324 330 . " to=[" . $new_name . "]..."); . " to=[" . $new_name . "]...");
325 331
326 332 $user_path = rg_user_path_by_id($ui['uid']); $user_path = rg_user_path_by_id($ui['uid']);
 
... ... function rg_user_rename($db, $ui, $new_name)
329 335 rg_log("old_path=$old_path new_path=$new_path"); rg_log("old_path=$old_path new_path=$new_path");
330 336
331 337 $ret = FALSE; $ret = FALSE;
332 do {
338 while (1) {
333 339 $do_link = TRUE; $do_link = TRUE;
334 340
335 341 // Check if we already did the rename // Check if we already did the rename
 
... ... function rg_user_rename($db, $ui, $new_name)
366 372 rg_internal_error("Cannot symlink $old_path -> $new_path ($php_errormsg)!"); rg_internal_error("Cannot symlink $old_path -> $new_path ($php_errormsg)!");
367 373 break; break;
368 374 } }
369 }
375 }
370 376
371 377 // TOOD: transaction? // TOOD: transaction?
372 378 $r = rg_user_insert_rename($db, $ui['uid'], $new_name); $r = rg_user_insert_rename($db, $ui['uid'], $new_name);
 
... ... function rg_user_rename($db, $ui, $new_name)
374 380 break; break;
375 381
376 382 // TODO: Check if all parameters are used. // TODO: Check if all parameters are used.
377 $event = array("category" => 2005, "prio" => 50,
383 $event = array("category" => 2005, "prio" => 50,
378 384 "ui.rename_from" => $ui['username'], "ui.rename_from" => $ui['username'],
379 385 "ui.rename_to" => $new_name, "ui.rename_to" => $new_name,
380 386 "IP" => rg_var_str("REMOTE_ADDR"), "IP" => rg_var_str("REMOTE_ADDR"),
 
... ... function rg_user_rename($db, $ui, $new_name)
387 393 } }
388 394
389 395 $ret = TRUE; $ret = TRUE;
390 } while (0);
396 break;
397 }
391 398
399 rg_log_exit();
392 400 rg_prof_end("user_rename"); rg_prof_end("user_rename");
393 401 return $ret; return $ret;
394 402 } }
 
... ... function rg_user_edit($db, $d)
402 410 global $rg_account_email_confirm; global $rg_account_email_confirm;
403 411
404 412 rg_prof_start("user_edit"); rg_prof_start("user_edit");
405 rg_log("user_edit: d: " . rg_array2string($d));
413 rg_log_enter("user_edit: d: " . rg_array2string($d));
406 414
407 415 $ret = FALSE; $ret = FALSE;
408 do {
416 while (1) {
409 417 if (rg_user_ok($d['username']) !== TRUE) if (rg_user_ok($d['username']) !== TRUE)
410 418 break; break;
411 419
 
... ... function rg_user_edit($db, $d)
507 515 } }
508 516
509 517 $ret = $row['uid']; $ret = $row['uid'];
510 } while (0);
518 break;
519 }
511 520
521 rg_log_exit();
512 522 rg_prof_end("user_edit"); rg_prof_end("user_edit");
513 523 return $ret; return $ret;
514 524 } }
 
... ... function rg_user_edit($db, $d)
519 529 function rg_user_remove($db, $rg, $uid) function rg_user_remove($db, $rg, $uid)
520 530 { {
521 531 rg_prof_start("user_remove"); rg_prof_start("user_remove");
522 rg_log("user_remove: uid=$uid");
532 rg_log_enter("user_remove: uid=$uid");
523 533
524 534 $ret = FALSE; $ret = FALSE;
525 do {
535 while (1) {
526 536 if (!rg_rights_allow($rg['login_ui']['rights'], "R", $rg['ip'], "")) if (!rg_rights_allow($rg['login_ui']['rights'], "R", $rg['ip'], ""))
527 537 break; break;
528 538
 
... ... function rg_user_remove($db, $rg, $uid)
539 549 rg_cache_unset("user::" . $uid); rg_cache_unset("user::" . $uid);
540 550
541 551 $ret = TRUE; $ret = TRUE;
542 } while (0);
552 break;
553 }
543 554
555 rg_log_exit();
544 556 rg_prof_end("user_remove"); rg_prof_end("user_remove");
545 557 return $ret; return $ret;
546 558 } }
 
... ... function rg_user_remove($db, $rg, $uid)
551 563 function rg_user_info($db, $uid, $user, $email) function rg_user_info($db, $uid, $user, $email)
552 564 { {
553 565 rg_prof_start("user_info"); rg_prof_start("user_info");
566 rg_log_enter("user_info: uid=$uid user=$user email=$email");
554 567
555 568 $ret = array(); $ret = array();
556 569 $ret['ok'] = 0; $ret['ok'] = 0;
 
... ... function rg_user_info($db, $uid, $user, $email)
563 576 $set_cache_user = FALSE; $set_cache_user = FALSE;
564 577 $set_cache_email = FALSE; $set_cache_email = FALSE;
565 578 while (1) { while (1) {
566 //rg_log("user_info: uid=$uid user=$user email=$email.");
567
568 579 $params = array("uid" => $uid, $params = array("uid" => $uid,
569 580 "user" => $user, "user" => $user,
570 581 "email" => $email); "email" => $email);
571 582
572 583 if ($uid > 0) { if ($uid > 0) {
573 $c = rg_cache_get("user::" . $uid);
574 if ($c !== FALSE) {
575 $ret = unserialize($c);
576 if ($ret === FALSE)
577 rg_log("cannot unserialize ($c)");
584 $ret = rg_cache_get("user::" . $uid);
585 if ($ret !== FALSE)
578 586 break; break;
579 }
580 587
581 588 $sql = "SELECT * FROM users WHERE uid = @@uid@@"; $sql = "SELECT * FROM users WHERE uid = @@uid@@";
582 589 $set_cache = TRUE; $set_cache = TRUE;
 
... ... function rg_user_info($db, $uid, $user, $email)
617 624 $row = rg_sql_fetch_array($res); $row = rg_sql_fetch_array($res);
618 625 rg_sql_free_result($res); rg_sql_free_result($res);
619 626 if ($rows == 0) { if ($rows == 0) {
620 rg_log("user not found");
627 rg_log("user_info: user [$uid/$user/$email] not found");
621 628 rg_user_set_error("user not found"); rg_user_set_error("user not found");
622 629 break; break;
623 630 } }
 
... ... function rg_user_info($db, $uid, $user, $email)
625 632 $ret = array_merge($ret, $row); $ret = array_merge($ret, $row);
626 633 $ret['exists'] = 1; $ret['exists'] = 1;
627 634 break; break;
628 };
635 }
629 636
630 637 if (($ret['ok'] == 1) && $set_cache) if (($ret['ok'] == 1) && $set_cache)
631 rg_cache_set("user::" . $ret['uid'], serialize($ret));
638 rg_cache_set("user::" . $ret['uid'], $ret);
632 639
633 640 if ($ret['exists'] == 1) { if ($ret['exists'] == 1) {
634 641 if ($set_cache_user) if ($set_cache_user)
 
... ... function rg_user_info($db, $uid, $user, $email)
638 645 rg_cache_set("email_to_uid::" . $ret['email'], $ret['uid']); rg_cache_set("email_to_uid::" . $ret['email'], $ret['uid']);
639 646 } }
640 647
648 rg_log_exit();
641 649 rg_prof_end("user_info"); rg_prof_end("user_info");
642 650 return $ret; return $ret;
643 651 } }
 
... ... function rg_user_info($db, $uid, $user, $email)
648 656 function rg_user_login_by_sid($db, &$rg) function rg_user_login_by_sid($db, &$rg)
649 657 { {
650 658 rg_prof_start("user_login_by_sid"); rg_prof_start("user_login_by_sid");
651 rg_log("user_login_by_sid: sid=" . $rg['sid']);
659 rg_log_enter("user_login_by_sid: sid=" . $rg['sid']);
652 660
653 661 // Make sure it is not passed by client // Make sure it is not passed by client
654 662 $rg['login_ui'] = array(); $rg['login_ui'] = array();
 
... ... function rg_user_login_by_sid($db, &$rg)
658 666 $rg['login_ui']['username'] = ""; $rg['login_ui']['username'] = "";
659 667
660 668 $ret = FALSE; $ret = FALSE;
661 do {
669 while (1) {
662 670 if (empty($rg['sid'])) { if (empty($rg['sid'])) {
663 671 rg_log("\tNo sid!"); rg_log("\tNo sid!");
664 672 break; break;
 
... ... function rg_user_login_by_sid($db, &$rg)
675 683 if ($rg['login_ui']['exists'] != 1) { if ($rg['login_ui']['exists'] != 1) {
676 684 rg_log("\tUid $uid does not exists (" . rg_user_error() . ")!"); rg_log("\tUid $uid does not exists (" . rg_user_error() . ")!");
677 685 rg_user_set_error("invalid uid"); rg_user_set_error("invalid uid");
678 break;
686 break;
679 687 } }
680 688
681 689 rg_sess_update($db, $sess); rg_sess_update($db, $sess);
 
... ... function rg_user_login_by_sid($db, &$rg)
683 691 rg_user_set_last_seen($db, $rg['login_ui']['uid']); rg_user_set_last_seen($db, $rg['login_ui']['uid']);
684 692
685 693 $ret = TRUE; $ret = TRUE;
686 } while (0);
694 break;
695 }
687 696
697 rg_log_exit();
688 698 rg_prof_end("user_login_by_sid"); rg_prof_end("user_login_by_sid");
689 699 return $ret; return $ret;
690 700 } }
 
... ... function rg_user_pass_valid($db, $uid, $pass)
723 733 function rg_user_auto_login($db, $uid, $lock_ip, &$ui) function rg_user_auto_login($db, $uid, $lock_ip, &$ui)
724 734 { {
725 735 rg_prof_start("user_auto_login"); rg_prof_start("user_auto_login");
726 rg_log("user_auto_login: uid=$uid lock_ip=$lock_ip");
736 rg_log_enter("user_auto_login: uid=$uid lock_ip=$lock_ip");
727 737
728 738 $ret = FALSE; $ret = FALSE;
729 do {
739 while (1) {
730 740 $ui = rg_user_info($db, $uid, "", ""); $ui = rg_user_info($db, $uid, "", "");
731 741 if ($ui['ok'] != 1) if ($ui['ok'] != 1)
732 742 break; break;
 
... ... function rg_user_auto_login($db, $uid, $lock_ip, &$ui)
746 756 $secure, TRUE /* httponly */); $secure, TRUE /* httponly */);
747 757
748 758 $ret = TRUE; $ret = TRUE;
749 } while (0);
759 break;
760 }
750 761
762 rg_log_exit();
751 763 rg_prof_end("user_auto_login"); rg_prof_end("user_auto_login");
752 764 return $ret; return $ret;
753 765 } }
 
... ... function rg_user_auto_login($db, $uid, $lock_ip, &$ui)
757 769 */ */
758 770 function rg_user_login_by_user_pass($db, $user, $pass, $lock_ip, &$ui) function rg_user_login_by_user_pass($db, $user, $pass, $lock_ip, &$ui)
759 771 { {
760 rg_log("user_login_by_user_pass: user=$user, pass=$pass lock_ip=$lock_ip");
772 rg_prof_start("user_login_by_user_pass");
773 rg_log_enter("user_login_by_user_pass: user=$user, pass=$pass"
774 . " lock_ip=$lock_ip");
761 775
762 776 $ui = array(); $ui = array();
763 777 $ui['uid'] = 0; $ui['uid'] = 0;
764 778 $ui['is_admin'] = 0; $ui['is_admin'] = 0;
765 779 $ui['rights'] = ""; $ui['rights'] = "";
766 780
767 if (empty($user) || empty($pass)) {
768 rg_user_set_error("invalid user or pass");
769 rg_log("user or pass are empty");
770 return FALSE;
771 }
781 $ret = FALSE;
782 while (1) {
783 if (empty($user) || empty($pass)) {
784 rg_user_set_error("invalid user or pass");
785 rg_log("user or pass are empty");
786 break;
787 }
772 788
773 $ui0 = rg_user_info($db, 0, $user, "");
774 if ($ui0['ok'] != 1)
775 return FALSE;
776 if ($ui0['exists'] != 1) {
777 rg_user_set_error("invalid user or pass");
778 rg_log("user doesn't exists");
779 return FALSE;
780 }
789 $ui0 = rg_user_info($db, 0, $user, "");
790 if ($ui0['ok'] != 1)
791 break;
792 if ($ui0['exists'] != 1) {
793 rg_user_set_error("invalid user or pass");
794 rg_log("user doesn't exists");
795 break;
796 }
781 797
782 if ($ui0['suspended'] > 0) {
783 rg_user_set_error("invalid user or pass");
784 rg_log("account is suspended");
785 return FALSE;
786 }
798 if ($ui0['suspended'] > 0) {
799 rg_user_set_error("invalid user or pass");
800 rg_log("account is suspended");
801 break;
802 }
787 803
788 if ($ui0['confirmed'] == 0) {
789 rg_user_set_error("invalid user or pass");
790 rg_log("account is not confirmed");
791 return FALSE;
792 }
804 if ($ui0['confirmed'] == 0) {
805 rg_user_set_error("invalid user or pass");
806 rg_log("account is not confirmed");
807 break;
808 }
793 809
794 $sha1pass = rg_user_pass($ui0['salt'], $pass);
795 if (strcmp($sha1pass, $ui0['pass']) != 0) {
796 rg_user_set_error("invalid user or pass");
797 rg_log("pass mismatch");
798 return FALSE;
799 }
810 $sha1pass = rg_user_pass($ui0['salt'], $pass);
811 if (strcmp($sha1pass, $ui0['pass']) != 0) {
812 rg_user_set_error("invalid user or pass");
813 rg_log("pass mismatch");
814 break;
815 }
800 816
801 $ui = $ui0;
802 rg_user_auto_login($db, $ui['uid'], $lock_ip, $ui);
817 $ui = $ui0;
818 rg_user_auto_login($db, $ui['uid'], $lock_ip, $ui);
803 819
804 rg_user_set_last_seen($db, $ui['uid']);
820 rg_user_set_last_seen($db, $ui['uid']);
805 821
806 return TRUE;
822 $ret = TRUE;
823 break;
824 }
825
826 rg_log_exit();
827 rg_prof_start("user_login_by_user_pass");
828 return $ret;
807 829 } }
808 830
809 831 /* /*
 
... ... function rg_user_login_by_user_pass($db, $user, $pass, $lock_ip, &$ui)
812 834 */ */
813 835 function rg_user_suspend($db, $rg, $uid, $op) function rg_user_suspend($db, $rg, $uid, $op)
814 836 { {
815 rg_log("user_suspend: uid=$uid, op=$op");
837 rg_log_enter("user_suspend: uid=$uid, op=$op");
816 838
817 if (!rg_rights_allow($rg['login_ui']['rights'], "S", $rg['ip'], ""))
818 return FALSE;
839 $ret = FALSE;
840 while (1) {
841 if (!rg_rights_allow($rg['login_ui']['rights'], "S", $rg['ip'], ""))
842 break;
819 843
820 $now = time();
844 $now = time();
821 845
822 if ($op == 1)
823 $v = $now;
824 else
825 $v = 0;
826
827 $params = array("suspeneded" => $v,
828 "uid" => $uid);
829 $sql = "UPDATE users SET suspended = @@suspended@@"
830 . " WHERE uid = @@uid@@";
831 $res = rg_sql_query_params($db, $sql, $params);
832 if ($res === FALSE) {
833 rg_user_set_error("cannot suspend (" . rg_sql_error() . ")");
834 return FALSE;
835 }
836 rg_sql_free_result($res);
846 if ($op == 1)
847 $v = $now;
848 else
849 $v = 0;
837 850
838 // Invalidate cache.
839 rg_cache_unset("user::" . $uid);
851 $params = array("suspeneded" => $v,
852 "uid" => $uid);
853 $sql = "UPDATE users SET suspended = @@suspended@@"
854 . " WHERE uid = @@uid@@";
855 $res = rg_sql_query_params($db, $sql, $params);
856 if ($res === FALSE) {
857 rg_user_set_error("cannot suspend (" . rg_sql_error() . ")");
858 break;
859 }
860 rg_sql_free_result($res);
840 861
841 return TRUE;
862 // update cache
863 rg_cache_set("user::" . $uid . "::suspended", $v);
864
865 break;
866 }
867
868 rg_log_exit();
869 return $ret;
842 870 } }
843 871
844 872 /* /*
 
... ... function rg_user_suspend($db, $rg, $uid, $op)
847 875 */ */
848 876 function rg_user_make_admin($db, $rg, $uid, $op) function rg_user_make_admin($db, $rg, $uid, $op)
849 877 { {
850 rg_log("user_make_admin: uid=$uid, op=$op");
851 878 rg_prof_start("user_make_admin"); rg_prof_start("user_make_admin");
879 rg_log_enter("user_make_admin: uid=$uid, op=$op");
852 880
853 881 $ret = FALSE; $ret = FALSE;
854 do {
855 // BIG TODO: here how do we specify the target repo?!
856 // Why should we?! It is about a user to become admin
857 // not about a repo!
858 // Also, we need to do a rg_rights_get to obtain the list of
859 // rights
860 if (!rg_rights_allow($rg['login_ui']['rights'], "A", $rg['ip'], ""))
861 return FALSE;
882 while (1) {
883 // We need to do a rg_rights_get to obtain the list of rights
884 if (!rg_rights_allow($rg['login_ui']['rights'], "M", $rg['ip'], ""))
885 break;
862 886
863 887 $params = array("op" => $op, "uid" => $uid); $params = array("op" => $op, "uid" => $uid);
864 888 $sql = "UPDATE users SET is_admin = @@op@@" $sql = "UPDATE users SET is_admin = @@op@@"
 
... ... function rg_user_make_admin($db, $rg, $uid, $op)
870 894 } }
871 895 rg_sql_free_result($res); rg_sql_free_result($res);
872 896
873 // TODO: check if this is working
874 897 rg_cache_set("user::" . $uid . "::is_admin", 1); rg_cache_set("user::" . $uid . "::is_admin", 1);
898
875 899 $ret = TRUE; $ret = TRUE;
876 } while (0);
900 break;
901 }
877 902
903 rg_log_exit();
878 904 rg_prof_end("user_make_admin"); rg_prof_end("user_make_admin");
879 905 return $ret; return $ret;
880 906 } }
 
... ... function rg_user_make_admin($db, $rg, $uid, $op)
884 910 */ */
885 911 function rg_user_set_last_seen($db, $uid) function rg_user_set_last_seen($db, $uid)
886 912 { {
887 rg_log("user_set_last_seen: uid=$uid");
913 rg_log_enter("user_set_last_seen: uid=$uid");
888 914
889 $now = time();
915 $ret = FALSE;
916 while (1) {
917 $now = time();
890 918
891 $IP = $_SERVER['REMOTE_ADDR'];
919 $IP = $_SERVER['REMOTE_ADDR'];
892 920
893 $params = array("now" => $now,
894 "IP" => $IP,
895 "uid" => $uid);
896 $sql = "UPDATE users SET last_seen = @@now@@, last_ip = @@IP@@"
897 . " WHERE uid = @@uid@@";
898 $res = rg_sql_query_params($db, $sql, $params);
899 if ($res === FALSE) {
900 rg_user_set_error("cannot update last seen (" . rg_sql_error() . ")");
901 return FALSE;
902 }
903 rg_sql_free_result($res);
921 $params = array("last_seen" => $now,
922 "last_ip" => $IP,
923 "uid" => $uid);
924 $sql = "UPDATE users SET last_seen = @@last_seen@@"
925 . ", last_ip = @@last_ip@@"
926 . " WHERE uid = @@uid@@";
927 $res = rg_sql_query_params($db, $sql, $params);
928 if ($res === FALSE) {
929 rg_user_set_error("cannot update last seen (" . rg_sql_error() . ")");
930 break;
931 }
932 rg_sql_free_result($res);
904 933
905 // TODO: check if we need to invalidate cache
934 rg_cache_merge("user::" . $uid, $params);
906 935
907 return TRUE;
936 $ret = TRUE;
937 break;
938 }
939
940 rg_log_exit();
941 return $ret;
908 942 } }
909 943
910 944 /* /*
 
... ... function rg_user_set_last_seen($db, $uid)
913 947 */ */
914 948 function rg_user_list($db) function rg_user_list($db)
915 949 { {
916 rg_log("user_list");
917
918 $ret = "";
950 rg_prof_start("user_list");
951 rg_log_enter("user_list");
919 952
920 $sql = "SELECT * FROM users ORDER BY username";
921 $res = rg_sql_query($db, $sql);
922 if ($res === FALSE) {
923 rg_user_set_error("cannot get info (" . rg_sql_error() . ")!");
924 return FALSE;
925 }
953 $ret = FALSE;
954 while (1) {
955 $sql = "SELECT * FROM users ORDER BY username";
956 $res = rg_sql_query($db, $sql);
957 if ($res === FALSE) {
958 rg_user_set_error("cannot get info (" . rg_sql_error() . ")!");
959 break;
960 }
926 961
927 $ret .= "<table>\n";
928 $ret .= "<tr>\n";
929 $ret .= " <th>User name</th>\n";
930 $ret .= " <th>Name</th>\n";
931 $ret .= " <th>E-mail</th>\n";
932 $ret .= " <th>Admin?</th>\n";
933 $ret .= " <th>Creation date (UTC)</th>\n";
934 $ret .= " <th>Plan</th>\n";
935 $ret .= " <th>Suspended?</th>\n";
936 $ret .= " <th>Confirmed?</th>\n";
937 $ret .= " <th>Session time</th>\n";
938 $ret .= " <th>Last seen (UTC)</th>\n";
939 $ret .= " <th>Last IP</th>\n";
940 $ret .= " <th>Rights</th>\n";
941 $ret .= " <th>Operations</th>\n";
942 $ret .= "</tr>\n";
943 while (($row = rg_sql_fetch_array($res))) {
962 $ret = "";
963 $ret .= "<table>\n";
944 964 $ret .= "<tr>\n"; $ret .= "<tr>\n";
945 $ret .= " <td>" . $row['username'] . "</td>\n";
946 $ret .= " <td>" . $row['realname'] . "</td>\n";
947 $ret .= " <td>" . $row['email'] . "</td>\n";
948 $ret .= " <td>" . ($row['is_admin'] == 1 ? "Yes" : "No") . "</td>\n";
949 $ret .= " <td>" . gmdate("Y-m-d", $row['itime']) . "</td>\n";
950
951 $pi = rg_plan_info($db, $row['plan_id']);
952 $plan = "Unlimited";
953 if ($pi['exists'] == 1)
954 $plan = $pi['name'];
955 $ret .= " <td>" . $plan . "</td>\n";
956 $ret .= " <td>" . ($row['suspended'] == 0 ? "No" : "Yes") . "</th>\n";
957 $ret .= " <td>" . ($row['confirmed'] == 0 ? "No" : gmdate("Y-m-d", $row['confirmed'])) . "</th>\n";
958 $ret .= " <td>" . $row['session_time'] . "s</td>\n";
959 $v = $row['last_seen'] == 0 ? "-" : gmdate("Y-m-d", $row['last_seen']);
960 $ret .= " <td>" . $v . "</td>\n";
961 $ret .= " <td>" . $row['last_ip'] . "</td>\n";
962 $v = implode(", ", rg_rights_text("user", $row['rights']));
963 $ret .= " <td>" . $v . "</td>\n";
964
965 // operations
966 $url = "/op/admin/users";
967 $url2 = $row['username'];
968 $ret .= " <td>";
969
970 // edit
971 $ret .= "[<a href=\"$url/edit/$url2\">Edit</a>]";
972
973 // suspend
974 $v = "suspend"; $t = "Suspend";
975 if ($row['suspended'] > 0) {
976 $t = "Unsuspend";
977 $v = "unsuspend";
978 }
979 $ret .= "[<a href=\"$url/$v/$url2\">$t</a>]";
965 $ret .= " <th>User name</th>\n";
966 $ret .= " <th>Name</th>\n";
967 $ret .= " <th>E-mail</th>\n";
968 $ret .= " <th>Admin?</th>\n";
969 $ret .= " <th>Creation date (UTC)</th>\n";
970 $ret .= " <th>Plan</th>\n";
971 $ret .= " <th>Suspended?</th>\n";
972 $ret .= " <th>Confirmed?</th>\n";
973 $ret .= " <th>Session time</th>\n";
974 $ret .= " <th>Last seen (UTC)</th>\n";
975 $ret .= " <th>Last IP</th>\n";
976 $ret .= " <th>Rights</th>\n";
977 $ret .= " <th>Operations</th>\n";
978 $ret .= "</tr>\n";
979 while (($row = rg_sql_fetch_array($res))) {
980 $ret .= "<tr>\n";
981 $ret .= " <td>" . $row['username'] . "</td>\n";
982 $ret .= " <td>" . $row['realname'] . "</td>\n";
983 $ret .= " <td>" . $row['email'] . "</td>\n";
984 $ret .= " <td>" . ($row['is_admin'] == 1 ? "Yes" : "No") . "</td>\n";
985 $ret .= " <td>" . gmdate("Y-m-d", $row['itime']) . "</td>\n";
986
987 $pi = rg_plan_info($db, $row['plan_id']);
988 $plan = "Unlimited";
989 if ($pi['exists'] == 1)
990 $plan = $pi['name'];
991 $ret .= " <td>" . $plan . "</td>\n";
992 $ret .= " <td>" . ($row['suspended'] == 0 ? "No" : "Yes") . "</th>\n";
993 $ret .= " <td>" . ($row['confirmed'] == 0 ? "No" : gmdate("Y-m-d", $row['confirmed'])) . "</th>\n";
994 $ret .= " <td>" . $row['session_time'] . "s</td>\n";
995 $v = $row['last_seen'] == 0 ? "-" : gmdate("Y-m-d", $row['last_seen']);
996 $ret .= " <td>" . $v . "</td>\n";
997 $ret .= " <td>" . $row['last_ip'] . "</td>\n";
998 $v = implode(", ", rg_rights_text("user", $row['rights']));
999 $ret .= " <td>" . $v . "</td>\n";
1000
1001 // operations
1002 $url = "/op/admin/users";
1003 $url2 = $row['username'];
1004 $ret .= " <td>";
1005
1006 // edit
1007 $ret .= "[<a href=\"$url/edit/$url2\">Edit</a>]";
1008
1009 // suspend
1010 $v = "suspend"; $t = "Suspend";
1011 if ($row['suspended'] > 0) {
1012 $t = "Unsuspend";
1013 $v = "unsuspend";
1014 }
1015 $ret .= "[<a href=\"$url/$v/$url2\">$t</a>]";
980 1016
981 // admin
982 $v = "make_admin"; $t = "Make admin";
983 if ($row['is_admin'] == 1) {
984 $t = "Remove admin";
985 $v = "remove_admin";
986 }
987 $ret .= "[<a href=\"$url/$v/$url2\">$t</a>]";
1017 // admin
1018 $v = "make_admin"; $t = "Make admin";
1019 if ($row['is_admin'] == 1) {
1020 $t = "Remove admin";
1021 $v = "remove_admin";
1022 }
1023 $ret .= "[<a href=\"$url/$v/$url2\">$t</a>]";
988 1024
989 // remove
990 if ($row['suspended'] > 0)
991 $ret .= "[<a href=\"$url/remove/$url2\">Remove!</a>]";
1025 // remove
1026 if ($row['suspended'] > 0)
1027 $ret .= "[<a href=\"$url/remove/$url2\">Remove!</a>]";
992 1028
993 $ret .= " </td>";
994 $ret .= "</tr>\n";
1029 $ret .= " </td>";
1030 $ret .= "</tr>\n";
1031 }
1032 $ret .= "</table>\n";
1033 rg_sql_free_result($res);
1034 break;
995 1035 } }
996 $ret .= "</table>\n";
997 rg_sql_free_result($res);
998 1036
1037 rg_log_exit();
1038 rg_prof_end("user_list");
999 1039 return $ret; return $ret;
1000 1040 } }
1001 1041
 
... ... function rg_user_forgot_pass_uid($db, $token)
1008 1048 $ret['ok'] = 0; $ret['ok'] = 0;
1009 1049 $ret['uid'] = 0; $ret['uid'] = 0;
1010 1050
1011 rg_log("user_forgot_pass_uid: token=$token");
1051 rg_log_enter("user_forgot_pass_uid: token=$token");
1012 1052
1013 $now = time();
1053 while (1) {
1054 $now = time();
1014 1055
1015 $params = array("token" => $token, "now" => $now);
1016 $sql = "SELECT uid FROM forgot_pass"
1017 . " WHERE token = @@token@@"
1018 . " AND expire > @@now@@";
1019 $res = rg_sql_query_params($db, $sql, $params);
1020 if ($res === FALSE) {
1021 rg_user_set_error("cannot lookup token (" . rg_sql_error() . ")");
1022 return $ret;
1023 }
1056 $params = array("token" => $token, "now" => $now);
1057 $sql = "SELECT uid FROM forgot_pass"
1058 . " WHERE token = @@token@@"
1059 . " AND expire > @@now@@";
1060 $res = rg_sql_query_params($db, $sql, $params);
1061 if ($res === FALSE) {
1062 rg_user_set_error("cannot lookup token (" . rg_sql_error() . ")");
1063 break;
1064 }
1024 1065
1025 $ret['ok'] = 1;
1066 $ret['ok'] = 1;
1026 1067
1027 $rows = rg_sql_num_rows($res);
1028 if ($rows > 0)
1029 $row = rg_sql_fetch_array($res);
1030 rg_sql_free_result($res);
1031 if ($rows == 0)
1032 return $ret;
1068 $rows = rg_sql_num_rows($res);
1069 if ($rows > 0)
1070 $row = rg_sql_fetch_array($res);
1071 rg_sql_free_result($res);
1072 if ($rows == 0)
1073 break;
1033 1074
1034 $ret['uid'] = $row['uid'];
1075 $ret['uid'] = $row['uid'];
1076 break;
1077 }
1035 1078
1079 rg_log_exit();
1036 1080 return $ret; return $ret;
1037 1081 } }
1038 1082
 
... ... function rg_user_forgot_pass_mail_prepare($db, $email)
1050 1094 $expire = time() + 24 * 3600; $expire = time() + 24 * 3600;
1051 1095 $token = rg_id(20); $token = rg_id(20);
1052 1096
1053 $r = rg_user_info($db, 0, "", $email);
1054 if ($r['ok'] == 0) {
1055 rg_log("\tInternal error.");
1056 return $ret;
1057 }
1058 if ($r['exists'] == 0) {
1059 rg_log("\tUser does not exists.");
1097 while (1) {
1098 $r = rg_user_info($db, 0, "", $email);
1099 if ($r['ok'] == 0) {
1100 rg_log("\tInternal error.");
1101 break;
1102 }
1103 if ($r['exists'] == 0) {
1104 rg_log("\tUser does not exists.");
1105 $ret['ok'] = 1;
1106 break;
1107 }
1108 $uid = $r['uid'];
1109
1110 // store token in database
1111 $params = array("token" => $token,
1112 "uid" => $uid,
1113 "expire" => $expire);
1114 $sql = "INSERT INTO forgot_pass (token, uid, expire)"
1115 . " VALUES (@@token@@, @@uid@@, @@expire@@)";
1116 $res = rg_sql_query_params($db, $sql, $params);
1117 if ($res === FALSE) {
1118 rg_user_set_error("cannot query (" . rg_sql_error() . ")");
1119 break;
1120 }
1121 rg_sql_free_result($res);
1122
1060 1123 $ret['ok'] = 1; $ret['ok'] = 1;
1061 return $ret;
1062 }
1063 $uid = $r['uid'];
1064
1065 // store token in database
1066 $params = array("token" => $token,
1067 "uid" => $uid,
1068 "expire" => $expire);
1069 $sql = "INSERT INTO forgot_pass (token, uid, expire)"
1070 . " VALUES (@@token@@, @@uid@@, @@expire@@)";
1071 $res = rg_sql_query_params($db, $sql, $params);
1072 if ($res === FALSE) {
1073 rg_user_set_error("cannot query (" . rg_sql_error() . ")");
1074 return $ret;
1124 $ret['exists'] = 1;
1125 $ret['token'] = $token;
1126 break;
1075 1127 } }
1076 rg_sql_free_result($res);
1077
1078 $ret['ok'] = 1;
1079 $ret['exists'] = 1;
1080 $ret['token'] = $token;
1081 1128
1082 1129 rg_log("DEBUG: user_forgot_pass_mail_prepare: ret=" . rg_array2string($ret)); rg_log("DEBUG: user_forgot_pass_mail_prepare: ret=" . rg_array2string($ret));
1083 1130
1131 rg_log_exit();
1084 1132 return $ret; return $ret;
1085 1133 } }
1086 1134
 
... ... function rg_user_forgot_pass_mail($db, $email)
1133 1181 */ */
1134 1182 function rg_user_forgot_pass_destroy($db, $uid) function rg_user_forgot_pass_destroy($db, $uid)
1135 1183 { {
1136 rg_log("user_forgot_pass_destroy: uid=$uid");
1184 rg_log_enter("user_forgot_pass_destroy: uid=$uid");
1137 1185
1138 $params = array("uid" => $uid);
1139 $sql = "DELETE FROM forgot_pass WHERE uid = @@uid@@";
1140 $res = rg_sql_query_params($db, $sql, $params);
1141 if ($res === FALSE) {
1142 rg_user_set_error("cannot query (" . rg_sql_error() . ")");
1143 return FALSE;
1186 $ret = FALSE;
1187 while (1) {
1188 $params = array("uid" => $uid);
1189 $sql = "DELETE FROM forgot_pass WHERE uid = @@uid@@";
1190 $res = rg_sql_query_params($db, $sql, $params);
1191 if ($res === FALSE) {
1192 rg_user_set_error("cannot query (" . rg_sql_error() . ")");
1193 break;
1194 }
1195 rg_sql_free_result($res);
1196
1197 $ret = TRUE;
1198 break;
1144 1199 } }
1145 rg_sql_free_result($res);
1146 1200
1147 return TRUE;
1201 rg_log_exit();
1202 return $ret;
1148 1203 } }
1149 1204
1150 1205 function rg_user_set_pass($db, $uid, $pass) function rg_user_set_pass($db, $uid, $pass)
1151 1206 { {
1152 1207 rg_log("user_set_pass: uid=$uid pass=$pass"); rg_log("user_set_pass: uid=$uid pass=$pass");
1153 1208
1154 $salt = rg_id(40);
1155 $pass = rg_user_pass($salt, $pass);
1156
1157 $params = array("salt" => $salt,
1158 "pass" => $pass,
1159 "uid" => $uid);
1160 $sql = "UPDATE users SET"
1161 ." salt = @@salt@@"
1162 . ", pass = @@pass@@"
1163 . " WHERE uid = @@uid@@";
1164 $res = rg_sql_query_params($db, $sql, $params);
1165 if ($res === FALSE) {
1166 rg_user_set_error("cannot update pass (" . rg_sql_error() . ")");
1167 return FALSE;
1168 }
1169 rg_sql_free_result($res);
1209 $ret = FALSE;
1210 while (1) {
1211 $salt = rg_id(40);
1212 $pass = rg_user_pass($salt, $pass);
1213
1214 $params = array("salt" => $salt,
1215 "pass" => $pass,
1216 "uid" => $uid);
1217 $sql = "UPDATE users SET"
1218 ." salt = @@salt@@"
1219 . ", pass = @@pass@@"
1220 . " WHERE uid = @@uid@@";
1221 $res = rg_sql_query_params($db, $sql, $params);
1222 if ($res === FALSE) {
1223 rg_user_set_error("cannot update pass (" . rg_sql_error() . ")");
1224 break;
1225 }
1226 rg_sql_free_result($res);
1170 1227
1171 // Invalidate cache.
1172 rg_cache_unset("user::" . $uid);
1228 // Invalidate cache.
1229 rg_cache_unset("user::" . $uid);
1173 1230
1174 return TRUE;
1231 $ret = TRUE;
1232 break;
1233 }
1234
1235 rg_log_exit();
1236 return $ret;
1175 1237 } }
1176 1238
1177 1239 /* /*
 
... ... function rg_user_set_pass($db, $uid, $pass)
1180 1242 function rg_user_confirm($db, $token) function rg_user_confirm($db, $token)
1181 1243 { {
1182 1244 rg_prof_start("user_confirm"); rg_prof_start("user_confirm");
1183 rg_log("user_confirm: token=$token");
1245 rg_log_enter("user_confirm: token=$token");
1184 1246
1185 1247 $now = time(); $now = time();
1186 1248 $token = preg_replace("/[^A-Za-z0-9]/", "", $token); $token = preg_replace("/[^A-Za-z0-9]/", "", $token);
1187 1249
1188 1250 $ret = FALSE; $ret = FALSE;
1189 do {
1251 while (1) {
1190 1252 if (empty($token)) { if (empty($token)) {
1191 1253 rg_user_set_error("invalid token"); rg_user_set_error("invalid token");
1192 1254 break; break;
 
... ... function rg_user_confirm($db, $token)
1224 1286 rg_cache_unset("user::" . $uid); rg_cache_unset("user::" . $uid);
1225 1287
1226 1288 $ret = $uid; $ret = $uid;
1227 } while (0);
1289 break;
1290 }
1228 1291
1292 rg_log_exit();
1229 1293 rg_prof_end("user_confirm"); rg_prof_end("user_confirm");
1230 1294 return $ret; return $ret;
1231 1295 } }
 
... ... function rg_user_confirm($db, $token)
1235 1299 */ */
1236 1300 function rg_user_suggestion($db, $uid, $email, $suggestion) function rg_user_suggestion($db, $uid, $email, $suggestion)
1237 1301 { {
1238 rg_log("user_suggestion: uid=$uid email=$email suggestion=$suggestion");
1239
1240 $params = array("uid" => $uid,
1241 "email" => $email,
1242 "sug" => $suggestion);
1243 $sql = "INSERT INTO suggestions (uid, email, suggestion)"
1244 . " VALUES (@@uid@@, @@email@@, @@sug@@)";
1245 $res = rg_sql_query_params($db, $sql, $params);
1246 if ($res === FALSE) {
1247 rg_user_set_error("cannot add suggestion (" . rg_sql_error() . ")");
1248 return FALSE;
1302 rg_prof_start("user_suggestion");
1303 rg_log_enter("user_suggestion: uid=$uid email=$email suggestion=$suggestion");
1304
1305 $ret = FALSE;
1306 while (1) {
1307 $params = array("uid" => $uid,
1308 "email" => $email,
1309 "sug" => $suggestion);
1310 $sql = "INSERT INTO suggestions (uid, email, suggestion)"
1311 . " VALUES (@@uid@@, @@email@@, @@sug@@)";
1312 $res = rg_sql_query_params($db, $sql, $params);
1313 if ($res === FALSE) {
1314 rg_user_set_error("cannot add suggestion (" . rg_sql_error() . ")");
1315 break;
1316 }
1317 rg_sql_free_result($res);
1318
1319 $ret = TRUE;
1320 break;
1249 1321 } }
1250 rg_sql_free_result($res);
1251 1322
1252 return TRUE;
1323 rg_log_exit();
1324 rg_prof_end("user_suggestion");
1325 return $ret;
1253 1326 } }
1254 1327
1255 1328 /* /*
File inc/user/repo-page.php changed (mode: 100644) (index 60370f3..783ad42)
... ... if ($rg['ri']['ok'] != 1) {
26 26 $_repo_page .= rg_warning("Internal error!"); $_repo_page .= rg_warning("Internal error!");
27 27 return; return;
28 28 } }
29 if ($rg['ri']['exists'] != 1) {
30 $_repo_page .= rg_template("repo/invalid.html", $rg);
29
30 if (($rg['ri']['exists'] != 1)
31 || rg_repo_allow($db, "repo", $rg['ri'], $rg['login_ui'], "A", $rg['ip'], "") !== TRUE) {
32 $_repo_page .= rg_template("user/repo/deny.html", $rg);
31 33 return; return;
32 34 } }
33 35
 
... ... if ($rg['ri']['git_dir_done'] == 0) {
46 48 } }
47 49 } }
48 50
49 if (rg_repo_allow($db, "repo", $rg['ri'], $rg['login_ui'], "A", $rg['ip'], "") !== TRUE) {
50 $_repo_page .= rg_template("user/repo/deny.html", $rg);
51 return;
52 }
53
54 51 // TODO: should we test against $ri?! // TODO: should we test against $ri?!
55 52 $can_admin = rg_repo_allow($db, "repo", $rg['ri'], $rg['login_ui'], "E", $rg['ip'], "") === TRUE ? 1 : 0; $can_admin = rg_repo_allow($db, "repo", $rg['ri'], $rg['login_ui'], "E", $rg['ip'], "") === TRUE ? 1 : 0;
56 53
File inc/util.inc.php changed (mode: 100644) (index 571aab0..97c00cf)
... ... function rg_1024($v)
45 45 */ */
46 46 function rg_id($len) function rg_id($len)
47 47 { {
48 rg_prof_start("urandom");
49
48 50 $id = ""; $id = "";
49 51
50 rg_prof_start("urandom");
51 52 $f = @fopen("/dev/urandom", "r"); $f = @fopen("/dev/urandom", "r");
52 53 if ($f !== NULL) { if ($f !== NULL) {
53 54 $buf = @fread($f, 128); $buf = @fread($f, 128);
 
... ... function rg_var_re($name, $re)
298 299 */ */
299 300 function rg_chars_allow($name, $allowed_regexp) function rg_chars_allow($name, $allowed_regexp)
300 301 { {
301 if (preg_match($allowed_regexp, $name) === 0)
302 if (preg_match($allowed_regexp, $name) === 0) {
303 rg_log("chars_allow: [$name] does not match [$allowed_regexp]");
302 304 return FALSE; return FALSE;
305 }
303 306
304 307 return TRUE; return TRUE;
305 308 } }
 
... ... function rg_replace_conditionals_block($block, &$data, &$stack)
486 489 if (empty($matches[3])) { if (empty($matches[3])) {
487 490 $new_cond = FALSE; $new_cond = FALSE;
488 491 } else { } else {
489 $r = preg_match('/^\s*(.*?)\s*(==|!=)\s*(.*?)\s*$/su',
492 $r = preg_match('/^\s*(.*?)\s*(==|!=)\s*(.*?)\s*$/Dsu',
490 493 $matches[3], $matches2); $matches[3], $matches2);
491 494 if ($r === FALSE) { if ($r === FALSE) {
492 495 rg_internal_error("Invalid condition!"); rg_internal_error("Invalid condition!");
 
... ... function rg_redirect($url)
851 854 */ */
852 855 function rg_redirect_html($seconds, $url) function rg_redirect_html($seconds, $url)
853 856 { {
854 global $more;
857 global $rg;
855 858
856 $more['rg_redirect_html'] = 1;
857 $more['rg_redirect_html_seconds'] = $seconds;
858 $more['rg_redirect_html_url'] = $url;
859 $rg['rg_redirect_html'] = 1;
860 $rg['rg_redirect_html_seconds'] = $seconds;
861 $rg['rg_redirect_html_url'] = $url;
859 862 } }
860 863
861 864 /* /*
 
... ... function rg_callback_hexa($matches)
873 876 */ */
874 877 function rg_array2string($a) function rg_array2string($a)
875 878 { {
879 $what = array("/[^\pL\pN\pP\pS ]/uU");
880
876 881 if (!is_array($a)) if (!is_array($a))
877 rg_internal_error("not an array!");
882 return preg_replace_callback($what, "rg_callback_hexa", $a);
878 883
879 884 if (empty($a)) if (empty($a))
880 885 return ""; return "";
881 886
882 $what = array("/[^\pL\pN\pP\pS ]/uU");
883
884 887 $ret = ""; $ret = "";
885 888 $add = ""; $add = "";
886 889 foreach ($a as $k => $v) { foreach ($a as $k => $v) {
File root/themes/default/mail/user/repo/update.body.txt changed (mode: 100644) (index c00b67f..678c559)
1 1 Hello! Hello!
2 2
3 @@if(@@ri.old.name@@ != @@ri.name@@){{Repository '@@ri.old.name@@' was renamed to '@@ri.name@@.}}{{}}
3 @@if(@@ri.renamed@@ == 1){{Repository '@@ri.old.name@@' was renamed to '@@ri.name@@.}}{{}}
4 4 @@if(@@ri.old.description_md5@@ != @@ri.description_md5@@){{ @@if(@@ri.old.description_md5@@ != @@ri.description_md5@@){{
5 5 Description changed to: Description changed to:
6 6 @@ri.description@@}}{{}} @@ri.description@@}}{{}}
 
... ... Description changed to:
8 8 New anonymous rights: New anonymous rights:
9 9 @@ri.rights_text@@ @@ri.rights_text@@
10 10 }}{{}} }}{{}}
11 Link to repository: @@ri.url@@.
11 Link to repository: @@ri.url@@
12 12
13 13 IP: @@IP@@ IP: @@IP@@
14 14
File root/themes/default/user/repo/rights/form_repo.html changed (mode: 100644) (index 9d52630..a684e6f)
9 9 <input type="hidden" name="grant" value="1" /> <input type="hidden" name="grant" value="1" />
10 10 <input type="hidden" name="token" value="@@rg_form_token@@" /> <input type="hidden" name="token" value="@@rg_form_token@@" />
11 11
12 <label class="form_item_title" for="target_user">User (use '*' for any user)</label><br />
13 <input type="text" name="target_user" value="@@target_user@@" />
12 <label class="form_item_title" for="username">User (use '*' for any user)</label><br />
13 <input type="text" name="username" value="@@username@@" />
14 14 <br /> <br />
15 15 <br /> <br />
16 16
 
23 23 <br /> <br />
24 24 <br /> <br />
25 25
26 <label class="form_item_title" for="prio">Priority</label><br />
26 <label class="form_item_title" for="prio">Priority (at least 10)</label><br />
27 27 <input type="text" name="prio" value="@@prio@@" /> <input type="text" name="prio" value="@@prio@@" />
28 28 <br /> <br />
29 29 <br /> <br />
File root/themes/default/user/repo/rights/form_repo_path.html changed (mode: 100644) (index 26428c8..4d3caef)
9 9 <input type="hidden" name="grant" value="1" /> <input type="hidden" name="grant" value="1" />
10 10 <input type="hidden" name="token" value="@@rg_form_token@@" /> <input type="hidden" name="token" value="@@rg_form_token@@" />
11 11
12 <label class="form_item_title" for="target_user">User (use '*' for any user)</label><br />
13 <input type="text" name="target_user" value="@@target_user@@" />
12 <label class="form_item_title" for="username">User (use '*' for any user)</label><br />
13 <input type="text" name="username" value="@@username@@" />
14 14 <br /> <br />
15 15 <br /> <br />
16 16
 
28 28 <br /> <br />
29 29 <br /> <br />
30 30
31 <label class="form_item_title" for="prio">Priority</label><br />
31 <label class="form_item_title" for="prio">Priority (at least 10)</label><br />
32 32 <input type="text" name="prio" value="@@prio@@" /> <input type="text" name="prio" value="@@prio@@" />
33 33 <br /> <br />
34 34 <br /> <br />
File root/themes/default/user/repo/rights/form_repo_refs.html changed (mode: 100644) (index 8c685a2..c2208ea)
9 9 <input type="hidden" name="grant" value="1" /> <input type="hidden" name="grant" value="1" />
10 10 <input type="hidden" name="token" value="@@rg_form_token@@" /> <input type="hidden" name="token" value="@@rg_form_token@@" />
11 11
12 <label class="form_item_title" for="target_user">User (use '*' for any user)</label><br />
13 <input type="text" name="target_user" value="@@target_user@@" />
12 <label class="form_item_title" for="username">User (use '*' for any user)</label><br />
13 <input type="text" name="username" value="@@username@@" />
14 14 <br /> <br />
15 15 <br /> <br />
16 16
 
28 28 <br /> <br />
29 29 <br /> <br />
30 30
31 <label class="form_item_title" for="prio">Priority</label><br />
31 <label class="form_item_title" for="prio">Priority (at least 10)</label><br />
32 32 <input type="text" name="prio" value="@@prio@@" /> <input type="text" name="prio" value="@@prio@@" />
33 33 <br /> <br />
34 34 <br /> <br />
File root/themes/default/user/repo/rights/list_repo/line.html changed (mode: 100644) (index 9cb9302..96a64c5)
1 1 <tr> <tr>
2 <td><input type="checkbox" name="rights_delete_ids[@@right_id@@]" /></td>
2 <td>@@if(@@can_be_deleted@@ == 1){{<input type="checkbox" name="rights_delete_ids[@@right_id@@]" />}}{{N/A}}</td>
3 3 <td>@@prio@@</td> <td>@@prio@@</td>
4 4 <td>@@who_name@@</td> <td>@@who_name@@</td>
5 5 <td>@@itime_text@@</td> <td>@@itime_text@@</td>
File root/themes/default/user/repo/rights/list_repo_path/line.html changed (mode: 100644) (index 167e787..8a55710)
1 1 <tr> <tr>
2 <td><input type="checkbox" name="rights_delete_ids[@@right_id@@]" /></td>
2 <td>@@if(@@can_be_deleted@@ == 1){{<input type="checkbox" name="rights_delete_ids[@@right_id@@]" />}}{{N/A}}</td>
3 3 <td>@@prio@@</td> <td>@@prio@@</td>
4 4 <td>@@who_name@@</td> <td>@@who_name@@</td>
5 5 <td>@@itime_text@@</td> <td>@@itime_text@@</td>
File root/themes/default/user/repo/rights/list_repo_refs/line.html changed (mode: 100644) (index 7b516c1..c067049)
1 1 <tr> <tr>
2 <td><input type="checkbox" name="rights_delete_ids[@@right_id@@]" /></td>
2 <td>@@if(@@can_be_deleted@@ == 1){{<input type="checkbox" name="rights_delete_ids[@@right_id@@]" />}}{{N/A}}</td>
3 3 <td>@@prio@@</td> <td>@@prio@@</td>
4 4 <td>@@who_name@@</td> <td>@@who_name@@</td>
5 5 <td>@@itime_text@@</td> <td>@@itime_text@@</td>
File samples/config.php changed (mode: 100644) (index 827ebb3..848351f)
... ... $rg_keys_file = $rg_base . "/.ssh/authorized_keys";
18 18 $rg_scripts = "/usr/share/rocketgit"; $rg_scripts = "/usr/share/rocketgit";
19 19
20 20 // Allowed repo names (regular expression) // Allowed repo names (regular expression)
21 $rg_repo_allow = '/^[\pL\pN\pP]*$/uU';
21 $rg_repo_allow = '/^[\pL\pN\pP]*$/uUD';
22 22
23 23 // Allowed repo name length // Allowed repo name length
24 24 $rg_repo_min_len = 2; $rg_repo_min_len = 2;
25 25 $rg_repo_max_len = 64; $rg_repo_max_len = 64;
26 26
27 27 // Allowed user names (negated regular expression) // Allowed user names (negated regular expression)
28 $rg_user_allow = '/^[\pL\pN\pP]*$/uU';
28 $rg_user_allow = '/^[\pL\pN\pP]*$/uUD';
29 29
30 30 // Allowed user name length // Allowed user name length
31 31 $rg_user_min_len = 3; $rg_user_min_len = 3;
File scripts/cache.php changed (mode: 100644) (index c8279d6..ac6438e)
... ... function rg_handle_command($k, &$conn_table, $cmd)
48 48 $s = &$conn_table['conns'][$k]; $s = &$conn_table['conns'][$k];
49 49
50 50 $a = explode(" ", $cmd, 2); $a = explode(" ", $cmd, 2);
51 $buf = "WHAT?!\n";
51 $buf = "ER Invalid command\n";
52 52 do { do {
53 53 if (!isset($a[0])) if (!isset($a[0]))
54 54 break; break;
 
... ... function rg_handle_command($k, &$conn_table, $cmd)
68 68 break; break;
69 69 $ns_var = trim($ns_var_value[0]); $ns_var = trim($ns_var_value[0]);
70 70 $value = trim($ns_var_value[1]); $value = trim($ns_var_value[1]);
71 rg_cache_server_set("normal::" . $ns_var, $value);
72 $buf = "OK\n";
71 $value = unserialize($value);
72 if ($value !== FALSE) {
73 rg_cache_core_set("normal::" . $ns_var, $value);
74 $buf = "OK\n";
75 } else {
76 $buf = "ER cannot unserialize data\n";
77 }
78 break;
79 }
80
81 if (strcmp($cmd, "MERGE") == 0) {
82 $ns_var_value = explode("=", $para1, 2);
83 if (!isset($ns_var_value[1]))
84 break;
85 $ns_var = trim($ns_var_value[0]);
86 $value = trim($ns_var_value[1]);
87 $value = unserialize($value);
88 if ($value !== FALSE) {
89 rg_cache_core_set("normal::" . $ns_var, $value);
90 $buf = "OK\n";
91 } else {
92 $buf = "ER cannot unserialize data\n";
93 }
73 94 break; break;
74 95 } }
75 96
76 97 if (strcmp($cmd, "INC") == 0) { if (strcmp($cmd, "INC") == 0) {
77 $v = rg_cache_server_inc("normal::" . $para1);
98 $v = rg_cache_core_inc("normal::" . $para1);
78 99 $buf = "OK v=$v\n"; $buf = "OK v=$v\n";
79 100 break; break;
80 101 } }
81 102
82 103 if (strcmp($cmd, "GET") == 0) { if (strcmp($cmd, "GET") == 0) {
83 $ret = rg_cache_server_get("normal::" . $para1);
104 $ret = rg_cache_core_get("normal::" . $para1);
84 105 if ($ret === FALSE) if ($ret === FALSE)
85 106 $buf = "NOT_FOUND\n"; $buf = "NOT_FOUND\n";
86 107 else else
 
... ... function rg_handle_command($k, &$conn_table, $cmd)
89 110 } }
90 111
91 112 if (strcmp($cmd, "UNSET") == 0) { if (strcmp($cmd, "UNSET") == 0) {
92 $ret = rg_cache_server_unset("normal::" . $para1);
113 $ret = rg_cache_core_unset("normal::" . $para1);
93 114 if ($ret === FALSE) if ($ret === FALSE)
94 115 $buf = "NOT_FOUND\n"; $buf = "NOT_FOUND\n";
95 116 else else
 
... ... function rg_handle_command($k, &$conn_table, $cmd)
98 119 } }
99 120
100 121 if (strcmp($cmd, "ADUMP") == 0) { if (strcmp($cmd, "ADUMP") == 0) {
101 $ret = rg_cache_server_adump("normal::" . $para1);
122 $ret = rg_cache_core_adump("normal::" . $para1);
102 123 if ($ret === FALSE) if ($ret === FALSE)
103 124 $buf = "NOT_FOUND\n"; $buf = "NOT_FOUND\n";
104 125 else else
 
... ... function rg_handle_command($k, &$conn_table, $cmd)
112 133 break; break;
113 134 $ns_var = trim($ns_var_value[0]); $ns_var = trim($ns_var_value[0]);
114 135 $value = trim($ns_var_value[1]); $value = trim($ns_var_value[1]);
115 rg_cache_server_apush("normal::" . $ns_var, $value);
136 rg_cache_core_apush("normal::" . $ns_var, $value);
116 137 $buf = "OK\n"; $buf = "OK\n";
117 138 break; break;
118 139 } }
119 140
120 141 if (strcmp($cmd, "APOP") == 0) { if (strcmp($cmd, "APOP") == 0) {
121 $ret = rg_cache_server_apop("normal::" . $para1);
142 $ret = rg_cache_core_apop("normal::" . $para1);
122 143 if ($ret === FALSE) if ($ret === FALSE)
123 144 $buf = "NOT_FOUND\n"; $buf = "NOT_FOUND\n";
124 145 else else
 
... ... function rg_handle_command($k, &$conn_table, $cmd)
127 148 } }
128 149
129 150 if (strcmp($cmd, "ASHIFT") == 0) { if (strcmp($cmd, "ASHIFT") == 0) {
130 $ret = rg_cache_server_ashift("normal::" . $para1);
151 $ret = rg_cache_core_ashift("normal::" . $para1);
131 152 if ($ret === FALSE) if ($ret === FALSE)
132 153 $buf = "NOT_FOUND\n"; $buf = "NOT_FOUND\n";
133 154 else else
File scripts/remote.php changed (mode: 100644) (index 3d2c1fa..f2f055e)
... ... if (isset($_SERVER['SSH_CONNECTION'])) {
72 72 $host = ""; $host = "";
73 73
74 74 // first parameter must be uid of the user // first parameter must be uid of the user
75 $conn_uid = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 0;
76 if ($conn_uid == 0)
75 $login_uid = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 0;
76 if ($login_uid == 0)
77 77 fatal("uid not provided!"); fatal("uid not provided!");
78 rg_log("\tuid is $conn_uid.");
78 rg_log("\tuid is $login_uid.");
79 79
80 80 // second parameter must be the ssh key id // second parameter must be the ssh key id
81 81 $key_id = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : 0; $key_id = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : 0;
 
... ... if (isset($_SERVER['SSH_CONNECTION'])) {
87 87 $cmd_repo = ""; $cmd_repo = "";
88 88 else else
89 89 $cmd_repo = trim($_SERVER['SSH_ORIGINAL_COMMAND']); $cmd_repo = trim($_SERVER['SSH_ORIGINAL_COMMAND']);
90 rg_ssh_dispatch($db, $conn_uid, $cmd_repo);
90 rg_ssh_dispatch($db, $login_uid, $cmd_repo);
91 91
92 92 $ssh_client = getenv("SSH_CLIENT"); $ssh_client = getenv("SSH_CLIENT");
93 93 $_t = explode(" ", $ssh_client); $_t = explode(" ", $ssh_client);
 
... ... if (isset($_SERVER['SSH_CONNECTION'])) {
101 101 rg_log("git-daemon connection..."); rg_log("git-daemon connection...");
102 102
103 103 // we have no client info // we have no client info
104 $conn_uid = 0;
104 $login_uid = 0;
105 105 $key_id = 0; $key_id = 0;
106 106
107 107 $f = @fopen("php://stdin", "r"); $f = @fopen("php://stdin", "r");
 
... ... if ($owner_ui['exists'] != 1)
172 172 fatal("User does not exists (repo)."); fatal("User does not exists (repo).");
173 173
174 174 // Load info about the connecting user // Load info about the connecting user
175 $conn_ui = rg_user_info($db, $conn_uid, "", "");
175 $conn_ui = rg_user_info($db, $login_uid, "", "");
176 176 if ($conn_ui['exists'] != 1) if ($conn_ui['exists'] != 1)
177 177 fatal("User does not exists (conn)."); fatal("User does not exists (conn).");
178 178
 
... ... if (($push == 1) && rg_user_over_limit($db, $owner_ui, $max))
209 209 . " (" . $owner_ui['disk_used_mb']. "MiB >= " . $max . "MiB)"); . " (" . $owner_ui['disk_used_mb']. "MiB >= " . $max . "MiB)");
210 210
211 211 // Put in environment all we need // Put in environment all we need
212 putenv("ROCKETGIT_UID=" . $conn_uid);
212 putenv("ROCKETGIT_LOGIN_UID=" . $login_uid);
213 213 putenv("ROCKETGIT_KEY_ID=" . $key_id); putenv("ROCKETGIT_KEY_ID=" . $key_id);
214 214 putenv("ROCKETGIT_REPO_ID=" . $ri['repo_id']); putenv("ROCKETGIT_REPO_ID=" . $ri['repo_id']);
215 215 putenv("ROCKETGIT_REPO_PATH=" . $repo_path); putenv("ROCKETGIT_REPO_PATH=" . $repo_path);
File tests/bug.php changed (mode: 100644) (index b188b80..6139a7f)
... ... require_once($INC . "/bug.inc.php");
8 8 require_once($INC . "/sql.inc.php"); require_once($INC . "/sql.inc.php");
9 9 require_once($INC . "/struct.inc.php"); require_once($INC . "/struct.inc.php");
10 10 require_once($INC . "/fixes.inc.php"); require_once($INC . "/fixes.inc.php");
11 require_once("common.php");
12 11
13 12 rg_log_set_file("bug.log"); rg_log_set_file("bug.log");
14 13
14 require_once("common.php");
15
15 16 // defaults // defaults
16 17 $uid = 1; $uid = 1;
17 18 $ui = array("uid" => $uid, "username" => "userX", "organization" => 0, "email" => "test@embedromix.ro"); $ui = array("uid" => $uid, "username" => "userX", "organization" => 0, "email" => "test@embedromix.ro");
 
... ... $repo_name = "A";
19 20
20 21 rg_log("Creating a repo"); rg_log("Creating a repo");
21 22 $new = array(); $new = array();
23 $new['repo_id'] = 0;
22 24 $new['master'] = 0; $new['master'] = 0;
23 25 $new['name'] = $repo_name; $new['name'] = $repo_name;
24 26 $new['max_commit_size'] = 0; $new['max_commit_size'] = 0;
25 27 $new['description'] = "desc"; $new['description'] = "desc";
26 28 $new['git_dir_done'] = 0; $new['git_dir_done'] = 0;
27 29 $new['public'] = 1; $new['public'] = 1;
28 $repo_id = rg_repo_edit($db, $ui, $new);
29 if ($repo_id === FALSE) {
30 $r = rg_repo_edit($db, $ui, $new);
31 if ($r === FALSE) {
30 32 rg_log("Cannot insert a repo (" . rg_repo_error() . ")!"); rg_log("Cannot insert a repo (" . rg_repo_error() . ")!");
31 33 exit(1); exit(1);
32 34 } }
 
... ... $data = array("bug_id" => 0,
37 39 "labels" => "label3,label1,label2", "labels" => "label3,label1,label2",
38 40 "state" => 1, "state" => 1,
39 41 "assigned_uid" => 6); "assigned_uid" => 6);
40 $ri = array("repo_id" => $repo_id, "name" => "repoX");
41 $r = rg_bug_edit($db, $ri, $ui, $data);
42 $ri = array("repo_id" => $new['repo_id'], "name" => "repoX");
43 $r = rg_bug_edit($db, $ui, $ri, $data);
42 44 if ($r === FALSE) { if ($r === FALSE) {
43 45 rg_log("Cannot insert a bug (" . rg_bug_error() . ")!"); rg_log("Cannot insert a bug (" . rg_bug_error() . ")!");
44 46 exit(1); exit(1);
45 47 } }
46 48 $bug_id = $r; $bug_id = $r;
47 49 // verify that labels were inserted // verify that labels were inserted
48 $r = rg_bug_label_get($db, $repo_id, $bug_id);
50 $r = rg_bug_label_get($db, $new['repo_id'], $bug_id);
49 51 if ($r === FALSE) { if ($r === FALSE) {
50 52 rg_log("Cannot get labels (" . rg_bug_error() . ")!"); rg_log("Cannot get labels (" . rg_bug_error() . ")!");
51 53 exit(1); exit(1);
 
... ... if ($uid === FALSE) {
78 80 } }
79 81
80 82 $data = array("note" => "This is just a note."); $data = array("note" => "This is just a note.");
81 $r = rg_bug_note_add($db, $repo_id, $bug_id, $uid, $data);
83 $r = rg_bug_note_add($db, $new['repo_id'], $bug_id, $uid, $data);
82 84 if ($r === FALSE) { if ($r === FALSE) {
83 85 rg_log("Cannot add a note (" . rg_bug_error() . ")!"); rg_log("Cannot add a note (" . rg_bug_error() . ")!");
84 86 exit(1); exit(1);
85 87 } }
86 88
87 $r = rg_bug_info($db, $repo_id, $bug_id);
89 $r = rg_bug_info($db, $new['repo_id'], $bug_id);
88 90 if ($r['exists'] != 1) { if ($r['exists'] != 1) {
89 91 rg_log("Cannot lookup a bug (" . rg_bug_error() . ")!"); rg_log("Cannot lookup a bug (" . rg_bug_error() . ")!");
90 92 exit(1); exit(1);
91 93 } }
92 94
93 95 // test a non existing bug // test a non existing bug
94 $r = rg_bug_info($db, $repo_id, 0);
96 $r = rg_bug_info($db, $new['repo_id'], 0);
95 97 if ($r['exists'] != 0) { if ($r['exists'] != 0) {
96 98 rg_log("Wrong bug number (0) returned valid data!"); rg_log("Wrong bug number (0) returned valid data!");
97 99 exit(1); exit(1);
 
... ... $q = array("reported_by" => "userA",
106 108 "title_string" => "IMPOSSIBLE TITLE", "title_string" => "IMPOSSIBLE TITLE",
107 109 "body_string" => "IMPOSSIBLE BODY", "body_string" => "IMPOSSIBLE BODY",
108 110 "bugs_per_page" => "1"); "bugs_per_page" => "1");
109 $r = rg_bug_search($db, $repo_id, $uid, $q);
111 $r = rg_bug_search($db, $new['repo_id'], $uid, $q);
110 112 if ($r === FALSE) { if ($r === FALSE) {
111 113 rg_log("Cannot search bugs 1 (" . rg_bug_error() . ")!"); rg_log("Cannot search bugs 1 (" . rg_bug_error() . ")!");
112 114 exit(1); exit(1);
 
... ... if (count($r) > 0) {
118 120
119 121 $q = array("title_string" => "g t", $q = array("title_string" => "g t",
120 122 "body_string" => ""); "body_string" => "");
121 $r = rg_bug_search($db, $repo_id, $uid, $q);
123 $r = rg_bug_search($db, $new['repo_id'], $uid, $q);
122 124 if ($r === FALSE) { if ($r === FALSE) {
123 125 rg_log("Cannot search bugs 2 (" . rg_bug_error() . ")!"); rg_log("Cannot search bugs 2 (" . rg_bug_error() . ")!");
124 126 exit(1); exit(1);
File tests/cache.php changed (mode: 100644) (index 0d96d11..b4fd571)
... ... require_once($INC . "/init.inc.php");
7 7 require_once($INC . "/util.inc.php"); require_once($INC . "/util.inc.php");
8 8 require_once($INC . "/log.inc.php"); require_once($INC . "/log.inc.php");
9 9 require_once($INC . "/cache.inc.php"); require_once($INC . "/cache.inc.php");
10 require_once("common.php");
11 10
12 11 rg_log_set_file("cache.log"); rg_log_set_file("cache.log");
13 12
14 rg_cache_server_set("a::b::c", "1");
13 require_once("common.php");
14
15 rg_cache_core_set("a::b::c", "1");
15 16
16 17 $e = "1"; $e = "1";
17 $r = rg_cache_server_get("a::b::c");
18 $r = rg_cache_core_get("a::b::c");
18 19 if ($r !== $e) { if ($r !== $e) {
19 20 print_r($rg_cache); print_r($rg_cache);
20 21 echo "[$r] != [$e]!\n"; echo "[$r] != [$e]!\n";
 
... ... if ($r !== $e) {
22 23 } }
23 24
24 25 $e = FALSE; $e = FALSE;
25 $r = rg_cache_server_get("x::y::z");
26 $r = rg_cache_core_get("x::y::z");
26 27 if ($r !== $e) { if ($r !== $e) {
27 28 print_r($rg_cache); print_r($rg_cache);
28 29 echo "r must be FALSE!\n"; echo "r must be FALSE!\n";
29 30 exit(1); exit(1);
30 31 } }
31 32
32 rg_cache_server_unset("x::y::z");
33 rg_cache_core_unset("x::y::z");
33 34 $e = FALSE; $e = FALSE;
34 $r = rg_cache_server_get("x::y::z");
35 $r = rg_cache_core_get("x::y::z");
35 36 if ($r !== $e) { if ($r !== $e) {
36 37 print_r($rg_cache); print_r($rg_cache);
37 38 echo "r must be FALSE ($r)!\n"; echo "r must be FALSE ($r)!\n";
 
... ... if ($r !== $e) {
40 41
41 42 ////////////////////////////////// Arrays ////////////////////////////////// Arrays
42 43
43 rg_cache_server_apush("v", "1");
44 rg_cache_server_apush("v", "2");
45 rg_cache_server_apush("v", "aa");
44 rg_cache_core_apush("v", "1");
45 rg_cache_core_apush("v", "2");
46 rg_cache_core_apush("v", "aa");
46 47 $e = "1,2,aa"; $e = "1,2,aa";
47 $r = rg_cache_server_adump("v");
48 $r = rg_cache_core_adump("v");
48 49 if ($r !== $e) { if ($r !== $e) {
49 50 print_r($rg_cache); print_r($rg_cache);
50 51 echo "[$r] != [$e]!\n"; echo "[$r] != [$e]!\n";
 
... ... if ($r !== $e) {
52 53 } }
53 54
54 55 $e = "aa"; $e = "aa";
55 $r = rg_cache_server_apop("v");
56 $r = rg_cache_core_apop("v");
56 57 if ($r !== $e) { if ($r !== $e) {
57 58 print_r($rg_cache); print_r($rg_cache);
58 59 echo "[$r] != [$e]!\n"; echo "[$r] != [$e]!\n";
 
... ... if ($r !== $e) {
60 61 } }
61 62
62 63 $e = "1"; $e = "1";
63 $r = rg_cache_server_ashift("v");
64 $r = rg_cache_core_ashift("v");
64 65 if ($r !== $e) { if ($r !== $e) {
65 66 print_r($rg_cache); print_r($rg_cache);
66 67 echo "[$r] != [$e]!\n"; echo "[$r] != [$e]!\n";
 
... ... if ($r !== $e) {
68 69 } }
69 70
70 71 $e = FALSE; $e = FALSE;
71 $r = rg_cache_server_ashift("v");
72 $r = rg_cache_server_ashift("v");
72 $r = rg_cache_core_ashift("v");
73 $r = rg_cache_core_ashift("v");
73 74 if ($r !== $e) { if ($r !== $e) {
74 75 print_r($rg_cache); print_r($rg_cache);
75 76 echo "r is not FALSE ($r)!\n"; echo "r is not FALSE ($r)!\n";
File tests/common.php changed (mode: 100644) (index 9841fbf..52be00d)
... ... $rg_sql_debug = 1;
11 11 $rg_session_time = 3600; $rg_session_time = 3600;
12 12 $rg_keys_file = "afile.txt"; $rg_keys_file = "afile.txt";
13 13 $rg_scripts = dirname(dirname(__FILE__)); $rg_scripts = dirname(dirname(__FILE__));
14 $rg_repo_allow = '/^[\pL\pN\pP]*$/uU';
14 $rg_repo_allow = '/^[\pL\pN\pP_]*$/uUD';
15 15 $rg_repo_min_len = 1; $rg_repo_min_len = 1;
16 16 $rg_repo_max_len = 100; $rg_repo_max_len = 100;
17 $rg_user_allow = '/^[\pL\pN\pP]*$/uU';
17 $rg_user_allow = '/^[\pL\pN\pP_]*$/uUD';
18 18 $rg_user_min_len = 1; $rg_user_min_len = 1;
19 19 $rg_user_max_len = 20; $rg_user_max_len = 20;
20 20 $rg_ssh_paras = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty"; $rg_ssh_paras = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty";
 
... ... if ($db === FALSE) {
40 40 exit(1); exit(1);
41 41 } }
42 42
43 // Force schema ver 0 to be able to apply updates
43 44 $r = rg_state_set($db, "schema_version", "0"); $r = rg_state_set($db, "schema_version", "0");
44 45 if ($r !== TRUE) { if ($r !== TRUE) {
45 46 echo "Cannot reset schema (" . rg_state_error() . ")!\n"; echo "Cannot reset schema (" . rg_state_error() . ")!\n";
 
... ... if ($r !== TRUE) {
64 65 exit(1); exit(1);
65 66 } }
66 67
68 rg_log("common.php finished");
69
67 70 ?> ?>
File tests/email.php changed (mode: 100644) (index 73c9764..ddbbf57)
... ... ini_set("track_errors", "On");
5 5 $INC = "../inc"; $INC = "../inc";
6 6 require_once($INC . "/init.inc.php"); require_once($INC . "/init.inc.php");
7 7 require_once($INC . "/util.inc.php"); require_once($INC . "/util.inc.php");
8
9 rg_log_set_file("email.log");
10
8 11 require_once("common.php"); require_once("common.php");
9 12
10 13 $rg_scripts = "../"; $rg_scripts = "../";
File tests/event.php changed (mode: 100644) (index 362d0e1..a178f2d)
... ... require_once($INC . "/events.inc.php");
11 11 require_once($INC . "/sql.inc.php"); require_once($INC . "/sql.inc.php");
12 12 require_once($INC . "/struct.inc.php"); require_once($INC . "/struct.inc.php");
13 13 require_once($INC . "/fixes.inc.php"); require_once($INC . "/fixes.inc.php");
14 require_once("common.php");
15 14
16 15 rg_log_set_file("event.log"); rg_log_set_file("event.log");
17 16
17 require_once("common.php");
18
18 19 $rg_sql_debug = 1; $rg_sql_debug = 1;
19 20
20 21 /* /*
File tests/git.php changed (mode: 100644) (index 6785ae9..ddda7f2)
... ... ini_set("track_errors", "On");
5 5 $INC = "../inc"; $INC = "../inc";
6 6 require_once($INC . "/init.inc.php"); require_once($INC . "/init.inc.php");
7 7 require_once($INC . "/git.inc.php"); require_once($INC . "/git.inc.php");
8 require_once("common.php");
9 8
10 9 rg_log_set_file("git.log"); rg_log_set_file("git.log");
11 10
11 require_once("common.php");
12
12 13 echo "[*] Checking if git-init works...\n"; echo "[*] Checking if git-init works...\n";
13 14 $r = rg_git_init("git.tmp"); $r = rg_git_init("git.tmp");
14 15 if ($r !== TRUE) { if ($r !== TRUE) {
File tests/git2.php changed (mode: 100644) (index f76e72e..986d038)
... ... ini_set("track_errors", "On");
5 5 $INC = "../inc"; $INC = "../inc";
6 6 require_once($INC . "/init.inc.php"); require_once($INC . "/init.inc.php");
7 7 require_once($INC . "/git.inc.php"); require_once($INC . "/git.inc.php");
8 require_once("common.php");
9 8
10 9 rg_log_set_file("git2.log"); rg_log_set_file("git2.log");
11 10
11 require_once("common.php");
12
12 13 system("./git2.sh"); system("./git2.sh");
13 14
14 15 // test rg_git_refs // test rg_git_refs
File tests/keys.php changed (mode: 100644) (index 3df8dac..d5e4efd)
... ... require_once($INC . "/keys.inc.php");
9 9 require_once($INC . "/sql.inc.php"); require_once($INC . "/sql.inc.php");
10 10 require_once($INC . "/struct.inc.php"); require_once($INC . "/struct.inc.php");
11 11 require_once($INC . "/fixes.inc.php"); require_once($INC . "/fixes.inc.php");
12 require_once("common.php");
13 12
14 13 rg_log_set_file("keys.log"); rg_log_set_file("keys.log");
15 14
15 require_once("common.php");
16
16 17 $rg_sql_debug = 1; $rg_sql_debug = 1;
17 18
18 19 // Defaults // Defaults
File tests/log.php changed (mode: 100644) (index bf2d431..3e48262)
... ... $INC = "../inc";
6 6 require_once($INC . "/init.inc.php"); require_once($INC . "/init.inc.php");
7 7 require_once($INC . "/util.inc.php"); require_once($INC . "/util.inc.php");
8 8 require_once($INC . "/log.inc.php"); require_once($INC . "/log.inc.php");
9 require_once("common.php");
10 9
11 10 rg_log_set_file("log.log"); rg_log_set_file("log.log");
12 11
12 require_once("common.php");
13
13 14 $n = "șacal\n\t"; $n = "șacal\n\t";
14 15 rg_log($n); rg_log($n);
15 16
File tests/prof.php changed (mode: 100644) (index 9ffd729..9aa8fe9)
... ... require_once($INC . "/init.inc.php");
7 7 require_once($INC . "/util.inc.php"); require_once($INC . "/util.inc.php");
8 8 require_once($INC . "/log.inc.php"); require_once($INC . "/log.inc.php");
9 9 require_once($INC . "/prof.inc.php"); require_once($INC . "/prof.inc.php");
10 require_once("common.php");
11 10
12 11 rg_log_set_file("prof.log"); rg_log_set_file("prof.log");
13 12
13 require_once("common.php");
14
14 15 rg_prof_start("label1"); rg_prof_start("label1");
15 16 sleep(.1); sleep(.1);
16 17 rg_prof_set(array("xxx" => 1)); rg_prof_set(array("xxx" => 1));
File tests/repo.php changed (mode: 100644) (index 268eeb8..f617d01)
... ... require_once($INC . "/repo.inc.php");
10 10 require_once($INC . "/sql.inc.php"); require_once($INC . "/sql.inc.php");
11 11 require_once($INC . "/struct.inc.php"); require_once($INC . "/struct.inc.php");
12 12 require_once($INC . "/fixes.inc.php"); require_once($INC . "/fixes.inc.php");
13
14 rg_log_set_file("repo.log");
15
16 rg_log("Starting");
17
13 18 require_once("common.php"); require_once("common.php");
14 19
15 20 $rg_sql_debug = 1; $rg_sql_debug = 1;
16 21
17 rg_log_set_file("repo.log");
18
19 22 rg_log("rg_repo_path 1"); rg_log("rg_repo_path 1");
20 23 $e = $rg_repos . "/by_id/11/22/33/44/11223344/repos/by_id/55.git"; $e = $rg_repos . "/by_id/11/22/33/44/11223344/repos/by_id/55.git";
21 24 $c = rg_repo_path_by_id(0x11223344, 55); $c = rg_repo_path_by_id(0x11223344, 55);
 
... ... if ($rg_ui['exists'] != 1) {
97 100
98 101 rg_log("Creating a repo"); rg_log("Creating a repo");
99 102 $new = array(); $new = array();
103 $new['repo_id'] = 0;
100 104 $new['master'] = 0; $new['master'] = 0;
101 105 $new['name'] = "A"; $new['name'] = "A";
102 106 $new['max_commit_size'] = 0; $new['max_commit_size'] = 0;
103 107 $new['description'] = "desc"; $new['description'] = "desc";
104 108 $new['git_dir_done'] = 0; $new['git_dir_done'] = 0;
105 109 $new['public'] = 1; $new['public'] = 1;
106 $repo_id = rg_repo_edit($db, $ui, $new);
107 if ($repo_id === FALSE) {
110 $r = rg_repo_edit($db, $rg_ui, $new);
111 if ($r === FALSE) {
108 112 rg_log("Cannot insert a repo (" . rg_repo_error() . ")!"); rg_log("Cannot insert a repo (" . rg_repo_error() . ")!");
109 113 exit(1); exit(1);
110 114 } }
115 $repo_id = $new['repo_id'];
111 116
112 117 $ri = rg_repo_info($db, $repo_id, 0, ""); $ri = rg_repo_info($db, $repo_id, 0, "");
113 118 if ($ri['exists'] != 1) { if ($ri['exists'] != 1) {
 
... ... if ($r === FALSE) {
134 139 } }
135 140
136 141 rg_log("test giving rights"); rg_log("test giving rights");
137 $right_id = 100;
138 $who = 400;
139 $tuid = 10;
140 $prio = 13;
141 $ip = "1.1.1.1";
142 $v = rg_rights_set($db, $right_id, $who, "repo", $ri['repo_id'],
143 $tuid, "P", "", $ip, $prio);
142 $a = array();
143 $a['right_id'] = 100;
144 $a['obj_id'] = $ri['repo_id'];
145 $a['who'] = 400;
146 $a['uid'] = 10;
147 $a['rights'] = "P";
148 $a['prio'] = 13;
149 $a['ip'] = "1.1.1.1";
150 $a['misc'] = "";
151 $v = rg_rights_set($db, "repo", $a);
144 152 if ($v === FALSE) { if ($v === FALSE) {
145 153 rg_log("Cannot give rights (1)!"); rg_log("Cannot give rights (1)!");
146 154 exit(1); exit(1);
147 155 } }
148 156
149 157 rg_log("non-owner gets correct rights: F gets from default rights."); rg_log("non-owner gets correct rights: F gets from default rights.");
150 $right_id = 0;
151 $who = 400;
152 $xuid = 12;
153 $rights = "AaB";
154 $prio = 50;
155 $ip = "";
156 $r = rg_rights_set($db, $right_id, $who, "repo", $ri['repo_id'],
157 $xuid, $rights, "", $ip, $prio);
158 $a = array();
159 $a['right_id'] = 0;
160 $a['obj_id'] = $ri['repo_id'];
161 $a['who'] = 400;
162 $a['uid'] = 12;
163 $a['rights'] = "AaB";
164 $a['prio'] = 50;
165 $a['ip'] = "";
166 $a['misc'] = "";
167 $r = rg_rights_set($db, "repo", $a);
158 168 if ($r !== TRUE) { if ($r !== TRUE) {
159 169 rg_log("Cannot set rights (" . rg_rights_error() . ")!"); rg_log("Cannot set rights (" . rg_rights_error() . ")!");
160 170 exit(1); exit(1);
161 171 } }
162 $e = "AaB";
163 $r = rg_rights_get($db, "repo", $ri['repo_id'], $xuid);
164 $c = $r['list'][0]['rights'];
172 $e = "F";
173 $r = rg_rights_get($db, $ri['repo_id'], "repo", $uid, $a['uid'], 0);
174 $c = isset($r['list'][0]['rights']) ? $r['list'][0]['rights'] : "BAD";
165 175 if (strcmp($c, $e) != 0) { if (strcmp($c, $e) != 0) {
166 176 rg_log("Non-owner did not get correct rights: c=$c e=$e."); rg_log("Non-owner did not get correct rights: c=$c e=$e.");
177 rg_log_ml("r=" . print_r($r, TRUE));
167 178 exit(1); exit(1);
168 179 } }
169 180
170 181 rg_log("owner can set separate rights for him"); rg_log("owner can set separate rights for him");
171 $uid = 500;
172 $tuid = 500;
173 $rights = "E";
174 $prio = 100;
175 $ip = "";
176 $v = rg_rights_set($db, $right_id, $uid, "repo", $ri['repo_id'],
177 $tuid, $rights, "", $ip, $prio);
182 $a = array();
183 $a['right_id'] = 0;
184 $a['obj_id'] = $ri['repo_id'];
185 $a['who'] = 400;
186 $a['uid'] = 500;
187 $a['rights'] = "E";
188 $a['prio'] = 100;
189 $a['ip'] = "";
190 $a['misc'] = "";
191 $v = rg_rights_set($db, "repo", $a);
178 192 if ($v === FALSE) { if ($v === FALSE) {
179 193 rg_log("Owner cannot set separate rights for him!"); rg_log("Owner cannot set separate rights for him!");
180 194 exit(1); exit(1);
 
... ... print_r($r);
190 204 // TODO: we should test if expected fields are returned! // TODO: we should test if expected fields are returned!
191 205
192 206
193 // test stats
194 $rg_state_dir = "repos";
195 $a = array(
196 "itime" => time(),
197 "ip" => "IPIPIPIPIPIP1",
198 "repo_id" => 3000,
199 "old_rev" => "abcdef",
200 "new_rev" => "434343",
201 "refname" => "refs/heads/xxx");
202 $f = rg_repo_stats_push2file($a);
203 if ($f === FALSE) {
204 echo "push2file returned FALSE!\n";
205 exit(1);
206 }
207 $r = unserialize(file_get_contents($rg_state_dir . "/qstats/$f"));
208 if ($r === FALSE) {
209 echo "Cannot get file or unserialize!\n";
210 exit(1);
211 }
212 if ($r['repo_id'] != 3000) {
213 print_r($r);
214 echo "rg_repo_stats_push2file is not working right!\n";
215 exit(1);
216 }
217
218 // Testing the rename of the repos
207 rg_log("Testing the rename of the repos");
208 $repo_name = "renameA";
219 209 $rg_repos = "repos"; $rg_repos = "repos";
220 210 $_path = rg_repo_path_by_id($uid, $repo_id); $_path = rg_repo_path_by_id($uid, $repo_id);
221 211 if (!file_exists($_path)) { if (!file_exists($_path)) {
File tests/rights.php changed (mode: 100644) (index f44e11b..65b0b3d)
... ... require_once($INC . "/init.inc.php");
7 7 require_once($INC . "/rights.inc.php"); require_once($INC . "/rights.inc.php");
8 8
9 9 rg_log_set_file("rights.log"); rg_log_set_file("rights.log");
10
10 11 require_once("common.php"); require_once("common.php");
11 12
12 13 $rg_sql_debug = 1; $rg_sql_debug = 1;
 
... ... if ($r !== TRUE) {
72 73 echo "Seems I cannot set rights 1 (" . rg_rights_error() . ")\n"; echo "Seems I cannot set rights 1 (" . rg_rights_error() . ")\n";
73 74 exit(1); exit(1);
74 75 } }
75 $a['rights'] = "d"; $a['misc'] = "misc2";
76 $a['rights'] = "d"; $a['misc'] = "misc2"; $a['prio'] = 4;
76 77 $r = rg_rights_set($db, "type1", $a); $r = rg_rights_set($db, "type1", $a);
77 78 if ($r !== TRUE) { if ($r !== TRUE) {
78 79 echo "Seems I cannot set rights 2 (" . rg_rights_error() . ")\n"; echo "Seems I cannot set rights 2 (" . rg_rights_error() . ")\n";
79 80 exit(1); exit(1);
80 81 } }
82 $a['rights'] = "E"; $a['misc'] = "misc3"; $a['prio'] = 4;
83 $r = rg_rights_set($db, "type2", $a);
84 if ($r !== TRUE) {
85 echo "Seems I cannot set rights 2 (" . rg_rights_error() . ")\n";
86 exit(1);
87 }
81 88
82 89 rg_log("Testing rg_rights_get..."); rg_log("Testing rg_rights_get...");
83 90 $right_id = 0; $right_id = 0;
84 $r = rg_rights_get($db, "type1", $a['obj_id'], $a['uid'], $right_id);
91 $r = rg_rights_get($db, $a['obj_id'], "type1", $uid, $a['uid'], $right_id);
92 if (($r['ok'] !== 1) || (strcmp($r['list'][1]['rights'], "d") != 0)) {
93 echo "Seems I cannot get rights (" . rg_rights_error() . ")\n";
94 print_r($r);
95 exit (1);
96 }
97 // 'get' again, to see if cache works
98 $r = rg_rights_get($db, $a['obj_id'], "type1", $uid, $a['uid'], $right_id);
85 99 if (($r['ok'] !== 1) || (strcmp($r['list'][1]['rights'], "d") != 0)) { if (($r['ok'] !== 1) || (strcmp($r['list'][1]['rights'], "d") != 0)) {
86 100 echo "Seems I cannot get rights (" . rg_rights_error() . ")\n"; echo "Seems I cannot get rights (" . rg_rights_error() . ")\n";
87 101 print_r($r); print_r($r);
 
... ... if (($r['ok'] !== 1) || (strcmp($r['list'][1]['rights'], "d") != 0)) {
90 104
91 105 rg_log("Testing delete_list..."); rg_log("Testing delete_list...");
92 106 $list = array(1, 2); $list = array(1, 2);
93 $r = rg_rights_delete_list($db, $a['obj_id'], $list);
107 $r = rg_rights_delete_list($db, "type1", $a['obj_id'], $list);
94 108 if ($r !== TRUE) { if ($r !== TRUE) {
95 109 echo "We should be able to delete rights!\n"; echo "We should be able to delete rights!\n";
96 110 exit(1); exit(1);
97 111 } }
98 112 $right_id = 0; $right_id = 0;
99 $r = rg_rights_get($db, "type1", $a['obj_id'], $a['uid'], $right_id);
113 $r = rg_rights_get($db, $a['obj_id'], "type1", $uid, $a['uid'], $right_id);
100 114 if (($r['ok'] !== 1) || (count($r['list']) > 0)) { if (($r['ok'] !== 1) || (count($r['list']) > 0)) {
101 115 echo "We should not have anymore type1 objects, after a delete.\n"; echo "We should not have anymore type1 objects, after a delete.\n";
102 116 print_r($r); print_r($r);
 
... ... if ($r !== TRUE) {
143 157 exit(1); exit(1);
144 158 } }
145 159
160 rg_log("Finish");
146 161
147 162 // TODO: test if a user can read other rights // TODO: test if a user can read other rights
148 163
File tests/sql.php changed (mode: 100644) (index 091ba2a..842ef80)
... ... $INC = "../inc";
6 6 require_once($INC . "/init.inc.php"); require_once($INC . "/init.inc.php");
7 7 require_once($INC . "/log.inc.php"); require_once($INC . "/log.inc.php");
8 8 require_once($INC . "/sql.inc.php"); require_once($INC . "/sql.inc.php");
9 require_once("common.php");
10 9
11 10 rg_log_set_file("sql.log"); rg_log_set_file("sql.log");
12 11
12 require_once("common.php");
13
13 14 echo "db: drop 'test' table...\n"; echo "db: drop 'test' table...\n";
14 15 $sql = "DROP TABLE IF EXISTS test"; $sql = "DROP TABLE IF EXISTS test";
15 16 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
File tests/state.php changed (mode: 100644) (index b4db53c..f0498a7)
... ... require_once($INC . "/log.inc.php");
8 8 require_once($INC . "/sql.inc.php"); require_once($INC . "/sql.inc.php");
9 9 require_once($INC . "/struct.inc.php"); require_once($INC . "/struct.inc.php");
10 10 require_once($INC . "/state.inc.php"); require_once($INC . "/state.inc.php");
11 require_once("common.php");
12 11
13 12 rg_log_set_file("state.log"); rg_log_set_file("state.log");
14 13
14 require_once("common.php");
15
15 16 $rg_sql_debug = 1; $rg_sql_debug = 1;
16 17
17 18 // check return for an invalid state // check return for an invalid state
File tests/user.php changed (mode: 100644) (index 624feea..65b1458)
... ... require_once($INC . "/user.inc.php");
8 8 require_once($INC . "/sql.inc.php"); require_once($INC . "/sql.inc.php");
9 9 require_once($INC . "/struct.inc.php"); require_once($INC . "/struct.inc.php");
10 10 require_once($INC . "/fixes.inc.php"); require_once($INC . "/fixes.inc.php");
11
12 rg_log_set_file("user.log");
13
11 14 require_once("common.php"); require_once("common.php");
12 15
13 16 $rg_sql_debug = 1; $rg_sql_debug = 1;
14 17
15 rg_log_set_file("user.log");
16 18
17 19 // Defaults // Defaults
18 20 $rg_repos = "ubase"; $rg_repos = "ubase";
File tests/util.php changed (mode: 100644) (index 016331a..d140fe2)
... ... $INC = "../inc";
6 6 require_once($INC . "/init.inc.php"); require_once($INC . "/init.inc.php");
7 7 require_once($INC . "/util.inc.php"); require_once($INC . "/util.inc.php");
8 8 require_once($INC . "/log.inc.php"); require_once($INC . "/log.inc.php");
9 require_once("common.php");
10 9
11 10 rg_log_set_file("util.log"); rg_log_set_file("util.log");
12 11
12 require_once("common.php");
13
13 14 $id = rg_id(16); $id = rg_id(16);
14 15 if (strlen($id) != 16) { if (strlen($id) != 16) {
15 16 echo "Cannot generate an id!\n"; echo "Cannot generate an id!\n";
16 17 exit(1); exit(1);
17 18 } }
18 19
20
21 // rg_array2string
22 $a = 5;
23 $e = "5";
24 $r = rg_array2string($a);
25 if ($r !== $e) {
26 echo "array2string is not working for integers ($r != $a)!\n";
27 exit(1);
28 }
29 $a = "6";
30 $e = "6";
31 $r = rg_array2string($a);
32 if ($r !== $e) {
33 echo "array2string is not working for strings ($r != $a)!\n";
34 exit(1);
35 }
36
37
19 38 @mkdir("util.tmp", 0700, TRUE); @mkdir("util.tmp", 0700, TRUE);
20 39 file_put_contents("util.tmp/file1", "aaa"); file_put_contents("util.tmp/file1", "aaa");
21 40 file_put_contents("util.tmp/file2", "bbb"); file_put_contents("util.tmp/file2", "bbb");
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master