Revision 5ebe85e9
Added by Ermal LUÇI about 14 years ago
etc/inc/voucher.inc | ||
---|---|---|
29 | 29 |
*/ |
30 | 30 |
|
31 | 31 |
/* |
32 |
pfSense_BUILDER_BINARIES: /usr/local/bin/voucher /usr/local/bin/minicron
|
|
32 |
pfSense_BUILDER_BINARIES: /usr/local/bin/voucher |
|
33 | 33 |
pfSense_MODULE: captiveportal |
34 | 34 |
*/ |
35 | 35 |
|
... | ... | |
265 | 265 |
if ($active_dirty == true) { |
266 | 266 |
foreach ($active_vouchers as $roll => $active) |
267 | 267 |
voucher_write_active_db($roll, $active); |
268 |
|
|
269 |
/* Triger a sync of the vouchers on config */ |
|
270 |
send_event("service sync vouchers"); |
|
268 | 271 |
} |
269 | 272 |
|
270 | 273 |
// Write back the used DB's |
... | ... | |
440 | 443 |
$active_vouchers[$first_voucher_roll][$first_voucher] = "$timestamp,$minutes"; |
441 | 444 |
voucher_write_active_db($roll, $active_vouchers[$first_voucher_roll]); |
442 | 445 |
|
446 |
/* Triger a sync of the vouchers on config */ |
|
447 |
send_event("service sync vouchers"); |
|
448 |
|
|
443 | 449 |
unlock($voucherlck); |
444 | 450 |
|
445 | 451 |
return $total_minutes; |
... | ... | |
448 | 454 |
function voucher_configure($sync = false) { |
449 | 455 |
global $config, $g; |
450 | 456 |
|
451 |
/* kill any running minicron */ |
|
452 |
killbypid("{$g['varrun_path']}/vouchercron.pid"); |
|
453 |
|
|
454 | 457 |
if (!isset($config['voucher']['enable'])) |
455 | 458 |
return 0; |
456 | 459 |
|
... | ... | |
459 | 462 |
if ($sync == true) |
460 | 463 |
captiveportal_syslog("Writing voucher db from sync data..."); |
461 | 464 |
|
462 |
// start cron if we're asked to save runtime DB periodically |
|
463 |
// to XML config if it changed |
|
464 |
$croninterval = $config['voucher']['saveinterval'] * 60; // need seconds. Config has minutes |
|
465 |
if ($croninterval) { |
|
466 |
/* start pruning process (interval defaults to 60 seconds) */ |
|
467 |
mwexec("/usr/local/bin/minicron $croninterval {$g['varrun_path']}/vouchercron.pid " . |
|
468 |
"/etc/rc.savevoucher"); |
|
469 |
} |
|
470 |
|
|
471 | 465 |
$voucherlck = lock('voucher', LOCK_EX); |
472 | 466 |
|
473 | 467 |
/* write public key used to verify vouchers */ |
... | ... | |
564 | 558 |
} |
565 | 559 |
} |
566 | 560 |
fclose($fd); |
567 |
if ($dirty) // if we found expired entries, lets save our snapshot |
|
561 |
if ($dirty) { // if we found expired entries, lets save our snapshot
|
|
568 | 562 |
voucher_write_active_db($roll, $active); |
563 |
|
|
564 |
/* Triger a sync of the vouchers on config */ |
|
565 |
send_event("service sync vouchers"); |
|
566 |
} |
|
569 | 567 |
} |
570 | 568 |
} |
571 | 569 |
return $active; |
... | ... | |
636 | 634 |
} |
637 | 635 |
|
638 | 636 |
/* Save active and used voucher DB into XML config and write it to flash |
639 |
* Called during reboot -> system_reboot_cleanup() and minicron
|
|
637 |
* Called during reboot -> system_reboot_cleanup() and every active voucher change
|
|
640 | 638 |
*/ |
641 | 639 |
function voucher_save_db_to_config() { |
642 | 640 |
global $config, $g; |
643 | 641 |
|
644 |
if (!isset($config['voucher']['enable']) || $config['voucher']['saveinterval'] == 0)
|
|
642 |
if (!isset($config['voucher']['enable']))
|
|
645 | 643 |
return; // no vouchers or don't want to save DB's |
646 | 644 |
|
647 | 645 |
$voucherlck = lock('voucher', LOCK_EX); |
... | ... | |
669 | 667 |
|
670 | 668 |
unlock($voucherlck); |
671 | 669 |
|
672 |
write_config(); |
|
670 |
write_config("Synching vouchers");
|
|
673 | 671 |
return; |
674 | 672 |
} |
675 | 673 |
|
Also available in: Unified diff
Fixes #1327. Trigger synching of vouchers to config through check_reload_status. Retire the saveinterval option since it is not useful anymore. Use the prune process of captiveportal to sync vouchers as well to fix issues as reported-by: http://forum.pfsense.org/index.php/topic,37636.0.html