database dump using pg_dump feature. please test. check new stuff in config.inc...
authorchriskl <chriskl>
Sat, 13 Dec 2003 11:04:03 +0000 (11:04 +0000)
committerchriskl <chriskl>
Sat, 13 Dec 2003 11:04:03 +0000 (11:04 +0000)
HISTORY
INSTALL
TODO
classes/Misc.php
conf/config.inc.php-dist
database.php
dbexport.php [new file with mode: 0644]
libraries/lib.inc.php

diff --git a/HISTORY b/HISTORY
index fec5f14bb0238e1363628b6276f3bfcdbc919bcc..ea818a7c515e080daed0762d60780675778962c2 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -5,6 +5,7 @@ Version 3.3-dev
 ---------------
 
 Features
+* Database dump feature, which uses pg_dump
 * Large speed improvements by reducing number of database
   connections and using external style sheet.
 
diff --git a/INSTALL b/INSTALL
index 102fb5f8fd14f1a27d35b77854ef2c9a22dfd930..21ba8485bb1d8f5d12e782bdcb6cf42284b751bc 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -18,16 +18,29 @@ phpPgAdmin Installation Guide
    the 'sql' subdirectory and view the SQL script for your database.  It
    will contain instructions on how to set up the reports database.
 
-4. Browse to the phpPgAdmin installation using a web browser.  You might
+4. If you run your PHP installation in safe mode, in order that the database
+   dump feature can work correctly, you need to set the 'safe_mode_allowed_env_vars'
+   php.ini variable to include the PGPASSWORD environmental variable.
+   
+   Also, you will need to ensure that your 'pg_dump' and 'pg_dumpall' utilities
+   are executable by the PHP process.
+
+5. Browse to the phpPgAdmin installation using a web browser.  You might
    need cookies enabled for phpPgAdmin to work.
 
-5. IMPORTANT - SECURITY
+6. IMPORTANT - SECURITY
 
    PostgreSQL by default does not require you to use a password to log in.
-   This means that if you set up phpPgAdmin where the world can see it,
-   someone could just come along and type username 'postgres' or 'pgsql'
-   with no password and easily log in as a super user.
-
    We STRONGLY recomment that you enable md5 passwords for local connections
    in your pg_hba.conf, and set a password for the default superuser account.
 
+   Due to the large number of phpPgAdmin installations that have not set
+   passwords on local connections, there is now a configuration file
+   option called 'extra_login_security', which is TRUE by default.  While
+   this option is enabled, you will be unable to log in to phpPgAdmin as
+   the 'root', 'administrator', 'pgsql' or 'postgres' users and empty passwords
+   will not work.
+   
+   Once you are certain you have properly secured your database server, you
+   can then disable 'extra_login_security' so that you can log in as your
+   database administrator using the administrator password.
diff --git a/TODO b/TODO
index c900ab008d555d814b4dfba16667a45da99950b4..4e74d125c6cf4c0ca2e13b13e3257171c025131f 100644 (file)
--- a/TODO
+++ b/TODO
@@ -32,17 +32,17 @@ Databases
 
 * -Fix failure to drop database even tho seemingly no-one is connected to it (chriskl, bryan)
 * Add alter database for 7.3+
-* Dump database using pg_dump streaming
+* -Dump database using pg_dump streaming (chriskl)
 
 Tables
 ------
 
-* Not using proper attFields array for attribute info (i was being lazy)
+* -Not using proper attFields array for attribute info (i was being lazy) (wontfix)
 * -Rename table
 * -Change table owner
 * -Cluster support
 * Vacuum & analyze (half done)
-* ORDER BY in Select function
+* -ORDER BY in Select function (can do so after the fact now - chriskl)
 * -Unify Select and Browse functions (chriskl)
 
 Views
@@ -135,7 +135,6 @@ Miscellaneous
 * Allow setting/dropping comments for all objects
 * Show owner for all objects
 * Allow changing owner for objects that have this feature (7.4+ generally)
-* pg_dump integration
 * -Config option to disallow pgsql and postgres logins
 * Do David Smith's redireect idea to prevent refresh login resending password
 * Translated FAQ
