List of commits:
Subject Hash Author Date (UTC)
Misc fixes eac04dc796b2c315b65753025e1e311bc25e83d7 Catalin(ux) M. BOIE 2012-03-26 18:14:32
Fixes for schema autoupdate 63d2a1a4f4c0498135a96f1a3d374868dc3d3535 Catalin(ux) M. BOIE 2012-03-23 04:19:09
Test CSRF token for the rights for a repo. e2d32e100f724e80ee623f191784ce429156ac39 Catalin(ux) M. BOIE 2012-03-22 03:54:37
Fixed anon push without create branch rights 3d474b7a569b16d87a426d4c3b971a50b3299894 Catalin(ux) M. BOIE 2012-03-22 03:43:06
Use rg_repos for repositories e5bda9469fddee7f201c22dfd89292830f4c342b Catalin(ux) M. BOIE 2012-03-22 03:42:06
Corrected <label> tags 7e8621e79480b8964e04de8c54f10f1a702ea1fd Catalin(ux) M. BOIE 2012-03-20 04:25:38
Fixed unit testing 31bfe5672e7d3b620d0e7b3c07ff72d84c149001 Catalin(ux) M. BOIE 2012-03-17 17:21:21
Fixed hook_update.sh unit testing 86c4079e81efc5a4a7878e91d8f4318e443961f7 Catalin(ux) M. BOIE 2012-03-16 22:32:35
Bulk updates f696473a7faee50782d3cc01e96cc85e7900b3de Catalin(ux) M. BOIE 2012-03-14 04:38:23
Style changes. 87e30b1df29b7c6efa438be1cf369192a8068655 Catalin(ux) M. BOIE 2012-02-19 22:50:22
Bulk 0923407bff68a58a0b7b034f8a6b4489ece5b237 Catalin(ux) M. BOIE 2012-02-12 22:21:44
Bulk update 30310488bca37cefeba96b52b71c9c3e72c32907 Catalin(ux) M. BOIE 2011-12-15 23:34:03
Profiling tests. afd1df2940fe440cde9b8ede988ff24c051a10d6 Catalin(ux) M. BOIE 2011-11-03 22:10:13
More bulk updates. a2a2e2545eaad61d0c675ea2afb801f207534515 Catalin(ux) M. BOIE 2011-11-03 22:09:34
Another round of bulk updates. 45bb00a88c420d439b4dd19971808722e4a70895 Catalin(ux) M. BOIE 2011-10-24 22:31:14
Bulk update. Mostly css. 04734cd7cfc4fd4ec55dad70a3490f3065027639 Catalin(ux) M. BOIE 2011-10-03 23:18:26
Added rg_exec function and converted all calls from exec to rg_exec. 097157e5886dace2b9f67ca238a1063a3baff4a0 Catalin(ux) M. BOIE 2011-09-28 03:28:49
Another round of bulk updates cb9dbb75518ab3c214167646197ca7eb0de8e4e6 Catalin(ux) M. BOIE 2011-09-26 19:22:12
Bulk updates cad0c710542dc3fb072268eba40b0abe11217fa9 Catalin(ux) M. BOIE 2011-09-21 20:25:23
Bulk changes. d5274ef5f261086a2af6bd19ac04061bb3d55584 Catalin(ux) M. BOIE 2011-09-15 20:16:46
Commit eac04dc796b2c315b65753025e1e311bc25e83d7 - Misc fixes
Author: Catalin(ux) M. BOIE
Author date (UTC): 2012-03-26 18:14
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2012-03-26 18:21
Parent(s): 63d2a1a4f4c0498135a96f1a3d374868dc3d3535
Signing key:
Tree: faa2a3a9b6da80b17a0ec4d18c5b0a837e0c83f6
File Lines added Lines deleted
TODO 5 8
admin/init.php 6 3
hooks/post-receive 13 11
inc/repo.inc.php 28 0
inc/sql.inc.php 1 2
inc/user.inc.php 1 3
root/index.php 2 1
samples/config.php 0 3
scripts/cron.php 2 1
scripts/q.php 2 1
scripts/remote.php 4 2
tests/keys.php 1 0
tests/repo.php 32 4
tests/state.php 1 1
tests/user.php 1 1
File TODO changed (mode: 100644) (index a3a6878..dc368df)
1 1 == BEFORE FIRST RELEASE! == == BEFORE FIRST RELEASE! ==
2 [ ] $rg_pass_key should be done in init.php
3 [ ] Test and fix update.php script.
4 [ ] Fix the "edit repo" page!
5 [ ] Update db structure at any function call (after an upgrade). (Deny any operation till schema update is done.)
6 [ ] Check if repo_path is valid from security pov.
7 [ ] Make available the push requests.
2 [ ] Make available the merge requests.
8 3 [ ] Add possibility to reject merge requests, to make them public, to delete etc. [ ] Add possibility to reject merge requests, to make them public, to delete etc.
9 [ ] Should init.php must create db schema or we delay for the first access?
4 [ ] rg_sql_querty must always return an error code!
5 [ ]
10 6
11 7 == Normal priority == == Normal priority ==
12 [ ]
8 [ ] If a user pushes an unknown repo, we may automatically create a repo!
9 [ ] Fix the "edit repo" page!
13 10 [ ] rg-repos should be split in rg_repos and rg_var_lib. [ ] rg-repos should be split in rg_repos and rg_var_lib.
14 11 [ ] 'cop' variable is not good - I do not remember what it means! [ ] 'cop' variable is not good - I do not remember what it means!
15 12 [ ] $blocks = explode("@@left@@-=ROCKETGIT=-@@left@@", $a) - seems that \0 is replaced! [ ] $blocks = explode("@@left@@-=ROCKETGIT=-@@left@@", $a) - seems that \0 is replaced!
File admin/init.php changed (mode: 100644) (index 8af30b3..c8c889b)
1 1 <?php <?php
2 // This is executed at the first instalation
2 // This is executed at the first instalation.
3 // Or, if you want to create another admin user.
3 4 error_reporting(E_ALL); error_reporting(E_ALL);
4 5 ini_set("track_errors", "On"); ini_set("track_errors", "On");
5 6
 
