Bug #351
closedVouchers backup
0%
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
Updated by Ermal Luçi almost 15 years ago
- Status changed from New to Feedback
Committed.
There is no need for sprintf actually and this avoids the limit.
Thanks.
Updated by Chris Buechler almost 15 years ago
Jirka - can you please test and report back if this fixes the issues reported?
Updated by Jirka Dutka almost 15 years ago
Chris Buechler wrote:
Jirka - can you please test and report back if this fixes the issues reported?
For me vouchers backup works fine, used vouchers are written into config.xml immediately after the first use (vouchers save interval set to 5 minutes). But so far I didn't try vouchers recovery after restart (already in production use - lack of courage :-)
Updated by Chris Buechler over 14 years ago
- Status changed from Feedback to Resolved
Updated by Kill Bill over 9 years ago
Sorry to revive this, but this has been totally no-op for years due to some completely broken commits. Also kindly see Bug #3128.