xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
Commit 9d680f000b7c486be4664e1cb944f424c977c874

Bulk update.

Author: Catalin(ux) M. BOIE
Author date (UTC): 2011-07-25 19:06
Committer: Catalin(ux) M. BOIE
Commit date (UTC): 2011-07-25 19:07
Tree: 493ce2376966d9db5983a0efc1d54f3fe9a1e07d
Parents: 9bb20c348a4933056d8f67bd151eb35cf0325835
File Lines added Lines deleted
README 10 1
TODO 25 3
admin/init.php 7 4
admin/update.php 52 0
duilder 7 6
duilder.conf 1 1
hooks/post-receive 71 0
hooks/post-update 8 0
hooks/pre-commit 7 8
hooks/pre-receive 69 0
hooks/update 65 22
inc/admin/users/add.php 12 2
inc/admin/users/user.form.php 1 1
inc/db/struct.inc.php 47 20
inc/db_sqlite.inc.php 0 108
inc/dispatch/dispatch.php 5 0
inc/feedback/suggestion.form.php 37 0
inc/feedback/suggestion.php 50 0
inc/git.inc.php 29 2
inc/keys.inc.php 1 1
inc/login/login.form.php 1 1
inc/repo.inc.php 36 17
inc/repo/repo.php 4 0
inc/repo/repo_page.php 2 1
inc/rights.inc.php 12 1
inc/sess.inc.php 1 1
inc/sql.inc.php 20 0
inc/state.inc.php 1 1
inc/token.inc.php 1 1
inc/user.inc.php 34 8
inc/user/forgot.php 20 15
inc/util.inc.php 20 0
rocketgit.spec.in 2 1
root/index.php 18 28
root/themes/common/rg1.png 0 0
root/themes/common/rg16x16.png 0 0
root/themes/common/rg2.png 0 0
root/themes/common/rg4.png 0 0
root/themes/common/rg5.png 0 0
root/themes/default/index.php 36 0
root/themes/default/main.css 26 0
samples/config.php 2 2
scripts/cron.php 4 6
scripts/q.php 3 5
scripts/remote.php 28 27
tests/Makefile 10 3
tests/hook_pre-receive.sh 38 0
tests/hook_update.sh 171 0
tests/keys.php 6 3
tests/repo.php 44 22
tests/rights.php 16 0
tests/sql.php 1 1
tests/state.php 7 4
tests/user.php 4 1

File README changed (mode: 100644) (index 8552860..5ad3d65)
9 9 == Features == == Features ==
10 10 . No Java . No Java
11 11 . No Javascript . No Javascript
12 . Very little dependencies
12 . Very little dependencies, all packaged in main-stream distributions
13 13 . SELinux friendly . SELinux friendly
14 . Very small
14 15 . .
15 16
16 17
 
57 58 # setsebool -P httpd_can_sendmail on # setsebool -P httpd_can_sendmail on
58 59
59 60 . Edit firewall to permit port ssh, git, http and https . Edit firewall to permit port ssh, git, http and https
61
62
63 == Thanks ==
64 . Special thanks to my family that supported me in this project.
65 . Special thanks to my brother that contributed brain and time to this project.
66 . Special thanks to git people for the best tool to manage sources.
67 . Special thanks to a lot of people that came with suggestions.
68 . Special thanks to gitosys, Gitorious and other projects from where I learned things.

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 admin/init.php changed (mode: 100644) (index 03fc8c0..df61bed)
... ... require_once("/etc/rocketgit/config.php");
8 8 $INC = dirname(__FILE__) . "/../inc"; $INC = dirname(__FILE__) . "/../inc";
9 9 require_once($INC . "/util.inc.php"); require_once($INC . "/util.inc.php");
10 10 require_once($INC . "/log.inc.php"); require_once($INC . "/log.inc.php");
11 require_once($INC . "/db.inc.php");
11 require_once($INC . "/sql.inc.php");
12 12 require_once($INC . "/db/struct.inc.php"); require_once($INC . "/db/struct.inc.php");
13 require_once($INC . "/repo.inc.php");
14 13
15 14 rg_log_set_file("init.log"); rg_log_set_file("init.log");
16 15
17 $db = rg_sql_open($rg_db);
16 $db = rg_sql_open($rg_sql);
18 17 if ($db === FALSE) { if ($db === FALSE) {
19 18 echo "Internal error (" . rg_sql_error() . ")!\n"; echo "Internal error (" . rg_sql_error() . ")!\n";
20 19 exit(1); exit(1);
21 20 } }
22 21
23 if (rg_db_struct_run($db, TRUE, 0) !== TRUE) {
22 $ignore_errors = FALSE;
23 $drop_tables = FALSE;
24 $old_schema_ver = 0;
25 $r = rg_sql_struct_run($db, $ignore_errors, $drop_tables, $old_schema_ver);
26 if ($r !== TRUE) {
24 27 echo "Cannot init structure (" . rg_sql_error() . ")!\n"; echo "Cannot init structure (" . rg_sql_error() . ")!\n";
25 28 exit(1); exit(1);
26 29 } }

File admin/update.php added (mode: 100644) (index 0000000..8eb5a09)
1 <?php
2 // This is executed at every update
3 error_reporting(E_ALL);
4 ini_set("track_errors", "On");
5
6 require_once("/etc/rocketgit/config.php");
7
8 $INC = dirname(__FILE__) . "/../inc";
9 require_once($INC . "/util.inc.php");
10 require_once($INC . "/log.inc.php");
11 require_once($INC . "/state.inc.php");
12 require_once($INC . "/sql.inc.php");
13 require_once($INC . "/db/struct.inc.php");
14
15 rg_log_set_file("/var/log/rocketgit/update.log");
16
17 $db = rg_sql_open($rg_sql);
18 if ($db === FALSE) {
19 echo "Internal error (" . rg_sql_error() . ")!\n";
20 exit(1);
21 }
22
23 // Get current schema version
24 $old_schema_ver = rg_state_get($db, "schema_version");
25 if (empty($old_schema_ver))
26 $old_schema_ver = 1;
27
28 if (rg_sql_begin($db) !== TRUE) {
29 echo "RocketGit: Cannot start transaction (" . rg_sql_error() . ")!\n";
30 exit(1);
31 }
32
33 $ignore_errors = FALSE;
34 $drop_tables = FALSE;
35 $r = rg_sql_struct_run($db, $ignore_errors, $drop_tables, $old_schema_ver);
36 if ($r !== TRUE) {
37 echo "rocketgir: Cannot update schema (" . rg_sql_error() . ")!\n";
38 exit(1);
39 }
40
41 if (rg_state_set("schema_version", $rg_sql_schema_version) !== TRUE) {
42 echo "rocketgir: Cannot set schema_version"
43 . " (" . rg_state_error() . ")!\n";
44 exit(1);
45 }
46
47 if (rg_sql_commit($db) !== TRUE) {
48 echo "RocketGit: Cannot start transaction (" . rg_sql_error() . ")!\n";
49 exit(1);
50 }
51
52 ?>

File duilder changed (mode: 100755) (index dbdd391..f8ee87e)
... ... USR_LIB="/usr/lib"
331 331 USR_SHARE="/usr/share" USR_SHARE="/usr/share"
332 332 USR_SHARE_DOC="/usr/share/doc/${PRJ}-${VER}" USR_SHARE_DOC="/usr/share/doc/${PRJ}-${VER}"
333 333 SBIN="/usr/sbin" SBIN="/usr/sbin"
334 VAR_LOG="/var/log"
335 VAR_RUN="/var/run"
334 VAR="/var"
336 335
337 336 while [ "${1}" != "" ]; do while [ "${1}" != "" ]; do
338 337 VAR="`echo ${1} | cut -d'=' -f1`" VAR="`echo ${1} | cut -d'=' -f1`"
 
... ... while [ "${1}" != "" ]; do
354 353 USR_LIB="${VAL}" USR_LIB="${VAL}"
355 354 ;; ;;
356 355 --localstatedir) --localstatedir)
357 VAR_RUN="${VAL}"
358 ;;
359 --log-dir)
360 VAR_LOG="${VAL}"
356 VAR="${VAL}"
361 357 ;; ;;
362 358 --datadir) --datadir)
363 359 USR_SHARE="${VAL}" USR_SHARE="${VAL}"
 
... ... while [ "${1}" != "" ]; do
366 362 shift shift
367 363 done done
368 364
365 # Last fixes
366 VAR_LOG="${VAR}/log"
367 VAR_RUN="${VAR}/run"
368
369
369 370 # Truncate future sed file # Truncate future sed file
370 371 > tmp.sed > tmp.sed
371 372

File duilder.conf changed (mode: 100644) (index f3ac577..3923b9d)
1 1 PRJ="rocketgit" PRJ="rocketgit"
2 VER="0.9"
2 VER="0.10"
3 3 REV="1" REV="1"
4 4 EXCLUDE=".exclude" EXCLUDE=".exclude"
5 5 EXPORT_PATH="/data/www/umbrella/kernel/us/rocketgit" EXPORT_PATH="/data/www/umbrella/kernel/us/rocketgit"

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/post-update added (mode: 100755) (index 0000000..ec17ec1)
1 #!/bin/sh
2 #
3 # An example hook script to prepare a packed repository for use over
4 # dumb transports.
5 #
6 # To enable this hook, rename this file to "post-update".
7
8 exec git update-server-info

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/admin/users/add.php changed (mode: 100644) (index 5424d49..bb0b957)
... ... if ($doit == 1) {
20 20 $session_time = rg_var_uint("session_time"); $session_time = rg_var_uint("session_time");
21 21
22 22 while (1) { while (1) {
23 if (rg_user_ok($xuser) !== TRUE) {
24 $errmsg[] = "Invalid user name (" . rg_user_error() . ")!";
25 break;
26 }
27
28 if (rg_user_pass_ok($xpass) !== TRUE) {
29 $errmsg[] = "Invalid password (" . rg_user_error() . ")!";
30 break;
31 }
32
23 33 $_ui = rg_user_info($db, 0, $xuser, ""); $_ui = rg_user_info($db, 0, $xuser, "");
24 34 if ($_ui['ok'] != 1) { if ($_ui['ok'] != 1) {
25 $errmsg[] = "Internal error!";
35 $errmsg[] = "Internal error.";
26 36 break; break;
27 37 } }
28 38
29 39 if ($_ui['exists'] == 1) { if ($_ui['exists'] == 1) {
30 $errmsg[] = "User already exists";
40 $errmsg[] = "User already exists.";
31 41 break; break;
32 42 } }
33 43

File inc/admin/users/user.form.php changed (mode: 100644) (index 4ee35c6..a3d4124)
... ... $_form .= '
20 20
21 21 <table> <table>
22 22 <tr> <tr>
23 <td>Name:</td>
23 <td>User name:</td>
24 24 <td><input type="text" name="xuser" value="' . $xuser . '"/></td> <td><input type="text" name="xuser" value="' . $xuser . '"/></td>
25 25 </tr> </tr>
26 26

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/db_sqlite.inc.php deleted (index 510a17a..0000000)
1 <?php
2 require_once($INC . "/log.inc.php");
3
4 $rg_sql_debug = 0;
5
6 $rg_sql_error = "";
7
8 /*
9 * Set error string
10 */
11 function rg_sql_set_error($str)
12 {
13 global $rg_sql_error;
14
15 rg_log("\tError: $str");
16 $rg_sql_error = $str;
17 }
18
19 function rg_sql_error()
20 {
21 global $rg_sql_error;
22
23 return $rg_sql_error;
24 }
25
26 /*
27 * Connect to database
28 */
29 function rg_sql_open($str)
30 {
31 global $rg_sql_debug;
32
33 if ($rg_sql_debug > 0)
34 rg_log("DB: opening [$str]...");
35
36 if (strncmp($str, "sqlite:", 7) != 0) {
37 sql_set_error("$str connect string not supported");
38 return FALSE;
39 }
40
41 $file = substr($str, 7);
42
43 $db = new SQLite3($file);
44 if ($db === FALSE) {
45 rg_sql_set_error("Cannot connect to database $file: " . $db->lastErrorMsg());
46 return FALSE;
47 }
48
49 return $db;
50 }
51
52 /*
53 * Escaping
54 */
55 function rg_sql_escape($db, $str)
56 {
57 return $db->escapeString($str);
58 }
59
60 /*
61 * Do a query
62 */
63 function rg_sql_query($db, $sql)
64 {
65 global $rg_sql_debug;
66
67 if ($rg_sql_debug > 0)
68 rg_log("DB: running [$sql]...");
69
70 $res = $db->query($sql);
71 if ($res === FALSE) {
72 rg_sql_set_error("$sql: " . $db->lastErrorMsg());
73 return FALSE;
74 }
75
76 return $res;
77 }
78
79 /*
80 * Close database
81 */
82 function rg_sql_close($db)
83 {
84 $db->close();
85 }
86
87 /*
88 * Free results
89 */
90 function rg_sql_free_result($res)
91 {
92 $res->finalize();
93 }
94
95 /*
96 * Returns a row as an associated array
97 */
98 function rg_sql_fetch_array($res)
99 {
100 return $res->fetchArray(SQLITE3_ASSOC);
101 }
102
103 function rg_sql_last_id($db)
104 {
105 return $db->lastInsertRowID();
106 }
107
108 ?>

File inc/dispatch/dispatch.php changed (mode: 100644) (index c1e9569..5b9d59c)
... ... case 'confirm':
72 72 $body .= $_confirm; $body .= $_confirm;
73 73 break; break;
74 74
75 case 'suggestion':
76 include($INC . "/feedback/suggestion.php");
77 $body .= $_suggestion;
78 break;
79
75 80 default: default:
76 81 rg_log("Invalid operation!"); rg_log("Invalid operation!");
77 82 } }

File inc/feedback/suggestion.form.php added (mode: 100644) (index 0000000..ea65116)
1 <?php
2
3 $_form = "";
4
5 if (count($errmsg) > 0)
6 $_form .= "<font color=red>" . implode("<br />\n", $errmsg) . "</font><br />\n";
7
8 $_form .= '
9 <form method="post" action="' . rg_re_post("suggestion") . '">
10 <input type="hidden" name="op" value="suggestion">
11 <input type="hidden" name="doit" value="1">
12 <input type="hidden" name="token" value="' . rg_token_get($db, $sid) . '">
13
14 <table>
15 <tr>
16 <td>E-mail:</td>
17 <td>
18 <input type="text" name="email" value="' . $email . '"><br />
19 </td>
20 </tr>
21
22 <tr>
23 <td>Suggection:</td>
24 <td>
25 <textarea name="suggestion" rows="6" cols="40">' . $suggestion . '</textarea><br />
26 </td>
27 </tr>
28
29 <tr>
30 <td colspan="2"><input type="submit" value="Send"></td>
31 </tr>
32
33 </table>
34 </form>
35 ';
36
37 ?>

File inc/feedback/suggestion.php added (mode: 100644) (index 0000000..bad041a)
1 <?php
2 rg_log("/feedback/suggestion");
3
4 $_suggestion = "<br />\n";
5
6 $errmsg = array();
7 $show_form = 1;
8
9 if ($doit == 1) {
10 $email = rg_var_str("email");
11 $suggestion = rg_var_str("suggestion");
12
13 while (1) {
14 if (!rg_token_valid($db, $sid, $token)) {
15 $error[] = "Invalid token. Try again.";
16 break;
17 }
18
19 if (empty($email)) {
20 $errmsg[] = "Invalid e-mail.";
21 break;
22 }
23
24 if (empty($suggestion)) {
25 $errmsg[] = "Invalid suggestion.";
26 break;
27 }
28
29 $r = rg_user_suggestion($db, $rg_ui['uid'], $email, $suggestion);
30 if ($r === FALSE) {
31 $errmsg[] = "Could not add suggestion (" . rg_user_error() . ")!";
32 break;
33 }
34
35 $show_form = 0;
36 $_suggestion .= "Thank you very much!";
37 break;
38 }
39 } else {
40 $email = "";
41 $suggestion = "";
42 }
43
44 if ($show_form == 1) {
45 include($INC . "/feedback/suggestion.form.php");
46 $_suggestion .= $_form;
47 }
48
49 ?>
50

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/keys.inc.php changed (mode: 100644) (index c47dedb..bbe6c5a)
1 1 <?php <?php
2 require_once($INC . "/db.inc.php");
2 require_once($INC . "/sql.inc.php");
3 3 require_once($INC . "/state.inc.php"); require_once($INC . "/state.inc.php");
4 4
5 5 $rg_keys_error = ""; $rg_keys_error = "";

File inc/login/login.form.php changed (mode: 100644) (index 268d54e..dd81c57)
... ... $_form .= '
10 10 <input type="hidden" name="subop" value="1"> <input type="hidden" name="subop" value="1">
11 11 <input type="hidden" name="doit" value="1"> <input type="hidden" name="doit" value="1">
12 12
13 User: <input type="text" name="user" value="' . $user . '"><br />
13 Username: <input type="text" name="user" value="' . $user . '"><br />
14 14 Password: <input type="password" name="pass" value="' . $pass . '"><br /> Password: <input type="password" name="pass" value="' . $pass . '"><br />
15 15 <input type="submit" value="Login"> <input type="submit" value="Login">
16 16 </form> </form>

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/repo/repo.php changed (mode: 100644) (index 75225c5..402f056)
... ... case 1: // create
41 41 $_body .= "OK!"; $_body .= "OK!";
42 42 } else { } else {
43 43 $_action = "Create"; $_action = "Create";
44
45 // defaults
46 $rights = $rg_repo_rights_default;
47
44 48 include($INC . "/repo/repo.form.php"); include($INC . "/repo/repo.form.php");
45 49 $_body .= $_form; $_body .= $_form;
46 50 } }

