Improve database description. Hide group and user admin from gumby users. Add Accou...
authorchriskl <chriskl>
Thu, 8 May 2003 14:15:55 +0000 (14:15 +0000)
committerchriskl <chriskl>
Thu, 8 May 2003 14:15:55 +0000 (14:15 +0000)
classes/Misc.php
classes/Reports.php
classes/database/Postgres.php
conf/config.inc.php-dist
lang/english.php
lang/recoded/english.php
libraries/lib.inc.php
topbar.php
users.php

index ba5c21967fbb630ce00062d75f9c65d1522d47ce..4ecd0d9d43605cbbd54fac253b716fcfbf436dca 100644 (file)
@@ -2,7 +2,7 @@
        /**
         * Class to hold various commonly used functions
         *
-        * $Id: Misc.php,v 1.30 2003/05/07 06:29:54 chriskl Exp $
+        * $Id: Misc.php,v 1.31 2003/05/08 14:15:57 chriskl Exp $
         */
         
        class Misc {
@@ -82,8 +82,9 @@
                function &getDatabaseAccessor($host, $port, $database, $username, $password) {
                        global $conf;
                        
+                       $desc = null;
                        $type = $this->getDriver($host, $port, $username, $password, 
-                                                        $conf['servers'][$_SESSION['webdbServerID']]['type']);
+                                                        $conf['servers'][$_SESSION['webdbServerID']]['type'], $desc);
                        include_once('classes/database/' . $type . '.php');
                        $localData = new $type( $host,
                                                                                        $port,
                 * @param $user The username to use
                 * @param $password The password to use
                 * @param $type The ADODB database type name.
+                * @param (return-by-ref) $description A description of the database and version
                 * @return The class name of the driver eg. Postgres73
                 * @return -1 Database functions not compiled in
                 * @return -2 Invalid database type
                 * @return -3 Database-specific failure
                 */
-               function getDriver($host, $port, $user, $password, $type) {
+               function getDriver($host, $port, $user, $password, $type, &$description) {
                        switch ($type) {
                                case 'postgres7':
                                        // Check functions are loaded
                                        if (!isset($params[1])) return -3;
 
                                        $version = $params[1]; // eg. 7.3.2
+                                       $description = "PostgreSQL {$params[1]}";
 
                                        if (strpos($version, '7.4') === 0)
                                                return 'Postgres74';
                                        break;
                                case 'mysql':
                                        // Check functions are loaded
+                                       $description = 'MySQL';
                                        if (!function_exists('mysql_connect')) return -1;
                                        return 'MySQL';
                                        break;
index f7cb1189eef03e879525f3926c484fcea3a42406..c024e629f700a6be37e88cefb25bf37302abb915 100644 (file)
@@ -4,7 +4,7 @@
         * the functions provided by the database driver exclusively, and hence
         * will work with any database without modification.
         *
-        * $Id: Reports.php,v 1.5 2003/04/21 06:36:24 chriskl Exp $
+        * $Id: Reports.php,v 1.6 2003/05/08 14:15:57 chriskl Exp $
         */
 
        class Reports {
                 * @return A recordset
                 */
                function &getReports() {
+                       global $conf;
+                       // Filter for owned reports if necessary
+                       if ($conf['owned_reports_only']) {
+                               $filter['created_by'] = $_SESSION['webdbUsername'];
+                       }
+                       else $filter = array();
+
                        $sql = $this->driver->getSelectSQL('ppa_reports',
                                array('report_id', 'report_name', 'db_name', 'date_created', 'created_by', 'descr', 'report_sql'),
-                               array(), array(), array('report_name'));
+                               $filter, array(), array('report_name'));
 
                        return $this->driver->selectSet($sql);
                }
index 20c50a5dd6e2e1646922bb92655c9b778f59e963..71a9fac7eac21a6051273708a062522c8c16a568 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.96 2003/05/07 15:00:56 chriskl Exp $
+ * $Id: Postgres.php,v 1.97 2003/05/08 14:15:57 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -1475,6 +1475,21 @@ class Postgres extends BaseDB {
                return $this->selectSet($sql);
        }
        
+       /**
+        * Determines whether or not a user is a super user
+        * @param $username The username of the user
+        * @return True if is a super user, false otherwise
+        */
+       function isSuperUser($username) {
+               $this->clean($username);
+               
+               $sql = "SELECT usesuper FROM pg_user WHERE usename='{$username}'";
+               
+               $usesuper = $this->selectField($sql, 'usesuper');
+               if ($usesuper == -1) return false;
+               else return $usesuper == 't';
+       }       
+       
        /**
         * Creates a new user
         * @param $username The username of the user to create
index 1ab039e13227c5e6adedb79317ee9f9d71fb44f3..c6da4c446fbdbca13d7e223eb7453acaa09f38b7 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.18 2003/05/08 02:03:53 chriskl Exp $
+        * $Id: config.inc.php-dist,v 1.19 2003/05/08 14:15:58 chriskl Exp $
         */
 
        // An example server.  Create as many of these as you wish,
        // (eg. Run 'SELECT * FROM pg_database' in the SQL area.)
        $conf['owned_only'] = false;
 
+       // Display reports feature?
+       $conf['show_reports'] = true;
+
+       // Only show owned reports?
+       // Note: This does not prevent people from accessing other reports by other
+       // means.
+       $conf['owned_reports_only'] = false;
+
        // Width of the left frame in pixels (object browser)
        $conf['left_width'] = 200;
        
index f524ccd05d79ddef2299ac424b7532b25c5374de..1bb113179c61599c047ac0cb946485825f78bca2 100755 (executable)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.74 2003/04/30 06:35:42 chriskl Exp $
+        * $Id: english.php,v 1.75 2003/05/08 14:15:58 chriskl Exp $
         */
 
        // Language and character set
        $lang['strconfdropuser'] = 'Are you sure you want to drop the user "%s"?';
        $lang['struserdropped'] = 'User dropped.';
        $lang['struserdroppedbad'] = 'Failed to drop user.';
+       $lang['straccount'] = 'Account';
+       $lang['strchangepassword'] = 'Change Password';
                
        // Groups
        $lang['strgroupadmin'] = 'Group Admin';
index f13ffc46b6e4a5baf9e1a25fed03f46290d1b479..6a14774a72e9f33c0d0c6df19942b3cd2f970b6f 100644 (file)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.26 2003/04/30 06:35:42 chriskl Exp $
+        * $Id: english.php,v 1.27 2003/05/08 14:15:59 chriskl Exp $
         */
 
        // Language and character set
        $lang['strconfdropuser'] = 'Are you sure you want to drop the user &quot;%s&quot;?';
        $lang['struserdropped'] = 'User dropped.';
        $lang['struserdroppedbad'] = 'Failed to drop user.';
+       $lang['straccount'] = 'Account';
+       $lang['strchangepassword'] = 'Change Password';
                
        // Groups
        $lang['strgroupadmin'] = 'Group Admin';
index 24b008e3252c743e18f2ef46bf1efb1c6f97981c..e4f232be77e8f127eb43c51c28a74fe035629524 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Function library read in upon startup
         *
-        * $Id: lib.inc.php,v 1.43 2003/05/07 01:20:02 chriskl Exp $
+        * $Id: lib.inc.php,v 1.44 2003/05/08 14:15:59 chriskl Exp $
         */
        
        // Set error reporting level to max
                                                        $conf['servers'][$_SESSION['webdbServerID']]['port'],
                                                        $_SESSION['webdbUsername'],
                                                        $_SESSION['webdbPassword'],
-                                                       $conf['servers'][$_SESSION['webdbServerID']]['type']);
+                                                       $conf['servers'][$_SESSION['webdbServerID']]['type'],
+                                                       $conf['description']);
                        // Check return type
                        if ($_type == -1) {
                                echo $lang['strnotloaded'];
index 83e4509360938cf51a3a9efd99679b3ea7d09f8d..1b76b0b8df62be0232c9f18af0181d1498d4d7e9 100755 (executable)
@@ -3,7 +3,7 @@
        /**
         * Top menu for phpPgAdmin
         *
-        * $Id: topbar.php,v 1.9 2003/04/21 06:36:23 chriskl Exp $
+        * $Id: topbar.php,v 1.10 2003/05/08 14:15:55 chriskl Exp $
         */
 
        // Include application functions
@@ -15,8 +15,9 @@
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
                <td width="211" rowspan="2"><img src="images/themes/<?php echo $conf['theme'] ?>/title.gif" width="211" height="50" alt="<?php echo htmlspecialchars($appName) ?>" /></td>
-               <td width="69%">
-               <?php echo sprintf($lang['strtopbar'], htmlspecialchars($conf['servers'][$_SESSION['webdbServerID']]['type']),
+               <td width="5" rowspan="2">&nbsp;</td>
+               <td>
+               <?php echo sprintf($lang['strtopbar'], htmlspecialchars($conf['description']),
                        htmlspecialchars($conf['servers'][$_SESSION['webdbServerID']]['host']),
                        htmlspecialchars($conf['servers'][$_SESSION['webdbServerID']]['port']),
                        htmlspecialchars($_SESSION['webdbUsername']), 
        </tr>
        <tr>
                <td>
+<?php
+       // For superuser, show user and group admin.  For normal user, show change password.
+       if ($data->isSuperUser($_SESSION['webdbUsername'])) :
+?>
                        <a class="toplink" href="users.php" target="detail"><?php echo $lang['struseradmin'] ?></a> | 
                        <a class="toplink" href="groups.php" target="detail"><?php echo $lang['strgroupadmin'] ?></a> |
+<?php
+       else :
+?>
+                       <a class="toplink" href="users.php?action=account" target="detail"><?php echo $lang['straccount'] ?></a> |
+<?php
+       endif;
+?>
+<?php if ($conf['show_reports']) : ?>
                        <a class="toplink" href="reports.php" target="detail"><?php echo $lang['strreports'] ?></a> |
+<?php endif; ?>
                        <a class="toplink" href="logout.php" target="_parent"><?php echo $lang['strlogout'] ?></a>
                </td>
        </tr>
index 6653e05ec4907b7b16088844ebe30c90ce1ab942..067b3d8452e815b0cf832fd8c3196fe10931f28e 100644 (file)
--- a/users.php
+++ b/users.php
@@ -3,7 +3,7 @@
        /**
         * Manage users in a database cluster
         *
-        * $Id: users.php,v 1.8 2003/04/19 09:25:22 chriskl Exp $
+        * $Id: users.php,v 1.9 2003/05/08 14:15:56 chriskl Exp $
         */
 
        // Include application functions
        $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
        if (!isset($msg)) $msg = '';
        $PHP_SELF = $_SERVER['PHP_SELF'];
-
+       
+       /**
+        * If a user is not a superuser, then we have an 'account management' page
+        * where they can change their password, etc.  We don't prevent them from
+        * messing with the URL to gain access to other user admin stuff, because
+        * the PostgreSQL permissions will prevent them changing anything anyway.
+        */
+       function doAccount($msg = '') {
+               global $data, $misc;
+               global $PHP_SELF, $lang;
+       
+               echo "<h2>{$lang['strusers']}: ", htmlspecialchars($_SESSION['webdbUsername']), ": {$lang['straccount']}</h2>\n";
+               $misc->printMsg($msg);
+               
+               $userdata = &$data->getUser($_SESSION['webdbUsername']);
+               
+               if ($userdata->recordCount() > 0) {
+                       echo "<table>\n";
+                       echo "<tr><th class=\"data\">{$lang['strusername']}</th><th class=\"data\">{$lang['strsuper']}</th><th class=\"data\">{$lang['strcreatedb']}</th><th class=\"data\">{$lang['strexpires']}</th></tr>\n";
+                       echo "<tr><td class=\"data1\">", htmlspecialchars($userdata->f[$data->uFields['uname']]), "</td>\n";
+                       echo "<td class=\"data1\">", $userdata->f[$data->uFields['usuper']], "</td>\n";
+                       echo "<td class=\"data1\">", $userdata->f[$data->uFields['ucreatedb']], "</td>\n";
+                       echo "<td class=\"data1\">", htmlspecialchars($userdata->f[$data->uFields['uexpires']]), "</td></tr>\n";
+                       echo "</table>\n";
+               }
+               else echo "<p>{$lang['strnodata']}</p>\n";
+               
+               echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=confchangepassword\">{$lang['strchangepassword']}</a></p>\n";
+       }
+       
        /** 
         * Function to save after editing a user
         */
        $misc->printBody();
 
        switch ($action) {
+               case 'account':
+                       doAccount();
+                       break;
                case 'save_create':
                        doSaveCreate();
                        break;