r4178 bugfix: PHP warnings were appearing before rackspace on SLB object page, defaul...
[racktables] / index.php
index 711e1e2..86ab3dd 100644 (file)
--- a/index.php
+++ b/index.php
 <?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;
+// call the main handler - page or tab handler.
+// catch exception and show its error message instead of page/tab content
+try {
+if (isset ($tabhandler[$pageno][$tabno]))
+       call_user_func ($tabhandler[$pageno][$tabno], getBypassValue());
+elseif (isset ($page[$pageno]['handler']))
+       $page[$pageno]['handler'] ($tabno);
+else
+       showError ("Failed to find handler for page '${pageno}', tab '${tabno}'");
+$content = ob_get_clean();
+} catch (Exception $e) {
+       ob_clean();
+       $content = '';
+       showError ("Unhandled exception: " . $e->getMessage());
 }
-       </style>
-       <script language='javascript' type='text/javascript' src='js/live_validation.js'></script>
-       <script language='javascript' type='text/javascript' src='js/Resize.js'></script>
-       <script language='javascript' type='text/javascript' src='js/collapsible_textareas.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>
+ob_start();
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head><title><?php echo getTitle ($pageno); ?></title>
+<?php printPageHeaders(); ?>
+</head>
 <body>
- <table border=0 cellpadding=0 cellspacing=0 width='100%' height='100%' class=maintable>
- <tr class=mainheader>
-  <td colspan=2>
-   <table width='100%' cellspacing=0 cellpadding=2 border=0>
+<table border=0 cellpadding=0 cellspacing=0 width="100%" height="100%" class="maintable">
+ <tr class="mainheader"><td>
+   <table width="100%" cellspacing="0" cellpadding="2" border="0">
    <tr>
-    <td valign=top><a href='http://racktables.org/'><?php printImageHREF ('logo'); ?></a></td>
+    <td valign=top><a href="http://racktables.org/"><?php printImageHREF ('logo'); ?></a></td>
     <td valign=top><div class=greeting><?php printGreeting(); ?></div></td>
    </tr>
    </table>
-  </td>
- </tr>
-
- <tr>
-  <td class="menubar" colspan=2>
-   <table border="0" width="100%" cellpadding="3" cellspacing="0">
-   <tr>
-<?php showPathAndSearch ($pageno); ?>
-   </tr>
-   </table>
-  </td>
- </tr>
-
-       <tr>
-<?php
-       showTabs ($pageno, $tabno);
-?>
-       </tr>
-
- <tr>
-  <td colspan=2>
+ </td></tr>
+ <tr><td class="menubar">
+  <table border="0" width="100%" cellpadding="3" cellspacing="0">
+  <tr><?php showPathAndSearch ($pageno); ?></tr>
+  </table>
+ </td></tr>
+ <tr><td><?php showTabs ($pageno, $tabno); ?></td></tr>
+ <tr><td><?php showMessageOrError(); ?></td></tr>
+ <tr><td><?php echo $content; ?></td></tr>
+</table>
+</body>
+</html>
 <?php
-if (isset ($tabhandler[$pageno][$tabno]))
-{
-       if (isset ($page[$pageno]['bypass']) && isset ($page[$pageno]['bypass_type']))
-       {
-               switch ($page[$pageno]['bypass_type'])
-               {
-                       case 'uint':
-                               assertUIntArg ($page[$pageno]['bypass']);
-                               break;
-                       default:
-                               showError ("Dispatching error for bypass parameter");
-                               break;
-               }
-               $tabhandler[$pageno][$tabno] ($_REQUEST[$page[$pageno]['bypass']]);
-       }
-       else
-               $tabhandler[$pageno][$tabno] ();
+       ob_flush();
+} catch (Exception $e) {
+       ob_end_clean();
+       printException($e);
 }
-elseif (isset ($page[$pageno]['handler']))
-       $page[$pageno]['handler'] ($tabno);
-else
-       showError ("Failed to find handler for page '${pageno}', tab '${tabno}'");
+clearMessages(); // prevent message appearing in foreign tab
 ?>
-       </td>
-       </tr>
-       </table>
-</body>
-</html>