List of commits:
Subject Hash Author Date (UTC)
Big rework for rg_exec/rg_exec2 6b962257e2494217bcd528bcdbb39544b3809c14 Catalin(ux) M. BOIE 2019-10-26 05:28:09
Be more explicit and specify exactly the ssh command instead of 'ssh ... totp' 3750e02fc5a0d75ba274c6ae9757e3d582348f51 Catalin(ux) M. BOIE 2019-10-25 02:54:52
Activating gzip compression in nginx sample file 60a153c84f1a8ee68c4008d2cb512d3016c50499 Catalin(ux) M. BOIE 2019-10-25 02:33:13
totp: urlencode parameters when calling qrencode 0b16e22978a8b5488e8f435a538dec07bb515476 Catalin(ux) M. BOIE 2019-10-19 03:53:20
/run/rocketgit-fpm/ -> /run to not create the dir 13ff6e91698260ba5a41591275fa915e33baebc9 Catalin(ux) M. BOIE 2019-10-01 16:08:43
Compute repo disk size only for not deleted repos 551d1798802853e5af1e12a1908cc10fbc432d17 Catalin(ux) M. BOIE 2019-09-30 22:08:27
git_log2listing big changes e91fdef76511d586af30a3aa4b44273a1203bd36 Catalin(ux) M. BOIE 2019-09-30 19:54:38
typo 0ef09cd6e02fa3bf79e0a26b887badc103b03d87 Catalin(ux) M. BOIE 2019-09-30 19:53:56
Some more error testing for http_confirm test 1f36b1f55465c57e935b830e456d8f8044ec17da Catalin(ux) M. BOIE 2019-09-30 19:53:38
fixes: ignore some errors 584eef4cbfb5427eaae34d72ea99b94ec4da29a4 Catalin(ux) M. BOIE 2019-09-30 19:52:45
cache: functional test for timeout acaeca2fbceb797b0fb58f1c05bdd8d1f9025f25 Catalin(ux) M. BOIE 2019-09-30 19:51:35
Fixed rg_git_merge because it was broken 797a976065420525f9f2c6a096ae306ffa5ed78d Catalin(ux) M. BOIE 2019-09-30 19:50:41
Disable GC when serving requests from web/fetch/push; we will do it from cron fd16c96f5f0a6d24e0c6aaf45c5a02833579667a Catalin(ux) M. BOIE 2019-09-30 19:48:49
git: fixes display of filenames which are not UTF-8 valid 83b6f641a547a4652aad6e921486d2b91cffdb9f Catalin(ux) M. BOIE 2019-09-30 19:46:07
rg_change_pass missed a log file name e49fc9f8c896414098713e418205d97b2e594c1f Catalin(ux) M. BOIE 2019-09-22 09:32:59
totp: remove a double DELETE sql query and invalidate cache after we remove the data from db ff22d7ddabc1c64a37fcb1749f54321974b0f8d3 Catalin(ux) M. BOIE 2019-09-22 09:28:30
selinux: added map (for packs) 911b2cffa2d754d466a31693af71d6c58639dd9d Catalin(ux) M. BOIE 2019-09-22 06:58:44
Do not allow : char in user name 460b846752c03368990b60efbbf12f74e229bda5 Catalin(ux) M. BOIE 2019-09-22 05:58:37
Do not allow : char in repo name b072ba3cd6c46e2ee7d07dc5890c8671d8462a09 Catalin(ux) M. BOIE 2019-09-22 05:56:56
Fix an XSS in repo description ee2d11f0b16b436d9e64a0c5ac57361d25e098e1 Catalin(ux) M. BOIE 2019-09-22 05:45:11
Commit 6b962257e2494217bcd528bcdbb39544b3809c14 - Big rework for rg_exec/rg_exec2
Author: Catalin(ux) M. BOIE
Author date (UTC): 2019-10-26 05:28
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2019-10-26 05:28
Parent(s): 3750e02fc5a0d75ba274c6ae9757e3d582348f51
Signer:
Signing key:
Signing status: N
Tree: a126d39418afa742db4901f55e08e0aa5427f5d2
File Lines added Lines deleted
inc/builder.inc.php 1 1
inc/git.inc.php 20 18
inc/user.inc.php 3 3
inc/util.inc.php 262 226
scripts/worker.php 21 21
tests/ask_pass_empty 1 1
tests/by_http.php 44 17
tests/cache.php 11 1
tests/common.php 3 0
tests/export.php 1 1
tests/git.php 3 3
tests/git2.php 8 4
tests/git_big_push.php 50 27
tests/helpers.inc.php 3 3
tests/http.inc.php 1 1
tests/ldap.php 4 4
tests/pr_anon.php 21 7
tests/repo.php 1 1
tests/source.php 1 1
tests/ssh.php 20 6
tests/user.php 2 2
tests/util.php 189 132
tests/util_exit_code.sh 2 0
tests/util_stdout_closes_first.sh 10 0
tests/wh_cloud.php 2 1
tests/wh_http.php 8 5
tests/wh_lambda.php 1 1
File inc/builder.inc.php changed (mode: 100644) (index e4949cb..30282fc)
... ... function rg_builder_add($db, $repo_id, $d)
89 89 function rg_builder_vm_list() function rg_builder_vm_list()
90 90 { {
91 91 $cmd = 'virsh list --name'; $cmd = 'virsh list --name';
92 $r = rg_exec($cmd, '', FALSE, FALSE);
92 $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
93 93 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
94 94 rg_log('Cannot find out virtual machines: ' . $r['errmsg']); rg_log('Cannot find out virtual machines: ' . $r['errmsg']);
95 95 return FALSE; return FALSE;
File inc/git.inc.php changed (mode: 100644) (index 9b4fe90..4053b28)
... ... $rg_git_debug = 0;
11 11 $rg_git_zero = "0000000000000000000000000000000000000000"; $rg_git_zero = "0000000000000000000000000000000000000000";
12 12 $rg_git_empty = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"; $rg_git_empty = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
13 13 define('GIT_LINK_MASK', intval(base_convert('160000', 8, 10))); define('GIT_LINK_MASK', intval(base_convert('160000', 8, 10)));
14 define('RG_GIT_HASH_LEN', 10);
14 15
15 16 define ('RG_GIT_CMD', 'git -c gc.auto=0'); define ('RG_GIT_CMD', 'git -c gc.auto=0');
16 17
 
... ... function rg_git_lock($repo_path, $timeout)
52 53
53 54 $ret = FALSE; $ret = FALSE;
54 55 while (1) { while (1) {
55 $f = @fopen($repo_path . '/rg_lock', 'w');
56 $f = @fopen($repo_path . '/rocketgit/rg_lock', 'w');
56 57 if ($f === FALSE) { if ($f === FALSE) {
57 58 rg_git_set_error('cannot lock repo (open)'); rg_git_set_error('cannot lock repo (open)');
58 59 break; break;
 
... ... function rg_git_init($dst)
309 310 if (!is_dir($dst . "/rocketgit")) { if (!is_dir($dst . "/rocketgit")) {
310 311 $dst2 = $dst . '.tmp'; $dst2 = $dst . '.tmp';
311 312 $cmd = RG_GIT_CMD . ' init --bare ' . escapeshellarg($dst2); $cmd = RG_GIT_CMD . ' init --bare ' . escapeshellarg($dst2);
312 $a = rg_exec($cmd, '', FALSE, FALSE);
313 $a = rg_exec($cmd, '', FALSE, FALSE, FALSE);
313 314 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
314 315 rg_git_set_error("error on init " . $a['errmsg'] . ")"); rg_git_set_error("error on init " . $a['errmsg'] . ")");
315 316 break; break;
 
... ... function rg_git_clone($src, $dst)
360 361 if (!file_exists($dst . "/rocketgit")) { if (!file_exists($dst . "/rocketgit")) {
361 362 $cmd = RG_GIT_CMD . "clone --bare " . escapeshellarg($src) $cmd = RG_GIT_CMD . "clone --bare " . escapeshellarg($src)
362 363 . " " . escapeshellarg($dst); . " " . escapeshellarg($dst);
363 $a = rg_exec($cmd, '', FALSE, FALSE);
364 $a = rg_exec($cmd, '', FALSE, FALSE, FALSE);
364 365 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
365 366 rg_git_set_error("error on clone (" . $a['errmsg'] . ")"); rg_git_set_error("error on clone (" . $a['errmsg'] . ")");
366 367 break; break;
 
... ... function rg_git_type($obj)
402 403 } }
403 404
404 405 $cmd = RG_GIT_CMD . ' cat-file -t ' . escapeshellarg($obj); $cmd = RG_GIT_CMD . ' cat-file -t ' . escapeshellarg($obj);
405 $a = rg_exec($cmd, '', FALSE, FALSE);
406 $a = rg_exec($cmd, '', FALSE, FALSE, FALSE);
406 407 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
407 408 rg_git_set_error('error on cat-file (' . $a['errmsg'] . ')'); rg_git_set_error('error on cat-file (' . $a['errmsg'] . ')');
408 409 break; break;
 
... ... function rg_git_content($obj)
428 429 $ret = FALSE; $ret = FALSE;
429 430 while (1) { while (1) {
430 431 $cmd = RG_GIT_CMD . ' cat-file -p ' . escapeshellarg($obj); $cmd = RG_GIT_CMD . ' cat-file -p ' . escapeshellarg($obj);
431 $a = rg_exec($cmd, '', FALSE, FALSE);
432 $a = rg_exec($cmd, '', FALSE, FALSE, FALSE);
432 433 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
433 434 rg_git_set_error('error on cat-file (' . $a['errmsg'] . ')'); rg_git_set_error('error on cat-file (' . $a['errmsg'] . ')');
434 435 break; break;
 
... ... function rg_git_rev_ok($rev)
505 506 $ret = FALSE; $ret = FALSE;
506 507 while (1) { while (1) {
507 508 $cmd = RG_GIT_CMD . ' rev-parse --verify ' . escapeshellarg($rev); $cmd = RG_GIT_CMD . ' rev-parse --verify ' . escapeshellarg($rev);
508 $a = rg_exec($cmd, '', FALSE, FALSE);
509 $a = rg_exec($cmd, '', FALSE, FALSE, FALSE);
509 510 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
510 511 rg_git_set_error("error on rev-parse (" . $a['errmsg'] . ")"); rg_git_set_error("error on rev-parse (" . $a['errmsg'] . ")");
511 512 break; break;
 
... ... function rg_git_whitespace_ok($old, $new)
540 541 $cmd = RG_GIT_CMD . " diff --check" $cmd = RG_GIT_CMD . " diff --check"
541 542 . " " . escapeshellarg($old) . " " . escapeshellarg($old)
542 543 . " " . escapeshellarg($new); . " " . escapeshellarg($new);
543 $a = rg_exec($cmd, '', FALSE, FALSE);
544 $a = rg_exec($cmd, '', FALSE, FALSE, FALSE);
544 545 rg_log("a:" . rg_array2string($a)); rg_log("a:" . rg_array2string($a));
545 546 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
546 547 rg_git_set_error("error on diff (" . $a['errmsg'] . ")"); rg_git_set_error("error on diff (" . $a['errmsg'] . ")");
 
... ... function rg_git_merge_base($repo_path, $a, $b)
604 605 if ($head === FALSE) if ($head === FALSE)
605 606 break; break;
606 607
608 // TODO: why do we use escape here?!
607 609 $key = 'git' $key = 'git'
608 610 . '::' . sha1($repo_path) . '::' . sha1($repo_path)
609 611 . '::' . 'merge-base' . '::' . 'merge-base'
 
... ... function rg_git_merge_base($repo_path, $a, $b)
621 623 . ' merge-base' . ' merge-base'
622 624 . ' ' . escapeshellarg($a) . ' ' . escapeshellarg($a)
623 625 . ' ' . escapeshellarg($b); . ' ' . escapeshellarg($b);
624 $a = rg_exec($cmd, '', FALSE, FALSE);
626 $a = rg_exec($cmd, '', FALSE, FALSE, FALSE);
625 627 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
626 628 rg_git_set_error('error on git merge_base (' rg_git_set_error('error on git merge_base ('
627 629 . $a['errmsg'] . ')'); . $a['errmsg'] . ')');
 
... ... function rg_git_update_ref($repo_path, $ref, $old, $new, $reason)
672 674 if (!empty($old)) if (!empty($old))
673 675 $cmd .= " " . escapeshellarg($old); $cmd .= " " . escapeshellarg($old);
674 676
675 $r = rg_exec($cmd, '', FALSE, FALSE);
677 $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
676 678 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
677 679 rg_git_set_error( rg_git_set_error(
678 680 'error on update-ref (' . $r['errmsg'] . ')'); 'error on update-ref (' . $r['errmsg'] . ')');
 
... ... function rg_git_shortlog($repo_path, $a, $b)
702 704 . ' --git-dir=' . escapeshellarg($repo_path) . ' --git-dir=' . escapeshellarg($repo_path)
703 705 . ' ' . escapeshellarg($a) . ' ' . escapeshellarg($a)
704 706 . '..' . escapeshellarg($b); . '..' . escapeshellarg($b);
705 $r = rg_exec($cmd, '', FALSE, FALSE);
707 $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
706 708 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
707 709 rg_git_set_error('error on shortlog (' . $r['errmsg'] . ')'); rg_git_set_error('error on shortlog (' . $r['errmsg'] . ')');
708 710 break; break;
 
... ... function rg_git_ls_tree($repo_path, $tree, $path)
739 741 . escapeshellarg($tree); . escapeshellarg($tree);
740 742 if (!empty($path)) if (!empty($path))
741 743 $cmd .= ' ' . escapeshellarg($path); $cmd .= ' ' . escapeshellarg($path);
742 $a = rg_exec($cmd, '', FALSE, FALSE);
744 $a = rg_exec($cmd, '', FALSE, FALSE, FALSE);
743 745 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
744 746 rg_git_set_error("error on ls-tree (" . $a['errmsg'] . ")"); rg_git_set_error("error on ls-tree (" . $a['errmsg'] . ")");
745 747 break; break;
 
... ... function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files,
1186 1188 foreach ($files as $f) foreach ($files as $f)
1187 1189 $cmd .= ' ' . escapeshellarg($f); $cmd .= ' ' . escapeshellarg($f);
1188 1190 } }
1189 $a = rg_exec($cmd, '', FALSE, FALSE);
1191 $a = rg_exec($cmd, '', FALSE, FALSE, FALSE);
1190 1192 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
1191 1193 rg_internal_error("error on log (" . $a['errmsg'] . ")" rg_internal_error("error on log (" . $a['errmsg'] . ")"
1192 1194 . " cmd=" . $cmd); . " cmd=" . $cmd);
 
... ... function rg_git_files($old, $new)
1633 1635
1634 1636 $cmd = RG_GIT_CMD . ' diff --name-only ' . escapeshellarg($old) $cmd = RG_GIT_CMD . ' diff --name-only ' . escapeshellarg($old)
1635 1637 . ' ' . escapeshellarg($new); . ' ' . escapeshellarg($new);
1636 $a = rg_exec($cmd, '', FALSE, FALSE);
1638 $a = rg_exec($cmd, '', FALSE, FALSE, FALSE);
1637 1639 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
1638 1640 rg_git_set_error("error on git diff (" . $a['errmsg'] . ")"); rg_git_set_error("error on git diff (" . $a['errmsg'] . ")");
1639 1641 break; break;
 
... ... function rg_git_diff_tree($tree1, $tree2)
2229 2231 while (1) { while (1) {
2230 2232 $cmd = RG_GIT_CMD . " diff-tree -r " . escapeshellarg($tree1) $cmd = RG_GIT_CMD . " diff-tree -r " . escapeshellarg($tree1)
2231 2233 . " " . escapeshellarg($tree2); . " " . escapeshellarg($tree2);
2232 $a = rg_exec($cmd, '', FALSE, FALSE);
2234 $a = rg_exec($cmd, '', FALSE, FALSE, FALSE);
2233 2235 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
2234 2236 rg_git_set_error("error on diff-tree (" . $a['errmsg'] . ")"); rg_git_set_error("error on diff-tree (" . $a['errmsg'] . ")");
2235 2237 break; break;
 
... ... function rg_git_content_by_file($treeish, $file)
2274 2276 while (1) { while (1) {
2275 2277 $cmd = RG_GIT_CMD . ' show ' . escapeshellarg($treeish) . ':' $cmd = RG_GIT_CMD . ' show ' . escapeshellarg($treeish) . ':'
2276 2278 . escapeshellarg($file); . escapeshellarg($file);
2277 $a = rg_exec($cmd, '', FALSE, FALSE);
2279 $a = rg_exec($cmd, '', FALSE, FALSE, FALSE);
2278 2280 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
2279 2281 rg_git_set_error("error on show (" . $a['errmsg'] . ")"); rg_git_set_error("error on show (" . $a['errmsg'] . ")");
2280 2282 break; break;
 
... ... function rg_git_archive($repo_path, $treeish, $archive_name, $format)
2400 2402 . ' archive --format=' . escapeshellarg($format) . ' archive --format=' . escapeshellarg($format)
2401 2403 . ' --output=' . escapeshellarg($archive_name) . ' --output=' . escapeshellarg($archive_name)
2402 2404 . ' ' . escapeshellarg($treeish); . ' ' . escapeshellarg($treeish);
2403 $a = rg_exec($cmd, '', FALSE, FALSE);
2405 $a = rg_exec($cmd, '', FALSE, FALSE, FALSE);
2404 2406 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
2405 2407 rg_git_set_error('error on git archive' rg_git_set_error('error on git archive'
2406 2408 . ' (' . $a['errmsg'] . ')'); . ' (' . $a['errmsg'] . ')');
 
... ... function rg_git_merge_tree($repo_path, $base, $a, $b)
2469 2471 . ' ' . escapeshellarg($base) . ' ' . escapeshellarg($base)
2470 2472 . ' ' . escapeshellarg($a) . ' ' . escapeshellarg($a)
2471 2473 . ' ' . escapeshellarg($b); . ' ' . escapeshellarg($b);
2472 $a = rg_exec($cmd, '', FALSE, FALSE);
2474 $a = rg_exec($cmd, '', FALSE, FALSE, FALSE);
2473 2475 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
2474 2476 rg_git_set_error('error on git merge-tree (' rg_git_set_error('error on git merge-tree ('
2475 2477 . $a['errmsg'] . ')'); . $a['errmsg'] . ')');
 
... ... function rg_git_request_pull($repo_path, $start, $url, $end, $patch)
2657 2659 if ($patch) if ($patch)
2658 2660 $cmd .= ' --patch'; $cmd .= ' --patch';
2659 2661 $cmd .= escapeshellarg($start) . '..' . escapeshellarg($end); $cmd .= escapeshellarg($start) . '..' . escapeshellarg($end);
2660 $r = rg_exec($cmd, '', FALSE, FALSE);
2662 $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
2661 2663 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
2662 2664 rg_git_set_error('error on git diff: ' . $a['errmsg']); rg_git_set_error('error on git diff: ' . $a['errmsg']);
2663 2665 break; break;
File inc/user.inc.php changed (mode: 100644) (index 78fc5fe..ce8d3c1)
... ... function rg_user_http_git($db, $rg, $paras)
2448 2448 $run = '/usr/libexec/git-core/' . $service $run = '/usr/libexec/git-core/' . $service
2449 2449 . ' --stateless-rpc --advertise-refs' . ' --stateless-rpc --advertise-refs'
2450 2450 . ' ' . escapeshellarg($repo_path); . ' ' . escapeshellarg($repo_path);
2451 $e = rg_exec($run, '', 'rg_echo', 'rg_git_band_2');
2451 $e = rg_exec($run, '', 0 /*use stdin*/, 'rg_echo', 'rg_git_band_2');
2452 2452 if ($e['code'] != 0) if ($e['code'] != 0)
2453 2453 rg_log('Error executing command: ' . $e['errmsg']); rg_log('Error executing command: ' . $e['errmsg']);
2454 2454 rg_log('Done!'); rg_log('Done!');
 
... ... function rg_user_http_git($db, $rg, $paras)
2482 2482 $run = '/usr/libexec/git-core/git-upload-pack' $run = '/usr/libexec/git-core/git-upload-pack'
2483 2483 . ' --stateless-rpc' . ' --stateless-rpc'
2484 2484 . ' ' . escapeshellarg($repo_path); . ' ' . escapeshellarg($repo_path);
2485 $e = rg_exec($run, $data_in, 'rg_echo', 'rg_git_band_2');
2485 $e = rg_exec($run, $data_in, 0 /*use stdin*/, 'rg_echo', 'rg_git_band_2');
2486 2486 if ($e['code'] != 0) if ($e['code'] != 0)
2487 2487 rg_log('Error executing command: ' . $e['errmsg']); rg_log('Error executing command: ' . $e['errmsg']);
2488 2488 rg_log('Done!'); rg_log('Done!');
 
... ... function rg_user_http_git($db, $rg, $paras)
2516 2516 $run = '/usr/libexec/git-core/git-receive-pack' $run = '/usr/libexec/git-core/git-receive-pack'
2517 2517 . ' --stateless-rpc' . ' --stateless-rpc'
2518 2518 . ' ' . escapeshellarg($repo_path); . ' ' . escapeshellarg($repo_path);
2519 $e = rg_exec($run, $data_in, 'rg_echo', 'rg_echo');
2519 $e = rg_exec($run, $data_in, 0 /*use stdin*/, 'rg_echo', 'rg_echo');
2520 2520 if ($e['code'] != 0) if ($e['code'] != 0)
2521 2521 rg_log('Error executing command: ' . $e['errmsg']); rg_log('Error executing command: ' . $e['errmsg']);
2522 2522 rg_log('Done!'); rg_log('Done!');
File inc/util.inc.php changed (mode: 100644) (index e4a7bf8..9cbf1fe)
... ... function rg_util_error()
30 30 */ */
31 31 $rg_template_functions = array(); $rg_template_functions = array();
32 32
33 /*
34 *
35 */
36 function rg_php_err()
37 {
38 $a = error_get_last();
39 if ($a === NULL)
40 return 'no error';
41
42 return $a['message'];
43 }
44
33 45 /* /*
34 46 * Register a function to be called when a @@func:func_name:var@@ construction * Register a function to be called when a @@func:func_name:var@@ construction
35 47 * is found in a template. * is found in a template.
 
... ... function rg_ok($msg)
1031 1043 } }
1032 1044
1033 1045 /* /*
1034 * Execute $cmd and returns the output as a string, binary safe
1035 * @input: some data to be sent to the process and received as stdin
1036 * @cb_stdout - call back called when there is something to be send to stdout
1037 * if @cb_stdout is FALSE, stdout output will be returned in $ret['data']
1038 * cb_stderr - call back called when there is something to be send to stderr
1039 * if @cb_stderr is FALSE, stderr output will be returned in $ret['stderr']
1046 * Helper for rg_exec to init the structure
1040 1047 */ */
1041 function rg_exec($cmd, $input, $cb_stdout, $cb_stderr)
1048 function rg_exec2_helper_init(&$info)
1042 1049 { {
1043 rg_prof_start('exec');
1044 rg_log_enter('Executing [' . $cmd . ']');
1045
1046 // DEBUG
1047 $d = FALSE;
1048
1049 $ret = array();
1050 $ret['ok'] = 0;
1051 $ret['errmsg'] = '';
1052 $ret['code'] = 65000; // fake code
1053 $ret['data'] = '';
1054 $ret['stderr'] = '';
1055 while (1) {
1056 $desc = array(
1057 0 => array("pipe", "r"),
1058 1 => array('pipe', 'w'),
1059 2 => array("pipe", "w")
1060 );
1061 $d && rg_log_ml('DEBUG: desc: ' . print_r($desc, TRUE));
1062
1063 $a = proc_open($cmd, $desc, $pipes);
1064 if ($a === FALSE) {
1065 $ret['errmsg'] = "cannot call proc_open";
1066 break;
1067 }
1068
1069 $d && rg_log_ml('DEBUG: proc_open pipes: ' . print_r($pipes, TRUE));
1070
1071 $rx = array($pipes[1], $pipes[2]);
1072 $wx = array();
1073 if (!empty($input))
1074 $wx[] = $pipes[0];
1075 while (!empty($rx)) {
1076 $revents = $rx;
1077 $wevents = $wx;
1078 $ex = NULL;
1079 $d && rg_log('DEBUG: before stream_select:'
1080 . ' revents: ' . rg_array2string($revents)
1081 . ' wevents: ' . rg_array2string($wevents));
1082 $r = stream_select($revents, $wevents, $ex, 5, 0);
1083 if ($r === FALSE) {
1084 $ret['errmsg'] = "cannot select";
1085 break;
1086 }
1087
1088 if ($r === 0) {
1089 $ps = proc_get_status($a);
1090 rg_log_ml('ps: ' . print_r($ps, TRUE));
1091 //rg_log('DEBUG: No activity (conn status=' . connection_status() . ')!');
1092 if (connection_aborted()) {
1093 $d && rg_log('connection aborted');
1094 $ret['errmsg'] = 'connection aborted';
1095 break;
1096 }
1097 continue;
1098 }
1099
1100 $d && rg_log('DEBUG: stream_select returned ' . $r
1101 . ' revents: ' . rg_array2string($revents)
1102 . ' wevents: ' . rg_array2string($wevents)
1103 . ' ex: ' . rg_array2string($ex));
1104
1105 foreach ($wevents as $fd) {
1106 if (!empty($ret['errmsg']))
1107 break;
1108
1109 $d && rg_log('DEBUG: write event on fd ' . $fd . '!');
1110
1111 $d && rg_log('DEBUG: Writing to fd ' . $fd
1112 . ' [' . $input . ']...');
1113 $r = @fwrite($fd, $input);
1114 if ($r === FALSE) {
1115 $ret['ermsg'] = 'cannot write';
1116 break;
1117 }
1118 $d && rg_log('DEBUG: fwrite returned ' . $r . '.');
1119 $input = substr($input, $r);
1120 if (empty($input))
1121 $wx = array();
1122 }
1050 $info['last_activity'] = 0;
1051 $info['last_errmsg'] = '';
1052 $info['closed'] = array(0 => 0, 1 => 0, 2 => 0);
1053 $info['start_ts'] = time();
1054 $info['last_failure'] = 0;
1055 if (!isset($info['out_buf']))
1056 $info['out_buf'] = '';
1057 $info['in_buf'] = '';
1058 $info['err_buf'] = '';
1059 $info['done'] = FALSE;
1123 1060
1124 $do_break = FALSE;
1125 foreach ($revents as $fd) {
1126 if (!empty($ret['errmsg']))
1127 break;
1061 if (!isset($info['idle_time']))
1062 $info['idle_time'] = 5;
1128 1063
1129 $d && rg_log('DEBUG: read event on fd ' . $fd . '!');
1130 $_d = fread($fd, 32 * 4096);
1131 if ($_d === FALSE) {
1132 $ret['errmsg'] = "cannot read";
1133 break;
1134 }
1064 if (!isset($info['output_done'])) {
1065 if (isset($info['input_fd']))
1066 $info['output_done'] = 0;
1067 else
1068 $info['output_done'] = 1;
1069 }
1070 }
1135 1071
1136 if (empty($_d)) {
1137 $d && rg_log('DEBUG: stream ' . $fd . ' returned no data.');
1138 // We exit only if we get EOF in stdout not on stderr
1139 if ($fd === $pipes[1])
1140 $do_break = TRUE;
1141 continue;
1142 }
1072 /*
1073 * Helper for rg_exec to close a stream
1074 */
1075 function rg_exec2_helper_close_stream($fd, $index, &$info, $stream)
1076 {
1077 global $rg_util_debug;
1143 1078
1144 if ($fd === $pipes[2]) {
1145 if ($cb_stderr === FALSE) {
1146 $d && rg_log('DEBUG: fd is pipes[2], append to stderr var: ' . $_d);
1147 $ret['stderr'] .= $_d;
1148 } else {
1149 $d && rg_log('DEBUG: fd is pipes[2], call stdout cb:' . $_d);
1150 $cb_stderr($_d);
1151 // We want the last error message to be able to log something
1152 $ret['stderr'] = $_d;
1153 }
1154 } else if ($fd === $pipes[1]) {
1155 if ($cb_stdout === FALSE) {
1156 $d && rg_log('DEBUG: fd is pipes[1], append to stdout var: ' . $_d);
1157 $ret['data'] .= $_d;
1158 } else {
1159 $d && rg_log('DEBUG: fd is pipes[1], call stdout cb: ' . $_d);
1160 $cb_stdout($_d);
1161 }
1162 } else {
1163 rg_internal_error('invalid fd');
1164 }
1165 }
1079 $rg_util_debug &&
1080 rg_log_enter($index . ' DEBUG: exec2_helper_close_stream: stream ' . $stream);
1166 1081
1167 if ($do_break || !empty($ret['errmsg']))
1168 break;
1169 }
1170 $ret['stderr'] = trim($ret['stderr']);
1171 $ret['data'] = trim($ret['data']);
1172
1173 for ($i = 0; $i < 3; $i++)
1174 if (isset($pipes[$i]))
1175 fclose($pipes[$i]);
1176
1177 $err = proc_close($a);
1178 if ($err != 0) {
1179 rg_log('DEBUG: exec returned ' . $err);
1180 $ret['code'] = $err;
1181 $ret['errmsg'] = 'task returned code ' . $err
1182 . ' (' . $ret['stderr'] . ')';
1183 break;
1184 }
1082 if ($stream == -1) {
1083 $info['output_done'] = 1;
1084 unset($info['input_fd']);
1085 } else {
1086 $info['closed'][$stream] = 1;
1087 unset($info['pipes'][$stream]);
1088 }
1185 1089
1186 //rg_log('DEBUG: exec returned ok');
1187 $ret['code'] = 0;
1188 $ret['ok'] = 1;
1189 break;
1090 $r = @fclose($fd);
1091 if ($r === FALSE)
1092 rg_log($index . ' Error closing stream ' . $stream
1093 . ' (' . rg_php_err() . ')');
1094
1095 if (($stream == 0) && isset($info['input_fd'])) {
1096 $rg_util_debug &&
1097 rg_log($index . ' DEBUG: closing stream 0 =>'
1098 . ' closing input_fd ' . $info['input_fd']);
1099 rg_exec2_helper_close_stream($info['input_fd'], $index, $info, -1);
1190 1100 } }
1191 1101
1102 $rg_util_debug &&
1192 1103 rg_log_exit(); rg_log_exit();
1193 rg_prof_end("exec");
1194 return $ret;
1195 1104 } }
1196 1105
1197 1106 /* /*
1198 1107 * This will replace rg_exec function * This will replace rg_exec function
1108 * Returns the array of the commands with the last status.
1199 1109 */ */
1200 function rg_exec2(&$a)
1110 function rg_exec2($a)
1201 1111 { {
1202 1112 global $rg_util_debug; global $rg_util_debug;
1203 1113
 
... ... function rg_exec2(&$a)
1207 1117 $rg_util_debug && $rg_util_debug &&
1208 1118 rg_log_ml('DEBUG: a: ' . print_r($a, TRUE)); rg_log_ml('DEBUG: a: ' . print_r($a, TRUE));
1209 1119
1120 $ret = array();
1121 $ret['ok'] = 0;
1122 $ret['cmds'] = $a['cmds'];
1123
1210 1124 // some status initialization // some status initialization
1211 1125 $s = array(); $s = array();
1212 foreach ($a['cmds'] as $cmd => &$info) {
1213 if (!isset($info['restart_delay']))
1214 $info['restart_delay'] = 0;
1215 if (!isset($info['idle_time']))
1216 $info['idle_time'] = 5;
1217
1126 foreach ($ret['cmds'] as $cmd => &$info) {
1218 1127 $info['needs_start'] = TRUE; $info['needs_start'] = TRUE;
1219 $info['needs_stop'] = FALSE;
1220 $info['last_failure'] = 0;
1221 if (!isset($info['out_buf']))
1222 $info['out_buf'] = '';
1223 $info['in_buf'] = '';
1224 $info['err_buf'] = '';
1225 $info['done'] = FALSE;
1226 $info['last_activity'] = 0;
1227 1128 $info['stopped'] = TRUE; $info['stopped'] = TRUE;
1228 $info['closed'] = array(1 => 0, 2 => 0);
1129 $info['needs_stop'] = FALSE;
1130 rg_exec2_helper_init($info);
1229 1131 } }
1230 1132
1231 $ret = array();
1232 $ret['ok'] = 0;
1233 1133 while (1) { while (1) {
1234 1134 // check if all commands are started // check if all commands are started
1235 1135 $now = time(); $now = time();
1236 1136 $rx = array(); $wx = array(); $rx = array(); $wx = array();
1237 1137 $lut = array(); $lut = array();
1238 1138 $done = TRUE; $done = TRUE;
1239 foreach ($a['cmds'] as $index => &$info) {
1240 if (($info['closed'][1] == 1) && ($info['closed'][2] == 1)) {
1241 $rg_util_debug && rg_log('DEBUG: Both in streams are closed.');
1139 foreach ($ret['cmds'] as $index => &$info) {
1140 if ($info['closed'][0] + $info['closed'][1] + $info['closed'][2] == 3) {
1141 $rg_util_debug &&
1142 rg_log($index . ' DEBUG: All streams are closed.'
1143 . ' Set needs_stop to TRUE');
1242 1144 $info['needs_stop'] = TRUE; $info['needs_stop'] = TRUE;
1243 1145 } }
1244 1146
1245 1147 if ($info['needs_stop'] == TRUE) { if ($info['needs_stop'] == TRUE) {
1246 1148 $rg_util_debug && $rg_util_debug &&
1247 rg_log('DEBUG: index ' . $index . ' needs stop!');
1149 rg_log($index . ' DEBUG: needs stop is TRUE!');
1248 1150
1249 1151 $info['ps'] = @proc_get_status($info['a']); $info['ps'] = @proc_get_status($info['a']);
1250 1152 $rg_util_debug && $rg_util_debug &&
1251 rg_log_ml('DEBUG: info[ps][' . $index . ']: '
1153 rg_log_ml($index . ' DEBUG: info[ps]: '
1252 1154 . print_r($info['ps'], TRUE)); . print_r($info['ps'], TRUE));
1253 1155
1254 1156 if ($info['ps']['running'] === FALSE) { if ($info['ps']['running'] === FALSE) {
 
... ... function rg_exec2(&$a)
1258 1160 if (isset($info['pipes'][$i])) if (isset($info['pipes'][$i]))
1259 1161 fclose($info['pipes'][$i]); fclose($info['pipes'][$i]);
1260 1162
1163 if (isset($info['input_fd'])) {
1164 @fclose($info['input_fd']);
1165 unset($info['input_fd']);
1166 }
1167
1261 1168 $err = @proc_close($info['a']); $err = @proc_close($info['a']);
1262 if ($err != 0)
1169 if ($err != 0) {
1263 1170 $rg_util_debug && $rg_util_debug &&
1264 rg_log('DEBUG: proc_close returned ' . $err);
1171 rg_log($index . ' DEBUG: proc_close returned ' . $err);
1172 }
1173 // TODO: where should we use it?
1265 1174 $ec = 0; /* we are force closing program */ $ec = 0; /* we are force closing program */
1266 1175 } }
1267 1176
1177 if (($info['ps']['exitcode'] != 0) && empty($info['last_errmsg']))
1178 $info['last_errmsg'] = 'child exited with an error code';
1179
1268 1180 if (isset($info['cb_finish'])) if (isset($info['cb_finish']))
1269 1181 $info['cb_finish']($index, $info, $ec); $info['cb_finish']($index, $info, $ec);
1270 1182
 
... ... function rg_exec2(&$a)
1274 1186 $info['needs_stop'] = FALSE; $info['needs_stop'] = FALSE;
1275 1187 $info['stopped'] = TRUE; $info['stopped'] = TRUE;
1276 1188
1277 if (isset($info['restart_delay'])) {
1189 if (!isset($info['restart_delay'])) {
1278 1190 $rg_util_debug && $rg_util_debug &&
1279 rg_log('DEBUG: index ' . $index . ' has no restart flag => done = TRUE');
1191 rg_log($index . ' DEBUG: no restart flag => done = TRUE');
1280 1192 $info['done'] = TRUE; $info['done'] = TRUE;
1193 } else {
1194 rg_exec2_helper_init($info);
1281 1195 } }
1282 1196 } }
1283 1197
1284 1198 $rg_util_debug && $rg_util_debug &&
1285 rg_log('DEBUG: index=' . $index
1286 . ' done=' . ($info['done'] === TRUE ? 'true' : 'false'));
1199 rg_log($index . ' DEBUG:'
1200 . ' info[done]=' . ($info['done'] === TRUE ? 'true' : 'false'));
1287 1201 if ($info['done']) if ($info['done'])
1288 1202 continue; continue;
1289 1203
1204 $rg_util_debug &&
1205 rg_log($index . ' DEBUG: set done to FALSE');
1290 1206 $done = FALSE; $done = FALSE;
1291 1207
1292 1208 if ($info['needs_start'] == TRUE) { if ($info['needs_start'] == TRUE) {
1293 $done = FALSE;
1209 $restart_delay = isset($info['restart_delay']) ? $info['restart_delay'] : 0;
1294 1210
1295 if ($info['last_failure'] + $info['restart_delay'] > $now)
1211 if ($info['last_failure'] + $restart_delay > $now)
1296 1212 continue; continue;
1297 1213
1298 1214 $rg_util_debug && $rg_util_debug &&
1299 rg_log('DEBUG: Running [' . $info['cmd'] . ']');
1215 rg_log($index . ' DEBUG: Running [' . $info['cmd'] . ']');
1300 1216 $desc = array( $desc = array(
1301 0 => array("pipe", "r"),
1217 0 => array('pipe', 'r'),
1302 1218 1 => array('pipe', 'w'), 1 => array('pipe', 'w'),
1303 1219 2 => array("pipe", "w") 2 => array("pipe", "w")
1304 1220 ); );
 
... ... function rg_exec2(&$a)
1313 1229 } }
1314 1230
1315 1231 $rg_util_debug && $rg_util_debug &&
1316 rg_log_ml('DEBUG: proc_open pipes: '
1317 . print_r($info['pipes'], TRUE));
1318 $info['needs_start'] = FALSE;
1319 $info['start_ts'] = time();
1232 rg_log($index . ' DEBUG: proc_open pipes: '
1233 . rg_array2string($info['pipes']));
1234
1320 1235 $info['stopped'] = FALSE; $info['stopped'] = FALSE;
1321 $info['last_errmsg'] = '';
1322 $info['closed'][1] = 0;
1323 $info['closed'][2] = 0;
1236 $info['needs_start'] = FALSE;
1237
1238 // cb_output can populate $info['out_buf']
1239 if (isset($info['cb_output'])) {
1240 $rg_util_debug &&
1241 rg_log($index . ' DEBUG: calling cb_output (first)...');
1242 $info['cb_output']($index, $info);
1243 }
1324 1244 } }
1325 1245
1326 1246 if ($info['stopped']) { if ($info['stopped']) {
1327 1247 $rg_util_debug && $rg_util_debug &&
1328 rg_log('DEBUG: index ' . $index. ' is stopped');
1248 rg_log($index . ' DEBUG: stopped is TRUE');
1329 1249 continue; continue;
1330 1250 } }
1331 1251
 
... ... function rg_exec2(&$a)
1335 1255 && ($info['last_activity'] > 0) && ($info['last_activity'] > 0)
1336 1256 && ($info['last_activity'] + $info['idle_time'] <= time())) { && ($info['last_activity'] + $info['idle_time'] <= time())) {
1337 1257 $rg_util_debug && $rg_util_debug &&
1338 rg_log('DEBUG: IDLE: ' . $index
1258 rg_log($index . ' DEBUG: IDLE:'
1339 1259 . ' last_activity=' . $info['last_activity'] . ' last_activity=' . $info['last_activity']
1340 1260 . ' now=' . time()); . ' now=' . time());
1341 1261 $info['cb_idle']($index, $info); $info['cb_idle']($index, $info);
1342 1262 } }
1343 1263
1344 if ($info['closed'][1] == 0) $rx[] = $info['pipes'][1];
1345 if ($info['closed'][2] == 0) $rx[] = $info['pipes'][2];
1346
1347 if (isset($info['cb_output']) || !empty($info['out_buf'])) {
1264 if (!empty($info['out_buf'])) {
1348 1265 $rg_util_debug && $rg_util_debug &&
1349 rg_log('DEBUG: We have cb_output or data in out_buf, enable write notification!');
1266 rg_log($index . ' DEBUG: enable write notification!');
1267
1350 1268 $wx[] = $info['pipes'][0]; $wx[] = $info['pipes'][0];
1269 } else if (($info['output_done'] == 1) && ($info['closed'][0] == 0)) {
1270 $rg_util_debug &&
1271 rg_log($index . ' DEBUG: No output available'
1272 . ', close output ' . $info['pipes'][0]);
1273 rg_exec2_helper_close_stream($info['pipes'][0], $index, $info, 0);
1351 1274 } }
1352 1275
1276 if ($info['closed'][1] == 0) $rx[] = $info['pipes'][1];
1277 if ($info['closed'][2] == 0) $rx[] = $info['pipes'][2];
1278 if (isset($info['input_fd']))
1279 $rx[] = $info['input_fd'];
1280
1353 1281 for ($i = 0; $i <= 2; $i++) { for ($i = 0; $i <= 2; $i++) {
1282 if (!isset($info['pipes'][$i]))
1283 continue;
1284
1354 1285 $k = intval($info['pipes'][$i]); $k = intval($info['pipes'][$i]);
1355 $lut[$k] = array('index' => $index, 'stream' => $i);
1286 $lut[$k] = array('index' => $index,
1287 'stream' => $i);
1288 }
1289
1290 if (isset($info['input_fd'])) {
1291 $k = intval($info['input_fd']);
1292 $lut[$k] = array('index' => $index,
1293 'stream' => -1);
1356 1294 } }
1357 1295 } }
1358 1296 if ($done) { if ($done) {
 
... ... function rg_exec2(&$a)
1364 1302
1365 1303 if (empty($rx) && empty($wx)) { if (empty($rx) && empty($wx)) {
1366 1304 $rg_util_debug && $rg_util_debug &&
1367 rg_log('DEBUG: No events... sleeping');
1305 rg_log('DEBUG: No r/w events; sleeping...');
1368 1306 sleep(1); sleep(1);
1369 1307 continue; continue;
1370 1308 } }
 
... ... function rg_exec2(&$a)
1372 1310 $revents = $rx; $revents = $rx;
1373 1311 $wevents = $wx; $wevents = $wx;
1374 1312 $ex = NULL; $ex = NULL;
1375 $rg_util_debug && rg_log('DEBUG: before stream_select:');
1376 $rg_util_debug && !empty($revents) && rg_log_ml('revents: ' . trim(print_r($revents, TRUE)));
1377 $rg_util_debug && !empty($wevents) && rg_log_ml('wevents: ' . trim(print_r($wevents, TRUE)));
1313 $rg_util_debug && rg_log('DEBUG: before stream_select:'
1314 . (empty($revents) ? '' : ' revents:' . rg_array2string($revents))
1315 . (empty($wevents) ? '' : ' wevents:' . rg_array2string($wevents)));
1378 1316 $r = stream_select($revents, $wevents, $ex, 1, 0); $r = stream_select($revents, $wevents, $ex, 1, 0);
1379 1317 if ($r === FALSE) { if ($r === FALSE) {
1380 1318 $ret['errmsg'] = "cannot select"; $ret['errmsg'] = "cannot select";
1381 1319 break; break;
1382 1320 } }
1383 1321
1384 if (isset($a['cb_tick']))
1385 $a['cb_tick']($a);
1322 $rg_util_debug && (!empty($revents) || !empty($wevents) || !empty($ex)) &&
1323 rg_log('DEBUG: after stream_select:'
1324 . (empty($revents) ? '' : ' revents:' . rg_array2string($revents))
1325 . (empty($wevents) ? '' : ' wevents:' . rg_array2string($wevents))
1326 . (empty($ex) ? '' : ' ex:' . rg_array2string($ex)));
1386 1327
1387 1328 if ($r === 0) if ($r === 0)
1388 1329 continue; continue;
1389 1330
1390 $rg_util_debug && rg_log('DEBUG: stream_select returned ' . $r . ' events.');
1391 $rg_util_debug && !empty($revents) && rg_log_ml('revents: ' . trim(print_r($revents, TRUE)));
1392 $rg_util_debug && !empty($wevents) && rg_log_ml('wevents: ' . trim(print_r($wevents, TRUE)));
1393 $rg_util_debug && !empty($ex) && rg_log_ml('ex: ' . trim(print_r($ex, TRUE)));
1394
1395 1331 foreach ($wevents as $fd) { foreach ($wevents as $fd) {
1396 1332 $ifd = intval($fd); $ifd = intval($fd);
1397 1333 $index = $lut[$ifd]['index']; $index = $lut[$ifd]['index'];
1398 1334 $rg_util_debug && $rg_util_debug &&
1399 rg_log('DEBUG: write event on ifd ' . $ifd
1400 . ' index=' . $index . '!');
1335 rg_log($index . ' DEBUG: write event on ifd ' . $ifd);
1401 1336
1402 $info = &$a['cmds'][$index];
1337 $info = &$ret['cmds'][$index];
1403 1338
1404 1339 $rg_util_debug && $rg_util_debug &&
1405 rg_log('DEBUG: out_buf before cb: ' . $info['out_buf']);
1340 rg_log($index . ' DEBUG: out_buf before cb: ' . $info['out_buf']);
1406 1341
1407 // cb_output will populate $info['out_buf']
1408 if (isset($info['cb_output']))
1342 // cb_output can populate $info['out_buf']
1343 if (isset($info['cb_output'])) {
1344 $rg_util_debug &&
1345 rg_log($index . ' DEBUG: calling cb_output...');
1409 1346 $info['cb_output']($index, $info); $info['cb_output']($index, $info);
1347 }
1410 1348
1411 1349 if (empty($info['out_buf'])) { if (empty($info['out_buf'])) {
1412 1350 $rg_util_debug && $rg_util_debug &&
1413 rg_log_ml('DEBUG: out_buf is empty!' . print_r($info, TRUE));
1351 rg_log_ml($index . ' DEBUG: out_buf is empty!'
1352 . ' info: ' . print_r($info, TRUE));
1414 1353 continue; continue;
1415 1354 } }
1416 1355
1417 1356 $rg_util_debug && $rg_util_debug &&
1418 rg_log('DEBUG: SENDING: [' . $info['out_buf'] . ']');
1357 rg_log($index . ' DEBUG: send: [' . $info['out_buf'] . ']');
1419 1358 $r = @fwrite($fd, $info['out_buf']); $r = @fwrite($fd, $info['out_buf']);
1420 1359 if ($r === FALSE) { if ($r === FALSE) {
1421 1360 $info['last_errmsg'] = 'cannot write'; $info['last_errmsg'] = 'cannot write';
1422 1361 if (isset($info['cb_error'])) if (isset($info['cb_error']))
1423 1362 $info['cb_error']($index, $info, $info['last_errmsg']); $info['cb_error']($index, $info, $info['last_errmsg']);
1363 else
1364 rg_log($index . ' fwrite returned FALSE');
1424 1365 $info['needs_stop'] = TRUE; $info['needs_stop'] = TRUE;
1425 1366 continue; continue;
1426 1367 } }
1427 1368 $rg_util_debug && $rg_util_debug &&
1428 rg_log('DEBUG: fwrite returned ' . $r . '.');
1369 rg_log($index . ' DEBUG: fwrite returned ' . $r . '.');
1429 1370 $info['out_buf'] = substr($info['out_buf'], $r); $info['out_buf'] = substr($info['out_buf'], $r);
1430 1371 } }
1431 1372
 
... ... function rg_exec2(&$a)
1434 1375 $index = $lut[$ifd]['index']; $index = $lut[$ifd]['index'];
1435 1376 $stream = $lut[$ifd]['stream']; $stream = $lut[$ifd]['stream'];
1436 1377 $rg_util_debug && $rg_util_debug &&
1437 rg_log('DEBUG: read event on ifd ' . $ifd
1438 . ' index=' . $index . ', stream=' . $stream . '!');
1378 rg_log($index . ' DEBUG: read event on ifd ' . $ifd
1379 . ', stream=' . $stream . '!');
1439 1380
1440 $info = &$a['cmds'][$index];
1381 $info = &$ret['cmds'][$index];
1441 1382
1442 1383 $_d = @fread($fd, 32 * 4096); $_d = @fread($fd, 32 * 4096);
1443 1384 if ($_d === FALSE) { if ($_d === FALSE) {
1444 1385 $rg_util_debug && $rg_util_debug &&
1445 rg_log('DEBUG: ifd ' . $ifd . ' fread returned FALSE');
1386 rg_log($index . ' DEBUG: ifd ' . $ifd . ' fread returned FALSE');
1446 1387 $info['last_errmsg'] = 'cannot read'; $info['last_errmsg'] = 'cannot read';
1447 1388 if (isset($info['cb_error'])) if (isset($info['cb_error']))
1448 1389 $info['cb_error']($index, $info, $info['last_errmsg']); $info['cb_error']($index, $info, $info['last_errmsg']);
 
... ... function rg_exec2(&$a)
1452 1393
1453 1394 if (empty($_d)) { if (empty($_d)) {
1454 1395 $rg_util_debug && $rg_util_debug &&
1455 rg_log('DEBUG: ifd ' . $ifd . ' returned no data.');
1456 $info['closed'][$stream] = 1;
1396 rg_log($index . ' DEBUG: ifd ' . $ifd . ' returned no data.');
1397 rg_exec2_helper_close_stream($fd, $index, $info, $stream);
1457 1398 continue; continue;
1458 1399 } }
1459 1400
1460 $info['last_activity'] = time();
1461 1401 $rg_util_debug && $rg_util_debug &&
1462 rg_log('DEBUG: index ' . $index . ': set last_activity to ' . $info['last_activity']);
1402 rg_log($index . ' DEBUG: fread [stream ' . $stream . '] returned ['
1403 . $_d . ']');
1404
1405 $info['last_activity'] = time();
1463 1406
1464 1407 switch ($stream) { switch ($stream) {
1408 case -1: $info['out_buf'] .= $_d; break;
1465 1409 case 1: $info['in_buf'] .= $_d; break; case 1: $info['in_buf'] .= $_d; break;
1466 1410 case 2: $info['err_buf'] .= $_d; break; case 2: $info['err_buf'] .= $_d; break;
1467 1411 } }
 
... ... function rg_exec2(&$a)
1469 1413 if (isset($info['cb_input'])) if (isset($info['cb_input']))
1470 1414 $info['cb_input']($index, $info, $stream); $info['cb_input']($index, $info, $stream);
1471 1415 } }
1416
1417 foreach ($ret['cmds'] as $index => &$info)
1418 if (isset($info['cb_tick']))
1419 $info['cb_tick']($index, $info);
1472 1420 } }
1473 1421
1474 1422 rg_log_exit(); rg_log_exit();
 
... ... function rg_exec2(&$a)
1476 1424 return $ret; return $ret;
1477 1425 } }
1478 1426
1427 /*
1428 * Helper for rg_exec
1429 */
1430 function rg_exec_helper_data($index, &$a, $stream)
1431 {
1432 rg_log('DEBUG: rg_exec_helper_data[' . $index . '] stream=' . $stream);
1433 switch ($stream) {
1434 case 1: $a['my_data_out']($a['in_buf']); $a['in_buf'] = ''; break;
1435 case 1: $a['my_err_out']($a['err_buf']); $a['err_buf'] = ''; break;
1436 }
1437 }
1438
1439 /*
1440 * Helper for rg_exec
1441 */
1442 function rg_exec_helper_output($index, &$a)
1443 {
1444 return $a['my_data_in']();
1445 }
1446
1447 /*
1448 * Execute $cmd and returns the output as a string, binary safe
1449 * @input: some data to be sent to the process and received as stdin
1450 * @cb_stdin - call back used to pass data frou our stdin to the process
1451 * ifa @cb_stdin is false, it is not called; if is 0, STDIN will be used.
1452 * @cb_stdout - call back called when there is something to be send to our stdout
1453 * if @cb_stdout is FALSE, stdout output will be returned in $ret['data']
1454 * cb_stderr - call back called when there is something to be sent to our stderr
1455 * if @cb_stderr is FALSE, stderr output will be returned in $ret['stderr']
1456 */
1457 function rg_exec($cmd, $input, $cb_stdin, $cb_stdout, $cb_stderr)
1458 {
1459 $ret = array();
1460 $ret['ok'] = 0;
1461 while(1) {
1462 $ret['errmsg'] = '';
1463 $ret['code'] = 65000; // fake code
1464 $ret['data'] = '';
1465 $ret['stderr'] = '';
1466
1467 $a = array('cmds' => array(
1468 'cmd1' => array(
1469 'cmd' => $cmd,
1470 'out_buf' => $input
1471 )
1472 )
1473 );
1474
1475 if ($cb_stdin === 0) {
1476 $a['cmds']['cmd1']['input_fd'] = @fopen('php://stdin', 'rb');
1477 if ($a['cmds']['cmd1']['input_fd'] === FALSE) {
1478 $ret['errmsg'] = 'cannot open stdin';
1479 break;
1480 }
1481 } else if ($cb_stdin !== FALSE) {
1482 $a['cmds']['cmd1']['my_data_in'] = $cb_stdin;
1483 $a['cmds']['cmd1']['cb_output'] = 'rg_exec_helper_output';
1484 }
1485
1486 if ($cb_stdout !== FALSE) {
1487 $a['cmds']['cmd1']['my_data_out'] = $cb_stdout;
1488 $a['cmds']['cmd1']['cb_input'] = 'rg_exec_helper_data';
1489 }
1490
1491 if ($cb_stderr !== FALSE) {
1492 $a['cmds']['cmd1']['my_err_out'] = $cb_stderr;
1493 $a['cmds']['cmd1']['cb_input'] = 'rg_exec_helper_data';
1494 }
1495
1496 $r = rg_exec2($a);
1497 if ($r['ok'] != 1) {
1498 $ret['errmsg'] = $r['errmsg'];
1499 break;
1500 }
1501
1502 $ret['code'] = $r['cmds']['cmd1']['ps']['exitcode'];
1503 $ret['data'] = $r['cmds']['cmd1']['in_buf'];
1504 $ret['stderr'] = $r['cmds']['cmd1']['err_buf'];
1505 $ret['errmsg'] = $r['cmds']['cmd1']['last_errmsg'];
1506
1507 if ($ret['code'] == 0)
1508 $ret['ok'] = 1;
1509 break;
1510 }
1511
1512 return $ret;
1513 }
1514
1479 1515 /* /*
1480 1516 * Force browser to redirect to another page * Force browser to redirect to another page
1481 1517 */ */
File scripts/worker.php changed (mode: 100644) (index c0172c2..046554f)
... ... function reload_config()
101 101 $cmd = 'ssh-keygen -t rsa -b 4096 -N \'\'' $cmd = 'ssh-keygen -t rsa -b 4096 -N \'\''
102 102 . ' -C \'Key to connect to builder\'' . ' -C \'Key to connect to builder\''
103 103 . ' -f ' . escapeshellarg($conf['state'] . '/key'); . ' -f ' . escapeshellarg($conf['state'] . '/key');
104 $r = rg_exec($cmd, '', FALSE, FALSE);
104 $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
105 105 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
106 106 rg_log('Cannot create key: ' . $r['errmsg'] . '!'); rg_log('Cannot create key: ' . $r['errmsg'] . '!');
107 107 sleep(60); sleep(60);
 
... ... function start_worker($job)
141 141 $do_umount = FALSE; $do_umount = FALSE;
142 142 $err = TRUE; $err = TRUE;
143 143 while (1) { while (1) {
144 rg_exec('virsh destroy ' . $ename, '', FALSE, FALSE);
145 rg_exec('virsh undefine ' . $ename, '', FALSE, FALSE);
144 rg_exec('virsh destroy ' . $ename, '', FALSE, FALSE, FALSE);
145 rg_exec('virsh undefine ' . $ename, '', FALSE, FALSE, FALSE);
146 146
147 147 $r = rg_del_tree($job['main']); $r = rg_del_tree($job['main']);
148 148 if ($r === FALSE) { if ($r === FALSE) {
 
... ... function start_worker($job)
159 159
160 160 // We need to allow libvirt access to the image // We need to allow libvirt access to the image
161 161 $r = rg_exec('chown qemu:qemu ' $r = rg_exec('chown qemu:qemu '
162 . escapeshellarg($job['main']), '', FALSE, FALSE);
162 . escapeshellarg($job['main']), '', FALSE, FALSE, FALSE);
163 163 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
164 164 $reason = 'cannot chown build dir to qemu user: ' . $r['errmsg']; $reason = 'cannot chown build dir to qemu user: ' . $r['errmsg'];
165 165 break; break;
 
... ... function start_worker($job)
175 175 } }
176 176
177 177 $r = rg_exec('qemu-img create -b ' . $master $r = rg_exec('qemu-img create -b ' . $master
178 . ' -f qcow2 ' . $img, '', FALSE, FALSE);
178 . ' -f qcow2 ' . $img, '', FALSE, FALSE, FALSE);
179 179 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
180 180 $reason = 'cannot create image: ' . $r['errmsg']; $reason = 'cannot create image: ' . $r['errmsg'];
181 181 break; break;
182 182 } }
183 183
184 $r = rg_exec('qemu-img create -f raw ' . $img2 . ' 1G', '',
185 FALSE, FALSE);
184 $r = rg_exec('qemu-img create -f raw ' . $img2 . ' 1G',
185 '', FALSE, FALSE, FALSE);
186 186 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
187 187 $reason = 'cannot create image2: ' . $r['errmsg']; $reason = 'cannot create image2: ' . $r['errmsg'];
188 188 break; break;
 
... ... function start_worker($job)
192 192 $path = getenv('PATH'); $path = getenv('PATH');
193 193 putenv('PATH=' . $path . ':/usr/sbin'); putenv('PATH=' . $path . ':/usr/sbin');
194 194
195 $r = rg_exec('mkfs.ext4 -L RG ' . $img2, '', FALSE, FALSE);
195 $r = rg_exec('mkfs.ext4 -L RG ' . $img2, '', FALSE, FALSE, FALSE);
196 196 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
197 197 $reason = 'cannot create fs: ' . $r['errmsg']; $reason = 'cannot create fs: ' . $r['errmsg'];
198 198 break; break;
 
... ... function start_worker($job)
204 204 break; break;
205 205 } }
206 206
207 $r = rg_exec('mount ' . $img2 . ' ' . $emain . '/root', '',
208 FALSE, FALSE);
207 $r = rg_exec('mount ' . $img2 . ' ' . $emain . '/root',
208 '', FALSE, FALSE, FALSE);
209 209 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
210 210 $reason = 'cannot mount fs: ' . $r['errmsg']; $reason = 'cannot mount fs: ' . $r['errmsg'];
211 211 break; break;
 
... ... function start_worker($job)
224 224 $cmd = ' git clone --depth 1' $cmd = ' git clone --depth 1'
225 225 . ' ' . escapeshellarg($job['url']) . ' ' . escapeshellarg($job['url'])
226 226 . ' ' . $emain . '/root/git'; . ' ' . $emain . '/root/git';
227 $r = rg_exec($cmd, '', FALSE, FALSE);
227 $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
228 228 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
229 229 $reason = 'cannot clone: ' . $r['errmsg']; $reason = 'cannot clone: ' . $r['errmsg'];
230 230 break; break;
 
... ... function start_worker($job)
324 324 break; break;
325 325 } }
326 326
327 $r = rg_exec('umount ' . $emain . '/root', '', FALSE, FALSE);
327 $r = rg_exec('umount ' . $emain . '/root', '', FALSE, FALSE, FALSE);
328 328 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
329 329 $reason = 'cannot umount fs: ' . $r['errmsg']; $reason = 'cannot umount fs: ' . $r['errmsg'];
330 330 break; break;
 
... ... function start_worker($job)
332 332 $do_umount = FALSE; $do_umount = FALSE;
333 333
334 334 // We need to allow libvirt access to the image // We need to allow libvirt access to the image
335 $r = rg_exec('chown qemu:qemu ' . $img2, '', FALSE, FALSE);
335 $r = rg_exec('chown qemu:qemu ' . $img2, '', FALSE, FALSE, FALSE);
336 336 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
337 337 $reason = 'cannot chown image to qemu user: ' . $r['errmsg']; $reason = 'cannot chown image to qemu user: ' . $r['errmsg'];
338 338 break; break;
 
... ... function start_worker($job)
358 358 . ' --rng /dev/random' . ' --rng /dev/random'
359 359 . ' --memballoon virtio' . ' --memballoon virtio'
360 360 . ' --console pty,target_type=virtio' . ' --console pty,target_type=virtio'
361 . ' ' . $env['paras'], '', FALSE, FALSE);
361 . ' ' . $env['paras'], '', FALSE, FALSE, FALSE);
362 362 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
363 363 $reason = 'cannot define and start virtual machine: ' $reason = 'cannot define and start virtual machine: '
364 364 . $r['errmsg']; . $r['errmsg'];
 
... ... function start_worker($job)
369 369 break; break;
370 370 } }
371 371 if ($do_umount) if ($do_umount)
372 rg_exec('umount ' . $emain . '/root', '', FALSE, FALSE);
372 rg_exec('umount ' . $emain . '/root', '', FALSE, FALSE, FALSE);
373 373
374 374 // Seems that any error above must retrigger the build on other worker // Seems that any error above must retrigger the build on other worker
375 375 if ($err) if ($err)
 
... ... function rg_job_extract_info(&$job)
478 478 } }
479 479
480 480 $cmd = 'mount ' . $emain . '/image2.raw ' . $emain . '/root'; $cmd = 'mount ' . $emain . '/image2.raw ' . $emain . '/root';
481 $r = rg_exec($cmd, '', FALSE, FALSE);
481 $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
482 482 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
483 483 $job['error'] = 'Could not mount image: ' . $r['errmsg']; $job['error'] = 'Could not mount image: ' . $r['errmsg'];
484 484 break; break;
 
... ... function rg_job_extract_info(&$job)
520 520 unset($job['env']); unset($job['env']);
521 521
522 522 $cmd = 'umount ' . $emain . '/root'; $cmd = 'umount ' . $emain . '/root';
523 $r = rg_exec($cmd, '', FALSE, FALSE);
523 $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
524 524 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
525 525 rg_log('Cannot unmount: ' . $r['errmsg'] . '!'); rg_log('Cannot unmount: ' . $r['errmsg'] . '!');
526 526 break; break;
 
... ... while(1) {
630 630
631 631 // TODO: do we destroy the pool in case of crash? // TODO: do we destroy the pool in case of crash?
632 632 $cmd = 'virsh pool-destroy rocketgit-j-' . $jid; $cmd = 'virsh pool-destroy rocketgit-j-' . $jid;
633 $r = rg_exec($cmd, '', FALSE, FALSE);
633 $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
634 634 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
635 635 $job['error'] = 'Could not destroy pool: ' . $r['errmsg']; $job['error'] = 'Could not destroy pool: ' . $r['errmsg'];
636 636 rg_log('Error: ' . $job['error']); rg_log('Error: ' . $job['error']);
 
... ... while(1) {
639 639
640 640 // TODO: do we clean the pool in case of crash? // TODO: do we clean the pool in case of crash?
641 641 // $cmd = 'virsh pool-undefine rocketgit-j-' . $jid; // $cmd = 'virsh pool-undefine rocketgit-j-' . $jid;
642 // $r = rg_exec($cmd, '', FALSE, FALSE);
642 // $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
643 643 // if ($r['ok'] != 1) { // if ($r['ok'] != 1) {
644 644 // $job['error'] = 'Could not undefine pool: ' . $r['errmsg']; // $job['error'] = 'Could not undefine pool: ' . $r['errmsg'];
645 645 // rg_log('Error: ' . $job['error']); // rg_log('Error: ' . $job['error']);
 
... ... while(1) {
648 648
649 649 // // TODO: do we clean the machine in case of crash? // // TODO: do we clean the machine in case of crash?
650 650 // $cmd = 'virsh undefine rg-worker-' . escapeshellarg($jid); // $cmd = 'virsh undefine rg-worker-' . escapeshellarg($jid);
651 // $r = rg_exec($cmd, '', FALSE, FALSE);
651 // $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
652 652 // if ($r['ok'] != 1) { // if ($r['ok'] != 1) {
653 653 // $job['error'] = 'Could not undefine machine: ' . $r['errmsg']; // $job['error'] = 'Could not undefine machine: ' . $r['errmsg'];
654 654 // rg_log('Error: ' . $job['error']); // rg_log('Error: ' . $job['error']);
 
... ... while(1) {
656 656 // } // }
657 657
658 658 // $cmd = 'virsh destroy rocketgit-j-' . $jid; // $cmd = 'virsh destroy rocketgit-j-' . $jid;
659 // $r = rg_exec($cmd, '', FALSE, FALSE);
659 // $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
660 660 // if ($r['ok'] != 1) { // if ($r['ok'] != 1) {
661 661 // $job['error'] = 'Could not destroy: ' . $r['errmsg']; // $job['error'] = 'Could not destroy: ' . $r['errmsg'];
662 662 // rg_log('Error: ' . $job['error']); // rg_log('Error: ' . $job['error']);
File tests/ask_pass_empty copied from file tests/ask_pass_guest (similarity 87%) (mode: 100755) (index f21bdcf..7c5de00)
1 1 #!/bin/bash #!/bin/bash
2 2
3 3 if [ "${1:0:8}" = "Username" ]; then if [ "${1:0:8}" = "Username" ]; then
4 echo -n "guest"
4 echo -n ""
5 5 fi fi
6 6
7 7 if [ "${1:0:8}" = "Password" ]; then if [ "${1:0:8}" = "Password" ]; then
File tests/by_http.php changed (mode: 100644) (index 3536aa2..12fdd6c)
... ... $a = rg_exec('rm -rf .by_http'
52 52 . ' && git remote add private_repo_git ' . escapeshellarg($repo2['clone_url_git']) . ' && git remote add private_repo_git ' . escapeshellarg($repo2['clone_url_git'])
53 53 . ' && echo "a signature" > a' . ' && echo "a signature" > a'
54 54 . ' && git add a' . ' && git add a'
55 . ' && git commit -a -m "' . $commit_body . '"', '', FALSE, FALSE);
55 . ' && git commit -a -m "' . $commit_body . '"',
56 '', FALSE, FALSE, FALSE);
56 57 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
57 58 rg_log("Something wrong generating the git repo: " . $a['stderr']); rg_log("Something wrong generating the git repo: " . $a['stderr']);
58 59 exit(1); exit(1);
 
... ... if ($a['ok'] != 1) {
60 61
61 62
62 63 rg_log(''); rg_log('');
63 rg_log_enter('Trying to push to public (without user/pass)...');
64 rg_log_enter('Trying to push to public (empty user)...');
65 putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass_empty');
66 $r = rg_exec('cd .by_http && git push public_repo master',
67 '', FALSE, FALSE, FALSE);
68 if ($r['ok'] == 1) {
69 rg_log_ml('r: ' . print_r($r, TRUE));
70 rg_log('Seems I can push with empty user!');
71 exit(1);
72 }
73 if (!strstr($r['stderr'], 'Authentication failed')) {
74 rg_log_ml('r: ' . print_r($r, TRUE));
75 rg_log('The stderr does not contain \'Authentication failed\'!');
76 exit(1);
77 }
78 rg_log_exit();
79
80
81 rg_log('');
82 rg_log_enter('Trying to push to public (with guest)...');
64 83 putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass_guest'); putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass_guest');
65 $r = rg_exec('cd .by_http && git push public_repo master', '', FALSE, FALSE);
84 $r = rg_exec('cd .by_http && git push public_repo master',
85 '', FALSE, FALSE, FALSE);
66 86 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
67 87 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
68 88 rg_log('Seems I cannot push without authentication (anonymous push)!'); rg_log('Seems I cannot push without authentication (anonymous push)!');
 
... ... rg_log_exit();
79 99 rg_log(''); rg_log('');
80 100 rg_log_enter('Trying to push to public (with user/pass)...'); rg_log_enter('Trying to push to public (with user/pass)...');
81 101 putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass');
82 $r = rg_exec('cd .by_http && strace -s2000 -f -tt -o by_http.strace git push --verbose public_repo master', '', FALSE, FALSE);
102 $r = rg_exec('cd .by_http && git push --verbose public_repo master',
103 '', FALSE, FALSE, FALSE);
83 104 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
84 105 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
85 106 rg_log('Seems I cannot push with authentication!'); rg_log('Seems I cannot push with authentication!');
 
... ... rg_log_exit();
91 112 rg_log(''); rg_log('');
92 113 rg_log_enter('Trying to fetch from public (with user/pass)...'); rg_log_enter('Trying to fetch from public (with user/pass)...');
93 114 putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass');
94 $r = rg_exec('cd .by_http && strace -s2000 -f -tt -o by_http.strace git fetch --verbose public_repo master', '', FALSE, FALSE);
115 $r = rg_exec('cd .by_http && git fetch --verbose public_repo master',
116 '', FALSE, FALSE, FALSE);
95 117 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
96 118 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
97 119 rg_log('Seems I cannot fetch with authentication!'); rg_log('Seems I cannot fetch with authentication!');
 
... ... rg_log_exit();
102 124
103 125 rg_log(''); rg_log('');
104 126 rg_log_enter('Trying to fetch from private (by git://)...'); rg_log_enter('Trying to fetch from private (by git://)...');
105 $r = rg_exec('cd .by_http && strace -s2000 -f -tt -o fetch_by_git.strace'
106 . ' git fetch --verbose private_repo_git master', '', FALSE, FALSE);
127 $r = rg_exec('cd .by_http && git fetch --verbose private_repo_git master',
128 '', FALSE, FALSE, FALSE);
107 129 if ($r['ok'] == 1) { if ($r['ok'] == 1) {
108 130 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
109 131 rg_log('Seems I can fetch by git://!'); rg_log('Seems I can fetch by git://!');
 
... ... rg_log_exit();
113 135
114 136
115 137 rg_log(''); rg_log('');
116 rg_log_enter('Trying to push to private (without user/pass)...');
138 rg_log_enter('Trying to push to private (guest user)...');
117 139 putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass_guest'); putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass_guest');
118 $r = rg_exec('cd .by_http && strace -s2000 -f -tt -o push_no_user.strace'
119 . ' git push --verbose private_repo master', '', FALSE, FALSE);
140 $r = rg_exec('cd .by_http && git push --verbose private_repo master',
141 '', FALSE, FALSE, FALSE);
120 142 if ($r['ok'] == 1) { if ($r['ok'] == 1) {
121 143 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
122 144 rg_log('Seems I can push without authentication (anonymous push)!'); rg_log('Seems I can push without authentication (anonymous push)!');
 
... ... rg_log_exit();
134 156 rg_log(''); rg_log('');
135 157 rg_log_enter('Trying to push to private (with user/pass)...'); rg_log_enter('Trying to push to private (with user/pass)...');
136 158 putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass');
137 $r = rg_exec('cd .by_http && strace -s2000 -f -tt -o push_with_user.strace'
138 . ' git push --verbose private_repo master', '', FALSE, FALSE);
159 $r = rg_exec('cd .by_http && git push --verbose private_repo master',
160 '', FALSE, FALSE, FALSE);
139 161 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
140 162 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
141 163 rg_log('Seems I cannot push with authentication!'); rg_log('Seems I cannot push with authentication!');
 
... ... rg_log_exit();
147 169 rg_log(''); rg_log('');
148 170 rg_log_enter('Trying to fetch from private (with user/pass)...'); rg_log_enter('Trying to fetch from private (with user/pass)...');
149 171 putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass');
150 $r = rg_exec('cd .by_http && strace -s2000 -f -tt -o x2.strace git fetch --verbose private_repo', '', FALSE, FALSE);
172 $r = rg_exec('cd .by_http && git fetch --verbose private_repo',
173 '', FALSE, FALSE, FALSE);
151 174 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
152 175 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
153 176 rg_log('Seems I cannot fetch with authentication!'); rg_log('Seems I cannot fetch with authentication!');
 
... ... rg_log('key: ' . $key);
166 189 rg_log(''); rg_log('');
167 190 rg_log_enter('Trying to push to public (with user/pass/login_token_missing)...'); rg_log_enter('Trying to push to public (with user/pass/login_token_missing)...');
168 191 putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass');
169 $r = rg_exec('cd .by_http && strace -s2000 -f -tt -o by_http.strace git push --verbose public_repo master', '', FALSE, FALSE);
192 $r = rg_exec('cd .by_http && git push --verbose public_repo master',
193 '', FALSE, FALSE, FALSE);
170 194 if ($r['ok'] !== 0) { if ($r['ok'] !== 0) {
171 195 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
172 196 rg_log('Seems I can push without passing login_token!'); rg_log('Seems I can push without passing login_token!');
 
... ... rg_log_exit();
178 202 rg_log(''); rg_log('');
179 203 rg_log_enter('Trying to fetch from public (with user/pass/login_token_missing)...'); rg_log_enter('Trying to fetch from public (with user/pass/login_token_missing)...');
180 204 putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass');
181 $r = rg_exec('cd .by_http && strace -s2000 -f -tt -o by_http.strace git fetch --verbose public_repo master', '', FALSE, FALSE);
205 $r = rg_exec('cd .by_http && git fetch --verbose public_repo master',
206 '', FALSE, FALSE, FALSE);
182 207 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
183 208 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
184 209 rg_log('Seems I cannot fetch without passing login_token!'); rg_log('Seems I cannot fetch without passing login_token!');
 
... ... rg_log('');
191 216 rg_log_enter('Trying to push to public (with user/pass/login_token_ok)...'); rg_log_enter('Trying to push to public (with user/pass/login_token_ok)...');
192 217 putenv('RG_LOGIN_TOKEN=' . rg_totp_compute($key, (time() - 30) / 30, 6)); putenv('RG_LOGIN_TOKEN=' . rg_totp_compute($key, (time() - 30) / 30, 6));
193 218 putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass');
194 $r = rg_exec('cd .by_http && strace -s2000 -f -tt -o by_http.strace git push --verbose public_repo master', '', FALSE, FALSE);
219 $r = rg_exec('cd .by_http && git push --verbose public_repo master',
220 '', FALSE, FALSE, FALSE);
195 221 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
196 222 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
197 223 rg_log('Seems I cannot push with authentication!'); rg_log('Seems I cannot push with authentication!');
 
... ... rg_log('');
204 230 rg_log_enter('Trying to fetch from public (with user/pass/login_token_ok)...'); rg_log_enter('Trying to fetch from public (with user/pass/login_token_ok)...');
205 231 putenv('RG_LOGIN_TOKEN=' . rg_totp_compute($key, (time() - 0) / 30, 6)); putenv('RG_LOGIN_TOKEN=' . rg_totp_compute($key, (time() - 0) / 30, 6));
206 232 putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass');
207 $r = rg_exec('cd .by_http && strace -s2000 -f -tt -o by_http.strace git fetch --verbose public_repo master', '', FALSE, FALSE);
233 $r = rg_exec('cd .by_http && git fetch --verbose public_repo master',
234 '', FALSE, FALSE, FALSE);
208 235 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
209 236 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
210 237 rg_log('Seems I cannot fetch with authentication!'); rg_log('Seems I cannot fetch with authentication!');
File tests/cache.php changed (mode: 100644) (index 00c2f1c..663c86d)
... ... if ($r !== $e) {
33 33 exit(1); exit(1);
34 34 } }
35 35
36 rg_log('');
37 rg_log('Testing unset on a dir (not value)...');
38 rg_cache_core_unset("a::b");
39 $r = rg_cache_core_get('a');
40 if (!empty($r)) {
41 rg_log_ml('rg_cache: ' . print_r($rg_cache, TRUE));
42 rg_log("unsetting a dir is not working!");
43 exit(1);
44 }
45
36 46 rg_log(''); rg_log('');
37 47 rg_log('Getting an invalid var...'); rg_log('Getting an invalid var...');
38 48 $e = FALSE; $e = FALSE;
 
... ... if ($r !== $e) {
44 54 } }
45 55
46 56 rg_log(''); rg_log('');
47 rg_log('Testing unsetting...');
57 rg_log('Testing unsetting of an invalid var...');
48 58 rg_cache_core_unset("x::y::z"); rg_cache_core_unset("x::y::z");
49 59 $e = FALSE; $e = FALSE;
50 60 $r = rg_cache_core_get("x::y::z"); $r = rg_cache_core_get("x::y::z");
File tests/common.php changed (mode: 100644) (index 38e7549..c27a36e)
... ... require_once($INC . "/sql.inc.php");
5 5 require_once($INC . "/struct.inc.php"); require_once($INC . "/struct.inc.php");
6 6 require_once($INC . "/fixes.inc.php"); require_once($INC . "/fixes.inc.php");
7 7
8 $rg_util_debug = TRUE;
9
8 10 rg_sql_app("rg-tests"); rg_sql_app("rg-tests");
9 11 $db = rg_sql_open($rg_sql); $db = rg_sql_open($rg_sql);
10 12 if ($db === FALSE) { if ($db === FALSE) {
 
... ... if ($db === FALSE) {
15 17 if (isset($rg_no_db) && $rg_no_db) if (isset($rg_no_db) && $rg_no_db)
16 18 return; return;
17 19
20
18 21 rg_log("Redo schema..."); rg_log("Redo schema...");
19 22
20 23 $r = rg_sql_struct_update($db, 0); $r = rg_sql_struct_update($db, 0);
File tests/export.php changed (mode: 100644) (index 624349c..11cc673)
... ... if ($r === FALSE) {
44 44 exit(1); exit(1);
45 45 } }
46 46
47 $a = rg_exec('cat export.json | json_verify', '', FALSE, FALSE);
47 $a = rg_exec('cat export.json | json_verify', '', FALSE, FALSE, FALSE);
48 48 if ($a['ok'] !== 1) { if ($a['ok'] !== 1) {
49 49 rg_log_ml(print_r($a, TRUE)); rg_log_ml(print_r($a, TRUE));
50 50 rg_log('Seems the JSON is not valid!'); rg_log('Seems the JSON is not valid!');
File tests/git.php changed (mode: 100644) (index d03fb99..7de37b4)
... ... $r = rg_exec('mkdir -p temp_repos'
28 28 . ' && cp a aclone && git add aclone' . ' && cp a aclone && git add aclone'
29 29 . ' && git mv b b2' . ' && git mv b b2'
30 30 . ' && git commit -a -m "bbb"', . ' && git commit -a -m "bbb"',
31 '', FALSE, FALSE);
31 '', FALSE, FALSE, FALSE);
32 32 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
33 33 rg_log('Could not exec repo script: ' . $r['errmsg'] . '!'); rg_log('Could not exec repo script: ' . $r['errmsg'] . '!');
34 34 exit(1); exit(1);
 
... ... $r = rg_exec('rm -rf temp_repos/git_bin'
83 83 . ' && seq 0 100 | while read a; do echo -en "\x`printf "%02x" ${a}`"; done > a' . ' && seq 0 100 | while read a; do echo -en "\x`printf "%02x" ${a}`"; done > a'
84 84 . ' && git add a && git commit -a -m "aaa"' . ' && git add a && git commit -a -m "aaa"'
85 85 . ' && echo -e \x0ff\x03\x90 > a && git commit -a -m "bbb"', . ' && echo -e \x0ff\x03\x90 > a && git commit -a -m "bbb"',
86 '', FALSE, FALSE);
86 '', FALSE, FALSE, FALSE);
87 87 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
88 88 rg_log('Could not exec repo script: ' . $r['errmsg'] . '!'); rg_log('Could not exec repo script: ' . $r['errmsg'] . '!');
89 89 exit(1); exit(1);
 
... ... $r = rg_exec('mkdir -p temp_repos && cd temp_repos'
183 183 . ' && echo -e "g" > a' . ' && echo -e "g" > a'
184 184 . ' && echo -e "gggg" > b' . ' && echo -e "gggg" > b'
185 185 . ' && git commit -a -m "ggg"', . ' && git commit -a -m "ggg"',
186 '', FALSE, FALSE);
186 '', FALSE, FALSE, FALSE);
187 187 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
188 188 rg_log('Could not exec repo script: ' . $r['errmsg'] . '!'); rg_log('Could not exec repo script: ' . $r['errmsg'] . '!');
189 189 exit(1); exit(1);
File tests/git2.php changed (mode: 100644) (index 40d9fc2..423f66b)
... ... $remote = 'ssh://rocketgit@' . $rg_ssh_host . ':' .$rg_ssh_port
68 68 . '/' . escapeshellarg($repo['name']); . '/' . escapeshellarg($repo['name']);
69 69 $r = rg_exec("cd git2 && git remote add origin $remote" $r = rg_exec("cd git2 && git remote add origin $remote"
70 70 . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2 -o IdentitiesOnly=yes\"" . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2 -o IdentitiesOnly=yes\""
71 . " && git push origin master", '', FALSE, FALSE);
71 . " && git push origin master",
72 '', FALSE, FALSE, FALSE);
72 73 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
73 74 rg_log_ml('out: ' . $r['errmsg']); rg_log_ml('out: ' . $r['errmsg']);
74 75 rg_log("Seems I cannot push master! err=$err"); rg_log("Seems I cannot push master! err=$err");
 
... ... rg_log('');
81 82 rg_log_enter('Trying to push tags...'); rg_log_enter('Trying to push tags...');
82 83 $r = rg_exec("cd git2" $r = rg_exec("cd git2"
83 84 . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2 -o IdentitiesOnly=yes\"" . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2 -o IdentitiesOnly=yes\""
84 . " && git push --tags origin", '', FALSE, FALSE);
85 . " && git push --tags origin",
86 '', FALSE, FALSE, FALSE);
85 87 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
86 88 rg_log_ml('error: ' . $r['errmsg']); rg_log_ml('error: ' . $r['errmsg']);
87 89 rg_log("Seems I cannot push tags!"); rg_log("Seems I cannot push tags!");
 
... ... rg_log_enter('Delete a branch must make it disappear also from web...');
127 129 $r = rg_exec("cd git2" $r = rg_exec("cd git2"
128 130 . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2 -o IdentitiesOnly=yes\"" . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2 -o IdentitiesOnly=yes\""
129 131 . " && git checkout -b branch22" . " && git checkout -b branch22"
130 . " && git push origin branch22", '', FALSE, FALSE);
132 . " && git push origin branch22",
133 '', FALSE, FALSE, FALSE);
131 134 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
132 135 rg_log_ml('out: ' . $r['errmsg']); rg_log_ml('out: ' . $r['errmsg']);
133 136 rg_log("Seems I cannot push branch22! err=$err"); rg_log("Seems I cannot push branch22! err=$err");
 
... ... if ($r['ok'] != 1) {
136 139 // Deleting the branch // Deleting the branch
137 140 $r = rg_exec("cd git2" $r = rg_exec("cd git2"
138 141 . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2 -o IdentitiesOnly=yes\"" . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2 -o IdentitiesOnly=yes\""
139 . " && git push origin :branch22", '', FALSE, FALSE);
142 . " && git push origin :branch22",
143 '', FALSE, FALSE, FALSE);
140 144 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
141 145 rg_log_ml('out: ' . $r['errmsg']); rg_log_ml('out: ' . $r['errmsg']);
142 146 rg_log("Seems I cannot delete branch22! err=$err"); rg_log("Seems I cannot delete branch22! err=$err");
File tests/git_big_push.php changed (mode: 100644) (index 09dc61e..13e2af2)
... ... $remote = escapeshellarg($repo['clone_url_http']);
38 38
39 39
40 40 rg_log(''); rg_log('');
41 rg_log_enter('Testing push with a lot of small objects...');
42 $r = rg_exec('mkdir -p temp_repos && cd temp_repos'
43 . ' && rm -rf git_small_obj && mkdir git_small_obj && cd git_small_obj'
41 if (!file_exists('temp_repos/git_small_obj')) {
42 rg_log_enter('Testing push with a lot of small objects (create repo)...');
43 $r = rg_exec('mkdir -p temp_repos && cd temp_repos'
44 . ' && mkdir git_small_obj.tmp && cd git_small_obj.tmp'
45 . ' && git init'
46 . ' && (for i in `seq 0 500`; do'
47 . ' dd if=/dev/urandom of=a-${i} bs=10000 count=1'
48 . ' && git add a-${i}'
49 . ' && git commit -m "aaa-${i}";'
50 . ' done)'
51 . ' && git remote add origin ' . $remote
52 . ' && cd .. && mv git_small_obj.tmp git_small_obj',
53 '', FALSE, FALSE, FALSE);
54 if ($r['ok'] != 1) {
55 rg_log_ml('r: ' . print_r($r, TRUE));
56 rg_log_ml('Could not push lots of small files: ' . $r['errmsg'] . '!');
57 exit(1);
58 }
59 rg_log_exit();
60 }
61
62 rg_log('');
63 rg_log_enter('Testing push with a lot of small objects (push)...');
64 $r = rg_exec('cd temp_repos/git_small_obj'
65 . ' && git remote set-url origin ' . $remote
44 66 . ' && export GIT_CURL_VERBOSE=1 GIT_TRACE=1 GIT_TRACE_PACKET=1' . ' && export GIT_CURL_VERBOSE=1 GIT_TRACE=1 GIT_TRACE_PACKET=1'
45 . ' && git init'
46 . ' && git remote add origin ' . $remote
47 . ' && (for i in `seq 0 500`; do'
48 . ' dd if=/dev/urandom of=a-${i} bs=10000 count=1'
49 . ' && git add a-${i}'
50 . ' && git commit -m "aaa-${i}";'
51 . ' done)'
52 67 . ' && git push --force origin master', . ' && git push --force origin master',
53 '', FALSE, FALSE);
68 '', FALSE, FALSE, FALSE);
54 69 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
70 rg_log_ml('r: ' . print_r($r, TRUE));
55 71 rg_log_ml('Could not push lots of small files: ' . $r['errmsg'] . '!'); rg_log_ml('Could not push lots of small files: ' . $r['errmsg'] . '!');
56 72 exit(1); exit(1);
57 73 } }
58 74 rg_log_exit(); rg_log_exit();
59 //system('rm -rf temp_repos/git_small_obj');
60 75
61 76
62 77 rg_log(''); rg_log('');
63 rg_log_enter('Testing push with a big file...');
64 $r = rg_exec('mkdir -p temp_repos && cd temp_repos'
65 . ' && rm -rf git_big_push && mkdir git_big_push && cd git_big_push'
66 . ' && git init'
67 . ' && git remote add origin ' . $remote
68 . ' && dd if=/dev/zero of=a bs=1M count=2'
69 . ' && git add a'
70 . ' && git commit -a -m "aaa"'
71 . ' && git config http.postBuffer 8000',
72 '', FALSE, FALSE);
73 if ($r['ok'] != 1) {
74 rg_log_ml('Could not exec repo script (part 1): ' . $r['errmsg'] . '!');
75 exit(1);
78 if (!file_exists('temp_repos/git_big_push')) {
79 rg_log_enter('Testing push with a big file (create repo)...');
80 $r = rg_exec('mkdir -p temp_repos && cd temp_repos'
81 . ' && mkdir git_big_push.tmp && cd git_big_push.tmp'
82 . ' && git init'
83 . ' && git remote add origin ' . $remote
84 . ' && dd if=/dev/zero of=a bs=1M count=2'
85 . ' && git add a'
86 . ' && git commit -a -m "aaa"'
87 . ' && git config http.postBuffer 8000'
88 . ' && cd .. && mv git_big_push.tmp git_big_push',
89 '', FALSE, FALSE, FALSE);
90 if ($r['ok'] != 1) {
91 rg_log_ml('r: ' . print_r($r, TRUE));
92 rg_log_ml('Could not exec repo script (part 1): ' . $r['errmsg'] . '!');
93 exit(1);
94 }
95 rg_log_exit();
76 96 } }
97
98 rg_log('');
99 rg_log_enter('Testing push with a big file (push)...');
77 100 $r = rg_exec('cd temp_repos/git_big_push' $r = rg_exec('cd temp_repos/git_big_push'
78 101 . ' && export GIT_CURL_VERBOSE=1 GIT_TRACE=1 GIT_TRACE_PACKET=1' . ' && export GIT_CURL_VERBOSE=1 GIT_TRACE=1 GIT_TRACE_PACKET=1'
102 . ' && git remote set-url origin ' . $remote
79 103 . ' && git push --force origin master', . ' && git push --force origin master',
80 '', FALSE, FALSE);
104 '', FALSE, FALSE, FALSE);
81 105 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
82 106 if (!strstr($r['errmsg'], 'git config http.postBuffer')) { if (!strstr($r['errmsg'], 'git config http.postBuffer')) {
83 107 rg_log_ml('Could not exec repo script (part 2): ' . $r['errmsg'] . '!'); rg_log_ml('Could not exec repo script (part 2): ' . $r['errmsg'] . '!');
 
... ... if ($r['ok'] != 1) {
85 109 } }
86 110 } }
87 111 rg_log_exit(); rg_log_exit();
88 system('rm -rf temp_repos/git_big_push');
89 112
90 113
91 114 rg_log('OK!'); rg_log('OK!');
File tests/helpers.inc.php changed (mode: 100644) (index d6ba475..ea362d8)
... ... function rg_test_upload_ssh_key($db, $rg_ui, $key_name)
280 280 unlink('keys/' . $key_name . '.pub'); unlink('keys/' . $key_name . '.pub');
281 281 $r = rg_exec("ssh-keygen -t rsa -N '' -b 4096 -C \"Key for RocketGit\"" $r = rg_exec("ssh-keygen -t rsa -N '' -b 4096 -C \"Key for RocketGit\""
282 282 . " -f keys/" . escapeshellarg($key_name) . " </dev/null", . " -f keys/" . escapeshellarg($key_name) . " </dev/null",
283 '', FALSE, FALSE);
283 '', FALSE, FALSE, FALSE);
284 284 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
285 285 rg_log('Cannot generate key: ' . $r['stderr']); rg_log('Cannot generate key: ' . $r['stderr']);
286 286 exit(1); exit(1);
 
... ... function test_ssh($uid, $extra)
466 466 $cmd = 'ssh -v' $cmd = 'ssh -v'
467 467 . ' -i keys/' . $uid . ' -i keys/' . $uid
468 468 . ' -p ' . $rg_ssh_port . ' -p ' . $rg_ssh_port
469 . ' -o ControlMaster=auto'
469 . ' -o ControlMaster=no'
470 470 . ' -o ControlPath=' . __DIR__ . '/jars/ssh-' . $uid . ' -o ControlPath=' . __DIR__ . '/jars/ssh-' . $uid
471 471 . ' rocketgit@' . $rg_ssh_host; . ' rocketgit@' . $rg_ssh_host;
472 472
473 return rg_exec($cmd . ' ' . $extra, '', FALSE, FALSE);
473 return rg_exec($cmd . ' ' . $extra, '', FALSE, FALSE, FALSE);
474 474 } }
475 475
476 476 ?> ?>
File tests/http.inc.php changed (mode: 100644) (index 63d5cd8..5710dde)
... ... function do_req($url, &$data, &$headers)
138 138 $ret['body'] = str_replace('<xss>', '|xss|', $ret['body']); $ret['body'] = str_replace('<xss>', '|xss|', $ret['body']);
139 139 file_put_contents("http.tidy.in", $ret['body']); file_put_contents("http.tidy.in", $ret['body']);
140 140 $cmd = "tidy -errors -utf8 -file http.tidy.out http.tidy.in"; $cmd = "tidy -errors -utf8 -file http.tidy.out http.tidy.in";
141 $r = rg_exec($cmd, '', FALSE, FALSE);
141 $r = rg_exec($cmd, '', FALSE, FALSE, FALSE);
142 142 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
143 143 rg_log_ml('tidy error: ' . $r['stderr']); rg_log_ml('tidy error: ' . $r['stderr']);
144 144 rg_log_ml(file_get_contents('http.tidy.out')); rg_log_ml(file_get_contents('http.tidy.out'));
File tests/ldap.php changed (mode: 100644) (index 275349a..6fa5ff6)
... ... function rg_ldap_start_server(&$l)
40 40 rg_log($k . '=' . $v); rg_log($k . '=' . $v);
41 41 putenv($k . '=' . $v); putenv($k . '=' . $v);
42 42 } }
43 rg_exec('cd ldap && bash -x start.sh &> ' . $log . '.log', '', FALSE, FALSE);
44 rg_exec('cd ldap && bash -x prepare.sh &> ' . $log . '.prep.log', '', FALSE, FALSE);
43 rg_exec('cd ldap && bash -x start.sh &> ' . $log . '.log', '', FALSE, FALSE, FALSE);
44 rg_exec('cd ldap && bash -x prepare.sh &> ' . $log . '.prep.log', '', FALSE, FALSE, FALSE);
45 45 exit(0); exit(0);
46 46 } }
47 47
 
... ... function rg_ldap_start_server(&$l)
70 70 function clean($log) function clean($log)
71 71 { {
72 72 rg_log('Cleaning processes attached to file ' . $log . '.log...'); rg_log('Cleaning processes attached to file ' . $log . '.log...');
73 $r = rg_exec('fuser -k -v -9 ' . escapeshellarg($log . '.log'), '', FALSE, FALSE);
73 $r = rg_exec('fuser -k -v -9 ' . escapeshellarg($log . '.log'), '', FALSE, FALSE, FALSE);
74 74 rg_log_ml('fuser returned: ' . print_r($r, TRUE)); rg_log_ml('fuser returned: ' . print_r($r, TRUE));
75 75 } }
76 76
 
... ... if ($r === FALSE) {
88 88
89 89 rg_log(''); rg_log('');
90 90 rg_log('Generating certificates...'); rg_log('Generating certificates...');
91 $r = rg_exec('./ca.sh ldap', '', FALSE, FALSE);
91 $r = rg_exec('./ca.sh ldap', '', FALSE, FALSE, FALSE);
92 92 if (!strstr($r['data'], 'CA_SH_OK')) { if (!strstr($r['data'], 'CA_SH_OK')) {
93 93 rg_log_ml('data: ' . $r['data']); rg_log_ml('data: ' . $r['data']);
94 94 rg_log('Cannot generate certificates!'); rg_log('Cannot generate certificates!');
File tests/pr_anon.php changed (mode: 100644) (index 5dcac32..2f4fa79)
... ... $r = rg_exec('mkdir -p temp_repos && cd temp_repos'
97 97 . ' && git remote add origin_git ' . ' && git remote add origin_git '
98 98 . ' git://' . $rg_git_host . ':' . $rg_git_port . ' git://' . $rg_git_host . ':' . $rg_git_port
99 99 . '/user/' . escapeshellarg($rg_ui['username']) . '/' . '/user/' . escapeshellarg($rg_ui['username']) . '/'
100 . escapeshellarg($repo['name']), '', FALSE, FALSE);
100 . escapeshellarg($repo['name']),
101 '', FALSE, FALSE, FALSE);
101 102 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
102 103 rg_log('Could not prepare git repo: ' . $r['errmsg'] . '!'); rg_log('Could not prepare git repo: ' . $r['errmsg'] . '!');
103 104 exit(1); exit(1);
 
... ... $r = rg_exec('export GIT_SSH_COMMAND="' . $ssh . '"'
112 113 . ' && echo "change1" > a && git add a && git commit -m "change1 desc"' . ' && echo "change1" > a && git add a && git commit -m "change1 desc"'
113 114 . ' && echo "change2" > a && git commit -a -m "change2 desc"' . ' && echo "change2" > a && git commit -a -m "change2 desc"'
114 115 . ' && git push origin_ssh master', . ' && git push origin_ssh master',
115 '', FALSE, FALSE);
116 '', FALSE, FALSE, FALSE);
116 117 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
117 118 rg_log('Non-anonymous push was rejected: ' . $r['errmsg'] . '!'); rg_log('Non-anonymous push was rejected: ' . $r['errmsg'] . '!');
118 119 exit(1); exit(1);
 
... ... $r = rg_exec('cd temp_repos/pr_anon'
127 128 . ' && git commit -m "anon change1 desc"' . ' && git commit -m "anon change1 desc"'
128 129 . ' && echo "change4" >> a; git commit -a -m "anon change2 desc"' . ' && echo "change4" >> a; git commit -a -m "anon change2 desc"'
129 130 . ' && git push origin_git master', . ' && git push origin_git master',
130 '', FALSE, FALSE);
131 '', FALSE, FALSE, FALSE);
131 132 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
132 133 rg_log('Anonymous push was rejected: ' . $r['errmsg'] . '!'); rg_log('Anonymous push was rejected: ' . $r['errmsg'] . '!');
133 134 exit(1); exit(1);
 
... ... rg_log_exit();
175 176
176 177 rg_log(''); rg_log('');
177 178 rg_log_enter('Merging merge request...'); rg_log_enter('Merging merge request...');
179 $mm1 = 'This is the merge message <xss>';
178 180 $data = array('token' => $r['tokens']['mr_merge'], $data = array('token' => $r['tokens']['mr_merge'],
179 'merge_ff' => 0, 'merge_msg' => 'This is the merge message <xss>');
181 'merge_ff' => 0, 'merge_msg' => $mm1);
180 182 $r = do_req($test_url . $url . $mri['id'] . '/merge', $data, $headers); $r = do_req($test_url . $url . $mri['id'] . '/merge', $data, $headers);
181 183 if ($r === FALSE) { if ($r === FALSE) {
182 184 rg_log('Cannot post merge form'); rg_log('Cannot post merge form');
 
... ... while (1) {
200 202 $tries++; $tries++;
201 203 sleep(1); sleep(1);
202 204 } }
205 $r = rg_exec('cd temp_repos/pr_anon'
206 . ' && git pull origin_git master'
207 . ' && git log --oneline -n1',
208 '', FALSE, FALSE, FALSE);
209 if ($r['ok'] != 1) {
210 rg_log('Could not pull: ' . $r['errmsg'] . '!');
211 exit(1);
212 }
213 if (!strstr($r['data'], $mm1)) {
214 rg_log_ml('r: ' . print_r($r, TRUE));
215 rg_log('Cannot find the merge message!');
216 exit(1);
217 }
203 218 rg_log_exit(); rg_log_exit();
204 219
205 220
206 221 rg_log(''); rg_log('');
207 222 rg_log_enter('Now, try to see what happens when a merge is with conflicts...'); rg_log_enter('Now, try to see what happens when a merge is with conflicts...');
208 223 $r = rg_exec('cd temp_repos/pr_anon' $r = rg_exec('cd temp_repos/pr_anon'
209 . ' && git pull origin_git master'
210 224 . ' && echo "change2" > a' . ' && echo "change2" > a'
211 225 . ' && git commit -a -m "conflict1b"' . ' && git commit -a -m "conflict1b"'
212 226 . ' && git push origin_git master', . ' && git push origin_git master',
213 '', FALSE, FALSE);
227 '', FALSE, FALSE, FALSE);
214 228 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
215 229 rg_log('Could not pull/commit/push by git proto: ' . $r['errmsg'] . '!'); rg_log('Could not pull/commit/push by git proto: ' . $r['errmsg'] . '!');
216 230 exit(1); exit(1);
 
... ... $r = rg_exec('export GIT_SSH_COMMAND="' . $ssh . '"'
221 235 . ' && echo "change1" > a' . ' && echo "change1" > a'
222 236 . ' && git commit -a -m "conflict1a"' . ' && git commit -a -m "conflict1a"'
223 237 . ' && git push origin_ssh master', . ' && git push origin_ssh master',
224 '', FALSE, FALSE);
238 '', FALSE, FALSE, FALSE);
225 239 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
226 240 rg_log('Could not reset/commit/push by ssh proto: ' . $r['errmsg'] . '!'); rg_log('Could not reset/commit/push by ssh proto: ' . $r['errmsg'] . '!');
227 241 exit(1); exit(1);
File tests/repo.php changed (mode: 100644) (index 366e18d..eede1b4)
... ... if ($ri['exists'] != 1) {
206 206
207 207 rg_log(''); rg_log('');
208 208 rg_log_enter('Cleaning repos folder...'); rg_log_enter('Cleaning repos folder...');
209 $r = rg_exec("rm -rf base/*", '', FALSE, FALSE);
209 $r = rg_exec("rm -rf base/*", '', FALSE, FALSE, FALSE);
210 210 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
211 211 rg_log("Failed to clean base folder."); rg_log("Failed to clean base folder.");
212 212 exit(1); exit(1);
File tests/source.php changed (mode: 100644) (index f6c7c39..c76e1d9)
... ... $r = rg_exec('mkdir -p temp_repos && cd temp_repos'
49 49 . ' && git remote add origin ' . $remote . ' && git remote add origin ' . $remote
50 50 . ' && export GIT_SSH_COMMAND="ssh -v -o ControlMaster=no -o IdentityFile=../../keys/source -o IdentitiesOnly=yes"' . ' && export GIT_SSH_COMMAND="ssh -v -o ControlMaster=no -o IdentityFile=../../keys/source -o IdentitiesOnly=yes"'
51 51 . ' && git push origin master', . ' && git push origin master',
52 '', FALSE, FALSE);
52 '', FALSE, FALSE, FALSE);
53 53 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
54 54 rg_log_ml('out: ' . $r['errmsg']); rg_log_ml('out: ' . $r['errmsg']);
55 55 rg_log('Seems I cannot push master!'); rg_log('Seems I cannot push master!');
File tests/ssh.php changed (mode: 100644) (index 5223049..9d1975a)
... ... if (php_uname("n") != "r1.embedromix.ro") {
30 30 } }
31 31
32 32
33 rg_log("Creating a user...");
33 rg_log('');
34 rg_log_enter("Creating a user...");
34 35 rg_test_create_user($db, $rg_ui); rg_test_create_user($db, $rg_ui);
35 36 rg_test_create_repo($db, $rg_ui, $repo); rg_test_create_repo($db, $rg_ui, $repo);
36 37 $r = test_login($test_url, $rg_ui); $r = test_login($test_url, $rg_ui);
 
