3 # Display a form for editing or creating a grant
5 require './postgresql-lib.pl';
7 $access{'users'} || &error($text{'grant_ecannot'});
8 &ui_print_header(undef, $text{'grant_edit'}, "");
9 if (&supports_schemas($in{'db'})) {
10 $s = &execute_sql_safe($in{'db'}, 'select relname, relacl, nspname from pg_class, pg_namespace where relnamespace = pg_namespace.oid and (relkind = \'r\' OR relkind = \'S\') and relname !~ \'^pg_\' order by relname');
13 $s = &execute_sql_safe($in{'db'}, 'select relname, relacl, \'public\' from pg_class where (relkind = \'r\' OR relkind = \'S\') and relname !~ \'^pg_\' order by relname');
15 foreach $g (@{$s->{'data'}}) {
16 if ($g->[0] eq $in{'table'} &&
17 $g->[2] eq $in{'ns'}) {
18 $g->[1] =~ s/^\{//; $g->[1] =~ s/\}$//;
19 @grant = map { /^"(.*)=(.*)"$/ || /^(.*)=(.*)$/; [ $1, $2 ] }
25 print &ui_form_start("save_grant.cgi", "post");
26 print &ui_hidden("db", $in{'db'});
27 print &ui_hidden("table", $in{'table'});
28 print &ui_hidden("ns", $in{'ns'});
29 print &ui_hidden("type", $in{'type'});
30 print &ui_hidden("search", $in{'search'});
31 print &ui_table_start($text{'grant_header'}, undef, 2);
34 print &ui_table_row($text{'grant_db'}, "<tt>$in{'db'}</tt>");
37 print &ui_table_row($text{'grant_ns'}, "<tt>$in{'ns'}</tt>");
40 print &ui_table_row($text{"grant_$in{'type'}"}, "<tt>$in{'table'}</tt>");
42 # Get users and groups for permissions table
43 $u = &execute_sql_safe($config{'basedb'}, "select usename from pg_shadow");
44 @users = map { $_->[0] } @{$u->{'data'}};
46 $r = &execute_sql_safe($config{'basedb'}, "select groname from pg_group");
47 @groups = map { $_->[0] } @{$r->{'data'}};
49 # Table of users / groups and permissions
52 foreach $g (@grant, [ undef, undef ]) {
53 # User / group selector
55 push(@row, &ui_select("user_$i",
56 !defined($g->[0]) ? "" :
57 $g->[0] eq '' ? "public" : $g->[0],
59 [ 'public', $text{'grant_public'} ],
60 (map { [ "group $_", &text('grant_group', $_) ] }
65 ($acl = $g->[1]) =~ s/\/.*//g;
67 foreach $p ( [ 'SELECT', 'r' ], [ 'UPDATE', 'w' ],
68 [ 'INSERT', 'a' ], [ 'DELETE', 'd' ],
69 [ 'RULE', 'R' ], [ 'REFERENCES', 'x' ],
70 [ 'TRIGGER', 't' ] ) {
71 $cbs .= &ui_checkbox("what_$i", $p->[0], $p->[0],
72 $acl =~ /$p->[1]/)."\n";
78 print &ui_table_row($text{'grant_users'},
79 &ui_columns_table([ $text{'grant_user'}, $text{'grant_what'} ],
83 print &ui_table_end();
84 print &ui_form_end([ [ undef, $text{'save'} ] ]);
86 &ui_print_footer("list_grants.cgi?search=".&urlize($in{'search'}),
87 $text{'grant_return'});