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) |
371 |
362 |
|
|
372 |
363 |
// Functions for repo rights management |
// Functions for repo rights management |
373 |
364 |
|
|
|
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 |
|
|
374 |
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 .= "<br />\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 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 |
|
|