File inc/bug.inc.php changed (mode: 100644) (index 2ce9a07..002e383) |
... |
... |
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['ui::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_all($db, $event) |
89 |
89 |
$x = $event; |
$x = $event; |
90 |
90 |
$x['category'] = 4101; |
$x['category'] = 4101; |
91 |
91 |
$x['prio'] = 100; |
$x['prio'] = 100; |
|
92 |
|
$x['ui'] = array(); |
92 |
93 |
|
|
93 |
94 |
// 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); |
|
|
95 |
|
$r = rg_watch_load_by_obj_id($db, "repo", $event['ri']['repo_id'], 0); |
95 |
96 |
if ($r === FALSE) |
if ($r === FALSE) |
96 |
97 |
return FALSE; |
return FALSE; |
97 |
98 |
if (!empty($r)) { |
if (!empty($r)) { |
98 |
99 |
foreach ($r as $index => $uid) { |
foreach ($r as $index => $uid) { |
99 |
|
$x['ui::uid'] = $uid; |
|
|
100 |
|
$x['ui']['uid'] = $uid; |
100 |
101 |
$ret[$uid] = $x; |
$ret[$uid] = $x; |
101 |
102 |
} |
} |
102 |
103 |
} |
} |
103 |
104 |
|
|
104 |
105 |
// 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']); |
|
|
106 |
|
$r = rg_watch_load_by_obj_id($db, 'bug', $event['ri']['repo_id'], |
|
107 |
|
$event['bug']['bug_id']); |
107 |
108 |
if ($r === FALSE) |
if ($r === FALSE) |
108 |
109 |
return FALSE; |
return FALSE; |
109 |
110 |
if (!empty($r)) { |
if (!empty($r)) { |
110 |
111 |
foreach ($r as $index => $uid) { |
foreach ($r as $index => $uid) { |
111 |
|
$x['ui::uid'] = $uid; |
|
|
112 |
|
$x['ui']['uid'] = $uid; |
112 |
113 |
$ret[$uid] = $x; |
$ret[$uid] = $x; |
113 |
114 |
} |
} |
114 |
115 |
} |
} |
|
... |
... |
function rg_bug_event_note_add_one($db, $event) |
127 |
128 |
$ret = FALSE; |
$ret = FALSE; |
128 |
129 |
while (1) { |
while (1) { |
129 |
130 |
// lookup user email |
// lookup user email |
130 |
|
$ui = rg_user_info($db, $event['ui::uid'], "", ""); |
|
|
131 |
|
$ui = rg_user_info($db, $event['ui']['uid'], '', ''); |
131 |
132 |
if ($ui['exists'] != 1) { |
if ($ui['exists'] != 1) { |
132 |
133 |
rg_internal_error("User does not exists!"); |
rg_internal_error("User does not exists!"); |
133 |
134 |
break; |
break; |
|
... |
... |
function rg_bug_event_note_add_one($db, $event) |
139 |
140 |
} |
} |
140 |
141 |
|
|
141 |
142 |
// send e-mail |
// send e-mail |
142 |
|
$event['ui::email'] = $ui['email']; |
|
|
143 |
|
$event['ui']['email'] = $ui['email']; |
143 |
144 |
$r = rg_mail_template("mail/user/repo/bug/new_note", $event); |
$r = rg_mail_template("mail/user/repo/bug/new_note", $event); |
144 |
145 |
if ($r === FALSE) |
if ($r === FALSE) |
145 |
146 |
break; |
break; |
|
... |
... |
function rg_bug_event_note_add_all($db, $event) |
163 |
164 |
$x = $event; |
$x = $event; |
164 |
165 |
$x['category'] = 4001; |
$x['category'] = 4001; |
165 |
166 |
$x['prio'] = 100; |
$x['prio'] = 100; |
|
167 |
|
$x['ui'] = array(); |
166 |
168 |
|
|
167 |
169 |
// 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::bug_id']); |
|
|
170 |
|
$r = rg_watch_load_by_obj_id($db, 'bug', $event['ri']['repo_id'], |
|
171 |
|
$event['bug']['bug_id']); |
170 |
172 |
if ($r === FALSE) |
if ($r === FALSE) |
171 |
173 |
return FALSE; |
return FALSE; |
172 |
174 |
if (!empty($r)) { |
if (!empty($r)) { |
173 |
175 |
foreach ($r as $index => $uid) { |
foreach ($r as $index => $uid) { |
174 |
|
$x['ui::uid'] = $uid; |
|
|
176 |
|
$x['ui']['uid'] = $uid; |
175 |
177 |
$ret[] = $x; |
$ret[] = $x; |
176 |
178 |
} |
} |
177 |
179 |
} |
} |
|
... |
... |
function rg_bug_edit($db, $login_ui, $ri, $data) |
502 |
504 |
|
|
503 |
505 |
// TODO: seems I do not distinguish between 'add' and 'edit' |
// TODO: seems I do not distinguish between 'add' and 'edit' |
504 |
506 |
$event = array("category" => 4100, "prio" => 200, |
$event = array("category" => 4100, "prio" => 200, |
505 |
|
"repo::repo_id" => $ri['repo_id'], |
|
506 |
|
"repo::name" => $ri['name'], |
|
507 |
|
"bug::who_added" => $login_ui['uid'], |
|
508 |
|
"bug::who_added_text" => $login_ui['username'], |
|
509 |
|
"bug::url" => rg_base_url() . rg_re_bugpage($login_ui, $ri['name'], $data['bug_id']), |
|
510 |
|
"bug::assigned_to_text" => $assigned_to_text, |
|
511 |
|
"bug::state_text" => rg_bug_state($data['state'])); |
|
512 |
|
$event = rg_array_merge($event, "bug", $data); |
|
|
507 |
|
'ri' => array( |
|
508 |
|
'repo_id' => $ri['repo_id'], |
|
509 |
|
'name' => $ri['name']), |
|
510 |
|
'bug' => array( |
|
511 |
|
'who_added' => $login_ui['uid'], |
|
512 |
|
'who_added_text' => $login_ui['username'], |
|
513 |
|
'url' => rg_base_url() . rg_re_bugpage($login_ui, $ri['name'], $data['bug_id']), |
|
514 |
|
'assigned_to_text' => $assigned_to_text, |
|
515 |
|
'state_text' => rg_bug_state($data['state']))); |
|
516 |
|
$event = rg_array_merge($event, 'bug', $data); |
513 |
517 |
$r = rg_event_add($db, $event); |
$r = rg_event_add($db, $event); |
514 |
518 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
515 |
519 |
rg_bug_set_error("cannot add event" |
rg_bug_set_error("cannot add event" |
|
... |
... |
function rg_bug_edit($db, $login_ui, $ri, $data) |
527 |
531 |
// update cache |
// update cache |
528 |
532 |
$data['ok'] = 1; |
$data['ok'] = 1; |
529 |
533 |
$data['exists'] = 1; |
$data['exists'] = 1; |
530 |
|
$key = $ri['repo_id'] . "::bugs::" . $data['bug_id']; |
|
531 |
534 |
rg_bug_cosmetic($db, $data); |
rg_bug_cosmetic($db, $data); |
|
535 |
|
$key = $ri['repo_id'] . "::bugs::" . $data['bug_id']; |
532 |
536 |
rg_cache_set($key, $data); |
rg_cache_set($key, $data); |
533 |
537 |
|
|
534 |
538 |
rg_event_signal_daemon("", 0); |
rg_event_signal_daemon("", 0); |
|
... |
... |
function rg_bug_delete_undelete($db, $who, $repo_id, $bug_id, $op) |
581 |
585 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
582 |
586 |
|
|
583 |
587 |
// update cache |
// update cache |
584 |
|
$key = $repo_id . "::bugs::" . $bug_id; |
|
585 |
588 |
$new = array(); |
$new = array(); |
586 |
589 |
$new['deleted'] = $deleted; |
$new['deleted'] = $deleted; |
587 |
590 |
$new['utime'] = $now; |
$new['utime'] = $now; |
588 |
591 |
$new['deleted_who'] = $who; |
$new['deleted_who'] = $who; |
589 |
592 |
rg_bug_cosmetic($db, $new); |
rg_bug_cosmetic($db, $new); |
|
593 |
|
$key = $repo_id . "::bugs::" . $bug_id; |
590 |
594 |
rg_cache_merge($key, $new); |
rg_cache_merge($key, $new); |
591 |
595 |
|
|
592 |
596 |
$ret = TRUE; |
$ret = TRUE; |
|
... |
... |
function rg_bug_note_add($db, $repo_id, $bug_id, $login_uid, $data) |
1020 |
1024 |
} |
} |
1021 |
1025 |
|
|
1022 |
1026 |
$event = array("category" => 4000, "prio" => 200, |
$event = array("category" => 4000, "prio" => 200, |
1023 |
|
"bug::bug_id" => $bug_id, |
|
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), |
|
1028 |
|
"note" => $data['note'], |
|
1029 |
|
"note::who_added" => $login_uid, |
|
1030 |
|
"note::who_added_text" => $_ui['username']); |
|
|
1027 |
|
'bug' => array( |
|
1028 |
|
'bug_id' => $bug_id, |
|
1029 |
|
'title' => $_bi['title'], |
|
1030 |
|
'url' => rg_base_url() . rg_re_bugpage($_ui, $_ri['name'], $bug_id)), |
|
1031 |
|
'ri' => array( |
|
1032 |
|
'repo_id' => $repo_id, |
|
1033 |
|
'name' => $_ri['name']), |
|
1034 |
|
'note' => array( |
|
1035 |
|
'body' => $data['note'], |
|
1036 |
|
'who_added' => $login_uid, |
|
1037 |
|
'who_added_text' => $_ui['username'])); |
1031 |
1038 |
$r = rg_event_add($db, $event); |
$r = rg_event_add($db, $event); |
1032 |
1039 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
1033 |
1040 |
rg_bug_set_error("cannot add event" |
rg_bug_set_error("cannot add event" |
|
... |
... |
function rg_bug_edit_high_level($db, &$rg) |
1276 |
1283 |
$x['ip'] = $rg['ip']; |
$x['ip'] = $rg['ip']; |
1277 |
1284 |
$x['misc'] = ''; |
$x['misc'] = ''; |
1278 |
1285 |
if (rg_rights_allow($db, $x) !== TRUE) { |
if (rg_rights_allow($db, $x) !== TRUE) { |
1279 |
|
$ret .= rg_template("repo/bug/deny_edit.html", $rg); |
|
|
1286 |
|
$ret .= rg_template("repo/bug/deny_edit.html", $rg, TRUE /* xss */); |
1280 |
1287 |
break; |
break; |
1281 |
1288 |
} |
} |
1282 |
1289 |
|
|
|
... |
... |
function rg_bug_edit_high_level($db, &$rg) |
1288 |
1295 |
break; |
break; |
1289 |
1296 |
} |
} |
1290 |
1297 |
|
|
1291 |
|
$rg['bug'] = rg_array_merge($rg['bug'], "", rg_bug_vars()); |
|
|
1298 |
|
$rg['bug'] = rg_array_merge($rg['bug'], '', rg_bug_vars()); |
1292 |
1299 |
|
|
1293 |
1300 |
if (!rg_valid_referer()) { |
if (!rg_valid_referer()) { |
1294 |
1301 |
$errmsg[] = "invalid referer; try again"; |
$errmsg[] = "invalid referer; try again"; |
|
... |
... |
function rg_bug_edit_high_level($db, &$rg) |
1325 |
1332 |
rg_bug_state_select($rg['bug']['state'], $exclude); |
rg_bug_state_select($rg['bug']['state'], $exclude); |
1326 |
1333 |
|
|
1327 |
1334 |
$hints = array(); |
$hints = array(); |
1328 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/bug/add.html", $rg); |
|
|
1335 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/bug/add.html", $rg, TRUE /* xss */); |
1329 |
1336 |
$rg['HTML:bug_edit_hints'] = rg_template_table("hints/list", $hints, $rg); |
$rg['HTML:bug_edit_hints'] = rg_template_table("hints/list", $hints, $rg); |
1330 |
1337 |
|
|
1331 |
|
$ret .= rg_template("repo/bug/bug_add_edit.html", $rg); |
|
|
1338 |
|
$ret .= rg_template("repo/bug/bug_add_edit.html", $rg, TRUE /* xss */); |
1332 |
1339 |
} |
} |
1333 |
1340 |
|
|
1334 |
1341 |
rg_log_exit(); |
rg_log_exit(); |
File inc/git.inc.php changed (mode: 100644) (index cc54913..a76f6d6) |
... |
... |
function rg_git_ls_tree($tree, $path) |
480 |
480 |
|
|
481 |
481 |
// We are forced to use print_r instead of array2string because |
// We are forced to use print_r instead of array2string because |
482 |
482 |
// it may be a multilevel array. |
// it may be a multilevel array. |
483 |
|
rg_log_ml("DEBUG: ls-tree: " . print_r($ret, TRUE)); |
|
|
483 |
|
//rg_log_ml("DEBUG: ls-tree: " . print_r($ret, TRUE)); |
484 |
484 |
|
|
485 |
485 |
rg_log_exit(); |
rg_log_exit(); |
486 |
486 |
rg_prof_end("git_ls_tree"); |
rg_prof_end("git_ls_tree"); |
|
... |
... |
function rg_git_diff($a, $template_file) |
921 |
921 |
$ret = "<div class=\"diff\">\n"; |
$ret = "<div class=\"diff\">\n"; |
922 |
922 |
|
|
923 |
923 |
$x = array(); |
$x = array(); |
924 |
|
$template = rg_template($template_file, $x); |
|
|
924 |
|
$template = rg_template($template_file, $x, TRUE /* xss */); |
925 |
925 |
|
|
926 |
926 |
// for each file changed |
// for each file changed |
927 |
927 |
foreach ($a as $fileindex => $finfo) { |
foreach ($a as $fileindex => $finfo) { |
|
... |
... |
function rg_git_diff($a, $template_file) |
930 |
930 |
$ret .= "<br />\n"; |
$ret .= "<br />\n"; |
931 |
931 |
|
|
932 |
932 |
$f = rg_xss_safe($finfo['file']); |
$f = rg_xss_safe($finfo['file']); |
933 |
|
$ret .= "<a name=\"$f\"></a>\n"; |
|
|
933 |
|
$ret .= "<a name=\"file-$f\"></a>\n"; |
934 |
934 |
|
|
935 |
|
$ret .= "<table class=\"chunk\">\n"; |
|
|
935 |
|
$ret .= "<table class=\"chunk\" summary=\"chunk\">\n"; |
936 |
936 |
$ret .= "<tr style=\"border: 1px; background: #dddddd\"><td colspan=\"4\">"; |
$ret .= "<tr style=\"border: 1px; background: #dddddd\"><td colspan=\"4\">"; |
937 |
937 |
if (strstr($finfo['flags'], "N")) |
if (strstr($finfo['flags'], "N")) |
938 |
938 |
$ret .= "File <b>$f</b> added"; |
$ret .= "File <b>$f</b> added"; |
|
... |
... |
function rg_git_diff($a, $template_file) |
985 |
985 |
$line_no_left = $ci['from']; |
$line_no_left = $ci['from']; |
986 |
986 |
$line_no_right = $ci['to']; |
$line_no_right = $ci['to']; |
987 |
987 |
foreach ($ci['lines'] as $line) { |
foreach ($ci['lines'] as $line) { |
988 |
|
$v = $template; |
|
989 |
|
|
|
990 |
|
$left_color = "#eeeeee"; |
|
991 |
|
$right_color = "#eeeeee"; |
|
|
988 |
|
$left_class = 'cl-e'; |
|
989 |
|
$right_class = 'cl-e'; |
992 |
990 |
|
|
993 |
991 |
$c = substr($line, 0, 1); |
$c = substr($line, 0, 1); |
994 |
|
$line = substr($line, 1); |
|
|
992 |
|
$line = rg_xss_safe(substr($line, 1)); |
995 |
993 |
if (strcmp($c, "+") == 0) { |
if (strcmp($c, "+") == 0) { |
996 |
|
$left = ""; |
|
|
994 |
|
$left = ''; |
997 |
995 |
$right = $line; |
$right = $line; |
998 |
|
$right_color = "#00ff00"; |
|
999 |
|
$line_left = " "; |
|
|
996 |
|
$right_class = "cl-g"; |
|
997 |
|
$line_left = ''; |
1000 |
998 |
$line_right = $line_no_right; |
$line_right = $line_no_right; |
1001 |
999 |
$line_no_right++; |
$line_no_right++; |
1002 |
1000 |
} else if (strcmp($c, "-") == 0) { |
} else if (strcmp($c, "-") == 0) { |
1003 |
1001 |
$left = $line; |
$left = $line; |
1004 |
|
$left_color = "#ff0000"; |
|
1005 |
|
$right = ""; |
|
|
1002 |
|
$left_class = "cl-r"; |
|
1003 |
|
$right = ''; |
1006 |
1004 |
$line_left = $line_no_left; |
$line_left = $line_no_left; |
1007 |
|
$line_right = " "; |
|
|
1005 |
|
$line_right = ''; |
1008 |
1006 |
$line_no_left++; |
$line_no_left++; |
1009 |
1007 |
} else { // ' ' or any other character |
} else { // ' ' or any other character |
1010 |
1008 |
$left = $line; |
$left = $line; |
|
... |
... |
function rg_git_diff($a, $template_file) |
1015 |
1013 |
$line_no_right++; |
$line_no_right++; |
1016 |
1014 |
} |
} |
1017 |
1015 |
|
|
1018 |
|
$v = preg_replace("/@@line_left@@/", $line_left, $v); |
|
1019 |
|
$v = preg_replace("/@@line_right@@/", $line_right, $v); |
|
1020 |
|
$v = preg_replace("/@@left@@/", rg_xss_safe($left), $v); |
|
1021 |
|
$v = preg_replace("/@@right@@/", rg_xss_safe($right), $v); |
|
1022 |
|
|
|
1023 |
|
$v = preg_replace("/@@left_color@@/", $left_color, $v); |
|
1024 |
|
$v = preg_replace("/@@right_color@@/", $right_color, $v); |
|
1025 |
|
$ret .= $v; |
|
|
1016 |
|
$a = array( |
|
1017 |
|
'line_left' => $line_left, |
|
1018 |
|
'line_right' => $line_right, |
|
1019 |
|
'left' => $left, |
|
1020 |
|
'right' => $right, |
|
1021 |
|
'left_class' => $left_class, |
|
1022 |
|
'right_class' => $right_class |
|
1023 |
|
); |
|
1024 |
|
|
|
1025 |
|
$ret .= rg_template_string($template, 0 /*off*/, |
|
1026 |
|
$a, FALSE /*xss_protection*/); |
1026 |
1027 |
} |
} |
1027 |
1028 |
} |
} |
1028 |
1029 |
$ret .= "</table>\n"; |
$ret .= "</table>\n"; |
|
... |
... |
function rg_git_update_tag($db, $a) |
1065 |
1066 |
$x = array(); |
$x = array(); |
1066 |
1067 |
$x['obj_id'] = $a['repo_id']; |
$x['obj_id'] = $a['repo_id']; |
1067 |
1068 |
$x['type'] = 'repo_refs'; |
$x['type'] = 'repo_refs'; |
1068 |
|
$x['owner'] = $a['repo::uid']; |
|
|
1069 |
|
$x['owner'] = $a['repo_uid']; |
1069 |
1070 |
$x['uid'] = $a['login_uid']; |
$x['uid'] = $a['login_uid']; |
1070 |
1071 |
$x['username'] = $a['login_username']; |
$x['username'] = $a['login_username']; |
1071 |
1072 |
$x['needed_rights'] = ''; |
$x['needed_rights'] = ''; |
1072 |
1073 |
$x['ip'] = $a['ip']; |
$x['ip'] = $a['ip']; |
1073 |
1074 |
$x['misc'] = $a['refname']; |
$x['misc'] = $a['refname']; |
1074 |
1075 |
|
|
1075 |
|
$history = array(); |
|
1076 |
|
$history['ri::repo_id'] = $a['repo_id']; |
|
1077 |
|
$history['ui::uid'] = $a['login_uid']; |
|
|
1076 |
|
$history = array('ri' => array(), 'ui' => array()); |
|
1077 |
|
$history['ri']['repo_id'] = $a['repo_id']; |
|
1078 |
|
$history['ui']['uid'] = $a['login_uid']; |
1078 |
1079 |
|
|
1079 |
1080 |
if (strcmp($a['new_rev_type'], "tag") == 0) { // Annotated |
if (strcmp($a['new_rev_type'], "tag") == 0) { // Annotated |
1080 |
1081 |
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create |
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create |
|
... |
... |
function rg_git_update_branch($db, $a) |
1171 |
1172 |
$_x = array(); |
$_x = array(); |
1172 |
1173 |
$_x['obj_id'] = $a['repo_id']; |
$_x['obj_id'] = $a['repo_id']; |
1173 |
1174 |
$_x['type'] = 'repo_refs'; |
$_x['type'] = 'repo_refs'; |
1174 |
|
$_x['owner'] = $a['repo::uid']; |
|
|
1175 |
|
$_x['owner'] = $a['repo_uid']; |
1175 |
1176 |
$_x['uid'] = $a['login_uid']; |
$_x['uid'] = $a['login_uid']; |
1176 |
1177 |
$_x['username'] = $a['login_username']; |
$_x['username'] = $a['login_username']; |
1177 |
1178 |
$_x['needed_rights'] = ''; |
$_x['needed_rights'] = ''; |
1178 |
1179 |
$_x['ip'] = $a['ip']; |
$_x['ip'] = $a['ip']; |
1179 |
1180 |
$_x['misc'] = $a['refname']; |
$_x['misc'] = $a['refname']; |
1180 |
1181 |
|
|
1181 |
|
$history = array(); |
|
1182 |
|
$history['ri::repo_id'] = $a['repo_id']; |
|
1183 |
|
$history['ui::uid'] = $a['login_uid']; |
|
|
1182 |
|
$history = array('ri' => array(), 'ui' => array()); |
|
1183 |
|
$history['ri']['repo_id'] = $a['repo_id']; |
|
1184 |
|
$history['ui']['uid'] = $a['login_uid']; |
1184 |
1185 |
|
|
1185 |
1186 |
if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete |
if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete |
1186 |
1187 |
$x = $_x; |
$x = $_x; |
|
... |
... |
function rg_git_update_branch($db, $a) |
1278 |
1279 |
$x['needed_rights'] = 'H'; |
$x['needed_rights'] = 'H'; |
1279 |
1280 |
if (rg_rights_allow($db, $x) !== TRUE) { |
if (rg_rights_allow($db, $x) !== TRUE) { |
1280 |
1281 |
$_z = array(); |
$_z = array(); |
1281 |
|
$msg = rg_template("msg/push_not_allowed.txt", $_z); |
|
|
1282 |
|
$msg = rg_template("msg/push_not_allowed.txt", $_z, FALSE /* xss */); |
1282 |
1283 |
rg_git_fatal($a['refname']. "\n" . $msg); |
rg_git_fatal($a['refname']. "\n" . $msg); |
1283 |
1284 |
} |
} |
1284 |
1285 |
|
|
|
... |
... |
function rg_git_update_branch($db, $a) |
1286 |
1287 |
// TODO: git may fail to update the reference after this hook; |
// TODO: git may fail to update the reference after this hook; |
1287 |
1288 |
// the mr code should check if the update was done. |
// the mr code should check if the update was done. |
1288 |
1289 |
$mr = "refs/mr/" |
$mr = "refs/mr/" |
1289 |
|
. preg_replace('/refs\/heads\//', '', $a['refname']) |
|
1290 |
|
. "_" . preg_replace('/rg_/', '', $a['namespace']); |
|
|
1290 |
|
. str_replace('refs/heads/', '', $a['refname']) |
|
1291 |
|
. "_" . str_replace('rg_', '', $a['namespace']); |
1291 |
1292 |
$reason = $a['login_username'] . ' pushed a merge request' |
$reason = $a['login_username'] . ' pushed a merge request' |
1292 |
1293 |
. ' for ref ' . $a['refname'] |
. ' for ref ' . $a['refname'] |
1293 |
1294 |
. ' into namespace ' . $a['namespace']; |
. ' into namespace ' . $a['namespace']; |
|
... |
... |
function rg_git_update_branch($db, $a) |
1304 |
1305 |
if ($r !== TRUE) |
if ($r !== TRUE) |
1305 |
1306 |
rg_git_fatal($a['refname'] . ": " . rg_mr_error()); |
rg_git_fatal($a['refname'] . ": " . rg_mr_error()); |
1306 |
1307 |
$_x = array(); |
$_x = array(); |
1307 |
|
$msg = rg_template("msg/push_merge_request.txt", $_x); |
|
|
1308 |
|
$msg = rg_template("msg/push_merge_request.txt", $_x, FALSE /* xss */); |
1308 |
1309 |
rg_git_info($a['refname'] . "\n" . $msg); |
rg_git_info($a['refname'] . "\n" . $msg); |
1309 |
1310 |
|
|
1310 |
1311 |
$history['history_category'] = REPO_CAT_GIT_BRANCH_ANON_PUSH; |
$history['history_category'] = REPO_CAT_GIT_BRANCH_ANON_PUSH; |
|
... |
... |
function rg_git_branches_and_tags($repo_dir, $base_url, $current_ref) |
1375 |
1376 |
$current = ltrim($current_ref, "/"); |
$current = ltrim($current_ref, "/"); |
1376 |
1377 |
if (empty($current)) |
if (empty($current)) |
1377 |
1378 |
$current = "branch/master"; |
$current = "branch/master"; |
1378 |
|
rg_log("DEBUG: current=[$current]"); |
|
|
1379 |
|
//rg_log("DEBUG: current=[$current]"); |
1379 |
1380 |
|
|
1380 |
1381 |
$refs = rg_git_refs($repo_dir); |
$refs = rg_git_refs($repo_dir); |
1381 |
1382 |
$_l = array(); |
$_l = array(); |
|
... |
... |
function rg_git_branches_and_tags($repo_dir, $base_url, $current_ref) |
1385 |
1386 |
|
|
1386 |
1387 |
foreach ($list as $name) { |
foreach ($list as $name) { |
1387 |
1388 |
$name = rg_xss_safe($name); |
$name = rg_xss_safe($name); |
1388 |
|
$ename = preg_replace('/\//', ',', $name); |
|
|
1389 |
|
$ename = str_replace('/', ',', $name); |
1389 |
1390 |
//rg_log("DEBUG: compare with [" . $o . "/" . $ename . "]"); |
//rg_log("DEBUG: compare with [" . $o . "/" . $ename . "]"); |
1390 |
1391 |
if (strcmp($current, $o . "/" . $ename) == 0) { |
if (strcmp($current, $o . "/" . $ename) == 0) { |
1391 |
1392 |
$add_s = "<b>"; |
$add_s = "<b>"; |
|
... |
... |
function rg_git_parse_ref(&$paras) |
1444 |
1445 |
$val = array_shift($paras); |
$val = array_shift($paras); |
1445 |
1446 |
$ret['ref_url'] = "/" . $ret['ref_type'] . "/" . $val; |
$ret['ref_url'] = "/" . $ret['ref_type'] . "/" . $val; |
1446 |
1447 |
|
|
1447 |
|
$val = preg_replace('/,/', '/', $val); |
|
|
1448 |
|
$val = str_replace(',', '/', $val); |
1448 |
1449 |
$ret['ref_val'] = $val; |
$ret['ref_val'] = $val; |
1449 |
1450 |
$ret['ref_path'] .= $val; |
$ret['ref_path'] .= $val; |
1450 |
1451 |
|
|
|
... |
... |
function rg_git_diff_tree($tree1, $tree2) |
1488 |
1489 |
break; |
break; |
1489 |
1490 |
} |
} |
1490 |
1491 |
|
|
1491 |
|
rg_log("DEBUG: diff-tree: " . rg_array2string($ret)); |
|
|
1492 |
|
//rg_log("DEBUG: diff-tree: " . rg_array2string($ret)); |
1492 |
1493 |
|
|
1493 |
1494 |
rg_log_exit(); |
rg_log_exit(); |
1494 |
1495 |
rg_prof_end("git_diff_tree"); |
rg_prof_end("git_diff_tree"); |
|
... |
... |
function rg_git_content_by_file($treeish, $file) |
1530 |
1531 |
function rg_git_log2listing($log, $rg, $commit_table) |
function rg_git_log2listing($log, $rg, $commit_table) |
1531 |
1532 |
{ |
{ |
1532 |
1533 |
if ($log === FALSE) |
if ($log === FALSE) |
1533 |
|
return rg_template('repo/not_init.html', $rg); |
|
|
1534 |
|
return rg_template('repo/not_init.html', $rg, TRUE /* xss */); |
1534 |
1535 |
|
|
1535 |
1536 |
$ret = ''; |
$ret = ''; |
1536 |
1537 |
|
|
|
... |
... |
function rg_git_log2listing($log, $rg, $commit_table) |
1540 |
1541 |
foreach ($log as $index => $i) |
foreach ($log as $index => $i) |
1541 |
1542 |
$log[$index]['vars']['commit_url'] = |
$log[$index]['vars']['commit_url'] = |
1542 |
1543 |
rg_xss_safe($rg['mr']) |
rg_xss_safe($rg['mr']) |
1543 |
|
. "#" . rg_xss_safe($i['vars']['sha1_short']); |
|
|
1544 |
|
. "#sha1-" . rg_xss_safe($i['vars']['sha1_short']); |
1544 |
1545 |
$ret .= rg_git_log_template($log, 'repo/log', $rg); |
$ret .= rg_git_log_template($log, 'repo/log', $rg); |
1545 |
1546 |
} |
} |
1546 |
1547 |
|
|
|
... |
... |
function rg_git_log2listing($log, $rg, $commit_table) |
1548 |
1549 |
foreach ($log as $junk => $i) { |
foreach ($log as $junk => $i) { |
1549 |
1550 |
// Some info about commit |
// Some info about commit |
1550 |
1551 |
$ret .= "<br /><b>" |
$ret .= "<br /><b>" |
1551 |
|
. "<a name=\"" . rg_xss_safe($i['vars']['sha1_short']) . "\">" |
|
|
1552 |
|
. "<a name=\"sha1-" . rg_xss_safe($i['vars']['sha1_short']) . "\">" |
1552 |
1553 |
. "Commit " . rg_xss_safe($i['vars']['sha1_short']) |
. "Commit " . rg_xss_safe($i['vars']['sha1_short']) |
1553 |
1554 |
. "</a></b> - " . rg_xss_safe($i['vars']['subject']) . "\n"; |
. "</a></b> - " . rg_xss_safe($i['vars']['subject']) . "\n"; |
1554 |
1555 |
|
|
|
... |
... |
function rg_git_log2listing($log, $rg, $commit_table) |
1574 |
1575 |
$ret .= $r; |
$ret .= $r; |
1575 |
1576 |
|
|
1576 |
1577 |
// diff |
// diff |
|
1578 |
|
//rg_log_ml("DEBUG: i[files]=" . print_r($i['files'], TRUE)); |
1577 |
1579 |
$r = rg_git_diff($i['files'], 'repo/diff.html'); |
$r = rg_git_diff($i['files'], 'repo/diff.html'); |
1578 |
1580 |
if ($r === FALSE) |
if ($r === FALSE) |
1579 |
1581 |
return "Internal error"; |
return "Internal error"; |
File inc/keys.inc.php changed (mode: 100644) (index 13d3dfe..0b05323) |
... |
... |
function rg_keys_info($key) |
122 |
122 |
$ret['ok'] = 0; |
$ret['ok'] = 0; |
123 |
123 |
while(1) { |
while(1) { |
124 |
124 |
if (strpos($key, "PRIVATE KEY") !== FALSE) { |
if (strpos($key, "PRIVATE KEY") !== FALSE) { |
125 |
|
rg_keys_set_error("private instead of pulic key"); |
|
|
125 |
|
rg_keys_set_error("private instead of public key"); |
126 |
126 |
break; |
break; |
127 |
127 |
} |
} |
128 |
128 |
|
|
129 |
|
$t = explode(" ", $key, 3); |
|
|
129 |
|
// We must have at least key type and the key |
|
130 |
|
$t = explode(' ', $key, 2); |
130 |
131 |
if (!isset($t[1])) { |
if (!isset($t[1])) { |
131 |
132 |
rg_keys_set_error("malformed ssh key (missing fields)"); |
rg_keys_set_error("malformed ssh key (missing fields)"); |
132 |
133 |
break; |
break; |
133 |
134 |
} |
} |
134 |
|
|
|
135 |
135 |
$ret['type'] = $t[0]; |
$ret['type'] = $t[0]; |
136 |
|
$ret['key'] = $t[1]; |
|
137 |
|
$ret['comment'] = isset($t[2]) ? $t[2] : ""; |
|
138 |
136 |
|
|
139 |
|
$d = base64_decode($ret['key']); |
|
140 |
|
if ($d === FALSE) { |
|
141 |
|
rg_keys_set_error("malformed input (base64 failed)"); |
|
|
137 |
|
if ((strncmp($ret['type'], 'ssh-', 4) != 0) |
|
138 |
|
&& (strncmp($ret['type'], 'ecdsa-', 6) != 0)) { |
|
139 |
|
rg_keys_set_error("key does not start with ssh- or ecdsa-"); |
142 |
140 |
break; |
break; |
143 |
141 |
} |
} |
144 |
|
$digest = md5($d); |
|
145 |
142 |
|
|
|
143 |
|
// We try to detect the key because spaces may mess up things |
|
144 |
|
$ret['comment'] = ''; |
|
145 |
|
$error = TRUE; |
|
146 |
|
$off = 0; |
|
147 |
|
while (1) { |
|
148 |
|
rg_log("DEBUG: off=$off"); |
|
149 |
|
|
|
150 |
|
// -1 signals that we used the whole string |
|
151 |
|
if ($off == -1) |
|
152 |
|
break; |
|
153 |
|
|
|
154 |
|
$pos = strpos($t[1], ' ', $off); |
|
155 |
|
if ($pos === FALSE) { |
|
156 |
|
$ret['key'] = $t[1]; |
|
157 |
|
$off = -1; |
|
158 |
|
} else { |
|
159 |
|
$ret['key'] = substr($t[1], 0, $pos); |
|
160 |
|
$off = $pos + 1; |
|
161 |
|
} |
|
162 |
|
rg_log("DEBUG: pos=$pos off=$off key=" . $ret['key']); |
|
163 |
|
|
|
164 |
|
$d = base64_decode($ret['key']); |
|
165 |
|
if ($d === FALSE) { |
|
166 |
|
rg_keys_set_error("malformed ssh key (base64 failed)"); |
|
167 |
|
continue; |
|
168 |
|
} |
|
169 |
|
$d_len = strlen($d); |
|
170 |
|
rg_log("d=" . bin2hex($d)); |
|
171 |
|
rg_log("d_len=$d_len"); |
|
172 |
|
|
|
173 |
|
if (strlen($d) < 4) { |
|
174 |
|
rg_keys_set_error("key is too short (< 4)"); |
|
175 |
|
continue; |
|
176 |
|
} |
|
177 |
|
|
|
178 |
|
// First, we have the length of the string 'ssh-*' |
|
179 |
|
$_t = unpack('N', $d); |
|
180 |
|
$len = $_t[1]; |
|
181 |
|
rg_log_ml("len=$len"); |
|
182 |
|
if ($d_len < 4 + $len) { |
|
183 |
|
rg_keys_set_error("key is too short"); |
|
184 |
|
continue; |
|
185 |
|
} |
|
186 |
|
$type2 = substr($d, 4, $len); |
|
187 |
|
rg_log("DEBUG: type2=$type2"); |
|
188 |
|
if (strcasecmp($ret['type'], $type2) != 0) { |
|
189 |
|
rg_keys_set_error('key type mismatch: ' . $ret['type'] . ' != ' . $type2); |
|
190 |
|
break; |
|
191 |
|
} |
|
192 |
|
|
|
193 |
|
if (strcasecmp($ret['type'], 'ssh-rsa') == 0) { |
|
194 |
|
$count = 2; |
|
195 |
|
} else if (strcasecmp($ret['type'], 'ssh-dss') == 0) { |
|
196 |
|
$count = 4; |
|
197 |
|
} else if (strncasecmp($ret['type'], 'ecdsa-', 6) == 0) { |
|
198 |
|
$count = 2; |
|
199 |
|
} else if (strcasecmp($ret['type'], 'ssh-ed25519') == 0) { |
|
200 |
|
$count = 1; |
|
201 |
|
} else { |
|
202 |
|
rg_log('Strange key type: ' . $ret['type']); |
|
203 |
|
// Probably this is a new key type, just consider it valid |
|
204 |
|
$_t = explode(' ', $key, 3); |
|
205 |
|
$ret['key'] = $_t[1]; |
|
206 |
|
if (isset($_t[2])) |
|
207 |
|
$ret['comment'] = $_t[2]; |
|
208 |
|
$error = FALSE; |
|
209 |
|
break; |
|
210 |
|
} |
|
211 |
|
|
|
212 |
|
$have_all_chunks = TRUE; |
|
213 |
|
$used = 4 + $len; |
|
214 |
|
for ($i = 0; $i < $count; $i++) { |
|
215 |
|
if ($d_len < $used + 4) { |
|
216 |
|
rg_keys_set_error('key is too short (chunk length)'); |
|
217 |
|
$have_all_chunks = FALSE; |
|
218 |
|
break; |
|
219 |
|
} |
|
220 |
|
$_t = unpack('N', substr($d, $used, 4)); |
|
221 |
|
$xlen = $_t[1]; |
|
222 |
|
rg_log_ml("xlen=$xlen"); |
|
223 |
|
if ($d_len < $used + 4 + $xlen) { |
|
224 |
|
rg_keys_set_error("key is too short (chunk body)"); |
|
225 |
|
$have_all_chunks = FALSE; |
|
226 |
|
break; |
|
227 |
|
} |
|
228 |
|
|
|
229 |
|
$used += 4 + $xlen; |
|
230 |
|
} |
|
231 |
|
if ($have_all_chunks === FALSE) |
|
232 |
|
continue; |
|
233 |
|
|
|
234 |
|
$ret['comment'] = substr($t[1], $off); |
|
235 |
|
|
|
236 |
|
$error = FALSE; |
|
237 |
|
break; |
|
238 |
|
} |
|
239 |
|
if ($error) |
|
240 |
|
break; |
|
241 |
|
|
|
242 |
|
$digest = md5($d); |
146 |
243 |
$a = array(); |
$a = array(); |
147 |
244 |
for ($i = 0; $i < 16; $i++) |
for ($i = 0; $i < 16; $i++) |
148 |
245 |
$a[] = substr($digest, $i * 2, 2); |
$a[] = substr($digest, $i * 2, 2); |
|
... |
... |
function rg_keys_remove($db, $ui, $list) |
184 |
281 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
185 |
282 |
|
|
186 |
283 |
$event = array("category" => 1001, "prio" => 50, |
$event = array("category" => 1001, "prio" => 50, |
187 |
|
"ui::email" => $ui['confirmed'] > 0 ? $ui['email'] : "", |
|
|
284 |
|
'ui' => array('email' => $ui['confirmed'] > 0 ? $ui['email'] : ""), |
188 |
285 |
"keys" => implode(",", $my_list)); |
"keys" => implode(",", $my_list)); |
189 |
286 |
$r = rg_event_add($db, $event); |
$r = rg_event_add($db, $event); |
190 |
287 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
|
... |
... |
function rg_keys_add($db, $ui, $key) |
240 |
337 |
global $rg_max_ssh_keys; |
global $rg_max_ssh_keys; |
241 |
338 |
|
|
242 |
339 |
rg_prof_start("keys_add"); |
rg_prof_start("keys_add"); |
243 |
|
rg_log_enter("keys_add: $key=$key"); |
|
|
340 |
|
rg_log_enter("keys_add: key=$key"); |
244 |
341 |
|
|
245 |
342 |
$ret = FALSE; |
$ret = FALSE; |
246 |
343 |
$do_rollback = 0; |
$do_rollback = 0; |
|
... |
... |
function rg_keys_add($db, $ui, $key) |
290 |
387 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
291 |
388 |
|
|
292 |
389 |
$event = array("category" => 1000, "prio" => 50, |
$event = array("category" => 1000, "prio" => 50, |
293 |
|
"ui::email" => $ui['confirmed'] > 0 ? $ui['email'] : "", |
|
|
390 |
|
'ui' => array('email' => $ui['confirmed'] > 0 ? $ui['email'] : ""), |
294 |
391 |
"key_id" => $key_id); |
"key_id" => $key_id); |
295 |
392 |
$r = rg_event_add($db, $event); |
$r = rg_event_add($db, $event); |
296 |
393 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
File inc/repo.inc.php changed (mode: 100644) (index 45a9d33..3706700) |
... |
... |
function rg_repo_event_symlink_by_name($db, $e) |
305 |
305 |
|
|
306 |
306 |
rg_prof_start("repo_event_symlink_by_name"); |
rg_prof_start("repo_event_symlink_by_name"); |
307 |
307 |
|
|
308 |
|
$id_path = rg_repo_path_by_id($e['ui::uid'], $e['ri::repo_id']); |
|
309 |
|
$id_path_rel = rg_repo_path_by_id_rel($e['ui::uid'], $e['ri::repo_id']); |
|
310 |
|
$new_path = rg_repo_path_by_name($e['ui::uid'], $e['ri::name']); |
|
|
308 |
|
$id_path = rg_repo_path_by_id($e['ui']['uid'], $e['ri']['repo_id']); |
|
309 |
|
$id_path_rel = rg_repo_path_by_id_rel($e['ui']['uid'], $e['ri']['repo_id']); |
|
310 |
|
$new_path = rg_repo_path_by_name($e['ui']['uid'], $e['ri']['name']); |
311 |
311 |
|
|
312 |
312 |
$ret = FALSE; |
$ret = FALSE; |
313 |
313 |
while (1) { |
while (1) { |
|
... |
... |
function rg_repo_event_storage_create($db, $e) |
374 |
374 |
|
|
375 |
375 |
$ret = FALSE; |
$ret = FALSE; |
376 |
376 |
while (1) { |
while (1) { |
377 |
|
$by_id_path = rg_repo_path_by_id($e['ui::uid'], $e['ri::repo_id']); |
|
|
377 |
|
$by_id_path = rg_repo_path_by_id($e['ui']['uid'], $e['ri']['repo_id']); |
378 |
378 |
if (!is_dir($by_id_path)) { |
if (!is_dir($by_id_path)) { |
379 |
379 |
if (mkdir($by_id_path, 0755, TRUE) === FALSE) { |
if (mkdir($by_id_path, 0755, TRUE) === FALSE) { |
380 |
380 |
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) |
382 |
382 |
} |
} |
383 |
383 |
} |
} |
384 |
384 |
|
|
385 |
|
if ($e['ri::master'] == 0) { |
|
|
385 |
|
if ($e['ri']['master'] == 0) { |
386 |
386 |
$r = rg_git_init($by_id_path); |
$r = rg_git_init($by_id_path); |
387 |
387 |
if ($r === FALSE) { |
if ($r === FALSE) { |
388 |
388 |
rg_repo_set_error("cannot init master" |
rg_repo_set_error("cannot init master" |
|
... |
... |
function rg_repo_event_storage_create($db, $e) |
390 |
390 |
break; |
break; |
391 |
391 |
} |
} |
392 |
392 |
} else { |
} else { |
393 |
|
$mi = rg_repo_info($db, $e['ri::master'], 0, ""); |
|
|
393 |
|
$mi = rg_repo_info($db, $e['ri']['master'], 0, ""); |
394 |
394 |
if ($mi['exists'] != 1) { |
if ($mi['exists'] != 1) { |
395 |
|
rg_repo_set_error("cannot find master (" . rg_repo_error() . ")"); |
|
|
395 |
|
rg_repo_set_error("cannot find master" |
|
396 |
|
. " (" . rg_repo_error() . ")"); |
396 |
397 |
break; |
break; |
397 |
398 |
} |
} |
398 |
399 |
|
|
399 |
|
$master_by_id_path = rg_repo_path_by_id($mi['uid'], $mi['repo_id']); |
|
|
400 |
|
$master_by_id_path = rg_repo_path_by_id($mi['uid'], |
|
401 |
|
$mi['repo_id']); |
400 |
402 |
$r = rg_git_clone($master_by_id_path, $by_id_path); |
$r = rg_git_clone($master_by_id_path, $by_id_path); |
401 |
403 |
if ($r === FALSE) { |
if ($r === FALSE) { |
402 |
|
rg_repo_set_error("could not create repo (" . rg_git_error() . ")"); |
|
|
404 |
|
rg_repo_set_error("could not create repo" |
|
405 |
|
. " (" . rg_git_error() . ")"); |
403 |
406 |
break; |
break; |
404 |
407 |
} |
} |
405 |
408 |
|
|
|
... |
... |
function rg_repo_event_storage_create($db, $e) |
409 |
412 |
if ($r === FALSE) |
if ($r === FALSE) |
410 |
413 |
break; |
break; |
411 |
414 |
|
|
412 |
|
$r = rg_repo_git_done($db, $e['ri::repo_id']); |
|
|
415 |
|
$r = rg_repo_git_done($db, $e['ri']['repo_id']); |
413 |
416 |
if ($r !== TRUE) |
if ($r !== TRUE) |
414 |
417 |
break; |
break; |
415 |
418 |
|
|
|
... |
... |
function rg_repo_history_insert($db, $event) |
465 |
468 |
rg_prof_start("repo_history_insert"); |
rg_prof_start("repo_history_insert"); |
466 |
469 |
rg_log_enter("repo_history_insert: event=" . rg_array2string($event)); |
rg_log_enter("repo_history_insert: event=" . rg_array2string($event)); |
467 |
470 |
|
|
468 |
|
if (!isset($event['ui::uid'])) |
|
469 |
|
$event['ui::uid'] = 0; |
|
|
471 |
|
if (!isset($event['ui']['uid'])) |
|
472 |
|
$event['ui']['uid'] = 0; |
470 |
473 |
|
|
471 |
474 |
$ret = FALSE; |
$ret = FALSE; |
472 |
475 |
while (1) { |
while (1) { |
473 |
476 |
$now = time(); |
$now = time(); |
474 |
477 |
$params = array("now" => $now, |
$params = array("now" => $now, |
475 |
|
"repo_id" => $event['ri::repo_id'], |
|
476 |
|
"uid" => $event['ui::uid'], |
|
|
478 |
|
"repo_id" => $event['ri']['repo_id'], |
|
479 |
|
"uid" => $event['ui']['uid'], |
477 |
480 |
"cat" => $event['history_category'], |
"cat" => $event['history_category'], |
478 |
481 |
"mess" => $event['history_message']); |
"mess" => $event['history_message']); |
479 |
482 |
$sql = "INSERT INTO repo_history_" . gmdate("Y_m", $now) |
$sql = "INSERT INTO repo_history_" . gmdate("Y_m", $now) |
|
... |
... |
function rg_repo_path_by_name($uid, $repo_name) |
628 |
631 |
*/ |
*/ |
629 |
632 |
function rg_repo_cosmetic(&$row) |
function rg_repo_cosmetic(&$row) |
630 |
633 |
{ |
{ |
631 |
|
$_a = rg_xss_safe($row['description']); |
|
632 |
|
$row['HTML:description_nlbr'] = nl2br($_a); |
|
|
634 |
|
if (strlen(substr($row['description'], 0, 1)) == 1) { |
|
635 |
|
$_a = rg_xss_safe($row['description']); |
|
636 |
|
$row['HTML:description_nlbr'] = nl2br($_a); |
|
637 |
|
} else { |
|
638 |
|
$row['HTML:description_nlbr'] = '-'; |
|
639 |
|
} |
633 |
640 |
} |
} |
634 |
641 |
|
|
635 |
642 |
/* |
/* |
|
... |
... |
function rg_repo_delete($db, $repo_id, $ui) |
747 |
754 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
748 |
755 |
|
|
749 |
756 |
$event = array("category" => 3001, "prio" => 50, |
$event = array("category" => 3001, "prio" => 50, |
750 |
|
"ui::email" => $ui['confirmed'] > 0 ? $ui['email'] : "", |
|
751 |
|
"ri::name" => $ri['name'], |
|
752 |
|
"ri::repo_id" => $repo_id); |
|
|
757 |
|
'ui' => array( |
|
758 |
|
'email' => $ui['confirmed'] > 0 ? $ui['email'] : ""), |
|
759 |
|
'ri' => array( |
|
760 |
|
'name' => $ri['name'], |
|
761 |
|
'repo_id' => $repo_id |
|
762 |
|
) |
|
763 |
|
); |
753 |
764 |
$r = rg_event_add($db, $event); |
$r = rg_event_add($db, $event); |
754 |
765 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
755 |
766 |
rg_repo_set_error("cannot add event" |
rg_repo_set_error("cannot add event" |
|
... |
... |
function rg_repo_edit($db, $login_ui, &$new) |
975 |
986 |
$old_description = $ri['description']; |
$old_description = $ri['description']; |
976 |
987 |
} |
} |
977 |
988 |
|
|
978 |
|
$event = array("category" => $cat, "prio" => 50, |
|
979 |
|
"notification" => $notification, |
|
980 |
|
"ui::uid" => $login_ui['uid'], |
|
981 |
|
"ui::email" => $login_ui['confirmed'] > 0 ? $login_ui['email'] : "", |
|
982 |
|
"ri::url" => rg_base_url() . rg_re_repopage($login_ui, $new['name']), |
|
983 |
|
"history_category" => $hcat, |
|
984 |
|
"history_message" => $hmess); |
|
985 |
|
$event = rg_array_merge($event, "ri::old", $ri); |
|
986 |
|
$event = rg_array_merge($event, "ri", $new); |
|
987 |
|
$event['ri::old::description_md5'] = md5($old_description); |
|
988 |
|
$event['ri::description_md5'] = md5($new['description']); |
|
|
989 |
|
$event = array('category' => $cat, 'prio' => 50, |
|
990 |
|
'notification' => $notification, |
|
991 |
|
'ui' => array( |
|
992 |
|
'uid' => $login_ui['uid'], |
|
993 |
|
'email' => $login_ui['confirmed'] > 0 ? $login_ui['email'] : "" |
|
994 |
|
), |
|
995 |
|
'history_category' => $hcat, |
|
996 |
|
'history_message' => $hmess); |
|
997 |
|
$event = rg_array_merge($event, 'ri_old', $ri); |
|
998 |
|
$new['url'] = rg_base_url() . rg_re_repopage($login_ui, $new['name']); |
|
999 |
|
$event = rg_array_merge($event, 'ri', $new); |
|
1000 |
|
$event['ri_old']['description_md5'] = md5($old_description); |
|
1001 |
|
$event['ri']['description_md5'] = md5($new['description']); |
989 |
1002 |
$r = rg_event_add($db, $event); |
$r = rg_event_add($db, $event); |
990 |
1003 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
991 |
1004 |
rg_repo_set_error("cannot add event" |
rg_repo_set_error("cannot add event" |
|
... |
... |
function rg_repo_admin_rights($db, $rg, $type) |
1229 |
1242 |
$x['ip'] = $rg['ip']; |
$x['ip'] = $rg['ip']; |
1230 |
1243 |
$x['misc'] = ""; |
$x['misc'] = ""; |
1231 |
1244 |
if (rg_rights_allow($db, $x) !== TRUE) |
if (rg_rights_allow($db, $x) !== TRUE) |
1232 |
|
return rg_template("user/repo/rights/deny.html", $rg); |
|
|
1245 |
|
return rg_template("user/repo/rights/deny.html", $rg, TRUE /* xss */); |
1233 |
1246 |
|
|
1234 |
1247 |
$ret = ""; |
$ret = ""; |
1235 |
1248 |
|
|
|
... |
... |
function rg_repo_admin_rights($db, $rg, $type) |
1268 |
1281 |
break; |
break; |
1269 |
1282 |
} |
} |
1270 |
1283 |
|
|
1271 |
|
$ret .= rg_template("user/repo/rights/delete_ok.html", $rg); |
|
|
1284 |
|
$ret .= rg_template("user/repo/rights/delete_ok.html", $rg, TRUE /* xss */); |
1272 |
1285 |
break; |
break; |
1273 |
1286 |
} |
} |
1274 |
1287 |
|
|
|
... |
... |
function rg_repo_admin_rights($db, $rg, $type) |
1328 |
1341 |
break; |
break; |
1329 |
1342 |
} |
} |
1330 |
1343 |
|
|
1331 |
|
$ret .= rg_template("user/repo/rights/grant_ok.html", $rg); |
|
|
1344 |
|
$ret .= rg_template("user/repo/rights/grant_ok.html", $rg, TRUE /* xss */); |
1332 |
1345 |
|
|
1333 |
1346 |
$load_defaults = 1; |
$load_defaults = 1; |
1334 |
1347 |
break; |
break; |
|
... |
... |
function rg_repo_admin_rights($db, $rg, $type) |
1343 |
1356 |
$rg['ip'] = ""; |
$rg['ip'] = ""; |
1344 |
1357 |
$rg['prio'] = 100; |
$rg['prio'] = 100; |
1345 |
1358 |
} else { |
} else { |
1346 |
|
$rg = rg_array_merge($rg, "", $a); |
|
|
1359 |
|
$rg = rg_array_merge($rg, '', $a); |
1347 |
1360 |
} |
} |
1348 |
1361 |
|
|
1349 |
1362 |
$rg['rg_form_token'] = rg_token_get($db, $rg); |
$rg['rg_form_token'] = rg_token_get($db, $rg); |
|
... |
... |
function rg_repo_admin_rights($db, $rg, $type) |
1361 |
1374 |
$ret .= rg_template_table("user/repo/rights/list_" . $type, |
$ret .= rg_template_table("user/repo/rights/list_" . $type, |
1362 |
1375 |
$r['list'], $rg); |
$r['list'], $rg); |
1363 |
1376 |
|
|
1364 |
|
$ret .= rg_template("user/repo/rights/form_" . $type . ".html", $rg); |
|
|
1377 |
|
$ret .= rg_template("user/repo/rights/form_" . $type . ".html", $rg, TRUE /* xss */); |
1365 |
1378 |
|
|
1366 |
1379 |
// hints |
// hints |
1367 |
1380 |
$hints = array(); |
$hints = array(); |
1368 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/edit_rights.html", $rg); |
|
1369 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/edit_" . $type . "_rights.html", $rg); |
|
|
1381 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/edit_rights.html", $rg, TRUE /* xss */); |
|
1382 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/edit_" . $type . "_rights.html", $rg, TRUE /* xss */); |
1370 |
1383 |
$ret .= rg_template_table("hints/list", $hints, $rg); |
$ret .= rg_template_table("hints/list", $hints, $rg); |
1371 |
1384 |
|
|
1372 |
1385 |
return $ret; |
return $ret; |
|
... |
... |
function rg_repo_admin_delete($db, $rg) |
1389 |
1402 |
$x['ip'] = $rg['ip']; |
$x['ip'] = $rg['ip']; |
1390 |
1403 |
$x['misc'] = ""; |
$x['misc'] = ""; |
1391 |
1404 |
if (rg_rights_allow($db, $x) !== TRUE) |
if (rg_rights_allow($db, $x) !== TRUE) |
1392 |
|
return rg_template("user/repo/delete/deny.html", $rg); |
|
|
1405 |
|
return rg_template("user/repo/delete/deny.html", $rg, TRUE /* xss */); |
1393 |
1406 |
|
|
1394 |
1407 |
$are_you_sure = rg_var_uint("are_you_sure"); |
$are_you_sure = rg_var_uint("are_you_sure"); |
1395 |
1408 |
|
|
|
... |
... |
function rg_repo_admin_delete($db, $rg) |
1402 |
1415 |
break; |
break; |
1403 |
1416 |
|
|
1404 |
1417 |
if ($are_you_sure == 0) { |
if ($are_you_sure == 0) { |
1405 |
|
$ret .= rg_template("user/repo/delete/no.html", $rg); |
|
|
1418 |
|
$ret .= rg_template("user/repo/delete/no.html", $rg, TRUE /* xss */); |
1406 |
1419 |
$show_form = 0; |
$show_form = 0; |
1407 |
1420 |
break; |
break; |
1408 |
1421 |
} |
} |
|
... |
... |
function rg_repo_admin_delete($db, $rg) |
1424 |
1437 |
break; |
break; |
1425 |
1438 |
} |
} |
1426 |
1439 |
|
|
1427 |
|
$ret .= rg_template("user/repo/delete/done.html", $rg); |
|
|
1440 |
|
$ret .= rg_template("user/repo/delete/done.html", $rg, TRUE /* xss */); |
1428 |
1441 |
$show_form = 0; |
$show_form = 0; |
1429 |
1442 |
|
|
1430 |
1443 |
// TODO: shouldn't we invalidate the cache? |
// TODO: shouldn't we invalidate the cache? |
|
... |
... |
function rg_repo_admin_delete($db, $rg) |
1434 |
1447 |
if ($show_form == 1) { |
if ($show_form == 1) { |
1435 |
1448 |
$rg['HTML:errmsg'] = rg_template_errmsg($errmsg); |
$rg['HTML:errmsg'] = rg_template_errmsg($errmsg); |
1436 |
1449 |
$rg['rg_form_token'] = rg_token_get($db, $rg); |
$rg['rg_form_token'] = rg_token_get($db, $rg); |
1437 |
|
$ret .= rg_template("user/repo/delete/sure.html", $rg); |
|
|
1450 |
|
$ret .= rg_template("user/repo/delete/sure.html", $rg, TRUE /* xss */); |
1438 |
1451 |
} |
} |
1439 |
1452 |
|
|
1440 |
1453 |
return $ret; |
return $ret; |
|
... |
... |
function rg_repo_edit_high_level($db, &$rg) |
1459 |
1472 |
|
|
1460 |
1473 |
// User is not logged in? |
// User is not logged in? |
1461 |
1474 |
if (!$edit && ($rg['login_ui']['uid'] == 0)) { |
if (!$edit && ($rg['login_ui']['uid'] == 0)) { |
1462 |
|
$ret .= rg_template("user/repo/deny_create.html", $rg); |
|
|
1475 |
|
$ret .= rg_template("user/repo/deny_create.html", $rg, TRUE /* xss */); |
1463 |
1476 |
$load_form = FALSE; |
$load_form = FALSE; |
1464 |
1477 |
break; |
break; |
1465 |
1478 |
} |
} |
|
... |
... |
function rg_repo_edit_high_level($db, &$rg) |
1475 |
1488 |
$x['ip'] = $rg['ip']; |
$x['ip'] = $rg['ip']; |
1476 |
1489 |
$x['misc'] = ""; |
$x['misc'] = ""; |
1477 |
1490 |
if (rg_rights_allow($db, $x) !== TRUE) { |
if (rg_rights_allow($db, $x) !== TRUE) { |
1478 |
|
$ret .= rg_template("user/repo/deny_edit.html", $rg); |
|
|
1491 |
|
$ret .= rg_template("user/repo/deny_edit.html", $rg, TRUE /* xss */); |
1479 |
1492 |
$load_form = FALSE; |
$load_form = FALSE; |
1480 |
1493 |
break; |
break; |
1481 |
1494 |
} |
} |
|
... |
... |
function rg_repo_edit_high_level($db, &$rg) |
1526 |
1539 |
$rg['ri']['home'] = rg_re_repopage($rg['login_ui'], |
$rg['ri']['home'] = rg_re_repopage($rg['login_ui'], |
1527 |
1540 |
$rg['ri']['name']); |
$rg['ri']['name']); |
1528 |
1541 |
if ($edit) { |
if ($edit) { |
1529 |
|
$ret .= rg_template("repo/edit_ok.html", $rg); |
|
|
1542 |
|
$ret .= rg_template("repo/edit_ok.html", $rg, TRUE /* xss */); |
1530 |
1543 |
} else { |
} else { |
1531 |
|
$ret .= rg_template("repo/create_ok.html", $rg); |
|
|
1544 |
|
$ret .= rg_template("repo/create_ok.html", $rg, TRUE /* xss */); |
1532 |
1545 |
} |
} |
1533 |
1546 |
|
|
1534 |
1547 |
$load_form = FALSE; |
$load_form = FALSE; |
|
... |
... |
function rg_repo_edit_high_level($db, &$rg) |
1548 |
1561 |
$rg['HTML:errmsg'] = rg_template_errmsg($errmsg); |
$rg['HTML:errmsg'] = rg_template_errmsg($errmsg); |
1549 |
1562 |
$rg['rg_form_token'] = rg_token_get($db, $rg); |
$rg['rg_form_token'] = rg_token_get($db, $rg); |
1550 |
1563 |
$hints = array(); |
$hints = array(); |
1551 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/create_repo.html", $rg); |
|
|
1564 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/create_repo.html", $rg, TRUE /* xss */); |
1552 |
1565 |
$rg['HTML:repo_edit_hints'] = rg_template_table("hints/list", $hints, $rg); |
$rg['HTML:repo_edit_hints'] = rg_template_table("hints/list", $hints, $rg); |
1553 |
|
$ret .= rg_template("repo/add_edit.html", $rg); |
|
|
1566 |
|
$ret .= rg_template("repo/add_edit.html", $rg, TRUE /* xss */); |
1554 |
1567 |
} |
} |
1555 |
1568 |
|
|
1556 |
1569 |
rg_log_exit(); |
rg_log_exit(); |
|
... |
... |
function rg_repo_admin($db, &$rg, $paras) |
1569 |
1582 |
$_op = empty($paras) ? "edit" : array_shift($paras); |
$_op = empty($paras) ? "edit" : array_shift($paras); |
1570 |
1583 |
|
|
1571 |
1584 |
$rg['menu']['repo'][$_op] = 1; |
$rg['menu']['repo'][$_op] = 1; |
1572 |
|
$ret .= rg_template("user/repo/menu.html", $rg); |
|
|
1585 |
|
$ret .= rg_template("user/repo/menu.html", $rg, TRUE /* xss */); |
1573 |
1586 |
|
|
1574 |
1587 |
switch ($_op) { |
switch ($_op) { |
1575 |
1588 |
case 'repo_rights': |
case 'repo_rights': |
|
... |
... |
function rg_repo_search_high_level($db, $rg, $ui, $url) |
1621 |
1634 |
|
|
1622 |
1635 |
$rg['q'] = $q; |
$rg['q'] = $q; |
1623 |
1636 |
$rg['HTML:errmsg'] = rg_template_errmsg($errmsg); |
$rg['HTML:errmsg'] = rg_template_errmsg($errmsg); |
1624 |
|
$rg['search::url'] = $url; |
|
1625 |
|
$ret .= rg_template("repo/search.html", $rg); |
|
|
1637 |
|
$rg['search_url'] = $url; |
|
1638 |
|
$ret .= rg_template("repo/search.html", $rg, TRUE /* xss */); |
1626 |
1639 |
|
|
1627 |
1640 |
return $ret; |
return $ret; |
1628 |
1641 |
} |
} |
|
... |
... |
function rg_repo_discover($db, $op, $rg, $ui) |
1649 |
1662 |
break; |
break; |
1650 |
1663 |
} |
} |
1651 |
1664 |
|
|
1652 |
|
$rg['discover::menu::' . $op] = 1; |
|
1653 |
|
$ret .= rg_template('repo/discover.html', $rg); |
|
|
1665 |
|
$rg['discover_menu_' . $op] = 1; |
|
1666 |
|
$ret .= rg_template('repo/discover.html', $rg, TRUE /* xss */); |
1654 |
1667 |
$ret .= $x; |
$ret .= $x; |
1655 |
1668 |
|
|
1656 |
1669 |
return $ret; |
return $ret; |
File inc/user.inc.php changed (mode: 100644) (index 84aff7d..7e935da) |
... |
... |
function rg_user_link_by_name($db, $event) |
105 |
105 |
|
|
106 |
106 |
rg_log("user_link_by_name: event=" . rg_array2string($event)); |
rg_log("user_link_by_name: event=" . rg_array2string($event)); |
107 |
107 |
|
|
108 |
|
$by_id = rg_user_path_by_id($event['ui::uid']); |
|
|
108 |
|
$by_id = rg_user_path_by_id($event['ui']['uid']); |
109 |
109 |
if (!is_dir($by_id) && (mkdir($by_id, 0755, TRUE) === FALSE)) { |
if (!is_dir($by_id) && (mkdir($by_id, 0755, TRUE) === FALSE)) { |
110 |
110 |
rg_user_set_error("cannot mkdir by_id=$by_id ($php_errormsg)"); |
rg_user_set_error("cannot mkdir by_id=$by_id ($php_errormsg)"); |
111 |
111 |
return FALSE; |
return FALSE; |
112 |
112 |
} |
} |
113 |
113 |
|
|
114 |
|
$by_name = rg_user_path_by_name($event['ui::username']); |
|
|
114 |
|
$by_name = rg_user_path_by_name($event['ui']['username']); |
115 |
115 |
$by_name_parent = dirname($by_name); |
$by_name_parent = dirname($by_name); |
116 |
116 |
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)) { |
117 |
117 |
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)"); |
118 |
118 |
return FALSE; |
return FALSE; |
119 |
119 |
} |
} |
120 |
120 |
|
|
121 |
|
$by_id_rel = rg_user_path_by_id_rel($event['ui::uid']); |
|
|
121 |
|
$by_id_rel = rg_user_path_by_id_rel($event['ui']['uid']); |
122 |
122 |
if (is_link($by_name)) |
if (is_link($by_name)) |
123 |
123 |
unlink($by_name); |
unlink($by_name); |
124 |
124 |
if (symlink($by_id_rel, $by_name) === FALSE) { |
if (symlink($by_id_rel, $by_name) === FALSE) { |
|
... |
... |
function rg_user_rename($db, $ui, $new_name) |
386 |
386 |
|
|
387 |
387 |
// TODO: Check if all parameters are used. |
// TODO: Check if all parameters are used. |
388 |
388 |
$event = array("category" => 2005, "prio" => 50, |
$event = array("category" => 2005, "prio" => 50, |
389 |
|
"ui::rename_from" => $ui['username'], |
|
390 |
|
"ui::rename_to" => $new_name, |
|
391 |
|
"ui::uid" => $ui['uid']); |
|
|
389 |
|
'ui' => array( |
|
390 |
|
'rename_from' => $ui['username'], |
|
391 |
|
'rename_to' => $new_name, |
|
392 |
|
'uid' => $ui['uid'] |
|
393 |
|
) |
|
394 |
|
); |
392 |
395 |
$r = rg_event_add($db, $event); |
$r = rg_event_add($db, $event); |
393 |
396 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
394 |
397 |
rg_repo_set_error("cannot add event" |
rg_repo_set_error("cannot add event" |
|
... |
... |
function rg_user_edit($db, $d) |
506 |
509 |
rg_cache_unset("user::" . $d['uid']); |
rg_cache_unset("user::" . $d['uid']); |
507 |
510 |
|
|
508 |
511 |
if ($d['uid'] == 0) { // add |
if ($d['uid'] == 0) { // add |
509 |
|
$event = array("category" => 2000, "prio" => 50, |
|
510 |
|
"ui::uid" => $row['uid'], |
|
511 |
|
"ui::username" => $d['username'], |
|
512 |
|
"ui::email" => $confirmed > 0 ? $d['email'] : "", |
|
513 |
|
"ui::confirm_token" => $d['confirm_token'], |
|
514 |
|
"rg_account_email_confirm" => $rg_account_email_confirm, |
|
515 |
|
"url" => rg_base_url() |
|
|
512 |
|
$event = array('category' => 2000, 'prio' => 50, |
|
513 |
|
'ui' => array( |
|
514 |
|
'uid' => $row['uid'], |
|
515 |
|
'username' => $d['username'], |
|
516 |
|
'email' => $confirmed > 0 ? $d['email'] : "", |
|
517 |
|
'confirm_token' => $d['confirm_token'] |
|
518 |
|
), |
|
519 |
|
'rg_account_email_confirm' => $rg_account_email_confirm, |
|
520 |
|
'url' => rg_base_url() |
516 |
521 |
); |
); |
517 |
522 |
$r = rg_event_add($db, $event); |
$r = rg_event_add($db, $event); |
518 |
523 |
if ($r === FALSE) { |
if ($r === FALSE) { |
|
... |
... |
function rg_user_list($db) |
1002 |
1007 |
} |
} |
1003 |
1008 |
|
|
1004 |
1009 |
$ret = ""; |
$ret = ""; |
1005 |
|
$ret .= "<table>\n"; |
|
|
1010 |
|
$ret .= "<table summary=\"users and operations\">\n"; |
1006 |
1011 |
$ret .= "<tr>\n"; |
$ret .= "<tr>\n"; |
1007 |
1012 |
$ret .= " <th>User name</th>\n"; |
$ret .= " <th>User name</th>\n"; |
1008 |
1013 |
$ret .= " <th>Name</th>\n"; |
$ret .= " <th>Name</th>\n"; |
|
... |
... |
function rg_user_confirm($db, $token) |
1295 |
1300 |
rg_log_enter("user_confirm: token=$token"); |
rg_log_enter("user_confirm: token=$token"); |
1296 |
1301 |
|
|
1297 |
1302 |
$now = time(); |
$now = time(); |
1298 |
|
$token = preg_replace("/[^A-Za-z0-9]/", "", $token); |
|
|
1303 |
|
$token = preg_replace("/[^A-Za-z0-9]/", '', $token); |
1299 |
1304 |
|
|
1300 |
1305 |
$ret = FALSE; |
$ret = FALSE; |
1301 |
1306 |
while (1) { |
while (1) { |
|
... |
... |
function rg_user_edit_high_level($db, &$rg) |
1415 |
1420 |
|
|
1416 |
1421 |
if (($rg['target_ui']['uid'] == 0) |
if (($rg['target_ui']['uid'] == 0) |
1417 |
1422 |
&& ($rg['rg_account_allow_creation'] != 1)) { |
&& ($rg['rg_account_allow_creation'] != 1)) { |
1418 |
|
$ret .= rg_template("user/create_na.html", $rg); |
|
|
1423 |
|
$ret .= rg_template("user/create_na.html", $rg, TRUE /* xss */); |
1419 |
1424 |
return $ret; |
return $ret; |
1420 |
1425 |
} |
} |
1421 |
1426 |
|
|
|
... |
... |
function rg_user_edit_high_level($db, &$rg) |
1431 |
1436 |
$x['ip'] = $rg['ip']; |
$x['ip'] = $rg['ip']; |
1432 |
1437 |
$x['misc'] = ""; |
$x['misc'] = ""; |
1433 |
1438 |
if (rg_rights_allow($db, $x) !== TRUE) { |
if (rg_rights_allow($db, $x) !== TRUE) { |
1434 |
|
$ret .= rg_template("access_denied.html", $rg); |
|
|
1439 |
|
$ret .= rg_template("access_denied.html", $rg, TRUE /* xss */); |
1435 |
1440 |
return $ret; |
return $ret; |
1436 |
1441 |
} |
} |
1437 |
1442 |
} |
} |
|
... |
... |
function rg_user_edit_high_level($db, &$rg) |
1525 |
1530 |
// TODO: should we just redirect to login page? |
// TODO: should we just redirect to login page? |
1526 |
1531 |
// TODO: or to user page if there is no need to confirm the account? |
// TODO: or to user page if there is no need to confirm the account? |
1527 |
1532 |
if ($ui['uid'] == 0) |
if ($ui['uid'] == 0) |
1528 |
|
$ret = rg_template("user/create_ok.html", $rg); |
|
|
1533 |
|
$ret = rg_template("user/create_ok.html", $rg, TRUE /* xss */); |
1529 |
1534 |
else |
else |
1530 |
|
$ret = rg_template("user/edit_ok.html", $rg); |
|
|
1535 |
|
$ret = rg_template("user/edit_ok.html", $rg, TRUE /* xss */); |
1531 |
1536 |
$load_form = FALSE; |
$load_form = FALSE; |
1532 |
1537 |
break; |
break; |
1533 |
1538 |
} |
} |
|
... |
... |
function rg_user_edit_high_level($db, &$rg) |
1539 |
1544 |
"rights", $ui['rights']); |
"rights", $ui['rights']); |
1540 |
1545 |
$rg['HTML:errmsg'] = rg_template_errmsg($errmsg); |
$rg['HTML:errmsg'] = rg_template_errmsg($errmsg); |
1541 |
1546 |
$rg['rg_form_token'] = rg_token_get($db, $rg); |
$rg['rg_form_token'] = rg_token_get($db, $rg); |
1542 |
|
$ret .= rg_template("user/add_edit.html", $rg); |
|
|
1547 |
|
$ret .= rg_template("user/add_edit.html", $rg, TRUE /* xss */); |
1543 |
1548 |
} |
} |
1544 |
1549 |
|
|
1545 |
1550 |
return $ret; |
return $ret; |
File inc/user/repo-page.php changed (mode: 100644) (index 7989e48..d97eee9) |
... |
... |
if ($rg['page_ui']['ok'] != 1) { |
13 |
13 |
return; |
return; |
14 |
14 |
} |
} |
15 |
15 |
if ($rg['page_ui']['exists'] != 1) { |
if ($rg['page_ui']['exists'] != 1) { |
16 |
|
$_repo_page .= rg_template("user/invalid.html", $rg); |
|
|
16 |
|
$_repo_page .= rg_template("user/invalid.html", $rg, TRUE /* xss */); |
17 |
17 |
return; |
return; |
18 |
18 |
} |
} |
19 |
19 |
|
|
20 |
20 |
if (rg_repo_ok($repo) !== TRUE) { |
if (rg_repo_ok($repo) !== TRUE) { |
21 |
|
$_repo_page .= rg_template("repo/invalid.html", $rg); |
|
|
21 |
|
$_repo_page .= rg_template("repo/invalid.html", $rg, TRUE /* xss */); |
22 |
22 |
return; |
return; |
23 |
23 |
} |
} |
24 |
24 |
$rg['ri'] = rg_repo_info($db, 0, $rg['page_ui']['uid'], $repo); |
$rg['ri'] = rg_repo_info($db, 0, $rg['page_ui']['uid'], $repo); |
|
... |
... |
while (1) { |
48 |
48 |
break; |
break; |
49 |
49 |
} |
} |
50 |
50 |
if ($allow !== TRUE) { |
if ($allow !== TRUE) { |
51 |
|
$_repo_page .= rg_template("user/repo/deny.html", $rg); |
|
|
51 |
|
$_repo_page .= rg_template("user/repo/deny.html", $rg, TRUE /* xss */); |
52 |
52 |
return; |
return; |
53 |
53 |
} |
} |
54 |
54 |
|
|
|
... |
... |
$rg['url_repo'] = rg_re_repopage($rg['page_ui'], $repo); |
63 |
63 |
$rg['ssh'] = rg_re_repo_ssh($organization, $user, $repo); |
$rg['ssh'] = rg_re_repo_ssh($organization, $user, $repo); |
64 |
64 |
$rg['git'] = rg_re_repo_git($organization, $user, $repo); |
$rg['git'] = rg_re_repo_git($organization, $user, $repo); |
65 |
65 |
$rg['can_admin'] = $can_admin; |
$rg['can_admin'] = $can_admin; |
66 |
|
$rg['hints'] = ""; |
|
|
66 |
|
$rg['HTML:hints'] = ''; |
67 |
67 |
|
|
68 |
68 |
$repo_path = rg_repo_path_by_id($rg['ri']['uid'], $rg['ri']['repo_id']); |
$repo_path = rg_repo_path_by_id($rg['ri']['uid'], $rg['ri']['repo_id']); |
69 |
69 |
rg_log("repo_path=$repo_path"); |
rg_log("repo_path=$repo_path"); |
70 |
70 |
putenv("GIT_DIR=$repo_path"); // TODO: this will be removed after all functios will got a path para |
putenv("GIT_DIR=$repo_path"); // TODO: this will be removed after all functios will got a path para |
71 |
71 |
|
|
72 |
|
$rg['repo_body'] = ""; |
|
73 |
|
$rg['branches_and_tags'] = ""; |
|
74 |
|
$rg['repo_submenu'] = ""; |
|
|
72 |
|
$rg['HTML:branches_and_tags'] = ''; |
75 |
73 |
$_repo_body = ""; |
$_repo_body = ""; |
76 |
74 |
|
|
77 |
75 |
// build urls list |
// build urls list |
78 |
76 |
$urls = array(); |
$urls = array(); |
79 |
77 |
if ($rg_ssh_port != 0) |
if ($rg_ssh_port != 0) |
80 |
|
$urls[]['HTML:url'] = '<a href="' . $rg['ssh'] . '">' . $rg['ssh'] . '</a>'; |
|
|
78 |
|
$urls[]['HTML:clone_url'] = '<a href="' . $rg['ssh'] . '">' . $rg['ssh'] . '</a>'; |
81 |
79 |
if ($rg_git_port != 0) |
if ($rg_git_port != 0) |
82 |
|
$urls[]['HTML:url'] = '<a href="' . $rg['git'] . '">' . $rg['git'] . '</a>'; |
|
|
80 |
|
$urls[]['HTML:clone_url'] = '<a href="' . $rg['git'] . '">' . $rg['git'] . '</a>'; |
83 |
81 |
$rg['HTML:urls'] = rg_template_table("repo/urls", $urls, $rg); |
$rg['HTML:urls'] = rg_template_table("repo/urls", $urls, $rg); |
84 |
82 |
|
|
85 |
83 |
function rg_add_clone_hints($db, &$rg, $ref) |
function rg_add_clone_hints($db, &$rg, $ref) |
|
... |
... |
function rg_add_clone_hints($db, &$rg, $ref) |
89 |
87 |
|
|
90 |
88 |
$hints = array(); |
$hints = array(); |
91 |
89 |
|
|
92 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/git_setup.html", $rg); |
|
|
90 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/git_setup.html", |
|
91 |
|
$rg, TRUE /* xss */); |
93 |
92 |
|
|
94 |
93 |
if ($rg['ri']['uid'] == $rg['login_ui']['uid']) { |
if ($rg['ri']['uid'] == $rg['login_ui']['uid']) { |
95 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/clone_owner.html", $rg); |
|
|
94 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/clone_owner.html", |
|
95 |
|
$rg, TRUE /* xss */); |
96 |
96 |
} else { |
} else { |
97 |
97 |
if ($rg_ssh_port != 0) |
if ($rg_ssh_port != 0) |
98 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/clone_ssh.html", $rg); |
|
|
98 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/clone_ssh.html", |
|
99 |
|
$rg, TRUE /* xss */); |
99 |
100 |
|
|
100 |
101 |
if ($rg_git_port != 0) |
if ($rg_git_port != 0) |
101 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/clone_git.html", $rg); |
|
|
102 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/clone_git.html", |
|
103 |
|
$rg, TRUE /* xss */); |
102 |
104 |
|
|
103 |
105 |
$x = array(); |
$x = array(); |
104 |
106 |
$x['obj_id'] = $rg['ri']['repo_id']; |
$x['obj_id'] = $rg['ri']['repo_id']; |
|
... |
... |
function rg_add_clone_hints($db, &$rg, $ref) |
110 |
112 |
$x['ip'] = $rg['ip']; |
$x['ip'] = $rg['ip']; |
111 |
113 |
$x['misc'] = $ref; |
$x['misc'] = $ref; |
112 |
114 |
if (rg_rights_allow($db, $x) === TRUE) |
if (rg_rights_allow($db, $x) === TRUE) |
113 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/anon_push.html", $rg); |
|
|
115 |
|
$hints[]['HTML:hint'] = rg_template("hints/repo/anon_push.html", |
|
116 |
|
$rg, TRUE /* xss */); |
114 |
117 |
} |
} |
115 |
118 |
|
|
116 |
119 |
$rg['HTML:hints'] = rg_template_table("hints/list", $hints, $rg); |
$rg['HTML:hints'] = rg_template_table("hints/list", $hints, $rg); |
|
... |
... |
if (strcmp($_subop, "history") == 0) { |
142 |
145 |
|
|
143 |
146 |
rg_add_clone_hints($db, $rg, $ref); |
rg_add_clone_hints($db, $rg, $ref); |
144 |
147 |
|
|
145 |
|
$_repo_body .= rg_template("repo/source.html", $rg); |
|
|
148 |
|
$_repo_body .= rg_template("repo/source.html", $rg, TRUE /* xss */); |
146 |
149 |
|
|
147 |
150 |
rg_log("DEBUG: _subsubop=[$_subsubop]"); |
rg_log("DEBUG: _subsubop=[$_subsubop]"); |
148 |
151 |
if ($rg['ri']['git_dir_done'] == 0) { |
if ($rg['ri']['git_dir_done'] == 0) { |
149 |
|
$_repo_body .= rg_template("repo/no_git_dir.html", $rg); |
|
|
152 |
|
$_repo_body .= rg_template("repo/no_git_dir.html", $rg, TRUE /* xss */); |
150 |
153 |
} else if (strcmp($_subsubop, "tree") == 0) { |
} else if (strcmp($_subsubop, "tree") == 0) { |
151 |
154 |
$type = array_shift($paras); |
$type = array_shift($paras); |
152 |
155 |
rg_log("DEBUG: tree: type=$type"); |
rg_log("DEBUG: tree: type=$type"); |
|
... |
... |
if (strcmp($_subop, "history") == 0) { |
168 |
171 |
); |
); |
169 |
172 |
$blob = array_merge($blob, $_content); |
$blob = array_merge($blob, $_content); |
170 |
173 |
$blob = array_merge($blob, $rg); |
$blob = array_merge($blob, $rg); |
171 |
|
$_repo_body .= rg_template("repo/blob.html", $blob); |
|
|
174 |
|
$_repo_body .= rg_template("repo/blob.html", $blob, TRUE /* xss */); |
172 |
175 |
} |
} |
173 |
176 |
} else if (strcmp($type, "tree") == 0) { |
} else if (strcmp($type, "tree") == 0) { |
174 |
177 |
// find treeish of dir |
// find treeish of dir |
|
... |
... |
if (strcmp($_subop, "history") == 0) { |
189 |
192 |
$_repo_body .= rg_template_table("repo/tree", $_tree, |
$_repo_body .= rg_template_table("repo/tree", $_tree, |
190 |
193 |
$rg); |
$rg); |
191 |
194 |
} |
} |
192 |
|
} else { |
|
193 |
|
// show the log |
|
|
195 |
|
} else { // show the log |
194 |
196 |
$log = rg_git_log($repo_path, 10, "", $ref, FALSE); |
$log = rg_git_log($repo_path, 10, "", $ref, FALSE); |
195 |
197 |
if ($log === FALSE) { |
if ($log === FALSE) { |
196 |
|
$_repo_body .= rg_template("repo/not_init.html", $rg); |
|
|
198 |
|
$_repo_body .= rg_template("repo/not_init.html", $rg, TRUE /* xss */); |
197 |
199 |
} else { |
} else { |
198 |
200 |
//rg_log_ml("DEBUG: log: " . print_r($log, TRUE)); |
//rg_log_ml("DEBUG: log: " . print_r($log, TRUE)); |
199 |
201 |
$_repo_body .= rg_git_log_template($log, "repo/log", $rg); |
$_repo_body .= rg_git_log_template($log, "repo/log", $rg); |
|
... |
... |
if (strcmp($_subop, "history") == 0) { |
202 |
204 |
$type = array_shift($paras); |
$type = array_shift($paras); |
203 |
205 |
//rg_log("DEBUG: log: type=$type"); |
//rg_log("DEBUG: log: type=$type"); |
204 |
206 |
if (strcmp($type, "commit") == 0) { |
if (strcmp($type, "commit") == 0) { |
205 |
|
$commit = rg_git_reference($paras[0]); |
|
|
207 |
|
if (empty($paras)) |
|
208 |
|
$commit = FALSE; |
|
209 |
|
else |
|
210 |
|
$commit = rg_git_reference($paras[0]); |
206 |
211 |
if ($commit === FALSE) { |
if ($commit === FALSE) { |
207 |
212 |
rg_internal_error("Invalid commit" |
rg_internal_error("Invalid commit" |
208 |
213 |
. " [" . $paras[0] . "]." |
. " [" . $paras[0] . "]." |
|
... |
... |
if (strcmp($_subop, "history") == 0) { |
230 |
235 |
$_repo_body .= $bug_body; |
$_repo_body .= $bug_body; |
231 |
236 |
} else if (strcmp($_subop, "stats") == 0) { |
} else if (strcmp($_subop, "stats") == 0) { |
232 |
237 |
if ($rg['ri']['git_dir_done'] == 0) |
if ($rg['ri']['git_dir_done'] == 0) |
233 |
|
$_repo_body .= rg_template("repo/no_git_dir.html", $rg); |
|
|
238 |
|
$_repo_body .= rg_template("repo/no_git_dir.html", $rg, TRUE /* xss */); |
234 |
239 |
else |
else |
235 |
|
$_repo_body .= rg_template("repo/stats.html", $rg); |
|
|
240 |
|
$_repo_body .= rg_template("repo/stats.html", $rg, TRUE /* xss */); |
236 |
241 |
} else if (strcmp($_subop, "mr") == 0) { |
} else if (strcmp($_subop, "mr") == 0) { |
237 |
242 |
if ($rg['ri']['git_dir_done'] == 0) { |
if ($rg['ri']['git_dir_done'] == 0) { |
238 |
|
$_repo_body .= rg_template("repo/no_git_dir.html", $rg); |
|
|
243 |
|
$_repo_body .= rg_template("repo/no_git_dir.html", $rg, TRUE /* xss */); |
239 |
244 |
} else { |
} else { |
240 |
|
$_repo_body .= rg_template("repo/mrs.html", $rg); |
|
|
245 |
|
$_repo_body .= rg_template("repo/mrs.html", $rg, TRUE /* xss */); |
241 |
246 |
|
|
242 |
247 |
$r = rg_mr_load($db, $rg['ri']['repo_id'], 20); |
$r = rg_mr_load($db, $rg['ri']['repo_id'], 20); |
243 |
248 |
if ($r === FALSE) { |
if ($r === FALSE) { |
|
... |
... |
if (strcmp($_subop, "history") == 0) { |
267 |
272 |
} |
} |
268 |
273 |
|
|
269 |
274 |
$mri['HTML:diff'] = rg_git_log2listing($_log, $rg, TRUE); |
$mri['HTML:diff'] = rg_git_log2listing($_log, $rg, TRUE); |
270 |
|
$_repo_body .= rg_template("repo/mr/page.html", $mri); |
|
|
275 |
|
$_repo_body .= rg_template("repo/mr/page.html", $mri, TRUE /* xss */); |
271 |
276 |
|
|
272 |
277 |
break; |
break; |
273 |
278 |
} |
} |
|
... |
... |
if (strcmp($_subop, "history") == 0) { |
276 |
281 |
|
|
277 |
282 |
$rg['per_repo_menu'][$_subop] = 1; |
$rg['per_repo_menu'][$_subop] = 1; |
278 |
283 |
$rg['HTML:repo_body'] = $_repo_body; |
$rg['HTML:repo_body'] = $_repo_body; |
279 |
|
$_repo_page = rg_template("repo/main.html", $rg); |
|
|
284 |
|
$_repo_page = rg_template("repo/main.html", $rg, TRUE /* xss */); |
280 |
285 |
?> |
?> |
File inc/util.inc.php changed (mode: 100644) (index 2ca3c11..7df267a) |
... |
... |
function rg_rmdir($dir) |
377 |
377 |
} |
} |
378 |
378 |
|
|
379 |
379 |
/* |
/* |
380 |
|
* Provides a link to an image, taking in consideration the theme |
|
381 |
|
* Used by rg_prepare_image. |
|
|
380 |
|
* Lookup a path in the current theme with fallback to default |
|
381 |
|
* Returns the correct path |
382 |
382 |
*/ |
*/ |
383 |
|
function rg_image_callback($matches) |
|
|
383 |
|
function rg_theme_resolve_path($path) |
384 |
384 |
{ |
{ |
385 |
|
global $rg_theme_dir; |
|
386 |
|
global $rg_theme; |
|
|
385 |
|
global $rg_theme, $rg_theme_dir; |
387 |
386 |
|
|
388 |
|
$n = $matches[1]; |
|
389 |
|
$url = "/themes/" . $rg_theme . "/" . $n; |
|
390 |
|
$xfile = $rg_theme_dir . "/" . $rg_theme . "/" . $n; |
|
391 |
|
if (!is_file($xfile)) |
|
392 |
|
$url = "/themes/default/" . $n; |
|
393 |
|
|
|
394 |
|
return $url; |
|
395 |
|
} |
|
|
387 |
|
$url = "/themes/" . $rg_theme . "/" . $path; |
|
388 |
|
$xfile = $rg_theme_dir . "/" . $rg_theme . "/" . $path; |
|
389 |
|
if (!is_file($xfile)) |
|
390 |
|
$url = "/themes/default/" . $path; |
396 |
391 |
|
|
397 |
|
/* |
|
398 |
|
* Prepares the images to point to a correct image. |
|
399 |
|
*/ |
|
400 |
|
function rg_prepare_image($s) |
|
401 |
|
{ |
|
402 |
|
return preg_replace_callback('/@@IMG:(.*)@@/uU', "rg_image_callback", $s); |
|
|
392 |
|
return $url; |
403 |
393 |
} |
} |
404 |
394 |
|
|
405 |
395 |
/* |
/* |
406 |
|
* Resolve variables like '@@func:func_name:paras@@' |
|
|
396 |
|
* Loads a file if exists, else return "" |
407 |
397 |
*/ |
*/ |
408 |
|
function rg_prepare_func($s, &$what, &$values) |
|
|
398 |
|
function rg_file_get_contents($f) |
409 |
399 |
{ |
{ |
410 |
|
global $rg_template_functions; |
|
411 |
|
|
|
412 |
|
$seen = array(); |
|
413 |
|
|
|
414 |
|
$r = preg_match_all('/@@func:(.*):(.*)@@/uU', $s, $matches, PREG_SET_ORDER); |
|
415 |
|
foreach ($matches as $i) { |
|
416 |
|
$k = '/' . $i[0] . '/'; |
|
417 |
|
$func = $i[1]; |
|
418 |
|
$var = $i[2]; |
|
419 |
|
|
|
420 |
|
/* Function already called? */ |
|
421 |
|
if (isset($seen[$k])) |
|
422 |
|
continue; |
|
423 |
|
|
|
424 |
|
if (!isset($rg_template_functions[$func])) |
|
425 |
|
continue; |
|
426 |
|
|
|
427 |
|
$v = preg_replace($what, $values, "@@" . $var . "@@"); |
|
428 |
|
$final = $rg_template_functions[$func]($v); |
|
|
400 |
|
global $php_errormsg; |
429 |
401 |
|
|
430 |
|
$what[] = $k; |
|
431 |
|
$values[] = $final; |
|
|
402 |
|
if (!file_exists($f)) |
|
403 |
|
return ""; |
432 |
404 |
|
|
433 |
|
$seen[$k] = 1; |
|
|
405 |
|
$c = @file_get_contents($f); |
|
406 |
|
if ($c === FALSE) { |
|
407 |
|
rg_internal_error("Could not load file [$f] ($php_errormsg)."); |
|
408 |
|
return ""; |
434 |
409 |
} |
} |
|
410 |
|
|
|
411 |
|
return $c; |
435 |
412 |
} |
} |
436 |
413 |
|
|
437 |
414 |
/* |
/* |
438 |
|
* Helper for rg_prepare_replace |
|
|
415 |
|
* Merges an array (a) into another (src), using a namespace |
|
416 |
|
* Protects modifiers (HTML: etc.). |
439 |
417 |
*/ |
*/ |
440 |
|
function rg_prepare_replace_helper($a, $prefix, &$what, &$values) |
|
|
418 |
|
function rg_array_merge($src, $namespace, $a) |
441 |
419 |
{ |
{ |
442 |
|
foreach ($a as $k => $v) { |
|
443 |
|
if (empty($prefix)) |
|
444 |
|
$add = ""; |
|
445 |
|
else |
|
446 |
|
$add = "::"; |
|
447 |
|
|
|
448 |
|
$new_prefix = $prefix . $add . $k; |
|
449 |
|
|
|
450 |
|
if (is_array($v)) { |
|
451 |
|
rg_prepare_replace_helper($v, $new_prefix, |
|
452 |
|
$what, $values); |
|
453 |
|
continue; |
|
454 |
|
} |
|
|
420 |
|
$ret = $src; |
455 |
421 |
|
|
456 |
|
if (strncmp($k, "HTML:", 5) == 0) { |
|
457 |
|
$k = substr($k, 5); |
|
458 |
|
$new_prefix = $prefix . $add . $k; |
|
459 |
|
} else { |
|
460 |
|
$v = rg_xss_safe($v); |
|
461 |
|
} |
|
|
422 |
|
if (!empty($namespace)) |
|
423 |
|
if (!isset($ret[$namespace])) |
|
424 |
|
$ret[$namespace] = array(); |
462 |
425 |
|
|
463 |
|
$what[$new_prefix] = "/@@" . preg_quote($new_prefix, '/') . "@@/uU"; |
|
464 |
|
$values[$new_prefix] = $v; |
|
|
426 |
|
foreach ($a as $k => $v) { |
|
427 |
|
if (empty($namespace)) |
|
428 |
|
$ret[$k] = $v; |
|
429 |
|
else |
|
430 |
|
$ret[$namespace][$k] = $v; |
465 |
431 |
} |
} |
|
432 |
|
|
|
433 |
|
return $ret; |
466 |
434 |
} |
} |
467 |
435 |
|
|
468 |
|
function rg_prepare_replace(&$data, &$what, &$values) |
|
|
436 |
|
/* |
|
437 |
|
* Performs a lookup of a var of type 'a::b::c' into an array and |
|
438 |
|
* returns FALSE or the value |
|
439 |
|
*/ |
|
440 |
|
function rg_template_tree_lookup($var, &$data, $xss_protection) |
469 |
441 |
{ |
{ |
470 |
|
if (!empty($data)) { |
|
471 |
|
if (!is_array($data)) |
|
472 |
|
rg_internal_error("prepare_replace: invalid type passed"); |
|
|
442 |
|
$tree = &$data; |
|
443 |
|
$t = explode('::', $var); |
|
444 |
|
$v = array_pop($t); |
|
445 |
|
foreach ($t as $token) { |
|
446 |
|
if (!isset($tree[$token])) |
|
447 |
|
return FALSE; |
473 |
448 |
|
|
474 |
|
rg_prepare_replace_helper($data, "", $what, $values); |
|
|
449 |
|
$tree = &$tree[$token]; |
475 |
450 |
} |
} |
476 |
451 |
|
|
477 |
|
// we replace @@unknown@@ with empty |
|
478 |
|
//$what['FINAL'] = "/@@.*@@/U"; |
|
479 |
|
//$values['FINAL'] = ""; |
|
480 |
|
|
|
481 |
|
//rg_log_ml("DEBUG: what: " . print_r($what, TRUE)); |
|
482 |
|
//rg_log_ml("DEBUG: values: " . print_r($values, TRUE)); |
|
483 |
|
} |
|
|
452 |
|
// We prefer the HTML version |
|
453 |
|
$hv = 'HTML:' . $v; |
|
454 |
|
if (isset($tree[$hv])) |
|
455 |
|
return $tree[$hv]; |
484 |
456 |
|
|
485 |
|
/* |
|
486 |
|
* Lookup a var into data array, if needed. |
|
487 |
|
* It is used for conditionals. |
|
488 |
|
*/ |
|
489 |
|
function rg_replace_lookup(&$data, $var) |
|
490 |
|
{ |
|
491 |
|
rg_prepare_replace($data, $what, $values); |
|
492 |
|
if (empty($what)) |
|
493 |
|
return $var; |
|
|
457 |
|
if (isset($tree[$v])) { |
|
458 |
|
if ($xss_protection) |
|
459 |
|
return rg_xss_safe($tree[$v]); |
|
460 |
|
else |
|
461 |
|
return $tree[$v]; |
|
462 |
|
} |
494 |
463 |
|
|
495 |
|
return preg_replace($what, $values, $var); |
|
|
464 |
|
return FALSE; |
496 |
465 |
} |
} |
497 |
466 |
|
|
498 |
467 |
/* |
/* |
499 |
|
* Helper for rg_replace_conditionals. |
|
500 |
|
* It works at line level. |
|
501 |
|
* @master_block (TRUE / FALSE) is the condition for parent block. |
|
|
468 |
|
* Evaluates a condition |
502 |
469 |
*/ |
*/ |
503 |
|
function rg_replace_conditionals_block($block, &$data, &$stack) |
|
|
470 |
|
function rg_template_eval_cond($cond, &$data) |
504 |
471 |
{ |
{ |
505 |
|
//rg_log("DEBUG: rg_replace_conditionals_block: block=[$block]" |
|
506 |
|
// . " stack=" . rg_array2string($stack)); |
|
507 |
|
|
|
508 |
|
if (!is_string($block)) { |
|
509 |
|
rg_internal_error("Block is not a string!"); |
|
510 |
|
return FALSE; |
|
511 |
|
} |
|
512 |
|
|
|
513 |
|
// Nesting error |
|
514 |
|
if (empty($stack)) { |
|
515 |
|
rg_internal_error("Nesting error!"); |
|
516 |
|
return FALSE; |
|
|
472 |
|
$t = explode('!=', $cond); |
|
473 |
|
if (count($t) == 2) { |
|
474 |
|
$negate = TRUE; |
|
475 |
|
} else { |
|
476 |
|
$t = explode('==', $cond); |
|
477 |
|
if (count($t) != 2) { |
|
478 |
|
rg_log("invalid condition [$cond]!"); |
|
479 |
|
return FALSE; |
|
480 |
|
} |
|
481 |
|
$negate = FALSE; |
517 |
482 |
} |
} |
518 |
483 |
|
|
519 |
|
$cond = array_pop($stack); |
|
520 |
|
$stack[] = $cond; |
|
521 |
|
//rg_log("cond is " . ($cond ? "TRUE" : "FALSE")); |
|
522 |
|
|
|
523 |
|
// First, try to match a start of 'if' |
|
524 |
|
$match1 = "@@if\s*\((.*?)\)\s*?{{"; |
|
525 |
|
$match2 = "{{"; |
|
526 |
|
$match3 = "}}"; |
|
527 |
|
$search = $match1 . '|' . $match2 . '|' . $match3; |
|
528 |
|
$r = preg_match('/^(.*?)(' . $search . ')(.*)/su', |
|
529 |
|
$block, $matches); |
|
530 |
|
if ($r === FALSE) |
|
531 |
|
return FALSE; |
|
532 |
|
if ($r === 1) { |
|
533 |
|
//rg_log("DEBUG: matches: " . rg_array2string($matches)); |
|
534 |
|
|
|
535 |
|
$ret = ""; |
|
536 |
|
if ($cond === TRUE) |
|
537 |
|
$ret = $matches[1]; |
|
538 |
|
|
|
539 |
|
$rest = $matches[4]; |
|
540 |
|
if (strcmp($matches[2], "}}") == 0) { |
|
541 |
|
// We pop from stack only at }} and not at {{ |
|
542 |
|
//rg_log("}}: Pop the stack!"); |
|
543 |
|
array_pop($stack); |
|
544 |
|
} else if (strcmp($matches[2], "{{") == 0) { |
|
545 |
|
//rg_log("{{"); |
|
546 |
|
} else { |
|
547 |
|
//rg_log("DEBUG: cond=" . $matches[3]); |
|
548 |
|
if (empty($matches[3])) { |
|
549 |
|
$new_cond = FALSE; |
|
550 |
|
} else { |
|
551 |
|
$r = preg_match('/^\s*(.*?)\s*(==|!=)\s*(.*?)\s*$/Dsu', |
|
552 |
|
$matches[3], $matches2); |
|
553 |
|
if ($r === FALSE) { |
|
554 |
|
rg_internal_error("Invalid condition!"); |
|
555 |
|
return FALSE; |
|
556 |
|
} |
|
557 |
|
if (count($matches2) < 3) { |
|
558 |
|
rg_log("matches[3]: " . $matches[3]); |
|
559 |
|
rg_log("matches2: " . rg_array2string($matches2)); |
|
560 |
|
rg_internal_error("Cannot match condition."); |
|
561 |
|
return FALSE; |
|
562 |
|
} |
|
563 |
|
$left = rg_replace_lookup($data, trim($matches2[1])); |
|
564 |
|
$op = trim($matches2[2]); |
|
565 |
|
$right = rg_replace_lookup($data, trim($matches2[3])); |
|
566 |
|
//rg_log("DEBUG: if left=[$left] op=[$op] right=[$right]"); |
|
567 |
|
if (empty($op)) { |
|
568 |
|
$new_cond = empty($left) ? FALSE : TRUE; |
|
569 |
|
} else if (strcmp($op, "==") == 0) { |
|
570 |
|
$new_cond = strcmp($left, $right) == 0 ? TRUE : FALSE; |
|
571 |
|
} else if (strcmp($op, "!=") == 0) { |
|
572 |
|
$new_cond = strcmp($left, $right) == 0 ? FALSE : TRUE; |
|
573 |
|
} else { |
|
574 |
|
rg_internal_error("Invalid operation!"); |
|
575 |
|
return FALSE; |
|
576 |
|
} |
|
577 |
|
} |
|
578 |
|
$not_new_cond = $new_cond ? FALSE : TRUE; |
|
|
484 |
|
$left = trim($t[0]); |
|
485 |
|
$left = rg_template_string($left, 0, $data, FALSE); |
579 |
486 |
|
|
580 |
|
// We have to respect the outer block condition |
|
581 |
|
// We have to push in reverse order. Remeber, first in, last out |
|
582 |
|
$stack[] = $not_new_cond && $cond; |
|
583 |
|
$stack[] = $new_cond && $cond; |
|
584 |
|
} |
|
|
487 |
|
$right = trim($t[1]); |
|
488 |
|
$right = rg_template_string($right, 0, $data, FALSE); |
585 |
489 |
|
|
586 |
|
$tmp = rg_replace_conditionals_block($rest, $data, $stack); |
|
587 |
|
if ($tmp === FALSE) |
|
|
490 |
|
$ret = strcmp($left, $right); |
|
491 |
|
if ($ret === 0) { |
|
492 |
|
if ($negate === TRUE) |
|
493 |
|
return FALSE; |
|
494 |
|
} else { |
|
495 |
|
if (!$negate) |
588 |
496 |
return FALSE; |
return FALSE; |
589 |
|
|
|
590 |
|
//rg_log("DEBUG: returning [" . $ret . $tmp . "]"); |
|
591 |
|
return $ret . $tmp; |
|
592 |
497 |
} |
} |
593 |
498 |
|
|
594 |
|
if ($cond === FALSE) |
|
595 |
|
$block = ""; |
|
596 |
|
|
|
597 |
|
//rg_log("DEBUG: returning [$block]"); |
|
598 |
|
return $block; |
|
|
499 |
|
return TRUE; |
599 |
500 |
} |
} |
600 |
501 |
|
|
601 |
502 |
/* |
/* |
602 |
|
* Replace conditionals |
|
603 |
|
* @@if(X == Y){{A}}{{B}} - if X == Y it will return A, else B. |
|
604 |
|
* Do note that there is no ending @@. |
|
605 |
|
* Because of complexity, I choosed to have a restriction: the 'if' is on |
|
606 |
|
* a single line or '@@if(...){{', '}}{{' and '}}' are on separate lines. |
|
607 |
|
* TODO: Also, we must have both branches (both true and false), for now. |
|
608 |
|
* We support nested ifs. |
|
|
503 |
|
* Finds matching }} for an {{ |
|
504 |
|
* We assume @off points to the byte after '{{' |
|
505 |
|
* Returns the offset of the byte before '}}' |
609 |
506 |
*/ |
*/ |
610 |
|
function rg_replace_conditionals($block, &$data) |
|
|
507 |
|
function rg_template_find_closing(&$s, $off) |
611 |
508 |
{ |
{ |
612 |
|
rg_prof_start("replace_conditionals"); |
|
613 |
|
$ret = array(); |
|
614 |
|
|
|
|
509 |
|
$nesting_level = 0; |
615 |
510 |
while (1) { |
while (1) { |
616 |
|
$stack = array(); |
|
617 |
|
$stack[] = TRUE; |
|
618 |
|
$ret = rg_replace_conditionals_block($block, $data, $stack); |
|
619 |
|
if ($ret === FALSE) |
|
620 |
|
break; |
|
|
511 |
|
$end = strpos($s, '}}', $off); |
|
512 |
|
if ($end === FALSE) |
|
513 |
|
return -1; |
621 |
514 |
|
|
622 |
|
if (empty($stack) || ($stack[0] !== TRUE)) { |
|
623 |
|
rg_internal_error("Template nesting error!"); |
|
624 |
|
$ret = FALSE; |
|
625 |
|
break; |
|
626 |
|
} |
|
|
515 |
|
$start = strpos($s, '{{', $off); |
|
516 |
|
if (($start === FALSE) || ($start >= $end)) { |
|
517 |
|
if ($nesting_level == 0) |
|
518 |
|
return $end - 1; |
627 |
519 |
|
|
628 |
|
break; |
|
|
520 |
|
$nesting_level--; |
|
521 |
|
$off = $end + 2; |
|
522 |
|
} else { |
|
523 |
|
$nesting_level++; |
|
524 |
|
$off = $start + 2; |
|
525 |
|
} |
629 |
526 |
} |
} |
630 |
|
|
|
631 |
|
rg_prof_end("replace_conditionals"); |
|
632 |
|
return $ret; |
|
633 |
527 |
} |
} |
634 |
528 |
|
|
635 |
529 |
/* |
/* |
636 |
|
* Loads a file if exists, else return "" |
|
|
530 |
|
* "Decodes" an 'if', returning 'true_start/end' and false_start/end' |
|
531 |
|
* s + off must point after ')' |
|
532 |
|
* Returns -1 on error, 0 on success |
637 |
533 |
*/ |
*/ |
638 |
|
function rg_file_get_contents($f) |
|
|
534 |
|
function rg_template_find_true_and_false(&$s, $off, &$true_start, &$true_end, |
|
535 |
|
&$false_start, &$false_end) |
639 |
536 |
{ |
{ |
640 |
|
global $php_errormsg; |
|
|
537 |
|
//rg_log_enter("DEBUG: template_find_true_and_false s+off=[" . substr($s, $off) . "]"); |
641 |
538 |
|
|
642 |
|
if (!file_exists($f)) |
|
643 |
|
return ""; |
|
|
539 |
|
$true_start = strpos($s, '{{', $off); |
|
540 |
|
if ($true_start === FALSE) { |
|
541 |
|
//rg_log("DEBUG: no '{{'!"); |
|
542 |
|
//rg_log_exit(); |
|
543 |
|
return -1; |
|
544 |
|
} |
|
545 |
|
$true_start += 2; |
644 |
546 |
|
|
645 |
|
$c = @file_get_contents($f); |
|
646 |
|
if ($c === FALSE) { |
|
647 |
|
rg_internal_error("Could not load file [$f] ($php_errormsg)."); |
|
648 |
|
return ""; |
|
|
547 |
|
if (strncmp(substr($s, $true_start, 1), "\n", 1) == 0) { |
|
548 |
|
//rg_log("DEBUG: true starts with CR, remove it"); |
|
549 |
|
$true_start++; |
649 |
550 |
} |
} |
650 |
551 |
|
|
651 |
|
return $c; |
|
|
552 |
|
$true_end = rg_template_find_closing($s, $true_start); |
|
553 |
|
if ($true_end == -1) { |
|
554 |
|
//rg_log("DEBUG: no true_end!"); |
|
555 |
|
//rg_log_exit(); |
|
556 |
|
return -1; |
|
557 |
|
} |
|
558 |
|
//rg_log("DEBUG: true_start=$true_start true_end=$true_end [" . substr($s, $true_end, 3) . "...]" |
|
559 |
|
// . " true=[" . substr($s, $true_start, $true_end - $true_start + 1) . "]"); |
|
560 |
|
|
|
561 |
|
// We try to detect if we have an else |
|
562 |
|
$false_start = -1; $false_end = -1; |
|
563 |
|
$x = strpos($s, '{{', $true_end); |
|
564 |
|
if ($x !== FALSE) { |
|
565 |
|
$gap = substr($s, $true_end + 3, $x - $true_end - 3); |
|
566 |
|
$gap = trim($gap); |
|
567 |
|
//rg_log("DEBUG: gap = [$gap]"); |
|
568 |
|
if (empty($gap)) { |
|
569 |
|
$false_start = $x + 2; |
|
570 |
|
if (strncmp(substr($s, $false_start, 1), "\n", 1) == 0) { |
|
571 |
|
//rg_log("DEBUG: false starts with CR, remove it"); |
|
572 |
|
$false_start++; |
|
573 |
|
} |
|
574 |
|
$false_end = rg_template_find_closing($s, $x + 2); |
|
575 |
|
//rg_log("DEBUG: false=[" . substr($s, $false_start, $false_end - $false_start + 1) . "]"); |
|
576 |
|
} else { |
|
577 |
|
//rg_log("DEBUG: gap prevents parsing stuff as false, we have only true part"); |
|
578 |
|
} |
|
579 |
|
} else { |
|
580 |
|
//rg_log("DEBUG: cannot find '{{'"); |
|
581 |
|
} |
|
582 |
|
|
|
583 |
|
rg_log_exit(); |
|
584 |
|
return 0; |
652 |
585 |
} |
} |
653 |
586 |
|
|
654 |
587 |
/* |
/* |
655 |
|
* Merges an array (a) into another (src), using a namespace |
|
656 |
|
* Protects modifiers (HTML: etc.). |
|
|
588 |
|
* Helper for rg_tempalte_string to deal with 'if's |
|
589 |
|
* Returns how many bytes used from string @s in @next |
657 |
590 |
*/ |
*/ |
658 |
|
function rg_array_merge($src, $namespace, $a) |
|
|
591 |
|
function rg_template_string_if(&$s, $off, &$data, &$next, $xss_protection) |
659 |
592 |
{ |
{ |
660 |
|
$ret = $src; |
|
|
593 |
|
rg_prof_start("template_string_if"); |
|
594 |
|
//rg_log_enter("DEBUG: template_string_if s+off=[" . substr($s, $off) . "]"); |
|
595 |
|
|
|
596 |
|
$ret = ''; |
|
597 |
|
$next = $off; |
|
598 |
|
|
|
599 |
|
$off += 5; /* skip '@@if(' */ |
|
600 |
|
$pos = strpos($s, ')', $off); |
|
601 |
|
if ($pos === FALSE) { |
|
602 |
|
rg_log("no closing ')' in [" . substr($s, $off) . "]!"); |
|
603 |
|
rg_log_exit(); |
|
604 |
|
rg_prof_end("template_string_if"); |
|
605 |
|
return ''; |
|
606 |
|
} |
661 |
607 |
|
|
662 |
|
if (empty($a)) |
|
663 |
|
return $ret; |
|
|
608 |
|
$cond = substr($s, $off, $pos - $off); $off = $pos + 1; |
|
609 |
|
$eval_cond = rg_template_eval_cond($cond, $data); |
|
610 |
|
//rg_log("DEBUG: cond=[$cond] eval_cond=" . ($eval_cond ? "true" : "false")); |
664 |
611 |
|
|
665 |
|
if (!empty($namespace)) |
|
666 |
|
$namespace .= "::"; |
|
|
612 |
|
// TODO: Between ')' and '{{' must be only space, else ignore anything?? |
667 |
613 |
|
|
668 |
|
foreach ($a as $k => $v) { |
|
669 |
|
$t = explode(":", $k, 2); |
|
670 |
|
if (count($t) == 1) |
|
671 |
|
$ret[$namespace . $k] = $v; |
|
672 |
|
else |
|
673 |
|
$ret[$t[0] . ":" . $namespace . $t[1]] = $v; |
|
|
614 |
|
$r = rg_template_find_true_and_false($s, $off, $true_start, $true_end, |
|
615 |
|
$false_start, $false_end); |
|
616 |
|
if ($r == -1) { |
|
617 |
|
rg_log("no if skeleton found [" . substr($s, $off) . "]!"); |
|
618 |
|
//rg_log_exit(); |
|
619 |
|
rg_prof_end("template_string_if"); |
|
620 |
|
return -1; |
|
621 |
|
} |
|
622 |
|
|
|
623 |
|
$x = ''; |
|
624 |
|
if ($eval_cond === TRUE) { |
|
625 |
|
$x = substr($s, $true_start, $true_end - $true_start + 1); |
|
626 |
|
} else { |
|
627 |
|
if ($false_start != -1) |
|
628 |
|
$x = substr($s, $false_start, $false_end - $false_start + 1); |
674 |
629 |
} |
} |
|
630 |
|
//rg_log("DEBUG: x=[$x]"); |
675 |
631 |
|
|
|
632 |
|
$ret .= rg_template_string($x, 0, $data, $xss_protection); |
|
633 |
|
|
|
634 |
|
if ($false_start != -1) |
|
635 |
|
$next = $false_end + 3; |
|
636 |
|
else |
|
637 |
|
$next = $true_end + 3; |
|
638 |
|
|
|
639 |
|
if (strncmp(substr($s, $next, 1), "\n", 1) == 0) |
|
640 |
|
$next++; |
|
641 |
|
|
|
642 |
|
//rg_log("DEBUG: next: [" . substr($s, $next) . "]"); |
|
643 |
|
//rg_log_exit(); |
|
644 |
|
rg_prof_end("template_string_if"); |
676 |
645 |
return $ret; |
return $ret; |
677 |
646 |
} |
} |
678 |
647 |
|
|
679 |
648 |
/* |
/* |
680 |
|
* Builds a html output based on a template with header, footer and line |
|
681 |
|
* @data - in array of data for every out line: index 0 is line 1, index 1 is line 2... |
|
|
649 |
|
* Replace all known variables in string @s |
|
650 |
|
* Example @data: a->a2->a3, b->b2; @s='@@a::a2@@ @@b@@' => 'a3 b2' |
|
651 |
|
* @xss_protection - TRUE if you want to apply rg_xss_safe on the value of vars |
682 |
652 |
*/ |
*/ |
683 |
|
function rg_template_table($dir, &$data, $more) |
|
|
653 |
|
function rg_template_string(&$s, $off, &$data, $xss_protection) |
684 |
654 |
{ |
{ |
685 |
|
global $rg_theme_dir; |
|
686 |
|
global $rg_theme; |
|
687 |
|
|
|
688 |
|
rg_log("rg_template_table: $dir"); |
|
689 |
|
|
|
690 |
|
$xdir = $rg_theme_dir . "/" . $rg_theme . "/" . $dir; |
|
691 |
|
if (!is_dir($xdir)) { |
|
692 |
|
rg_log("$xdir not found."); |
|
693 |
|
$xdir = $rg_theme_dir . "/default/" . $dir; |
|
694 |
|
rg_log("Using [$xdir]"); |
|
695 |
|
} |
|
696 |
|
|
|
697 |
|
$m_what = array(); $m_values = array(); |
|
698 |
|
rg_prepare_replace($more, $m_what, $m_values); |
|
699 |
|
|
|
700 |
|
if (!is_array($data) || empty($data)) { |
|
701 |
|
$no_data = rg_file_get_contents($xdir . "/nodata.html"); |
|
702 |
|
$r = rg_replace_conditionals($no_data, $more); |
|
703 |
|
return preg_replace($m_what, $m_values, $r); |
|
704 |
|
} |
|
705 |
|
|
|
706 |
|
$head = rg_file_get_contents($xdir . "/header.html"); |
|
707 |
|
$line = rg_file_get_contents($xdir . "/line.html"); |
|
708 |
|
$foot = rg_file_get_contents($xdir . "/footer.html"); |
|
709 |
|
$between = rg_file_get_contents($xdir . "/between.html"); |
|
|
655 |
|
global $rg_template_functions; |
710 |
656 |
|
|
711 |
|
$head = rg_replace_conditionals($head, $more); |
|
712 |
|
$foot = rg_replace_conditionals($foot, $more); |
|
713 |
|
$between = rg_replace_conditionals($between, $more); |
|
|
657 |
|
rg_prof_start("rg_template_string"); |
|
658 |
|
//rg_log_enter("DEBUG: template_string: s+off=[" . substr($s, $off) . "]"); |
714 |
659 |
|
|
715 |
|
$head = preg_replace($m_what, $m_values, $head); |
|
716 |
|
$foot = preg_replace($m_what, $m_values, $foot); |
|
717 |
|
$between = preg_replace($m_what, $m_values, $between); |
|
|
660 |
|
$ret = ''; |
|
661 |
|
while (strlen(substr($s, $off, 1)) == 1) { |
|
662 |
|
//rg_log("DEBUG: template_string: s+off=[" . substr($s, $off) . "]"); |
|
663 |
|
$pos = strpos($s, '@@', $off); |
|
664 |
|
if ($pos === FALSE) { |
|
665 |
|
$ret .= substr($s, $off); |
|
666 |
|
break; |
|
667 |
|
} |
|
668 |
|
$var_start = $pos + 2; |
|
669 |
|
|
|
670 |
|
// copy everything before '@@' |
|
671 |
|
$ret .= substr($s, $off, $pos - $off); |
|
672 |
|
//rg_log("DEBUG: after copy all before @@, ret=[$ret]"); |
|
673 |
|
$off = $pos; |
|
674 |
|
|
|
675 |
|
$s2 = substr($s, $off, 5); |
|
676 |
|
if (strcmp($s2, '@@if(') == 0) { |
|
677 |
|
$ret .= rg_template_string_if($s, $off, $data, $next, |
|
678 |
|
$xss_protection); |
|
679 |
|
$off = $next; |
|
680 |
|
continue; |
|
681 |
|
} |
718 |
682 |
|
|
719 |
|
$body = ""; |
|
720 |
|
$first = 1; |
|
721 |
|
foreach ($data as $index => $info) { |
|
722 |
|
$what = $m_what; $values = $m_values; |
|
|
683 |
|
$off += 2; /* skip start '@@' */ |
|
684 |
|
$pos2 = strpos($s, '@@', $off); |
|
685 |
|
if ($pos2 === FALSE) { |
|
686 |
|
// We have only start '@@' |
|
687 |
|
$ret .= substr($s, $off); |
|
688 |
|
break; |
|
689 |
|
} |
|
690 |
|
$var_end = $pos2 - 1; |
|
691 |
|
$off = $pos2 + 2; |
|
692 |
|
|
|
693 |
|
$var = substr($s, $var_start, $var_end - $var_start + 1); |
|
694 |
|
//rg_log("DEBUG: var=[$var]"); |
|
695 |
|
|
|
696 |
|
$value = rg_template_tree_lookup($var, $data, $xss_protection); |
|
697 |
|
if ($value === FALSE) { |
|
698 |
|
$value = '@@' . $var . '@@'; |
|
699 |
|
if (strncmp($var, 'IMG:', 4) == 0) { |
|
700 |
|
$path = substr($var, 4); |
|
701 |
|
$path = rg_template_string($path, 0, $data, $xss_protection); |
|
702 |
|
//rg_log("DEBUG: found an img tag path=[$path]!"); |
|
703 |
|
$value = rg_theme_resolve_path($path); |
|
704 |
|
} else if (strncmp($var, 'FUNC:', 5) == 0) { |
|
705 |
|
$rest = substr($var, 5); |
|
706 |
|
//rg_log("DEBUG: found a function call rest=[$rest]!"); |
|
707 |
|
$fpos = strpos($rest, ':'); |
|
708 |
|
if ($fpos === FALSE) { |
|
709 |
|
// no params |
|
710 |
|
$_param = ''; |
|
711 |
|
} else { |
|
712 |
|
$_param = '@@' . substr($rest, $fpos + 1) . '@@'; |
|
713 |
|
} |
723 |
714 |
|
|
724 |
|
rg_prepare_replace($info, $what, $values); |
|
725 |
|
rg_prepare_func($line, $what, $values); |
|
|
715 |
|
$func = substr($rest, 0, $fpos); |
|
716 |
|
//rg_log("DEBUG: func=$func _param=$_param"); |
726 |
717 |
|
|
727 |
|
$line = rg_prepare_image($line); |
|
|
718 |
|
// out var may be with '@@' |
|
719 |
|
$param = rg_template_string($_param, 0, $data, $xss_protection); |
728 |
720 |
|
|
729 |
|
if ($first == 1) { |
|
730 |
|
$first = 0; |
|
731 |
|
} else { |
|
732 |
|
$body .= $between; |
|
|
721 |
|
if (isset($rg_template_functions[$func])) |
|
722 |
|
$value = $rg_template_functions[$func]($param); |
|
723 |
|
} else { |
|
724 |
|
rg_log("DEBUG: VAR [$var] NOT FOUND!"); |
|
725 |
|
} |
733 |
726 |
} |
} |
734 |
|
|
|
735 |
|
$more2 = array_merge($more, $info); |
|
736 |
|
$r = rg_replace_conditionals($line, $more2); |
|
737 |
|
$body .= preg_replace($what, $values, $r); |
|
|
727 |
|
//rg_log("DEBUG: value=[$value]"); |
|
728 |
|
$ret .= $value; |
738 |
729 |
} |
} |
739 |
730 |
|
|
740 |
|
return $head . $body . $foot; |
|
|
731 |
|
//rg_log("DEBUG: ret=[$ret]"); |
|
732 |
|
//rg_log_exit(); |
|
733 |
|
rg_prof_end("rg_template_string"); |
|
734 |
|
return $ret; |
741 |
735 |
} |
} |
742 |
736 |
|
|
743 |
737 |
/* |
/* |
744 |
|
* Loads a template. |
|
745 |
|
* TODO: why we pass variable by reference?! |
|
|
738 |
|
* Loads a template from disk and replase all known variables |
|
739 |
|
* @xss_protection - TRUE if you want to apply rg_xss_safe on the value of vars |
746 |
740 |
*/ |
*/ |
747 |
|
function rg_template($file, &$data) |
|
|
741 |
|
function rg_template($file, &$data, $xss_protection) |
748 |
742 |
{ |
{ |
749 |
743 |
global $rg_theme_dir; |
global $rg_theme_dir; |
750 |
744 |
global $rg_theme; |
global $rg_theme; |
|
... |
... |
function rg_template($file, &$data) |
752 |
746 |
rg_prof_start("rg_template"); |
rg_prof_start("rg_template"); |
753 |
747 |
rg_log_enter("rg_template: $file"); |
rg_log_enter("rg_template: $file"); |
754 |
748 |
|
|
755 |
|
$ret = ""; |
|
|
749 |
|
$ret = ''; |
756 |
750 |
while (1) { |
while (1) { |
757 |
751 |
$xfile = $rg_theme_dir . "/" . $rg_theme . "/" . $file; |
$xfile = $rg_theme_dir . "/" . $rg_theme . "/" . $file; |
758 |
752 |
if (!is_file($xfile)) { |
if (!is_file($xfile)) { |
|
... |
... |
function rg_template($file, &$data) |
771 |
765 |
break; |
break; |
772 |
766 |
} |
} |
773 |
767 |
|
|
774 |
|
$what = array(); |
|
775 |
|
$values = array(); |
|
|
768 |
|
$ret = rg_template_string($body, 0, $data, $xss_protection); |
|
769 |
|
break; |
|
770 |
|
} |
|
771 |
|
|
|
772 |
|
//rg_log("DEBUG: rg_template returns [$ret]"); |
|
773 |
|
rg_log_exit(); |
|
774 |
|
rg_prof_end("rg_template"); |
|
775 |
|
return $ret; |
|
776 |
|
} |
|
777 |
|
|
|
778 |
|
/* |
|
779 |
|
* Builds a html output based on a template with header, footer and line |
|
780 |
|
* @data - in array of data for every out line: index 0 is line 1, index 1 is line 2... |
|
781 |
|
*/ |
|
782 |
|
function rg_template_table($dir, &$data, $more) |
|
783 |
|
{ |
|
784 |
|
global $rg_theme_dir; |
|
785 |
|
global $rg_theme; |
776 |
786 |
|
|
777 |
|
rg_prepare_replace($data, $what, $values); |
|
778 |
|
rg_prepare_func($body, $what, $values); |
|
|
787 |
|
rg_log("rg_template_table: $dir"); |
779 |
788 |
|
|
780 |
|
$body = rg_prepare_image($body); |
|
|
789 |
|
$xdir = $rg_theme_dir . "/" . $rg_theme . "/" . $dir; |
|
790 |
|
if (!is_dir($xdir)) { |
|
791 |
|
rg_log("$xdir not found."); |
|
792 |
|
$xdir = $rg_theme_dir . "/default/" . $dir; |
|
793 |
|
rg_log("Using [$xdir]"); |
|
794 |
|
} |
781 |
795 |
|
|
782 |
|
$r = rg_replace_conditionals($body, $data); |
|
783 |
|
// TODO: check error code! |
|
|
796 |
|
if (!is_array($data) || empty($data)) |
|
797 |
|
return rg_template($xdir . "/nodata.html", $more, TRUE /* xss */); |
784 |
798 |
|
|
785 |
|
$ret = preg_replace($what, $values, $r); |
|
786 |
|
// TODO: check error code! |
|
|
799 |
|
$head = rg_template($xdir . "/header.html", $more, TRUE /* xss */); |
|
800 |
|
$foot = rg_template($xdir . "/footer.html", $more, TRUE /* xss */); |
|
801 |
|
$between = rg_template($xdir . "/between.html", $more, TRUE /* xss */); |
787 |
802 |
|
|
788 |
|
break; |
|
|
803 |
|
$line = rg_file_get_contents($xdir . "/line.html"); |
|
804 |
|
|
|
805 |
|
$body = ''; |
|
806 |
|
$first = 1; |
|
807 |
|
foreach ($data as $index => $info) { |
|
808 |
|
if ($first == 1) |
|
809 |
|
$first = 0; |
|
810 |
|
else |
|
811 |
|
$body .= $between; |
|
812 |
|
|
|
813 |
|
$more2 = array_merge($more, $info); |
|
814 |
|
$body .= rg_template_string($line, 0, $more2, TRUE /* xss */); |
789 |
815 |
} |
} |
790 |
816 |
|
|
791 |
|
rg_log_exit(); |
|
792 |
|
rg_prof_end("rg_template"); |
|
793 |
|
return $ret; |
|
|
817 |
|
return $head . $body . $foot; |
794 |
818 |
} |
} |
795 |
819 |
|
|
796 |
820 |
/* |
/* |
|
... |
... |
function rg_warning($msg) |
839 |
863 |
rg_log("Warning: $msg"); |
rg_log("Warning: $msg"); |
840 |
864 |
|
|
841 |
865 |
$x = array("msg" => $msg); |
$x = array("msg" => $msg); |
842 |
|
return rg_template("warning.html", $x); |
|
|
866 |
|
return rg_template("warning.html", $x, TRUE /* xss */); |
843 |
867 |
} |
} |
844 |
868 |
|
|
845 |
869 |
/* |
/* |
|
... |
... |
function rg_ok($msg) |
852 |
876 |
return ""; |
return ""; |
853 |
877 |
|
|
854 |
878 |
$x = array("msg" => $msg); |
$x = array("msg" => $msg); |
855 |
|
return rg_template("ok.html", $x); |
|
|
879 |
|
return rg_template("ok.html", $x, TRUE /* xss */); |
856 |
880 |
} |
} |
857 |
881 |
|
|
858 |
882 |
/* |
/* |
|
... |
... |
function rg_copy_tree($src, $dst, $mask) |
1080 |
1104 |
{ |
{ |
1081 |
1105 |
global $php_errormsg; |
global $php_errormsg; |
1082 |
1106 |
|
|
1083 |
|
rg_log("rg_copy_tree($src, $dst, $mask)"); |
|
|
1107 |
|
rg_prof_start("copy_tree"); |
|
1108 |
|
rg_log_enter("rg_copy_tree($src, $dst, $mask)"); |
1084 |
1109 |
|
|
1085 |
|
if (!is_dir($dst)) { |
|
1086 |
|
$r = @mkdir($dst, $mask); |
|
1087 |
|
if ($r !== TRUE) { |
|
1088 |
|
rg_log("ERROR: Cannot mkdir [$dst] ($php_errormsg)."); |
|
1089 |
|
return FALSE; |
|
|
1110 |
|
$ret = FALSE; |
|
1111 |
|
while (1) { |
|
1112 |
|
if (!is_dir($dst)) { |
|
1113 |
|
$r = @mkdir($dst, $mask); |
|
1114 |
|
if ($r !== TRUE) { |
|
1115 |
|
rg_log("ERROR: Cannot mkdir [$dst] ($php_errormsg)."); |
|
1116 |
|
break; |
|
1117 |
|
} |
1090 |
1118 |
} |
} |
1091 |
|
} |
|
1092 |
1119 |
|
|
1093 |
|
$d = rg_dir_load($src); |
|
1094 |
|
foreach ($d as $obj) { |
|
1095 |
|
if (is_dir($src . "/" . $obj)) { |
|
1096 |
|
if (!is_dir($dst . "/" . $obj)) { |
|
1097 |
|
$r = @mkdir($dst . "/" . $obj, $mask); |
|
1098 |
|
if ($r !== TRUE) { |
|
1099 |
|
rg_log("ERROR: Cannot mkdir [$dst/$obj]" |
|
1100 |
|
. " ($php_errormsg)."); |
|
1101 |
|
return FALSE; |
|
|
1120 |
|
$d = rg_dir_load($src); |
|
1121 |
|
$err = FALSE; |
|
1122 |
|
foreach ($d as $obj) { |
|
1123 |
|
if (is_dir($src . "/" . $obj)) { |
|
1124 |
|
if (!is_dir($dst . "/" . $obj)) { |
|
1125 |
|
$r = @mkdir($dst . "/" . $obj, $mask); |
|
1126 |
|
if ($r !== TRUE) { |
|
1127 |
|
rg_log("ERROR: Cannot mkdir [$dst/$obj]" |
|
1128 |
|
. " ($php_errormsg)."); |
|
1129 |
|
$err = TRUE; |
|
1130 |
|
break; |
|
1131 |
|
} |
1102 |
1132 |
} |
} |
1103 |
|
} |
|
1104 |
1133 |
|
|
1105 |
|
$r = rg_copy_tree($src . "/" . $obj, $dst . "/" . $obj, $mask); |
|
1106 |
|
if ($r !== TRUE) |
|
1107 |
|
return FALSE; |
|
1108 |
|
} else { |
|
1109 |
|
$r = @copy($src . "/" . $obj, $dst . "/" . $obj); |
|
1110 |
|
if ($r !== TRUE) { |
|
1111 |
|
rg_log("ERROR: Cannot copy file ($php_errormsg)."); |
|
1112 |
|
return FALSE; |
|
|
1134 |
|
$r = rg_copy_tree($src . "/" . $obj, $dst . "/" . $obj, $mask); |
|
1135 |
|
if ($r !== TRUE) { |
|
1136 |
|
$err = TRUE; |
|
1137 |
|
break; |
|
1138 |
|
} |
|
1139 |
|
} else { |
|
1140 |
|
$r = @copy($src . "/" . $obj, $dst . "/" . $obj); |
|
1141 |
|
if ($r !== TRUE) { |
|
1142 |
|
rg_log("ERROR: Cannot copy file ($php_errormsg)."); |
|
1143 |
|
$err = TRUE; |
|
1144 |
|
break; |
|
1145 |
|
} |
1113 |
1146 |
} |
} |
1114 |
1147 |
} |
} |
|
1148 |
|
|
|
1149 |
|
if (!$err) |
|
1150 |
|
$ret = TRUE; |
|
1151 |
|
break; |
1115 |
1152 |
} |
} |
1116 |
1153 |
|
|
1117 |
|
return TRUE; |
|
|
1154 |
|
rg_log_exit(); |
|
1155 |
|
rg_prof_end("copy_tree"); |
|
1156 |
|
return $ret; |
1118 |
1157 |
} |
} |
1119 |
1158 |
|
|
1120 |
1159 |
/* |
/* |
|
... |
... |
function rg_mail_template($template, $more) |
1201 |
1240 |
rg_log("mail_template: $template, more=" . rg_array2string($more)); |
rg_log("mail_template: $template, more=" . rg_array2string($more)); |
1202 |
1241 |
|
|
1203 |
1242 |
// Account was not confirmed, so do not send mail |
// Account was not confirmed, so do not send mail |
1204 |
|
if (empty($more['ui::email'])) |
|
|
1243 |
|
if (empty($more['ui']['email'])) |
1205 |
1244 |
return TRUE; |
return TRUE; |
1206 |
1245 |
|
|
1207 |
1246 |
$more['HTML:rg_admin_email'] = $rg_admin_email; |
$more['HTML:rg_admin_email'] = $rg_admin_email; |
1208 |
1247 |
$more['HTML:utf8_rg_admin_name'] = "=?UTF-8?B?" |
$more['HTML:utf8_rg_admin_name'] = "=?UTF-8?B?" |
1209 |
1248 |
. base64_encode($rg_admin_name) . "?="; |
. base64_encode($rg_admin_name) . "?="; |
1210 |
1249 |
|
|
1211 |
|
$subject = rg_template($template . ".subj.txt", $more); |
|
|
1250 |
|
$subject = rg_template($template . ".subj.txt", $more, FALSE /* xss */); |
1212 |
1251 |
$subject = "=?UTF-8?B?" . base64_encode(trim($subject)) . "?="; |
$subject = "=?UTF-8?B?" . base64_encode(trim($subject)) . "?="; |
1213 |
|
$header = rg_template("mail/common.head.txt", $more); |
|
1214 |
|
$header .= rg_template($template . ".head.txt", $more); |
|
|
1252 |
|
$header = rg_template("mail/common.head.txt", $more, FALSE /* xss */); |
|
1253 |
|
$header .= rg_template($template . ".head.txt", $more, FALSE /* xss */); |
1215 |
1254 |
$header = trim($header); |
$header = trim($header); |
1216 |
|
$body = rg_template($template . ".body.txt", $more); |
|
|
1255 |
|
$body = rg_template($template . ".body.txt", $more, FALSE /* xss */); |
1217 |
1256 |
|
|
1218 |
|
rg_log("CHECK: mail_template(" . $more['ui::email'] . ", |
|
|
1257 |
|
rg_log("CHECK: mail_template(" . $more['ui']['email'] . ", |
1219 |
1258 |
$subject, $body, $header, -f $rg_admin_email"); |
$subject, $body, $header, -f $rg_admin_email"); |
1220 |
|
$ret = mail($more['ui::email'], $subject, $body, $header, |
|
|
1259 |
|
$ret = mail($more['ui']['email'], $subject, $body, $header, |
1221 |
1260 |
"-f $rg_admin_email"); |
"-f $rg_admin_email"); |
1222 |
1261 |
if ($ret === FALSE) |
if ($ret === FALSE) |
1223 |
|
rg_log("Sending mail failed to=" . $more['ui::email'] . " subject=$subject!"); |
|
|
1262 |
|
rg_log("Sending mail failed to=" . $more['ui']['email'] |
|
1263 |
|
. " subject=$subject!"); |
1224 |
1264 |
|
|
1225 |
1265 |
rg_prof_end("mail_template"); |
rg_prof_end("mail_template"); |
1226 |
1266 |
return $ret; |
return $ret; |
File tests/keys.php changed (mode: 100644) (index 5f236c1..4576db7) |
... |
... |
$res = rg_sql_query($db, $sql); |
28 |
28 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
29 |
29 |
|
|
30 |
30 |
// insert a key 1 |
// insert a key 1 |
31 |
|
$key = "aaa 'bbb' first_key"; |
|
32 |
|
$key_id1 = rg_keys_add($db, $rg_ui, $key); |
|
|
31 |
|
$key1 = "ssh-dss AAAAB3NzaC1kc3MAAACBAJLkWtcoCUbWCRXecE907nO1gSh6IrfkD5bsyobrFOp6xYuJvfteKKpE79HUcbEpzIVFNk3mlQf/+k9cFP2Wy8F34UXFk8cXU4FU7z/TM1iHHOHnqFqvzv59LRaaMw4MaHm/4WKdfJy16KOLgosSBzWif3a1nKMdIZuYeIGso7qFAAAAFQC4JU7YoGu2nZQ0fEXFKaRhq+d9UQAAAIEAhgslkwwID6oBBdWx+mUuaXKt/bZcdCfNyjnejxlsZHPfDnayuqCKIgxlhYpiPS6LwiSK5feL55meF33HanCzX53z7ieoW6Je9z2H8/93sCvzk4LMj7XkeEy3G5UnRuL+uc6qrazF7Pu448cQH0pkh6N0zNueQlPpGL4/lHbIiVgAAACAQJup/h36aD9DprosVCQe40nalp7t4o/M75Y70sV7FNrL0azUQcn1ZL+J8F9l/dDRPG3rST2DABgba9pHGWa96vaNfTLnopy3po/296SYQl7/1nek0YtioEikoB+HQxk7eSwRI6bTpKEFNyUnp2/bcNjJYORKCeYwJJ2KDW6GJro= first_key"; |
|
32 |
|
$key_id1 = rg_keys_add($db, $rg_ui, $key1); |
33 |
33 |
if ($key_id1 === FALSE) { |
if ($key_id1 === FALSE) { |
34 |
34 |
rg_log("Cannot add key 1 (" . rg_keys_error() . ")!"); |
rg_log("Cannot add key 1 (" . rg_keys_error() . ")!"); |
35 |
35 |
exit(1); |
exit(1); |
|
... |
... |
if ($key_id1 === FALSE) { |
37 |
37 |
|
|
38 |
38 |
// insert a key 2 |
// insert a key 2 |
39 |
39 |
$rg_ui['uid'] = 2; |
$rg_ui['uid'] = 2; |
40 |
|
$key = "aaa 'bbb' second_key"; |
|
41 |
|
$key_id2 = rg_keys_add($db, $rg_ui, $key); |
|
|
40 |
|
$key2 = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+2OHaQiZzdwV4HQF9pCBbSQFaoM5Q0YmmRYDL8BUCjwClDgOLp9lQVN5XksoBx2t9INj6XrobjNc/GUF60c1Ald0FtjRl7nIZdYvKDutlxHcGUy6MHsVnCDviXQJD9Hm9fyuBLdy3/oadSCAaQYE/Tcf9rWt1NmhQ7560bCGmh4pw8N+XXAz2nQBCqvIK8VDoBbOOgFa/HOwBrKCgaGmcTGs5wRWHbw3+h6CO1vqEYcSCSqBPMG1JOMfMTuJ0aTXXEkSNPF+TVva85L4qrQslyHbn2JU1t7/HQsFnGtgF1o2AglIR2RbyMmr6axI51Srf20EB9/c9T3auYQipbw85 second_key"; |
|
41 |
|
$key_id2 = rg_keys_add($db, $rg_ui, $key2); |
42 |
42 |
if ($key_id2 === FALSE) { |
if ($key_id2 === FALSE) { |
43 |
43 |
rg_log("Cannot add key 2 (" . rg_keys_error() . ")!"); |
rg_log("Cannot add key 2 (" . rg_keys_error() . ")!"); |
44 |
44 |
exit(1); |
exit(1); |
|
... |
... |
if ($c === FALSE) { |
60 |
60 |
} |
} |
61 |
61 |
$e = "command=\"" |
$e = "command=\"" |
62 |
62 |
. $rg_scripts . "/scripts/remote.sh 1 $key_id1\"," |
. $rg_scripts . "/scripts/remote.sh 1 $key_id1\"," |
63 |
|
. $rg_ssh_paras . " aaa 'bbb' first_key\n" |
|
|
63 |
|
. $rg_ssh_paras . ' ' . $key1 . "\n" |
64 |
64 |
. "command=\"" |
. "command=\"" |
65 |
65 |
. $rg_scripts . "/scripts/remote.sh 2 $key_id2\"," |
. $rg_scripts . "/scripts/remote.sh 2 $key_id2\"," |
66 |
|
. $rg_ssh_paras . " aaa 'bbb' second_key\n"; |
|
|
66 |
|
. $rg_ssh_paras . ' ' . $key2 . "\n"; |
67 |
67 |
if (strcmp($c, $e) != 0) { |
if (strcmp($c, $e) != 0) { |
68 |
68 |
rg_log("Generated file does not seems OK!"); |
rg_log("Generated file does not seems OK!"); |
69 |
69 |
rg_log("e: $e"); |
rg_log("e: $e"); |
|
... |
... |
if (strcmp($c, $e) != 0) { |
74 |
74 |
@unlink("afile.txt"); |
@unlink("afile.txt"); |
75 |
75 |
|
|
76 |
76 |
|
|
|
77 |
|
// test rg_max_ssh_keys - must fail because overlimit |
|
78 |
|
$rg_max_ssh_keys = 1; |
|
79 |
|
$key3 = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUiVHDS3rhn79+9YbXXN+npU9tDTzXZHkXZF9BNqI0GrnASuaBU2oJ/UK2OCgGQ45JOlzUCXcP09hHcyPqd4pZdHQhMAImCnm0iRivQ9VhJRRbl/s8kokoStZGAdcW+ETlhUtRXSQOu8U1PXqwUwZCkeE9asmS4Wg9/OO3eDuTMvE3yiNpHKt6TcVYlU6PlsiTFVJrAuIEbXRs5b5luuM+nM17caos0mn6w+kZ3QD9AnX+9pN4VgXKxEHGfWpOCtRDOQb9mTk2bX6MBJrcKtkAPnyYDiaRs1ANG7L4AP6to/gy3A9w6flTAD94gFAm833earIZJnCiavx3/dUWWt3L third_key'; |
|
80 |
|
$key_id3 = rg_keys_add($db, $rg_ui, $key3); |
|
81 |
|
if ($key_id3 !== FALSE) { |
|
82 |
|
rg_log("Seems we can add more keys than allowed! Not good!"); |
|
83 |
|
exit(1); |
|
84 |
|
} |
|
85 |
|
|
77 |
86 |
// delete a key |
// delete a key |
78 |
87 |
$rg_ui['uid'] = 1; |
$rg_ui['uid'] = 1; |
79 |
|
$list = array($key_id1 => "junk"); |
|
|
88 |
|
$list = array($key_id1 => 'junk'); |
80 |
89 |
$r = rg_keys_remove($db, $rg_ui, $list); |
$r = rg_keys_remove($db, $rg_ui, $list); |
81 |
90 |
if ($r === FALSE) { |
if ($r === FALSE) { |
82 |
91 |
rg_log("Cannot remove key (" . rg_keys_error() . ")!"); |
rg_log("Cannot remove key (" . rg_keys_error() . ")!"); |
|
... |
... |
if ($r === FALSE) { |
84 |
93 |
} |
} |
85 |
94 |
|
|
86 |
95 |
|
|
87 |
|
// test rg_max_ssh_keys |
|
88 |
|
$rg_max_ssh_keys = 1; |
|
89 |
|
// insert a key - should succeed |
|
90 |
|
$rg_ui['uid'] = 10; |
|
91 |
|
$key = "aaa 'bbb' first_key"; |
|
92 |
|
$key_id1 = rg_keys_add($db, $rg_ui, $key); |
|
93 |
|
if ($key_id1 === FALSE) { |
|
94 |
|
rg_log("Cannot add key 1 (" . rg_keys_error() . ")!"); |
|
|
96 |
|
rg_log_ml("\n\nTesting a good key"); |
|
97 |
|
$type = 'ssh-dss'; |
|
98 |
|
$body = 'AAAAB3NzaC1kc3MAAACBAJLkWtcoCUbWCRXecE907nO1gSh6IrfkD5bsyobrFOp6xYuJvfteKKpE79HUcbEpzIVFNk3mlQf/+k9cFP2Wy8F34UXFk8cXU4FU7z/TM1iHHOHnqFqvzv59LRaaMw4MaHm/4WKdfJy16KOLgosSBzWif3a1nKMdIZuYeIGso7qFAAAAFQC4JU7YoGu2nZQ0fEXFKaRhq+d9UQAAAIEAhgslkwwID6oBBdWx+mUuaXKt/bZcdCfNyjnejxlsZHPfDnayuqCKIgxlhYpiPS6LwiSK5feL55meF33HanCzX53z7ieoW6Je9z2H8/93sCvzk4LMj7XkeEy3G5UnRuL+uc6qrazF7Pu448cQH0pkh6N0zNueQlPpGL4/lHbIiVgAAACAQJup/h36aD9DprosVCQe40nalp7t4o/M75Y70sV7FNrL0azUQcn1ZL+J8F9l/dDRPG3rST2DABgba9pHGWa96vaNfTLnopy3po/296SYQl7/1nek0YtioEikoB+HQxk7eSwRI6bTpKEFNyUnp2/bcNjJYORKCeYwJJ2KDW6GJro='; |
|
99 |
|
$comment = 'comment'; |
|
100 |
|
$key = $type . ' ' . $body . ' ' . $comment; |
|
101 |
|
$r = rg_keys_info($key); |
|
102 |
|
if ($r['ok'] != 1) { |
|
103 |
|
rg_log("Error for a valid key: " . rg_keys_error() . "!"); |
|
104 |
|
exit(1); |
|
105 |
|
} |
|
106 |
|
|
|
107 |
|
rg_log_ml("\n\nTesting the recover when the key is full of spaces because of the paste"); |
|
108 |
|
$type = 'ssh-dss'; |
|
109 |
|
$body = 'AAAAB3Nza' . "\n" . 'C1kc3MAAACB' . ' ' . 'AJLkWtcoCUbWCR' . ' ' |
|
110 |
|
. 'XecE907nO1gSh6IrfkD5bsyobrFOp6xYuJvft' . ' ' . 'eKKpE79HUcbEpzIVFN' |
|
111 |
|
. 'k3mlQf/+k9cFP2Wy8F34UXFk8cXU4FU7z/TM1iHHOHnqFqvzv59LRaaMw4MaHm/4WK' |
|
112 |
|
. 'dfJy16KOLgosSBzWif3a1nKMdIZuYeIGso7qFAAAAFQC4JU7YoGu2nZQ0fEXFKaRhq' |
|
113 |
|
. '+d9UQAAAIEAhgslkwwID6oBBdWx+mUuaXKt/bZcdCfNyjnejxlsZHPfDnayuqCKIgx' |
|
114 |
|
. 'lhYpiPS6LwiSK5feL55meF33HanCzX53z7ieoW6Je9z2H8/93sCvzk4LMj7XkeEy3G' |
|
115 |
|
. '5UnRuL+uc6qrazF7Pu448cQH0pkh6N0zNueQlPpGL4/lHbIiVgAAACAQJup/h36aD9' |
|
116 |
|
. 'DprosVCQe40nalp7t4o/M75Y70sV7FNrL0azUQcn1ZL+J8F9l/dDRPG3rST2DABgba' |
|
117 |
|
. '9pHGWa96vaNfTLnopy3po/296SYQl7/1nek0YtioEikoB+HQxk7eSwRI6bTpKEFNyU' |
|
118 |
|
. 'np2/bcNjJYORKCeYwJJ2KDW6' . ' ' . 'GJro='; |
|
119 |
|
$comment = 'comment1 comment2 comment3'; |
|
120 |
|
$key = $type . ' ' . $body . ' ' . $comment; |
|
121 |
|
$r = rg_keys_info($key); |
|
122 |
|
if ($r['ok'] != 1) { |
|
123 |
|
rg_log("Error for a valid key (with spaces): " . rg_keys_error() . "!"); |
|
124 |
|
exit(1); |
|
125 |
|
} |
|
126 |
|
|
|
127 |
|
rg_log_ml("\n\nTesting mismatch between types"); |
|
128 |
|
$type = 'ssh-rsa'; |
|
129 |
|
$comment = 'comment1 comment2 comment3'; |
|
130 |
|
$key = $type . ' ' . $body . ' ' . $comment; |
|
131 |
|
$r = rg_keys_info($key); |
|
132 |
|
if ($r['ok'] != 0) { |
|
133 |
|
rg_log("No error for an invalid key (type mismatch)!"); |
|
134 |
|
exit(1); |
|
135 |
|
} |
|
136 |
|
|
|
137 |
|
|
|
138 |
|
rg_log_ml("\n\nTesing ecdsa key type"); |
|
139 |
|
$type = 'ecdsa-sha2-nistp256'; |
|
140 |
|
$body = 'AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBDCLAxnMiMaSm+YI+f' |
|
141 |
|
. '7RNLafBzv1JUWD/4/MeVf4JdMPN4QaNwXlCe9mR9Lmy1eDd/tW2AsEBfobhFbSI8eHtP4='; |
|
142 |
|
$comment = 'comment'; |
|
143 |
|
$key = $type . ' ' . $body . ' ' . $comment; |
|
144 |
|
$r = rg_keys_info($key); |
|
145 |
|
if ($r['ok'] != 1) { |
|
146 |
|
rg_log("Error for a valid key (ecdsa): " . rg_keys_error() . "!"); |
95 |
147 |
exit(1); |
exit(1); |
96 |
148 |
} |
} |
97 |
|
// insert a key - must fail because overlimit |
|
98 |
|
$key = "aaa 'bbb' second_key"; |
|
99 |
|
$key_id2 = rg_keys_add($db, $rg_ui, $key); |
|
100 |
|
if ($key_id2 !== FALSE) { |
|
101 |
|
rg_log("Seems we can add more keys than allowed!"); |
|
|
149 |
|
if (strcasecmp($r['fingerprint'], '85:8f:2f:84:c2:db:88:e5:95:f6:22:b9:8d:91:59:cc') != 0) { |
|
150 |
|
rg_log("Invalid fingerprint!"); |
102 |
151 |
exit(1); |
exit(1); |
103 |
152 |
} |
} |
104 |
153 |
|
|
105 |
154 |
|
|
|
155 |
|
rg_log_ml("\n\nTesing ed25519 key type"); |
|
156 |
|
$type = 'ssh-ed25519'; |
|
157 |
|
$body = 'AAAAC3NzaC1lZDI1NTE5AAAAIGYlG3R7u0oMzvy9iAzKB29U26U9o3+mXCXODAQYKEEu'; |
|
158 |
|
$comment = 'comment'; |
|
159 |
|
$key = $type . ' ' . $body . ' ' . $comment; |
|
160 |
|
$r = rg_keys_info($key); |
|
161 |
|
if ($r['ok'] != 1) { |
|
162 |
|
rg_log("Error for a valid key (ed25519): " . rg_keys_error() . "!"); |
|
163 |
|
exit(1); |
|
164 |
|
} |
|
165 |
|
if (strcasecmp($r['fingerprint'], '28:f7:1b:cb:ba:43:0a:41:b8:30:a3:8e:8f:bc:d5:4a') != 0) { |
|
166 |
|
rg_log("Invalid fingerprint!"); |
|
167 |
|
exit(1); |
|
168 |
|
} |
|
169 |
|
|
106 |
170 |
|
|
107 |
171 |
rg_sql_close($db); |
rg_sql_close($db); |
108 |
172 |
|
|
File tests/util.php changed (mode: 100644) (index d4e63bd..1679820) |
... |
... |
$rg_no_db = TRUE; |
14 |
14 |
require_once("common.php"); |
require_once("common.php"); |
15 |
15 |
|
|
16 |
16 |
|
|
17 |
|
// Test rg_prepare_replace_helper |
|
18 |
|
$a = array('a' => 'A', 'arr' => array('bb' => 'BB', 'HTML:cc' => 'ș')); |
|
19 |
|
$what = array(); |
|
20 |
|
$value = array(); |
|
21 |
|
$r = rg_prepare_replace($a, $what, $values); |
|
22 |
|
$r2 = preg_replace($what, $values, '@@a@@-@@arr::bb@@-@@arr::cc@@-@@alien@@'); |
|
23 |
|
$e = 'A-BB-ș-@@alien@@'; |
|
24 |
|
if (strcmp($r2, $e) != 0) { |
|
25 |
|
rg_log("prepare_replace_helper is not working as expeceted!"); |
|
26 |
|
rg_log_ml("e: $e"); |
|
27 |
|
rg_log_ml("r2: $r2"); |
|
|
17 |
|
rg_log("Testing template_tree_lookup1"); |
|
18 |
|
$var = 'a::b'; |
|
19 |
|
$e = '<'; |
|
20 |
|
$data = array('a' => array('HTML:b' => '<')); |
|
21 |
|
$r = rg_template_tree_lookup($var, $data, TRUE /*xss_protection*/); |
|
22 |
|
if (strcmp($r, $e) != 0) { |
|
23 |
|
rg_log("rg_template_string [template_tree_lookup1] is not working as expected [$r] != [$e]!"); |
|
24 |
|
exit(1); |
|
25 |
|
} |
|
26 |
|
|
|
27 |
|
// Test: rg_template_tree_lookup |
|
28 |
|
$data = array('a' => array('a2' => array('a3' => 'X'))); |
|
29 |
|
$e = 'X'; |
|
30 |
|
$r = rg_template_tree_lookup('a::a2::a3', $data, FALSE /*xss*/); |
|
31 |
|
if (strcmp($r, $e) != 0) { |
|
32 |
|
rg_log("tree_lookup is not working as expected!"); |
|
33 |
|
exit(1); |
|
34 |
|
} |
|
35 |
|
|
|
36 |
|
|
|
37 |
|
rg_log("Testing ::+nesting"); |
|
38 |
|
$s = '@@a::b@@'; |
|
39 |
|
$e = '<'; |
|
40 |
|
$data = array('a' => array('b' => '<')); |
|
41 |
|
$r = rg_template_string($s, 0, $data, TRUE /*xss*/); |
|
42 |
|
if (strcmp($r, $e) != 0) { |
|
43 |
|
rg_log("rg_template_string [::+nesting] is not working as expected [$r] != [$e]!"); |
|
44 |
|
exit(1); |
|
45 |
|
} |
|
46 |
|
|
|
47 |
|
rg_log("Testing ::+nesting-html0"); |
|
48 |
|
$s = '@@a@@'; |
|
49 |
|
$e = 'Y'; |
|
50 |
|
$data = array('HTML:a' => 'Y'); |
|
51 |
|
$r = rg_template_string($s, 0, $data, TRUE /*xss*/); |
|
52 |
|
if (strcmp($r, $e) != 0) { |
|
53 |
|
rg_log("rg_template_string [::+nesting-html0] is not working as expected [$r] != [$e]!"); |
|
54 |
|
exit(1); |
|
55 |
|
} |
|
56 |
|
|
|
57 |
|
rg_log("Testing ::+nesting-html"); |
|
58 |
|
$s = '@@a::b@@'; |
|
59 |
|
$e = '<'; |
|
60 |
|
$data = array('a' => array('HTML:b' => '<')); |
|
61 |
|
$r = rg_template_string($s, 0, $data, TRUE /*xss*/); |
|
62 |
|
if (strcmp($r, $e) != 0) { |
|
63 |
|
rg_log("rg_template_string [::+nesting-html] is not working as expected [$r] != [$e]!"); |
|
64 |
|
exit(1); |
|
65 |
|
} |
|
66 |
|
|
|
67 |
|
rg_log("Testing nesting"); |
|
68 |
|
$s = '@@if(@@x@@ == 0){{@@if(@@x@@ == 0){{@@if(@@x@@ == 0){{3}}{{!3}}}}{{!2}}}}{{!1}}'; |
|
69 |
|
$e = '3'; |
|
70 |
|
$data = array('x' => 0); |
|
71 |
|
$r = rg_template_string($s, 0, $data, TRUE /*xss*/); |
|
72 |
|
if (strcmp($r, $e) != 0) { |
|
73 |
|
rg_log("rg_template_string [3 nested] is not working as expected [$r] != [$e]!"); |
|
74 |
|
exit(1); |
|
75 |
|
} |
|
76 |
|
|
|
77 |
|
rg_log("Testing nesting with false"); |
|
78 |
|
$s = '@@if(@@x@@ == 0){{@@if(@@x@@ != 0){{}}{{@@if(@@x@@ == 0){{3}}{{!3}}}}}}{{!1}}'; |
|
79 |
|
$e = '3'; |
|
80 |
|
$data = array('x' => 0); |
|
81 |
|
$r = rg_template_string($s, 0, $data, TRUE /*xss*/); |
|
82 |
|
if (strcmp($r, $e) != 0) { |
|
83 |
|
rg_log("rg_template_string [3 nested false] is not working as expected [$r] != [$e]!"); |
28 |
84 |
exit(1); |
exit(1); |
29 |
85 |
} |
} |
30 |
86 |
|
|
|
87 |
|
rg_log("Testing string compared with int"); |
|
88 |
|
$s = '@@if(@@x@@ == 0){{A}}'; |
|
89 |
|
$e = 'A'; |
|
90 |
|
$data = array('x' => 0); |
|
91 |
|
$r = rg_template_string($s, 0, $data, TRUE /*xss*/); |
|
92 |
|
if (strcmp($r, $e) != 0) { |
|
93 |
|
rg_log("rg_template_string [string int] is not working as expected [$r] != [$e]!"); |
|
94 |
|
exit(1); |
|
95 |
|
} |
|
96 |
|
|
|
97 |
|
rg_log("Testing !="); |
|
98 |
|
$s = '@@if(x != 0)123456789{{A}}'; |
|
99 |
|
rg_log("s=$s"); |
|
100 |
|
$e = 'A'; |
|
101 |
|
$data = array(); |
|
102 |
|
$r = rg_template_string($s, 0, $data, TRUE /*xss*/); |
|
103 |
|
if (strcmp($r, $e) != 0) { |
|
104 |
|
rg_log("rg_template_string [!=] is not working as expected [$r] != [$e]!"); |
|
105 |
|
exit(1); |
|
106 |
|
} |
|
107 |
|
|
|
108 |
|
// Test: empty if |
|
109 |
|
$s = '@@if(x == x)123456789{{}}'; |
|
110 |
|
rg_log("s=$s"); |
|
111 |
|
$e = ''; |
|
112 |
|
$data = array(); |
|
113 |
|
$r = rg_template_string($s, 0, $data, TRUE /*xss*/); |
|
114 |
|
if (strcmp($r, $e) != 0) { |
|
115 |
|
rg_log("rg_template_string [empty if] is not working as expected [$r] != [$e]!"); |
|
116 |
|
exit(1); |
|
117 |
|
} |
|
118 |
|
|
|
119 |
|
// Test: empty if |
|
120 |
|
$s = '@@if(x == x)123456789{{}}{{}}'; |
|
121 |
|
rg_log("s=$s"); |
|
122 |
|
$e = ''; |
|
123 |
|
$data = array(); |
|
124 |
|
$r = rg_template_string($s, 0, $data, TRUE /*xss*/); |
|
125 |
|
if (strcmp($r, $e) != 0) { |
|
126 |
|
rg_log("rg_template_string [empty if with false] is not working as expected [$r] != [$e]!"); |
|
127 |
|
exit(1); |
|
128 |
|
} |
|
129 |
|
|
|
130 |
|
// Test: rg_template_string with if (negate) |
|
131 |
|
$s = 'Start@@if(@@v@@ != x)123456789{{@@a@@}} x {{alien}}End'; |
|
132 |
|
rg_log("s=$s"); |
|
133 |
|
$data = array('a' => '<>', 'v' => 'x2'); |
|
134 |
|
$e = 'Start<> x {{alien}}End'; |
|
135 |
|
$r = rg_template_string($s, 0, $data, TRUE /*xss*/); |
|
136 |
|
if (strcmp($r, $e) != 0) { |
|
137 |
|
rg_log("rg_template_string [simple if true xss neg] is not working as expected [$r] != [$e]!"); |
|
138 |
|
exit(1); |
|
139 |
|
} |
|
140 |
|
|
|
141 |
|
// Test: rg_template_string with if |
|
142 |
|
$s = 'Start@@if(@@v@@ == x)123456789{{@@a@@}} x {{alien}}End'; |
|
143 |
|
rg_log("s=$s"); |
|
144 |
|
$data = array('a' => '<>', 'v' => 'x'); |
|
145 |
|
$e = 'Start<> x {{alien}}End'; |
|
146 |
|
$r = rg_template_string($s, 0, $data, TRUE /*xss*/); |
|
147 |
|
if (strcmp($r, $e) != 0) { |
|
148 |
|
rg_log("rg_template_string [simple if true xss] is not working as expected [$r] != [$e]!"); |
|
149 |
|
exit(1); |
|
150 |
|
} |
|
151 |
|
|
|
152 |
|
// Test: rg_template_string with if |
|
153 |
|
$s = '@@if("" == "")123456789{{A}}'; |
|
154 |
|
rg_log("s=$s"); |
|
155 |
|
$data = array(); |
|
156 |
|
$e = 'A'; |
|
157 |
|
$r = rg_template_string($s, 0, $data, FALSE /*xss*/); |
|
158 |
|
if (strcmp($r, $e) != 0) { |
|
159 |
|
rg_log("rg_template_string [simple if true] is not working as expected [$r] != [$e]!"); |
|
160 |
|
exit(1); |
|
161 |
|
} |
|
162 |
|
|
|
163 |
|
// Test: rg_template_string with if |
|
164 |
|
$s = '@@if("a" != "")123456789{{A}}'; |
|
165 |
|
rg_log("s=$s"); |
|
166 |
|
$data = array(); |
|
167 |
|
$e = 'A'; |
|
168 |
|
$r = rg_template_string($s, 0, $data, FALSE /*xss*/); |
|
169 |
|
if (strcmp($r, $e) != 0) { |
|
170 |
|
rg_log("rg_template_string [simple if false] is not working as expected [$r] != [$e]!"); |
|
171 |
|
exit(1); |
|
172 |
|
} |
|
173 |
|
|
|
174 |
|
// Test: rg_template_string with if |
|
175 |
|
$s = '@@if("" != "")123456789{{A}}{{B}}'; |
|
176 |
|
rg_log("s=$s"); |
|
177 |
|
$data = array(); |
|
178 |
|
$e = 'B'; |
|
179 |
|
$r = rg_template_string($s, 0, $data, FALSE /*xss*/); |
|
180 |
|
if (strcmp($r, $e) != 0) { |
|
181 |
|
rg_log("rg_template_string [if without gap] is not working as expected [$r] != [$e]!"); |
|
182 |
|
exit(1); |
|
183 |
|
} |
|
184 |
|
|
|
185 |
|
// Test: rg_template_string with if (with gap) |
|
186 |
|
$s = "@@if(\"\" != \"\")123456789{{A}} \n\t {{B}}"; |
|
187 |
|
rg_log("s=$s"); |
|
188 |
|
$data = array(); |
|
189 |
|
$e = 'B'; |
|
190 |
|
$r = rg_template_string($s, 0, $data, FALSE /*xss*/); |
|
191 |
|
if (strcmp($r, $e) != 0) { |
|
192 |
|
rg_log("rg_template_string [if with gap] is not working as expected [$r] != [$e]!"); |
|
193 |
|
exit(1); |
|
194 |
|
} |
|
195 |
|
|
|
196 |
|
// Test: rg_template_string |
|
197 |
|
$data = array(); |
|
198 |
|
$s = '@@a::a2@@ @@b@@ @@b@@'; |
|
199 |
|
$e = $s; |
|
200 |
|
$r = rg_template_string($s, 0, $data, FALSE /*xss*/); |
|
201 |
|
if (strcmp($r, $e) != 0) { |
|
202 |
|
rg_log("rg_template_string [empty data] is not working as expected [$r] != [$e]!"); |
|
203 |
|
exit(1); |
|
204 |
|
} |
|
205 |
|
|
|
206 |
|
$s = '@@a::a2@@ @@b@@ @@b@@ @@c@@'; |
|
207 |
|
$data = array( |
|
208 |
|
'a' => array('a2' => 'a3'), |
|
209 |
|
'b' => 'X' |
|
210 |
|
); |
|
211 |
|
$e = 'a3 X X @@c@@'; |
|
212 |
|
$r = rg_template_string($s, 0, $data, FALSE /*xss*/); |
|
213 |
|
if (strcmp($r, $e) != 0) { |
|
214 |
|
rg_log("rg_template_string [second level] is not working as expected [$r] != [$e]!"); |
|
215 |
|
exit(1); |
|
216 |
|
} |
|
217 |
|
|
|
218 |
|
|
31 |
219 |
// Test template functions |
// Test template functions |
32 |
|
function inc($v) { return $v + 1; } |
|
33 |
|
function dec($v) { return $v - 1; } |
|
|
220 |
|
function inc($v) { rg_log("DEBUG: inc called with v=$v"); return $v + 1; } |
|
221 |
|
function dec($v) { rg_log("DEBUG: dec called with v=$v"); return $v - 1; } |
34 |
222 |
rg_template_func("inc", "inc"); |
rg_template_func("inc", "inc"); |
35 |
223 |
rg_template_func("dec", "dec"); |
rg_template_func("dec", "dec"); |
36 |
224 |
$_rg = array("uid" => 5); |
$_rg = array("uid" => 5); |
37 |
|
$r = trim(rg_template("func.txt", $_rg)); |
|
|
225 |
|
$r = trim(rg_template("func.txt", $_rg, TRUE /*xss*/)); |
38 |
226 |
$e = "5 + 1 = 6 | 5 - 1 = 4 | 4"; |
$e = "5 + 1 = 6 | 5 - 1 = 4 | 4"; |
39 |
227 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
40 |
228 |
rg_log("template func1 test failed [$r] != [$e]"); |
rg_log("template func1 test failed [$r] != [$e]"); |
|
... |
... |
if ($r !== TRUE) { |
76 |
264 |
} |
} |
77 |
265 |
|
|
78 |
266 |
|
|
79 |
|
rg_log("util.php: testing function rg_prepare_replace_helper..."); |
|
80 |
|
$what = array(); $values = array(); |
|
81 |
|
$a = array("a" => "b"); |
|
82 |
|
rg_prepare_replace_helper($a, "", $what, $values); |
|
83 |
|
$w = rg_array2string($what); |
|
84 |
|
$v = rg_array2string($values); |
|
85 |
|
$ew = "a=[/@@a@@/uU]"; |
|
86 |
|
$ev = "a=[b]"; |
|
87 |
|
if ((strcmp($w, $ew) != 0) || (strcmp($v, $ev) != 0)) { |
|
88 |
|
rg_log("Wrong prepare_replace: [$w] != [$ew] OR [$v] != [$ev]!"); |
|
89 |
|
exit(1); |
|
90 |
|
} |
|
91 |
|
|
|
92 |
|
$what = array(); $values = array(); |
|
93 |
|
$a = array("ri" => array("repo_id" => "1", "name" => "repo1")); |
|
94 |
|
rg_prepare_replace_helper($a, "", $what, $values); |
|
95 |
|
$w = rg_array2string($what); |
|
96 |
|
$v = rg_array2string($values); |
|
97 |
|
$ew = "ri::repo_id=[/@@ri\:\:repo_id@@/uU] ri::name=[/@@ri\:\:name@@/uU]"; |
|
98 |
|
$ev = "ri::repo_id=[1] ri::name=[repo1]"; |
|
99 |
|
if ((strcmp($w, $ew) != 0) || (strcmp($v, $ev) != 0)) { |
|
100 |
|
rg_log("Wrong prepare_replace: [$w] != [$ew] OR [$v] != [$ev]!"); |
|
101 |
|
exit(1); |
|
102 |
|
} |
|
103 |
|
|
|
104 |
|
|
|
105 |
267 |
$r = rg_exec("/xxxx"); |
$r = rg_exec("/xxxx"); |
106 |
268 |
if ($r['ok'] == 1) { |
if ($r['ok'] == 1) { |
107 |
269 |
rg_log("util.php: running non existing command does not return 0!"); |
rg_log("util.php: running non existing command does not return 0!"); |
|
... |
... |
if (strcmp($r, $e) != 0) { |
146 |
308 |
$t = "test rg_template with conditional formating (false)"; |
$t = "test rg_template with conditional formating (false)"; |
147 |
309 |
rg_log($t); |
rg_log($t); |
148 |
310 |
$data = array("X" => "0", "A" => "Avalue", "B" => "Bvalue"); |
$data = array("X" => "0", "A" => "Avalue", "B" => "Bvalue"); |
149 |
|
$r = rg_template("t3/c1", $data); |
|
|
311 |
|
$r = rg_template("t3/c1", $data, TRUE /*xss*/); |
150 |
312 |
$e = "XXBvalueYY"; |
$e = "XXBvalueYY"; |
151 |
313 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
152 |
314 |
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
... |
... |
if (strcmp($r, $e) != 0) { |
156 |
318 |
$t = "test rg_template with conditional formating (true)"; |
$t = "test rg_template with conditional formating (true)"; |
157 |
319 |
rg_log($t); |
rg_log($t); |
158 |
320 |
$data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue"); |
$data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue"); |
159 |
|
$r = rg_template("t3/c1", $data); |
|
|
321 |
|
$r = rg_template("t3/c1", $data, TRUE /*xss*/); |
160 |
322 |
$e = "XXAvalueYY"; |
$e = "XXAvalueYY"; |
161 |
323 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
162 |
324 |
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
... |
... |
if (strcmp($r, $e) != 0) { |
166 |
328 |
$t = "test rg_template with conditional formating (multiline)"; |
$t = "test rg_template with conditional formating (multiline)"; |
167 |
329 |
rg_log($t); |
rg_log($t); |
168 |
330 |
$data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue"); |
$data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue"); |
169 |
|
$r = rg_template("t3/c1", $data); |
|
|
331 |
|
$r = rg_template("t3/c1", $data, TRUE /*xss*/); |
170 |
332 |
$e = "XXAvalueYY"; |
$e = "XXAvalueYY"; |
171 |
333 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
172 |
334 |
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
... |
... |
$t = "test rg_template with conditional formating (nested 1)"; |
177 |
339 |
rg_log($t); |
rg_log($t); |
178 |
340 |
$data = array("X" => "1", "Y" => "1", "A" => "Avalue", "B" => "Bvalue", |
$data = array("X" => "1", "Y" => "1", "A" => "Avalue", "B" => "Bvalue", |
179 |
341 |
"R" => "Rvalue", "T" => "Tvalue"); |
"R" => "Rvalue", "T" => "Tvalue"); |
180 |
|
$r = rg_template("t3/c3", $data); |
|
|
342 |
|
$r = rg_template("t3/c3", $data, TRUE /*xss*/); |
181 |
343 |
$e = "XXRvalueZZYY"; |
$e = "XXRvalueZZYY"; |
182 |
344 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
183 |
345 |
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
... |
... |
$t = "test rg_template with conditional formating (nested 2)"; |
188 |
350 |
rg_log($t); |
rg_log($t); |
189 |
351 |
$data = array("X" => "1", "Y" => "0", "A" => "Avalue", "B" => "Bvalue", |
$data = array("X" => "1", "Y" => "0", "A" => "Avalue", "B" => "Bvalue", |
190 |
352 |
"R" => "Rvalue", "T" => "Tvalue"); |
"R" => "Rvalue", "T" => "Tvalue"); |
191 |
|
$r = rg_template("t3/c3", $data); |
|
|
353 |
|
$r = rg_template("t3/c3", $data, TRUE /*xss*/); |
192 |
354 |
$e = "XXTvalueZZYY"; |
$e = "XXTvalueZZYY"; |
193 |
355 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
194 |
356 |
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
... |
... |
$t = "test rg_template with conditional formating (nested 3)"; |
199 |
361 |
rg_log($t); |
rg_log($t); |
200 |
362 |
$data = array("X" => "0", "Y" => "1", "A" => "Avalue", "B" => "Bvalue", |
$data = array("X" => "0", "Y" => "1", "A" => "Avalue", "B" => "Bvalue", |
201 |
363 |
"R" => "Rvalue", "T" => "Tvalue"); |
"R" => "Rvalue", "T" => "Tvalue"); |
202 |
|
$r = rg_template("t3/c3", $data); |
|
|
364 |
|
$r = rg_template("t3/c3", $data, TRUE /*xss*/); |
203 |
365 |
$e = "XXBvalueYY"; |
$e = "XXBvalueYY"; |
204 |
366 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
205 |
367 |
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
... |
... |
if (strcmp($r, $e) != 0) { |
209 |
371 |
$t = "test rg_template with conditional formating (nested nested 1)"; |
$t = "test rg_template with conditional formating (nested nested 1)"; |
210 |
372 |
rg_log($t); |
rg_log($t); |
211 |
373 |
$data = array("X" => "1", "Y" => "1", "Z" => "1"); |
$data = array("X" => "1", "Y" => "1", "Z" => "1"); |
212 |
|
$r = rg_template("t3/c4", $data); |
|
|
374 |
|
$r = rg_template("t3/c4", $data, TRUE /*xss*/); |
213 |
375 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
214 |
376 |
$e = "XXTRUE_LEVEL_2YY"; |
$e = "XXTRUE_LEVEL_2YY"; |
215 |
377 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
|
... |
... |
if (strcmp($r, $e) != 0) { |
220 |
382 |
$t = "test rg_template with conditional formating (nested nested 2)"; |
$t = "test rg_template with conditional formating (nested nested 2)"; |
221 |
383 |
rg_log($t); |
rg_log($t); |
222 |
384 |
$data = array("X" => "1", "Y" => "0", "Z" => "1"); |
$data = array("X" => "1", "Y" => "0", "Z" => "1"); |
223 |
|
$r = rg_template("t3/c4", $data); |
|
|
385 |
|
$r = rg_template("t3/c4", $data, TRUE /*xss*/); |
224 |
386 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
225 |
387 |
$e = "XXFALSE_LEVEL_1YY"; |
$e = "XXFALSE_LEVEL_1YY"; |
226 |
388 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
|
... |
... |
if (strcmp($r, $e) != 0) { |
231 |
393 |
$t = "test rg_template with conditional formating (nested nested 2)"; |
$t = "test rg_template with conditional formating (nested nested 2)"; |
232 |
394 |
rg_log($t); |
rg_log($t); |
233 |
395 |
$data = array("X" => "0", "Y" => "1", "Z" => "1"); |
$data = array("X" => "0", "Y" => "1", "Z" => "1"); |
234 |
|
$r = rg_template("t3/c4", $data); |
|
|
396 |
|
$r = rg_template("t3/c4", $data, TRUE /*xss*/); |
235 |
397 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
236 |
398 |
$e = "XXFALSE_LEVEL_0YY"; |
$e = "XXFALSE_LEVEL_0YY"; |
237 |
399 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
|
... |
... |
if (strcmp($r, $e) != 0) { |
242 |
404 |
$t = "test rg_template with conditional formating (nested nested 3)"; |
$t = "test rg_template with conditional formating (nested nested 3)"; |
243 |
405 |
rg_log($t); |
rg_log($t); |
244 |
406 |
$data = array("X" => "0", "Y" => "0", "Z" => "0"); |
$data = array("X" => "0", "Y" => "0", "Z" => "0"); |
245 |
|
$r = rg_template("t3/c5", $data); |
|
|
407 |
|
$r = rg_template("t3/c5", $data, TRUE /*xss*/); |
246 |
408 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
247 |
409 |
$e = "XX-X0Y0Z0-YY"; |
$e = "XX-X0Y0Z0-YY"; |
248 |
410 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
|
... |
... |
if (strcmp($r, $e) != 0) { |
253 |
415 |
$t = "test rg_template with conditional formating (nested nested 4)"; |
$t = "test rg_template with conditional formating (nested nested 4)"; |
254 |
416 |
rg_log($t); |
rg_log($t); |
255 |
417 |
$data = array("X" => "0", "Y" => "1", "Z" => "0"); |
$data = array("X" => "0", "Y" => "1", "Z" => "0"); |
256 |
|
$r = rg_template("t3/c5", $data); |
|
|
418 |
|
$r = rg_template("t3/c5", $data, TRUE /*xss*/); |
257 |
419 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
258 |
420 |
$e = "XX-X0Y1Z0-YY"; |
$e = "XX-X0Y1Z0-YY"; |
259 |
421 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
|
... |
... |
if (strcmp($r, $e) != 0) { |
264 |
426 |
$t = "test rg_template with conditional formating (empty)"; |
$t = "test rg_template with conditional formating (empty)"; |
265 |
427 |
rg_log($t); |
rg_log($t); |
266 |
428 |
$data = array(); |
$data = array(); |
267 |
|
$r = rg_template("t3/c6", $data); |
|
|
429 |
|
$r = rg_template("t3/c6", $data, TRUE /*xss*/); |
268 |
430 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
269 |
431 |
$e = "A"; |
$e = "A"; |
270 |
432 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
|
... |
... |
if (strcmp($r, $e) != 0) { |
275 |
437 |
$t = "test rg_template with conditional formating (quotes)"; |
$t = "test rg_template with conditional formating (quotes)"; |
276 |
438 |
rg_log($t); |
rg_log($t); |
277 |
439 |
$data = array("a" => "abc"); |
$data = array("a" => "abc"); |
278 |
|
$r = rg_template("t3/c6b", $data); |
|
|
440 |
|
$r = rg_template("t3/c6b", $data, TRUE /*xss*/); |
279 |
441 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
280 |
442 |
$e = "AY"; |
$e = "AY"; |
281 |
443 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
|
... |
... |
if (strcmp($r, $e) != 0) { |
286 |
448 |
$t = "test rg_template with conditional formating (!empty)"; |
$t = "test rg_template with conditional formating (!empty)"; |
287 |
449 |
rg_log($t); |
rg_log($t); |
288 |
450 |
$data = array("AAA" => ""); |
$data = array("AAA" => ""); |
289 |
|
$r = rg_template("t3/c7", $data); |
|
|
451 |
|
$r = rg_template("t3/c7", $data, TRUE /*xss*/); |
290 |
452 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
291 |
453 |
$e = "B"; |
$e = "B"; |
292 |
454 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
|
... |
... |
if (strcmp($r, $e) != 0) { |
294 |
456 |
exit(1); |
exit(1); |
295 |
457 |
} |
} |
296 |
458 |
|
|
297 |
|
$t = "test rg_replace_lookup"; |
|
298 |
|
rg_log($t); |
|
299 |
|
$data = array("AAA" => "1", "BBB" => "2", "CCC" => "1"); |
|
300 |
|
$r = rg_replace_lookup($data, "@@AAA@@@@BBB@@@@CCC@@"); |
|
301 |
|
$e = "121"; |
|
302 |
|
if (strcmp($r, $e) != 0) { |
|
303 |
|
rg_log("util.php: $t: not working (r=[$r] e=[$e])!"); |
|
304 |
|
exit(1); |
|
305 |
|
} |
|
306 |
|
|
|
307 |
459 |
$t = "test rg_template with conditional formating (a variable contains '{{')"; |
$t = "test rg_template with conditional formating (a variable contains '{{')"; |
308 |
460 |
rg_log($t); |
rg_log($t); |
309 |
461 |
$data = array("AAA" => "1", "BBB" => "}}", "CCC" => "{{"); |
$data = array("AAA" => "1", "BBB" => "}}", "CCC" => "{{"); |
310 |
|
$r = rg_template("t3/c8", $data); |
|
|
462 |
|
$r = rg_template("t3/c8", $data, TRUE /*xss*/); |
311 |
463 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
312 |
464 |
$e = "}}"; |
$e = "}}"; |
313 |
465 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
|
... |
... |
if (strcmp($r, $e) != 0) { |
318 |
470 |
$t = "test rg_template with conditional formating: false branch is empty)"; |
$t = "test rg_template with conditional formating: false branch is empty)"; |
319 |
471 |
rg_log($t); |
rg_log($t); |
320 |
472 |
$data = array("X" => "abc"); |
$data = array("X" => "abc"); |
321 |
|
$r = rg_template("t3/c9", $data); |
|
|
473 |
|
$r = rg_template("t3/c9", $data, TRUE /*xss*/); |
322 |
474 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
323 |
475 |
$e = "XXBLABLABLAabcYYabc"; |
$e = "XXBLABLABLAabcYYabc"; |
324 |
476 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
|
... |
... |
if (strcmp($r, $e) != 0) { |
326 |
478 |
exit(1); |
exit(1); |
327 |
479 |
} |
} |
328 |
480 |
|
|
|
481 |
|
$t = "test rg_template with conditional formating: false branch is empty, no space stripping)"; |
|
482 |
|
rg_log($t); |
|
483 |
|
$data = array("X" => "abc"); |
|
484 |
|
$r = rg_template("t3/c9", $data, TRUE /*xss protection*/); |
|
485 |
|
$e = "XX\n\tBLA\n\tBLA\n\tBLA\n\tabc\nYY\nabc\n"; |
|
486 |
|
if (strcmp($r, $e) != 0) { |
|
487 |
|
rg_log("util.php: $t: not working (r=[$r] e=[$e])!"); |
|
488 |
|
exit(1); |
|
489 |
|
} |
|
490 |
|
|
329 |
491 |
$t = "test rg_copy_tree"; |
$t = "test rg_copy_tree"; |
330 |
492 |
rg_log($t); |
rg_log($t); |
331 |
493 |
$r = rg_copy_tree("tree1", "tree1.copy", 0755); |
$r = rg_copy_tree("tree1", "tree1.copy", 0755); |
|
... |
... |
if (strcmp($x2, $e) != 0) { |
358 |
520 |
|
|
359 |
521 |
$src = array(); |
$src = array(); |
360 |
522 |
$a = array("u" => "uval", "HTML:A" => "Aval"); |
$a = array("u" => "uval", "HTML:A" => "Aval"); |
361 |
|
$x = rg_array_merge($src, "X", $a); |
|
362 |
|
if (strcmp($x['X::u'], "uval") != 0) { |
|
|
523 |
|
$x = rg_array_merge($src, 'X', $a); |
|
524 |
|
if (strcmp($x['X']['u'], "uval") != 0) { |
363 |
525 |
rg_log("array_merge is not working correctly (2)!"); |
rg_log("array_merge is not working correctly (2)!"); |
364 |
526 |
print_r($x); |
print_r($x); |
365 |
527 |
exit(1); |
exit(1); |
366 |
528 |
} |
} |
367 |
|
if (strcmp($x['HTML:X::A'], "Aval") != 0) { |
|
|
529 |
|
if (strcmp($x['X']['HTML:A'], "Aval") != 0) { |
368 |
530 |
rg_log("array_merge is not working correctly (1)!"); |
rg_log("array_merge is not working correctly (1)!"); |
369 |
531 |
print_r($x); |
print_r($x); |
370 |
532 |
exit(1); |
exit(1); |