<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Captive Portal: suggestion + potential bug + fix]]></title><description><![CDATA[<p dir="auto">Using <strong>2.1-DEV, snapshot from Wed May 2 10:06:09 EDT 2012</strong></p>
<p dir="auto">Suggestion:<br />
Make it possible to set <em>$cpcfg['zoneid']</em> via web-GUI, since it is being used for the port the captive portal zone runs on.<br />
However, it is possible to manually change <strong>&lt;zoneid&gt;in /conf/config.xml&lt;/zoneid&gt;</strong>.</p>
<p dir="auto">Problem<br />
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 "<strong><em>if ($orig_host != $ourhostname)</em></strong>" in <strong>line 73 in /user/local/captiveportal/index.php</strong> always returns <em>false</em>.</p>
<p dir="auto">Fix<br />
When <em>$cpcfg['zoneid']</em> is set to '80', don't expect the port to show in the URL and don't add the port to the redirect URL.</p>
<p dir="auto">Replace the following section from <strong>line 62 in /usr/local/captiveportal/index.php</strong></p>
<pre><code>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']}";
}

</code></pre>
<p dir="auto">with this:</p>
<pre><code>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}";
}

</code></pre>
<p dir="auto">Also, I removed 'index.php' from the redirect string, to make it look nicer. It works just fine without:<br />
<em>header("Location: https://{$ourhostname}/<s>index.php</s>?zone={$cpzone} …</em><br />
<strong>line 78 in  /usr/local/captiveportal/index.php</strong></p>
]]></description><link>https://forum.netgate.com/topic/44697/captive-portal-suggestion-potential-bug-fix</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Apr 2026 23:59:07 GMT</lastBuildDate><atom:link href="https://forum.netgate.com/topic/44697.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 06 May 2012 19:10:35 GMT</pubDate><ttl>60</ttl></channel></rss>