Index: wifidog/include/schema_validate.php =================================================================== --- wifidog/include/schema_validate.php (revision 1364) +++ wifidog/include/schema_validate.php (working copy) @@ -47,7 +47,7 @@ /** * Define current database schema version */ -define('REQUIRED_SCHEMA_VERSION', 62); +define('REQUIRED_SCHEMA_VERSION', 63); /** Used to test a new shecma version before modyfying the database */ define('SCHEMA_UPDATE_TEST_MODE', false); /** @@ -1415,6 +1415,17 @@ $sql .= "ALTER TABLE nodes ALTER COLUMN connection_limit_node_max_total_bytes_override TYPE bigint;\n"; } + $new_schema_version = 63; + if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { + printUpdateVersion($new_schema_version); + $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; + + $sql .= "ALTER TABLE networks ADD column allow_original_url_redirect bool; \n"; + $sql .= "ALTER TABLE networks ALTER COLUMN allow_original_url_redirect SET DEFAULT FALSE;\n"; + + $sql .= "ALTER TABLE nodes ADD column allow_original_URL_redirect bool; \n"; + $sql .= "ALTER TABLE nodes ALTER COLUMN allow_original_URL_redirect SET DEFAULT FALSE;\n"; + } /* $new_schema_version = ; if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { @@ -1452,4 +1463,4 @@ * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: - */ \ No newline at end of file + */ Index: wifidog/classes/Network.php =================================================================== --- wifidog/classes/Network.php (revision 1364) +++ wifidog/classes/Network.php (working copy) @@ -1404,6 +1404,45 @@ return $retval; } + /** + * Are nodes allowed to redirect users to the original requested web page instead of + * the portal? + * + * @return bool True or false + * + * @access public + */ + public function getPortalOriginalUrlAllowed() + { + return (($this->_row['allow_original_url_redirect'] == 't') ? true : false); + } + + /** + * Set if nodes are allowed to redirect users to the original requested web page + * instead of the portal? + * + * @param bool $value The new value, true or false + * + * @return bool True on success, false on failure + * + * @access public + */ + public function setPortalOriginalUrlAllowed($value) + { + // Init values + $retval = true; + + if ($value != $this->getPortalOriginalUrlAllowed()) { + $db = AbstractDb::getObject(); + $value ? $value = 'TRUE' : $value = 'FALSE'; + $retval = $db->execSqlUpdate("UPDATE networks SET allow_original_url_redirect = {$value} WHERE network_id = '{$this->getId()}'", false); + $this->refresh(); + } + + return $retval; + } + + /** The length of the window during which the user must not have exceeded the limits below. * * @return string Interval as returned by postgresql @@ -1665,6 +1704,12 @@ $data = InterfaceElements::generateInputCheckbox("network_" . $this->getId() . "_allow_custom_portal_redirect", "", _("Yes"), $this->getCustomPortalRedirectAllowed(), "network_allow_custom_portal_redirect_radio"); $html_network_node_properties[] = InterfaceElements::generateAdminSectionContainer("network_allow_custom_portal_redirect", $title, $data, $help); + // allow_original_URL_redirect + $title = _("Original URL redirection"); + $help = _("Are nodes allowed to redirect users to the web page they originally requested instead of the portal?"); + $data = InterfaceElements::generateInputCheckbox("network_" . $this->getId() . "_allow_original_URL_redirect", "", _("Yes"), $this->getPortalOriginalUrlAllowed(), "network_allow_original_URL_redirect_radio"); + $html_network_node_properties[] = InterfaceElements::generateAdminSectionContainer("network_allow_original_URL_redirect", $title, $data, $help); + // Build section $html .= InterfaceElements::generateAdminSectionContainer("network_node_properties", _("Network's node properties"), implode(null, $html_network_node_properties)); @@ -1874,6 +1919,10 @@ $name = "network_".$this->getId()."_allow_custom_portal_redirect"; $this->setCustomPortalRedirectAllowed(empty ($_REQUEST[$name]) ? false : true); + // 'allow_original_URL_redirect + $name = "network_".$this->getId()."_allow_original_URL_redirect"; + $this->setPortalOriginalUrlAllowed(empty ($_REQUEST[$name]) ? false : true); + /* * Dynamic abuse control */ Index: wifidog/classes/Node.php =================================================================== --- wifidog/classes/Node.php (revision 1364) +++ wifidog/classes/Node.php (working copy) @@ -1019,6 +1019,32 @@ return $retval; } + /** redirect users to the original requested web page instead of portal + Must be enabled in the Network configuration to have any effect + @return a string */ + function getPortalOriginalUrlAllowed() + { + return (($this->_row['allow_original_url_redirect'] == 't') ? true : false); + } + + /** redirect users to the original requested web page instead of portal + Must be enabled in the Network configuration to have any effect + @return true on success, false on failure */ + function setPortalOriginalUrlAllowed($value) + { + $retval = true; + if ($value != $this->getPortalOriginalUrlAllowed()) + { + $db = AbstractDb::getObject(); + $value ? $value = 'TRUE' : $value = 'FALSE'; + $retval = $db->execSqlUpdate("UPDATE nodes SET allow_original_url_redirect = '{$value}' WHERE node_id = '{$this->getId()}'", false); + $this->refresh(); + } + return $retval; + } + + + /** * Retrieves the admin interface of this object * @@ -1240,6 +1266,12 @@ $_html_node_config[] = InterfaceElements::generateAdminSectionContainer("node_custom_portal_redirect_url", $_title, $_data); } + // allow_original_URL_redirect + $title = _("Original URL redirection"); + $help = _("Are nodes allowed to redirect users to the web page they originally requested instead of the portal? this will overide the custom portal URL"); + $data = InterfaceElements::generateInputCheckbox("node_" . $node_id . "_allow_original_URL_redirect", "", _("Yes"), $this->getPortalOriginalUrlAllowed(), "node_allow_original_URL_redirect_radio"); + $_html_node_config[] = InterfaceElements::generateAdminSectionContainer("node_allow_original_URL_redirect", $title, $data, $help); + // Build section $html .= InterfaceElements::generateAdminSectionContainer("node_config", _("Node configuration"), implode(null, $_html_node_config)); @@ -1424,6 +1456,13 @@ $this->setCustomPortalRedirectUrl($_REQUEST[$name]); } + // allow_original_URL_redirect + if ($network->getPortalOriginalUrlAllowed()) + { + $name = "node_" . $node_id . "_allow_original_URL_redirect"; + $this->setPortalOriginalUrlAllowed(empty ($_REQUEST[$name]) ? false : true); + } + // End Node configuration section // Access rights Index: wifidog/portal/index.php =================================================================== --- wifidog/portal/index.php (revision 1364) +++ wifidog/portal/index.php (working copy) @@ -108,6 +108,24 @@ } /* + * If this node allows redirection to original URL, and the network config allows it, + * redirect to original URL + */ +$session_original_url = $session->get(SESS_ORIGINAL_URL_VAR); + +if ($node->getPortalOriginalUrlAllowed() && $network->getPortalOriginalUrlAllowed() && !empty ($session_original_url)) + /** + * If the database doesn't get cleaned up by a cron job, we'll do now (normally this is done in ManiUI, but for custom URLs, MainUI may never be instanciated + */ + if (CONF_USE_CRON_FOR_DB_CLEANUP == false) { + garbage_collect(); + } + header("Location: {$session_original_url}"); + exit; +} + + +/* * If this node has a custom portal defined, and the network config allows it, * redirect to the custom portal */ @@ -215,4 +233,4 @@ * c-hanging-comment-ender-p: nil * End: */ -?> \ No newline at end of file +?>