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 91a81af5a65c575fa1d61ac9cc5eb759b746a9ed

Checkpoint
Author: Catalin(ux) M. BOIE
Author date (UTC): 2014-10-29 04:19
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2014-10-29 04:19
Parent(s): 8aa274777cd39834ea3467399ec8b072a136e525
Signing key:
Tree: e0d603c60e5068c0256e033481ec14f7675acdbd
File Lines added Lines deleted
TODO 10 4
hooks/update 4 4
inc/cache.inc.php 9 9
inc/git.inc.php 22 16
inc/repo.inc.php 18 13
inc/rights.inc.php 19 7
inc/struct.inc.php 9 0
inc/user.inc.php 6 3
inc/util.inc.php 60 8
root/themes/default/user/repo/rights/form_repo.html 5 0
root/themes/default/user/repo/rights/form_repo_path.html 5 0
root/themes/default/user/repo/rights/form_repo_refs.html 5 0
root/themes/default/user/repo/rights/list_repo/header.html 1 0
root/themes/default/user/repo/rights/list_repo/line.html 2 3
root/themes/default/user/repo/rights/list_repo_path/header.html 1 0
root/themes/default/user/repo/rights/list_repo_path/line.html 2 3
root/themes/default/user/repo/rights/list_repo_refs/header.html 1 0
root/themes/default/user/repo/rights/list_repo_refs/line.html 2 3
tests/Makefile 1 1
tests/cache.php 1 0
tests/common.php 3 0
tests/email.php 1 0
tests/git.php 1 0
tests/git2.php 1 0
tests/log.php 1 0
tests/prof.php 1 0
tests/rights.php 6 6
tests/themes/util/func.txt 1 0
tests/user.php 9 0
tests/util.php 21 4
File TODO changed (mode: 100644) (index 53e52a8..143d8f7)
1 1 == Where I stopped last time == == Where I stopped last time ==
2 [ ] Important: only the owner of a repo must see all rights!
3 Probably also for user.
4 But, 'Admin' can be access only by the owner!
2 [ ] In loguri, la username, paar unele cu '?'. O fi de la cache + bug-ul in user.inc?
3 [ ] We should invalidate rights cache when repo goes from public -> private
4 and viceversa.
5 [ ] For autogenerated rights, disable also edit button.
6 [ ] adding rights is not working
7 [ ] We should not call cosmetic in rights hl because we anyway load again the
8 list.
5 9 [ ] Use can_be_deleted when showing delete checkboxes for rights. Done. Test. [ ] Use can_be_deleted when showing delete checkboxes for rights. Done. Test.
6 [ ] For delete, do not show checkboxes for injected items.
7 10 [ ] Add unit test for inject functions. [ ] Add unit test for inject functions.
8 11 [ ] When changing rights, invalidate/update cache. [ ] When changing rights, invalidate/update cache.
9 12 [ ] Retest repo rename. Better, add an unit test. [ ] Retest repo rename. Better, add an unit test.
 
35 38 that user sees the repo as public. that user sees the repo as public.
36 39
37 40 == BEFORE NEXT RELEASE == == BEFORE NEXT RELEASE ==
41 [ ] If a user has all rights, show "All" instead of full list.
42 Do this in rg_rights_text?
43 [ ] Should a user see her/his rights?
38 44 [ ] Add rights 'allow non-ascii file names'. [ ] Add rights 'allow non-ascii file names'.
39 45 [ ] Add 'desc' to rights. [ ] Add 'desc' to rights.
40 46 [ ] We should not show delete checkboxes/buttons if a user is not allowed [ ] We should not show delete checkboxes/buttons if a user is not allowed
File hooks/update changed (mode: 100755) (index f83fd37..de44135)
... ... rg_log_set_file($rg_log_dir . "/hook_update.log");
35 35 $db = rg_sql_open($rg_sql); $db = rg_sql_open($rg_sql);
36 36
37 37 $a = array(); $a = array();
38 $a['login_uid'] = @sprintf("%u", getenv("ROCKETGIT_LOGIN_UID"));
38 $a['login_uid'] = sprintf("%u", getenv("ROCKETGIT_LOGIN_UID"));
39 39 $a['repo_id'] = getenv("ROCKETGIT_REPO_ID"); $a['repo_id'] = getenv("ROCKETGIT_REPO_ID");
40 40 $a['ip'] = getenv("ROCKETGIT_IP"); $a['ip'] = getenv("ROCKETGIT_IP");
41 41 $a['namespace'] = getenv("GIT_NAMESPACE"); $a['namespace'] = getenv("GIT_NAMESPACE");
 
