From de132ae3ac9ae89e9c18113b879273d5eb3bf2b8 Mon Sep 17 00:00:00 2001 From: bcyrill Date: Tue, 15 Jan 2013 23:26:25 +0100 Subject: Add portal_hostname_from_client_ip function --- usr/local/captiveportal/index.php | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) (limited to 'usr') diff --git a/usr/local/captiveportal/index.php b/usr/local/captiveportal/index.php index 2782cdf..29bf068 100755 --- a/usr/local/captiveportal/index.php +++ b/usr/local/captiveportal/index.php @@ -61,35 +61,17 @@ if (!$clientip) { return; } -$listenporthttps = $cpcfg['listenporthttps'] ? $cpcfg['listenporthttps'] : ($cpcfg['zoneid'] + 1); -$listenporthttp = $cpcfg['listenporthttp'] ? $cpcfg['listenporthttp'] : $cpcfg['zoneid']; - -if (isset($cpcfg['httpslogin'])) - $ourhostname = $cpcfg['httpsname'] . ":" . $listenporthttps; -else { - $ifip = portal_ip_from_client_ip($clientip); - if (!$ifip) { - $ourhostname = "{$config['system']['hostname']}.{$config['system']['domain']}:{$listenporthttp}"; - } else { - if (is_ipaddrv6($ifip)) - $ourhostname = "[{$ifip}]:{$listenporthttp}"; - else - $ourhostname = "{$ifip}:{$listenporthttp}"; - } -} - +$ourhostname = portal_hostname_from_client_ip($clientip); if ($orig_host != $ourhostname) { - /* the client thinks it's connected to the desired web server, but instead - it's connected to us. Issue a redirect... */ + /* the client thinks it's connected to the desired web server, but instead + it's connected to us. Issue a redirect... */ + $protocol = (isset($cpcfg['httpslogin'])) ? 'https://' : 'http://'; + header("Location: {$protocol}{$ourhostname}/index.php?zone={$cpzone}&redirurl=" . urlencode("http://{$orig_host}/{$orig_request}")); - if (isset($cpcfg['httpslogin'])) - header("Location: https://{$ourhostname}/index.php?zone={$cpzone}&redirurl=" . urlencode("http://{$orig_host}/{$orig_request}")); - else - header("Location: http://{$ourhostname}/index.php?zone={$cpzone}&redirurl=" . urlencode("http://{$orig_host}/{$orig_request}")); - - ob_flush(); - return; + ob_flush(); + return; } + if (!empty($cpcfg['redirurl'])) $redirurl = $cpcfg['redirurl']; else if (preg_match("/redirurl=(.*)/", $orig_request, $matches)) -- cgit v1.1