Captive Portal: suggestion + potential bug + fix
-
Using 2.1-DEV, snapshot from Wed May 2 10:06:09 EDT 2012
Suggestion:
Make it possible to set $cpcfg['zoneid'] via web-GUI, since it is being used for the port the captive portal zone runs on.
However, it is possible to manually change <zoneid>in /conf/config.xml</zoneid>.Problem
The redirection doesn't work properly if port is set to 80 (infinite redirect loop). Apparently the standard http port is being kicked out of the URL (by the browser?) so that "if ($orig_host != $ourhostname)" in line 73 in /user/local/captiveportal/index.php always returns false.Fix
When $cpcfg['zoneid'] is set to '80', don't expect the port to show in the URL and don't add the port to the redirect URL.Replace the following section from line 62 in /usr/local/captiveportal/index.php
if (isset($config['captiveportal'][$cpzone]['httpslogin'])) $ourhostname = $config['captiveportal'][$cpzone]['httpsname'] . ":" . ($cpcfg['zoneid'] + 1); else { $ifip = portal_ip_from_client_ip($clientip); if (!$ifip) $ourhostname = $config['system']['hostname'] . $config['system']['domain'] . ":{$cpcfg['zoneid']}"; else $ourhostname = "{$ifip}:{$cpcfg['zoneid']}"; }
with this:
if (isset($config['captiveportal'][$cpzone]['httpslogin'])) $ourhostname = $config['captiveportal'][$cpzone]['httpsname'] . ":" . ($cpcfg['zoneid'] + 1); else { $ifip = portal_ip_from_client_ip($clientip); $captiveport = ($cpcfg['zoneid'] != '80' ? ':'.$cpcfg['zoneid'] : ''); if (!$ifip) $ourhostname = $config['system']['hostname'] . $config['system']['domain'] . "{$captiveport}"; else $ourhostname = "{$ifip}{$captiveport}"; }
Also, I removed 'index.php' from the redirect string, to make it look nicer. It works just fine without:
header("Location: https://{$ourhostname}/index.php?zone={$cpzone} …
line 78 in /usr/local/captiveportal/index.php