... ... if ($db === FALSE) {
20 21 exit(1); exit(1);
21 22 } }
22 23
23 $r = rg_sql_struct_update_if_needed($db, RG_NO_DROP_TABLES);
24 $r = rg_sql_struct_update_if_needed($db, 0);
24 25 if ($r !== TRUE) { if ($r !== TRUE) {
25 26 echo "Cannot init structure. Check the logs!\n"; echo "Cannot init structure. Check the logs!\n";
26 27 exit(1); exit(1);
 
... ... while (1) {
73 74
74 75
75 76 // Store the timestamp of the first install // Store the timestamp of the first install
76 rg_state_set($db, "first_install", time());
77 $first_install = rg_state_get($db, "first_install");
78 if ($first_install == 0)
79 rg_state_set($db, "first_install", time());
77 80
78 81 echo "Done!\n"; echo "Done!\n";
79 82 ?> ?>
File hooks/post-receive changed (mode: 100755) (index 0355ab7..b71148d)
... ... while (($set = fgets($f))) {
59 59 fclose($f); fclose($f);
60 60
61 61
62 $diff = sprintf("%u", (microtime(TRUE) - $_start) * 1000);
63 rg_log("Took " . $diff . "ms.");
64
65 @file_put_contents($repo_path . "/rg/hook-post-receive",
66 "repo: " . $repo . " ($repo_path)"
67 . "\nat: " . sprintf("%u", $_start)
68 . "\nuid: " . $uid
69 . "\npara: $refname $old_rev $new_rev"
70 . "\nTook: " . $diff . "ms"
71 . "\n_SERVER: " . print_r($_SERVER, TRUE));
72
73 62 // Mark repository dirty for disk statistics and other stuff // Mark repository dirty for disk statistics and other stuff
74 63 @file_put_contents($rg_path . "/dirty", ""); @file_put_contents($rg_path . "/dirty", "");
75 64
65 $a = array(
66 "op" => "push",
67 "itime" => getenv("ROCKETGIT_ITIME"),
68 "uid" => $uid,
69 "repo_id" => getenv("ROCKETGIT_REPO_ID")
70 "old_rev" => $old_rev,
71 "new_rev" => $new_rev,
72 "refname" => $refname,
73 "elap_ms" => $_start - getenv("ROCKETGIT_ITIME"),
74 "ip" => getenv("ROCKETGIT_IP")
75 );
76 rg_repo_stats_push2file($a);
77
76 78 rg_prof_end("post-receive"); rg_prof_end("post-receive");
77 79 rg_prof_log("rg_log"); rg_prof_log("rg_log");
78 80 ?> ?>
File inc/repo.inc.php changed (mode: 100644) (index 550d190..4376cae)
... ... function rg_repo_over_limit($ri)
587 587 return FALSE; return FALSE;
588 588 } }
589 589
590 /*
591 * Add in queue a statistic file
592 */
593 function rg_repo_stats_push2file($a)
594 {
595 global $php_errormsg;
596 global $rg_repos;
597
598 $q = $rg_repos . "/qstats";
599 if (!is_dir($q)) {
600 $r = @mkdir($q, 0700);
601 if ($r !== TRUE) {
602 rg_internal_error("Cannot create dir $q ($php_errormsg)!");
603 return FALSE;
604 }
605 }
606
607 $buf = serialize($a);
608 $file = sha1($buf);
609 $r = file_put_contents($q . "/" . $file, $buf);
610 if ($r === FALSE) {
611 rg_internal_error("Cannot store file in qstats ($php_errormsg)!");
612 return FALSE;
613 }
614
615 return $file;
616 }
617
590 618 ?> ?>
File inc/sql.inc.php changed (mode: 100644) (index be8a396..886a074)
... ... function rg_sql_query($db, $sql)
72 72 { {
73 73 global $rg_sql_debug; global $rg_sql_debug;
74 74
75 $_s = microtime(TRUE);
76
77 75 if ($rg_sql_debug > 0) if ($rg_sql_debug > 0)
78 76 rg_log("\tDB: running [$sql]..."); rg_log("\tDB: running [$sql]...");
79 77
78 $_s = microtime(TRUE);
80 79 $res = @pg_query($db, $sql); $res = @pg_query($db, $sql);
81 80 if ($res === FALSE) { if ($res === FALSE) {
82 81 rg_sql_set_error("$sql: " . @pg_last_error($db)); rg_sql_set_error("$sql: " . @pg_last_error($db));
File inc/user.inc.php changed (mode: 100644) (index fcc6952..a4ae5ca)
... ... function rg_user_url($ui)
63 63 */ */
64 64 function rg_user_pass($salt, $pass) function rg_user_pass($salt, $pass)
65 65 { {
66 global $rg_pass_key;
67
68 return sha1($salt . "===" . $rg_pass_key . "===" . $pass);
66 return sha1($salt . "===" . $pass);
69 67 } }
70 68
71 69 /* /*
File root/index.php changed (mode: 100644) (index 4e209dc..621d2de)
... ... $INC = dirname(__FILE__) . "/../inc";
6 6 require_once("/etc/rocketgit/config.php"); require_once("/etc/rocketgit/config.php");
7 7 require_once($INC . "/log.inc.php"); require_once($INC . "/log.inc.php");
8 8 include_once($INC . "/sql.inc.php"); include_once($INC . "/sql.inc.php");
9 include_once($INC . "/struct.inc.php");
9 10 include_once($INC . "/user.inc.php"); include_once($INC . "/user.inc.php");
10 11 include_once($INC . "/repo.inc.php"); include_once($INC . "/repo.inc.php");
11 12 include_once($INC . "/keys.inc.php"); include_once($INC . "/keys.inc.php");
 
... ... if ($db === FALSE) {
88 89 die("Cannot open database!"); die("Cannot open database!");
89 90 } }
90 91
91 $r = rg_sql_struct_update_if_needed($db, RG_NO_DROP_TABLES);
92 $r = rg_sql_struct_update_if_needed($db, 0);
92 93 if ($r !== TRUE) { if ($r !== TRUE) {
93 94 echo "Schema is not up-to-date! Try again later"; echo "Schema is not up-to-date! Try again later";
94 95 exit(1); exit(1);
File samples/config.php changed (mode: 100644) (index 2cb3510..1b8f9a7)
... ... $rg_user_max_len = 32;
34 34 // SSH parameters for authorized_keys // SSH parameters for authorized_keys
35 35 $rg_ssh_paras = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty"; $rg_ssh_paras = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty";
36 36
37 // Random key that will be used for encription of the password for better security
38 $rg_pass_key = "reigjmn9483jfisendfhwefhefhesfuhfskhjukhtw4khfwkur";
39
40 37 // From what address we will send mails (forgot pass etc.)? // From what address we will send mails (forgot pass etc.)?
41 38 $rg_admin_name = "RocketGit Admin"; $rg_admin_name = "RocketGit Admin";
42 39 $rg_admin_email = "admin@site.tld"; $rg_admin_email = "admin@site.tld";
File scripts/cron.php changed (mode: 100644) (index db495c2..fbcbf65)
... ... require_once("/etc/rocketgit/config.php");
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 12 require_once($INC . "/sql.inc.php"); require_once($INC . "/sql.inc.php");
13 require_once($INC . "/struct.inc.php");
13 14 require_once($INC . "/repo.inc.php"); require_once($INC . "/repo.inc.php");
14 15 require_once($INC . "/keys.inc.php"); require_once($INC . "/keys.inc.php");
15 16
 
... ... if ($db === FALSE) {
27 28 exit(1); exit(1);
28 29 } }
29 30
30 $r = rg_sql_struct_update_if_needed($db, RG_NO_DROP_TABLES);
31 $r = rg_sql_struct_update_if_needed($db, 0);
31 32 if ($r !== TRUE) if ($r !== TRUE)
32 33 exit(1); exit(1);
33 34
File scripts/q.php changed (mode: 100644) (index c1bac8b..bd48577)
... ... require_once("/etc/rocketgit/config.php");
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 14 require_once($INC . "/sql.inc.php"); require_once($INC . "/sql.inc.php");
15 require_once($INC . "/struct.inc.php");
15 16 require_once($INC . "/repo.inc.php"); require_once($INC . "/repo.inc.php");
16 17 require_once($INC . "/prof.inc.php"); require_once($INC . "/prof.inc.php");
17 18 require_once($INC . "/mr.inc.php"); require_once($INC . "/mr.inc.php");
 
... ... if ($db === FALSE) {
32 33 exit(1); exit(1);
33 34 } }
34 35
35 $r = rg_sql_struct_update_if_needed($db, RG_NO_DROP_TABLES);
36 $r = rg_sql_struct_update_if_needed($db, 0);
36 37 if ($r !== TRUE) if ($r !== TRUE)
37 38 exit(1); exit(1);
38 39
File scripts/remote.php changed (mode: 100644) (index 20d22bb..b8061aa)
... ... $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 11 require_once($INC . "/sql.inc.php"); require_once($INC . "/sql.inc.php");
12 require_once($INC . "/struct.inc.php");
12 13 require_once($INC . "/repo.inc.php"); require_once($INC . "/repo.inc.php");
13 14 require_once($INC . "/prof.inc.php"); require_once($INC . "/prof.inc.php");
14 15
 
... ... $db = rg_sql_open($rg_sql);
133 134 if ($db === FALSE) if ($db === FALSE)
134 135 fatal("Internal error (db)!"); fatal("Internal error (db)!");
135 136
136 $r = rg_sql_struct_update_if_needed($db, RG_NO_DROP_TABLES);
137 $r = rg_sql_struct_update_if_needed($db, 0);
137 138 if ($r !== TRUE) if ($r !== TRUE)
138 139 fatal("We are in a short maintenance. Try again later."); fatal("We are in a short maintenance. Try again later.");
139 140
 
... ... putenv("ROCKETGIT_REPO_ID=" . $ri['repo_id']);
176 177 putenv("ROCKETGIT_REPO_RIGHTS=" . $rights); putenv("ROCKETGIT_REPO_RIGHTS=" . $rights);
177 178 putenv("ROCKETGIT_REPO_PATH=" . $repo_path); putenv("ROCKETGIT_REPO_PATH=" . $repo_path);
178 179 putenv("ROCKETGIT_IP=$ip"); putenv("ROCKETGIT_IP=$ip");
180 putenv("ROCKETGIT_ITIME=" . microtime(TRUE));
179 181 if ($push == 1) { if ($push == 1) {
180 182 $namespace = "rg_" . rg_id(8); $namespace = "rg_" . rg_id(8);
181 183 rg_log("namespace is $namespace."); rg_log("namespace is $namespace.");
182 184 putenv("GIT_NAMESPACE=" . $namespace); putenv("GIT_NAMESPACE=" . $namespace);
183 185
184 // Prepare refs to not receive:
186 // Prepare refs to avoid:
185 187 // "No refs in common and none specified; doing nothing. // "No refs in common and none specified; doing nothing.
186 188 // Perhaps you should specify a branch such as 'master'." // Perhaps you should specify a branch such as 'master'."
187 189 $dst = $repo_path . "/refs/namespaces/" . $namespace . "/refs/heads"; $dst = $repo_path . "/refs/namespaces/" . $namespace . "/refs/heads";
File tests/keys.php changed (mode: 100644) (index 0407357..0526db4)
... ... ini_set("track_errors", "On");
5 5 $INC = "../inc"; $INC = "../inc";
6 6 require_once($INC . "/util.inc.php"); require_once($INC . "/util.inc.php");
7 7 require_once($INC . "/keys.inc.php"); require_once($INC . "/keys.inc.php");
8 require_once($INC . "/sql.inc.php");
8 9 require_once($INC . "/struct.inc.php"); require_once($INC . "/struct.inc.php");
9 10
10 11 rg_log_set_file("keys.log"); rg_log_set_file("keys.log");
File tests/repo.php changed (mode: 100644) (index 38547df..b779f70)
... ... ini_set("track_errors", "On");
4 4
5 5 $INC = "../inc"; $INC = "../inc";
6 6 require_once($INC . "/repo.inc.php"); require_once($INC . "/repo.inc.php");
7 require_once($INC . "/sql.inc.php");
7 8 require_once($INC . "/struct.inc.php"); require_once($INC . "/struct.inc.php");
8 9
9 10 rg_log_set_file("repo.log"); rg_log_set_file("repo.log");
 
... ... if ($r !== TRUE) {
91 92 exit(1); exit(1);
92 93 } }
93 94
94 rg_log("Inserting a fake user");
95 $repo_id = time();
96 $repo_name = "repo-" . $repo_id;
97 rg_log("Inserting a fake repo");
95 98 $sql = "INSERT INTO repos (repo_id, name, uid, itime" $sql = "INSERT INTO repos (repo_id, name, uid, itime"
96 99 . ", disk_quota_mb, max_commit_size" . ", disk_quota_mb, max_commit_size"
97 100 . ", master, description, git_dir_done, default_rights)" . ", master, description, git_dir_done, default_rights)"
98 . " VALUES (1, 'repo1', 1, 0, 0, 0, 0, 'bla bla desc', 1, 'F')";
101 . " VALUES ($repo_id, '$repo_name', 1, 0, 0, 0, 0, 'bla bla desc', 1, 'F')";
99 102 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
100 103 if ($res === FALSE) { if ($res === FALSE) {
101 rg_log("Cannot insert a user (" . rg_sql_error() . ")!");
104 rg_log("Cannot insert a repo (" . rg_sql_error() . ")!");
102 105 exit(1); exit(1);
103 106 } }
104 107
105 108 rg_log("test giving rights"); rg_log("test giving rights");
106 $repo_id = 1;
107 109 $rr = array("repo_id" => $repo_id); $rr = array("repo_id" => $repo_id);
108 110 $ri = rg_repo_info($db, $rr); $ri = rg_repo_info($db, $rr);
109 111 $uid = 10; $uid = 10;
 
... ... if ($r !== FALSE) {
171 173 exit(1); exit(1);
172 174 } }
173 175
176
177 // test stats
178 $rg_repos = "repos";
179 $a = array(
180 "itime" => time(),
181 "ip" => "IPIPIPIPIPIP1",
182 "repo_id" => 3000,
183 "old_rev" => "abcdef",
184 "new_rev" => "434343",
185 "refname" => "refs/heads/xxx");
186 $f = rg_repo_stats_push2file($a);
187 if ($f === FALSE) {
188 echo "push2file returned FALSE!\n";
189 exit(1);
190 }
191 $r = unserialize(file_get_contents($rg_repos . "/qstats/$f"));
192 if ($r === FALSE) {
193 echo "Cannot get file or unserialize!\n";
194 exit(1);
195 }
196 if ($r['repo_id'] != 3000) {
197 print_r($r);
198 echo "rg_repo_stats_push2file is not working right!\n";
199 exit(1);
200 }
201
174 202 rg_sql_close($db); rg_sql_close($db);
175 203
176 204 echo "repo: OK!\n"; echo "repo: OK!\n";
File tests/state.php changed (mode: 100644) (index 7df990f..dfbfe22)
... ... ini_set("track_errors", "On");
5 5 $INC = "../inc"; $INC = "../inc";
6 6 require_once($INC . "/log.inc.php"); require_once($INC . "/log.inc.php");
7 7 require_once($INC . "/sql.inc.php"); require_once($INC . "/sql.inc.php");
8 require_once($INC . "/state.inc.php");
9 8 require_once($INC . "/struct.inc.php"); require_once($INC . "/struct.inc.php");
9 require_once($INC . "/state.inc.php");
10 10
11 11 rg_log_set_file("state.log"); rg_log_set_file("state.log");
12 12
File tests/user.php changed (mode: 100644) (index 7ced4fe..e6501bb)
... ... ini_set("track_errors", "On");
4 4
5 5 $INC = "../inc"; $INC = "../inc";
6 6 require_once($INC . "/user.inc.php"); require_once($INC . "/user.inc.php");
7 require_once($INC . "/sql.inc.php");
7 8 require_once($INC . "/struct.inc.php"); require_once($INC . "/struct.inc.php");
8 9
9 10 $rg_sql_debug = 1; $rg_sql_debug = 1;
 
... ... $rg_sql_debug = 1;
11 12 rg_log_set_file("user.log"); rg_log_set_file("user.log");
12 13
13 14 $rg_user_max_len = 20; $rg_user_max_len = 20;
14 $rg_pass_key = "aaa";
15 15 $rg_session_time = 3600; $rg_session_time = 3600;
16 16 $rg_user_allow = '/^[A-Za-z0-9_.-]*$/'; $rg_user_allow = '/^[A-Za-z0-9_.-]*$/';
17 17 $rg_admin_email = "admin@localhost"; $rg_admin_email = "admin@localhost";
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

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

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

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

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