Commit d03721da authored by Franco Fichtner's avatar Franco Fichtner

captiveportal: apply PSR2 style

parent 87387963
......@@ -30,14 +30,16 @@
$captiveportal_element_sizelimit = 1048576;
function cpelementscmp($a, $b) {
return strcasecmp($a['name'], $b['name']);
function cpelementscmp($a, $b)
{
return strcasecmp($a['name'], $b['name']);
}
function cpelements_sort() {
function cpelements_sort()
{
global $config, $cpzone;
usort($config['captiveportal'][$cpzone]['element'],"cpelementscmp");
usort($config['captiveportal'][$cpzone]['element'], "cpelementscmp");
}
require_once("guiconfig.inc");
......@@ -47,84 +49,87 @@ require_once("shaper.inc");
require_once("captiveportal.inc");
$cpzone = $_GET['zone'];
if (isset($_POST['zone']))
if (isset($_POST['zone'])) {
$cpzone = $_POST['zone'];
}
if (empty($cpzone)) {
header("Location: services_captiveportal_zones.php");
exit;
}
if (!is_array($config['captiveportal']))
if (!is_array($config['captiveportal'])) {
$config['captiveportal'] = array();
}
$a_cp =& $config['captiveportal'];
$pgtitle = array(gettext("Services"),gettext("Captive portal"), $a_cp[$cpzone]['zone']);
$shortcut_section = "captiveportal";
if (!is_array($a_cp[$cpzone]['element']))
$a_cp[$cpzone]['element'] = array();
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;
foreach ($a_element as $element) {
$total_size += $element['size'];
$total_size += $element['size'];
}
if ($_POST) {
unset($input_errors);
if (is_uploaded_file($_FILES['new']['tmp_name'])) {
if(!stristr($_FILES['new']['name'], "captiveportal-"))
$name = "captiveportal-" . $_FILES['new']['name'];
else
$name = $_FILES['new']['name'];
$size = filesize($_FILES['new']['tmp_name']);
// is there already a file with that name?
foreach ($a_element as $element) {
if ($element['name'] == $name) {
$input_errors[] = sprintf(gettext("A file with the name '%s' already exists."), $name);
break;
}
}
// check total file size
if (($total_size + $size) > $captiveportal_element_sizelimit) {
$input_errors[] = gettext("The total size of all files uploaded may not exceed ") .
format_bytes($captiveportal_element_sizelimit) . ".";
}
if (!$input_errors) {
$element = array();
$element['name'] = $name;
$element['size'] = $size;
$element['content'] = base64_encode(file_get_contents($_FILES['new']['tmp_name']));
$a_element[] = $element;
cpelements_sort();
write_config();
captiveportal_write_elements();
header("Location: services_captiveportal_filemanager.php?zone={$cpzone}");
exit;
}
if (!stristr($_FILES['new']['name'], "captiveportal-")) {
$name = "captiveportal-" . $_FILES['new']['name'];
} else {
$name = $_FILES['new']['name'];
}
$size = filesize($_FILES['new']['tmp_name']);
// is there already a file with that name?
foreach ($a_element as $element) {
if ($element['name'] == $name) {
$input_errors[] = sprintf(gettext("A file with the name '%s' already exists."), $name);
break;
}
}
// check total file size
if (($total_size + $size) > $captiveportal_element_sizelimit) {
$input_errors[] = gettext("The total size of all files uploaded may not exceed ") .
format_bytes($captiveportal_element_sizelimit) . ".";
}
if (!$input_errors) {
$element = array();
$element['name'] = $name;
$element['size'] = $size;
$element['content'] = base64_encode(file_get_contents($_FILES['new']['tmp_name']));
$a_element[] = $element;
cpelements_sort();
write_config();
captiveportal_write_elements();
header("Location: services_captiveportal_filemanager.php?zone={$cpzone}");
exit;
}
}
} else if (($_GET['act'] == "del") && !empty($cpzone) && $a_element[$_GET['id']]) {
@unlink("/var/db/cpelements/" . $a_element[$_GET['id']]['name']);
@unlink("/usr/local/captiveportal/" . $a_element[$_GET['id']]['name']);
unset($a_element[$_GET['id']]);
write_config();
header("Location: services_captiveportal_filemanager.php?zone={$cpzone}");
exit;
} elseif (($_GET['act'] == "del") && !empty($cpzone) && $a_element[$_GET['id']]) {
@unlink("/var/db/cpelements/" . $a_element[$_GET['id']]['name']);
@unlink("/usr/local/captiveportal/" . $a_element[$_GET['id']]['name']);
unset($a_element[$_GET['id']]);
write_config();
header("Location: services_captiveportal_filemanager.php?zone={$cpzone}");
exit;
}
include("head.inc");
$main_buttons = array(
array('label'=>gettext('add file'), 'href'=>'services_captiveportal_filemanager.php?zone='.$cpzone.'&act=add'),
array('label'=>gettext('add file'), 'href'=>'services_captiveportal_filemanager.php?zone='.$cpzone.'&act=add'),
);
......@@ -138,21 +143,23 @@ $main_buttons = array(
<div class="container-fluid">
<div class="row">
<?php if ($input_errors) print_input_errors($input_errors); ?>
<?php if ($input_errors) {
print_input_errors($input_errors);
} ?>
<section class="col-xs-12">
<?php
$tab_array = array();
$tab_array[] = array(gettext("Captive portal(s)"), false, "services_captiveportal.php?zone={$cpzone}");
$tab_array[] = array(gettext("MAC"), false, "services_captiveportal_mac.php?zone={$cpzone}");
$tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php?zone={$cpzone}");
// Hide Allowed Hostnames as this feature is currently not supported
// $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);
?>
$tab_array = array();
$tab_array[] = array(gettext("Captive portal(s)"), false, "services_captiveportal.php?zone={$cpzone}");
$tab_array[] = array(gettext("MAC"), false, "services_captiveportal_mac.php?zone={$cpzone}");
$tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php?zone={$cpzone}");
// Hide Allowed Hostnames as this feature is currently not supported
// $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);
?>
<div class="tab-content content-box col-xs-12">
......@@ -162,7 +169,8 @@ $main_buttons = array(
<input type="hidden" name="zone" id="zone" value="<?=htmlspecialchars($cpzone);?>" />
<?php if ($_GET['act'] == 'add'): ?>
<?php if ($_GET['act'] == 'add') :
?>
<div class="table-responsive">
<table class="table table-striped table-sort">
<tr>
......@@ -180,7 +188,8 @@ $main_buttons = array(
</div>
<br/>
<?php endif; ?>
<?php
endif; ?>
......@@ -193,25 +202,34 @@ $main_buttons = array(
</td>
</tr>
<?php if (is_array($a_cp[$cpzone]['element'])):
$i = 0; foreach ($a_cp[$cpzone]['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" class="list nowrap">
<a href="services_captiveportal_filemanager.php?zone=<?=$cpzone;?>&amp;act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this file?"); ?>')">
<a href="services_captiveportal_filemanager.php?zone=<?=$cpzone;
?>&amp;act=del&amp;id=<?=$i;
?>" onclick="return confirm('<?=gettext("Do you really want to delete this file?"); ?>')">
<span class="glyphicon glyphicon-remove" title="<?=gettext("delete file"); ?>"></span></a>
</td>
</tr>
<?php $i++; endforeach; endif; ?>
<?php $i++;
endforeach;
<?php if ($total_size > 0): ?>
endif; ?>
<?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>
<td valign="middle" style="background-color: #eee" class="list nowrap"></td>
</tr>
<?php endif; ?>
<?php
endif; ?>
</table>
</div>
......@@ -220,14 +238,14 @@ $main_buttons = array(
<?=gettext("Note:"); ?><br />
</strong></span>
<?=gettext("Any files that you upload here with the filename prefix of captiveportal- will " .
"be made available in the root directory of the captive portal HTTP(S) server. " .
"You may reference them directly from your portal page HTML code using relative paths. " .
"Example: you've uploaded an image with the name 'captiveportal-test.jpg' using the " .
"file manager. Then you can include it in your portal page like this:"); ?><br /><br />
"be made available in the root directory of the captive portal HTTP(S) server. " .
"You may reference them directly from your portal page HTML code using relative paths. " .
"Example: you've uploaded an image with the name 'captiveportal-test.jpg' using the " .
"file manager. Then you can include it in your portal page like this:"); ?><br /><br />
<tt>&lt;img src=&quot;captiveportal-test.jpg&quot; width=... height=...&gt;</tt>
<br /><br />
<?=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:"); ?>
"to your custom page from the initial page by using text similar to:"); ?>
<br /><br />
<tt>&lt;a href="/captiveportal-aup.php?zone=$PORTAL_ZONE$&amp;redirurl=$PORTAL_REDIRURL$"&gt;<?=gettext("Acceptable usage policy"); ?>&lt;/a&gt;</tt>
<br /><br />
......@@ -241,4 +259,4 @@ $main_buttons = array(
</div>
</section>
<?php include("foot.inc"); ?>
<?php include("foot.inc");
......@@ -33,37 +33,39 @@ require_once("shaper.inc");
require_once("captiveportal.inc");
$cpzone = $_GET['zone'];
if (isset($_POST['zone']))
if (isset($_POST['zone'])) {
$cpzone = $_POST['zone'];
}
if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
header("Location: services_captiveportal_zones.php");
exit;
}
if (!is_array($config['captiveportal']))
if (!is_array($config['captiveportal'])) {
$config['captiveportal'] = array();
}
$a_cp =& $config['captiveportal'];
$pgtitle = array(gettext("Services"),gettext("Captive portal"), $a_cp[$cpzone]['zone']);
$shortcut_section = "captiveportal";
if ($_GET['act'] == "del") {
$a_allowedips =& $config['captiveportal'][$cpzone]['allowedip'];
if ($a_allowedips[$_GET['id']]) {
$ipent = $a_allowedips[$_GET['id']];
unset($a_allowedips[$_GET['id']]);
write_config();
header("Location: services_captiveportal_ip.php?zone={$cpzone}");
exit;
}
$a_allowedips =& $config['captiveportal'][$cpzone]['allowedip'];
if ($a_allowedips[$_GET['id']]) {
$ipent = $a_allowedips[$_GET['id']];
unset($a_allowedips[$_GET['id']]);
write_config();
header("Location: services_captiveportal_ip.php?zone={$cpzone}");
exit;
}
}
include("head.inc");
$main_buttons = array(
array('label'=>'Add IP address', 'href'=>'services_captiveportal_ip_edit.php?zone='.$cpzone),
array('label'=>'Add IP address', 'href'=>'services_captiveportal_ip_edit.php?zone='.$cpzone),
);
......@@ -77,21 +79,23 @@ $main_buttons = array(
<div class="container-fluid">
<div class="row">
<?php if ($savemsg) print_info_box($savemsg); ?>
<?php if ($savemsg) {
print_info_box($savemsg);
} ?>
<section class="col-xs-12">
<?php
$tab_array = array();
$tab_array[] = array(gettext("Captive portal(s)"), false, "services_captiveportal.php?zone={$cpzone}");
$tab_array[] = array(gettext("MAC"), false, "services_captiveportal_mac.php?zone={$cpzone}");
$tab_array[] = array(gettext("Allowed IP addresses"), true, "services_captiveportal_ip.php?zone={$cpzone}");
// Hide Allowed Hostnames as this feature is currently not supported
// $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);
?>
$tab_array = array();
$tab_array[] = array(gettext("Captive portal(s)"), false, "services_captiveportal.php?zone={$cpzone}");
$tab_array[] = array(gettext("MAC"), false, "services_captiveportal_mac.php?zone={$cpzone}");
$tab_array[] = array(gettext("Allowed IP addresses"), true, "services_captiveportal_ip.php?zone={$cpzone}");
// Hide Allowed Hostnames as this feature is currently not supported
// $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);
?>
<div class="tab-content content-box col-xs-12">
......@@ -109,41 +113,50 @@ $main_buttons = array(
</td>
</tr>
<?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;?>&amp;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;
?>&amp;id=<?=$i;?>'">
<td class="listlr">
<?php
if($ip['dir'] == "to") {
echo "any <span class=\"glyphicon glyphicon-arrow-right\" aria-hidden=\"true\" alt=\"in\"></span> ";
}
if($ip['dir'] == "both") {
echo "<span class=\"glyphicon glyphicon-resize-horizontal\" aria-hidden=\"true\" alt=\"pass\"></span> ";
}
echo strtolower($ip['ip']);
if($ip['sn'] != "32" && is_numeric($ip['sn'])) {
$sn = $ip['sn'];
echo "/$sn";
}
if($ip['dir'] == "from") {
echo "<span class=\"glyphicon glyphicon-arrow-right\" aria-hidden=\"true\" alt=\"any\"></span> any";
}
?>
if ($ip['dir'] == "to") {
echo "any <span class=\"glyphicon glyphicon-arrow-right\" aria-hidden=\"true\" alt=\"in\"></span> ";
}
if ($ip['dir'] == "both") {
echo "<span class=\"glyphicon glyphicon-resize-horizontal\" aria-hidden=\"true\" alt=\"pass\"></span> ";
}
echo strtolower($ip['ip']);
if ($ip['sn'] != "32" && is_numeric($ip['sn'])) {
$sn = $ip['sn'];
echo "/$sn";
}
if ($ip['dir'] == "from") {
echo "<span class=\"glyphicon glyphicon-arrow-right\" aria-hidden=\"true\" alt=\"any\"></span> any";
}
?>
</td>
<td class="listbg">
<?=htmlspecialchars($ip['descr']);?>&nbsp;
</td>
<td valign="middle" class="list nowrap"><a href="services_captiveportal_ip_edit.php?zone=<?=$cpzone;?>&amp;id=<?=$i;?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
<a href="services_captiveportal_ip.php?zone=<?=$cpzone;?>&amp;act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this address?"); ?>')" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></a></td>
<td valign="middle" class="list nowrap"><a href="services_captiveportal_ip_edit.php?zone=<?=$cpzone;
?>&amp;id=<?=$i;?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
<a href="services_captiveportal_ip.php?zone=<?=$cpzone;
?>&amp;act=del&amp;id=<?=$i;
?>" onclick="return confirm('<?=gettext("Do you really want to delete this address?"); ?>')" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></a></td>
</tr>
<?php $i++; endforeach; endif; ?>
<?php $i++;
endforeach;
endif; ?>
<tr>
<td colspan="2" class="list"><p class="vexpl"><span class="red"><strong>
<?=gettext("Note:"); ?><br />
<?=gettext("Note:"); ?><br />
</strong></span>
<?=gettext("Adding allowed IP addresses will allow IP access to/from these addresses through the captive portal without being taken to the portal page. This can be used for a web server serving images for the portal page or a DNS server on another network, for example."); ?></p>
<?=gettext("Adding allowed IP addresses will allow IP access to/from these addresses through the captive portal without being taken to the portal page. This can be used for a web server serving images for the portal page or a DNS server on another network, for example."); ?></p>
</td>
<td class="list">&nbsp;</td>
</tr>
......@@ -157,4 +170,4 @@ $main_buttons = array(
</div>
</section>
<?php include("foot.inc"); ?>
<?php include("foot.inc");
......@@ -28,14 +28,16 @@
POSSIBILITY OF SUCH DAMAGE.
*/
function allowedipscmp($a, $b) {
return strcmp($a['ip'], $b['ip']);
function allowedipscmp($a, $b)
{
return strcmp($a['ip'], $b['ip']);
}
function allowedips_sort() {
global $g, $config, $cpzone;
function allowedips_sort()
{
global $g, $config, $cpzone;
usort($config['captiveportal'][$cpzone]['allowedip'],"allowedipscmp");
usort($config['captiveportal'][$cpzone]['allowedip'], "allowedipscmp");
}
require_once("guiconfig.inc");
......@@ -48,102 +50,114 @@ $pgtitle = array(gettext("Services"),gettext("Captive portal"),gettext("Edit all
$shortcut_section = "captiveportal";
$cpzone = $_GET['zone'];
if (isset($_POST['zone']))
if (isset($_POST['zone'])) {
$cpzone = $_POST['zone'];
}
if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
header("Location: services_captiveportal_zones.php");
exit;
}
if (!is_array($config['captiveportal']))
if (!is_array($config['captiveportal'])) {
$config['captiveportal'] = array();
}
$a_cp =& $config['captiveportal'];
if (is_numericint($_GET['id']))
$id = $_GET['id'];
if (isset($_POST['id']) && is_numericint($_POST['id']))
$id = $_POST['id'];
if (is_numericint($_GET['id'])) {
$id = $_GET['id'];
}
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
$id = $_POST['id'];
}
if (!is_array($config['captiveportal'][$cpzone]['allowedip']))
$config['captiveportal'][$cpzone]['allowedip'] = array();
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'];
$pconfig['bw_up'] = $a_allowedips[$id]['bw_up'];
$pconfig['bw_down'] = $a_allowedips[$id]['bw_down'];
$pconfig['descr'] = $a_allowedips[$id]['descr'];
$pconfig['ip'] = $a_allowedips[$id]['ip'];
$pconfig['sn'] = $a_allowedips[$id]['sn'];
$pconfig['bw_up'] = $a_allowedips[$id]['bw_up'];
$pconfig['bw_down'] = $a_allowedips[$id]['bw_down'];
$pconfig['descr'] = $a_allowedips[$id]['descr'];
}
if ($_POST) {
unset($input_errors);
$pconfig = $_POST;
/* input validation */
$reqdfields = explode(" ", "ip sn");
$reqdfieldsn = array(gettext("Allowed IP address"), gettext("Subnet mask"));
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
if ($_POST['ip'] && !is_ipaddr($_POST['ip']))
$input_errors[] = sprintf(gettext("A valid IP address must be specified. [%s]"), $_POST['ip']);
if ($_POST['sn'] && (!is_numeric($_POST['sn']) || ($_POST['sn'] < 1) || ($_POST['sn'] > 32)))
$input_errors[] = gettext("A valid subnet mask must be specified");
if ($_POST['bw_up'] && !is_numeric($_POST['bw_up']))
$input_errors[] = gettext("Upload speed needs to be an integer");
if ($_POST['bw_down'] && !is_numeric($_POST['bw_down']))
$input_errors[] = gettext("Download speed needs to be an integer");
foreach ($a_allowedips as $ipent) {
if (isset($id) && ($a_allowedips[$id]) && ($a_allowedips[$id] === $ipent))
continue;
if ($ipent['ip'] == $_POST['ip']){
$input_errors[] = sprintf("[%s] %s.", $_POST['ip'], gettext("already allowed")) ;
break ;
}
}
if (!$input_errors) {
$ip = array();
$ip['ip'] = $_POST['ip'];
$ip['sn'] = $_POST['sn'];
$ip['descr'] = $_POST['descr'];
if ($_POST['bw_up'])
$ip['bw_up'] = $_POST['bw_up'];
if ($_POST['bw_down'])
$ip['bw_down'] = $_POST['bw_down'];
if (isset($id) && $a_allowedips[$id]) {
$oldip = $a_allowedips[$id]['ip'];
if (!empty($a_allowedips[$id]['sn']))
$oldmask = $a_allowedips[$id]['sn'];
else
$oldmask = 32;
$a_allowedips[$id] = $ip;
} else {
$a_allowedips[] = $ip;
}
allowedips_sort();
write_config();
if (isset($a_cp[$cpzone]['enable']) && is_module_loaded("ipfw.ko")) {
$rules = "";
$cpzoneid = $a_cp[$cpzone]['zoneid'];
unset($ipfw);
captiveportal_allowedip_configure_entry($ip);
$uniqid = uniqid("{$cpzone}_allowed");
}
header("Location: services_captiveportal_ip.php?zone={$cpzone}");
exit;
}
unset($input_errors);
$pconfig = $_POST;
/* input validation */
$reqdfields = explode(" ", "ip sn");
$reqdfieldsn = array(gettext("Allowed IP address"), gettext("Subnet mask"));
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
if ($_POST['ip'] && !is_ipaddr($_POST['ip'])) {
$input_errors[] = sprintf(gettext("A valid IP address must be specified. [%s]"), $_POST['ip']);
}
if ($_POST['sn'] && (!is_numeric($_POST['sn']) || ($_POST['sn'] < 1) || ($_POST['sn'] > 32))) {
$input_errors[] = gettext("A valid subnet mask must be specified");
}
if ($_POST['bw_up'] && !is_numeric($_POST['bw_up'])) {
$input_errors[] = gettext("Upload speed needs to be an integer");
}
if ($_POST['bw_down'] && !is_numeric($_POST['bw_down'])) {
$input_errors[] = gettext("Download speed needs to be an integer");
}
foreach ($a_allowedips as $ipent) {
if (isset($id) && ($a_allowedips[$id]) && ($a_allowedips[$id] === $ipent)) {
continue;
}
if ($ipent['ip'] == $_POST['ip']) {
$input_errors[] = sprintf("[%s] %s.", $_POST['ip'], gettext("already allowed")) ;
break ;
}
}
if (!$input_errors) {
$ip = array();
$ip['ip'] = $_POST['ip'];
$ip['sn'] = $_POST['sn'];
$ip['descr'] = $_POST['descr'];
if ($_POST['bw_up']) {
$ip['bw_up'] = $_POST['bw_up'];
}
if ($_POST['bw_down']) {
$ip['bw_down'] = $_POST['bw_down'];
}
if (isset($id) && $a_allowedips[$id]) {
$oldip = $a_allowedips[$id]['ip'];
if (!empty($a_allowedips[$id]['sn'])) {
$oldmask = $a_allowedips[$id]['sn'];
} else {
$oldmask = 32;
}
$a_allowedips[$id] = $ip;
} else {
$a_allowedips[] = $ip;
}
allowedips_sort();
write_config();
if (isset($a_cp[$cpzone]['enable']) && is_module_loaded("ipfw.ko")) {
$rules = "";
$cpzoneid = $a_cp[$cpzone]['zoneid'];
unset($ipfw);
captiveportal_allowedip_configure_entry($ip);
$uniqid = uniqid("{$cpzone}_allowed");
}
header("Location: services_captiveportal_ip.php?zone={$cpzone}");
exit;
}
}
include("head.inc");
......@@ -160,7 +174,9 @@ include("head.inc");
<div class="row">
<?php if ($input_errors) print_input_errors($input_errors); ?>
<?php if ($input_errors) {
print_input_errors($input_errors);
} ?>
<section class="col-xs-12">
......@@ -176,11 +192,17 @@ include("head.inc");
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("IP address"); ?></td>
<td width="78%" class="vtable">
<?=$mandfldhtml;?><input name="ip" type="text" class="formfld unknown" id="ip" size="17" value="<?=htmlspecialchars($pconfig['ip']);?>" />
<?=$mandfldhtml;
?><input name="ip" type="text" class="formfld unknown" id="ip" size="17" value="<?=htmlspecialchars($pconfig['ip']);?>" />
/<select name='sn' class="formselect" id='sn'>
<?php for ($i = 32; $i >= 1; $i--): ?>
<option value="<?=$i;?>" <?php if ($i == $pconfig['sn']) echo "selected=\"selected\""; ?>><?=$i;?></option>
<?php endfor; ?>
<?php for ($i = 32; $i >= 1; $i--) :
?>
<option value="<?=$i;?>" <?php if ($i == $pconfig['sn']) {
echo "selected=\"selected\"";
} ?>><?=$i;?></option>
<?php
endfor; ?>
</select>
<br />
<span class="vexpl"><?=gettext("IP address and subnet mask. Use /32 for a single IP");?>.</span>
......@@ -214,9 +236,11 @@ include("head.inc");
<td width="78%">
<input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
<input name="zone" type="hidden" value="<?=htmlspecialchars($cpzone);?>" />
<?php if (isset($id) && $a_allowedips[$id]): ?>
<?php if (isset($id) && $a_allowedips[$id]) :
?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
<?php endif; ?>
<?php
endif; ?>
</td>
</tr>
</table>
......@@ -228,4 +252,4 @@ include("head.inc");
</div>
</section>
<?php include("foot.inc"); ?>
<?php include("foot.inc");
......@@ -37,91 +37,96 @@ global $cpzone;
global $cpzoneid;
$cpzone = $_GET['zone'];
if (isset($_POST['zone']))
$cpzone = $_POST['zone'];
if (isset($_POST['zone'])) {
$cpzone = $_POST['zone'];
}
if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
header("Location: services_captiveportal_zones.php");
exit;
header("Location: services_captiveportal_zones.php");
exit;
}
if (!is_array($config['captiveportal']))
$config['captiveportal'] = array();
if (!is_array($config['captiveportal'])) {
$config['captiveportal'] = array();
}
$a_cp =& $config['captiveportal'];
$pgtitle = array(gettext("Services"),gettext("Captive portal"), $a_cp[$cpzone]['zone']);
$shortcut_section = "captiveportal";
if ($_POST) {
$pconfig = $_POST;
if ($_POST['apply']) {
$retval = 0;
$rules = captiveportal_passthrumac_configure();
$savemsg = get_std_save_message($retval);
if ($retval == 0)
clear_subsystem_dirty('passthrumac');
}
if ($_POST['postafterlogin']) {
if (!is_array($a_passthrumacs)) {
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))
$_POST['delmac'] = $mac['mac'];
else
echo gettext("No entry exists for this username:") . " " . $_POST['username'] . "\n";
}
if ($_POST['delmac']) {
$found = false;
foreach ($a_passthrumacs as $idx => $macent) {
if ($macent['mac'] == $_POST['delmac']) {
$found = true;
break;
}
}
if ($found == true) {
$cpzoneid = $a_cp[$cpzone]['zoneid'];
captiveportal_passthrumac_delete_entry($a_passthrumacs[$idx]);
unset($a_passthrumacs[$idx]);
write_config();
echo gettext("The entry was sucessfully deleted") . "\n";
} else
echo gettext("No entry exists for this mac address:") . " " . $_POST['delmac'] . "\n";
}
exit;
}
$pconfig = $_POST;
if ($_POST['apply']) {
$retval = 0;
$rules = captiveportal_passthrumac_configure();
$savemsg = get_std_save_message($retval);
if ($retval == 0) {
clear_subsystem_dirty('passthrumac');
}
}
if ($_POST['postafterlogin']) {
if (!is_array($a_passthrumacs)) {
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)) {
$_POST['delmac'] = $mac['mac'];
} else {
echo gettext("No entry exists for this username:") . " " . $_POST['username'] . "\n";
}
}
if ($_POST['delmac']) {
$found = false;
foreach ($a_passthrumacs as $idx => $macent) {
if ($macent['mac'] == $_POST['delmac']) {
$found = true;
break;
}
}
if ($found == true) {
$cpzoneid = $a_cp[$cpzone]['zoneid'];
captiveportal_passthrumac_delete_entry($a_passthrumacs[$idx]);
unset($a_passthrumacs[$idx]);
write_config();
echo gettext("The entry was sucessfully deleted") . "\n";
} else {
echo gettext("No entry exists for this mac address:") . " " . $_POST['delmac'] . "\n";
}
}
exit;
}
}
if ($_GET['act'] == "del") {
$a_passthrumacs =& $a_cp[$cpzone]['passthrumac'];
if ($a_passthrumacs[$_GET['id']]) {
$cpzoneid = $a_cp[$cpzone]['zoneid'];
captiveportal_passthrumac_delete_entry($a_passthrumacs[$_GET['id']]);
unset($a_passthrumacs[$_GET['id']]);
write_config();
header("Location: services_captiveportal_mac.php?zone={$cpzone}");
exit;
}
$a_passthrumacs =& $a_cp[$cpzone]['passthrumac'];
if ($a_passthrumacs[$_GET['id']]) {
$cpzoneid = $a_cp[$cpzone]['zoneid'];
captiveportal_passthrumac_delete_entry($a_passthrumacs[$_GET['id']]);
unset($a_passthrumacs[$_GET['id']]);
write_config();
header("Location: services_captiveportal_mac.php?zone={$cpzone}");
exit;
}
}
include("head.inc");
$main_buttons = array(
array('label'=>gettext("add host"), 'href'=>'services_captiveportal_mac_edit.php?zone='.$cpzone),
array('label'=>gettext("add host"), 'href'=>'services_captiveportal_mac_edit.php?zone='.$cpzone),
);
?>
......@@ -132,24 +137,28 @@ $main_buttons = array(
<div class="container-fluid">
<div class="row">
<?php if ($savemsg) print_info_box($savemsg); ?>
<?php if (is_subsystem_dirty('passthrumac')): ?><p>
<?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 />
<?php endif; ?>
<?php
endif; ?>
<section class="col-xs-12">
<?php
$tab_array = array();
$tab_array[] = array(gettext("Captive portal(s)"), false, "services_captiveportal.php?zone={$cpzone}");
$tab_array[] = array(gettext("MAC"), true, "services_captiveportal_mac.php?zone={$cpzone}");
$tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php?zone={$cpzone}");
// Hide Allowed Hostnames as this feature is currently not supported
// $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);
?>
$tab_array = array();
$tab_array[] = array(gettext("Captive portal(s)"), false, "services_captiveportal.php?zone={$cpzone}");
$tab_array[] = array(gettext("MAC"), true, "services_captiveportal_mac.php?zone={$cpzone}");
$tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php?zone={$cpzone}");
// Hide Allowed Hostnames as this feature is currently not supported
// $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);
?>
<div class="tab-content content-box col-xs-12">
......@@ -167,31 +176,36 @@ $main_buttons = array(
<td width="10%" class="list"></td>
</tr>
<?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;?>&amp;id=<?=$i;?>'">
<td valign="middle" class="list nowrap">
<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$mac['action'];?>.gif" width="11" height="11" border="0" alt="icon" />
</td>
<td class="listlr">
<?=$mac['mac'];?>
</td>
<td class="listbg">
<?=htmlspecialchars($mac['descr']);?>&nbsp;
</td>
<td valign="middle" class="list nowrap">
<a href="services_captiveportal_mac_edit.php?zone=<?=$cpzone;?>&amp;id=<?=$i;?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
&nbsp;
<a href="services_captiveportal_mac.php?zone=<?=$cpzone;?>&amp;act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this host?"); ?>')" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></a>
</td>
</tr>
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;
?>&amp;id=<?=$i;?>'">
<td valign="middle" class="list nowrap">
<img src="./themes/<?= $g['theme'];
?>/images/icons/icon_<?=$mac['action'];?>.gif" width="11" height="11" border="0" alt="icon" />
</td>
<td class="listlr">
<?=$mac['mac'];?>
</td>
<td class="listbg">
<?=htmlspecialchars($mac['descr']);?>&nbsp;
</td>
<td valign="middle" class="list nowrap">
<a href="services_captiveportal_mac_edit.php?zone=<?=$cpzone;
?>&amp;id=<?=$i;?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
&nbsp;
<a href="services_captiveportal_mac.php?zone=<?=$cpzone;
?>&amp;act=del&amp;id=<?=$i;
?>" onclick="return confirm('<?=gettext("Do you really want to delete this host?"); ?>')" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></a>
</td>
</tr>
<?php
$i++;
endforeach;
endif;
?>
$i++;
endforeach;
endif;
?>
<tr>
<td colspan="3" class="list">
......@@ -213,4 +227,4 @@ $main_buttons = array(
</div>
</section>
<?php include("foot.inc"); ?>
<?php include("foot.inc");
......@@ -27,14 +27,16 @@
POSSIBILITY OF SUCH DAMAGE.
*/
function passthrumacscmp($a, $b) {
return strcmp($a['mac'], $b['mac']);
function passthrumacscmp($a, $b)
{
return strcmp($a['mac'], $b['mac']);
}
function passthrumacs_sort() {
global $config, $cpzone;
function passthrumacs_sort()
{
global $config, $cpzone;
usort($config['captiveportal'][$cpzone]['passthrumac'],"passthrumacscmp");
usort($config['captiveportal'][$cpzone]['passthrumac'], "passthrumacscmp");
}
require_once("guiconfig.inc");
......@@ -50,111 +52,121 @@ $pgtitle = array(gettext("Services"),gettext("Captive portal"),gettext("Edit MAC
$shortcut_section = "captiveportal";
$cpzone = $_GET['zone'];
if (isset($_POST['zone']))
$cpzone = $_POST['zone'];
if (isset($_POST['zone'])) {
$cpzone = $_POST['zone'];
}
if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
header("Location: services_captiveportal_zones.php");
exit;
header("Location: services_captiveportal_zones.php");
exit;
}
if (!is_array($config['captiveportal']))
$config['captiveportal'] = array();
if (!is_array($config['captiveportal'])) {
$config['captiveportal'] = array();
}
$a_cp =& $config['captiveportal'];
if (is_numericint($_GET['id']))
$id = $_GET['id'];
if (isset($_POST['id']) && is_numericint($_POST['id']))
$id = $_POST['id'];
if (is_numericint($_GET['id'])) {
$id = $_GET['id'];
}
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
$id = $_POST['id'];
}
if (!is_array($a_cp[$cpzone]['passthrumac']))
$a_cp[$cpzone]['passthrumac'] = array();
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['action'] = $a_passthrumacs[$id]['action'];
$pconfig['mac'] = $a_passthrumacs[$id]['mac'];
$pconfig['bw_up'] = $a_passthrumacs[$id]['bw_up'];
$pconfig['bw_down'] = $a_passthrumacs[$id]['bw_down'];
$pconfig['descr'] = $a_passthrumacs[$id]['descr'];
$pconfig['username'] = $a_passthrumacs[$id]['username'];
$pconfig['action'] = $a_passthrumacs[$id]['action'];
$pconfig['mac'] = $a_passthrumacs[$id]['mac'];
$pconfig['bw_up'] = $a_passthrumacs[$id]['bw_up'];
$pconfig['bw_down'] = $a_passthrumacs[$id]['bw_down'];
$pconfig['descr'] = $a_passthrumacs[$id]['descr'];
$pconfig['username'] = $a_passthrumacs[$id]['username'];
}
if ($_POST) {
unset($input_errors);
$pconfig = $_POST;
/* input validation */
$reqdfields = explode(" ", "action mac");
$reqdfieldsn = array(gettext("Action"), gettext("MAC address"));
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
if ($_POST['mac']) {
if (is_macaddr($_POST['mac'])) {
$iflist = get_interface_list();
foreach ($iflist as $if) {
if ($_POST['mac'] == strtolower($if['mac'])) {
$input_errors[] = sprintf(gettext("The MAC address %s belongs to a local interface, you cannot use it here."), $_POST['mac']);
break;
}
}
} else {
$input_errors[] = sprintf("%s. [%s]", gettext("A valid MAC address must be specified"), $_POST['mac']);
}
}
if ($_POST['bw_up'] && !is_numeric($_POST['bw_up']))
$input_errors[] = gettext("Upload speed needs to be an integer");
if ($_POST['bw_down'] && !is_numeric($_POST['bw_down']))
$input_errors[] = gettext("Download speed needs to be an integer");
foreach ($a_passthrumacs as $macent) {
if (isset($id) && ($a_passthrumacs[$id]) && ($a_passthrumacs[$id] === $macent))
continue;
if ($macent['mac'] == $_POST['mac']){
$input_errors[] = sprintf("[%s] %s.", $_POST['mac'], gettext("already exists"));
break;
}
}
if (!$input_errors) {
$mac = array();
$mac['action'] = $_POST['action'];
$mac['mac'] = $_POST['mac'];
if ($_POST['bw_up'])
$mac['bw_up'] = $_POST['bw_up'];
if ($_POST['bw_down'])
$mac['bw_down'] = $_POST['bw_down'];
if ($_POST['username'])
$mac['username'] = $_POST['username'];
$mac['descr'] = $_POST['descr'];
if (isset($id) && $a_passthrumacs[$id]) {
$oldmac = $a_passthrumacs[$id];
$a_passthrumacs[$id] = $mac;
} else {
$oldmac = $mac;
$a_passthrumacs[] = $mac;
}
passthrumacs_sort();
write_config();
if (isset($config['captiveportal'][$cpzone]['enable'])) {
$cpzoneid = $config['captiveportal'][$cpzone]['zoneid'];
captiveportal_passthrumac_delete_entry($oldmac);
captiveportal_passthrumac_configure_entry($mac);
unset($cpzoneid);
}
header("Location: services_captiveportal_mac.php?zone={$cpzone}");
exit;
}
unset($input_errors);
$pconfig = $_POST;
/* input validation */
$reqdfields = explode(" ", "action mac");
$reqdfieldsn = array(gettext("Action"), gettext("MAC address"));
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
if ($_POST['mac']) {
if (is_macaddr($_POST['mac'])) {
$iflist = get_interface_list();
foreach ($iflist as $if) {
if ($_POST['mac'] == strtolower($if['mac'])) {
$input_errors[] = sprintf(gettext("The MAC address %s belongs to a local interface, you cannot use it here."), $_POST['mac']);
break;
}
}
} else {
$input_errors[] = sprintf("%s. [%s]", gettext("A valid MAC address must be specified"), $_POST['mac']);
}
}
if ($_POST['bw_up'] && !is_numeric($_POST['bw_up'])) {
$input_errors[] = gettext("Upload speed needs to be an integer");
}
if ($_POST['bw_down'] && !is_numeric($_POST['bw_down'])) {
$input_errors[] = gettext("Download speed needs to be an integer");
}
foreach ($a_passthrumacs as $macent) {
if (isset($id) && ($a_passthrumacs[$id]) && ($a_passthrumacs[$id] === $macent)) {
continue;
}
if ($macent['mac'] == $_POST['mac']) {
$input_errors[] = sprintf("[%s] %s.", $_POST['mac'], gettext("already exists"));
break;
}
}
if (!$input_errors) {
$mac = array();
$mac['action'] = $_POST['action'];
$mac['mac'] = $_POST['mac'];
if ($_POST['bw_up']) {
$mac['bw_up'] = $_POST['bw_up'];
}
if ($_POST['bw_down']) {
$mac['bw_down'] = $_POST['bw_down'];
}
if ($_POST['username']) {
$mac['username'] = $_POST['username'];
}
$mac['descr'] = $_POST['descr'];
if (isset($id) && $a_passthrumacs[$id]) {
$oldmac = $a_passthrumacs[$id];
$a_passthrumacs[$id] = $mac;
} else {
$oldmac = $mac;
$a_passthrumacs[] = $mac;
}
passthrumacs_sort();
write_config();
if (isset($config['captiveportal'][$cpzone]['enable'])) {
$cpzoneid = $config['captiveportal'][$cpzone]['zoneid'];
captiveportal_passthrumac_delete_entry($oldmac);
captiveportal_passthrumac_configure_entry($mac);
unset($cpzoneid);
}
header("Location: services_captiveportal_mac.php?zone={$cpzone}");
exit;
}
}
include("head.inc");
?>
......@@ -168,7 +180,9 @@ include("head.inc");
<div class="row">
<?php if ($input_errors) print_input_errors($input_errors); ?>
<?php if ($input_errors) {
print_input_errors($input_errors);
} ?>
<section class="col-xs-12">
......@@ -186,15 +200,17 @@ include("head.inc");
<td width="78%" class="vtable">
<select name="action" class="formselect">
<?php
$actions = explode(" ", "Pass Block");
foreach ($actions as $action):
?>
<option value="<?=strtolower($action);?>"<?php if (strtolower($action) == strtolower($pconfig['action'])) echo "selected=\"selected\""; ?>>
<?=htmlspecialchars($action);?>
</option>
$actions = explode(" ", "Pass Block");
foreach ($actions as $action) :
?>
<option value="<?=strtolower($action);?>"<?php if (strtolower($action) == strtolower($pconfig['action'])) {
echo "selected=\"selected\"";
} ?>>
<?=htmlspecialchars($action);?>
</option>
<?php
endforeach;
?>
endforeach;
?>
</select>
<br />
<span class="vexpl"><?=gettext("Choose what to do with packets coming from this MAC address"); ?>.</span>
......@@ -203,12 +219,13 @@ include("head.inc");
<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']);?>" />
<?=$mandfldhtml;
?><input name="mac" type="text" class="formfld unknown" id="mac" size="17" value="<?=htmlspecialchars($pconfig['mac']);?>" />
<?php
$ip = getenv('REMOTE_ADDR');
$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`;
$mac = str_replace("\n","",$mac);
?>
$ip = getenv('REMOTE_ADDR');
$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`;
$mac = str_replace("\n", "", $mac);
?>
<a onclick="document.forms[0].mac.value='<?=$mac?>';" href="#"><?=gettext("Copy my MAC address");?></a>
<br />
<span class="vexpl"><?=gettext("MAC address (6 hex octets separated by colons)"); ?></span></td>
......@@ -244,12 +261,16 @@ include("head.inc");
<td width="78%">
<input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
<input name="zone" type="hidden" value="<?=htmlspecialchars($cpzone);?>" />
<?php if (isset($id) && $a_passthrumacs[$id]): ?>
<?php if (isset($id) && $a_passthrumacs[$id]) :
?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
<?php endif; ?>
<?php if (isset($pconfig['username']) && $pconfig['username']): ?>
<?php
endif; ?>
<?php if (isset($pconfig['username']) && $pconfig['username']) :
?>
<input name="username" type="hidden" value="<?=htmlspecialchars($pconfig['username']);?>" />
<?php endif; ?>
<?php
endif; ?>
</td>
</tr>
</table>
......@@ -261,4 +282,4 @@ include("head.inc");
</div>
</section>
<?php include("foot.inc"); ?>
<?php include("foot.inc");
......@@ -28,7 +28,7 @@
*/
if ($_POST['postafterlogin']) {
$nocsrf = true;
$nocsrf = true;
}
require_once('guiconfig.inc');
......@@ -41,8 +41,9 @@ require_once('voucher.inc');
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_captiveportal_vouchers.php');
$cpzone = $_GET['zone'];
if (isset($_POST['zone']))
if (isset($_POST['zone'])) {
$cpzone = $_POST['zone'];
}
if (empty($cpzone)) {
header("Location: services_captiveportal_zones.php");
......@@ -51,137 +52,147 @@ if (empty($cpzone)) {
function generatekey($exponent)
{
$ret = array();
/* generate a random 64 bit RSA key pair using the voucher binary */
$fd = popen(sprintf('/usr/local/bin/voucher -g 64 -e %s', $exponent), 'r');
if ($fd !== false) {
$output = fread($fd, 16384);
pclose($fd);
list($privkey, $pubkey) = explode("\0", $output);
$ret['priv'] = $privkey;
$ret['pub'] = $pubkey;
}
return $ret;
$ret = array();
/* generate a random 64 bit RSA key pair using the voucher binary */
$fd = popen(sprintf('/usr/local/bin/voucher -g 64 -e %s', $exponent), 'r');
if ($fd !== false) {
$output = fread($fd, 16384);
pclose($fd);
list($privkey, $pubkey) = explode("\0", $output);
$ret['priv'] = $privkey;
$ret['pub'] = $pubkey;
}
return $ret;
}
if (!is_array($config['captiveportal']))
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'])) {
$config['voucher'] = array();
}
if (empty($a_cp[$cpzone])) {
log_error("Submission on captiveportal page with unknown zone parameter: " . htmlspecialchars($cpzone));
header("Location: services_captiveportal_zones.php");
exit;
log_error("Submission on captiveportal page with unknown zone parameter: " . htmlspecialchars($cpzone));
header("Location: services_captiveportal_zones.php");
exit;
}
$pgtitle = array(gettext("Services"), gettext("Captive portal"), gettext("Vouchers"), $a_cp[$cpzone]['zone']);
$shortcut_section = "captiveportal-vouchers";
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'][$cpzone]['exponent'])) {
while (true) {
while (($exponent = rand()) % 30000 < 5000)
continue;
$exponent = ($exponent * 2) + 1; // Make it odd number
if ($exponent <= 65537)
break;
}
$config['voucher'][$cpzone]['exponent'] = $exponent;
unset($exponent);
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'][$cpzone]['exponent'])) {
while (true) {
while (($exponent = rand()) % 30000 < 5000) {
continue;
}
$exponent = ($exponent * 2) + 1; // Make it odd number
if ($exponent <= 65537) {
break;
}
}
$config['voucher'][$cpzone]['exponent'] = $exponent;
unset($exponent);
}
if ($_REQUEST['generatekey']) {
$key = generatekey($config['voucher'][$cpzone]['exponent']);
$key = generatekey($config['voucher'][$cpzone]['exponent']);
$alertmessage = _(
'You will need to recreate any existing Voucher Rolls due ' .
'to the public and private key changes. Click cancel if you ' .
'do not wish to recreate the vouchers.'
);
$alertmessage = _(
'You will need to recreate any existing Voucher Rolls due ' .
'to the public and private key changes. Click cancel if you ' .
'do not wish to recreate the vouchers.'
);
echo json_encode(array(
'alertmessage' => $alertmessage,
'privatekey' => $key['priv'],
'publickey' => $key['pub'],
));
echo json_encode(array(
'alertmessage' => $alertmessage,
'privatekey' => $key['priv'],
'publickey' => $key['pub'],
));
exit;
exit;
}
if (!isset($config['voucher'][$cpzone]['publickey'])) {
$key = generatekey($config['voucher'][$cpzone]['exponent']);
$config['voucher'][$cpzone]['publickey'] = base64_encode($key['pub']);
$config['voucher'][$cpzone]['privatekey'] = base64_encode($key['priv']);
$key = generatekey($config['voucher'][$cpzone]['exponent']);
$config['voucher'][$cpzone]['publickey'] = base64_encode($key['pub']);
$config['voucher'][$cpzone]['privatekey'] = base64_encode($key['priv']);
}
// Check for invalid or expired vouchers
if (!isset($config['voucher'][$cpzone]['descrmsgnoaccess']))
$config['voucher'][$cpzone]['descrmsgnoaccess'] = gettext("Voucher invalid");
if (!isset($config['voucher'][$cpzone]['descrmsgexpired']))
$config['voucher'][$cpzone]['descrmsgexpired'] = gettext("Voucher expired");
if (!isset($config['voucher'][$cpzone]['descrmsgnoaccess'])) {
$config['voucher'][$cpzone]['descrmsgnoaccess'] = gettext("Voucher invalid");
}
if (!isset($config['voucher'][$cpzone]['descrmsgexpired'])) {
$config['voucher'][$cpzone]['descrmsgexpired'] = gettext("Voucher expired");
}
$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{$cpzone}");
unset($a_roll[$id]);
voucher_unlink_db($roll);
unlock($voucherlck);
write_config();
$roll = $a_roll[$id]['number'];
$voucherlck = lock("voucher{$cpzone}");
unset($a_roll[$id]);
voucher_unlink_db($roll);
unlock($voucherlck);
write_config();
}
header("Location: services_captiveportal_vouchers.php?zone={$cpzone}");
exit;
} /* print all vouchers of the selected roll */
elseif ($_GET['act'] == "csv") {
$privkey = base64_decode($config['voucher'][$cpzone]['privatekey']);
if (strstr($privkey, "BEGIN RSA PRIVATE KEY")) {
$fd = fopen("/var/etc/voucher_{$cpzone}.private", "w");
if (!$fd) {
$input_errors[] = gettext("Cannot write private key file") . ".\n";
} else {
chmod("/var/etc/voucher_{$cpzone}.private", 0600);
fwrite($fd, $privkey);
fclose($fd);
$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_{$cpzone}_roll{$number}.csv");
if (file_exists("/var/etc/voucher_{$cpzone}.cfg")) {
system("/usr/local/bin/voucher -c /var/etc/voucher_{$cpzone}.cfg -p /var/etc/voucher_{$cpzone}.private $number $count");
}
@unlink("/var/etc/voucher_{$cpzone}.private");
} else {
header("Location: services_captiveportal_vouchers.php?zone={$cpzone}");
}
exit;
}
} else {
$input_errors[] = gettext("Need private RSA key to print vouchers") . "\n";
}
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'][$cpzone]['privatekey']);
if (strstr($privkey,"BEGIN RSA PRIVATE KEY")) {
$fd = fopen("/var/etc/voucher_{$cpzone}.private","w");
if (!$fd) {
$input_errors[] = gettext("Cannot write private key file") . ".\n";
} else {
chmod("/var/etc/voucher_{$cpzone}.private", 0600);
fwrite($fd, $privkey);
fclose($fd);
$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_{$cpzone}_roll{$number}.csv");
if (file_exists("/var/etc/voucher_{$cpzone}.cfg")) {
system("/usr/local/bin/voucher -c /var/etc/voucher_{$cpzone}.cfg -p /var/etc/voucher_{$cpzone}.private $number $count");
}
@unlink("/var/etc/voucher_{$cpzone}.private");
} else {
header("Location: services_captiveportal_vouchers.php?zone={$cpzone}");
}
exit;
}
} else {
$input_errors[] = gettext("Need private RSA key to print vouchers") . "\n";
}
}
$pconfig['enable'] = isset($config['voucher'][$cpzone]['enable']);
......@@ -197,83 +208,91 @@ $pconfig['msgnoaccess'] = $config['voucher'][$cpzone]['descrmsgnoaccess'];
$pconfig['msgexpired'] = $config['voucher'][$cpzone]['descrmsgexpired'];
if ($_POST) {
unset($input_errors);
unset($input_errors);
if ($_POST['postafterlogin']) {
voucher_expire($_POST['voucher_expire']);
exit;
}
$pconfig = $_POST;
/* input validation */
if ($_POST['enable'] == "yes") {
$reqdfields = explode(" ", "charset rollbits ticketbits checksumbits publickey magic");
$reqdfieldsn = array(gettext("charset"),gettext("rollbits"),gettext("ticketbits"),gettext("checksumbits"),gettext("publickey"),gettext("magic"));
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
}
// Check for form errors
if ($_POST['charset'] && (strlen($_POST['charset'] < 2)))
$input_errors[] = gettext("Need at least 2 characters to create vouchers.");
if ($_POST['charset'] && (strpos($_POST['charset'],"\"")>0))
$input_errors[] = gettext("Double quotes aren't allowed.");
if ($_POST['charset'] && (strpos($_POST['charset'],",")>0))
$input_errors[] = "',' " . gettext("aren't allowed.");
if ($_POST['rollbits'] && (!is_numeric($_POST['rollbits']) || ($_POST['rollbits'] < 1) || ($_POST['rollbits'] > 31)))
$input_errors[] = gettext("# of Bits to store Roll Id needs to be between 1..31.");
if ($_POST['ticketbits'] && (!is_numeric($_POST['ticketbits']) || ($_POST['ticketbits'] < 1) || ($_POST['ticketbits'] > 16)))
$input_errors[] = gettext("# of Bits to store Ticket Id needs to be between 1..16.");
if ($_POST['checksumbits'] && (!is_numeric($_POST['checksumbits']) || ($_POST['checksumbits'] < 1) || ($_POST['checksumbits'] > 31)))
$input_errors[] = gettext("# of Bits to store checksum needs to be between 1..31.");
if ($_POST['publickey'] && (!strstr($_POST['publickey'],"BEGIN PUBLIC KEY")))
$input_errors[] = gettext("This doesn't look like an RSA Public key.");
if ($_POST['privatekey'] && (!strstr($_POST['privatekey'],"BEGIN RSA PRIVATE KEY")))
$input_errors[] = gettext("This doesn't look like an RSA Private key.");
if ($_POST['vouchersyncdbip'] && (is_ipaddr_configured($_POST['vouchersyncdbip'])))
$input_errors[] = gettext("You cannot sync the voucher database to this host (itself).");
if (!$input_errors) {
if (empty($config['voucher'][$cpzone])) {
$newvoucher = array();
} else {
$newvoucher = $config['voucher'][$cpzone];
}
if ($_POST['enable'] == "yes") {
$newvoucher['enable'] = true;
} else {
unset($newvoucher['enable']);
}
if ($_POST['postafterlogin']) {
voucher_expire($_POST['voucher_expire']);
exit;
}
$newvoucher['charset'] = $_POST['charset'];
$newvoucher['rollbits'] = $_POST['rollbits'];
$newvoucher['ticketbits'] = $_POST['ticketbits'];
$newvoucher['checksumbits'] = $_POST['checksumbits'];
$newvoucher['magic'] = $_POST['magic'];
$newvoucher['exponent'] = $_POST['exponent'];
$newvoucher['publickey'] = base64_encode($_POST['publickey']);
$newvoucher['privatekey'] = base64_encode($_POST['privatekey']);
$newvoucher['descrmsgnoaccess'] = $_POST['msgnoaccess'];
$newvoucher['descrmsgexpired'] = $_POST['msgexpired'];
$config['voucher'][$cpzone] = $newvoucher;
write_config();
voucher_configure_zone();
if (!$input_errors) {
header("Location: services_captiveportal_vouchers.php?zone={$cpzone}");
exit;
}
}
$pconfig = $_POST;
/* input validation */
if ($_POST['enable'] == "yes") {
$reqdfields = explode(" ", "charset rollbits ticketbits checksumbits publickey magic");
$reqdfieldsn = array(gettext("charset"),gettext("rollbits"),gettext("ticketbits"),gettext("checksumbits"),gettext("publickey"),gettext("magic"));
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
}
// Check for form errors
if ($_POST['charset'] && (strlen($_POST['charset'] < 2))) {
$input_errors[] = gettext("Need at least 2 characters to create vouchers.");
}
if ($_POST['charset'] && (strpos($_POST['charset'], "\"")>0)) {
$input_errors[] = gettext("Double quotes aren't allowed.");
}
if ($_POST['charset'] && (strpos($_POST['charset'], ",")>0)) {
$input_errors[] = "',' " . gettext("aren't allowed.");
}
if ($_POST['rollbits'] && (!is_numeric($_POST['rollbits']) || ($_POST['rollbits'] < 1) || ($_POST['rollbits'] > 31))) {
$input_errors[] = gettext("# of Bits to store Roll Id needs to be between 1..31.");
}
if ($_POST['ticketbits'] && (!is_numeric($_POST['ticketbits']) || ($_POST['ticketbits'] < 1) || ($_POST['ticketbits'] > 16))) {
$input_errors[] = gettext("# of Bits to store Ticket Id needs to be between 1..16.");
}
if ($_POST['checksumbits'] && (!is_numeric($_POST['checksumbits']) || ($_POST['checksumbits'] < 1) || ($_POST['checksumbits'] > 31))) {
$input_errors[] = gettext("# of Bits to store checksum needs to be between 1..31.");
}
if ($_POST['publickey'] && (!strstr($_POST['publickey'], "BEGIN PUBLIC KEY"))) {
$input_errors[] = gettext("This doesn't look like an RSA Public key.");
}
if ($_POST['privatekey'] && (!strstr($_POST['privatekey'], "BEGIN RSA PRIVATE KEY"))) {
$input_errors[] = gettext("This doesn't look like an RSA Private key.");
}
if ($_POST['vouchersyncdbip'] && (is_ipaddr_configured($_POST['vouchersyncdbip']))) {
$input_errors[] = gettext("You cannot sync the voucher database to this host (itself).");
}
if (!$input_errors) {
if (empty($config['voucher'][$cpzone])) {
$newvoucher = array();
} else {
$newvoucher = $config['voucher'][$cpzone];
}
if ($_POST['enable'] == "yes") {
$newvoucher['enable'] = true;
} else {
unset($newvoucher['enable']);
}
$newvoucher['charset'] = $_POST['charset'];
$newvoucher['rollbits'] = $_POST['rollbits'];
$newvoucher['ticketbits'] = $_POST['ticketbits'];
$newvoucher['checksumbits'] = $_POST['checksumbits'];
$newvoucher['magic'] = $_POST['magic'];
$newvoucher['exponent'] = $_POST['exponent'];
$newvoucher['publickey'] = base64_encode($_POST['publickey']);
$newvoucher['privatekey'] = base64_encode($_POST['privatekey']);
$newvoucher['descrmsgnoaccess'] = $_POST['msgnoaccess'];
$newvoucher['descrmsgexpired'] = $_POST['msgexpired'];
$config['voucher'][$cpzone] = $newvoucher;
write_config();
voucher_configure_zone();
if (!$input_errors) {
header("Location: services_captiveportal_vouchers.php?zone={$cpzone}");
exit;
}
}
}
$closehead = false;
include("head.inc");
if ($pconfig['enable']) {
$main_buttons = array(
array('label'=>gettext("add voucher"), 'href'=>'services_captiveportal_vouchers_edit.php?zone='.$cpzone),
);
$main_buttons = array(
array('label'=>gettext("add voucher"), 'href'=>'services_captiveportal_vouchers_edit.php?zone='.$cpzone),
);
}
?>
......@@ -335,22 +354,26 @@ function enable_change(enable_change) {
<div class="container-fluid">
<div class="row">
<?php if ($input_errors) print_input_errors($input_errors); ?>
<?php if ($savemsg) print_info_box($savemsg); ?>
<?php if ($input_errors) {
print_input_errors($input_errors);
} ?>
<?php if ($savemsg) {
print_info_box($savemsg);
} ?>
<section class="col-xs-12">
<?php
$tab_array = array();
$tab_array[] = array(gettext("Captive portal(s)"), false, "services_captiveportal.php?zone={$cpzone}");
$tab_array[] = array(gettext("MAC"), false, "services_captiveportal_mac.php?zone={$cpzone}");
$tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php?zone={$cpzone}");
// Hide Allowed Hostnames as this feature is currently not supported
// $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);
?>
$tab_array = array();
$tab_array[] = array(gettext("Captive portal(s)"), false, "services_captiveportal.php?zone={$cpzone}");
$tab_array[] = array(gettext("MAC"), false, "services_captiveportal_mac.php?zone={$cpzone}");
$tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php?zone={$cpzone}");
// Hide Allowed Hostnames as this feature is currently not supported
// $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);
?>
<div class="tab-content content-box col-xs-12">
......@@ -364,7 +387,9 @@ function enable_change(enable_change) {
<tr>
<td width="22%" valign="top" class="vtable">&nbsp;</td>
<td width="78%" class="vtable">
<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked=\"checked\""; ?> onclick="enable_change(false)" />
<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) {
echo "checked=\"checked\"";
} ?> onclick="enable_change(false)" />
<strong><?=gettext("Enable Vouchers"); ?></strong>
</td>
</tr>
......@@ -381,7 +406,8 @@ function enable_change(enable_change) {
<td width="35%" class="listhdr"><?=gettext("Comment"); ?></td>
<td width="15%" class="list"></td>
</tr>
<?php $i = 0; foreach($a_roll as $rollent): ?>
<?php $i = 0; foreach ($a_roll as $rollent) :
?>
<tr>
<td class="listlr">
<?=htmlspecialchars($rollent['number']); ?>&nbsp;
......@@ -397,26 +423,44 @@ function enable_change(enable_change) {
</td>
<td valign="middle" class="list nowrap">
<div id='addeditdelete<?=$i?>'>
<?php if ($pconfig['enable']): ?>
<a class="btn btn-default btn-xs" href="services_captiveportal_vouchers_edit.php?zone=<?=$cpzone;?>&amp;id=<?=$i; ?>"><span class="glyphicon glyphicon-pencil" title="<?=gettext("edit voucher"); ?>" alt="<?=gettext("edit voucher"); ?>" ></span></a>
<a class="btn btn-default btn-xs" href="services_captiveportal_vouchers.php?zone=<?=$cpzone;?>&amp;act=del&amp;id=<?=$i; ?>" onclick="return confirm('<?=gettext("Do you really want to delete this voucher? This makes all vouchers from this roll invalid"); ?>')"><span class="glyphicon glyphicon-remove" title="<?=gettext("delete vouchers"); ?>" alt="<?=gettext("delete vouchers"); ?>"></span></a>
<a class="btn btn-default btn-xs" href="services_captiveportal_vouchers.php?zone=<?=$cpzone;?>&amp;act=csv&amp;id=<?=$i; ?>"><span class="glyphicon glyphicon-download-alt" title="<?=gettext("generate vouchers for this roll to CSV file"); ?>" alt="<?=gettext("generate vouchers for this roll to CSV file"); ?>"></span></a>
<?php endif;?>
<?php if ($pconfig['enable']) :
?>
<a class="btn btn-default btn-xs" href="services_captiveportal_vouchers_edit.php?zone=<?=$cpzone;
?>&amp;id=<?=$i;
?>"><span class="glyphicon glyphicon-pencil" title="<?=gettext("edit voucher");
?>" alt="<?=gettext("edit voucher"); ?>" ></span></a>
<a class="btn btn-default btn-xs" href="services_captiveportal_vouchers.php?zone=<?=$cpzone;
?>&amp;act=del&amp;id=<?=$i;
?>" onclick="return confirm('<?=gettext("Do you really want to delete this voucher? This makes all vouchers from this roll invalid");
?>')"><span class="glyphicon glyphicon-remove" title="<?=gettext("delete vouchers");
?>" alt="<?=gettext("delete vouchers"); ?>"></span></a>
<a class="btn btn-default btn-xs" href="services_captiveportal_vouchers.php?zone=<?=$cpzone;
?>&amp;act=csv&amp;id=<?=$i;
?>"><span class="glyphicon glyphicon-download-alt" title="<?=gettext("generate vouchers for this roll to CSV file");
?>" alt="<?=gettext("generate vouchers for this roll to CSV file"); ?>"></span></a>
<?php
endif;?>
</div>
</td>
</tr>
<?php $i++; endforeach; ?>
<?php $i++;
endforeach; ?>
</table>
<?php if ($pconfig['enable']): ?>
<?php if ($pconfig['enable']) :
?>
<?=gettext("Create, generate and activate Rolls with Vouchers that allow access through the " .
"captive portal for the configured time. Once a voucher is activated, " .
"its clock is started and runs uninterrupted until it expires. During that " .
"time, the voucher can be re-used from the same or a different computer. If the voucher " .
"is used again from another computer, the previous session is stopped."); ?>
<?php else: ?>
"captive portal for the configured time. Once a voucher is activated, " .
"its clock is started and runs uninterrupted until it expires. During that " .
"time, the voucher can be re-used from the same or a different computer. If the voucher " .
"is used again from another computer, the previous session is stopped."); ?>
<?php
else :
?>
<?=gettext("Enable Voucher support first using the checkbox above and hit Save at the bottom."); ?>
<?php endif;?>
<?php
endif;?>
</td>
</tr>
<tr>
......@@ -426,14 +470,18 @@ function enable_change(enable_change) {
<td class="vtable">
<textarea name="publickey" cols="65" rows="4" id="publickey" class="formpre"><?=htmlspecialchars($pconfig['publickey']);?></textarea>
<br />
<?=gettext("Paste an RSA public key (64 Bit or smaller) in PEM format here. This key is used to decrypt vouchers."); ?> <a href='#' onclick='generatenewkey();'><?=gettext('Generate');?></a> <?=gettext('new key');?>.</td>
<?=gettext("Paste an RSA public key (64 Bit or smaller) in PEM format here. This key is used to decrypt vouchers.");
?> <a href='#' onclick='generatenewkey();'><?=gettext('Generate');
?></a> <?=gettext('new key');?>.</td>
</tr>
<tr>
<td valign="top" class="vncell"><?=gettext("Voucher private key"); ?></td>
<td class="vtable">
<textarea name="privatekey" cols="65" rows="5" id="privatekey" class="formpre"><?=htmlspecialchars($pconfig['privatekey']);?></textarea>
<br />
<?=gettext("Paste an RSA private key (64 Bit or smaller) in PEM format here. This key is only used to generate encrypted vouchers and doesn't need to be available if the vouchers have been generated offline."); ?> <a href='#' onclick='generatenewkey();'> <?=gettext('Generate');?></a> <?=gettext('new key');?>.</td>
<?=gettext("Paste an RSA private key (64 Bit or smaller) in PEM format here. This key is only used to generate encrypted vouchers and doesn't need to be available if the vouchers have been generated offline.");
?> <a href='#' onclick='generatenewkey();'> <?=gettext('Generate');
?></a> <?=gettext('new key');?>.</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Character set"); ?></td>
......@@ -501,7 +549,8 @@ function enable_change(enable_change) {
<input type="hidden" name="zone" id="zone" value="<?=htmlspecialchars($cpzone);?>" />
<input type="hidden" name="exponent" id="exponent" value="<?=$pconfig['exponent'];?>" />
<input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" onclick="enable_change(true); before_save();" />
<input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
<input type="button" class="btn btn-default" value="<?=gettext("Cancel");
?>" onclick="window.location.href='<?=$referer;?>'" />
</td>
</tr>
<tr>
......@@ -528,4 +577,4 @@ function enable_change(enable_change) {
enable_change(false);
//]]>
</script>
<?php include("foot.inc"); ?>
<?php include("foot.inc");
......@@ -37,16 +37,18 @@ $pgtitle = array(gettext("Services"), gettext("Captive portal"), gettext("Edit V
$shortcut_section = "captiveportal-vouchers";
$cpzone = $_GET['zone'];
if (isset($_POST['zone']))
if (isset($_POST['zone'])) {
$cpzone = $_POST['zone'];
}
if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
header("Location: services_captiveportal_zones.php");
exit;
}
if (!is_array($config['captiveportal']))
if (!is_array($config['captiveportal'])) {
$config['captiveportal'] = array();
}
$a_cp =& $config['captiveportal'];
if (!is_array($config['voucher'])) {
......@@ -54,30 +56,31 @@ if (!is_array($config['voucher'])) {
}
if (!is_array($config['voucher'][$cpzone]['roll'])) {
$config['voucher'][$cpzone]['roll'] = array();
$config['voucher'][$cpzone]['roll'] = array();
}
$a_roll = &$config['voucher'][$cpzone]['roll'];
if (is_numericint($_GET['id']))
$id = $_GET['id'];
if (isset($_POST['id']) && is_numericint($_POST['id']))
$id = $_POST['id'];
if (is_numericint($_GET['id'])) {
$id = $_GET['id'];
}
if (isset($_POST['id']) && is_numericint($_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['descr'] = $a_roll[$id]['descr'];
$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['descr'] = $a_roll[$id]['descr'];
}
$maxnumber = (1<<$config['voucher'][$cpzone]['rollbits']) -1; // Highest Roll#
$maxcount = (1<<$config['voucher'][$cpzone]['ticketbits']) -1; // Highest Ticket#
if ($_POST) {
unset($input_errors);
$pconfig = $_POST;
unset($input_errors);
$pconfig = $_POST;
/* input validation */
$reqdfields = explode(" ", "number count minutes");
......@@ -85,27 +88,30 @@ if ($_POST) {
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
// Look for duplicate roll #
foreach($a_roll as $re) {
if($re['number'] == $_POST['number']) {
$input_errors[] = sprintf(gettext("Roll number %s already exists."), $_POST['number']);
break;
}
}
// Look for duplicate roll #
foreach ($a_roll as $re) {
if ($re['number'] == $_POST['number']) {
$input_errors[] = sprintf(gettext("Roll number %s already exists."), $_POST['number']);
break;
}
}
if (!is_numeric($_POST['number']) || $_POST['number'] >= $maxnumber)
if (!is_numeric($_POST['number']) || $_POST['number'] >= $maxnumber) {
$input_errors[] = sprintf(gettext("Roll number must be numeric and less than %s"), $maxnumber);
}
if (!is_numeric($_POST['count']) || $_POST['count'] < 1 || $_POST['count'] > $maxcount)
if (!is_numeric($_POST['count']) || $_POST['count'] < 1 || $_POST['count'] > $maxcount) {
$input_errors[] = sprintf(gettext("A roll has at least one voucher and less than %s."), $maxcount);
}
if (!is_numeric($_POST['minutes']) || $_POST['minutes'] < 1)
if (!is_numeric($_POST['minutes']) || $_POST['minutes'] < 1) {
$input_errors[] = gettext("Each voucher must be good for at least 1 minute.");
}
if (!$input_errors) {
if (isset($id) && $a_roll[$id])
if (isset($id) && $a_roll[$id]) {
$rollent = $a_roll[$id];
}
$rollent['zone'] = $_POST['zone'];
$rollent['number'] = $_POST['number'];
......@@ -113,15 +119,15 @@ if ($_POST) {
$rollent['descr'] = $_POST['descr'];
/* New Roll or modified voucher count: create bitmask */
$voucherlck = lock("voucher{$cpzone}");
$voucherlck = lock("voucher{$cpzone}");
if ($_POST['count'] != $rollent['count']) {
$rollent['count'] = $_POST['count'];
$len = ($rollent['count']>>3) + 1; // count / 8 +1
$rollent['used'] = base64_encode(str_repeat("\000",$len)); // 4 bitmask
$rollent['used'] = base64_encode(str_repeat("\000", $len)); // 4 bitmask
$rollent['active'] = array();
voucher_write_used_db($rollent['number'], $rollent['used']);
voucher_write_active_db($rollent['number'], array()); // create empty DB
voucher_log(LOG_INFO,sprintf(gettext('All %1$s vouchers from Roll %2$s marked unused'), $rollent['count'], $rollent['number']));
voucher_log(LOG_INFO, sprintf(gettext('All %1$s vouchers from Roll %2$s marked unused'), $rollent['count'], $rollent['number']));
} else {
// existing roll has been modified but without changing the count
// read active and used DB from ramdisk and store it in XML config
......@@ -129,7 +135,7 @@ if ($_POST) {
$activent = array();
$db = array();
$active_vouchers = voucher_read_active_db($rollent['number'], $rollent['minutes']);
foreach($active_vouchers as $voucher => $line) {
foreach ($active_vouchers as $voucher => $line) {
list($timestamp, $minutes) = explode(",", $line);
$activent['voucher'] = $voucher;
$activent['timestamp'] = $timestamp;
......@@ -138,12 +144,13 @@ if ($_POST) {
}
$rollent['active'] = $db;
}
unlock($voucherlck);
unlock($voucherlck);
if (isset($id) && $a_roll[$id])
if (isset($id) && $a_roll[$id]) {
$a_roll[$id] = $rollent;
else
} else {
$a_roll[] = $rollent;
}
write_config();
......@@ -165,8 +172,12 @@ include("head.inc");
<div class="row">
<?php if ($input_errors) print_input_errors($input_errors); ?>
<?php if ($savemsg) print_info_box($savemsg); ?>
<?php if ($input_errors) {
print_input_errors($input_errors);
} ?>
<?php if ($savemsg) {
print_info_box($savemsg);
} ?>
<section class="col-xs-12">
......@@ -180,15 +191,19 @@ include("head.inc");
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Roll"); ?>#</td>
<td width="78%" class="vtable">
<?=$mandfldhtml;?><input name="number" type="text" class="formfld" id="number" size="10" value="<?=htmlspecialchars($pconfig['number']);?>" />
<?=$mandfldhtml;
?><input name="number" type="text" class="formfld" id="number" size="10" value="<?=htmlspecialchars($pconfig['number']);?>" />
<br />
<span class="vexpl"><?=gettext("Enter the Roll"); ?># (0..<?=htmlspecialchars($maxnumber);?>) <?=gettext("found on top of the generated/printed vouchers"); ?>.</span>
<span class="vexpl"><?=gettext("Enter the Roll");
?># (0..<?=htmlspecialchars($maxnumber);
?>) <?=gettext("found on top of the generated/printed vouchers"); ?>.</span>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Minutes per Ticket"); ?></td>
<td width="78%" class="vtable">
<?=$mandfldhtml;?><input name="minutes" type="text" class="formfld" id="minutes" size="10" value="<?=htmlspecialchars($pconfig['minutes']);?>" />
<?=$mandfldhtml;
?><input name="minutes" type="text" class="formfld" id="minutes" size="10" value="<?=htmlspecialchars($pconfig['minutes']);?>" />
<br />
<span class="vexpl"><?=gettext("Defines the time in minutes that a user is allowed access. The clock starts ticking the first time a voucher is used for authentication"); ?>.</span>
</td>
......@@ -196,15 +211,19 @@ include("head.inc");
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Count"); ?></td>
<td width="78%" class="vtable">
<?=$mandfldhtml;?><input name="count" type="text" class="formfld" id="count" size="10" value="<?=htmlspecialchars($pconfig['count']);?>" />
<?=$mandfldhtml;
?><input name="count" type="text" class="formfld" id="count" size="10" value="<?=htmlspecialchars($pconfig['count']);?>" />
<br />
<span class="vexpl"><?=gettext("Enter the number of vouchers"); ?> (1..<?=htmlspecialchars($maxcount);?>) <?=gettext("found on top of the generated/printed vouchers. WARNING: Changing this number for an existing Roll will mark all vouchers as unused again"); ?>.</span>
<span class="vexpl"><?=gettext("Enter the number of vouchers");
?> (1..<?=htmlspecialchars($maxcount);
?>) <?=gettext("found on top of the generated/printed vouchers. WARNING: Changing this number for an existing Roll will mark all vouchers as unused again"); ?>.</span>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Comment"); ?></td>
<td width="78%" class="vtable">
<?=$mandfldhtml;?><input name="descr" type="text" class="formfld" id="descr" size="60" value="<?=htmlspecialchars($pconfig['descr']);?>" />
<?=$mandfldhtml;
?><input name="descr" type="text" class="formfld" id="descr" size="60" value="<?=htmlspecialchars($pconfig['descr']);?>" />
<br />
<span class="vexpl"><?=gettext("Can be used to further identify this roll. Ignored by the system"); ?>.</span>
</td>
......@@ -214,9 +233,11 @@ include("head.inc");
<td width="78%">
<input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
<input name="zone" type="hidden" value="<?=htmlspecialchars($cpzone);?>" />
<?php if (isset($id) && $a_roll[$id]): ?>
<?php if (isset($id) && $a_roll[$id]) :
?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
<?php endif; ?>
<?php
endif; ?>
</td>
</tr>
</table>
......@@ -228,4 +249,4 @@ include("head.inc");
</div>
</section>
<?php include("foot.inc"); ?>
<?php include("foot.inc");
......@@ -34,23 +34,25 @@ require_once("captiveportal.inc");
global $cpzone;
global $cpzoneid;
if (!is_array($config['captiveportal']))
$config['captiveportal'] = array();
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]) {
$cpzoneid = $a_cp[$cpzone]['zoneid'];
unset($a_cp[$cpzone]['enable']);
captiveportal_configure();
unset($a_cp[$cpzone]);
if (isset($config['voucher'][$cpzone]))
unset($config['voucher'][$cpzone]);
write_config();
header("Location: services_captiveportal_zones.php");
exit;
}
$cpzone = $_GET['zone'];
if ($a_cp[$cpzone]) {
$cpzoneid = $a_cp[$cpzone]['zoneid'];
unset($a_cp[$cpzone]['enable']);
captiveportal_configure();
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"));
......@@ -58,7 +60,7 @@ $shortcut_section = "captiveportal";
include("head.inc");
$main_buttons = array(
array('href'=>'services_captiveportal_zones_edit.php', 'label'=>gettext("add a new captiveportal instance")),
array('href'=>'services_captiveportal_zones_edit.php', 'label'=>gettext("add a new captiveportal instance")),
);
?>
......@@ -70,10 +72,14 @@ $main_buttons = array(
<div class="container-fluid">
<div class="row">
<?php if ($savemsg) print_info_box($savemsg); ?>
<?php if (is_subsystem_dirty('captiveportal')): ?><p>
<?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; ?>
<?php
endif; ?>
<section class="col-xs-12">
......@@ -93,35 +99,40 @@ $main_buttons = array(
</td>
</tr>
<?php foreach ($a_cp as $cpzone => $cpitem):
if (!is_array($cpitem))
continue;
?>
<?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) . " ";
?>
foreach ($cpifaces as $cpiface) {
echo convert_friendly_interface_to_friendly_descr($cpiface) . " ";
}
?>
</td>
<td class="listr" ondblclick="document.location='services_captiveportal.php?zone=<?=$cpzone;?>';">
<?php
$cpdb = new OPNsense\CaptivePortal\DB($cpzone) ;
echo $cpdb->countClients() ;
?>
<?php
$cpdb = new OPNsense\CaptivePortal\DB($cpzone) ;
echo $cpdb->countClients() ;
?>
</td>
<td class="listbg" ondblclick="document.location='services_captiveportal.php?zone=<?=$cpzone;?>';">
<?=htmlspecialchars($cpitem['descr']);?>&nbsp;
</td>
<td valign="middle" class="list nowrap">
<a href="services_captiveportal.php?zone=<?=$cpzone?>" title="<?=gettext("edit captiveportal instance"); ?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
<a href="services_captiveportal_zones.php?act=del&amp;zone=<?=$cpzone;?>" onclick="return confirm('<?=gettext("Do you really want to delete this entry?");?>')" title="<?=gettext("delete captiveportal instance");?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></a>
<a href="services_captiveportal_zones.php?act=del&amp;zone=<?=$cpzone;
?>" onclick="return confirm('<?=gettext("Do you really want to delete this entry?");
?>')" title="<?=gettext("delete captiveportal instance");?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></a>
</td>
</tr>
<?php endforeach; ?>
<?php
endforeach; ?>
</table>
</div>
</form>
......@@ -130,4 +141,4 @@ $main_buttons = array(
</div>
</div>
</section>
<?php include("foot.inc"); ?>
<?php include("foot.inc");
......@@ -35,43 +35,43 @@ require_once("captiveportal.inc");
$pgtitle = array(gettext("Services"),gettext("Captive portal"),gettext("Edit Zones"));
$shortcut_section = "captiveportal";
if (!is_array($config['captiveportal']))
$config['captiveportal'] = array();
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);
if (preg_match('/[^A-Za-z0-9_]/', $_POST['zone'])) {
$input_errors[] = gettext("The zone name can only contain letters, digits, and underscores (_).");
}
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'];
$a_cp[$cpzone]['localauth_priv'] = true;
write_config();
header("Location: services_captiveportal.php?zone={$cpzone}");
exit;
}
unset($input_errors);
$pconfig = $_POST;
/* input validation */
$reqdfields = explode(" ", "zone");
$reqdfieldsn = array(gettext("Zone name"));
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
if (preg_match('/[^A-Za-z0-9_]/', $_POST['zone'])) {
$input_errors[] = gettext("The zone name can only contain letters, digits, and underscores (_).");
}
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'];
$a_cp[$cpzone]['localauth_priv'] = true;
write_config();
header("Location: services_captiveportal.php?zone={$cpzone}");
exit;
}
}
include("head.inc");
?>
......@@ -84,7 +84,9 @@ include("head.inc");
<div class="row">
<?php if ($input_errors) print_input_errors($input_errors); ?>
<?php if ($input_errors) {
print_input_errors($input_errors);
} ?>
<section class="col-xs-12">
......@@ -131,4 +133,4 @@ include("head.inc");
</div>
</section>
<?php include("foot.inc"); ?>
<?php include("foot.inc");
......@@ -35,16 +35,18 @@ require_once("captiveportal.inc");
require_once("voucher.inc");
$cpzone = $_GET['zone'];
if (isset($_POST['zone']))
$cpzone = $_POST['zone'];
if (isset($_POST['zone'])) {
$cpzone = $_POST['zone'];
}
if (empty($cpzone)) {
header("Location: status_captiveportal.php");
exit;
header("Location: status_captiveportal.php");
exit;
}
if (!is_array($config['captiveportal']))
$config['captiveportal'] = array();
if (!is_array($config['captiveportal'])) {
$config['captiveportal'] = array();
}
$a_cp =& $config['captiveportal'];
$pgtitle = array(gettext("Status"), gettext("Captive portal"), gettext("Expire Vouchers"), $a_cp[$cpzone]['zone']);
......@@ -64,14 +66,14 @@ include("head.inc");
<section class="col-xs-12">
<?php
$tab_array = array();
$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"), false, "status_captiveportal_test.php?zone={$cpzone}");
$tab_array[] = array(gettext("Expire Vouchers"), true, "status_captiveportal_expire.php?zone={$cpzone}");
display_top_tabs($tab_array);
?>
$tab_array = array();
$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"), false, "status_captiveportal_test.php?zone={$cpzone}");
$tab_array[] = array(gettext("Expire Vouchers"), true, "status_captiveportal_expire.php?zone={$cpzone}");
display_top_tabs($tab_array);
?>
<div class="tab-content content-box col-xs-12">
......@@ -99,20 +101,20 @@ include("head.inc");
</table>
<?php
if ($_POST) {
if ($_POST['vouchers']) {
$result = voucher_expire($_POST['vouchers']);
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\" summary=\"results\">\n";
if ( $result) {
echo "<tr><td bgcolor=\"#D9DEE8\"><img src=\"/themes/{$g['theme']}/images/icons/icon_pass.gif\" alt=\"pass\" /></td>";
echo "<td bgcolor=\"#D9DEE8\">Success</td></tr>";
} else {
echo "<tr><td bgcolor=\"#FFD9D1\"><img src=\"/themes/{$g['theme']}/images/icons/icon_block.gif\" alt=\"block\" /></td>";
echo "<td bgcolor=\"#FFD9D1\">Error</td></tr>";
}
echo "</table>";
}
}
if ($_POST) {
if ($_POST['vouchers']) {
$result = voucher_expire($_POST['vouchers']);
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\" summary=\"results\">\n";
if ($result) {
echo "<tr><td bgcolor=\"#D9DEE8\"><img src=\"/themes/{$g['theme']}/images/icons/icon_pass.gif\" alt=\"pass\" /></td>";
echo "<td bgcolor=\"#D9DEE8\">Success</td></tr>";
} else {
echo "<tr><td bgcolor=\"#FFD9D1\"><img src=\"/themes/{$g['theme']}/images/icons/icon_block.gif\" alt=\"block\" /></td>";
echo "<td bgcolor=\"#FFD9D1\">Error</td></tr>";
}
echo "</table>";
}
}
?>
</div>
......@@ -125,4 +127,4 @@ if ($_POST) {
</section>
<?php include("foot.inc"); ?>
<?php include("foot.inc");
......@@ -35,16 +35,18 @@ require_once("captiveportal.inc");
require_once("voucher.inc");
$cpzone = $_GET['zone'];
if (isset($_POST['zone']))
if (isset($_POST['zone'])) {
$cpzone = $_POST['zone'];
}
if (empty($cpzone)) {
header("Location: status_captiveportal.php");
exit;
}
if (!is_array($config['captiveportal']))
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']);
......@@ -65,14 +67,14 @@ include("head.inc");
<section class="col-xs-12">
<?php
$tab_array = array();
$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}");
$tab_array[] = array(gettext("Expire Vouchers"), false, "status_captiveportal_expire.php?zone={$cpzone}");
display_top_tabs($tab_array);
?>
$tab_array = array();
$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}");
$tab_array[] = array(gettext("Expire Vouchers"), false, "status_captiveportal_expire.php?zone={$cpzone}");
display_top_tabs($tab_array);
?>
<div class="tab-content content-box col-xs-12">
......@@ -128,4 +130,4 @@ if ($_POST) {
<? include("foot.inc"); ?>
<? include("foot.inc");
......@@ -35,22 +35,24 @@ require_once("captiveportal.inc");
require_once("voucher.inc");
$cpzone = $_GET['zone'];
if (isset($_POST['zone']))
$cpzone = $_POST['zone'];
if (isset($_POST['zone'])) {
$cpzone = $_POST['zone'];
}
if (empty($cpzone)) {
header("Location: status_captiveportal.php");
exit;
header("Location: status_captiveportal.php");
exit;
}
if (!is_array($config['captiveportal']))
$config['captiveportal'] = array();
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']);
$shortcut_section = "captiveportal-vouchers";
if (!is_array($config['voucher'][$cpzone]['roll'])) {
$config['voucher'][$cpzone]['roll'] = array();
$config['voucher'][$cpzone]['roll'] = array();
}
$a_roll = &$config['voucher'][$cpzone]['roll'];
......@@ -69,14 +71,14 @@ include("head.inc");
<section class="col-xs-12">
<?php
$tab_array = array();
$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}");
$tab_array[] = array(gettext("Expire Vouchers"), false, "status_captiveportal_expire.php?zone={$cpzone}");
display_top_tabs($tab_array);
?>
$tab_array = array();
$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}");
$tab_array[] = array(gettext("Expire Vouchers"), false, "status_captiveportal_expire.php?zone={$cpzone}");
display_top_tabs($tab_array);
?>
<div class="tab-content content-box col-xs-12">
......@@ -96,14 +98,14 @@ include("head.inc");
<td class="listhdr"><?=gettext("ready"); ?></td>
</tr>
<?php
$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']);
$ready = $rollent['count'] - $used;
/* used also count active vouchers, remove them */
$used = $used - $active;
?>
$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']);
$ready = $rollent['count'] - $used;
/* used also count active vouchers, remove them */
$used = $used - $active;
?>
<tr>
<td class="listlr">
<?=htmlspecialchars($rollent['number']); ?>&nbsp;
......@@ -127,7 +129,10 @@ include("head.inc");
<?=htmlspecialchars($ready); ?>&nbsp;
</td>
</tr>
<?php $i++; endforeach; unlock($voucherlck); ?>
<?php $i++;
endforeach;
unlock($voucherlck); ?>
</table>
</div>
</form>
......@@ -138,4 +143,4 @@ include("head.inc");
</div>
</section>
<?php include("foot.inc"); ?>
<?php include("foot.inc");
......@@ -35,58 +35,61 @@ require_once("captiveportal.inc");
require_once("voucher.inc");
$cpzone = $_GET['zone'];
if (isset($_POST['zone']))
$cpzone = $_POST['zone'];
if (isset($_POST['zone'])) {
$cpzone = $_POST['zone'];
}
if (empty($cpzone)) {
header("Location: status_captiveportal.php");
exit;
header("Location: status_captiveportal.php");
exit;
}
if (!is_array($config['captiveportal']))
$config['captiveportal'] = array();
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']);
$shortcut_section = "captiveportal-vouchers";
function clientcmp($a, $b) {
global $order;
return strcmp($a[$order], $b[$order]);
function clientcmp($a, $b)
{
global $order;
return strcmp($a[$order], $b[$order]);
}
if (!is_array($config['voucher'][$cpzone]['roll'])) {
$config['voucher'][$cpzone]['roll'] = array();
$config['voucher'][$cpzone]['roll'] = array();
}
$a_roll = $config['voucher'][$cpzone]['roll'];
$db = array();
foreach($a_roll as $rollent) {
$roll = $rollent['number'];
$minutes = $rollent['minutes'];
if (!file_exists("/var/db/voucher_{$cpzone}_active_{$roll}.db")) {
continue;
}
$active_vouchers = file("/var/db/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());
if ($remaining > 0) {
$dbent[0] = $voucher;
$dbent[1] = $roll;
$dbent[2] = $timestamp;
$dbent[3] = intval($remaining/60);
$dbent[4] = $timestamp + 60*$minutes; // expires at
$db[] = $dbent;
}
}
foreach ($a_roll as $rollent) {
$roll = $rollent['number'];
$minutes = $rollent['minutes'];
if (!file_exists("/var/db/voucher_{$cpzone}_active_{$roll}.db")) {
continue;
}
$active_vouchers = file("/var/db/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());
if ($remaining > 0) {
$dbent[0] = $voucher;
$dbent[1] = $roll;
$dbent[2] = $timestamp;
$dbent[3] = intval($remaining/60);
$dbent[4] = $timestamp + 60*$minutes; // expires at
$db[] = $dbent;
}
}
}
if ($_GET['order']) {
$order = $_GET['order'];
usort($db, "clientcmp");
$order = $_GET['order'];
usort($db, "clientcmp");
}
include("head.inc");
......@@ -104,14 +107,14 @@ include("head.inc");
<section class="col-xs-12">
<?php
$tab_array = array();
$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}");
$tab_array[] = array(gettext("Expire Vouchers"), false, "status_captiveportal_expire.php?zone={$cpzone}");
display_top_tabs($tab_array);
?>
$tab_array = array();
$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}");
$tab_array[] = array(gettext("Expire Vouchers"), false, "status_captiveportal_expire.php?zone={$cpzone}");
display_top_tabs($tab_array);
?>
<div class="tab-content content-box col-xs-12">
......@@ -122,23 +125,31 @@ include("head.inc");
<div class="table-responsive">
<table class="table table-striped table-sort">
<tr>
<td class="listhdrr"><a href="?order=0&amp;showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("Voucher"); ?></a></td>
<td class="listhdrr"><a href="?order=1&amp;showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("Roll"); ?></a></td>
<td class="listhdrr"><a href="?order=2&amp;showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("Activated at"); ?></a></td>
<td class="listhdrr"><a href="?order=3&amp;showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("Expires in"); ?></a></td>
<td class="listhdr"><a href="?order=4&amp;showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("Expires at"); ?></a></td>
<td class="listhdrr"><a href="?order=0&amp;showact=<?=htmlspecialchars($_GET['showact']);
?>"><?=gettext("Voucher"); ?></a></td>
<td class="listhdrr"><a href="?order=1&amp;showact=<?=htmlspecialchars($_GET['showact']);
?>"><?=gettext("Roll"); ?></a></td>
<td class="listhdrr"><a href="?order=2&amp;showact=<?=htmlspecialchars($_GET['showact']);
?>"><?=gettext("Activated at"); ?></a></td>
<td class="listhdrr"><a href="?order=3&amp;showact=<?=htmlspecialchars($_GET['showact']);
?>"><?=gettext("Expires in"); ?></a></td>
<td class="listhdr"><a href="?order=4&amp;showact=<?=htmlspecialchars($_GET['showact']);
?>"><?=gettext("Expires at"); ?></a></td>
<td class="list"></td>
</tr>
<?php foreach ($db as $dbent): ?>
<?php foreach ($db as $dbent) :
?>
<tr>
<td class="listlr"><?=$dbent[0];?></td>
<td class="listr"><?=$dbent[1];?></td>
<td class="listr"><?=htmlspecialchars(date("m/d/Y H:i:s", $dbent[2]));?></td>
<td class="listr"><?=$dbent[3];?> <?=gettext("min"); ?></td>
<td class="listr"><?=$dbent[3];
?> <?=gettext("min"); ?></td>
<td class="listr"><?=htmlspecialchars(date("m/d/Y H:i:s", $dbent[4]));?></td>
<td class="list"></td>
</tr>
<?php endforeach; ?>
<?php
endforeach; ?>
</table>
</div>
</form>
......@@ -149,4 +160,4 @@ include("head.inc");
</div>
</section>
<?php include("foot.inc"); ?>
<?php include("foot.inc");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment