Commit 338f71c2 authored by Franco Fichtner's avatar Franco Fichtner

rc|vouchers: shuffle around the backup invoke; merge halt/reboot glue

parent ad5065e0
...@@ -1645,10 +1645,10 @@ function system_reboot($sync = false) ...@@ -1645,10 +1645,10 @@ function system_reboot($sync = false)
mwexec($cmd); mwexec($cmd);
} }
function system_reboot_cleanup() { function system_reboot_cleanup()
{
global $config, $cpzone; global $config, $cpzone;
mwexec("/usr/local/bin/beep.sh stop");
require_once("captiveportal.inc"); require_once("captiveportal.inc");
if (is_array($config['captiveportal'])) { if (is_array($config['captiveportal'])) {
foreach ($config['captiveportal'] as $cpzone=>$cp) { foreach ($config['captiveportal'] as $cpzone=>$cp) {
...@@ -1656,8 +1656,6 @@ function system_reboot_cleanup() { ...@@ -1656,8 +1656,6 @@ function system_reboot_cleanup() {
captiveportal_send_server_accounting(true); captiveportal_send_server_accounting(true);
} }
} }
require_once("voucher.inc");
voucher_save_db_to_config();
} }
function system_console_configure() function system_console_configure()
......
<?php <?php
/* /*
Copyright (C) 2010-2012 Ermal Luci <eri@pfsense.org> Copyright (C) 2010-2012 Ermal Luci <eri@pfsense.org>
Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com> Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2007 Marcel Wiget <mwiget@mac.com> Copyright (C) 2007 Marcel Wiget <mwiget@mac.com>
All rights reserved. All rights reserved.
...@@ -28,15 +29,8 @@ ...@@ -28,15 +29,8 @@
*/ */
/*
pfSense_BUILDER_BINARIES: /usr/local/bin/voucher
pfSense_MODULE: captiveportal
*/
/* include all configuration functions */ /* include all configuration functions */
if(!function_exists('captiveportal_syslog')) require_once("captiveportal.inc");
require_once("captiveportal.inc");
function voucher_expire($voucher_received) { function voucher_expire($voucher_received) {
global $g, $config, $cpzone; global $g, $config, $cpzone;
...@@ -276,8 +270,9 @@ function voucher_auth($voucher_received, $test = 0) { ...@@ -276,8 +270,9 @@ function voucher_auth($voucher_received, $test = 0) {
return $total_minutes; return $total_minutes;
} }
function voucher_configure($sync = false) { function voucher_configure($sync = false)
global $config, $g, $cpzone; {
global $config, $cpzone;
if (is_array($config['voucher'])) { if (is_array($config['voucher'])) {
foreach ($config['voucher'] as $voucherzone => $vcfg) { foreach ($config['voucher'] as $voucherzone => $vcfg) {
...@@ -474,57 +469,70 @@ function voucher_log($priority, $message) { ...@@ -474,57 +469,70 @@ function voucher_log($priority, $message) {
closelog(); closelog();
} }
/* Save active and used voucher DB into XML config and write it to flash /*
* Called during reboot -> system_reboot_cleanup() and every active voucher change * Save active and used voucher DB into XML config and write it to config
* Called during reboot and every active voucher change
*/ */
function voucher_save_db_to_config() { function voucher_save_db_to_config()
global $config, $g, $cpzone; {
global $config, $cpzone;
if (is_array($config['voucher'])) { if (!isset($config['voucher'])) {
foreach ($config['voucher'] as $voucherzone => $vcfg) { return;
$cpzone = $voucherzone; }
voucher_save_db_to_config_zone();
} $needs_write = 0;
foreach ($config['voucher'] as $voucherzone => $vcfg) {
$cpzone = $voucherzone;
$needs_write += voucher_save_db_to_config_zone();
}
if ($needs_write) {
write_config("Backing up vouchers");
} }
} }
function voucher_save_db_to_config_zone() { function voucher_save_db_to_config_zone()
global $config, $g, $cpzone; {
global $config, $cpzone;
if (!isset($config['voucher'][$cpzone]['enable'])) if (!isset($config['voucher'][$cpzone]['enable'])) {
return; // no vouchers or don't want to save DB's // no vouchers or don't want to save DB's
return 0;
}
if (!is_array($config['voucher'][$cpzone]['roll'])) if (!isset($config['voucher'][$cpzone]['roll'])) {
return; return 0;
}
$voucherlck = lock("voucher{$cpzone}", LOCK_EX); $voucherlck = lock("voucher{$cpzone}", LOCK_EX);
// walk all active rolls and save runtime DB's to flash // walk all active rolls and save runtime DBs
$a_roll = &$config['voucher'][$cpzone]['roll']; $a_roll = &$config['voucher'][$cpzone]['roll'];
while (list($key, $value) = each($a_roll)) { while (list($key, $value) = each($a_roll)) {
$rollent = &$a_roll[$key]; $rollent = &$a_roll[$key];
$roll = $rollent['number']; $roll = $rollent['number'];
$bitmask = voucher_read_used_db($roll); $bitmask = voucher_read_used_db($roll);
$rollent['used'] = base64_encode($bitmask); $rollent['used'] = base64_encode($bitmask);
$active_vouchers = voucher_read_active_db($roll); $active_vouchers = voucher_read_active_db($roll);
$db = array(); $db = array();
$dbi = 1; $dbi = 1;
foreach($active_vouchers as $voucher => $line) {
list($timestamp,$minutes) = explode(",", $line);
$activent['voucher'] = $voucher;
$activent['timestamp'] = $timestamp;
$activent['minutes'] = $minutes;
$db["v{$dbi}"] = $activent;
$dbi++;
}
$rollent['active'] = $db;
unset($active_vouchers);
}
unlock($voucherlck); foreach($active_vouchers as $voucher => $line) {
list($timestamp, $minutes) = explode(',', $line);
$activent['voucher'] = $voucher;
$activent['timestamp'] = $timestamp;
$activent['minutes'] = $minutes;
$db["v{$dbi}"] = $activent;
$dbi++;
}
write_config("Synching vouchers"); $rollent['active'] = $db;
return; unset($active_vouchers);
} }
?> unlock($voucherlck);
return 1;
}
#!/bin/sh #!/bin/sh
# shutdown rc scripts # invoke shared powerdown routines
/usr/local/etc/rc.opnsense stop . /usr/local/etc/rc.halt.common
/usr/local/etc/rc.backup_rrd
/usr/local/etc/rc.backup_dhcpleases
# wait for config lock to release
php -a >/dev/null << EOF
\$fp = fopen('/conf/config.xml', "w+");
if (flock(\$fp, LOCK_EX)) {
flock(\$fp, LOCK_UN);
fclose(\$fp);
}
EOF
# power down the system
/sbin/shutdown -op now /sbin/shutdown -op now
#!/bin/sh
# shutdown rc scripts
/usr/local/etc/rc.opnsense stop
# backup volatile internals
/usr/local/etc/rc.backup_rrd
/usr/local/etc/rc.backup_dhcpleases
/usr/local/etc/rc.savevouchers
# wait for config lock to release
php -a >/dev/null << EOF
\$fp = fopen('/conf/config.xml', "w+");
if (flock(\$fp, LOCK_EX)) {
flock(\$fp, LOCK_UN);
fclose(\$fp);
}
EOF
# run beep sequence if enabled
/usr/local/bin/beep.sh stop
#!/bin/sh #!/bin/sh
# shutdown rc scripts # invoke shared powerdown routines
/usr/local/etc/rc.opnsense stop . /usr/local/etc/rc.halt.common
/usr/local/etc/rc.backup_rrd
/usr/local/etc/rc.backup_dhcpleases
# wait for config lock to release
php -a >/dev/null << EOF
\$fp = fopen('/conf/config.xml', "w+");
if (flock(\$fp, LOCK_EX)) {
flock(\$fp, LOCK_UN);
fclose(\$fp);
}
EOF
# reboot the system
/sbin/shutdown -or now /sbin/shutdown -or now
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