File inc/repo/repo_page.php changed (mode: 100644) (index 16a1f1b..4eb37eb)
... ... if ($show_repo_info == 1) {
166 166 $_rt .= "Maxim commit size: " . rg_1024($ri['max_commit_size']) . "<br />\n"; $_rt .= "Maxim commit size: " . rg_1024($ri['max_commit_size']) . "<br />\n";
167 167 $_rt .= "Maxim number of users: " . $ri['max_users'] . "<br />\n"; $_rt .= "Maxim number of users: " . $ri['max_users'] . "<br />\n";
168 168 $_url = "git://" . $_SERVER['HTTP_HOST'] . "/" . $ri['name'] . ".git"; $_url = "git://" . $_SERVER['HTTP_HOST'] . "/" . $ri['name'] . ".git";
169 $_rt .= "Git URL: <a href=\"$_url\">$_url</a><br />\n";
169 if (!empty($_dr))
170 $_rt .= "Git URL: <a href=\"$_url\">$_url</a><br />\n";
170 171 $_url = "ssh://rocketgit@" . $_SERVER['HTTP_HOST'] . "/" . $ri['name'] . ".git"; $_url = "ssh://rocketgit@" . $_SERVER['HTTP_HOST'] . "/" . $ri['name'] . ".git";
171 172 $_rt .= "Git over SSH URL: <a href=\"$_url\">$_url</a><br />\n"; $_rt .= "Git over SSH URL: <a href=\"$_url\">$_url</a><br />\n";
172 173 $_rt .= "<br />\n"; $_rt .= "<br />\n";

File inc/rights.inc.php changed (mode: 100644) (index d102dba..f4442b0)
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
 
... ... function rg_rights_mask($val, $mask)
289 289 return $ret; return $ret;
290 290 } }
291 291
292 /*
293 * Returns TRUE if all 'needed_rights' are included in 'rights'
294 */
295 function rg_rights_allow($rights, $needed_rights)
296 {
297 $r = rg_rights_mask($rights, $needed_rights);
298 if (strcmp($r, $needed_rights) != 0)
299 return FALSE;
300
301 return TRUE;
302 }
292 303 ?> ?>

