#!/usr/local/bin/php . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ $pgtitle = array("Services", "Captive portal"); require("guiconfig.inc"); if (!is_array($config['captiveportal'])) { $config['captiveportal'] = array(); $config['captiveportal']['page'] = array(); $config['captiveportal']['timeout'] = 60; } if ($_GET['act'] == "viewhtml") { echo base64_decode($config['captiveportal']['page']['htmltext']); exit; } else if ($_GET['act'] == "viewerrhtml") { echo base64_decode($config['captiveportal']['page']['errtext']); exit; } $pconfig['cinterface'] = $config['captiveportal']['interface']; $pconfig['timeout'] = $config['captiveportal']['timeout']; $pconfig['idletimeout'] = $config['captiveportal']['idletimeout']; $pconfig['enable'] = isset($config['captiveportal']['enable']); $pconfig['auth_method'] = $config['captiveportal']['auth_method']; $pconfig['radacct_enable'] = isset($config['captiveportal']['radacct_enable']); $pconfig['httpslogin_enable'] = isset($config['captiveportal']['httpslogin']); $pconfig['httpsname'] = $config['captiveportal']['httpsname']; $pconfig['cert'] = base64_decode($config['captiveportal']['certificate']); $pconfig['key'] = base64_decode($config['captiveportal']['private-key']); $pconfig['logoutwin_enable'] = isset($config['captiveportal']['logoutwin_enable']); $pconfig['nomacfilter'] = isset($config['captiveportal']['nomacfilter']); $pconfig['peruserbw'] = isset($config['captiveportal']['peruserbw']); $pconfig['bwauthmacup'] = $config['captiveportal']['bwauthmacup']; $pconfig['bwauthmacdn'] = $config['captiveportal']['bwauthmacdn']; $pconfig['bwauthipup'] = $config['captiveportal']['bwauthipup']; $pconfig['bwauthipdn'] = $config['captiveportal']['bwauthipdn']; $pconfig['bwdefaultup'] = $config['captiveportal']['bwdefaultup']; $pconfig['bwdefaultdn'] = $config['captiveportal']['bwdefaultdn']; $pconfig['redirurl'] = $config['captiveportal']['redirurl']; $pconfig['radiusip'] = $config['captiveportal']['radiusip']; $pconfig['radiusport'] = $config['captiveportal']['radiusport']; $pconfig['radiusacctport'] = $config['captiveportal']['radiusacctport']; $pconfig['radiuskey'] = $config['captiveportal']['radiuskey']; if ($_POST) { unset($input_errors); $pconfig = $_POST; /* input validation */ if ($_POST['enable']) { $config['captiveportal']['enable'] = $_POST['enable'] ? true : false; $reqdfields = explode(" ", "cinterface"); $reqdfieldsn = explode(",", "Interface"); do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); /* make sure no interfaces are bridged */ for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) { $coptif = &$config['interfaces']['opt' . $i]; if (isset($coptif['enable']) && $coptif['bridge']) { $input_errors[] = "The captive portal cannot be used when one or more interfaces are bridged."; break; } } if ($_POST['httpslogin_enable']) { if (!$_POST['cert'] || !$_POST['key']) { $input_errors[] = "Certificate and key must be specified for HTTPS login."; } else { if (!strstr($_POST['cert'], "BEGIN CERTIFICATE") || !strstr($_POST['cert'], "END CERTIFICATE")) $input_errors[] = "This certificate does not appear to be valid."; if (!strstr($_POST['key'], "BEGIN RSA PRIVATE KEY") || !strstr($_POST['key'], "END RSA PRIVATE KEY")) $input_errors[] = "This key does not appear to be valid."; } if (!$_POST['httpsname'] || !is_domain($_POST['httpsname'])) { $input_errors[] = "The HTTPS server name must be specified for HTTPS login."; } } } if ($_POST['timeout'] && (!is_numeric($_POST['timeout']) || ($_POST['timeout'] < 1))) { $input_errors[] = "The timeout must be at least 1 minute."; } if ($_POST['idletimeout'] && (!is_numeric($_POST['idletimeout']) || ($_POST['idletimeout'] < 1))) { $input_errors[] = "The idle timeout must be at least 1 minute."; } if (($_POST['radiusip'] && !is_ipaddr($_POST['radiusip']))) { $input_errors[] = "A valid IP address must be specified. [".$_POST['radiusip']."]"; } if (($_POST['radiusport'] && !is_port($_POST['radiusport']))) { $input_errors[] = "A valid port number must be specified. [".$_POST['radiusport']."]"; } if (($_POST['radiusacctport'] && !is_port($_POST['radiusacctport']))) { $input_errors[] = "A valid port number must be specified. [".$_POST['radiusport']."]"; } if (!$input_errors) { $config['captiveportal']['interface'] = $_POST['cinterface']; $config['captiveportal']['timeout'] = $_POST['timeout']; $config['captiveportal']['idletimeout'] = $_POST['idletimeout']; $config['captiveportal']['enable'] = $_POST['enable'] ? true : false; $config['captiveportal']['auth_method'] = $_POST['auth_method']; $config['captiveportal']['radacct_enable'] = $_POST['radacct_enable'] ? true : false; $config['captiveportal']['httpslogin'] = $_POST['httpslogin_enable'] ? true : false; $config['captiveportal']['httpsname'] = $_POST['httpsname']; $config['captiveportal']['certificate'] = base64_encode($_POST['cert']); $config['captiveportal']['private-key'] = base64_encode($_POST['key']); $config['captiveportal']['logoutwin_enable'] = $_POST['logoutwin_enable'] ? true : false; $config['captiveportal']['peruserbw'] = $_POST['peruserbw'] ? true : false; $config['captiveportal']['bwauthmacup'] = $_POST['bwauthmacup']; $config['captiveportal']['bwauthmacdn'] = $_POST['bwauthmacdn']; $config['captiveportal']['bwauthipup'] = $_POST['bwauthipup']; $config['captiveportal']['bwauthipdn'] = $_POST['bwauthipdn']; $config['captiveportal']['bwdefaultup'] = $_POST['bwdefaultup']; $config['captiveportal']['bwdefaultdn'] = $_POST['bwdefaultdn']; $config['captiveportal']['nomacfilter'] = $_POST['nomacfilter'] ? true : false; $config['captiveportal']['redirurl'] = $_POST['redirurl']; $config['captiveportal']['radiusip'] = $_POST['radiusip']; $config['captiveportal']['radiusport'] = $_POST['radiusport']; $config['captiveportal']['radiusacctport'] = $_POST['radiusacctport']; $config['captiveportal']['radiuskey'] = $_POST['radiuskey']; /* file upload? */ if (is_uploaded_file($_FILES['htmlfile']['tmp_name'])) $config['captiveportal']['page']['htmltext'] = base64_encode(file_get_contents($_FILES['htmlfile']['tmp_name'])); if (is_uploaded_file($_FILES['errfile']['tmp_name'])) $config['captiveportal']['page']['errtext'] = base64_encode(file_get_contents($_FILES['errfile']['tmp_name'])); write_config(); $retval = 0; if (!file_exists($d_sysrebootreqd_path)) { config_lock(); $retval = captiveportal_configure(); config_unlock(); } $savemsg = get_std_save_message($retval); } } ?> <?=gentitle("pfSense webGUI");?>
  onClick="enable_change(false)"> Enable captive portal
