postgresql/ 0040755 0005671 0000012 00000000000 10117720626 012747 5 ustar jcameron wheel postgresql/edit_grant.cgi 0100775 0005671 0000012 00000005354 10114726052 015560 0 ustar jcameron wheel #!/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'}, ""); $s = &execute_sql($in{'db'}, 'select relname, relacl 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->[1] =~ s/^\{//; $g->[1] =~ s/\}$//; @grant = map { /^"(.*)=(.*)"$/ || /^(.*)=(.*)$/; [ $1, $2 ] } split(/,/, $g->[1]); } } @tables = &list_tables($in{'db'}); print "
\n"; &ui_print_footer("list_grants.cgi", $text{'grant_return'}); postgresql/postgresql-lib.pl 0100664 0005671 0000012 00000040011 10117720360 016241 0 ustar jcameron wheel # postgresql-lib.pl # Common PostgreSQL functions # XXX dropping fields from schema table # XXX maybe can only rename within schema? # XXX updating date field # XXX access control and schema tables do '../web-lib.pl'; &init_config(); require '../ui-lib.pl'; if ($config{'plib'}) { $ENV{$gconfig{'ld_env'}} .= ':' if ($ENV{$gconfig{'ld_env'}}); $ENV{$gconfig{'ld_env'}} .= $config{'plib'}; } if ($config{'psql'} =~ /^(.*)\/bin\/psql$/ && $1 ne '' && $1 ne '/usr') { $ENV{$gconfig{'ld_env'}} .= ':' if ($ENV{$gconfig{'ld_env'}}); $ENV{$gconfig{'ld_env'}} .= "$1/lib"; } if ($module_info{'usermin'}) { # Login and password is set by user in Usermin, and the module always # runs as the Usermin user &switch_to_remote_user(); &create_user_config_dirs(); $postgres_login = $userconfig{'login'}; $postgres_pass = $userconfig{'pass'}; $postgres_sameunix = 0; %access = ( 'backup' => 1, 'restore' => 1 ); } else { # Login and password is determined by ACL in Webmin %access = &get_module_acl(); if ($access{'user'} && !$use_global_login) { $postgres_login = $access{'user'}; $postgres_pass = $access{'pass'}; $postgres_sameunix = $access{'sameunix'}; } else { $postgres_login = $config{'login'}; $postgres_pass = $config{'pass'}; $postgres_sameunix = $config{'sameunix'}; } } $cron_cmd = "$module_config_directory/backup.pl"; if (!$config{'nodbi'}) { # Check if we have DBD::Pg eval <$emsg" ); } else { @titles = ( " Command Invocation " ) ; @row = ( " Done ( return code : $rc )" ) ; map { s/^\s+//; s/\s+$// } @row ; push ( @data, \@row ) ; return { 'titles' => \@titles, 'data' => \@data } ; } } } } # execute_sql_logged(database, command) sub execute_sql_logged { &additional_log('sql', $_[0], $_[1]); return &execute_sql(@_); } # run_as_postgres(command) sub run_as_postgres { pipe(OUTr, OUTw); local $pid = fork(); if (!$pid) { untie(*STDIN); untie(*STDOUT); untie(*STDERR); close(STDIN); open(STDOUT, ">&OUTw"); open(STDERR, ">&OUTw"); local @u = getpwnam($config{'user'}); $( = $u[3]; $) = "$u[3] $u[3]"; ($>, $<) = ($u[2], $u[2]); exec(@_); print "Exec failed : $!\n"; exit 1; } close(OUTw); return OUTr; } sub can_edit_db { if ($module_info{'usermin'}) { foreach $l (split(/\t/, $config{'access'})) { if ($l =~ /^(\S+):\s*(.*)$/ && ($1 eq $remote_user || $1 eq '*')) { local @dbs = split(/\s+/, $2); foreach $d (@dbs) { $d =~ s/\$REMOTE_USER/$remote_user/g; return 1 if ($d eq '*' || $_[0] =~ /^$d$/); } return 0; } } return 0; } else { local $d; return 1 if ($access{'dbs'} eq '*'); foreach $d (split(/\s+/, $access{'dbs'})) { return 1 if ($d && $d eq $_[0]); } return 0; } } # get_hba_config(version) # Parses the postgres host access config file sub get_hba_config { local $lnum = 0; open(HBA, $config{'hba_conf'}); while(
\n"; } $d = &execute_sql($in{'db'}, "select count(*) from $qt $search"); $total = $d->{'data'}->[0]->[0]; if ($in{'jump'} > 0) { $in{'start'} = int($in{'jump'} / $config{'perpage'}) * $config{'perpage'}; if ($in{'start'} >= $total) { $in{'start'} = $total - $config{'perpage'}; $in{'start'} = int(($in{'start'} / $config{'perpage'}) + 1) * $config{'perpage'}; } } else { $in{'start'} = int($in{'start'}); } if ($in{'new'} && $total > $config{'perpage'}) { # go to the last screen for adding a row $in{'start'} = $total - $config{'perpage'}; $in{'start'} = int(($in{'start'} / $config{'perpage'}) + 1) * $config{'perpage'}; } if ($in{'start'} || $total > $config{'perpage'}) { print "
",&text('view_searchhead', "$in{'for'}", "$in{'field'}")," | \n"; print "$text{'view_searchreset'} | \n"; print "
$?\n$out"); } } else { open(PID, $config{'pid_file'}); ($pid =
$text{'field_header'} | ||||||||||||
|
$text{'grant_tvi'} | ", "$text{'grant_type'} | ", "$text{'grant_db'} | ", "$text{'grant_users'} |
",&html_escape($g->[0])," | \n"; print "",$text{"grant_$type"}." | \n"; print "",&html_escape($d)," | \n"; print "\n"; $g->[1] =~ s/^\{//; $g->[1] =~ s/\}$//; @gr = grep { /=\S/ } map { /^"(.*)"$/ ? $1 : $_ } split(/,/, $g->[1]); foreach $gr (@gr) { print " | " if ($gr ne $gr[0]); if ($gr =~ /^=(\S+)/) { print $text{'grant_public'}; } elsif ($gr =~ /^group\s+(\S+)=(\S+)/) { print &text('grant_group', "".&html_escape($1).""); } elsif ($gr =~ /^(\S+)=(\S+)$/) { print "".&html_escape($1).""; } } print " |
\n"; } else { print "$text{'grant_none'}
\n"; } &ui_print_footer("", $text{'index_return'}); postgresql/save_user.cgi 0100775 0005671 0000012 00000002763 10114725647 015446 0 ustar jcameron wheel #!/usr/local/bin/perl # save_user.cgi # Create, update or delete a postgres user require './postgresql-lib.pl'; &ReadParse(); $access{'users'} || &error($text{'user_ecannot'}); &error_setup($text{'user_err'}); if ($in{'delete'}) { # just delete the user &execute_sql_logged($config{'basedb'}, "drop user \"$in{'user'}\""); &webmin_log("delete", "user", $in{'user'}); } else { # parse inputs $version = &get_postgresql_version(); if (!$in{'pass_def'}) { $in{'pass'} =~ /^\S+$/ || &error($text{'user_epass'}); $sql .= $version >= 7 ? " with password '$in{'pass'}'" : " with password $in{'pass'}"; } elsif ($in{'new'}) { $sql .= " with password ''"; } if ($in{'db'}) { $sql .= " createdb"; } else { $sql .= " nocreatedb"; } if ($in{'other'}) { $sql .= " createuser"; } else { $sql .= " nocreateuser"; } if (!$in{'until_def'}) { $sql .= " valid until '$in{'until'}'"; } if ($in{'new'}) { $in{'name'} =~ /^\S+$/ || &error($text{'user_ename'}); &execute_sql_logged($config{'basedb'}, "create user \"$in{'name'}\" $sql"); &webmin_log("create", "user", $in{'name'}); } else { &execute_sql_logged($config{'basedb'}, "alter user \"$in{'user'}\" $sql"); if (&get_postgresql_version() >= 7.4 && $in{'name'} ne $in{'user'}) { # Rename too &execute_sql_logged($config{'basedb'}, "alter user \"$in{'user'}\" ". "rename to \"$in{'name'}\""); } &webmin_log("modify", "user", $in{'user'}); } } &redirect("list_users.cgi"); postgresql/edit_table.cgi 0100755 0005671 0000012 00000005332 10115476265 015537 0 ustar jcameron wheel #!/usr/local/bin/perl # edit_table.cgi # Display the structure of some table require './postgresql-lib.pl'; &ReadParse(); &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'}); $desc = &text('table_header', "$in{'table'}", "$in{'db'}"); &ui_print_header($desc, $text{'table_title'}, "", "edit_table"); @desc = &table_structure($in{'db'}, $in{'table'}); print "
\n"; &type_table(0, $mid); print " | \n"; &type_table($mid, scalar(@desc)) if (@desc > 1); print " |
\n"; print " | \n"; print "\n"; print " | \n"; print "\n"; print " | \n"; print "\n"; print " | \n"; print "
$text{'table_field'} | ", "$text{'table_type'} | ", "$text{'table_arr'} | ", "$text{'table_null'} |
",&html_escape($r->{'field'})," | \n"; print "",&html_escape($r->{'type'})," | \n"; print "",$r->{'arr'} eq 'YES' ? $text{'yes'} : $text{'no'}," | \n"; print "",$r->{'null'} eq 'YES' ? $text{'yes'} : $text{'no'}," | \n"; print "