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 c383074b6967a1d6de1bac42f4960cf0d705e23f

Fixes all over the place
Mostly state_get and fixes_needed.
Author: Catalin(ux) M. BOIE
Author date (UTC): 2015-04-09 20:19
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2015-04-09 20:19
Parent(s): d56c69368f304dca943a8050111666fd9ba34364
Signing key:
Tree: 001dee54fb660e5bff336ece75998f402cb687b9
File Lines added Lines deleted
TODO 7 4
inc/admin.inc.php 49 0
inc/fixes.inc.php 14 10
inc/state.inc.php 3 0
inc/struct.inc.php 11 1
inc/token.inc.php 1 1
inc/util.inc.php 1 1
root/index.php 2 7
root/themes/default/main.html 2 4
scripts/cron.php 7 1
scripts/events.php 2 2
scripts/remote.php 2 2
File TODO changed (mode: 100644) (index 8d06659..579e2d2)
1 1 == Where I stopped last time == == Where I stopped last time ==
2 2 [ ] Add "Spread the word!" on website. [ ] Add "Spread the word!" on website.
3 3
4 [ ] I am able to disable merge/pull requests? Anon yes, but the other ones?
5 4 [ ] Check 'description_nice' and apply this everywhere. Maybe we should unset [ ] Check 'description_nice' and apply this everywhere. Maybe we should unset
6 5 'description', so people will not be tempted to use it. 'description', so people will not be tempted to use it.
7 6 Maybe just overwrite 'description'. Maybe just overwrite 'description'.
 
12 11 Nu e OK. Trebuie doar pentru anumite cazuri: la o descriere pe pagina Nu e OK. Trebuie doar pentru anumite cazuri: la o descriere pe pagina
13 12 proiectului, e nevoie. Dar intr-un form, in textarea, nu e nevoie. proiectului, e nevoie. Dar intr-un form, in textarea, nu e nevoie.
14 13 Apoi as putea elimina description_nice. Apoi as putea elimina description_nice.
15 [ ] Security: Link-uri + xss (Ionut)
16 14 [ ] Upload kvm image to downloads.rocketgit.com. Sign it? sha256 it? [ ] Upload kvm image to downloads.rocketgit.com. Sign it? sha256 it?
17 15 [ ] Security: validate sparas! [ ] Security: validate sparas!
18 16 [ ] Menus - change color for selected items, not the background color. [ ] Menus - change color for selected items, not the background color.
 
20 18 creat din cauza event-ului care nu poate sa se conecteze la cache: creat din cauza event-ului care nu poate sa se conecteze la cache:
21 19 broken pipe. Foarte ciudat. De ce nu ar putea trimite? broken pipe. Foarte ciudat. De ce nu ar putea trimite?
22 20 Probabil socket-ul nu mai e deschis pentru ca cache-ul s-a restartat? Probabil socket-ul nu mai e deschis pentru ca cache-ul s-a restartat?
23 [ ] Seems that 'token_key' is not created at boot time! Bad!
24 21 [ ] I can do a select before write to be sure socket is open. [ ] I can do a select before write to be sure socket is open.
25 22 If I get a error signal from select, reopen the socket. If I get a error signal from select, reopen the socket.
26 23 [ ] SPF? mail-ul ajunge in spam! [ ] SPF? mail-ul ajunge in spam!
 
28 25 [ ] [ ]
29 26
30 27 == BEFORE NEXT RELEASE == == BEFORE NEXT RELEASE ==
28 [ ] Security: Link-uri + xss (Ionut)
29 [ ] I am able to disable merge/pull requests? Anon yes, but the other ones?
30 [ ] report1: add disk space
31 [ ] Compress logs (when we are short in disk space)?
32 [ ] nofollow
33 [ ] Check other filesystems: nils2 etc for virtual machine.
31 34 [ ] Add right 'allow bad commit messages'. [ ] Add right 'allow bad commit messages'.
32 35 [ ] Add a new section in 'Rights' to enforce a regex on the commit message. [ ] Add a new section in 'Rights' to enforce a regex on the commit message.
33 36 [ ] Merge requests are not ok - still using files. [ ] Merge requests are not ok - still using files.
 
