summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/inc/captiveportal.inc16
-rwxr-xr-xusr/local/captiveportal/index.php39
2 files changed, 48 insertions, 7 deletions
diff --git a/etc/inc/captiveportal.inc b/etc/inc/captiveportal.inc
index 28dab57..48f9dba 100644
--- a/etc/inc/captiveportal.inc
+++ b/etc/inc/captiveportal.inc
@@ -181,6 +181,14 @@ EOD;
$fd = @fopen("{$g['varetc_path']}/captiveportal.html", "w");
if ($fd) {
+ // Special case handling. Convert so that we can pass this page
+ // through the PHP interpreter later without clobbering the vars.
+ $htmltext = str_replace("\$PORTAL_REDIRURL\$", "#PORTAL_REDIRURL#", $htmltext);
+ $htmltext = str_replace("\$PORTAL_MESSAGE\$", "#PORTAL_MESSAGE#", $htmltext);
+ $htmltext = str_replace("\$CLIENT_MAC\$", "#CLIENT_MAC#", $htmltext);
+ $htmltext = str_replace("\$CLIENT_IP\$", "#CLIENT_IP#", $htmltext);
+ $htmltext = str_replace("\$ORIGINAL_PORTAL_IP\$", "#ORIGINAL_PORTAL_IP#", $htmltext);
+ $htmltext = str_replace("\$PORTAL_ACTION\$", "#PORTAL_ACTION#", $htmltext);
fwrite($fd, $htmltext);
fclose($fd);
}
@@ -210,6 +218,14 @@ EOD;
$fd = @fopen("{$g['varetc_path']}/captiveportal-error.html", "w");
if ($fd) {
+ // Special case handling. Convert so that we can pass this page
+ // through the PHP interpreter later without clobbering the vars.
+ $errtext = str_replace("\$PORTAL_REDIRURL\$", "#PORTAL_REDIRURL#", $errtext);
+ $errtext = str_replace("\$PORTAL_MESSAGE\$", "#PORTAL_MESSAGE#", $errtext);
+ $errtext = str_replace("\$CLIENT_MAC\$", "#CLIENT_MAC#", $errtext);
+ $errtext = str_replace("\$CLIENT_IP\$", "#CLIENT_IP#", $errtext);
+ $errtext = str_replace("\$ORIGINAL_PORTAL_IP\$", "#ORIGINAL_PORTAL_IP#", $errtext);
+ $errtext = str_replace("\$PORTAL_ACTION\$", "#PORTAL_ACTION#", $errtext);
fwrite($fd, $errtext);
fclose($fd);
}
diff --git a/usr/local/captiveportal/index.php b/usr/local/captiveportal/index.php
index 56cddc0..41ebc9c 100755
--- a/usr/local/captiveportal/index.php
+++ b/usr/local/captiveportal/index.php
@@ -194,20 +194,22 @@ function portal_reply_page($redirurl, $type = null, $message = null, $clientmac
/* Get captive portal layout */
if ($type == "login")
- $htmltext = file_get_contents("{$g['varetc_path']}/captiveportal.html");
+ $htmltext = get_include_contents("{$g['varetc_path']}/captiveportal.html");
else
- $htmltext = file_get_contents("{$g['varetc_path']}/captiveportal-error.html");
+ $htmltext = get_include_contents("{$g['varetc_path']}/captiveportal-error.html");
/* substitute other variables */
- if (isset($config['captiveportal']['httpslogin']))
+ if (isset($config['captiveportal']['httpslogin'])) {
$htmltext = str_replace("\$PORTAL_ACTION\$", "https://{$config['captiveportal']['httpsname']}:8001/", $htmltext);
- else {
- $ifip = portal_ip_from_client_ip($clientip);
+ $htmltext = str_replace("#PORTAL_ACTION#", "https://{$config['captiveportal']['httpsname']}:8001/", $htmltext);
+ } else {
+ $ifip = portal_ip_from_client_ip($clientip);
if (!$ifip)
$ourhostname = $config['system']['hostname'] . ":8000";
else
$ourhostname = "{$ifip}:8000";
$htmltext = str_replace("\$PORTAL_ACTION\$", "http://{$ourhostname}/", $htmltext);
+ $htmltext = str_replace("#PORTAL_ACTION#", "http://{$ourhostname}/", $htmltext);
}
$htmltext = str_replace("\$PORTAL_REDIRURL\$", htmlspecialchars($redirurl), $htmltext);
@@ -215,9 +217,27 @@ function portal_reply_page($redirurl, $type = null, $message = null, $clientmac
$htmltext = str_replace("\$CLIENT_MAC\$", htmlspecialchars($clientmac), $htmltext);
$htmltext = str_replace("\$CLIENT_IP\$", htmlspecialchars($clientip), $htmltext);
+ // Special handling case for captive portal master page so that it can be ran
+ // through the PHP interpreter using the include method above. We convert the
+ // $VARIABLE$ case to #VARIABLE# in /etc/inc/captiveportal.inc before writing out.
+ $htmltext = str_replace("#PORTAL_REDIRURL#", htmlspecialchars($redirurl), $htmltext);
+ $htmltext = str_replace("#PORTAL_MESSAGE#", htmlspecialchars($message), $htmltext);
+ $htmltext = str_replace("#CLIENT_MAC#", htmlspecialchars($clientmac), $htmltext);
+ $htmltext = str_replace("#CLIENT_IP#", htmlspecialchars($clientip), $htmltext);
+
echo $htmltext;
}
+function get_include_contents($filename) {
+ if (is_file($filename)) {
+ ob_start();
+ include $filename;
+ $contents = ob_get_contents();
+ ob_end_clean();
+ return $contents;
+ }
+ return false;
+}
function portal_mac_radius($clientmac,$clientip) {
global $config ;
@@ -448,7 +468,12 @@ document.location.href="{$my_redirurl}";
EOD;
} else {
- header("Location: " . $my_redirurl);
+ if($_POST['ORIGINAL_PORTAL_IP']) {
+ header ('HTTP/1.1 301 Moved Permanently');
+ header("Location: " . $_POST['ORIGINAL_PORTAL_IP']);
+ } else {
+ header("Location: " . $my_redirurl);
+ }
}
return $sessionid;
@@ -486,4 +511,4 @@ function disconnect_client($sessionid, $logoutReason = "LOGOUT", $term_cause = 1
unlock($cplock);
}
-?>
+?> \ No newline at end of file
OpenPOWER on IntegriCloud