... ... if ($r === FALSE) {
38 39 rg_log("Cannot login!"); rg_log("Cannot login!");
39 40 exit(1); exit(1);
40 41 } }
42 rg_log_exit();
43
41 44
42 45 rg_test_upload_ssh_key($db, $rg_ui, $rg_ui['uid']); rg_test_upload_ssh_key($db, $rg_ui, $rg_ui['uid']);
43 46
47
44 48 rg_log(''); rg_log('');
49 rg_log_enter('Testing ssh help...');
45 50 $list = array('', 'status', 'repos', 'repo', 'totp'); $list = array('', 'status', 'repos', 'repo', 'totp');
46 51 foreach ($list as $s) { foreach ($list as $s) {
47 52 rg_log('Connecting for [' . $s . ']'); rg_log('Connecting for [' . $s . ']');
 
... ... foreach ($list as $s) {
56 61 exit(1); exit(1);
57 62 } }
58 63 } }
64 rg_log_exit();
65
59 66
67 rg_log('');
68 rg_log_enter('Testing ssh help for totp commands...');
60 69 $list = array('remove-device', 'unenroll'); $list = array('remove-device', 'unenroll');
61 70 foreach ($list as $s) { foreach ($list as $s) {
62 71 rg_log('Connecting for [totp ' . $s . ']'); rg_log('Connecting for [totp ' . $s . ']');
 
... ... foreach ($list as $s) {
66 75 exit(1); exit(1);
67 76 } }
68 77 } }
78 rg_log_exit();
69 79
70 80
71 81 rg_log(''); rg_log('');
 
