add ability to logicaly group servers under custom top nodes in the browser tree
authorJehan-Guillaume (ioguix) de Rorthais <ioguix@free.fr>
Sat, 13 Mar 2010 00:47:46 +0000 (01:47 +0100)
committerGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Sat, 13 Mar 2010 00:49:44 +0000 (01:49 +0100)
HISTORY
browser.php
classes/Misc.php
conf/config.inc.php-dist
lang/english.php
lang/recoded/english.php
servers.php

diff --git a/HISTORY b/HISTORY
index d6e6be8bf623940d5114e3bcad495b29238930e5..5c7324332ecdc0f609070a2e37a45c6075ffbcab 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -17,6 +17,7 @@ Features
 * Allow users to specify a template database at database creation time
 * Support killing processes  
 * Add ability to create indexes concurrently
+* Allow user to logicaly group their server under custom named node in the browser tree
 
 Bugs
 * Fix problems with query tracking on overly long queries
index 563d7fa9edd3ca878b998f0ec57e752de33b2a6b..6b1e5e1efe0aea6a23290918c62025d2439e7d8a 100644 (file)
        $_no_db_connection = true;
        include_once('./libraries/lib.inc.php');
        
+       if (isset($conf['srv_groups'])) {
+               $treeaction = 'groupstree';
+       }
+       else {
+               $treeaction = 'tree';
+       }
+       
        // Output header
        $misc->printHeader('', '
                <script src="xloadtree/xtree2.js" type="text/javascript"></script>
@@ -64,7 +71,7 @@ WebFXTreeAbstractNode.prototype._ondblclick = function(e){
        return false;
 };
 */
-var tree = new WebFXLoadTree("<?php echo $lang['strservers']; ?>", "servers.php?action=tree", "servers.php");
+var tree = new WebFXLoadTree("<?php echo $lang['strservers']; ?>", "servers.php?action=<?php echo $treeaction ?>", "servers.php");
 
 tree.write();
 tree.setExpanded(true);
index 59f9e4a16a2935eeee250cb39334d96522fc3144..69688881daa14670fcd4c18b59ddda180cd50ed6 100644 (file)
                                return escapeshellcmd($str);
                }
 
+               /**
+                * Get list of servers' groups if existing in the conf
+                * @return a recordset of servers' groups
+                */
+               function getServersGroups() {
+                       global $conf, $lang;
+                       $grps = array();
+                       
+                       foreach ($conf['srv_groups'] as $i => $group) {
+                               $grps[$i] = array(
+                                       'id' => $i,
+                                       'desc' => $group['desc'],
+                               );                              
+                       }
+                       
+                       $grps['all'] = array(
+                               'id' => 'all', 
+                               'desc' => $lang['strallservers'],
+                       );
+
+                       include_once('./classes/ArrayRecordSet.php');
+                       return new ArrayRecordSet($grps);
+               }
+               
+
                /**
                 * Get list of servers
                 * @param $recordset return as RecordSet suitable for printTable if true,
                 *                   otherwise just return an array.
+                * @param $group a group name to filter the returned servers using $conf[srv_groups]
                 */