... ... rg_log("_SERVER: " . rg_array2string($_SERVER));
48 48 umask(0022); umask(0022);
49 49
50 50
51 $a['refname'] = @rg_git_reference($_SERVER['argv'][1]);
51 $a['refname'] = rg_git_reference($_SERVER['argv'][1]);
52 52 $a['old_rev'] = rg_git_rev(@$_SERVER['argv'][2]); $a['old_rev'] = rg_git_rev(@$_SERVER['argv'][2]);
53 53 $a['new_rev'] = rg_git_rev(@$_SERVER['argv'][3]); $a['new_rev'] = rg_git_rev(@$_SERVER['argv'][3]);
54 54 rg_log("refname=" . $a['refname'] . " old_rev=" . $a['old_rev'] rg_log("refname=" . $a['refname'] . " old_rev=" . $a['old_rev']
55 55 . " new_rev=" . $a['new_rev']); . " new_rev=" . $a['new_rev']);
56 56
57 57 if (empty($a['refname']) || empty($a['old_rev']) || empty($a['new_rev'])) if (empty($a['refname']) || empty($a['old_rev']) || empty($a['new_rev']))
58 rg_git_fatal("Invalid parameters [" . $a['refname']
59 . " " . $a['old_rev'] ." " . $a['new_rev'] . "]!");
58 rg_git_fatal("Invalid parameters: ref=[" . $a['refname']
59 . "] old=[" . $a['old_rev'] . "] new=[" . $a['new_rev'] . "]!");
60 60
61 61 if (strcmp($a['new_rev'], $rg_git_zero) == 0) if (strcmp($a['new_rev'], $rg_git_zero) == 0)
62 62 $a['new_rev_type'] = rg_git_type($a['old_rev']); $a['new_rev_type'] = rg_git_type($a['old_rev']);
File inc/cache.inc.php changed (mode: 100644) (index fadce23..0567530)
... ... function rg_cache_core_set($ns_var, $value)
49 49 { {
50 50 global $rg_cache; global $rg_cache;
51 51
52 rg_log_ml("cache_core_set: $ns_var = " . print_r($value, TRUE));
52 //rg_log_ml("cache_core_set: $ns_var = " . print_r($value, TRUE));
53 53
54 54 $tree = &$rg_cache; $tree = &$rg_cache;
55 55 $t = explode("::", $ns_var); $t = explode("::", $ns_var);
 
... ... function rg_cache_core_merge($ns_var, $list)
71 71 { {
72 72 global $rg_cache; global $rg_cache;
73 73
74 rg_log_ml("cache_core_merge: $ns_var = " . print_r($list, TRUE));
74 //rg_log_ml("cache_core_merge: $ns_var = " . print_r($list, TRUE));
75 75
76 76 $tree = &$rg_cache; $tree = &$rg_cache;
77 77 $t = explode("::", $ns_var); $t = explode("::", $ns_var);
 
... ... function rg_cache_core_get($ns_var)
120 120 { {
121 121 global $rg_cache; global $rg_cache;
122 122
123 rg_log("cache_core_get: $ns_var");
123 //rg_log("cache_core_get: $ns_var");
124 124
125 125 $tree = &$rg_cache; $tree = &$rg_cache;
126 126 $t = explode("::", $ns_var); $t = explode("::", $ns_var);
127 127 $var = array_pop($t); $var = array_pop($t);
128 128 foreach ($t as $token) { foreach ($t as $token) {
129 129 if (!isset($tree[$token])) { if (!isset($tree[$token])) {
130 rg_log("CHECK: cache_core_get: token '$token' not found, return false");
130 //rg_log("CHECK: cache_core_get: token '$token' not found, return false");
131 131 return FALSE; return FALSE;
132 132 } }
133 133
 
... ... function rg_cache_core_get($ns_var)
135 135 } }
136 136
137 137 if (isset($tree[$var])) { if (isset($tree[$var])) {
138 rg_log_ml("CHECK: cache_core_get: found key in cache: $ns_var = " . print_r($tree[$var], TRUE));
138 //rg_log_ml("CHECK: cache_core_get: found key in cache: $ns_var = " . print_r($tree[$var], TRUE));
139 139 return $tree[$var]; return $tree[$var];
140 140 } }
141 141
142 rg_log_ml("CHECK: cache_core_get: [$ns_var] not found in rg_cache. rg_cache: " . print_r($rg_cache, TRUE));
142 //rg_log_ml("CHECK: cache_core_get: [$ns_var] not found in rg_cache. rg_cache: " . print_r($rg_cache, TRUE));
143 143 return FALSE; return FALSE;
144 144 } }
145 145
 
... ... function rg_cache_core_unset($ns_var)
156 156 $var = array_pop($t); $var = array_pop($t);
157 157 foreach ($t as $token) { foreach ($t as $token) {
158 158 if (!isset($tree[$token])) { if (!isset($tree[$token])) {
159 rg_log("CHECK: cache_core_unset: token [$token] not found");
159 //rg_log("CHECK: cache_core_unset: token [$token] not found");
160 160 return FALSE; return FALSE;
161 161 } }
162 162
 
... ... function rg_cache_core_unset($ns_var)
165 165
166 166 if (isset($tree[$var])) { if (isset($tree[$var])) {
167 167 unset($tree[$var]); unset($tree[$var]);
168 rg_log_ml("CHECK: cache_core_unset: rg_cache=" . print_r($rg_cache, TRUE));
168 //rg_log_ml("CHECK: cache_core_unset: rg_cache=" . print_r($rg_cache, TRUE));
169 169 return TRUE; return TRUE;
170 170 } }
171 171
172 rg_log("CHECK: cache_core_unset: key [$var] not found");
172 //rg_log("CHECK: cache_core_unset: key [$var] not found");
173 173 return FALSE; return FALSE;
174 174 } }
175 175
File inc/git.inc.php changed (mode: 100644) (index 7e47161..bc25461)
... ... function rg_git_rev($rev)
249 249 */ */
250 250 function rg_git_reference($refname) function rg_git_reference($refname)
251 251 { {
252 if (!preg_match('/^[a-zA-Z0-9^~\/_]$/D', $refname))
252 $pattern = "[a-zA-Z0-9^~\/_]";
253 if (preg_match('/^' . $pattern . '$/uD', $refname) === FALSE) {
254 $chars = preg_replace('/' . $pattern . '/', '', $refname);
255 rg_log("git_reference: ref [$refname] contains invalid chars ($chars)");
253 256 return ""; return "";
257 }
254 258
255 259 return $refname; return $refname;
256 260 } }
 
... ... function rg_git_update_tag($db, $a)
893 897 rg_log("git_update_tag: " . rg_array2string($a)); rg_log("git_update_tag: " . rg_array2string($a));
894 898
895 899 $ip = $a['ip']; $ip = $a['ip'];
900 $uid = $a['login_uid'];
896 901
897 902 if (strcmp($a['new_rev_type'], "tag") == 0) { // Annotated if (strcmp($a['new_rev_type'], "tag") == 0) { // Annotated
898 903 if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create
899 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $a['uid'], "S", $ip, $a['refname']))
904 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "S", $ip, $a['refname']))
900 905 rg_git_fatal($a['refname'] . "\nNo rights to" rg_git_fatal($a['refname'] . "\nNo rights to"
901 906 . " create an annotated tag."); . " create an annotated tag.");
902 907 } else if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete } else if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete
903 908 rg_log("delete ann tag"); rg_log("delete ann tag");
904 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $a['uid'], "n", $ip, $a['refname']))
909 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "n", $ip, $a['refname']))
905 910 rg_git_fatal($a['refname'] . "\nNo rights to" rg_git_fatal($a['refname'] . "\nNo rights to"
906 911 . " delete an annotated tag."); . " delete an annotated tag.");
907 912 } else { // change } else { // change
908 913 rg_log("This seems it cannot happen in recent git."); rg_log("This seems it cannot happen in recent git.");
909 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $a['uid'], "S", $ip, $a['refname']))
914 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "S", $ip, $a['refname']))
910 915 rg_git_fatal($a['refname'] . "\nNo rights to" rg_git_fatal($a['refname'] . "\nNo rights to"
911 916 . " change an annotated tag."); . " change an annotated tag.");
912 917 } }
913 918 } else { // Un-annotated } else { // Un-annotated
914 919 if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create
915 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $a['uid'], "Y", $ip, $a['refname']))
920 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "Y", $ip, $a['refname']))
916 921 rg_git_fatal($a['refname'] . "\nNo rights to" rg_git_fatal($a['refname'] . "\nNo rights to"
917 922 . " create an un-annotated tag."); . " create an un-annotated tag.");
918 923 } else if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete } else if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete
919 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $a['uid'], "u", $ip, $a['refname']))
924 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "u", $ip, $a['refname']))
920 925 rg_git_fatal($a['refname'] . "\nNo rights to" rg_git_fatal($a['refname'] . "\nNo rights to"
921 926 . " delete an un-annotated tag."); . " delete an un-annotated tag.");
922 927 } else { // change } else { // change
923 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $a['uid'], "U", $ip, $a['refname']))
928 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "U", $ip, $a['refname']))
924 929 rg_git_fatal($a['refname'] . "\nNo rights to" rg_git_fatal($a['refname'] . "\nNo rights to"
925 930 . " change an un-annotated tag."); . " change an un-annotated tag.");
926 931 } }
 
