r4286 process.php: delete
authorDenis Ovsienko <infrastation@yandex.ru>
Fri, 4 Mar 2011 12:03:17 +0000 (12:03 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Fri, 4 Mar 2011 12:03:17 +0000 (12:03 +0000)
index.php: merge redirecting code from process.php into dispatching block
makeHrefProcess(): update respectively
popup.php: idem
buildWideRedirectURL(): suppress "module" argument to get out if redirection cycle

wwwroot/inc/functions.php
wwwroot/inc/interface.php
wwwroot/inc/ophandlers.php
wwwroot/index.php
wwwroot/popup.php
wwwroot/process.php [deleted file]

index 5e88ab6880180509ede50fa49afe13bc10100e37..f2fe0e502064474ea9b39321bddaf3b84b30d002 100644 (file)
@@ -2418,7 +2418,7 @@ function makeHref($params = array())
 function makeHrefProcess($params = array())
 {
        global $pageno, $tabno;
-       $ret = 'process.php?';
+       $ret = '?module=redirect&';
        $first = true;
        if (!isset($params['page']))
                $params['page'] = $pageno;
index 832ab0443d0420fb5d1f93acd144c84b37cea7ec..d7a00a3745fbd8030b788f783395998a3ba78e96 100644 (file)
@@ -6877,7 +6877,7 @@ function printOpFormIntro ($opname, $extra = array(), $upload = FALSE)
 {
        global $pageno, $tabno, $page;
 
-       echo "<form method=post id=${opname} name=${opname} action='process.php?page=${pageno}&tab=${tabno}&op=${opname}'";
+       echo "<form method=post id=${opname} name=${opname} action='?module=redirect&page=${pageno}&tab=${tabno}&op=${opname}'";
        if ($upload)
                echo " enctype='multipart/form-data'";
        echo ">";
index e32b450486ddade662bb406db4eda8637d6da673..4b0157985652e57dd75a0bb680afd673be970634 100644 (file)
@@ -419,7 +419,7 @@ function buildWideRedirectURL ($log = NULL, $nextpage = NULL, $nexttab = NULL, $
 
        if (count ($moreArgs) > 0)
                foreach ($moreArgs as $arg => $value)
-                       if (gettype ($value) != 'array')
+                       if (gettype ($value) != 'array' and $arg != 'module')
                                $url .= '&' . urlencode ($arg) . '=' . urlencode ($value);
                        else
                                foreach ($value as $v)
index a865222133b645ca06c677eb7c0216cc23bba2a8..5d8c52a12d35fad57f7421c94707f022367dd9ba 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 ob_start();
 try {
+// Code block below is a module request dispatcher. Turning it into a
+// function will break things because of the way require() works.
 if (array_key_exists ('module', $_REQUEST))
 {
        switch ($_REQUEST['module'])
@@ -18,7 +20,8 @@ if (array_key_exists ('module', $_REQUEST))
                if (!permitted())
                {
                        require_once 'inc/interface.php';
-                       renderAccessDenied();
+                       renderAccessDenied (FALSE);
+                       break;
                }
 
                $asattach = (isset ($_REQUEST['asattach']) and $_REQUEST['asattach'] == 'no') ? FALSE : TRUE;
@@ -40,6 +43,7 @@ if (array_key_exists ('module', $_REQUEST))
                }
                catch (Exception $e)
                {
+                       ob_clean();
                        renderError();
                }
                break;
@@ -61,6 +65,59 @@ if (array_key_exists ('module', $_REQUEST))
                        echo "NAK\nRuntime exception: ". $e->getMessage();
                }
                break;
+       case 'redirect':
+               // Include init after ophandlers/snmp, not before, so local.php can redefine things.
+               require_once 'inc/ophandlers.php';
+               // snmp.php is an exception, it is treated by a special hack
+               if (isset ($_REQUEST['op']) and $_REQUEST['op'] == 'querySNMPData')
+                       require_once 'inc/snmp.php';
+               require_once 'inc/init.php';
+               try
+               {
+                       genericAssertion ('op', 'string');
+                       $op = $_REQUEST['op'];
+                       prepareNavigation();
+                       $location = buildWideRedirectURL();
+                       // FIXME: find a better way to handle this error
+                       if ($op == 'addFile' && !isset($_FILES['file']['error']))
+                               throw new RackTablesError ('File upload error, check upload_max_filesize in php.ini', RackTablesError::MISCONFIGURED);
+                       fixContext();
+                       if
+                       (
+                               !isset ($ophandler[$pageno][$tabno][$op]) or
+                               !function_exists ($ophandler[$pageno][$tabno][$op])
+                       )
+                               throw new RackTablesError ("Invalid navigation data for '${pageno}-${tabno}-${op}'", RackTablesError::INTERNAL);
+                       // We have a chance to handle an error before starting HTTP header.
+                       if (!isset ($delayauth[$pageno][$tabno][$op]) and !permitted())
+                               showError ('Operation not permitted');
+                       else
+                       {
+                               // Call below does the job of bypass argument assertion, if such is required,
+                               // so the ophandler function doesn't have to re-assert this portion of its
+                               // arguments. And it would be even better to pass returned value to ophandler,
+                               // so it is not necessary to remember the name of bypass in it.
+                               getBypassValue();
+                               if (strlen ($redirect_to = call_user_func ($ophandler[$pageno][$tabno][$op])))
+                                       $location = $redirect_to;
+                       }
+                       header ("Location: " . $location);
+               }
+               // known "soft" failures require a short error message
+               catch (InvalidRequestArgException2 $e)
+               {
+                       ob_clean();
+                       showError ($e->getMessage());
+                       header ('Location: ' . $location);
+               }
+               catch (RTDatabaseError $e)
+               {
+                       ob_clean();
+                       showError ('Database error: ' . $e->getMessage());
+                       header ('Location: ' . $location);
+               }
+               // any other error requires no special handling and will be caught outside
+               break;
        default:
                throw new InvalidRequestArgException ('module', $_REQUEST['module']);
        }
index 14424f59872d28d6c6a02b59f327541ba454dc5a..8c45a634855234fd478ff5b197ba365d9cb7cc9d 100644 (file)
@@ -143,7 +143,7 @@ header ('Content-Type: text/html; charset=UTF-8');
                        echo '<br>';
                        echo "<input type=submit value='Proceed' onclick='".
                        "if (getElementById(\"parents\").value != \"\") {".
-                       "       opener.location=\"process.php?page=object&tab=edit&op=linkEntities&object_id=${object_id}&child_entity_type=object&child_entity_id=${object_id}&parent_entity_type=object&parent_entity_id=\"+getElementById(\"parents\").value; ".
+                       "       opener.location=\"?module=redirect&page=object&tab=edit&op=linkEntities&object_id=${object_id}&child_entity_type=object&child_entity_id=${object_id}&parent_entity_type=object&parent_entity_id=\"+getElementById(\"parents\").value; ".
                        "       window.close();}'>";
                        echo '</form></div>';
                        break;
@@ -179,7 +179,7 @@ header ('Content-Type: text/html; charset=UTF-8');
                        echo '<br>';
                        echo "<input type='submit' value='Link' onclick='".
                        "if (getElementById(\"ports\").value != \"\") {".
-                       "       opener.location=\"process.php?page=object&tab=ports&op=linkPort&object_id=${port_info['object_id']}&port_id=$port_id&remote_port_id=\"+getElementById(\"ports\").value+\"&cable=\"+getElementById(\"cable\").value; ".
+                       "       opener.location=\"module=redirect&page=object&tab=ports&op=linkPort&object_id=${port_info['object_id']}&port_id=$port_id&remote_port_id=\"+getElementById(\"ports\").value+\"&cable=\"+getElementById(\"cable\").value; ".
                        "       window.close();}'>";
                        echo '</form></div>';
                        break;
diff --git a/wwwroot/process.php b/wwwroot/process.php
deleted file mode 100644 (file)
index 8ba4551..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-ob_start();
-try {
-// Include init after ophandlers/snmp, not before, so local.php can redefine things.
-require 'inc/ophandlers.php';
-// snmp.php is an exception, it is treated by a special hack
-if (isset ($_REQUEST['op']) and $_REQUEST['op'] == 'querySNMPData')
-       include 'inc/snmp.php';
-require 'inc/init.php';
-assertStringArg ('op');
-$op = $_REQUEST['op'];
-prepareNavigation();
-$location = buildWideRedirectURL();
-
-// FIXME: find a better way to handle this error
-if ($op == 'addFile' && !isset($_FILES['file']['error']))
-       throw new RackTablesError ('File upload error, check upload_max_filesize in php.ini', RackTablesError::MISCONFIGURED);
-fixContext();
-
-if
-(
-       !isset ($ophandler[$pageno][$tabno][$op]) or
-       !function_exists ($ophandler[$pageno][$tabno][$op])
-)
-       throw new RackTablesError ("Invalid navigation data for '${pageno}-${tabno}-${op}'", RackTablesError::INTERNAL);
-
-// We have a chance to handle an error before starting HTTP header.
-if (!isset ($delayauth[$pageno][$tabno][$op]) and !permitted())
-       showError ('Operation not permitted');
-else
-{
-       // Call below does the job of bypass argument assertion, if such is required,
-       // so the ophandler function doesn't have to re-assert this portion of its
-       // arguments. And it would be even better to pass returned value to ophandler,
-       // so it is not necessary to remember the name of bypass in it.
-       getBypassValue();
-       if (strlen ($redirect_to = call_user_func ($ophandler[$pageno][$tabno][$op])))
-               $location = $redirect_to;
-}
-header ("Location: " . $location);
-ob_end_flush();
-}
-// "soft" failures only require a short error message
-catch (InvalidRequestArgException $e)
-{
-       ob_end_clean();
-       showError ($e->getMessage());
-       header ('Location: ' . $location);
-}
-catch (RTDatabaseError $e)
-{
-       ob_end_clean();
-       showError ('Database error: ' . $e->getMessage());
-       header ('Location: ' . $location);
-}
-// the rest ends up in a dedicated page
-catch (Exception $e)
-{
-       ob_end_clean();
-       printException ($e);
-}
-
-?>