... ... foreach ($sc as &$t)
215 225
216 226
217 227 rg_log(''); rg_log('');
218 rg_log('Testing \'unenroll\' (must work)');
228 rg_log_enter('Testing \'unenroll\' (must work)');
219 229 $token = array_pop($sc); $token = array_pop($sc);
220 230 $token = ltrim($token, '0'); $token = ltrim($token, '0');
221 231 $_cmd = ' totp unenroll ' . $token; $_cmd = ' totp unenroll ' . $token;
 
... ... if (!strstr($r['data'], 'You are now unenrolled')) {
229 239 rg_log('Cannot unenroll!'); rg_log('Cannot unenroll!');
230 240 exit(1); exit(1);
231 241 } }
242 rg_log_exit();
243
232 244
233 245 rg_log(''); rg_log('');
234 rg_log('After enroll we should not be able to use the scratch codes');
246 rg_log_enter('After enroll we should not be able to use the scratch codes');
235 247 $token = array_pop($sc); $token = array_pop($sc);
236 248 $r = test_ssh($rg_ui['uid'], ' totp val ' . $token . ' 2m'); $r = test_ssh($rg_ui['uid'], ' totp val ' . $token . ' 2m');
237 249 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
 
... ... if (strstr($r['data'], 'Success!')) {
243 255 rg_log('Seems we are able to use scratch codes after unenroll!'); rg_log('Seems we are able to use scratch codes after unenroll!');
244 256 exit(1); exit(1);
245 257 } }
258 rg_log_exit();
246 259
247 260
248 261 $sc = rg_test_sc_generate($db, $rg_ui); $sc = rg_test_sc_generate($db, $rg_ui);
249 262
250 263
251 264 rg_log(''); rg_log('');
252 rg_log('sc: testing \'val\' cmd...');
265 rg_log_enter('sc: testing \'val\' cmd...');
253 266 $token = array_pop($sc); $token = array_pop($sc);
254 267 $_cmd = ' totp val ' . $token . ' 2m'; $_cmd = ' totp val ' . $token . ' 2m';
255 268 $r = test_ssh($rg_ui['uid'], $_cmd); $r = test_ssh($rg_ui['uid'], $_cmd);
 
