summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharlie <root@testfbsd8.localdomain>2009-06-13 17:24:28 +0000
committerCharlie <root@testfbsd8.localdomain>2009-06-13 17:24:28 +0000
commit336e3c1cabef46d5825bb0540a6715dff86450e7 (patch)
tree3b831086004d35bb0abdf9b81605a4ced7d4fb80
parent67115722ccd3a0c0d40c5ac70cdce079ff02c6ab (diff)
downloadpfsense-336e3c1cabef46d5825bb0540a6715dff86450e7.zip
pfsense-336e3c1cabef46d5825bb0540a6715dff86450e7.tar.gz
Port voucher login ability on CaptivePortal from M0n0Wall.
Various locking fixes are done with the import and this means that as of now pfSense has a better performin/behaving CP than m0n0wall.
-rw-r--r--etc/inc/captiveportal.inc11
-rw-r--r--etc/inc/system.inc2
-rw-r--r--etc/inc/voucher.inc406
-rw-r--r--etc/inc/xmlparse.inc2
-rwxr-xr-xetc/rc.bootup4
-rw-r--r--etc/rc.savevoucher35
-rwxr-xr-xusr/local/captiveportal/index.php51
-rwxr-xr-xusr/local/www/services_captiveportal.php4
-rwxr-xr-xusr/local/www/services_captiveportal_filemanager.php1
-rwxr-xr-xusr/local/www/services_captiveportal_ip.php1
-rwxr-xr-xusr/local/www/services_captiveportal_mac.php1
-rw-r--r--usr/local/www/services_captiveportal_vouchers.php395
-rw-r--r--usr/local/www/services_captiveportal_vouchers_edit.php182
-rwxr-xr-xusr/local/www/status_captiveportal.php36
-rw-r--r--usr/local/www/status_captiveportal_test.php95
-rw-r--r--usr/local/www/status_captiveportal_voucher_rolls.php109
-rw-r--r--usr/local/www/status_captiveportal_vouchers.php117
17 files changed, 1444 insertions, 8 deletions
diff --git a/etc/inc/captiveportal.inc b/etc/inc/captiveportal.inc
index 736763b..e653500 100644
--- a/etc/inc/captiveportal.inc
+++ b/etc/inc/captiveportal.inc
@@ -450,7 +450,8 @@ function captiveportal_prune_old() {
else
$idletimeout = 0;
- if (!$timeout && !$idletimeout && !isset($config['captiveportal']['reauthenticate']) && !isset($config['captiveportal']['radiussession_timeout']))
+ if (!$timeout && !$idletimeout && !isset($config['captiveportal']['reauthenticate']) &&
+ !isset($config['captiveportal']['radiussession_timeout']) && !isset($config['voucher']['enable']))
return;
$captiveportallck = lock('captiveportal');
@@ -506,6 +507,14 @@ function captiveportal_prune_old() {
}
}
+ /* if vouchers are configured, activate session timeouts */
+ if (!$timedout && isset($config['voucher']['enable']) && !empty($cpdb[$i][7])) {
+ if (time() >= ($cpdb[$i][0] + $cpdb[$i][7])) {
+ $timedout = true;
+ $term_cause = 5; // Session-Timeout
+ }
+ }
+
/* if radius session_timeout is enabled and the session_timeout is not null, then check if the user should be logged out */
if (!$timedout && isset($config['captiveportal']['radiussession_timeout']) && !empty($cpdb[$i][7])) {
if (time() >= ($cpdb[$i][0] + $cpdb[$i][7])) {
diff --git a/etc/inc/system.inc b/etc/inc/system.inc
index 158720f..b2f6c26 100644
--- a/etc/inc/system.inc
+++ b/etc/inc/system.inc
@@ -1007,6 +1007,8 @@ function system_reboot_sync() {
function system_reboot_cleanup() {
mwexec("/usr/local/bin/beep.sh stop");
captiveportal_radius_stop_all();
+ require_once("voucher.inc");
+ voucher_save_db_to_config();
}
function system_do_shell_commands($early = 0) {
diff --git a/etc/inc/voucher.inc b/etc/inc/voucher.inc
new file mode 100644
index 0000000..34f4f77
--- /dev/null
+++ b/etc/inc/voucher.inc
@@ -0,0 +1,406 @@
+<?php
+/*
+ Copyright (C) 2007 Marcel Wiget <mwiget@mac.com>.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+*/
+
+/* include all configuration functions */
+require_once("config.inc");
+
+/*
+ *Authenticate a voucher and return the remaining time credit in minutes
+ * if $test is set, don't mark the voucher as used nor add it to the list
+ * of active vouchers
+ */
+function voucher_auth($voucher_received, $test = 0) {
+
+ global $g, $config, $dirtyfile;
+
+ // if $test is set, simply test the voucher. Don't change anything
+ // but return a more verbose error and result message back
+
+ if (! $test)
+ $voucherlck = lock('voucher');
+
+ // read rolls into assoc array with rollid as key and minutes as value
+ $a_roll = &$config['voucher']['roll'];
+ foreach ($a_roll as $rollent) {
+ $tickets_per_roll[$rollent['number']] = $rollent['count'];
+ $minutes_per_roll[$rollent['number']] = $rollent['minutes'];
+ }
+
+ // split into an array. Useful for multiple vouchers given
+ $a_vouchers_received = split("[\t\n\r ]+",$voucher_received);
+ $error = 0;
+ $test_result = array(); // used to display for voucher test option in GUI
+ $total_minutes = 0;
+ $first_voucher = "";
+ $first_voucher_roll = 0;
+
+ // go through all received vouchers, check their valid and extract
+ // Roll# and Ticket# using the external readvoucher binary
+
+ foreach ($a_vouchers_received as $voucher) {
+
+ $v = escapeshellarg($voucher);
+ if (strlen($voucher) < 3)
+ continue; // seems too short to be a voucher!
+
+ $result = exec("/usr/local/bin/voucher -c {$g['varetc_path']}/voucher.cfg -k {$g['varetc_path']}/voucher.public -- $v");
+ list($status, $roll, $nr) = explode(" ", $result);
+ if ($status == "OK") {
+ if (!$first_voucher)
+ {
+ $first_voucher = $voucher; // store first voucher. Thats the one we give the timecredit
+ $first_voucher_roll = $roll;
+ }
+ // check if we have this ticket on a registered roll for this ticket
+ if ($tickets_per_roll[$roll] && ($nr <= $tickets_per_roll[$roll])) {
+ // voucher is from a registered roll.
+ if (!isset($active_vouchers[$roll]))
+ $active_vouchers[$roll] = voucher_read_active_db($roll);
+ // valid voucher. Store roll# and ticket#
+ if ($line = $active_vouchers[$roll][$voucher]) {
+ list($timestamp,$minutes) = explode(",", $line);
+ // we have an already active voucher here.
+ $remaining = intval((($timestamp + 60*$minutes) - time())/60);
+ $test_result[] = "$voucher ($roll/$nr) active and good for $remaining Minutes";
+ $total_minutes += $remaining;
+ } else {
+ // voucher not used. Check if ticket Id is on the roll (not too high)
+ // and if the ticket is marked used.
+ // check if voucher already marked as used
+ if (!isset($bitstring[$roll]))
+ $bitstring[$roll] = voucher_read_used_db($roll);
+ $pos = $nr >> 3; // divide by 8 -> octet
+ $mask = 1 << ($nr % 8);
+ if (ord($bitstring[$roll][$pos]) & $mask) {
+ $test_result[] = "$voucher ($roll/$nr) already used and expired";
+ $total_minutes = -1; // voucher expired
+ $error++;
+ } else {
+ // mark bit for this voucher as used
+ $bitstring[$roll][$pos] = chr(ord($bitstring[$roll][$pos]) | $mask);
+ $test_result[] = "$voucher ($roll/$nr) good for {$minutes_per_roll[$roll]} Minutes";
+ $total_minutes += $minutes_per_roll[$roll];
+ }
+ }
+ } else {
+ $test_result[] = "$voucher ($roll/$nr): not found on any registererd Roll";
+ }
+ } else {
+ // hmm, thats weired ... not what I expected
+ $test_result[] = "$voucher invalid: $result !!";
+ $error++;
+ }
+ }
+
+ // if this was a test call, we're done. Return the result.
+ if ($test) {
+ if ($error) {
+ $test_result[] = "Access denied!";
+ } else {
+ $test_result[] = "Access granted for $total_minutes Minutes in total.";
+ }
+ unlock($voucherlck);
+ return $test_result;
+ }
+
+ // if we had an error (one of the vouchers is invalid), return 0.
+ // Discussion: we could return the time remaining for good vouchers, but then
+ // the user wouldn't know that he used at least one invalid voucher.
+
+ if ($error) {
+ unlock($voucherlck);
+ if ($total_minutes > 0) // probably not needed, but want to make sure
+ $total_minutes = 0; // we only report -1 (expired) or 0 (no access)
+ return $total_minutes; // well, at least one voucher had errors. Say NO ACCESS
+ }
+
+ // All given vouchers were valid and this isn't simply a test.
+ // Write back the used DB's
+
+ if (is_array($bitstring))
+ foreach ($bitstring as $roll => $used)
+ voucher_write_used_db($roll, base64_encode($used));
+
+ // Active DB: we only add the first voucher if multiple given
+ // and give that one all the time credit. This allows the user to logout and
+ // log in later using just the first voucher. It also keeps username limited
+ // to one voucher and that voucher shows the correct time credit in 'active vouchers'
+
+ if ($line = $active_vouchers[$first_voucher_roll][$first_voucher]) {
+ list($timestamp, $minutes) = explode(",", $line);
+ } else {
+ $timestamp = time(); // new voucher
+ $minutes = $total_minutes;
+ }
+
+ $active_vouchers[$first_voucher_roll][$first_voucher] = "$timestamp,$minutes";
+ voucher_write_active_db($roll, $active_vouchers[$first_voucher_roll]);
+
+ // mark the DB's as dirty.
+ if ($fd = fopen($dirtyfile, "w"))
+ fclose($fd);
+
+ unlock($voucherlck);
+
+ return $total_minutes;
+}
+
+function voucher_configure() {
+ global $config, $g;
+
+ /* kill any running minicron */
+ killbypid("{$g['varrun_path']}/vouchercron.pid");
+
+ if (isset($config['voucher']['enable'])) {
+
+ if ($g['booting']) {
+ echo "Enabling voucher support... ";
+ }
+
+ // start cron if we're asked to save runtime DB periodically
+ // to XML config if it changed
+ $croninterval = $config['voucher']['saveinterval'] * 60; // need seconds. Config has minutes
+ if ($croninterval) {
+ /* start pruning process (interval defaults to 60 seconds) */
+ mwexec("/usr/local/bin/minicron $croninterval {$g['varrun_path']}/vouchercron.pid " .
+ "/etc/rc.savevoucher");
+ }
+
+ $voucherlck = lock('voucher');
+ /* write public key used to verify vouchers */
+ $pubkey = base64_decode($config['voucher']['publickey']);
+ $fd = fopen("{$g['varetc_path']}/voucher.public", "w");
+ if (!$fd) {
+ printf("Error: cannot write voucher.public\n");
+ unlock($voucherlck);
+ return 1;
+ }
+ chmod("{$g['varetc_path']}/voucher.public", 0600);
+ fwrite($fd, $pubkey);
+ fclose($fd);
+
+ /* write config file used by voucher binary to decode vouchers */
+ $fd = fopen("{$g['varetc_path']}/voucher.cfg", "w");
+ if (!$fd) {
+ printf("Error: cannot write voucher.cfg\n");
+ unlock($voucherlck);
+ return 1;
+ }
+ chmod("{$g['varetc_path']}/voucher.cfg", 0600);
+ fwrite($fd, "{$config['voucher']['rollbits']},{$config['voucher']['ticketbits']},{$config['voucher']['checksumbits']},{$config['voucher']['magic']},{$config['voucher']['charset']}\n");
+ fclose($fd);
+ unlock($voucherlck);
+
+ if ($g['booting']) {
+
+ // create active and used DB per roll on ramdisk from config
+ $a_roll = &$config['voucher']['roll'];
+ $voucherlck = lock('voucher');
+
+ foreach ($a_roll as $rollent) {
+
+ $roll = $rollent['number'];
+ voucher_write_used_db($roll, $rollent['used']);
+ $minutes = $rollent['minutes'];
+ $active_vouchers = array();
+ $a_active = &$rollent['active'];
+ if (is_array($a_active)) {
+ foreach ($a_active as $activent) {
+ $voucher = $activent['voucher'];
+ $timestamp = $activent['timestamp'];
+ $minutes = $activent['minutes'];
+ // its tempting to check for expired timestamps, but during
+ // bootup, we most likely don't have the correct time time.
+ $active_vouchers[$voucher] = "$timestamp,$minutes";
+ }
+ }
+ voucher_write_active_db($roll, $active_vouchers);
+ }
+
+ unlock($voucherlck);
+ echo "done\n";
+ }
+ }
+ return 0;
+}
+
+/* write bitstring of used vouchers to ramdisk.
+ * Bitstring must already be base64_encoded!
+ */
+function voucher_write_used_db($roll, $vdb) {
+
+ global $g;
+
+ $fd = fopen("{$g['vardb_path']}/voucher_used_$roll.db", "w");
+ if ($fd) {
+ fwrite($fd, $vdb . "\n");
+ fclose($fd);
+ } else {
+ voucher_log(LOG_ERR, "cant write {$g['vardb_path']}/voucher_used_$roll.db");
+ }
+}
+
+/* return assoc array of active vouchers with activation timestamp
+ * voucher is index.
+ */
+function voucher_read_active_db($roll) {
+
+ global $g;
+
+ $active = array();
+ $dirty = 0;
+ $file = "{$g['vardb_path']}/voucher_active_$roll.db";
+ if (file_exists($file)) {
+ $fd = fopen($file, "r");
+ if ($fd) {
+ while (!feof($fd)) {
+ $line = trim(fgets($fd));
+ if ($line) {
+ list($voucher,$timestamp,$minutes) = explode(",", $line); // voucher,timestamp
+ if ((($timestamp + 60*$minutes) - time()) > 0) {
+ $active[$voucher] = "$timestamp,$minutes";
+ } else {
+ $dirty=1;
+ }
+ }
+ }
+ fclose($fd);
+ if ($dirty) // if we found expired entries, lets save our snapshot
+ voucher_write_active_db($roll, $active);
+ }
+ }
+ return $active;
+}
+
+/* store array of active vouchers back to DB */
+function voucher_write_active_db($roll, $active) {
+
+ global $g;
+
+ $fd = fopen("{$g['vardb_path']}/voucher_active_$roll.db", "w");
+ if ($fd) {
+ foreach($active as $voucher => $value)
+ fwrite($fd, "$voucher,$value\n");
+ fclose($fd);
+ }
+}
+
+/* return how many vouchers are marked used on a roll */
+function voucher_used_count($roll) {
+
+ global $g;
+
+ $bitstring = voucher_read_used_db($roll);
+ $max = strlen($bitstring) * 8;
+ $used = 0;
+ for ($i = 1; $i <= $max; $i++) {
+ // check if ticket already used or not.
+ $pos = $i >> 3; // divide by 8 -> octet
+ $mask = 1 << (($i % 8)-1); // mask to test bit in octet
+ if (ord($bitstring[$pos]) & $mask)
+ $used++;
+ }
+ return $used;
+}
+
+function voucher_read_used_db($roll) {
+
+ global $g;
+
+ $vdb = "";
+ $file = "{$g['vardb_path']}/voucher_used_$roll.db";
+ if (file_exists($file)) {
+ $fd = fopen($file, "r");
+ if ($fd) {
+ $vdb = trim(fgets($fd));
+ fclose($fd);
+ } else {
+ voucher_log(LOG_ERR, "cant read {$g['vardb_path']}/voucher_used_$roll.db");
+ }
+ }
+ return base64_decode($vdb);
+}
+
+function voucher_unlink_db($roll) {
+
+ global $g;
+ unlink("{$g['vardb_path']}/voucher_used_$roll.db");
+ unlink("{$g['vardb_path']}/voucher_active_$roll.db");
+}
+
+/* we share the log with captiveportal for now */
+function voucher_log($priority, $message) {
+
+ define_syslog_variables();
+ $message = trim($message);
+ openlog("logportalauth", LOG_PID, LOG_LOCAL4);
+ syslog($priority, "Voucher: " . $message);
+ closelog();
+}
+
+/* Save active and used voucher DB into XML config and write it to flash
+ * Called during reboot -> system_reboot_cleanup() and minicron
+ */
+function voucher_save_db_to_config() {
+
+ global $config, $g, $dirtyfile;
+
+ if (!isset($config['voucher']['enable']) || $config['voucher']['saveinterval'] == 0)
+ return; // no vouchers or don't want to save DB's
+
+ if (!file_exists($dirtyfile))
+ return; // nothing changed.
+
+ $voucherlck = lock('voucher');
+
+ // walk all active rolls and save runtime DB's to flash
+ $a_roll = &$config['voucher']['roll'];
+// foreach ($a_roll as $rollent) {
+ while (list($key, $value) = each($a_roll)) {
+ $rollent = &$a_roll[$key];
+ $roll = $rollent['number'];
+ $bitmask = voucher_read_used_db($roll);
+ $rollent['used'] = base64_encode($bitmask);
+ $active_vouchers = voucher_read_active_db($roll);
+ $db = array();
+ foreach($active_vouchers as $voucher => $line) {
+ list($timestamp,$minutes) = explode(",", $line);
+ $activent['voucher'] = $voucher;
+ $activent['timestamp'] = $timestamp;
+ $activent['minutes'] = $minutes;
+ $db[] = $activent;
+ }
+ $rollent['active'] = $db;
+ }
+ unlock($voucherlck);
+ unlink($dirtyfile);
+ write_config();
+ return;
+}
+
+?>
diff --git a/etc/inc/xmlparse.inc b/etc/inc/xmlparse.inc
index 574e8f1..cb55117 100644
--- a/etc/inc/xmlparse.inc
+++ b/etc/inc/xmlparse.inc
@@ -45,7 +45,7 @@ function listtags() {
"member menu tab mobilekey monitor_type mount ntpserver onetoone ".
"openvpn-server openvpn-client openvpn-csc " .
"option ppp package passthrumac phase1 phase2 priv proxyarpnet qinqentry queue ".
- "pages pipe route row rrddatafile rule schedule service servernat servers ".
+ "pages pipe roll route row rrddatafile rule schedule service servernat servers ".
"serversdisabled earlyshellcmd shellcmd staticmap subqueue timerange ".
"tunnel user vip virtual_server vlan winsserver wolentry widget "
);
diff --git a/etc/rc.bootup b/etc/rc.bootup
index c254dd3..7784ec2 100755
--- a/etc/rc.bootup
+++ b/etc/rc.bootup
@@ -264,6 +264,10 @@ vpn_setup();
/* start the captive portal */
captiveportal_configure();
+/* start Voucher support */
+require_once("voucher.inc");
+voucher_configure();
+
/* run any shell commands specified in config.xml */
system_do_shell_commands();
diff --git a/etc/rc.savevoucher b/etc/rc.savevoucher
new file mode 100644
index 0000000..338fd49
--- /dev/null
+++ b/etc/rc.savevoucher
@@ -0,0 +1,35 @@
+#!/usr/local/bin/php -f
+<?php
+/*
+ part of m0n0wall (http://m0n0.ch/wall)
+
+ Copyright (C) 2007 Marcel Wiget <mwiget@mac.com>.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+ /* parse the configuration and include all functions used below */
+ require_once("voucher.inc");
+
+ voucher_save_db_to_config();
+?>
diff --git a/usr/local/captiveportal/index.php b/usr/local/captiveportal/index.php
index 3771bf9..408e7f5 100755
--- a/usr/local/captiveportal/index.php
+++ b/usr/local/captiveportal/index.php
@@ -121,6 +121,33 @@ EOD;
/* radius functions handle everything so we exit here since we're done */
exit;
+} else if ($_POST['accept'] && $_POST['auth_voucher']) {
+
+ $voucher = trim($_POST['auth_voucher']);
+ $timecredit = voucher_auth($voucher);
+ // $timecredit contains either a credit in minutes or an error message
+ if ($timecredit > 0) { // voucher is valid. Remaining minutes returned
+ // if multiple vouchers given, use the first as username
+ $a_vouchers = split("[\t\n\r ]+",$voucher);
+ $voucher = $a_vouchers[0];
+ $attr = array( 'voucher' => 1,
+ 'session_timeout' => $timecredit*60,
+ 'session_terminate_time' => 0);
+ if (portal_allow($clientip, $clientmac,$voucher,null,$attr)) {
+
+ // YES: user is good for $timecredit minutes.
+ captiveportal_logportalauth($voucher,$clientmac,$clientip,"VOUCHER LOGIN good for $timecredit min.");
+ } else {
+ portal_reply_page($redirurl, "error", $config['voucher']['msgexpired']);
+ }
+ } else if (-1 == $timecredit) { // valid but expired
+ captiveportal_logportalauth($voucher,$clientmac,$clientip,"FAILURE","voucher expired");
+ portal_reply_page($redirurl, "error", $config['voucher']['msgexpired']);
+ } else {
+ captiveportal_logportalauth($voucher,$clientmac,$clientip,"FAILURE");
+ portal_reply_page($redirurl, "error", $config['voucher']['msgnoaccess']);
+ }
+
} else if ($_POST['accept'] && $radius_enable) {
if ($_POST['auth_user'] && $_POST['auth_pass']) {
@@ -233,6 +260,9 @@ function portal_allow($clientip,$clientmac,$username,$password = null, $attribut
$radiusservers = captiveportal_get_radius_servers();
+ if ($attributes['voucher'])
+ $remaining_time = $attributes['session_timeout'];
+
/* Find an existing session */
for ($i = 0; $i < count($cpdb); $i++) {
/* on the same ip */
@@ -241,6 +271,19 @@ function portal_allow($clientip,$clientmac,$username,$password = null, $attribut
$sessionid = $cpdb[$i][5];
break;
}
+ elseif (($attributes['voucher']) && ($username != 'unauthenticated') && ($cpdb[$i][4] == $username)) {
+ // user logged in with an active voucher. Check for how long and calculate
+ // how much time we can give him (voucher credit - used time)
+ $remaining_time = $cpdb[$i][0] + $cpdb[$i][7] - time();
+ if ($remaining_time < 0) // just in case.
+ $remaining_time = 0;
+
+ /* This user was already logged in so we disconnect the old one */
+ captiveportal_disconnect($cpdb[$i],$radiusservers,13);
+ captiveportal_logportalauth($cpdb[$i][4],$cpdb[$i][3],$cpdb[$i][2],"CONCURRENT LOGIN - TERMINATING OLD SESSION");
+ unset($cpdb[$i]);
+ break;
+ }
elseif ((isset($config['captiveportal']['noconcurrentlogins'])) && ($username != 'unauthenticated')) {
/* on the same username */
if ($cpdb[$i][4] == $username) {
@@ -253,6 +296,11 @@ function portal_allow($clientip,$clientmac,$username,$password = null, $attribut
}
}
+ if ($attributes['voucher'] && $remaining_time <= 0) {
+ unlock($cplock);
+ return 0; // voucher already used and no time left
+ }
+
if (!isset($sessionid)) {
/* generate unique session ID */
@@ -290,6 +338,9 @@ function portal_allow($clientip,$clientmac,$username,$password = null, $attribut
exec("/sbin/ipfw add $l2ruleno set 3 deny all from any to $clientip not MAC $clientmac any layer2 out");
}
+ if ($attributes['voucher'])
+ $attributes['session_timeout'] = $remaining_time;
+
/* encode password in Base64 just in case it contains commas */
$bpassword = base64_encode($password);
$cpdb[] = array(time(), $ruleno, $clientip, $clientmac, $username, $sessionid, $bpassword,
diff --git a/usr/local/www/services_captiveportal.php b/usr/local/www/services_captiveportal.php
index f0d8b24..93961a5 100755
--- a/usr/local/www/services_captiveportal.php
+++ b/usr/local/www/services_captiveportal.php
@@ -264,6 +264,7 @@ function enable_change(enable_change) {
$tab_array[] = array("Captive portal", true, "services_captiveportal.php");
$tab_array[] = array("Pass-through MAC", false, "services_captiveportal_mac.php");
$tab_array[] = array("Allowed IP addresses", false, "services_captiveportal_ip.php");
+ $tab_array[] = array("Vouchers", false, "services_captiveportal_vouchers.php");
$tab_array[] = array("File Manager", false, "services_captiveportal_filemanager.php");
display_top_tabs($tab_array);
?> </td></tr>
@@ -558,12 +559,13 @@ value="<?=htmlspecialchars($pconfig['radiuskey2']);?>"></td>
<?php endif; ?>
Upload an HTML file for the portal page here (leave blank to keep the current one). Make sure to include a form (POST to &quot;$PORTAL_ACTION$&quot;)
with a submit button (name=&quot;accept&quot;) and a hidden field with name=&quot;redirurl&quot; and value=&quot;$PORTAL_REDIRURL$&quot;.
-Include the &quot;auth_user&quot; and &quot;auth_pass&quot; input fields if authentication is enabled, otherwise it will always fail.
+Include the &quot;auth_user&quot; and &quot;auth_pass&quot; and/or &quot;auth_voucher&quot; input fields if authentication is enabled, otherwise it will always fail.
Example code for the form:<br>
<br>
<tt>&lt;form method=&quot;post&quot; action=&quot;$PORTAL_ACTION$&quot;&gt;<br>
&nbsp;&nbsp;&nbsp;&lt;input name=&quot;auth_user&quot; type=&quot;text&quot;&gt;<br>
&nbsp;&nbsp;&nbsp;&lt;input name=&quot;auth_pass&quot; type=&quot;password&quot;&gt;<br>
+ &nbsp;&nbsp;&nbsp;&lt;input name=&quot;auth_voucher&quot; type=&quot;text&quot;&gt;<br>
&nbsp;&nbsp;&nbsp;&lt;input name=&quot;redirurl&quot; type=&quot;hidden&quot; value=&quot;$PORTAL_REDIRURL$&quot;&gt;<br>
&nbsp;&nbsp;&nbsp;&lt;input name=&quot;accept&quot; type=&quot;submit&quot; value=&quot;Continue&quot;&gt;<br>
&lt;/form&gt;</tt></td>
diff --git a/usr/local/www/services_captiveportal_filemanager.php b/usr/local/www/services_captiveportal_filemanager.php
index 0c1a12c..3466f77 100755
--- a/usr/local/www/services_captiveportal_filemanager.php
+++ b/usr/local/www/services_captiveportal_filemanager.php
@@ -119,6 +119,7 @@ include("head.inc");
$tab_array[] = array("Captive portal", false, "services_captiveportal.php");
$tab_array[] = array("Pass-through MAC", false, "services_captiveportal_mac.php");
$tab_array[] = array("Allowed IP addresses", false, "services_captiveportal_ip.php");
+ $tab_array[] = array("Vouchers", false, "services_captiveportal_vouchers.php");
$tab_array[] = array("File Manager", true, "services_captiveportal_filemanager.php");
display_top_tabs($tab_array);
?> </td></tr>
diff --git a/usr/local/www/services_captiveportal_ip.php b/usr/local/www/services_captiveportal_ip.php
index 70908c7..ed828ac 100755
--- a/usr/local/www/services_captiveportal_ip.php
+++ b/usr/local/www/services_captiveportal_ip.php
@@ -90,6 +90,7 @@ include("head.inc");
$tab_array[] = array("Captive portal", false, "services_captiveportal.php");
$tab_array[] = array("Pass-through MAC", false, "services_captiveportal_mac.php");
$tab_array[] = array("Allowed IP addresses", true, "services_captiveportal_ip.php");
+ $tab_array[] = array("Vouchers", false, "services_captiveportal_vouchers.php");
$tab_array[] = array("File Manager", false, "services_captiveportal_filemanager.php");
display_top_tabs($tab_array);
?>
diff --git a/usr/local/www/services_captiveportal_mac.php b/usr/local/www/services_captiveportal_mac.php
index 01ef052..1b779f5 100755
--- a/usr/local/www/services_captiveportal_mac.php
+++ b/usr/local/www/services_captiveportal_mac.php
@@ -90,6 +90,7 @@ include("head.inc");
$tab_array[] = array("Captive portal", false, "services_captiveportal.php");
$tab_array[] = array("Pass-through MAC", true, "services_captiveportal_mac.php");
$tab_array[] = array("Allowed IP addresses", false, "services_captiveportal_ip.php");
+ $tab_array[] = array("Vouchers", false, "services_captiveportal_vouchers.php");
$tab_array[] = array("File Manager", false, "services_captiveportal_filemanager.php");
display_top_tabs($tab_array);
?>
diff --git a/usr/local/www/services_captiveportal_vouchers.php b/usr/local/www/services_captiveportal_vouchers.php
new file mode 100644
index 0000000..b2e54bd
--- /dev/null
+++ b/usr/local/www/services_captiveportal_vouchers.php
@@ -0,0 +1,395 @@
+<?php
+/*
+ Copyright (C) 2007 Marcel Wiget <mwiget@mac.com>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+##|+PRIV
+##|*IDENT=page-services-captiveportal-vouchers
+##|*NAME=Services: Captive portal Vouchers page
+##|*DESCR=Allow access to the 'Services: Captive portal Vouchers' page.
+##|*MATCH=services_captiveportal_vouchers.php*
+##|-PRIV
+
+$pgtitle = array("Services", "Captive portal", "Vouchers");
+require("guiconfig.inc");
+require_once("voucher.inc");
+
+if (!is_array($config['voucher'])) {
+ $config['voucher'] = array();
+}
+
+if (!is_array($config['voucher']['roll'])) {
+ $config['voucher']['roll'] = array();
+}
+if (!isset($config['voucher']['charset'])) {
+ $config['voucher']['charset'] = '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
+}
+if (!isset($config['voucher']['rollbits'])) {
+ $config['voucher']['rollbits'] = 16;
+}
+if (!isset($config['voucher']['ticketbits'])) {
+ $config['voucher']['ticketbits'] = 10;
+}
+if (!isset($config['voucher']['saveinterval'])) {
+ $config['voucher']['saveinterval'] = 300;
+}
+if (!isset($config['voucher']['checksumbits'])) {
+ $config['voucher']['checksumbits'] = 5;
+}
+if (!isset($config['voucher']['magic'])) {
+ $config['voucher']['magic'] = rand(); // anything slightly random will do
+}
+if (!isset($config['voucher']['publickey'])) {
+
+ /* generate a random 64 bit RSA key pair using the voucher binary */
+ $fd = popen("/usr/local/bin/voucher -g 64", "r");
+ if ($fd !== false) {
+ $output = fread($fd, 16384);
+ pclose($fd);
+
+ list($privkey, $pubkey) = explode("\0", $output);
+
+ $config['voucher']['publickey'] = base64_encode($pubkey);
+ $config['voucher']['privatekey'] = base64_encode($privkey);
+ }
+}
+if (!isset($config['voucher']['msgnoaccess'])) {
+ $config['voucher']['msgnoaccess'] = "Voucher invalid";
+}
+if (!isset($config['voucher']['msgexpired'])) {
+ $config['voucher']['msgexpired'] = "Voucher expired";
+}
+
+$a_roll = &$config['voucher']['roll'];
+
+if ($_GET['act'] == "del") {
+ $id = $_GET['id'];
+ if ($a_roll[$id]) {
+ $roll = $a_roll[$id]['number'];
+ $voucherlck = lock('voucher');
+ unset($a_roll[$id]);
+ voucher_unlink_db($roll);
+ unlock($voucherlck);
+ write_config();
+ header("Location: services_captiveportal_vouchers.php");
+ exit;
+ }
+}
+
+/* print all vouchers of the selected roll */
+if ($_GET['act'] == "csv") {
+ $privkey = base64_decode($config['voucher']['privatekey']);
+ if (strstr($privkey,"BEGIN RSA PRIVATE KEY")) {
+ $fd = fopen("{$g['varetc_path']}/voucher.private","w");
+ if (!$fd) {
+ $input_errors[] = "Cannot write private key file.\n";
+ } else {
+ chmod("{$g['varetc_path']}/voucher.private", 0600);
+ fwrite($fd, $privkey);
+ fclose($fd);
+
+ $a_voucher = &$config['voucher']['roll'];
+ $id = $_GET['id'];
+ if (isset($id) && $a_voucher[$id]) {
+ $number = $a_voucher[$id]['number'];
+ $count = $a_voucher[$id]['count'];
+
+ header("Content-Type: application/octet-stream");
+ header("Content-Disposition: attachment; filename=vouchers_roll$number.csv");
+ system("/usr/local/bin/voucher -c {$g['varetc_path']}/voucher.cfg -p {$g['varetc_path']}/voucher.private $number $count");
+ unlink("{$g['varetc_path']}/voucher.private");
+ exit;
+ }
+ }
+ } else {
+ $input_errors[] = "Need private RSA key to print vouchers\n";
+ }
+}
+
+$pconfig['enable'] = isset($config['voucher']['enable']);
+$pconfig['charset'] = $config['voucher']['charset'];
+$pconfig['rollbits'] = $config['voucher']['rollbits'];
+$pconfig['ticketbits'] = $config['voucher']['ticketbits'];
+$pconfig['saveinterval'] = $config['voucher']['saveinterval'];
+$pconfig['checksumbits'] = $config['voucher']['checksumbits'];
+$pconfig['magic'] = $config['voucher']['magic'];
+$pconfig['publickey'] = base64_decode($config['voucher']['publickey']);
+$pconfig['privatekey'] = base64_decode($config['voucher']['privatekey']);
+$pconfig['msgnoaccess'] = $config['voucher']['msgnoaccess'];
+$pconfig['msgexpired'] = $config['voucher']['msgexpired'];
+
+if ($_POST) {
+
+ unset($input_errors);
+ $pconfig = $_POST;
+
+ /* input validation */
+ if ($_POST['enable']) {
+ $reqdfields = explode(" ", "charset rollbits ticketbits checksumbits publickey magic saveinterval");
+ $reqdfieldsn = explode(",", "charset,rollbits,ticketbits,checksumbits,publickey,magic,saveinterval");
+
+ do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
+ }
+
+ if ($_POST['charset'] && (strlen($_POST['charset'] < 2))) {
+ $input_errors[] = "Need at least 2 characters to create vouchers.";
+ }
+ if ($_POST['charset'] && (strpos($_POST['charset'],"\"")>0)) {
+ $input_errors[] = "Double quotes aren't allowed.";
+ }
+ if ($_POST['charset'] && (strpos($_POST['charset'],",")>0)) {
+ $input_errors[] = "',' aren't allowed.";
+ }
+ if ($_POST['rollbits'] && (!is_numeric($_POST['rollbits']) || ($_POST['rollbits'] < 1) || ($_POST['rollbits'] > 31))) {
+ $input_errors[] = "# 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[] = "# 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[] = "# of Bits to store checksum needs to be between 1..31.";
+ }
+ if ($_POST['saveinterval'] && (!is_numeric($_POST['saveinterval']) || ($_POST['saveinterval'] < 1))) {
+ $input_errors[] = "Save interval in minutes cant be negative.";
+ }
+ if ($_POST['publickey'] && (!strstr($_POST['publickey'],"BEGIN PUBLIC KEY"))) {
+ $input_errors[] = "This doesn't look like an RSA Public key.";
+ }
+ if ($_POST['privatekey'] && (!strstr($_POST['privatekey'],"BEGIN RSA PRIVATE KEY"))) {
+ $input_errors[] = "This doesn't look like an RSA Private key.";
+ }
+
+ if (!$input_errors) {
+ $config['voucher']['enable'] = $_POST['enable'] ? true : false;
+ $config['voucher']['charset'] = $_POST['charset'];
+ $config['voucher']['rollbits'] = $_POST['rollbits'];
+ $config['voucher']['ticketbits'] = $_POST['ticketbits'];
+ $config['voucher']['checksumbits'] = $_POST['checksumbits'];
+ $config['voucher']['magic'] = $_POST['magic'];
+ $config['voucher']['saveinterval'] = $_POST['saveinterval'];
+ $config['voucher']['publickey'] = base64_encode($_POST['publickey']);
+ $config['voucher']['privatekey'] = base64_encode($_POST['privatekey']);
+ $config['voucher']['msgnoaccess'] = $_POST['msgnoaccess'];
+ $config['voucher']['msgexpired'] = $_POST['msgexpired'];
+
+ write_config();
+ voucher_configure();
+ if (isset($config['voucher']['enable']) && !isset($config['captiveportal']['enable'])) {
+ $savemsg = "Don't forget to configure and enable Captive Portal.";
+ }
+ }
+}
+include("head.inc");
+?>
+<?php include("fbegin.inc"); ?>
+<script type="text/javascript">
+<!--
+function enable_change(enable_change) {
+ var endis;
+ endis = !(document.iform.enable.checked || enable_change);
+
+ document.iform.charset.disabled = endis;
+ document.iform.rollbits.disabled = endis;
+ document.iform.ticketbits.disabled = endis;
+ document.iform.saveinterval.disabled = endis;
+ document.iform.checksumbits.disabled = endis;
+ document.iform.magic.disabled = endis;
+ document.iform.publickey.disabled = endis;
+ document.iform.privatekey.disabled = endis;
+ document.iform.msgnoaccess.disabled = endis;
+ document.iform.msgexpired.disabled = endis;
+}
+//-->
+</script>
+<?php if ($input_errors) print_input_errors($input_errors); ?>
+<?php if ($savemsg) print_info_box($savemsg); ?>
+<form action="services_captiveportal_vouchers.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
+<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="tab pane">
+ <tr><td class="tabnavtbl">
+ <ul id="tabnav">
+<?php
+ $tab_array = array();
+ $tab_array[] = array("Captive portal", false, "services_captiveportal.php");
+ $tab_array[] = array("Pass-through MAC", false, "services_captiveportal_mac.php");
+ $tab_array[] = array("Allowed IP addresses", false, "services_captiveportal_ip.php");
+ $tab_array[] = array("Vouchers", true, "services_captiveportal_vouchers.php");
+ $tab_array[] = array("File Manager", false, "services_captiveportal_filemanager.php");
+ display_top_tabs($tab_array);
+?>
+ </ul>
+ </td></tr>
+ <tr>
+ <td class="tabcont">
+ <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="checkbox pane">
+ <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"; ?> onClick="enable_change(false)">
+ <strong>Enable Vouchers</strong></td>
+ </tr>
+ <tr>
+ <td valign="top" class="vncell">Voucher Rolls</td>
+ <td class="vtable">
+
+ <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="content pane">
+ <tr>
+ <td width="10%" class="listhdrr">Roll#</td>
+ <td width="20%" class="listhdrr">Minutes/Ticket</td>
+ <td width="20%" class="listhdrr"># of Tickets</td>
+ <td width="35%" class="listhdr">Comment</td>
+ <td width="15%" class="list"></td>
+ </tr>
+ <?php $i = 0; foreach($a_roll as $rollent): ?>
+ <tr>
+ <td class="listlr">
+ <?=htmlspecialchars($rollent['number']); ?>&nbsp;
+ </td>
+ <td class="listr">
+ <?=htmlspecialchars($rollent['minutes']);?>&nbsp;
+ </td>
+ <td class="listr">
+ <?=htmlspecialchars($rollent['count']);?>&nbsp;
+ </td>
+ <td class="listr">
+ <?=htmlspecialchars($rollent['comment']); ?>&nbsp;
+ </td>
+ <td valign="middle" nowrap class="list">
+ <?php if ($pconfig['enable']): ?>
+ <a href="services_captiveportal_vouchers_edit.php?id=<?=$i; ?>"><img src="e.gif" title="edit voucher" width="17" height="17" border="0" alt="edit voucher"></a>
+ <a href="services_captiveportal_vouchers.php?act=del&amp;id=<?=$i; ?>" onclick="return confirm('Do you really want to delete this voucher? This makes all vouchers from this roll invalid')"><img src="x.gif" title="delete vouchers" width="17" height="17" border="0" alt="delete vouchers"></a>
+ <a href="services_captiveportal_vouchers.php?act=csv&amp;id=<?=$i; ?>"><img src="log_s.gif" title="generate vouchers for this roll to CSV file" width="11" height="15" border="0" alt="generate vouchers for this roll to CSV file"></a>
+ <?php endif;?>
+ </td>
+ </tr>
+ <?php $i++; endforeach; ?>
+ <tr>
+ <td class="list" colspan="4"></td>
+ <?php if ($pconfig['enable']): ?>
+ <td class="list"> <a href="services_captiveportal_vouchers_edit.php"><img src="plus.gif" title="add voucher" width="17" height="17" border="0" alt="add voucher"></a></td>
+ <?php endif;?>
+ </tr>
+ </table>
+<?php if ($pconfig['enable']): ?>
+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: ?>
+Enable Voucher support first using the checkbox above and hit Save at the bottom.</td>
+<?php endif;?>
+ </tr>
+ <tr>
+ <td valign="top" class="vncellreq">Voucher public key</td>
+ <td class="vtable">
+ <textarea name="publickey" cols="65" rows="4" id="publickey" class="formpre"><?=htmlspecialchars($pconfig['publickey']);?></textarea>
+ <br>
+ Paste an RSA public key (64 Bit or smaller) in PEM format here. This key is used to decrypt vouchers.</td>
+ </tr>
+ <tr>
+ <td valign="top" class="vncell">Voucher private key</td>
+ <td class="vtable">
+ <textarea name="privatekey" cols="65" rows="5" id="privatekey" class="formpre"><?=htmlspecialchars($pconfig['privatekey']);?></textarea>
+ <br>
+ 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.</td>
+ </tr>
+ <tr>
+ <td width="22%" valign="top" class="vncellreq">Character set</td>
+ <td width="78%" class="vtable">
+ <input name="charset" type="text" class="formfld" id="charset" size="80" value="<?=htmlspecialchars($pconfig['charset']);?>">
+ <br>
+ Tickets are generated with the specified character set. It should contain printable characters (numbers, lower case and upper case letters) that are hard to confuse with others. Avoid e.g. 0/O and l/1.</td>
+ </tr>
+ <tr>
+ <td width="22%" valign="top" class="vncellreq"># of Roll Bits</td>
+ <td width="78%" class="vtable">
+ <input name="rollbits" type="text" class="formfld" id="rollbits" size="2" value="<?=htmlspecialchars($pconfig['rollbits']);?>">
+ <br>
+ Reserves a range in each voucher to store the Roll# it belongs to. Allowed range: 1..31. Sum of Roll+Ticket+Checksum bits must be one Bit less than the RSA key size.</td>
+ </tr>
+ <tr>
+ <td width="22%" valign="top" class="vncellreq"># of Ticket Bits</td>
+ <td width="78%" class="vtable">
+ <input name="ticketbits" type="text" class="formfld" id="ticketbits" size="2" value="<?=htmlspecialchars($pconfig['ticketbits']);?>">
+ <br>
+ Reserves a range in each voucher to store the Ticket# it belongs to. Allowed range: 1..16. Using 16 bits allows a roll to have up to 65535 vouchers. A bit array, stored in RAM and in the config, is used to mark if a voucher has been used. A bit array for 65535 vouchers requires 8 KB of storage.</td>
+ </tr>
+ <tr>
+ <td width="22%" valign="top" class="vncellreq"># of Checksum Bits</td>
+ <td width="78%" class="vtable">
+ <input name="checksumbits" type="text" class="formfld" id="checksumbits" size="2" value="<?=htmlspecialchars($pconfig['checksumbits']);?>">
+ <br>
+ Reserves a range in each voucher to store a simple checksum over Roll# and Ticket#. Allowed range is 0..31.</td>
+ </tr>
+ <tr>
+ <td width="22%" valign="top" class="vncellreq">Magic Number</td>
+ <td width="78%" class="vtable">
+ <input name="magic" type="text" class="formfld" id="magic" size="20" value="<?=htmlspecialchars($pconfig['magic']);?>">
+ <br>
+ Magic number stored in every voucher. Verified during voucher check. Size depends on how many bits are left by Roll+Ticket+Checksum bits. If all bits are used, no magic number will be used and checked.</td>
+ </tr>
+ <tr>
+ <td width="22%" valign="top" class="vncellreq">Save Interval</td>
+ <td width="78%" class="vtable">
+ <input name="saveinterval" type="text" class="formfld" id="saveinterval" size="4" value="<?=htmlspecialchars($pconfig['saveinterval']);?>">
+ Minutes<br>
+ The list of active and used vouchers can be stored in the system's configuration file once every x minutes to survive power outages. No save is done if no new vouchers have been activated. Enter 0 to never write runtime state to XML config.</td>
+ </tr>
+ <tr>
+ <td width="22%" valign="top" class="vncellreq">Invalid Voucher Message</td>
+ <td width="78%" class="vtable">
+ <input name="msgnoaccess" type="text" class="formfld" id="msgnoaccess" size="80" value="<?=htmlspecialchars($pconfig['msgnoaccess']);?>">
+ Error message displayed for invalid vouchers on captive portal error page ($PORTAL_MESSAGE$).</td>
+ </tr>
+ <tr>
+ <td width="22%" valign="top" class="vncellreq">Expired Voucher Message</td>
+ <td width="78%" class="vtable">
+ <input name="msgexpired" type="text" class="formfld" id="msgexpired" size="80" value="<?=htmlspecialchars($pconfig['msgexpired']);?>">
+ Error message displayed for expired vouchers on paptive portal error page ($PORTAL_MESSAGE$).</td>
+ </tr>
+ <tr>
+ <td width="22%" valign="top">&nbsp;</td>
+ <td width="78%">
+ <input name="Submit" type="submit" class="formbtn" value="Save" onClick="enable_change(true)">
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2" class="list"><p class="vexpl">
+ <span class="red"><strong> Note:<br> </strong></span>
+ Changing any Voucher parameter (apart from managing the list of Rolls) on this page will render existing vouchers useless if they were generated with different settings.
+ </p>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+</form>
+<script type="text/javascript">
+<!--
+enable_change(false);
+//-->
+</script>
+<?php include("fend.inc"); ?>
diff --git a/usr/local/www/services_captiveportal_vouchers_edit.php b/usr/local/www/services_captiveportal_vouchers_edit.php
new file mode 100644
index 0000000..dff7cb3
--- /dev/null
+++ b/usr/local/www/services_captiveportal_vouchers_edit.php
@@ -0,0 +1,182 @@
+<?php
+/*
+ Copyright (C) 2007 Marcel Wiget <mwiget@mac.com>.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+##|+PRIV
+##|*IDENT=page-services-captiveportal-voucher-edit
+##|*NAME=Services: Captive portal Voucher Rolls page
+##|*DESCR=Allow access to the 'Services: Captive portal Edit Voucher Rolls' page.
+##|*MATCH=services_captiveportal_vouchers_edit.php*
+##|-PRIV
+
+$pgtitle = array("Services", "Captive portal", "Edit Voucher Rolls");
+require("guiconfig.inc");
+require_once("voucher.inc");
+
+if (!is_array($config['voucher'])) {
+ $config['voucher'] = array();
+}
+
+if (!is_array($config['voucher']['roll'])) {
+ $config['voucher']['roll'] = array();
+}
+// captiveportal_users_sort();
+$a_roll = &$config['voucher']['roll'];
+
+$id = $_GET['id'];
+if (isset($_POST['id']))
+ $id = $_POST['id'];
+
+if (isset($id) && $a_roll[$id]) {
+ $pconfig['number'] = $a_roll[$id]['number'];
+ $pconfig['count'] = $a_roll[$id]['count'];
+ $pconfig['minutes'] = $a_roll[$id]['minutes'];
+ $pconfig['comment'] = $a_roll[$id]['comment'];
+}
+
+$maxnumber = (1<<$config['voucher']['rollbits']) -1; // Highest Roll#
+$maxcount = (1<<$config['voucher']['ticketbits']) -1; // Highest Ticket#
+
+if ($_POST) {
+
+ unset($input_errors);
+ $pconfig = $_POST;
+
+ /* input validation */
+ $reqdfields = explode(" ", "number count minutes");
+ $reqdfieldsn = explode(",", "Number,Count,minutes");
+
+ do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
+
+ if (!is_numeric($_POST['number']) || $_POST['number'] >= $maxnumber)
+ $input_errors[] = "Roll number must be numeric and less than $maxnumber";
+
+ if (!is_numeric($_POST['count']) || $_POST['count'] < 1 || $_POST['count'] > $maxcount)
+ $input_errors[] = "A roll has at least one voucher and less than $maxcount.";
+
+ if (!is_numeric($_POST['minutes']) || $_POST['minutes'] < 1)
+ $input_errors[] = "Each voucher must be good for at least 1 minute.";
+
+ if (!$input_errors) {
+
+ if (isset($id) && $a_roll[$id])
+ $rollent = $a_roll[$id];
+
+ $rollent['number'] = $_POST['number'];
+ $rollent['minutes'] = $_POST['minutes'];
+ $rollent['comment'] = $_POST['comment'];
+
+ /* New Roll or modified voucher count: create bitmask */
+ $voucherlck = lock('voucher');
+ 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['active'] = array();
+ voucher_write_used_db($rollent['number'], $rollent['used']);
+ voucher_write_active_db($rollent['number'], array()); // create empty DB
+ voucher_log(LOG_INFO, "All {$rollent['count']} vouchers from Roll {$rollent['number']} marked unused");
+ } else {
+ // existing roll has been modified but without changing the count
+ // read active and used DB from ramdisk and store it in XML config
+ $rollent['used'] = base64_encode(voucher_read_used_db($rollent['number']));
+ $activent = array();
+ $db = array();
+ $active_vouchers = voucher_read_active_db($rollent['number'], $rollent['minutes']);
+ foreach($active_vouchers as $voucher => $line) {
+ list($timestamp, $minutes) = explode(",", $line);
+ $activent['voucher'] = $voucher;
+ $activent['timestamp'] = $timestamp;
+ $activent['minutes'] = $minutes;
+ $db[] = $activent;
+ }
+ $rollent['active'] = $db;
+ }
+ unlock($voucherlck);
+
+ if (isset($id) && $a_roll[$id])
+ $a_roll[$id] = $rollent;
+ else
+ $a_roll[] = $rollent;
+
+ write_config();
+
+ header("Location: services_captiveportal_vouchers.php");
+ exit;
+ }
+}
+
+include("head.inc");
+?>
+<?php include("fbegin.inc"); ?>
+<?php if ($input_errors) print_input_errors($input_errors); ?>
+<?php if ($savemsg) print_info_box($savemsg); ?>
+<form action="services_captiveportal_vouchers_edit.php" method="post" name="iform" id="iform">
+ <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="content pane">
+ <tr>
+ <td width="22%" valign="top" class="vncellreq">Roll#</td>
+ <td width="78%" class="vtable">
+ <?=$mandfldhtml;?><input name="number" type="text" class="formfld" id="number" size="10" value="<?=htmlspecialchars($pconfig['number']);?>">
+ <br>
+ <span class="vexpl">Enter the Roll# (0..<?=htmlspecialchars($maxnumber);?>) found on top of the generated/printed vouchers.</span>
+ </td>
+ </tr>
+ <tr>
+ <td width="22%" valign="top" class="vncellreq">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']);?>">
+ <br>
+ <span class="vexpl">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>
+ </tr>
+ <tr>
+ <td width="22%" valign="top" class="vncellreq">Count</td>
+ <td width="78%" class="vtable">
+ <?=$mandfldhtml;?><input name="count" type="text" class="formfld" id="count" size="10" value="<?=htmlspecialchars($pconfig['count']);?>">
+ <br>
+ <span class="vexpl">Enter the number of vouchers (1..<?=htmlspecialchars($maxcount);?>) 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">Comment</td>
+ <td width="78%" class="vtable">
+ <?=$mandfldhtml;?><input name="comment" type="text" class="formfld" id="comment" size="60" value="<?=htmlspecialchars($pconfig['comment']);?>">
+ <br>
+ <span class="vexpl">Can be used to further identify this roll. Ignored by the system.</span>
+ </td>
+ </tr>
+ <tr>
+ <td width="22%" valign="top">&nbsp;</td>
+ <td width="78%">
+ <input name="Submit" type="submit" class="formbtn" value="Save">
+ <?php if (isset($id) && $a_roll[$id]): ?>
+ <input name="id" type="hidden" value="<?=$id;?>">
+ <?php endif; ?>
+ </td>
+ </tr>
+ </table>
+ </form>
+<?php include("fend.inc"); ?>
diff --git a/usr/local/www/status_captiveportal.php b/usr/local/www/status_captiveportal.php
index 8895437..9e17d4b 100755
--- a/usr/local/www/status_captiveportal.php
+++ b/usr/local/www/status_captiveportal.php
@@ -36,11 +36,8 @@
##|*MATCH=status_captiveportal.php*
##|-PRIV
-
require("guiconfig.inc");
-$concurrent = `cat /var/db/captiveportal.db | wc -l`;
-
$pgtitle = array("Status: Captive portal");
include("head.inc");
@@ -64,10 +61,13 @@ function clientcmp($a, $b) {
}
$cpdb = array();
-if (file_exists("/var/db/captiveportal.db"))
- $cpcontents = file("/var/db/captiveportal.db", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
+if (file_exists("{$g['vardb_path']}/captiveportal.db"))
+ $cpcontents = file("{$g['vardb_path']}/captiveportal.db", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
else
$cpcontents = array();
+
+$concurrent = count($cpcontents);
+
foreach ($cpcontents as $cpcontent) {
$cpent = explode(",", $cpcontent);
if ($_GET['showact'])
@@ -88,6 +88,24 @@ if ($_GET['order']) {
usort($cpdb, "clientcmp");
}
?>
+
+<?php if (isset($config['voucher']['enable'])): ?>
+<form action="status_captiveportal.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
+<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="tab pane">
+<tr><td class="tabnavtbl">
+<?php
+ $tab_array = array();
+ $tab_array[] = array("Logged Users", true, "status_captiveportal.php");
+ $tab_array[] = array("Active Vouchers", false, "status_captiveportal_vouchers.php");
+ $tab_array[] = array("Voucher Rolls", false, "status_captiveportal_voucher_rolls.php");
+ $tab_array[] = array("Test Vouchers", false, "status_captiveportal_test.php");
+ display_top_tabs($tab_array);
+?>
+</td></tr>
+<tr>
+<td class="tabcont">
+<? endif; ?>
+
<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="listhdrr"><a href="?order=ip&amp;showact=<?=$_GET['showact'];?>"><?=gettext("IP address");?></a></td>
@@ -115,6 +133,14 @@ if ($_GET['order']) {
</tr>
<?php endforeach; ?>
</table>
+
+<?php if (isset($config['voucher']['enable'])): ?>
+</td>
+</tr>
+</table>
+</form>
+<?php endif; ?>
+
<form action="status_captiveportal.php" method="get" style="margin: 14px;">
<input type="hidden" name="order" value="<?=$_GET['order'];?>" />
<?php if ($_GET['showact']): ?>
diff --git a/usr/local/www/status_captiveportal_test.php b/usr/local/www/status_captiveportal_test.php
new file mode 100644
index 0000000..fd5cf73
--- /dev/null
+++ b/usr/local/www/status_captiveportal_test.php
@@ -0,0 +1,95 @@
+<?php
+/*
+ Copyright (C) 2007 Marcel Wiget <mwiget@mac.com>.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+##|+PRIV
+##|*IDENT=page-status-captiveportal-test
+##|*NAME=Status: Captive portal test Vouchers page
+##|*DESCR=Allow access to the 'Status: Captive portal Test Vouchers' page.
+##|*MATCH=status_captiveportal_test.php*
+##|-PRIV
+
+$pgtitle = array("Status", "Captive portal", "Test Vouchers");
+require("guiconfig.inc");
+require_once("voucher.inc");
+
+include("head.inc");
+include("fbegin.inc");
+?>
+
+<form action="status_captiveportal_test.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
+<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="tab pane">
+<tr><td class="tabnavtbl">
+<?php
+ $tab_array = array();
+ $tab_array[] = array("Users", false, "status_captiveportal.php");
+ $tab_array[] = array("Active Vouchers", false, "status_captiveportal_vouchers.php");
+ $tab_array[] = array("Voucher Rolls", false, "status_captiveportal_voucher_rolls.php");
+ $tab_array[] = array("Test Vouchers", true, "status_captiveportal_test.php");
+ display_top_tabs($tab_array);
+?>
+</td></tr>
+<tr>
+<td class="tabcont">
+
+<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="content pane">
+ <tr>
+ <td valign="top" class="vncellreq">Voucher(s)</td>
+ <td class="vtable">
+ <textarea name="vouchers" cols="65" rows="3" type="text" id="vouchers" class="formpre"><?=htmlspecialchars($_POST['vouchers']);?></textarea>
+ <br>
+Enter multiple vouchers separated by space or newline. The remaining time, if valid, will be shown for each voucher.</td>
+ </tr>
+ <tr>
+ <td width="22%" valign="top">&nbsp;</td>
+ <td width="78%">
+ <input name="Submit" type="submit" class="formbtn" value="Submit">
+ </td>
+ </tr>
+</table>
+</td></tr></table>
+</form>
+<p>
+<?php
+if ($_POST) {
+ if ($_POST['vouchers']) {
+ $test_results = voucher_auth($_POST['vouchers'], 1);
+ echo "<p><table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\">\n";
+ foreach ($test_results as $result) {
+ if (strpos($result, " good ") || strpos($result, " granted ")) {
+ echo "<tr><td bgcolor=\"#D9DEE8\"><img src=\"/pass.gif\"></td>";
+ echo "<td bgcolor=\"#D9DEE8\">$result</td></tr>";
+ } else {
+ echo "<tr><td bgcolor=\"#FFD9D1\"><img src=\"/block.gif\"></td>";
+ echo "<td bgcolor=\"#FFD9D1\">$result</td></tr>";
+ }
+ }
+ echo "</table></p>";
+ }
+}
+
+include("fend.inc");
+?>
diff --git a/usr/local/www/status_captiveportal_voucher_rolls.php b/usr/local/www/status_captiveportal_voucher_rolls.php
new file mode 100644
index 0000000..5e8a49f
--- /dev/null
+++ b/usr/local/www/status_captiveportal_voucher_rolls.php
@@ -0,0 +1,109 @@
+<?php
+/*
+ Copyright (C) 2007 Marcel Wiget <mwiget@mac.com>.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+##|+PRIV
+##|*IDENT=page-status-captiveportal-voucher-rolls
+##|*NAME=Status: Captive portal Voucher Rolls page
+##|*DESCR=Allow access to the 'Status: Captive portal Voucher Rolls' page.
+##|*MATCH=status_captiveportal_voucher_rolls.php*
+##|-PRIV
+
+$pgtitle = array("Status", "Captive portal", "Voucher Rolls");
+require("guiconfig.inc");
+require_once("voucher.inc");
+
+if (!is_array($config['voucher']['roll'])) {
+ $config['voucher']['roll'] = array();
+}
+$a_roll = &$config['voucher']['roll'];
+
+include("head.inc");
+include("fbegin.inc");
+?>
+
+<form action="status_captiveportal_voucher_rolls.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
+<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="tab pane">
+<tr><td class="tabnavtbl">
+<?php
+ $tab_array = array();
+ $tab_array[] = array("Users", false, "status_captiveportal.php");
+ $tab_array[] = array("Active Vouchers", false, "status_captiveportal_vouchers.php");
+ $tab_array[] = array("Voucher Rolls", true, "status_captiveportal_voucher_rolls.php");
+ $tab_array[] = array("Test Vouchers", false, "status_captiveportal_test.php");
+ display_top_tabs($tab_array);
+?>
+</td></tr>
+<tr>
+<td class="tabcont">
+
+<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="content pane">
+ <tr>
+ <td class="listhdrr">Roll#</td>
+ <td class="listhdrr">Minutes/Ticket</td>
+ <td class="listhdrr"># of Tickets</td>
+ <td class="listhdrr">Comment</td>
+ <td class="listhdrr">used</td>
+ <td class="listhdrr">active</td>
+ <td class="listhdr">ready</td>
+ </tr>
+<?php
+ $voucherlck = lock('voucher');
+ $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;
+?>
+ <tr>
+ <td class="listlr">
+ <?=htmlspecialchars($rollent['number']); ?>&nbsp;
+ </td>
+ <td class="listr">
+ <?=htmlspecialchars($rollent['minutes']);?>&nbsp;
+ </td>
+ <td class="listr">
+ <?=htmlspecialchars($rollent['count']);?>&nbsp;
+ </td>
+ <td class="listr">
+ <?=htmlspecialchars($rollent['comment']); ?>&nbsp;
+ </td>
+ <td class="listr">
+ <?=htmlspecialchars($used); ?>&nbsp;
+ </td>
+ <td class="listr">
+ <?=htmlspecialchars($active); ?>&nbsp;
+ </td>
+ <td class="listr">
+ <?=htmlspecialchars($ready); ?>&nbsp;
+ </td>
+ </tr>
+ <?php $i++; endforeach; unlock($voucherlck); ?>
+</table>
+</td>
+</tr>
+</table>
+</form>
+<?php include("fend.inc"); ?>
diff --git a/usr/local/www/status_captiveportal_vouchers.php b/usr/local/www/status_captiveportal_vouchers.php
new file mode 100644
index 0000000..8587942
--- /dev/null
+++ b/usr/local/www/status_captiveportal_vouchers.php
@@ -0,0 +1,117 @@
+<?php
+/*
+ Copyright (C) 2007 Marcel Wiget <mwiget@mac.com>.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+##|+PRIV
+##|*IDENT=page-status-captiveportal-vouchers
+##|*NAME=Status: Captive portal Vouchers page
+##|*DESCR=Allow access to the 'Status: Captive portal Vouchers' page.
+##|*MATCH=status_captiveportal_vouchers.php*
+##|-PRIV
+
+$pgtitle = array("Status", "Captive portal", "Vouchers");
+require("guiconfig.inc");
+require_once("voucher.inc");
+
+function clientcmp($a, $b) {
+ global $order;
+ return strcmp($a[$order], $b[$order]);
+}
+
+if (!is_array($config['voucher']['roll'])) {
+ $config['voucher']['roll'] = array();
+}
+$a_roll = $config['voucher']['roll'];
+
+$db = array();
+
+foreach($a_roll as $rollent) {
+ $roll = $rollent['number'];
+ $minutes = $rollent['minutes'];
+ $active_vouchers = file("{$g['vardb_path']}/voucher_active_$roll.db", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
+ foreach($active_vouchers as $voucher => $line) {
+ list($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");
+}
+
+include("head.inc");
+include("fbegin.inc");
+?>
+
+<form action="status_captiveportal_vouchers.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
+<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="tab pane">
+<tr><td class="tabnavtbl">
+<?php
+ $tab_array = array();
+ $tab_array[] = array("Users", false, "status_captiveportal.php");
+ $tab_array[] = array("Active Vouchers", true, "status_captiveportal_vouchers.php");
+ $tab_array[] = array("Voucher Rolls", false, "status_captiveportal_voucher_rolls.php");
+ $tab_array[] = array("Test Vouchers", false, "status_captiveportal_test.php");
+ display_top_tabs($tab_array);
+?>
+</td></tr>
+<tr>
+<td class="tabcont">
+
+<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="content pane">
+ <tr>
+ <td class="listhdrr"><a href="?order=0&showact=<?=$_GET['showact'];?>">Voucher</a></td>
+ <td class="listhdrr"><a href="?order=1&showact=<?=$_GET['showact'];?>">Roll</a></td>
+ <td class="listhdrr"><a href="?order=2&showact=<?=$_GET['showact'];?>">Activated at</a></td>
+ <td class="listhdrr"><a href="?order=3&showact=<?=$_GET['showact'];?>">Expires in</a></td>
+ <td class="listhdr"><a href="?order=4&showact=<?=$_GET['showact'];?>">Expires at</a></td>
+ <td class="list"></td>
+ </tr>
+<?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];?> min</td>
+ <td class="listr"><?=htmlspecialchars(date("m/d/Y H:i:s", $dbent[4]));?></td>
+ <td class="list"></td>
+ </tr>
+<?php endforeach; ?>
+</table>
+</td>
+</tr>
+</table>
+</form>
+<?php include("fend.inc"); ?>
OpenPOWER on IntegriCloud