... ... function rg_git_update_branch($db, $a)
954 959 rg_log("git_update_branch: " . rg_array2string($a)); rg_log("git_update_branch: " . rg_array2string($a));
955 960
956 961 $ip = $a['ip']; $ip = $a['ip'];
962 $uid = $a['login_uid'];
957 963
958 964 if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete
959 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $a['uid'], "D", $ip, $a['refname']))
965 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "D", $ip, $a['refname']))
960 966 rg_git_fatal($a['refname'] . "\nNo rights to delete" rg_git_fatal($a['refname'] . "\nNo rights to delete"
961 967 . " a branch."); . " a branch.");
962 968 return; return;
 
... ... function rg_git_update_branch($db, $a)
965 971 // If we have 'H' (anonymous push), we have also create branch // If we have 'H' (anonymous push), we have also create branch
966 972 $check_fast_forward = 1; $check_fast_forward = 1;
967 973 if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create
968 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $a['uid'], "H|C", $ip, $a['refname']))
974 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "H|C", $ip, $a['refname']))
969 975 rg_git_fatal($a['refname'] . "\nYou have no rights" rg_git_fatal($a['refname'] . "\nYou have no rights"
970 976 . " to create a branch."); . " to create a branch.");
971 977 $check_fast_forward = 0; $check_fast_forward = 0;
 
... ... function rg_git_update_branch($db, $a)
973 979
974 980 // Create or change // Create or change
975 981 // Check for non fast-forward update // Check for non fast-forward update
976 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $a['uid'], "O", $ip, $a['refname'])
982 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "O", $ip, $a['refname'])
977 983 && ($check_fast_forward == 1)) { && ($check_fast_forward == 1)) {
978 984 $merge_base = rg_git_merge_base($a['old_rev'], $a['new_rev']); $merge_base = rg_git_merge_base($a['old_rev'], $a['new_rev']);
979 985 if ($merge_base === FALSE) { if ($merge_base === FALSE) {
 
... ... function rg_git_update_branch($db, $a)
989 995
990 996 // Check if user pushes a merge commit // Check if user pushes a merge commit
991 997 // TODO: Check all commits, not only the last one! // TODO: Check all commits, not only the last one!
992 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $a['uid'], "M", $ip, $a['refname'])) {
998 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "M", $ip, $a['refname'])) {
993 999 if (rg_git_rev_ok($a['new_rev'] . "^2")) if (rg_git_rev_ok($a['new_rev'] . "^2"))
994 1000 rg_git_fatal($a['refname'] . "\nNo rights to push merges."); rg_git_fatal($a['refname'] . "\nNo rights to push merges.");
995 1001 } }
996 1002
997 1003 // Check for bad whitespace // Check for bad whitespace
998 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $a['uid'], "W", $ip, $a['refname'])) {
1004 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "W", $ip, $a['refname'])) {
999 1005 // TODO: add caching because we may check again below // TODO: add caching because we may check again below
1000 1006 $w = rg_git_whitespace_ok($a['old_rev'], $a['new_rev']); $w = rg_git_whitespace_ok($a['old_rev'], $a['new_rev']);
1001 1007 if ($w !== TRUE) if ($w !== TRUE)
 
... ... function rg_git_update_branch($db, $a)
1009 1015 if ($r === FALSE) if ($r === FALSE)
1010 1016 rg_git_fatal($a['refname'] . "\nInternal error, try again later\n"); rg_git_fatal($a['refname'] . "\nInternal error, try again later\n");
1011 1017 foreach ($r as $file) { foreach ($r as $file) {
1012 if (rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $a['uid'], "P", $ip, $file) !== TRUE) {
1018 if (rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "P", $ip, $file) !== TRUE) {
1013 1019 rg_git_fatal($a['refname'] rg_git_fatal($a['refname']
1014 1020 . "\nNo rights to push file [$path]\n"); . "\nNo rights to push file [$path]\n");
1015 1021 } }
1016 1022
1017 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $a['uid'], "W", $ip, $a['refname'])) {
1023 if (!rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "W", $ip, $a['refname'])) {
1018 1024 $w = rg_git_whitespace_ok($a['old_rev'], $a['new_rev']); $w = rg_git_whitespace_ok($a['old_rev'], $a['new_rev']);
1019 1025 if ($w !== TRUE) { if ($w !== TRUE) {
1020 1026 rg_git_fatal($a['refname'] rg_git_fatal($a['refname']
 
... ... function rg_git_update_branch($db, $a)
1024 1030 } }
1025 1031 } }
1026 1032
1027 if (rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $a['uid'], "P", $ip, $a['refname']) !== TRUE) {
1033 if (rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "P", $ip, $a['refname']) !== TRUE) {
1028 1034 rg_log("\tPush is not allowed, let's see the anon one"); rg_log("\tPush is not allowed, let's see the anon one");
1029 if (rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $a['uid'], "H", $ip, $a['refname']) === FALSE) {
1035 if (rg_rights_allow($db, $a['repo_id'], "repo_refs", $a['repo.uid'], $uid, "H", $ip, $a['refname']) === FALSE) {
1030 1036 $_x = array(); $_x = array();
1031 1037 $msg = rg_template("msg/push_not_allowed.txt", $_x); $msg = rg_template("msg/push_not_allowed.txt", $_x);
1032 1038 rg_git_fatal($a['refname']. "\n" . $msg); rg_git_fatal($a['refname']. "\n" . $msg);
File inc/repo.inc.php changed (mode: 100644) (index 373eef3..a0faacb)
... ... function rg_repo_admin_rights($db, $rg, $type)
1169 1169 $ret = ""; $ret = "";
1170 1170
1171 1171 $a = array(); $a = array();
1172 $a['type'] = $type;
1172 1173 $a['right_id'] = rg_var_uint("right_id"); $a['right_id'] = rg_var_uint("right_id");
1173 1174 $a['edit_id'] = rg_var_uint("edit_id"); $a['edit_id'] = rg_var_uint("edit_id");
1174 1175 $a['username'] = rg_var_str("username"); $a['username'] = rg_var_str("username");
 
... ... function rg_repo_admin_rights($db, $rg, $type)
1176 1177 $a['misc'] = rg_var_str("misc"); $a['misc'] = rg_var_str("misc");
1177 1178 $a['ip'] = rg_var_str("ip"); $a['ip'] = rg_var_str("ip");
1178 1179 $a['prio'] = rg_var_uint("prio"); $a['prio'] = rg_var_uint("prio");
1179 rg_log_ml("CHECK: a(POST)=" . print_r($a, TRUE));
1180 $a['desc'] = rg_var_str("desc");
1181 //rg_log_ml("CHECK: a(POST)=" . print_r($a, TRUE));
1180 1182
1181 1183 $errmsg = array(); $errmsg = array();
1182 1184 $list_errmsg = array(); $list_errmsg = array();
 
... ... function rg_repo_admin_rights($db, $rg, $type)
1207 1209
1208 1210 // edit // edit
1209 1211 while ($a['edit_id'] > 0) { while ($a['edit_id'] > 0) {
1210 // TODO: check rights
1211
1212 1212 $owner = $rg['ri']['uid']; $owner = $rg['ri']['uid'];
1213 1213 $r = rg_rights_get($db, $rg['ri']['repo_id'], $type, $r = rg_rights_get($db, $rg['ri']['repo_id'], $type,
1214 1214 $owner, $rg['login_ui']['uid'], $a['edit_id']); $owner, $rg['login_ui']['uid'], $a['edit_id']);
 
... ... function rg_repo_admin_rights($db, $rg, $type)
1222 1222 break; break;
1223 1223 } }
1224 1224
1225 // Only one right is returned when we edit one
1225 1226 $a = $r['list'][0]; $a = $r['list'][0];
1226 1227
1227 1228 $load_defaults = 0; $load_defaults = 0;
 
... ... function rg_repo_admin_rights($db, $rg, $type)
1237 1238 break; break;
1238 1239 } }
1239 1240
1240 $r = rg_rights_validate_ip($a['ip']);
1241 if ($r !== TRUE) {
1242 $errmsg[] = rg_rights_error();
1243 break;
1241 if (strcmp($a['username'], '*') == 0) {
1242 $a['uid'] = 0;
1243 } else {
1244 $_ui = rg_user_info($db, 0, $a['username'], "");
1245 if ($_ui['exists'] == 1) {
1246 $a['uid'] = $_ui['uid'];
1247 } else {
1248 $errmsg[] = rg_user_error();
1249 break;
1250 }
1244 1251 } }
1245 1252
1246 1253 $a['obj_id'] = $rg['ri']['repo_id']; $a['obj_id'] = $rg['ri']['repo_id'];
 
