File TODO changed (mode: 100644) (index 56be1d1..2585d29) |
1 |
1 |
== Where I stopped last time == |
== Where I stopped last time == |
2 |
|
[ ] Friends will need a way to register an account with a full account type. |
|
|
2 |
|
[ ] hook_update.sh is not working right. |
|
3 |
|
[ ] phase1: Friends will need a way to register an account with a full account type. |
3 |
4 |
Find a way to distribute this code and a way to support it in rg. |
Find a way to distribute this code and a way to support it in rg. |
4 |
5 |
Probably I will allow only one plan (Friends) till they all create |
Probably I will allow only one plan (Friends) till they all create |
5 |
6 |
accounts. After this, I will remove this plan? |
accounts. After this, I will remove this plan? |
6 |
|
[ ] In mail-ul phase1, ar trebui adaugata si misiunea acestui proiect. |
|
|
7 |
|
[ ] phase1: In mail, ar trebui adaugata si misiunea acestui proiect. |
7 |
8 |
Eventual un FAQ care sa contina si cum vom sustine acest proiect |
Eventual un FAQ care sa contina si cum vom sustine acest proiect |
8 |
9 |
din punct de vedere financiar. Nu uita de repo-uri privat/publice. |
din punct de vedere financiar. Nu uita de repo-uri privat/publice. |
|
10 |
|
[ ] phase1: add in mail a text like: "...any info ... reply to this e-mail" |
|
11 |
|
[ ] phase1: In mail trebuie sa existe un link catre site-ul principal. |
9 |
12 |
[ ] Se pare ca sesiunea expira, indifierent daca e activa (apas butoane)! |
[ ] Se pare ca sesiunea expira, indifierent daca e activa (apas butoane)! |
10 |
|
[ ] Convert var.subvar to var::subvar because php replaces '.' with '_'! |
|
11 |
13 |
[ ] Accessing a file with '"' inside, is not working. |
[ ] Accessing a file with '"' inside, is not working. |
12 |
14 |
See rocketgit.com/user/catalinux/test1/source/tree/blob/"xx\"yy" |
See rocketgit.com/user/catalinux/test1/source/tree/blob/"xx\"yy" |
13 |
15 |
[ ] First page: our mission, how do I install it etc.? |
[ ] First page: our mission, how do I install it etc.? |
14 |
|
[ ] In mail trebuie sa existe un link catre site-ul principal. |
|
15 |
16 |
[ ] themes/default/repo/bug/note_add.html. @@note@@ is correct? |
[ ] themes/default/repo/bug/note_add.html. @@note@@ is correct? |
16 |
|
[ ] In themes/default/mail/* are we allowed with '.'? Should be '::'? |
|
17 |
17 |
[ ] Seems we are stuck processing events in events.php daemon because we are |
[ ] Seems we are stuck processing events in events.php daemon because we are |
18 |
18 |
stuck in 'accept'. We should keep processing the events queue. |
stuck in 'accept'. We should keep processing the events queue. |
19 |
|
[ ] phase1: add in mail a text like: "...any info ... reply to this e-mail" |
|
20 |
19 |
[ ] Check 'description_nice' and apply this everywhere. Maybe we should unset |
[ ] Check 'description_nice' and apply this everywhere. Maybe we should unset |
21 |
20 |
'description', so people will not be tempted to use it. |
'description', so people will not be tempted to use it. |
22 |
21 |
Maybe just overwrite 'description'. And then continue with 'note' |
Maybe just overwrite 'description'. And then continue with 'note' |
|
28 |
27 |
Nu e OK. Trebuie doar pentru anumite cazuri: la o descriere pe pagina |
Nu e OK. Trebuie doar pentru anumite cazuri: la o descriere pe pagina |
29 |
28 |
proiectului, e nevoie. Dar intr-un form, in textarea, nu e nevoie. |
proiectului, e nevoie. Dar intr-un form, in textarea, nu e nevoie. |
30 |
29 |
Apoi as putea elimina description_nice. |
Apoi as putea elimina description_nice. |
31 |
|
Am o idee. Sa introduc un string de forma '<xss>' in toate cimpurile |
|
32 |
|
folosite la unit testing si apoi sa testez prezenta acestor cimpuri |
|
33 |
|
in output-ul curl-ului. Daca e prezent, buba! |
|
34 |
30 |
[ ] Test closing a bug/watch/unwatch/etc. |
[ ] Test closing a bug/watch/unwatch/etc. |
|
31 |
|
[ ] Security: Link-uri + xss (Ionut) |
35 |
32 |
[ ] |
[ ] |
36 |
33 |
|
|
37 |
34 |
== BEFORE NEXT RELEASE == |
== BEFORE NEXT RELEASE == |
|
35 |
|
[ ] Show the age of a repo/user/bug/etc. |
|
36 |
|
[ ] We should update the size of the repos only if is dirty (something pushed). |
38 |
37 |
[ ] Before custom hooks, allow enforcing a custom regex for a commit. |
[ ] Before custom hooks, allow enforcing a custom regex for a commit. |
39 |
38 |
[ ] rg_repo_delete trebuie sa stearga si rights si bugs si notes si bug files |
[ ] rg_repo_delete trebuie sa stearga si rights si bugs si notes si bug files |
40 |
39 |
si watch-uri. |
si watch-uri. |
File inc/bug.inc.php changed (mode: 100644) (index 16a0f44..d6e4169) |
... |
... |
function rg_bug_event_add_one($db, $event) |
51 |
51 |
$ret = FALSE; |
$ret = FALSE; |
52 |
52 |
while (1) { |
while (1) { |
53 |
53 |
// lookup user email |
// lookup user email |
54 |
|
$ui = rg_user_info($db, $event['uid'], "", ""); |
|
|
54 |
|
$ui = rg_user_info($db, $event['ui::uid'], "", ""); |
55 |
55 |
if ($ui['exists'] != 1) { |
if ($ui['exists'] != 1) { |
56 |
56 |
rg_internal_error("User does not exists!"); |
rg_internal_error("User does not exists!"); |
57 |
57 |
break; |
break; |
|
... |
... |
function rg_bug_event_add_one($db, $event) |
64 |
64 |
} |
} |
65 |
65 |
|
|
66 |
66 |
// send e-mail |
// send e-mail |
67 |
|
$event['ui.email'] = $ui['email']; |
|
|
67 |
|
$event['ui::email'] = $ui['email']; |
68 |
68 |
$r = rg_mail_template("mail/user/repo/bug/new", $event); |
$r = rg_mail_template("mail/user/repo/bug/new", $event); |
69 |
69 |
if ($r === FALSE) |
if ($r === FALSE) |
70 |
70 |
break; |
break; |
|
... |
... |
function rg_bug_event_add_one($db, $event) |
73 |
73 |
break; |
break; |
74 |
74 |
} |
} |
75 |
75 |
|
|
76 |
|
rg_log_exit(); |
|
|
76 |
|
rg_log_exit(); |
77 |
77 |
return $ret; |
return $ret; |
78 |
78 |
} |
} |
79 |
79 |
|
|
|
... |
... |
function rg_bug_event_add_all($db, $event) |
91 |
91 |
$x['prio'] = 100; |
$x['prio'] = 100; |
92 |
92 |
|
|
93 |
93 |
// We will sent notifications to all watchers of a repo |
// We will sent notifications to all watchers of a repo |
94 |
|
$r = rg_watch_load_by_obj_id($db, "repo", $event['repo.repo_id'], 0); |
|
|
94 |
|
$r = rg_watch_load_by_obj_id($db, "repo", $event['repo::repo_id'], 0); |
95 |
95 |
if ($r === FALSE) |
if ($r === FALSE) |
96 |
96 |
return FALSE; |
return FALSE; |
97 |
97 |
if (!empty($r)) { |
if (!empty($r)) { |
98 |
98 |
foreach ($r as $index => $uid) { |
foreach ($r as $index => $uid) { |
99 |
|
$x['uid'] = $uid; |
|
100 |
|
$ret[] = $x; |
|
|
99 |
|
$x['ui::uid'] = $uid; |
|
100 |
|
$ret[$uid] = $x; |
101 |
101 |
} |
} |
102 |
102 |
} |
} |
103 |
103 |
|
|
104 |
104 |
// We will sent notifications to all watchers of a bug |
// We will sent notifications to all watchers of a bug |
105 |
|
$r = rg_watch_load_by_obj_id($db, "bug", $event['repo.repo_id'], |
|
106 |
|
$event['bug.bug_id']); |
|
|
105 |
|
$r = rg_watch_load_by_obj_id($db, "bug", $event['repo::repo_id'], |
|
106 |
|
$event['bug::bug_id']); |
107 |
107 |
if ($r === FALSE) |
if ($r === FALSE) |
108 |
108 |
return FALSE; |
return FALSE; |
109 |
109 |
if (!empty($r)) { |
if (!empty($r)) { |
110 |
110 |
foreach ($r as $index => $uid) { |
foreach ($r as $index => $uid) { |
111 |
|
$x['uid'] = $uid; |
|
112 |
|
$ret[] = $x; |
|
|
111 |
|
$x['ui::uid'] = $uid; |
|
112 |
|
$ret[$uid] = $x; |
113 |
113 |
} |
} |
114 |
114 |
} |
} |
115 |
115 |
|
|
|
... |
... |
function rg_bug_event_note_add_one($db, $event) |
127 |
127 |
$ret = FALSE; |
$ret = FALSE; |
128 |
128 |
while (1) { |
while (1) { |
129 |
129 |
// lookup user email |
// lookup user email |
130 |
|
$ui = rg_user_info($db, $event['uid'], "", ""); |
|
|
130 |
|
$ui = rg_user_info($db, $event['ui::uid'], "", ""); |
131 |
131 |
if ($ui['exists'] != 1) { |
if ($ui['exists'] != 1) { |
132 |
132 |
rg_internal_error("User does not exists!"); |
rg_internal_error("User does not exists!"); |
133 |
133 |
break; |
break; |
|
... |
... |
function rg_bug_event_note_add_one($db, $event) |
139 |
139 |
} |
} |
140 |
140 |
|
|
141 |
141 |
// send e-mail |
// send e-mail |
142 |
|
$event['ui.email'] = $ui['email']; |
|
|
142 |
|
$event['ui::email'] = $ui['email']; |
143 |
143 |
$r = rg_mail_template("mail/user/repo/bug/new_note", $event); |
$r = rg_mail_template("mail/user/repo/bug/new_note", $event); |
144 |
144 |
if ($r === FALSE) |
if ($r === FALSE) |
145 |
145 |
break; |
break; |
|
... |
... |
function rg_bug_event_note_add_all($db, $event) |
165 |
165 |
$x['prio'] = 100; |
$x['prio'] = 100; |
166 |
166 |
|
|
167 |
167 |
// Now, build the list of users that will receive notification |
// Now, build the list of users that will receive notification |
168 |
|
$r = rg_watch_load_by_obj_id($db, "bug", $event['repo.repo_id'], |
|
169 |
|
$event['bug_id']); |
|
|
168 |
|
$r = rg_watch_load_by_obj_id($db, "bug", $event['repo::repo_id'], |
|
169 |
|
$event['bug::bug_id']); |
170 |
170 |
if ($r === FALSE) |
if ($r === FALSE) |
171 |
171 |
return FALSE; |
return FALSE; |
172 |
172 |
if (!empty($r)) { |
if (!empty($r)) { |
173 |
173 |
foreach ($r as $index => $uid) { |
foreach ($r as $index => $uid) { |
174 |
|
$x['uid'] = $uid; |
|
|
174 |
|
$x['ui::uid'] = $uid; |
175 |
175 |
$ret[] = $x; |
$ret[] = $x; |
176 |
176 |
} |
} |
177 |
177 |
} |
} |
|
... |
... |
function rg_bug_edit($db, $login_ui, $ri, $data) |
501 |
501 |
} |
} |
502 |
502 |
|
|
503 |
503 |
$event = array("category" => 4100, "prio" => 200, |
$event = array("category" => 4100, "prio" => 200, |
504 |
|
"repo.repo_id" => $ri['repo_id'], |
|
505 |
|
"repo.name" => $ri['name'], |
|
506 |
|
"bug.who_added" => $login_ui['uid'], |
|
507 |
|
"bug.who_added_text" => $login_ui['username'], |
|
508 |
|
"bug.url" => rg_base_url() . rg_re_bugpage($login_ui, $ri['name'], $data['bug_id']), |
|
509 |
|
"bug.assigned_to_text" => $assigned_to_text, |
|
510 |
|
"bug.state_text" => rg_bug_state($data['state']), |
|
511 |
|
"IP" => rg_var_str("REMOTE_ADDR")); |
|
|
504 |
|
"repo::repo_id" => $ri['repo_id'], |
|
505 |
|
"repo::name" => $ri['name'], |
|
506 |
|
"bug::who_added" => $login_ui['uid'], |
|
507 |
|
"bug::who_added_text" => $login_ui['username'], |
|
508 |
|
"bug::url" => rg_base_url() . rg_re_bugpage($login_ui, $ri['name'], $data['bug_id']), |
|
509 |
|
"bug::assigned_to_text" => $assigned_to_text, |
|
510 |
|
"bug::state_text" => rg_bug_state($data['state'])); |
512 |
511 |
$event = rg_array_merge($event, "bug", $data); |
$event = rg_array_merge($event, "bug", $data); |
513 |
512 |
$r = rg_event_add($db, $event); |
$r = rg_event_add($db, $event); |
514 |
513 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
|
... |
... |
function rg_bug_edit($db, $login_ui, $ri, $data) |
522 |
521 |
break; |
break; |
523 |
522 |
} |
} |
524 |
523 |
|
|
525 |
|
rg_event_signal_daemon("", 0); |
|
526 |
|
|
|
527 |
524 |
// update cache |
// update cache |
528 |
525 |
$data['ok'] = 1; |
$data['ok'] = 1; |
529 |
526 |
$data['exists'] = 1; |
$data['exists'] = 1; |
|
... |
... |
function rg_bug_edit($db, $login_ui, $ri, $data) |
531 |
528 |
rg_bug_cosmetic($db, $data); |
rg_bug_cosmetic($db, $data); |
532 |
529 |
rg_cache_set($key, $data); |
rg_cache_set($key, $data); |
533 |
530 |
|
|
|
531 |
|
rg_event_signal_daemon("", 0); |
|
532 |
|
|
534 |
533 |
$ret = $data['bug_id']; |
$ret = $data['bug_id']; |
535 |
534 |
$rollback = 0; |
$rollback = 0; |
536 |
535 |
break; |
break; |
|
... |
... |
function rg_bug_note_add($db, $repo_id, $bug_id, $login_uid, $data) |
1019 |
1018 |
} |
} |
1020 |
1019 |
|
|
1021 |
1020 |
$event = array("category" => 4000, "prio" => 200, |
$event = array("category" => 4000, "prio" => 200, |
1022 |
|
"bug_id" => $bug_id, |
|
1023 |
|
"note.who_added" => $login_uid, |
|
1024 |
|
"repo.repo_id" => $repo_id, |
|
1025 |
|
"repo.name" => $_ri['name'], |
|
1026 |
|
"bug.title" => $_bi['title'], |
|
1027 |
|
"bug.url" => rg_base_url() . rg_re_bugpage($_ui, $_ri['name'], $bug_id), |
|
|
1021 |
|
"bug::bug_id" => $bug_id, |
|
1022 |
|
"repo::repo_id" => $repo_id, |
|
1023 |
|
"repo::name" => $_ri['name'], |
|
1024 |
|
"bug::title" => $_bi['title'], |
|
1025 |
|
"bug::url" => rg_base_url() . rg_re_bugpage($_ui, $_ri['name'], $bug_id), |
1028 |
1026 |
"note" => $data['note'], |
"note" => $data['note'], |
1029 |
|
"note.who_added_text" => $_ui['username'], |
|
1030 |
|
"IP" => rg_var_str("REMOTE_ADDR")); |
|
|
1027 |
|
"note::who_added" => $login_uid, |
|
1028 |
|
"note::who_added_text" => $_ui['username']); |
1031 |
1029 |
$r = rg_event_add($db, $event); |
$r = rg_event_add($db, $event); |
1032 |
1030 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
1033 |
1031 |
rg_bug_set_error("cannot add event" |
rg_bug_set_error("cannot add event" |
File inc/git.inc.php changed (mode: 100644) (index 363ea10..96a99c9) |
... |
... |
function rg_git_diff2array($diff, &$extra) |
566 |
566 |
// parse line "@@ -14,6 +14,8 @@ function..." |
// parse line "@@ -14,6 +14,8 @@ function..." |
567 |
567 |
// @@ from_file_range to_file_range @@ ... |
// @@ from_file_range to_file_range @@ ... |
568 |
568 |
if (strncmp($line, "@@", 2) == 0) { |
if (strncmp($line, "@@", 2) == 0) { |
569 |
|
rg_log("DEBUG: chunks: $line"); |
|
|
569 |
|
//rg_log("DEBUG: chunks: $line"); |
570 |
570 |
|
|
571 |
571 |
$_t = explode(" ", $line, 5); |
$_t = explode(" ", $line, 5); |
572 |
572 |
if (count($_t) < 4) { |
if (count($_t) < 4) { |
|
... |
... |
function rg_git_log($path, $max, $from, $to, $also_patch) |
650 |
650 |
while (1) { |
while (1) { |
651 |
651 |
if (!file_exists($path . "/refs/heads/master")) { |
if (!file_exists($path . "/refs/heads/master")) { |
652 |
652 |
rg_log("\tRepo is empty."); |
rg_log("\tRepo is empty."); |
653 |
|
$ret = ""; |
|
654 |
653 |
break; |
break; |
655 |
654 |
} |
} |
656 |
655 |
|
|
|
... |
... |
function rg_git_diff($a, $template_file) |
882 |
881 |
|
|
883 |
882 |
// for each file changed |
// for each file changed |
884 |
883 |
foreach ($a as $fileindex => $finfo) { |
foreach ($a as $fileindex => $finfo) { |
885 |
|
if (!isset($finfo['file'])) |
|
886 |
|
rg_log("BAD finfo:" . rg_array2string($finfo)); |
|
887 |
|
|
|
888 |
|
rg_log_ml("DEBUG: finfo: " . print_r($finfo, TRUE)); |
|
|
884 |
|
//rg_log_ml("DEBUG: finfo: " . print_r($finfo, TRUE)); |
889 |
885 |
|
|
890 |
886 |
$ret .= "<br />\n"; |
$ret .= "<br />\n"; |
891 |
887 |
|
|
|
... |
... |
function rg_git_diff($a, $template_file) |
908 |
904 |
$ret .= "File <b>$f</b> changed"; |
$ret .= "File <b>$f</b> changed"; |
909 |
905 |
|
|
910 |
906 |
if (!empty($finfo['similarity'])) |
if (!empty($finfo['similarity'])) |
911 |
|
$ret .= " (similarity " . rg_xss_Safe($finfo['similarity']) . ")"; |
|
|
907 |
|
$ret .= " (similarity " . rg_xss_safe($finfo['similarity']) . ")"; |
912 |
908 |
|
|
913 |
909 |
if (!empty($finfo['dissimilarity'])) |
if (!empty($finfo['dissimilarity'])) |
914 |
910 |
$ret .= " (dissimilarity " . rg_xss_safe($finfo['dissimilarity']) . ")"; |
$ret .= " (dissimilarity " . rg_xss_safe($finfo['dissimilarity']) . ")"; |
|
... |
... |
function rg_git_update_tag($db, $a) |
1025 |
1021 |
$ip = $a['ip']; |
$ip = $a['ip']; |
1026 |
1022 |
$uid = $a['login_uid']; |
$uid = $a['login_uid']; |
1027 |
1023 |
|
|
|
1024 |
|
$history = array(); |
|
1025 |
|
$history['ri::repo_id'] = $a['repo_id']; |
|
1026 |
|
$history['ui::uid'] = $uid; |
|
1027 |
|
|
1028 |
1028 |
if (strcmp($a['new_rev_type'], "tag") == 0) { // Annotated |
if (strcmp($a['new_rev_type'], "tag") == 0) { // Annotated |
1029 |
1029 |
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create |
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create |
1030 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "S", $ip, $a['refname'])) |
|
|
1030 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo::uid'], $uid, "S", $ip, $a['refname'])) |
1031 |
1031 |
rg_git_fatal($a['refname'] . "\nNo rights to" |
rg_git_fatal($a['refname'] . "\nNo rights to" |
1032 |
1032 |
. " create an annotated tag."); |
. " create an annotated tag."); |
|
1033 |
|
$history['history_category'] = REPO_CAT_GIT_ATAG_CREATE; |
|
1034 |
|
$history['history_message'] = 'Annotated tag ' . $a['refname'] . ' created (' . $a['new_rev'] . ').'; |
|
1035 |
|
rg_repo_history_insert($db, $history); |
1033 |
1036 |
} else if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete |
} else if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete |
1034 |
1037 |
rg_log("delete ann tag"); |
rg_log("delete ann tag"); |
1035 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "n", $ip, $a['refname'])) |
|
|
1038 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo::uid'], $uid, "n", $ip, $a['refname'])) |
1036 |
1039 |
rg_git_fatal($a['refname'] . "\nNo rights to" |
rg_git_fatal($a['refname'] . "\nNo rights to" |
1037 |
1040 |
. " delete an annotated tag."); |
. " delete an annotated tag."); |
|
1041 |
|
$history['history_category'] = REPO_CAT_GIT_ATAG_DELETE; |
|
1042 |
|
$history['history_message'] = 'Annotated tag ' . $a['refname'] . ' deleted (' . $a['old_rev'] . ').'; |
|
1043 |
|
rg_repo_history_insert($db, $history); |
1038 |
1044 |
} else { // change |
} else { // change |
1039 |
1045 |
rg_log("This seems it cannot happen in recent git."); |
rg_log("This seems it cannot happen in recent git."); |
1040 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "S", $ip, $a['refname'])) |
|
|
1046 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo::uid'], $uid, "S", $ip, $a['refname'])) |
1041 |
1047 |
rg_git_fatal($a['refname'] . "\nNo rights to" |
rg_git_fatal($a['refname'] . "\nNo rights to" |
1042 |
1048 |
. " change an annotated tag."); |
. " change an annotated tag."); |
|
1049 |
|
$history['history_category'] = REPO_CAT_GIT_ATAG_UPDATE; |
|
1050 |
|
$history['history_message'] = 'Annotated tag ' . $a['refname'] . ' updated from ' . $a['old_rev'] . ' to ' . $a['new_rev'] . '.'; |
|
1051 |
|
rg_repo_history_insert($db, $history); |
1043 |
1052 |
} |
} |
1044 |
1053 |
} else { // Un-annotated |
} else { // Un-annotated |
1045 |
1054 |
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create |
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create |
1046 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "Y", $ip, $a['refname'])) |
|
|
1055 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo::uid'], $uid, "Y", $ip, $a['refname'])) |
1047 |
1056 |
rg_git_fatal($a['refname'] . "\nNo rights to" |
rg_git_fatal($a['refname'] . "\nNo rights to" |
1048 |
1057 |
. " create an un-annotated tag."); |
. " create an un-annotated tag."); |
|
1058 |
|
$history['history_category'] = REPO_CAT_GIT_UTAG_CREATE; |
|
1059 |
|
$history['history_message'] = 'Un-annotated tag ' . $a['refname'] . ' created (' . $a['new_rev'] . ').'; |
|
1060 |
|
rg_repo_history_insert($db, $history); |
1049 |
1061 |
} else if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete |
} else if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete |
1050 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "u", $ip, $a['refname'])) |
|
|
1062 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo::uid'], $uid, "u", $ip, $a['refname'])) |
1051 |
1063 |
rg_git_fatal($a['refname'] . "\nNo rights to" |
rg_git_fatal($a['refname'] . "\nNo rights to" |
1052 |
1064 |
. " delete an un-annotated tag."); |
. " delete an un-annotated tag."); |
|
1065 |
|
$history['history_category'] = REPO_CAT_GIT_UTAG_DELETE; |
|
1066 |
|
$history['history_message'] = 'Un-annotated tag ' . $a['refname'] . ' deleted (' . $a['old_rev'] . ').'; |
|
1067 |
|
rg_repo_history_insert($db, $history); |
1053 |
1068 |
} else { // change |
} else { // change |
1054 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "U", $ip, $a['refname'])) |
|
|
1069 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo::uid'], $uid, "U", $ip, $a['refname'])) |
1055 |
1070 |
rg_git_fatal($a['refname'] . "\nNo rights to" |
rg_git_fatal($a['refname'] . "\nNo rights to" |
1056 |
1071 |
. " change an un-annotated tag."); |
. " change an un-annotated tag."); |
|
1072 |
|
$history['history_category'] = REPO_CAT_GIT_UTAG_UPDATE; |
|
1073 |
|
$history['history_message'] = 'Annotated tag ' . $a['refname'] . ' updated from ' . $a['old_rev'] . ' to ' . $a['new_rev'] . '.'; |
|
1074 |
|
rg_repo_history_insert($db, $history); |
1057 |
1075 |
} |
} |
1058 |
1076 |
} |
} |
1059 |
1077 |
|
|
|
... |
... |
function rg_git_update_tag($db, $a) |
1068 |
1086 |
. rg_git_error() . ")"); |
. rg_git_error() . ")"); |
1069 |
1087 |
} |
} |
1070 |
1088 |
|
|
1071 |
|
// We can clean now the namespace - TODO |
|
|
1089 |
|
// We can clean now the tmp namespace - TODO |
1072 |
1090 |
} |
} |
1073 |
1091 |
|
|
1074 |
1092 |
rg_log_exit(); |
rg_log_exit(); |
|
... |
... |
function rg_git_update_branch($db, $a) |
1088 |
1106 |
$ip = $a['ip']; |
$ip = $a['ip']; |
1089 |
1107 |
$uid = $a['login_uid']; |
$uid = $a['login_uid']; |
1090 |
1108 |
|
|
|
1109 |
|
$history = array(); |
|
1110 |
|
$history['ri::repo_id'] = $a['repo_id']; |
|
1111 |
|
$history['ui::uid'] = $uid; |
|
1112 |
|
|
1091 |
1113 |
if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete |
if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete |
1092 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "D", $ip, $a['refname'])) |
|
|
1114 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo::uid'], $uid, "D", $ip, $a['refname'])) |
1093 |
1115 |
rg_git_fatal($a['refname'] . "\nNo rights to delete" |
rg_git_fatal($a['refname'] . "\nNo rights to delete" |
1094 |
1116 |
. " a branch."); |
. " a branch."); |
|
1117 |
|
$history['history_category'] = REPO_CAT_GIT_BRANCH_DELETE; |
|
1118 |
|
$history['history_message'] = 'Reference ' . $a['refname'] . ' deleted.'; |
|
1119 |
|
rg_repo_history_insert($db, $history); |
1095 |
1120 |
return; |
return; |
1096 |
1121 |
} |
} |
1097 |
1122 |
|
|
1098 |
1123 |
// If we have 'H' (anonymous push), we have also create branch |
// If we have 'H' (anonymous push), we have also create branch |
1099 |
1124 |
$check_fast_forward = 1; |
$check_fast_forward = 1; |
1100 |
1125 |
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create |
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create |
1101 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "H|C", $ip, $a['refname'])) |
|
|
1126 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo::uid'], $uid, "H|C", $ip, $a['refname'])) |
1102 |
1127 |
rg_git_fatal($a['refname'] . "\nYou have no rights" |
rg_git_fatal($a['refname'] . "\nYou have no rights" |
1103 |
1128 |
. " to create a branch."); |
. " to create a branch."); |
1104 |
1129 |
$check_fast_forward = 0; |
$check_fast_forward = 0; |
|
... |
... |
function rg_git_update_branch($db, $a) |
1106 |
1131 |
|
|
1107 |
1132 |
// Create or change |
// Create or change |
1108 |
1133 |
// Check for non fast-forward update |
// Check for non fast-forward update |
1109 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "O", $ip, $a['refname']) |
|
|
1134 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo::uid'], $uid, "O", $ip, $a['refname']) |
1110 |
1135 |
&& ($check_fast_forward == 1)) { |
&& ($check_fast_forward == 1)) { |
1111 |
1136 |
$merge_base = rg_git_merge_base($a['old_rev'], $a['new_rev']); |
$merge_base = rg_git_merge_base($a['old_rev'], $a['new_rev']); |
1112 |
1137 |
if ($merge_base === FALSE) { |
if ($merge_base === FALSE) { |
|
... |
... |
function rg_git_update_branch($db, $a) |
1122 |
1147 |
|
|
1123 |
1148 |
// Check if user pushes a merge commit |
// Check if user pushes a merge commit |
1124 |
1149 |
// TODO: Check all commits, not only the last one! |
// TODO: Check all commits, not only the last one! |
1125 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "M", $ip, $a['refname'])) { |
|
|
1150 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo::uid'], $uid, "M", $ip, $a['refname'])) { |
1126 |
1151 |
if (rg_git_rev_ok($a['new_rev'] . "^2")) |
if (rg_git_rev_ok($a['new_rev'] . "^2")) |
1127 |
1152 |
rg_git_fatal($a['refname'] . "\nNo rights to push merges."); |
rg_git_fatal($a['refname'] . "\nNo rights to push merges."); |
1128 |
1153 |
} |
} |
1129 |
1154 |
|
|
1130 |
1155 |
// Check for bad whitespace |
// Check for bad whitespace |
1131 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "W", $ip, $a['refname'])) { |
|
|
1156 |
|
if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo::uid'], $uid, "W", $ip, $a['refname'])) { |
1132 |
1157 |
// TODO: add caching because we may check again below |
// TODO: add caching because we may check again below |
1133 |
1158 |
$w = rg_git_whitespace_ok($a['old_rev'], $a['new_rev']); |
$w = rg_git_whitespace_ok($a['old_rev'], $a['new_rev']); |
1134 |
1159 |
if ($w !== TRUE) |
if ($w !== TRUE) |
|
... |
... |
function rg_git_update_branch($db, $a) |
1143 |
1168 |
rg_git_fatal($a['refname'] . "\nInternal error, try again later\n"); |
rg_git_fatal($a['refname'] . "\nInternal error, try again later\n"); |
1144 |
1169 |
foreach ($r as $file) { |
foreach ($r as $file) { |
1145 |
1170 |
if (rg_rights_allow($db, $a['repo_id'], "repo_path", |
if (rg_rights_allow($db, $a['repo_id'], "repo_path", |
1146 |
|
$a['repo.uid'], $uid, "P", $ip, $file) !== TRUE) { |
|
|
1171 |
|
$a['repo::uid'], $uid, "P", $ip, $file) !== TRUE) { |
1147 |
1172 |
rg_git_fatal($a['refname'] |
rg_git_fatal($a['refname'] |
1148 |
1173 |
. "\nNo rights to push file [$file]\n"); |
. "\nNo rights to push file [$file]\n"); |
1149 |
1174 |
} |
} |
1150 |
1175 |
|
|
1151 |
1176 |
if (!rg_rights_allow($db, $a['repo_id'], "repo_path", |
if (!rg_rights_allow($db, $a['repo_id'], "repo_path", |
1152 |
|
$a['repo.uid'], $uid, "W", $ip, $a['refname'])) { |
|
|
1177 |
|
$a['repo::uid'], $uid, "W", $ip, $a['refname'])) { |
1153 |
1178 |
$w = rg_git_whitespace_ok($a['old_rev'], $a['new_rev']); |
$w = rg_git_whitespace_ok($a['old_rev'], $a['new_rev']); |
1154 |
1179 |
if ($w !== TRUE) { |
if ($w !== TRUE) { |
1155 |
1180 |
rg_git_fatal($a['refname'] |
rg_git_fatal($a['refname'] |
|
... |
... |
function rg_git_update_branch($db, $a) |
1159 |
1184 |
} |
} |
1160 |
1185 |
} |
} |
1161 |
1186 |
|
|
1162 |
|
if (rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "P", $ip, $a['refname']) !== TRUE) { |
|
|
1187 |
|
if (rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo::uid'], $uid, "P", $ip, $a['refname']) !== TRUE) { |
1163 |
1188 |
rg_log("\tPush is not allowed, let's see the anon one"); |
rg_log("\tPush is not allowed, let's see the anon one"); |
1164 |
|
if (rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "H", $ip, $a['refname']) === FALSE) { |
|
|
1189 |
|
if (rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo::uid'], $uid, "H", $ip, $a['refname']) === FALSE) { |
1165 |
1190 |
$_x = array(); |
$_x = array(); |
1166 |
1191 |
$msg = rg_template("msg/push_not_allowed.txt", $_x); |
$msg = rg_template("msg/push_not_allowed.txt", $_x); |
1167 |
1192 |
rg_git_fatal($a['refname']. "\n" . $msg); |
rg_git_fatal($a['refname']. "\n" . $msg); |
|
... |
... |
function rg_git_update_branch($db, $a) |
1200 |
1225 |
. rg_git_error() . ")"); |
. rg_git_error() . ")"); |
1201 |
1226 |
} |
} |
1202 |
1227 |
|
|
1203 |
|
// We can clean now the namespace - TODO |
|
|
1228 |
|
// We can clean now the tmp namespace - TODO |
|
1229 |
|
} |
|
1230 |
|
|
|
1231 |
|
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { |
|
1232 |
|
$history['history_category'] = REPO_CAT_GIT_BRANCH_CREATE; |
|
1233 |
|
$history['history_message'] = 'Reference ' . $a['refname'] . ' created.'; |
|
1234 |
|
} else { |
|
1235 |
|
$history['history_category'] = REPO_CAT_GIT_BRANCH_UPDATE; |
|
1236 |
|
$history['history_message'] = 'Reference ' . $a['refname'] . ' updated from ' . $a['old_rev'] . ' to ' . $a['new_rev'] . '.'; |
1204 |
1237 |
} |
} |
|
1238 |
|
rg_repo_history_insert($db, $history); |
1205 |
1239 |
} |
} |
1206 |
1240 |
|
|
1207 |
1241 |
rg_prof_end("git_update_branch"); |
rg_prof_end("git_update_branch"); |
File inc/repo.inc.php changed (mode: 100644) (index 0f698c4..df13ea2) |
... |
... |
define('REPO_CAT_RENAME', 4); |
191 |
191 |
define('REPO_CAT_UPDATE', 5); |
define('REPO_CAT_UPDATE', 5); |
192 |
192 |
define('REPO_CAT_BUG_ADDED', 10); |
define('REPO_CAT_BUG_ADDED', 10); |
193 |
193 |
define('REPO_CAT_BUG_CLOSED', 11); |
define('REPO_CAT_BUG_CLOSED', 11); |
|
194 |
|
define('REPO_CAT_GIT_ATAG_CREATE', 20); |
|
195 |
|
define('REPO_CAT_GIT_ATAG_DELETE', 21); |
|
196 |
|
define('REPO_CAT_GIT_ATAG_UPDATE', 22); |
|
197 |
|
define('REPO_CAT_GIT_UTAG_CREATE', 30); |
|
198 |
|
define('REPO_CAT_GIT_UTAG_DELETE', 31); |
|
199 |
|
define('REPO_CAT_GIT_UTAG_UPDATE', 32); |
|
200 |
|
define('REPO_CAT_GIT_BRANCH_DELETE', 40); |
|
201 |
|
define('REPO_CAT_GIT_BRANCH_UPDATE', 41); |
|
202 |
|
define('REPO_CAT_GIT_BRANCH_CREATE', 42); |
194 |
203 |
|
|
195 |
204 |
$rg_repo_error = ""; |
$rg_repo_error = ""; |
196 |
205 |
|
|
|
... |
... |
function rg_repo_event_symlink_by_name($db, $e) |
280 |
289 |
{ |
{ |
281 |
290 |
rg_prof_start("repo_event_symlink_by_name"); |
rg_prof_start("repo_event_symlink_by_name"); |
282 |
291 |
|
|
283 |
|
$id_path = rg_repo_path_by_id($e['ui.uid'], $e['ri.repo_id']); |
|
284 |
|
$id_path_rel = rg_repo_path_by_id_rel($e['ui.uid'], $e['ri.repo_id']); |
|
285 |
|
$new_path = rg_repo_path_by_name($e['ui.uid'], $e['ri.name']); |
|
|
292 |
|
$id_path = rg_repo_path_by_id($e['ui::uid'], $e['ri::repo_id']); |
|
293 |
|
$id_path_rel = rg_repo_path_by_id_rel($e['ui::uid'], $e['ri::repo_id']); |
|
294 |
|
$new_path = rg_repo_path_by_name($e['ui::uid'], $e['ri::name']); |
286 |
295 |
|
|
287 |
296 |
$ret = FALSE; |
$ret = FALSE; |
288 |
297 |
while (1) { |
while (1) { |
|
... |
... |
function rg_repo_event_storage_create($db, $e) |
349 |
358 |
|
|
350 |
359 |
$ret = FALSE; |
$ret = FALSE; |
351 |
360 |
while (1) { |
while (1) { |
352 |
|
$by_id_path = rg_repo_path_by_id($e['ui.uid'], $e['ri.repo_id']); |
|
|
361 |
|
$by_id_path = rg_repo_path_by_id($e['ui::uid'], $e['ri::repo_id']); |
353 |
362 |
if (!is_dir($by_id_path)) { |
if (!is_dir($by_id_path)) { |
354 |
363 |
if (mkdir($by_id_path, 0755, TRUE) === FALSE) { |
if (mkdir($by_id_path, 0755, TRUE) === FALSE) { |
355 |
364 |
rg_repo_set_error("could not create folder $dst"); |
rg_repo_set_error("could not create folder $dst"); |
|
... |
... |
function rg_repo_event_storage_create($db, $e) |
357 |
366 |
} |
} |
358 |
367 |
} |
} |
359 |
368 |
|
|
360 |
|
if ($e['ri.master'] == 0) { |
|
|
369 |
|
if ($e['ri::master'] == 0) { |
361 |
370 |
$r = rg_git_init($by_id_path); |
$r = rg_git_init($by_id_path); |
362 |
371 |
if ($r === FALSE) { |
if ($r === FALSE) { |
363 |
372 |
rg_repo_set_error("cannot init master" |
rg_repo_set_error("cannot init master" |
|
... |
... |
function rg_repo_event_storage_create($db, $e) |
365 |
374 |
break; |
break; |
366 |
375 |
} |
} |
367 |
376 |
} else { |
} else { |
368 |
|
$mi = rg_repo_info($db, $e['ri.master'], 0, ""); |
|
|
377 |
|
$mi = rg_repo_info($db, $e['ri::master'], 0, ""); |
369 |
378 |
if ($mi['exists'] != 1) { |
if ($mi['exists'] != 1) { |
370 |
379 |
rg_repo_set_error("cannot find master (" . rg_repo_error() . ")"); |
rg_repo_set_error("cannot find master (" . rg_repo_error() . ")"); |
371 |
380 |
break; |
break; |
|
... |
... |
function rg_repo_event_storage_create($db, $e) |
384 |
393 |
if ($r === FALSE) |
if ($r === FALSE) |
385 |
394 |
break; |
break; |
386 |
395 |
|
|
387 |
|
$r = rg_repo_git_done($db, $e['ri.repo_id']); |
|
|
396 |
|
$r = rg_repo_git_done($db, $e['ri::repo_id']); |
388 |
397 |
if ($r !== TRUE) |
if ($r !== TRUE) |
389 |
398 |
break; |
break; |
390 |
399 |
|
|
|
... |
... |
function rg_repo_history_insert($db, $event) |
440 |
449 |
rg_prof_start("repo_history_insert"); |
rg_prof_start("repo_history_insert"); |
441 |
450 |
rg_log_enter("repo_history_insert: event=" . rg_array2string($event)); |
rg_log_enter("repo_history_insert: event=" . rg_array2string($event)); |
442 |
451 |
|
|
|
452 |
|
if (!isset($event['ui::uid'])) |
|
453 |
|
$event['ui::uid'] = 0; |
|
454 |
|
|
443 |
455 |
$ret = FALSE; |
$ret = FALSE; |
444 |
456 |
while (1) { |
while (1) { |
445 |
457 |
$now = time(); |
$now = time(); |
446 |
458 |
$params = array("now" => $now, |
$params = array("now" => $now, |
447 |
|
"repo_id" => $event['ri.repo_id'], |
|
|
459 |
|
"repo_id" => $event['ri::repo_id'], |
|
460 |
|
"uid" => $event['ui::uid'], |
448 |
461 |
"cat" => $event['history_category'], |
"cat" => $event['history_category'], |
449 |
462 |
"mess" => $event['history_message']); |
"mess" => $event['history_message']); |
450 |
463 |
$sql = "INSERT INTO repo_history_" . gmdate("Y_m", $now) |
$sql = "INSERT INTO repo_history_" . gmdate("Y_m", $now) |
451 |
|
. " (itime, repo_id, category, message)" |
|
452 |
|
. " VALUES (@@now@@, @@repo_id@@, @@cat@@, @@mess@@)"; |
|
|
464 |
|
. " (itime, uid, repo_id, category, message)" |
|
465 |
|
. " VALUES (@@now@@, @@uid@@, @@repo_id@@, @@cat@@, @@mess@@)"; |
453 |
466 |
$res = rg_sql_query_params($db, $sql, $params); |
$res = rg_sql_query_params($db, $sql, $params); |
454 |
467 |
if ($res === FALSE) |
if ($res === FALSE) |
455 |
468 |
break; |
break; |
|
... |
... |
function rg_repo_history_load($db, $repo_id, $category, $number, $max_seconds) |
488 |
501 |
if ($number > 0) |
if ($number > 0) |
489 |
502 |
$limit_sql = " LIMIT " . $number; |
$limit_sql = " LIMIT " . $number; |
490 |
503 |
else |
else |
491 |
|
$limit_sql = " LIMIT 100"; |
|
|
504 |
|
$limit_sql = " LIMIT 30"; |
492 |
505 |
|
|
493 |
506 |
$time_sql = ""; |
$time_sql = ""; |
494 |
507 |
if ($max_seconds > 0) |
if ($max_seconds > 0) |
|
... |
... |
function rg_repo_history_load($db, $repo_id, $category, $number, $max_seconds) |
506 |
519 |
|
|
507 |
520 |
$ret = array(); |
$ret = array(); |
508 |
521 |
while (($row = rg_sql_fetch_array($res))) { |
while (($row = rg_sql_fetch_array($res))) { |
|
522 |
|
$row['username'] = 'n/a'; |
|
523 |
|
if ($row['uid'] > 0) { |
|
524 |
|
$ui = rg_user_info($db, '', $row['uid'], ''); |
|
525 |
|
if ($ui['exists'] == 1) |
|
526 |
|
$row['username'] = $ui['username']; |
|
527 |
|
} |
|
528 |
|
|
509 |
529 |
if ($row['itime'] == 0) |
if ($row['itime'] == 0) |
510 |
530 |
$row['itime_text'] = "N/A"; |
$row['itime_text'] = "N/A"; |
511 |
531 |
else |
else |
|
... |
... |
function rg_repo_delete($db, $repo_id, $ui) |
710 |
730 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
711 |
731 |
|
|
712 |
732 |
$event = array("category" => 3001, "prio" => 50, |
$event = array("category" => 3001, "prio" => 50, |
713 |
|
"IP" => rg_var_str("REMOTE_ADDR"), |
|
714 |
|
"ui.email" => $ui['confirmed'] > 0 ? $ui['email'] : "", |
|
715 |
|
"ri.name" => $ri['name'], |
|
716 |
|
"ri.repo_id" => $repo_id); |
|
|
733 |
|
"ui::email" => $ui['confirmed'] > 0 ? $ui['email'] : "", |
|
734 |
|
"ri::name" => $ri['name'], |
|
735 |
|
"ri::repo_id" => $repo_id); |
717 |
736 |
$r = rg_event_add($db, $event); |
$r = rg_event_add($db, $event); |
718 |
737 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
719 |
738 |
rg_repo_set_error("cannot add event" |
rg_repo_set_error("cannot add event" |
|
... |
... |
function rg_repo_edit($db, $login_ui, &$new) |
935 |
954 |
|
|
936 |
955 |
$event = array("category" => $cat, "prio" => 50, |
$event = array("category" => $cat, "prio" => 50, |
937 |
956 |
"notification" => $notification, |
"notification" => $notification, |
938 |
|
"ui.uid" => $login_ui['uid'], |
|
939 |
|
"ui.email" => $login_ui['confirmed'] > 0 ? $login_ui['email'] : "", |
|
940 |
|
"ri.url" => rg_base_url() . rg_re_repopage($login_ui, $new['name']), |
|
|
957 |
|
"ui::uid" => $login_ui['uid'], |
|
958 |
|
"ui::email" => $login_ui['confirmed'] > 0 ? $login_ui['email'] : "", |
|
959 |
|
"ri::url" => rg_base_url() . rg_re_repopage($login_ui, $new['name']), |
941 |
960 |
"history_category" => $hcat, |
"history_category" => $hcat, |
942 |
|
"history_message" => $hmess, |
|
943 |
|
"IP" => rg_var_str("REMOTE_ADDR")); |
|
944 |
|
$event = rg_array_merge($event, "ri.old", $ri); |
|
|
961 |
|
"history_message" => $hmess); |
|
962 |
|
$event = rg_array_merge($event, "ri::old", $ri); |
945 |
963 |
$event = rg_array_merge($event, "ri", $new); |
$event = rg_array_merge($event, "ri", $new); |
946 |
|
$event['ri.old.description_md5'] = md5($old_description); |
|
947 |
|
$event['ri.description_md5'] = md5($new['description']); |
|
|
964 |
|
$event['ri::old::description_md5'] = md5($old_description); |
|
965 |
|
$event['ri::description_md5'] = md5($new['description']); |
948 |
966 |
$r = rg_event_add($db, $event); |
$r = rg_event_add($db, $event); |
949 |
967 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
950 |
968 |
rg_repo_set_error("cannot add event" |
rg_repo_set_error("cannot add event" |
951 |
969 |
. " (" . rg_event_error() . ")"); |
. " (" . rg_event_error() . ")"); |
952 |
970 |
break; |
break; |
953 |
971 |
} |
} |
954 |
|
rg_event_signal_daemon("", 0); |
|
955 |
972 |
|
|
956 |
973 |
$new['ok'] = 1; |
$new['ok'] = 1; |
957 |
974 |
$new['exists'] = 1; |
$new['exists'] = 1; |
|
... |
... |
function rg_repo_edit($db, $login_ui, &$new) |
959 |
976 |
rg_cache_set("repo_by_name::" . $login_ui['uid'] . "::" |
rg_cache_set("repo_by_name::" . $login_ui['uid'] . "::" |
960 |
977 |
. $new['name'], $new['repo_id']); |
. $new['name'], $new['repo_id']); |
961 |
978 |
|
|
|
979 |
|
rg_event_signal_daemon("", 0); |
|
980 |
|
|
962 |
981 |
$ret = TRUE; |
$ret = TRUE; |
963 |
982 |
break; |
break; |
964 |
983 |
} |
} |
File inc/user.inc.php changed (mode: 100644) (index 0759ac2..cd3fcc2) |
... |
... |
function rg_user_link_by_name($db, $event) |
103 |
103 |
{ |
{ |
104 |
104 |
rg_log("user_link_by_name: event=" . rg_array2string($event)); |
rg_log("user_link_by_name: event=" . rg_array2string($event)); |
105 |
105 |
|
|
106 |
|
$by_id = rg_user_path_by_id($event['ui.uid']); |
|
|
106 |
|
$by_id = rg_user_path_by_id($event['ui::uid']); |
107 |
107 |
if (!is_dir($by_id) && (mkdir($by_id, 0755, TRUE) === FALSE)) { |
if (!is_dir($by_id) && (mkdir($by_id, 0755, TRUE) === FALSE)) { |
108 |
108 |
rg_user_set_error("cannot mkdir by_id=$by_id ($php_errormsg)"); |
rg_user_set_error("cannot mkdir by_id=$by_id ($php_errormsg)"); |
109 |
109 |
return FALSE; |
return FALSE; |
110 |
110 |
} |
} |
111 |
111 |
|
|
112 |
|
$by_name = rg_user_path_by_name($event['ui.username']); |
|
|
112 |
|
$by_name = rg_user_path_by_name($event['ui::username']); |
113 |
113 |
$by_name_parent = dirname($by_name); |
$by_name_parent = dirname($by_name); |
114 |
114 |
if (!is_dir($by_name_parent) && (mkdir($by_name_parent, 0755, TRUE) === FALSE)) { |
if (!is_dir($by_name_parent) && (mkdir($by_name_parent, 0755, TRUE) === FALSE)) { |
115 |
115 |
rg_user_set_error("cannot mkdir by_name_parent=$by_name_parent ($php_errmsg)"); |
rg_user_set_error("cannot mkdir by_name_parent=$by_name_parent ($php_errmsg)"); |
116 |
116 |
return FALSE; |
return FALSE; |
117 |
117 |
} |
} |
118 |
118 |
|
|
119 |
|
$by_id_rel = rg_user_path_by_id_rel($event['ui.uid']); |
|
|
119 |
|
$by_id_rel = rg_user_path_by_id_rel($event['ui::uid']); |
120 |
120 |
if (is_link($by_name)) |
if (is_link($by_name)) |
121 |
121 |
unlink($by_name); |
unlink($by_name); |
122 |
122 |
if (symlink($by_id_rel, $by_name) === FALSE) { |
if (symlink($by_id_rel, $by_name) === FALSE) { |
|
... |
... |
function rg_user_rename($db, $ui, $new_name) |
382 |
382 |
|
|
383 |
383 |
// TODO: Check if all parameters are used. |
// TODO: Check if all parameters are used. |
384 |
384 |
$event = array("category" => 2005, "prio" => 50, |
$event = array("category" => 2005, "prio" => 50, |
385 |
|
"ui.rename_from" => $ui['username'], |
|
386 |
|
"ui.rename_to" => $new_name, |
|
387 |
|
"IP" => rg_var_str("REMOTE_ADDR"), |
|
388 |
|
"ui.uid" => $ui['uid']); |
|
|
385 |
|
"ui::rename_from" => $ui['username'], |
|
386 |
|
"ui::rename_to" => $new_name, |
|
387 |
|
"ui::uid" => $ui['uid']); |
389 |
388 |
$r = rg_event_add($db, $event); |
$r = rg_event_add($db, $event); |
390 |
389 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
391 |
390 |
rg_repo_set_error("cannot add event" |
rg_repo_set_error("cannot add event" |
|
... |
... |
function rg_user_edit($db, $d) |
504 |
503 |
|
|
505 |
504 |
if ($d['uid'] == 0) { // add |
if ($d['uid'] == 0) { // add |
506 |
505 |
$event = array("category" => 2000, "prio" => 50, |
$event = array("category" => 2000, "prio" => 50, |
507 |
|
"ui.uid" => $d['uid'], |
|
508 |
|
"ui.username" => $d['username'], |
|
509 |
|
"ui.email" => $confirmed > 0 ? $d['email'] : "", |
|
510 |
|
"ui.confirm_token" => $d['confirm_token'], |
|
|
506 |
|
"ui::uid" => $row['uid'], |
|
507 |
|
"ui::username" => $d['username'], |
|
508 |
|
"ui::email" => $confirmed > 0 ? $d['email'] : "", |
|
509 |
|
"ui::confirm_token" => $d['confirm_token'], |
511 |
510 |
"rg_account_email_confirm" => $rg_account_email_confirm, |
"rg_account_email_confirm" => $rg_account_email_confirm, |
512 |
511 |
"url" => rg_base_url() |
"url" => rg_base_url() |
513 |
512 |
); |
); |
|
... |
... |
function rg_user_info($db, $uid, $user, $email) |
636 |
635 |
$ret = array_merge($ret, $row); |
$ret = array_merge($ret, $row); |
637 |
636 |
$ret['exists'] = 1; |
$ret['exists'] = 1; |
638 |
637 |
|
|
639 |
|
rg_cache_set("user::" . $uid, $ret); |
|
|
638 |
|
rg_cache_set("user::" . $ret['uid'], $ret); |
640 |
639 |
rg_cache_set("username_to_uid::" . $ret['username'], $ret['uid']); |
rg_cache_set("username_to_uid::" . $ret['username'], $ret['uid']); |
641 |
640 |
rg_cache_set("email_to_uid::" . $ret['email'], $ret['uid']); |
rg_cache_set("email_to_uid::" . $ret['email'], $ret['uid']); |
642 |
641 |
break; |
break; |
File inc/user/repo-page.php changed (mode: 100644) (index 6368bb4..712a31e) |
... |
... |
if (($rg['ri']['exists'] != 1) |
36 |
36 |
|
|
37 |
37 |
if (!isset($rg['ri']['git_dir_done'])) |
if (!isset($rg['ri']['git_dir_done'])) |
38 |
38 |
$rg['ri']['git_dir_done'] = 0; |
$rg['ri']['git_dir_done'] = 0; |
39 |
|
if ($rg['ri']['git_dir_done'] == 0) { |
|
40 |
|
// We will wait a little for the git dir to be done |
|
41 |
|
// TODO: Should we really wait for this?! |
|
42 |
|
// We may just consider that the repo is empty. Hm. |
|
43 |
|
$ev_id = "repo_create-" . $rg['login_ui']['uid'] . "-" |
|
44 |
|
. $rg['ri']['repo_id'] . "-git"; |
|
45 |
|
$timeout = 10 * 1000; // seconds |
|
46 |
|
$r = rg_event_signal_daemon($ev_id, $timeout); |
|
47 |
|
if ($r === FALSE) { |
|
48 |
|
// Seems we did not get the notification |
|
49 |
|
$_repo_page .= rg_warning("Internal error!"); |
|
50 |
|
return; |
|
51 |
|
} |
|
52 |
|
} |
|
53 |
39 |
|
|
54 |
|
// TODO: should we test against $ri?! |
|
55 |
40 |
$can_admin = rg_rights_allow($db, $rg['ri']['repo_id'], "repo", |
$can_admin = rg_rights_allow($db, $rg['ri']['repo_id'], "repo", |
56 |
41 |
$rg['ri']['uid'], $rg['login_ui']['uid'], "E", $rg['ip'], "") === TRUE ? 1 : 0; |
$rg['ri']['uid'], $rg['login_ui']['uid'], "E", $rg['ip'], "") === TRUE ? 1 : 0; |
57 |
42 |
|
|
|
... |
... |
if (strcmp($_subop, "history") == 0) { |
116 |
101 |
$_repo_body .= rg_template("repo/source.html", $rg); |
$_repo_body .= rg_template("repo/source.html", $rg); |
117 |
102 |
|
|
118 |
103 |
rg_log("DEBUG: _subsubop=[$_subsubop]"); |
rg_log("DEBUG: _subsubop=[$_subsubop]"); |
119 |
|
if (strcmp($_subsubop, "tree") == 0) { |
|
|
104 |
|
if ($rg['ri']['git_dir_done'] == 0) { |
|
105 |
|
$_repo_body .= rg_template("repo/no_git_dir.html", $rg); |
|
106 |
|
} else if (strcmp($_subsubop, "tree") == 0) { |
120 |
107 |
$type = array_shift($paras); |
$type = array_shift($paras); |
121 |
108 |
rg_log("DEBUG: tree: type=$type"); |
rg_log("DEBUG: tree: type=$type"); |
122 |
109 |
if (strcmp($type, "blob") == 0) { |
if (strcmp($type, "blob") == 0) { |
|
... |
... |
if (strcmp($_subop, "history") == 0) { |
161 |
148 |
// show the log |
// show the log |
162 |
149 |
$log = rg_git_log($repo_path, 10, "", $ref, FALSE); |
$log = rg_git_log($repo_path, 10, "", $ref, FALSE); |
163 |
150 |
if ($log === FALSE) { |
if ($log === FALSE) { |
164 |
|
rg_log("Error generating log (" . rg_git_error() . ")!"); |
|
165 |
|
$_repo_body .= rg_warning("Error generating log!"); |
|
166 |
|
// TODO: rg_internal_error? |
|
167 |
|
} else if (empty($log)) { |
|
168 |
151 |
$_repo_body .= rg_template("repo/not_init.html", $rg); |
$_repo_body .= rg_template("repo/not_init.html", $rg); |
169 |
152 |
} else { |
} else { |
170 |
153 |
rg_log_ml("DEBUG: log: " . print_r($log, TRUE)); |
rg_log_ml("DEBUG: log: " . print_r($log, TRUE)); |
|
... |
... |
if (strcmp($_subop, "history") == 0) { |
191 |
174 |
|
|
192 |
175 |
$log = rg_git_log($repo_path, 1, $first, $second, TRUE); |
$log = rg_git_log($repo_path, 1, $first, $second, TRUE); |
193 |
176 |
if ($log === FALSE) { |
if ($log === FALSE) { |
194 |
|
$_repo_body .= rg_warning("Could not generate log."); |
|
195 |
|
rg_internal_error("Could not generate log!"); |
|
|
177 |
|
$_repo_body .= rg_template("repo/not_init.html", $rg); |
196 |
178 |
} else { |
} else { |
197 |
179 |
// stats |
// stats |
198 |
180 |
//rg_log("DEBUG: log[0]['files']: " . rg_array2string($log[0]['files'])); |
//rg_log("DEBUG: log[0]['files']: " . rg_array2string($log[0]['files'])); |
|
... |
... |
if (strcmp($_subop, "history") == 0) { |
221 |
203 |
include($INC . "/user/repo/bug/main.php"); |
include($INC . "/user/repo/bug/main.php"); |
222 |
204 |
$_repo_body .= $bug_body; |
$_repo_body .= $bug_body; |
223 |
205 |
} else if (strcmp($_subop, "stats") == 0) { |
} else if (strcmp($_subop, "stats") == 0) { |
224 |
|
$_repo_body .= rg_template("repo/stats.html", $rg); |
|
|
206 |
|
if ($rg['ri']['git_dir_done'] == 0) |
|
207 |
|
$_repo_body .= rg_template("repo/no_git_dir.html", $rg); |
|
208 |
|
else |
|
209 |
|
$_repo_body .= rg_template("repo/stats.html", $rg); |
225 |
210 |
} else if (strcmp($_subop, "mr") == 0) { |
} else if (strcmp($_subop, "mr") == 0) { |
226 |
|
if (empty($paras)) { |
|
|
211 |
|
if ($rg['ri']['git_dir_done'] == 0) { |
|
212 |
|
$_repo_body .= rg_template("repo/no_git_dir.html", $rg); |
|
213 |
|
} else if (empty($paras)) { |
227 |
214 |
$_repo_body .= rg_template("repo/mrs.html", $rg); |
$_repo_body .= rg_template("repo/mrs.html", $rg); |
228 |
215 |
|
|
229 |
216 |
$r = rg_mr_load($db, $rg['ri']['repo_id'], 20); |
$r = rg_mr_load($db, $rg['ri']['repo_id'], 20); |
File inc/util.inc.php changed (mode: 100644) (index a2710a5..31a168d) |
... |
... |
function rg_re_userpage($ui) |
180 |
180 |
if ($ui['organization'] == 0) |
if ($ui['organization'] == 0) |
181 |
181 |
$prefix = "/user"; |
$prefix = "/user"; |
182 |
182 |
|
|
183 |
|
$s = $prefix . "/" . rg_xss_safe($ui['username']); |
|
|
183 |
|
$s = $prefix . "/" . rawurlencode($ui['username']); |
184 |
184 |
|
|
185 |
185 |
return rg_re_url($s); |
return rg_re_url($s); |
186 |
186 |
} |
} |
|
... |
... |
function rg_re_repopage($ui, $repo_name) |
194 |
194 |
exit(1); |
exit(1); |
195 |
195 |
} |
} |
196 |
196 |
|
|
197 |
|
$s = rg_re_userpage($ui) . "/" . rg_xss_safe($repo_name); |
|
|
197 |
|
$s = rg_re_userpage($ui) . "/" . rawurlencode($repo_name); |
198 |
198 |
|
|
199 |
199 |
return rg_re_url($s); |
return rg_re_url($s); |
200 |
200 |
} |
} |
|
... |
... |
function rg_re_repo_ssh($organization, $user, $repo) |
238 |
238 |
$prefix = "/user"; |
$prefix = "/user"; |
239 |
239 |
|
|
240 |
240 |
return "ssh://rocketgit@" . $rg_ssh_host . $port |
return "ssh://rocketgit@" . $rg_ssh_host . $port |
241 |
|
. $prefix . "/" . rg_xss_safe($user) . "/" . rg_xss_safe($repo); |
|
|
241 |
|
. $prefix . "/" . rawurlencode($user) . "/" . rawurlencode($repo); |
242 |
242 |
} |
} |
243 |
243 |
|
|
244 |
244 |
function rg_re_repo_git($organization, $user, $repo) |
function rg_re_repo_git($organization, $user, $repo) |
|
... |
... |
function rg_re_repo_git($organization, $user, $repo) |
256 |
256 |
$prefix = "/user"; |
$prefix = "/user"; |
257 |
257 |
|
|
258 |
258 |
return "git://" . $rg_git_host . $port |
return "git://" . $rg_git_host . $port |
259 |
|
. $prefix . "/" . rg_xss_safe($user) . "/" . rg_xss_safe($repo); |
|
|
259 |
|
. $prefix . "/" . rawurlencode($user) . "/" . rawurlencode($repo); |
260 |
260 |
} |
} |
261 |
261 |
|
|
262 |
262 |
function rg_var_str($name) |
function rg_var_str($name) |
|
... |
... |
function rg_file_get_contents($f) |
653 |
653 |
return $c; |
return $c; |
654 |
654 |
} |
} |
655 |
655 |
|
|
|
656 |
|
/* |
|
657 |
|
* Merges an array (a) into another (src), using a namespace |
|
658 |
|
* Protects modifiers (HTML: etc.). |
|
659 |
|
*/ |
|
660 |
|
function rg_array_merge($src, $namespace, $a) |
|
661 |
|
{ |
|
662 |
|
$ret = $src; |
|
663 |
|
|
|
664 |
|
if (empty($a)) |
|
665 |
|
return $ret; |
|
666 |
|
|
|
667 |
|
if (!empty($namespace)) |
|
668 |
|
$namespace .= "::"; |
|
669 |
|
|
|
670 |
|
foreach ($a as $k => $v) { |
|
671 |
|
$t = explode(":", $k, 2); |
|
672 |
|
if (count($t) == 1) |
|
673 |
|
$ret[$namespace . $k] = $v; |
|
674 |
|
else |
|
675 |
|
$ret[$t[0] . ":" . $namespace . $t[1]] = $v; |
|
676 |
|
} |
|
677 |
|
|
|
678 |
|
return $ret; |
|
679 |
|
} |
|
680 |
|
|
656 |
681 |
/* |
/* |
657 |
682 |
* Builds a html output based on a template with header, footer and line |
* Builds a html output based on a template with header, footer and line |
658 |
683 |
* @data - in array of data for every out line: index 0 is line 1, index 1 is line 2... |
* @data - in array of data for every out line: index 0 is line 1, index 1 is line 2... |
|
... |
... |
function rg_template($file, &$data) |
732 |
757 |
$ret = ""; |
$ret = ""; |
733 |
758 |
while (1) { |
while (1) { |
734 |
759 |
$xfile = $rg_theme_dir . "/" . $rg_theme . "/" . $file; |
$xfile = $rg_theme_dir . "/" . $rg_theme . "/" . $file; |
735 |
|
if (!is_file($xfile)) |
|
|
760 |
|
if (!is_file($xfile)) { |
736 |
761 |
$xfile = $rg_theme_dir . "/default/" . $file; |
$xfile = $rg_theme_dir . "/default/" . $file; |
|
762 |
|
if (!is_file($xfile)) |
|
763 |
|
$xfile = $file; |
|
764 |
|
if (!is_file($xfile)) { |
|
765 |
|
rg_log("Cannot find $file!"); |
|
766 |
|
break; |
|
767 |
|
} |
|
768 |
|
} |
737 |
769 |
|
|
738 |
770 |
$body = rg_file_get_contents($xfile); |
$body = rg_file_get_contents($xfile); |
739 |
771 |
if (empty($body)) { |
if (empty($body)) { |
|
... |
... |
function rg_warning($msg) |
806 |
838 |
if (empty($msg)) |
if (empty($msg)) |
807 |
839 |
return ""; |
return ""; |
808 |
840 |
|
|
|
841 |
|
rg_log("Warning: $msg"); |
|
842 |
|
|
809 |
843 |
$x = array("msg" => $msg); |
$x = array("msg" => $msg); |
810 |
844 |
return rg_template("warning.html", $x); |
return rg_template("warning.html", $x); |
811 |
845 |
} |
} |
|
... |
... |
function rg_mail_template($template, $more) |
1161 |
1195 |
rg_log("mail_template: $template, more=" . rg_array2string($more)); |
rg_log("mail_template: $template, more=" . rg_array2string($more)); |
1162 |
1196 |
|
|
1163 |
1197 |
// Account was not confirmed, so do not send mail |
// Account was not confirmed, so do not send mail |
1164 |
|
if (empty($more['ui.email'])) |
|
|
1198 |
|
if (empty($more['ui::email'])) |
1165 |
1199 |
return TRUE; |
return TRUE; |
1166 |
1200 |
|
|
1167 |
1201 |
$more['HTML:rg_admin_email'] = $rg_admin_email; |
$more['HTML:rg_admin_email'] = $rg_admin_email; |
|
... |
... |
function rg_mail_template($template, $more) |
1175 |
1209 |
$header = trim($header); |
$header = trim($header); |
1176 |
1210 |
$body = rg_template($template . ".body.txt", $more); |
$body = rg_template($template . ".body.txt", $more); |
1177 |
1211 |
|
|
1178 |
|
rg_log("CHECK: mail_template(" . $more['ui.email'] . ", |
|
|
1212 |
|
rg_log("CHECK: mail_template(" . $more['ui::email'] . ", |
1179 |
1213 |
$subject, $body, $header, -f $rg_admin_email"); |
$subject, $body, $header, -f $rg_admin_email"); |
1180 |
|
$ret = mail($more['ui.email'], $subject, $body, $header, |
|
|
1214 |
|
$ret = mail($more['ui::email'], $subject, $body, $header, |
1181 |
1215 |
"-f $rg_admin_email"); |
"-f $rg_admin_email"); |
1182 |
1216 |
if ($ret === FALSE) |
if ($ret === FALSE) |
1183 |
|
rg_log("Sending mail failed to=" . $more['ui.email'] . " subject=$subject!"); |
|
|
1217 |
|
rg_log("Sending mail failed to=" . $more['ui::email'] . " subject=$subject!"); |
1184 |
1218 |
|
|
1185 |
1219 |
rg_prof_end("mail_template"); |
rg_prof_end("mail_template"); |
1186 |
1220 |
return $ret; |
return $ret; |
1187 |
1221 |
} |
} |
1188 |
1222 |
|
|
1189 |
|
/* |
|
1190 |
|
* Merges an array (a) into another (src), using a namespace |
|
1191 |
|
* Protects modifiers (HTML: etc.). |
|
1192 |
|
*/ |
|
1193 |
|
function rg_array_merge($src, $namespace, $a) |
|
1194 |
|
{ |
|
1195 |
|
$ret = $src; |
|
1196 |
|
|
|
1197 |
|
if (empty($a)) |
|
1198 |
|
return $ret; |
|
1199 |
|
|
|
1200 |
|
if (!empty($namespace)) |
|
1201 |
|
$namespace .= "."; |
|
1202 |
|
|
|
1203 |
|
foreach ($a as $k => $v) { |
|
1204 |
|
$t = explode(":", $k, 2); |
|
1205 |
|
if (count($t) == 1) |
|
1206 |
|
$ret[$namespace . $k] = $v; |
|
1207 |
|
else |
|
1208 |
|
$ret[$t[0] . ":" . $namespace . $t[1]] = $v; |
|
1209 |
|
} |
|
1210 |
|
|
|
1211 |
|
return $ret; |
|
1212 |
|
} |
|
1213 |
|
|
|
1214 |
1223 |
/* |
/* |
1215 |
1224 |
* Special implode, with prefix/postfix |
* Special implode, with prefix/postfix |
1216 |
1225 |
*/ |
*/ |
|
... |
... |
function rg_socket_recv_wait($socket, $wait, $timeout) |
1260 |
1269 |
} |
} |
1261 |
1270 |
|
|
1262 |
1271 |
if ($r === 0) { // timeout |
if ($r === 0) { // timeout |
1263 |
|
rg_log("Timeout!"); |
|
|
1272 |
|
rg_log("Timeout in reading!"); |
1264 |
1273 |
break; |
break; |
1265 |
1274 |
} |
} |
1266 |
1275 |
|
|
File tests/http_csrf.php changed (mode: 100644) (index d3e758a..1467ad1) |
... |
... |
$INC = dirname(__FILE__) . "/../inc"; |
8 |
8 |
require_once(dirname(__FILE__) . "/config.php"); |
require_once(dirname(__FILE__) . "/config.php"); |
9 |
9 |
require_once($INC . "/init.inc.php"); |
require_once($INC . "/init.inc.php"); |
10 |
10 |
require_once($INC . "/util.inc.php"); |
require_once($INC . "/util.inc.php"); |
|
11 |
|
require_once("helpers.inc.php"); |
11 |
12 |
require_once("http.inc.php"); |
require_once("http.inc.php"); |
12 |
13 |
|
|
13 |
14 |
rg_log_set_file("http_csrf.log"); |
rg_log_set_file("http_csrf.log"); |
|
... |
... |
$rg_sql = "host=localhost user=rocketgit dbname=rocketgit connect_timeout=10"; |
16 |
17 |
$rg_no_db = TRUE; |
$rg_no_db = TRUE; |
17 |
18 |
require_once("common.php"); |
require_once("common.php"); |
18 |
19 |
|
|
|
20 |
|
$_testns = 'http_csrf'; |
19 |
21 |
$rg_cache_enable = TRUE; |
$rg_cache_enable = TRUE; |
20 |
22 |
|
|
21 |
23 |
$now = time(); |
$now = time(); |
22 |
24 |
|
|
23 |
|
$r = test_login($test_url, $good_sid); |
|
|
25 |
|
rg_test_create_user($db, $rg_ui); |
|
26 |
|
$r = test_login($test_url, $rg_ui, $good_sid); |
24 |
27 |
if ($r === FALSE) { |
if ($r === FALSE) { |
25 |
28 |
rg_log("Cannot login!"); |
rg_log("Cannot login!"); |
26 |
29 |
exit(1); |
exit(1); |
|
... |
... |
$data = array(); |
33 |
36 |
$headers = array("Cookie: sid=" . $good_sid); |
$headers = array("Cookie: sid=" . $good_sid); |
34 |
37 |
$r = do_req($test_url . "/op/suggestion?t=load_suggestion_form_ua", $data, $headers); |
$r = do_req($test_url . "/op/suggestion?t=load_suggestion_form_ua", $data, $headers); |
35 |
38 |
if (!stristr($r['body'], "action=\"/op/suggestion\"")) { |
if (!stristr($r['body'], "action=\"/op/suggestion\"")) { |
36 |
|
file_put_contents("http_csrf.log", print_r($r, TRUE)); |
|
37 |
|
rg_log_ml("Cannot load form!"); |
|
|
39 |
|
rg_log_ml(print_r($r, TRUE)); |
|
40 |
|
rg_log("Cannot load form! See above."); |
38 |
41 |
exit(1); |
exit(1); |
39 |
42 |
} |
} |
40 |
43 |
$good_token = $r['token']; |
$good_token = $r['token']; |
|
... |
... |
$data = array( |
49 |
52 |
$headers = array("Cookie: sid=" . $good_sid); |
$headers = array("Cookie: sid=" . $good_sid); |
50 |
53 |
$r = do_req($test_url . "/op/suggestion?t=post_suggestion_form_diff_ua", $data, $headers); |
$r = do_req($test_url . "/op/suggestion?t=post_suggestion_form_diff_ua", $data, $headers); |
51 |
54 |
if (!stristr($r['body'], "invalid token")) { |
if (!stristr($r['body'], "invalid token")) { |
52 |
|
file_put_contents("http_csrf.log", $r['body']); |
|
53 |
|
rg_log_ml("Seems I could add a suggestion bypassing CSRF" |
|
54 |
|
. " protection based on user-agent!"); |
|
|
55 |
|
rg_log_ml(print_r($r, TRUE)); |
|
56 |
|
rg_log("Seems I could add a suggestion bypassing CSRF" |
|
57 |
|
. " protection based on user-agent! See above."); |
55 |
58 |
exit(1); |
exit(1); |
56 |
59 |
} |
} |
57 |
60 |
|
|
|
... |
... |
$data = array(); |
63 |
66 |
$headers = array("Cookie: sid=" . $good_sid); |
$headers = array("Cookie: sid=" . $good_sid); |
64 |
67 |
$r = do_req($test_url . "/op/suggestion?t=load_suggestion_form_referer", $data, $headers); |
$r = do_req($test_url . "/op/suggestion?t=load_suggestion_form_referer", $data, $headers); |
65 |
68 |
if (!stristr($r['body'], "action=\"/op/suggestion\"")) { |
if (!stristr($r['body'], "action=\"/op/suggestion\"")) { |
66 |
|
file_put_contents("http_csrf.log", print_r($r, TRUE)); |
|
67 |
|
rg_log_ml("Cannot load form!"); |
|
|
69 |
|
rg_log_ml(print_r($r, TRUE)); |
|
70 |
|
rg_log("Cannot load form! See above."); |
68 |
71 |
exit(1); |
exit(1); |
69 |
72 |
} |
} |
70 |
73 |
$good_token = $r['token']; |
$good_token = $r['token']; |
|
... |
... |
$data = array( |
81 |
84 |
$headers = array("Cookie: sid=" . $good_sid); |
$headers = array("Cookie: sid=" . $good_sid); |
82 |
85 |
$r = do_req($test_url . "/op/suggestion?t=post_suggestion_form_diff_referer", $data, $headers); |
$r = do_req($test_url . "/op/suggestion?t=post_suggestion_form_diff_referer", $data, $headers); |
83 |
86 |
if (!stristr($r['body'], "invalid referer")) { |
if (!stristr($r['body'], "invalid referer")) { |
84 |
|
file_put_contents("http_csrf.log", $r['body']); |
|
|
87 |
|
rg_log_ml(print_r($r, TRUE)); |
85 |
88 |
rg_log_ml("Seems I could add a suggestion bypassing CSRF" |
rg_log_ml("Seems I could add a suggestion bypassing CSRF" |
86 |
|
. " protection based on referer!"); |
|
|
89 |
|
. " protection based on referer! See above."); |
87 |
90 |
exit(1); |
exit(1); |
88 |
91 |
} |
} |
89 |
92 |
|
|
|
... |
... |
rg_log("Testing logout CSRF (wrong token)..."); |
92 |
95 |
test_set_ua("user-agent-1"); |
test_set_ua("user-agent-1"); |
93 |
96 |
test_set_referer($test_url); |
test_set_referer($test_url); |
94 |
97 |
$headers = array("Cookie: sid=" . $good_sid); |
$headers = array("Cookie: sid=" . $good_sid); |
95 |
|
$r = do_req($test_url . "/op/logout?t=wrong_token&token=0cb2c9f6e8405eadfef1ccd00c99e3ff", $data, $headers); |
|
|
98 |
|
$data['token'] = strtoupper($good_token); |
|
99 |
|
$r = do_req($test_url . "/op/logout?t=wrong_token", $data, $headers); |
96 |
100 |
if (stristr($r['body'], "You are now logged out")) { |
if (stristr($r['body'], "You are now logged out")) { |
97 |
|
file_put_contents("http_csrf.log", print_r($r, TRUE)); |
|
98 |
|
rg_log_ml("No error on logout with wrong token?!"); |
|
|
101 |
|
rg_log_ml(print_r($r, TRUE)); |
|
102 |
|
rg_log("No error on logout with wrong token?! See above."); |
99 |
103 |
exit(1); |
exit(1); |
100 |
104 |
} |
} |
101 |
105 |
|
|
|
... |
... |
rg_log("Testing logout CSRF (token passed in cookie)..."); |
104 |
108 |
test_set_ua("user-agent-1"); |
test_set_ua("user-agent-1"); |
105 |
109 |
test_set_referer($test_url); |
test_set_referer($test_url); |
106 |
110 |
$headers = array("Cookie: sid=" . $good_sid . "; token=" . $good_logout_token); |
$headers = array("Cookie: sid=" . $good_sid . "; token=" . $good_logout_token); |
|
111 |
|
$data = array('doit' => 1); |
107 |
112 |
$r = do_req($test_url . "/op/logout?t=token_passed_by_cookie", $data, $headers); |
$r = do_req($test_url . "/op/logout?t=token_passed_by_cookie", $data, $headers); |
108 |
113 |
if (stristr($r['body'], "You are now logged out")) { |
if (stristr($r['body'], "You are now logged out")) { |
109 |
|
file_put_contents("http_csrf.log", print_r($r, TRUE)); |
|
110 |
|
rg_log_ml("No error on logout with token passed by cookie?!"); |
|
|
114 |
|
rg_log_ml(print_r($r, TRUE)); |
|
115 |
|
rg_log("No error on logout with token passed by cookie?! See above."); |
111 |
116 |
exit(1); |
exit(1); |
112 |
117 |
} |
} |
113 |
118 |
|
|
114 |
119 |
|
|
115 |
120 |
rg_log("Testing logout CSRF (good token)..."); |
rg_log("Testing logout CSRF (good token)..."); |
116 |
121 |
$url = $test_url . "/op/logout?t=good_token&token=" . $good_logout_token; |
$url = $test_url . "/op/logout?t=good_token&token=" . $good_logout_token; |
|
122 |
|
$data['token'] = $good_token; |
117 |
123 |
$r = do_req($url, $data, $headers); |
$r = do_req($url, $data, $headers); |
118 |
124 |
if (!stristr($r['body'], "You are now logged out")) { |
if (!stristr($r['body'], "You are now logged out")) { |
119 |
|
file_put_contents("http_csrf.log", $url . "\n" . print_r($r, TRUE)); |
|
120 |
|
rg_log_ml("Seems I cannot logout with a good token!"); |
|
|
125 |
|
rg_log_ml(print_r($r, TRUE)); |
|
126 |
|
rg_log("Seems I cannot logout with a good token! See above."); |
121 |
127 |
exit(1); |
exit(1); |
122 |
128 |
} |
} |
123 |
129 |
|
|
124 |
|
rg_log("Done!"); |
|
|
130 |
|
rg_log("OK!"); |
125 |
131 |
?> |
?> |
File tests/http_login.php changed (mode: 100644) (index d97b155..f90d0dc) |
... |
... |
$INC = dirname(__FILE__) . "/../inc"; |
6 |
6 |
require_once(dirname(__FILE__) . "/config.php"); |
require_once(dirname(__FILE__) . "/config.php"); |
7 |
7 |
require_once($INC . "/init.inc.php"); |
require_once($INC . "/init.inc.php"); |
8 |
8 |
require_once($INC . "/util.inc.php"); |
require_once($INC . "/util.inc.php"); |
|
9 |
|
require_once("helpers.inc.php"); |
9 |
10 |
require_once("http.inc.php"); |
require_once("http.inc.php"); |
10 |
11 |
|
|
11 |
12 |
rg_log_set_file("http_login.log"); |
rg_log_set_file("http_login.log"); |
12 |
13 |
|
|
|
14 |
|
$rg_sql = "host=localhost user=rocketgit dbname=rocketgit connect_timeout=10"; |
13 |
15 |
$rg_no_db = TRUE; |
$rg_no_db = TRUE; |
14 |
16 |
require_once("common.php"); |
require_once("common.php"); |
15 |
17 |
|
|
|
18 |
|
$_testns = 'http_login'; |
|
19 |
|
$rg_cache_enable = TRUE; |
|
20 |
|
|
|
21 |
|
rg_test_create_user($db, $rg_ui); |
|
22 |
|
|
16 |
23 |
rg_log("Test login operation"); |
rg_log("Test login operation"); |
17 |
24 |
// First we need to load the form so we can get the token |
// First we need to load the form so we can get the token |
18 |
25 |
// We provide an old cookie to test if we generate a new pre-login one |
// We provide an old cookie to test if we generate a new pre-login one |
|
... |
... |
$data = array(); |
20 |
27 |
$headers = array("Cookie: sid=d978671c2cd12fba05be218bb1653c1ce7bfb947"); |
$headers = array("Cookie: sid=d978671c2cd12fba05be218bb1653c1ce7bfb947"); |
21 |
28 |
$r = do_req($test_url . "/op/login", $data, $headers); |
$r = do_req($test_url . "/op/login", $data, $headers); |
22 |
29 |
if ($r === FALSE) { |
if ($r === FALSE) { |
23 |
|
echo "Cannot load login form.\n"; |
|
|
30 |
|
rg_log("Cannot load login form."); |
24 |
31 |
exit(1); |
exit(1); |
25 |
32 |
} |
} |
26 |
33 |
$good_sid = $r['sid']; |
$good_sid = $r['sid']; |
|
... |
... |
$data = array(); |
38 |
45 |
$headers = array(); |
$headers = array(); |
39 |
46 |
$r = do_req($test_url . "/op/login", $data, $headers); |
$r = do_req($test_url . "/op/login", $data, $headers); |
40 |
47 |
if ($r === FALSE) { |
if ($r === FALSE) { |
41 |
|
echo "Cannot load login form.\n"; |
|
|
48 |
|
rg_log("Cannot load login form."); |
42 |
49 |
exit(1); |
exit(1); |
43 |
50 |
} |
} |
44 |
51 |
//rg_log_ml("After loading attacker login form, r: " . print_r($r, TRUE)); |
//rg_log_ml("After loading attacker login form, r: " . print_r($r, TRUE)); |
|
... |
... |
rg_log("Now we can attack, we use attacker token but user cookie..."); |
50 |
57 |
$data = array( |
$data = array( |
51 |
58 |
"doit" => 1, |
"doit" => 1, |
52 |
59 |
"token" => $bad_token, |
"token" => $bad_token, |
53 |
|
"user" => "catab", |
|
54 |
|
"pass" => "aaaa", |
|
|
60 |
|
"user" => $rg_ui['username'], |
|
61 |
|
"pass" => $rg_ui['pass'], |
55 |
62 |
"lock_ip" => 1 |
"lock_ip" => 1 |
56 |
63 |
); |
); |
57 |
64 |
$headers = array("Cookie: sid=" . $good_sid); |
$headers = array("Cookie: sid=" . $good_sid); |
58 |
|
$r = do_req($test_url . "/op/login", $data, $headers); |
|
|
65 |
|
$r = do_req($test_url . "/op/login?t=bad_token_good_sid", $data, $headers); |
59 |
66 |
if ($r === FALSE) { |
if ($r === FALSE) { |
60 |
|
rg_log_ml("Cannot do the request: " . print_r($r, TRUE)); |
|
|
67 |
|
rg_log_ml(print_r($r, TRUE)); |
|
68 |
|
rg_log_ml("Cannot do the request. Check above."); |
61 |
69 |
exit(1); |
exit(1); |
62 |
70 |
} |
} |
63 |
|
file_put_contents("http_login_attack.log", print_r($r, TRUE)); |
|
64 |
71 |
if (!strstr($r['body'], "invalid token")) { |
if (!strstr($r['body'], "invalid token")) { |
65 |
|
rg_log("We sould get an invalid token error message. Check http_login_attack.log!"); |
|
|
72 |
|
rg_log_ml(print_r($r, TRUE)); |
|
73 |
|
rg_log("We sould get an invalid token error message. Check above!"); |
66 |
74 |
exit(1); |
exit(1); |
67 |
75 |
} |
} |
68 |
76 |
|
|
|
... |
... |
rg_log("Do the real login post request"); |
70 |
78 |
$data = array( |
$data = array( |
71 |
79 |
"doit" => 1, |
"doit" => 1, |
72 |
80 |
"token" => $good_token, |
"token" => $good_token, |
73 |
|
"user" => "catab", |
|
74 |
|
"pass" => "aaaa", |
|
|
81 |
|
"user" => $rg_ui['username'], |
|
82 |
|
"pass" => $rg_ui['pass'], |
75 |
83 |
"lock_ip" => 1 |
"lock_ip" => 1 |
76 |
84 |
); |
); |
77 |
85 |
$headers = array("Cookie: sid=" . $good_sid); |
$headers = array("Cookie: sid=" . $good_sid); |
78 |
|
$r = do_req($test_url . "/op/login", $data, $headers); |
|
|
86 |
|
$r = do_req($test_url . "/op/login?t=good_sid_good_token", $data, $headers); |
79 |
87 |
if ($r === FALSE) { |
if ($r === FALSE) { |
80 |
88 |
rg_log_ml("Cannot login: " . print_r($r, TRUE)); |
rg_log_ml("Cannot login: " . print_r($r, TRUE)); |
81 |
89 |
exit(1); |
exit(1); |
82 |
90 |
} |
} |
83 |
|
file_put_contents("http_login_good.log", print_r($r, TRUE)); |
|
84 |
91 |
if (strstr($r['body'], "invalid user or pass")) { |
if (strstr($r['body'], "invalid user or pass")) { |
85 |
|
rg_log("Login invalid. Check http_login_good.log!"); |
|
|
92 |
|
rg_log_ml(print_r($r, TRUE)); |
|
93 |
|
rg_log("Login invalid. Check above!"); |
86 |
94 |
exit(1); |
exit(1); |
87 |
95 |
} |
} |
88 |
96 |
|
|
89 |
|
|
|
90 |
97 |
rg_log("Check what happens if we are logged in and want to login again"); |
rg_log("Check what happens if we are logged in and want to login again"); |
91 |
|
$r = test_login($test_url, $good_sid); |
|
|
98 |
|
$r = test_login($test_url, $rg_ui, $good_sid); |
92 |
99 |
if ($r === FALSE) { |
if ($r === FALSE) { |
93 |
|
rg_log("Seems we cannot login again if we are already login!"); |
|
|
100 |
|
rg_log_ml(print_r($r, TRUE)); |
|
101 |
|
rg_log("Seems we cannot login again if we are already logged in!"); |
94 |
102 |
exit(1); |
exit(1); |
95 |
103 |
} |
} |
96 |
104 |
|
|
97 |
105 |
|
|
98 |
|
rg_log("Done!"); |
|
|
106 |
|
rg_log("OK!"); |
99 |
107 |
?> |
?> |
File tests/http_settings.php changed (mode: 100644) (index 4837ef5..1238817) |
... |
... |
$INC = dirname(__FILE__) . "/../inc"; |
8 |
8 |
require_once(dirname(__FILE__) . "/config.php"); |
require_once(dirname(__FILE__) . "/config.php"); |
9 |
9 |
require_once($INC . "/init.inc.php"); |
require_once($INC . "/init.inc.php"); |
10 |
10 |
require_once($INC . "/util.inc.php"); |
require_once($INC . "/util.inc.php"); |
|
11 |
|
require_once("helpers.inc.php"); |
11 |
12 |
require_once("http.inc.php"); |
require_once("http.inc.php"); |
12 |
13 |
|
|
13 |
14 |
rg_log_set_file("http_settings.log"); |
rg_log_set_file("http_settings.log"); |
|
... |
... |
$rg_sql = "host=localhost user=rocketgit dbname=rocketgit connect_timeout=10"; |
16 |
17 |
$rg_no_db = TRUE; |
$rg_no_db = TRUE; |
17 |
18 |
require_once("common.php"); |
require_once("common.php"); |
18 |
19 |
|
|
|
20 |
|
$_testns = 'http_settings'; |
19 |
21 |
$rg_cache_enable = TRUE; |
$rg_cache_enable = TRUE; |
20 |
22 |
|
|
21 |
23 |
$now = time(); |
$now = time(); |
|
... |
... |
if ($r !== FALSE) { |
36 |
38 |
|
|
37 |
39 |
test_restore($db); |
test_restore($db); |
38 |
40 |
|
|
39 |
|
$r = test_login($test_url, $good_sid); |
|
|
41 |
|
rg_test_create_user($db, $rg_ui); |
|
42 |
|
$r = test_login($test_url, $rg_ui, $good_sid); |
40 |
43 |
if ($r === FALSE) { |
if ($r === FALSE) { |
41 |
44 |
rg_log("Cannot login!"); |
rg_log("Cannot login!"); |
42 |
45 |
exit(1); |
exit(1); |
|
... |
... |
rg_log("Posting change pass form"); |
57 |
60 |
$data = array( |
$data = array( |
58 |
61 |
"doit" => 1, |
"doit" => 1, |
59 |
62 |
"token" => $good_token, |
"token" => $good_token, |
60 |
|
"old_pass" => "aaaa", |
|
|
63 |
|
"old_pass" => $rg_ui['pass'], |
61 |
64 |
"pass1" => "bbbb", |
"pass1" => "bbbb", |
62 |
65 |
"pass2" => "bbbb" |
"pass2" => "bbbb" |
63 |
66 |
); |
); |
|
... |
... |
if (!strstr($r['body'], "Password was updated with success")) { |
71 |
74 |
|
|
72 |
75 |
|
|
73 |
76 |
rg_log("Now, try to login with the old password"); |
rg_log("Now, try to login with the old password"); |
74 |
|
$r2 = test_login($test_url, $junk); |
|
|
77 |
|
$r2 = test_login($test_url, $rg_ui, $junk); |
75 |
78 |
if ($r2 !== FALSE) { |
if ($r2 !== FALSE) { |
76 |
79 |
rg_log_ml("Seems we were able to login with the old password!"); |
rg_log_ml("Seems we were able to login with the old password!"); |
77 |
80 |
exit(1); |
exit(1); |
|
... |
... |
$data = array( |
92 |
95 |
"doit" => 1, |
"doit" => 1, |
93 |
96 |
"token" => $good_token, |
"token" => $good_token, |
94 |
97 |
"old_pass" => "bbbb", |
"old_pass" => "bbbb", |
95 |
|
"pass1" => "aaaa", |
|
96 |
|
"pass2" => "aaaa" |
|
|
98 |
|
"pass1" => $rg_ui['pass'], |
|
99 |
|
"pass2" => $rg_ui['pass'] |
97 |
100 |
); |
); |
98 |
101 |
$headers = array("Cookie: sid=" . $good_sid); |
$headers = array("Cookie: sid=" . $good_sid); |
99 |
102 |
$r = do_req($test_url . "/op/settings/change_pass?t=change_back_the_password", $data, $headers); |
$r = do_req($test_url . "/op/settings/change_pass?t=change_back_the_password", $data, $headers); |
|
... |
... |
if ($r === FALSE) { |
116 |
119 |
} |
} |
117 |
120 |
|
|
118 |
121 |
rg_log("Posting edit info form"); |
rg_log("Posting edit info form"); |
119 |
|
$realname = "Catalin(ux) M. BOIE ($now)<xss>"; |
|
120 |
122 |
$session_time = intval($now / 393956); |
$session_time = intval($now / 393956); |
121 |
123 |
$data = array( |
$data = array( |
122 |
124 |
"doit" => 1, |
"doit" => 1, |
123 |
125 |
"token" => $r['token'], |
"token" => $r['token'], |
124 |
126 |
"uid" => 4, |
"uid" => 4, |
125 |
|
"username" => "catab<xss>", |
|
126 |
|
"realname" => $realname, |
|
|
127 |
|
"username" => $rg_ui['username'], |
|
128 |
|
"realname" => $rg_ui['realname'], |
127 |
129 |
"plan_id" => 5, |
"plan_id" => 5, |
128 |
130 |
"session_time" => $session_time |
"session_time" => $session_time |
129 |
131 |
); |
); |
|
... |
... |
if (!strstr($r['body'], "Information was updated with success")) { |
136 |
138 |
} |
} |
137 |
139 |
|
|
138 |
140 |
rg_log("Verify against database"); |
rg_log("Verify against database"); |
139 |
|
$sql = "SELECT * FROM users WHERE username = 'catab<xss>'"; |
|
|
141 |
|
$sql = "SELECT * FROM users WHERE username = '" . $rg_ui['username'] . "'"; |
140 |
142 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
141 |
143 |
$row = rg_sql_fetch_array($res); |
$row = rg_sql_fetch_array($res); |
142 |
144 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
143 |
|
if (strcmp($realname, $row['realname']) != 0) { |
|
|
145 |
|
if (strcmp($rg_ui['realname'], $row['realname']) != 0) { |
144 |
146 |
file_put_contents("http_settings_edit_info.log", $r['body']); |
file_put_contents("http_settings_edit_info.log", $r['body']); |
145 |
147 |
rg_log_ml("realname was not changed: " . print_r($row, TRUE)); |
rg_log_ml("realname was not changed: " . print_r($row, TRUE)); |
146 |
148 |
exit(1); |
exit(1); |
|
... |
... |
if ($r === FALSE) { |
167 |
169 |
exit(1); |
exit(1); |
168 |
170 |
} |
} |
169 |
171 |
rg_log("Posting keys form"); |
rg_log("Posting keys form"); |
170 |
|
$key = "ssh-dss YWFh comment<xss>"; |
|
|
172 |
|
$key = "ssh-dss YWFh comment<xss>" . $rg_ui['uid']; |
171 |
173 |
$data = array("add" => 1, "token" => $r['token'], "key" => $key); |
$data = array("add" => 1, "token" => $r['token'], "key" => $key); |
172 |
174 |
$headers = array("Cookie: sid=" . $good_sid); |
$headers = array("Cookie: sid=" . $good_sid); |
173 |
175 |
$r = do_req($test_url . "/op/settings/keys?t=post_key_form_add", $data, $headers); |
$r = do_req($test_url . "/op/settings/keys?t=post_key_form_add", $data, $headers); |
|
... |
... |
if ($r === FALSE) { |
176 |
178 |
rg_log_ml("Cannot upload key: " . print_r($r, TRUE)); |
rg_log_ml("Cannot upload key: " . print_r($r, TRUE)); |
177 |
179 |
exit(1); |
exit(1); |
178 |
180 |
} |
} |
179 |
|
$sql = "SELECT * FROM keys WHERE key = 'ssh-dss YWFh commentxss'"; |
|
|
181 |
|
$sql = "SELECT * FROM keys WHERE key = 'ssh-dss YWFh commentxss" . $rg_ui['uid'] . "'"; |
180 |
182 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
181 |
183 |
$rows = rg_sql_num_rows($res); |
$rows = rg_sql_num_rows($res); |
182 |
184 |
if ($rows > 0) |
if ($rows > 0) |
|
... |
... |
if ($r === FALSE) { |
198 |
200 |
exit(1); |
exit(1); |
199 |
201 |
} |
} |
200 |
202 |
rg_log("Posting delete keys form"); |
rg_log("Posting delete keys form"); |
201 |
|
$key = "ssh-dss YWFh comment<xss>"; |
|
202 |
203 |
$data = array("delete" => 1, "token" => $r['token'], "key_delete_ids[$key_id]" => "on"); |
$data = array("delete" => 1, "token" => $r['token'], "key_delete_ids[$key_id]" => "on"); |
203 |
204 |
$headers = array("Cookie: sid=" . $good_sid); |
$headers = array("Cookie: sid=" . $good_sid); |
204 |
205 |
$r = do_req($test_url . "/op/settings/keys?t=post_key_form_del", $data, $headers); |
$r = do_req($test_url . "/op/settings/keys?t=post_key_form_del", $data, $headers); |
|
... |
... |
if ($rows == 1) { |
216 |
217 |
exit(1); |
exit(1); |
217 |
218 |
} |
} |
218 |
219 |
|
|
219 |
|
rg_log("Done!"); |
|
|
220 |
|
rg_log("OK!"); |
220 |
221 |
?> |
?> |
File tests/keys.php changed (mode: 100644) (index 903c351..5f236c1) |
... |
... |
rg_sql_free_result($res); |
31 |
31 |
$key = "aaa 'bbb' first_key"; |
$key = "aaa 'bbb' first_key"; |
32 |
32 |
$key_id1 = rg_keys_add($db, $rg_ui, $key); |
$key_id1 = rg_keys_add($db, $rg_ui, $key); |
33 |
33 |
if ($key_id1 === FALSE) { |
if ($key_id1 === FALSE) { |
34 |
|
echo "Cannot add key 1 (" . rg_keys_error() . ")!\n"; |
|
|
34 |
|
rg_log("Cannot add key 1 (" . rg_keys_error() . ")!"); |
35 |
35 |
exit(1); |
exit(1); |
36 |
36 |
} |
} |
37 |
37 |
|
|
|
... |
... |
$rg_ui['uid'] = 2; |
40 |
40 |
$key = "aaa 'bbb' second_key"; |
$key = "aaa 'bbb' second_key"; |
41 |
41 |
$key_id2 = rg_keys_add($db, $rg_ui, $key); |
$key_id2 = rg_keys_add($db, $rg_ui, $key); |
42 |
42 |
if ($key_id2 === FALSE) { |
if ($key_id2 === FALSE) { |
43 |
|
echo "Cannot add key 2 (" . rg_keys_error() . ")!\n"; |
|
|
43 |
|
rg_log("Cannot add key 2 (" . rg_keys_error() . ")!"); |
44 |
44 |
exit(1); |
exit(1); |
45 |
45 |
} |
} |
46 |
46 |
|
|
|
... |
... |
$rg_scripts = "/a"; |
50 |
50 |
$rg_ssh_paras = "ssh1,ssh2,ssh3"; |
$rg_ssh_paras = "ssh1,ssh2,ssh3"; |
51 |
51 |
$r = rg_keys_regen($db); |
$r = rg_keys_regen($db); |
52 |
52 |
if ($r === FALSE) { |
if ($r === FALSE) { |
53 |
|
echo "Cannot regenerate keys (" . rg_keys_error() . ")!\n"; |
|
|
53 |
|
rg_log("Cannot regenerate keys (" . rg_keys_error() . ")!"); |
54 |
54 |
exit(1); |
exit(1); |
55 |
55 |
} |
} |
56 |
56 |
$c = @file_get_contents("afile.txt"); |
$c = @file_get_contents("afile.txt"); |
57 |
57 |
if ($c === FALSE) { |
if ($c === FALSE) { |
58 |
|
echo "Cannot regenerate file (afile.txt not found)!\n"; |
|
|
58 |
|
rg_log("Cannot regenerate file (afile.txt not found)!"); |
59 |
59 |
exit(1); |
exit(1); |
60 |
60 |
} |
} |
61 |
61 |
$e = "command=\"" |
$e = "command=\"" |
|
... |
... |
$e = "command=\"" |
65 |
65 |
. $rg_scripts . "/scripts/remote.sh 2 $key_id2\"," |
. $rg_scripts . "/scripts/remote.sh 2 $key_id2\"," |
66 |
66 |
. $rg_ssh_paras . " aaa 'bbb' second_key\n"; |
. $rg_ssh_paras . " aaa 'bbb' second_key\n"; |
67 |
67 |
if (strcmp($c, $e) != 0) { |
if (strcmp($c, $e) != 0) { |
68 |
|
echo "Generated file does not seems OK!\n"; |
|
69 |
|
echo "e: $e\n"; |
|
70 |
|
echo "c: $c\n"; |
|
|
68 |
|
rg_log("Generated file does not seems OK!"); |
|
69 |
|
rg_log("e: $e"); |
|
70 |
|
rg_log("c: $c"); |
71 |
71 |
exit(1); |
exit(1); |
72 |
72 |
} |
} |
73 |
73 |
|
|
|
... |
... |
$rg_ui['uid'] = 1; |
79 |
79 |
$list = array($key_id1 => "junk"); |
$list = array($key_id1 => "junk"); |
80 |
80 |
$r = rg_keys_remove($db, $rg_ui, $list); |
$r = rg_keys_remove($db, $rg_ui, $list); |
81 |
81 |
if ($r === FALSE) { |
if ($r === FALSE) { |
82 |
|
echo "Cannot remove key (" . rg_keys_error() . ")!\n"; |
|
|
82 |
|
rg_log("Cannot remove key (" . rg_keys_error() . ")!"); |
83 |
83 |
exit(1); |
exit(1); |
84 |
84 |
} |
} |
85 |
85 |
|
|
|
... |
... |
$rg_ui['uid'] = 10; |
91 |
91 |
$key = "aaa 'bbb' first_key"; |
$key = "aaa 'bbb' first_key"; |
92 |
92 |
$key_id1 = rg_keys_add($db, $rg_ui, $key); |
$key_id1 = rg_keys_add($db, $rg_ui, $key); |
93 |
93 |
if ($key_id1 === FALSE) { |
if ($key_id1 === FALSE) { |
94 |
|
echo "Cannot add key 1 (" . rg_keys_error() . ")!\n"; |
|
|
94 |
|
rg_log("Cannot add key 1 (" . rg_keys_error() . ")!"); |
95 |
95 |
exit(1); |
exit(1); |
96 |
96 |
} |
} |
97 |
97 |
// insert a key - must fail because overlimit |
// insert a key - must fail because overlimit |
98 |
98 |
$key = "aaa 'bbb' second_key"; |
$key = "aaa 'bbb' second_key"; |
99 |
99 |
$key_id2 = rg_keys_add($db, $rg_ui, $key); |
$key_id2 = rg_keys_add($db, $rg_ui, $key); |
100 |
100 |
if ($key_id2 !== FALSE) { |
if ($key_id2 !== FALSE) { |
101 |
|
echo "Seems we can add more keys than allowed!\n"; |
|
|
101 |
|
rg_log("Seems we can add more keys than allowed!"); |
102 |
102 |
exit(1); |
exit(1); |
103 |
103 |
} |
} |
104 |
104 |
|
|
|
... |
... |
if ($key_id2 !== FALSE) { |
106 |
106 |
|
|
107 |
107 |
rg_sql_close($db); |
rg_sql_close($db); |
108 |
108 |
|
|
109 |
|
echo "keys: OK\n"; |
|
|
109 |
|
rg_log("OK"); |
110 |
110 |
?> |
?> |
File tests/repo.php changed (mode: 100644) (index 82c3003..bbc8e43) |
... |
... |
require_once($INC . "/struct.inc.php"); |
13 |
13 |
require_once($INC . "/fixes.inc.php"); |
require_once($INC . "/fixes.inc.php"); |
14 |
14 |
require_once("helpers.inc.php"); |
require_once("helpers.inc.php"); |
15 |
15 |
|
|
|
16 |
|
$old_allow = $rg_repo_allow; |
|
17 |
|
|
16 |
18 |
rg_log_set_file("repo.log"); |
rg_log_set_file("repo.log"); |
17 |
19 |
|
|
18 |
20 |
rg_log("Starting"); |
rg_log("Starting"); |
|
... |
... |
if ($res === FALSE) { |
104 |
106 |
} |
} |
105 |
107 |
$rg_ui = rg_user_info($db, $uid, "", ""); |
$rg_ui = rg_user_info($db, $uid, "", ""); |
106 |
108 |
if ($rg_ui['exists'] != 1) { |
if ($rg_ui['exists'] != 1) { |
107 |
|
echo "Cannot load user info!\n"; |
|
|
109 |
|
rg_log("Cannot load user info!"); |
108 |
110 |
exit(1); |
exit(1); |
109 |
111 |
} |
} |
110 |
112 |
|
|
|
... |
... |
if ($res === FALSE) { |
121 |
123 |
exit(1); |
exit(1); |
122 |
124 |
} |
} |
123 |
125 |
|
|
|
126 |
|
$rg_repo_allow = $old_allow; |
|
127 |
|
$rg_repo_max_len = 50; |
|
128 |
|
|
124 |
129 |
rg_test_create_repo($db, $rg_ui, $new); |
rg_test_create_repo($db, $rg_ui, $new); |
125 |
130 |
$repo_id = $new['repo_id']; |
$repo_id = $new['repo_id']; |
126 |
131 |
|
|
|
... |
... |
if ($ri['exists'] != 1) { |
134 |
139 |
rg_log("Clean repos folder..."); |
rg_log("Clean repos folder..."); |
135 |
140 |
$r = rg_exec("rm -rf base/*"); |
$r = rg_exec("rm -rf base/*"); |
136 |
141 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
137 |
|
echo "Failed to clean base folder.\n"; |
|
|
142 |
|
rg_log("Failed to clean base folder."); |
138 |
143 |
exit(1); |
exit(1); |
139 |
144 |
} |
} |
140 |
145 |
|
|
141 |
146 |
rg_log("Creating git folder."); |
rg_log("Creating git folder."); |
142 |
147 |
$e = array(); |
$e = array(); |
143 |
148 |
$e = rg_array_merge($e, "ri", $ri); |
$e = rg_array_merge($e, "ri", $ri); |
144 |
|
$e['ui.uid'] = $rg_ui['uid']; |
|
|
149 |
|
$e['ui::uid'] = $rg_ui['uid']; |
145 |
150 |
$r = rg_repo_event_storage_create($db, $e); |
$r = rg_repo_event_storage_create($db, $e); |
146 |
151 |
if ($r === FALSE) { |
if ($r === FALSE) { |
147 |
|
echo "Cannot create storage dir (" . rg_repo_error() . ")!\n"; |
|
|
152 |
|
rg_log("Cannot create storage dir (" . rg_repo_error() . ")!"); |
148 |
153 |
exit(1); |
exit(1); |
149 |
154 |
} |
} |
150 |
155 |
|
|
|
... |
... |
$_path = rg_repo_path_by_id($uid, $repo_id); |
227 |
232 |
if (!file_exists($_path)) { |
if (!file_exists($_path)) { |
228 |
233 |
$r = @mkdir($_path, 0755, TRUE); |
$r = @mkdir($_path, 0755, TRUE); |
229 |
234 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
230 |
|
echo "Cannot create fake dir ($_path)!\n"; |
|
|
235 |
|
rg_log("Cannot create fake dir ($_path)!"); |
231 |
236 |
exit(1); |
exit(1); |
232 |
237 |
} |
} |
233 |
238 |
} |
} |
|
... |
... |
$_path = dirname(rg_repo_path_by_name($uid, $repo_name)); |
235 |
240 |
if (!file_exists($_path)) { |
if (!file_exists($_path)) { |
236 |
241 |
$r = @mkdir($_path, 0755, TRUE); |
$r = @mkdir($_path, 0755, TRUE); |
237 |
242 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
238 |
|
echo "Cannot create fake dir 2 ($_path)!\n"; |
|
|
243 |
|
rg_log("Cannot create fake dir 2 ($_path)!"); |
239 |
244 |
exit(1); |
exit(1); |
240 |
245 |
} |
} |
241 |
246 |
} |
} |
|
... |
... |
$new['rights'] = "F"; |
245 |
250 |
$new['name'] = $repo_name . "b"; |
$new['name'] = $repo_name . "b"; |
246 |
251 |
$r = rg_repo_edit($db, $rg_ui, $new); |
$r = rg_repo_edit($db, $rg_ui, $new); |
247 |
252 |
if ($r === FALSE) { |
if ($r === FALSE) { |
248 |
|
echo "Cannot rename repository (" . rg_repo_error() . ")!\n"; |
|
|
253 |
|
rg_log("Cannot rename repository (" . rg_repo_error() . ")!"); |
249 |
254 |
exit(1); |
exit(1); |
250 |
255 |
} |
} |
251 |
256 |
// Do a second rename |
// Do a second rename |
252 |
257 |
$new['name'] = $repo_name . "c"; |
$new['name'] = $repo_name . "c"; |
253 |
258 |
$r = rg_repo_edit($db, $rg_ui, $new); |
$r = rg_repo_edit($db, $rg_ui, $new); |
254 |
259 |
if ($r === FALSE) { |
if ($r === FALSE) { |
255 |
|
echo "Cannot rename repository (" . rg_repo_error() . ")!\n"; |
|
|
260 |
|
rg_log("Cannot rename repository (" . rg_repo_error() . ")!"); |
256 |
261 |
exit(1); |
exit(1); |
257 |
262 |
} |
} |
258 |
263 |
|
|
|
... |
... |
if ($r === FALSE) { |
260 |
265 |
$size = rg_repo_size("size", TRUE); |
$size = rg_repo_size("size", TRUE); |
261 |
266 |
$e = 13; |
$e = 13; |
262 |
267 |
if ($size != $e) { |
if ($size != $e) { |
263 |
|
echo "Dir 'size' has an unexpected size ($e != $r)!\n"; |
|
|
268 |
|
rg_log("Dir 'size' has an unexpected size ($e != $r)!"); |
264 |
269 |
exit(1); |
exit(1); |
265 |
270 |
} |
} |
266 |
271 |
|
|
267 |
272 |
rg_sql_close($db); |
rg_sql_close($db); |
268 |
273 |
|
|
269 |
|
echo "repo: OK!\n"; |
|
|
274 |
|
rg_log("OK!"); |
270 |
275 |
?> |
?> |
File tests/rights.php changed (mode: 100644) (index 349438c..87dc084) |
... |
... |
rg_log("test if combine works correctly (1)"); |
25 |
25 |
$a = "AF"; $b = "AD"; $e = "AFD"; |
$a = "AF"; $b = "AD"; $e = "AFD"; |
26 |
26 |
$r = rg_rights_combine($a, $b); |
$r = rg_rights_combine($a, $b); |
27 |
27 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
28 |
|
echo "Combine rights error1 ([$r] vs [$e])\n"; |
|
|
28 |
|
rg_log("Combine rights error1 ([$r] vs [$e])"); |
29 |
29 |
exit(1); |
exit(1); |
30 |
30 |
} |
} |
31 |
31 |
|
|
|
... |
... |
rg_log("test if combine works correctly (2)"); |
33 |
33 |
$a = ""; $b = ""; $e = ""; |
$a = ""; $b = ""; $e = ""; |
34 |
34 |
$r = rg_rights_combine($a, $b); |
$r = rg_rights_combine($a, $b); |
35 |
35 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
36 |
|
echo "Combine rights error1 ([$r] vs [$e])\n"; |
|
|
36 |
|
rg_log("Combine rights error1 ([$r] vs [$e])"); |
37 |
37 |
exit(1); |
exit(1); |
38 |
38 |
} |
} |
39 |
39 |
|
|
|
... |
... |
rg_log("test if combine works correctly (3)"); |
41 |
41 |
$a = "AXUJUNFUUFU"; $b = ""; $e = $a; |
$a = "AXUJUNFUUFU"; $b = ""; $e = $a; |
42 |
42 |
$r = rg_rights_combine($a, $b); |
$r = rg_rights_combine($a, $b); |
43 |
43 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
44 |
|
echo "Combine rights error1 ([$r] vs [$e])\n"; |
|
|
44 |
|
rg_log("Combine rights error1 ([$r] vs [$e])"); |
45 |
45 |
exit(1); |
exit(1); |
46 |
46 |
} |
} |
47 |
47 |
|
|
|
... |
... |
rg_log("testing mask..."); |
49 |
49 |
$a = "ABCDE"; $mask = "AEZ"; $e = "AE"; |
$a = "ABCDE"; $mask = "AEZ"; $e = "AE"; |
50 |
50 |
$r = rg_rights_mask($a, $mask); |
$r = rg_rights_mask($a, $mask); |
51 |
51 |
if (strcmp($e, $e) != 0) { |
if (strcmp($e, $e) != 0) { |
52 |
|
echo "mask is not working right [$r] != [$e]!\n"; |
|
|
52 |
|
rg_log("mask is not working right [$r] != [$e]!"); |
53 |
53 |
exit(1); |
exit(1); |
54 |
54 |
} |
} |
55 |
55 |
|
|
|
... |
... |
$ip = "1.2.3.4"; |
60 |
60 |
$misc = FALSE; |
$misc = FALSE; |
61 |
61 |
$r = rg_rights_test($rights, $needed_rights, $ip, $misc); |
$r = rg_rights_test($rights, $needed_rights, $ip, $misc); |
62 |
62 |
if ($r !== FALSE) { |
if ($r !== FALSE) { |
63 |
|
echo "allow is not working right!\n"; |
|
|
63 |
|
rg_log("allow is not working right!"); |
64 |
64 |
exit(1); |
exit(1); |
65 |
65 |
} |
} |
66 |
66 |
|
|
|
... |
... |
$a['prio'] = 13; |
77 |
77 |
$a['description'] = "desc1"; |
$a['description'] = "desc1"; |
78 |
78 |
$r = rg_rights_set($db, "type1", $a); |
$r = rg_rights_set($db, "type1", $a); |
79 |
79 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
80 |
|
echo "Seems I cannot set rights 1 (" . rg_rights_error() . ")\n"; |
|
|
80 |
|
rg_log("Seems I cannot set rights 1 (" . rg_rights_error() . ")"); |
81 |
81 |
exit(1); |
exit(1); |
82 |
82 |
} |
} |
83 |
83 |
$a['rights'] = "d"; $a['misc'] = "misc2"; $a['prio'] = 14; |
$a['rights'] = "d"; $a['misc'] = "misc2"; $a['prio'] = 14; |
84 |
84 |
$r = rg_rights_set($db, "type1", $a); |
$r = rg_rights_set($db, "type1", $a); |
85 |
85 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
86 |
|
echo "Seems I cannot set rights 2 (" . rg_rights_error() . ")\n"; |
|
|
86 |
|
rg_log("Seems I cannot set rights 2 (" . rg_rights_error() . ")"); |
87 |
87 |
exit(1); |
exit(1); |
88 |
88 |
} |
} |
89 |
89 |
$a['rights'] = "E"; $a['misc'] = "misc3"; $a['prio'] = 14; |
$a['rights'] = "E"; $a['misc'] = "misc3"; $a['prio'] = 14; |
90 |
90 |
$r = rg_rights_set($db, "type2", $a); |
$r = rg_rights_set($db, "type2", $a); |
91 |
91 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
92 |
|
echo "Seems I cannot set rights 2 (" . rg_rights_error() . ")\n"; |
|
|
92 |
|
rg_log("Seems I cannot set rights 2 (" . rg_rights_error() . ")"); |
93 |
93 |
exit(1); |
exit(1); |
94 |
94 |
} |
} |
95 |
95 |
|
|
|
... |
... |
rg_log("Testing rg_rights_get..."); |
97 |
97 |
$right_id = 0; |
$right_id = 0; |
98 |
98 |
$r = rg_rights_get($db, $a['obj_id'], "type1", $a['who'], $a['uid'], $right_id); |
$r = rg_rights_get($db, $a['obj_id'], "type1", $a['who'], $a['uid'], $right_id); |
99 |
99 |
if (($r['ok'] !== 1) || (strcmp($r['list'][1]['rights'], "d") != 0)) { |
if (($r['ok'] !== 1) || (strcmp($r['list'][1]['rights'], "d") != 0)) { |
100 |
|
echo "Seems I cannot get rights (" . rg_rights_error() . ")\n"; |
|
|
100 |
|
rg_log("Seems I cannot get rights (" . rg_rights_error() . ")"); |
101 |
101 |
print_r($r); |
print_r($r); |
102 |
102 |
exit (1); |
exit (1); |
103 |
103 |
} |
} |
104 |
104 |
// 'get' again, to see if cache works |
// 'get' again, to see if cache works |
105 |
105 |
$r = rg_rights_get($db, $a['obj_id'], "type1", $a['who'], $a['uid'], $right_id); |
$r = rg_rights_get($db, $a['obj_id'], "type1", $a['who'], $a['uid'], $right_id); |
106 |
106 |
if (($r['ok'] !== 1) || (strcmp($r['list'][1]['rights'], "d") != 0)) { |
if (($r['ok'] !== 1) || (strcmp($r['list'][1]['rights'], "d") != 0)) { |
107 |
|
echo "Seems I cannot get rights (" . rg_rights_error() . ")\n"; |
|
|
107 |
|
rg_log("Seems I cannot get rights (" . rg_rights_error() . ")"); |
108 |
108 |
print_r($r); |
print_r($r); |
109 |
109 |
exit (1); |
exit (1); |
110 |
110 |
} |
} |
|
... |
... |
foreach ($r['list'] as $junk => $i) |
115 |
115 |
$list[] = $i['right_id']; |
$list[] = $i['right_id']; |
116 |
116 |
$r = rg_rights_delete_list($db, "type1", $a['obj_id'], $list); |
$r = rg_rights_delete_list($db, "type1", $a['obj_id'], $list); |
117 |
117 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
118 |
|
echo "We should be able to delete rights!\n"; |
|
|
118 |
|
rg_log("We should be able to delete rights!"); |
119 |
119 |
exit(1); |
exit(1); |
120 |
120 |
} |
} |
121 |
121 |
$right_id = 0; |
$right_id = 0; |
122 |
122 |
$r = rg_rights_get($db, $a['obj_id'], "type1", $a['who'], $a['uid'], $right_id); |
$r = rg_rights_get($db, $a['obj_id'], "type1", $a['who'], $a['uid'], $right_id); |
123 |
123 |
if (($r['ok'] !== 1) || (count($r['list']) > 0)) { |
if (($r['ok'] !== 1) || (count($r['list']) > 0)) { |
124 |
124 |
print_r($r); |
print_r($r); |
125 |
|
echo "We should not have anymore type1 objects, after a delete.\n"; |
|
|
125 |
|
rg_log("We should not have anymore type1 objects, after a delete."); |
126 |
126 |
exit (1); |
exit (1); |
127 |
127 |
} |
} |
128 |
128 |
|
|
|
... |
... |
$list = "1.2.3.4/24 10.0.0.0/8 fd00::/64" |
132 |
132 |
. " 2222::/24"; |
. " 2222::/24"; |
133 |
133 |
$r = rg_rights_test_ip($list, "1.2.3.5"); |
$r = rg_rights_test_ip($list, "1.2.3.5"); |
134 |
134 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
135 |
|
echo "ip test 1 failed\n"; |
|
|
135 |
|
rg_log("ip test 1 failed"); |
136 |
136 |
exit(1); |
exit(1); |
137 |
137 |
} |
} |
138 |
138 |
rg_log("Testing IP match part - test2"); |
rg_log("Testing IP match part - test2"); |
139 |
139 |
$r = rg_rights_test_ip($list, "10.2.3.4"); |
$r = rg_rights_test_ip($list, "10.2.3.4"); |
140 |
140 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
141 |
|
echo "ip test 2 failed\n"; |
|
|
141 |
|
rg_log("ip test 2 failed"); |
142 |
142 |
exit(1); |
exit(1); |
143 |
143 |
} |
} |
144 |
144 |
rg_log("Testing IP match part - test3"); |
rg_log("Testing IP match part - test3"); |
145 |
145 |
$r = rg_rights_test_ip($list, "fd00::3030:aaaa"); |
$r = rg_rights_test_ip($list, "fd00::3030:aaaa"); |
146 |
146 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
147 |
|
echo "ip test 3 failed\n"; |
|
|
147 |
|
rg_log("ip test 3 failed"); |
148 |
148 |
exit(1); |
exit(1); |
149 |
149 |
} |
} |
150 |
150 |
rg_log("Testing IP match part - test4a"); |
rg_log("Testing IP match part - test4a"); |
151 |
151 |
$r = rg_rights_test_ip($list, "1234:5678:aaaa:bbbb:cccc:dddd:eeee:44"); |
$r = rg_rights_test_ip($list, "1234:5678:aaaa:bbbb:cccc:dddd:eeee:44"); |
152 |
152 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
153 |
|
echo "ip test 4a failed\n"; |
|
|
153 |
|
rg_log("ip test 4a failed"); |
154 |
154 |
exit(1); |
exit(1); |
155 |
155 |
} |
} |
156 |
156 |
rg_log("Testing IP match part - test4b"); |
rg_log("Testing IP match part - test4b"); |
157 |
157 |
$r = rg_rights_test_ip($list, "1234:5678:aaaa:bbbb:cccc:dddd:eeee:3344"); |
$r = rg_rights_test_ip($list, "1234:5678:aaaa:bbbb:cccc:dddd:eeee:3344"); |
158 |
158 |
if ($r === TRUE) { |
if ($r === TRUE) { |
159 |
|
echo "ip test 4b failed\n"; |
|
|
159 |
|
rg_log("ip test 4b failed"); |
160 |
160 |
exit(1); |
exit(1); |
161 |
161 |
} |
} |
162 |
162 |
rg_log("Testing IP match part - test5"); |
rg_log("Testing IP match part - test5"); |
163 |
163 |
$r = rg_rights_test_ip($list, "2222::5533"); |
$r = rg_rights_test_ip($list, "2222::5533"); |
164 |
164 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
165 |
|
echo "ip test 5 failed\n"; |
|
|
165 |
|
rg_log("ip test 5 failed"); |
166 |
166 |
exit(1); |
exit(1); |
167 |
167 |
} |
} |
168 |
168 |
|
|
|
... |
... |
rg_log("Finish"); |
170 |
170 |
|
|
171 |
171 |
// TODO: test if a user can read other rights |
// TODO: test if a user can read other rights |
172 |
172 |
|
|
173 |
|
echo "rights: OK!\n"; |
|
|
173 |
|
rg_log("OK!"); |
174 |
174 |
?> |
?> |
File tests/sql.php changed (mode: 100644) (index 9f4169c..5c85652) |
... |
... |
rg_log_set_file("sql.log"); |
12 |
12 |
|
|
13 |
13 |
require_once("common.php"); |
require_once("common.php"); |
14 |
14 |
|
|
15 |
|
echo "db: drop 'test' table...\n"; |
|
|
15 |
|
rg_log("db: drop 'test' table..."); |
16 |
16 |
$sql = "DROP TABLE IF EXISTS test"; |
$sql = "DROP TABLE IF EXISTS test"; |
17 |
17 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
18 |
18 |
if ($res === FALSE) { |
if ($res === FALSE) { |
19 |
|
echo "Cannot create table 'test' (" . rg_sql_error() . ")!\n"; |
|
|
19 |
|
rg_log("Cannot create table 'test' (" . rg_sql_error() . ")!"); |
20 |
20 |
exit(1); |
exit(1); |
21 |
21 |
} |
} |
22 |
22 |
|
|
23 |
|
echo "db: test creation of a table...\n"; |
|
|
23 |
|
rg_log("db: test creation of a table..."); |
24 |
24 |
$sql = "CREATE TABLE test (id TEXT PRIMARY KEY" |
$sql = "CREATE TABLE test (id TEXT PRIMARY KEY" |
25 |
25 |
. ", f1 TEXT DEFAULT '', f2 TEXT DEFAULT '')"; |
. ", f1 TEXT DEFAULT '', f2 TEXT DEFAULT '')"; |
26 |
26 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
27 |
27 |
if ($res === FALSE) { |
if ($res === FALSE) { |
28 |
|
echo "Cannot create table 'test' (" . rg_sql_error() . ")!\n"; |
|
|
28 |
|
rg_log("Cannot create table 'test' (" . rg_sql_error() . ")!"); |
29 |
29 |
exit(1); |
exit(1); |
30 |
30 |
} |
} |
31 |
31 |
|
|
32 |
|
echo "db: test insert...\n"; |
|
|
32 |
|
rg_log("db: test insert..."); |
33 |
33 |
$sql = "INSERT INTO test (id) VALUES ('aaa')"; |
$sql = "INSERT INTO test (id) VALUES ('aaa')"; |
34 |
34 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
35 |
35 |
if ($res === FALSE) { |
if ($res === FALSE) { |
36 |
|
echo "Cannot insert!\n"; |
|
|
36 |
|
rg_log("Cannot insert!"); |
37 |
37 |
exit(1); |
exit(1); |
38 |
38 |
} |
} |
39 |
39 |
|
|
40 |
|
echo "db: test insert with the same key...\n"; |
|
|
40 |
|
rg_log("db: test insert with the same key..."); |
41 |
41 |
$sql = "INSERT INTO test (id) VALUES ('aaa')"; |
$sql = "INSERT INTO test (id) VALUES ('aaa')"; |
42 |
42 |
$res = @rg_sql_query($db, $sql); |
$res = @rg_sql_query($db, $sql); |
43 |
43 |
if ($res !== FALSE) { |
if ($res !== FALSE) { |
44 |
|
echo "I can do double insert, not good!\n"; |
|
|
44 |
|
rg_log("I can do double insert, not good!"); |
45 |
45 |
exit(1); |
exit(1); |
46 |
46 |
} |
} |
47 |
47 |
|
|
48 |
|
echo "db: test delete...\n"; |
|
|
48 |
|
rg_log("db: test delete..."); |
49 |
49 |
$sql = "DELETE FROM test WHERE id = 'aaa'"; |
$sql = "DELETE FROM test WHERE id = 'aaa'"; |
50 |
50 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
51 |
51 |
if ($res === FALSE) { |
if ($res === FALSE) { |
52 |
|
echo "Cannot delete!\n"; |
|
|
52 |
|
rg_log("Cannot delete!"); |
53 |
53 |
exit(1); |
exit(1); |
54 |
54 |
} |
} |
55 |
55 |
|
|
56 |
|
echo "db: test prepare with named values...\n"; |
|
|
56 |
|
rg_log("db: test prepare with named values..."); |
57 |
57 |
$sql = "INSERT INTO test(id, f1, f2) VALUES (@@id@@, @@f@@, @@f@@)"; |
$sql = "INSERT INTO test(id, f1, f2) VALUES (@@id@@, @@f@@, @@f@@)"; |
58 |
58 |
$params = array("id" => "myid", "f" => "value", "junk" => "aaa"); |
$params = array("id" => "myid", "f" => "value", "junk" => "aaa"); |
59 |
59 |
$res = rg_sql_query_params($db, $sql, $params); |
$res = rg_sql_query_params($db, $sql, $params); |
60 |
60 |
if ($res === FALSE) { |
if ($res === FALSE) { |
61 |
|
echo "Cannot insert into test using @@x@@!\n"; |
|
|
61 |
|
rg_log("Cannot insert into test using @@x@@!"); |
62 |
62 |
exit(1); |
exit(1); |
63 |
63 |
} |
} |
64 |
64 |
$sql = "SELECT * FROM test WHERE id = 'myid'"; |
$sql = "SELECT * FROM test WHERE id = 'myid'"; |
65 |
65 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
66 |
66 |
$row = rg_sql_fetch_array($res); |
$row = rg_sql_fetch_array($res); |
67 |
67 |
if (strcmp($row['f1'], "value") != 0) { |
if (strcmp($row['f1'], "value") != 0) { |
68 |
|
echo "Seems that insert with @@x@@ are not working!\n"; |
|
|
68 |
|
rg_log("Seems that insert with @@x@@ are not working!"); |
69 |
69 |
exit(1); |
exit(1); |
70 |
70 |
} |
} |
71 |
71 |
|
|
|
... |
... |
if (strcmp($row['f1'], "value") != 0) { |
73 |
73 |
|
|
74 |
74 |
rg_sql_close($db); |
rg_sql_close($db); |
75 |
75 |
|
|
76 |
|
echo "db: OK!\n"; |
|
|
76 |
|
rg_log("OK!"); |
77 |
77 |
?> |
?> |
File tests/user.php changed (mode: 100644) (index 56c7d4c..15f5e54) |
... |
... |
$_SERVER['HTTP_HOST'] = "fake.tld"; |
29 |
29 |
|
|
30 |
30 |
$r = rg_exec("rm -rf ubase"); |
$r = rg_exec("rm -rf ubase"); |
31 |
31 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
32 |
|
echo "Cannot remove ubase dir (" . $r['errmsg'] . ")!\n"; |
|
|
32 |
|
rg_log("Cannot remove ubase dir (" . $r['errmsg'] . ")!"); |
33 |
33 |
exit(1); |
exit(1); |
34 |
34 |
} |
} |
35 |
35 |
|
|
|
... |
... |
rg_sql_free_result($res); |
40 |
40 |
// Test if empty uid/user/email returns error |
// Test if empty uid/user/email returns error |
41 |
41 |
$_ui = rg_user_info($db, 0, "", ""); |
$_ui = rg_user_info($db, 0, "", ""); |
42 |
42 |
if ($_ui['ok'] == 1) { |
if ($_ui['ok'] == 1) { |
43 |
|
echo "Seems that invalid user does not return error!\n"; |
|
|
43 |
|
rg_log("Seems that invalid user does not return error!"); |
44 |
44 |
exit(1); |
exit(1); |
45 |
45 |
} |
} |
46 |
46 |
|
|
|
... |
... |
$_u['confirm_token'] = ""; |
59 |
59 |
$_u['plan_id'] = 1000; |
$_u['plan_id'] = 1000; |
60 |
60 |
$uid = rg_user_edit($db, $_u); |
$uid = rg_user_edit($db, $_u); |
61 |
61 |
if ($uid === FALSE) { |
if ($uid === FALSE) { |
62 |
|
echo "Cannot add user (" . rg_user_error() . ")!\n"; |
|
|
62 |
|
rg_log("Cannot add user (" . rg_user_error() . ")!"); |
63 |
63 |
exit(1); |
exit(1); |
64 |
64 |
} |
} |
65 |
65 |
|
|
66 |
66 |
// Simulate event: link_by_name |
// Simulate event: link_by_name |
67 |
|
$ev = array("ui.uid" => $uid, "ui.username" => $_u['username']); |
|
|
67 |
|
$ev = array("ui::uid" => $uid, "ui::username" => $_u['username']); |
68 |
68 |
$r = rg_user_link_by_name($db, $ev); |
$r = rg_user_link_by_name($db, $ev); |
69 |
69 |
if ($r === FALSE) { |
if ($r === FALSE) { |
70 |
|
echo "Cannot link by name (" . rg_user_error() . ")!\n"; |
|
|
70 |
|
rg_log("Cannot link by name (" . rg_user_error() . ")!"); |
71 |
71 |
exit(1); |
exit(1); |
72 |
72 |
} |
} |
73 |
73 |
|
|
74 |
74 |
$v = rg_user_forgot_pass_mail_prepare($db, "rg@localhost"); |
$v = rg_user_forgot_pass_mail_prepare($db, "rg@localhost"); |
75 |
75 |
if (empty($v['token'])) { |
if (empty($v['token'])) { |
76 |
76 |
print_r($v); |
print_r($v); |
77 |
|
echo "Error(rg_user_forgot_pass_mail): " . rg_user_error() . "!\n"; |
|
|
77 |
|
rg_log("Error(rg_user_forgot_pass_mail): " . rg_user_error() . "!"); |
78 |
78 |
exit(1); |
exit(1); |
79 |
79 |
} |
} |
80 |
80 |
|
|
81 |
81 |
$_ui = rg_user_info($db, $uid, "", ""); |
$_ui = rg_user_info($db, $uid, "", ""); |
82 |
82 |
if ($_ui['exists'] != 1) { |
if ($_ui['exists'] != 1) { |
83 |
|
echo "Seems that user with $uid does not exists!\n"; |
|
|
83 |
|
rg_log("Seems that user with $uid does not exists!"); |
84 |
84 |
exit(1); |
exit(1); |
85 |
85 |
} |
} |
86 |
86 |
$pass = $_ui['pass']; |
$pass = $_ui['pass']; |
|
... |
... |
$_u['uid'] = $uid; |
90 |
90 |
$_u['pass'] = ""; |
$_u['pass'] = ""; |
91 |
91 |
$r = rg_user_edit($db, $_u); |
$r = rg_user_edit($db, $_u); |
92 |
92 |
if ($r === FALSE) { |
if ($r === FALSE) { |
93 |
|
echo "Cannot edit user with empty pass (" . rg_user_error() . ")!\n"; |
|
|
93 |
|
rg_log("Cannot edit user with empty pass (" . rg_user_error() . ")!"); |
94 |
94 |
exit(1); |
exit(1); |
95 |
95 |
} |
} |
96 |
96 |
// the pass should not be changed here |
// the pass should not be changed here |
97 |
97 |
$_ui = rg_user_info($db, $uid, "", ""); |
$_ui = rg_user_info($db, $uid, "", ""); |
98 |
98 |
if ($_ui['exists'] != 1) { |
if ($_ui['exists'] != 1) { |
99 |
|
echo "Seems that user with $uid does not exists!\n"; |
|
|
99 |
|
rg_log("Seems that user with $uid does not exists!"); |
100 |
100 |
exit(1); |
exit(1); |
101 |
101 |
} |
} |
102 |
102 |
if (strcmp($pass, $_ui['pass']) != 0) { |
if (strcmp($pass, $_ui['pass']) != 0) { |
103 |
|
echo "Password was changed! Bad!\n"; |
|
|
103 |
|
rg_log("Password was changed! Bad!"); |
104 |
104 |
exit(1); |
exit(1); |
105 |
105 |
} |
} |
106 |
106 |
|
|
|
... |
... |
$_u['pass'] = "pass2"; |
109 |
109 |
$_u['pass2'] = "pass2"; |
$_u['pass2'] = "pass2"; |
110 |
110 |
$r = rg_user_edit($db, $_u); |
$r = rg_user_edit($db, $_u); |
111 |
111 |
if ($r === FALSE) { |
if ($r === FALSE) { |
112 |
|
echo "Cannot edit user with not empty pass (" . rg_user_error() . ")!\n"; |
|
|
112 |
|
rg_log("Cannot edit user with not empty pass (" . rg_user_error() . ")!"); |
113 |
113 |
exit(1); |
exit(1); |
114 |
114 |
} |
} |
115 |
115 |
// the pass should be changed here |
// the pass should be changed here |
116 |
116 |
$salt = $_ui['salt']; |
$salt = $_ui['salt']; |
117 |
117 |
$_ui = rg_user_info($db, $uid, "", ""); |
$_ui = rg_user_info($db, $uid, "", ""); |
118 |
118 |
if ($_ui['exists'] != 1) { |
if ($_ui['exists'] != 1) { |
119 |
|
echo "Seems that user with $uid does not exists!\n"; |
|
|
119 |
|
rg_log("Seems that user with $uid does not exists!"); |
120 |
120 |
exit(1); |
exit(1); |
121 |
121 |
} |
} |
122 |
122 |
if (strcmp($salt, $_ui['salt']) == 0) { |
if (strcmp($salt, $_ui['salt']) == 0) { |
123 |
|
echo "Salt was not changed ($salt)!\n"; |
|
|
123 |
|
rg_log("Salt was not changed ($salt)!"); |
124 |
124 |
exit(1); |
exit(1); |
125 |
125 |
} |
} |
126 |
126 |
if (strcmp($pass, $_ui['pass']) == 0) { |
if (strcmp($pass, $_ui['pass']) == 0) { |
127 |
|
echo "Password was not changed!\n"; |
|
|
127 |
|
rg_log("Password was not changed!"); |
128 |
128 |
exit(1); |
exit(1); |
129 |
129 |
} |
} |
130 |
130 |
|
|
131 |
131 |
// change password |
// change password |
132 |
132 |
$r = rg_user_set_pass($db, $uid, "pass3"); |
$r = rg_user_set_pass($db, $uid, "pass3"); |
133 |
133 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
134 |
|
echo "Cannot change pass!\n"; |
|
|
134 |
|
rg_log("Cannot change pass!"); |
135 |
135 |
exit(1); |
exit(1); |
136 |
136 |
} |
} |
137 |
137 |
|
|
138 |
138 |
// get token for e-mail forgot pass feature |
// get token for e-mail forgot pass feature |
139 |
139 |
$r = rg_user_forgot_pass_mail_prepare($db, "rg@localhost"); |
$r = rg_user_forgot_pass_mail_prepare($db, "rg@localhost"); |
140 |
140 |
if (empty($r['token'])) { |
if (empty($r['token'])) { |
141 |
|
echo "Could not get token (" . rg_user_error() . ")!\n"; |
|
|
141 |
|
rg_log("Could not get token (" . rg_user_error() . ")!"); |
142 |
142 |
exit(1); |
exit(1); |
143 |
143 |
} |
} |
144 |
144 |
|
|
145 |
145 |
$r = rg_user_forgot_pass_uid($db, $r['token']); |
$r = rg_user_forgot_pass_uid($db, $r['token']); |
146 |
146 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
147 |
|
echo "Cannot find uid based on token (" . rg_user_error() . ")!\n"; |
|
|
147 |
|
rg_log("Cannot find uid based on token (" . rg_user_error() . ")!"); |
148 |
148 |
exit(1); |
exit(1); |
149 |
149 |
} |
} |
150 |
150 |
|
|
151 |
151 |
if ($r['uid'] != $uid) { |
if ($r['uid'] != $uid) { |
152 |
|
echo "Token returned does not belong to the proper user!\n"; |
|
|
152 |
|
rg_log("Token returned does not belong to the proper user!"); |
153 |
153 |
exit(1); |
exit(1); |
154 |
154 |
} |
} |
155 |
155 |
|
|
|
... |
... |
$e = "ubase/by_id/" . substr($x, 0, 2) . "/" . substr($x, 2, 2) |
159 |
159 |
. "/" . substr($x, 4, 2) . "/" . substr($x, 6, 2) . "/" . $x; |
. "/" . substr($x, 4, 2) . "/" . substr($x, 6, 2) . "/" . $x; |
160 |
160 |
$r = rg_user_path_by_id($uid); |
$r = rg_user_path_by_id($uid); |
161 |
161 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
162 |
|
echo "path_by_id: e=[$e] != r=[$r]!\n"; |
|
|
162 |
|
rg_log("path_by_id: e=[$e] != r=[$r]!"); |
163 |
163 |
exit(1); |
exit(1); |
164 |
164 |
} |
} |
165 |
165 |
|
|
166 |
166 |
// test renames |
// test renames |
167 |
167 |
$r = rg_user_rename($db, $_ui, "userA2"); |
$r = rg_user_rename($db, $_ui, "userA2"); |
168 |
168 |
if ($r === FALSE) { |
if ($r === FALSE) { |
169 |
|
echo "Cannot rename user (" . rg_user_error() . ")!\n"; |
|
|
169 |
|
rg_log("Cannot rename user (" . rg_user_error() . ")!"); |
170 |
170 |
exit(1); |
exit(1); |
171 |
171 |
} |
} |
172 |
172 |
|
|
|
... |
... |
$_u['confirm_token'] = ""; |
185 |
185 |
$_u['plan_id'] = 1000; |
$_u['plan_id'] = 1000; |
186 |
186 |
$uid5 = rg_user_edit($db, $_u); |
$uid5 = rg_user_edit($db, $_u); |
187 |
187 |
if ($uid5 === FALSE) { |
if ($uid5 === FALSE) { |
188 |
|
echo "Cannot add user5 (" . rg_user_error() . ")!\n"; |
|
|
188 |
|
rg_log("Cannot add user5 (" . rg_user_error() . ")!"); |
189 |
189 |
exit(1); |
exit(1); |
190 |
190 |
} |
} |
191 |
191 |
|
|
192 |
192 |
$r = system("mkdir -p ubase/users/u/s/user5"); |
$r = system("mkdir -p ubase/users/u/s/user5"); |
193 |
193 |
if ($r === FALSE) { |
if ($r === FALSE) { |
194 |
|
echo "Cannot make fixes simulation dir ($php_errormsg)!\n"; |
|
|
194 |
|
rg_log("Cannot make fixes simulation dir ($php_errormsg)!"); |
195 |
195 |
exit(1); |
exit(1); |
196 |
196 |
} |
} |
197 |
197 |
$r = rg_fixes_user_index_by_id($db); |
$r = rg_fixes_user_index_by_id($db); |
198 |
198 |
if ($r === FALSE) { |
if ($r === FALSE) { |
199 |
|
echo "cannot re-index by id!\n"; |
|
|
199 |
|
rg_log("cannot re-index by id!"); |
200 |
200 |
exit(1); |
exit(1); |
201 |
201 |
} |
} |
202 |
202 |
|
|
203 |
|
echo "user: OK!\n"; |
|
|
203 |
|
rg_log("OK!"); |
204 |
204 |
?> |
?> |
File tests/util.php changed (mode: 100644) (index 184ee4b..a230cfd) |
... |
... |
$_rg = array("uid" => 5); |
23 |
23 |
$r = trim(rg_template("func.txt", $_rg)); |
$r = trim(rg_template("func.txt", $_rg)); |
24 |
24 |
$e = "5 + 1 = 6 | 5 - 1 = 4 | 4"; |
$e = "5 + 1 = 6 | 5 - 1 = 4 | 4"; |
25 |
25 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
26 |
|
echo "template func1 test failed [$r] != [$e]\n"; |
|
|
26 |
|
rg_log("template func1 test failed [$r] != [$e]"); |
27 |
27 |
exit(1); |
exit(1); |
28 |
28 |
} |
} |
29 |
29 |
|
|
30 |
30 |
|
|
31 |
31 |
$id = rg_id(16); |
$id = rg_id(16); |
32 |
32 |
if (strlen($id) != 16) { |
if (strlen($id) != 16) { |
33 |
|
echo "Cannot generate an id!\n"; |
|
|
33 |
|
rg_log("Cannot generate an id!"); |
34 |
34 |
exit(1); |
exit(1); |
35 |
35 |
} |
} |
36 |
36 |
|
|
|
... |
... |
$a = 5; |
40 |
40 |
$e = "5"; |
$e = "5"; |
41 |
41 |
$r = rg_array2string($a); |
$r = rg_array2string($a); |
42 |
42 |
if ($r !== $e) { |
if ($r !== $e) { |
43 |
|
echo "array2string is not working for integers ($r != $a)!\n"; |
|
|
43 |
|
rg_log("array2string is not working for integers ($r != $a)!"); |
44 |
44 |
exit(1); |
exit(1); |
45 |
45 |
} |
} |
46 |
46 |
$a = "6"; |
$a = "6"; |
47 |
47 |
$e = "6"; |
$e = "6"; |
48 |
48 |
$r = rg_array2string($a); |
$r = rg_array2string($a); |
49 |
49 |
if ($r !== $e) { |
if ($r !== $e) { |
50 |
|
echo "array2string is not working for strings ($r != $a)!\n"; |
|
|
50 |
|
rg_log("array2string is not working for strings ($r != $a)!"); |
51 |
51 |
exit(1); |
exit(1); |
52 |
52 |
} |
} |
53 |
53 |
|
|
|
... |
... |
file_put_contents("util.tmp/file1", "aaa"); |
57 |
57 |
file_put_contents("util.tmp/file2", "bbb"); |
file_put_contents("util.tmp/file2", "bbb"); |
58 |
58 |
$r = rg_rmdir("util.tmp"); |
$r = rg_rmdir("util.tmp"); |
59 |
59 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
60 |
|
echo "Cannot delete dir (" . rg_util_error() . ")!\n"; |
|
|
60 |
|
rg_log("Cannot delete dir (" . rg_util_error() . ")!"); |
61 |
61 |
exit(1); |
exit(1); |
62 |
62 |
} |
} |
63 |
63 |
|
|
64 |
64 |
|
|
65 |
|
echo "util.php: testing function rg_prepare_replace_helper...\n"; |
|
|
65 |
|
rg_log("util.php: testing function rg_prepare_replace_helper..."); |
66 |
66 |
$what = array(); $values = array(); |
$what = array(); $values = array(); |
67 |
67 |
$a = array("a" => "b"); |
$a = array("a" => "b"); |
68 |
68 |
rg_prepare_replace_helper($a, "", $what, $values); |
rg_prepare_replace_helper($a, "", $what, $values); |
|
... |
... |
$v = rg_array2string($values); |
71 |
71 |
$ew = "a=[/@@a@@/uU]"; |
$ew = "a=[/@@a@@/uU]"; |
72 |
72 |
$ev = "a=[b]"; |
$ev = "a=[b]"; |
73 |
73 |
if ((strcmp($w, $ew) != 0) || (strcmp($v, $ev) != 0)) { |
if ((strcmp($w, $ew) != 0) || (strcmp($v, $ev) != 0)) { |
74 |
|
echo "Wrong prepare_replace: [$w] != [$ew] OR [$v] != [$ev]!\n"; |
|
|
74 |
|
rg_log("Wrong prepare_replace: [$w] != [$ew] OR [$v] != [$ev]!"); |
75 |
75 |
exit(1); |
exit(1); |
76 |
76 |
} |
} |
77 |
77 |
|
|
|
... |
... |
$v = rg_array2string($values); |
83 |
83 |
$ew = "ri::repo_id=[/@@ri\:\:repo_id@@/uU] ri::name=[/@@ri\:\:name@@/uU]"; |
$ew = "ri::repo_id=[/@@ri\:\:repo_id@@/uU] ri::name=[/@@ri\:\:name@@/uU]"; |
84 |
84 |
$ev = "ri::repo_id=[1] ri::name=[repo1]"; |
$ev = "ri::repo_id=[1] ri::name=[repo1]"; |
85 |
85 |
if ((strcmp($w, $ew) != 0) || (strcmp($v, $ev) != 0)) { |
if ((strcmp($w, $ew) != 0) || (strcmp($v, $ev) != 0)) { |
86 |
|
echo "Wrong prepare_replace: [$w] != [$ew] OR [$v] != [$ev]!\n"; |
|
|
86 |
|
rg_log("Wrong prepare_replace: [$w] != [$ew] OR [$v] != [$ev]!"); |
87 |
87 |
exit(1); |
exit(1); |
88 |
88 |
} |
} |
89 |
89 |
|
|
90 |
90 |
|
|
91 |
91 |
$r = rg_exec("/xxxx"); |
$r = rg_exec("/xxxx"); |
92 |
92 |
if ($r['ok'] == 1) { |
if ($r['ok'] == 1) { |
93 |
|
echo "util.php: running non existing command does not return 0!\n"; |
|
|
93 |
|
rg_log("util.php: running non existing command does not return 0!"); |
94 |
94 |
print_r($r); |
print_r($r); |
95 |
95 |
exit(1); |
exit(1); |
96 |
96 |
} |
} |
97 |
97 |
|
|
98 |
98 |
$r = rg_exec("ls"); |
$r = rg_exec("ls"); |
99 |
99 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
100 |
|
echo "util.php: cannot run a command!\n"; |
|
|
100 |
|
rg_log("util.php: cannot run a command!"); |
101 |
101 |
print_r($r); |
print_r($r); |
102 |
102 |
exit(1); |
exit(1); |
103 |
103 |
} |
} |
104 |
104 |
|
|
105 |
105 |
$r = rg_exec("./util_exit_code.sh 5"); |
$r = rg_exec("./util_exit_code.sh 5"); |
106 |
106 |
if ($r['code'] != 5) { |
if ($r['code'] != 5) { |
107 |
|
echo "util.php: error code seems to not be propageted!\n"; |
|
|
107 |
|
rg_log("util.php: error code seems to not be propageted!"); |
108 |
108 |
print_r($r); |
print_r($r); |
109 |
109 |
exit(1); |
exit(1); |
110 |
110 |
} |
} |
|
... |
... |
$data = array(); |
115 |
115 |
$r = rg_template_table("t1", $data, array("a" => "A")); |
$r = rg_template_table("t1", $data, array("a" => "A")); |
116 |
116 |
$e = "XAX"; |
$e = "XAX"; |
117 |
117 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
118 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
118 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
119 |
119 |
exit(1); |
exit(1); |
120 |
120 |
} |
} |
121 |
121 |
|
|
|
... |
... |
$data = array(array("a" => "A", "b" => "B"), array("a" => "A2", "b" => "B2")); |
125 |
125 |
$r = rg_template_table("t2", $data, array("c" => "C")); |
$r = rg_template_table("t2", $data, array("c" => "C")); |
126 |
126 |
$e = "HEADCABCA2B2CFOOTC"; |
$e = "HEADCABCA2B2CFOOTC"; |
127 |
127 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
128 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
128 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
129 |
129 |
exit(1); |
exit(1); |
130 |
130 |
} |
} |
131 |
131 |
|
|
|
... |
... |
$data = array("X" => "0", "A" => "Avalue", "B" => "Bvalue"); |
135 |
135 |
$r = rg_template("t3/c1", $data); |
$r = rg_template("t3/c1", $data); |
136 |
136 |
$e = "XXBvalueYY"; |
$e = "XXBvalueYY"; |
137 |
137 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
138 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
138 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
139 |
139 |
exit(1); |
exit(1); |
140 |
140 |
} |
} |
141 |
141 |
|
|
|
... |
... |
$data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue"); |
145 |
145 |
$r = rg_template("t3/c1", $data); |
$r = rg_template("t3/c1", $data); |
146 |
146 |
$e = "XXAvalueYY"; |
$e = "XXAvalueYY"; |
147 |
147 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
148 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
148 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
149 |
149 |
exit(1); |
exit(1); |
150 |
150 |
} |
} |
151 |
151 |
|
|
|
... |
... |
$data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue"); |
155 |
155 |
$r = rg_template("t3/c1", $data); |
$r = rg_template("t3/c1", $data); |
156 |
156 |
$e = "XXAvalueYY"; |
$e = "XXAvalueYY"; |
157 |
157 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
158 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
158 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
159 |
159 |
exit(1); |
exit(1); |
160 |
160 |
} |
} |
161 |
161 |
|
|
|
... |
... |
$data = array("X" => "1", "Y" => "1", "A" => "Avalue", "B" => "Bvalue", |
166 |
166 |
$r = rg_template("t3/c3", $data); |
$r = rg_template("t3/c3", $data); |
167 |
167 |
$e = "XXRvalueZZYY"; |
$e = "XXRvalueZZYY"; |
168 |
168 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
169 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
169 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
170 |
170 |
exit(1); |
exit(1); |
171 |
171 |
} |
} |
172 |
172 |
|
|
|
... |
... |
$data = array("X" => "1", "Y" => "0", "A" => "Avalue", "B" => "Bvalue", |
177 |
177 |
$r = rg_template("t3/c3", $data); |
$r = rg_template("t3/c3", $data); |
178 |
178 |
$e = "XXTvalueZZYY"; |
$e = "XXTvalueZZYY"; |
179 |
179 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
180 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
180 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
181 |
181 |
exit(1); |
exit(1); |
182 |
182 |
} |
} |
183 |
183 |
|
|
|
... |
... |
$data = array("X" => "0", "Y" => "1", "A" => "Avalue", "B" => "Bvalue", |
188 |
188 |
$r = rg_template("t3/c3", $data); |
$r = rg_template("t3/c3", $data); |
189 |
189 |
$e = "XXBvalueYY"; |
$e = "XXBvalueYY"; |
190 |
190 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
191 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
191 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
192 |
192 |
exit(1); |
exit(1); |
193 |
193 |
} |
} |
194 |
194 |
|
|
|
... |
... |
$r = rg_template("t3/c4", $data); |
199 |
199 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
200 |
200 |
$e = "XXTRUE_LEVEL_2YY"; |
$e = "XXTRUE_LEVEL_2YY"; |
201 |
201 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
202 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
202 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
203 |
203 |
exit(1); |
exit(1); |
204 |
204 |
} |
} |
205 |
205 |
|
|
|
... |
... |
$r = rg_template("t3/c4", $data); |
210 |
210 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
211 |
211 |
$e = "XXFALSE_LEVEL_1YY"; |
$e = "XXFALSE_LEVEL_1YY"; |
212 |
212 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
213 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
213 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
214 |
214 |
exit(1); |
exit(1); |
215 |
215 |
} |
} |
216 |
216 |
|
|
|
... |
... |
$r = rg_template("t3/c4", $data); |
221 |
221 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
222 |
222 |
$e = "XXFALSE_LEVEL_0YY"; |
$e = "XXFALSE_LEVEL_0YY"; |
223 |
223 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
224 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
224 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
225 |
225 |
exit(1); |
exit(1); |
226 |
226 |
} |
} |
227 |
227 |
|
|
|
... |
... |
$r = rg_template("t3/c5", $data); |
232 |
232 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
233 |
233 |
$e = "XX-X0Y0Z0-YY"; |
$e = "XX-X0Y0Z0-YY"; |
234 |
234 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
235 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
235 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
236 |
236 |
exit(1); |
exit(1); |
237 |
237 |
} |
} |
238 |
238 |
|
|
|
... |
... |
$r = rg_template("t3/c5", $data); |
243 |
243 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
244 |
244 |
$e = "XX-X0Y1Z0-YY"; |
$e = "XX-X0Y1Z0-YY"; |
245 |
245 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
246 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
246 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
247 |
247 |
exit(1); |
exit(1); |
248 |
248 |
} |
} |
249 |
249 |
|
|
|
... |
... |
$r = rg_template("t3/c6", $data); |
254 |
254 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
255 |
255 |
$e = "A"; |
$e = "A"; |
256 |
256 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
257 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
257 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
258 |
258 |
exit(1); |
exit(1); |
259 |
259 |
} |
} |
260 |
260 |
|
|
|
... |
... |
$r = rg_template("t3/c6b", $data); |
265 |
265 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
266 |
266 |
$e = "AY"; |
$e = "AY"; |
267 |
267 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
268 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
268 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
269 |
269 |
exit(1); |
exit(1); |
270 |
270 |
} |
} |
271 |
271 |
|
|
|
... |
... |
$r = rg_template("t3/c7", $data); |
276 |
276 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
277 |
277 |
$e = "B"; |
$e = "B"; |
278 |
278 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
279 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
|
279 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
280 |
280 |
exit(1); |
exit(1); |
281 |
281 |
} |
} |
282 |
282 |
|
|
|
... |
... |
$data = array("AAA" => "1", "BBB" => "2", "CCC" => "1"); |
286 |
286 |
$r = rg_replace_lookup($data, "@@AAA@@@@BBB@@@@CCC@@"); |
$r = rg_replace_lookup($data, "@@AAA@@@@BBB@@@@CCC@@"); |
287 |
287 |
$e = "121"; |
$e = "121"; |
288 |
288 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
289 |
|
echo "util.php: $t: not working (r=[$r] e=[$e])!\n"; |
|
|
289 |
|
rg_log("util.php: $t: not working (r=[$r] e=[$e])!"); |
290 |
290 |
exit(1); |
exit(1); |
291 |
291 |
} |
} |
292 |
292 |
|
|
|
... |
... |
$r = rg_template("t3/c8", $data); |
297 |
297 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
298 |
298 |
$e = "}}"; |
$e = "}}"; |
299 |
299 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
300 |
|
echo "util.php: $t: not working (r=[$r] e=[$e])!\n"; |
|
|
300 |
|
rg_log("util.php: $t: not working (r=[$r] e=[$e])!"); |
301 |
301 |
exit(1); |
exit(1); |
302 |
302 |
} |
} |
303 |
303 |
|
|
|
... |
... |
$r = rg_template("t3/c9", $data); |
308 |
308 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
309 |
309 |
$e = "XXBLABLABLAabcYYabc"; |
$e = "XXBLABLABLAabcYYabc"; |
310 |
310 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
311 |
|
echo "util.php: $t: not working (r=[$r] e=[$e])!\n"; |
|
|
311 |
|
rg_log("util.php: $t: not working (r=[$r] e=[$e])!"); |
312 |
312 |
exit(1); |
exit(1); |
313 |
313 |
} |
} |
314 |
314 |
|
|
|
... |
... |
$t = "test rg_copy_tree"; |
316 |
316 |
rg_log($t); |
rg_log($t); |
317 |
317 |
$r = rg_copy_tree("tree1", "tree1.copy", 0755); |
$r = rg_copy_tree("tree1", "tree1.copy", 0755); |
318 |
318 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
319 |
|
echo "util.php: $t: not working!\n"; |
|
|
319 |
|
rg_log("util.php: $t: not working!"); |
320 |
320 |
exit(1); |
exit(1); |
321 |
321 |
} |
} |
322 |
322 |
if (!file_exists("tree1.copy/a/f2")) { |
if (!file_exists("tree1.copy/a/f2")) { |
323 |
|
echo "util.php: $t(2): not working!\n"; |
|
|
323 |
|
rg_log("util.php: $t(2): not working!"); |
324 |
324 |
exit(1); |
exit(1); |
325 |
325 |
} |
} |
326 |
326 |
|
|
|
327 |
|
$t = "rg_dir_load"; |
|
328 |
|
rg_log($t); |
327 |
329 |
$x = rg_dir_load("/non_existing_dir"); |
$x = rg_dir_load("/non_existing_dir"); |
328 |
330 |
if ($x !== FALSE) { |
if ($x !== FALSE) { |
329 |
|
echo "rg_dir_load(non_existing) is not working right!\n"; |
|
|
331 |
|
rg_log("$t(non_existing) is not working right!"); |
330 |
332 |
exit(1); |
exit(1); |
331 |
333 |
} |
} |
332 |
334 |
|
|
|
335 |
|
$t = "rg_dir_load_pattern"; |
|
336 |
|
rg_log($t); |
333 |
337 |
$x = rg_dir_load_pattern("util/dir_pattern", "err-.*"); |
$x = rg_dir_load_pattern("util/dir_pattern", "err-.*"); |
334 |
338 |
$x2 = implode("", $x); |
$x2 = implode("", $x); |
335 |
339 |
$e = "err-asasasas"; |
$e = "err-asasasas"; |
336 |
340 |
if (strcmp($x2, $e) != 0) { |
if (strcmp($x2, $e) != 0) { |
337 |
|
echo "rg_dir_load_pattern() is not working right ($r != $e)!\n"; |
|
|
341 |
|
rg_log("$t() is not working right ($r != $e)!"); |
338 |
342 |
exit(1); |
exit(1); |
339 |
343 |
} |
} |
340 |
344 |
|
|
341 |
345 |
$src = array(); |
$src = array(); |
342 |
346 |
$a = array("u" => "uval", "HTML:A" => "Aval"); |
$a = array("u" => "uval", "HTML:A" => "Aval"); |
343 |
347 |
$x = rg_array_merge($src, "X", $a); |
$x = rg_array_merge($src, "X", $a); |
344 |
|
if (strcmp($x['X.u'], "uval") != 0) { |
|
345 |
|
echo "array_merge is not working correctly (2)!\n"; |
|
|
348 |
|
if (strcmp($x['X::u'], "uval") != 0) { |
|
349 |
|
rg_log("array_merge is not working correctly (2)!"); |
346 |
350 |
print_r($x); |
print_r($x); |
347 |
351 |
exit(1); |
exit(1); |
348 |
352 |
} |
} |
349 |
|
if (strcmp($x['HTML:X.A'], "Aval") != 0) { |
|
350 |
|
echo "array_merge is not working correctly (1)!\n"; |
|
|
353 |
|
if (strcmp($x['HTML:X::A'], "Aval") != 0) { |
|
354 |
|
rg_log("array_merge is not working correctly (1)!"); |
351 |
355 |
print_r($x); |
print_r($x); |
352 |
356 |
exit(1); |
exit(1); |
353 |
357 |
} |
} |
354 |
358 |
|
|
355 |
359 |
|
|
356 |
|
echo "util: OK!\n"; |
|
|
360 |
|
// rg_re_repo_git($organization, $user, $repo) |
|
361 |
|
$r = rg_re_repo_git(1, 'u1<', 'repo2ș'); |
|
362 |
|
$e = 'git://r1.embedromix.ro/u1%3C/repo2%C8%99'; |
|
363 |
|
if (strcmp($r, $e) != 0) { |
|
364 |
|
rg_log("re_repo_git is wrong [$r] != [$e]!"); |
|
365 |
|
exit(1); |
|
366 |
|
} |
|
367 |
|
|
|
368 |
|
rg_log("OK!"); |
357 |
369 |
?> |
?> |