File inc/admin.inc.php changed (mode: 100644) (index 76e750f..35df737) |
... |
... |
require_once($INC . "/workers.inc.php"); |
8 |
8 |
*/ |
*/ |
9 |
9 |
$rg_admin_functions = array( |
$rg_admin_functions = array( |
10 |
10 |
6000 => "rg_admin_invite", |
6000 => "rg_admin_invite", |
11 |
|
6001 => "rg_admin_invite_one" |
|
|
11 |
|
6001 => "rg_admin_invite_one", |
|
12 |
|
// new new style |
|
13 |
|
'admin_invite' => 'rg_admin_invite', |
|
14 |
|
'admin_invite_one' => 'rg_admin_invite_one' |
12 |
15 |
); |
); |
13 |
16 |
rg_event_register_functions($rg_admin_functions); |
rg_event_register_functions($rg_admin_functions); |
14 |
17 |
|
|
|
... |
... |
function rg_admin_invite($db, $event) |
29 |
32 |
|
|
30 |
33 |
$ret[] = array_merge($event, |
$ret[] = array_merge($event, |
31 |
34 |
array( |
array( |
32 |
|
'category' => 6001, |
|
|
35 |
|
'category' => 'admin_invite_one', |
33 |
36 |
'prio' => 100, |
'prio' => 100, |
34 |
37 |
'email' => trim($t[0]), |
'email' => trim($t[0]), |
35 |
38 |
'name' => trim($t[1]) |
'name' => trim($t[1]) |
|
... |
... |
function rg_admin_invites_high_level($db, $rg) |
159 |
162 |
break; |
break; |
160 |
163 |
|
|
161 |
164 |
$event = array( |
$event = array( |
162 |
|
'category' => 6000, |
|
|
165 |
|
'category' => 'admin_invite', |
163 |
166 |
'prio' => 50, |
'prio' => 50, |
164 |
167 |
'ui' => $rg['login_ui']); |
'ui' => $rg['login_ui']); |
165 |
168 |
$event = array_merge($event, $inv); |
$event = array_merge($event, $inv); |
|
... |
... |
function rg_admin_report1_suggestions($db, $from, $to) |
308 |
311 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
309 |
312 |
} |
} |
310 |
313 |
|
|
311 |
|
$ret .= "\nTotal suggestions: " . $total; |
|
|
314 |
|
$ret .= 'Total suggestions: ' . $total; |
312 |
315 |
$ret .= "\nYesterday suggestions: " . $yesterday; |
$ret .= "\nYesterday suggestions: " . $yesterday; |
313 |
316 |
$ret .= $yesterday_text; |
$ret .= $yesterday_text; |
314 |
317 |
|
|
|
... |
... |
function rg_admin_report1($db, $rg) |
332 |
335 |
. " and " . gmdate('Y-m-d H:i:s', $y_end) . " UTC\n"; |
. " and " . gmdate('Y-m-d H:i:s', $y_end) . " UTC\n"; |
333 |
336 |
$body .= 'For site ' . $site . "\n"; |
$body .= 'For site ' . $site . "\n"; |
334 |
337 |
|
|
|
338 |
|
$g = array(); |
335 |
339 |
$list = array( |
$list = array( |
336 |
340 |
'users' => 'users', |
'users' => 'users', |
337 |
341 |
'repos' => 'repositories', |
'repos' => 'repositories', |
|
... |
... |
function rg_admin_report1($db, $rg) |
351 |
355 |
$total_yesterday_changes = 0; |
$total_yesterday_changes = 0; |
352 |
356 |
$body .= "\n" . 'Yesterday' . "\t" . 'Total' . "\t" . 'Category' . "\n"; |
$body .= "\n" . 'Yesterday' . "\t" . 'Total' . "\t" . 'Category' . "\n"; |
353 |
357 |
foreach ($list as $table => $text) { |
foreach ($list as $table => $text) { |
|
358 |
|
$g[$table] = array(); |
|
359 |
|
|
354 |
360 |
// Yesterday |
// Yesterday |
355 |
361 |
$sql = "SELECT COUNT(*) AS count FROM " . $table |
$sql = "SELECT COUNT(*) AS count FROM " . $table |
356 |
362 |
. " WHERE itime >= $y_start" |
. " WHERE itime >= $y_start" |
|
... |
... |
function rg_admin_report1($db, $rg) |
362 |
368 |
$row = rg_sql_fetch_array($res); |
$row = rg_sql_fetch_array($res); |
363 |
369 |
$yesterday = $row['count']; |
$yesterday = $row['count']; |
364 |
370 |
$total_yesterday_changes += $row['count']; |
$total_yesterday_changes += $row['count']; |
|
371 |
|
$g[$table]['yesterday'] = $yesterday; |
365 |
372 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
366 |
373 |
} |
} |
367 |
374 |
|
|
|
... |
... |
function rg_admin_report1($db, $rg) |
373 |
380 |
} else { |
} else { |
374 |
381 |
$row = rg_sql_fetch_array($res); |
$row = rg_sql_fetch_array($res); |
375 |
382 |
$total = $row['total']; |
$total = $row['total']; |
|
383 |
|
$g[$table]['total'] = $total; |
376 |
384 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
377 |
385 |
} |
} |
378 |
386 |
|
|
379 |
|
$body .= $yesterday . "\t" . $total . "\t" . $text . "\n"; |
|
|
387 |
|
$body .= $yesterday . "\t\t" . $total . "\t" . $text . "\n"; |
380 |
388 |
} |
} |
381 |
389 |
|
|
382 |
390 |
$body .= "\nYesterday users:"; |
$body .= "\nYesterday users:"; |
|
... |
... |
function rg_admin_report1($db, $rg) |
423 |
431 |
$rg['ui']['email'] = $rg_admin_email; |
$rg['ui']['email'] = $rg_admin_email; |
424 |
432 |
$rg['mail'] = array(); |
$rg['mail'] = array(); |
425 |
433 |
$rg['mail']['subject'] = 'RocketGit report' |
$rg['mail']['subject'] = 'RocketGit report' |
426 |
|
. ' [' . $users . 'u]' |
|
427 |
|
. ' [' . $repos . 'r]' |
|
|
434 |
|
. ' [' . $g['users']['yesterday'] . 'u]' |
|
435 |
|
. ' [' . $g['repos']['yesterday'] . 'r]' |
428 |
436 |
. ' [' . $total_yesterday_changes . 'c]' |
. ' [' . $total_yesterday_changes . 'c]' |
429 |
437 |
. ' (' . $site . ')'; |
. ' (' . $site . ')'; |
430 |
438 |
$rg['mail']['body'] = $body; |
$rg['mail']['body'] = $body; |
|
... |
... |
function rg_admin_settings_ssh($db, $rg) |
619 |
627 |
|
|
620 |
628 |
// Load defaults |
// Load defaults |
621 |
629 |
while (1) { |
while (1) { |
622 |
|
$r = rg_state_get($db, 'max_ssh_keys'); |
|
|
630 |
|
$r = rg_state_get_uint($db, 'max_ssh_keys'); |
623 |
631 |
if ($r === FALSE) { |
if ($r === FALSE) { |
624 |
632 |
$ret = rg_template('admin/settings/load_err.html', |
$ret = rg_template('admin/settings/load_err.html', |
625 |
633 |
$rg, TRUE /*xss*/); |
$rg, TRUE /*xss*/); |
626 |
634 |
break; |
break; |
627 |
635 |
} |
} |
628 |
|
if (empty($r)) |
|
629 |
|
$r = $rg_max_ssh_keys; |
|
630 |
636 |
$rg['max_ssh_keys'] = $r; |
$rg['max_ssh_keys'] = $r; |
631 |
637 |
|
|
632 |
|
$r = rg_state_get($db, 'ssh_key_min_bits_rsa'); |
|
|
638 |
|
$r = rg_state_get_uint($db, 'ssh_key_min_bits_rsa'); |
633 |
639 |
if ($r === FALSE) { |
if ($r === FALSE) { |
634 |
640 |
$ret = rg_template('admin/settings/load_err.html', |
$ret = rg_template('admin/settings/load_err.html', |
635 |
641 |
$rg, TRUE /*xss*/); |
$rg, TRUE /*xss*/); |
636 |
642 |
break; |
break; |
637 |
643 |
} |
} |
638 |
|
if (empty($r)) |
|
639 |
|
$r = 2048; |
|
640 |
644 |
$rg['ssh_key_min_bits_rsa'] = $r; |
$rg['ssh_key_min_bits_rsa'] = $r; |
641 |
645 |
|
|
642 |
|
$r = rg_state_get($db, 'ssh_key_allow_dsa'); |
|
|
646 |
|
$r = rg_state_get_uint($db, 'ssh_key_allow_dsa'); |
643 |
647 |
if ($r === FALSE) { |
if ($r === FALSE) { |
644 |
648 |
$ret = rg_template('admin/settings/load_err.html', |
$ret = rg_template('admin/settings/load_err.html', |
645 |
649 |
$rg, TRUE /*xss*/); |
$rg, TRUE /*xss*/); |
646 |
650 |
break; |
break; |
647 |
651 |
} |
} |
648 |
|
if (empty($r)) |
|
649 |
|
$r = 0; |
|
650 |
652 |
$rg['ssh_key_allow_dsa'] = $r; |
$rg['ssh_key_allow_dsa'] = $r; |
651 |
653 |
|
|
652 |
|
$r = rg_state_get($db, 'ssh_key_min_bits_ecdsa'); |
|
|
654 |
|
$r = rg_state_get_uint($db, 'ssh_key_min_bits_ecdsa'); |
653 |
655 |
if ($r === FALSE) { |
if ($r === FALSE) { |
654 |
656 |
$ret = rg_template('admin/settings/load_err.html', |
$ret = rg_template('admin/settings/load_err.html', |
655 |
657 |
$rg, TRUE /*xss*/); |
$rg, TRUE /*xss*/); |
656 |
658 |
break; |
break; |
657 |
659 |
} |
} |
658 |
|
if (empty($r)) |
|
659 |
|
$r = 256; |
|
660 |
660 |
$rg['ssh_key_min_bits_ecdsa'] = $r; |
$rg['ssh_key_min_bits_ecdsa'] = $r; |
661 |
661 |
|
|
662 |
|
$r = rg_state_get($db, 'AuthorizedKeysCommand'); |
|
|
662 |
|
$r = rg_state_get_uint($db, 'AuthorizedKeysCommand'); |
663 |
663 |
if ($r === FALSE) { |
if ($r === FALSE) { |
664 |
664 |
$ret = rg_template('admin/settings/load_err.html', |
$ret = rg_template('admin/settings/load_err.html', |
665 |
665 |
$rg, TRUE /*xss*/); |
$rg, TRUE /*xss*/); |
666 |
666 |
break; |
break; |
667 |
667 |
} |
} |
668 |
|
if (empty($r)) |
|
669 |
|
$r = 0; |
|
670 |
668 |
$rg['AuthorizedKeysCommand'] = $r; |
$rg['AuthorizedKeysCommand'] = $r; |
671 |
669 |
|
|
672 |
670 |
$hints[]['HTML:hint'] = rg_template('admin/settings/ssh/hints.html', |
$hints[]['HTML:hint'] = rg_template('admin/settings/ssh/hints.html', |
|
... |
... |
function rg_admin_settings_git($db, $rg) |
722 |
720 |
|
|
723 |
721 |
// Load defaults |
// Load defaults |
724 |
722 |
while (1) { |
while (1) { |
725 |
|
$r = rg_state_get($db, 'git_patch_limit'); |
|
|
723 |
|
$r = rg_state_get_uint($db, 'git_patch_limit'); |
726 |
724 |
if ($r === FALSE) { |
if ($r === FALSE) { |
727 |
725 |
$ret = rg_template('admin/settings/load_err.html', |
$ret = rg_template('admin/settings/load_err.html', |
728 |
726 |
$rg, TRUE /*xss*/); |
$rg, TRUE /*xss*/); |
729 |
727 |
break; |
break; |
730 |
728 |
} |
} |
731 |
|
if (empty($r)) |
|
|
729 |
|
if ($r == 0) |
732 |
730 |
$r = $rg_git_patch_limit_default; |
$r = $rg_git_patch_limit_default; |
733 |
731 |
$rg['git_patch_limit'] = $r; |
$rg['git_patch_limit'] = $r; |
734 |
732 |
|
|
File inc/git.inc.php changed (mode: 100644) (index 1a16e22..7f8e8d3) |
... |
... |
function rg_git_fatal($msg) |
42 |
42 |
} |
} |
43 |
43 |
|
|
44 |
44 |
/* |
/* |
45 |
|
* Returns true if a repo is empty, else, false |
|
|
45 |
|
* Returns 1 if a repo is empty, 0 if not, -1 on error |
46 |
46 |
*/ |
*/ |
47 |
47 |
function rg_git_repo_is_empty($repo_path) |
function rg_git_repo_is_empty($repo_path) |
48 |
48 |
{ |
{ |
|
... |
... |
function rg_git_repo_is_empty($repo_path) |
53 |
53 |
$repo_path .= '/.git'; |
$repo_path .= '/.git'; |
54 |
54 |
|
|
55 |
55 |
if (!file_exists($repo_path . '/refs/heads')) |
if (!file_exists($repo_path . '/refs/heads')) |
56 |
|
return TRUE; |
|
|
56 |
|
return 1; |
57 |
57 |
|
|
58 |
58 |
$scan = glob($repo_path . '/refs/heads/*'); |
$scan = glob($repo_path . '/refs/heads/*'); |
59 |
59 |
if ($scan === FALSE) { |
if ($scan === FALSE) { |
60 |
|
rg_internal_error('globa returned false'); |
|
61 |
|
return FALSE; |
|
|
60 |
|
rg_internal_error('glob returned false'); |
|
61 |
|
return -1; |
62 |
62 |
} |
} |
63 |
63 |
|
|
64 |
64 |
if (empty($scan)) |
if (empty($scan)) |
65 |
|
return TRUE; |
|
|
65 |
|
return 1; |
66 |
66 |
|
|
67 |
67 |
rg_log_ml('DEBUG: scan: ' . print_r($scan, TRUE)); |
rg_log_ml('DEBUG: scan: ' . print_r($scan, TRUE)); |
68 |
|
return FALSE; |
|
|
68 |
|
return 0; |
69 |
69 |
} |
} |
70 |
70 |
|
|
71 |
71 |
/* |
/* |
72 |
|
* Returns true if the branch contains no commit |
|
|
72 |
|
* Returns true if the ref is present in the repo |
73 |
73 |
*/ |
*/ |
74 |
|
function rg_git_branch_is_empty($repo_path, $ref) |
|
|
74 |
|
function rg_git_ref_exists($repo_path, $ref) |
75 |
75 |
{ |
{ |
76 |
76 |
if (empty($repo_path)) |
if (empty($repo_path)) |
77 |
77 |
$repo_path = '.'; |
$repo_path = '.'; |
|
... |
... |
function rg_git_branch_is_empty($repo_path, $ref) |
79 |
79 |
if (file_exists($repo_path . '/.git')) |
if (file_exists($repo_path . '/.git')) |
80 |
80 |
$repo_path .= '/.git'; |
$repo_path .= '/.git'; |
81 |
81 |
|
|
82 |
|
if (!file_exists($repo_path . '/refs/heads/' . $ref)) |
|
|
82 |
|
if (file_exists($repo_path . '/refs/heads/' . $ref)) |
83 |
83 |
return TRUE; |
return TRUE; |
84 |
84 |
|
|
85 |
85 |
return FALSE; |
return FALSE; |
|
... |
... |
function rg_git_patch_limit($db) |
159 |
159 |
global $rg_git_patch_limit_force; |
global $rg_git_patch_limit_force; |
160 |
160 |
global $rg_git_patch_limit_default; |
global $rg_git_patch_limit_default; |
161 |
161 |
|
|
162 |
|
// This is for functionl tests |
|
|
162 |
|
// This is for functional tests |
163 |
163 |
if (isset($rg_git_patch_limit_force)) |
if (isset($rg_git_patch_limit_force)) |
164 |
164 |
return $rg_git_patch_limit_force; |
return $rg_git_patch_limit_force; |
165 |
165 |
|
|
166 |
|
$r = rg_state_get($db, 'git_patch_limit'); |
|
167 |
|
if (($r === FALSE) || empty($r)) |
|
|
166 |
|
$r = rg_state_get_uint($db, 'git_patch_limit'); |
|
167 |
|
if (($r === FALSE) || ($r === 0)) |
168 |
168 |
return $rg_git_patch_limit_default; |
return $rg_git_patch_limit_default; |
169 |
169 |
|
|
170 |
|
return intval($r); |
|
|
170 |
|
return $r; |
171 |
171 |
} |
} |
172 |
172 |
|
|
173 |
173 |
/* |
/* |
|
... |
... |
function rg_git_quote($s) |
282 |
282 |
*/ |
*/ |
283 |
283 |
function rg_git_install_hooks($dst) |
function rg_git_install_hooks($dst) |
284 |
284 |
{ |
{ |
285 |
|
global $php_errormsg; |
|
286 |
285 |
global $rg_scripts; |
global $rg_scripts; |
287 |
286 |
|
|
288 |
287 |
rg_prof_start("git_install_hooks"); |
rg_prof_start("git_install_hooks"); |
|
... |
... |
function rg_git_install_hooks($dst) |
316 |
315 |
rg_log("Link hooks dir..."); |
rg_log("Link hooks dir..."); |
317 |
316 |
if (symlink($rg_scripts . "/hooks", $dst . "/hooks") === FALSE) { |
if (symlink($rg_scripts . "/hooks", $dst . "/hooks") === FALSE) { |
318 |
317 |
rg_git_set_error("cannot make symlink [$rg_scripts/hooks]" |
rg_git_set_error("cannot make symlink [$rg_scripts/hooks]" |
319 |
|
. "->[$dst/] ($php_errormsg)."); |
|
|
318 |
|
. "->[$dst/] (" . rg_php_err() . ")."); |
320 |
319 |
break; |
break; |
321 |
320 |
} |
} |
322 |
321 |
|
|
|
... |
... |
function rg_git_install_hooks($dst) |
334 |
333 |
*/ |
*/ |
335 |
334 |
function rg_git_init($dst) |
function rg_git_init($dst) |
336 |
335 |
{ |
{ |
337 |
|
global $php_errormsg; |
|
338 |
|
|
|
339 |
336 |
rg_prof_start("git_init"); |
rg_prof_start("git_init"); |
340 |
337 |
rg_log_enter("git_init: dst=$dst"); |
rg_log_enter("git_init: dst=$dst"); |
341 |
338 |
|
|
|
... |
... |
function rg_git_init($dst) |
345 |
342 |
if (!file_exists($dir)) { |
if (!file_exists($dir)) { |
346 |
343 |
$r = @mkdir($dir, 0700, TRUE); |
$r = @mkdir($dir, 0700, TRUE); |
347 |
344 |
if ($r === FALSE) { |
if ($r === FALSE) { |
348 |
|
rg_git_set_error("cannot create dir [$dir] ($php_errormsg)"); |
|
|
345 |
|
rg_git_set_error("cannot create dir [$dir] (" . rg_php_err() . ")"); |
349 |
346 |
break; |
break; |
350 |
347 |
} |
} |
351 |
348 |
} |
} |
|
... |
... |
function rg_git_init($dst) |
361 |
358 |
} |
} |
362 |
359 |
|
|
363 |
360 |
if (!@mkdir($dst2 . '/rocketgit')) { |
if (!@mkdir($dst2 . '/rocketgit')) { |
364 |
|
rg_git_set_error("cannot create '$dst/rocketgit' dir ($php_errormsg)"); |
|
|
361 |
|
rg_git_set_error("cannot create '$dst/rocketgit' dir (" . rg_php_err() . ")"); |
365 |
362 |
break; |
break; |
366 |
363 |
} |
} |
367 |
364 |
|
|
|
... |
... |
function rg_git_init($dst) |
386 |
383 |
|
|
387 |
384 |
function rg_git_clone($src, $dst) |
function rg_git_clone($src, $dst) |
388 |
385 |
{ |
{ |
389 |
|
global $php_errormsg; |
|
390 |
|
|
|
391 |
386 |
rg_prof_start("git_clone"); |
rg_prof_start("git_clone"); |
392 |
387 |
rg_log_enter("git_clone: src=$src, dst=$dst"); |
rg_log_enter("git_clone: src=$src, dst=$dst"); |
393 |
388 |
|
|
|
... |
... |
function rg_git_clone($src, $dst) |
397 |
392 |
if (!file_exists($dir)) { |
if (!file_exists($dir)) { |
398 |
393 |
$r = @mkdir($dir, 0700, TRUE); |
$r = @mkdir($dir, 0700, TRUE); |
399 |
394 |
if ($r === FALSE) { |
if ($r === FALSE) { |
400 |
|
rg_git_set_error("cannot create dir [$dir] ($php_errormsg)"); |
|
|
395 |
|
rg_git_set_error("cannot create dir [$dir] (" . rg_php_err() . ")"); |
401 |
396 |
break; |
break; |
402 |
397 |
} |
} |
403 |
398 |
} |
} |
|
... |
... |
function rg_git_clone($src, $dst) |
412 |
407 |
} |
} |
413 |
408 |
|
|
414 |
409 |
if (!@mkdir($dst . "/rocketgit", 0700)) { |
if (!@mkdir($dst . "/rocketgit", 0700)) { |
415 |
|
rg_git_set_error("cannot create '$dst/rocketgit' dir ($php_errormsg)"); |
|
|
410 |
|
rg_git_set_error("cannot create '$dst/rocketgit' dir (" . rg_php_err() . ")"); |
416 |
411 |
break; |
break; |
417 |
412 |
} |
} |
418 |
413 |
} |
} |
|
... |
... |
function rg_git_load_ref($repo_path, $ref) |
629 |
624 |
* Returns a common ancestor between two commits (FALSE on error) |
* Returns a common ancestor between two commits (FALSE on error) |
630 |
625 |
* TODO: Unit testing |
* TODO: Unit testing |
631 |
626 |
*/ |
*/ |
632 |
|
function rg_git_merge_base($repo_path, $a, $b) |
|
|
627 |
|
function rg_git_merge_base($repo_path, $refname_or_hash, $b) |
633 |
628 |
{ |
{ |
634 |
629 |
global $rg_git_zero; |
global $rg_git_zero; |
635 |
630 |
global $rg_git_empty; |
global $rg_git_empty; |
636 |
631 |
|
|
637 |
632 |
rg_prof_start('git_merge_base'); |
rg_prof_start('git_merge_base'); |
638 |
|
rg_log_enter('git_merge_base' . ' a=' . $a . ' b=' . $b); |
|
|
633 |
|
rg_log_enter('git_merge_base' . ' refname_or_hash=' . $refname_or_hash |
|
634 |
|
. ' b=' . $b); |
639 |
635 |
|
|
640 |
636 |
$ret = FALSE; |
$ret = FALSE; |
641 |
637 |
while (1) { |
while (1) { |
642 |
|
if (rg_git_branch_is_empty($repo_path, $a)) { |
|
|
638 |
|
$r = rg_git_repo_is_empty($repo_path); |
|
639 |
|
if ($r === -1) |
|
640 |
|
break; |
|
641 |
|
|
|
642 |
|
if ($r === 1) { |
|
643 |
|
rg_log('DEBUG_MERGE: repo is empty. Return rg_git_empty.'); |
643 |
644 |
$ret = $rg_git_empty; |
$ret = $rg_git_empty; |
644 |
645 |
break; |
break; |
645 |
646 |
} |
} |
646 |
647 |
|
|
647 |
|
if (empty($repo_path)) |
|
648 |
|
$add = ''; |
|
649 |
|
else |
|
650 |
|
$add = ' --git-dir=' . escapeshellarg($repo_path); |
|
|
648 |
|
$head = rg_git_load_ref($repo_path, $refname_or_hash); |
|
649 |
|
rg_log('DEBUG_MERGE: head=' . $head); |
|
650 |
|
if ($head === FALSE) |
|
651 |
|
break; |
|
652 |
|
if (!rg_git_ref_exists($repo_path, $refname_or_hash)) |
|
653 |
|
rg_log('DEBUG_MERGE: ref does not exists, probably is a hash'); |
651 |
654 |
|
|
|
655 |
|
// TODO: we cannot use the caching because refname_or_hash |
|
656 |
|
// can be a refname which is a moving target. |
|
657 |
|
if (0) { |
652 |
658 |
if (!empty($repo_path)) { |
if (!empty($repo_path)) { |
653 |
|
$head = rg_git_load_ref($repo_path, $a); |
|
654 |
|
if ($head === FALSE) |
|
655 |
|
break; |
|
656 |
|
|
|
657 |
659 |
// TODO: why do we use escape here?! |
// TODO: why do we use escape here?! |
658 |
660 |
$key = 'git' |
$key = 'git' |
659 |
661 |
. '::' . sha1($repo_path) |
. '::' . sha1($repo_path) |
|
... |
... |
function rg_git_merge_base($repo_path, $a, $b) |
666 |
668 |
break; |
break; |
667 |
669 |
} |
} |
668 |
670 |
} |
} |
|
671 |
|
} |
|
672 |
|
|
|
673 |
|
if (empty($repo_path)) |
|
674 |
|
$add = ''; |
|
675 |
|
else |
|
676 |
|
$add = ' --git-dir=' . escapeshellarg($repo_path); |
669 |
677 |
|
|
670 |
678 |
$cmd = RG_GIT_CMD |
$cmd = RG_GIT_CMD |
671 |
679 |
. $add |
. $add |
672 |
680 |
. ' merge-base' |
. ' merge-base' |
673 |
|
. ' ' . escapeshellarg($a) |
|
|
681 |
|
. ' ' . escapeshellarg($refname_or_hash) |
674 |
682 |
. ' ' . escapeshellarg($b); |
. ' ' . escapeshellarg($b); |
675 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
|
676 |
|
if ($a['ok'] != 1) { |
|
677 |
|
rg_git_set_error('error on git merge_base (' |
|
678 |
|
. $a['errmsg'] . ')'); |
|
|
683 |
|
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
|
684 |
|
if ($r['ok'] != 1) { |
|
685 |
|
rg_git_set_error('error on git merge-base (' |
|
686 |
|
. $r['errmsg'] . ')'); |
679 |
687 |
break; |
break; |
680 |
688 |
} |
} |
681 |
689 |
|
|
682 |
|
$ret = trim($a['data']); |
|
|
690 |
|
$ret = trim($r['data']); |
683 |
691 |
|
|
|
692 |
|
if (0) { |
684 |
693 |
if (!empty($repo_path)) |
if (!empty($repo_path)) |
685 |
694 |
rg_cache_set($key, $ret, RG_SOCKET_NO_WAIT); |
rg_cache_set($key, $ret, RG_SOCKET_NO_WAIT); |
|
695 |
|
} |
686 |
696 |
|
|
687 |
697 |
break; |
break; |
688 |
698 |
} |
} |
|
... |
... |
function rg_git_ls_tree($repo_path, $tree, $path) |
779 |
789 |
|
|
780 |
790 |
$ret = FALSE; |
$ret = FALSE; |
781 |
791 |
while (1) { |
while (1) { |
782 |
|
if (rg_git_repo_is_empty($repo_path)) { |
|
|
792 |
|
$r = rg_git_repo_is_empty($repo_path); |
|
793 |
|
if ($r === -1) |
|
794 |
|
break; |
|
795 |
|
|
|
796 |
|
if ($r === 1) { |
783 |
797 |
$ret = array(); |
$ret = array(); |
784 |
798 |
break; |
break; |
785 |
799 |
} |
} |
|
... |
... |
function rg_git_diff2array($diff, &$out) |
1165 |
1179 |
return $ret; |
return $ret; |
1166 |
1180 |
} |
} |
1167 |
1181 |
|
|
|
1182 |
|
/* |
|
1183 |
|
* Returns 1 if a range of commits contain at least a merge, |
|
1184 |
|
* 0 if not, -1 on error. |
|
1185 |
|
*/ |
|
1186 |
|
function rg_git_log_has_merges($repo_path, $from, $to) |
|
1187 |
|
{ |
|
1188 |
|
global $rg_git_debug; |
|
1189 |
|
|
|
1190 |
|
rg_prof_start('git_log_has_merges'); |
|
1191 |
|
rg_log_enter('git_log_has_merges: repo_path=' . $repo_path |
|
1192 |
|
. ' from=' . $from . ' to=' . $to); |
|
1193 |
|
|
|
1194 |
|
$ret = -1; |
|
1195 |
|
while (1) { |
|
1196 |
|
$from_to = rg_git_from_to($from, $to); |
|
1197 |
|
|
|
1198 |
|
$cmd = RG_GIT_CMD . ' --no-pager' |
|
1199 |
|
. ' --git-dir=' . escapeshellarg($repo_path) |
|
1200 |
|
. ' log' |
|
1201 |
|
. ' --merges --oneline --max-count=1'; |
|
1202 |
|
if (!empty($from_to)) |
|
1203 |
|
$cmd .= ' ' . escapeshellarg($from_to); |
|
1204 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
|
1205 |
|
if ($a['ok'] != 1) { |
|
1206 |
|
rg_internal_error("error on log (" . $a['errmsg'] . ")" |
|
1207 |
|
. " cmd=" . $cmd); |
|
1208 |
|
rg_git_set_error('could not generate log; try again later'); |
|
1209 |
|
break; |
|
1210 |
|
} |
|
1211 |
|
|
|
1212 |
|
$rg_git_debug && rg_log('a:' . print_r($a, TRUE)); |
|
1213 |
|
if (empty($a['data'])) { |
|
1214 |
|
$ret = 0; |
|
1215 |
|
break; |
|
1216 |
|
} |
|
1217 |
|
|
|
1218 |
|
$ret = 1; |
|
1219 |
|
break; |
|
1220 |
|
} |
|
1221 |
|
|
|
1222 |
|
rg_log_exit(); |
|
1223 |
|
rg_prof_end('git_log_has_merges'); |
|
1224 |
|
return $ret; |
|
1225 |
|
} |
|
1226 |
|
|
1168 |
1227 |
/* |
/* |
1169 |
1228 |
* Show last @max commits, no merges, sort by topo |
* Show last @max commits, no merges, sort by topo |
1170 |
1229 |
* @also_patch = TRUE if caller needs also the patch |
* @also_patch = TRUE if caller needs also the patch |
|
... |
... |
function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files, |
1189 |
1248 |
$max_count = ($max == 0) ? "" : " --max-count=$max"; |
$max_count = ($max == 0) ? "" : " --max-count=$max"; |
1190 |
1249 |
$patches = $also_patch ? " --patch" : ""; |
$patches = $also_patch ? " --patch" : ""; |
1191 |
1250 |
$from_to = rg_git_from_to($from, $to); |
$from_to = rg_git_from_to($from, $to); |
|
1251 |
|
|
1192 |
1252 |
$id = rg_id(16); |
$id = rg_id(16); |
1193 |
1253 |
$sep_start = '-=ROCKETGIT-START-' . $id . '=-'; |
$sep_start = '-=ROCKETGIT-START-' . $id . '=-'; |
1194 |
1254 |
$sep_end = '-=ROCKETGIT_END_OF_VARS-' . $id . '=-'; |
$sep_end = '-=ROCKETGIT_END_OF_VARS-' . $id . '=-'; |
|
... |
... |
function rg_git_diff($id, $a, $template_file) |
1721 |
1781 |
if ($rg_git_debug > 90) |
if ($rg_git_debug > 90) |
1722 |
1782 |
rg_log_ml("DEBUG: finfo: " . print_r($finfo, TRUE)); |
rg_log_ml("DEBUG: finfo: " . print_r($finfo, TRUE)); |
1723 |
1783 |
|
|
1724 |
|
$ret .= "<br />\n"; |
|
1725 |
|
|
|
1726 |
1784 |
$v = rg_visible_string($finfo['file']); |
$v = rg_visible_string($finfo['file']); |
1727 |
1785 |
$f = rg_xss_safe($v); |
$f = rg_xss_safe($v); |
1728 |
1786 |
$ret .= '<a name="file-' . $id . '-' . sha1($finfo['file']) . '"></a>' . "\n"; |
$ret .= '<a name="file-' . $id . '-' . sha1($finfo['file']) . '"></a>' . "\n"; |
|
... |
... |
function rg_git_update_branch($db, $a) |
1990 |
2048 |
. "\nYou have no rights to delete a branch."); |
. "\nYou have no rights to delete a branch."); |
1991 |
2049 |
$history['history_category'] = REPO_CAT_GIT_BRANCH_DELETE; |
$history['history_category'] = REPO_CAT_GIT_BRANCH_DELETE; |
1992 |
2050 |
$history['history_message'] = 'Reference ' . $a['refname'] |
$history['history_message'] = 'Reference ' . $a['refname'] |
1993 |
|
. ' deleted'; |
|
|
2051 |
|
. ' deleted (was ' . $a['old_rev'] . ')'; |
1994 |
2052 |
rg_repo_history_insert($db, $history); |
rg_repo_history_insert($db, $history); |
1995 |
2053 |
break; |
break; |
1996 |
2054 |
} |
} |
|
... |
... |
function rg_git_update_branch($db, $a) |
2011 |
2069 |
$x = $_x; |
$x = $_x; |
2012 |
2070 |
$x['needed_rights'] = 'O'; |
$x['needed_rights'] = 'O'; |
2013 |
2071 |
if ((rg_rights_allow($db, $x) !== TRUE) && ($check_fast_forward == 1)) { |
if ((rg_rights_allow($db, $x) !== TRUE) && ($check_fast_forward == 1)) { |
2014 |
|
$merge_base = rg_git_merge_base($a['repo_path'], $a['old_rev'], |
|
2015 |
|
$a['new_rev']); |
|
|
2072 |
|
$merge_base = rg_git_merge_base($a['repo_path'], |
|
2073 |
|
$a['old_rev'], $a['new_rev']); |
2016 |
2074 |
if ($merge_base === FALSE) { |
if ($merge_base === FALSE) { |
2017 |
2075 |
rg_log("Error in merge_base: " . rg_git_error()); |
rg_log("Error in merge_base: " . rg_git_error()); |
2018 |
2076 |
rg_git_fatal($a['refname'] . "\nInternal error." |
rg_git_fatal($a['refname'] . "\nInternal error." |
2019 |
2077 |
. " Please try again later."); |
. " Please try again later."); |
2020 |
2078 |
} |
} |
2021 |
2079 |
|
|
2022 |
|
if (strcmp($merge_base, $a['old_rev']) != 0) |
|
|
2080 |
|
if (strcmp($merge_base, $a['old_rev']) != 0) { |
|
2081 |
|
rg_log('DEBUG: merge_base=' . $merge_base); |
|
2082 |
|
rg_log('DEBUG: merge_base != old_rev [' . $a['old_rev'] . ']'); |
2023 |
2083 |
rg_git_fatal($a['refname'] |
rg_git_fatal($a['refname'] |
2024 |
2084 |
. "\nYou have no rights to do a non fast-forward push;" |
. "\nYou have no rights to do a non fast-forward push;" |
2025 |
|
. " Do a fetch and re-base before pushing."); |
|
|
2085 |
|
. " Do a merge or re-base before pushing."); |
|
2086 |
|
} |
2026 |
2087 |
} |
} |
2027 |
2088 |
|
|
2028 |
2089 |
// Check if user pushes a merge commit |
// Check if user pushes a merge commit |
2029 |
|
// TODO: Check all commits, not only the last one! |
|
2030 |
2090 |
$x = $_x; |
$x = $_x; |
2031 |
2091 |
$x['needed_rights'] = 'M'; |
$x['needed_rights'] = 'M'; |
2032 |
2092 |
if (rg_rights_allow($db, $x) !== TRUE) { |
if (rg_rights_allow($db, $x) !== TRUE) { |
2033 |
|
if (rg_git_rev_ok($a['new_rev'] . "^2") !== FALSE) |
|
|
2093 |
|
$r = rg_git_log_has_merges($a['repo_path'], |
|
2094 |
|
$a['old_rev'], $a['new_rev']); |
|
2095 |
|
if ($r == -1) { |
|
2096 |
|
rg_git_fatal($a['refname'] . "\n" . rg_git_error()); |
|
2097 |
|
} else if ($r == 1) { |
2034 |
2098 |
rg_git_fatal($a['refname'] |
rg_git_fatal($a['refname'] |
2035 |
|
. "\nYou have no rights to push merges."); |
|
|
2099 |
|
. "\nYou have no rights to push merges." |
|
2100 |
|
. ' Do a rebase.'); |
|
2101 |
|
} |
2036 |
2102 |
} |
} |
2037 |
2103 |
|
|
2038 |
2104 |
// Check for bad whitespace |
// Check for bad whitespace |
|
... |
... |
function rg_git_update_branch($db, $a) |
2106 |
2172 |
rg_log("DEBUG: We are allowed to push."); |
rg_log("DEBUG: We are allowed to push."); |
2107 |
2173 |
|
|
2108 |
2174 |
$ev = $a; |
$ev = $a; |
2109 |
|
$ev['category'] = 3007; |
|
|
2175 |
|
$ev['category'] = 'repo_event_push'; |
2110 |
2176 |
$ev['prio'] = 50; |
$ev['prio'] = 50; |
2111 |
2177 |
$ev['ri'] = array( |
$ev['ri'] = array( |
2112 |
2178 |
'repo_id' => $a['repo_id'], |
'repo_id' => $a['repo_id'], |
|
... |
... |
function rg_git_content_by_file($treeish, $file) |
2335 |
2401 |
} |
} |
2336 |
2402 |
|
|
2337 |
2403 |
/* |
/* |
2338 |
|
* High level function that shows commits between two points |
|
|
2404 |
|
* High level function that shows commits between two points. |
2339 |
2405 |
* Input is the array returned by rg_git_log() |
* Input is the array returned by rg_git_log() |
2340 |
2406 |
* @commit_table - TRUE if you want commit table to show (FALSE for log/commit) |
* @commit_table - TRUE if you want commit table to show (FALSE for log/commit) |
2341 |
2407 |
*/ |
*/ |
|
... |
... |
function rg_git_log2listing($log, $rg, $commit_table) |
2343 |
2409 |
{ |
{ |
2344 |
2410 |
rg_log_enter('git_log2listing'); |
rg_log_enter('git_log2listing'); |
2345 |
2411 |
|
|
|
2412 |
|
$ret = ''; |
2346 |
2413 |
while (1) { |
while (1) { |
2347 |
2414 |
if ($log === FALSE) { |
if ($log === FALSE) { |
2348 |
|
$ret = rg_template('repo/not_init.html', $rg, TRUE /*xss*/); |
|
|
2415 |
|
$ret = rg_template('repo/err/not_init.html', $rg, TRUE /*xss*/); |
2349 |
2416 |
break; |
break; |
2350 |
2417 |
} |
} |
2351 |
2418 |
|
|
2352 |
|
$ret = ''; |
|
2353 |
|
|
|
2354 |
2419 |
if ($commit_table) { |
if ($commit_table) { |
2355 |
2420 |
// Show a short list of commits |
// Show a short list of commits |
2356 |
2421 |
// Set 'url' |
// Set 'url' |
|
... |
... |
function rg_git_log2listing($log, $rg, $commit_table) |
2358 |
2423 |
$log[$index]['vars']['commit_url'] = |
$log[$index]['vars']['commit_url'] = |
2359 |
2424 |
rg_xss_safe($rg['mr']['id']) |
rg_xss_safe($rg['mr']['id']) |
2360 |
2425 |
. "#sha1-" . rg_xss_safe($i['vars']['sha1']); |
. "#sha1-" . rg_xss_safe($i['vars']['sha1']); |
2361 |
|
$ret .= rg_git_log_template($log, 'repo/log', $rg); |
|
|
2426 |
|
$rg['HTML:commit_table'] = rg_git_log_template($log, |
|
2427 |
|
'repo/log', $rg); |
|
2428 |
|
} else { |
|
2429 |
|
$rg['HTML:commit_table'] = ''; |
2362 |
2430 |
} |
} |
2363 |
2431 |
|
|
2364 |
|
// TODO: move this into a template! |
|
2365 |
|
$ret .= '<div style="margin-top: 8pt; margin-left: 8pt">' . "\n"; |
|
2366 |
|
foreach ($log as $junk => $i) { |
|
|
2432 |
|
foreach ($log as $junk => &$i) { |
2367 |
2433 |
//rg_log_ml('DEBUG: i=' . print_r($i, TRUE)); |
//rg_log_ml('DEBUG: i=' . print_r($i, TRUE)); |
2368 |
2434 |
|
|
2369 |
2435 |
// Some info about commit |
// Some info about commit |
2370 |
|
$ret .= "<b>" |
|
2371 |
|
. "<a name=\"sha1-" . rg_xss_safe($i['vars']['sha1']) . "\">" |
|
2372 |
|
. "Commit " . rg_xss_safe($i['vars']['sha1']) |
|
2373 |
|
. "</a></b> - " . rg_xss_safe($i['vars']['subject']) . "\n"; |
|
2374 |
|
|
|
2375 |
2436 |
if (!empty($i['vars']['body'])) |
if (!empty($i['vars']['body'])) |
2376 |
|
$ret .= "<br />\n" |
|
2377 |
|
. nl2br(rg_xss_safe($i['vars']['body'])); |
|
2378 |
|
|
|
2379 |
|
$ret .= "<br /><b>Author</b>: " . rg_xss_safe($i['vars']['author name']); |
|
|
2437 |
|
$i['vars']['HTML:x_body'] |
|
2438 |
|
= '<div class="commit_body">' |
|
2439 |
|
. nl2br(rg_xss_safe(trim($i['vars']['body']))) |
|
2440 |
|
. '</div>'; |
|
2441 |
|
else |
|
2442 |
|
$i['vars']['HTML:x_body'] = ''; |
2380 |
2443 |
|
|
2381 |
|
$ret .= "<br /><b>Author date (UTC)</b>: " |
|
2382 |
|
. gmdate("Y-m-d H:i", $i['vars']['author date']); |
|
|
2444 |
|
$i['vars']['HTML:x_author date'] |
|
2445 |
|
= gmdate("Y-m-d H:i", $i['vars']['author date']); |
2383 |
2446 |
|
|
2384 |
2447 |
if (!empty($i['vars']['committer name'])) |
if (!empty($i['vars']['committer name'])) |
2385 |
|
$ret .= "<br /><b>Committer</b>: " |
|
2386 |
|
. rg_xss_safe($i['vars']['committer name']); |
|
2387 |
|
|
|
2388 |
|
$ret .= '<br /><b>Commit date (UTC)</b>: ' |
|
2389 |
|
. gmdate("Y-m-d H:i", $i['vars']['committer date']); |
|
2390 |
|
|
|
2391 |
|
$ret .= '<br /><b>Tree</b>: ' . $i['vars']['tree']; |
|
2392 |
|
|
|
2393 |
|
if (!empty($i['vars']['parents'])) |
|
2394 |
|
$ret .= '<br /><b>Parents</b>: ' |
|
2395 |
|
. $i['vars']['parents']; |
|
|
2448 |
|
$i['vars']['x_committer name'] |
|
2449 |
|
= $i['vars']['committer name']; |
|
2450 |
|
else |
|
2451 |
|
$i['vars']['HTML:x_committer name'] = '?'; |
2396 |
2452 |
|
|
2397 |
|
if (!empty($i['vars']['sign_key'])) |
|
2398 |
|
$ret .= '<br /><b>Signing key</b>: ' |
|
2399 |
|
. $i['vars']['sign_key']; |
|
|
2453 |
|
$i['vars']['HTML:x_committer date'] |
|
2454 |
|
= gmdate("Y-m-d H:i", $i['vars']['committer date']); |
2400 |
2455 |
|
|
2401 |
2456 |
// stats |
// stats |
2402 |
2457 |
$r = rg_git_files_stats($i['vars']['sha1'], $i['files'], |
$r = rg_git_files_stats($i['vars']['sha1'], $i['files'], |
2403 |
2458 |
'repo/fstat'); |
'repo/fstat'); |
2404 |
|
if ($r === FALSE) { |
|
2405 |
|
$ret = FALSE; |
|
2406 |
|
break; |
|
2407 |
|
} |
|
2408 |
|
$ret .= $r; |
|
|
2459 |
|
if ($r === FALSE) |
|
2460 |
|
$i['HTML:x_stats'] = rg_template('repo/err/stats.html', $rg, TRUE /*xss*/); |
|
2461 |
|
else |
|
2462 |
|
$i['HTML:x_stats'] = $r; |
2409 |
2463 |
|
|
2410 |
2464 |
// diff |
// diff |
2411 |
2465 |
//rg_log_ml("DEBUG: i[files]=" . print_r($i['files'], TRUE)); |
//rg_log_ml("DEBUG: i[files]=" . print_r($i['files'], TRUE)); |
2412 |
2466 |
$r = rg_git_diff($i['vars']['sha1'], $i['files'], |
$r = rg_git_diff($i['vars']['sha1'], $i['files'], |
2413 |
2467 |
'repo/diff.html'); |
'repo/diff.html'); |
2414 |
|
if ($r === FALSE) { |
|
2415 |
|
$ret = FALSE; |
|
2416 |
|
break; |
|
2417 |
|
} |
|
2418 |
|
$ret .= $r; |
|
|
2468 |
|
if ($r === FALSE) |
|
2469 |
|
$i['HTML:x_diff'] = rg_template('repo/err/diff.html', $rg, TRUE /*xss*/); |
|
2470 |
|
else |
|
2471 |
|
$i['HTML:x_diff'] = $r; |
2419 |
2472 |
} |
} |
2420 |
2473 |
break; |
break; |
2421 |
2474 |
} |
} |
2422 |
|
|
|
2423 |
|
if (!empty($rg['HTML:commit_labels'])) |
|
2424 |
|
$ret .= '<br />' . $rg['HTML:commit_labels']; |
|
2425 |
|
$ret .= '</div>' . "\n"; |
|
|
2475 |
|
$ret .= rg_template_table('repo/commits', $log, $rg); |
2426 |
2476 |
|
|
2427 |
2477 |
rg_log_exit(); |
rg_log_exit(); |
2428 |
2478 |
return $ret; |
return $ret; |
|
... |
... |
function rg_git_merge_tree($repo_path, $base, $a, $b) |
2496 |
2546 |
|
|
2497 |
2547 |
$ret = FALSE; |
$ret = FALSE; |
2498 |
2548 |
while (1) { |
while (1) { |
2499 |
|
if (rg_git_repo_is_empty($repo_path)) |
|
|
2549 |
|
$r = rg_git_repo_is_empty($repo_path); |
|
2550 |
|
if ($r === -1) |
|
2551 |
|
break; |
|
2552 |
|
|
|
2553 |
|
if ($r === 1) |
2500 |
2554 |
$a = $rg_git_empty; |
$a = $rg_git_empty; |
2501 |
2555 |
|
|
2502 |
2556 |
$head = rg_git_load_ref($repo_path, $a); |
$head = rg_git_load_ref($repo_path, $a); |
2503 |
2557 |
if ($head === FALSE) |
if ($head === FALSE) |
2504 |
2558 |
break; |
break; |
2505 |
2559 |
|
|
2506 |
|
$key = 'git' |
|
2507 |
|
. '::' . sha1($repo_path) |
|
2508 |
|
. '::' . 'merge-tree' |
|
2509 |
|
. '::' . $head . '::' . $b; |
|
2510 |
|
$r = rg_cache_get($key); |
|
2511 |
|
if ($r !== FALSE) { |
|
2512 |
|
$ret = $r; |
|
2513 |
|
break; |
|
|
2560 |
|
if (!empty($repo_path)) { |
|
2561 |
|
$key = 'git' |
|
2562 |
|
. '::' . sha1($repo_path) |
|
2563 |
|
. '::' . 'merge-tree' |
|
2564 |
|
. '::' . $head . '::' . $b; |
|
2565 |
|
$r = rg_cache_get($key); |
|
2566 |
|
if ($r !== FALSE) { |
|
2567 |
|
$ret = $r; |
|
2568 |
|
break; |
|
2569 |
|
} |
2514 |
2570 |
} |
} |
2515 |
2571 |
|
|
2516 |
2572 |
$cmd = RG_GIT_CMD . ' --git-dir=' . escapeshellarg($repo_path) |
$cmd = RG_GIT_CMD . ' --git-dir=' . escapeshellarg($repo_path) |
|
... |
... |
function rg_git_merge_tree($repo_path, $base, $a, $b) |
2525 |
2581 |
break; |
break; |
2526 |
2582 |
} |
} |
2527 |
2583 |
|
|
2528 |
|
$ret = trim($a['data']); |
|
2529 |
|
rg_cache_set($key, $ret, RG_SOCKET_NO_WAIT); |
|
|
2584 |
|
if (!empty($repo_path)) { |
|
2585 |
|
$ret = trim($a['data']); |
|
2586 |
|
rg_cache_set($key, $ret, RG_SOCKET_NO_WAIT); |
|
2587 |
|
} |
2530 |
2588 |
rg_log_ml('DEBUG: merge-tree: ' . $ret); |
rg_log_ml('DEBUG: merge-tree: ' . $ret); |
2531 |
2589 |
break; |
break; |
2532 |
2590 |
} |
} |
|
... |
... |
function rg_git_merge($repo_path, $ref_name, $new, $ff, $msg) |
2593 |
2651 |
|
|
2594 |
2652 |
rg_prof_start('git_merge'); |
rg_prof_start('git_merge'); |
2595 |
2653 |
rg_log_enter('git_merge' . ' ref_name=' . $ref_name |
rg_log_enter('git_merge' . ' ref_name=' . $ref_name |
2596 |
|
. ' new=' . $new . ' ff=' . $ff . ' msg=' . $msg); |
|
|
2654 |
|
. ' new=' . $new . ' ff=' . $ff . ' msg=[' . $msg . ']'); |
2597 |
2655 |
|
|
2598 |
2656 |
$ret = FALSE; |
$ret = FALSE; |
2599 |
2657 |
while (1) { |
while (1) { |
2600 |
|
if (rg_git_repo_is_empty($repo_path)) |
|
|
2658 |
|
$r = rg_git_repo_is_empty($repo_path); |
|
2659 |
|
if ($r === -1) |
|
2660 |
|
break; |
|
2661 |
|
|
|
2662 |
|
if ($r === 1) |
2601 |
2663 |
$ref_name_tmp = $rg_git_empty; |
$ref_name_tmp = $rg_git_empty; |
2602 |
2664 |
else |
else |
2603 |
2665 |
$ref_name_tmp = $ref_name; |
$ref_name_tmp = $ref_name; |
2604 |
2666 |
|
|
2605 |
|
// TODO: this must go away - the cache will malfunction? |
|
2606 |
|
if (empty($repo_path)) |
|
2607 |
|
$add = ''; |
|
2608 |
|
else |
|
2609 |
|
$add = ' --git-dir=' . escapeshellarg($repo_path); |
|
2610 |
|
|
|
2611 |
2667 |
$r = rg_git_lock($repo_path, 60); |
$r = rg_git_lock($repo_path, 60); |
2612 |
2668 |
if ($r === FALSE) |
if ($r === FALSE) |
2613 |
2669 |
break; |
break; |
|
... |
... |
function rg_git_merge($repo_path, $ref_name, $new, $ff, $msg) |
2629 |
2685 |
rg_log('DEBUG: ref_name points to ' . $cur); |
rg_log('DEBUG: ref_name points to ' . $cur); |
2630 |
2686 |
|
|
2631 |
2687 |
// If repo was empty, we are forced to do a ff |
// If repo was empty, we are forced to do a ff |
2632 |
|
if (strcmp($mb, $rg_git_empty) == 0) |
|
|
2688 |
|
if (strcmp($mb, $rg_git_empty) == 0) { |
|
2689 |
|
rg_log('DEBUG: merge base is empty, allow fast-forward.'); |
2633 |
2690 |
$ff = 1; |
$ff = 1; |
|
2691 |
|
} |
2634 |
2692 |
|
|
2635 |
2693 |
if (($ff == 1) && (strcmp($mb, $cur) == 0)) { |
if (($ff == 1) && (strcmp($mb, $cur) == 0)) { |
2636 |
2694 |
rg_log('DEBUG: we can do a fast forward...'); |
rg_log('DEBUG: we can do a fast forward...'); |
|
... |
... |
function rg_git_merge($repo_path, $ref_name, $new, $ff, $msg) |
2641 |
2699 |
$e_ref_name_tmp = escapeshellarg($ref_name_tmp); |
$e_ref_name_tmp = escapeshellarg($ref_name_tmp); |
2642 |
2700 |
$e_new = escapeshellarg($new); |
$e_new = escapeshellarg($new); |
2643 |
2701 |
|
|
|
2702 |
|
// TODO: this must go away - the cache will malfunction? |
|
2703 |
|
if (empty($repo_path)) |
|
2704 |
|
$add = ''; |
|
2705 |
|
else |
|
2706 |
|
$add = ' --git-dir=' . escapeshellarg($repo_path); |
|
2707 |
|
|
2644 |
2708 |
$cmd = RG_GIT_CMD |
$cmd = RG_GIT_CMD |
2645 |
2709 |
. $add . ' read-tree -i -m ' |
. $add . ' read-tree -i -m ' |
2646 |
2710 |
. $e_mb . ' ' . $e_ref_name_tmp . ' ' . $e_new; |
. $e_mb . ' ' . $e_ref_name_tmp . ' ' . $e_new; |
File inc/repo.inc.php changed (mode: 100644) (index 774c84f..9f2f761) |
... |
... |
$rg_repo_functions = array( |
461 |
461 |
3004 => "rg_repo_event_symlink_by_name", |
3004 => "rg_repo_event_symlink_by_name", |
462 |
462 |
3005 => "rg_repo_event_storage_create", |
3005 => "rg_repo_event_storage_create", |
463 |
463 |
3006 => "rg_repo_history_insert", |
3006 => "rg_repo_history_insert", |
464 |
|
3007 => 'rg_repo_event_push' |
|
|
464 |
|
3007 => 'rg_repo_event_push', |
|
465 |
|
// new new style |
|
466 |
|
'repo_event_new' => 'rg_repo_event_new', |
|
467 |
|
'repo_event_del' => 'rg_repo_event_del', |
|
468 |
|
'repo_event_update' => 'rg_repo_event_update', |
|
469 |
|
'repo_event_notify_user' => 'rg_repo_event_notify_user', |
|
470 |
|
'repo_event_symlink_by_name' => 'rg_repo_event_symlink_by_name', |
|
471 |
|
'repo_event_storage_create' => 'rg_repo_event_storage_create', |
|
472 |
|
'repo_history_insert' => 'rg_repo_history_insert', |
|
473 |
|
'repo_event_push' => 'rg_repo_event_push' |
465 |
474 |
); |
); |
466 |
475 |
rg_event_register_functions($rg_repo_functions); |
rg_event_register_functions($rg_repo_functions); |
467 |
476 |
|
|
|
... |
... |
function rg_repo_event_new($db, $event) |
474 |
483 |
|
|
475 |
484 |
$event['op'] = "new"; |
$event['op'] = "new"; |
476 |
485 |
|
|
477 |
|
// Create git dir |
|
478 |
486 |
$x = $event; |
$x = $event; |
479 |
|
$x['category'] = 3005; |
|
|
487 |
|
$x['category'] = 'repo_event_storage_create'; |
480 |
488 |
$x['prio'] = 20; |
$x['prio'] = 20; |
481 |
489 |
$x['notification'] .= "-git"; |
$x['notification'] .= "-git"; |
482 |
490 |
$ret[] = $x; |
$ret[] = $x; |
483 |
491 |
|
|
484 |
|
// make symlink by name |
|
485 |
492 |
$x = $event; |
$x = $event; |
486 |
|
$x['category'] = 3004; |
|
|
493 |
|
$x['category'] = 'repo_event_symlink_by_name'; |
487 |
494 |
$x['prio'] = 200; |
$x['prio'] = 200; |
488 |
495 |
$x['notification'] .= "-symlink"; |
$x['notification'] .= "-symlink"; |
489 |
496 |
$ret[] = $x; |
$ret[] = $x; |
490 |
497 |
|
|
491 |
|
// notify user |
|
492 |
498 |
$x = $event; |
$x = $event; |
493 |
|
$x['category'] = 3003; |
|
|
499 |
|
$x['category'] = 'repo_event_notify_user'; |
494 |
500 |
$x['prio'] = 100; |
$x['prio'] = 100; |
495 |
501 |
$x['notification'] .= "-notify"; |
$x['notification'] .= "-notify"; |
496 |
502 |
$ret[] = $x; |
$ret[] = $x; |
|
... |
... |
function rg_repo_event_new($db, $event) |
504 |
510 |
|
|
505 |
511 |
// add a history entry |
// add a history entry |
506 |
512 |
$x = $event; |
$x = $event; |
507 |
|
$x['category'] = 3006; |
|
|
513 |
|
$x['category'] = 'repo_history_insert'; |
508 |
514 |
$x['prio'] = 50; |
$x['prio'] = 50; |
509 |
515 |
$ret[] = $x; |
$ret[] = $x; |
510 |
516 |
|
|
|
... |
... |
function rg_repo_event_del($db, $event) |
522 |
528 |
|
|
523 |
529 |
$event['op'] = "del"; |
$event['op'] = "del"; |
524 |
530 |
// notify user |
// notify user |
525 |
|
$ret[] = array_merge($event, array("category" => 3003, "prio" => 100)); |
|
|
531 |
|
$ret[] = array_merge($event, |
|
532 |
|
array('category' => 'repo_event_notify_user', 'prio' => 100)); |
526 |
533 |
|
|
527 |
534 |
// TODO: notify watchers |
// TODO: notify watchers |
528 |
535 |
|
|
|
... |
... |
function rg_repo_event_update($db, $event) |
669 |
676 |
$event['op'] = "update"; |
$event['op'] = "update"; |
670 |
677 |
|
|
671 |
678 |
// make symlink by name |
// make symlink by name |
672 |
|
$ret[] = array_merge($event, array("category" => 3004, "prio" => 200)); |
|
|
679 |
|
$ret[] = array_merge($event, |
|
680 |
|
array('category' => 'repo_event_symlink_by_name', 'prio' => 200)); |
673 |
681 |
|
|
674 |
682 |
// notify user |
// notify user |
675 |
|
$ret[] = array_merge($event, array("category" => 3003, "prio" => 100)); |
|
|
683 |
|
$ret[] = array_merge($event, |
|
684 |
|
array('category' => 'repo_event_notify_user', 'prio' => 100)); |
676 |
685 |
|
|
677 |
686 |
// TODO: notify watchers |
// TODO: notify watchers |
678 |
687 |
|
|
|
... |
... |
function rg_repo_event_notify_user($db, $event) |
702 |
711 |
|
|
703 |
712 |
/* |
/* |
704 |
713 |
* Inserts an event into repo_history table |
* Inserts an event into repo_history table |
|
714 |
|
* TODO: we do not know yet if update-ref succeded. |
705 |
715 |
*/ |
*/ |
706 |
716 |
function rg_repo_history_insert($db, $event) |
function rg_repo_history_insert($db, $event) |
707 |
717 |
{ |
{ |
|
... |
... |
function rg_repo_event_push($db, $event) |
745 |
755 |
|
|
746 |
756 |
// TODO: we must be sure here that the update-ref finished with success |
// TODO: we must be sure here that the update-ref finished with success |
747 |
757 |
// TODO: load references and check them? |
// TODO: load references and check them? |
|
758 |
|
// 'post-update' hook knows if it succeeded or not. How to use it? |
748 |
759 |
|
|
749 |
760 |
// notify user |
// notify user |
750 |
761 |
if (0) { // TODO |
if (0) { // TODO |
751 |
762 |
$x = $event; |
$x = $event; |
752 |
|
$x['category'] = 3003; |
|
|
763 |
|
$x['category'] = 'repo_event_notify_user'; |
753 |
764 |
$x['prio'] = 100; |
$x['prio'] = 100; |
754 |
765 |
$x['notification'] .= "-notify"; |
$x['notification'] .= "-notify"; |
755 |
766 |
$ret[] = $x; |
$ret[] = $x; |
|
... |
... |
function rg_repo_delete($db, $repo_id, $ui) |
940 |
951 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
941 |
952 |
|
|
942 |
953 |
$event = array( |
$event = array( |
943 |
|
'category' => 3001, |
|
|
954 |
|
'category' => 'repo_event_del', |
944 |
955 |
'prio' => 50, |
'prio' => 50, |
945 |
956 |
'ui' => $ui, |
'ui' => $ui, |
946 |
957 |
'ri' => array( |
'ri' => array( |
|
... |
... |
function rg_repo_edit($db, $login_ui, &$new) |
1167 |
1178 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
1168 |
1179 |
|
|
1169 |
1180 |
if ($new['repo_id'] == 0) { |
if ($new['repo_id'] == 0) { |
1170 |
|
$cat = 3000; |
|
|
1181 |
|
$cat = 'repo_event_new'; |
1171 |
1182 |
$hcat = REPO_CAT_CREATE; |
$hcat = REPO_CAT_CREATE; |
1172 |
1183 |
$hmess = "Repository has been created"; |
$hmess = "Repository has been created"; |
1173 |
1184 |
$notification = "repo_create-" . $login_ui['uid'] |
$notification = "repo_create-" . $login_ui['uid'] |
|
... |
... |
function rg_repo_edit($db, $login_ui, &$new) |
1175 |
1186 |
$old_description = ""; |
$old_description = ""; |
1176 |
1187 |
$new['repo_id'] = $row['repo_id']; |
$new['repo_id'] = $row['repo_id']; |
1177 |
1188 |
} else { |
} else { |
1178 |
|
$cat = 3002; |
|
|
1189 |
|
$cat = 'repo_event_update'; |
1179 |
1190 |
$hcat = REPO_CAT_UPDATE; |
$hcat = REPO_CAT_UPDATE; |
1180 |
1191 |
$hmess = "Repository has been updated"; |
$hmess = "Repository has been updated"; |
1181 |
1192 |
$notification = ""; |
$notification = ""; |
|
... |
... |
function rg_repo_stats($rg) |
2179 |
2190 |
|
|
2180 |
2191 |
while (1) { |
while (1) { |
2181 |
2192 |
if ($rg['ri']['git_dir_done'] == 0) { |
if ($rg['ri']['git_dir_done'] == 0) { |
2182 |
|
$ret = rg_template('repo/no_git_dir.html', $rg, TRUE /*xss*/); |
|
|
2193 |
|
$ret = rg_template('repo/err/no_git_dir.html', $rg, TRUE /*xss*/); |
2183 |
2194 |
break; |
break; |
2184 |
2195 |
} |
} |
2185 |
2196 |
|
|
|
... |
... |
function rg_repo_api($db, $a) |
2460 |
2471 |
function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user, |
function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user, |
2461 |
2472 |
$repo, $cmd) |
$repo, $cmd) |
2462 |
2473 |
{ |
{ |
|
2474 |
|
global $rg_log_sid; |
|
2475 |
|
|
2463 |
2476 |
rg_prof_start('repo_fetch_push_helper'); |
rg_prof_start('repo_fetch_push_helper'); |
2464 |
2477 |
rg_log_enter('repo_fetch_push_helper: host=' . $host |
rg_log_enter('repo_fetch_push_helper: host=' . $host |
2465 |
|
. ' prefix=' . $prefix . ' user=' . $user |
|
2466 |
|
. ' repo=' . $repo . ' cmd=' . $cmd); |
|
|
2478 |
|
. ' ip=' . $ip . ' prefix=' . $prefix . ' user=[' . $user . ']' |
|
2479 |
|
. ' repo=[' . $repo . '] cmd=[' . $cmd . ']'); |
2467 |
2480 |
|
|
2468 |
2481 |
$ret = array('ok' => 0, 'allow' => 0, 'push_allowed' => 0); |
$ret = array('ok' => 0, 'allow' => 0, 'push_allowed' => 0); |
2469 |
2482 |
while (1) { |
while (1) { |
|
... |
... |
function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user, |
2502 |
2515 |
|
|
2503 |
2516 |
// Loading info about the repository |
// Loading info about the repository |
2504 |
2517 |
if (rg_repo_ok($repo) !== TRUE) { |
if (rg_repo_ok($repo) !== TRUE) { |
2505 |
|
$ret['errmsg'] = 'repository is invalid (' |
|
2506 |
|
. rg_repo_error() . ')'; |
|
|
2518 |
|
$ret['errmsg'] = rg_repo_error(); |
2507 |
2519 |
break; |
break; |
2508 |
2520 |
} |
} |
2509 |
2521 |
$ret['ri'] = rg_repo_info($db, 0, $ret['owner_ui']['uid'], $repo); |
$ret['ri'] = rg_repo_info($db, 0, $ret['owner_ui']['uid'], $repo); |
|
... |
... |
function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user, |
2622 |
2634 |
putenv('ROCKETGIT_IP=' . $ip); |
putenv('ROCKETGIT_IP=' . $ip); |
2623 |
2635 |
putenv('ROCKETGIT_ITIME=' . microtime(TRUE)); |
putenv('ROCKETGIT_ITIME=' . microtime(TRUE)); |
2624 |
2636 |
putenv('ROCKETGIT_HOST=' . $host); |
putenv('ROCKETGIT_HOST=' . $host); |
|
2637 |
|
putenv('ROCKETGIT_LOG_SID=' . $rg_log_sid); |
2625 |
2638 |
if (($ret['push'] == 1) && ($ret['push_allowed'] == 0)) { |
if (($ret['push'] == 1) && ($ret['push_allowed'] == 0)) { |
2626 |
2639 |
rg_log('DEBUG: We need to clone the namespace...'); |
rg_log('DEBUG: We need to clone the namespace...'); |
2627 |
2640 |
$namespace = 'rg_' . rg_id(8); |
$namespace = 'rg_' . rg_id(8); |
File inc/totp.inc.php changed (mode: 100644) (index 733c5cf..e3d9e15) |
... |
... |
function rg_totp_text($secret) |
185 |
185 |
/* |
/* |
186 |
186 |
* Cosmetic fixes for a login token row |
* Cosmetic fixes for a login token row |
187 |
187 |
*/ |
*/ |
188 |
|
function rg_totp_cosmetic(&$row) |
|
|
188 |
|
function rg_totp_cosmetic_row(&$row) |
189 |
189 |
{ |
{ |
190 |
190 |
if (isset($row['itime'])) |
if (isset($row['itime'])) |
191 |
191 |
$row['itime_nice'] = gmdate('Y-m-d H:i', $row['itime']); |
$row['itime_nice'] = gmdate('Y-m-d H:i', $row['itime']); |
|
... |
... |
function rg_totp_cosmetic(&$row) |
206 |
206 |
} |
} |
207 |
207 |
} |
} |
208 |
208 |
|
|
|
209 |
|
/* |
|
210 |
|
* Cosmetic fixes for a login token array |
|
211 |
|
*/ |
|
212 |
|
function rg_totp_cosmetic_list(&$a) |
|
213 |
|
{ |
|
214 |
|
foreach ($a as $junk => &$row) |
|
215 |
|
rg_totp_cosmetic_row($row); |
|
216 |
|
} |
|
217 |
|
|
209 |
218 |
/* |
/* |
210 |
219 |
* Cosmetic fixes for a scratch token row |
* Cosmetic fixes for a scratch token row |
211 |
220 |
*/ |
*/ |
212 |
|
function rg_totp_sc_cosmetic(&$row) |
|
|
221 |
|
function rg_totp_sc_cosmetic_row(&$row) |
213 |
222 |
{ |
{ |
214 |
223 |
if (isset($row['itime'])) |
if (isset($row['itime'])) |
215 |
224 |
$row['itime_nice'] = gmdate('Y-m-d H:i', $row['itime']); |
$row['itime_nice'] = gmdate('Y-m-d H:i', $row['itime']); |
216 |
225 |
} |
} |
217 |
226 |
|
|
|
227 |
|
/* |
|
228 |
|
* Cosmetic fixes for a login token array |
|
229 |
|
*/ |
|
230 |
|
function rg_totp_sc_cosmetic_list(&$a) |
|
231 |
|
{ |
|
232 |
|
foreach ($a as $junk => &$row) |
|
233 |
|
rg_totp_sc_cosmetic_row($row); |
|
234 |
|
} |
|
235 |
|
|
218 |
236 |
/* |
/* |
219 |
237 |
* Returns if the user is enrolled or not |
* Returns if the user is enrolled or not |
220 |
238 |
*/ |
*/ |
|
... |
... |
function rg_totp_set_last_use($db, $uid, $id, $tc, $ts) |
282 |
300 |
$key = 'user' . '::' . $uid . '::' . 'login_tokens' |
$key = 'user' . '::' . $uid . '::' . 'login_tokens' |
283 |
301 |
. '::' . 'device' . '::' . $id; |
. '::' . 'device' . '::' . $id; |
284 |
302 |
$a = array('used' => $ts, 'last_used_tc' => $tc, 'conf' => 't'); |
$a = array('used' => $ts, 'last_used_tc' => $tc, 'conf' => 't'); |
285 |
|
rg_totp_cosmetic($a); |
|
286 |
303 |
rg_cache_merge($key, $a, RG_SOCKET_NO_WAIT); |
rg_cache_merge($key, $a, RG_SOCKET_NO_WAIT); |
287 |
304 |
|
|
288 |
305 |
$ret = TRUE; |
$ret = TRUE; |
|
... |
... |
function rg_totp_device_list($db, $uid) |
327 |
344 |
$ret['list'] = array(); |
$ret['list'] = array(); |
328 |
345 |
while (($row = rg_sql_fetch_array($res))) { |
while (($row = rg_sql_fetch_array($res))) { |
329 |
346 |
$id = $row['id']; |
$id = $row['id']; |
330 |
|
|
|
331 |
|
rg_totp_cosmetic($row); |
|
332 |
|
|
|
333 |
347 |
$ret['list'][$id] = $row; |
$ret['list'][$id] = $row; |
334 |
348 |
} |
} |
335 |
349 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
336 |
350 |
|
|
337 |
351 |
rg_cache_set($key, $ret['list'], RG_SOCKET_NO_WAIT); |
rg_cache_set($key, $ret['list'], RG_SOCKET_NO_WAIT); |
|
352 |
|
|
338 |
353 |
$ret['ok'] = 1; |
$ret['ok'] = 1; |
339 |
354 |
break; |
break; |
340 |
355 |
} |
} |
|
356 |
|
if ($ret['ok'] == 1) |
|
357 |
|
rg_totp_cosmetic_list($ret['list']); |
341 |
358 |
|
|
342 |
359 |
rg_log_exit(); |
rg_log_exit(); |
343 |
360 |
rg_prof_end('totp_device_list'); |
rg_prof_end('totp_device_list'); |
|
... |
... |
function rg_totp_enroll($db, $uid, $name, $secret, $ip, $conf) |
446 |
463 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
447 |
464 |
|
|
448 |
465 |
$params['id'] = $row['id']; |
$params['id'] = $row['id']; |
449 |
|
rg_totp_cosmetic($params); |
|
450 |
466 |
$key = 'user' . '::' . $uid . '::' . 'login_tokens' |
$key = 'user' . '::' . $uid . '::' . 'login_tokens' |
451 |
467 |
. '::' . 'device' . '::' . $params['id']; |
. '::' . 'device' . '::' . $params['id']; |
452 |
468 |
rg_cache_set($key, $params, RG_SOCKET_NO_WAIT); |
rg_cache_set($key, $params, RG_SOCKET_NO_WAIT); |
|
... |
... |
function rg_totp_sc_list($db, $uid) |
836 |
852 |
$ret['ok'] = 1; |
$ret['ok'] = 1; |
837 |
853 |
break; |
break; |
838 |
854 |
} |
} |
|
855 |
|
if ($ret['ok'] == 1) |
|
856 |
|
rg_totp_sc_cosmetic_list($ret['list']); |
839 |
857 |
|
|
840 |
858 |
//rg_log_ml('DEBUG: sc_list ret[list]: ' . print_r($ret['list'], TRUE)); |
//rg_log_ml('DEBUG: sc_list ret[list]: ' . print_r($ret['list'], TRUE)); |
841 |
859 |
|
|
|
... |
... |
function rg_totp_sc_generate($db, $uid, $count) |
894 |
912 |
} |
} |
895 |
913 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
896 |
914 |
|
|
897 |
|
rg_totp_cosmetic($params); |
|
898 |
915 |
$key = 'user' . '::' . $uid . '::' . 'login_tokens' |
$key = 'user' . '::' . $uid . '::' . 'login_tokens' |
899 |
916 |
. '::' . 'sc' . '::' . $now; |
. '::' . 'sc' . '::' . $now; |
900 |
917 |
rg_cache_set($key, $ret['list'], RG_SOCKET_NO_WAIT); |
rg_cache_set($key, $ret['list'], RG_SOCKET_NO_WAIT); |
|
... |
... |
function rg_totp_sc_high_level($db, $rg, $paras) |
1192 |
1209 |
$_list[$itime] = array( |
$_list[$itime] = array( |
1193 |
1210 |
'itime' => $itime, |
'itime' => $itime, |
1194 |
1211 |
'sc_count' => 1); |
'sc_count' => 1); |
1195 |
|
rg_totp_sc_cosmetic($_list[$itime]); |
|
|
1212 |
|
rg_totp_sc_cosmetic_row($_list[$itime]); |
1196 |
1213 |
} else { |
} else { |
1197 |
1214 |
$_list[$itime]['sc_count']++; |
$_list[$itime]['sc_count']++; |
1198 |
1215 |
} |
} |
File inc/user.inc.php changed (mode: 100644) (index f3ab0bc..2bf94e1) |
... |
... |
$rg_user_functions = array( |
50 |
50 |
2002 => "rg_user_event_notify_user", |
2002 => "rg_user_event_notify_user", |
51 |
51 |
2005 => "rg_user_event_rename", |
2005 => "rg_user_event_rename", |
52 |
52 |
2006 => "rg_user_link_by_name", |
2006 => "rg_user_link_by_name", |
53 |
|
'ask-email-confirmation' => 'rg_user_event_ask_email_confirmation' |
|
|
53 |
|
'ask-email-confirmation' => 'rg_user_event_ask_email_confirmation', |
|
54 |
|
// new new style |
|
55 |
|
'user_event_new' => 'rg_user_event_new', |
|
56 |
|
'user_event_login' => 'rg_user_event_login', |
|
57 |
|
'user_event_notify_user' => 'rg_user_event_notify_user', |
|
58 |
|
'user_event_rename' => 'rg_user_event_rename', |
|
59 |
|
'user_link_by_name' => 'rg_user_link_by_name' |
54 |
60 |
); |
); |
55 |
61 |
rg_event_register_functions($rg_user_functions); |
rg_event_register_functions($rg_user_functions); |
56 |
62 |
|
|
|
... |
... |
function rg_user_event_new($db, $event) |
85 |
91 |
$event['op'] = 'new'; |
$event['op'] = 'new'; |
86 |
92 |
|
|
87 |
93 |
// create link by name |
// create link by name |
88 |
|
$ret[] = array_merge($event, array("category" => 2006, "prio" => 500)); |
|
|
94 |
|
$ret[] = array_merge($event, |
|
95 |
|
array('category' => 'user_link_by_name', 'prio' => 500)); |
89 |
96 |
|
|
90 |
97 |
// notify user |
// notify user |
91 |
|
$ret[] = array_merge($event, array("category" => 2002, "prio" => 200)); |
|
|
98 |
|
$ret[] = array_merge($event, |
|
99 |
|
array('category' => 'user_event_notify_user', 'prio' => 200)); |
92 |
100 |
|
|
93 |
101 |
return $ret; |
return $ret; |
94 |
102 |
} |
} |
|
... |
... |
function rg_user_event_rename($db, $event) |
138 |
146 |
|
|
139 |
147 |
$event['op'] = "rename"; |
$event['op'] = "rename"; |
140 |
148 |
// notify user |
// notify user |
141 |
|
$ret[] = array_merge($event, array("category" => 2002, "prio" => 100)); |
|
|
149 |
|
$ret[] = array_merge($event, |
|
150 |
|
array('category' => 'user_event_notify_user', 'prio' => 100)); |
142 |
151 |
// TODO: notify watchers |
// TODO: notify watchers |
143 |
152 |
|
|
144 |
153 |
return $ret; |
return $ret; |
|
... |
... |
function rg_user_rename($db, $ui, $new_name) |
484 |
493 |
|
|
485 |
494 |
// TODO: Check if all parameters are used. |
// TODO: Check if all parameters are used. |
486 |
495 |
$event = array( |
$event = array( |
487 |
|
'category' => 2005, |
|
|
496 |
|
'category' => 'user_event_rename', |
488 |
497 |
'prio' => 50, |
'prio' => 50, |
489 |
498 |
'ui' => $ui, |
'ui' => $ui, |
490 |
499 |
'rename_from' => $ui['username'], |
'rename_from' => $ui['username'], |
|
... |
... |
function rg_user_info($db, $uid, $user, $email) |
761 |
770 |
&& (isset($c['info'])) |
&& (isset($c['info'])) |
762 |
771 |
&& (isset($c['info']['itime']))) { |
&& (isset($c['info']['itime']))) { |
763 |
772 |
$ret = $c['info']; |
$ret = $c['info']; |
|
773 |
|
$ret['ok'] = 1; |
764 |
774 |
$ret['exists'] = 1; |
$ret['exists'] = 1; |
765 |
775 |
rg_user_cosmetic($ret); |
rg_user_cosmetic($ret); |
766 |
776 |
break; |
break; |
|
... |
... |
function rg_user_list_to_full_info($db, $list) |
2178 |
2188 |
* Please note that if the webserver was configured without an input filter |
* Please note that if the webserver was configured without an input filter |
2179 |
2189 |
* (like apache's SetInputFilter DEFLATE), this function will |
* (like apache's SetInputFilter DEFLATE), this function will |
2180 |
2190 |
* take care of it. |
* take care of it. |
|
2191 |
|
* TE is alway empty and CL>0 using the current nginx configuration. |
|
2192 |
|
* content_encoding may be gzip or empty. |
2181 |
2193 |
* Returns the uncompressed stream. |
* Returns the uncompressed stream. |
2182 |
2194 |
*/ |
*/ |
2183 |
2195 |
function rg_process_input($content_length, $content_encoding, &$err) |
function rg_process_input($content_length, $content_encoding, &$err) |
|
... |
... |
function rg_process_input($content_length, $content_encoding, &$err) |
2185 |
2197 |
$te = isset($_SERVER['HTTP_TRANSFER_ENCODING']) ? |
$te = isset($_SERVER['HTTP_TRANSFER_ENCODING']) ? |
2186 |
2198 |
$_SERVER['HTTP_TRANSFER_ENCODING'] : ''; |
$_SERVER['HTTP_TRANSFER_ENCODING'] : ''; |
2187 |
2199 |
|
|
2188 |
|
rg_log_enter('DEBUG: process_input: cl=' . $content_length |
|
|
2200 |
|
rg_log_enter('DEBUG: process_input: content_length=' . $content_length |
2189 |
2201 |
. ' content_encoding=' . $content_encoding |
. ' content_encoding=' . $content_encoding |
2190 |
2202 |
. ' te=' . $te); |
. ' te=' . $te); |
2191 |
2203 |
|
|
|
... |
... |
function rg_process_input($content_length, $content_encoding, &$err) |
2200 |
2212 |
. ' (' . $max_nice . ').' . "\n" |
. ' (' . $max_nice . ').' . "\n" |
2201 |
2213 |
. 'You may want to ask the admin to raise' |
. 'You may want to ask the admin to raise' |
2202 |
2214 |
. ' the limits (post_max_size).'; |
. ' the limits (post_max_size).'; |
|
2215 |
|
rg_internal_error($err); |
2203 |
2216 |
break; |
break; |
2204 |
2217 |
} |
} |
2205 |
2218 |
|
|
|
... |
... |
function rg_process_input($content_length, $content_encoding, &$err) |
2213 |
2226 |
break; |
break; |
2214 |
2227 |
} |
} |
2215 |
2228 |
|
|
|
2229 |
|
if (!empty($te)) { |
|
2230 |
|
$err = 'Unknown Transfer-Encoding: ' . $te; |
|
2231 |
|
rg_internal_error($err); |
|
2232 |
|
break; |
|
2233 |
|
} |
|
2234 |
|
|
2216 |
2235 |
// TODO: Sadly, we are not able to do the streaming! |
// TODO: Sadly, we are not able to do the streaming! |
2217 |
2236 |
// It is not available to php-fpm! |
// It is not available to php-fpm! |
2218 |
2237 |
|
|
|
... |
... |
function rg_process_input($content_length, $content_encoding, &$err) |
2225 |
2244 |
. ' \'git config http.postBuffer 200000000\'.' . "\n" |
. ' \'git config http.postBuffer 200000000\'.' . "\n" |
2226 |
2245 |
. ' The value must be bigger than what you' |
. ' The value must be bigger than what you' |
2227 |
2246 |
. ' want to push.'; |
. ' want to push.'; |
|
2247 |
|
rg_internal_error($err); |
2228 |
2248 |
break; |
break; |
2229 |
|
|
|
2230 |
|
rg_log('DEBUG: have to read data from php://stdin'); |
|
2231 |
|
$f = @fopen('php://stdin', 'rb'); |
|
2232 |
|
if ($f === FALSE) { |
|
2233 |
|
rg_log('Cannot open stdin!'); |
|
2234 |
|
break; |
|
2235 |
|
} |
|
2236 |
|
rg_log('DEBUG: start reading from php://stdin'); |
|
2237 |
|
while (1) { |
|
2238 |
|
$x = @fread($f, 65536); |
|
2239 |
|
rg_log('DEBUG: x='); |
|
2240 |
|
if ($x === FALSE) { |
|
2241 |
|
rg_log('DEBUG: cannot read!'); |
|
2242 |
|
break; |
|
2243 |
|
} |
|
2244 |
|
rg_log('DEBUG: BLOCK: ' . $x); |
|
2245 |
|
$ret = $x; |
|
2246 |
|
break; |
|
2247 |
|
} |
|
2248 |
|
fclose($f); |
|
2249 |
2249 |
} else { // Content-Length > 0 |
} else { // Content-Length > 0 |
2250 |
|
// TODO: we should just pass the file descriptor |
|
2251 |
|
// (with stream filter gzip if needed) |
|
2252 |
|
// and not buffer the whole content. |
|
2253 |
|
$ret = @file_get_contents('php://input'); |
|
2254 |
|
if (empty($ret)) { |
|
2255 |
|
$err = 'No input provided. Please let us know.'; |
|
2256 |
|
rg_internal_error($err); |
|
2257 |
|
$ret = FALSE; |
|
2258 |
|
break; |
|
2259 |
|
} |
|
2260 |
|
rg_log('DEBUG: php://input returned ' . strlen($ret) . ' bytes'); |
|
2261 |
2250 |
} |
} |
2262 |
2251 |
|
|
2263 |
|
rg_log('DEBUG: data_in[0-31]: ' . substr($ret, 0, 32)); |
|
2264 |
2252 |
if (strcmp($content_encoding, 'gzip') == 0) { |
if (strcmp($content_encoding, 'gzip') == 0) { |
2265 |
|
$ret = @gzdecode($ret); |
|
2266 |
|
if ($ret === FALSE) { |
|
2267 |
|
$err = 'Cannot decompress!'; |
|
2268 |
|
rg_internal_error($err); |
|
2269 |
|
break; |
|
2270 |
|
} |
|
2271 |
|
rg_log('DEBUG: after decompress[0-31]: ' |
|
2272 |
|
. substr($ret, 0, 32)); |
|
|
2253 |
|
// ok, we are dealing with it |
|
2254 |
|
} else if (!empty($content_encoding)) { |
|
2255 |
|
$err = 'Unknown Content-Encoding: ' . $content_encoding; |
|
2256 |
|
rg_internal_error($err); |
|
2257 |
|
break; |
2273 |
2258 |
} |
} |
2274 |
2259 |
|
|
|
2260 |
|
$ret = TRUE; |
2275 |
2261 |
break; |
break; |
2276 |
2262 |
} |
} |
2277 |
2263 |
|
|
|
2264 |
|
rg_log_exit(); |
2278 |
2265 |
return $ret; |
return $ret; |
2279 |
2266 |
} |
} |
2280 |
2267 |
|
|
|
2268 |
|
/* |
|
2269 |
|
* Helper for rg_user_http_git |
|
2270 |
|
*/ |
|
2271 |
|
function rg_user_http_git_cb_input($index, &$a, $stream) |
|
2272 |
|
{ |
|
2273 |
|
rg_log_enter('rg_user_http_git_cb_input'); |
|
2274 |
|
|
|
2275 |
|
switch ($stream) { |
|
2276 |
|
case 1: // stdout |
|
2277 |
|
echo $a['in_buf']; |
|
2278 |
|
$a['in_buf'] = ''; |
|
2279 |
|
break; |
|
2280 |
|
|
|
2281 |
|
case 2: // stderr |
|
2282 |
|
$a['cb_input_stderr_func']($a['err_buf']); |
|
2283 |
|
$a['err_buf'] = ''; |
|
2284 |
|
break; |
|
2285 |
|
} |
|
2286 |
|
|
|
2287 |
|
rg_log_exit(); |
|
2288 |
|
} |
|
2289 |
|
|
2281 |
2290 |
/* |
/* |
2282 |
2291 |
* Deals with push/fetch by HTTP(S) |
* Deals with push/fetch by HTTP(S) |
2283 |
2292 |
*/ |
*/ |
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
2459 |
2468 |
$_SERVER['HTTP_CONTENT_ENCODING'] : ''; |
$_SERVER['HTTP_CONTENT_ENCODING'] : ''; |
2460 |
2469 |
rg_log('DEBUG: cl=' . $content_length . ' ce=' . $content_encoding . '.'); |
rg_log('DEBUG: cl=' . $content_length . ' ce=' . $content_encoding . '.'); |
2461 |
2470 |
|
|
|
2471 |
|
$input_fd = @fopen('php://input', 'r'); |
|
2472 |
|
if ($input_fd === FALSE) { |
|
2473 |
|
$err = 'cannot open php://input: '. rg_php_err(); |
|
2474 |
|
rg_internal_error($err); |
|
2475 |
|
break; |
|
2476 |
|
} |
|
2477 |
|
|
|
2478 |
|
$cmd = array( |
|
2479 |
|
'cmds' => array( |
|
2480 |
|
'cmd1' => array( |
|
2481 |
|
'cb_output' => 'rg_exec2_helper_read_fd', |
|
2482 |
|
'cb_output_fd' => $input_fd, |
|
2483 |
|
//TODO 'out_buf_done' => 0, |
|
2484 |
|
'cb_input' => 'rg_user_http_git_cb_input' |
|
2485 |
|
) |
|
2486 |
|
) |
|
2487 |
|
); |
|
2488 |
|
|
|
2489 |
|
if (strcasecmp($content_encoding, 'gzip') == 0) |
|
2490 |
|
$cmd['cmds']['cmd1']['out_buf_helper'] = 'rg_exec2_helper_gzip_in'; |
|
2491 |
|
|
2462 |
2492 |
if (strcmp($file, 'info/refs') == 0) { |
if (strcmp($file, 'info/refs') == 0) { |
2463 |
2493 |
rg_log('DEBUG: info/refs'); |
rg_log('DEBUG: info/refs'); |
2464 |
2494 |
// TODO: we should allow this only if the connecting |
// TODO: we should allow this only if the connecting |
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
2469 |
2499 |
echo rg_git_pack('# service=' . $service . "\n"); |
echo rg_git_pack('# service=' . $service . "\n"); |
2470 |
2500 |
echo rg_git_flush(); |
echo rg_git_flush(); |
2471 |
2501 |
|
|
2472 |
|
$run = '/usr/libexec/git-core/' . $service |
|
|
2502 |
|
$cmd['cmds']['cmd1']['cmd'] = '/usr/libexec/git-core/' . $service |
2473 |
2503 |
. ' --stateless-rpc --advertise-refs' |
. ' --stateless-rpc --advertise-refs' |
2474 |
2504 |
. ' ' . escapeshellarg($repo_path); |
. ' ' . escapeshellarg($repo_path); |
2475 |
|
$e = rg_exec($run, '', 0 /*use stdin*/, 'rg_echo', 'rg_git_band_2'); |
|
2476 |
|
if ($e['code'] != 0) |
|
2477 |
|
rg_log('Error executing command: ' . $e['errmsg']); |
|
|
2505 |
|
$cmd['cmds']['cmd1']['cb_input_stderr_func'] = 'rg_git_band_2'; |
|
2506 |
|
$e = rg_exec2($cmd); |
|
2507 |
|
rg_log_ml('XDEBUG: e: ' . print_r($e, TRUE)); |
|
2508 |
|
if (!isset($e['code'])) |
|
2509 |
|
exit(1); |
|
2510 |
|
if ($e['ok'] != 1) { |
|
2511 |
|
$err = 'error executing command: ' . $e['errmsg']; |
|
2512 |
|
rg_internal_error($err); |
|
2513 |
|
break; |
|
2514 |
|
} |
2478 |
2515 |
rg_log('Done!'); |
rg_log('Done!'); |
2479 |
|
} else if (strcasecmp($rg['ct'], 'application/x-git-upload-pack-request') == 0) { |
|
|
2516 |
|
break; |
|
2517 |
|
} |
|
2518 |
|
|
|
2519 |
|
if (strcasecmp($rg['ct'], 'application/x-git-upload-pack-request') == 0) { |
2480 |
2520 |
rg_log('DEBUG: git-upload-pack...'); |
rg_log('DEBUG: git-upload-pack...'); |
2481 |
2521 |
|
|
2482 |
2522 |
header('Content-Type: application/x-git-upload-pack-result'); |
header('Content-Type: application/x-git-upload-pack-result'); |
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
2498 |
2538 |
putenv('ROCKETGIT_SHOW_INFO=0'); |
putenv('ROCKETGIT_SHOW_INFO=0'); |
2499 |
2539 |
*/ |
*/ |
2500 |
2540 |
|
|
2501 |
|
$data_in = rg_process_input($content_length, |
|
2502 |
|
$content_encoding, $err); |
|
2503 |
|
if ($data_in === FALSE) |
|
|
2541 |
|
$r = rg_process_input($content_length, $content_encoding, $err); |
|
2542 |
|
if ($r === FALSE) |
2504 |
2543 |
break; |
break; |
2505 |
2544 |
|
|
2506 |
|
$run = '/usr/libexec/git-core/git-upload-pack' |
|
|
2545 |
|
$cmd['cmds']['cmd1']['cmd'] = '/usr/libexec/git-core/git-upload-pack' |
2507 |
2546 |
. ' --stateless-rpc' |
. ' --stateless-rpc' |
2508 |
2547 |
. ' ' . escapeshellarg($repo_path); |
. ' ' . escapeshellarg($repo_path); |
2509 |
|
$e = rg_exec($run, $data_in, 0 /*use stdin*/, |
|
2510 |
|
'rg_echo', 'rg_git_band_2'); |
|
2511 |
|
if ($e['code'] != 0) |
|
2512 |
|
rg_log('Error executing command: ' . $e['errmsg']); |
|
|
2548 |
|
$cmd['cmds']['cmd1']['cb_input_stderr_func'] = 'rg_git_band_2'; |
|
2549 |
|
$e = rg_exec2($cmd); |
|
2550 |
|
if ($e['ok'] != 1) { |
|
2551 |
|
$err = 'error executing command: ' . $e['errmsg']; |
|
2552 |
|
rg_internal_error($err); |
|
2553 |
|
break; |
|
2554 |
|
} |
|
2555 |
|
|
2513 |
2556 |
rg_log('Done!'); |
rg_log('Done!'); |
2514 |
2557 |
} else if (strcasecmp($rg['ct'], 'application/x-git-receive-pack-request') == 0) { |
} else if (strcasecmp($rg['ct'], 'application/x-git-receive-pack-request') == 0) { |
2515 |
2558 |
rg_log('DEBUG: git-receive-pack...'); |
rg_log('DEBUG: git-receive-pack...'); |
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
2527 |
2570 |
. ' instead of ' . $host . '.'); |
. ' instead of ' . $host . '.'); |
2528 |
2571 |
putenv('ROCKETGIT_SHOW_INFO=0'); |
putenv('ROCKETGIT_SHOW_INFO=0'); |
2529 |
2572 |
|
|
2530 |
|
$data_in = rg_process_input($content_length, |
|
2531 |
|
$content_encoding, $err); |
|
2532 |
|
if ($data_in === FALSE) { |
|
|
2573 |
|
$r = rg_process_input($content_length, $content_encoding, $err); |
|
2574 |
|
if ($r === FALSE) { |
2533 |
2575 |
// We have to send '200'. |
// We have to send '200'. |
2534 |
2576 |
// Else, we cannot send the hints |
// Else, we cannot send the hints |
2535 |
2577 |
header($protocol . ' 200 Service unavailable'); |
header($protocol . ' 200 Service unavailable'); |
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
2538 |
2580 |
break; |
break; |
2539 |
2581 |
} |
} |
2540 |
2582 |
|
|
2541 |
|
$run = '/usr/libexec/git-core/git-receive-pack' |
|
|
2583 |
|
$cmd['cmds']['cmd1']['cmd'] = '/usr/libexec/git-core/git-receive-pack' |
2542 |
2584 |
. ' --stateless-rpc' |
. ' --stateless-rpc' |
2543 |
2585 |
. ' ' . escapeshellarg($repo_path); |
. ' ' . escapeshellarg($repo_path); |
2544 |
|
$e = rg_exec($run, $data_in, 0 /*use stdin*/, 'rg_echo', 'rg_echo'); |
|
2545 |
|
if ($e['code'] != 0) |
|
2546 |
|
rg_log('Error executing command: ' . $e['errmsg']); |
|
|
2586 |
|
|
|
2587 |
|
$cmd['cmds']['cmd1']['cb_input_stderr_func'] = 'rg_echo'; |
|
2588 |
|
$e = rg_exec2($cmd); |
|
2589 |
|
if ($e['ok'] != 1) { |
|
2590 |
|
$err = 'error executing command: ' . $e['errmsg']; |
|
2591 |
|
rg_internal_error($err); |
|
2592 |
|
break; |
|
2593 |
|
} |
|
2594 |
|
|
2547 |
2595 |
rg_log('Done!'); |
rg_log('Done!'); |
2548 |
2596 |
} else { |
} else { |
2549 |
2597 |
rg_log('Unknown service!'); |
rg_log('Unknown service!'); |
File inc/util.inc.php changed (mode: 100644) (index b6e07f1..91c9689) |
... |
... |
define('RG_SOCKET_NO_WAIT', 0x01); |
9 |
9 |
|
|
10 |
10 |
if (!isset($rg_util_debug)) |
if (!isset($rg_util_debug)) |
11 |
11 |
$rg_util_debug = FALSE; |
$rg_util_debug = FALSE; |
|
12 |
|
if (strcmp(getenv('ROCKETGIT_UTIL_DEBUG'), '1') == 0) |
|
13 |
|
$rg_util_debug = TRUE; |
12 |
14 |
|
|
13 |
15 |
$rg_util_error = ""; |
$rg_util_error = ""; |
14 |
16 |
|
|
|
... |
... |
function rg_mega2bytes($s) |
105 |
107 |
*/ |
*/ |
106 |
108 |
function rg_random_bytes($len) |
function rg_random_bytes($len) |
107 |
109 |
{ |
{ |
|
110 |
|
static $buf = ''; |
|
111 |
|
static $buf_len = 0; |
|
112 |
|
|
108 |
113 |
rg_prof_start('random_bytes'); |
rg_prof_start('random_bytes'); |
109 |
114 |
|
|
110 |
115 |
$ret = FALSE; |
$ret = FALSE; |
111 |
116 |
|
|
112 |
|
$f = @fopen('/dev/urandom', 'r'); |
|
113 |
|
if ($f !== NULL) { |
|
114 |
|
$ret = @fread($f, $len); |
|
|
117 |
|
if ($len > $buf_len) { |
|
118 |
|
$f = @fopen('/dev/urandom', 'r'); |
|
119 |
|
if ($f === NULL) |
|
120 |
|
rg_fatal('cannot open urandom'); |
|
121 |
|
|
|
122 |
|
while ($len > $buf_len) { |
|
123 |
|
$r = @fread($f, max(512, $len)); |
|
124 |
|
if ($r === FALSE) |
|
125 |
|
rg_fatal('cannot read from urandom'); |
|
126 |
|
|
|
127 |
|
$buf .= $r; |
|
128 |
|
$buf_len += strlen($r); |
|
129 |
|
} |
|
130 |
|
|
115 |
131 |
fclose($f); |
fclose($f); |
116 |
132 |
} |
} |
117 |
133 |
|
|
118 |
|
if ($ret === FALSE) { |
|
119 |
|
$ret = ''; |
|
120 |
|
for ($i = 0; $i < $len; $i++) |
|
121 |
|
$ret .= rand(0, 255); |
|
122 |
|
} |
|
|
134 |
|
$ret = substr($buf, $len); |
|
135 |
|
$buf = substr($buf, $len); |
|
136 |
|
$buf_len -= $len; |
123 |
137 |
|
|
124 |
138 |
rg_prof_end('random_bytes'); |
rg_prof_end('random_bytes'); |
125 |
139 |
return $ret; |
return $ret; |
|
... |
... |
function rg_ok($msg) |
1121 |
1135 |
return rg_template("ok.html", $x, TRUE /* xss */); |
return rg_template("ok.html", $x, TRUE /* xss */); |
1122 |
1136 |
} |
} |
1123 |
1137 |
|
|
|
1138 |
|
/* |
|
1139 |
|
* Helper for reading input from a fd for rg_exec2. |
|
1140 |
|
* Used as a 'cb_output' function. |
|
1141 |
|
*/ |
|
1142 |
|
function rg_exec2_helper_read_fd($index, &$info) |
|
1143 |
|
{ |
|
1144 |
|
$ret = -1; |
|
1145 |
|
while (1) { |
|
1146 |
|
$r = @fread($info['cb_output_fd'], 16 * 4096); |
|
1147 |
|
if ($r === FALSE) { |
|
1148 |
|
$err = 'cannot read from cb_output_fd: ' . rg_php_err(); |
|
1149 |
|
rg_internal_error($err); |
|
1150 |
|
break; |
|
1151 |
|
} |
|
1152 |
|
|
|
1153 |
|
$len = strlen($r); |
|
1154 |
|
if ($len === 0) { |
|
1155 |
|
fclose($info['cb_output_fd']); |
|
1156 |
|
$ret = 0; |
|
1157 |
|
break; |
|
1158 |
|
} |
|
1159 |
|
|
|
1160 |
|
$info['out_buf'] .= $r; |
|
1161 |
|
$ret = $len; |
|
1162 |
|
break; |
|
1163 |
|
} |
|
1164 |
|
|
|
1165 |
|
return $ret; |
|
1166 |
|
} |
|
1167 |
|
|
|
1168 |
|
/* |
|
1169 |
|
* Helper for decompressing input for rg_exec2. |
|
1170 |
|
* On error, it returns FALSE and $err contains the error message. |
|
1171 |
|
*/ |
|
1172 |
|
function rg_exec2_helper_gzip_in(&$info) |
|
1173 |
|
{ |
|
1174 |
|
global $rg_util_debug; |
|
1175 |
|
|
|
1176 |
|
$rg_util_debug && |
|
1177 |
|
rg_log('exec2_helper_gzip_in...'); |
|
1178 |
|
|
|
1179 |
|
if (empty($info['out_buf'])) |
|
1180 |
|
return TRUE; |
|
1181 |
|
|
|
1182 |
|
if (!isset($info['gzip_in_ctx'])) { |
|
1183 |
|
$info['gzip_in_ctx'] = inflate_init(ZLIB_ENCODING_GZIP); |
|
1184 |
|
if ($info['gzip_in_ctx'] === FALSE) { |
|
1185 |
|
$err = 'cannot initialize context'; |
|
1186 |
|
return FALSE; |
|
1187 |
|
} |
|
1188 |
|
|
|
1189 |
|
$info['gzip_in_bytes'] = 0; |
|
1190 |
|
} |
|
1191 |
|
|
|
1192 |
|
$do_exit = FALSE; |
|
1193 |
|
do { |
|
1194 |
|
$rg_util_debug && |
|
1195 |
|
rg_log(' calling inflate_add with buf[0-31]=' . substr($info['out_buf'], 0, 32) . (!empty($info['out_buf']) ? '' : ' and ZLIB_FINISH')); |
|
1196 |
|
if (!empty($info['out_buf'])) |
|
1197 |
|
$r = inflate_add($info['gzip_in_ctx'], $info['out_buf']); |
|
1198 |
|
else |
|
1199 |
|
$r = inflate_add($info['gzip_in_ctx'], $info['out_buf'], ZLIB_FINISH); |
|
1200 |
|
if ($r === FALSE) { |
|
1201 |
|
$err = 'error in decompression: ' . rg_php_err(); |
|
1202 |
|
rg_internal_error($err); |
|
1203 |
|
return FALSE; |
|
1204 |
|
} |
|
1205 |
|
|
|
1206 |
|
$s = inflate_get_status($info['gzip_in_ctx']); |
|
1207 |
|
if ($s === ZLIB_STREAM_END) { |
|
1208 |
|
$rg_util_debug && rg_log(' Got ZLIB_STREAM_END; set out_buf_done to 1 and do_exit to TRUE'); |
|
1209 |
|
$info['out_buf'] = ''; // because zlib may finish before consuming all input |
|
1210 |
|
$info['out_buf_done'] = 1; |
|
1211 |
|
unset($info['gzip_in_ctx']); |
|
1212 |
|
$do_exit = TRUE; |
|
1213 |
|
} else if ($s === ZLIB_OK) { |
|
1214 |
|
$rg_util_debug && rg_log(' Got ZLIB_OK'); |
|
1215 |
|
|
|
1216 |
|
$rl = inflate_get_read_len($info['gzip_in_ctx']); |
|
1217 |
|
if ($rl === FALSE) { |
|
1218 |
|
$err = 'cannot retrieve read_len'; |
|
1219 |
|
return FALSE; |
|
1220 |
|
} |
|
1221 |
|
$rg_util_debug && |
|
1222 |
|
rg_log(' gzip_in_bytes=' . $info['gzip_in_bytes'] . ' read_len=' . $rl); |
|
1223 |
|
|
|
1224 |
|
$diff = $rl - $info['gzip_in_bytes']; |
|
1225 |
|
$info['gzip_in_bytes'] = $rl; |
|
1226 |
|
$info['out_buf'] = substr($info['out_buf'], $diff); |
|
1227 |
|
|
|
1228 |
|
if (!empty($r)) |
|
1229 |
|
$do_exit = TRUE; |
|
1230 |
|
} else { |
|
1231 |
|
unset($info['gzip_in_ctx']); |
|
1232 |
|
if ($s === FALSE) |
|
1233 |
|
rg_log(' status is FALSE'); |
|
1234 |
|
else if ($s === ZLIB_BUF_ERROR) |
|
1235 |
|
rg_log(' status is ZLIB_BUF_ERROR'); |
|
1236 |
|
else |
|
1237 |
|
rg_log(' status is unknown [' . $s . ']'); |
|
1238 |
|
return FALSE; |
|
1239 |
|
} |
|
1240 |
|
|
|
1241 |
|
$rg_util_debug && |
|
1242 |
|
rg_log(' decompression produced: [' . $r . '] out_buf=' . $info['out_buf']); |
|
1243 |
|
} while (!$do_exit); |
|
1244 |
|
|
|
1245 |
|
$info['out_buf_real'] .= $r; |
|
1246 |
|
|
|
1247 |
|
return TRUE; |
|
1248 |
|
} |
|
1249 |
|
|
1124 |
1250 |
/* |
/* |
1125 |
1251 |
* Helper for rg_exec to init the structure |
* Helper for rg_exec to init the structure |
1126 |
1252 |
*/ |
*/ |
|
... |
... |
function rg_exec2_helper_init(&$info) |
1132 |
1258 |
$info['last_failure'] = 0; |
$info['last_failure'] = 0; |
1133 |
1259 |
if (!isset($info['out_buf'])) |
if (!isset($info['out_buf'])) |
1134 |
1260 |
$info['out_buf'] = ''; |
$info['out_buf'] = ''; |
|
1261 |
|
$info['out_buf_real'] = ''; |
1135 |
1262 |
$info['in_buf'] = ''; |
$info['in_buf'] = ''; |
1136 |
1263 |
$info['err_buf'] = ''; |
$info['err_buf'] = ''; |
1137 |
1264 |
$info['done'] = FALSE; |
$info['done'] = FALSE; |
|
... |
... |
function rg_exec2_helper_init(&$info) |
1145 |
1272 |
else |
else |
1146 |
1273 |
$info['input_fd_done'] = 1; |
$info['input_fd_done'] = 1; |
1147 |
1274 |
|
|
1148 |
|
if (!isset($info['output_done'])) |
|
1149 |
|
$info['output_done'] = 1; |
|
|
1275 |
|
if (isset($info['cb_output'])) |
|
1276 |
|
$info['cb_output_done'] = 0; |
|
1277 |
|
else |
|
1278 |
|
$info['cb_output_done'] = 1; |
|
1279 |
|
|
|
1280 |
|
// TODO: what this is doing, rename it to something better |
|
1281 |
|
if (!isset($info['out_buf_done'])) |
|
1282 |
|
$info['out_buf_done'] = 1; |
|
1283 |
|
|
|
1284 |
|
// m2p = 'me' to 'program' |
|
1285 |
|
$info['m2p_bytes'] = 0; |
|
1286 |
|
|
|
1287 |
|
// w2m = 'web' to 'me' |
|
1288 |
|
$info['w2m_bytes'] = 0; |
1150 |
1289 |
} |
} |
1151 |
1290 |
|
|
1152 |
1291 |
/* |
/* |
|
... |
... |
function rg_exec2_helper_close_stream($index, $fd, &$info, $stream) |
1182 |
1321 |
rg_log_exit(); |
rg_log_exit(); |
1183 |
1322 |
} |
} |
1184 |
1323 |
|
|
|
1324 |
|
/* |
|
1325 |
|
* Tries to procude data to be sent to the peer process |
|
1326 |
|
*/ |
|
1327 |
|
function rg_exec2_helper_populate_out_buf($index, &$info) |
|
1328 |
|
{ |
|
1329 |
|
global $rg_util_debug; |
|
1330 |
|
|
|
1331 |
|
$rg_util_debug && |
|
1332 |
|
rg_log_enter($index . ': exec2_helper_populate_out_buf'); |
|
1333 |
|
|
|
1334 |
|
// cb_output can populate $info['out_buf'] |
|
1335 |
|
if ($info['cb_output_done'] == 0) { |
|
1336 |
|
$r = $info['cb_output']($index, $info); |
|
1337 |
|
if ($r == -1) { |
|
1338 |
|
// TODO |
|
1339 |
|
} else if ($r == 0) { |
|
1340 |
|
$info['cb_output_done'] = 1; |
|
1341 |
|
} else { |
|
1342 |
|
$info['w2m_bytes'] += $r; |
|
1343 |
|
} |
|
1344 |
|
} |
|
1345 |
|
|
|
1346 |
|
if (!isset($info['out_buf_helper'])) { |
|
1347 |
|
$info['out_buf_real'] .= $info['out_buf']; |
|
1348 |
|
$info['out_buf'] = ''; |
|
1349 |
|
} else { |
|
1350 |
|
$info['out_buf_helper']($info); |
|
1351 |
|
} |
|
1352 |
|
|
|
1353 |
|
rg_log_exit(); |
|
1354 |
|
} |
|
1355 |
|
|
1185 |
1356 |
/* |
/* |
1186 |
1357 |
* This will replace rg_exec function |
* This will replace rg_exec function |
1187 |
1358 |
* Returns the array of the commands with the last status. |
* Returns the array of the commands with the last status. |
|
... |
... |
function rg_exec2($a) |
1190 |
1361 |
{ |
{ |
1191 |
1362 |
global $rg_util_debug; |
global $rg_util_debug; |
1192 |
1363 |
|
|
1193 |
|
rg_prof_start('exec2'); |
|
1194 |
|
rg_log_enter('exec2'); |
|
|
1364 |
|
$_id = ''; $_add = ''; |
|
1365 |
|
foreach ($a['cmds'] as $_junk => $_i) { |
|
1366 |
|
$_id .= $_add . '[' . $_i['cmd'] . ']'; |
|
1367 |
|
$_add = ' '; |
|
1368 |
|
} |
|
1369 |
|
|
|
1370 |
|
rg_prof_start('exec2 ' . $_id); |
|
1371 |
|
rg_log_enter('exec2 ' . $_id); |
1195 |
1372 |
|
|
1196 |
1373 |
$rg_util_debug && |
$rg_util_debug && |
1197 |
1374 |
rg_log_ml('DEBUG: a: ' . print_r($a, TRUE)); |
rg_log_ml('DEBUG: a: ' . print_r($a, TRUE)); |
|
... |
... |
function rg_exec2($a) |
1319 |
1496 |
|
|
1320 |
1497 |
$info['stopped'] = FALSE; |
$info['stopped'] = FALSE; |
1321 |
1498 |
$info['started'] = time(); |
$info['started'] = time(); |
1322 |
|
|
|
1323 |
|
// cb_output can populate $info['out_buf'] |
|
1324 |
|
if (isset($info['cb_output'])) { |
|
1325 |
|
$rg_util_debug && |
|
1326 |
|
rg_log($index . ' DEBUG: calling cb_output (first)...'); |
|
1327 |
|
$info['cb_output']($index, $info); |
|
1328 |
|
} |
|
1329 |
1499 |
} |
} |
1330 |
1500 |
|
|
1331 |
1501 |
if ($info['stopped']) { |
if ($info['stopped']) { |
|
... |
... |
function rg_exec2($a) |
1334 |
1504 |
continue; |
continue; |
1335 |
1505 |
} |
} |
1336 |
1506 |
|
|
|
1507 |
|
rg_exec2_helper_populate_out_buf($index, $info); |
|
1508 |
|
|
1337 |
1509 |
// Check idle |
// Check idle |
1338 |
1510 |
if (isset($info['cb_idle']) |
if (isset($info['cb_idle']) |
1339 |
1511 |
&& ($info['idle_time'] > 0) |
&& ($info['idle_time'] > 0) |
|
... |
... |
function rg_exec2($a) |
1346 |
1518 |
$info['cb_idle']($index, $info); |
$info['cb_idle']($index, $info); |
1347 |
1519 |
} |
} |
1348 |
1520 |
|
|
1349 |
|
if (!empty($info['out_buf'])) { |
|
|
1521 |
|
if (!empty($info['out_buf_real'])) { |
1350 |
1522 |
$rg_util_debug && |
$rg_util_debug && |
1351 |
|
rg_log($index . ' DEBUG: out_buf not empty =>' |
|
|
1523 |
|
rg_log($index . ' DEBUG: out_buf_real not empty =>' |
1352 |
1524 |
. ' enable write notification!'); |
. ' enable write notification!'); |
1353 |
1525 |
|
|
1354 |
1526 |
$wx[] = $info['pipes'][0]; |
$wx[] = $info['pipes'][0]; |
1355 |
1527 |
} else if (($info['input_fd_done'] == 1) |
} else if (($info['input_fd_done'] == 1) |
1356 |
|
&& ($info['output_done'] == 1) |
|
|
1528 |
|
&& ($info['out_buf_done'] == 1) |
1357 |
1529 |
&& (isset($info['pipes'][0]))) { |
&& (isset($info['pipes'][0]))) { |
1358 |
1530 |
$rg_util_debug && |
$rg_util_debug && |
1359 |
|
rg_log($index . ' DEBUG: empty(out_buf)' |
|
|
1531 |
|
rg_log($index . ' DEBUG: empty(out_buf_real)' |
1360 |
1532 |
. ' && input_fd_done == 1' |
. ' && input_fd_done == 1' |
1361 |
|
. ' && output_done == 1' |
|
|
1533 |
|
. ' && out_buf_done == 1' |
1362 |
1534 |
. ': close output ' . $info['pipes'][0]); |
. ': close output ' . $info['pipes'][0]); |
1363 |
1535 |
rg_exec2_helper_close_stream($index, |
rg_exec2_helper_close_stream($index, |
1364 |
1536 |
$info['pipes'][0], $info, 0); |
$info['pipes'][0], $info, 0); |
|
... |
... |
function rg_exec2($a) |
1426 |
1598 |
|
|
1427 |
1599 |
$info = &$ret['cmds'][$index]; |
$info = &$ret['cmds'][$index]; |
1428 |
1600 |
|
|
1429 |
|
$rg_util_debug && |
|
1430 |
|
rg_log($index . ' DEBUG: out_buf before cb: ' . $info['out_buf']); |
|
|
1601 |
|
rg_exec2_helper_populate_out_buf($index, $info); |
1431 |
1602 |
|
|
1432 |
|
// cb_output can populate $info['out_buf'] |
|
1433 |
|
if (isset($info['cb_output'])) { |
|
|
1603 |
|
if (empty($info['out_buf_real'])) { |
1434 |
1604 |
$rg_util_debug && |
$rg_util_debug && |
1435 |
|
rg_log($index . ' DEBUG: calling cb_output...'); |
|
1436 |
|
$info['cb_output']($index, $info); |
|
1437 |
|
} |
|
1438 |
|
|
|
1439 |
|
if (empty($info['out_buf'])) { |
|
1440 |
|
$rg_util_debug && |
|
1441 |
|
rg_log_ml($index . ' DEBUG: out_buf is empty!' |
|
|
1605 |
|
rg_log_ml($index . ' DEBUG: out_buf_real is empty!' |
1442 |
1606 |
. ' info: ' . print_r($info, TRUE)); |
. ' info: ' . print_r($info, TRUE)); |
1443 |
1607 |
continue; |
continue; |
1444 |
1608 |
} |
} |
1445 |
1609 |
|
|
1446 |
|
$rg_util_debug && |
|
1447 |
|
rg_log($index . ' DEBUG: send: [' . $info['out_buf'] . ']'); |
|
1448 |
|
$r = @fwrite($fd, $info['out_buf']); |
|
|
1610 |
|
//$rg_util_debug && |
|
1611 |
|
//rg_log($index . ' DEBUG: sending: [' . $info['out_buf_real'] . ']'); |
|
1612 |
|
$r = @fwrite($fd, $info['out_buf_real']); |
1449 |
1613 |
if ($r === FALSE) { |
if ($r === FALSE) { |
1450 |
1614 |
$info['last_errmsg'] = 'cannot write'; |
$info['last_errmsg'] = 'cannot write'; |
1451 |
1615 |
if (isset($info['cb_error'])) |
if (isset($info['cb_error'])) |
|
... |
... |
function rg_exec2($a) |
1455 |
1619 |
$info['wait_for_stop'] = TRUE; |
$info['wait_for_stop'] = TRUE; |
1456 |
1620 |
continue; |
continue; |
1457 |
1621 |
} |
} |
1458 |
|
$rg_util_debug && |
|
1459 |
|
rg_log($index . ' DEBUG: fwrite returned ' . $r . '.'); |
|
1460 |
|
$info['out_buf'] = substr($info['out_buf'], $r); |
|
|
1622 |
|
$info['out_buf_real'] = substr($info['out_buf_real'], $r); |
|
1623 |
|
$info['m2p_bytes'] += $r; |
1461 |
1624 |
} |
} |
1462 |
1625 |
|
|
1463 |
1626 |
foreach ($revents as $fd) { |
foreach ($revents as $fd) { |
|
... |
... |
function rg_exec2($a) |
1516 |
1679 |
} |
} |
1517 |
1680 |
|
|
1518 |
1681 |
rg_log_exit(); |
rg_log_exit(); |
1519 |
|
rg_prof_end('exec2'); |
|
|
1682 |
|
rg_prof_end('exec2 ' . $_id); |
1520 |
1683 |
return $ret; |
return $ret; |
1521 |
1684 |
} |
} |
1522 |
1685 |
|
|
|
... |
... |
function rg_exec($cmd, $input, $cb_stdin, $cb_stdout, $cb_stderr) |
1570 |
1733 |
if ($cb_stdin === 0) { |
if ($cb_stdin === 0) { |
1571 |
1734 |
$a['cmds']['cmd1']['input_fd'] = @fopen('php://stdin', 'rb'); |
$a['cmds']['cmd1']['input_fd'] = @fopen('php://stdin', 'rb'); |
1572 |
1735 |
if ($a['cmds']['cmd1']['input_fd'] === FALSE) { |
if ($a['cmds']['cmd1']['input_fd'] === FALSE) { |
1573 |
|
$ret['errmsg'] = 'cannot open stdin'; |
|
|
1736 |
|
$ret['errmsg'] = 'cannot open stdin: ' . rg_php_err(); |
1574 |
1737 |
break; |
break; |
1575 |
1738 |
} |
} |
1576 |
1739 |
} else if ($cb_stdin !== FALSE) { |
} else if ($cb_stdin !== FALSE) { |
|
... |
... |
function rg_unserialize($s) |
2453 |
2616 |
$r = @json_decode($s, TRUE); |
$r = @json_decode($s, TRUE); |
2454 |
2617 |
if ($r !== NULL) |
if ($r !== NULL) |
2455 |
2618 |
return $r; |
return $r; |
|
2619 |
|
|
|
2620 |
|
$m = 'cannot decode json: ' . json_last_error_msg(); |
|
2621 |
|
rg_internal_error($m); |
|
2622 |
|
rg_util_set_error($m); |
|
2623 |
|
return FALSE; |
2456 |
2624 |
} |
} |
2457 |
2625 |
|
|
2458 |
|
if (strncmp($s, 'a:', 2) == 0) { |
|
|
2626 |
|
$x = substr($s, 1, 1); |
|
2627 |
|
if (strcmp($x, ':') == 0) { |
2459 |
2628 |
$r = @unserialize($s); |
$r = @unserialize($s); |
2460 |
2629 |
if ($r !== FALSE) |
if ($r !== FALSE) |
2461 |
2630 |
return $r; |
return $r; |
2462 |
2631 |
} |
} |
2463 |
2632 |
|
|
2464 |
|
return FALSE; |
|
|
2633 |
|
if (strcmp($s, '[]') == 0) |
|
2634 |
|
return array(); |
|
2635 |
|
|
|
2636 |
|
if (strncmp($s, '"', 1) == 0) |
|
2637 |
|
return substr($s, 1, -1); |
|
2638 |
|
|
|
2639 |
|
return $s; |
2465 |
2640 |
} |
} |
2466 |
2641 |
|
|
2467 |
2642 |
/* |
/* |
|
... |
... |
function rg_unserialize($s) |
2469 |
2644 |
*/ |
*/ |
2470 |
2645 |
function rg_serialize($a) |
function rg_serialize($a) |
2471 |
2646 |
{ |
{ |
2472 |
|
return @json_encode($a, TRUE); |
|
|
2647 |
|
if (!is_array($a)) |
|
2648 |
|
return $a; |
|
2649 |
|
|
|
2650 |
|
$r = @json_encode($a, TRUE); |
|
2651 |
|
if ($r === FALSE) { |
|
2652 |
|
$m = 'error encoding json: ' . json_last_error_msg(); |
|
2653 |
|
rg_internal_error($m); |
|
2654 |
|
rg_util_set_error($m); |
|
2655 |
|
return FALSE; |
|
2656 |
|
} |
|
2657 |
|
|
|
2658 |
|
return $r; |
2473 |
2659 |
} |
} |
|
2660 |
|
|
|
2661 |
|
/* |
|
2662 |
|
* Compress data for web |
|
2663 |
|
*/ |
|
2664 |
|
function rg_gzencode($c, &$orig_len, &$comp_len) |
|
2665 |
|
{ |
|
2666 |
|
rg_prof_start('gzencode'); |
|
2667 |
|
$ret = @gzencode($c, 6); |
|
2668 |
|
if ($ret === FALSE) |
|
2669 |
|
rg_fatal('cannot gzencode'); |
|
2670 |
|
|
|
2671 |
|
$orig_len = strlen($c); |
|
2672 |
|
$comp_len = strlen($ret); |
|
2673 |
|
rg_log('COMPRESSION: orig=' . $orig_len |
|
2674 |
|
. ' comp=' . $comp_len |
|
2675 |
|
. ' ratio=' . sprintf('%.3f', $orig_len / $comp_len)); |
|
2676 |
|
|
|
2677 |
|
rg_prof_end('gzencode'); |
|
2678 |
|
return $ret; |
|
2679 |
|
} |
|
2680 |
|
|
|
2681 |
|
/* |
|
2682 |
|
* Output data to client |
|
2683 |
|
*/ |
|
2684 |
|
function rg_web_output($c) |
|
2685 |
|
{ |
|
2686 |
|
$acc = @$_SERVER['HTTP_ACCEPT_ENCODING']; |
|
2687 |
|
rg_log('DEBUG: client supports: ' . $acc); |
|
2688 |
|
if (stristr($acc, 'gzip')) { |
|
2689 |
|
header('Content-Encoding: gzip'); |
|
2690 |
|
$c = rg_gzencode($c, $orig_len, $comp_len); |
|
2691 |
|
header('Content-Length: ' . $comp_len); |
|
2692 |
|
} |
|
2693 |
|
|
|
2694 |
|
echo $c; |
|
2695 |
|
} |
|
2696 |
|
|
File scripts/cache.php changed (mode: 100644) (index 9e8b40a..48d9884) |
... |
... |
require_once($INC . "/ver.php"); |
30 |
30 |
|
|
31 |
31 |
function rg_destroy($k, &$conn_table) |
function rg_destroy($k, &$conn_table) |
32 |
32 |
{ |
{ |
33 |
|
rg_log("Destroying key $k..."); |
|
|
33 |
|
rg_log($k . ": Destroying"); |
34 |
34 |
if (isset($conn_table['r'][$k])) |
if (isset($conn_table['r'][$k])) |
35 |
35 |
unset($conn_table['r'][$k]); |
unset($conn_table['r'][$k]); |
36 |
36 |
if (isset($conn_table['w'][$k])) |
if (isset($conn_table['w'][$k])) |
|
... |
... |
function rg_destroy($k, &$conn_table) |
44 |
44 |
|
|
45 |
45 |
function rg_handle_command($k, &$conn_table, $cmd) |
function rg_handle_command($k, &$conn_table, $cmd) |
46 |
46 |
{ |
{ |
47 |
|
//rg_log("rg_handle_command: k=$k, cmd=$cmd"); |
|
|
47 |
|
//rg_log($k . ": handle_command: cmd=$cmd"); |
48 |
48 |
|
|
49 |
49 |
$s = &$conn_table['conns'][$k]; |
$s = &$conn_table['conns'][$k]; |
50 |
50 |
|
|
|
... |
... |
function rg_handle_command($k, &$conn_table, $cmd) |
60 |
60 |
|
|
61 |
61 |
$flags = trim($a[1]); |
$flags = trim($a[1]); |
62 |
62 |
if (strncmp($flags, 'F=', 2) != 0) { |
if (strncmp($flags, 'F=', 2) != 0) { |
63 |
|
rg_log('Invalid command (no flags): $cmd'); |
|
|
63 |
|
rg_log($k . ': Invalid command (no flags): $cmd'); |
64 |
64 |
break; |
break; |
65 |
65 |
} |
} |
66 |
66 |
$flags = substr($flags, 2); |
$flags = substr($flags, 2); |
|
... |
... |
function rg_handle_command($k, &$conn_table, $cmd) |
69 |
69 |
|
|
70 |
70 |
$id = trim($a[2]); |
$id = trim($a[2]); |
71 |
71 |
if (strncmp($id, 'I=', 2) != 0) { |
if (strncmp($id, 'I=', 2) != 0) { |
72 |
|
rg_log('Invalid command (no id): $cmd'); |
|
|
72 |
|
rg_log($k . ': Invalid command (no id): $cmd'); |
73 |
73 |
break; |
break; |
74 |
74 |
} |
} |
75 |
75 |
$id = substr($id, 2); |
$id = substr($id, 2); |
|
... |
... |
function rg_handle_command($k, &$conn_table, $cmd) |
88 |
88 |
break; |
break; |
89 |
89 |
$ns_var = trim($ns_var_value[0]); |
$ns_var = trim($ns_var_value[0]); |
90 |
90 |
$value = trim($ns_var_value[1]); |
$value = trim($ns_var_value[1]); |
91 |
|
$value = unserialize(stripcslashes($value)); |
|
|
91 |
|
$value = rg_unserialize($value); |
92 |
92 |
if ($value !== FALSE) { |
if ($value !== FALSE) { |
93 |
93 |
rg_cache_core_set("normal::" . $ns_var, $value); |
rg_cache_core_set("normal::" . $ns_var, $value); |
94 |
94 |
$buf = 'OK ' . $id . "\n"; |
$buf = 'OK ' . $id . "\n"; |
|
... |
... |
function rg_handle_command($k, &$conn_table, $cmd) |
104 |
104 |
break; |
break; |
105 |
105 |
$ns_var = trim($ns_var_value[0]); |
$ns_var = trim($ns_var_value[0]); |
106 |
106 |
$value = trim($ns_var_value[1]); |
$value = trim($ns_var_value[1]); |
107 |
|
$value = unserialize(stripcslashes($value)); |
|
|
107 |
|
$value = rg_unserialize($value); |
108 |
108 |
if ($value !== FALSE) { |
if ($value !== FALSE) { |
109 |
109 |
$ret = rg_cache_core_merge("normal::" . $ns_var, |
$ret = rg_cache_core_merge("normal::" . $ns_var, |
110 |
110 |
$value); |
$value); |
|
... |
... |
function rg_handle_command($k, &$conn_table, $cmd) |
157 |
157 |
break; |
break; |
158 |
158 |
$ns_var = trim($ns_var_value[0]); |
$ns_var = trim($ns_var_value[0]); |
159 |
159 |
$value = trim($ns_var_value[1]); |
$value = trim($ns_var_value[1]); |
160 |
|
$value = unserialize(stripcslashes($value)); |
|
|
160 |
|
$value = rg_unserialize($value); |
161 |
161 |
if ($value !== FALSE) { |
if ($value !== FALSE) { |
162 |
162 |
rg_cache_core_apush("normal::" . $ns_var, $value); |
rg_cache_core_apush("normal::" . $ns_var, $value); |
163 |
163 |
$buf = 'OK ' . $id . "\n"; |
$buf = 'OK ' . $id . "\n"; |
|
... |
... |
function rg_handle_command($k, &$conn_table, $cmd) |
186 |
186 |
} |
} |
187 |
187 |
|
|
188 |
188 |
if (strcmp($cmd, "SHUTDOWN") == 0) { |
if (strcmp($cmd, "SHUTDOWN") == 0) { |
189 |
|
rg_log('Shutting down...'); |
|
|
189 |
|
rg_log($k . ': Shutting down...'); |
190 |
190 |
exit(0); |
exit(0); |
191 |
191 |
} |
} |
192 |
192 |
|
|
193 |
193 |
if (strcmp($cmd, "SLEEP") == 0) { |
if (strcmp($cmd, "SLEEP") == 0) { |
194 |
|
rg_log('Sleeping...'); |
|
|
194 |
|
rg_log($k . ': Sleeping...'); |
195 |
195 |
$buf = 'OK ' . $id . "\n"; |
$buf = 'OK ' . $id . "\n"; |
196 |
196 |
sleep(3); |
sleep(3); |
197 |
197 |
} |
} |
|
... |
... |
function rg_handle_command($k, &$conn_table, $cmd) |
200 |
200 |
} |
} |
201 |
201 |
|
|
202 |
202 |
if ($no_wait === FALSE) { |
if ($no_wait === FALSE) { |
203 |
|
rg_log($k . ':DEBUG: enqueue: ' . $buf); |
|
|
203 |
|
rg_log($k . ': DEBUG: enqueue: ' . $buf); |
204 |
204 |
$s['send'] .= $buf; |
$s['send'] .= $buf; |
205 |
205 |
$conn_table['w'][$k] = $s['socket']; |
$conn_table['w'][$k] = $s['socket']; |
206 |
206 |
} |
} |
|
... |
... |
function rg_handle_command($k, &$conn_table, $cmd) |
208 |
208 |
|
|
209 |
209 |
function rg_handle_recv($k, &$conn_table) |
function rg_handle_recv($k, &$conn_table) |
210 |
210 |
{ |
{ |
211 |
|
//rg_log("handle_recv on key $k..."); |
|
|
211 |
|
//rg_log($k . ": handle_recv"); |
212 |
212 |
$s = &$conn_table['conns'][$k]; |
$s = &$conn_table['conns'][$k]; |
213 |
213 |
|
|
214 |
214 |
$ret = @socket_recv($s['socket'], $buf, 32 * 4096, 0); |
$ret = @socket_recv($s['socket'], $buf, 32 * 4096, 0); |
215 |
215 |
if ($ret === FALSE) { |
if ($ret === FALSE) { |
216 |
|
rg_log("Error in recv (" . socket_strerror(socket_last_error()) . ")"); |
|
|
216 |
|
rg_log($k . ": Error in recv (" . socket_strerror(socket_last_error()) . ")"); |
217 |
217 |
rg_destroy($k, $conn_table); |
rg_destroy($k, $conn_table); |
218 |
218 |
return; |
return; |
219 |
219 |
} |
} |
220 |
220 |
if ($ret === 0) { |
if ($ret === 0) { |
221 |
|
rg_log("Remote closed the connection (received 0)."); |
|
|
221 |
|
rg_log($k . ": Remote closed the connection (received 0)."); |
222 |
222 |
rg_destroy($k, $conn_table); |
rg_destroy($k, $conn_table); |
223 |
223 |
return; |
return; |
224 |
224 |
} |
} |
225 |
225 |
|
|
226 |
|
rg_log($k . ':DEBUG: received: ' . $buf); |
|
|
226 |
|
rg_log($k . ': DEBUG: received: ' . $buf); |
227 |
227 |
|
|
228 |
228 |
$s['recv'] .= $buf; |
$s['recv'] .= $buf; |
229 |
229 |
$s['close_at'] = time() + 30; |
$s['close_at'] = time() + 30; |
|
... |
... |
function rg_handle_recv($k, &$conn_table) |
242 |
242 |
|
|
243 |
243 |
function rg_handle_send($k, &$conn_table) |
function rg_handle_send($k, &$conn_table) |
244 |
244 |
{ |
{ |
245 |
|
//rg_log("Sending on key $k..."); |
|
|
245 |
|
//rg_log($k . ": Sending..."); |
246 |
246 |
$s = &$conn_table['conns'][$k]; |
$s = &$conn_table['conns'][$k]; |
247 |
247 |
|
|
248 |
248 |
$ret = @socket_send($s['socket'], $s['send'], strlen($s['send']), 0); |
$ret = @socket_send($s['socket'], $s['send'], strlen($s['send']), 0); |
249 |
249 |
if ($ret === FALSE) { |
if ($ret === FALSE) { |
250 |
|
rg_log("Cannot send (" . socket_strerror(socket_last_error()) . ")"); |
|
|
250 |
|
rg_log($k . ": Cannot send (" . socket_strerror(socket_last_error()) . ")"); |
251 |
251 |
rg_destroy($k, $conn_table); |
rg_destroy($k, $conn_table); |
252 |
252 |
return; |
return; |
253 |
253 |
} |
} |
|
... |
... |
function rg_handle_new($client, &$conn_table) |
269 |
269 |
"close_at" => time() + 30 |
"close_at" => time() + 30 |
270 |
270 |
); |
); |
271 |
271 |
$conn_table['r'][$key] = $client; |
$conn_table['r'][$key] = $client; |
272 |
|
//rg_log("Added client with key $key."); |
|
|
272 |
|
//rg_log($key . ": Added client"); |
273 |
273 |
|
|
274 |
274 |
/* This way I can enforce the connecting user to be apache/rocketgit |
/* This way I can enforce the connecting user to be apache/rocketgit |
275 |
275 |
but is seems it does not work correctly in PHP... |
but is seems it does not work correctly in PHP... |
|
... |
... |
function rg_handle_idle(&$conn_table) |
288 |
288 |
continue; |
continue; |
289 |
289 |
} |
} |
290 |
290 |
if ($info['close_at'] < $now) { |
if ($info['close_at'] < $now) { |
291 |
|
rg_log("Destroy $key because has been too much time idle."); |
|
|
291 |
|
rg_log($key . ": Destroy key because has been too much time idle."); |
292 |
292 |
rg_destroy($key, $conn_table); |
rg_destroy($key, $conn_table); |
293 |
293 |
} |
} |
294 |
294 |
} |
} |