r4073 minor change in UI for recent change: VST form commit on ENTER and hints on...
[racktables] / index.php
index 2f662c3..50f1a43 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,43 +1,20 @@
 <?php
-
+ob_start();
+try {
+require 'inc/interface.php';
 require 'inc/init.php';
-authorize();
+prepareNavigation();
+// no ctx override is necessary
+fixContext();
+redirectIfNecessary();
+if (!permitted())
+       renderAccessDenied();
+header ('Content-Type: text/html; charset=UTF-8');
+// Only store the tab name after clearance is got. Any failure is unhandleable.
+if (isset ($_REQUEST['tab']) and ! isset ($_SESSION['RTLT'][$pageno]['dont_remember']))
+       $_SESSION['RTLT'][$pageno] = array ('tabname' => $tabno, 'time' => time());
 
-echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
-echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
-echo '<head><title>' . getTitle ($pageno, $tabno) . "</title>\n";
-echo "<link rel=stylesheet type='text/css' href=pi.css />\n";
-echo "<link rel=icon href='" . getFaviconURL() . "' type='image/x-icon' />";
-echo "<style type='text/css'>\n";
-// Print style information
-foreach (array ('F', 'A', 'U', 'T', 'Th', 'Tw', 'Thw') as $statecode)
-{
-       echo "td.state_${statecode} {\n";
-       echo "\ttext-align: center;\n";
-       echo "\tbackground-color: #" . (getConfigVar ('color_' . $statecode)) . ";\n";
-       echo "\tfont: bold 10px Verdana, sans-serif;\n";
-       echo "}\n\n";
-}
 ?>
-.validation-error {
-       border:1px solid red;
-}
-
-.validation-success {
-       border:1px solid green;
-}
-       </style>
-       <script language='javascript' type='text/javascript' src='live_validation.js'></script>
-       <script type="text/javascript">
-       function init() {
-               document.add_new_range.range.setAttribute('match', "^\\d\\d?\\d?\\.\\d\\d?\\d?\\.\\d\\d?\\d?\\.\\d\\d?\\d?\\/\\d\\d?$");
-
-               Validate.init();
-       }
-       window.onload=init;
-       </script>
-       </head>
-<body>
  <table border=0 cellpadding=0 cellspacing=0 width='100%' height='100%' class=maintable>
  <tr class=mainheader>
   <td colspan=2>
@@ -78,22 +55,51 @@ if (isset ($tabhandler[$pageno][$tabno]))
                        case 'uint':
                                assertUIntArg ($page[$pageno]['bypass']);
                                break;
-                       default:
-                               showError ("Dispatching error for bypass parameter");
+                       case 'uint0':
+                               assertUIntArg ($page[$pageno]['bypass'], TRUE);
+                               break;
+                       case 'inet4':
+                               assertIPv4Arg ($page[$pageno]['bypass']);
                                break;
+                       case 'string':
+                               assertStringArg ($page[$pageno]['bypass']);
+                               break;
+                       default:
+                               throw new RackTablesError ('Dispatching error for bypass parameter', RackTablesError::INTERNAL);
                }
-               $tabhandler[$pageno][$tabno] ($_REQUEST[$page[$pageno]['bypass']]);
+               showMessageOrError();
+               call_user_func ($tabhandler[$pageno][$tabno], $_REQUEST[$page[$pageno]['bypass']]);
        }
        else
-               $tabhandler[$pageno][$tabno] ();
+       {
+               showMessageOrError();
+               call_user_func ($tabhandler[$pageno][$tabno]);
+       }
 }
 elseif (isset ($page[$pageno]['handler']))
+{
+       showMessageOrError();
        $page[$pageno]['handler'] ($tabno);
+}
 else
-       showError ("Failed to find handler for page '${pageno}', tab '${tabno}'");
+       throw new RackTablesError ("Failed to find handler for page '${pageno}', tab '${tabno}'", RackTablesError::INTERNAL);
 ?>
        </td>
        </tr>
        </table>
-</body>
-</html>
+<?php
+       $body = ob_get_clean();
+       ob_start();
+       echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
+       echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
+       echo '<head><title>' . getTitle ($pageno) . "</title>\n";
+       printPageHeaders();
+       echo "</head>\n";
+       echo "<body>\n$body</body>\n";
+       echo '</html>';
+       ob_flush();
+} catch (Exception $e) {
+       ob_end_clean();
+       printException($e);
+}
+