4 // Code block below is a module request dispatcher. Turning it into a
5 // function will break things because of the way require() works.
8 case ! array_key_exists ('module', $_REQUEST):
9 case 'interface' == $_REQUEST['module']:
10 require_once 'inc/interface.php';
11 // init.php has to be included after interface.php, otherwise the bits
12 // set by local.php get lost
13 require_once 'inc/init.php';
15 // Security context is built on the requested page/tab/bypass data,
18 redirectIfNecessary();
21 renderAccessDenied (FALSE);
24 header ('Content-Type: text/html; charset=UTF-8');
25 // Only store the tab name after clearance is got. Any failure is unhandleable.
26 if (isset ($_REQUEST['tab']) and ! isset ($_SESSION['RTLT'][$pageno]['dont_remember']))
27 $_SESSION['RTLT'][$pageno] = array ('tabname' => $tabno, 'time' => time());
28 // call the main handler - page or tab handler.
29 if (isset ($tabhandler[$pageno][$tabno]))
30 call_user_func ($tabhandler[$pageno][$tabno], getBypassValue());
31 elseif (isset ($page[$pageno]['handler']))
32 $page[$pageno]['handler'] ($tabno);
34 throw new RackTablesError ("Failed to find handler for page '${pageno}', tab '${tabno}'", RackTablesError
::INTERNAL
);
35 // Embed the current text in OB into interface layout (the latter also
36 // empties color message buffer).
37 $contents = ob_get_contents();
39 renderInterfaceHTML ($pageno, $tabno, $contents);
41 case 'tsuri' == $_REQUEST['module']:
42 require_once 'inc/init.php';
43 genericAssertion ('uri', 'string');
44 proxyStaticURI ($_REQUEST['uri']);
46 case 'download' == $_REQUEST['module']:
47 require_once 'inc/init.php';
53 renderAccessDenied (FALSE);
57 $asattach = (isset ($_REQUEST['asattach']) and $_REQUEST['asattach'] == 'no') ?
FALSE : TRUE;
58 $file = getFile (getBypassValue());
59 header("Content-Type: {$file['type']}");
60 header("Content-Length: {$file['size']}");
62 header("Content-Disposition: attachment; filename={$file['name']}");
63 echo $file['contents'];
65 case 'image' == $_REQUEST['module']:
66 require_once 'inc/render_image.php';
67 // 'progressbar's never change, attempt an IMS chortcut before loading init.php
69 require_once 'inc/init.php';
72 dispatchImageRequest();
80 case 'ajax' == $_REQUEST['module']:
81 require_once 'inc/ajax-interface.php';
82 require_once 'inc/init.php';
85 dispatchAJAXRequest();
87 catch (InvalidRequestArgException
$e)
90 echo "NAK\nMalformed request";
95 echo "NAK\nRuntime exception: ". $e->getMessage();
98 case 'redirect' == $_REQUEST['module']:
99 // Include init after ophandlers/snmp, not before, so local.php can redefine things.
100 require_once 'inc/ophandlers.php';
101 // snmp.php is an exception, it is treated by a special hack
102 if (isset ($_REQUEST['op']) and $_REQUEST['op'] == 'querySNMPData')
103 require_once 'inc/snmp.php';
104 require_once 'inc/init.php';
107 genericAssertion ('op', 'string');
108 $op = $_REQUEST['op'];
110 $location = buildWideRedirectURL();
111 // FIXME: find a better way to handle this error
112 if ($op == 'addFile' && !isset($_FILES['file']['error']))
113 throw new RackTablesError ('File upload error, check upload_max_filesize in php.ini', RackTablesError
::MISCONFIGURED
);
117 !isset ($ophandler[$pageno][$tabno][$op]) or
118 !function_exists ($ophandler[$pageno][$tabno][$op])
120 throw new RackTablesError ("Invalid navigation data for '${pageno}-${tabno}-${op}'", RackTablesError
::INTERNAL
);
121 // We have a chance to handle an error before starting HTTP header.
122 if (!isset ($delayauth[$pageno][$tabno][$op]) and !permitted())
123 showError ('Operation not permitted');
126 // Call below does the job of bypass argument assertion, if such is required,
127 // so the ophandler function doesn't have to re-assert this portion of its
128 // arguments. And it would be even better to pass returned value to ophandler,
129 // so it is not necessary to remember the name of bypass in it.
131 if (strlen ($redirect_to = call_user_func ($ophandler[$pageno][$tabno][$op])))
132 $location = $redirect_to;
134 header ("Location: " . $location);
136 // known "soft" failures require a short error message
137 catch (InvalidRequestArgException
$e)
140 showError ($e->getMessage());
141 header ('Location: ' . $location);
143 catch (RTDatabaseError
$e)
146 showError ('Database error: ' . $e->getMessage());
147 header ('Location: ' . $location);
149 // any other error requires no special handling and will be caught outside
151 case 'popup' == $_REQUEST['module']:
152 require_once 'inc/popup.php';
153 require_once 'inc/init.php';
157 throw new InvalidRequestArgException ('module', $_REQUEST['module']);
164 clearMessages(); // prevent message appearing in foreign tab