| 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/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 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); |