... ... if (!strstr($r['data'], 'Success!')) {
262 275 rg_log('Cannot validate ip!'); rg_log('Cannot validate ip!');
263 276 exit(1); exit(1);
264 277 } }
278 rg_log_exit();
265 279
266 280
267 281 rg_log(''); rg_log('');
268 rg_log('Reuse of the scratch code must be forbidden (sc)');
282 rg_log_enter('Reuse of the scratch code must be forbidden (sc)');
269 283 $_cmd = ' totp val ' . $token . ' 2m'; $_cmd = ' totp val ' . $token . ' 2m';
270 284 $r = test_ssh($rg_ui['uid'], $_cmd); $r = test_ssh($rg_ui['uid'], $_cmd);
271 285 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
 
... ... if (!strstr($r['stderr'], 'invalid token')) {
277 291 rg_log('we get no error on token reuse!'); rg_log('we get no error on token reuse!');
278 292 exit(1); exit(1);
279 293 } }
280
294 rg_log_exit();
281 295
282 296 rg_log("OK!"); rg_log("OK!");
283 297 ?> ?>
File tests/user.php changed (mode: 100644) (index e9acd8e..4155f0f)
... ... $rg_admin_name = "RocketGit Admin";
27 27 $_SERVER['HTTP_HOST'] = "fake.tld"; $_SERVER['HTTP_HOST'] = "fake.tld";
28 28
29 29
30 $r = rg_exec("rm -rf ubase", '', FALSE, FALSE);
30 $r = rg_exec("rm -rf ubase", '', FALSE, FALSE, FALSE);
31 31 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
32 32 rg_log("Cannot remove ubase dir (" . $r['errmsg'] . ")!"); rg_log("Cannot remove ubase dir (" . $r['errmsg'] . ")!");
33 33 exit(1); exit(1);
 