@@ -168,7 +167,6 @@ Principles
 * Put functions in the highest class possible.  For instance, simple selects 
   should be in BaseDB, whereas something that works for 7.1+ should be in the 
   7.1 class.  This will minimise bugs and duplicated code.
-* We primarily support Postgres, and only secondarily support MySQL, etc.
 * Adhere to current coding standards
 * Avoid using global variables if possible
 
index a133926d7ec6ae26e1c4f34e217053a9aecdb09c..1b95a76b3163f3ef338445a632ec26db7a5c0ec2 100644 (file)
@@ -2,7 +2,7 @@
        /**
         * Class to hold various commonly used functions
         *
-        * $Id: Misc.php,v 1.51 2003/12/13 09:28:46 chriskl Exp $
+        * $Id: Misc.php,v 1.52 2003/12/13 11:04:04 chriskl Exp $
         */
         
        class Misc {
                 * Display the navigation header for tables
                 */
                function printDatabaseNav() {
-                       global $lang, $data;
+                       global $lang, $conf, $data;
 
                        $vars = 'database=' . urlencode($_REQUEST['database']);
 
                        echo "<table class=\"navbar\" border=\"0\" width=\"100%\" cellpadding=\"5\" cellspacing=\"3\"><tr>\n";
                        // Only show schemas if available
                        if ($data->hasSchemas()) {
-                               echo "<td width=\"14%\"><a href=\"database.php?{$vars}\">{$lang['strschemas']}</a></td>\n";
+                               echo "<td width=\"12%\"><a href=\"database.php?{$vars}\">{$lang['strschemas']}</a></td>\n";
                        }
                        // Only show database privs if available
                        if (isset($data->privlist['database'])) {
-                               echo "<td width=\"14%\"><a href=\"privileges.php?{$vars}&amp;type=database&amp;object=", urlencode($_REQUEST['database']), "\">{$lang['strprivileges']}</a></td>\n";
+                               echo "<td width=\"13%\"><a href=\"privileges.php?{$vars}&amp;type=database&amp;object=", urlencode($_REQUEST['database']), "\">{$lang['strprivileges']}</a></td>\n";
+                       }
+                       echo "<td width=\"12%\"><a href=\"database.php?{$vars}&amp;action=sql\">{$lang['strsql']}</a></td>\n";
+                       echo "<td width=\"13%\"><a href=\"database.php?{$vars}&amp;action=find\">{$lang['strfind']}</a></td>\n";
+                       echo "<td width=\"12%\"><a href=\"database.php?{$vars}&amp;action=variables\">{$lang['strvariables']}</a></td>\n";
+                       echo "<td width=\"13%\"><a href=\"database.php?{$vars}&amp;action=processes\">{$lang['strprocesses']}</a></td>\n";
+                       echo "<td width=\"12%\"><a href=\"database.php?{$vars}&amp;action=admin\">{$lang['stradmin']}</a></td>\n";
+                       // Check that database dumps are enabled.  The is_executable function
+                       // check is required as it only appeared in Win32 PHP in version 5.0.0
+                       if ($conf['pg_dump_path'] !== null && $conf['pg_dump_path'] != ''
+                                       && function_exists('is_executable') && is_executable($conf['pg_dump_path'])) {                  
+                               echo "<td width=\"13%\"><a href=\"database.php?{$vars}&amp;action=export\">{$lang['strexport']}</a></td>\n";
                        }
-                       echo "<td width=\"14%\"><a href=\"database.php?{$vars}&amp;action=sql\">{$lang['strsql']}</a></td>\n";
-                       echo "<td width=\"14%\"><a href=\"database.php?{$vars}&amp;action=find\">{$lang['strfind']}</a></td>\n";
-                       echo "<td width=\"14%\"><a href=\"database.php?{$vars}&amp;action=variables\">{$lang['strvariables']}</a></td>\n";
-                       echo "<td width=\"14%\"><a href=\"database.php?{$vars}&amp;action=processes\">{$lang['strprocesses']}</a></td>\n";
-                       echo "<td width=\"14%\"><a href=\"database.php?{$vars}&amp;action=admin\">{$lang['stradmin']}</a></td>\n";
                        echo "</tr></table>\n";
                }
 
index 45d583f8601850c72beabf1c59849770da370ff4..85ec55f86a954c4c56c61361c88adaf8d55584b1 100644 (file)
@@ -4,7 +4,7 @@
         * Central phpPgAdmin configuration.  As a user you may modify the
         * settings here for your particular configuration.
         *
-        * $Id: config.inc.php-dist,v 1.29 2003/11/14 09:22:10 chriskl Exp $
+        * $Id: config.inc.php-dist,v 1.30 2003/12/13 11:04:04 chriskl Exp $
         */
 
        // An example server.  Create as many of these as you wish,
        // means.
        $conf['owned_reports_only'] = false;
 
+       // Allow database and cluster dumps?
+       // Note: Set this to the fully qualified path name for your pg_dump and
+       // pg_dumpall utilities.  If you set them to '' or null, then the feature
+       // will be disabled.  Read the INSTALL file for more information.
+       $conf['pg_dump_path'] = '/usr/local/bin/pg_dump';
+       $conf['pg_dumpall_path'] = '/usr/local/bin/pg_dumpall';
+       
        // Minimum length users can set their password to.
        $conf['min_password_length'] = 1;
 
@@ -80,6 +87,6 @@
         * Don't modify anything below this line *
         *****************************************/
 
-       $conf['version'] = 11;
+       $conf['version'] = 12;
 
 ?>
index fd8f60749f874988882c7bd5a4693f240317ec1f..ae734d098bcf1afef222a03b316237c80e645a24 100755 (executable)
@@ -3,7 +3,7 @@
        /**
         * Manage schemas within a database
         *
-        * $Id: database.php,v 1.27 2003/12/13 09:28:46 chriskl Exp $
+        * $Id: database.php,v 1.28 2003/12/13 11:04:04 chriskl Exp $
         */
 
        // Include application functions
                        else echo "<p>{$lang['strnoobjects']}</p>\n";
                }               
        }