... ... function rg_repo_admin_rights($db, $rg, $type)
1251 1258 break; break;
1252 1259 } }
1253 1260
1254 // lookup users
1255 rg_rights_cosmetic($db, $a);
1256
1257 1261 $ret .= rg_template("user/repo/rights/grant_ok.html", $rg); $ret .= rg_template("user/repo/rights/grant_ok.html", $rg);
1258 1262
1259 1263 $load_defaults = 1; $load_defaults = 1;
 
... ... function rg_repo_admin_rights($db, $rg, $type)
1261 1265 } }
1262 1266
1263 1267 if ($load_defaults == 1) { if ($load_defaults == 1) {
1264 $rg['right_id'] = $a['right_id'];
1268 $rg['right_id'] = 0;
1265 1269 $rg['username'] = ""; $rg['username'] = "";
1266 1270 $rg['rights'] = rg_rights_default($type); $rg['rights'] = rg_rights_default($type);
1271 $rg['desc'] = "";
1267 1272 $rg['misc'] = ""; $rg['misc'] = "";
1268 1273 $rg['ip'] = ""; $rg['ip'] = "";
1269 1274 $rg['prio'] = 100; $rg['prio'] = 100;
 
... ... function rg_repo_admin_rights($db, $rg, $type)
1278 1283 $rg['rights']); $rg['rights']);
1279 1284
1280 1285 // list rights // list rights
1281 $rights_list = rg_rights_load($db, $rg['ri']['repo_id'], $type);
1282 $r = rg_rights_get($db, $rg['ri']['repo_id'], $type, $rg['ri']['uid'], -1, 0);
1286 $r = rg_rights_get($db, $rg['ri']['repo_id'], $type, $rg['ri']['uid'],
1287 -1, 0);
1283 1288 if ($r['ok'] != 1) if ($r['ok'] != 1)
1284 1289 $ret .= rg_warning("Cannot load rights. Try later."); $ret .= rg_warning("Cannot load rights. Try later.");
1285 1290 else else
File inc/rights.inc.php changed (mode: 100644) (index edf7d4e..02ce797)
... ... function rg_rights_text($type, $rights)
131 131
132 132 $ret = array(); $ret = array();
133 133
134 $all = rg_rights_all($type);
135 if (strcmp($rights, $all) == 0) {
136 $ret[] = "All";
137 return $ret;
138 }
139
134 140 $len = strlen($rights); $len = strlen($rights);
135 141 if ($len == 0) if ($len == 0)
136 142 return array("None"); return array("None");
 
