#!/usr/local/bin/perl # edit_grant.cgi # Display a form for editing or creating a grant require './postgresql-lib.pl'; &ReadParse(); $access{'users'} || &error($text{'grant_ecannot'}); &ui_print_header(undef, $text{'grant_edit'}, ""); if (&supports_schemas($in{'db'})) { $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'); } else { $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'); } foreach $g (@{$s->{'data'}}) { if ($g->[0] eq $in{'table'} && $g->[2] eq $in{'ns'}) { $g->[1] =~ s/^\{//; $g->[1] =~ s/\}$//; @grant = map { /^"(.*)=(.*)"$/ || /^(.*)=(.*)$/; [ $1, $2 ] } split(/,/, $g->[1]); } } print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
$text{'grant_header'}
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; $u = &execute_sql_safe($config{'basedb'}, "select usename from pg_shadow"); @users = map { $_->[0] } @{$u->{'data'}}; $r = &execute_sql_safe($config{'basedb'}, "select groname from pg_group"); @groups = map { $_->[0] } @{$r->{'data'}}; print "\n"; print "
$text{'grant_db'}$in{'db'}
$text{'grant_ns'}$in{'ns'}
",$text{"grant_$in{'type'}"},"$in{'table'}
$text{'grant_users'}
\n"; print "\n"; print " ", "\n"; $i = 0; foreach $g (@grant, [ undef, undef ]) { print "\n"; $i++; } print "
$text{'grant_user'}$text{'grant_what'}
\n"; ($acl = $g->[1]) =~ s/\/.*//g; foreach $p ( [ 'SELECT', 'r' ], [ 'UPDATE', 'w' ], [ 'INSERT', 'a' ], [ 'DELETE', 'd' ], [ 'RULE', 'R' ], [ 'REFERENCES', 'x' ], [ 'TRIGGER', 't' ] ) { printf " %s\n", $p->[0], $acl =~ /$p->[1]/ ? 'checked' : '', $p->[0]; } print "
\n"; print "
\n"; &ui_print_footer("list_grants.cgi?search=".&urlize($in{'search'}), $text{'grant_return'});