-               function getServers($recordset = false) {
+               function getServers($recordset = false, $group = false) {
                        global $conf;
-
+                       
                        $srvs = isset($_SESSION['webdbLogin']) && is_array($_SESSION['webdbLogin']) ? $_SESSION['webdbLogin'] : array();
-
+                       
+                       if ($group !== false) {
+                               if ($group !== 'all')
+                                       $group = array_fill_keys(explode(',', $conf['srv_groups'][$group]['servers']), 1);
+                       } 
+                       
                        foreach($conf['servers'] as $idx => $info) {
-                               $server_id = $info['host'].':'.$info['port'].':'.$info['sslmode'];
-
-                               if (!isset($srvs[$server_id])) {
-                                       $srvs[$server_id] = $info;
+                               if (($group === false) 
+                                       or (isset($group[$idx]))
+                                       or ($group === 'all')
+                               ) {
+                                       $server_id = $info['host'].':'.$info['port'].':'.$info['sslmode'];
+
+                                       if (!isset($srvs[$server_id])) {
+                                               $srvs[$server_id] = $info;
+                                       }
+                                       $srvs[$server_id]['id'] = $server_id;
                                }
-                               $srvs[$server_id]['id'] = $server_id;
                        }
 
                        function _cmp_desc($a, $b) {
index 01d3e1d63db3ca7c051cc440a79728c7b54f2c40..65a5b2472d126d3aa6db96a0ecee8a17715cdb44 100644 (file)
        //$conf['servers'][1]['pg_dumpall_path'] = 'C:\\Program Files\\PostgreSQL\\8.0\\bin\\pg_dumpall.exe';
        //$conf['servers'][1]['slony_support'] = false;
        //$conf['servers'][1]['slony_sql'] = 'C:\\Program Files\\PostgreSQL\\8.0\\share';
+       
+       
+       // Example of groups definition.
+       // Groups allow administrators to logicaly group servers together under group nodes in the left browser tree
+       //
+       // The group '0' description
+       //$conf['srv_groups'][0]['desc'] = 'group one';
+       //
+       // Add here servers indexes belonging to the group '0' seperated by comma
+       //$conf['srv_groups'][0]['servers'] = '0,1,2'; 
+       //
+       // A server can belong to multi groups
+       //$conf['srv_groups'][1]['desc'] = 'group two';
+       //$conf['srv_groups'][1]['servers'] = '3,1';
+       
 
        // Default language. E.g.: 'english', 'polish', etc.  See lang/ directory
        // for all possibilities. If you specify 'auto' (the default) it will use 
index cceb8bd3aa6a780fbd85a20e53505d7b6cf4fab3..2b48c931156dd43261f1d96088329aea56221d6d 100644 (file)
@@ -30,6 +30,8 @@
        $lang['strlogindisallowed'] = 'Login disallowed for security reasons.';
        $lang['strserver'] = 'Server';
        $lang['strservers'] = 'Servers';
+       $lang['strgroupservers'] = 'Servers in group "%s"';
+       $lang['strallservers'] = 'All servers';
        $lang['strintroduction'] = 'Introduction';
        $lang['strhost'] = 'Host';
        $lang['strport'] = 'Port';
index eeb70025bd945b8103cfcc577fda9feb87f77eb4..fdb5ae41e89fc457d29c7ae391e419a771f888a7 100644 (file)
@@ -30,6 +30,8 @@
        $lang['strlogindisallowed'] = 'Login disallowed for security reasons.';
        $lang['strserver'] = 'Server';
        $lang['strservers'] = 'Servers';
+       $lang['strgroupservers'] = 'Servers in group &quot;%s&quot;';
+       $lang['strallservers'] = 'All servers';
        $lang['strintroduction'] = 'Introduction';
        $lang['strhost'] = 'Host';
        $lang['strport'] = 'Port';
index 7aba25923e0aa8c8dec4f9a4ce16a65b2b018f9e..7790085dba18d23be8e718ca654c203257f0e1fd 100644 (file)
@@ -33,7 +33,9 @@
                $misc->printTabs('root','servers');
                $misc->printMsg($msg);
                
-               $servers = $misc->getServers(true);
+               $group = isset($_GET['group']) ? $_GET['group'] : false;
+               
+               $servers = $misc->getServers(true, $group);
                
                function svPre(&$rowdata, $actions) {
                        $actions['logout']['disable'] = empty($rowdata->fields['username']);
                        ),
                );
                
+               if (($group !== false) and isset($conf['srv_groups'][$group])) {
+                       printf("<h2>{$lang['strgroupservers']}</h2>", htmlentities($conf['srv_groups'][$group]['desc']));
+               }
+               
                $misc->printTable($servers, $columns, $actions, $lang['strnoobjects'], 'svPre');
+               
+               if (isset($conf['srv_groups'])) {
+                       echo "<br /><ul class=\"navlink\">\n";
+                       echo "\t<li><a href=\"servers.php\">{$lang['strallservers']}</a></li>\n";
+                       foreach ($conf['srv_groups'] as $id => $grp) {
+                               echo "\t<li><a href=\"servers.php?group={$id}\">", htmlentities($grp['desc']), "</a></li>\n";
+                       }
+                       echo "</ul>\n";                 
+               }
        }
        
-       function doTree() {
+       function doTree($group = false) {
                global $misc;
                
-               $servers = $misc->getServers(true);
+               $servers = $misc->getServers(true, $group);
                
                $reqvars = $misc->getRequestVars('server');
                
                exit;
        }
        
-       if ($action == 'tree') doTree();
+       function doGroupsTree() {
+               global $misc;
+               
+               $groups = $misc->getServersGroups();
+               
+               $attrs = array(
+                       'text'   => field('desc'),
+                       'icon'   => 'Servers',                  
+                       'action' => url('servers.php',
+                               array(
+                                       'group' => field('id')
+                               )
+                       ),
+                       'branch' => url('servers.php',
+                               array(
+                                       'action' => 'tree',
+                                       'group' => field('id')
+                               )
+                       )
+               );
+               
+               $misc->printTreeXML($groups, $attrs);
+               exit;
+       }
+       
+       if ($action == 'tree') {
+               if (isset($_GET['group'])) doTree($_GET['group']);
+               else doTree(false);
+       }
+
+       if ($action == 'groupstree') doGroupsTree();
        
        $misc->printHeader($lang['strservers']);
        $misc->printBody();
                case 'logout':
                        doLogout();
                        break;
-               case 'tree':
                default:
                        doDefault($msg);
                        break;