... ... function rg_rights_cosmetic($db, &$row)
208 214 $row['nice.ip'] = "Any"; $row['nice.ip'] = "Any";
209 215 else else
210 216 $row['nice.ip'] = $row['ip']; $row['nice.ip'] = $row['ip'];
217
218 if (!isset($row['desc']))
219 $row['desc'] = "";
211 220 } }
212 221
213 222 /* /*
 
... ... function rg_rights_get($db, $obj_id, $type, $owner, $uid, $right_id)
297 306 if (isset($rg_rights_inject[$type])) { if (isset($rg_rights_inject[$type])) {
298 307 $f = $rg_rights_inject[$type]; $f = $rg_rights_inject[$type];
299 308 $rows = $f($db, $obj_id, $type, $owner, $uid); $rows = $f($db, $obj_id, $type, $owner, $uid);
300 rg_log_ml("rights_get: rows:" . print_r($rows, TRUE));
301 309 foreach ($rows as $row) { foreach ($rows as $row) {
302 310 rg_rights_cosmetic($db, $row); rg_rights_cosmetic($db, $row);
303 311 rg_log_ml("rights_get: inject specific rights: " . print_r($row, TRUE)); rg_log_ml("rights_get: inject specific rights: " . print_r($row, TRUE));
 
... ... function rg_rights_get($db, $obj_id, $type, $owner, $uid, $right_id)
320 328
321 329 // now, filter by uid and right_id // now, filter by uid and right_id
322 330 foreach ($r as $k => $v) { foreach ($r as $k => $v) {
323 if (($right_id > 0) && ($v['right_id'] == $right_id)) {
324 $ret['list'][] = $v;
325 break;
326 }
331 if (($right_id > 0) && ($v['right_id'] != $right_id))
332 continue;
327 333
328 334 if (($uid == -1) || ($v['uid'] == $uid) || ($v['uid'] == 0)) if (($uid == -1) || ($v['uid'] == $uid) || ($v['uid'] == 0))
329 335 $ret['list'][] = $v; $ret['list'][] = $v;
 
... ... function rg_rights_set($db, $type, $a)
357 363 break; break;
358 364 } }
359 365
366 $r = rg_rights_validate_ip($a['ip']);
367 if ($r !== TRUE)
368 break;
369
360 370 $a['type'] = $type; $a['type'] = $type;
361 371 $a['now'] = time(); $a['now'] = time();
362 372 if ($a['right_id'] > 0) if ($a['right_id'] > 0)
 
... ... function rg_rights_set($db, $type, $a)
370 380 . ", prio = @@prio@@" . ", prio = @@prio@@"
371 381 . ", itime = @@now@@" . ", itime = @@now@@"
372 382 . ", who = @@who@@" . ", who = @@who@@"
383 . ", desc = @@desc@@"
373 384 . " WHERE right_id = @@right_id@@"; . " WHERE right_id = @@right_id@@";
374 385 else else
375 386 $sql = "INSERT INTO rights (type, uid, obj_id, rights" $sql = "INSERT INTO rights (type, uid, obj_id, rights"
376 . ", misc, ip, prio, itime, who)"
387 . ", misc, ip, prio, itime, who, desc)"
377 388 . " VALUES (@@type@@, @@uid@@, @@obj_id@@, @@rights@@" . " VALUES (@@type@@, @@uid@@, @@obj_id@@, @@rights@@"
378 . ", @@misc@@, @@ip@@, @@prio@@, @@now@@, @@who@@)";
389 . ", @@misc@@, @@ip@@, @@prio@@, @@now@@, @@who@@"
390 . ", @@desc@@)";
379 391 $res = rg_sql_query_params($db, $sql, $a); $res = rg_sql_query_params($db, $sql, $a);
380 392 if ($res === FALSE) { if ($res === FALSE) {
381 393 rg_rights_set_error("cannot alter rights (" . rg_sql_error() . ")!"); rg_rights_set_error("cannot alter rights (" . rg_sql_error() . ")!");
File inc/struct.inc.php changed (mode: 100644) (index 0b5a0b0..0e84a9c)
... ... $rg_sql_struct[28]['other'] = array(
385 385 "ALTER TABLE repos ADD last_bug_id INTEGER NOT NULL DEFAULT 0" "ALTER TABLE repos ADD last_bug_id INTEGER NOT NULL DEFAULT 0"
386 386 ); );
387 387
388 /* add this in next update
389 $rg_sql_struct[29] = array();
390 $rg_sql_struct[29]['tables'] = array();
391 $rg_sql_struct[29]['other'] = array(
392 "add rights.desc" =>
393 "ALTER TABLE rights ADD desc TEXT NOT NULL DEFAULT ''"
394 );
395 */
396
388 397 // This must be the last line // This must be the last line
389 398 $rg_sql_schema_ver = count($rg_sql_struct); $rg_sql_schema_ver = count($rg_sql_struct);
390 399
File inc/user.inc.php changed (mode: 100644) (index 89c8b97..6a1e5d7)
... ... function rg_user_info($db, $uid, $user, $email)
582 582 "email" => $email); "email" => $email);
583 583
584 584 if ($uid > 0) { if ($uid > 0) {
585 $ret = rg_cache_get("user::" . $uid);
586 if ($ret !== FALSE)
585 $c = rg_cache_get("user::" . $uid);
586 if ($c !== FALSE) {
587 $ret = $c;
587 588 break; break;
589 }
588 590
589 591 $sql = "SELECT * FROM users WHERE uid = @@uid@@"; $sql = "SELECT * FROM users WHERE uid = @@uid@@";
590 592 $set_cache = TRUE; $set_cache = TRUE;
 
... ... function rg_user_info($db, $uid, $user, $email)
610 612 $sql = "SELECT * FROM users WHERE email = @@email@@"; $sql = "SELECT * FROM users WHERE email = @@email@@";
611 613 $set_cache_email = TRUE; $set_cache_email = TRUE;
612 614 } else { } else {
615 rg_user_set_error("invalid user");
613 616 break; break;
614 617 } }
615 618
 
