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