3 # Neither "throw/catch" for custom exceptions nor printException() will
4 # work without first loading exceptions.php.
5 require_once 'inc/exceptions.php';
7 // Code block below is a module request dispatcher. Turning it into a
8 // function will break things because of the way require() works.
11 case ! array_key_exists ('module', $_REQUEST):
12 case 'interface' == $_REQUEST['module']:
13 require_once 'inc/interface.php';
14 // init.php has to be included after interface.php, otherwise the bits
15 // set by local.php get lost
16 require_once 'inc/init.php';
18 // Security context is built on the requested page/tab/bypass data,
21 redirectIfNecessary();
24 renderAccessDenied (FALSE);
27 header ('Content-Type: text/html; charset=UTF-8');
28 // Only store the tab name after clearance is got. Any failure is unhandleable.
29 if (isset ($_REQUEST['tab']) and ! isset ($_SESSION['RTLT'][$pageno]['dont_remember']))
30 $_SESSION['RTLT'][$pageno] = array ('tabname' => $tabno, 'time' => time());
31 // call the main handler - page or tab handler.
32 if (isset ($tabhandler[$pageno][$tabno]))
33 call_user_func ($tabhandler[$pageno][$tabno], getBypassValue());
34 elseif (isset ($page[$pageno]['handler']))
35 $page[$pageno]['handler'] ($tabno);
37 throw new RackTablesError ("Failed to find handler for page '${pageno}', tab '${tabno}'", RackTablesError
::INTERNAL
);
38 // Embed the current text in OB into interface layout (the latter also
39 // empties color message buffer).
40 $contents = ob_get_contents();
42 renderInterfaceHTML ($pageno, $tabno, $contents);
44 case 'chrome' == $_REQUEST['module']:
45 require_once 'inc/init.php';
46 genericAssertion ('uri', 'string');
47 proxyStaticURI ($_REQUEST['uri']);
49 case 'download' == $_REQUEST['module']:
50 require_once 'inc/init.php';
56 renderAccessDenied (FALSE);
60 $asattach = (isset ($_REQUEST['asattach']) and $_REQUEST['asattach'] == 'no') ?
FALSE : TRUE;
61 $file = getFile (getBypassValue());
62 header("Content-Type: {$file['type']}");
63 header("Content-Length: {$file['size']}");
65 header("Content-Disposition: attachment; filename={$file['name']}");
66 echo $file['contents'];
68 case 'image' == $_REQUEST['module']:
69 require_once 'inc/render_image.php';
70 // 'progressbar's never change, attempt an IMS chortcut before loading init.php
72 require_once 'inc/init.php';
75 dispatchImageRequest();
83 case 'ajax' == $_REQUEST['module']:
84 require_once 'inc/ajax-interface.php';
85 require_once 'inc/init.php';
88 dispatchAJAXRequest();
90 catch (InvalidRequestArgException
$e)
93 echo "NAK\nMalformed request";
98 echo "NAK\nRuntime exception: ". $e->getMessage();
101 case 'redirect' == $_REQUEST['module']:
102 // Include init after ophandlers/snmp, not before, so local.php can redefine things.
103 require_once 'inc/ophandlers.php';
104 // snmp.php is an exception, it is treated by a special hack
105 if (isset ($_REQUEST['op']) and $_REQUEST['op'] == 'querySNMPData')
106 require_once 'inc/snmp.php';
107 require_once 'inc/init.php';
110 genericAssertion ('op', 'string');
111 $op = $_REQUEST['op'];
113 $location = buildWideRedirectURL();
114 // FIXME: find a better way to handle this error
115 if ($op == 'addFile' && !isset($_FILES['file']['error']))
116 throw new RackTablesError ('File upload error, check upload_max_filesize in php.ini', RackTablesError
::MISCONFIGURED
);
120 !isset ($ophandler[$pageno][$tabno][$op]) or
121 !function_exists ($ophandler[$pageno][$tabno][$op])
123 throw new RackTablesError ("Invalid navigation data for '${pageno}-${tabno}-${op}'", RackTablesError
::INTERNAL
);
124 // We have a chance to handle an error before starting HTTP header.
125 if (!isset ($delayauth[$pageno][$tabno][$op]) and !permitted())
126 showError ('Operation not permitted');
129 // Call below does the job of bypass argument assertion, if such is required,
130 // so the ophandler function doesn't have to re-assert this portion of its
131 // arguments. And it would be even better to pass returned value to ophandler,
132 // so it is not necessary to remember the name of bypass in it.
134 if (strlen ($redirect_to = call_user_func ($ophandler[$pageno][$tabno][$op])))
135 $location = $redirect_to;
137 header ("Location: " . $location);
139 // known "soft" failures require a short error message
140 catch (InvalidRequestArgException
$e)
143 showError ($e->getMessage());
144 header ('Location: ' . $location);
146 catch (RTDatabaseError
$e)
149 showError ('Database error: ' . $e->getMessage());
150 header ('Location: ' . $location);
152 // any other error requires no special handling and will be caught outside
154 case 'popup' == $_REQUEST['module']:
155 require_once 'inc/popup.php';
156 require_once 'inc/init.php';
159 case 'upgrade' == $_REQUEST['module']:
160 require_once 'inc/config.php'; // for CODE_VERSION
161 require_once 'inc/dictionary.php';
162 require_once 'inc/upgrade.php';
163 // Enforce default value for now, releases prior to 0.17.0 didn't support 'httpd' auth source.
164 $user_auth_src = 'database';
165 if (FALSE === @include_once
'inc/secret.php')
166 die ('<center>There is no working RackTables instance here, <a href="?module=installer">install</a>?</center>');
169 $dbxlink = new PDO ($pdo_dsn, $db_username, $db_password);
171 catch (PDOException
$e)
173 die ("Database connection failed:\n\n" . $e->getMessage());
175 renderUpgraderHTML();
177 case 'installer' == $_REQUEST['module']:
178 require_once 'inc/dictionary.php';
179 require_once 'inc/install.php';
180 renderInstallerHTML();
183 throw new InvalidRequestArgException ('module', $_REQUEST['module']);
190 # prevent message appearing in foreign tab
191 if (isset ($_SESSION['log']))
192 unset ($_SESSION['log']);