File inc/sess.inc.php changed (mode: 100644) (index 7001e34..5646012)
1 1 <?php <?php
2 2 require_once($INC . "/log.inc.php"); require_once($INC . "/log.inc.php");
3 require_once($INC . "/db.inc.php");
3 require_once($INC . "/sql.inc.php");
4 4 require_once($INC . "/token.inc.php"); require_once($INC . "/token.inc.php");
5 5
6 6 /* /*

File inc/sql.inc.php renamed from inc/db.inc.php (similarity 86%) (mode: 100644) (index 8fbb4e8..83c09da)
... ... function rg_sql_affected_rows($res)
127 127 return pg_affected_rows($res); return pg_affected_rows($res);
128 128 } }
129 129
130 function rg_sql_begin($db)
131 {
132 $res = rg_sql_query($db, "BEGIN");
133 if ($res === FALSE)
134 return FALSE;
135
136 rg_sql_free_result($res);
137 return TRUE;
138 }
139
140 function rg_sql_commit($db)
141 {
142 $res = rg_sql_query($db, "COMMIT");
143 if ($res === FALSE)
144 return FALSE;
145
146 rg_sql_free_result($res);
147 return TRUE;
148 }
149
130 150 ?> ?>

File inc/state.inc.php changed (mode: 100644) (index b629f96..8dff3ae)
1 1 <?php <?php
2 require_once($INC . "/db.inc.php");
2 require_once($INC . "/sql.inc.php");
3 3
4 4 function rg_state_set_error($str) function rg_state_set_error($str)
5 5 { {

File inc/token.inc.php changed (mode: 100644) (index 6e7c67b..cb343cd)
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
6 6 $rg_token_error = ""; $rg_token_error = "";
7 7

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 inc/user/forgot.php changed (mode: 100644) (index df85597..97c3dc3)
... ... if ($doit == 1) {
16 16 } else { } else {
17 17 $r = rg_user_forgot_pass_uid($db, $forgot_token); $r = rg_user_forgot_pass_uid($db, $forgot_token);
18 18 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
19 $errmsg[] = "Internal error, try again later.";
20 } else if ($r['uid'] == 0) {
21 $errmsg[] = "Invalid (or expired) reset pass URL!";
22 } else {
23 if (rg_user_set_pass($db, $r['uid'], $pass1)) {
24 rg_user_forgot_pass_destroy($db, $r['uid']);
25 // auto-login
26 $_hide_form = 1;
27 if (rg_user_auto_login($db, $r['uid'], $rg_ui))
28 $new_op = "home";
29 else
30 $new_op = "login";
31 } else {
32 $errmsg[] = "Internal error - try later!";
33 }
19 $_forgot .= "Internal error, try again later.<br />\n";
20 return;
34 21 } }
22
23 if ($r['uid'] == 0) {
24 $_forgot .= "Invalid (or expired) reset pass URL!<br />\n";
25 return;
26 }
27
28 if (!rg_user_set_pass($db, $r['uid'], $pass1)) {
29 $_forgot .= "Internal error, try again later.<br />\n";
30 return;
31 }
32
33 rg_user_forgot_pass_destroy($db, $r['uid']);
34 // auto-login
35 $_hide_form = 1;
36 if (rg_user_auto_login($db, $r['uid'], $rg_ui))
37 $new_op = "home";
38 else
39 $new_op = "login";
35 40 } }
36 41 } }
37 42

File inc/util.inc.php changed (mode: 100644) (index 655bc7b..5cf5450)
... ... function rg_re_url($op)
82 82 return $_SERVER['PHP_SELF'] . "?op=" . $op; return $_SERVER['PHP_SELF'] . "?op=" . $op;
83 83 } }
84 84
85 /*
86 * This is used for forms
87 */
88 function rg_re_post($op)
89 {
90 if (isset($_REQUEST['rewrite_engine']))
91 return "/+" . $op;
92
93 return $_SERVER['PHP_SELF'];
94 }
95
85 96 function rg_re_repopage($repo_id, $repo_name) function rg_re_repopage($repo_id, $repo_name)
86 97 { {
87 98 if (isset($_REQUEST['rewrite_engine'])) if (isset($_REQUEST['rewrite_engine']))
 
... ... function rg_rmdir($dir)
161 172 return TRUE; return TRUE;
162 173 } }
163 174
175 function rg_fatal($msg)
176 {
177 rg_log("FATAL: $msg");
178 echo "==========\n";
179 echo "RocketGit: $msg\n";
180 echo "==========\n";
181 exit(1);
182 }
183
164 184 ?> ?>

