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

Checkpoint, all tests pass
Author: Catalin(ux) M. BOIE
Author date (UTC): 2015-03-08 23:22
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2015-03-08 23:22
Parent(s): 553d3374edc1c93cb5af6d5807ead7d862fc5b61
Signing key:
Tree: eb7876f399444ac1a5d8574ae8ca5e474941183a
File Lines added Lines deleted
TODO 8 9
hooks/update 2 12
inc/bug.inc.php 31 33
inc/dispatch/dispatch.php 1 1
inc/events.inc.php 2 0
inc/git.inc.php 58 24
inc/keys.inc.php 2 4
inc/repo.inc.php 43 24
inc/struct.inc.php 6 0
inc/token.inc.php 3 2
inc/user.inc.php 11 12
inc/user/repo-page.php 11 24
inc/user/repo/bug/main.php 2 1
inc/user/repo/bug/show/show.php 2 2
inc/util.inc.php 44 35
root/themes/default/mail/user/repo/del.body.txt 1 1
root/themes/default/mail/user/repo/del.subj.txt 1 1
root/themes/default/mail/user/repo/new.body.txt 3 3
root/themes/default/mail/user/repo/new.subj.txt 1 1
root/themes/default/mail/user/repo/update.body.txt 5 5
root/themes/default/mail/user/repo/update.subj.txt 1 1
root/themes/default/mail/user/welcome.body.txt 1 1
root/themes/default/repo/add_edit.html 2 2
root/themes/default/repo/history/header.html 1 0
root/themes/default/repo/history/line.html 1 0
root/themes/default/repo/invalid.html 1 1
root/themes/default/repo/no_git_dir.html 3 0
root/themes/default/user/keys/main.html 1 0
scripts/cron.php 6 7
tests/Makefile 1 1
tests/bug.php 4 3
tests/cache.php 8 8
tests/config.php 1 1
tests/event.php 5 5
tests/git.php 5 5
tests/git2.php 1 1
tests/git_log1.expected 78 0
tests/git_log1.final 78 0
tests/git_log1.php 16 2
tests/git_log1.sh 16 0
tests/helpers.inc.php 33 0
tests/http.inc.php 6 6
tests/http_bug.php 9 28
tests/http_csrf.php 24 18
tests/http_login.php 25 17
tests/http_settings.php 15 14
tests/keys.php 11 11
tests/prof.php 7 7
tests/repo.php 15 10
tests/rights.php 19 19
tests/sql.php 14 14
tests/state.php 5 5
tests/themes/default 1 0
tests/user.php 24 24
tests/util.php 51 39
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 hooks/update changed (mode: 100755) (index 27cb0bf..51c79a9)
... ... $db = rg_sql_open($rg_sql);
37 37
38 38 $a = array(); $a = array();
39 39 $a['login_uid'] = sprintf("%u", getenv("ROCKETGIT_LOGIN_UID")); $a['login_uid'] = sprintf("%u", getenv("ROCKETGIT_LOGIN_UID"));
40 $a['repo_id'] = getenv("ROCKETGIT_REPO_ID");
40 $a['repo_id'] = sprintf("%u", getenv("ROCKETGIT_REPO_ID"));
41 41 $a['ip'] = getenv("ROCKETGIT_IP"); $a['ip'] = getenv("ROCKETGIT_IP");
42 42 $a['namespace'] = getenv("GIT_NAMESPACE"); $a['namespace'] = getenv("GIT_NAMESPACE");
43 43 $a['repo_path'] = getenv("ROCKETGIT_REPO_PATH"); $a['repo_path'] = getenv("ROCKETGIT_REPO_PATH");
44 $a['repo.uid'] = getenv("ROCKETGIT_REPO_UID");
44 $a['repo::uid'] = sprintf("%u", getenv("ROCKETGIT_REPO_UID"));
45 45
46 46 rg_log("Start " . rg_array2string($a)); rg_log("Start " . rg_array2string($a));
47 47 rg_log("_SERVER: " . rg_array2string($_SERVER)); rg_log("_SERVER: " . rg_array2string($_SERVER));
 
