r4282 addRack(): use the right message code
[racktables] / wwwroot / index.php
CommitLineData
b325120a 1<?php
90a3d6d8
DY
2ob_start();
3try {
36ef72d9
DO
4if (array_key_exists ('module', $_REQUEST))
5{
b52cc354 6 require_once 'inc/init.php';
36ef72d9
DO
7 switch ($_REQUEST['module'])
8 {
9 case 'tsuri':
10 genericAssertion ('uri', 'string');
11 proxyStaticURI ($_REQUEST['uri']);
12 break;
0415b520
DO
13 case 'download':
14 $pageno = 'file';
15 $tabno = 'download';
16 fixContext();
17 if (!permitted())
18 {
19 require_once 'inc/interface.php';
20 renderAccessDenied();
21 }
22
23 $asattach = (isset ($_REQUEST['asattach']) and $_REQUEST['asattach'] == 'no') ? FALSE : TRUE;
24 $file = getFile (getBypassValue());
25 header("Content-Type: {$file['type']}");
26 header("Content-Length: {$file['size']}");
27 if ($asattach)
28 header("Content-Disposition: attachment; filename={$file['name']}");
29 echo $file['contents'];
30 break;
36ef72d9
DO
31 default:
32 throw new InvalidRequestArgException ('module', $_REQUEST['module']);
33 }
0415b520 34 ob_end_flush();
36ef72d9
DO
35 exit;
36}
37
b52cc354
DO
38require_once 'inc/interface.php';
39# init.php has to be included after interface.php, otherwise the bits
40# set by local.php get lost
41require_once 'inc/init.php';
329ec966 42prepareNavigation();
da958e52
DO
43// no ctx override is necessary
44fixContext();
750d26d2 45redirectIfNecessary();
da958e52 46if (!permitted())
da958e52 47 renderAccessDenied();
878512c6 48header ('Content-Type: text/html; charset=UTF-8');
b0348307 49// Only store the tab name after clearance is got. Any failure is unhandleable.
fa5b2764
AA
50if (isset ($_REQUEST['tab']) and ! isset ($_SESSION['RTLT'][$pageno]['dont_remember']))
51 $_SESSION['RTLT'][$pageno] = array ('tabname' => $tabno, 'time' => time());
e673ee24 52
1d4d254b
AA
53// call the main handler - page or tab handler.
54// catch exception and show its error message instead of page/tab content
55try {
e45a78d7 56if (isset ($tabhandler[$pageno][$tabno]))
08408472 57 call_user_func ($tabhandler[$pageno][$tabno], getBypassValue());
e45a78d7 58elseif (isset ($page[$pageno]['handler']))
e673ee24
DO
59 $page[$pageno]['handler'] ($tabno);
60else
1d4d254b 61 showError ("Failed to find handler for page '${pageno}', tab '${tabno}'");
08408472 62$content = ob_get_clean();
1d4d254b
AA
63} catch (Exception $e) {
64 ob_clean();
65 $content = '';
66 showError ("Unhandled exception: " . $e->getMessage());
67}
68
08408472 69ob_start();
e673ee24 70?>
08408472
AA
71<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
72<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
73<head><title><?php echo getTitle ($pageno); ?></title>
74<?php printPageHeaders(); ?>
75</head>
76<body>
77<table border=0 cellpadding=0 cellspacing=0 width="100%" height="100%" class="maintable">
78 <tr class="mainheader"><td>
79 <table width="100%" cellspacing="0" cellpadding="2" border="0">
80 <tr>
81 <td valign=top><a href="http://racktables.org/"><?php printImageHREF ('logo'); ?></a></td>
82 <td valign=top><div class=greeting><?php printGreeting(); ?></div></td>
83 </tr>
84 </table>
85 </td></tr>
86 <tr><td class="menubar">
87 <table border="0" width="100%" cellpadding="3" cellspacing="0">
88 <tr><?php showPathAndSearch ($pageno); ?></tr>
89 </table>
90 </td></tr>
91 <tr><td><?php showTabs ($pageno, $tabno); ?></td></tr>
1d4d254b 92 <tr><td><?php showMessageOrError(); ?></td></tr>
08408472
AA
93 <tr><td><?php echo $content; ?></td></tr>
94</table>
95</body>
96</html>
e410ebfc 97<?php
65e557dd 98 ob_flush();
90a3d6d8
DY
99} catch (Exception $e) {
100 ob_end_clean();
101 printException($e);
102}
1d4d254b 103clearMessages(); // prevent message appearing in foreign tab
e410ebfc 104?>