... ... if ($uid5 === FALSE) {
212 212 exit(1); exit(1);
213 213 } }
214 214
215 $r = rg_exec("mkdir -p ubase/users/u/s/user5", '', FALSE, FALSE);
215 $r = rg_exec("mkdir -p ubase/users/u/s/user5", '', FALSE, FALSE, FALSE);
216 216 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
217 217 rg_log('Cannot make fixes simulation dir: ' . $r['stderr'] . '!'); rg_log('Cannot make fixes simulation dir: ' . $r['stderr'] . '!');
218 218 exit(1); exit(1);
File tests/util.php changed (mode: 100644) (index abf6055..f1da20c)
... ... if ($r !== TRUE) {
295 295 } }
296 296
297 297
298 $r = rg_exec("/xxxx", '', FALSE, FALSE);
298 rg_log('');
299 rg_log_enter('exec a non existing command');
300 $r = rg_exec("/xxxx", '', FALSE, FALSE, FALSE);
299 301 if ($r['ok'] == 1) { if ($r['ok'] == 1) {
300 rg_log("util.php: running non existing command does not return 0!");
301 print_r($r);
302 rg_log_ml('r: ' . print_r($r, TRUE));
303 rg_log("running non existing command does not return 0!");
304 exit(1);
305 }
306 if (strcmp($r['stderr'], "sh: /xxxx: No such file or directory\n") != 0) {
307 rg_log_ml('r: ' . print_r($r, TRUE));
308 rg_log('stderr is not correct!');
302 309 exit(1); exit(1);
303 310 } }
311 if ($r['code'] != 127) {
312 rg_log_ml('r: ' . print_r($r, TRUE));
313 rg_log('error code must be 127!');
314 exit(1);
315 }
316 rg_log_exit();
304 317
305 $r = rg_exec("ls", '', FALSE, FALSE);
318 rg_log('');
319 rg_log_enter('exec a normal \'ls\' command');
320 $r = rg_exec("ls", '', FALSE, FALSE, FALSE);
306 321 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
307 rg_log("util.php: cannot run a command!");
308 print_r($r);
322 rg_log_ml('r: ' . print_r($r, TRUE));
323 rg_log("cannot run a command!");
309 324 exit(1); exit(1);
310 325 } }
326 rg_log_exit();
327
311 328
312 $r = rg_exec("./util_exit_code.sh 5", '', FALSE, FALSE);
313 if ($r['code'] != 5) {
314 rg_log("util.php: error code seems to not be propageted!");
315 print_r($r);
329 rg_log('');
330 rg_log_enter('force exit code 5');
331 $r = rg_exec("./util_exit_code.sh 5", '', FALSE, FALSE, FALSE);
332 if (($r['ok'] == 1) || ($r['code'] != 5)) {
333 rg_log_ml('r: ' . print_r($r, TRUE));
334 rg_log("error code seems to not be propageted!");
316 335 exit(1); exit(1);
317 336 } }
337 rg_log_exit();
338
339
340 rg_log('');
341 rg_log_enter('stdout closes first');
342 $r = rg_exec("./util_stdout_closes_first.sh", '', FALSE, FALSE, FALSE);
343 if (($r['ok'] != 1) || ($r['code'] != 0)) {
344 rg_log_ml('r: ' . print_r($r, TRUE));
345 rg_log("stdout_closes_first should return ok/code0!");
346 exit(1);
347 }
348 if (strcmp($r['data'], "stdout\n") != 0) {
349 rg_log_ml('r: ' . print_r($r, TRUE));
350 rg_log("stdout returned value is not correct!");
351 exit(1);
352 }
353 if (strcmp($r['stderr'], "stderr1\nstderr2\n") != 0) {
354 rg_log_ml('r: ' . print_r($r, TRUE));
355 rg_log("stderr returned value is not correct!");
356 exit(1);
357 }
358 rg_log_exit();
359
360
361 rg_log('');
362 rg_log_enter('exec2 - complex');
363 // Define helpers
364 function cb_input($index, &$a, $stream)
365 {
366 if (isset($a['cb_input_called']))
367 return;
368
369 rg_log('cb_input[' . $index . '] stream=' . $stream);
370 switch ($stream) {
371 case 1: rg_log(' stdout: ' . $a['in_buf']); break;
372 case 2: rg_log(' stderr: ' . $a['err_buf']); break;
373 }
374
375 $a['out_buf'] .= ' send_something_from_cb_input_' . $index . "\n";
376 $a['cb_input_called'] = 1;
377 }
378 function cb_output($index, &$a)
379 {
380 if (isset($a['cb_output_called']))
381 return;
382
383 rg_log('cb_output[' . $index . ']');
384
385 $a['out_buf'] .= ' generated_output_' . $index . "\n";
386 $a['cb_output_called'] = 1;
387 }
388 function cb_error($index, &$a, $msg)
389 {
390 rg_log('cb_error[' . $index . ']: ' . $msg);
391 // If we need to restart the command, use this:
392 //$a['restart_delay'] = 0; // in seconds
393 }
394 function cb_idle($index, &$a)
395 {
396 rg_log('cb_idle[' . $index . ']');
397 }
398 function cb_finish($index, &$a, $exitcode)
399 {
400 rg_log('cb_finish[' . $index . ']: exitcode=' . $exitcode);
401 }
402 function cb_tick($index, &$a)
403 {
404 rg_log('cb_tick[' . $index . ']');
405 $a['my'] = 'tick_was_here';
318 406
407 if (!isset($a['cb_input_called']) || !isset($a['cb_output_called']))
408 return;
409
410 // We do not want to output something anymore
411 // This can be set from any callback.
412 rg_log('cb_tick: now we can set output_done to 1');
413 $a['output_done'] = 1;
414 }
415
416 $a = array(
417 'cmds' => array(
418 'cmd1' => array(
419 'cmd' => 'echo first1; read a; sleep .2; echo last1; echo "err1-[${a}]" 1>&2',
420 'cb_input' => 'cb_input',
421 'cb_output' => 'cb_output',
422 'cb_error' => 'cb_error',
423 'cb_idle' => 'cb_idle',
424 'cb_finish' => 'cb_finish',
425 'cb_tick' => 'cb_tick',
426 'out_buf' => 'aaa1',
427 'output_done' => 0
428 ),
429 'cmd2' => array(
430 'cmd' => 'echo first2; read a; sleep .2; echo last2; echo "err2-[${a}]" 1>&2',
431 'cb_input' => 'cb_input',
432 'cb_output' => 'cb_output',
433 'cb_error' => 'cb_error',
434 'cb_idle' => 'cb_idle',
435 'cb_finish' => 'cb_finish',
436 'cb_tick' => 'cb_tick',
437 'out_buf' => 'aaa2',
438 'output_done' => 0
439 )
440 )
441 );
442 $r = rg_exec2($a);
443 if ($r['ok'] != 1) {
444 rg_log('rg_exec2 failed: ' . $r['errmsg'] . '!');
445 exit(1);
446 }
447 $e = "first1\nlast1\n";
448 if (strcmp($r['cmds']['cmd1']['in_buf'], $e) != 0) {
449 rg_log('cmd1 in_buf is not ok: ['
450 . $r['cmds']['cmd1']['in_buf'] . '] != [' . $e . ']!');
451 exit(1);
452 }
453 $e = "first2\nlast2\n";
454 if (strcmp($r['cmds']['cmd2']['in_buf'], $e) != 0) {
455 rg_log('cmd2 in_buf is not ok: ['
456 . $r['cmds']['cmd2']['in_buf'] . '] != [' . $e . ']!');
457 exit(1);
458 }
459 $e = "err2-[aaa2 generated_output_cmd2]\n";
460 if (strcmp($r['cmds']['cmd2']['err_buf'], $e) != 0) {
461 rg_log('cmd2 err_buf is not ok: ['
462 . $r['cmds']['cmd2']['err_buf'] . '] != [' . $e . ']!');
463 exit(1);
464 }
465 $e = 'tick_was_here';
466 if (!isset($r['cmds']['cmd2']['my']) || (strcmp($r['cmds']['cmd2']['my'], $e) != 0)) {
467 rg_log_ml('r: ' . print_r($r, TRUE));
468 rg_log('my is not ok (cb_tick was not called?)!');
469 exit(1);
470 }
471 rg_log_exit();
472
473
474 rg_log('');
319 475 $t = "test rg_template_table(dir, data, more) with no data"; $t = "test rg_template_table(dir, data, more) with no data";
320 rg_log($t);
476 rg_log_enter($t);
321 477 $data = array(); $data = array();
322 478 $r = rg_template_table("t1", $data, array("a" => "A")); $r = rg_template_table("t1", $data, array("a" => "A"));
323 479 $e = "XAX"; $e = "XAX";
324 480 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
325 rg_log("util.php: $t: not working (r=$r e=$e)!");
481 rg_log("$t: not working (r=$r e=$e)!");
326 482 exit(1); exit(1);
327 483 } }
484 rg_log_exit();
328 485
329 486 $t = "test rg_template_table(dir, data, more) with data"; $t = "test rg_template_table(dir, data, more) with data";
330 487 rg_log($t); rg_log($t);
 