File rocketgit.spec.in changed (mode: 100644) (index 972c810..694f685)
... ... Source: http://kernel.embedromix.ro/us/rocketgit/%{name}-%{version}.tar.gz
8 8 URL: http://kernel.embedromix.ro/us/ URL: http://kernel.embedromix.ro/us/
9 9 BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
10 10 BuildArch: noarch BuildArch: noarch
11 Requires: httpd, php, php-process, php-cli, php-pgsql, xinetd
11 Requires: httpd, php, php-cli, php-pgsql, xinetd
12 12 Requires: shadow-utils, git, postgresql-server, policycoreutils-python Requires: shadow-utils, git, postgresql-server, policycoreutils-python
13 13
14 14
 
... ... fi
29 29 %postun %postun
30 30 if [ $1 = 0 ]; then if [ $1 = 0 ]; then
31 31 userdel rocketgit userdel rocketgit
32 semanage fcontext -d "/var/log/rocketgit-web(/.*)?" || :
32 33 fi fi
33 34
34 35 %prep %prep

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 = "&nbsp;"; $add = "&nbsp;";
93 83 } }
94 84
95 if (isset($rg_ui['username']))
96 $menu .= "&nbsp;&nbsp;&nbsp;[" . $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 root/themes/common/rg1.png copied from file artwork/rocketgit v1.png (similarity 100%)

File root/themes/common/rg16x16.png copied from file artwork/rocketgit v1 16x16.png (similarity 100%)

File root/themes/common/rg2.png added (mode: 100644) (index 0000000..d1dabdd)

File root/themes/common/rg4.png added (mode: 100644) (index 0000000..94ee9ce)

File root/themes/common/rg5.png added (mode: 100644) (index 0000000..946b1a0)

File root/themes/default/index.php added (mode: 100644) (index 0000000..1320dc5)
1 <?php
2 $css = preg_replace("/\n\t/", " ", @file_get_contents($THEME . "/main.css"));
3 ?>
4
5 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <html xmlns="http://www.w3.org/1999/xhtml">
7 <head>
8 <title>RocketGit</title>
9 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
10 <style type="text/css"><?php echo $css; ?></style>
11 </head>
12
13 <body>
14
15 <table width="800" class="main_table" align="center">
16 <tr width="800">
17 <td class="white_border">
18 <div style="float: left"><img src="<?php echo $THEME_COMMON; ?>/../common/rg16x16.png" /> <b><i>RocketGit</i></b></div>
19 <div style="padding-left: 120px"><?php echo $menu; ?></div>
20 <div style="float: right"><?php echo $rg_username; ?></div>
21 </td>
22 </tr>
23
24 <tr>
25 <td class="white_border" colspan="3">
26 <?php echo $body; ?>
27 </td>
28 </tr>
29
30 <tr>
31 <td class="white_border" colspan="3"><small>Copyright: <a href="http://kernel.embedromix.ro" target="_new">Catalin(ux) M. BOIE</a></small></td>
32 </tr>
33 </table>
34
35 </body>
36 </html>

