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 31a2d477a86a3a408c44720bb8c8e280fc4894d2

Bulk updates.

Author: Catalin(ux) M. BOIE
Author date (UTC): 2011-04-06 20:37
Committer: Catalin(ux) M. BOIE
Commit date (UTC): 2011-04-06 20:37
Tree: 6d19e667615ad7e08908350cf079b6ed0c4a0b15
Parents: 852d93d3bf7995ca427982f4ec1aa2bd1bf75063
File Lines added Lines deleted
admin/sql.php 2 56
inc/db/struct.inc.php 80 0
inc/repo.inc.php 48 51
inc/repo/repo_page.php 47 49
inc/repo/rights.form.php 2 2
scripts/cron.php 5 0
scripts/q.php 4 2
scripts/ssh.php 2 0
tests/db.php 2 0
tests/keys.php 6 12
tests/repo.php 31 43
tests/user.php 7 5
tests/util.php 2 0

File admin/sql.php changed (mode: 100644) (index 84971a1..31f33cb)
... ... require_once("/etc/gg/config.php");
6 6 $INC = dirname(__FILE__) . "/../inc"; $INC = dirname(__FILE__) . "/../inc";
7 7 require_once($INC . "/xlog.inc.php"); require_once($INC . "/xlog.inc.php");
8 8 require_once($INC . "/db.inc.php"); require_once($INC . "/db.inc.php");
9 require_once($INC . "/db/struct.inc.php");
9 10 require_once($INC . "/repo.inc.php"); require_once($INC . "/repo.inc.php");
10 11
11 12 $db = sql_open($gg_db); $db = sql_open($gg_db);
12 13 if ($db === FALSE) if ($db === FALSE)
13 14 fatal("Internal error (db)!"); fatal("Internal error (db)!");
14 15
15 $sql = "CREATE TABLE repos (repo_id INTEGER PRIMARY KEY"
16 . ", name TEXT"
17 . ", uid INTEGER"
18 . ", itime INTEGER"
19 . ", disk_quota_mb INTEGER"
20 . ", max_commit_size INTEGER"
21 . ", master INTEGER"
22 . ", desc TEXT"
23 . ", git_dir_done INTEGER"
24 . ", default_rights TEXT"
25 . ", deleted INTEGER"
26 . ")";
27 $res = sql_query($db, $sql);
28 if ($res === FALSE)
29 echo "WARN: Cannot create 'repos' table!\n";
30
31 $sql = "CREATE TABLE repo_rights (repo_id INTEGER, uid INTEGER, rights TEXT"
32 . ", itime INTEGER)";
33 $res = sql_query($db, $sql);
34 if ($res === FALSE)
35 echo "WARN: Cannot create 'repo_rights' table!\n";
36
37 $sql = "CREATE TABLE state (var TEXT PRIMARY KEY, value TEXT)";
38 $res = sql_query($db, $sql);
39 if ($res === FALSE)
40 echo "WARN: Cannot create 'state' table!\n";
41
42 $sql = "CREATE TABLE keys (key_id INTEGER PRIMARY KEY, itime INTEGER"
43 . ", uid INTEGER, key TEXT)";
44 $res = sql_query($db, $sql);
45 if ($res === FALSE)
46 echo "WARN: Cannot create 'keys' table!\n";
47
48 $sql = "CREATE TABLE users (uid INTEGER PRIMARY KEY, user TEXT, salt TEXT"
49 . ", pass TEXT, email TEXT, itime INTEGER"
50 . ", suspended INTEGER"
51 . ", session_time INTEGER DEFAULT 3600"
52 . ", last_seen INTEGER"
53 . ", is_admin INTEGER"
54 . ", disk_quota_mb INTEGER"
55 . ", disk_mb INTEGER"
56 . ")";
57 $res = sql_query($db, $sql);
58 if ($res === FALSE)
59 echo "WARN: Cannot create 'users' table!\n";
60
61 $sql = "CREATE TABLE sess (sid TEXT PRIMARY KEY, uid INTEGER, expire INTEGER"
62 . ", session_time INTEGER, ip TEXT)";
63 $res = sql_query($db, $sql);
64 if ($res === FALSE)
65 echo "WARN: Cannot create 'sess' table!\n";
66
67 $sql = "CREATE TABLE forgot_pass (token TEXT PRIMARY KEY, uid INTEGER, expire INTEGER)";
68 $res = sql_query($db, $sql);
69 if ($res === FALSE)
70 echo "WARN: Cannot create 'forgot_pass' table!\n";
16 gg_db_struct_run($db, TRUE);
71 17
72 18 echo "Done!\n"; echo "Done!\n";
73 19 ?> ?>