... ... $data = array(array("a" => "A", "b" => "B"), array("a" => "A2", "b" => "B2"));
332 489 $r = rg_template_table("t2", $data, array("c" => "C")); $r = rg_template_table("t2", $data, array("c" => "C"));
333 490 $e = "HEADCABCA2B2CFOOTC"; $e = "HEADCABCA2B2CFOOTC";
334 491 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
335 rg_log("util.php: $t: not working (r=$r e=$e)!");
492 rg_log("$t: not working (r=$r e=$e)!");
336 493 exit(1); exit(1);
337 494 } }
338 495
 
... ... $data = array("X" => "0", "A" => "Avalue", "B" => "Bvalue");
342 499 $r = rg_template("t3/c1", $data, TRUE /*xss*/); $r = rg_template("t3/c1", $data, TRUE /*xss*/);
343 500 $e = "XXBvalueYY"; $e = "XXBvalueYY";
344 501 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
345 rg_log("util.php: $t: not working (r=$r e=$e)!");
502 rg_log("$t: not working (r=$r e=$e)!");
346 503 exit(1); exit(1);
347 504 } }
348 505
 
... ... $data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue");
352 509 $r = rg_template("t3/c1", $data, TRUE /*xss*/); $r = rg_template("t3/c1", $data, TRUE /*xss*/);
353 510 $e = "XXAvalueYY"; $e = "XXAvalueYY";
354 511 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
355 rg_log("util.php: $t: not working (r=$r e=$e)!");
512 rg_log("$t: not working (r=$r e=$e)!");
356 513 exit(1); exit(1);
357 514 } }
358 515
 