+
+       /**
+        * Displays options for database download
+        */
+       function doExport($msg = '') {
+               global $data, $misc;
+               global $PHP_SELF, $lang;
+
+               $misc->printDatabaseNav();
+               echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strexport']}</h2>\n";
+               $misc->printMsg($msg);
+
+               echo "<form action=\"dbexport.php\" method=\"post\">\n";
+               echo "<table>\n";
+               echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\" colspan=\"2\">{$lang['stroptions']}</th></tr>\n";
+               // Data only
+               echo "<tr><th class=\"data left\" rowspan=\"2\">";
+               echo "<input type=\"radio\" name=\"what\" value=\"dataonly\" checked=\"checked\" />{$lang['strdataonly']}</th>\n";
+               echo "<td>{$lang['strformat']}</td>\n";
+               echo "<td><select name=\"d_format\">\n";
+               echo "<option value=\"copy\">COPY</option>\n";
+               echo "<option value=\"sql\">SQL</option>\n";
+               echo "</select>\n</td>\n</tr>\n";
+               echo "<td>{$lang['stroids']}</td><td><input type=\"checkbox\" name=\"d_oids\" /></td>\n</tr>\n";
+               // Structure only
+               echo "<tr><th class=\"data left\"><input type=\"radio\" name=\"what\" value=\"structureonly\" />{$lang['strstructureonly']}</th>\n";
+               echo "<td>{$lang['strdrop']}</td><td><input type=\"checkbox\" name=\"s_clean\" /></td>\n</tr>\n";
+               // Structure and data
+               echo "<tr><th class=\"data left\" rowspan=\"3\">";
+               echo "<input type=\"radio\" name=\"what\" value=\"structureanddata\" />{$lang['strstructureanddata']}</th>\n";
+               echo "<td>{$lang['strformat']}</td>\n";
+               echo "<td><select name=\"sd_format\">\n";
+               echo "<option value=\"copy\">COPY</option>\n";
+               echo "<option value=\"sql\">SQL</option>\n";
+               echo "</select>\n</td>\n</tr>\n";
+               echo "<td>{$lang['strdrop']}</td><td><input type=\"checkbox\" name=\"sd_clean\" /></td>\n</tr>\n";
+               echo "<td>{$lang['stroids']}</td><td><input type=\"checkbox\" name=\"sd_oids\" /></td>\n</tr>\n";
+               echo "</table>\n";
+               
+               echo "<h3>{$lang['stroptions']}</h3>\n";
+               echo "<table>\n";               
+               echo "<tr>\n<th class=\"data left\">{$lang['strdownload']}</th>\n";
+               echo "<td><input type=\"checkbox\" name=\"download\" /></td>\n</tr>\n";
+               echo "</table>\n";
+
+               echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n";
+               echo $misc->form;
+               echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n";
+               echo "</form>\n";
+       }
        
        /**
         * Show the current status of all database variables
                case 'processes':
                        doProcesses();
                        break;
+               case 'export':
+                       doExport();
+                       break;
                default:
                        doDefault();
                        break;
diff --git a/dbexport.php b/dbexport.php
new file mode 100644 (file)
index 0000000..417cbb7
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+       /**
+        * Does an export of a database to the screen or as a download
+        *
+        * $Id: dbexport.php,v 1.1 2003/12/13 11:04:04 chriskl Exp $
+        */
+
+       // Include application functions
+       $_no_output = true;
+       include_once('libraries/lib.inc.php');
+       
+       // Check that database dumps are enabled.  The is_executable function
+       // check is required as it only appeared in Win32 PHP in version 5.0.0
+       if ($conf['pg_dump_path'] !== null && $conf['pg_dump_path'] != ''
+                       && function_exists('is_executable') && is_executable($conf['pg_dump_path'])) {
+
+               // Make it do a download, if necessary
+               if (isset($_REQUEST['download'])) {
+                       header('Content-Type: application/download');
+                       header('Content-Disposition: attachment; filename=dbdump.sql');
+               }
+               else {
+                       header('Content-Type: text/plain');
+               }
+
+               // Set environmental variable for password that pg_dump uses
+               putenv('PGPASSWORD=' . $_SESSION['webdbPassword']);
+
+               // Prepare command line arguments
+               $hostname = $conf['servers'][$_SESSION['webdbServerID']]['host'];
+               $port = $conf['servers'][$_SESSION['webdbServerID']]['port'];
+               $username = escapeshellarg($_SESSION['webdbUsername']);
+               $database = escapeshellarg($_REQUEST['database']);
+
+               // Build command for executing pg_dump
+               $cmd = escapeshellcmd($conf['pg_dump_path']) . " -i -U {$username}";
+               if ($hostname !== null && $hostname != '') {
+                       $cmd .= " -h " . escapeshellarg($hostname);
+               }
+               if ($port !== null && $port != '') {
+                       $cmd .= " -p " . escapeshellarg($port);
+               }
+                               
+               switch ($_REQUEST['what']) {
+                       case 'dataonly':
+                               $cmd .= ' -a';
+                               if ($_REQUEST['d_format'] == 'sql') $cmd .= ' -d';
+                               elseif (isset($_REQUEST['d_oids'])) $cmd .= ' -o';
+                               break;
+                       case 'structureonly':
+                               $cmd .= ' -s';
+                               if (isset($_REQUEST['s_clean'])) $cmd .= ' -c';
+                               break;
+                       case 'structureanddata':
+                               if ($_REQUEST['sd_format'] == 'sql') $cmd .= ' -d';                             
+                               elseif (isset($_REQUEST['sd_oids'])) $cmd .= ' -o';
+                               if (isset($_REQUEST['sd_clean'])) $cmd .= ' -c';
+                               break;
+               }
+               
+               $cmd .= " -U {$username} {$database}";
+
+               // Execute command and return the output to the screen
+               passthru($cmd);
+       }
+
+?>
index 5577b5f2583383237f5e59589f45bbce35338d7f..e95cf3efb3fcaf9a3ce6ce5727a90c140bf37685 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Function library read in upon startup
         *
-        * $Id: lib.inc.php,v 1.69 2003/12/10 16:03:30 chriskl Exp $
+        * $Id: lib.inc.php,v 1.70 2003/12/13 11:04:04 chriskl Exp $
         */
        
        // Set error reporting level to max
@@ -29,7 +29,7 @@
        // Configuration file version.  If this is greater than that in config.inc.php, then
        // the app will refuse to run.  This and $conf['version'] should be incremented whenever
        // backwards incompatible changes are made to config.inc.php-dist.
-       $conf['base_version'] = 11;
+       $conf['base_version'] = 12;
 
        // List of available language files
        $appLangFiles = array(