diff --git a/postgresql/config.info b/postgresql/config.info index 321a9a091..cee84a953 100644 --- a/postgresql/config.info +++ b/postgresql/config.info @@ -22,8 +22,9 @@ stop_cmd=Command to stop PostgreSQL,3,Kill process setup_cmd=Command to initialize PostgreSQL,3,None pid_file=Path to postmaster PID file,8 hba_conf=Paths to host access config file,9,60,3,\t -host=PostgreSQL host to connect to,3,localhost +host=PostgreSQL host to connect to,3,Local socket port=PostgreSQL port to connect to,3,Default +sslmode=SSL connection mode,4,-Default,disable-Unencrypted only,allow-Unencrypted then SSL,prefer-SSL then unencrypted,require-SSL only,verify_ca-SSL with trusted CA only,verify_full-SSL with trusted CA and matching hostname only dump_cmd=Path to pg_dump command,0 rstr_cmd=Path to pg_restore command,0 repository=Default backup repository directory,3,None diff --git a/postgresql/index.cgi b/postgresql/index.cgi index f166e9ee1..7883140f9 100755 --- a/postgresql/index.cgi +++ b/postgresql/index.cgi @@ -302,13 +302,19 @@ if (&foreign_available("cpan")) { sub main_header { -local ($noschemas) = @_; +my ($noschemas) = @_; +my $smsg = ""; +if (!$noschemas) { + eval { + local $main::error_must_die = 1; + $smsg = supports_schemas($config{'basedb'}) ? + " ".$text{'index_sch'} : ""; + }; + } &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0, &help_search_link("postgresql", "man", "doc", "google"), undef, undef, $postgresql_version ? - &text('index_version', $postgresql_version). - ($noschemas ? "" : - &supports_schemas($config{'basedb'}) ? " $text{'index_sch'}" : "") : + &text('index_version', $postgresql_version).$smsg : undef); } diff --git a/postgresql/postgresql-lib.pl b/postgresql/postgresql-lib.pl index cac7735b0..811c8096b 100755 --- a/postgresql/postgresql-lib.pl +++ b/postgresql/postgresql-lib.pl @@ -75,11 +75,11 @@ EOF sub is_postgresql_running { local $temp = &transname(); -local $host = $config{'host'} ? "-h $config{'host'}" : ""; -$host .= " -p $config{'port'}" if ($config{'port'}); local $cmd = "e_path($config{'psql'}). + &host_port_flags(). (!&supports_pgpass() ? " -u" : " -U $postgres_login"). - " -c '' $host $config{'basedb'}"; + " -c ''". + " ".$config{'basedb'}; if ($postgres_sameunix && defined(getpwnam($postgres_login))) { $cmd = "su $postgres_login -c ".quotemeta($cmd); } @@ -291,6 +291,9 @@ if ($driver_handle && local $cstr = "dbname=$_[0]"; $cstr .= ";host=$config{'host'}" if ($config{'host'}); $cstr .= ";port=$config{'port'}" if ($config{'port'}); + local $sslmode = $config{'sslmode'}; + $sslmode =~ s/_/-/g; + $cstr .= ";sslmode=$sslmode" if ($sslmode); local @uinfo; if ($postgres_sameunix && (@uinfo = getpwnam($postgres_login))) { @@ -400,11 +403,11 @@ else { } # Call the psql program - local $host = $config{'host'} ? "-h $config{'host'}" : ""; - $host .= " -p $config{'port'}" if ($config{'port'}); local $cmd = "e_path($config{'psql'})." --html". + &host_port_flags(). (!&supports_pgpass() ? " -u" : " -U $postgres_login"). - " -c "."e_path($sql)." $host $_[0]"; + " -c "."e_path($sql). + " ".$_[0]; if ($postgres_sameunix && defined(getpwnam($postgres_login))) { $cmd = &command_as_user($postgres_login, 0, $cmd); } @@ -800,10 +803,9 @@ if (!defined($user)) { $pass = $postgres_pass; } local $cmd = "e_path($config{'psql'})." -f "."e_path($file). + &host_port_flags(). (&supports_pgpass() ? " -U $user" : " -u"). - ($config{'host'} ? " -h $config{'host'}" : ""). - ($config{'port'} ? " -h $config{'port'}" : ""). - " $db"; + " ".$db; if ($postgres_sameunix && defined(getpwnam($postgres_login))) { $cmd = &command_as_user($postgres_login, 0, $cmd); } @@ -1145,10 +1147,9 @@ elsif ($compress == 2) { $writer = "bzip2 -c >".quotemeta($path); } my $cmd = "e_path($config{'dump_cmd'}). + &host_port_flags(). (!$postgres_login ? "" : &supports_pgpass() ? " -U $postgres_login" : " -u"). - ($config{'host'} ? " -h $config{'host'}" : ""). - ($config{'port'} ? " -p $config{'port'}" : ""). ($format eq 'p' ? "" : " -b"). $tablesarg. " -F$format $db | $writer"; @@ -1176,10 +1177,9 @@ sub restore_database my ($db, $path, $only, $clean, $tables) = @_; my $tablesarg = join(" ", map { " -t ".quotemeta('"'.$_.'"') } @$tables); my $cmd = "e_path($config{'rstr_cmd'}). + &host_port_flags(). (!$postgres_login ? "" : &supports_pgpass() ? " -U $postgres_login" : " -u"). - ($config{'host'} ? " -h $config{'host'}" : ""). - ($config{'port'} ? " -p $config{'port'}" : ""). ($only ? " -a" : ""). ($clean ? " -c" : ""). $tablesarg. @@ -1253,6 +1253,27 @@ else { return $cmd; } +# host_port_flags() +# Returns flags to set the correct host and post for postgreSQL CLI commands +sub host_port_flags +{ +local $sslmode = $config{'sslmode'}; +$sslmode =~ s/_/-/g; +if ($sslmode) { + my @rv; + push(@rv, "host=".$config{'host'}) if ($config{'host'}); + push(@rv, "port=".$config{'port'}) if ($config{'port'}); + push(@rv, "sslmode=".$sslmode) if ($sslmode); + return @rv ? " '".join(" ", @rv)."'" : ""; + } +else { + my $rv = ""; + $rv .= " -h $config{'host'}" if ($config{'host'}); + $rv .= " -p $config{'port'}" if ($config{'port'}); + return $rv; + } +} + # extract_grants(field) # Given a field from pg_class that contains grants either as a comma-separated # list or an array, return a list of tuples in user,grant format