r1112 + initial code for dynamic tabs and triggers
authorDenis Ovsienko <infrastation@yandex.ru>
Mon, 3 Sep 2007 15:10:53 +0000 (15:10 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Mon, 3 Sep 2007 15:10:53 +0000 (15:10 +0000)
inc/init.php
inc/navigation.php
inc/triggers.php [new file with mode: 0644]

index f1a037b7b8868211d27b30d9d429c2905c8ba3e9..5aeba48b7a8fb2796196e5f134a89e1f0084d06a 100644 (file)
@@ -79,5 +79,6 @@ require_once 'inc/navigation.php';
 require_once 'inc/pagetitles.php';
 require_once 'inc/pagehandlers.php';
 require_once 'inc/ophandlers.php';
 require_once 'inc/pagetitles.php';
 require_once 'inc/pagehandlers.php';
 require_once 'inc/ophandlers.php';
+require_once 'inc/triggers.php';
 
 ?>
 
 ?>
index cb6282410b6f3e5278fed75d76e4b255c5e3ccb0..31fcf09df63282a261677883040f6f6c8deae586 100644 (file)
@@ -52,6 +52,8 @@ $tab['object']['rackspace'] = 'Rackspace';
 $tab['object']['ports'] = 'Ports';
 $tab['object']['network'] = 'IPv4';
 $tab['object']['portfwrd'] = 'Port Forwarding';
 $tab['object']['ports'] = 'Ports';
 $tab['object']['network'] = 'IPv4';
 $tab['object']['portfwrd'] = 'Port Forwarding';
+$tab['object']['switchvlans'] = 'VLANs';
+$trigger['object']['switchvlans'] = 'trigger_switchvlans';
 $ophandler['object']['ports']['addPort'] = 'addPortForObject';
 $ophandler['object']['ports']['delPort'] = 'delPortFromObject';
 $ophandler['object']['ports']['editPort'] = 'editPortForObject';
 $ophandler['object']['ports']['addPort'] = 'addPortForObject';
 $ophandler['object']['ports']['delPort'] = 'delPortFromObject';
 $ophandler['object']['ports']['editPort'] = 'editPortForObject';
@@ -67,6 +69,7 @@ $ophandler['object']['edit']['upd'] = 'updateAttrValue';
 $ophandler['object']['portfwrd']['forwardPorts'] = 'addPortForwarding';
 $ophandler['object']['portfwrd']['delPortForwarding'] = 'delPortForwarding';
 $ophandler['object']['portfwrd']['updPortForwarding'] = 'updPortForwarding';
 $ophandler['object']['portfwrd']['forwardPorts'] = 'addPortForwarding';
 $ophandler['object']['portfwrd']['delPortForwarding'] = 'delPortForwarding';
 $ophandler['object']['portfwrd']['updPortForwarding'] = 'updPortForwarding';
+$ophandler['object']['switchvlans']['submit'] = 'updateVLANMembership';
 
 $page['ipv4space']['title'] = 'static_title';
 $page['ipv4space']['handler'] = 'handler_ipv4space';
 
 $page['ipv4space']['title'] = 'static_title';
 $page['ipv4space']['handler'] = 'handler_ipv4space';
@@ -227,7 +230,7 @@ function getTitle ($pageno, $tabno)
 
 function showTabs ($pageno, $tabno)
 {
 
 function showTabs ($pageno, $tabno)
 {
-       global $tab, $root, $page, $remote_username;
+       global $tab, $root, $page, $remote_username, $trigger;
        if (!isset ($tab[$pageno]['default']))
                return;
        echo "<td><div class=greynavbar><ul id=foldertab style='margin-bottom: 0px; padding-top: 10px;'>";
        if (!isset ($tab[$pageno]['default']))
                return;
        echo "<td><div class=greynavbar><ul id=foldertab style='margin-bottom: 0px; padding-top: 10px;'>";
@@ -236,6 +239,13 @@ function showTabs ($pageno, $tabno)
                // Hide forbidden tabs.
                if (authorized ($remote_username, $pageno, $tabidx) == FALSE)
                        continue;
                // Hide forbidden tabs.
                if (authorized ($remote_username, $pageno, $tabidx) == FALSE)
                        continue;
+               // Dynamic tabs should only be shown in certain cases (trigger exists and returns true).
+               if
+               (
+                       isset ($trigger[$pageno][$tabidx]) &&
+                       $trigger[$pageno][$tabidx] () != TRUE
+               )
+                       continue;
                echo '<li><a' . (($tabidx == $tabno) ? ' class=current' : '');
                echo " href='${root}?page=${pageno}&tab=${tabidx}";
                if (isset ($page[$pageno]['bypass']) and isset ($_REQUEST[$page[$pageno]['bypass']]))
                echo '<li><a' . (($tabidx == $tabno) ? ' class=current' : '');
                echo " href='${root}?page=${pageno}&tab=${tabidx}";
                if (isset ($page[$pageno]['bypass']) and isset ($_REQUEST[$page[$pageno]['bypass']]))
diff --git a/inc/triggers.php b/inc/triggers.php
new file mode 100644 (file)
index 0000000..b554814
--- /dev/null
@@ -0,0 +1,38 @@
+<?
+/*
+*
+*  This file is a library of tab triggers for RackTables.
+*
+*/
+
+// Triggers may be optionally referred by some tabs of a page.
+// In case they are defined, the given tab is only displayed if
+// the trigger returned true. In certain cases, a key is necessary
+// to decide (the 'bypass' hint of a page), and in some cases,
+// other data can be used.
+
+// This trigger filters out everything except switches with known-good
+// software.
+// FIXME: That's a bit of hardcoding at the moment, but
+// let's thinks about fixing it later.
+function trigger_switchvlans ()
+{
+       assertUIntArg ('object_id');
+       $object_id = $_REQUEST['object_id'];
+       $object = getObjectInfo ($object_id);
+       if ($object['objtype_id'] != 8)
+               return FALSE;
+       $values = getAttrValues ($object_id);
+       foreach ($values as $record)
+       {
+               if ($record['id'] != 4)
+                       continue;
+               if (in_array ($record['key'], array (1, 20, 21)))
+                       return TRUE;
+               else
+                       return FALSE;
+       }
+       return FALSE;
+}
+
+?>