... ... if (strncmp($a['refname'], "refs/tags/", 10) == 0) {
75 75 rg_git_fatal("Unknown refname type provided [" . $a['refname'] . "]"); rg_git_fatal("Unknown refname type provided [" . $a['refname'] . "]");
76 76 } }
77 77
78 /*TODO: replace with event
79 @file_put_contents($a['repo_path'] . "/rocketgit/hook-update",
80 "repo: " . $a['repo_path']
81 . "\nat: " . sprintf("%u", $_start)
82 . "\nuid: " . $a['login_uid']
83 . "\npara: " . $a['refname'] . " " . $a['old_rev'] . " " . $a['new_rev']
84 . "\nProfiling:\n" . rg_prof_text()
85 . "\n_SERVER: " . rg_array2string($_SERVER));
86 */
87
88 78 rg_prof_end("hook-update"); rg_prof_end("hook-update");
89 79 rg_prof_log(); rg_prof_log();
90 80 ?> ?>
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/dispatch/dispatch.php changed (mode: 100644) (index 96d3a7d..75f2062)
... ... case 'login':
11 11
12 12 case 'logout': case 'logout':
13 13 if (!rg_valid_referer()) if (!rg_valid_referer())
14 break;
14 rg_log("Invalid referer");
15 15
16 16 if (!rg_token_valid($db, $rg, TRUE)) if (!rg_token_valid($db, $rg, TRUE))
17 17 break; break;
File inc/events.inc.php changed (mode: 100644) (index fd65dda..916d3d8)
... ... function rg_event_add($db, $event)
87 87 rg_prof_start("event_add"); rg_prof_start("event_add");
88 88 rg_log_enter("event_add: event=" . rg_array2string($event)); rg_log_enter("event_add: event=" . rg_array2string($event));
89 89
90 $event['IP'] = rg_var_str('REMOTE_ADDR');
91
90 92 $ret = FALSE; $ret = FALSE;
91 93 while (1) { while (1) {
92 94 $now = time(); $now = time();
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/keys.inc.php changed (mode: 100644) (index f8a01cf..6fb73ff)
... ... function rg_keys_remove($db, $ui, $list)
184 184 rg_sql_free_result($res); rg_sql_free_result($res);
185 185
186 186 $event = array("category" => 1001, "prio" => 50, $event = array("category" => 1001, "prio" => 50,
187 "ui.email" => $ui['confirmed'] > 0 ? $ui['email'] : "",
188 "IP" => rg_var_str("REMOTE_ADDR"),
187 "ui::email" => $ui['confirmed'] > 0 ? $ui['email'] : "",
189 188 "keys" => implode(",", $my_list)); "keys" => implode(",", $my_list));
190 189 $r = rg_event_add($db, $event); $r = rg_event_add($db, $event);
191 190 if ($r !== TRUE) { if ($r !== TRUE) {
 
... ... function rg_keys_add($db, $ui, $key)
291 290 rg_sql_free_result($res); rg_sql_free_result($res);
292 291
293 292 $event = array("category" => 1000, "prio" => 50, $event = array("category" => 1000, "prio" => 50,
294 "ui.email" => $ui['confirmed'] > 0 ? $ui['email'] : "",
295 "IP" => rg_var_str("REMOTE_ADDR"),
293 "ui::email" => $ui['confirmed'] > 0 ? $ui['email'] : "",
296 294 "key_id" => $key_id); "key_id" => $key_id);
297 295 $r = rg_event_add($db, $event); $r = rg_event_add($db, $event);
298 296 if ($r !== TRUE) { if ($r !== TRUE) {
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/struct.inc.php changed (mode: 100644) (index ebfb3e1..641cfc3)
... ... $rg_sql_struct[30]['other'] = array(
402 402 "events.next_try" => "ALTER TABLE events ADD next_try INTEGER NOT NULL DEFAULT 0" "events.next_try" => "ALTER TABLE events ADD next_try INTEGER NOT NULL DEFAULT 0"
403 403 ); );
404 404
405 $rg_sql_struct[31] = array();
406 $rg_sql_struct[31]['tables'] = array();
407 $rg_sql_struct[31]['other'] = array(
408 "repo_history" => "ALTER TABLE repo_history ADD uid INTEGER NOT NULL DEFAULT 0"
409 );
410
405 411
406 412 // This must be the last line // This must be the last line
407 413 $rg_sql_schema_ver = count($rg_sql_struct); $rg_sql_schema_ver = count($rg_sql_struct);
File inc/token.inc.php changed (mode: 100644) (index c16461f..5b4445b)
... ... function rg_token_valid($db, $rg, $double_allowed)
105 105 while (1) { while (1) {
106 106 $ua_hash = substr(sha512($rg['ua']), 0, 8); $ua_hash = substr(sha512($rg['ua']), 0, 8);
107 107
108 if (strlen($rg['token']) != 32) {
108 $len = strlen($rg['token']);
109 if ($len != 32) {
109 110 rg_token_set_error("invalid token"); rg_token_set_error("invalid token");
110 rg_security_violation_no_exit("invalid token (len)");
111 rg_security_violation_no_exit("invalid token ($len != 32)");
111 112 break; break;
112 113 } }
113 114
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/user/repo/bug/main.php changed (mode: 100644) (index 05865cb..2092590)
... ... case 'list':
39 39 $_bug_body .= rg_warning("Error: cannot delete search!"); // TODO $_bug_body .= rg_warning("Error: cannot delete search!"); // TODO
40 40 } }
41 41
42 $r = rg_bug_search_load_all($db, $rg['ri']['repo_id'], $rg['login_ui']['uid']);
42 $r = rg_bug_search_load_all($db, $rg['ri']['repo_id'],
43 $rg['login_ui']['uid']);
43 44 if ($r === FALSE) { if ($r === FALSE) {
44 45 $_bug_body .= rg_warning("Error: cannot load all searches!"); // TODO $_bug_body .= rg_warning("Error: cannot load all searches!"); // TODO
45 46 } else { } else {
File inc/user/repo/bug/show/show.php changed (mode: 100644) (index 8a6c8b0..01339c2)
... ... while (1) {
162 162 break; break;
163 163 } }
164 164
165 $ret = rg_bug_delete_undelete($db, $rg['login_ui']['uid'], $rg['ri']['repo_id'],
166 $ibug['bug_id'], $del_undel);
165 $ret = rg_bug_delete_undelete($db, $rg['login_ui']['uid'],
166 $rg['ri']['repo_id'], $ibug['bug_id'], $del_undel);
167 167 if ($ret === FALSE) { if ($ret === FALSE) {
168 168 $delete_error = rg_bug_error(); $delete_error = rg_bug_error();
169 169 break; break;
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 root/themes/default/mail/user/repo/del.body.txt changed (mode: 100644) (index 7b756eb..f1b9ec5)
1 1 Hello! Hello!
2 2
3 Repository '@@ri.name@@' was deleted.
3 Repository '@@ri::name@@' was deleted.
4 4
5 5 IP: @@IP@@ IP: @@IP@@
6 6
File root/themes/default/mail/user/repo/del.subj.txt changed (mode: 100644) (index 0df07b4..9f483cb)
1 '@@ri.name@@' repo was deleted
1 '@@ri::name@@' repo was deleted
File root/themes/default/mail/user/repo/new.body.txt changed (mode: 100644) (index 6277b53..26fbb55)
1 1 Hello! Hello!
2 2
3 @@if(@@ri.public == 1){{Public}}{{Private}} repository '@@ri.name@@' was created.
3 @@if(@@ri::public == 1){{Public}}{{Private}} repository '@@ri::name@@' was created.
4 4
5 5 Description: Description:
6 @@ri.description@@
6 @@ri::description@@
7 7
8 Link to repository: @@ri.url@@.
8 Link to repository: @@ri::url@@.
9 9 IP: @@IP@@ IP: @@IP@@
10 10
11 11 -- --
File root/themes/default/mail/user/repo/new.subj.txt changed (mode: 100644) (index b6e53b6..2cc45c3)
1 '@@ri.name@@' repo was created
1 '@@ri::name@@' repo was created
File root/themes/default/mail/user/repo/update.body.txt changed (mode: 100644) (index 04880b1..ad475f6)
1 1 Hello! Hello!
2 2
3 @@if(@@ri.renamed@@ == 1){{Repository '@@ri.old.name@@' was renamed to '@@ri.name@@.}}{{}}
4 @@if(@@ri.old.description_md5@@ != @@ri.description_md5@@){{
3 @@if(@@ri::renamed@@ == 1){{Repository '@@ri::old::name@@' was renamed to '@@ri::name@@.}}{{}}
4 @@if(@@ri::old::description_md5@@ != @@ri::description_md5@@){{
5 5 Description changed to: Description changed to:
6 @@ri.description@@}}{{}}
7 @@if(@@ri.public@@ == 1){{Repo is public.}}{{Repo is private.}}
8 Link to repository: @@ri.url@@
6 @@ri::description@@}}{{}}
7 Repository is @@if(@@ri::public@@ == 1){{public}}{{private}}.
8 Link to repository: @@ri::url@@
9 9
10 10 IP: @@IP@@ IP: @@IP@@
11 11
File root/themes/default/mail/user/repo/update.subj.txt changed (mode: 100644) (index ee59d51..4db950f)
1 '@@ri.old.name@@' repo was changed
1 '@@ri::old::name@@' repo was changed
File root/themes/default/mail/user/welcome.body.txt changed (mode: 100644) (index f1f8d09..19c1cd7)
... ... Enjoy your stay!
9 9 You must confirm your e-mail address before you can use your account, You must confirm your e-mail address before you can use your account,
10 10 by clicking on the link below:}} by clicking on the link below:}}
11 11 {{You may want to confirm your e-mail address by clicking on the link below:}} {{You may want to confirm your e-mail address by clicking on the link below:}}
12 @@url@@/op/confirm/@@ui.confirm_token@@
12 @@url@@/op/confirm/@@ui::confirm_token@@
13 13
14 14 Thank you! Thank you!
15 15
File root/themes/default/repo/add_edit.html changed (mode: 100644) (index e2b56be..b767244)
1 1 <div class="formarea"> <div class="formarea">
2 2
3 <div class="formarea_title">@@if(@@ri.repo_id@@ == 0){{Create repository}}{{Edit repository}}</div><br />
3 <div class="formarea_title">@@if(@@ri::repo_id@@ == 0){{Create repository}}{{Edit repository}}</div><br />
4 4
5 5 @@errmsg@@ @@errmsg@@
6 6
7 <form method="post" action="@@form_url@@/@@if(@@ri.repo_id@@ == 0){{create}}{{edit}}">
7 <form method="post" action="@@form_url@@/@@if(@@ri::repo_id@@ == 0){{create}}{{edit}}">
8 8 <input type="hidden" name="repo_id" value="@@ri::repo_id@@" /> <input type="hidden" name="repo_id" value="@@ri::repo_id@@" />
9 9 <input type="hidden" name="master" value="@@ri::master@@" /> <input type="hidden" name="master" value="@@ri::master@@" />
10 10 <input type="hidden" name="doit" value="1" /> <input type="hidden" name="doit" value="1" />
File root/themes/default/repo/history/header.html changed (mode: 100644) (index b4fc9ee..c0f66ae)
1 1 <table> <table>
2 2 <tr> <tr>
3 3 <th>Date (UTC)</th> <th>Date (UTC)</th>
4 <th>User</th>
4 5 <th>Event</th> <th>Event</th>
5 6 </tr> </tr>
File root/themes/default/repo/history/line.html changed (mode: 100644) (index 5efd58c..ddf30fa)
1 1 <tr> <tr>
2 2 <td>@@itime_text@@</td> <td>@@itime_text@@</td>
3 <td>@@username@@</td>
3 4 <td>@@message@@</td> <td>@@message@@</td>
4 5 </tr> </tr>
File root/themes/default/repo/invalid.html changed (mode: 100644) (index 61fcdc1..ca080a3)
1 1 <div class="warning"> <div class="warning">
2 Invalid repository.
2 Invalid repository name.
3 3 </div> </div>
File root/themes/default/repo/no_git_dir.html added (mode: 100644) (index 0000000..6084e41)
1 <div class="warning">
2 The git dir for this repo was not yet created. Please retry.
3 </div>
File root/themes/default/user/keys/main.html changed (mode: 100644) (index d7191de..6668ca1)
1 @@status@@
1 2 @@add_form@@ @@add_form@@
2 3
3 4 @@keys@@ @@keys@@
File scripts/cron.php changed (mode: 100644) (index aef77a3..d0ae805)
... ... if ((gmdate("H") == 0) && (gmdate("i") == 3)) {
59 59
60 60 $all_files = $row['master'] == 0 ? TRUE : FALSE; $all_files = $row['master'] == 0 ? TRUE : FALSE;
61 61 $disk_used = rg_repo_size($repo_path, $all_files); $disk_used = rg_repo_size($repo_path, $all_files);
62 $disk_used_mb = $disk_used === FALSE ? 0 : intval($disk_used / 1024 / 1024);
63 if ($disk_used === FALSE) {
64 rg_log("Could not open dir!");
65 } else if ($disk_used == $row['disk_used_mb']) {
66 // do nothing
67 } else {
62 if ($disk_used_mb === FALSE) {
63 rg_log("Cannot compute the repo size: " . rg_repo_error());
64 continue;
65 }
66 $disk_used_mb = sprintf("%u", $disk_used / 1024 / 1024);
67 if ($disk_used_mb != $row['disk_used_mb']) {
68 68 $sql = "UPDATE repos SET disk_used_mb = $disk_used_mb" $sql = "UPDATE repos SET disk_used_mb = $disk_used_mb"
69 69 . " WHERE repo_id = " . $row['repo_id']; . " WHERE repo_id = " . $row['repo_id'];
70 70 $res2 = rg_sql_query($db, $sql); $res2 = rg_sql_query($db, $sql);
 
... ... if ((gmdate("H") == 0) && (gmdate("i") == 3)) {
72 72 rg_log("Cannot run query!"); rg_log("Cannot run query!");
73 73 break; break;
74 74 } }
75
76 75 rg_sql_free_result($res2); rg_sql_free_result($res2);
77 76 } }
78 77 } }
File tests/Makefile changed (mode: 100644) (index f1a7992..407b057)
... ... http_admin:
76 76
77 77 .PHONY: clean .PHONY: clean
78 78 clean: clean:
79 @rm -f *.log *.strace *.strace.* *.out *.lock err-*
79 @rm -rf git_log1 *.log *.strace *.strace.* *.out *.lock err-* *.diff
File tests/bug.php changed (mode: 100644) (index d694270..02800c3)
... ... require_once($INC . "/bug.inc.php");
9 9 require_once($INC . "/sql.inc.php"); require_once($INC . "/sql.inc.php");
10 10 require_once($INC . "/struct.inc.php"); require_once($INC . "/struct.inc.php");
11 11 require_once($INC . "/fixes.inc.php"); require_once($INC . "/fixes.inc.php");
12 require_once("helpers.inc.php");
12 13
13 14 rg_log_set_file("bug.log"); rg_log_set_file("bug.log");
14 15
 
... ... $ui = array("uid" => $uid, "username" => "userX", "organization" => 0, "email" =
21 22 $repo_name = "bug-A"; $repo_name = "bug-A";
22 23
23 24
24 rg_test_repo_create($db, $ui, $new);
25 rg_test_create_repo($db, $ui, $new);
25 26
26 27 $data = array("bug_id" => 0, $data = array("bug_id" => 0,
27 28 "title" => "Bug title", "title" => "Bug title",
 
... ... $_u['confirm_token'] = "";
65 66 $_u['plan_id'] = 1000; $_u['plan_id'] = 1000;
66 67 $uid = rg_user_edit($db, $_u); $uid = rg_user_edit($db, $_u);
67 68 if ($uid === FALSE) { if ($uid === FALSE) {
68 echo "Cannot add user (" . rg_user_error() . ")!\n";
69 rg_log("Cannot add user (" . rg_user_error() . ")!");
69 70 exit(1); exit(1);
70 71 } }
71 72
 
... ... if (count($r) == 0) {
122 123
123 124 rg_sql_close($db); rg_sql_close($db);
124 125
125 echo "bug: OK!\n";
126 rg_log("OK!");
126 127 ?> ?>
File tests/cache.php changed (mode: 100644) (index 59cd47a..94e431e)
... ... $e = "1";
20 20 $r = rg_cache_core_get("a::b::c"); $r = rg_cache_core_get("a::b::c");
21 21 if ($r !== $e) { if ($r !== $e) {
22 22 print_r($rg_cache); print_r($rg_cache);
23 echo "[$r] != [$e]!\n";
23 rg_log("[$r] != [$e]!");
24 24 exit(1); exit(1);
25 25 } }
26 26
 
... ... $e = FALSE;
28 28 $r = rg_cache_core_get("x::y::z"); $r = rg_cache_core_get("x::y::z");
29 29 if ($r !== $e) { if ($r !== $e) {
30 30 print_r($rg_cache); print_r($rg_cache);
31 echo "r must be FALSE!\n";
31 rg_log("r must be FALSE!");
32 32 exit(1); exit(1);
33 33 } }
34 34
 
... ... $e = FALSE;
37 37 $r = rg_cache_core_get("x::y::z"); $r = rg_cache_core_get("x::y::z");
38 38 if ($r !== $e) { if ($r !== $e) {
39 39 print_r($rg_cache); print_r($rg_cache);
40 echo "r must be FALSE ($r)!\n";
40 rg_log("r must be FALSE ($r)!");
41 41 exit(1); exit(1);
42 42 } }
43 43
 
... ... $e = "1,2,aa";
50 50 $r = rg_cache_core_adump("v"); $r = rg_cache_core_adump("v");
51 51 if ($r !== $e) { if ($r !== $e) {
52 52 print_r($rg_cache); print_r($rg_cache);
53 echo "[$r] != [$e]!\n";
53 rg_log("[$r] != [$e]!");
54 54 exit(1); exit(1);
55 55 } }
56 56
 
... ... $e = "aa";
58 58 $r = rg_cache_core_apop("v"); $r = rg_cache_core_apop("v");
59 59 if ($r !== $e) { if ($r !== $e) {
60 60 print_r($rg_cache); print_r($rg_cache);
61 echo "[$r] != [$e]!\n";
61 rg_log("[$r] != [$e]!");
62 62 exit(1); exit(1);
63 63 } }
64 64
 
... ... $e = "1";
66 66 $r = rg_cache_core_ashift("v"); $r = rg_cache_core_ashift("v");
67 67 if ($r !== $e) { if ($r !== $e) {
68 68 print_r($rg_cache); print_r($rg_cache);
69 echo "[$r] != [$e]!\n";
69 rg_log("[$r] != [$e]!");
70 70 exit(1); exit(1);
71 71 } }
72 72
 
... ... $r = rg_cache_core_ashift("v");
75 75 $r = rg_cache_core_ashift("v"); $r = rg_cache_core_ashift("v");
76 76 if ($r !== $e) { if ($r !== $e) {
77 77 print_r($rg_cache); print_r($rg_cache);
78 echo "r is not FALSE ($r)!\n";
78 rg_log("r is not FALSE ($r)!");
79 79 exit(1); exit(1);
80 80 } }
81 81
82 echo "cache: OK!\n";
82 rg_log("OK!");
83 83
84 84 ?> ?>
File tests/config.php changed (mode: 100644) (index 213185a..84f052f)
... ... $rg_repo_min_len = 1;
12 12 $rg_repo_max_len = 100; $rg_repo_max_len = 100;
13 13 $rg_user_allow = '/^[\pL\pN\pP_<>]*$/uUD'; $rg_user_allow = '/^[\pL\pN\pP_<>]*$/uUD';
14 14 $rg_user_min_len = 1; $rg_user_min_len = 1;
15 $rg_user_max_len = 20;
15 $rg_user_max_len = 50;
16 16 $rg_ssh_paras = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty"; $rg_ssh_paras = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty";
17 17 $rg_admin_name = "RocketGit Admin (test)"; $rg_admin_name = "RocketGit Admin (test)";
18 18 $rg_admin_email = "admin@site.tld"; $rg_admin_email = "admin@site.tld";
File tests/event.php changed (mode: 100644) (index 28f35ed..3be3774)
... ... $functions[2] = "func2and3";
55 55 $functions[3] = "func2and3"; $functions[3] = "func2and3";
56 56 $r = rg_event_register_functions($functions); $r = rg_event_register_functions($functions);
57 57 if ($r !== TRUE) { if ($r !== TRUE) {
58 echo "Cannot register functions!\n";
58 rg_log("Cannot register functions!");
59 59 exit(1); exit(1);
60 60 } }
61 61
 
... ... if ($r !== TRUE) {
63 63 $event = array( $event = array(
64 64 "prio" => 1, "prio" => 1,
65 65 "category" => 1, "category" => 1,
66 "ri.repo_id" => 200
66 "ri::repo_id" => 200
67 67 ); );
68 68
69 69 $r = rg_event_add($db, $event); $r = rg_event_add($db, $event);
70 70 if ($r !== TRUE) { if ($r !== TRUE) {
71 echo "Cannot add event (" . rg_event_error() . ")!\n";
71 rg_log("Cannot add event (" . rg_event_error() . ")!");
72 72 exit(1); exit(1);
73 73 } }
74 74 rg_event_signal_daemon("", 0); rg_event_signal_daemon("", 0);
 
... ... rg_event_signal_daemon("", 0);
76 76 $notify_list = array(); $notify_list = array();
77 77 $r = rg_event_process_queue($db, $notify_list); $r = rg_event_process_queue($db, $notify_list);
78 78 if ($r === FALSE) { if ($r === FALSE) {
79 echo "Cannot process queue (" . rg_event_error() . ")!\n";
79 rg_log("Cannot process queue (" . rg_event_error() . ")!");
80 80 exit(1); exit(1);
81 81 } }
82 82
83 83 rg_sql_close($db); rg_sql_close($db);
84 84
85 echo "event: OK!\n";
85 rg_log("OK!");
86 86 ?> ?>
File tests/git.php changed (mode: 100644) (index f5fe1aa..ee3eb51)
... ... rg_log_set_file("git.log");
12 12 $rg_no_db = TRUE; $rg_no_db = TRUE;
13 13 require_once("common.php"); require_once("common.php");
14 14
15 echo "[*] Checking if git-init works...\n";
15 rg_log("[*] Checking if git-init works...");
16 16 $r = rg_git_init("git.tmp"); $r = rg_git_init("git.tmp");
17 17 if ($r !== TRUE) { if ($r !== TRUE) {
18 echo "Cannot run rg_git_init (" . rg_git_error() . ")!\n";
18 rg_log("Cannot run rg_git_init (" . rg_git_error() . ")!");
19 19 exit(1); exit(1);
20 20 } }
21 21
22 22 /* /*
23 echo "[*] Populate repo...\n";
23 rg_log("[*] Populate repo...");
24 24 file_put_contents("git.tmp/a", "aaa"); file_put_contents("git.tmp/a", "aaa");
25 25 system("cd git.tmp; git commit -a -m \"aa\"; git checkout -n b1"); system("cd git.tmp; git commit -a -m \"aa\"; git checkout -n b1");
26 26 // This is a bare repo! Could not work! // This is a bare repo! Could not work!
27 27 */ */
28 28
29 echo "[*] Testing rg_git_refs...\n";
29 rg_log("[*] Testing rg_git_refs...");
30 30 $refs = rg_git_refs("git.tmp"); $refs = rg_git_refs("git.tmp");
31 31 print_r($refs); print_r($refs);
32 32
33 33 system("rm -rf git.tmp"); system("rm -rf git.tmp");
34 34
35 echo "git: OK\n";
35 rg_log("OK");
36 36 ?> ?>
File tests/git2.php changed (mode: 100644) (index 6eeb09e..66752f2)
... ... print_r($refs);
21 21 system("rm -rf git2"); system("rm -rf git2");
22 22
23 23
24 echo "git2: OK\n";
24 rg_log("OK");
25 25 ?> ?>
File tests/git_log1.expected added (mode: 100644) (index 0000000..168e603)
1 <div class="diff">
2 <br />
3 <a name="dis1">
4 <table class="chunk" width="100%">
5 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>dis1</b> changed (mode: 100644) (index 2c4179b..2bf9115):</td></tr>
6 1 &nbsp; #ff0000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa #eeeeee
7 2 1 #eeeeee baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa #eeeeee baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
8 &nbsp; 2 #eeeeee #00ff00 caaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
9 </table>
10 </div>
11 <div class="diff">
12 <br />
13 <a name="dis1">
14 <table class="chunk" width="100%">
15 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>dis1</b> added (mode: 100644) (index 0000000..2c4179b):</td></tr>
16 &nbsp; 1 #eeeeee #00ff00 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
17 &nbsp; 2 #eeeeee #00ff00 baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
18 </table>
19 </div>
20 <div class="diff">
21 <br />
22 <a name="a b c">
23 <table class="chunk" width="100%">
24 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>a b c</b> added (mode: 100644) (index 0000000..72943a1):</td></tr>
25 &nbsp; 1 #eeeeee #00ff00 aaa
26 </table>
27 </div>
28 <div class="diff">
29 <br />
30 <a name="a3">
31 <table class="chunk" width="100%">
32 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>a3</b> deleted (index 193814c..0000000):</td></tr>
33 1 &nbsp; #ff0000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa #eeeeee
34 </table>
35 </div>
36 <div class="diff">
37 <br />
38 <a name="a3">
39 <table class="chunk" width="100%">
40 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>a3</b> renamed from a2 (similarity 100%):</td></tr>
41 </table>
42 <br />
43 <a name="c">
44 <table class="chunk" width="100%">
45 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>c</b> added (mode: 100644) (index 0000000..8ded189):</td></tr>
46 &nbsp; 1 #eeeeee #00ff00 aaaaaaaaaaaaaaaaaaaa
47 </table>
48 </div>
49 <div class="diff">
50 <br />
51 <a name="a2">
52 <table class="chunk" width="100%">
53 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>a2</b> added (mode: 100644) (index 0000000..193814c):</td></tr>
54 &nbsp; 1 #eeeeee #00ff00 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
55 </table>
56 </div>
57 <div class="diff">
58 <br />
59 <a name="empty.txt">
60 <table class="chunk" width="100%">
61 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>empty.txt</b> added (mode: 100644) (index 0000000..e69de29):</td></tr>
62 </table>
63 </div>
64 <div class="diff">
65 <br />
66 <a name="xx&quot;yy">
67 <table class="chunk" width="100%">
68 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>xx&quot;yy</b> added (mode: 100644) (index 0000000..e69de29):</td></tr>
69 </table>
70 </div>
71 <div class="diff">
72 <br />
73 <a name="a">
74 <table class="chunk" width="100%">
75 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>a</b> added (mode: 100644) (index 0000000..193814c):</td></tr>
76 &nbsp; 1 #eeeeee #00ff00 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
77 </table>
78 </div>
File tests/git_log1.final added (mode: 100644) (index 0000000..168e603)
1 <div class="diff">
2 <br />
3 <a name="dis1">
4 <table class="chunk" width="100%">
5 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>dis1</b> changed (mode: 100644) (index 2c4179b..2bf9115):</td></tr>
6 1 &nbsp; #ff0000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa #eeeeee
7 2 1 #eeeeee baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa #eeeeee baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
8 &nbsp; 2 #eeeeee #00ff00 caaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
9 </table>
10 </div>
11 <div class="diff">
12 <br />
13 <a name="dis1">
14 <table class="chunk" width="100%">
15 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>dis1</b> added (mode: 100644) (index 0000000..2c4179b):</td></tr>
16 &nbsp; 1 #eeeeee #00ff00 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
17 &nbsp; 2 #eeeeee #00ff00 baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
18 </table>
19 </div>
20 <div class="diff">
21 <br />
22 <a name="a b c">
23 <table class="chunk" width="100%">
24 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>a b c</b> added (mode: 100644) (index 0000000..72943a1):</td></tr>
25 &nbsp; 1 #eeeeee #00ff00 aaa
26 </table>
27 </div>
28 <div class="diff">
29 <br />
30 <a name="a3">
31 <table class="chunk" width="100%">
32 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>a3</b> deleted (index 193814c..0000000):</td></tr>
33 1 &nbsp; #ff0000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa #eeeeee
34 </table>
35 </div>
36 <div class="diff">
37 <br />
38 <a name="a3">
39 <table class="chunk" width="100%">
40 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>a3</b> renamed from a2 (similarity 100%):</td></tr>
41 </table>
42 <br />
43 <a name="c">
44 <table class="chunk" width="100%">
45 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>c</b> added (mode: 100644) (index 0000000..8ded189):</td></tr>
46 &nbsp; 1 #eeeeee #00ff00 aaaaaaaaaaaaaaaaaaaa
47 </table>
48 </div>
49 <div class="diff">
50 <br />
51 <a name="a2">
52 <table class="chunk" width="100%">
53 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>a2</b> added (mode: 100644) (index 0000000..193814c):</td></tr>
54 &nbsp; 1 #eeeeee #00ff00 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
55 </table>
56 </div>
57 <div class="diff">
58 <br />
59 <a name="empty.txt">
60 <table class="chunk" width="100%">
61 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>empty.txt</b> added (mode: 100644) (index 0000000..e69de29):</td></tr>
62 </table>
63 </div>
64 <div class="diff">
65 <br />
66 <a name="xx&quot;yy">
67 <table class="chunk" width="100%">
68 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>xx&quot;yy</b> added (mode: 100644) (index 0000000..e69de29):</td></tr>
69 </table>
70 </div>
71 <div class="diff">
72 <br />
73 <a name="a">
74 <table class="chunk" width="100%">
75 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>a</b> added (mode: 100644) (index 0000000..193814c):</td></tr>
76 &nbsp; 1 #eeeeee #00ff00 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
77 </table>
78 </div>
File tests/git_log1.php changed (mode: 100644) (index 50ed2cd..38b19fe)
... ... $from = "";
21 21 $to = ""; $to = "";
22 22 $also_patch = TRUE; $also_patch = TRUE;
23 23 $r = rg_git_log($path, $max, $from, $to, $also_patch); $r = rg_git_log($path, $max, $from, $to, $also_patch);
24 if ($r === FALSE) {
25 rg_log("Cannot generate log (" . rg_git_error() . ")!");
26 exit(1);
27 }
24 28 file_put_contents(dirname(__FILE__) . "/git_log1.out", print_r($r, TRUE)); file_put_contents(dirname(__FILE__) . "/git_log1.out", print_r($r, TRUE));
25 29
26 $a = rg_git_diff($r, "git_log1.tmpl");
27 file_put_contents(dirname(__FILE__) . "/git_log1.final", $a);
30 $final = '';
31 foreach ($r as $commit_index => $commit_info) {
32 $a = rg_git_diff($commit_info['files'], dirname(__FILE__) . "/git_log1.tmpl");
33 if ($a === FALSE) {
34 rg_log("Cannot call rg_git_diff for commit_index $commit_index"
35 . " (" . rg_git_error() . ")!");
36 exit(1);
37 }
38
39 $final .= $a;
40 }
41 file_put_contents(dirname(__FILE__) . "/git_log1.final", $final);
28 42
29 43 ?> ?>
File tests/git_log1.sh changed (mode: 100755) (index a01dff6..a6c668a)
... ... echo "baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" > dis1
49 49 echo "caaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" >> dis1 echo "caaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" >> dis1
50 50 git commit -a -m "dis1 changed" git commit -a -m "dis1 changed"
51 51
52 set +e
53
54 echo "Running git_log1.php..."
52 55 php ../git_log1.php php ../git_log1.php
56 if [ "${?}" != "0" ]; then
57 echo "git_log1.php exited with error."
58 exit 1
59 fi
60
61 cd ..
62
63 echo "Building diff..."
64 diff -u git_log1.final git_log1.expected > git_log1.diff
65 if [ "${?}" != "0" ]; then
66 echo "Error: check git_log1.diff!"
67 exit 1
68 fi
53 69
54 70 echo "git_log1: OK" echo "git_log1: OK"
File tests/helpers.inc.php changed (mode: 100644) (index 5f070ef..064188a)
... ... function rg_test_create_user($db, &$rg_ui)
51 51 } }
52 52 $rg_ui['uid'] = $r; $rg_ui['uid'] = $r;
53 53
54 // delete associated bugs
55 $sql = "SELECT * FROM repos WHERE uid = " . $rg_ui['uid'];
56 $res = rg_sql_query($db, $sql);
57 while (($row = rg_sql_fetch_array($res))) {
58 $_t = array('bug_labels', 'bug_notes', 'bug_search', 'bugs',
59 'merge_requests', 'watch_bug', 'watch_repo');
60 foreach ($_t as $_table) {
61 $sql = "DELETE FROM $_table WHERE repo_id = " . $row['repo_id'];
62 $res2 = rg_sql_query($db, $sql);
63 rg_sql_free_result($res2);
64 }
65
66 $sql = "DELETE FROM rights WHERE type = 'repo' AND obj_id = " . $row['repo_id'];
67 $res2 = rg_sql_query($db, $sql);
68 rg_sql_free_result($res2);
69 }
70 rg_sql_free_result($res);
71
72 // delete associated repos
73 $sql = "DELETE FROM repos WHERE uid = " . $rg_ui['uid'];
74 $res = rg_sql_query($db, $sql);
75 rg_sql_free_result($res);
76
77 // Delete associated keys
78 $sql = "DELETE FROM keys WHERE uid = " . $rg_ui['uid'];
79 $res = rg_sql_query($db, $sql);
80 rg_sql_free_result($res);
81
82 // delete given rights
83 $sql = "DELETE FROM rights WHERE uid = " . $rg_ui['uid'];
84 $res = rg_sql_query($db, $sql);
85 rg_sql_free_result($res);
86
54 87 return TRUE; return TRUE;
55 88 } }
56 89
File tests/http.inc.php changed (mode: 100644) (index f422f51..c7b4cf2)
... ... function do_req($url, &$data, &$headers)
100 100 } }
101 101
102 102 /* /*
103 * Helper function
103 * Helper function that will do the login and will return the good sid
104 104 */ */
105 function test_login($url, &$good_sid)
105 function test_login($url, $rg_ui, &$good_sid)
106 106 { {
107 107 global $test_ua; global $test_ua;
108 108
 
... ... function test_login($url, &$good_sid)
128 128 $data = array( $data = array(
129 129 "doit" => 1, "doit" => 1,
130 130 "token" => $good_token, "token" => $good_token,
131 "user" => "catab",
132 "pass" => "aaaa",
131 "user" => $rg_ui['username'],
132 "pass" => $rg_ui['pass'],
133 133 "lock_ip" => 1 "lock_ip" => 1
134 134 ); );
135 135 $headers = array("Cookie: sid=" . $good_sid); $headers = array("Cookie: sid=" . $good_sid);
 
... ... function test_login($url, &$good_sid)
140 140 } }
141 141 $good_sid = $r['sid']; $good_sid = $r['sid'];
142 142
143 file_put_contents("http_login.log", print_r($r, TRUE));
144 143 if (strstr($r['body'], "invalid user or pass")) { if (strstr($r['body'], "invalid user or pass")) {
145 rg_log("Login invalid. Check http_login.log!");
144 rg_log_ml(print_r($r, TRUE));
145 rg_log("Login invalid. Check above!");
146 146 return FALSE; return FALSE;
147 147 } }
148 148
File tests/http_bug.php changed (mode: 100644) (index b589b16..d9547d0)
... ... rg_test_create_user($db, $rg_ui);
22 22 rg_test_create_user($db, $rg_ui2); rg_test_create_user($db, $rg_ui2);
23 23 rg_test_create_repo($db, $rg_ui, $repo); rg_test_create_repo($db, $rg_ui, $repo);
24 24
25 // First we need to load the form so we can get the token
26 // We provide an old cookie to test if we generate a new pre-login one
27 $r = do_req($test_url . "/op/login", $data, $headers);
28 if ($r === FALSE) {
29 rg_log('Cannot load login form.');
25 $r = test_login($test_url, $rg_ui, $good_sid);
26 if ($r === FALSE)
30 27 exit(1); exit(1);
31 }
32 $good_sid = $r['sid'];
33 $good_token = $r['token'];
34
35 28
36 rg_log("Do the login (sid=$good_sid token=$good_token)...");
37 $data = array(
38 "doit" => 1,
39 "token" => $good_token,
40 "user" => $rg_ui['username'],
41 "pass" => $rg_ui['pass'],
42 "lock_ip" => 0);
43 $headers = array("Cookie: sid=" . $good_sid);
44 $r = do_req($test_url . "/op/login", $data, $headers);
45 if ($r === FALSE) {
46 rg_log_ml('Cannot login: ' . print_r($r, TRUE));
47 exit(1);
48 }
49 if (strstr($r['body'], "invalid user or pass")) {
50 rg_log_ml('Login invalid. r=' . print_r($r, TRUE));
51 exit(1);
52 }
53 29
54 30 rg_log("Loading bug form..."); rg_log("Loading bug form...");
55 31 $url = "/user/" . $rg_ui['username'] . "/" . $repo['name'] . "/bug/add"; $url = "/user/" . $rg_ui['username'] . "/" . $repo['name'] . "/bug/add";
32 $headers = array("Cookie: sid=" . $good_sid);
56 33 $data = array(); $data = array();
57 34 $r = do_req($test_url . $url, $data, $headers); $r = do_req($test_url . $url, $data, $headers);
58 35 if ($r === FALSE) { if ($r === FALSE) {
 
... ... if ($r === FALSE) {
60 37 exit(1); exit(1);
61 38 } }
62 39 $token = $r['token']; $token = $r['token'];
40 if (empty($token)) {
41 rg_log_ml(print_r($r, TRUE));
42 rg_log("Seems I cannot load a token. See above.");
43 exit(1);
44 }
63 45
64 46 rg_log("Posting bug form (token=$token)..."); rg_log("Posting bug form (token=$token)...");
65 47 $labels = array('a/b', 'uu::bb', '<xss>'); sort($labels); $labels = array('a/b', 'uu::bb', '<xss>'); sort($labels);
 
... ... if ($r === FALSE) {
74 56 rg_log('Cannot post bug request.'); rg_log('Cannot post bug request.');
75 57 exit(1); exit(1);
76 58 } }
77 rg_log_ml("CHECK: headers=" . print_r($headers, TRUE));
78 59 $sql = 'SELECT * FROM bugs WHERE repo_id = ' . $repo['repo_id']; $sql = 'SELECT * FROM bugs WHERE repo_id = ' . $repo['repo_id'];
79 60 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
80 61 $row = rg_sql_fetch_array($res); $row = rg_sql_fetch_array($res);
 
... ... if ($row['uid'] != $rg_ui['uid']) {
142 123 } }
143 124
144 125 rg_prof_log(); rg_prof_log();
145 rg_log("Done!");
126 rg_log("OK!");
146 127 ?> ?>
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/prof.php changed (mode: 100644) (index 554d000..43529c3)
... ... rg_prof_set(array("xxx" => 1));
20 20 rg_prof_end("label1"); rg_prof_end("label1");
21 21 $t = rg_prof_get(); $t = rg_prof_get();
22 22 if (!isset($t['label1'])) { if (!isset($t['label1'])) {
23 print_r($t);
24 echo "Profiling for label 1 is not present!\n";
23 rg_log_ml(print_r($t, TRUE));
24 rg_log("Profiling for label 1 is not present! See above t.");
25 25 exit(1); exit(1);
26 26 } }
27 27
 
... ... rg_prof_end("label2");
33 33 rg_prof_end("label2"); rg_prof_end("label2");
34 34 $t = rg_prof_get(); $t = rg_prof_get();
35 35 if (($t['label2']['time_ms'] < 1800) || ($t['label2']['time_ms'] > 2200)) { if (($t['label2']['time_ms'] < 1800) || ($t['label2']['time_ms'] > 2200)) {
36 print_r($t);
37 echo "Nested profiling is not working (time_ms)\n";
36 rg_log_ml(print_r($t, TRUE));
37 rg_log("Nested profiling is not working (time_ms). See above t.");
38 38 exit(1); exit(1);
39 39 } }
40 40 if ($t['label2']['runs'] != 2) { if ($t['label2']['runs'] != 2) {
41 print_r($t);
42 echo "Nested profiling is not working (runs)\n";
41 rg_log_ml(print_r($t, TRUE));
42 rg_log("Nested profiling is not working (runs). See above t.");
43 43 exit(1); exit(1);
44 44 } }
45 45
46 echo "prof: OK!\n";
46 rg_log("OK!");
47 47 ?> ?>
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/state.php changed (mode: 100644) (index 7a5ff0f..f60b6f5)
... ... $rg_sql_debug = 1;
19 19 // check return for an invalid state // check return for an invalid state
20 20 $r = rg_state_get($db, "asdsdsdf"); $r = rg_state_get($db, "asdsdsdf");
21 21 if ($r !== "") { if ($r !== "") {
22 echo "Cannot get '' (but '$r') for an unknown key!\n";
22 rg_log("Cannot get '' (but '$r') for an unknown key!");
23 23 exit(1); exit(1);
24 24 } }
25 25
26 26 $r = rg_state_set($db, "a", "bau"); $r = rg_state_set($db, "a", "bau");
27 27 if ($r !== TRUE) { if ($r !== TRUE) {
28 echo "Cannot get a TRUE for setting 'a' to 'bau' ($r)!\n";
28 rg_log("Cannot get a TRUE for setting 'a' to 'bau' ($r)!");
29 29 exit(1); exit(1);
30 30 } }
31 31
32 32 $r = rg_state_set($db, "a", "cucu"); $r = rg_state_set($db, "a", "cucu");
33 33 if ($r !== TRUE) { if ($r !== TRUE) {
34 echo "Cannot get a TRUE for setting 'a' to 'cucu' ($r)!\n";
34 rg_log("Cannot get a TRUE for setting 'a' to 'cucu' ($r)!");
35 35 exit(1); exit(1);
36 36 } }
37 37
38 38 $r = rg_state_get($db, "a"); $r = rg_state_get($db, "a");
39 39 if (strcmp($r, "cucu") != 0) { if (strcmp($r, "cucu") != 0) {
40 echo "Cannot get correct state ('$r' != 'cucu')!\n";
40 rg_log("Cannot get correct state ('$r' != 'cucu')!");
41 41 exit(1); exit(1);
42 42 } }
43 43
44 44 rg_sql_close($db); rg_sql_close($db);
45 45
46 echo "state: OK!\n";
46 rg_log("OK!");
47 47 ?> ?>
File tests/themes/default added (mode: 120000) (index 0000000..dddfc27)
1 ../../root/themes/default
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 ?> ?>
Hints

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

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

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

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