Interface
Choose which interface to run the captive portal on.
Idle timeout minutes
Clients will be disconnected after this amount of inactivity. They may log in again immediately, though. Leave this field blank for no idle timeout.
Hard timeout minutes
Clients will be disconnected after this amount of time, regardless of activity. They may log in again immediately, though. Leave this field blank for no hard timeout (not recommended unless an idle timeout is set).
Logout popup window > Enable logout popup window
If enabled, a popup window will appear when clients are allowed through the captive portal. This allows clients to explicitly disconnect themselves before the idle or hard timeout occurs. When RADIUS accounting is enabled, this option is implied.
Redirection URL
If you provide a URL here, clients will be redirected to that URL instead of the one they initially tried to access after they've authenticated.
MAC filtering > Disable MAC filtering
If this option is set, no attempts will be made to ensure that the MAC address of clients stays the same while they're logged in. This is required when the MAC address cannot be determined (usually because there are routers between m0n0wall and the clients).
Per-user bandwidth restriction onClick="enable_peruserbw()"> Enable per-user bandwidth restriction

Pass-through MAC download   Kbit/s
Pass-through MAC upload Kbit/s
Pass-through IP download Kbit/s
Pass-through IP upload Kbit/s
Default download Kbit/s
Default upload Kbit/s

If this option is set, the captive portal will restrict each user who logs in to a specific bandwidth as set in RADIUS. Your RADIUS server must return the attributes Nomadix-Bw-Up and Nomadix-Bw-Down (1 and 2 VSAs from Vendor 3309, Nomadix) along with Access-Accept for this to work. Bandwidth is set in Kbit/s. You can control pass-through and default bandwidths above.
RADIUS server
No Authentication:   onClick="auth_method_change()">
Local Usermanager:   onClick="auth_method_change()">
RADIUS Authentication:   onClick="auth_method_change()">
IP address:
Port:
Shared secret:  
Accounting:   onClick="radacct_change()">
Accounting port:  

Enter the IP address and port of the RADIUS server which users of the captive portal have to authenticate against. Leave blank to disable RADIUS authentication. Leave port number blank to use the default port (1812). Leave the RADIUS shared secret blank to not use a RADIUS shared secret. RADIUS accounting packets will also be sent to the RADIUS server if accounting is enabled (default port is 1813).
HTTPS login onClick="enable_https()"> Enable HTTPS login
If enabled, the username and password will be transmitted over an HTTPS connection to protect against eavesdroppers. This option only applies when RADIUS authentication is used. A server name, certificate and matching private key must also be specified below.
HTTPS server name
This name will be used in the form action for the HTTPS POST and should match the Common Name (CN) in your certificate (otherwise, the client browser will most likely display a security warning). Make sure captive portal clients can resolve this name in DNS.
HTTPS certificate
Paste a signed certificate in X.509 PEM format here.
HTTPS private key
Paste an RSA private key in PEM format here.
Portal page contents
View current page

Upload an HTML file for the portal page here (leave blank to keep the current one). Make sure to include a form (POST to "$PORTAL_ACTION$") with a submit button (name="accept") and a hidden field with name="redirurl" and value="$PORTAL_REDIRURL$". Include the "auth_user" and "auth_pass" input elements if RADIUS authentication is enabled. If RADIUS is enabled and no "auth_user" is present, authentication will always fail. If RADIUS is not enabled, you can omit both of these input elements. Example code for the form:

<form method="post" action="$PORTAL_ACTION$">
   <input name="auth_user" type="text">
   <input name="auth_pass" type="password">
   <input name="redirurl" type="hidden" value="$PORTAL_REDIRURL$">
   <input name="accept" type="submit" value="Continue">
</form>
Authentication
error page
contents

View current page

The contents of the HTML file that you upload here are displayed when an authentication error occurs.
 
  Note:
Changing any settings on this page will disconnect all clients! Don't forget to enable the DHCP server on your captive portal interface! Make sure that the default/maximum DHCP lease time is higher than the timeout entered on this page. Also, the DNS forwarder needs to be enabled for DNS lookups by unauthenticated clients to work.