50 53 [ ] slogan: it is not rocket science [ ] slogan: it is not rocket science
51 54 [ ] Only one daemon should update the structure, else they will conflict. [ ] Only one daemon should update the structure, else they will conflict.
52 55 Dpne. Check. Dpne. Check.
53 [ ] nofollow la logout; poate si in alte pati
56 [ ] nofollow la logout; poate si in alte parti
54 57 [ ] Check if SSL cyphers are ok [ ] Check if SSL cyphers are ok
55 58 [ ] Se pare ca autogenerez drepturi 'All' pentru orice user asupra repo-ului. [ ] Se pare ca autogenerez drepturi 'All' pentru orice user asupra repo-ului.
56 59 Se pare ca si la "Path rights"! Se pare ca si la "Path rights"!
File inc/admin.inc.php changed (mode: 100644) (index e533cc1..1127ab1)
... ... function rg_init($db, $rg)
230 230 return $ret; return $ret;
231 231 } }
232 232
233 /*
234 * Helper for rg_admin_report1 - suggestion report
235 */
236 function rg_admin_report1_suggestions($db, $from, $to)
237 {
238 $ret = array();
239 $ret['yesterday'] = "";
240
241 // Total
242 $sql = "SELECT COUNT(*) AS total FROM suggestions";
243 $res = rg_sql_query($db, $sql);
244 if ($res === FALSE) {
245 $ret['total'] = "ERR";
246 } else {
247 $row = rg_sql_fetch_array($res);
248 $ret['total'] = $row['total'];
249 }
250 rg_sql_free_result($res);
251
252 // Yesterday - not yet because we do not have itime
253 /*
254 $sql = "SELECT uid, suggestion FROM suggestions"
255 . " WHERE itime >= $y_start"
256 . " AND itime <= $y_end";
257 $res = rg_sql_query($db, $sql);
258 if ($res === FALSE) {
259 $ret['yesterday'] = "ERR";
260 } else {
261 $count = 0;
262 $list = '';
263 while (($row = rg_sql_fetch_array($res))) {
264 $count++;
265 $list .= sprintf("%8u %s\n",
266 $row['uid'], $row['suggestion']);
267 }
268 if ($count)
269 $ret['yesterday'] = "\nYesterday suggestions"
270 . " (" . $count . "):\n" . $list;
271 }
272 rg_sql_free_result($res);
273 */
274
275 return $ret;
276 }
277
233 278 /* /*
234 279 * Send some daily statistics to the admin * Send some daily statistics to the admin
235 280 */ */
 
... ... function rg_admin_report1($db, $rg)
306 351 } }
307 352 rg_sql_free_result($res); rg_sql_free_result($res);
308 353
354 $sug = rg_admin_report1_suggestions($db, $y_start, $y_end);
355 $body .= "\n\nTotal suggestions: " . $sug['total'] . "\n";
356 $body .= $sug['yesterday'] . "\n";
357
309 358 $rg['ui::email'] = $rg_admin_email; $rg['ui::email'] = $rg_admin_email;
310 359 $rg['mail::subject'] = 'RocketGit daily report' $rg['mail::subject'] = 'RocketGit daily report'
311 360 . ' [' . $users . '/' . $total_users . ']' . ' [' . $users . '/' . $total_users . ']'
File inc/fixes.inc.php changed (mode: 100644) (index 5a57ec0..2e002de)
... ... function rg_fixes_run($db, $old_ver)
325 325
326 326 /* /*
327 327 * Tests if fixes are needed. * Tests if fixes are needed.
328 * Returns old version or FALSE if fixes are not needed.
328 * Returns FALSE on error, 0 if not needed, 1 if needed.
329 329 */ */
330 330 function rg_fixes_needed($db) function rg_fixes_needed($db)
331 331 { {
 
... ... function rg_fixes_needed($db)
336 336 $ret = FALSE; $ret = FALSE;
337 337 while (1) { while (1) {
338 338 $old = rg_state_get($db, "fixes_version"); $old = rg_state_get($db, "fixes_version");
339 if ($old === FALSE) {
340 //TODO: error rg_log("\tDEBUG: schema is up to date!");
339 if ($old === FALSE)
341 340 break; break;
342 }
343 341
344 if (empty($old))
342 if ($old === "")
345 343 $old = 0; $old = 0;
346 344
347 345 //rg_log("DEBUG: old=$old new=$rg_fixes_ver"); //rg_log("DEBUG: old=$old new=$rg_fixes_ver");
348 346 if ($old == $rg_fixes_ver) { if ($old == $rg_fixes_ver) {
349 //rg_log("DEBUG: fixes are up to date!");
347 // fixes are up to date
348 $ret = 0;
350 349 break; break;
351 350 } }
352 351
353 $ret = TRUE;
352 $ret = 1;
354 353 break; break;
355 354 } }
356 355
 
... ... function rg_fixes_needed($db)
361 360 /* /*
362 361 * Apply fixes if needed * Apply fixes if needed
363 362 * Returns FALSE in case of error * Returns FALSE in case of error
364 * This must not be run by web user because of the owner of the locking file.
365 363 */ */
366 364 function rg_fixes_update($db) function rg_fixes_update($db)
367 365 { {
 
... ... function rg_fixes_update($db)
371 369
372 370 $ret = FALSE; $ret = FALSE;
373 371 while (1) { while (1) {
374 $old = rg_fixes_needed($db);
375 if ($old === FALSE) {
372 $old = rg_state_get($db, "fixes_version");
373 if ($old === FALSE)
374 break;
375
376 if ($old === "")
377 $old = 0;
378
379 if ($old == $rg_fixes_ver) {
376 380 $ret = TRUE; $ret = TRUE;
377 381 break; break;
378 382 } }
File inc/state.inc.php changed (mode: 100644) (index 360640e..983d57b)
... ... function rg_state_set($db, $var, $value)
96 96 while (1) { while (1) {
97 97 $params = array("var" => $var, "value" => $value); $params = array("var" => $var, "value" => $value);
98 98 $old = rg_state_get($db, $var); $old = rg_state_get($db, $var);
99 if ($old === FALSE)
100 break;
101
99 102 if (strcmp($old, $value) == 0) if (strcmp($old, $value) == 0)
100 103 return TRUE; return TRUE;
101 104
File inc/struct.inc.php changed (mode: 100644) (index 8a5ab38..6d5654f)
... ... $rg_sql_struct[32]['other'] = array(
414 414 "repo_license" => "ALTER TABLE repos ADD license TEXT NOT NULL DEFAULT ''" "repo_license" => "ALTER TABLE repos ADD license TEXT NOT NULL DEFAULT ''"
415 415 ); );
416 416
417 /* TODO
418 $rg_sql_struct[33] = array();
419 $rg_sql_struct[33]['tables'] = array();
420 $rg_sql_struct[33]['other'] = array(
421 "suggestion_itime" => "ALTER TABLE suggestions ADD itime INTEGER NOT NULL DEFAULT 0"
422 );
423
424 TODO: do not fill email in suggestions - we have the uid!
425 TODO: "suggestion_drop_email" => "ALTER TABLE suggestions DROP email"
426 */
417 427
418 428 // This must be the last line // This must be the last line
419 429 $rg_sql_schema_ver = count($rg_sql_struct); $rg_sql_schema_ver = count($rg_sql_struct);
 
... ... function rg_sql_struct_slaves_update($db)
617 627
618 628 $last_ts = rg_state_get($db, "slaves_create_last_ts"); $last_ts = rg_state_get($db, "slaves_create_last_ts");
619 629 if ($last_ts === FALSE) if ($last_ts === FALSE)
620 $last_ts = 0;
630 break;
621 631
622 632 $last_ts = sprintf("%u", $last_ts); $last_ts = sprintf("%u", $last_ts);
623 633 if ($last_ts == 0) if ($last_ts == 0)
File inc/token.inc.php changed (mode: 100644) (index 5b4445b..3f49644)
... ... function rg_token_get_master($db)
76 76 if (empty($key)) { if (empty($key)) {
77 77 $key = rg_id(32); $key = rg_id(32);
78 78 $r = rg_state_set($db, "token_key", $key); $r = rg_state_set($db, "token_key", $key);
79 if ($r === FALSE) {
79 if ($r !== TRUE) {
80 80 rg_token_set_error("cannot set state:" rg_token_set_error("cannot set state:"
81 81 . " " . rg_state_error()); . " " . rg_state_error());
82 82 break; break;
File inc/util.inc.php changed (mode: 100644) (index 8e772dd..1292336)
... ... function rg_error_handler($no, $str, $file, $line)
1127 1127 } }
1128 1128
1129 1129 /* /*
1130 * shutdown function to log fatal errors
1130 * Shutdown function to log fatal errors
1131 1131 */ */
1132 1132 function rg_error_shutdown() function rg_error_shutdown()
1133 1133 { {
File root/index.php changed (mode: 100644) (index 65bccd1..b6fd42d)
... ... $good = 0;
82 82 $tries = 10; $tries = 10;
83 83 while ($tries > 0) { while ($tries > 0) {
84 84 $r = rg_sql_struct_update_needed($db); $r = rg_sql_struct_update_needed($db);
85 if ($r === FALSE) {
86 rg_log("sql_struct_update_needed returned FALSE! Exit.");
87 break;
88 }
89
90 85 if ($r === 0) { if ($r === 0) {
91 86 $r = rg_fixes_needed($db); $r = rg_fixes_needed($db);
92 if ($r === FALSE) {
87 if ($r === 0) {
93 88 $good = 1; $good = 1;
94 89 break; break;
95 90 } }
 
... ... if ($r === FALSE) {
126 121 $body .= rg_template('admin/db_error.html'); $body .= rg_template('admin/db_error.html');
127 122 } else if ($r === '') { } else if ($r === '') {
128 123 $body .= rg_init($db, $rg); $body .= rg_init($db, $rg);
129 } else if ($r > 0) {
124 } else {
130 125 $rg['first_install_text'] = gmdate("Y-m-d", $r); $rg['first_install_text'] = gmdate("Y-m-d", $r);
131 126
132 127 rg_log("Dispatching to [$_op]"); rg_log("Dispatching to [$_op]");
File root/themes/default/main.html changed (mode: 100644) (index fd000f8..6ad3e08)
55 55 <div class="island"> <div class="island">
56 56 <div class="island_title">Install</div> <div class="island_title">Install</div>
57 57 To install this software on your server, just go to To install this software on your server, just go to
58 <a href="http://rocketgit.com/user/catalinux/rocketgit/source">RocketGit repo</a>
59 and follow the instructions. It only takes two minutes.
60 In the near future we will provide pre-made virtual machine images to
61 achieve under 60 seconds install time.
58 <a href="http://rocketgit.com/op/download">download section</a>
59 and follow the instructions. It only takes few minutes.
62 60 </div> </div>
63 61 </div> </div>
64 62 </div> </div>
File scripts/cron.php changed (mode: 100644) (index b456fb2..c4ba0d2)
... ... if ($r !== TRUE)
62 62 exit(1); exit(1);
63 63
64 64 $install_id = rg_state_get($db, "install_id"); $install_id = rg_state_get($db, "install_id");
65 if ($install_id === FALSE)
66 exit(1);
65 67 if (empty($install_id)) if (empty($install_id))
66 68 rg_state_set($db, "install_id", sha512(microtime(TRUE))); rg_state_set($db, "install_id", sha512(microtime(TRUE)));
67 69
68 70 $first_install = rg_state_get($db, 'first_install'); $first_install = rg_state_get($db, 'first_install');
69 if ($first_install === '')
71 if ($first_install === FALSE)
72 exit(1);
73 if (empty($first_install)) {
74 rg_log("Admin did not created the user, so no need to run this code.");
70 75 exit(0); exit(0);
76 }
71 77
72 78 if (gmdate("Hi") == "0105") { if (gmdate("Hi") == "0105") {
73 79 while (1) { while (1) {
File scripts/events.php changed (mode: 100644) (index d6557c1..ab82f6a)
... ... if ($db === FALSE) {
43 43 exit(1); exit(1);
44 44 } }
45 45
46 if (rg_sql_struct_update_needed($db))
46 if (rg_sql_struct_update_needed($db) !== 0)
47 47 exit(0); exit(0);
48 48
49 if (rg_fixes_needed($db))
49 if (rg_fixes_needed($db) !== 0)
50 50 exit(0); exit(0);
51 51
52 52 // Remove the socket, else we will get error // Remove the socket, else we will get error
File scripts/remote.php changed (mode: 100644) (index 7f65dc7..0a39673)
... ... $db = rg_sql_open($rg_sql);
58 58 if ($db === FALSE) if ($db === FALSE)
59 59 fatal("Internal error (db)!"); fatal("Internal error (db)!");
60 60
61 if (rg_sql_struct_update_needed($db))
61 if (rg_sql_struct_update_needed($db) !== 0)
62 62 fatal("We are in a short maintenance window. Try again later."); fatal("We are in a short maintenance window. Try again later.");
63 63
64 if (rg_fixes_needed($db))
64 if (rg_fixes_needed($db) !== 0)
65 65 fatal("We are in a short maintenance window. Try again later."); fatal("We are in a short maintenance window. Try again later.");
66 66
67 67 if (isset($_SERVER['SSH_CONNECTION'])) { if (isset($_SERVER['SSH_CONNECTION'])) {
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