fix bug #2605601 Doesn't check if pg_dump_path is valid
authorGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Wed, 11 Mar 2009 02:01:37 +0000 (22:01 -0400)
committerGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Wed, 11 Mar 2009 02:01:37 +0000 (22:01 -0400)
dbexport.php
lang/english.php
lang/recoded/english.php

index 2c922607bb6f24aedb9b68cb72fe8c5224ddfde6..d7dce3b02e7b96365e999cfd004e3dfc09665448 100644 (file)
        $_no_output = true;
        include_once('./libraries/lib.inc.php');
 
+       // Are we doing a cluster-wide dump or just a per-database dump
+       $dumpall = ($_REQUEST['subject'] == 'server');
+       
        // Check that database dumps are enabled.
-       if ($misc->isDumpEnabled()) {
+       if ($misc->isDumpEnabled($dumpall)) {
+
+               $server_info = $misc->getServerInfo();
+
+               // Get the path of the pg_dump/pg_dumpall executable
+               $exe = $misc->escapeShellCmd($server_info[$dumpall ? 'pg_dumpall_path' : 'pg_dump_path']);
+
+               // Obtain the pg_dump version number and check if the path is good
+               $version = array();
+               preg_match("/(\d+(?:\.\d+)?)(?:\.\d+)?.*$/", exec($exe . " --version"), $version);
+
+               if (empty($version)) {
+                       if ($dumpall)
+                               printf($lang['strbadpgdumpallpath'], $server_info['pg_dumpall_path']);
+                       else
+                               printf($lang['strbadpgdumppath'], $server_info['pg_dump_path']);
+                       exit;
+               }
 
                // Make it do a download, if necessary
                switch($_REQUEST['output']){
@@ -40,7 +60,6 @@
                }
 
                // Set environmental variables that pg_dump uses
-               $server_info = $misc->getServerInfo();          
                putenv('PGPASSWORD=' . $server_info['password']);
                putenv('PGUSER=' . $server_info['username']);
                $hostname = $server_info['host'];
                        putenv('PGPORT=' . $port);
                }
 
-               // Are we doing a cluster-wide dump or just a per-database dump
-               $dumpall = ($_REQUEST['subject'] == 'server');
-               
-               // Get the path og the pg_dump/pg_dumpall executable
-               $exe = $misc->escapeShellCmd($server_info[$dumpall ? 'pg_dumpall_path' : 'pg_dump_path']);
-               
                // Build command for executing pg_dump.  '-i' means ignore version differences.
                $cmd = $exe . " -i";
                
                        break; 
                case 'table':
                case 'view':
-                       // Obtain the pg_dump version number
-                       $version = array();
-                       preg_match("/(\d+(?:\.\d+)?)(?:\.\d+)?.*$/", exec($exe . " --version"), $version);
-
                        // Starting in 8.2, -n and -t are orthagonal, so we now schema qualify
                        // the table name in the -t argument and quote both identifiers
                        if ( ((float) $version[1]) >= 8.2 ) {
index 9bf6d322d7a509230307c633a21c60139b1ae831..3c558b37efc2c2fad4cc6d3223a9dae072167855 100644 (file)
        $lang['strcannotdumponwindows'] = 'Dumping of complex table and schema names on Windows is not supported.';
        $lang['strinvalidserverparam'] = 'Attempt to connect with invalid server parameter, possibly someone is trying to hack your system.'; 
        $lang['strnoserversupplied'] = 'No server supplied!';
+       $lang['strbadpgdumppath'] = 'Export error: Failed to execute pg_dump (given path in your conf/config.inc.php : %s). Please, fix this path in your configuration and relog.';
+       $lang['strbadpgdumpallpath'] = 'Export error: Failed to execute pg_dumpall (given path in your conf/config.inc.php : %s). Please, fix this path in your configuration and relog.';
 
        // Tables
        $lang['strtable'] = 'Table';
index d5fdab4bc69a4a8ed65ae2e7c4400c90cde15f4f..77e8f30d41a868424ad7ed3f342f783aaa22d8ea 100644 (file)
        $lang['strcannotdumponwindows'] = 'Dumping of complex table and schema names on Windows is not supported.';
        $lang['strinvalidserverparam'] = 'Attempt to connect with invalid server parameter, possibly someone is trying to hack your system.'; 
        $lang['strnoserversupplied'] = 'No server supplied!';
+       $lang['strbadpgdumppath'] = 'Export error: Failed to execute pg_dump (given path in your conf/config.inc.php : %s). Please, fix this path in your configuration and relog.';
+       $lang['strbadpgdumpallpath'] = 'Export error: Failed to execute pg_dumpall (given path in your conf/config.inc.php : %s). Please, fix this path in your configuration and relog.';
 
        // Tables
        $lang['strtable'] = 'Table';