Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Captive Portal: suggestion + potential bug + fix

    Scheduled Pinned Locked Moved 2.1 Snapshot Feedback and Problems - RETIRED
    1 Posts 1 Posters 1.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      helixxx
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.