... ... function rg_user_info($db, $uid, $user, $email)
636 639 } }
637 640
638 641 if (($ret['ok'] == 1) && $set_cache) if (($ret['ok'] == 1) && $set_cache)
639 rg_cache_set("user::" . $ret['uid'], $ret);
642 rg_cache_set("user::" . $uid, $ret);
640 643
641 644 if ($ret['exists'] == 1) { if ($ret['exists'] == 1) {
642 645 if ($set_cache_user) if ($set_cache_user)
File inc/util.inc.php changed (mode: 100644) (index 97c00cf..e6270a7)
... ... function rg_util_error()
19 19 return $rg_util_error; return $rg_util_error;
20 20 } }
21 21
22 /*
23 * This array will keep all registered function for templates
24 */
25 $rg_template_functions = array();
26
27 /*
28 * Register a function to be called when a @@func:func_name:var@@ construction
29 * is found in a template.
30 * Please note that the function is called once per template.
31 */
32 function rg_template_func($name, $real_func_name)
33 {
34 global $rg_template_functions;
35
36 $rg_template_functions[$name] = $real_func_name;
37 }
38
22 39 function rg_1024($v) function rg_1024($v)
23 40 { {
24 41 if ($v <= 9999) if ($v <= 9999)
 
... ... function rg_image_callback($matches)
370 387 /* /*
371 388 * Prepares the images to point to a correct image. * Prepares the images to point to a correct image.
372 389 */ */
373 function rg_prepare_image($line)
390 function rg_prepare_image($s)
374 391 { {
375 return preg_replace_callback('/@@IMG:(.*)@@/uU', "rg_image_callback", $line);
392 return preg_replace_callback('/@@IMG:(.*)@@/uU', "rg_image_callback", $s);
393 }
394
395 /*
396 * Resolve variables like '@@func:func_name:paras@@'
397 */
398 function rg_prepare_func($s, &$what, &$values)
399 {
400 global $rg_template_functions;
401
402 $seen = array();
403
404 $r = preg_match_all('/@@func:(.*):(.*)@@/uU', $s, $matches, PREG_SET_ORDER);
405 foreach ($matches as $i) {
406 $k = '/' . $i[0] . '/';
407 $func = $i[1];
408 $var = $i[2];
409
410 /* Function already called? */
411 if (isset($seen[$k]))
412 continue;
413
414 if (!isset($rg_template_functions[$func]))
415 continue;
416
417 $v = preg_replace($what, $values, "@@" . $var . "@@");
418 $final = $rg_template_functions[$func]($v);
419
420 $what[] = $k;
421 $values[] = $final;
422
423 $seen[$k] = 1;
424 }
376 425 } }
377 426
378 427 /* /*
 
... ... function rg_prepare_replace_helper($a, $prefix, &$what, &$values)
395 444 } }
396 445
397 446 if (strncmp($k, "HTML:", 5) == 0) { if (strncmp($k, "HTML:", 5) == 0) {
398 $new_prefix = $prefix . $add . substr($k, 5);
447 $k = substr($k, 5);
448 $new_prefix = $prefix . $add . $k;
399 449 } else { } else {
400 if (is_array($v))
401 rg_log_ml("DEBUG: Invalid type for [$k]: " . print_r($v, TRUE));
402 450 $v = htmlspecialchars($v); $v = htmlspecialchars($v);
403 451 } }
452
404 453 $what[$new_prefix] = "/@@" . $new_prefix . "@@/uU"; $what[$new_prefix] = "/@@" . $new_prefix . "@@/uU";
405 454 $values[$new_prefix] = $v; $values[$new_prefix] = $v;
406 455 } }
 
... ... function rg_file_get_contents($f)
590 639
591 640 /* /*
592 641 * 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
593 * @data - array of data for every line: index 0 is line 1, index 1 is line 2...
642 * @data - in array of data for every out line: index 0 is line 1, index 1 is line 2...
594 643 */ */
595 644 function rg_template_table($dir, &$data, $more) function rg_template_table($dir, &$data, $more)
596 645 { {
 
... ... function rg_template_table($dir, &$data, $more)
634 683 $what = $m_what; $values = $m_values; $what = $m_what; $values = $m_values;
635 684
636 685 rg_prepare_replace($info, $what, $values); rg_prepare_replace($info, $what, $values);
686 rg_prepare_func($line, $what, $values);
637 687
638 688 $line = rg_prepare_image($line); $line = rg_prepare_image($line);
639 689
 
... ... function rg_template($file, &$data)
676 726 $values = array(); $values = array();
677 727
678 728 rg_prepare_replace($data, $what, $values); rg_prepare_replace($data, $what, $values);
729 rg_prepare_func($body, $what, $values);
679 730
680 731 $body = rg_prepare_image($body); $body = rg_prepare_image($body);
681 732
 
... ... function rg_socket($path, $buf, $timeout)
1239 1290 rg_prof_start("socket"); rg_prof_start("socket");
1240 1291
1241 1292 $ret = FALSE; $ret = FALSE;
1242 do {
1293 while (1) {
1243 1294 if (isset($rg_socket_cache[$path])) { if (isset($rg_socket_cache[$path])) {
1244 1295 $socket = $rg_socket_cache[$path]; $socket = $rg_socket_cache[$path];
1245 1296 } else { } else {
 
... ... function rg_socket($path, $buf, $timeout)
1280 1331 } }
1281 1332
1282 1333 $ret = rg_socket_recv_wait($socket, "\n", $timeout); $ret = rg_socket_recv_wait($socket, "\n", $timeout);
1283 } while (0);
1334 break;
1335 }
1284 1336
1285 1337 rg_prof_end("socket"); rg_prof_end("socket");
1286 1338 return $ret; return $ret;
File root/themes/default/user/repo/rights/form_repo.html changed (mode: 100644) (index a684e6f..c0878a4)
18 18 @@rights_checkboxes@@ @@rights_checkboxes@@
19 19 <br /> <br />
20 20
21 <label class="form_item_title" for="desc">Description</label><br />
22 <textarea name="desc" rows="3" cols="50">@@desc@@</textarea>
23 <br />
24 <br />
25
21 26 <label class="form_item_title" for="ip">IP addresses/prefix (comma/space separated)</label><br /> <label class="form_item_title" for="ip">IP addresses/prefix (comma/space separated)</label><br />
22 27 <textarea name="ip" rows="3" cols="50">@@ip@@</textarea> <textarea name="ip" rows="3" cols="50">@@ip@@</textarea>
23 28 <br /> <br />
File root/themes/default/user/repo/rights/form_repo_path.html changed (mode: 100644) (index 4d3caef..7580b47)
23 23 @@rights_checkboxes@@ @@rights_checkboxes@@
24 24 <br /> <br />
25 25
26 <label class="form_item_title" for="desc">Description</label><br />
27 <textarea name="desc" rows="3" cols="50">@@desc@@</textarea>
28 <br />
29 <br />
30
26 31 <label class="form_item_title" for="ip">IP addresses/prefix (comma/space separated)</label><br /> <label class="form_item_title" for="ip">IP addresses/prefix (comma/space separated)</label><br />
27 32 <textarea name="ip" rows="3" cols="50">@@ip@@</textarea> <textarea name="ip" rows="3" cols="50">@@ip@@</textarea>
28 33 <br /> <br />
File root/themes/default/user/repo/rights/form_repo_refs.html changed (mode: 100644) (index c2208ea..19bb83b)
23 23 @@rights_checkboxes@@ @@rights_checkboxes@@
24 24 <br /> <br />
25 25
26 <label class="form_item_title" for="desc">Description</label><br />
27 <textarea name="desc" rows="3" cols="50">@@desc@@</textarea>
28 <br />
29 <br />
30
26 31 <label class="form_item_title" for="ip">IP addresses/prefix (comma/space separated)</label><br /> <label class="form_item_title" for="ip">IP addresses/prefix (comma/space separated)</label><br />
27 32 <textarea name="ip" rows="3" cols="50">@@ip@@</textarea> <textarea name="ip" rows="3" cols="50">@@ip@@</textarea>
28 33 <br /> <br />
File root/themes/default/user/repo/rights/list_repo/header.html changed (mode: 100644) (index 8e5634a..a91bf64)
15 15 <th>User</th> <th>User</th>
16 16 <th>IP</th> <th>IP</th>
17 17 <th>Repo rights</th> <th>Repo rights</th>
18 <th>Description</th>
18 19 <th>Operations</th> <th>Operations</th>
19 20 </tr> </tr>
File root/themes/default/user/repo/rights/list_repo/line.html changed (mode: 100644) (index 1b1ab70..2ac646e)
6 6 <td>@@username@@</td> <td>@@username@@</td>
7 7 <td>@@nice.ip@@</td> <td>@@nice.ip@@</td>
8 8 <td>@@rights_text@@</td> <td>@@rights_text@@</td>
9 <td>
10 <a href="@@url_repo@@/admin/repo_rights?edit_id=@@right_id@@">Edit</a>
11 </td>
9 <td>@@desc@@</td>
10 <td>@@if(@@can_be_deleted@@ == 1){{<a href="@@url_repo@@/admin/repo_rights?edit_id=@@right_id@@">Edit</a>}}{{N/A}}</td>
12 11 </tr> </tr>
File root/themes/default/user/repo/rights/list_repo_path/header.html changed (mode: 100644) (index e2065de..440f7d1)
16 16 <th>IP</th> <th>IP</th>
17 17 <th>Path</th> <th>Path</th>
18 18 <th>Path rights</th> <th>Path rights</th>
19 <th>Description</th>
19 20 <th>Operations</th> <th>Operations</th>
20 21 </tr> </tr>
File root/themes/default/user/repo/rights/list_repo_path/line.html changed (mode: 100644) (index 7e29b40..df4a5b5)
7 7 <td>@@nice.ip@@</td> <td>@@nice.ip@@</td>
8 8 <td>@@misc@@</td> <td>@@misc@@</td>
9 9 <td>@@rights_text@@</td> <td>@@rights_text@@</td>
10 <td>
11 <a href="@@url_repo@@/admin/path_rights?edit_id=@@right_id@@">Edit</a>
12 </td>
10 <td>@@desc@@</td>
11 <td>@@if(@@can_be_deleted@@ == 1){{<a href="@@url_repo@@/admin/path_rights?edit_id=@@right_id@@">Edit</a>}}{{N/A}}</td>
13 12 </tr> </tr>
File root/themes/default/user/repo/rights/list_repo_refs/header.html changed (mode: 100644) (index 9310164..7fd17e0)
16 16 <th>IP</th> <th>IP</th>
17 17 <th>Ref</th> <th>Ref</th>
18 18 <th>Refs rights</th> <th>Refs rights</th>
19 <th>Description</th>
19 20 <th>Operations</th> <th>Operations</th>
20 21 </tr> </tr>
File root/themes/default/user/repo/rights/list_repo_refs/line.html changed (mode: 100644) (index 4d459cd..e10cb9d)
7 7 <td>@@nice.ip@@</td> <td>@@nice.ip@@</td>
8 8 <td>@@misc@@</td> <td>@@misc@@</td>
9 9 <td>@@rights_text@@</td> <td>@@rights_text@@</td>
10 <td>
11 <a href="@@url_repo@@/admin/refs_rights?edit_id=@@right_id@@">Edit</a>
12 </td>
10 <td>@@desc@@</td>
11 <td>@@if(@@can_be_deleted@@ == 1){{<a href="@@url_repo@@/admin/refs_rights?edit_id=@@right_id@@">Edit</a>}}{{N/A}}</td>
13 12 </tr> </tr>
File tests/Makefile changed (mode: 100644) (index 87f3c32..84808fd)
... ... hook_update_anon_nm:
54 54
55 55 .PHONY: clean .PHONY: clean
56 56 clean: clean:
57 @rm -f *.log *.strace *.out *.lock
57 @rm -f *.log *.strace *.out *.lock err-*
File tests/cache.php changed (mode: 100644) (index b4fd571..98cea4b)
... ... require_once($INC . "/cache.inc.php");
10 10
11 11 rg_log_set_file("cache.log"); rg_log_set_file("cache.log");
12 12
13 $rg_no_db = TRUE;
13 14 require_once("common.php"); require_once("common.php");
14 15
15 16 rg_cache_core_set("a::b::c", "1"); rg_cache_core_set("a::b::c", "1");
File tests/common.php changed (mode: 100644) (index 52be00d..a0825f5)
... ... $rg_lang = "en";
34 34 $rg_cache_enable = FALSE; $rg_cache_enable = FALSE;
35 35 $rg_event_socket = ""; $rg_event_socket = "";
36 36
37 if (isset($rg_no_db) && $rg_no_db)
38 return;
39
37 40 $db = rg_sql_open("dbname=trg"); $db = rg_sql_open("dbname=trg");
38 41 if ($db === FALSE) { if ($db === FALSE) {
39 42 rg_log("Cannot create a database (" . rg_sql_error() . ")!"); rg_log("Cannot create a database (" . rg_sql_error() . ")!");
File tests/email.php changed (mode: 100644) (index ddbbf57..aabb6ef)
... ... require_once($INC . "/util.inc.php");
8 8
9 9 rg_log_set_file("email.log"); rg_log_set_file("email.log");
10 10
11 $rg_no_db = TRUE;
11 12 require_once("common.php"); require_once("common.php");
12 13
13 14 $rg_scripts = "../"; $rg_scripts = "../";
File tests/git.php changed (mode: 100644) (index ddda7f2..27767db)
... ... require_once($INC . "/git.inc.php");
8 8
9 9 rg_log_set_file("git.log"); rg_log_set_file("git.log");
10 10
11 $rg_no_db = TRUE;
11 12 require_once("common.php"); require_once("common.php");
12 13
13 14 echo "[*] Checking if git-init works...\n"; echo "[*] Checking if git-init works...\n";
File tests/git2.php changed (mode: 100644) (index 986d038..59c32e2)
... ... require_once($INC . "/git.inc.php");
8 8
9 9 rg_log_set_file("git2.log"); rg_log_set_file("git2.log");
10 10
11 $rg_no_db = TRUE;
11 12 require_once("common.php"); require_once("common.php");
12 13
13 14 system("./git2.sh"); system("./git2.sh");
File tests/log.php changed (mode: 100644) (index 3e48262..a94138c)
... ... require_once($INC . "/log.inc.php");
9 9
10 10 rg_log_set_file("log.log"); rg_log_set_file("log.log");
11 11
12 $rg_no_db = TRUE;
12 13 require_once("common.php"); require_once("common.php");
13 14
14 15 $n = "șacal\n\t"; $n = "șacal\n\t";
File tests/prof.php changed (mode: 100644) (index 9aa8fe9..7faae86)
... ... require_once($INC . "/prof.inc.php");
10 10
11 11 rg_log_set_file("prof.log"); rg_log_set_file("prof.log");
12 12
13 $rg_no_db = TRUE;
13 14 require_once("common.php"); require_once("common.php");
14 15
15 16 rg_prof_start("label1"); rg_prof_start("label1");
File tests/rights.php changed (mode: 100644) (index c509cdd..a4ddacd)
... ... $a['uid'] = 200;
68 68 $a['rights'] = "abc"; $a['rights'] = "abc";
69 69 $a['misc'] = "misc1"; $a['misc'] = "misc1";
70 70 $a['ip'] = "1.1.1.1 2.2.2.2 10.0.0.0/8"; $a['ip'] = "1.1.1.1 2.2.2.2 10.0.0.0/8";
71 $a['prio'] = 3;
71 $a['prio'] = 13;
72 72 $r = rg_rights_set($db, "type1", $a); $r = rg_rights_set($db, "type1", $a);
73 73 if ($r !== TRUE) { if ($r !== TRUE) {
74 74 echo "Seems I cannot set rights 1 (" . rg_rights_error() . ")\n"; echo "Seems I cannot set rights 1 (" . rg_rights_error() . ")\n";
75 75 exit(1); exit(1);
76 76 } }
77 $a['rights'] = "d"; $a['misc'] = "misc2"; $a['prio'] = 4;
77 $a['rights'] = "d"; $a['misc'] = "misc2"; $a['prio'] = 14;
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 80 echo "Seems I cannot set rights 2 (" . rg_rights_error() . ")\n"; echo "Seems I cannot set rights 2 (" . rg_rights_error() . ")\n";
81 81 exit(1); exit(1);
82 82 } }
83 $a['rights'] = "E"; $a['misc'] = "misc3"; $a['prio'] = 4;
83 $a['rights'] = "E"; $a['misc'] = "misc3"; $a['prio'] = 14;
84 84 $r = rg_rights_set($db, "type2", $a); $r = rg_rights_set($db, "type2", $a);
85 85 if ($r !== TRUE) { if ($r !== TRUE) {
86 86 echo "Seems I cannot set rights 2 (" . rg_rights_error() . ")\n"; echo "Seems I cannot set rights 2 (" . rg_rights_error() . ")\n";
 
... ... if ($r !== TRUE) {
89 89
90 90 rg_log("Testing rg_rights_get..."); rg_log("Testing rg_rights_get...");
91 91 $right_id = 0; $right_id = 0;
92 $r = rg_rights_get($db, $a['obj_id'], "type1", $uid, $a['uid'], $right_id);
92 $r = rg_rights_get($db, $a['obj_id'], "type1", $a['who'], $a['uid'], $right_id);
93 93 if (($r['ok'] !== 1) || (strcmp($r['list'][1]['rights'], "d") != 0)) { if (($r['ok'] !== 1) || (strcmp($r['list'][1]['rights'], "d") != 0)) {
94 94 echo "Seems I cannot get rights (" . rg_rights_error() . ")\n"; echo "Seems I cannot get rights (" . rg_rights_error() . ")\n";
95 95 print_r($r); print_r($r);
96 96 exit (1); exit (1);
97 97 } }
98 98 // 'get' again, to see if cache works // 'get' again, to see if cache works
99 $r = rg_rights_get($db, $a['obj_id'], "type1", $uid, $a['uid'], $right_id);
99 $r = rg_rights_get($db, $a['obj_id'], "type1", $a['who'], $a['uid'], $right_id);
100 100 if (($r['ok'] !== 1) || (strcmp($r['list'][1]['rights'], "d") != 0)) { if (($r['ok'] !== 1) || (strcmp($r['list'][1]['rights'], "d") != 0)) {
101 101 echo "Seems I cannot get rights (" . rg_rights_error() . ")\n"; echo "Seems I cannot get rights (" . rg_rights_error() . ")\n";
102 102 print_r($r); print_r($r);
 
... ... if ($r !== TRUE) {
111 111 exit(1); exit(1);
112 112 } }
113 113 $right_id = 0; $right_id = 0;
114 $r = rg_rights_get($db, $a['obj_id'], "type1", $uid, $a['uid'], $right_id);
114 $r = rg_rights_get($db, $a['obj_id'], "type1", $a['who'], $a['uid'], $right_id);
115 115 if (($r['ok'] !== 1) || (count($r['list']) > 0)) { if (($r['ok'] !== 1) || (count($r['list']) > 0)) {
116 116 echo "We should not have anymore type1 objects, after a delete.\n"; echo "We should not have anymore type1 objects, after a delete.\n";
117 117 print_r($r); print_r($r);
File tests/themes/util/func.txt added (mode: 100644) (index 0000000..df89500)
1 @@uid@@ + 1 = @@func:inc:uid@@ | @@uid@@ - 1 = @@func:dec:uid@@ | @@func:dec:uid@@
File tests/user.php changed (mode: 100644) (index 65b1458..58e9c3a)
... ... if ($r['ok'] != 1) {
32 32 exit(1); exit(1);
33 33 } }
34 34
35
36 // Test if empty uid/user/email returns error
37 $_ui = rg_user_info($db, 0, "", "");
38 if ($_ui['ok'] == 1) {
39 echo "Seems that invalid user does not return error!\n";
40 exit(1);
41 }
42
43
35 44 // add user // add user
36 45 $_u['uid'] = 0; $_u['uid'] = 0;
37 46 $_u['realname'] = "userA real name"; $_u['realname'] = "userA real name";
File tests/util.php changed (mode: 100644) (index d140fe2..b402137)
... ... require_once($INC . "/log.inc.php");
9 9
10 10 rg_log_set_file("util.log"); rg_log_set_file("util.log");
11 11
12 $rg_no_db = TRUE;
12 13 require_once("common.php"); require_once("common.php");
13 14
15
16 // Test template functions
17 function inc($v) { return $v + 1; }
18 function dec($v) { return $v - 1; }
19 rg_template_func("inc", "inc");
20 rg_template_func("dec", "dec");
21 $_rg = array("uid" => 5);
22 $r = trim(rg_template("func.txt", $_rg));
23 $e = "5 + 1 = 6 | 5 - 1 = 4 | 4";
24 if (strcmp($r, $e) != 0) {
25 echo "template func1 test failed [$r] != [$e]\n";
26 exit(1);
27 }
28
29
14 30 $id = rg_id(16); $id = rg_id(16);
15 31 if (strlen($id) != 16) { if (strlen($id) != 16) {
16 32 echo "Cannot generate an id!\n"; echo "Cannot generate an id!\n";
 
... ... if (strcmp($x2, $e) != 0) {
324 340 $src = array(); $src = array();
325 341 $a = array("u" => "uval", "HTML:A" => "Aval"); $a = array("u" => "uval", "HTML:A" => "Aval");
326 342 $x = rg_array_merge($src, "X", $a); $x = rg_array_merge($src, "X", $a);
327 if (strcmp($x['HTML:X.A'], "Aval") != 0) {
328 echo "array_merge is not working correctly (1)!\n";
343 if (strcmp($x['X.u'], "uval") != 0) {
344 echo "array_merge is not working correctly (2)!\n";
329 345 print_r($x); print_r($x);
330 346 exit(1); exit(1);
331 347 } }
332 if (strcmp($x['X.u'], "uval") != 0) {
333 echo "array_merge is not working correctly (2)!\n";
348 if (strcmp($x['HTML:X.A'], "Aval") != 0) {
349 echo "array_merge is not working correctly (1)!\n";
334 350 print_r($x); print_r($x);
335 351 exit(1); exit(1);
336 352 } }
337 353
354
338 355 echo "util: OK!\n"; echo "util: OK!\n";
339 356 ?> ?>
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