File root/themes/default/main.css changed (mode: 100644) (index d25b7ad..839b416)
... ... body {
4 4 font-size: 14px; font-size: 14px;
5 5 } }
6 6
7 .main_table {
8 border-collapse: collapse;
9 background: #ffffcc;
10 color: #000;
11 border-spacing: 1px;
12 padding: 1px;
13 }
14
7 15 table { table {
8 16 border-collapse: collapse; border-collapse: collapse;
9 17 border: 1px solid #000; border: 1px solid #000;
 
... ... th, td {
20 28 border: 1px solid #000; border: 1px solid #000;
21 29 } }
22 30
31 .white_border {
32 border: 1px solid #ffffcc;
33 border: 1px solid #000;
34 }
35
36 .menu {
37 font-size: 14px;
38 font-weight: bold;
39 float: left;
40 text-decoration: none;
41 color: red;
42 background-color: yellow;
43 padding: 5px 20px;
44 }
45
46 .menu:hover {
47 color: green;
48 }

File samples/config.php changed (mode: 100644) (index 9c5a599..a402042)
... ... $rg_base = "/home/rocketgit";
8 8 $rg_base_repo = $rg_base . "/repositories"; $rg_base_repo = $rg_base . "/repositories";
9 9
10 10 // Database // Database
11 $rg_db = "user=rocketgit dbname=rocketgit";
12 $rg_db_debug = 1;
11 $rg_sql = "user=rocketgit dbname=rocketgit";
12 $rg_sql_debug = 1;
13 13
14 14 // Session // Session
15 15 $rg_session_time = 3600; $rg_session_time = 3600;

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/q.php changed (mode: 100644) (index a39d201..2fd1d85)
... ... require_once("/etc/rocketgit/config.php");
11 11
12 12 $INC = dirname(__FILE__) . "/../inc"; $INC = dirname(__FILE__) . "/../inc";
13 13 require_once($INC . "/log.inc.php"); require_once($INC . "/log.inc.php");
14 require_once($INC . "/db.inc.php");
14 require_once($INC . "/sql.inc.php");
15 15 require_once($INC . "/repo.inc.php"); require_once($INC . "/repo.inc.php");
16 16
17 17 rg_log_set_file("/var/log/rocketgit/q.log"); rg_log_set_file("/var/log/rocketgit/q.log");
 
... ... rg_log_set_file("/var/log/rocketgit/q.log");
20 20 $lock = "/var/run/rocketgit/q.lock"; $lock = "/var/run/rocketgit/q.lock";
21 21 rg_lock_or_exit($lock); rg_lock_or_exit($lock);
22 22
23 $rg_sql_debug = $rg_db_debug;
23 rg_log("Start...");
24 24
25 rg_log("Start: euid=" . posix_geteuid() . "...");
26
27 $db = rg_sql_open($rg_db);
25 $db = rg_sql_open($rg_sql);
28 26 if ($db === FALSE) { if ($db === FALSE) {
29 27 rg_log("Cannot connect to database!"); rg_log("Cannot connect to database!");
30 28 // TODO: inform admin - already by e-mail? // TODO: inform admin - already by e-mail?

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/Makefile changed (mode: 100644) (index d61d7fd..1af6ef6)
1 tests := util db keys repo rights state user git
1 tests := util db keys repo rights state user git hook_update hook_pre-receive
2 2 .PHONY: $(tests) .PHONY: $(tests)
3 3
4 4 all: $(tests) all: $(tests)
 
... ... all: $(tests)
6 6 util: util:
7 7 php util.php php util.php
8 8
9 db:
10 php db.php
9 sql:
10 php sql.php
11 11
12 12 keys: keys:
13 13 php keys.php php keys.php
 
... ... user:
27 27 git: git:
28 28 php git.php php git.php
29 29
30 hook_update:
31 ./hook_update.sh
32
33 hook_pre-receive:
34 ./hook_pre_receive.sh
35
36
30 37 .PHONY: clean .PHONY: clean
31 38 clean: clean:
32 39 @rm -f *.log @rm -f *.log

File tests/hook_pre-receive.sh added (mode: 100755) (index 0000000..e752891)
1 #!/bin/bash
2
3 rm -rf hook_pre-receive_*.git
4 mkdir hook_pre-receive_dest.git
5 (
6 cd hook_pre-receive_dest.git
7 git init --bare
8 )
9 cp ../hooks/pre-receive hook_pre-receive_dest.git/hooks/
10
11 git clone hook_pre-receive_dest.git hook_pre-receive_src.git
12
13 cd hook_pre-receive_src.git
14
15 echo "=== Testing push without rights..."
16 echo "aaa" > a
17 git add a
18 git commit -m "a" a
19 git push origin master
20 if [ "${?}" != "1" ]; then
21 echo "Should not work!"
22 exit 1
23 fi
24 echo "=== Testing push with rights..."
25 export ROCKETGIT_RIGHTS="P"
26 git push origin master
27 if [ "${?}" != "0" ]; then
28 echo "Should work!"
29 exit 1
30 fi
31
32
33 cd ..
34 echo "Rights=${ROCKETGIT_RIGHTS}."
35
36 rm -rf hook_pre-receive_*.git
37
38 echo "Done!"

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/keys.php changed (mode: 100644) (index 3ed68e7..c3eb80f)
... ... require_once($INC . "/db/struct.inc.php");
8 8
9 9 rg_log_set_file("keys.log"); rg_log_set_file("keys.log");
10 10
11 $rg_db_debug = 1;
11 $rg_sql_debug = 1;
12 12
13 13 $db = rg_sql_open("dbname=trg"); $db = rg_sql_open("dbname=trg");
14 14 if ($db === FALSE) { if ($db === FALSE) {
 
... ... if ($db === FALSE) {
16 16 exit(1); exit(1);
17 17 } }
18 18
19 // state table
20 $r = rg_db_struct_run($db, FALSE, 1);
19 // needed for state table
20 $ignore_errors = FALSE;
21 $drop_tables = TRUE;
22 $old_schema_ver = 0;
23 $r = rg_sql_struct_run($db, $ignore_errors, $drop_tables, $old_schema_ver);
21 24 if ($r === FALSE) { if ($r === FALSE) {
22 25 echo "Cannot create structure!\n"; echo "Cannot create structure!\n";
23 26 exit(1); exit(1);

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 ?> ?>

File tests/rights.php changed (mode: 100644) (index 7afbac0..984c62e)
... ... if (strcmp($e, $e) != 0) {
39 39 exit(1); exit(1);
40 40 } }
41 41
42 rg_log("rights: testing allow...");
43 $rights = "ABC"; $needed_rights = "BCD";
44 $r = rg_rights_allow($rights, $needed_rights);
45 if ($r !== FALSE) {
46 echo "allow is not working right!\n";
47 exit(1);
48 }
49
50 rg_log("rights: testing allow...");
51 $rights = "ABC"; $needed_rights = "";
52 $r = rg_rights_allow($rights, $needed_rights);
53 if ($r !== TRUE) {
54 echo "allow is not working right (empty needed_rights)!\n";
55 exit(1);
56 }
57
42 58 echo "rights: OK\n"; echo "rights: OK\n";
43 59 ?> ?>

File tests/sql.php renamed from tests/db.php (similarity 97%) (mode: 100644) (index 5a4661f..40fda8b)
... ... error_reporting(E_ALL | E_STRICT);
3 3 ini_set("track_errors", "On"); ini_set("track_errors", "On");
4 4
5 5 $INC = "../inc"; $INC = "../inc";
6 require_once($INC . "/db.inc.php");
6 require_once($INC . "/sql.inc.php");
7 7
8 8 echo "db: open connection...\n"; echo "db: open connection...\n";
9 9 $db = rg_sql_open("dbname=trg"); $db = rg_sql_open("dbname=trg");

File tests/state.php changed (mode: 100644) (index f48c70e..0b1d963)
... ... ini_set("track_errors", "On");
4 4
5 5 $INC = "../inc"; $INC = "../inc";
6 6 require_once($INC . "/log.inc.php"); require_once($INC . "/log.inc.php");
7 require_once($INC . "/db.inc.php");
7 require_once($INC . "/sql.inc.php");
8 8 require_once($INC . "/state.inc.php"); require_once($INC . "/state.inc.php");
9 9 require_once($INC . "/db/struct.inc.php"); require_once($INC . "/db/struct.inc.php");
10 10
11 11 rg_log_set_file("state.log"); rg_log_set_file("state.log");
12 12
13 $rg_db_debug = 1;
13 $rg_sql_debug = 1;
14 14
15 15 $db = rg_sql_open("dbname=trg"); $db = rg_sql_open("dbname=trg");
16 16 if ($db === FALSE) { if ($db === FALSE) {
 
... ... if ($db === FALSE) {
18 18 exit(1); exit(1);
19 19 } }
20 20
21 // state table
22 $r = rg_db_struct_run($db, FALSE, 1);
21 // needed for state table
22 $ignore_errors = FALSE;
23 $drop_tables = TRUE;
24 $old_schema_ver = 0;
25 $r = rg_sql_struct_run($db, $ignore_errors, $drop_tables, $old_schema_ver);
23 26 if ($r === FALSE) { if ($r === FALSE) {
24 27 echo "Cannot create structure!\n"; echo "Cannot create structure!\n";
25 28 exit(1); exit(1);

File tests/user.php changed (mode: 100644) (index b3cefaf..1f9f35c)
... ... if ($db === FALSE) {
20 20 exit(1); exit(1);
21 21 } }
22 22
23 $r = rg_db_struct_run($db, FALSE, 1);
23 $ignore_errors = FALSE;
24 $drop_tables = TRUE;
25 $old_schema_ver = 0;
26 $r = rg_sql_struct_run($db, $ignore_errors, $drop_tables, $old_schema_ver);
24 27 if ($r === FALSE) { if ($r === FALSE) {
25 28 echo "Cannot create structure!\n"; echo "Cannot create structure!\n";
26 29 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://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

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