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 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/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/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 |
/* |
/* |