File TODO changed (mode: 100644) (index da9ec60..bf263c0) |
5 |
5 |
[ ] Check XSRF attacks and other types. |
[ ] Check XSRF attacks and other types. |
6 |
6 |
[ ] $rg_pass_key should be done in init.php |
[ ] $rg_pass_key should be done in init.php |
7 |
7 |
[ ] Changing repo name probably is not working right. |
[ ] Changing repo name probably is not working right. |
|
8 |
|
[ ] Run update.php before rpm upgrade the scripts. |
|
9 |
|
[ ] Check if /var/run/rocketgit is really created. Maybe is boot related. |
|
10 |
|
Locking is working right? Because seems the repo were created! |
|
11 |
|
[ ] rg_repo_allow seems to not be used. |
|
12 |
|
[ ] Deny any operation till schema update is done. |
|
13 |
|
[ ] Test and fix update.php script. |
8 |
14 |
[ ] |
[ ] |
9 |
15 |
|
|
10 |
|
== Low priority == |
|
|
16 |
|
== Normal priority == |
|
17 |
|
[ ] Check pack-protocol.txt! |
|
18 |
|
[ ] When push is executed with success, show a nice message from RocketGit. |
|
19 |
|
[ ] Move is_private member in repo array, not test for empty on default rights |
|
20 |
|
[ ] Move default rights to rights table - I do not remember why. |
|
21 |
|
Maybe for consistency. |
|
22 |
|
Ah, yes, also to be able to set rights per branches and per files. |
|
23 |
|
[ ] Log files may be written per repo and per user, with locking... |
|
24 |
|
[ ] Push may be always allowed - but will be done as a merge request! Cool. |
|
25 |
|
Disk space accounting? |
11 |
26 |
[ ] We should make a repo dirty ony if user pushed something with success. |
[ ] We should make a repo dirty ony if user pushed something with success. |
12 |
27 |
[ ] <link rel="icon" type="image/png" id="favicon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8%2F9hAAAACGFjVEwAAAASAAAAAJNtBPIAAAAaZmNUTAAAAAAAAAAQAAAAEAAAAAAAAAAALuAD6AABhIDeugAAALhJREFUOI2Nk8sNxCAMRDlGohauXFOMpfTiAlxICqAELltHLqlgctg1InzMRhpFAc%2BLGWTnmoeZYamt78zXdZmaQtQMADlnU0OIAlbmJUBEcO4bRKQY2rUXIPmAGnDuG%2FBx3%2FfvOPVaDUg%2BoAPUf1PArIMCSD5glMEsUGaG%2BkyAFWIBaCsKuA%2BHGCNijLgP133XgOEtaPFMy2vUolEGJoCIzBmoRUR9%2B7rxj16DZaW%2FmgtmxnJ8V3oAnApQwNS5zpcAAAAaZmNUTAAAAAEAAAAQAAAAEAAAAAAAAAAAAB4D6AIB52fclgAAACpmZEFUAAAAAjiNY2AYBVhBc3Pzf2LEcGreqcbwH1kDNjHauWAUjAJyAADymxf9WF%2Bu8QAAABpmY1RMAAAAAwAAABAAAAAQAAAAAAAAAAAAHgPoAgEK8Q9%2FAAAAFmZkQVQAAAAEOI1jYBgFo2AUjAIIAAAEEAAB0xIn4wAAABpmY1RMAAAABQAAABAAAAAQAAAAAAAAAAAAHgPoAgHnO30FAAAAQGZkQVQAAAAGOI1jYBieYKcaw39ixHCC%2F6cwFWMTw2rz%2F1MM%2F6Vu%2Ff%2F%2F%2FxTD%2F51qEIwuRjsXILuEGLFRMApgAADhNCsVfozYcAAAABpmY1RMAAAABwAAABAAAAAQAAAAAAAAAAAAHgPoAgEKra7sAAAAFmZkQVQAAAAIOI1jYBgFo2AUjAIIAAAEEAABM9s3hAAAABpmY1RMAAAACQAAABAAAAAQAAAAAAAAAAAAHgPoAgHn3p%2BwAAAAKmZkQVQAAAAKOI1jYBgFWEFzc%2FN%2FYsRwat6pxvAfWQM2Mdq5YBSMAnIAAPKbF%2F1BhPl6AAAAGmZjVEwAAAALAAAAEAAAABAAAAAAAAAAAAAeA%2BgCAQpITFkAAAAWZmRBVAAAAAw4jWNrgAWjYBSMArgAAAQQAAHaszpmAAAAGmZjVEwAAAANAAAAEAAAABAAAAAAAAAAAAAeA%2BgCAeeCPiMAAABAZmRBVAAAAA44jWNrgJ5gpxrDf2LEcIL%2FpzAVYxPDavP%2FUwz%2FpW79%2F%2F%2F%2FFMP%2FnWoQjC5GOxcgu4QYsVEwCmAAAOE0KxUmBL0KAAAAGmZjVEwAAAAPAAAAEAAAABAAAAAAAAAAAAAeA%2BgCAQoU7coAAAAWZmRBVAAAABA4jWNrgAWjYBSMArgAAAQQAAEpOBELAAAAGmZjVEwAAAARAAAAEAAAABAAAAAAAAAAAAAeA%2BgCAeYVWtoAAAAqZmRBVAAAABI4jWNrgAVYQXNz839ixHBq3qnG8B9ZAzYx2rlgFIwCcgAA8psX%2FWvpAecAAAAaZmNUTAAAABMAAAAQAAAAEAAAAAAAAAAAAB4D6AIBC4OJMwAAABZmZEFUAAAAFDiNY2AYBaNgFIwCCAAABBAAAcBQHOkAAAAaZmNUTAAAABUAAAAQAAAAEAAAAAAAAAAAAB4D6AIB5kn7SQAAAEBmZEFUAAAAFjiNY2AYnmCnGsN%2FYsRwgv%2BnMBVjE8Nq8%2F9TDP%2Blbv3%2F%2F%2F8Uw%2F%2BdahCMLkY7FyC7hBixUTAKYAAA4TQrFc%2BcEoQAAAAaZmNUTAAAABcAAAAQAAAAEAAAAAAAAAAAAB4D6AIBC98ooAAAABZmZEFUAAAAGDiNY2AYBaNgFIwCCAAABBAAASCZDI4AAAAaZmNUTAAAABkAAAAQAAAAEAAAAAAAAAAAAB4D6AIB5qwZ%2FAAAACpmZEFUAAAAGjiNY2AYBVhBc3Pzf2LEcGreqcbwH1kDNjHauWAUjAJyAADymxf9cjJWbAAAABpmY1RMAAAAGwAAABAAAAAQAAAAAAAAAAAAHgPoAgELOsoVAAAAFmZkQVQAAAAcOI1jYBgFo2AUjAIIAAAEEAAByfEBbAAAABpmY1RMAAAAHQAAABAAAAAQAAAAAAAAAAAAHgPoAgHm8LhvAAAAQGZkQVQAAAAeOI1jYBieYKcaw39ixHCC%2F6cwFWMTw2rz%2F1MM%2F6Vu%2Ff%2F%2F%2FxTD%2F51qEIwuRjsXILuEGLFRMApgAADhNCsVlxR3%2FgAAABpmY1RMAAAAHwAAABAAAAAQAAAAAAAAAAAAHgPoAgELZmuGAAAAFmZkQVQAAAAgOI1jYBgFo2AUjAIIAAAEEAABHP5cFQAAABpmY1RMAAAAIQAAABAAAAAQAAAAAAAAAAAAHgPoAgHlgtAOAAAAKmZkQVQAAAAiOI1jYBgFWEFzc%2FN%2FYsRwat6pxvAfWQM2Mdq5YBSMAnIAAPKbF%2F0%2FMvDdAAAAAElFTkSuQmCC"/> |
[ ] <link rel="icon" type="image/png" id="favicon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8%2F9hAAAACGFjVEwAAAASAAAAAJNtBPIAAAAaZmNUTAAAAAAAAAAQAAAAEAAAAAAAAAAALuAD6AABhIDeugAAALhJREFUOI2Nk8sNxCAMRDlGohauXFOMpfTiAlxICqAELltHLqlgctg1InzMRhpFAc%2BLGWTnmoeZYamt78zXdZmaQtQMADlnU0OIAlbmJUBEcO4bRKQY2rUXIPmAGnDuG%2FBx3%2FfvOPVaDUg%2BoAPUf1PArIMCSD5glMEsUGaG%2BkyAFWIBaCsKuA%2BHGCNijLgP133XgOEtaPFMy2vUolEGJoCIzBmoRUR9%2B7rxj16DZaW%2FmgtmxnJ8V3oAnApQwNS5zpcAAAAaZmNUTAAAAAEAAAAQAAAAEAAAAAAAAAAAAB4D6AIB52fclgAAACpmZEFUAAAAAjiNY2AYBVhBc3Pzf2LEcGreqcbwH1kDNjHauWAUjAJyAADymxf9WF%2Bu8QAAABpmY1RMAAAAAwAAABAAAAAQAAAAAAAAAAAAHgPoAgEK8Q9%2FAAAAFmZkQVQAAAAEOI1jYBgFo2AUjAIIAAAEEAAB0xIn4wAAABpmY1RMAAAABQAAABAAAAAQAAAAAAAAAAAAHgPoAgHnO30FAAAAQGZkQVQAAAAGOI1jYBieYKcaw39ixHCC%2F6cwFWMTw2rz%2F1MM%2F6Vu%2Ff%2F%2F%2FxTD%2F51qEIwuRjsXILuEGLFRMApgAADhNCsVfozYcAAAABpmY1RMAAAABwAAABAAAAAQAAAAAAAAAAAAHgPoAgEKra7sAAAAFmZkQVQAAAAIOI1jYBgFo2AUjAIIAAAEEAABM9s3hAAAABpmY1RMAAAACQAAABAAAAAQAAAAAAAAAAAAHgPoAgHn3p%2BwAAAAKmZkQVQAAAAKOI1jYBgFWEFzc%2FN%2FYsRwat6pxvAfWQM2Mdq5YBSMAnIAAPKbF%2F1BhPl6AAAAGmZjVEwAAAALAAAAEAAAABAAAAAAAAAAAAAeA%2BgCAQpITFkAAAAWZmRBVAAAAAw4jWNrgAWjYBSMArgAAAQQAAHaszpmAAAAGmZjVEwAAAANAAAAEAAAABAAAAAAAAAAAAAeA%2BgCAeeCPiMAAABAZmRBVAAAAA44jWNrgJ5gpxrDf2LEcIL%2FpzAVYxPDavP%2FUwz%2FpW79%2F%2F%2F%2FFMP%2FnWoQjC5GOxcgu4QYsVEwCmAAAOE0KxUmBL0KAAAAGmZjVEwAAAAPAAAAEAAAABAAAAAAAAAAAAAeA%2BgCAQoU7coAAAAWZmRBVAAAABA4jWNrgAWjYBSMArgAAAQQAAEpOBELAAAAGmZjVEwAAAARAAAAEAAAABAAAAAAAAAAAAAeA%2BgCAeYVWtoAAAAqZmRBVAAAABI4jWNrgAVYQXNz839ixHBq3qnG8B9ZAzYx2rlgFIwCcgAA8psX%2FWvpAecAAAAaZmNUTAAAABMAAAAQAAAAEAAAAAAAAAAAAB4D6AIBC4OJMwAAABZmZEFUAAAAFDiNY2AYBaNgFIwCCAAABBAAAcBQHOkAAAAaZmNUTAAAABUAAAAQAAAAEAAAAAAAAAAAAB4D6AIB5kn7SQAAAEBmZEFUAAAAFjiNY2AYnmCnGsN%2FYsRwgv%2BnMBVjE8Nq8%2F9TDP%2Blbv3%2F%2F%2F8Uw%2F%2BdahCMLkY7FyC7hBixUTAKYAAA4TQrFc%2BcEoQAAAAaZmNUTAAAABcAAAAQAAAAEAAAAAAAAAAAAB4D6AIBC98ooAAAABZmZEFUAAAAGDiNY2AYBaNgFIwCCAAABBAAASCZDI4AAAAaZmNUTAAAABkAAAAQAAAAEAAAAAAAAAAAAB4D6AIB5qwZ%2FAAAACpmZEFUAAAAGjiNY2AYBVhBc3Pzf2LEcGreqcbwH1kDNjHauWAUjAJyAADymxf9cjJWbAAAABpmY1RMAAAAGwAAABAAAAAQAAAAAAAAAAAAHgPoAgELOsoVAAAAFmZkQVQAAAAcOI1jYBgFo2AUjAIIAAAEEAAByfEBbAAAABpmY1RMAAAAHQAAABAAAAAQAAAAAAAAAAAAHgPoAgHm8LhvAAAAQGZkQVQAAAAeOI1jYBieYKcaw39ixHCC%2F6cwFWMTw2rz%2F1MM%2F6Vu%2Ff%2F%2F%2FxTD%2F51qEIwuRjsXILuEGLFRMApgAADhNCsVlxR3%2FgAAABpmY1RMAAAAHwAAABAAAAAQAAAAAAAAAAAAHgPoAgELZmuGAAAAFmZkQVQAAAAgOI1jYBgFo2AUjAIIAAAEEAABHP5cFQAAABpmY1RMAAAAIQAAABAAAAAQAAAAAAAAAAAAHgPoAgHlgtAOAAAAKmZkQVQAAAAiOI1jYBgFWEFzc%2FN%2FYsRwat6pxvAfWQM2Mdq5YBSMAnIAAPKbF%2F0%2FMvDdAAAAAElFTkSuQmCC"/> |
13 |
|
[ ] Add key form may be joined with list keys command! |
|
|
28 |
|
[ ] "Add key" form may be joined with list keys command! |
14 |
29 |
[ ] Allow to recover a deleted repository. |
[ ] Allow to recover a deleted repository. |
15 |
30 |
[ ] Deny access in all functions to deleted repositories. |
[ ] Deny access in all functions to deleted repositories. |
16 |
31 |
[ ] Count the numbers of clones/pushes/pulls. |
[ ] Count the numbers of clones/pushes/pulls. |
|
21 |
36 |
[ ] Add a repo_prop_set/get function that will set/get a file in .git folder. |
[ ] Add a repo_prop_set/get function that will set/get a file in .git folder. |
22 |
37 |
This way we can speed up some lookups (no need for database). Hm. |
This way we can speed up some lookups (no need for database). Hm. |
23 |
38 |
[ ] When we delete an repository, we will do repo_prop_set(repo, disabled) and we will |
[ ] When we delete an repository, we will do repo_prop_set(repo, disabled) and we will |
24 |
|
return OK, in the background we will do the removing. Do not forget to also remove clones. Hm. |
|
|
39 |
|
return OK, in the background we will do the removing. |
|
40 |
|
Do not forget to also remove clones. Hm. |
25 |
41 |
[ ] E-mail aliases section. |
[ ] E-mail aliases section. |
26 |
42 |
[ ] User details section (full name, blog, avatar, mail notifications). |
[ ] User details section (full name, blog, avatar, mail notifications). |
27 |
43 |
[ ] Check if user is over-quota on push. |
[ ] Check if user is over-quota on push. |
|
58 |
74 |
[ ] Move forget pass token into users table. |
[ ] Move forget pass token into users table. |
59 |
75 |
[ ] Audit all error messages to not propage usefull info to an attacker. |
[ ] Audit all error messages to not propage usefull info to an attacker. |
60 |
76 |
[ ] git-daemon connection - cannot get IP info? setenv? |
[ ] git-daemon connection - cannot get IP info? setenv? |
|
77 |
|
[ ] Do not show submenus if user is not logged in on repopage (ialbeascu) |
|
78 |
|
- duplicate menus?! maybe add an admin link in repopage that goes |
|
79 |
|
to repo. |
|
80 |
|
[ ] Undo SELinux stuff when uninstalling applications. |
|
81 |
|
[ ] Nice graphic (unrelated to git): http://tctechcrunch2011.files.wordpress.com/2011/07/hadoop2.png?w=640 |
|
82 |
|
[ ] git-notes may be used to attach messages to commits. Nice. |
61 |
83 |
[ ] |
[ ] |
62 |
84 |
|
|
63 |
85 |
== Versus == |
== Versus == |
File hooks/post-receive added (mode: 100755) (index 0000000..8eb0c15) |
|
1 |
|
#!/usr/bin/php |
|
2 |
|
<?php |
|
3 |
|
|
|
4 |
|
// |
|
5 |
|
// post-receive hook |
|
6 |
|
// TODO: This hook can be run for marking repo dirty. |
|
7 |
|
// It is executed once, input is the list of SUCCESSFULLY updated ref. |
|
8 |
|
// The error code is ignored. |
|
9 |
|
// Useful to send mails. |
|
10 |
|
// Warn: new_ref may not point to ref because of concurrent updates. |
|
11 |
|
// |
|
12 |
|
|
|
13 |
|
error_reporting(E_ALL); |
|
14 |
|
ini_set("track_errors", "On"); |
|
15 |
|
|
|
16 |
|
$_start = microtime(TRUE); |
|
17 |
|
|
|
18 |
|
require_once("/etc/rocketgit/config.php"); |
|
19 |
|
|
|
20 |
|
$INC = $rg_scripts . "/inc"; |
|
21 |
|
require_once($INC . "/util.inc.php"); |
|
22 |
|
require_once($INC . "/log.inc.php"); |
|
23 |
|
require_once($INC . "/sql.inc.php"); |
|
24 |
|
require_once($INC . "/repo.inc.php"); |
|
25 |
|
|
|
26 |
|
rg_log_set_file("/var/log/rocketgit/hook_post-receive.log"); |
|
27 |
|
|
|
28 |
|
rg_log("Start..."); |
|
29 |
|
rg_log("_SERVER: " . print_r($_SERVER, TRUE)); |
|
30 |
|
|
|
31 |
|
umask(0022); |
|
32 |
|
|
|
33 |
|
|
|
34 |
|
$f = @fopen("php://stdin", "r"); |
|
35 |
|
if ($f === FALSE) { |
|
36 |
|
rg_log("Error: Cannot open stdin!"); |
|
37 |
|
rg_fatal("Internal error!"); |
|
38 |
|
} |
|
39 |
|
while (($set = fgets($f))) { |
|
40 |
|
$set = trim($set); |
|
41 |
|
if (empty($set)) |
|
42 |
|
continue; |
|
43 |
|
|
|
44 |
|
$x = explode(" ", $set); |
|
45 |
|
$old_rev = @rg_git_rev($x[0]); |
|
46 |
|
$new_rev = @rg_git_rev($x[1]); |
|
47 |
|
$refname = @rg_git_reference($x[2]); |
|
48 |
|
rg_log("refname=$refname old_rev=$old_rev new_rev=$new_rev."); |
|
49 |
|
|
|
50 |
|
if (empty($refname) || empty($old_rev) || empty($new_rev)) |
|
51 |
|
rg_fatal("Invalid parameters [$old_rev $new_rev $refname]!"); |
|
52 |
|
|
|
53 |
|
// TODO: What we should do here?! check man githooks and git-receive-pack! |
|
54 |
|
} |
|
55 |
|
fclose($f); |
|
56 |
|
|
|
57 |
|
|
|
58 |
|
$diff = sprintf("%u", (microtime(TRUE) - $_start) * 1000); |
|
59 |
|
rg_log("Took " . $diff . "ms."); |
|
60 |
|
|
|
61 |
|
@file_put_contents($repo_path . "/rg/hook-post-receive", |
|
62 |
|
"repo: " . $repo . " ($repo_path)" |
|
63 |
|
. "\nat: " . sprintf("%u", $_start) |
|
64 |
|
. "\nuid: " . $uid |
|
65 |
|
. "\npara: $refname $old_rev $new_rev" |
|
66 |
|
. "\nTook: " . $diff . "ms" |
|
67 |
|
. "\n_SERVER: " . print_r($_SERVER, TRUE)); |
|
68 |
|
|
|
69 |
|
// Mark repository dirty for disk statistics and other stuff |
|
70 |
|
@file_put_contents($rg_path . "/dirty", ""); |
|
71 |
|
?> |
File hooks/pre-commit changed (mode: 100755) (index 486f370..831b433) |
... |
... |
$_start = microtime(TRUE); |
9 |
9 |
|
|
10 |
10 |
require_once("/etc/rocketgit/config.php"); |
require_once("/etc/rocketgit/config.php"); |
11 |
11 |
|
|
12 |
|
$INC = dirname(__FILE__) . "/../inc"; |
|
|
12 |
|
$INC = $rg_scripts . "/inc"; |
13 |
13 |
require_once($INC . "/util.inc.php"); |
require_once($INC . "/util.inc.php"); |
14 |
14 |
require_once($INC . "/log.inc.php"); |
require_once($INC . "/log.inc.php"); |
15 |
|
require_once($INC . "/db.inc.php"); |
|
|
15 |
|
require_once($INC . "/sql.inc.php"); |
16 |
16 |
require_once($INC . "/repo.inc.php"); |
require_once($INC . "/repo.inc.php"); |
|
17 |
|
require_once($INC . "/git.inc.php"); |
17 |
18 |
|
|
18 |
19 |
rg_log_set_file("/var/log/rocketgit/hook_pre-commit.log"); |
rg_log_set_file("/var/log/rocketgit/hook_pre-commit.log"); |
19 |
20 |
|
|
20 |
|
rg_log("Start: euid=" . posix_geteuid() . "..."); |
|
|
21 |
|
rg_log("Start..."); |
21 |
22 |
rg_log("_SERVER: " . print_r($_SERVER, TRUE)); |
rg_log("_SERVER: " . print_r($_SERVER, TRUE)); |
22 |
23 |
|
|
23 |
24 |
umask(0022); |
umask(0022); |
24 |
25 |
|
|
25 |
|
$against = |
|
26 |
|
if (rg_git_ref_ok("HEAD")) |
|
|
26 |
|
|
|
27 |
|
if (rg_git_rev_ok("HEAD")) |
27 |
28 |
$against = "HEAD"; |
$against = "HEAD"; |
28 |
29 |
else |
else |
29 |
30 |
$against = $rg_repo_empty; |
$against = $rg_repo_empty; |
|
... |
... |
else |
31 |
32 |
// TODO: Here we can deny non ascii file names |
// TODO: Here we can deny non ascii file names |
32 |
33 |
// git diff --cached --name-only --diff-filter=A -z $against | LC_ALL=C tr -d '[ -~]\0') |
// git diff --cached --name-only --diff-filter=A -z $against | LC_ALL=C tr -d '[ -~]\0') |
33 |
34 |
|
|
|
35 |
|
|
34 |
36 |
$diff = sprintf("%u", (microtime(TRUE) - $_start) * 1000); |
$diff = sprintf("%u", (microtime(TRUE) - $_start) * 1000); |
35 |
37 |
rg_log("Took " . $diff . "ms."); |
rg_log("Took " . $diff . "ms."); |
36 |
38 |
|
|
|
... |
... |
rg_log("Took " . $diff . "ms."); |
40 |
42 |
. "\nuid: " . $uid |
. "\nuid: " . $uid |
41 |
43 |
. "\ncmd: against=$against" |
. "\ncmd: against=$against" |
42 |
44 |
. "\nTook: " . $diff . "ms"); |
. "\nTook: " . $diff . "ms"); |
43 |
|
|
|
44 |
|
// Mark repository dirty for disk statistics and other stuff |
|
45 |
|
@file_put_contents($rg_path . "/dirty", ""); |
|
46 |
45 |
?> |
?> |
File hooks/pre-receive added (mode: 100755) (index 0000000..d7d3035) |
|
1 |
|
#!/usr/bin/php |
|
2 |
|
<?php |
|
3 |
|
|
|
4 |
|
// |
|
5 |
|
// pre-receive hook |
|
6 |
|
// If one check fails, receiving is denied. |
|
7 |
|
// Executed before any ref is updated and before fast-forward checks. |
|
8 |
|
// |
|
9 |
|
|
|
10 |
|
error_reporting(E_ALL); |
|
11 |
|
ini_set("track_errors", "On"); |
|
12 |
|
|
|
13 |
|
$_start = microtime(TRUE); |
|
14 |
|
|
|
15 |
|
require_once("/etc/rocketgit/config.php"); |
|
16 |
|
|
|
17 |
|
$INC = $rg_scripts . "/inc"; |
|
18 |
|
require_once($INC . "/util.inc.php"); |
|
19 |
|
require_once($INC . "/log.inc.php"); |
|
20 |
|
require_once($INC . "/sql.inc.php"); |
|
21 |
|
require_once($INC . "/repo.inc.php"); |
|
22 |
|
|
|
23 |
|
rg_log_set_file("/var/log/rocketgit/hook_pre-receive.log"); |
|
24 |
|
|
|
25 |
|
$uid = @sprintf("%u", getenv("ROCKETGIT_UID")); |
|
26 |
|
$rights = getenv("ROCKETGIT_RIGHTS"); |
|
27 |
|
|
|
28 |
|
rg_log("Start uid=$uid, rights=[$rights]..."); |
|
29 |
|
rg_log("_SERVER: " . print_r($_SERVER, TRUE)); |
|
30 |
|
|
|
31 |
|
umask(0022); |
|
32 |
|
|
|
33 |
|
|
|
34 |
|
$f = @fopen("php://stdin", "r"); |
|
35 |
|
if ($f === FALSE) { |
|
36 |
|
rg_log("Error: Cannot open stdin!"); |
|
37 |
|
rg_fatal("Internal error!"); |
|
38 |
|
} |
|
39 |
|
while (($set = fgets($f))) { |
|
40 |
|
$set = trim($set); |
|
41 |
|
if (empty($set)) |
|
42 |
|
continue; |
|
43 |
|
|
|
44 |
|
$x = explode(" ", $set); |
|
45 |
|
$old_rev = @rg_git_rev($x[0]); |
|
46 |
|
$new_rev = @rg_git_rev($x[1]); |
|
47 |
|
$refname = @rg_git_reference($x[2]); |
|
48 |
|
rg_log("refname=$refname old_rev=$old_rev new_rev=$new_rev."); |
|
49 |
|
|
|
50 |
|
if (empty($refname) || empty($old_rev) || empty($new_rev)) |
|
51 |
|
rg_fatal("Invalid parameters [$old_rev $new_rev $refname]!"); |
|
52 |
|
|
|
53 |
|
if (rg_rights_allow($rights, "P") === FALSE) |
|
54 |
|
rg_fatal("Push is not allowed in this repository!"); |
|
55 |
|
} |
|
56 |
|
fclose($f); |
|
57 |
|
|
|
58 |
|
|
|
59 |
|
$diff = sprintf("%u", (microtime(TRUE) - $_start) * 1000); |
|
60 |
|
rg_log("Took " . $diff . "ms."); |
|
61 |
|
|
|
62 |
|
@file_put_contents($repo_path . "/rg/hook-pre-receive", |
|
63 |
|
"repo: " . $repo . " ($repo_path)" |
|
64 |
|
. "\nat: " . sprintf("%u", $_start) |
|
65 |
|
. "\nuid: " . $uid |
|
66 |
|
. "\npara: $refname $old_rev $new_rev" |
|
67 |
|
. "\nTook: " . $diff . "ms" |
|
68 |
|
. "\t_SERVER: " . print_r($_SERVER, TRUE)); |
|
69 |
|
?> |
File hooks/update changed (mode: 100755) (index 976b872..67b8cf3) |
1 |
1 |
#!/usr/bin/php |
#!/usr/bin/php |
2 |
2 |
<?php |
<?php |
|
3 |
|
|
|
4 |
|
// |
3 |
5 |
// This is called by 'update' hook |
// This is called by 'update' hook |
4 |
6 |
// Inspired by update.sample in git package |
// Inspired by update.sample in git package |
|
7 |
|
// TODO: what we receive when a tag will be created? |
|
8 |
|
// |
|
9 |
|
|
5 |
10 |
error_reporting(E_ALL); |
error_reporting(E_ALL); |
6 |
11 |
ini_set("track_errors", "On"); |
ini_set("track_errors", "On"); |
7 |
12 |
|
|
|
... |
... |
$_start = microtime(TRUE); |
9 |
14 |
|
|
10 |
15 |
require_once("/etc/rocketgit/config.php"); |
require_once("/etc/rocketgit/config.php"); |
11 |
16 |
|
|
12 |
|
$INC = dirname(__FILE__) . "/../inc"; |
|
|
17 |
|
$INC = $rg_scripts . "/inc"; |
13 |
18 |
require_once($INC . "/util.inc.php"); |
require_once($INC . "/util.inc.php"); |
14 |
19 |
require_once($INC . "/log.inc.php"); |
require_once($INC . "/log.inc.php"); |
15 |
|
require_once($INC . "/db.inc.php"); |
|
|
20 |
|
require_once($INC . "/sql.inc.php"); |
16 |
21 |
require_once($INC . "/repo.inc.php"); |
require_once($INC . "/repo.inc.php"); |
17 |
22 |
|
|
18 |
23 |
rg_log_set_file("/var/log/rocketgit/hook_update.log"); |
rg_log_set_file("/var/log/rocketgit/hook_update.log"); |
19 |
24 |
|
|
20 |
|
rg_log("Start: euid=" . posix_geteuid() . "..."); |
|
|
25 |
|
$uid = @sprintf("%u", getenv("ROCKETGIT_UID")); |
|
26 |
|
$rights = getenv("ROCKETGIT_RIGHTS"); |
|
27 |
|
|
|
28 |
|
rg_log("Start uid=$uid, rights=[$rights]..."); |
21 |
29 |
rg_log("_SERVER: " . print_r($_SERVER, TRUE)); |
rg_log("_SERVER: " . print_r($_SERVER, TRUE)); |
22 |
30 |
|
|
23 |
31 |
umask(0022); |
umask(0022); |
24 |
32 |
|
|
25 |
|
$refname = @$_SERVER['argv'][1]; |
|
|
33 |
|
|
|
34 |
|
$refname = @rg_git_reference($_SERVER['argv'][1]); |
26 |
35 |
$old_rev = rg_git_rev(@$_SERVER['argv'][2]); |
$old_rev = rg_git_rev(@$_SERVER['argv'][2]); |
27 |
36 |
$new_rev = rg_git_rev(@$_SERVER['argv'][3]); |
$new_rev = rg_git_rev(@$_SERVER['argv'][3]); |
28 |
37 |
rg_log("refname=$refname old_rev=$old_rev new_rev=$new_rev."); |
rg_log("refname=$refname old_rev=$old_rev new_rev=$new_rev."); |
29 |
38 |
|
|
30 |
|
if (empty($refname) || empty($old_rev) || empty($new_rev)) { |
|
31 |
|
echo "rg: Invalid parameters!\n"; |
|
32 |
|
exit(1); |
|
33 |
|
} |
|
|
39 |
|
if (empty($refname) || empty($old_rev) || empty($new_rev)) |
|
40 |
|
rg_fatal("Invalid parameters [$refname $old_rev $new_rev]!"); |
34 |
41 |
|
|
35 |
|
if (strcmp($rg_repo_zero, $new_rev) == 0) |
|
|
42 |
|
if (strcmp($new_rev, $rg_git_zero) == 0) |
36 |
43 |
$new_rev_type = "delete"; |
$new_rev_type = "delete"; |
37 |
44 |
else |
else |
38 |
45 |
$new_rev_type = rg_git_type($new_rev); |
$new_rev_type = rg_git_type($new_rev); |
|
... |
... |
rg_log("new_rev_type=$new_rev_type."); |
40 |
47 |
|
|
41 |
48 |
if (strcmp($new_rev_type, "commit") == 0) { |
if (strcmp($new_rev_type, "commit") == 0) { |
42 |
49 |
rg_log("It's a commit..."); |
rg_log("It's a commit..."); |
|
50 |
|
|
|
51 |
|
if (strcmp($old_rev, $rg_git_zero) != 0) { |
|
52 |
|
rg_log("This is a reference update..."); |
|
53 |
|
|
|
54 |
|
// check non fast-forward update |
|
55 |
|
if (!rg_rights_allow($rights, "O")) { |
|
56 |
|
$merge_base = rg_git_merge_base($old_rev, $new_rev); |
|
57 |
|
if ($merge_base === FALSE) { |
|
58 |
|
rg_log("Error: " . rg_git_error()); |
|
59 |
|
rg_fatal("Internal error! Try again later!"); |
|
60 |
|
} |
|
61 |
|
|
|
62 |
|
if (strcmp($merge_base, $old_rev) != 0) |
|
63 |
|
rg_fatal("Non fast-forward is not allowed for $refname!"); |
|
64 |
|
} |
|
65 |
|
} |
|
66 |
|
|
43 |
67 |
if (strncmp($refname, "refs/tags/", 10) == 0) { |
if (strncmp($refname, "refs/tags/", 10) == 0) { |
44 |
|
// This is an not annoted tag - we can reject it |
|
45 |
68 |
rg_log("Un-annotated tag..."); |
rg_log("Un-annotated tag..."); |
|
69 |
|
if (strcmp($old_rev, $rg_git_zero) == 0) { |
|
70 |
|
if (!rg_rights_allow($rights, "Y")) |
|
71 |
|
rg_fatal("No rights to create an un-annotated tag!"); |
|
72 |
|
} else { //change |
|
73 |
|
if (!rg_rights_allow($rights, "U")) |
|
74 |
|
rg_fatal("No rights to change an un-annotated tag!"); |
|
75 |
|
} |
46 |
76 |
} else if (strncmp($refname, "refs/heads/", 11) == 0) { |
} else if (strncmp($refname, "refs/heads/", 11) == 0) { |
47 |
|
if (strcmp($old_rev, $rg_repo_zero) == 0) { |
|
|
77 |
|
if (strcmp($old_rev, $rg_git_zero) == 0) { |
48 |
78 |
rg_log("Creating a branch..."); |
rg_log("Creating a branch..."); |
|
79 |
|
if (!rg_rights_allow($rights, "C")) |
|
80 |
|
rg_fatal("You have no rights to create a branch!"); |
49 |
81 |
} else if (rg_git_rev_ok($new_rev . "^2")) { |
} else if (rg_git_rev_ok($new_rev . "^2")) { |
50 |
82 |
rg_log("Merge commit..."); |
rg_log("Merge commit..."); |
|
83 |
|
if (!rg_rights_allow($rights, "M")) |
|
84 |
|
rg_fatal("You have no rights to push merge commits!"); |
51 |
85 |
} else { |
} else { |
52 |
86 |
rg_log("Normal commit..."); |
rg_log("Normal commit..."); |
53 |
|
if (!rg_git_whitespace_ok($old_rev, $new_rev)) { |
|
54 |
|
rg_log("Bad whitespace..."); |
|
|
87 |
|
if (!rg_rights_allow($rights, "W")) { |
|
88 |
|
if (!rg_git_whitespace_ok($old_rev, $new_rev)) |
|
89 |
|
rg_fatal("Bad whitespace is not allowed!"); |
55 |
90 |
} |
} |
56 |
91 |
} |
} |
|
92 |
|
} else { |
|
93 |
|
rg_fatal("Unknown refname provided!"); |
57 |
94 |
} |
} |
58 |
95 |
|
|
59 |
|
// refs/remotes/* |
|
|
96 |
|
// TODO: refs/remotes/* |
60 |
97 |
} else if (strcmp($new_rev_type, "delete") == 0) { |
} else if (strcmp($new_rev_type, "delete") == 0) { |
61 |
98 |
rg_log("It's a delete..."); |
rg_log("It's a delete..."); |
62 |
99 |
if (strncmp($refname, "refs/tags/", 10) == 0) { |
if (strncmp($refname, "refs/tags/", 10) == 0) { |
63 |
|
rg_log("Deleting a tag..."); |
|
|
100 |
|
rg_log("Deleting an un-annotated tag..."); |
|
101 |
|
if (!rg_rights_allow($rights, "u")) |
|
102 |
|
rg_fatal("You have no rights to delete a tag!"); |
64 |
103 |
} else if (strncmp($refname, "refs/heads/", 11) == 0) { |
} else if (strncmp($refname, "refs/heads/", 11) == 0) { |
65 |
104 |
rg_log("Deleting a branch..."); |
rg_log("Deleting a branch..."); |
|
105 |
|
if (!rg_rights_allow($rights, "D")) |
|
106 |
|
rg_fatal("You have no rights to delete a branch!"); |
66 |
107 |
} else if (strncmp($refname, "refs/remotes/", 13) == 0) { |
} else if (strncmp($refname, "refs/remotes/", 13) == 0) { |
67 |
108 |
rg_log("Deleting a tracking branch..."); |
rg_log("Deleting a tracking branch..."); |
|
109 |
|
if (!rg_rights_allow($rights, "D")) |
|
110 |
|
rg_fatal("You have no rights to delete a tracking branch!"); |
68 |
111 |
} |
} |
69 |
112 |
} else if (strcmp($new_rev_type, "tag") == 0) { |
} else if (strcmp($new_rev_type, "tag") == 0) { |
70 |
|
rg_log("It's a tag..."); |
|
|
113 |
|
rg_log("It's an annotated tag..."); |
71 |
114 |
if (strncmp($refname, "refs/tags/", 10) == 0) { |
if (strncmp($refname, "refs/tags/", 10) == 0) { |
72 |
115 |
rg_log("Modify tag..."); |
rg_log("Modify tag..."); |
|
116 |
|
if (!rg_rights_allow($rights, "S")) |
|
117 |
|
rg_fatal("You have no rights to modify a tag!"); |
73 |
118 |
} |
} |
74 |
119 |
} else { |
} else { |
75 |
|
echo "rg: Invalid new rev type!\n"; |
|
76 |
|
exit(1); |
|
|
120 |
|
rg_log("Invalid new_rev type!"); |
|
121 |
|
rg_fatal("Internal error!"); |
77 |
122 |
} |
} |
78 |
123 |
|
|
79 |
124 |
|
|
|
... |
... |
rg_log("Took " . $diff . "ms."); |
85 |
130 |
. "\nat: " . sprintf("%u", $_start) |
. "\nat: " . sprintf("%u", $_start) |
86 |
131 |
. "\nuid: " . $uid |
. "\nuid: " . $uid |
87 |
132 |
. "\npara: $refname $old_rev $new_rev" |
. "\npara: $refname $old_rev $new_rev" |
88 |
|
. "\nTook: " . $diff . "ms"); |
|
89 |
|
|
|
90 |
|
// Mark repository dirty for disk statistics and other stuff |
|
91 |
|
@file_put_contents($rg_path . "/dirty", ""); |
|
|
133 |
|
. "\nTook: " . $diff . "ms" |
|
134 |
|
. "\n_SERVER: " . print_r($_SERVER, TRUE)); |
92 |
135 |
?> |
?> |
File inc/db/struct.inc.php changed (mode: 100644) (index 1bc1782..f359fb8) |
1 |
1 |
<?php |
<?php |
2 |
|
$rg_db_struct = array(); |
|
|
2 |
|
$rg_sql_schema_ver = 1; |
3 |
3 |
|
|
4 |
|
$rg_db_struct[0] = array( |
|
|
4 |
|
$rg_sql_struct = array(); |
|
5 |
|
$rg_sql_struct[0] = array(); |
|
6 |
|
$rg_sql_struct[0]['tables'] = array( |
5 |
7 |
"repos" => "CREATE TABLE repos" |
"repos" => "CREATE TABLE repos" |
6 |
8 |
. " (repo_id SERIAL PRIMARY KEY" |
. " (repo_id SERIAL PRIMARY KEY" |
7 |
9 |
. ", name TEXT UNIQUE NOT NULL" |
. ", name TEXT UNIQUE NOT NULL" |
|
... |
... |
$rg_db_struct[0] = array( |
63 |
65 |
. ", sid TEXT NOT NULL" |
. ", sid TEXT NOT NULL" |
64 |
66 |
. ", expire INTEGER NOT NULL)" |
. ", expire INTEGER NOT NULL)" |
65 |
67 |
); |
); |
|
68 |
|
$rg_sql_struct[0]['other'] = array(); |
|
69 |
|
|
|
70 |
|
$rg_sql_struct[1] = array(); |
|
71 |
|
$rg_sql_struct[1]['tables'] = array( |
|
72 |
|
"suggestions" => "CREATE TABLE suggestions" |
|
73 |
|
. " (suggestion_id SERIAL PRIMARY KEY" |
|
74 |
|
. ", uid INTEGER NOT NULL" |
|
75 |
|
. ", email TEXT NOT NULL" |
|
76 |
|
. ", suggestion TEXT NOT NULL)" |
|
77 |
|
); |
|
78 |
|
$rg_sql_struct[1]['other'] = array(); |
66 |
79 |
|
|
67 |
80 |
/* |
/* |
68 |
81 |
* Generate structure |
* Generate structure |
69 |
82 |
*/ |
*/ |
70 |
|
function rg_db_struct_run($db, $ignore_errors, $drop_tables) |
|
|
83 |
|
function rg_sql_struct_run($db, $ignore_errors, $drop_tables, $old_schema_ver) |
71 |
84 |
{ |
{ |
72 |
|
global $rg_db_struct; |
|
|
85 |
|
global $rg_sql_struct; |
|
86 |
|
global $rg_sql_schema_ver; |
73 |
87 |
|
|
74 |
|
foreach ($rg_db_struct as $index => $sqls) { |
|
75 |
|
foreach ($sqls as $table => $sql) { |
|
76 |
|
if ($drop_tables == 1) { |
|
77 |
|
echo "Dropping table [$table]...\n"; |
|
78 |
|
$sql2 = "DROP TABLE IF EXISTS $table"; |
|
79 |
|
$res = rg_sql_query($db, $sql2); |
|
80 |
|
rg_sql_free_result($res); |
|
81 |
|
} |
|
|
88 |
|
rg_log("sql_struct_run:" |
|
89 |
|
. " ignore_errors=" . ($ignore_errors ? "Yes" : "No") |
|
90 |
|
. " drop_tables=" . ($drop_tables ? "Yes" : "No") |
|
91 |
|
. " old_schema_ver=$old_schema_ver..."); |
|
92 |
|
|
|
93 |
|
for ($i = $old_schema_ver; $i <= $rg_sql_schema_ver; $i++) { |
|
94 |
|
foreach ($rg_sql_struct[$i] as $type => $sqls) { |
|
95 |
|
if (count($sqls) == 0) |
|
96 |
|
continue; |
|
97 |
|
|
|
98 |
|
foreach ($sqls as $id => $sql) { |
|
99 |
|
rg_log("Applying schema $i, type $type, id $id..."); |
|
100 |
|
|
|
101 |
|
if ((strcmp($type, "tables") == 0) |
|
102 |
|
&& ($drop_tables === TRUE)) { |
|
103 |
|
rg_log("Dropping table [$id]..."); |
|
104 |
|
$sql2 = "DROP TABLE IF EXISTS $id"; |
|
105 |
|
$res = rg_sql_query($db, $sql2); |
|
106 |
|
rg_sql_free_result($res); |
|
107 |
|
} |
82 |
108 |
|
|
83 |
|
echo "Creating table [$table]...\n"; |
|
84 |
|
$res = rg_sql_query($db, $sql); |
|
85 |
|
if ($res === FALSE) { |
|
86 |
|
echo "WARN: Cannot create '$table' table ($sql) (" . rg_sql_error() . ")!\n"; |
|
87 |
|
if (!$ignore_errors) |
|
88 |
|
return FALSE; |
|
89 |
|
} else { |
|
90 |
|
rg_sql_free_result($res); |
|
|
109 |
|
rg_log("Running [$sql]..."); |
|
110 |
|
$res = rg_sql_query($db, $sql); |
|
111 |
|
if ($res === FALSE) { |
|
112 |
|
rg_log("WARN: Cannot run sql ($sql) (" . rg_sql_error() . ")!"); |
|
113 |
|
if (!$ignore_errors) |
|
114 |
|
return FALSE; |
|
115 |
|
} else { |
|
116 |
|
rg_sql_free_result($res); |
|
117 |
|
} |
91 |
118 |
} |
} |
92 |
119 |
} |
} |
93 |
120 |
} |
} |
File inc/git.inc.php changed (mode: 100644) (index 8acf049..17ea73b) |
2 |
2 |
require_once($INC . "/util.inc.php"); |
require_once($INC . "/util.inc.php"); |
3 |
3 |
require_once($INC . "/log.inc.php"); |
require_once($INC . "/log.inc.php"); |
4 |
4 |
|
|
|
5 |
|
$rg_git_zero = "0000000000000000000000000000000000000000"; |
|
6 |
|
|
5 |
7 |
$rg_git_error = ""; |
$rg_git_error = ""; |
6 |
8 |
|
|
7 |
9 |
function rg_git_set_error($str) |
function rg_git_set_error($str) |
|
... |
... |
function rg_git_type($obj) |
131 |
133 |
return FALSE; |
return FALSE; |
132 |
134 |
} |
} |
133 |
135 |
|
|
134 |
|
return $a; |
|
|
136 |
|
return trim($a); |
135 |
137 |
} |
} |
136 |
138 |
|
|
137 |
139 |
/* |
/* |
|
... |
... |
function rg_git_rev($rev) |
142 |
144 |
return preg_replace("/[^a-zA-Z0-9^~]/", "", $rev); |
return preg_replace("/[^a-zA-Z0-9^~]/", "", $rev); |
143 |
145 |
} |
} |
144 |
146 |
|
|
|
147 |
|
/* |
|
148 |
|
* Validates a reference |
|
149 |
|
*/ |
|
150 |
|
function rg_git_reference($refname) |
|
151 |
|
{ |
|
152 |
|
if (!preg_match("/[a-zA-Z0-9^~\/_]/", $refname)) |
|
153 |
|
return ""; |
|
154 |
|
|
|
155 |
|
return $refname; |
|
156 |
|
} |
|
157 |
|
|
145 |
158 |
// Check a revision if is OK |
// Check a revision if is OK |
146 |
159 |
// TODO: Unit testing |
// TODO: Unit testing |
147 |
160 |
function rg_git_rev_ok($rev) |
function rg_git_rev_ok($rev) |
|
... |
... |
function rg_git_rev_ok($rev) |
161 |
174 |
// TODO: Unit testing |
// TODO: Unit testing |
162 |
175 |
function rg_git_whitespace_ok($old, $new) |
function rg_git_whitespace_ok($old, $new) |
163 |
176 |
{ |
{ |
164 |
|
$cmd = "git diff --check " . $old . " " . $new . ""; |
|
|
177 |
|
$cmd = "git diff --check " . $old . " " . $new; |
165 |
178 |
rg_log("\texec $cmd..."); |
rg_log("\texec $cmd..."); |
166 |
179 |
$a = @exec($cmd, $output, $err); |
$a = @exec($cmd, $output, $err); |
167 |
180 |
if ($err != 0) { |
if ($err != 0) { |
|
... |
... |
function rg_git_whitespace_ok($old, $new) |
172 |
185 |
return TRUE; |
return TRUE; |
173 |
186 |
} |
} |
174 |
187 |
|
|
|
188 |
|
// TODO: Unit testing |
|
189 |
|
function rg_git_merge_base($old, $new) |
|
190 |
|
{ |
|
191 |
|
$cmd = "git merge-base " . $old . " " . $new; |
|
192 |
|
rg_log("\texec $cmd..."); |
|
193 |
|
$a = @exec($cmd, $output, $err); |
|
194 |
|
if ($err != 0) { |
|
195 |
|
rg_git_set_error("error $err out=[" . implode("|", $output) . "] a=[$a]"); |
|
196 |
|
return FALSE; |
|
197 |
|
} |
|
198 |
|
|
|
199 |
|
return trim($a); |
|
200 |
|
} |
|
201 |
|
|
175 |
202 |
?> |
?> |
File inc/repo.inc.php changed (mode: 100644) (index fbd06b8..2e4f20f) |
1 |
1 |
<?php |
<?php |
2 |
2 |
require_once($INC . "/util.inc.php"); |
require_once($INC . "/util.inc.php"); |
3 |
3 |
require_once($INC . "/log.inc.php"); |
require_once($INC . "/log.inc.php"); |
4 |
|
require_once($INC . "/db.inc.php"); |
|
|
4 |
|
require_once($INC . "/sql.inc.php"); |
5 |
5 |
require_once($INC . "/user.inc.php"); |
require_once($INC . "/user.inc.php"); |
6 |
6 |
require_once($INC . "/git.inc.php"); |
require_once($INC . "/git.inc.php"); |
7 |
7 |
require_once($INC . "/rights.inc.php"); |
require_once($INC . "/rights.inc.php"); |
8 |
8 |
|
|
9 |
|
$rg_repo_zero = "0000000000000000000000000000000000000000"; |
|
10 |
9 |
$rg_repo_empty = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"; |
$rg_repo_empty = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"; |
11 |
10 |
|
|
12 |
11 |
$rg_repo_error = ""; |
$rg_repo_error = ""; |
|
... |
... |
$rg_repo_rights = array( |
15 |
14 |
"A" => "Admin", |
"A" => "Admin", |
16 |
15 |
"F" => "Fetch", |
"F" => "Fetch", |
17 |
16 |
"P" => "Push", |
"P" => "Push", |
|
17 |
|
"S" => "Create annotated tag", |
|
18 |
|
"Y" => "Create un-annotated tag", |
|
19 |
|
"U" => "Modify un-annotated tag", |
|
20 |
|
"u" => "Delete un-annotated tag", |
|
21 |
|
"C" => "Create branch", |
18 |
22 |
"D" => "Delete branch", |
"D" => "Delete branch", |
19 |
|
"t" => "Delete tag", |
|
20 |
|
"T" => "Modify tag", |
|
21 |
|
"C" => "Create branch" |
|
|
23 |
|
"O" => "Non fast-forwards", |
|
24 |
|
"M" => "Merge commits", |
|
25 |
|
"W" => "Bad whitespace" |
22 |
26 |
); |
); |
23 |
27 |
|
|
|
28 |
|
// What rights are on by default |
|
29 |
|
$rg_repo_rights_default = "FM"; |
|
30 |
|
|
24 |
31 |
rg_rights_register("repo", $rg_repo_rights); |
rg_rights_register("repo", $rg_repo_rights); |
25 |
32 |
|
|
26 |
33 |
|
|
|
... |
... |
function rg_repo_allow($db, $ri, $rg_ui, $needed_rights) |
150 |
157 |
} else { |
} else { |
151 |
158 |
$rr = rg_repo_rights_get($db, $ri, $rg_ui['uid'], 0); |
$rr = rg_repo_rights_get($db, $ri, $rg_ui['uid'], 0); |
152 |
159 |
if ($rr['ok'] != 1) { |
if ($rr['ok'] != 1) { |
153 |
|
rg_repo_set_error("Cannot get rights!"); |
|
|
160 |
|
rg_repo_set_error("cannot get rights from db"); |
154 |
161 |
return FALSE; |
return FALSE; |
155 |
162 |
} |
} |
156 |
163 |
$db_rights = $rr['rights']; |
$db_rights = $rr['rights']; |
157 |
164 |
} |
} |
158 |
165 |
rg_log("\tdb rights: " . $db_rights); |
rg_log("\tdb rights: " . $db_rights); |
159 |
166 |
|
|
160 |
|
$len = strlen($needed_rights); |
|
161 |
|
for ($i = 0; $i < $len; $i++) { |
|
162 |
|
if (!strstr($db_rights, $needed_rights[$i])) { |
|
163 |
|
rg_repo_set_error("No rights (" . $needed_rights[$i] . ")"); |
|
164 |
|
return FALSE; |
|
165 |
|
} |
|
|
167 |
|
if (rg_rights_allow($db_rights, $needed_rights) !== TRUE) { |
|
168 |
|
rg_repo_set_error("no rights ($needed_rights) vs ($db_rights)"); |
|
169 |
|
return FALSE; |
166 |
170 |
} |
} |
167 |
171 |
|
|
168 |
172 |
rg_log("\tAllow access!"); |
rg_log("\tAllow access!"); |
|
... |
... |
function rg_repo_rights_get($db, $ri, $uid, $flags) |
466 |
470 |
// Give all rights to owner |
// Give all rights to owner |
467 |
471 |
if ($ri['uid'] == $uid) { |
if ($ri['uid'] == $uid) { |
468 |
472 |
rg_log("\tuid $uid is the owner."); |
rg_log("\tuid $uid is the owner."); |
469 |
|
$dr = rg_rights_all("repo"); |
|
|
473 |
|
$rights = rg_rights_all("repo"); |
470 |
474 |
if (($flags & RG_RIGHTS_FILL_EXISTS) == 0) { |
if (($flags & RG_RIGHTS_FILL_EXISTS) == 0) { |
471 |
475 |
rg_log("\tNo need to fill 'exists' field. Return."); |
rg_log("\tNo need to fill 'exists' field. Return."); |
472 |
|
$ret['rights'] = $dr; |
|
|
476 |
|
$ret['rights'] = $rights; |
473 |
477 |
$ret['ok'] = 1; |
$ret['ok'] = 1; |
474 |
478 |
return $ret; |
return $ret; |
475 |
479 |
} |
} |
476 |
480 |
} else { |
} else { |
477 |
|
$dr = $ri['default_rights']; |
|
|
481 |
|
$rights = $ri['default_rights']; |
478 |
482 |
} |
} |
479 |
483 |
|
|
480 |
484 |
$r = rg_rights_get($db, "repo", $repo_id, $uid); |
$r = rg_rights_get($db, "repo", $repo_id, $uid); |
|
... |
... |
function rg_repo_rights_get($db, $ri, $uid, $flags) |
483 |
487 |
return FALSE; |
return FALSE; |
484 |
488 |
} |
} |
485 |
489 |
|
|
486 |
|
$ret['rights'] = rg_rights_combine($dr, $r['rights']); |
|
487 |
|
rg_log("\tFinal rights($dr + " . $r['rights'] . ")=" . $ret['rights']); |
|
|
490 |
|
$ret['rights'] = rg_rights_combine($rights, $r['rights']); |
|
491 |
|
rg_log("\tFinal rights($rights + " |
|
492 |
|
. $r['rights'] . ")=" . $ret['rights']); |
488 |
493 |
$ret['ok'] = 1; |
$ret['ok'] = 1; |
489 |
494 |
|
|
490 |
495 |
return $ret; |
return $ret; |
|
... |
... |
function rg_repo_rights_list($db, $ri, $url) |
523 |
528 |
return $r; |
return $r; |
524 |
529 |
} |
} |
525 |
530 |
|
|
|
531 |
|
/* |
|
532 |
|
* Returns TRUE if a repo is over limit |
|
533 |
|
*/ |
|
534 |
|
function rg_repo_over_limit($ri) |
|
535 |
|
{ |
|
536 |
|
if ($ri['disk_quota_mb'] == 0) |
|
537 |
|
return FALSE; |
|
538 |
|
|
|
539 |
|
if ($ri['disk_used_mb'] >= $ri['disk_quota_mb']) |
|
540 |
|
return TRUE; |
|
541 |
|
|
|
542 |
|
return FALSE; |
|
543 |
|
} |
|
544 |
|
|
526 |
545 |
?> |
?> |
File inc/user.inc.php changed (mode: 100644) (index b3e7bf7..914d27a) |
1 |
1 |
<?php |
<?php |
2 |
2 |
require_once($INC . "/util.inc.php"); |
require_once($INC . "/util.inc.php"); |
3 |
3 |
require_once($INC . "/log.inc.php"); |
require_once($INC . "/log.inc.php"); |
4 |
|
require_once($INC . "/db.inc.php"); |
|
|
4 |
|
require_once($INC . "/sql.inc.php"); |
5 |
5 |
require_once($INC . "/sess.inc.php"); |
require_once($INC . "/sess.inc.php"); |
6 |
6 |
require_once($INC . "/rights.inc.php"); |
require_once($INC . "/rights.inc.php"); |
7 |
7 |
|
|
|
... |
... |
function rg_user_auto_login($db, $uid, &$rg_ui) |
296 |
296 |
*/ |
*/ |
297 |
297 |
function rg_user_login_by_user_pass($db, $user, $pass, &$rg_ui) |
function rg_user_login_by_user_pass($db, $user, $pass, &$rg_ui) |
298 |
298 |
{ |
{ |
299 |
|
rg_log("user_login: user=$user, pass=$pass..."); |
|
|
299 |
|
rg_log("user_login_by_user_pass: user=$user, pass=$pass..."); |
300 |
300 |
|
|
301 |
301 |
$rg_ui = array(); |
$rg_ui = array(); |
302 |
302 |
$rg_ui['uid'] = 0; |
$rg_ui['uid'] = 0; |
|
... |
... |
function rg_user_login_by_user_pass($db, $user, $pass, &$rg_ui) |
307 |
307 |
return FALSE; |
return FALSE; |
308 |
308 |
} |
} |
309 |
309 |
|
|
310 |
|
$rg_ui = rg_user_info($db, 0, $user, ""); |
|
311 |
|
if ($rg_ui['exists'] != 1) { |
|
|
310 |
|
$rg_ui0 = rg_user_info($db, 0, $user, ""); |
|
311 |
|
if ($rg_ui0['ok'] != 1) { |
|
312 |
|
rg_user_set_error("internal error"); |
|
313 |
|
return FALSE; |
|
314 |
|
} |
|
315 |
|
if ($rg_ui0['exists'] != 1) { |
312 |
316 |
rg_user_set_error("invalid user or pass"); |
rg_user_set_error("invalid user or pass"); |
313 |
317 |
return FALSE; |
return FALSE; |
314 |
318 |
} |
} |
315 |
319 |
|
|
316 |
|
if ($rg_ui['suspended'] > 0) { |
|
|
320 |
|
if ($rg_ui0['suspended'] > 0) { |
317 |
321 |
rg_user_set_error("invalid user or pass"); |
rg_user_set_error("invalid user or pass"); |
318 |
322 |
return FALSE; |
return FALSE; |
319 |
323 |
} |
} |
320 |
324 |
|
|
321 |
|
if ($rg_ui['confirmed'] == 0) { |
|
|
325 |
|
if ($rg_ui0['confirmed'] == 0) { |
322 |
326 |
rg_user_set_error("invalid user or pass"); |
rg_user_set_error("invalid user or pass"); |
323 |
327 |
return FALSE; |
return FALSE; |
324 |
328 |
} |
} |
325 |
329 |
|
|
326 |
|
$sha1pass = rg_user_pass($rg_ui['salt'], $pass); |
|
327 |
|
if (strcmp($sha1pass, $rg_ui['pass']) != 0) { |
|
|
330 |
|
$sha1pass = rg_user_pass($rg_ui0['salt'], $pass); |
|
331 |
|
if (strcmp($sha1pass, $rg_ui0['pass']) != 0) { |
328 |
332 |
rg_user_set_error("invalid user or pass"); |
rg_user_set_error("invalid user or pass"); |
329 |
333 |
return FALSE; |
return FALSE; |
330 |
334 |
} |
} |
331 |
335 |
|
|
|
336 |
|
$rg_ui = $rg_ui0; |
332 |
337 |
rg_user_auto_login($db, $rg_ui['uid'], $rg_ui); |
rg_user_auto_login($db, $rg_ui['uid'], $rg_ui); |
333 |
338 |
|
|
334 |
339 |
rg_user_set_last_seen($db, $rg_ui['uid']); |
rg_user_set_last_seen($db, $rg_ui['uid']); |
|
... |
... |
function rg_user_confirm($db, $token) |
712 |
717 |
rg_user_set_error("cannot update confirmed (" . rg_sql_error() . ")"); |
rg_user_set_error("cannot update confirmed (" . rg_sql_error() . ")"); |
713 |
718 |
return FALSE; |
return FALSE; |
714 |
719 |
} |
} |
|
720 |
|
rg_sql_free_result($res); |
715 |
721 |
|
|
716 |
722 |
return $uid; |
return $uid; |
717 |
723 |
} |
} |
718 |
724 |
|
|
|
725 |
|
/* |
|
726 |
|
* Add a suggestion to database |
|
727 |
|
*/ |
|
728 |
|
function rg_user_suggestion($db, $uid, $email, $suggestion) |
|
729 |
|
{ |
|
730 |
|
$e_email = rg_sql_escape($db, $email); |
|
731 |
|
$e_suggestion = rg_sql_escape($db, $suggestion); |
|
732 |
|
|
|
733 |
|
$sql = "INSERT INTO suggestions (uid, email, suggestion)" |
|
734 |
|
. " VALUES ($uid, '$e_email', '$e_suggestion')"; |
|
735 |
|
$res = rg_sql_query($db, $sql); |
|
736 |
|
if ($res === FALSE) { |
|
737 |
|
rg_user_set_error("cannot add suggestion (" . rg_sql_error() . ")"); |
|
738 |
|
return FALSE; |
|
739 |
|
} |
|
740 |
|
rg_sql_free_result($res); |
|
741 |
|
|
|
742 |
|
return TRUE; |
|
743 |
|
} |
|
744 |
|
|
719 |
745 |
?> |
?> |
File root/index.php changed (mode: 100644) (index 69e85d1..f81dc1a) |
... |
... |
$INC = dirname(__FILE__) . "/../inc"; |
8 |
8 |
$ROOT = dirname(__FILE__); |
$ROOT = dirname(__FILE__); |
9 |
9 |
|
|
10 |
10 |
$THEME = $ROOT . "/themes/default"; |
$THEME = $ROOT . "/themes/default"; |
|
11 |
|
$THEME_COMMON = "themes/common"; |
11 |
12 |
|
|
12 |
13 |
require_once("/etc/rocketgit/config.php"); |
require_once("/etc/rocketgit/config.php"); |
13 |
14 |
require_once($INC . "/log.inc.php"); |
require_once($INC . "/log.inc.php"); |
14 |
|
include_once($INC . "/db.inc.php"); |
|
|
15 |
|
include_once($INC . "/sql.inc.php"); |
15 |
16 |
include_once($INC . "/user.inc.php"); |
include_once($INC . "/user.inc.php"); |
16 |
17 |
include_once($INC . "/repo.inc.php"); |
include_once($INC . "/repo.inc.php"); |
17 |
18 |
include_once($INC . "/keys.inc.php"); |
include_once($INC . "/keys.inc.php"); |
|
... |
... |
include_once($INC . "/token.inc.php"); |
19 |
20 |
|
|
20 |
21 |
rg_log_set_file("/var/log/rocketgit-web/main.log"); |
rg_log_set_file("/var/log/rocketgit-web/main.log"); |
21 |
22 |
|
|
22 |
|
$rg_sql_debug = $rg_db_debug; |
|
23 |
|
|
|
24 |
23 |
// TODO: make subop and subsubop as strings |
// TODO: make subop and subsubop as strings |
25 |
24 |
$op = rg_var_str("op"); |
$op = rg_var_str("op"); |
26 |
25 |
$subop = rg_var_uint("subop"); |
$subop = rg_var_uint("subop"); |
|
... |
... |
rg_log("_COOKIE: " . trim(print_r($_COOKIE, TRUE))); |
35 |
34 |
rg_log("Start! op=$op/$subop/$subsubop, doit=$doit, sid=$sid..."); |
rg_log("Start! op=$op/$subop/$subsubop, doit=$doit, sid=$sid..."); |
36 |
35 |
|
|
37 |
36 |
|
|
38 |
|
$head = ""; |
|
39 |
|
$head .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"" |
|
40 |
|
. " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
|
41 |
|
$head .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"; |
|
42 |
|
$head .= "<head>\n"; |
|
43 |
|
$head .= " <title>RocketGit</title>\n"; |
|
44 |
|
$head .= " <meta content=\"text/html; charset=UTF-8\" http-equiv=\"content-type\" />\n"; |
|
45 |
|
$css = preg_replace("/\n/", " ", @file_get_contents($THEME . "/main.css")); |
|
46 |
|
$head .= " <style type=\"text/css\">" . $css . "</style>\n"; |
|
47 |
|
$head .= "</head>\n"; |
|
48 |
|
$head .= "<body>\n"; |
|
49 |
|
|
|
50 |
|
|
|
51 |
37 |
// database connection |
// database connection |
52 |
|
$db = rg_sql_open($rg_db); |
|
|
38 |
|
$db = rg_sql_open($rg_sql); |
53 |
39 |
if ($db === FALSE) |
if ($db === FALSE) |
54 |
40 |
die("Cannot open database!"); |
die("Cannot open database!"); |
55 |
41 |
|
|
|
... |
... |
do { |
62 |
48 |
include($INC . "/dispatch/dispatch.php"); |
include($INC . "/dispatch/dispatch.php"); |
63 |
49 |
} while (strcmp($op, "") != 0); |
} while (strcmp($op, "") != 0); |
64 |
50 |
|
|
65 |
|
$tail = "</body>\n"; |
|
66 |
|
$tail .= "</html>\n"; |
|
67 |
|
|
|
68 |
51 |
|
|
69 |
52 |
// menu |
// menu |
70 |
53 |
$amenu = array( |
$amenu = array( |
71 |
|
"login" => array("text" => "Login"), |
|
|
54 |
|
"login" => array("text" => "Login", "uid0" => 1), |
72 |
55 |
"personal" => array("text" => "Personal"), |
"personal" => array("text" => "Personal"), |
73 |
56 |
"repo" => array("text" => "Repositories"), |
"repo" => array("text" => "Repositories"), |
74 |
57 |
"keys" => array("text" => "SSH keys"), |
"keys" => array("text" => "SSH keys"), |
75 |
58 |
"admin" => array("text" => "Admin", "needs_admin" => 1), |
"admin" => array("text" => "Admin", "needs_admin" => 1), |
|
59 |
|
"suggestion"=> array("text" => "Suggestion"), |
76 |
60 |
"logout" => array("text" => "Logout") |
"logout" => array("text" => "Logout") |
77 |
61 |
); |
); |
78 |
62 |
|
|
|
... |
... |
foreach ($amenu as $_op => $_info) { |
82 |
66 |
if (isset($_info['needs_admin']) && ($rg_ui['is_admin'] == 0)) |
if (isset($_info['needs_admin']) && ($rg_ui['is_admin'] == 0)) |
83 |
67 |
continue; |
continue; |
84 |
68 |
|
|
|
69 |
|
if (isset($_info['uid0']) && ($rg_ui['uid'] > 0)) |
|
70 |
|
continue; |
|
71 |
|
|
|
72 |
|
if (!isset($_info['uid0']) && ($rg_ui['uid'] == 0)) |
|
73 |
|
continue; |
|
74 |
|
|
85 |
75 |
$_text = $_info['text']; |
$_text = $_info['text']; |
86 |
76 |
if (strcmp($_op, $op) == 0) { |
if (strcmp($_op, $op) == 0) { |
87 |
77 |
$menu .= $add . "[$_text]\n"; |
$menu .= $add . "[$_text]\n"; |
88 |
78 |
} else { |
} else { |
89 |
|
$menu .= $add . "[<a href=\"" |
|
90 |
|
. rg_re_url($_op) . "\">$_text</a>]\n"; |
|
|
79 |
|
$menu .= $add . "<a class=\"menu\" href=\"" |
|
80 |
|
. rg_re_url($_op) . "\">$_text</a>\n"; |
91 |
81 |
} |
} |
92 |
82 |
$add = " "; |
$add = " "; |
93 |
83 |
} |
} |
94 |
84 |
|
|
95 |
|
if (isset($rg_ui['username'])) |
|
96 |
|
$menu .= " [" . $rg_ui['username'] . "]\n"; |
|
97 |
|
$menu .= "<br />\n"; |
|
98 |
|
|
|
|
85 |
|
if ($rg_ui['uid'] > 0) |
|
86 |
|
$rg_username = $rg_ui['username']; |
|
87 |
|
else |
|
88 |
|
$rg_username = "Not logged in"; |
99 |
89 |
|
|
100 |
|
echo $head . $menu . $body . $tail; |
|
|
90 |
|
include($THEME . "/index.php"); |
101 |
91 |
|
|
102 |
92 |
$_diff = sprintf("%u", (microtime(TRUE) - $_s) * 1000); |
$_diff = sprintf("%u", (microtime(TRUE) - $_s) * 1000); |
103 |
93 |
rg_log("Done in $_diff ms."); |
rg_log("Done in $_diff ms."); |
File scripts/cron.php changed (mode: 100644) (index 4e150a8..b1affcd) |
... |
... |
require_once("/etc/rocketgit/config.php"); |
9 |
9 |
|
|
10 |
10 |
$INC = dirname(__FILE__) . "/../inc"; |
$INC = dirname(__FILE__) . "/../inc"; |
11 |
11 |
require_once($INC . "/log.inc.php"); |
require_once($INC . "/log.inc.php"); |
12 |
|
require_once($INC . "/db.inc.php"); |
|
|
12 |
|
require_once($INC . "/sql.inc.php"); |
13 |
13 |
require_once($INC . "/repo.inc.php"); |
require_once($INC . "/repo.inc.php"); |
14 |
14 |
require_once($INC . "/keys.inc.php"); |
require_once($INC . "/keys.inc.php"); |
15 |
15 |
|
|
|
... |
... |
rg_log_set_file("/var/log/rocketgit/cron.log"); |
19 |
19 |
$lock = "/var/run/rocketgit/cron.lock"; |
$lock = "/var/run/rocketgit/cron.lock"; |
20 |
20 |
rg_lock_or_exit($lock); |
rg_lock_or_exit($lock); |
21 |
21 |
|
|
22 |
|
$rg_sql_debug = $rg_db_debug; |
|
|
22 |
|
rg_log("Start..."); |
23 |
23 |
|
|
24 |
|
rg_log("Start: euid=" . posix_geteuid() . "..."); |
|
25 |
|
|
|
26 |
|
$db = rg_sql_open($rg_db); |
|
|
24 |
|
$db = rg_sql_open($rg_sql); |
27 |
25 |
if ($db === FALSE) { |
if ($db === FALSE) { |
28 |
26 |
rg_log("Cannot connect to database (" . rg_sql_error() . ")!"); |
rg_log("Cannot connect to database (" . rg_sql_error() . ")!"); |
29 |
27 |
// TODO: inform admin - already by e-mail? |
// TODO: inform admin - already by e-mail? |
|
... |
... |
if (date("H") == 0) { |
64 |
62 |
} else { |
} else { |
65 |
63 |
while (($row = rg_sql_fetch_array($res))) { |
while (($row = rg_sql_fetch_array($res))) { |
66 |
64 |
$sql = "UPDATE users" |
$sql = "UPDATE users" |
67 |
|
. " SET disk_space_used = " . $row['disk_space_used'] |
|
|
65 |
|
. " SET disk_used_mb = " . $row['disk_used_mb'] |
68 |
66 |
. " WHERE uid = " . $row['uid']; |
. " WHERE uid = " . $row['uid']; |
69 |
67 |
$res2 = rg_sql_query($db, $sql); |
$res2 = rg_sql_query($db, $sql); |
70 |
68 |
rg_sql_free_result($res2); |
rg_sql_free_result($res2); |
File scripts/remote.php changed (mode: 100644) (index 04fa37b..d8c8822) |
... |
... |
require_once("/etc/rocketgit/config.php"); |
10 |
10 |
$INC = dirname(__FILE__) . "/../inc"; |
$INC = dirname(__FILE__) . "/../inc"; |
11 |
11 |
require_once($INC . "/util.inc.php"); |
require_once($INC . "/util.inc.php"); |
12 |
12 |
require_once($INC . "/log.inc.php"); |
require_once($INC . "/log.inc.php"); |
13 |
|
require_once($INC . "/db.inc.php"); |
|
|
13 |
|
require_once($INC . "/sql.inc.php"); |
14 |
14 |
require_once($INC . "/repo.inc.php"); |
require_once($INC . "/repo.inc.php"); |
15 |
15 |
|
|
16 |
16 |
rg_log_set_file("/var/log/rocketgit/remote.log"); |
rg_log_set_file("/var/log/rocketgit/remote.log"); |
17 |
17 |
|
|
18 |
|
$rg_sql_debug = $rg_db_debug; |
|
19 |
|
|
|
20 |
18 |
function fatal($str) |
function fatal($str) |
21 |
19 |
{ |
{ |
22 |
20 |
global $access_type; |
global $access_type; |
23 |
21 |
|
|
24 |
22 |
rg_log("Sending error: " . $str); |
rg_log("Sending error: " . $str); |
25 |
|
$str2 = "FATAL ERROR: " . $str . "\n"; |
|
|
23 |
|
$str2 = "RocketGit: FATAL ERROR: " . $str . "\n"; |
26 |
24 |
if ($access_type == 2) { // git |
if ($access_type == 2) { // git |
27 |
25 |
$str3 = "\n" . $str2; |
$str3 = "\n" . $str2; |
28 |
26 |
$len = strlen($str3) + 4; |
$len = strlen($str3) + 4; |
|
... |
... |
function fatal($str) |
34 |
32 |
exit(1); |
exit(1); |
35 |
33 |
} |
} |
36 |
34 |
|
|
37 |
|
rg_log("Start: euid=" . posix_geteuid() . "..."); |
|
38 |
|
//rg_log("_SERVER: " . print_r($_SERVER, TRUE)); |
|
|
35 |
|
rg_log("Start..."); |
|
36 |
|
rg_log("_SERVER: " . print_r($_SERVER, TRUE)); |
39 |
37 |
|
|
40 |
38 |
umask(0022); |
umask(0022); |
41 |
39 |
|
|
|
... |
... |
if (isset($_SERVER['SSH_CONNECTION'])) { |
77 |
75 |
if ($line_len < $len) |
if ($line_len < $len) |
78 |
76 |
fatal("Too less data ($line_len/$len) received!"); |
fatal("Too less data ($line_len/$len) received!"); |
79 |
77 |
|
|
80 |
|
// parse something like: 002bgit-upload-pack /aa.git.host=localhost |
|
|
78 |
|
// parse something like: 002bgit-upload-pack /aa.git[0x00]host=localhost |
81 |
79 |
$line = substr($line, 4); |
$line = substr($line, 4); |
82 |
80 |
$v = explode("\0", $line); |
$v = explode("\0", $line); |
83 |
81 |
$cmd_repo = trim($v[0]); |
$cmd_repo = trim($v[0]); |
|
... |
... |
if (isset($_SERVER['SSH_CONNECTION'])) { |
87 |
85 |
// extract command and compute permissions |
// extract command and compute permissions |
88 |
86 |
if (strncmp($cmd_repo, "git-upload-pack", 15) == 0) { |
if (strncmp($cmd_repo, "git-upload-pack", 15) == 0) { |
89 |
87 |
$cmd = "git-upload-pack"; |
$cmd = "git-upload-pack"; |
90 |
|
$perms = "F"; |
|
|
88 |
|
$needed_rights = "F"; |
|
89 |
|
$push = 0; |
91 |
90 |
} else if (strncmp($cmd_repo, "git-receive-pack", 16) == 0) { |
} else if (strncmp($cmd_repo, "git-receive-pack", 16) == 0) { |
92 |
91 |
$cmd = "git-receive-pack"; |
$cmd = "git-receive-pack"; |
93 |
|
$perms = "P"; |
|
|
92 |
|
$needed_rights = ""; |
|
93 |
|
$push = 1; |
94 |
94 |
} else { |
} else { |
95 |
|
fatal("Unknown command!"); |
|
|
95 |
|
fatal("Unknown command [$cmd_repo]!"); |
96 |
96 |
} |
} |
97 |
97 |
|
|
98 |
98 |
// extract repository name |
// extract repository name |
|
... |
... |
$repo = trim($repo, "' "); |
101 |
101 |
$repo = ltrim($repo, "/"); |
$repo = ltrim($repo, "/"); |
102 |
102 |
$repo = preg_replace('/\.git$/' , '', $repo); |
$repo = preg_replace('/\.git$/' , '', $repo); |
103 |
103 |
|
|
104 |
|
rg_log("host=[$host] cmd=[$cmd] repo=[$repo] perms=[$perms]."); |
|
|
104 |
|
rg_log("host=[$host] cmd=[$cmd] repo=[$repo]."); |
105 |
105 |
|
|
106 |
106 |
// validity/security checks |
// validity/security checks |
107 |
107 |
if (rg_repo_ok($repo) !== TRUE) |
if (rg_repo_ok($repo) !== TRUE) |
108 |
108 |
fatal("Repo [$repo] is invalid (" . rg_repo_error() . ")"); |
fatal("Repo [$repo] is invalid (" . rg_repo_error() . ")"); |
109 |
109 |
|
|
110 |
|
$db = rg_sql_open($rg_db); |
|
|
110 |
|
$db = rg_sql_open($rg_sql); |
111 |
111 |
if ($db === FALSE) |
if ($db === FALSE) |
112 |
112 |
fatal("Internal error (db)!"); |
fatal("Internal error (db)!"); |
113 |
113 |
|
|
|
... |
... |
if ($ri['exists'] != 1) |
120 |
120 |
if ($ri['deleted'] == 1) |
if ($ri['deleted'] == 1) |
121 |
121 |
fatal("Repo was deleted!"); |
fatal("Repo was deleted!"); |
122 |
122 |
|
|
123 |
|
$rg_ui = array("uid" => $uid, "is_admin" => 0); |
|
124 |
|
if (!rg_repo_allow($db, $ri, $rg_ui, $perms)) |
|
125 |
|
fatal("You do not have this type of access to this repository!"); |
|
|
123 |
|
$ret = rg_repo_rights_get($db, $ri, $uid, 0); |
|
124 |
|
if ($ret['ok'] !== 1) |
|
125 |
|
fatal("Internal error (rights_get)"); |
|
126 |
|
$rights = $ret['rights']; |
|
127 |
|
|
|
128 |
|
if (rg_rights_allow($rights, $needed_rights) === FALSE) |
|
129 |
|
fatal("Repo does not exists."); |
126 |
130 |
|
|
127 |
131 |
// TODO: limit per connection |
// TODO: limit per connection |
128 |
132 |
|
|
|
... |
... |
$repo_base = rg_repo_name2base($repo); |
132 |
136 |
$repo_path = $repo_base . $repo . ".git"; |
$repo_path = $repo_base . $repo . ".git"; |
133 |
137 |
rg_log("repo_path=$repo_path."); |
rg_log("repo_path=$repo_path."); |
134 |
138 |
|
|
|
139 |
|
if (($push == 1) && rg_repo_over_limit($ri)) |
|
140 |
|
fatal("Cannot push: repo is over limit" |
|
141 |
|
. " (" . $ri['disk_used_mb']. "MiB >= " |
|
142 |
|
. $ri['disk_quota_mb'] . "MiB)"); |
|
143 |
|
|
|
144 |
|
// Put in environment all we need |
|
145 |
|
putenv("ROCKETGIT_UID=" . $uid); |
|
146 |
|
putenv("ROCKETGIT_RIGHTS=" . $rights); |
|
147 |
|
|
135 |
148 |
$run = "git-shell -c \"" . $cmd . " '" . escapeshellcmd($repo_path) . "'\""; |
$run = "git-shell -c \"" . $cmd . " '" . escapeshellcmd($repo_path) . "'\""; |
136 |
149 |
rg_log("Running [$run]..."); |
rg_log("Running [$run]..."); |
137 |
150 |
passthru($run, $ret); |
passthru($run, $ret); |
|
... |
... |
rg_log("[$run] returned $ret."); |
139 |
152 |
|
|
140 |
153 |
$diff = sprintf("%u", (microtime(TRUE) - $_start) * 1000); |
$diff = sprintf("%u", (microtime(TRUE) - $_start) * 1000); |
141 |
154 |
rg_log("Took " . $diff . "ms."); |
rg_log("Took " . $diff . "ms."); |
142 |
|
|
|
143 |
|
@file_put_contents($repo_path . "/rocketgit/last_access", |
|
144 |
|
"repo: " . $repo . " ($repo_path)" |
|
145 |
|
. "\nat: " . sprintf("%u", $_start) |
|
146 |
|
. "\nuid: " . $uid |
|
147 |
|
. "\ncmd: $cmd" |
|
148 |
|
. "\nperms: $perms" |
|
149 |
|
. "\nTook: " . $diff . "ms"); |
|
150 |
|
|
|
151 |
|
// Mark repository dirty for disk statistics and other stuff |
|
152 |
|
if (strcmp($cmd, "git-receive-pack") == 0) |
|
153 |
|
@file_put_contents($rg_path . "/dirty", ""); |
|
154 |
155 |
?> |
?> |
File tests/hook_update.sh added (mode: 100755) (index 0000000..36b13a1) |
|
1 |
|
#!/bin/bash |
|
2 |
|
|
|
3 |
|
rm -rf hook_update_*.git |
|
4 |
|
mkdir hook_update_dest.git |
|
5 |
|
( |
|
6 |
|
cd hook_update_dest.git |
|
7 |
|
git init --bare |
|
8 |
|
) |
|
9 |
|
cp ../hooks/update hook_update_dest.git/hooks/ |
|
10 |
|
|
|
11 |
|
git clone hook_update_dest.git hook_update_src.git |
|
12 |
|
|
|
13 |
|
cd hook_update_src.git |
|
14 |
|
|
|
15 |
|
echo "=== Testing push without rights..." |
|
16 |
|
echo "aaa" > a |
|
17 |
|
git add a |
|
18 |
|
git commit -m "a" a |
|
19 |
|
echo "bbb" >> a |
|
20 |
|
git commit -m "b" a |
|
21 |
|
git push origin master |
|
22 |
|
if [ "${?}" != "1" ]; then |
|
23 |
|
echo "Should not work!" |
|
24 |
|
exit 1 |
|
25 |
|
fi |
|
26 |
|
echo "=== Testing push with rights..." |
|
27 |
|
export ROCKETGIT_RIGHTS="C" |
|
28 |
|
git push origin master |
|
29 |
|
if [ "${?}" != "0" ]; then |
|
30 |
|
echo "Should work!" |
|
31 |
|
exit 1 |
|
32 |
|
fi |
|
33 |
|
|
|
34 |
|
echo "=== Testing not fast-forward without rights..." |
|
35 |
|
git reset --hard HEAD~1 |
|
36 |
|
echo "bbb" > a |
|
37 |
|
git commit -m "new a" a |
|
38 |
|
git push --force origin master |
|
39 |
|
if [ "${?}" != "1" ]; then |
|
40 |
|
echo "Should not work!" |
|
41 |
|
exit 1 |
|
42 |
|
fi |
|
43 |
|
echo "=== Testing not fast-forward with rights..." |
|
44 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}O" |
|
45 |
|
cd hook_update_src.git |
|
46 |
|
git push --force origin master |
|
47 |
|
if [ "${?}" != "0" ]; then |
|
48 |
|
echo "Should work!" |
|
49 |
|
exit 1 |
|
50 |
|
fi |
|
51 |
|
|
|
52 |
|
echo "=== Testing un-annotated tag creation without rights..." |
|
53 |
|
git tag tag1 |
|
54 |
|
git push --tags origin |
|
55 |
|
if [ "${?}" != "1" ]; then |
|
56 |
|
echo "Should not work!" |
|
57 |
|
exit 1 |
|
58 |
|
fi |
|
59 |
|
echo "=== Testing un-annotated tag creation with rights..." |
|
60 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}Y" |
|
61 |
|
git push --tags origin |
|
62 |
|
if [ "${?}" != "0" ]; then |
|
63 |
|
echo "Should work!" |
|
64 |
|
exit 1 |
|
65 |
|
fi |
|
66 |
|
|
|
67 |
|
echo "=== Testing un-annotated tag modify without rights..." |
|
68 |
|
git tag -d tag1 |
|
69 |
|
git tag tag1 HEAD~1 |
|
70 |
|
git push --force --tags origin |
|
71 |
|
if [ "${?}" != "1" ]; then |
|
72 |
|
echo "Should not work!" |
|
73 |
|
exit 1 |
|
74 |
|
fi |
|
75 |
|
echo "=== Testing un-annotated tag modify with rights..." |
|
76 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}U" |
|
77 |
|
git push --force --tags origin |
|
78 |
|
if [ "${?}" != "0" ]; then |
|
79 |
|
echo "Should work!" |
|
80 |
|
exit 1 |
|
81 |
|
fi |
|
82 |
|
|
|
83 |
|
echo "=== Testing un-annotated tag deletion without rights..." |
|
84 |
|
git tag -d tag1 |
|
85 |
|
git push origin :refs/tags/tag1 |
|
86 |
|
if [ "${?}" != "1" ]; then |
|
87 |
|
echo "Should not work!" |
|
88 |
|
exit 1 |
|
89 |
|
fi |
|
90 |
|
echo "=== Testing un-annotated tag deletion with rights..." |
|
91 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}u" |
|
92 |
|
git push origin :refs/tags/tag1 |
|
93 |
|
if [ "${?}" != "0" ]; then |
|
94 |
|
echo "Should work!" |
|
95 |
|
exit 1 |
|
96 |
|
fi |
|
97 |
|
|
|
98 |
|
echo "=== Testing merge-commit without rights..." |
|
99 |
|
git checkout -b branch1 |
|
100 |
|
echo "ccc" >> a |
|
101 |
|
git commit -m "new b" a |
|
102 |
|
git checkout master |
|
103 |
|
echo "a" > b; git add b |
|
104 |
|
git commit -m "c" b |
|
105 |
|
git merge branch1 |
|
106 |
|
git push |
|
107 |
|
if [ "${?}" != "1" ]; then |
|
108 |
|
echo "Should not work!" |
|
109 |
|
exit 1 |
|
110 |
|
fi |
|
111 |
|
echo "=== Testing merge-commit with rights..." |
|
112 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}M" |
|
113 |
|
git push |
|
114 |
|
if [ "${?}" != "0" ]; then |
|
115 |
|
echo "Should work!" |
|
116 |
|
exit 1 |
|
117 |
|
fi |
|
118 |
|
|
|
119 |
|
echo "=== Testing bad-whitespace without rights..." |
|
120 |
|
echo -e " \t \ta \t\n \r\n" > b |
|
121 |
|
git commit -m "d" b |
|
122 |
|
git push |
|
123 |
|
if [ "${?}" != "1" ]; then |
|
124 |
|
echo "Should not work!" |
|
125 |
|
exit 1 |
|
126 |
|
fi |
|
127 |
|
echo "=== Testing merge-commit with rights..." |
|
128 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}W" |
|
129 |
|
git push |
|
130 |
|
if [ "${?}" != "0" ]; then |
|
131 |
|
echo "Should work!" |
|
132 |
|
exit 1 |
|
133 |
|
fi |
|
134 |
|
|
|
135 |
|
echo "=== Testing branch delete without rights..." |
|
136 |
|
git push origin branch1 |
|
137 |
|
git push origin :branch1 |
|
138 |
|
if [ "${?}" != "1" ]; then |
|
139 |
|
echo "Should not work!" |
|
140 |
|
exit 1 |
|
141 |
|
fi |
|
142 |
|
echo "=== Testing branch delete with rights..." |
|
143 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}D" |
|
144 |
|
git push origin :branch1 |
|
145 |
|
if [ "${?}" != "0" ]; then |
|
146 |
|
echo "Should work!" |
|
147 |
|
exit 1 |
|
148 |
|
fi |
|
149 |
|
|
|
150 |
|
echo "=== Testing annotated tag create without rights..." |
|
151 |
|
git tag -a tag2 -m "xxx" |
|
152 |
|
git push origin --tags |
|
153 |
|
if [ "${?}" != "1" ]; then |
|
154 |
|
echo "Should not work!" |
|
155 |
|
exit 1 |
|
156 |
|
fi |
|
157 |
|
echo "=== Testing annotated tag create with rights..." |
|
158 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}S" |
|
159 |
|
git push origin --tags |
|
160 |
|
if [ "${?}" != "0" ]; then |
|
161 |
|
echo "Should work!" |
|
162 |
|
exit 1 |
|
163 |
|
fi |
|
164 |
|
|
|
165 |
|
|
|
166 |
|
cd .. |
|
167 |
|
echo "Rights=${ROCKETGIT_RIGHTS}." |
|
168 |
|
|
|
169 |
|
rm -rf hook_update_*.git |
|
170 |
|
|
|
171 |
|
echo "Done!" |
File tests/repo.php changed (mode: 100644) (index 4c73d48..819e53c) |
... |
... |
rg_log("name2base1"); |
19 |
19 |
$e = "/u/a/a/"; |
$e = "/u/a/a/"; |
20 |
20 |
$c = rg_repo_name2base("aa"); |
$c = rg_repo_name2base("aa"); |
21 |
21 |
if (strcmp($c, $e) != 0) { |
if (strcmp($c, $e) != 0) { |
22 |
|
echo "name2base1 is not working correctly: c=$c e=$e.\n"; |
|
|
22 |
|
rg_log("name2base1 is not working correctly: c=$c e=$e."); |
23 |
23 |
exit(1); |
exit(1); |
24 |
24 |
} |
} |
25 |
25 |
|
|
|
... |
... |
rg_log("name2base2"); |
27 |
27 |
$e = "/u/a/_/"; |
$e = "/u/a/_/"; |
28 |
28 |
$c = rg_repo_name2base("a"); |
$c = rg_repo_name2base("a"); |
29 |
29 |
if (strcmp($c, $e) != 0) { |
if (strcmp($c, $e) != 0) { |
30 |
|
echo "name2base2 is not working correctly: c=$c e=$e.\n"; |
|
|
30 |
|
rg_log("name2base2 is not working correctly: c=$c e=$e."); |
31 |
31 |
exit(1); |
exit(1); |
32 |
32 |
} |
} |
33 |
33 |
|
|
|
... |
... |
$rg_repo_allow = '/^[A-Za-z0-9]*$/'; |
36 |
36 |
$v = "xx"; |
$v = "xx"; |
37 |
37 |
$c = rg_repo_ok($v); |
$c = rg_repo_ok($v); |
38 |
38 |
if ($c !== TRUE) { |
if ($c !== TRUE) { |
39 |
|
echo "repo_allow problem for valid repo [$v] (c=$c).\n"; |
|
|
39 |
|
rg_log("repo_allow problem for valid repo [$v] (c=$c)."); |
40 |
40 |
exit(1); |
exit(1); |
41 |
41 |
} |
} |
42 |
42 |
|
|
|
... |
... |
$rg_repo_allow = '/^[A-Za-z0-9]*$/'; |
45 |
45 |
$v = "eyhtmcmet_"; |
$v = "eyhtmcmet_"; |
46 |
46 |
$c = rg_repo_ok($v); |
$c = rg_repo_ok($v); |
47 |
47 |
if ($c !== FALSE) { |
if ($c !== FALSE) { |
48 |
|
echo "repo_allow problem for '_' in [$v] (c=$c).\n"; |
|
|
48 |
|
rg_log("repo_allow problem for '_' in [$v] (c=$c)."); |
49 |
49 |
exit(1); |
exit(1); |
50 |
50 |
} |
} |
51 |
51 |
|
|
|
... |
... |
$rg_repo_allow = '/^[A-Za-z0-9_.-]*$/'; |
54 |
54 |
$v = ".e&y.h-tmcmet&_.-"; |
$v = ".e&y.h-tmcmet&_.-"; |
55 |
55 |
$c = rg_repo_ok($v); |
$c = rg_repo_ok($v); |
56 |
56 |
if ($c !== FALSE) { |
if ($c !== FALSE) { |
57 |
|
echo "repo_allow problem for '&'.\n"; |
|
|
57 |
|
rg_log("repo_allow problem for '&'."); |
58 |
58 |
exit(1); |
exit(1); |
59 |
59 |
} |
} |
60 |
60 |
|
|
|
... |
... |
$rg_repo_allow = '/^[A-Za-z0-9_.-]*$/'; |
63 |
63 |
$v = "a..b"; |
$v = "a..b"; |
64 |
64 |
$c = rg_repo_ok($v); |
$c = rg_repo_ok($v); |
65 |
65 |
if ($c !== FALSE) { |
if ($c !== FALSE) { |
66 |
|
echo "repo_allow problem for '..'.\n"; |
|
|
66 |
|
rg_log("repo_allow problem for '..'."); |
67 |
67 |
exit(1); |
exit(1); |
68 |
68 |
} |
} |
69 |
69 |
|
|
|
... |
... |
$rg_repo_allow = '/^[A-Za-z0-9]*$/'; |
73 |
73 |
$rg_repo_max_len = 10; |
$rg_repo_max_len = 10; |
74 |
74 |
$c = rg_repo_ok($v); |
$c = rg_repo_ok($v); |
75 |
75 |
if ($c !== FALSE) { |
if ($c !== FALSE) { |
76 |
|
echo "repo_ok: max length is not enforced!\n"; |
|
|
76 |
|
rg_log("repo_ok: max length is not enforced!"); |
77 |
77 |
exit(1); |
exit(1); |
78 |
78 |
} |
} |
79 |
79 |
|
|
80 |
80 |
$db = rg_sql_open("dbname=trg"); |
$db = rg_sql_open("dbname=trg"); |
81 |
81 |
if ($db === FALSE) { |
if ($db === FALSE) { |
82 |
|
echo "Cannot create a database (" . rg_sql_error() . ")!\n"; |
|
|
82 |
|
rg_log("Cannot create a database (" . rg_sql_error() . ")!"); |
83 |
83 |
exit(1); |
exit(1); |
84 |
84 |
} |
} |
85 |
85 |
|
|
86 |
|
$r = rg_db_struct_run($db, FALSE, 1); |
|
|
86 |
|
$ignore_errors = TRUE; |
|
87 |
|
$drop_tables = TRUE; |
|
88 |
|
$old_schema_ver = 0; |
|
89 |
|
$r = rg_sql_struct_run($db, $ignore_errors, $drop_tables, $old_schema_ver); |
87 |
90 |
if ($r === FALSE) { |
if ($r === FALSE) { |
88 |
|
echo "Cannot create struct!\n"; |
|
|
91 |
|
rg_log("Cannot create struct!"); |
89 |
92 |
exit(1); |
exit(1); |
90 |
93 |
} |
} |
91 |
94 |
|
|
|
95 |
|
rg_log("Inserting a fake user"); |
92 |
96 |
$sql = "INSERT INTO repos (repo_id, name, uid, itime" |
$sql = "INSERT INTO repos (repo_id, name, uid, itime" |
93 |
97 |
. ", disk_quota_mb, max_commit_size" |
. ", disk_quota_mb, max_commit_size" |
94 |
98 |
. ", master, description, git_dir_done, default_rights)" |
. ", master, description, git_dir_done, default_rights)" |
95 |
99 |
. " VALUES (1, 'repo1', 1, 0, 0, 0, 0, 'bla bla desc', 1, 'F')"; |
. " VALUES (1, 'repo1', 1, 0, 0, 0, 0, 'bla bla desc', 1, 'F')"; |
96 |
100 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
97 |
101 |
if ($res === FALSE) { |
if ($res === FALSE) { |
98 |
|
echo "Cannot insert a user (" . rg_sql_error() . ")!\n"; |
|
|
102 |
|
rg_log("Cannot insert a user (" . rg_sql_error() . ")!"); |
99 |
103 |
exit(1); |
exit(1); |
100 |
104 |
} |
} |
101 |
105 |
|
|
102 |
|
echo "test giving rights\n"; |
|
|
106 |
|
rg_log("test giving rights"); |
103 |
107 |
$repo_id = 1; |
$repo_id = 1; |
104 |
108 |
$ri = rg_repo_info($db, $repo_id, ""); |
$ri = rg_repo_info($db, $repo_id, ""); |
105 |
109 |
$uid = 10; |
$uid = 10; |
106 |
110 |
$v = rg_repo_rights_set($db, $ri, $uid, "P"); |
$v = rg_repo_rights_set($db, $ri, $uid, "P"); |
107 |
111 |
if ($v === FALSE) { |
if ($v === FALSE) { |
108 |
|
echo "Cannot give rights (1)!\n"; |
|
|
112 |
|
rg_log("Cannot give rights (1)!"); |
109 |
113 |
exit(1); |
exit(1); |
110 |
114 |
} |
} |
111 |
115 |
|
|
112 |
|
echo "owner gets all rights.\n"; |
|
|
116 |
|
rg_log("owner gets all rights"); |
113 |
117 |
$uid = 1; |
$uid = 1; |
114 |
118 |
$e = rg_rights_all("repo"); |
$e = rg_rights_all("repo"); |
115 |
119 |
$r = rg_repo_rights_get($db, $ri, $uid, 0); |
$r = rg_repo_rights_get($db, $ri, $uid, 0); |
116 |
120 |
$c = $r['rights']; |
$c = $r['rights']; |
117 |
121 |
if (strcmp($c, $e) != 0) { |
if (strcmp($c, $e) != 0) { |
118 |
|
echo "Owner did not get all rights: c=$c e=$e.\n"; |
|
|
122 |
|
rg_log("Owner did not get all rights: c=$c e=$e."); |
119 |
123 |
exit(1); |
exit(1); |
120 |
124 |
} |
} |
121 |
125 |
|
|
122 |
|
echo "non-owner gets correct rights: F gets from default rights.\n"; |
|
|
126 |
|
rg_log("non-owner gets correct rights: F gets from default rights."); |
123 |
127 |
$uid = 12; |
$uid = 12; |
124 |
128 |
$r = rg_repo_rights_set($db, $ri, $uid, "P"); |
$r = rg_repo_rights_set($db, $ri, $uid, "P"); |
125 |
129 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
126 |
|
echo "Cannot set rights (" . rg_repo_error() . ")!\n"; |
|
|
130 |
|
rg_log("Cannot set rights (" . rg_repo_error() . ")!"); |
127 |
131 |
exit(1); |
exit(1); |
128 |
132 |
} |
} |
129 |
133 |
$e = "FP"; |
$e = "FP"; |
130 |
134 |
$r = rg_repo_rights_get($db, $ri, $uid, 0); |
$r = rg_repo_rights_get($db, $ri, $uid, 0); |
131 |
135 |
$c = $r['rights']; |
$c = $r['rights']; |
132 |
136 |
if (strcmp($c, $e) != 0) { |
if (strcmp($c, $e) != 0) { |
133 |
|
echo "Non-owner did not get correct rights: c=$c e=$e.\n"; |
|
|
137 |
|
rg_log("Non-owner did not get correct rights: c=$c e=$e."); |
134 |
138 |
exit(1); |
exit(1); |
135 |
139 |
} |
} |
136 |
140 |
|
|
137 |
|
echo "owner can set separate rights for him\n"; |
|
|
141 |
|
rg_log("owner can set separate rights for him"); |
138 |
142 |
$uid = 1; |
$uid = 1; |
139 |
143 |
$v = rg_repo_rights_set($db, $ri, $uid, "A"); |
$v = rg_repo_rights_set($db, $ri, $uid, "A"); |
140 |
144 |
if ($v === FALSE) { |
if ($v === FALSE) { |
141 |
|
echo "Owner cannot set separate rights for him!\n"; |
|
|
145 |
|
rg_log("Owner cannot set separate rights for him!"); |
142 |
146 |
exit(1); |
exit(1); |
143 |
147 |
} |
} |
144 |
148 |
|
|
145 |
149 |
rg_log("list1"); |
rg_log("list1"); |
146 |
150 |
$r = rg_repo_rights_list($db, $ri, "/prj1"); |
$r = rg_repo_rights_list($db, $ri, "/prj1"); |
147 |
151 |
if ($r === FALSE) { |
if ($r === FALSE) { |
148 |
|
echo "Cannot list rights (" . rg_repo_error() . ")\n"; |
|
|
152 |
|
rg_log("Cannot list rights (" . rg_repo_error() . ")"); |
|
153 |
|
exit(1); |
|
154 |
|
} |
|
155 |
|
|
|
156 |
|
rg_log("disk1"); |
|
157 |
|
$ri['disk_quota_mb'] = 10; |
|
158 |
|
$ri['disk_used_mb'] = 20; |
|
159 |
|
$r = rg_repo_over_limit($ri); |
|
160 |
|
if ($r !== TRUE) { |
|
161 |
|
rg_log("Over limit is wrong (1)!"); |
|
162 |
|
exit(1); |
|
163 |
|
} |
|
164 |
|
|
|
165 |
|
rg_log("disk2"); |
|
166 |
|
$ri['disk_quota_mb'] = 20; |
|
167 |
|
$ri['disk_used_mb'] = 10; |
|
168 |
|
$r = rg_repo_over_limit($ri); |
|
169 |
|
if ($r !== FALSE) { |
|
170 |
|
rg_log("Over limit is wrong (2)!"); |
149 |
171 |
exit(1); |
exit(1); |
150 |
172 |
} |
} |
151 |
173 |
|
|
152 |
174 |
rg_sql_close($db); |
rg_sql_close($db); |
153 |
175 |
|
|
154 |
|
echo "OK\n"; |
|
|
176 |
|
echo "repo: done!\n"; |
155 |
177 |
?> |
?> |