summaryrefslogtreecommitdiffstats
path: root/etc/inc/voucher.inc
diff options
context:
space:
mode:
authorVinicius Coque <vinicius.coque@bluepex.com>2011-06-20 08:50:19 -0300
committerVinicius Coque <vinicius.coque@bluepex.com>2011-06-20 08:50:19 -0300
commitf0b17f3f7226f819c94dfab4c9abc0f3e4962152 (patch)
tree3118cd18bd89dd64cf991c1023099d63593ecedd /etc/inc/voucher.inc
parentd8012adbce60d9a90dac54e5b7832f8fa7e82fb6 (diff)
parent3745f21e2a9ccac1dadf78864ef65f2318ac919c (diff)
downloadpfsense-f0b17f3f7226f819c94dfab4c9abc0f3e4962152.zip
pfsense-f0b17f3f7226f819c94dfab4c9abc0f3e4962152.tar.gz
Merge remote-tracking branch 'mainline/master' into inc
Diffstat (limited to 'etc/inc/voucher.inc')
-rw-r--r--etc/inc/voucher.inc48
1 files changed, 31 insertions, 17 deletions
diff --git a/etc/inc/voucher.inc b/etc/inc/voucher.inc
index dda49d2..d50269f 100644
--- a/etc/inc/voucher.inc
+++ b/etc/inc/voucher.inc
@@ -29,7 +29,7 @@
*/
/*
- pfSense_BUILDER_BINARIES: /usr/local/bin/voucher /usr/local/bin/minicron
+ pfSense_BUILDER_BINARIES: /usr/local/bin/voucher
pfSense_MODULE: captiveportal
*/
@@ -213,6 +213,9 @@ function voucher_expire($voucher_received) {
$a_vouchers_received = split("[\t\n\r ]+",$voucher_received);
$active_dirty = false;
+ $cpdb = captiveportal_read_db(false, 4); /* Indexed by Voucher */
+ $unsetindexes[] = array();
+
// go through all received vouchers, check their valid and extract
// Roll# and Ticket# using the external readvoucher binary
foreach ($a_vouchers_received as $voucher) {
@@ -242,6 +245,15 @@ function voucher_expire($voucher_received) {
if (!(ord($bitstring[$roll][$pos]) & $mask))
$bitstring[$roll][$pos] = chr(ord($bitstring[$roll][$pos]) | $mask);
captiveportal_syslog("{$voucher} ({$roll}/{$nr}) forced to expire");
+
+ /* Check if this voucher has any active sessions */
+ if (isset($cpdb[$voucher])) {
+ $cpentry = $cpdb[$voucher];
+ captiveportal_disconnect($cpentry,null,13);
+ captiveportal_logportalauth($cpentry[4],$cpentry[3],$cpentry[2],"FORCLY TERMINATING VOUCHER {$voucher} SESSION");
+ unset($cpdb[$voucher]);
+ $unsetindexes[] = $cpentry[5];
+ }
} else
captiveportal_syslog("$voucher ($roll/$nr): not found on any registererd Roll");
} else
@@ -253,6 +265,9 @@ function voucher_expire($voucher_received) {
if ($active_dirty == true) {
foreach ($active_vouchers as $roll => $active)
voucher_write_active_db($roll, $active);
+
+ /* Triger a sync of the vouchers on config */
+ send_event("service sync vouchers");
}
// Write back the used DB's
@@ -269,6 +284,10 @@ function voucher_expire($voucher_received) {
unlock($voucherlck);
+ /* Write database */
+ if (!empty($unsetindexes))
+ captiveportal_write_db($cpdb, false, $unsetindexes);
+
return true;
}
@@ -424,6 +443,9 @@ function voucher_auth($voucher_received, $test = 0) {
$active_vouchers[$first_voucher_roll][$first_voucher] = "$timestamp,$minutes";
voucher_write_active_db($roll, $active_vouchers[$first_voucher_roll]);
+ /* Triger a sync of the vouchers on config */
+ send_event("service sync vouchers");
+
unlock($voucherlck);
return $total_minutes;
@@ -432,9 +454,6 @@ function voucher_auth($voucher_received, $test = 0) {
function voucher_configure($sync = false) {
global $config, $g;
- /* kill any running minicron */
- killbypid("{$g['varrun_path']}/vouchercron.pid");
-
if (!isset($config['voucher']['enable']))
return 0;
@@ -443,15 +462,6 @@ function voucher_configure($sync = false) {
if ($sync == true)
captiveportal_syslog("Writing voucher db from sync data...");
- // 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', LOCK_EX);
/* write public key used to verify vouchers */
@@ -548,8 +558,12 @@ function voucher_read_active_db($roll) {
}
}
fclose($fd);
- if ($dirty) // if we found expired entries, lets save our snapshot
+ if ($dirty) { // if we found expired entries, lets save our snapshot
voucher_write_active_db($roll, $active);
+
+ /* Triger a sync of the vouchers on config */
+ send_event("service sync vouchers");
+ }
}
}
return $active;
@@ -620,12 +634,12 @@ function voucher_log($priority, $message) {
}
/* Save active and used voucher DB into XML config and write it to flash
- * Called during reboot -> system_reboot_cleanup() and minicron
+ * Called during reboot -> system_reboot_cleanup() and every active voucher change
*/
function voucher_save_db_to_config() {
global $config, $g;
- if (!isset($config['voucher']['enable']) || $config['voucher']['saveinterval'] == 0)
+ if (!isset($config['voucher']['enable']))
return; // no vouchers or don't want to save DB's
$voucherlck = lock('voucher', LOCK_EX);
@@ -653,7 +667,7 @@ function voucher_save_db_to_config() {
unlock($voucherlck);
- write_config();
+ write_config("Synching vouchers");
return;
}
OpenPOWER on IntegriCloud