Actions
Bug #351
closedVouchers backup
Start date:
02/11/2010
Due date:
% Done:
0%
Estimated time:
Plus Target Version:
Release Notes:
Affected Version:
2.0
Affected Architecture:
Description
Active vouchers are not written to the configuration file, after reboot/upgrade/powerfail can be re-used with an initial time.
/etc/rc.savevoucher is not marked executable, so that even minicron for storing vouchers is running, it is never launced.
But there is fatal bug in voucher_save_db_to_config() which causes pfsense crash due to an error in generated config.xml - active vouchers are named <0>, <1>,<2> etc. - not allowed in XML file.
Solution:
/* 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;
if (!isset($config['voucher']['enable']) || $config['voucher']['saveinterval'] == 0)
return; // no vouchers or don't want to save DB's
if (!is_subsystem_dirty('voucher'))
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();
$dbi = 1;
foreach($active_vouchers as $voucher => $line) {
list($timestamp,$minutes) = explode(",", $line);
$activent['voucher'] = $voucher;
$activent['timestamp'] = $timestamp;
$activent['minutes'] = $minutes;
$db['v' . sprintf("%03d", $dbi)] = $activent; // write <v001>, <v002>, ... instead of <0>, <1> (not allowed in XML file)
$dbi++;
}
$rollent['active'] = $db;
}
clear_subsystem_dirty('voucher');
unlock($voucherlck);
write_config();
return;
}
After this change it's safe to mark /etc/rc.savevoucher executable, config.xml is no more broken
Q: Is 1000 active vouchers per roll enough? If not, please replace sprintf("%03d",... with something else
Actions