... ... $data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue");
362 519 $r = rg_template("t3/c1", $data, TRUE /*xss*/); $r = rg_template("t3/c1", $data, TRUE /*xss*/);
363 520 $e = "XXAvalueYY"; $e = "XXAvalueYY";
364 521 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
365 rg_log("util.php: $t: not working (r=$r e=$e)!");
522 rg_log("$t: not working (r=$r e=$e)!");
366 523 exit(1); exit(1);
367 524 } }
368 525
 
... ... $data = array("X" => "1", "Y" => "1", "A" => "Avalue", "B" => "Bvalue",
373 530 $r = rg_template("t3/c3", $data, TRUE /*xss*/); $r = rg_template("t3/c3", $data, TRUE /*xss*/);
374 531 $e = "XXRvalueZZYY"; $e = "XXRvalueZZYY";
375 532 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
376 rg_log("util.php: $t: not working (r=$r e=$e)!");
533 rg_log("$t: not working (r=$r e=$e)!");
377 534 exit(1); exit(1);
378 535 } }
379 536
 
... ... $data = array("X" => "1", "Y" => "0", "A" => "Avalue", "B" => "Bvalue",
384 541 $r = rg_template("t3/c3", $data, TRUE /*xss*/); $r = rg_template("t3/c3", $data, TRUE /*xss*/);
385 542 $e = "XXTvalueZZYY"; $e = "XXTvalueZZYY";
386 543 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
387 rg_log("util.php: $t: not working (r=$r e=$e)!");
544 rg_log("$t: not working (r=$r e=$e)!");
388 545 exit(1); exit(1);
389 546 } }
390 547
 
