Different portal page per location



  • Hi,

    Great work, latest snapshot (FreeBSD6/RELENG_1_2) is looking good!

    Any idea on what needs to be done and how difficult it would be to display a specific portal page based on the users subnet/ location?

    Or some other way get the users location and show them a custom portal page.

    I was thinking of getting the client Ip and checking it against a table of know subnets and if there is a match, display the custom page tied to that subnet and a catch-all for unknown subnets.

    I realize this is not foolproof but for wireless client we give out the address, and for the odd case we will have a generic page.

    here is some code I dug up to try and get the correct address:

    function getIP() {
    $ip;

    if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
    else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
    else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
    else $ip = "UNKNOWN";

    return $ip;

    }

    Thanks

    -Mark



  • See this post:

    http://forum.pfsense.org/index.php/topic,5335.msg32093.html#msg32093

    Basically follow the instructions on how to add a new .php page then redirect from the primary captive portal page to the custom page where you can then show a page per IP address or subnet.



  • or see this page
    http://forum.pfsense.org/index.php/topic,4937.0.html

    the codes in there make a normal portal page that jumps to a custum .php page that shows youre ipadress



  • Thanks for the quick replies,

    I did notice the redirect by time thread….

    I tried it but the user experience is not the best, the initial load of index.php plus 2 redirects before the user sees the login page shows as a slow load (too much delay):

    here is the logic:
    User browser is opened, tries to go to site "X" and is redirected to the pfsense lighthttpd index.php page which reads the users ip address etc, and based on config, loads captiveportal.html, which redirects to the script below (redir.php) with then redirects to the correct page.

    I am thinking I could embed the code below directly in the first index.php page and bypass extra redirects.

    $apm = "192.168.99..";
    $pdx = "192.168.100..
    ";
    $ip = $_SERVER['REMOTE_ADDR'];
    if (ereg($apm,$ip)) {
          header('Location: https://phc.hdn.net/apm.html');
    } elseif (ereg($pdx,$ip)) {
          header('Location: https://phc.hdn.net/pdx.html');
    } else {
          header('Location: https://phc.hdn.net/default.html');
    };
    ?>

    comments?

    Thanks
    -M



  • yust skip 1 more redirect:
    and include the pages on load time by the ip

    
    $apm = "192.168.99..*";
    $pdx = "192.168.100..*";
    $ip = $_SERVER['REMOTE_ADDR'];
    if (ereg($apm,$ip)) {
          include("https://phc.hdn.net/apm.html");
     } elseif (ereg($pdx,$ip)) {
          include("https://phc.hdn.net/pdx.html");
     } else {
          include("https://phc.hdn.net/default.html");
     };
    ?>
    
    


  • Thanks…. getting closer!

    Good catch on using the include instead of the header...

    Now the redirect works but the user login does not redirect to the original requested URL, it just reloads the login page...
    however if I add a hard location in using GUI that location is OK.

    here is what I am using:

    portal page:  (this redirects with the following URL in the client browser)

    https://phc.hdn.net:8001/captiveportal-redir.php?portal_action=https://phc.hdn.net:8001/&portal_redirurl=http://www.craigslist.org/

    The php code to show ip based login page:

    Here I got rid of the Location as a straight include seems fine.

    $test = "192.168.99..*";
    $pdx = "192.168.100..*";
    $apm = "10.10.60..*";
    $ip = $_SERVER['REMOTE_ADDR'];
    if (ereg($apm,$ip)) {
          include('captiveportal-apm.html');
     } elseif (ereg($pdx,$ip)) {
          include('captiveportal-pdx.html');
     } else {
          include('captiveportal-index.html');
     };
    ?>
    


  • do you have lines to use the entery of the user ?
    like this:

    
    ">
    
       ">
    
    | 
    
    ### usernaam
    
     |  |
    | 
    
    ### wachtwoord 
    
     |  |
    |  |  |
    
    


  • my form is as such:

    the only difference is the embedded php for the vars…

    I will try it with the embedded php...

    I need to pull this first url the user tries to go to, it seems to use the second , which is the login page...

    
    <form name="form1" method="post" action="$PORTAL_ACTION$">
    
          Username:
    
    Thanks!
    
    </form>
    
    


  • $PORTAL_REDIRURL$ and $PORTAL_ACTION$
    are only on the first page before the redirect to youre php page
    with

    you send them as get variables to youre php page
    so you need to use $_GET["name of get variable"] to get them in youre php page

    make redir.php like this:

    
    $test = "192.168.99..*";
    $pdx = "192.168.100..*";
    $apm = "10.10.60..*";
    $ip = $_SERVER['REMOTE_ADDR'];
    if (ereg($apm,$ip)) {
          include('captiveportal-apm.html');
     } elseif (ereg($pdx,$ip)) {
          include('captiveportal-pdx.html');
     } else {
          include('captiveportal-index.html');
     };
    ?>
    
    ">
    
       ">
    
    | 
       Username:  
     | 
       Password:  
     |   
    
     |
    
    


  • That seems to have worked great,.

    Redirects work!
    Per Ip subnet redirect to custom login page works also

    Thanks!

    -Mark


Log in to reply