diff options
author | Ermal <eri@pfsense.org> | 2011-09-07 06:42:58 +0000 |
---|---|---|
committer | Ermal <eri@pfsense.org> | 2011-09-07 13:04:01 +0000 |
commit | b4792bf8fe3b1cef416c7135fea88c1a0b08800a (patch) | |
tree | d32a5fb188939e28cd42c92aa9b4cf6729ff4947 /usr | |
parent | 9b55203f878786a2bbd0b7d5dda4474d2533695b (diff) | |
download | pfsense-b4792bf8fe3b1cef416c7135fea88c1a0b08800a.zip pfsense-b4792bf8fe3b1cef416c7135fea88c1a0b08800a.tar.gz |
Add the multi instance CP to master branch. This allows to define CP with different properties on different interfaces.
Diffstat (limited to 'usr')
19 files changed, 963 insertions, 442 deletions
diff --git a/usr/local/captiveportal/index.php b/usr/local/captiveportal/index.php index 1bd9366..9ed509f 100755 --- a/usr/local/captiveportal/index.php +++ b/usr/local/captiveportal/index.php @@ -44,6 +44,9 @@ header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header("Connection: close"); +$cpzone = $_REQUEST['zone']; +$cpcfg = $config['captiveportal'][$cpzone]; + $orig_host = $_ENV['HTTP_HOST']; $orig_request = $_REQUEST['redirurl']; $clientip = $_SERVER['REMOTE_ADDR']; @@ -56,36 +59,36 @@ if (!$clientip) { exit; } -if (isset($config['captiveportal']['httpslogin'])) - $ourhostname = $config['captiveportal']['httpsname'] . ":8001"; +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'] . ":8000"; + $ourhostname = $config['system'][$cpzone]['hostname'] . ":{$cpcfg['zoneid']}"; else - $ourhostname = "{$ifip}:8000"; + $ourhostname = "{$ifip}:{$cpcfg['zoneid']}"; } if ($orig_host != $ourhostname) { /* the client thinks it's connected to the desired web server, but instead it's connected to us. Issue a redirect... */ - if (isset($config['captiveportal']['httpslogin'])) - header("Location: https://{$ourhostname}/index.php?redirurl=" . urlencode("http://{$orig_host}{$orig_request}")); + if (isset($config['captiveportal'][$cpzone]['httpslogin'])) + header("Location: https://{$ourhostname}/index.php?zone={$cpzone}&redirurl=" . urlencode("http://{$orig_host}{$orig_request}")); else - header("Location: http://{$ourhostname}/index.php?redirurl=" . urlencode("http://{$orig_host}{$orig_request}")); + header("Location: http://{$ourhostname}/index.php?zone={$cpzone}&redirurl=" . urlencode("http://{$orig_host}{$orig_request}")); exit; } -if (!empty($config['captiveportal']['redirurl'])) - $redirurl = $config['captiveportal']['redirurl']; +if (!empty($config['captiveportal'][$cpzone]['redirurl'])) + $redirurl = $config['captiveportal'][$cpzone]['redirurl']; else if (preg_match("/redirurl=(.*)/", $orig_request, $matches)) $redirurl = urldecode($matches[1]); else if ($_REQUEST['redirurl']) $redirurl = $_REQUEST['redirurl']; -$macfilter = !isset($config['captiveportal']['nomacfilter']); -$passthrumac = isset($config['captiveportal']['passthrumacadd']); +$macfilter = !isset($config['captiveportal'][$cpzone]['nomacfilter']); +$passthrumac = isset($config['captiveportal'][$cpzone]['passthrumacadd']); /* find MAC address for client */ $clientmac = arp_get_mac_by_ip($clientip); @@ -98,9 +101,9 @@ if (!$clientmac && ($macfilter || $passthrumac)) { } /* find out if we need RADIUS + RADIUSMAC or not */ -if (file_exists("{$g['vardb_path']}/captiveportal_radius.db")) { +if (file_exists("{$g['vardb_path']}/captiveportal_radius_{$cpzone}.db")) { $radius_enable = TRUE; - if (isset($config['captiveportal']['radmac_enable'])) + if (isset($config['captiveportal'][$cpzone]['radmac_enable'])) $radmac_enable = TRUE; } @@ -149,14 +152,14 @@ EOD; // YES: user is good for $timecredit minutes. captiveportal_logportalauth($voucher,$clientmac,$clientip,"Voucher login good for $timecredit min."); } else { - portal_reply_page($redirurl, "error", $config['voucher']['msgexpired'] ? $config['voucher']['msgexpired']: $errormsg); + portal_reply_page($redirurl, "error", $config['voucher'][$cpzone]['msgexpired'] ? $config['voucher'][$cpzone]['msgexpired']: $errormsg); } } else if (-1 == $timecredit) { // valid but expired captiveportal_logportalauth($voucher,$clientmac,$clientip,"FAILURE","voucher expired"); - portal_reply_page($redirurl, "error", $config['voucher']['msgexpired'] ? $config['voucher']['msgexpired']: $errormsg); + portal_reply_page($redirurl, "error", $config['voucher'][$cpzone]['msgexpired'] ? $config['voucher'][$cpzone]['msgexpired']: $errormsg); } else { captiveportal_logportalauth($voucher,$clientmac,$clientip,"FAILURE"); - portal_reply_page($redirurl, "error", $config['voucher']['msgnoaccess'] ? $config['voucher']['msgnoaccess'] : $errormsg); + portal_reply_page($redirurl, "error", $config['voucher'][$cpzone]['msgnoaccess'] ? $config['voucher'][$cpzone]['msgnoaccess'] : $errormsg); } } else if ($_POST['accept'] && $radius_enable) { @@ -182,7 +185,7 @@ EOD; portal_reply_page($redirurl, "error", $errormsg); } -} else if ($_POST['accept'] && $config['captiveportal']['auth_method'] == "local") { +} else if ($_POST['accept'] && $config['captiveportal'][$cpzone]['auth_method'] == "local") { //check against local user manager $loginok = local_backed($_POST['auth_user'], $_POST['auth_pass']); @@ -193,7 +196,7 @@ EOD; captiveportal_logportalauth($_POST['auth_user'],$clientmac,$clientip,"FAILURE"); portal_reply_page($redirurl, "error", $errormsg); } -} else if ($_POST['accept'] && $clientip && $config['captiveportal']['auth_method'] == "none") { +} else if ($_POST['accept'] && $clientip && $config['captiveportal'][$cpzone]['auth_method'] == "none") { captiveportal_logportalauth("unauthenticated",$clientmac,$clientip,"ACCEPT"); portal_allow($clientip, $clientmac, "unauthenticated"); } else { diff --git a/usr/local/captiveportal/radius_accounting.inc b/usr/local/captiveportal/radius_accounting.inc index 704c229..1f24e65 100644 --- a/usr/local/captiveportal/radius_accounting.inc +++ b/usr/local/captiveportal/radius_accounting.inc @@ -51,13 +51,13 @@ PEAR::loadExtension('bcmath'); function RADIUS_ACCOUNTING_START($ruleno, $username, $sessionid, $radiusservers, $clientip, $clientmac) { - global $config; + global $config, $cpzone; $retvalue = array(); $nas_mac = mac_format(get_interface_mac("wan")); $clientmac = mac_format($clientmac); $nas_port = intval($ruleno); - $radiusvendor = $config['captiveportal']['radiusvendor'] ? $config['captiveportal']['radiusvendor'] : null; + $radiusvendor = $config['captiveportal'][$cpzone]['radiusvendor'] ? $config['captiveportal'][$cpzone]['radiusvendor'] : null; switch($radiusvendor) { @@ -67,10 +67,10 @@ function RADIUS_ACCOUNTING_START($ruleno, $username, $sessionid, $radiusservers, break; default: - if (is_ipaddr($config['captiveportal']['radiussrcip_attribute'])) - $calledstationid = $config['captiveportal']['radiussrcip_attribute']; + if (is_ipaddr($config['captiveportal'][$cpzone]['radiussrcip_attribute'])) + $calledstationid = $config['captiveportal'][$cpzone]['radiussrcip_attribute']; else - $calledstationid = get_interface_ip($config['captiveportal']['radiussrcip_attribute']); + $calledstationid = get_interface_ip($config['captiveportal'][$cpzone]['radiussrcip_attribute']); $callingstationid = $clientmac; $callingstationid = $clientmac; } @@ -166,13 +166,13 @@ RADIUS ACCOUNTING STOP/UPDATE function RADIUS_ACCOUNTING_STOP($ruleno,$username,$sessionid,$start_time,$radiusservers,$clientip,$clientmac, $term_cause = 1, $interimupdate=false,$stop_time = null) { - global $config; + global $config, $cpzone; $retvalue = array(); $nas_mac = mac_format(get_interface_mac("wan")); $clientmac = mac_format($clientmac); $nas_port = intval($ruleno); - $radiusvendor = $config['captiveportal']['radiusvendor'] ? $config['captiveportal']['radiusvendor'] : null; + $radiusvendor = $config['captiveportal'][$cpzone]['radiusvendor'] ? $config['captiveportal'][$cpzone]['radiusvendor'] : null; $stop_time = (empty($stop_time)) ? time() : $stop_time; $session_time = $stop_time - $start_time; $volume = getVolume($clientip); diff --git a/usr/local/captiveportal/radius_authentication.inc b/usr/local/captiveportal/radius_authentication.inc index 142ab0e..28802ee 100644 --- a/usr/local/captiveportal/radius_authentication.inc +++ b/usr/local/captiveportal/radius_authentication.inc @@ -48,13 +48,13 @@ RADIUS AUTHENTICATION function RADIUS_AUTHENTICATION($username,$password,$radiusservers,$clientip,$clientmac,$ruleno) { - global $config; + global $config, $cpzone; $retvalue = array(); $nas_mac = mac_format(get_interface_mac(get_real_interface("wan"))); $clientmac = mac_format($clientmac); $nas_port = $ruleno; - $radiusvendor = $config['captiveportal']['radiusvendor'] ? $config['captiveportal']['radiusvendor'] : null; + $radiusvendor = $config['captiveportal'][$cpzone]['radiusvendor'] ? $config['captiveportal'][$cpzone]['radiusvendor'] : null; // Do we even need to set it to NULL? $retvalue['error'] = $retvalue['reply_message'] = $retvalue['url_redirection'] = $retvalue['session_timeout'] = $retvalue['idle_timeout'] = $retvalue['session_terminate_time'] = null; @@ -65,10 +65,10 @@ function RADIUS_AUTHENTICATION($username,$password,$radiusservers,$clientip,$cli $callingstationid = $clientip; break; default: - if (is_ipaddr($config['captiveportal']['radiussrcip_attribute'])) - $calledstationid = $config['captiveportal']['radiussrcip_attribute']; + if (is_ipaddr($config['captiveportal'][$cpzone]['radiussrcip_attribute'])) + $calledstationid = $config['captiveportal'][$cpzone]['radiussrcip_attribute']; else - $calledstationid = get_interface_ip($config['captiveportal']['radiussrcip_attribute']); + $calledstationid = get_interface_ip($config['captiveportal'][$cpzone]['radiussrcip_attribute']); $callingstationid = $clientmac; break; } diff --git a/usr/local/www/services_captiveportal.php b/usr/local/www/services_captiveportal.php index 2f1db79..a54c697 100755 --- a/usr/local/www/services_captiveportal.php +++ b/usr/local/www/services_captiveportal.php @@ -47,65 +47,87 @@ require("filter.inc"); require("shaper.inc"); require("captiveportal.inc"); -$pgtitle = array(gettext("Services"),gettext("Captive portal")); +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) + $cpzone = $_POST['zone']; -if (!is_array($config['captiveportal'])) { - $config['captiveportal'] = array(); - $config['captiveportal']['page'] = array(); - $config['captiveportal']['timeout'] = 60; +if (empty($cpzone)) { + header("Location: services_captiveportal_zones.php"); + exit; } +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; + +$pgtitle = array(gettext("Services"),gettext("Captive portal"), $a_cp[$cpzone]['zone']); + if ($_GET['act'] == "viewhtml") { - echo base64_decode($config['captiveportal']['page']['htmltext']); + if (isset($cpzone) && $a_cp[$cpzone]) + echo base64_decode($pconfig['page']['htmltext']); exit; } else if ($_GET['act'] == "viewerrhtml") { - echo base64_decode($config['captiveportal']['page']['errtext']); + if (isset($cpzone) && $a_cp[$cpzone]) + echo base64_decode($pconfig['page']['errtext']); exit; } else if ($_GET['act'] == "viewlogouthtml") { - echo base64_decode($config['captiveportal']['page']['logouttext']); + if (isset($cpzone) && $a_cp[$cpzone]) + echo base64_decode($pconfig['page']['logouttext']); exit; } -$pconfig['cinterface'] = $config['captiveportal']['interface']; -$pconfig['maxprocperip'] = $config['captiveportal']['maxprocperip']; -$pconfig['timeout'] = $config['captiveportal']['timeout']; -$pconfig['idletimeout'] = $config['captiveportal']['idletimeout']; -$pconfig['freelogins_count'] = $config['captiveportal']['freelogins_count']; -$pconfig['freelogins_resettimeout'] = $config['captiveportal']['freelogins_resettimeout']; -$pconfig['freelogins_updatetimeouts'] = isset($config['captiveportal']['freelogins_updatetimeouts']); -$pconfig['enable'] = isset($config['captiveportal']['enable']); -$pconfig['auth_method'] = $config['captiveportal']['auth_method']; -$pconfig['radacct_enable'] = isset($config['captiveportal']['radacct_enable']); -$pconfig['radmac_enable'] = isset($config['captiveportal']['radmac_enable']); -$pconfig['radmac_secret'] = $config['captiveportal']['radmac_secret']; -$pconfig['reauthenticate'] = isset($config['captiveportal']['reauthenticate']); -$pconfig['reauthenticateacct'] = $config['captiveportal']['reauthenticateacct']; -$pconfig['httpslogin_enable'] = isset($config['captiveportal']['httpslogin']); -$pconfig['httpsname'] = $config['captiveportal']['httpsname']; -$pconfig['preauthurl'] = strtolower($config['captiveportal']['preauthurl']); -$pconfig['cert'] = base64_decode($config['captiveportal']['certificate']); -$pconfig['cacert'] = base64_decode($config['captiveportal']['cacertificate']); -$pconfig['key'] = base64_decode($config['captiveportal']['private-key']); -$pconfig['logoutwin_enable'] = isset($config['captiveportal']['logoutwin_enable']); -$pconfig['peruserbw'] = isset($config['captiveportal']['peruserbw']); -$pconfig['bwdefaultdn'] = $config['captiveportal']['bwdefaultdn']; -$pconfig['bwdefaultup'] = $config['captiveportal']['bwdefaultup']; -$pconfig['nomacfilter'] = isset($config['captiveportal']['nomacfilter']); -$pconfig['noconcurrentlogins'] = isset($config['captiveportal']['noconcurrentlogins']); -$pconfig['redirurl'] = $config['captiveportal']['redirurl']; -$pconfig['radiusip'] = $config['captiveportal']['radiusip']; -$pconfig['radiusip2'] = $config['captiveportal']['radiusip2']; -$pconfig['radiusport'] = $config['captiveportal']['radiusport']; -$pconfig['radiusport2'] = $config['captiveportal']['radiusport2']; -$pconfig['radiusacctport'] = $config['captiveportal']['radiusacctport']; -$pconfig['radiuskey'] = $config['captiveportal']['radiuskey']; -$pconfig['radiuskey2'] = $config['captiveportal']['radiuskey2']; -$pconfig['radiusvendor'] = $config['captiveportal']['radiusvendor']; -$pconfig['radiussession_timeout'] = isset($config['captiveportal']['radiussession_timeout']); -$pconfig['radiussrcip_attribute'] = $config['captiveportal']['radiussrcip_attribute']; -$pconfig['passthrumacadd'] = isset($config['captiveportal']['passthrumacadd']); -$pconfig['passthrumacaddusername'] = isset($config['captiveportal']['passthrumacaddusername']); -$pconfig['radmac_format'] = $config['captiveportal']['radmac_format']; +if (isset($cpzone) && $a_cp[$cpzone]) { + $pconfig['zoneid'] = $a_cp[$cpzone]['zoneid']; + $pconfig['cinterface'] = $a_cp[$cpzone]['interface']; + $pconfig['maxproc'] = $a_cp[$cpzone]['maxproc']; + $pconfig['maxprocperip'] = $a_cp[$cpzone]['maxprocperip']; + $pconfig['timeout'] = $a_cp[$cpzone]['timeout']; + $pconfig['idletimeout'] = $a_cp[$cpzone]['idletimeout']; + $pconfig['freelogins_count'] = $a_cp[$cpzone]['freelogins_count']; + $pconfig['freelogins_resettimeout'] = $a_cp[$cpzone]['freelogins_resettimeout']; + $pconfig['freelogins_updatetimeouts'] = isset($a_cp[$cpzone]['freelogins_updatetimeouts']); + $pconfig['enable'] = isset($a_cp[$cpzone]['enable']); + $pconfig['pms_enabled'] = $a_cp[$cpzone]['pms_enabled']; + $pconfig['auth_method'] = $a_cp[$cpzone]['auth_method']; + $pconfig['radacct_enable'] = isset($a_cp[$cpzone]['radacct_enable']); + $pconfig['radmac_enable'] = isset($a_cp[$cpzone]['radmac_enable']); + $pconfig['radmac_secret'] = $a_cp[$cpzone]['radmac_secret']; + $pconfig['reauthenticate'] = isset($a_cp[$cpzone]['reauthenticate']); + $pconfig['reauthenticateacct'] = $a_cp[$cpzone]['reauthenticateacct']; + $pconfig['httpslogin_enable'] = isset($a_cp[$cpzone]['httpslogin']); + $pconfig['httpsname'] = $a_cp[$cpzone]['httpsname']; + $pconfig['preauthurl'] = strtolower($a_cp[$cpzone]['preauthurl']); + $pconfig['cert'] = base64_decode($a_cp[$cpzone]['certificate']); + $pconfig['cacert'] = base64_decode($a_cp[$cpzone]['cacertificate']); + $pconfig['key'] = base64_decode($a_cp[$cpzone]['private-key']); + $pconfig['logoutwin_enable'] = isset($a_cp[$cpzone]['logoutwin_enable']); + $pconfig['peruserbw'] = isset($a_cp[$cpzone]['peruserbw']); + $pconfig['bwdefaultdn'] = $a_cp[$cpzone]['bwdefaultdn']; + $pconfig['bwdefaultup'] = $a_cp[$cpzone]['bwdefaultup']; + $pconfig['nomacfilter'] = isset($a_cp[$cpzone]['nomacfilter']); + $pconfig['noconcurrentlogins'] = isset($a_cp[$cpzone]['noconcurrentlogins']); + $pconfig['redirurl'] = $a_cp[$cpzone]['redirurl']; + $pconfig['radiusip'] = $a_cp[$cpzone]['radiusip']; + $pconfig['radiusip2'] = $a_cp[$cpzone]['radiusip2']; + $pconfig['radiusport'] = $a_cp[$cpzone]['radiusport']; + $pconfig['radiusport2'] = $a_cp[$cpzone]['radiusport2']; + $pconfig['radiusacctport'] = $a_cp[$cpzone]['radiusacctport']; + $pconfig['radiuskey'] = $a_cp[$cpzone]['radiuskey']; + $pconfig['radiuskey2'] = $a_cp[$cpzone]['radiuskey2']; + $pconfig['radiusvendor'] = $a_cp[$cpzone]['radiusvendor']; + $pconfig['radiussession_timeout'] = isset($a_cp[$cpzone]['radiussession_timeout']); + $pconfig['radiussrcip_attribute'] = $a_cp[$cpzone]['radiussrcip_attribute']; + $pconfig['passthrumacadd'] = isset($a_cp[$cpzone]['passthrumacadd']); + $pconfig['passthrumacaddusername'] = isset($a_cp[$cpzone]['passthrumacaddusername']); + $pconfig['radmac_format'] = $a_cp[$cpzone]['radmac_format']; + $pconfig['page'] = array(); + if ($a_cp[$cpzone]['page']['htmltext']) + $pconfig['page']['htmltext'] = $a_cp[$cpzone]['page']['htmltext']; + if ($a_cp[$cpzone]['page']['errtext']) + $pconfig['page']['errtext'] = $a_cp[$cpzone]['page']['errtext']; + if ($a_cp[$cpzone]['page']['logouttext']) + $pconfig['page']['logouttext'] = $a_cp[$cpzone]['page']['logouttext']; +} if ($_POST) { @@ -114,16 +136,24 @@ if ($_POST) { /* input validation */ if ($_POST['enable']) { - $reqdfields = explode(" ", "cinterface"); - $reqdfieldsn = array(gettext("Interface")); + $reqdfields = explode(" ", "zone cinterface"); + $reqdfieldsn = array(gettext("Zone name"), gettext("Interface")); do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); - /* make sure no interfaces are bridged */ - if (is_array($_POST['cinterface'])) - foreach ($pconfig['cinterface'] as $cpbrif) + /* make sure no interfaces are bridged or used on other zones */ + if (is_array($_POST['cinterface'])) { + foreach ($pconfig['cinterface'] as $cpbrif) { if (link_interface_to_bridge($cpbrif)) $input_errors[] = sprintf(gettext("The captive portal cannot be used on interface %s since it is part of a bridge."), $cpbrif); + foreach ($a_cp as $cpkey => $cp) { + if ($cpkey != $cpzone || empty($cpzone)) { + if (in_array($cpbrif, explode(",", $cp['interface']))) + $input_errors[] = sprintf(gettext("The captive portal cannot be used on interface %s since it is used already on %s instance."), $cpbrif, $cp['zone']); + } + } + } + } if ($_POST['httpslogin_enable']) { if (!$_POST['cert'] || !$_POST['key']) { @@ -171,72 +201,110 @@ if ($_POST) { if (($_POST['radiusacctport'] && !is_port($_POST['radiusacctport']))) { $input_errors[] = sprintf(gettext("A valid port number must be specified. [%s]"), $_POST['radiusacctport']); } - if ($_POST['maxprocperip'] && (!is_numeric($_POST['maxprocperip']) || ($_POST['maxprocperip'] < 4) || $_POST['maxprocperip'] > 100)) { + if ($_POST['maxproc'] && (!is_numeric($_POST['maxproc']) || ($_POST['maxproc'] < 4) || ($_POST['maxproc'] > 100))) { + $input_errors[] = gettext("The total maximum number of concurrent connections must be between 4 and 100."); + } + $mymaxproc = $_POST['maxproc'] ? $_POST['maxproc'] : 16; + if ($_POST['maxprocperip'] && (!is_numeric($_POST['maxprocperip']) || ($_POST['maxprocperip'] > $mymaxproc))) { $input_errors[] = gettext("The maximum number of concurrent connections per client IP address may not be larger than the global maximum."); } if (!$input_errors) { + $newcp =& $a_cp[$cpzone]; + //$newcp['zoneid'] = $a_cp[$cpzone]['zoneid']; + if (empty($newcp['zoneid'])) { + $newcp['zoneid'] = 8000; + foreach ($a_cp as $keycpzone => $cp) + if ($cp['zoneid'] == $newcp['zoneid'] && $keycpzone != $cpzone) + $newcp['zoneid'] += 2; /* Resreve space for SSL config if needed */ + } + $oldifaces = $newcp['interface']; if (is_array($_POST['cinterface'])) - $config['captiveportal']['interface'] = implode(",", $_POST['cinterface']); - $config['captiveportal']['maxprocperip'] = $_POST['maxprocperip'] ? $_POST['maxprocperip'] : false; - $config['captiveportal']['timeout'] = $_POST['timeout']; - $config['captiveportal']['idletimeout'] = $_POST['idletimeout']; - $config['captiveportal']['freelogins_count'] = $_POST['freelogins_count']; - $config['captiveportal']['freelogins_resettimeout'] = $_POST['freelogins_resettimeout']; - $config['captiveportal']['freelogins_updatetimeouts'] = $_POST['freelogins_updatetimeouts'] ? true : false; - $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']['reauthenticate'] = $_POST['reauthenticate'] ? true : false; - $config['captiveportal']['radmac_enable'] = $_POST['radmac_enable'] ? true : false; - $config['captiveportal']['radmac_secret'] = $_POST['radmac_secret'] ? $_POST['radmac_secret'] : false; - $config['captiveportal']['reauthenticateacct'] = $_POST['reauthenticateacct']; - $config['captiveportal']['httpslogin'] = $_POST['httpslogin_enable'] ? true : false; - $config['captiveportal']['httpsname'] = $_POST['httpsname']; - $config['captiveportal']['preauthurl'] = $_POST['preauthurl']; - $config['captiveportal']['peruserbw'] = $_POST['peruserbw'] ? true : false; - $config['captiveportal']['bwdefaultdn'] = $_POST['bwdefaultdn']; - $config['captiveportal']['bwdefaultup'] = $_POST['bwdefaultup']; - $config['captiveportal']['certificate'] = base64_encode($_POST['cert']); - $config['captiveportal']['cacertificate'] = base64_encode($_POST['cacert']); - $config['captiveportal']['private-key'] = base64_encode($_POST['key']); - $config['captiveportal']['logoutwin_enable'] = $_POST['logoutwin_enable'] ? true : false; - $config['captiveportal']['nomacfilter'] = $_POST['nomacfilter'] ? true : false; - $config['captiveportal']['noconcurrentlogins'] = $_POST['noconcurrentlogins'] ? true : false; - $config['captiveportal']['redirurl'] = $_POST['redirurl']; - $config['captiveportal']['radiusip'] = $_POST['radiusip']; - $config['captiveportal']['radiusip2'] = $_POST['radiusip2']; - $config['captiveportal']['radiusport'] = $_POST['radiusport']; - $config['captiveportal']['radiusport2'] = $_POST['radiusport2']; - $config['captiveportal']['radiusacctport'] = $_POST['radiusacctport']; - $config['captiveportal']['radiuskey'] = $_POST['radiuskey']; - $config['captiveportal']['radiuskey2'] = $_POST['radiuskey2']; - $config['captiveportal']['radiusvendor'] = $_POST['radiusvendor'] ? $_POST['radiusvendor'] : false; - $config['captiveportal']['radiussession_timeout'] = $_POST['radiussession_timeout'] ? true : false; - $config['captiveportal']['radiussrcip_attribute'] = $_POST['radiussrcip_attribute']; - $config['captiveportal']['passthrumacadd'] = $_POST['passthrumacadd'] ? true : false; - $config['captiveportal']['passthrumacaddusername'] = $_POST['passthrumacaddusername'] ? true : false; - $config['captiveportal']['radmac_format'] = $_POST['radmac_format'] ? $_POST['radmac_format'] : false; + $newcp['interface'] = implode(",", $_POST['cinterface']); + $newcp['maxproc'] = $_POST['maxproc']; + $newcp['maxprocperip'] = $_POST['maxprocperip'] ? $_POST['maxprocperip'] : false; + $newcp['timeout'] = $_POST['timeout']; + $newcp['idletimeout'] = $_POST['idletimeout']; + $newcp['freelogins_count'] = $_POST['freelogins_count']; + $newcp['freelogins_resettimeout'] = $_POST['freelogins_resettimeout']; + $newcp['freelogins_updatetimeouts'] = $_POST['freelogins_updatetimeouts'] ? true : false; + if ($_POST['enable']) + $newcp['enable'] = true; + else + unset($newcp['enable']); + if ($_POST['pms_enabled']) + $newcp['pms_enabled'] = $_POST['pms_enabled']; + else + unset($newcp['pms_enabled']); + $newcp['auth_method'] = $_POST['auth_method']; + $newcp['radacct_enable'] = $_POST['radacct_enable'] ? true : false; + $newcp['reauthenticate'] = $_POST['reauthenticate'] ? true : false; + $newcp['radmac_enable'] = $_POST['radmac_enable'] ? true : false; + $newcp['radmac_secret'] = $_POST['radmac_secret'] ? $_POST['radmac_secret'] : false; + $newcp['reauthenticateacct'] = $_POST['reauthenticateacct']; + $newcp['httpslogin'] = $_POST['httpslogin_enable'] ? true : false; + $newcp['httpsname'] = $_POST['httpsname']; + $newcp['preauthurl'] = $_POST['preauthurl']; + $newcp['peruserbw'] = $_POST['peruserbw'] ? true : false; + $newcp['bwdefaultdn'] = $_POST['bwdefaultdn']; + $newcp['bwdefaultup'] = $_POST['bwdefaultup']; + $newcp['certificate'] = base64_encode($_POST['cert']); + $newcp['cacertificate'] = base64_encode($_POST['cacert']); + $newcp['private-key'] = base64_encode($_POST['key']); + $newcp['logoutwin_enable'] = $_POST['logoutwin_enable'] ? true : false; + $newcp['nomacfilter'] = $_POST['nomacfilter'] ? true : false; + $newcp['noconcurrentlogins'] = $_POST['noconcurrentlogins'] ? true : false; + $newcp['redirurl'] = $_POST['redirurl']; + $newcp['radiusip'] = $_POST['radiusip']; + $newcp['radiusip2'] = $_POST['radiusip2']; + $newcp['radiusport'] = $_POST['radiusport']; + $newcp['radiusport2'] = $_POST['radiusport2']; + $newcp['radiusacctport'] = $_POST['radiusacctport']; + $newcp['radiuskey'] = $_POST['radiuskey']; + $newcp['radiuskey2'] = $_POST['radiuskey2']; + $newcp['radiusvendor'] = $_POST['radiusvendor'] ? $_POST['radiusvendor'] : false; + $newcp['radiussession_timeout'] = $_POST['radiussession_timeout'] ? true : false; + $newcp['radiussrcip_attribute'] = $_POST['radiussrcip_attribute']; + $newcp['passthrumacadd'] = $_POST['passthrumacadd'] ? true : false; + $newcp['passthrumacaddusername'] = $_POST['passthrumacaddusername'] ? true : false; + $newcp['radmac_format'] = $_POST['radmac_format'] ? $_POST['radmac_format'] : false; + if (!is_array($newcp['page'])) + $newcp['page'] = array(); + $newcp['timeout'] = 60; /* file upload? */ if (is_uploaded_file($_FILES['htmlfile']['tmp_name'])) - $config['captiveportal']['page']['htmltext'] = base64_encode(file_get_contents($_FILES['htmlfile']['tmp_name'])); + $newcp['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'])); + $newcp['page']['errtext'] = base64_encode(file_get_contents($_FILES['errfile']['tmp_name'])); if (is_uploaded_file($_FILES['logoutfile']['tmp_name'])) - $config['captiveportal']['page']['logouttext'] = base64_encode(file_get_contents($_FILES['logoutfile']['tmp_name'])); + $newcp['page']['logouttext'] = base64_encode(file_get_contents($_FILES['logoutfile']['tmp_name'])); write_config(); - $retval = 0; - $retval = captiveportal_configure(); + if (!empty($oldifaces) && $oldifaces != $newcp['interface']) { + $ocpinterfaces = explode(",", $oldifaces); + foreach ($ocpinterfaces as $cpifgrp) { + $listrealif = get_real_interface($cpifgrp); + if (does_interface_exist($listrealif)) { + pfSense_interface_flags($listrealif, -IFF_IPFW_FILTER); + $carpif = link_ip_to_carp_interface(find_interface_ip($listrealif)); + if (!empty($carpif)) { + $carpsif = explode(" ", $carpif); + foreach ($carpsif as $cpcarp) + pfSense_interface_flags($cpcarp, -IFF_IPFW_FILTER); + } + } + } + } - $savemsg = get_std_save_message($retval); - + captiveportal_configure_zone($newcp); + filter_configure(); + header("Location: services_captiveportal_zones.php"); + exit; + } else { if (is_array($_POST['cinterface'])) $pconfig['cinterface'] = implode(",", $_POST['cinterface']); - - filter_configure(); } } include("head.inc"); @@ -250,6 +318,7 @@ function enable_change(enable_change) { radius_endis = !((!endis && document.iform.auth_method[2].checked) || enable_change); document.iform.cinterface.disabled = endis; + //document.iform.maxproc.disabled = endis; document.iform.maxprocperip.disabled = endis; document.iform.idletimeout.disabled = endis; document.iform.freelogins_count.disabled = endis; @@ -272,6 +341,7 @@ function enable_change(enable_change) { document.iform.auth_method[0].disabled = endis; document.iform.auth_method[1].disabled = endis; document.iform.auth_method[2].disabled = endis; + document.iform.auth_method[3].disabled = endis; document.iform.radmac_enable.disabled = radius_endis; document.iform.httpslogin_enable.disabled = endis; document.iform.radmac_format.disabled = radius_endis; @@ -308,12 +378,12 @@ function enable_change(enable_change) { <tr><td class="tabnavtbl"> <?php $tab_array = array(); - $tab_array[] = array(gettext("Captive portal"), true, "services_captiveportal.php"); - $tab_array[] = array(gettext("Pass-through MAC"), false, "services_captiveportal_mac.php"); - $tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php"); - $tab_array[] = array(gettext("Allowed Hostnames"), false, "services_captiveportal_hostname.php"); - $tab_array[] = array(gettext("Vouchers"), false, "services_captiveportal_vouchers.php"); - $tab_array[] = array(gettext("File Manager"), false, "services_captiveportal_filemanager.php"); + $tab_array[] = array(gettext("Captive portal(s)"), true, "services_captiveportal.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Pass-through MAC"), false, "services_captiveportal_mac.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Allowed Hostnames"), false, "services_captiveportal_hostname.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Vouchers"), false, "services_captiveportal_vouchers.php?zone={$cpzone}"); + $tab_array[] = array(gettext("File Manager"), false, "services_captiveportal_filemanager.php?zone={$cpzone}"); display_top_tabs($tab_array, true); ?> </td></tr> <tr> @@ -344,8 +414,7 @@ function enable_change(enable_change) { <td class="vtable"> <table cellpadding="0" cellspacing="0"> <tr> - <td><input name="maxprocperip" type="text" class="formfld unknown" id="maxprocperip" size="5" -value="<?=htmlspecialchars($pconfig['maxprocperip']);?>"> <?=gettext("per client IP address (0 = no limit)"); ?></td> + <td><input name="maxprocperip" type="text" class="formfld unknown" id="maxprocperip" size="5" value="<?=htmlspecialchars($pconfig['maxprocperip']);?>"> <?=gettext("per client IP address (0 = no limit)"); ?></td> </tr> </table> <?=gettext("This setting limits the number of concurrent connections to the captive portal HTTP(S) server. This does not set how many users can be logged in " . @@ -458,6 +527,14 @@ value="<?=htmlspecialchars($pconfig['maxprocperip']);?>"> <?=gettext("per client <?=gettext("If this option is set, the captive portal will restrict each user who logs in to the specified default bandwidth. RADIUS can override the default settings. Leave empty or set to 0 for no limit."); ?> </td> </tr> <tr> + <td valign="top" class="vncell"><?=gettext("PMS authentication"); ?> </td> + <td class="vtable"> + <input name="pms_enabled" type="checkbox" class="formfld" id="pms_enabled" value="yes" <?php if ($pconfig['pms_enabled']) echo "checked"; ?>> + <strong><?=gettext("Enable PMS authentication"); ?></strong><br> + <?=gettext("If this option is set, users will be authenticated through the PMS backend if they fill the necessary information in the login page.");?> + </td> + </tr> + <tr> <td width="22%" valign="top" class="vncell"><?=gettext("Authentication"); ?></td> <td width="78%" class="vtable"> <table cellpadding="0" cellspacing="0"> @@ -586,8 +663,8 @@ value="<?=htmlspecialchars($pconfig['maxprocperip']);?>"> <?=gettext("per client $ipaddr = get_interface_ip($ifdesc); if (is_ipaddr($ipaddr)) { $selected = ""; - if ($ifdesc == $pconfig['radiussrcip_attribute']) - $selected = "selected"; + if ($ipaddr == $pconfig['radiussrcip_attribute']) + $ifdesc = "selected"; echo "<option value='{$ifdesc}' {$selected}>{$ifdescr} - {$ipaddr}</option>\n"; } } @@ -695,18 +772,18 @@ value="<?=htmlspecialchars($pconfig['maxprocperip']);?>"> <?=gettext("per client <?=gettext("Paste a certificate in X.509 PEM format here."); ?></td> </tr> <tr> - <td width="22%" valign="top" class="vncellreq"><?=gettext("Portal page contents"); ?></td> + <td width="22%" valign="top" class="vncell"><?=gettext("Portal page contents"); ?></td> <td width="78%" class="vtable"> <?=$mandfldhtml;?><input type="file" name="htmlfile" class="formfld file" id="htmlfile"><br> <?php list($host) = explode(":", $_SERVER['HTTP_HOST']); - if(isset($config['captiveportal']['httpslogin'])) { - $href = "https://$host:8001"; + if($pconfig['zoneid']) { + $href = "https://{$host}:{$pconfig['zoneid']}"; } else { - $href = "http://$host:8000"; + $href = "http://{$host}:8000"; } ?> - <?php if ($config['captiveportal']['page']['htmltext']): ?> + <?php if ($pconfig['page']['htmltext']): ?> <a href="<?=$href?>" target="_new"><?=gettext("View current page"); ?></a> <br> <br> @@ -740,7 +817,7 @@ value="<?=htmlspecialchars($pconfig['maxprocperip']);?>"> <?=gettext("per client <?=gettext("contents"); ?></td> <td class="vtable"> <input name="errfile" type="file" class="formfld file" id="errfile"><br> - <?php if ($config['captiveportal']['page']['errtext']): ?> + <?php if ($pconfig['page']['errtext']): ?> <a href="?act=viewerrhtml" target="_blank"><?=gettext("View current page"); ?></a> <br> <br> @@ -754,7 +831,7 @@ value="<?=htmlspecialchars($pconfig['maxprocperip']);?>"> <?=gettext("per client <?=gettext("contents"); ?></td> <td class="vtable"> <input name="logoutfile" type="file" class="formfld file" id="logoutfile"><br> - <?php if ($config['captiveportal']['page']['logouttext']): ?> + <?php if ($pconfig['page']['logouttext']): ?> <a href="?act=viewlogouthtml" target="_blank"><?=gettext("View current page"); ?></a> <br> <br> @@ -764,7 +841,9 @@ value="<?=htmlspecialchars($pconfig['maxprocperip']);?>"> <?=gettext("per client <tr> <td width="22%" valign="top"> </td> <td width="78%"> + <?php echo "<input name='zone' id='zone' type='hidden' value='{$cpzone}'/>"; ?> <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onClick="enable_change(true)"> + <a href="services_captiveportal_zones.php"><input name="Cancel" type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onClick="enable_change(true)"></a> </td> </tr> <tr> @@ -785,4 +864,3 @@ enable_change(false); <?php include("fend.inc"); ?> </body> </html> - diff --git a/usr/local/www/services_captiveportal_filemanager.php b/usr/local/www/services_captiveportal_filemanager.php index 7bc61ec..2aa2329 100755 --- a/usr/local/www/services_captiveportal_filemanager.php +++ b/usr/local/www/services_captiveportal_filemanager.php @@ -44,9 +44,9 @@ function cpelementscmp($a, $b) { } function cpelements_sort() { - global $config; + global $config, $cpzone; - usort($config['captiveportal']['element'],"cpelementscmp"); + usort($config['captiveportal'][$cpzone]['element'],"cpelementscmp"); } $statusurl = "status_captiveportal.php"; @@ -59,12 +59,24 @@ require("filter.inc"); require("shaper.inc"); require("captiveportal.inc"); -$pgtitle = array(gettext("Services"),gettext("Captive portal")); +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) + $cpzone = $_POST['zone']; + +if (empty($cpzone)) { + header("Location: services_captiveportal_zones.php"); + exit; +} + +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; -if (!is_array($config['captiveportal']['element'])) - $config['captiveportal']['element'] = array(); +$pgtitle = array(gettext("Services"),gettext("Captive portal"), $a_cp[$cpzone]['zone']); -$a_element = &$config['captiveportal']['element']; +if (!is_array($a_cp[$cpzone]['element'])) + $a_cp[$cpzone]['element'] = array(); +$a_element =& $a_cp[$cpzone]['element']; // Calculate total size of all files $total_size = 0; @@ -108,21 +120,19 @@ if ($_POST) { write_config(); captiveportal_write_elements(); - header("Location: services_captiveportal_filemanager.php"); + header("Location: services_captiveportal_filemanager.php?zone={$cpzone}"); exit; } } -} else { - if (($_GET['act'] == "del") && $a_element[$_GET['id']]) { - conf_mount_rw(); - unlink_if_exists($g['captiveportal_path'] . "/" . $a_element[$id]['name']); - unset($a_element[$_GET['id']]); - write_config(); - captiveportal_write_elements(); - conf_mount_ro(); - header("Location: services_captiveportal_filemanager.php"); - exit; - } +} else if (($_GET['act'] == "del") && !empty($cpzone) && $a_element[$_GET['id']]) { + conf_mount_rw(); + unlink_if_exists($g['captiveportal_path'] . "/" . $a_element[$id]['name']); + unset($a_element[$_GET['id']]); + write_config(); + captiveportal_write_elements(); + conf_mount_ro(); + header("Location: services_captiveportal_filemanager.php?zone={$cpzone}"); + exit; } include("head.inc"); @@ -131,17 +141,18 @@ include("head.inc"); <?php include("fbegin.inc"); ?> <body link="#0000CC" vlink="#0000CC" alink="#0000CC"> <form action="services_captiveportal_filemanager.php" method="post" enctype="multipart/form-data" name="iform" id="iform"> +<input type="hidden" name="zone" id="zone" value="<?=$cpzone;?>" /> <?php if ($input_errors) print_input_errors($input_errors); ?> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr><td class="tabnavtbl"> <?php $tab_array = array(); - $tab_array[] = array(gettext("Captive portal"), false, "services_captiveportal.php"); - $tab_array[] = array(gettext("Pass-through MAC"), false, "services_captiveportal_mac.php"); - $tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php"); - $tab_array[] = array(gettext("Allowed Hostnames"), false, "services_captiveportal_hostname.php"); - $tab_array[] = array(gettext("Vouchers"), false, "services_captiveportal_vouchers.php"); - $tab_array[] = array(gettext("File Manager"), true, "services_captiveportal_filemanager.php"); + $tab_array[] = array(gettext("Captive portal"), false, "services_captiveportal.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Pass-through MAC"), false, "services_captiveportal_mac.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Allowed Hostnames"), false, "services_captiveportal_hostname.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Vouchers"), false, "services_captiveportal_vouchers.php?zone={$cpzone}"); + $tab_array[] = array(gettext("File Manager"), true, "services_captiveportal_filemanager.php?zone={$cpzone}"); display_top_tabs($tab_array, true); ?> </td></tr> <tr> @@ -154,22 +165,23 @@ include("head.inc"); <table border="0" cellspacing="0" cellpadding="1"> <tr> <td width="17" heigth="17"></td> - <td><a href="services_captiveportal_filemanager.php?act=add"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add file"); ?>" width="17" height="17" border="0"></a></td> + <td><a href="services_captiveportal_filemanager.php?zone=<?=$cpzone;?>&act=add"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add file"); ?>" width="17" height="17" border="0"></a></td> </tr> </table> </td> </tr> - <?php $i = 0; foreach ($a_element as $element): ?> +<?php if (is_array($a_cp[$cpzone]['element'])): + $i = 0; foreach ($a_cp[$cpzone]['element'] as $element): ?> <tr> <td class="listlr"><?=htmlspecialchars($element['name']);?></td> <td class="listr" align="right"><?=format_bytes($element['size']);?></td> <td valign="middle" nowrap class="list"> - <a href="services_captiveportal_filemanager.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this file?"); ?>')"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete file"); ?>" width="17" height="17" border="0"></a> + <a href="services_captiveportal_filemanager.php?zone=<?=$cpzone;?>&act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this file?"); ?>')"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete file"); ?>" width="17" height="17" border="0"></a> </td> </tr> - <?php $i++; endforeach; ?> + <?php $i++; endforeach; endif; ?> - <?php if (count($a_element) > 0): ?> + <?php if ($total_size > 0): ?> <tr> <td class="listlr" style="background-color: #eee"><strong><?=gettext("TOTAL"); ?></strong></td> <td class="listr" style="background-color: #eee" align="right"><strong><?=format_bytes($total_size);?></strong></td> @@ -182,7 +194,7 @@ include("head.inc"); <td class="listlr" colspan="2"><input type="file" name="new" class="formfld file" size="40" id="new"> <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Upload"); ?>"></td> <td valign="middle" nowrap class="list"> - <a href="services_captiveportal_filemanager.php"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("cancel"); ?>" width="17" height="17" border="0"></a> + <a href="services_captiveportal_filemanager.php?zone=<?=$cpzone;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("cancel"); ?>" width="17" height="17" border="0"></a> </td> </tr> <?php else: ?> @@ -192,7 +204,7 @@ include("head.inc"); <table border="0" cellspacing="0" cellpadding="1"> <tr> <td width="17" heigth="17"></td> - <td><a href="services_captiveportal_filemanager.php?act=add"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add file"); ?>" width="17" height="17" border="0"></a></td> + <td><a href="services_captiveportal_filemanager.php?zone=<?=$cpzone;?>&act=add"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add file"); ?>" width="17" height="17" border="0"></a></td> </tr> </table> </td> @@ -212,7 +224,7 @@ include("head.inc"); <?=gettext("In addition, you can also upload .php files for execution. You can pass the filename " . "to your custom page from the initial page by using text similar to:"); ?> <br><br> - <tt><a href="/captiveportal-aup.php?redirurl=$PORTAL_REDIRURL$"><?=gettext("Acceptable usage policy"); ?></a></tt> + <tt><a href="/captiveportal-aup.php?zone=$PORTAL_ZONE$&redirurl=$PORTAL_REDIRURL$"><?=gettext("Acceptable usage policy"); ?></a></tt> <br><br> <?php printf(gettext("The total size limit for all files is %s."), format_bytes($g['captiveportal_element_sizelimit']));?></span> </td> @@ -222,4 +234,3 @@ include("head.inc"); <?php include("fend.inc"); ?> </body> </html> - diff --git a/usr/local/www/services_captiveportal_hostname.php b/usr/local/www/services_captiveportal_hostname.php index 3668a35..3955da8 100755 --- a/usr/local/www/services_captiveportal_hostname.php +++ b/usr/local/www/services_captiveportal_hostname.php @@ -50,22 +50,32 @@ require("filter.inc"); require("shaper.inc"); require("captiveportal.inc"); -$pgtitle = array(gettext("Services"),gettext("Captive portal")); +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) + $cpzone = $_POST['zone']; -if (!is_array($config['captiveportal']['allowedhostname'])) - $config['captiveportal']['allowedhostname'] = array(); +if (empty($cpzone)) { + header("Location: services_captiveportal_zones.php"); + exit; +} + +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; -$a_allowedhostnames = &$config['captiveportal']['allowedhostname'] ; +$pgtitle = array(gettext("Services"),gettext("Captive portal"), $a_cp[$cpzone]['zone']); -if ($_GET['act'] == "del") { - if ($a_allowedhostnames[$_GET['id']]) { +if ($_GET['act'] == "del" && !empty($cpzone)) { + $a_allowedhostnames =& $a_cp[$cpzone]['allowedhostname']; + if ($allowedhostnames[$_GET['id']]) { $ipent = $a_allowedhostnames[$_GET['id']]; - if (isset($config['captiveportal']['enable'])) { + if (isset($a_cp[$cpzone]['enable'])) { if (!empty($ipent['sn'])) $ipent['ip'] .= "/{$ipent['sn']}"; $ip = gethostbyname($ipent['ip']); if(is_ipaddr($ip)) { + captiveportal_ipfw_set_context($zone); mwexec("/sbin/ipfw table 3 delete {$ip}"); mwexec("/sbin/ipfw table 4 delete {$ip}"); mwexec("/sbin/ipfw table 5 delete {$ip}"); @@ -79,7 +89,7 @@ if ($_GET['act'] == "del") { unset($a_allowedhostnames[$_GET['id']]); write_config(); - header("Location: services_captiveportal_hostname.php"); + header("Location: services_captiveportal_hostname.php?zone={$cpzone}"); exit; } } @@ -90,17 +100,18 @@ include("head.inc"); <?php include("fbegin.inc"); ?> <body link="#0000CC" vlink="#0000CC" alink="#0000CC"> <form action="services_captiveportal_hostname.php" method="post"> +<input type="hidden" name="zone" id="zone" value="<?=$cpzone;?>" /> <?php if ($savemsg) print_info_box($savemsg); ?> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr><td class="tabnavtbl"> <?php $tab_array = array(); - $tab_array[] = array(gettext("Captive portal"), false, "services_captiveportal.php"); - $tab_array[] = array(gettext("Pass-through MAC"), false, "services_captiveportal_mac.php"); - $tab_array[] = array(gettext("Allowed IP Addresses"), false, "services_captiveportal_ip.php"); - $tab_array[] = array(gettext("Allowed Hostnames"), true, "services_captiveportal_hostname.php"); - $tab_array[] = array(gettext("Vouchers"), false, "services_captiveportal_vouchers.php"); - $tab_array[] = array(gettext("File Manager"), false, "services_captiveportal_filemanager.php"); + $tab_array[] = array(gettext("Captive portal"), false, "services_captiveportal.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Pass-through MAC"), false, "services_captiveportal_mac.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Allowed IP Addresses"), false, "services_captiveportal_ip.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Allowed Hostnames"), true, "services_captiveportal_hostname.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Vouchers"), false, "services_captiveportal_vouchers.php?zone={$cpzone}"); + $tab_array[] = array(gettext("File Manager"), false, "services_captiveportal_filemanager.php?zone={$cpzone}"); display_top_tabs($tab_array, true); ?> </td></tr> @@ -108,19 +119,20 @@ include("head.inc"); <td class="tabcont"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> - <td width="30%" class="listhdrr"><?=gettext("Hostname"); ?></td> - <td width="60%" class="listhdr"><?=gettext("Description"); ?></td> + <td width="60%" class="listhdrr"><?=gettext("Hostname"); ?></td> + <td width="40%" class="listhdr"><?=gettext("Description"); ?></td> <td width="10%" class="list"> <table border="0" cellspacing="0" cellpadding="1"> <tr> <td width="17" heigth="17"></td> - <td><a href="services_captiveportal_hostname_edit.php"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add address"); ?>" width="17" height="17" border="0"></a></td> + <td><a href="services_captiveportal_hostname_edit.php?zone=<?=$cpzone;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add address"); ?>" width="17" height="17" border="0"></a></td> </tr> </table> </td> </tr> - <?php $i = 0; foreach ($a_allowedhostnames as $ip): ?> - <tr ondblclick="document.location='services_captiveportal_hostname_edit.php?id=<?=$i;?>'"> +<?php if (is_array($a_cp[$cpzone]['allowedhostname'])): + $i = 0; foreach ($a_cp[$cpzone]['allowedhostname'] as $ip): ?> + <tr ondblclick="document.location='services_captiveportal_hostname_edit.php?zone=<?=$cpzone;?>&id=<?=$i;?>'"> <td class="listlr"> <?php if($ip['dir'] == "to") { @@ -139,17 +151,17 @@ include("head.inc"); <td class="listbg"> <?=htmlspecialchars($ip['descr']);?> </td> - <td valign="middle" nowrap class="list"> <a href="services_captiveportal_hostname_edit.php?id=<?=$i;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit address"); ?>" width="17" height="17" border="0"></a> - <a href="services_captiveportal_hostname.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this address?"); ?>')"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete address"); ?>" width="17" height="17" border="0"></a></td> + <td valign="middle" nowrap class="list"> <a href="services_captiveportal_hostname_edit.php?zone=<?=$cpzone;?>&id=<?=$i;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit address"); ?>" width="17" height="17" border="0"></a> + <a href="services_captiveportal_hostname.php?zone=<?=$cpzone;?>&act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this address?"); ?>')"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete address"); ?>" width="17" height="17" border="0"></a></td> </tr> - <?php $i++; endforeach; ?> + <?php $i++; endforeach; endif; ?> <tr> <td class="list" colspan="2"> </td> <td class="list"> <table border="0" cellspacing="0" cellpadding="1"> <tr> <td width="17" heigth="17"></td> - <td><a href="services_captiveportal_hostname_edit.php"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add address"); ?>" width="17" height="17" border="0"></a></td> + <td><a href="services_captiveportal_hostname_edit.php?zone=<?=$cpzone;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add address"); ?>" width="17" height="17" border="0"></a></td> </tr> </table> </td> diff --git a/usr/local/www/services_captiveportal_hostname_edit.php b/usr/local/www/services_captiveportal_hostname_edit.php index cc09459..f67ac6e 100755 --- a/usr/local/www/services_captiveportal_hostname_edit.php +++ b/usr/local/www/services_captiveportal_hostname_edit.php @@ -46,8 +46,8 @@ function allowedhostnamescmp($a, $b) { } function allowedhostnames_sort() { - global $g, $config; - usort($config['captiveportal']['allowedhostname'],"allowedhostname"); + global $g, $config, $cpzone; + usort($config['captiveportal'][$cpzone]['allowedhostname'],"allowedhostname"); } $statusurl = "status_captiveportal.php"; @@ -61,16 +61,29 @@ require("captiveportal.inc"); $pgtitle = array(gettext("Services"),gettext("Captive portal"),gettext("Edit allowed Hostname")); -if (!is_array($config['captiveportal']['allowedhostname'])) - $config['captiveportal']['allowedhostname'] = array(); +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) + $cpzone = $_POST['zone']; -$a_allowedhostnames = &$config['captiveportal']['allowedhostname']; +if (empty($cpzone)) { + header("Location: services_captiveportal_zones.php"); + exit; +} + +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; $id = $_GET['id']; if (isset($_POST['id'])) $id = $_POST['id']; +if (!is_array($a_cp[$cpzone]['allowedhostname'])) + $a_cp[$cpzone]['allowedhostname'] = array(); +$a_allowedhostnames = &$a_cp[$cpzone]['allowedhostname']; + if (isset($id) && $a_allowedhostnames[$id]) { + $pconfig['zone'] = $a_allowedhostnames[$id]['zone']; $pconfig['hostname'] = $a_allowedhostnames[$id]['hostname']; $pconfig['sn'] = $a_allowedhostnames[$id]['sn']; $pconfig['dir'] = $a_allowedhostnames[$id]['dir']; @@ -127,10 +140,10 @@ if ($_POST) { write_config(); - if (isset($config['captiveportal']['enable']) && is_module_loaded("ipfw.ko")) + if (isset($a_cp[$cpzone]['enable']) && is_module_loaded("ipfw.ko")) captiveportal_init_rules(); - header("Location: services_captiveportal_hostname.php"); + header("Location: services_captiveportal_hostname.php?zone={$cpzone}"); exit; } } @@ -188,6 +201,7 @@ include("head.inc"); <td width="22%" valign="top"> </td> <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>"> + <input name="zone" type="hidden" value="<?=htmlspecialchars($cpzone);?>"> <?php if (isset($id) && $a_allowedhostnames[$id]): ?> <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>"> <?php endif; ?> diff --git a/usr/local/www/services_captiveportal_ip.php b/usr/local/www/services_captiveportal_ip.php index d636f8a..b8e4dc4 100755 --- a/usr/local/www/services_captiveportal_ip.php +++ b/usr/local/www/services_captiveportal_ip.php @@ -48,20 +48,30 @@ require("filter.inc"); require("shaper.inc"); require("captiveportal.inc"); -$pgtitle = array(gettext("Services"),gettext("Captive portal")); +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) + $cpzone = $_POST['zone']; -if (!is_array($config['captiveportal']['allowedip'])) - $config['captiveportal']['allowedip'] = array(); +if (empty($cpzone)) { + header("Location: services_captiveportal_zones.php"); + exit; +} + +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; -$a_allowedips = &$config['captiveportal']['allowedip'] ; +$pgtitle = array(gettext("Services"),gettext("Captive portal"), $a_cp[$cpzone]['zone']); if ($_GET['act'] == "del") { + $a_allowedips =& $config['captiveportal'][$cpzone]['allowedip']; if ($a_allowedips[$_GET['id']]) { $ipent = $a_allowedips[$_GET['id']]; - if (isset($config['captiveportal']['enable'])) { + if (isset($config['captiveportal'][$cpzone]['enable'])) { if (!empty($ipent['sn'])) $ipent['ip'] .= "/{$ipent['sn']}"; + captiveportal_ipfw_set_context($cpzone); mwexec("/sbin/ipfw table 3 delete " . $ipent['ip']); mwexec("/sbin/ipfw table 4 delete " . $ipent['ip']); mwexec("/sbin/ipfw table 5 delete " . $ipent['ip']); @@ -74,7 +84,7 @@ if ($_GET['act'] == "del") { unset($a_allowedips[$_GET['id']]); write_config(); - header("Location: services_captiveportal_ip.php"); + header("Location: services_captiveportal_ip.php?zone={$cpzone}"); exit; } } @@ -85,17 +95,18 @@ include("head.inc"); <?php include("fbegin.inc"); ?> <body link="#0000CC" vlink="#0000CC" alink="#0000CC"> <form action="services_captiveportal_ip.php" method="post"> +<input type="hidden" name="zone" id="zone" value="<?=$cpzone;?>" /> <?php if ($savemsg) print_info_box($savemsg); ?> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr><td class="tabnavtbl"> <?php $tab_array = array(); - $tab_array[] = array(gettext("Captive portal"), false, "services_captiveportal.php"); - $tab_array[] = array(gettext("Pass-through MAC"), false, "services_captiveportal_mac.php"); - $tab_array[] = array(gettext("Allowed IP addresses"), true, "services_captiveportal_ip.php"); - $tab_array[] = array(gettext("Allowed Hostnames"), false, "services_captiveportal_hostname.php"); - $tab_array[] = array(gettext("Vouchers"), false, "services_captiveportal_vouchers.php"); - $tab_array[] = array(gettext("File Manager"), false, "services_captiveportal_filemanager.php"); + $tab_array[] = array(gettext("Captive portal"), false, "services_captiveportal.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Pass-through MAC"), false, "services_captiveportal_mac.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Allowed IP addresses"), true, "services_captiveportal_ip.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Allowed Hostnames"), false, "services_captiveportal_hostname.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Vouchers"), false, "services_captiveportal_vouchers.php?zone={$cpzone}"); + $tab_array[] = array(gettext("File Manager"), false, "services_captiveportal_filemanager.php?zone={$cpzone}"); display_top_tabs($tab_array, true); ?> </td></tr> @@ -103,19 +114,20 @@ include("head.inc"); <td class="tabcont"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> - <td width="30%" class="listhdrr"><?=gettext("IP address"); ?></td> - <td width="60%" class="listhdr"><?=gettext("Description"); ?></td> + <td width="40%" class="listhdrr"><?=gettext("IP address"); ?></td> + <td width="50%" class="listhdr"><?=gettext("Description"); ?></td> <td width="10%" class="list"> <table border="0" cellspacing="0" cellpadding="1"> <tr> <td width="17" heigth="17"></td> - <td><a href="services_captiveportal_ip_edit.php"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add address"); ?>" width="17" height="17" border="0"></a></td> + <td><a href="services_captiveportal_ip_edit.php?zone=<?=$cpzone;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add address"); ?>" width="17" height="17" border="0"></a></td> </tr> </table> </td> </tr> - <?php $i = 0; foreach ($a_allowedips as $ip): ?> - <tr ondblclick="document.location='services_captiveportal_ip_edit.php?id=<?=$i;?>'"> +<?php if (is_array($a_cp[$cpzone]['allowedip'])): + $i = 0; foreach ($a_cp[$cpzone]['allowedip'] as $ip): ?> + <tr ondblclick="document.location='services_captiveportal_ip_edit.php?zone=<?=$cpzone;?>&id=<?=$i;?>'"> <td class="listlr"> <?php if($ip['dir'] == "to") { @@ -138,17 +150,17 @@ include("head.inc"); <td class="listbg"> <?=htmlspecialchars($ip['descr']);?> </td> - <td valign="middle" nowrap class="list"> <a href="services_captiveportal_ip_edit.php?id=<?=$i;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit address"); ?>" width="17" height="17" border="0"></a> - <a href="services_captiveportal_ip.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this address?"); ?>')"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete address"); ?>" width="17" height="17" border="0"></a></td> + <td valign="middle" nowrap class="list"> <a href="services_captiveportal_ip_edit.php?zone=<?=$cpzone;?>&id=<?=$i;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit address"); ?>" width="17" height="17" border="0"></a> + <a href="services_captiveportal_ip.php?zone=<?=$cpzone;?>&act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this address?"); ?>')"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete address"); ?>" width="17" height="17" border="0"></a></td> </tr> - <?php $i++; endforeach; ?> + <?php $i++; endforeach; endif; ?> <tr> <td class="list" colspan="2"> </td> <td class="list"> <table border="0" cellspacing="0" cellpadding="1"> <tr> <td width="17" heigth="17"></td> - <td><a href="services_captiveportal_ip_edit.php"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add address"); ?>" width="17" height="17" border="0"></a></td> + <td><a href="services_captiveportal_ip_edit.php?zone=<?=$cpzone;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add address"); ?>" width="17" height="17" border="0"></a></td> </tr> </table> </td> diff --git a/usr/local/www/services_captiveportal_ip_edit.php b/usr/local/www/services_captiveportal_ip_edit.php index 01d52a2..e397b21 100755 --- a/usr/local/www/services_captiveportal_ip_edit.php +++ b/usr/local/www/services_captiveportal_ip_edit.php @@ -46,9 +46,9 @@ function allowedipscmp($a, $b) { } function allowedips_sort() { - global $g, $config; + global $g, $config, $cpzone; - usort($config['captiveportal']['allowedip'],"allowedipscmp"); + usort($config['captiveportal'][$cpzone]['allowedip'],"allowedipscmp"); } $statusurl = "status_captiveportal.php"; @@ -62,15 +62,27 @@ require("captiveportal.inc"); $pgtitle = array(gettext("Services"),gettext("Captive portal"),gettext("Edit allowed IP address")); -if (!is_array($config['captiveportal']['allowedip'])) - $config['captiveportal']['allowedip'] = array(); +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) + $cpzone = $_POST['zone']; + +if (empty($cpzone)) { + header("Location: services_captiveportal_zones.php"); + exit; +} -$a_allowedips = &$config['captiveportal']['allowedip']; +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; $id = $_GET['id']; if (isset($_POST['id'])) $id = $_POST['id']; +if (!is_array($config['captiveportal'][$cpzone]['allowedip'])) + $config['captiveportal'][$cpzone]['allowedip'] = array(); +$a_allowedips =& $config['captiveportal'][$cpzone]['allowedip']; + if (isset($id) && $a_allowedips[$id]) { $pconfig['ip'] = $a_allowedips[$id]['ip']; $pconfig['sn'] = $a_allowedips[$id]['sn']; @@ -135,17 +147,18 @@ if ($_POST) { write_config(); - if (isset($config['captiveportal']['enable']) && is_module_loaded("ipfw.ko")) { + if (isset($a_cp[$cpzone]['enable']) && is_module_loaded("ipfw.ko")) { $rules = ""; for ($i = 3; $i < 10; $i++) $rules .= "table {$i} delete {$oldip}\n"; $rules .= captiveportal_allowedip_configure_entry($ip); - file_put_contents("{$g['tmp_path']}/allowedip_tmp{$id}", $rules); - mwexec("/sbin/ipfw -q {$g['tmp_path']}/allowedip_tmp{$id}"); - @unlink("{$g['tmp_path']}/allowedip_tmp{$id}"); + file_put_contents("{$g['tmp_path']}/{$cpzone}_allowedip_tmp{$id}", $rules); + captiveportal_ipfw_set_context($cpzone); + mwexec("/sbin/ipfw -q {$g['tmp_path']}/{$cpzone}_allowedip_tmp{$id}"); + @unlink("{$g['tmp_path']}/{$cpzone}_allowedip_tmp{$id}"); } - header("Location: services_captiveportal_ip.php"); + header("Location: services_captiveportal_ip.php?zone={$cpzone}"); exit; } } @@ -216,6 +229,7 @@ include("head.inc"); <td width="22%" valign="top"> </td> <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>"> + <input name="zone" type="hidden" value="<?=htmlspecialchars($cpzone);?>"> <?php if (isset($id) && $a_allowedips[$id]): ?> <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>"> <?php endif; ?> diff --git a/usr/local/www/services_captiveportal_mac.php b/usr/local/www/services_captiveportal_mac.php index f42ac80..83f88a2 100755 --- a/usr/local/www/services_captiveportal_mac.php +++ b/usr/local/www/services_captiveportal_mac.php @@ -47,13 +47,20 @@ require("filter.inc"); require("shaper.inc"); require("captiveportal.inc"); -$pgtitle = array(gettext("Services"),gettext("Captive portal")); +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) + $cpzone = $_POST['zone']; -if (!is_array($config['captiveportal']['passthrumac'])) - $config['captiveportal']['passthrumac'] = array(); +if (empty($cpzone)) { + header("Location: services_captiveportal_zones.php"); + exit; +} -$a_passthrumacs = &$config['captiveportal']['passthrumac'] ; +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; +$pgtitle = array(gettext("Services"),gettext("Captive portal"), $a_cp[$cpzone]['zone']); if ($_POST) { @@ -73,6 +80,14 @@ if ($_POST) { echo gettext("No entry exists yet!") ."\n"; exit; } + if (empty($_POST['zone'])) { + echo gettext("Please set the zone on which the operation should be allowed"); + exit; + } + if (!is_array($a_cp[$cpzone]['passthrumac'])) + $a_cp[$cpzone]['passthrumac'] = array(); + $a_passthrumacs =& $a_cp[$cpzone]['passthrumac']; + if ($_POST['username']) { $mac = captiveportal_passthrumac_findbyname($_POST['username']); if (!empty($mac)) @@ -92,6 +107,7 @@ if ($_POST) { $ruleno = captiveportal_get_ipfw_passthru_ruleno($_POST['delmac']); if ($ruleno) { captiveportal_free_ipfw_ruleno($ruleno, true); + captiveportal_ipfw_set_context($cpzone); mwexec("/sbin/ipfw delete {$ruleno}; /sbin/ipfw delete " . ++$ruleno); } unset($a_passthrumacs[$idx]); @@ -105,15 +121,17 @@ if ($_POST) { } if ($_GET['act'] == "del") { + $a_passthrumacs =& $a_cp[$cpzone]; if ($a_passthrumacs[$_GET['id']]) { $ruleno = captiveportal_get_ipfw_passthru_ruleno($a_passthrumacs[$_GET['id']]['mac']); if ($ruleno) { + captiveportal_ipfw_set_context($cpzone); captiveportal_free_ipfw_ruleno($ruleno); mwexec("/sbin/ipfw delete {$ruleno}; /sbin/ipfw delete " . ++$ruleno); } unset($a_passthrumacs[$_GET['id']]); write_config(); - header("Location: services_captiveportal_mac.php"); + header("Location: services_captiveportal_mac.php?zone={$cpzone}"); exit; } } @@ -124,6 +142,7 @@ include("head.inc"); <?php include("fbegin.inc"); ?> <body link="#0000CC" vlink="#0000CC" alink="#0000CC"> <form action="services_captiveportal_mac.php" method="post"> +<input type="hidden" name="zone" id="zone" value="<?=$cpzone;?>"/> <?php if ($savemsg) print_info_box($savemsg); ?> <?php if (is_subsystem_dirty('passthrumac')): ?><p> <?php print_info_box_np(gettext("The captive portal MAC address configuration has been changed.<br>You must apply the changes in order for them to take effect."));?><br> @@ -132,12 +151,12 @@ include("head.inc"); <tr><td class="tabnavtbl"> <?php $tab_array = array(); - $tab_array[] = array(gettext("Captive portal"), false, "services_captiveportal.php"); - $tab_array[] = array(gettext("Pass-through MAC"), true, "services_captiveportal_mac.php"); - $tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php"); - $tab_array[] = array(gettext("Allowed Hostnames"), false, "services_captiveportal_hostname.php"); - $tab_array[] = array(gettext("Vouchers"), false, "services_captiveportal_vouchers.php"); - $tab_array[] = array(gettext("File Manager"), false, "services_captiveportal_filemanager.php"); + $tab_array[] = array(gettext("Captive portal"), false, "services_captiveportal.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Pass-through MAC"), true, "services_captiveportal_mac.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Allowed Hostnames"), false, "services_captiveportal_hostname.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Vouchers"), false, "services_captiveportal_vouchers.php?zone={$cpzone}"); + $tab_array[] = array(gettext("File Manager"), false, "services_captiveportal_filemanager.php?zone={$cpzone}"); display_top_tabs($tab_array, true); ?> </td></tr> @@ -145,25 +164,26 @@ include("head.inc"); <td class="tabcont"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> - <td width="30%" class="listhdrr"><?=gettext("MAC address"); ?></td> - <td width="60%" class="listhdr"><?=gettext("Description"); ?></td> + <td width="40%" class="listhdrr"><?=gettext("MAC address"); ?></td> + <td width="50%" class="listhdr"><?=gettext("Description"); ?></td> <td width="10%" class="list"></td> </tr> - <?php $i = 0; foreach ($a_passthrumacs as $mac): ?> - <tr ondblclick="document.location='services_captiveportal_mac_edit.php?id=<?=$i;?>'"> +<?php if (is_array($a_cp[$cpzone]['passthrumac'])): + $i = 0; foreach ($a_cp[$cpzone]['passthrumac'] as $mac): ?> + <tr ondblclick="document.location='services_captiveportal_mac_edit.php?zone=<?=$cpzone;?>&id=<?=$i;?>'"> <td class="listlr"> <?=strtolower($mac['mac']);?> </td> <td class="listbg"> <?=htmlspecialchars($mac['descr']);?> </td> - <td valign="middle" nowrap class="list"> <a href="services_captiveportal_mac_edit.php?id=<?=$i;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit host"); ?>" width="17" height="17" border="0"></a> - <a href="services_captiveportal_mac.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this host?"); ?>')"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete host"); ?>" width="17" height="17" border="0"></a></td> + <td valign="middle" nowrap class="list"> <a href="services_captiveportal_mac_edit.php?zone=<?=$cpzone;?>&id=<?=$i;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit host"); ?>" width="17" height="17" border="0"></a> + <a href="services_captiveportal_mac.php?zone=<?=$cpzone;?>&act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this host?"); ?>')"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete host"); ?>" width="17" height="17" border="0"></a></td> </tr> - <?php $i++; endforeach; ?> + <?php $i++; endforeach; endif; ?> <tr> <td class="list" colspan="2"> </td> - <td class="list"> <a href="services_captiveportal_mac_edit.php"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add host"); ?>" width="17" height="17" border="0"></a></td> + <td class="list"> <a href="services_captiveportal_mac_edit.php?zone=<?=$cpzone;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add host"); ?>" width="17" height="17" border="0"></a></td> </tr> <tr> <td colspan="2" class="list"><span class="vexpl"><span class="red"><strong> diff --git a/usr/local/www/services_captiveportal_mac_edit.php b/usr/local/www/services_captiveportal_mac_edit.php index 07f6d8c..9f590cb 100755 --- a/usr/local/www/services_captiveportal_mac_edit.php +++ b/usr/local/www/services_captiveportal_mac_edit.php @@ -43,9 +43,9 @@ function passthrumacscmp($a, $b) { } function passthrumacs_sort() { - global $config; + global $config, $cpzone; - usort($config['captiveportal']['passthrumac'],"passthrumacscmp"); + usort($config['captiveportal'][$cpzone]['passthrumac'],"passthrumacscmp"); } $statusurl = "status_captiveportal.php"; @@ -59,15 +59,27 @@ require("captiveportal.inc"); $pgtitle = array(gettext("Services"),gettext("Captive portal"),gettext("Edit pass-through MAC address")); -if (!is_array($config['captiveportal']['passthrumac'])) - $config['captiveportal']['passthrumac'] = array(); +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) + $cpzone = $_POST['zone']; -$a_passthrumacs = &$config['captiveportal']['passthrumac']; +if (empty($cpzone)) { + header("Location: services_captiveportal_zones.php"); + exit; +} + +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; $id = $_GET['id']; if (isset($_POST['id'])) $id = $_POST['id']; +if (!is_array($a_cp[$cpzone]['passthrumac'])) + $a_cp[$cpzone]['passthrumac'] = array(); +$a_passthrumacs = &$a_cp[$cpzone]['passthrumac']; + if (isset($id) && $a_passthrumacs[$id]) { $pconfig['mac'] = $a_passthrumacs[$id]['mac']; $pconfig['bw_up'] = $a_passthrumacs[$id]['bw_up']; @@ -138,11 +150,12 @@ if ($_POST) { } $rules .= captiveportal_passthrumac_configure_entry($mac); - file_put_contents("{$g['tmp_path']}/tmpmacedit{$id}", $rules); - mwexec("/sbin/ipfw -q {$g['tmp_path']}/tmpmacedit{$id}"); - @unlink("{$g['tmp_path']}/tmpmacedit{$id}"); + file_put_contents("{$g['tmp_path']}/{$cpzone}_tmpmacedit{$id}", $rules); + captiveportal_ipfw_set_context($cpzone); + mwexec("/sbin/ipfw -q {$g['tmp_path']}/{$cpzone}_tmpmacedit{$id}"); + @unlink("{$g['tmp_path']}/{$cpzone}_tmpmacedit{$id}"); - header("Location: services_captiveportal_mac.php"); + header("Location: services_captiveportal_mac.php?zone={$cpzone}"); exit; } } @@ -156,7 +169,7 @@ include("head.inc"); <tr> <td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Pass-through MAC address");?></td> </tr> - <tr> + <tr> <td width="22%" valign="top" class="vncellreq"><?=gettext("MAC address"); ?></td> <td width="78%" class="vtable"> <?=$mandfldhtml;?><input name="mac" type="text" class="formfld unknown" id="mac" size="17" value="<?=htmlspecialchars($pconfig['mac']);?>"> @@ -186,6 +199,7 @@ include("head.inc"); <td width="22%" valign="top"> </td> <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>"> + <input name="zone" type="hidden" value="<?=htmlspecialchars($cpzone);?>"> <?php if (isset($id) && $a_passthrumacs[$id]): ?> <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>"> <?php endif; ?> diff --git a/usr/local/www/services_captiveportal_vouchers.php b/usr/local/www/services_captiveportal_vouchers.php index 05bce04..df423a0 100644 --- a/usr/local/www/services_captiveportal_vouchers.php +++ b/usr/local/www/services_captiveportal_vouchers.php @@ -39,8 +39,18 @@ $statusurl = "status_captiveportal_vouchers.php"; $logurl = "diag_logs_auth.php"; +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) + $cpzone = $_POST['zone']; + +if (empty($cpzone)) { + header("Location: services_captiveportal_zones.php"); + exit; +} + if ($_POST['postafterlogin']) $nocsrf= true; + require("guiconfig.inc"); require("functions.inc"); require("filter.inc"); @@ -65,77 +75,81 @@ EOF; exit; } -$pgtitle = array(gettext("Services"), gettext("Captive portal"), gettext("Vouchers")); +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; if (!is_array($config['voucher'])) $config['voucher'] = array(); -if (!is_array($config['voucher']['roll'])) - $config['voucher']['roll'] = array(); -if (!isset($config['voucher']['charset'])) - $config['voucher']['charset'] = '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'; -if (!isset($config['voucher']['rollbits'])) - $config['voucher']['rollbits'] = 16; -if (!isset($config['voucher']['ticketbits'])) - $config['voucher']['ticketbits'] = 10; -if (!isset($config['voucher']['checksumbits'])) - $config['voucher']['checksumbits'] = 5; -if (!isset($config['voucher']['magic'])) - $config['voucher']['magic'] = rand(); // anything slightly random will do +$pgtitle = array(gettext("Services"), gettext("Captive portal"), gettext("Vouchers"), $a_cp[$cpzone]['zone']); + +if (!is_array($config['voucher'][$cpzone]['roll'])) + $config['voucher'][$cpzone]['roll'] = array(); +if (!isset($config['voucher'][$cpzone]['charset'])) + $config['voucher'][$cpzone]['charset'] = '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'; +if (!isset($config['voucher'][$cpzone]['rollbits'])) + $config['voucher'][$cpzone]['rollbits'] = 16; +if (!isset($config['voucher'][$cpzone]['ticketbits'])) + $config['voucher'][$cpzone]['ticketbits'] = 10; +if (!isset($config['voucher'][$cpzone]['checksumbits'])) + $config['voucher'][$cpzone]['checksumbits'] = 5; +if (!isset($config['voucher'][$cpzone]['magic'])) + $config['voucher'][$cpzone]['magic'] = rand(); // anything slightly random will do -if (!isset($config['voucher']['publickey'])) { +if (!isset($config['voucher'][$cpzone]['publickey'])) { /* generate a random 64 bit RSA key pair using the voucher binary */ $fd = popen("/usr/local/bin/voucher -g 64", "r"); if ($fd !== false) { $output = fread($fd, 16384); pclose($fd); list($privkey, $pubkey) = explode("\0", $output); - $config['voucher']['publickey'] = base64_encode($pubkey); - $config['voucher']['privatekey'] = base64_encode($privkey); + $config['voucher'][$cpzone]['publickey'] = base64_encode($pubkey); + $config['voucher'][$cpzone]['privatekey'] = base64_encode($privkey); } } // Check for invalid or expired vouchers -if (!isset($config['voucher']['msgnoaccess'])) - $config['voucher']['msgnoaccess'] = gettext("Voucher invalid"); -if (!isset($config['voucher']['msgexpired'])) - $config['voucher']['msgexpired'] = gettext("Voucher expired"); +if (!isset($config['voucher'][$cpzone]['msgnoaccess'])) + $config['voucher'][$cpzone]['msgnoaccess'] = gettext("Voucher invalid"); +if (!isset($config['voucher'][$cpzone]['msgexpired'])) + $config['voucher'][$cpzone]['msgexpired'] = gettext("Voucher expired"); -$a_roll = &$config['voucher']['roll']; +$a_roll = &$config['voucher'][$cpzone]['roll']; if ($_GET['act'] == "del") { $id = $_GET['id']; if ($a_roll[$id]) { $roll = $a_roll[$id]['number']; - $voucherlck = lock('voucher'); + $voucherlck = lock("voucher{$cpzone}"); unset($a_roll[$id]); voucher_unlink_db($roll); unlock($voucherlck); write_config(); - header("Location: services_captiveportal_vouchers.php"); + header("Location: services_captiveportal_vouchers.php?zone={$cpzone}"); exit; } } /* print all vouchers of the selected roll */ else if ($_GET['act'] == "csv") { - $privkey = base64_decode($config['voucher']['privatekey']); + $privkey = base64_decode($config['voucher'][$cpzone]['privatekey']); if (strstr($privkey,"BEGIN RSA PRIVATE KEY")) { - $fd = fopen("{$g['varetc_path']}/voucher.private","w"); + $fd = fopen("{$g['varetc_path']}/voucher_{$cpzone}.private","w"); if (!$fd) { $input_errors[] = gettext("Cannot write private key file") . ".\n"; } else { - chmod("{$g['varetc_path']}/voucher.private", 0600); + chmod("{$g['varetc_path']}/voucher_{$cpzone}.private", 0600); fwrite($fd, $privkey); fclose($fd); - $a_voucher = &$config['voucher']['roll']; + $a_voucher = &$config['voucher'][$cpzone]['roll']; $id = $_GET['id']; if (isset($id) && $a_voucher[$id]) { $number = $a_voucher[$id]['number']; $count = $a_voucher[$id]['count']; header("Content-Type: application/octet-stream"); - header("Content-Disposition: attachment; filename=vouchers_roll$number.csv"); - system("/usr/local/bin/voucher -c {$g['varetc_path']}/voucher.cfg -p {$g['varetc_path']}/voucher.private $number $count"); - unlink("{$g['varetc_path']}/voucher.private"); + header("Content-Disposition: attachment; filename=vouchers_{$cpzone}_roll{$number}.csv"); + system("/usr/local/bin/voucher -c {$g['varetc_path']}/voucher_{$cpzone}.cfg -p {$g['varetc_path']}/voucher_{$cpzone}.private $number $count"); + unlink("{$g['varetc_path']}/voucher_{$cpzone}.private"); exit; } } @@ -144,20 +158,20 @@ else if ($_GET['act'] == "csv") { } } -$pconfig['enable'] = isset($config['voucher']['enable']); -$pconfig['charset'] = $config['voucher']['charset']; -$pconfig['rollbits'] = $config['voucher']['rollbits']; -$pconfig['ticketbits'] = $config['voucher']['ticketbits']; -$pconfig['checksumbits'] = $config['voucher']['checksumbits']; -$pconfig['magic'] = $config['voucher']['magic']; -$pconfig['publickey'] = base64_decode($config['voucher']['publickey']); -$pconfig['privatekey'] = base64_decode($config['voucher']['privatekey']); -$pconfig['msgnoaccess'] = $config['voucher']['msgnoaccess']; -$pconfig['msgexpired'] = $config['voucher']['msgexpired']; -$pconfig['vouchersyncdbip'] = $config['voucher']['vouchersyncdbip']; -$pconfig['vouchersyncport'] = $config['voucher']['vouchersyncport']; -$pconfig['vouchersyncpass'] = $config['voucher']['vouchersyncpass']; -$pconfig['vouchersyncusername'] = $config['voucher']['vouchersyncusername']; +$pconfig['enable'] = isset($config['voucher'][$cpzone]['enable']); +$pconfig['charset'] = $config['voucher'][$cpzone]['charset']; +$pconfig['rollbits'] = $config['voucher'][$cpzone]['rollbits']; +$pconfig['ticketbits'] = $config['voucher'][$cpzone]['ticketbits']; +$pconfig['checksumbits'] = $config['voucher'][$cpzone]['checksumbits']; +$pconfig['magic'] = $config['voucher'][$cpzone]['magic']; +$pconfig['publickey'] = base64_decode($config['voucher'][$cpzone]['publickey']); +$pconfig['privatekey'] = base64_decode($config['voucher'][$cpzone]['privatekey']); +$pconfig['msgnoaccess'] = $config['voucher'][$cpzone]['msgnoaccess']; +$pconfig['msgexpired'] = $config['voucher'][$cpzone]['msgexpired']; +$pconfig['vouchersyncdbip'] = $config['voucher'][$cpzone]['vouchersyncdbip']; +$pconfig['vouchersyncport'] = $config['voucher'][$cpzone]['vouchersyncport']; +$pconfig['vouchersyncpass'] = $config['voucher'][$cpzone]['vouchersyncpass']; +$pconfig['vouchersyncusername'] = $config['voucher'][$cpzone]['vouchersyncusername']; if ($_POST) { @@ -206,52 +220,54 @@ if ($_POST) { } if (!$input_errors) { + $newvoucher = array(); if ($_POST['enable'] == "yes") - $config['voucher']['enable'] = true; + $newvoucher['enable'] = true; else - unset($config['voucher']['enable']); + unset($newvoucher['enable']); if (empty($_POST['vouchersyncusername'])) { - $config['voucher']['charset'] = $_POST['charset']; - $config['voucher']['rollbits'] = $_POST['rollbits']; - $config['voucher']['ticketbits'] = $_POST['ticketbits']; - $config['voucher']['checksumbits'] = $_POST['checksumbits']; - $config['voucher']['magic'] = $_POST['magic']; - $config['voucher']['publickey'] = base64_encode($_POST['publickey']); - $config['voucher']['privatekey'] = base64_encode($_POST['privatekey']); - $config['voucher']['msgnoaccess'] = $_POST['msgnoaccess']; - $config['voucher']['msgexpired'] = $_POST['msgexpired']; + $newvoucher['charset'] = $_POST['charset']; + $newvoucher['rollbits'] = $_POST['rollbits']; + $newvoucher['ticketbits'] = $_POST['ticketbits']; + $newvoucher['checksumbits'] = $_POST['checksumbits']; + $newvoucher['magic'] = $_POST['magic']; + $newvoucher['publickey'] = base64_encode($_POST['publickey']); + $newvoucher['privatekey'] = base64_encode($_POST['privatekey']); + $newvoucher['msgnoaccess'] = $_POST['msgnoaccess']; + $newvoucher['msgexpired'] = $_POST['msgexpired']; + $config['voucher'][$cpzone] = $newvoucher; write_config(); - voucher_configure(); + voucher_configure_zone(); } else { - $config['voucher']['vouchersyncdbip'] = $_POST['vouchersyncdbip']; - $config['voucher']['vouchersyncport'] = $_POST['vouchersyncport']; - $config['voucher']['vouchersyncusername'] = $_POST['vouchersyncusername']; - $config['voucher']['vouchersyncpass'] = $_POST['vouchersyncpass']; - if($config['voucher']['vouchersyncpass'] && $config['voucher']['vouchersyncusername'] && - $config['voucher']['vouchersyncport'] && $config['voucher']['vouchersyncdbip']) { + $newvoucher['vouchersyncdbip'] = $_POST['vouchersyncdbip']; + $newvoucher['vouchersyncport'] = $_POST['vouchersyncport']; + $newvoucher['vouchersyncusername'] = $_POST['vouchersyncusername']; + $newvoucher['vouchersyncpass'] = $_POST['vouchersyncpass']; + if($newvoucher['vouchersyncpass'] && $newvoucher['vouchersyncusername'] && + $newvoucher['vouchersyncport'] && $newvoucher['vouchersyncdbip']) { // Synchronize the voucher DB from the master node require_once("xmlrpc.inc"); - if($config['voucher']['vouchersyncport'] == "443") - $url = "https://{$config['voucher']['vouchersyncdbip']}"; + if($newvoucher['vouchersyncport'] == "443") + $url = "https://{$newvoucher['vouchersyncdbip']}"; else - $url = "http://{$config['voucher']['vouchersyncdbip']}"; + $url = "http://{$newvoucher['vouchersyncdbip']}"; $execcmd = <<<EOF - \$toreturn['voucher'] = \$config['voucher']; + \$toreturn['voucher'] = \$config['voucher'][$cpzone]; unset(\$toreturn['vouchersyncport'], \$toreturn['vouchersyncpass'], \$toreturn['vouchersyncusername'], \$toreturn['vouchersyncdbip']); EOF; /* assemble xmlrpc payload */ $params = array( - XML_RPC_encode($config['voucher']['vouchersyncpass']), + XML_RPC_encode($newvoucher['vouchersyncpass']), XML_RPC_encode($execcmd) ); - $port = $config['voucher']['vouchersyncport']; + $port = $newvoucher['vouchersyncport']; log_error("voucher XMLRPC sync data {$url}:{$port}."); $msg = new XML_RPC_Message('pfsense.exec_php', $params); $cli = new XML_RPC_Client('/xmlrpc.php', $url, $port); - $cli->setCredentials($config['voucher']['vouchersyncusername'], $config['voucher']['vouchersyncpass']); + $cli->setCredentials($newvoucher['vouchersyncusername'], $newvoucher['vouchersyncpass']); $resp = $cli->send($msg, "250"); if(!is_object($resp)) { $error = "A communications error occurred while attempting CaptivePortalVoucherSync XMLRPC sync with {$url}:{$port} (pfsense.exec_php)."; @@ -276,37 +292,37 @@ EOF; } else { // If we received back the voucher roll and other information then store it. if($toreturn['voucher']['roll']) - $config['voucher']['roll'] = $toreturn['voucher']['roll']; + $config['voucher'][$cpzone]['roll'] = $toreturn['voucher']['roll']; if($toreturn['voucher']['rollbits']) - $config['voucher']['rollbits'] = $toreturn['voucher']['rollbits']; + $config['voucher'][$cpzone]['rollbits'] = $toreturn['voucher']['rollbits']; if($toreturn['voucher']['ticketbits']) - $config['voucher']['ticketbits'] = $toreturn['voucher']['ticketbits']; + $config['voucher'][$cpzone]['ticketbits'] = $toreturn['voucher']['ticketbits']; if($toreturn['voucher']['checksumbits']) - $config['voucher']['checksumbits'] = $toreturn['voucher']['checksumbits']; + $config['voucher'][$cpzone]['checksumbits'] = $toreturn['voucher']['checksumbits']; if($toreturn['voucher']['magic']) - $config['voucher']['magic'] = $toreturn['voucher']['magic']; + $config['voucher'][$cpzone]['magic'] = $toreturn['voucher']['magic']; if($toreturn['voucher']['publickey']) - $config['voucher']['publickey'] = $toreturn['voucher']['publickey']; + $config['voucher'][$cpzone]['publickey'] = $toreturn['voucher']['publickey']; if($toreturn['voucher']['privatekey']) - $config['voucher']['privatekey'] = $toreturn['voucher']['privatekey']; + $config['voucher'][$cpzone]['privatekey'] = $toreturn['voucher']['privatekey']; if($toreturn['voucher']['msgnoaccess']) - $config['voucher']['msgnoaccess'] = $toreturn['voucher']['msgnoaccess']; + $config['voucher'][$cpzone]['msgnoaccess'] = $toreturn['voucher']['msgnoaccess']; if($toreturn['voucher']['msgexpired']) - $config['voucher']['msgexpired'] = $toreturn['voucher']['msgexpired']; + $config['voucher'][$cpzone]['msgexpired'] = $toreturn['voucher']['msgexpired']; if($toreturn['voucher']['msgnoaccess']) - $config['voucher']['msgnoaccess'] = $toreturn['voucher']['msgnoaccess']; - $savemsg = sprintf(gettext("Voucher database has been synchronized from %1\$s:%2\$s"),$url,$port); + $config['voucher'][$cpzone]['msgnoaccess'] = $toreturn['voucher']['msgnoaccess']; + $savemsg = gettext("Voucher database has been synchronized from {$url}:{$port}"); write_config(); - voucher_configure(true); + voucher_configure_zone(true); } } } } - if($savemsg && isset($config['voucher']['enable']) && !isset($config['captiveportal']['enable'])) - $savemsg .= "<br/>"; - if (isset($config['voucher']['enable']) && !isset($config['captiveportal']['enable'])) - $savemsg .= gettext("Don't forget to configure and enable Captive Portal."); + if (!$input_errors) { + header("Location: services_captiveportal_vouchers.php?zone={$cpzone}"); + exit; + } } } include("head.inc"); @@ -384,12 +400,12 @@ function enable_change(enable_change) { <ul id="tabnav"> <?php $tab_array = array(); - $tab_array[] = array(gettext("Captive portal"), false, "services_captiveportal.php"); - $tab_array[] = array(gettext("Pass-through MAC"), false, "services_captiveportal_mac.php"); - $tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php"); - $tab_array[] = array(gettext("Allowed Hostnames"), false, "services_captiveportal_hostname.php"); - $tab_array[] = array(gettext("Vouchers"), true, "services_captiveportal_vouchers.php"); - $tab_array[] = array(gettext("File Manager"), false, "services_captiveportal_filemanager.php"); + $tab_array[] = array(gettext("Captive portal"), false, "services_captiveportal.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Pass-through MAC"), false, "services_captiveportal_mac.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Allowed Hostnames"), false, "services_captiveportal_hostname.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Vouchers"), true, "services_captiveportal_vouchers.php?zone={$cpzone}"); + $tab_array[] = array(gettext("File Manager"), false, "services_captiveportal_filemanager.php?zone={$cpzone}"); display_top_tabs($tab_array, true); ?> </ul> @@ -439,9 +455,9 @@ function enable_change(enable_change) { <td valign="middle" nowrap class="list"> <div id='addeditdelete<?=$i?>'> <?php if ($pconfig['enable']): ?> - <a href="services_captiveportal_vouchers_edit.php?id=<?=$i; ?>"><img src="/themes/<?=$g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit voucher"); ?>" width="17" height="17" border="0" alt="<?=gettext("edit voucher"); ?>"></a> - <a href="services_captiveportal_vouchers.php?act=del&id=<?=$i; ?>" onclick="return confirm('<?=gettext("Do you really want to delete this voucher? This makes all vouchers from this roll invalid"); ?>')"><img src="/themes/<?=$g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete vouchers"); ?>" width="17" height="17" border="0" alt="<?=gettext("delete vouchers"); ?>"></a> - <a href="services_captiveportal_vouchers.php?act=csv&id=<?=$i; ?>"><img src="/themes/<?=$g['theme']; ?>/images/icons/icon_log_s.gif" title="<?=gettext("generate vouchers for this roll to CSV file"); ?>" width="11" height="15" border="0" alt="<?=gettext("generate vouchers for this roll to CSV file"); ?>"></a> + <a href="services_captiveportal_vouchers_edit.php?zone=<?=$cpzone;?>&id=<?=$i; ?>"><img src="/themes/<?=$g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit voucher"); ?>" width="17" height="17" border="0" alt="<?=gettext("edit voucher"); ?>"></a> + <a href="services_captiveportal_vouchers.php?zone=<?=$cpzone;?>&act=del&id=<?=$i; ?>" onclick="return confirm('<?=gettext("Do you really want to delete this voucher? This makes all vouchers from this roll invalid"); ?>')"><img src="/themes/<?=$g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete vouchers"); ?>" width="17" height="17" border="0" alt="<?=gettext("delete vouchers"); ?>"></a> + <a href="services_captiveportal_vouchers.php?zone=<?=$cpzone;?>&act=csv&id=<?=$i; ?>"><img src="/themes/<?=$g['theme']; ?>/images/icons/icon_log_s.gif" title="<?=gettext("generate vouchers for this roll to CSV file"); ?>" width="11" height="15" border="0" alt="<?=gettext("generate vouchers for this roll to CSV file"); ?>"></a> <?php endif;?> </div> </td> @@ -451,7 +467,7 @@ function enable_change(enable_change) { <td class="list" colspan="4"></td> <?php if ($pconfig['enable']) - echo "<td class=\"list\"><div id='addnewroll'> <a href=\"services_captiveportal_vouchers_edit.php\"><img src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" title=\"" . gettext("add voucher") . "\" width=\"17\" height=\"17\" border=\"0\" alt=\"" . gettext("add voucher") . "\"></a></div></td>"; + echo "<td class=\"list\"><div id='addnewroll'> <a href=\"services_captiveportal_vouchers_edit.php?zone={$cpzone}\"><img src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" title=\"" . gettext("add voucher") . "\" width=\"17\" height=\"17\" border=\"0\" alt=\"" . gettext("add voucher") . "\"></a></div></td>"; ?> </tr> </table> @@ -577,6 +593,7 @@ function enable_change(enable_change) { <tr> <td width="22%" valign="top"> </td> <td width="78%"> + <input type="hidden" name="zone" id="zone" value="<?=$cpzone;?>" /> <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onClick="enable_change(true); before_save();"> <input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()"> </td> diff --git a/usr/local/www/services_captiveportal_vouchers_edit.php b/usr/local/www/services_captiveportal_vouchers_edit.php index 94724a9..97e03dd 100644 --- a/usr/local/www/services_captiveportal_vouchers_edit.php +++ b/usr/local/www/services_captiveportal_vouchers_edit.php @@ -47,28 +47,42 @@ require_once("voucher.inc"); $pgtitle = array(gettext("Services"), gettext("Captive portal"), gettext("Edit Voucher Rolls")); +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) + $cpzone = $_POST['zone']; + +if (empty($cpzone)) { + header("Location: services_captiveportal_zones.php"); + exit; +} + +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; + if (!is_array($config['voucher'])) { $config['voucher'] = array(); } -if (!is_array($config['voucher']['roll'])) { - $config['voucher']['roll'] = array(); +if (!is_array($config['voucher'][$cpzone]['roll'])) { + $config['voucher'][$cpzone]['roll'] = array(); } -$a_roll = &$config['voucher']['roll']; +$a_roll = &$config['voucher'][$cpzone]['roll']; $id = $_GET['id']; if (isset($_POST['id'])) $id = $_POST['id']; if (isset($id) && $a_roll[$id]) { + $pconfig['zone'] = $a_roll[$id]['zone']; $pconfig['number'] = $a_roll[$id]['number']; $pconfig['count'] = $a_roll[$id]['count']; $pconfig['minutes'] = $a_roll[$id]['minutes']; $pconfig['comment'] = $a_roll[$id]['comment']; } -$maxnumber = (1<<$config['voucher']['rollbits']) -1; // Highest Roll# -$maxcount = (1<<$config['voucher']['ticketbits']) -1; // Highest Ticket# +$maxnumber = (1<<$config['voucher'][$cpzone]['rollbits']) -1; // Highest Roll# +$maxcount = (1<<$config['voucher'][$cpzone]['ticketbits']) -1; // Highest Ticket# if ($_POST) { @@ -103,12 +117,13 @@ if ($_POST) { if (isset($id) && $a_roll[$id]) $rollent = $a_roll[$id]; + $rollent['zone'] = $_POST['zone']; $rollent['number'] = $_POST['number']; $rollent['minutes'] = $_POST['minutes']; $rollent['comment'] = $_POST['comment']; /* New Roll or modified voucher count: create bitmask */ - $voucherlck = lock('voucher'); + $voucherlck = lock("voucher{$cpzone}"); if ($_POST['count'] != $rollent['count']) { $rollent['count'] = $_POST['count']; $len = ($rollent['count']>>3) + 1; // count / 8 +1 @@ -142,7 +157,7 @@ if ($_POST) { write_config(); - header("Location: services_captiveportal_vouchers.php"); + header("Location: services_captiveportal_vouchers.php?zone={$cpzone}"); exit; } } @@ -190,6 +205,7 @@ include("head.inc"); <td width="22%" valign="top"> </td> <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>"> + <input name="zone" type="hidden" value="<?=htmlspecialchars($cpzone);?>"> <?php if (isset($id) && $a_roll[$id]): ?> <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>"> <?php endif; ?> diff --git a/usr/local/www/services_captiveportal_zones.php b/usr/local/www/services_captiveportal_zones.php new file mode 100644 index 0000000..735cd20 --- /dev/null +++ b/usr/local/www/services_captiveportal_zones.php @@ -0,0 +1,113 @@ +<?php +/* + LICENSE +*/ + +##|+PRIV +##|*IDENT=page-services-captiveportalserver-zones +##|*NAME=Services: Captiveprotal Zones page +##|*DESCR=Allow access to the 'Services: CaptivePortal Zones' page. +##|*MATCH=services_captiveportal_zones.php* +##|-PRIV + +require("guiconfig.inc"); +require("functions.inc"); +require("filter.inc"); +require("shaper.inc"); +require("captiveportal.inc"); + +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp = &$config['captiveportal']; + +if ($_GET['act'] == "del" && !empty($_GET['zone'])) { + $cpzone = $_GET['zone']; + if ($a_cp[$cpzone]) { + unset($a_cp[$cpzone]['enable']); + captiveportal_configure_zone($a_cp[$cpzone]); + unset($a_cp[$cpzone]); + if (isset($config['voucher'][$cpzone])) + unset($config['voucher'][$cpzone]); + write_config(); + header("Location: services_captiveportal_zones.php"); + exit; + } +} + +$pgtitle = array(gettext("Captiveportal"),gettext("Zones")); +include("head.inc"); + +?> + +<body link="#0000CC" vlink="#0000CC" alink="#0000CC"> +<?php include("fbegin.inc"); ?> +<form action="services_captiveportal_zones.php" method="post"> +<?php if ($savemsg) print_info_box($savemsg); ?> +<?php if (is_subsystem_dirty('captiveportal')): ?><p> +<?php print_info_box_np(gettext("The CaptivePortal entry list has been changed") . ".<br>" . gettext("You must apply the changes in order for them to take effect."));?> +<?php endif; ?> + +<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0"> +<tr> + <td width="15%" class="listhdrr"><?=gettext("Zone");?></td> + <td width="30%" class="listhdrr"><?=gettext("Interfaces");?></td> + <td width="10%" class="listhdrr"><?=gettext("Number of users");?></td> + <td width="40%" class="listhdrr"><?=gettext("Description");?></td> + <td width="5%" class="list"> + <table border="0" cellspacing="0" cellpadding="1"> + <tr> + <td valign="middle" width="17"> </td> + <td valign="middle"><a href="services_captiveportal_zones_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?=gettext("add a new captiveportal instance");?>"></a></td> + </tr> + </table> + </td> +</tr> + <?php foreach ($a_cp as $cpzone => $cpitem): + if (!is_array($cpitem)) + continue; + ?> +<tr> + <td class="listlr" ondblclick="document.location='services_captiveportal.php?zone=<?=$cpzone;?>';"> + <?=htmlspecialchars($cpitem['zone']);?> + </td> + <td class="listlr" ondblclick="document.location='services_captiveportal.php?zone=<?=$cpzone;?>';"> + <?php $cpifaces = explode(",", $cpitem['interface']); + foreach ($cpifaces as $cpiface) + echo convert_friendly_interface_to_friendly_descr($cpiface) . " "; + ?> + </td> + <td class="listr" ondblclick="document.location='services_captiveportal.php?zone=<?=$cpzone;?>';"> + <?=count(captiveportal_read_db());?> + </td> + <td class="listbg" ondblclick="document.location='services_captiveportal.php?zone=<?=$cpzone;?>';"> + <?=htmlspecialchars($cpitem['descr']);?> + </td> + <td valign="middle" nowrap class="list"> + <table border="0" cellspacing="0" cellpadding="1"> + <tr> + <td valign="middle"><a href="services_captiveportal.php?zone=<?=$cpzone?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" title="<?=gettext("edit captiveportal instance"); ?>"></a></td> + <td><a href="services_captiveportal_zones.php?act=del&zone=<?=$cpzone;?>" onclick="return confirm('<?=gettext("Do you really want to delete this entry?");?>')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" title="<?=gettext("delete captiveportal instance");?>"></a></td> + </tr> + </table> + </td> +</tr> + <?php endforeach; ?> +<tr> + <td class="list" colspan="4"></td> + <td class="list"> + <table border="0" cellspacing="0" cellpadding="1"> + <tr> + <td valign="middle" width="17"> </td> + <td valign="middle"><a href="services_captiveportal_zones_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?=gettext("add a new captiveportal instance");?>"></a></td> + </td> + </tr> + </table> + </td> +</tr> +</table> +</tr> +</table> +</form> +<?php include("fend.inc"); ?> +</body> +</html> diff --git a/usr/local/www/services_captiveportal_zones_edit.php b/usr/local/www/services_captiveportal_zones_edit.php new file mode 100644 index 0000000..169a761 --- /dev/null +++ b/usr/local/www/services_captiveportal_zones_edit.php @@ -0,0 +1,117 @@ +<?php +/* + services_captiveportal_mac_edit.php + Copyright (C) 2011 Ermal Luci + 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. +*/ +/* + pfSense_MODULE: captiveportal +*/ + +##|+PRIV +##|*IDENT=page-services-captiveportal-editzones +##|*NAME=Services: Captive portal: Edit Zones page +##|*DESCR=Allow access to the 'Services: Captive portal: Edit Zones' page. +##|*MATCH=services_captiveportal_zones_edit.php* +##|-PRIV + +$statusurl = "status_captiveportal_zones_edit.php"; +$logurl = "diag_logs_auth.php"; + +require("guiconfig.inc"); +require("functions.inc"); +require("filter.inc"); +require("shaper.inc"); +require("captiveportal.inc"); + +$pgtitle = array(gettext("Services"),gettext("Captive portal"),gettext("Edit Zones")); + +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; + +if ($_POST) { + + unset($input_errors); + $pconfig = $_POST; + + /* input validation */ + $reqdfields = explode(" ", "zone"); + $reqdfieldsn = array(gettext("Zone name")); + + do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); + + foreach ($a_cp as $cpkey => $cpent) { + if ($cpent['zone'] == $_POST['zone']){ + $input_errors[] = sprintf("[%s] %s.", $_POST['zone'], gettext("already exists")); + break; + } + } + + if (!$input_errors) { + $cpzone = strtolower($_POST['zone']); + $a_cp[$cpzone] = array(); + $a_cp[$cpzone]['zone'] = str_replace(" ", "", $_POST['zone']); + $a_cp[$cpzone]['descr'] = $_POST['descr']; + write_config(); + + header("Location: services_captiveportal.php?zone={$cpzone}"); + exit; + } +} +include("head.inc"); +?> +<?php include("fbegin.inc"); ?> +<body link="#0000CC" vlink="#0000CC" alink="#0000CC"> +<?php if ($input_errors) print_input_errors($input_errors); ?> + <form action="services_captiveportal_zones_edit.php" method="post" name="iform" id="iform"> + <table width="100%" border="0" cellpadding="6" cellspacing="0"> + <tr> + <td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Captiveportal Zones");?></td> + </tr> + <tr> + <td width="22%" valign="top" class="vncellreq"><?=gettext("Zone name"); ?></td> + <td width="78%" class="vtable"> + <input name="zone" type="text" class="formfld unknown" id="zone" size="64"> + <br> + <span class="vexpl"><?=gettext("Zone name. Cannot contain spaces."); ?></span></td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td> + <td width="78%" class="vtable"> + <input name="descr" type="text" class="formfld unknown" id="descr" size="40" > + <br> <span class="vexpl"><?=gettext("You may enter a description here " . + "for your reference (not parsed)"); ?>.</span></td> + </tr> + <tr> + <td width="22%" valign="top"> </td> + <td width="78%"> + <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Continue"); ?>"> + </td> + </tr> + </table> +</form> +<?php include("fend.inc"); ?> +</body> +</html> diff --git a/usr/local/www/status_captiveportal.php b/usr/local/www/status_captiveportal.php index 41787f3..fac8145 100755 --- a/usr/local/www/status_captiveportal.php +++ b/usr/local/www/status_captiveportal.php @@ -45,28 +45,21 @@ require("filter.inc"); require("shaper.inc"); require("captiveportal.inc"); -if ($_GET['act'] == "del") { +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) + $cpzone = $_POST['zone']; + +if ($_GET['act'] == "del" && !empty($cpzone)) { captiveportal_disconnect_client($_GET['id']); - Header("Location: status_captiveportal.php"); + Header("Location: status_captiveportal.php?zone={$cpzone}"); exit; } -function clientcmp($a, $b) { - global $order; - return strcmp($a[$order], $b[$order]); -} - -$cpdb = array(); -if (file_exists("{$g['vardb_path']}/captiveportal.db")) { - $captiveportallck = lock('captiveportaldb'); - $cpcontents = file("/var/db/captiveportal.db", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); - unlock($captiveportallck); -} else - $cpcontents = array(); +$pgtitle = array(gettext("Status: Captive portal")); -$concurrent = count($cpcontents); - -$pgtitle = array(gettext("Status: Captive portal ({$concurrent})")); +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; include("head.inc"); @@ -79,39 +72,56 @@ include("head.inc"); flush(); -foreach ($cpcontents as $cpcontent) { - $cpent = explode(",", $cpcontent); - $sessionid = $cpent[5]; - if ($_GET['showact']) - $cpent[5] = captiveportal_get_last_activity($cpent[2]); - $cpdb[$sessionid] = $cpent; +function clientcmp($a, $b) { + global $order; + return strcmp($a[$order], $b[$order]); } -if ($_GET['order']) { - if ($_GET['order'] == "ip") - $order = 2; - else if ($_GET['order'] == "mac") - $order = 3; - else if ($_GET['order'] == "user") - $order = 4; - else if ($_GET['order'] == "lastact") - $order = 5; - else - $order = 0; - usort($cpdb, "clientcmp"); + +if (!empty($cpzone)) { + $cpdb = array(); + if (file_exists("{$g['vardb_path']}/captiveportal_{$cpzone}.db")) { + $captiveportallck = lock('captiveportaldb{$cpzone}'); + $cpcontents = file("/var/db/captiveportal_{$cpzone}.db", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + unlock($captiveportallck); + } else + $cpcontents = array(); + + $concurrent = count($cpcontents); + + foreach ($cpcontents as $cpcontent) { + $cpent = explode(",", $cpcontent); + $sessionid = $cpent[5]; + if ($_GET['showact']) + $cpent[5] = captiveportal_get_last_activity($cpent[2]); + $cpdb[$sessionid] = $cpent; + } + if ($_GET['order']) { + if ($_GET['order'] == "ip") + $order = 2; + else if ($_GET['order'] == "mac") + $order = 3; + else if ($_GET['order'] == "user") + $order = 4; + else if ($_GET['order'] == "lastact") + $order = 5; + else + $order = 0; + usort($cpdb, "clientcmp"); + } } ?> -<?php if (isset($config['voucher']['enable'])): ?> +<?php if (!empty($cpzone) && isset($config['voucher'][$cpzone]['enable'])): ?> <form action="status_captiveportal.php" method="post" enctype="multipart/form-data" name="iform" id="iform"> <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="tab pane"> <tr><td class="tabnavtbl"> <?php $tab_array = array(); - $tab_array[] = array(gettext("Active Users"), true, "status_captiveportal.php"); - $tab_array[] = array(gettext("Active Vouchers"), false, "status_captiveportal_vouchers.php"); - $tab_array[] = array(gettext("Voucher Rolls"), false, "status_captiveportal_voucher_rolls.php"); - $tab_array[] = array(gettext("Test Vouchers"), false, "status_captiveportal_test.php"); + $tab_array[] = array(gettext("Active Users"), true, "status_captiveportal.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Active Vouchers"), false, "status_captiveportal_vouchers.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Voucher Rolls"), false, "status_captiveportal_voucher_rolls.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Test Vouchers"), false, "status_captiveportal_test.php?zone={$cpzone}"); display_top_tabs($tab_array); ?> </td></tr> @@ -121,6 +131,32 @@ if ($_GET['order']) { <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> + <td width="20%" class="vncell" valign="top"> + <br/><?=gettext("Captive Portal Zone"); ?><br/<br/> + </td> + <td "class="vncell" width="30%" align="center"> + <form action="status_captiveportal.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> + <select name="zone" class="formselect" onchange="document.form1.submit()"> + echo "<option value="">none</option>\n"; + <?php foreach ($a_cp as $cpkey => $cp) { + echo "<option value='{$cpkey}' "; + if ($cpzone == $cpkey) + echo "selected"; + echo ">" . htmlspecialchars($cp['zone']) . "</option>\n"; + } + ?> + </select> + <br/> + </form> + </td> + <td colspan="3" width="50%"></td> + </tr> + <tr><td colspan="5"><br/></tr> +<?php if (!empty($cpzone)): ?> + <tr> + <td colspan="5" valign="top" class="listtopic"><?=gettext("Captiveportal status");?></td> + </tr> + <tr> <td class="listhdrr"><a href="?order=ip&showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("IP address");?></a></td> <td class="listhdrr"><a href="?order=mac&showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("MAC address");?></a></td> <td class="listhdrr"><a href="?order=user&showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("Username");?></a></td> @@ -142,12 +178,12 @@ if ($_GET['order']) { <td class="listr"><?php if ($cpent[5]) echo htmlspecialchars(date("m/d/Y H:i:s", $cpent[5]));?></td> <?php endif; ?> <td valign="middle" class="list" nowrap> - <a href="?order=<?=$_GET['order'];?>&showact=<?=htmlspecialchars($_GET['showact']);?>&act=del&id=<?=$sid;?>" onclick="return confirm('<?=gettext("Do you really want to disconnect this client?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" title="<?=gettext("Disconnect");?>"></a></td> + <a href="?zone=<?=$cpzone;?>&order=<?=$_GET['order'];?>&showact=<?=htmlspecialchars($_GET['showact']);?>&act=del&id=<?=$sid;?>" onclick="return confirm('<?=gettext("Do you really want to disconnect this client?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" title="<?=gettext("Disconnect");?>"></a></td> </tr> -<?php endforeach; ?> +<?php endforeach; endif; ?> </table> -<?php if (isset($config['voucher']['enable'])): ?> +<?php if (!empty($cpzone) && isset($config['voucher'][$cpzone]['enable'])): ?> </td> </tr> </table> @@ -156,6 +192,7 @@ if ($_GET['order']) { <form action="status_captiveportal.php" method="get" style="margin: 14px;"> <input type="hidden" name="order" value="<?=$_GET['order'];?>" /> +<?php if (!empty($cpzone)): ?> <?php if ($_GET['showact']): ?> <input type="hidden" name="showact" value="0" /> <input type="submit" class="formbtn" value="<?=gettext("Don't show last activity");?>" /> @@ -163,6 +200,8 @@ if ($_GET['order']) { <input type="hidden" name="showact" value="1" /> <input type="submit" class="formbtn" value="<?=gettext("Show last activity");?>" /> <?php endif; ?> +<input type="hidden" name="zone" value="<?=$cpzone;?>" /> +<?php endif; ?> </form> <?php include("fend.inc"); ?> diff --git a/usr/local/www/status_captiveportal_test.php b/usr/local/www/status_captiveportal_test.php index 576a019..514fa21 100644 --- a/usr/local/www/status_captiveportal_test.php +++ b/usr/local/www/status_captiveportal_test.php @@ -42,10 +42,24 @@ require("shaper.inc"); require("captiveportal.inc"); require_once("voucher.inc"); -$pgtitle = array(gettext("Status"), gettext("Captive portal"), gettext("Test Vouchers")); +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) + $cpzone = $_POST['zone']; + +if (empty($cpzone)) { + header("Location: services_captiveportal_zones.php"); + exit; +} + +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; + +$pgtitle = array(gettext("Status"), gettext("Captive portal"), gettext("Test Vouchers"), $a_cp[$cpzone]['zone']); include("head.inc"); include("fbegin.inc"); + ?> <form action="status_captiveportal_test.php" method="post" enctype="multipart/form-data" name="iform" id="iform"> @@ -53,10 +67,10 @@ include("fbegin.inc"); <tr><td class="tabnavtbl"> <?php $tab_array = array(); - $tab_array[] = array(gettext("Active Users"), false, "status_captiveportal.php"); - $tab_array[] = array(gettext("Active Vouchers"), false, "status_captiveportal_vouchers.php"); - $tab_array[] = array(gettext("Voucher Rolls"), false, "status_captiveportal_voucher_rolls.php"); - $tab_array[] = array(gettext("Test Vouchers"), true, "status_captiveportal_test.php"); + $tab_array[] = array(gettext("Active Users"), false, "status_captiveportal.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Active Vouchers"), false, "status_captiveportal_vouchers.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Voucher Rolls"), false, "status_captiveportal_voucher_rolls.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Test Vouchers"), true, "status_captiveportal_test.php?zone={$cpzone}"); display_top_tabs($tab_array); ?> </td></tr> @@ -74,6 +88,7 @@ include("fbegin.inc"); <tr> <td width="22%" valign="top"> </td> <td width="78%"> + <input name="zone" type="hidden" value="<?=$cpzone;?>"> <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Submit"); ?>"> </td> </tr> diff --git a/usr/local/www/status_captiveportal_voucher_rolls.php b/usr/local/www/status_captiveportal_voucher_rolls.php index 3276c7b..f066fd7 100644 --- a/usr/local/www/status_captiveportal_voucher_rolls.php +++ b/usr/local/www/status_captiveportal_voucher_rolls.php @@ -41,12 +41,25 @@ require("filter.inc"); require("shaper.inc"); require("captiveportal.inc"); require_once("voucher.inc"); -$pgtitle = array(gettext("Status"), gettext("Captive portal"), gettext("Voucher Rolls")); -if (!is_array($config['voucher']['roll'])) { - $config['voucher']['roll'] = array(); +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) + $cpzone = $_POST['zone']; + +if (empty($cpzone)) { + header("Location: services_captiveportal_zones.php"); + exit; +} + +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; +$pgtitle = array(gettext("Status"), gettext("Captive portal"), gettext("Voucher Rolls"), $a_cp[$cpzone]['zone']); + +if (!is_array($config['voucher'][$cpzone]['roll'])) { + $config['voucher'][$cpzone]['roll'] = array(); } -$a_roll = &$config['voucher']['roll']; +$a_roll = &$config['voucher'][$cpzone]['roll']; include("head.inc"); include("fbegin.inc"); @@ -57,10 +70,10 @@ include("fbegin.inc"); <tr><td class="tabnavtbl"> <?php $tab_array = array(); - $tab_array[] = array(gettext("Active Users"), false, "status_captiveportal.php"); - $tab_array[] = array(gettext("Active Vouchers"), false, "status_captiveportal_vouchers.php"); - $tab_array[] = array(gettext("Voucher Rolls"), true, "status_captiveportal_voucher_rolls.php"); - $tab_array[] = array(gettext("Test Vouchers"), false, "status_captiveportal_test.php"); + $tab_array[] = array(gettext("Active Users"), false, "status_captiveportal.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Active Vouchers"), false, "status_captiveportal_vouchers.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Voucher Rolls"), true, "status_captiveportal_voucher_rolls.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Test Vouchers"), false, "status_captiveportal_test.php?zone={$cpzone}"); display_top_tabs($tab_array); ?> </td></tr> @@ -78,7 +91,7 @@ include("fbegin.inc"); <td class="listhdr"><?=gettext("ready"); ?></td> </tr> <?php - $voucherlck = lock('voucher'); + $voucherlck = lock("vouche{$cpzone}r"); $i = 0; foreach($a_roll as $rollent): $used = voucher_used_count($rollent['number']); $active = count(voucher_read_active_db($rollent['number']),$rollent['minutes']); diff --git a/usr/local/www/status_captiveportal_vouchers.php b/usr/local/www/status_captiveportal_vouchers.php index 4d3afd8..05d534e 100644 --- a/usr/local/www/status_captiveportal_vouchers.php +++ b/usr/local/www/status_captiveportal_vouchers.php @@ -41,24 +41,37 @@ require("filter.inc"); require("shaper.inc"); require("captiveportal.inc"); require_once("voucher.inc"); -$pgtitle = array(gettext("Status"), gettext("Captive portal"), gettext("Vouchers")); + +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) + $cpzone = $_POST['zone']; + +if (empty($cpzone)) { + header("Location: services_captiveportal_zones.php"); + exit; +} + +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; +$pgtitle = array(gettext("Status"), gettext("Captive portal"), gettext("Vouchers"), $a_cp[$cpzone]['zone']); function clientcmp($a, $b) { global $order; return strcmp($a[$order], $b[$order]); } -if (!is_array($config['voucher']['roll'])) { - $config['voucher']['roll'] = array(); +if (!is_array($config['voucher'][$cpzone]['roll'])) { + $config['voucher'][$cpzone]['roll'] = array(); } -$a_roll = $config['voucher']['roll']; +$a_roll = $config['voucher'][$cpzone]['roll']; $db = array(); foreach($a_roll as $rollent) { $roll = $rollent['number']; $minutes = $rollent['minutes']; - $active_vouchers = file("{$g['vardb_path']}/voucher_active_$roll.db", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $active_vouchers = file("{$g['vardb_path']}/voucher_{$cpzone}_active_$roll.db", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach($active_vouchers as $voucher => $line) { list($voucher,$timestamp, $minutes) = explode(",", $line); $remaining = (($timestamp + 60*$minutes) - time()); @@ -87,10 +100,10 @@ include("fbegin.inc"); <tr><td class="tabnavtbl"> <?php $tab_array = array(); - $tab_array[] = array(gettext("Active Users"), false, "status_captiveportal.php"); - $tab_array[] = array(gettext("Active Vouchers"), true, "status_captiveportal_vouchers.php"); - $tab_array[] = array(gettext("Voucher Rolls"), false, "status_captiveportal_voucher_rolls.php"); - $tab_array[] = array(gettext("Test Vouchers"), false, "status_captiveportal_test.php"); + $tab_array[] = array(gettext("Active Users"), false, "status_captiveportal.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Active Vouchers"), true, "status_captiveportal_vouchers.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Voucher Rolls"), false, "status_captiveportal_voucher_rolls.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Test Vouchers"), false, "status_captiveportal_test.php?zone={$cpzone}"); display_top_tabs($tab_array); ?> </td></tr> |