... ... $data = array("X" => "0", "Y" => "1", "A" => "Avalue", "B" => "Bvalue",
395 552 $r = rg_template("t3/c3", $data, TRUE /*xss*/); $r = rg_template("t3/c3", $data, TRUE /*xss*/);
396 553 $e = "XXBvalueYY"; $e = "XXBvalueYY";
397 554 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
398 rg_log("util.php: $t: not working (r=$r e=$e)!");
555 rg_log("$t: not working (r=$r e=$e)!");
399 556 exit(1); exit(1);
400 557 } }
401 558
 
... ... $r = rg_template("t3/c4", $data, TRUE /*xss*/);
406 563 $r = preg_replace('/\s/', '', $r); $r = preg_replace('/\s/', '', $r);
407 564 $e = "XXTRUE_LEVEL_2YY"; $e = "XXTRUE_LEVEL_2YY";
408 565 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
409 rg_log("util.php: $t: not working (r=$r e=$e)!");
566 rg_log("$t: not working (r=$r e=$e)!");
410 567 exit(1); exit(1);
411 568 } }
412 569
 
... ... $r = rg_template("t3/c4", $data, TRUE /*xss*/);
417 574 $r = preg_replace('/\s/', '', $r); $r = preg_replace('/\s/', '', $r);
418 575 $e = "XXFALSE_LEVEL_1YY"; $e = "XXFALSE_LEVEL_1YY";
419 576 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
420 rg_log("util.php: $t: not working (r=$r e=$e)!");
577 rg_log("$t: not working (r=$r e=$e)!");
421 578 exit(1); exit(1);
422 579 } }
423 580
 
... ... $r = rg_template("t3/c4", $data, TRUE /*xss*/);
428 585 $r = preg_replace('/\s/', '', $r); $r = preg_replace('/\s/', '', $r);
429 586 $e = "XXFALSE_LEVEL_0YY"; $e = "XXFALSE_LEVEL_0YY";
430 587 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
431 rg_log("util.php: $t: not working (r=$r e=$e)!");
588 rg_log("$t: not working (r=$r e=$e)!");
432 589 exit(1); exit(1);
433 590 } }
434 591
 
... ... $r = rg_template("t3/c5", $data, TRUE /*xss*/);
439 596 $r = preg_replace('/\s/', '', $r); $r = preg_replace('/\s/', '', $r);
440 597 $e = "XX-X0Y0Z0-YY"; $e = "XX-X0Y0Z0-YY";
441 598 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
442 rg_log("util.php: $t: not working (r=$r e=$e)!");
599 rg_log("$t: not working (r=$r e=$e)!");
443 600 exit(1); exit(1);
444 601 } }
445 602
 
... ... $r = rg_template("t3/c5", $data, TRUE /*xss*/);
450 607 $r = preg_replace('/\s/', '', $r); $r = preg_replace('/\s/', '', $r);
451 608 $e = "XX-X0Y1Z0-YY"; $e = "XX-X0Y1Z0-YY";
452 609 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
453 rg_log("util.php: $t: not working (r=$r e=$e)!");
610 rg_log("$t: not working (r=$r e=$e)!");
454 611 exit(1); exit(1);
455 612 } }
456 613
 
... ... $r = rg_template("t3/c6", $data, TRUE /*xss*/);
461 618 $r = preg_replace('/\s/', '', $r); $r = preg_replace('/\s/', '', $r);
462 619 $e = "A"; $e = "A";
463 620 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
464 rg_log("util.php: $t: not working (r=$r e=$e)!");
621 rg_log("$t: not working (r=$r e=$e)!");
465 622 exit(1); exit(1);
466 623 } }
467 624
 
... ... $r = rg_template("t3/c6b", $data, TRUE /*xss*/);
472 629 $r = preg_replace('/\s/', '', $r); $r = preg_replace('/\s/', '', $r);
473 630 $e = "AY"; $e = "AY";
474 631 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
475 rg_log("util.php: $t: not working (r=$r e=$e)!");
632 rg_log("$t: not working (r=$r e=$e)!");
476 633 exit(1); exit(1);
477 634 } }
478 635
 
... ... $r = rg_template("t3/c7", $data, TRUE /*xss*/);
483 640 $r = preg_replace('/\s/', '', $r); $r = preg_replace('/\s/', '', $r);
484 641 $e = "B"; $e = "B";
485 642 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
486 rg_log("util.php: $t: not working (r=$r e=$e)!");
643 rg_log("$t: not working (r=$r e=$e)!");
487 644 exit(1); exit(1);
488 645 } }
489 646
 
... ... $r = rg_template("t3/c8", $data, TRUE /*xss*/);
494 651 $r = preg_replace('/\s/', '', $r); $r = preg_replace('/\s/', '', $r);
495 652 $e = "}}"; $e = "}}";
496 653 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
497 rg_log("util.php: $t: not working (r=[$r] e=[$e])!");
654 rg_log("$t: not working (r=[$r] e=[$e])!");
498 655 exit(1); exit(1);
499 656 } }
500 657
 
... ... $r = rg_template("t3/c9", $data, TRUE /*xss*/);
505 662 $r = preg_replace('/\s/', '', $r); $r = preg_replace('/\s/', '', $r);
506 663 $e = "XXBLABLABLAabcYYabc"; $e = "XXBLABLABLAabcYYabc";
507 664 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
508 rg_log("util.php: $t: not working (r=[$r] e=[$e])!");
665 rg_log("$t: not working (r=[$r] e=[$e])!");
509 666 exit(1); exit(1);
510 667 } }
511 668
 
... ... $data = array("X" => "abc");
515 672 $r = rg_template("t3/c9", $data, TRUE /*xss protection*/); $r = rg_template("t3/c9", $data, TRUE /*xss protection*/);
516 673 $e = "XX\n\tBLA\n\tBLA\n\tBLA\n\tabc\nYY\nabc\n"; $e = "XX\n\tBLA\n\tBLA\n\tBLA\n\tabc\nYY\nabc\n";
517 674 if (strcmp($r, $e) != 0) { if (strcmp($r, $e) != 0) {
518 rg_log("util.php: $t: not working (r=[$r] e=[$e])!");
675 rg_log("$t: not working (r=[$r] e=[$e])!");
519 676 exit(1); exit(1);
520 677 } }
521 678
 
... ... $t = "test rg_copy_tree";
537 694 rg_log($t); rg_log($t);
538 695 $r = rg_copy_tree("tree1", "tree1.copy", 0755); $r = rg_copy_tree("tree1", "tree1.copy", 0755);
539 696 if ($r !== TRUE) { if ($r !== TRUE) {
540 rg_log("util.php: $t: not working!");
697 rg_log("$t: not working!");
541 698 exit(1); exit(1);
542 699 } }
543 700 if (!file_exists("tree1.copy/a/f2")) { if (!file_exists("tree1.copy/a/f2")) {
544 rg_log("util.php: $t(2): not working!");
701 rg_log("$t(2): not working!");
545 702 exit(1); exit(1);
546 703 } }
547 704
 
... ... if (strcmp($r, $e) != 0) {
587 744 } }
588 745
589 746
590 rg_log('');
591 rg_log_enter('rg_exec2');
592 // Define helpers
593 function cb_input($index, &$a, $stream)
594 {
595 rg_log('cb_input[' . $index . '] stream=' . $stream);
596 switch ($stream) {
597 case 1: rg_log(' stdout: ' . $a['in_buf']); break;
598 case 1: rg_log(' stderr: ' . $a['err_buf']); break;
599 }
600
601 $a['out_buf'] .= ' send_something_from_cb_input_' . $index . "\n";
602 }
603 function cb_output($index, &$a)
604 {
605 rg_log('cb_output[' . $index . ']');
606
607 $a['out_buf'] .= ' generated_output_' . $index . "\n";
608
609 // we do not want anymore to be called
610 rg_log('Unsetting cb_output');
611 unset($a['cb_output']);
612 }
613 function cb_error($index, &$a, $msg)
614 {
615 rg_log('cb_error[' . $index . ']: ' . $msg);
616 // If we need to restart the command, use this:
617 //$a['needs_restart'] = TRUE;
618 }
619 function cb_idle($index, &$a)
620 {
621 rg_log('cb_idle[' . $index . ']');
622 $a['done'] = TRUE;
623 }
624 function cb_finish($index, &$a, $exitcode)
625 {
626 rg_log('cb_finish[' . $index . ']: exitcode=' . $exitcode);
627 }
628 function cb_tick(&$a)
629 {
630 rg_log('cb_tick');
631 $a['my'] = 'tick_was_here';
632 }
633
634 $a = array(
635 'cmds' => array(
636 'cmd1' => array(
637 'cmd' => 'echo first1; read a; sleep 2; echo last1; echo "err1-[${a}]" 1>&2',
638 'cb_input' => 'cb_input',
639 'cb_output' => 'cb_output',
640 'cb_error' => 'cb_error',
641 'cb_idle' => 'cb_idle',
642 'cb_finish' => 'cb_finish',
643 'out_buf' => 'aaa1'
644 ),
645 'cmd2' => array(
646 'cmd' => 'echo first2; read a; sleep 2; echo last2; echo "err2-[${a}]" 1>&2',
647 'cb_input' => 'cb_input',
648 'cb_output' => 'cb_output',
649 'cb_error' => 'cb_error',
650 'cb_idle' => 'cb_idle',
651 'cb_finish' => 'cb_finish',
652 'out_buf' => 'aaa2'
653 )
654 ),
655 'cb_tick' => 'cb_tick'
656 );
657 $r = rg_exec2($a);
658 if ($r['ok'] != 1) {
659 rg_log('rg_exec2 failed: ' . $r['errmsg'] . '!');
660 exit(1);
661 }
662 $e = "first1\nlast1\n";
663 if (strcmp($a['cmds']['cmd1']['in_buf'], $e) != 0) {
664 rg_log('cmd1 in_buf is not ok: ['
665 . $a['cmds']['cmd1']['in_buf'] . '] != [' . $e . ']!');
666 exit(1);
667 }
668 $e = "first2\nlast2\n";
669 if (strcmp($a['cmds']['cmd2']['in_buf'], $e) != 0) {
670 rg_log('cmd2 in_buf is not ok: ['
671 . $a['cmds']['cmd2']['in_buf'] . '] != [' . $e . ']!');
672 exit(1);
673 }
674 $e = "err2-[aaa2 generated_output_cmd2]\n";
675 if (strcmp($a['cmds']['cmd2']['err_buf'], $e) != 0) {
676 rg_log('cmd2 err_buf is not ok: ['
677 . $a['cmds']['cmd2']['err_buf'] . '] != [' . $e . ']!');
678 exit(1);
679 }
680 $e = 'tick_was_here';
681 if (!isset($a['my']) || (strcmp($a['my'], $e) != 0)) {
682 rg_log('my is not ok (cb_tick was not called?): ['
683 . (isset($a['my']) ? $a['my'] : '') . '] != [' . $e . ']!');
684 exit(1);
685 }
686 rg_log_exit();
687
688
689
690 747 rg_log(''); rg_log('');
691 748 $s = 'șțaaș'; $s = 'șțaaș';
692 749 rg_log_enter('visible_string [' . $s . ']'); rg_log_enter('visible_string [' . $s . ']');
File tests/util_exit_code.sh changed (mode: 100755) (index 195b568..cd87e19)
1 1 #!/bin/bash #!/bin/bash
2 2
3 echo "stdout"
4
3 5 exit ${1} exit ${1}
File tests/util_stdout_closes_first.sh added (mode: 100755) (index 0000000..18283ef)
1 #!/bin/bash
2
3 echo "stdout"
4 echo "stderr1" 1>&2
5
6 exec 1<&-
7
8 sleep .2
9
10 echo "stderr2" 1>&2
File tests/wh_cloud.php changed (mode: 100644) (index 478ce80..060a241)
... ... rg_test_create_repo($db, $rg_ui, $repo);
106 106 $repo_url = 'ssh://rocketgit@' . $rg_ssh_host . ':' . $rg_ssh_port $repo_url = 'ssh://rocketgit@' . $rg_ssh_host . ':' . $rg_ssh_port
107 107 . '/user/' . $rg_ui['username'] . '/' . $repo['name']; . '/user/' . $rg_ui['username'] . '/' . $repo['name'];
108 108 rg_log('repo_url=' . escapeshellarg($repo_url)); rg_log('repo_url=' . escapeshellarg($repo_url));
109 $r = rg_exec('./wh_cloud.git.sh ' . escapeshellarg($repo_url), '', FALSE, FALSE);
109 $r = rg_exec('./wh_cloud.git.sh ' . escapeshellarg($repo_url),
110 '', FALSE, FALSE, FALSE);
110 111 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
111 112 rg_log('Could not create local git repo: ' . $r['errmsg'] . '!'); rg_log('Could not create local git repo: ' . $r['errmsg'] . '!');
112 113 exit(1); exit(1);
File tests/wh_http.php changed (mode: 100644) (index 08db757..38d4666)
... ... function clean()
29 29 { {
30 30 rg_log_enter('clean'); rg_log_enter('clean');
31 31 for ($id = 1; $id <= 3; $id++) { for ($id = 1; $id <= 3; $id++) {
32 rg_exec('fuser -k -9 wh-stunnel-' . $id . '.log', '', FALSE, FALSE);
32 rg_exec('fuser -k -9 wh-stunnel-' . $id . '.log', '', FALSE, FALSE, FALSE);
33 33 @unlink('wh-stunnel.conf-' . $id . '.tmp'); @unlink('wh-stunnel.conf-' . $id . '.tmp');
34 34 } }
35 35 rg_log_exit(); rg_log_exit();
 
... ... prepare_http();
39 39
40 40 rg_log(''); rg_log('');
41 41 rg_log('Generating certificates...'); rg_log('Generating certificates...');
42 $r = rg_exec('./ca.sh wh', '', FALSE, FALSE);
42 $r = rg_exec('./ca.sh wh', '', FALSE, FALSE, FALSE);
43 43 if (!strstr($r['data'], 'CA_SH_OK')) { if (!strstr($r['data'], 'CA_SH_OK')) {
44 44 rg_log_ml('data: ' . $r['data']); rg_log_ml('data: ' . $r['data']);
45 45 rg_log('Cannot generate certificates!'); rg_log('Cannot generate certificates!');
 
... ... if ($pid == -1) {
82 82 exit(1); exit(1);
83 83 } }
84 84 if ($pid == 0) { //child if ($pid == 0) { //child
85 rg_exec('stunnel wh-stunnel.conf-1.tmp 1>wh-stunnel-1-1.log 2>wh-stunnel-1-2.log', '', FALSE, FALSE);
85 rg_exec('stunnel wh-stunnel.conf-1.tmp 1>wh-stunnel-1-1.log 2>wh-stunnel-1-2.log',
86 '', FALSE, FALSE, FALSE);
86 87 exit(0); exit(0);
87 88 } }
88 89 rg_log('Started stunnel with pid ' . $pid); rg_log('Started stunnel with pid ' . $pid);
 
... ... if ($pid == -1) {
96 97 exit(1); exit(1);
97 98 } }
98 99 if ($pid == 0) { //child if ($pid == 0) { //child
99 rg_exec('stunnel wh-stunnel.conf-2.tmp 1>wh-stunnel-2-1.log 2>wh-stunnel-2-2.log', '', FALSE, FALSE);
100 rg_exec('stunnel wh-stunnel.conf-2.tmp 1>wh-stunnel-2-1.log 2>wh-stunnel-2-2.log',
101 '', FALSE, FALSE, FALSE);
100 102 exit(0); exit(0);
101 103 } }
102 104 rg_log('Started stunnel with pid ' . $pid); rg_log('Started stunnel with pid ' . $pid);
 
... ... if ($pid == -1) {
110 112 exit(1); exit(1);
111 113 } }
112 114 if ($pid == 0) { //child if ($pid == 0) { //child
113 rg_exec('stunnel wh-stunnel.conf-3.tmp 1>wh-stunnel-3-1.log 2>wh-stunnel-3-2.log', '', FALSE, FALSE);
115 rg_exec('stunnel wh-stunnel.conf-3.tmp 1>wh-stunnel-3-1.log 2>wh-stunnel-3-2.log',
116 '', FALSE, FALSE, FALSE);
114 117 exit(0); exit(0);
115 118 } }
116 119 rg_log('Started stunnel with pid ' . $pid); rg_log('Started stunnel with pid ' . $pid);
File tests/wh_lambda.php changed (mode: 100644) (index 2103c81..4e7016e)
... ... rg_log_enter('Pushing repo, so the trigger has a chanse to execute...');
105 105 $repo_url = 'ssh://rocketgit@' . $rg_ssh_host . ':' . $rg_ssh_port $repo_url = 'ssh://rocketgit@' . $rg_ssh_host . ':' . $rg_ssh_port
106 106 . '/user/' . $rg_ui['username'] . '/' . $repo['name']; . '/user/' . $rg_ui['username'] . '/' . $repo['name'];
107 107 rg_log('repo_url=' . $repo_url); rg_log('repo_url=' . $repo_url);
108 $r = rg_exec('./wh_cloud.git.sh ' . escapeshellarg($repo_url), '', FALSE, FALSE);
108 $r = rg_exec('./wh_cloud.git.sh ' . escapeshellarg($repo_url), '', FALSE, FALSE, FALSE);
109 109 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
110 110 rg_log_ml('Could not create local git repo: ' . $r['errmsg'] . '!'); rg_log_ml('Could not create local git repo: ' . $r['errmsg'] . '!');
111 111 exit(1); exit(1);
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/rocketgit

Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/rocketgit

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