File inc/db/struct.inc.php added (mode: 100644) (index 0000000..e113643)
1 <?php
2 error_reporting(E_ALL);
3
4 $gg_db_struct = array();
5
6 $gg_db_struct[0] = array(
7 "repos" => "CREATE TABLE repos"
8 . " (repo_id INTEGER PRIMARY KEY"
9 . ", name TEXT"
10 . ", uid INTEGER"
11 . ", itime INTEGER"
12 . ", disk_quota_mb INTEGER"
13 . ", max_commit_size INTEGER"
14 . ", master INTEGER"
15 . ", desc TEXT"
16 . ", git_dir_done INTEGER"
17 . ", default_rights TEXT"
18 . ", deleted INTEGER"
19 . ")",
20 "repo_rights" => "CREATE TABLE repo_rights"
21 . " (repo_id INTEGER"
22 . ", uid INTEGER"
23 . ", rights TEXT"
24 . ", itime INTEGER)",
25 "state" => "CREATE TABLE state"
26 . " (var TEXT PRIMARY KEY"
27 . ", value TEXT)",
28 "keys" => "CREATE TABLE keys"
29 . " (key_id INTEGER PRIMARY KEY"
30 . ", itime INTEGER"
31 . ", uid INTEGER, key TEXT)",
32 "users" => "CREATE TABLE users"
33 . " (uid INTEGER PRIMARY KEY"
34 . ", user TEXT"
35 . ", salt TEXT"
36 . ", pass TEXT"
37 . ", email TEXT"
38 . ", itime INTEGER"
39 . ", suspended INTEGER"
40 . ", session_time INTEGER DEFAULT 3600"
41 . ", last_seen INTEGER"
42 . ", is_admin INTEGER"
43 . ", disk_quota_mb INTEGER"
44 . ", disk_mb INTEGER"
45 . ")",
46 "sess" => "CREATE TABLE sess"
47 . " (sid TEXT PRIMARY KEY"
48 . ", uid INTEGER"
49 . ", expire INTEGER"
50 . ", session_time INTEGER"
51 . ", ip TEXT)",
52 "forgot_pass" => "CREATE TABLE forgot_pass"
53 . " (token TEXT PRIMARY KEY"
54 . ", uid INTEGER"
55 . ", expire INTEGER)"
56 );
57
58 /*
59 * Generate structure
60 */
61 function gg_db_struct_run($db, $ignore_errors)
62 {
63 global $gg_db_struct;
64
65 foreach ($gg_db_struct as $index => $sqls) {
66 foreach ($sqls as $table => $sql) {
67 echo "[$table] Running [$sql]...\n";
68 $res = sql_query($db, $sql);
69 if ($res === FALSE) {
70 echo "WARN: Cannot create '$table' table!\n";
71 if (!$ignore_errors)
72 return FALSE;
73 }
74 }
75 }
76
77 return TRUE;
78 }
79
80 ?>

