summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/inc/captiveportal.inc6
-rw-r--r--etc/inc/voucher.inc32
-rw-r--r--usr/local/www/services_captiveportal_vouchers.php23
3 files changed, 23 insertions, 38 deletions
diff --git a/etc/inc/captiveportal.inc b/etc/inc/captiveportal.inc
index 711b2d4..a87e732 100644
--- a/etc/inc/captiveportal.inc
+++ b/etc/inc/captiveportal.inc
@@ -652,6 +652,7 @@ function captiveportal_prune_old() {
* had a chance to iterate over all accounts.
*/
$unsetindexes = array();
+ $voucher_needs_sync = false;
foreach ($cpdb as $cpentry) {
$timedout = false;
@@ -694,6 +695,7 @@ function captiveportal_prune_old() {
if (time() >= ($cpentry[0] + $cpentry[7])) {
$timedout = true;
$term_cause = 5; // Session-Timeout
+ $voucher_needs_sync = true;
}
}
@@ -762,6 +764,10 @@ function captiveportal_prune_old() {
}
}
+ if ($voucher_needs_sync == true)
+ /* Triger a sync of the vouchers on config */
+ send_event("service sync vouchers");
+
/* write database */
if (!empty($unsetindexes))
captiveportal_write_db($cpdb, false, $unsetindexes);
diff --git a/etc/inc/voucher.inc b/etc/inc/voucher.inc
index ad96914..be3e322 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
*/
@@ -265,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
@@ -440,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;
@@ -448,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;
@@ -459,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 */
@@ -564,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;
@@ -636,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);
@@ -669,7 +667,7 @@ function voucher_save_db_to_config() {
unlock($voucherlck);
- write_config();
+ write_config("Synching vouchers");
return;
}
diff --git a/usr/local/www/services_captiveportal_vouchers.php b/usr/local/www/services_captiveportal_vouchers.php
index f5af953..f4f4b89 100644
--- a/usr/local/www/services_captiveportal_vouchers.php
+++ b/usr/local/www/services_captiveportal_vouchers.php
@@ -78,8 +78,6 @@ 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'] = 5;
if (!isset($config['voucher']['checksumbits']))
$config['voucher']['checksumbits'] = 5;
if (!isset($config['voucher']['magic']))
@@ -150,7 +148,6 @@ $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']);
@@ -176,8 +173,8 @@ if ($_POST) {
/* input validation */
if ($_POST['enable'] == "yes") {
if (!$_POST['vouchersyncusername']) {
- $reqdfields = explode(" ", "charset rollbits ticketbits checksumbits publickey magic saveinterval");
- $reqdfieldsn = array(gettext("charset"),gettext("rollbits"),gettext("ticketbits"),gettext("checksumbits"),gettext("publickey"),gettext("magic"),gettext("saveinterval"));
+ $reqdfields = explode(" ", "charset rollbits ticketbits checksumbits publickey magic");
+ $reqdfieldsn = array(gettext("charset"),gettext("rollbits"),gettext("ticketbits"),gettext("checksumbits"),gettext("publickey"),gettext("magic"));
} else {
$reqdfields = explode(" ", "vouchersyncdbip vouchersyncport vouchersyncpass vouchersyncusername");
$reqdfieldsn = array(gettext("Synchronize Voucher Database IP"),gettext("Sync port"),gettext("Sync password"),gettext("Sync username"));
@@ -200,8 +197,6 @@ if ($_POST) {
$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['saveinterval'] && (!is_numeric($_POST['saveinterval']) || ($_POST['saveinterval'] < 1)))
- $input_errors[] = gettext("Save interval in minutes cant be negative.");
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")))
@@ -221,7 +216,6 @@ if ($_POST) {
$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'];
@@ -287,8 +281,6 @@ EOF;
$config['voucher']['rollbits'] = $toreturn['voucher']['rollbits'];
if($toreturn['voucher']['ticketbits'])
$config['voucher']['ticketbits'] = $toreturn['voucher']['ticketbits'];
- if($toreturn['voucher']['saveinterval'])
- $config['voucher']['saveinterval'] = $toreturn['voucher']['saveinterval'];
if($toreturn['voucher']['checksumbits'])
$config['voucher']['checksumbits'] = $toreturn['voucher']['checksumbits'];
if($toreturn['voucher']['magic'])
@@ -336,7 +328,6 @@ function before_save() {
document.iform.charset.disabled = false;
document.iform.rollbits.disabled = false;
document.iform.ticketbits.disabled = false;
- document.iform.saveinterval.disabled = false;
document.iform.checksumbits.disabled = false;
document.iform.magic.disabled = false;
document.iform.publickey.disabled = false;
@@ -353,7 +344,6 @@ function enable_change(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;
@@ -368,7 +358,6 @@ function enable_change(enable_change) {
document.iform.charset.disabled = true;
document.iform.rollbits.disabled = true;
document.iform.ticketbits.disabled = true;
- document.iform.saveinterval.disabled = true;
document.iform.checksumbits.disabled = true;
document.iform.magic.disabled = true;
document.iform.publickey.disabled = true;
@@ -534,14 +523,6 @@ function enable_change(enable_change) {
</td>
</tr>
<tr>
- <td width="22%" valign="top" class="vncellreq"><?=gettext("Save Interval"); ?></td>
- <td width="78%" class="vtable">
- <input name="saveinterval" type="text" class="formfld" id="saveinterval" size="4" value="<?=htmlspecialchars($pconfig['saveinterval']);?>">
- <?=gettext("Minutes"); ?><br>
- <?=gettext("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"><?=gettext("Invalid Voucher Message"); ?></td>
<td width="78%" class="vtable">
<input name="msgnoaccess" type="text" class="formfld" id="msgnoaccess" size="80" value="<?=htmlspecialchars($pconfig['msgnoaccess']);?>">
OpenPOWER on IntegriCloud