File inc/repo.inc.php changed (mode: 100644) (index 12ee83d..bd1ce29)
... ... function repo_info($db, $repo_id, $repo)
49 49 $ret['ok'] = 0; $ret['ok'] = 0;
50 50 $ret['exists'] = 0; $ret['exists'] = 0;
51 51
52 $repo_id = sprintf("%u", $repo_id);
53 52 if ($repo_id > 0) { if ($repo_id > 0) {
54 53 $add = " AND repo_id = $repo_id"; $add = " AND repo_id = $repo_id";
55 54 } else if (!empty($repo)) { } else if (!empty($repo)) {
 
... ... function repo_allow($db, $ri, $uid, $needed_rights)
87 86 { {
88 87 xlog("repo_allow: uid=$uid, needed_rights=$needed_rights..."); xlog("repo_allow: uid=$uid, needed_rights=$needed_rights...");
89 88
90 $e_uid = sprintf("%u", $uid);
91 $e_perms = preg_replace("/[^A-Z]/", "", $perms);
92
93 if (($ri['deleted'] == 1) && ($ri['uid'] != $uid)) {
94 xlog("\tRepo is deleted!");
95 return FALSE;
96 }
97
98 if (empty($e_perms)) {
89 if (empty($needed_rights)) {
99 90 xlog("\tNo perms passed!"); xlog("\tNo perms passed!");
100 91 return FALSE; return FALSE;
101 92 } }
102 93
103 $rr = gg_repo_rights_get($db, $ri['repo_id'], $uid);
104 if ($rr['exists'] != 1) {
94 $rr = gg_repo_rights_get($db, $ri, $uid);
95 if ($rr['ok'] != 1) {
105 96 gg_repo_set_error("No access!"); gg_repo_set_error("No access!");
106 97 return FALSE; return FALSE;
107 98 } }
 
... ... function repo_git_done($db, $repo_id)
372 363 // Functions for repo rights management // Functions for repo rights management
373 364
374 365 /* /*
366 * Combine two repo rights strings
367 */
368 function gg_repo_rights_combine($a, $b)
369 {
370 $len = strlen($b);
371 for ($i = 0; $i < $len; $i++)
372 if (!strstr($a, $b[$i]))
373 $a .= $b[$i];
374
375 return $a;
376 }
377
378 /*
375 379 * Get rights for a user * Get rights for a user
376 380 */ */
377 function gg_repo_rights_get($db, $repo_id, $uid)
381 function gg_repo_rights_get($db, $ri, $uid)
378 382 { {
379 xlog("gg_repo_rights_get: repo_id=$repo_id, uid=$uid...");
383 global $gg_repo_rights;
384
385 xlog("gg_repo_rights_get: repo_id=" . $ri['repo_id'] . ", uid=$uid...");
380 386
381 387 $ret = array(); $ret = array();
382 388 $ret['ok'] = 0; $ret['ok'] = 0;
383 389 $ret['exists'] = 0; $ret['exists'] = 0;
390 $ret['rights'] = "";
391
392 $repo_id = $ri['repo_id'];
393 $dr = $ri['default_rights'];
394
395 // Give all rights to owner
396 if ($ri['uid'] == $uid) {
397 foreach ($gg_repo_rights as $letter => $junk)
398 $dr = gg_repo_rights_combine($dr, $letter);
399 }
384 400
385 $sql = "SELECT * FROM repo_rights"
401 $sql = "SELECT rights FROM repo_rights"
386 402 . " WHERE repo_id = $repo_id" . " WHERE repo_id = $repo_id"
387 403 . " AND uid = $uid" . " AND uid = $uid"
388 404 . " LIMIT 1"; . " LIMIT 1";
 
... ... function gg_repo_rights_get($db, $repo_id, $uid)
395 411 $ret['ok'] = 1; $ret['ok'] = 1;
396 412 $row = sql_fetch_array($res); $row = sql_fetch_array($res);
397 413 sql_free_result($res); sql_free_result($res);
398 if (!isset($row['uid'])) {
399 gg_repo_set_error("User not found!");
400 return $ret;
414 if (isset($row['rights'])) {
415 $ret['rights'] = $row['rights'];
416 $ret['exists'] = 1;
401 417 } }
402 418
403 $row['ok'] = 1;
404 $row['exists'] = 1;
405 return $row;
419 $ret['rights'] = gg_repo_rights_combine($dr, $ret['rights']);
420
421 return $ret;
406 422 } }
407 423
408 424 /* /*
409 425 * Add rights for a repo * Add rights for a repo
410 426 */ */
411 function gg_repo_rights_set($db, $repo_id, $gg_uid, $uid, $rights)
427 function gg_repo_rights_set($db, $ri, $uid, $rights)
412 428 { {
413 xlog("gg_repo_rights_add: repo_id=$repo_id, gg_uid=$gg_uid"
429 xlog("gg_repo_rights_set: repo_id=" . $ri['repo_id']
414 430 . ", uid=$uid, rights=$rights..."); . ", uid=$uid, rights=$rights...");
415 431
416 // check if repo owner is gg_uid, or has admin rights
417 $ri = repo_info($db, $repo_id, "");
418 if ($ri['exists'] != 1) {
419 gg_repo_set_error("Repo does not exists");
420 return FALSE;
421 }
422
423 // check default rights first
424 if (!strstr($ri['default_rights'], "A")) {
425 if ($ri['uid'] != $gg_uid) {
426 // this means that web user is not the owner, search rights
427 $rr = gg_repo_rights_get($db, $repo_id, $gg_uid);
428 if ($rr['exists'] != 1) {
429 gg_repo_set_error("You are not allowed (no rights)!");
430 return FALSE;
431 }
432
433 if (!strstr($rr['rights'], "A")) {
434 gg_repo_set_error("You are not allowed (no admin rights)!");
435 return FALSE;
436 }
437 }
438 }
432 $repo_id = $ri['repo_id'];
439 433
440 434 if (empty($rights)) { if (empty($rights)) {
441 435 $sql = "DELETE FROM repo_rights" $sql = "DELETE FROM repo_rights"
442 436 . " WHERE repo_id = $repo_id" . " WHERE repo_id = $repo_id"
443 437 . " AND uid = $uid"; . " AND uid = $uid";
444 438 } else { } else {
445 $r = gg_repo_rights_get($db, $repo_id, $uid);
446 if ($r['ok'] != 1)
447 return $r;
448
449 439 $e_rights = sql_escape($db, $rights); $e_rights = sql_escape($db, $rights);
450 440
451 if ($r['exists'] == 1) {
441 $rr = gg_repo_rights_get($db, $ri, $repo_id);
442 if ($rr === FALSE)
443 return $rr;
444
445 if ($rr['exists'] == 1) {
452 446 $sql = "UPDATE repo_rights" $sql = "UPDATE repo_rights"
453 447 . " SET rights = '$e_rights'" . " SET rights = '$e_rights'"
454 448 . " WHERE repo_id = $repo_id" . " WHERE repo_id = $repo_id"
 
... ... function gg_repo_rights_text($rights)
566 560 $ret = array(); $ret = array();
567 561
568 562 $len = strlen($rights); $len = strlen($rights);
563 if ($len == 0)
564 return array("None");
565
569 566 for ($i = 0; $i < $len; $i++) { for ($i = 0; $i < $len; $i++) {
570 567 if (isset($gg_repo_rights[$rights[$i]])) if (isset($gg_repo_rights[$rights[$i]]))
571 568 $ret[] = $gg_repo_rights[$rights[$i]]; $ret[] = $gg_repo_rights[$rights[$i]];

File inc/repo/repo_page.php changed (mode: 100644) (index e067b97..a7f40ec)
... ... $_menu .= "
\n";
23 23
24 24 $_body = ""; $_body = "";
25 25
26 $ri = repo_info($db, $repo_id, "");
27 if (($ri['ok'] != 1) || ($ri['deleted'] == 1)) {
28 $_body .= "Invalid repository!";
29 // force subop 0
30 $subop = 0;
31 }
32
33 $_body .= "Repo <b>" . $ri['name'] . "</b><br />\n";
34 if (!empty($ri['desc']))
35 $_body .= "<small>" . $ri['desc'] . "</small><br />\n";
36 $_dr = gg_repo_rights_text($ri['default_rights']);
37 $_body .= "Default rights: " . implode(", ", $_dr) . "<br /><br />\n";
38 $_body .= "Maxim commit size: " . gg_1024($ri['max_commit_size']) . "<br />\n";
39 $_body .= "<br />\n";
40
26 41 switch ($subop) { switch ($subop) {
27 42 case 1: // edit case 1: // edit
28 43 if ($doit == 1) { if ($doit == 1) {
 
... ... case 1: // edit
33 48 else else
34 49 $_body .= "OK!"; $_body .= "OK!";
35 50 } else { } else {
36 $_ri = repo_info($db, $repo_id, "");
37 if ($_ri['ok'] != 1) {
38 $_body .= "Invalid repository!";
39 } else {
40 // load variables
41 $name = $_ri['name'];
42 $rights = $_ri['default_rights'];
43 $max_commit_size = $_ri['max_commit_size'];
44 $desc = $_ri['desc'];
45
46 $_action = "Update";
47 include($INC . "/repo/repo.form.php");
48 $_body .= $_form;
49 }
51 // load variables
52 $name = $ri['name'];
53 $rights = $ri['default_rights'];
54 $max_commit_size = $ri['max_commit_size'];
55 $desc = $ri['desc'];
56
57 $_action = "Update";
58 include($INC . "/repo/repo.form.php");
59 $_body .= $_form;
50 60 } }
51 61 break; break;
52 62
53 63 case 2: // rights case 2: // rights
54 64 $errmsg = ""; $errmsg = "";
65 $_errors = 0;
66
67 while ($doit == 1) {
68 // lookup user
69 $_ui = user_info($db, 0, $user, "");
70 if ($_ui['exists'] != 1) {
71 $errmsg .= "User does not exists!";
72 $_errors++;
73 break;
74 }
55 75
56 if ($doit == 1) {
57 $_errors = 0;
58
59 while (1) {
60 // lookup user
61 $_ui = user_info($db, 0, $user, "");
62 if ($_ui['exists'] != 1) {
63 $errmsg .= "User does not exists!";
64 $_errors++;
65 break;
66 }
67
68 // TODO: Check if user is allowed to give rights
69
70 $e = gg_repo_rights_set($db, $repo_id, $gg_uid,
71 $_ui['uid'], $rights);
72 if ($e === FALSE) {
73 $errmsg .= gg_repo_error();
74 $_errors++;
75 break;
76 }
76 // TODO: Check if user is allowed to give rights
77 77
78 $e = gg_repo_rights_set($db, $ri, $_ui['uid'], $rights);
79 if ($e === FALSE) {
80 $errmsg .= gg_repo_error();
81 $_errors++;
78 82 break; break;
79 83 } }
80 }
81 84
82 $_ri = repo_info($db, $repo_id, "");
83 if ($_ri['ok'] != 1) {
84 $_body .= "Invalid repository!";
85 } else {
86 // list rights
87 $_body .= "<b>Repository " . $_ri['name'] . "</b><br />\n";
88 $_body .= gg_repo_rights_list($db, $repo_id);
85 break;
86 }
89 87
90 // give rights form
91 $_body .= "<br />\n";
88 // list rights
89 $_body .= gg_repo_rights_list($db, $repo_id);
92 90
93 $checkboxes = gg_repo_rights_checkboxes($rights);
91 // give rights form
92 $_body .= "<br />\n";
94 93
95 include($INC . "/repo/rights.form.php");
96 $_body .= $_form;
97 }
94 include($INC . "/repo/rights.form.php");
95 $_body .= $_form;
98 96 break; break;
99 97
100 98 case 3: //delete case 3: //delete

File inc/repo/rights.form.php changed (mode: 100644) (index a189e57..c9d07b5)
... ... $_form = '
19 19 <tr> <tr>
20 20 <td>Rights:</td> <td>Rights:</td>
21 21 <td> <td>
22 ' . $checkboxes . '
22 ' . gg_repo_rights_checkboxes($rights) . '
23 23 </td> </td>
24 24 </tr> </tr>
25 25
26 26 <tr> <tr>
27 <td colspan="2"><input type="submit" value="Add!"></td>
27 <td colspan="2"><input type="submit" value="Give"></td>
28 28 </tr> </tr>
29 29
30 30 </table> </table>

File scripts/cron.php changed (mode: 100644) (index f1575f7..5bd0f77)
... ... if (date("H") == 1) {
79 79 xlog("Regenerate keys..."); xlog("Regenerate keys...");
80 80 keys_regen($db); keys_regen($db);
81 81
82 // Arhive deleted repositories
83 if (date("H") == 23) {
84 //TODO: xlog("Delete repositories...");
85 }
86
82 87 // this has to be the last thing that touches the database // this has to be the last thing that touches the database
83 88 if (date("H") == 0) { if (date("H") == 0) {
84 89 xlog("Run VACUUM on database..."); xlog("Run VACUUM on database...");

File scripts/q.php changed (mode: 100644) (index c2911ce..a8ad2c9)
... ... if ($db === FALSE) {
31 31 exit(1); exit(1);
32 32 } }
33 33
34 // limit the number of runs, so we can upgrade the software and this script will
34 // Limit the number of runs, so we can upgrade the software and this script will
35 35 // restart. // restart.
36 36 $runs = 1; $runs = 1;
37 37 while ($runs-- > 0) { while ($runs-- > 0) {
 
... ... while ($runs-- > 0) {
46 46 } }
47 47
48 48 xlog("Check to create not-yet-created repos..."); xlog("Check to create not-yet-created repos...");
49 // Ordered by master to create masters first
49 50 $sql = "SELECT repo_id, master, name FROM repos" $sql = "SELECT repo_id, master, name FROM repos"
50 . " WHERE git_dir_done = 0"
51 . " WHERE deleted = 0"
52 . " AND git_dir_done = 0"
51 53 . " ORDER BY master"; . " ORDER BY master";
52 54 $res = sql_query($db, $sql); $res = sql_query($db, $sql);
53 55 if ($res === FALSE) { if ($res === FALSE) {

File scripts/ssh.php changed (mode: 100644) (index 7c4b308..c5d1555)
... ... if ($ri['ok'] != 1)
119 119 fatal("Temporary error!"); fatal("Temporary error!");
120 120 if ($ri['exists'] != 1) if ($ri['exists'] != 1)
121 121 fatal("Repo does not exists!"); fatal("Repo does not exists!");
122 if ($ri['deleted'] == 1)
123 fatal("Repo was deleted!");
122 124
123 125 if (!repo_allow($db, $ri, $uid, $perms)) if (!repo_allow($db, $ri, $uid, $perms))
124 126 fatal("You do not have this type of access to this repository!"); fatal("You do not have this type of access to this repository!");

File tests/db.php changed (mode: 100644) (index 500d74a..0ab593c)
1 1 <?php <?php
2 error_reporting(E_ALL | E_STRICT);
3
2 4 $INC = "../inc"; $INC = "../inc";
3 5 require_once($INC . "/db.inc.php"); require_once($INC . "/db.inc.php");
4 6

File tests/keys.php changed (mode: 100644) (index ce69fa4..d5e9cee)
1 1 <?php <?php
2 error_reporting(E_ALL | E_STRICT);
3
2 4 $INC = "../inc"; $INC = "../inc";
3 5 require_once($INC . "/keys.inc.php"); require_once($INC . "/keys.inc.php");
6 require_once($INC . "/db/struct.inc.php");
4 7
5 8 @unlink("keys.sqlite"); @unlink("keys.sqlite");
6 9
 
... ... if ($db === FALSE) {
11 14 } }
12 15
13 16 // state table // state table
14 $sql = "CREATE TABLE state (var TEXT PRIMARY KEY, value TEXT)";
15 $res = sql_query($db, $sql);
16 if ($res === FALSE) {
17 echo "Cannot create state table!";
18 exit(1);
19 }
20
21 // keys table
22 $sql = "CREATE TABLE keys (key_id INT PRIMARY KEY, itime INT, uid INT, key TEXT)";
23 $res = sql_query($db, $sql);
24 if ($res === FALSE) {
25 echo "Cannot create keys table!";
17 $r = gg_db_struct_run($db, FALSE);
18 if ($r === FALSE) {
19 echo "Cannot create tables!";
26 20 exit(1); exit(1);
27 21 } }
28 22

File tests/repo.php changed (mode: 100644) (index e912ddc..882e6ec)
1 1 <?php <?php
2 error_reporting(E_ALL | E_STRICT);
3
2 4 $INC = "../inc"; $INC = "../inc";
3 5 require_once($INC . "/repo.inc.php"); require_once($INC . "/repo.inc.php");
6 require_once($INC . "/db/struct.inc.php");
7
8 xlog_set_file(__FILE__ . ".log");
4 9
5 10 @unlink("repo.sqlite"); @unlink("repo.sqlite");
6 11
 
... ... if ($db === FALSE) {
10 15 exit(1); exit(1);
11 16 } }
12 17
13 $sql = "CREATE TABLE repos (repo_id INTEGER PRIMARY KEY, name TEXT, uid INTEGER"
14 . ", itime INTEGER"
15 . ", public INTEGER"
16 . ", disk_quota_mb INTEGER"
17 . ", max_commit_size INTEGER"
18 . ", master INTEGER"
19 . ", desc TEXT"
20 . ", git_dir_done INTEGER"
21 . ")";
22 $res = sql_query($db, $sql);
23 if ($res === FALSE) {
24 echo "WARN: Cannot create 'repos' table!\n";
18 $r = gg_db_struct_run($db, FALSE);
19 if ($r === FALSE) {
20 echo "Cannot create struct!\n";
25 21 exit(1); exit(1);
26 22 } }
27 23
28 $sql = "CREATE TABLE repo_rights (repo_id INTEGER, uid INTEGER, rights TEXT"
29 . ", itime INTEGER)";
24 $sql = "INSERT INTO repos (repo_id, name, uid, itime"
25 . ", disk_quota_mb, max_commit_size"
26 . ", master, desc, git_dir_done, default_rights)"
27 . " VALUES (1, 'repo1', 1, 0, 0, 0, 0, 'bla bla desc', 1, '')";
30 28 $res = sql_query($db, $sql); $res = sql_query($db, $sql);
31 29 if ($res === FALSE) { if ($res === FALSE) {
32 echo "WARN: Cannot create 'repo_rights' table!\n";
30 echo "Cannot insert a user!\n";
33 31 exit(1); exit(1);
34 32 } }
35 33
36 $sql = "CREATE TABLE users (uid INTEGER PRIMARY KEY, user TEXT, salt TEXT"
37 . ", pass TEXT, email TEXT, itime INTEGER"
38 . ", suspended INTEGER"
39 . ", session_time INTEGER DEFAULT 3600"
40 . ", last_seen INTEGER"
41 . ", is_admin INTEGER"
42 . ", disk_quota_mb INTEGER"
43 . ", disk_mb INTEGER"
44 . ")";
45 $res = sql_query($db, $sql);
46 if ($res === FALSE) {
47 echo "WARN: Cannot create 'users' table!\n";
34 $repo_id = 1;
35 $ri = repo_info($db, $repo_id, "");
36 $uid = 10;
37 $v = gg_repo_rights_set($db, $ri, $uid, "F");
38 if ($v === FALSE) {
39 echo "Cannot give rights (1)!\n";
48 40 exit(1); exit(1);
49 41 } }
50 42
51 $sql = "INSERT INTO repos (repo_id, name, uid, itime"
52 . ", disk_quota_mb, max_commit_size"
53 . ", master, desc, git_dir_done)"
54 . " VALUES (1, 'repo1', 1, 0, 0, 0, 0, 'bla bla desc', 1)";
55 $res = sql_query($db, $sql);
56 if ($res === FALSE) {
57 echo "Cannot insert a user!\n";
43 $a = "AF"; $b = "AD"; $e = "AFD";
44 $r = gg_repo_rights_combine($a, $b);
45 if (strcmp($r, $e) != 0) {
46 echo "Combine rights error1 ([$r] vs [$e])\n";
58 47 exit(1); exit(1);
59 48 } }
60 49
61 $v = gg_repo_rights_set($db, 1, 1, "F");
62 if ($v === FALSE) {
63 echo "Cannot give rights (1)!\n";
50 $a = ""; $b = ""; $e = "";
51 $r = gg_repo_rights_combine($a, $b);
52 if (strcmp($r, $e) != 0) {
53 echo "Combine rights error1 ([$r] vs [$e])\n";
64 54 exit(1); exit(1);
65 55 } }
66 56
67 // check if we try to give rights for a not owned repo
68 $gg_uid = 2;
69 $uid = 1;
70 $v = gg_repo_rights_get($db, $repo_id, $gg_uid, $uid, "A");
71 if ($v === TRUE) {
72 echo "Error: " . gg_repo_error() . "!\n";
57 $a = "AXUJUNFUUFU"; $b = ""; $e = $a;
58 $r = gg_repo_rights_combine($a, $b);
59 if (strcmp($r, $e) != 0) {
60 echo "Combine rights error1 ([$r] vs [$e])\n";
73 61 exit(1); exit(1);
74 62 } }
75 63

File tests/user.php changed (mode: 100644) (index 7e5f149..ce01c95)
1 1 <?php <?php
2 error_reporting(E_ALL | E_STRICT);
3
2 4 $INC = "../inc"; $INC = "../inc";
3 5 require_once($INC . "/user.inc.php"); require_once($INC . "/user.inc.php");
6 require_once($INC . "/db/struct.inc.php");
4 7
5 8 @unlink("user.sqlite"); @unlink("user.sqlite");
6 9
 
... ... if ($db === FALSE) {
10 13 exit(1); exit(1);
11 14 } }
12 15
13 $sql = "CREATE TABLE users (email TEXT PRIMARY KEY, forgot_pass_token TEXT, forgot_pass_expire INTEGER)";
14 $res = sql_query($db, $sql);
15 if ($res === FALSE) {
16 echo "Cannot create users table!";
16 $r = gg_db_struct_run($db, FALSE);
17 if ($r === FALSE) {
18 echo "Cannot create structure!";
17 19 exit(1); exit(1);
18 20 } }
19 21
 
... ... if ($res === FALSE) {
24 26 exit(1); exit(1);
25 27 } }
26 28
27 $v = user_forgot_pass($db, "gg@localhost");
29 $v = user_forgot_pass_mail($db, "gg@localhost");
28 30 if ($v === FALSE) { if ($v === FALSE) {
29 31 echo "Error: " . user_error() . "!\n"; echo "Error: " . user_error() . "!\n";
30 32 exit(1); exit(1);

File tests/util.php changed (mode: 100644) (index 5b96512..bbbbba8)
1 1 <?php <?php
2 error_reporting(E_ALL | E_STRICT);
3
2 4 $INC = "../inc"; $INC = "../inc";
3 5 require_once($INC . "/util.inc.php"); require_once($INC . "/util.inc.php");
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