Project

General

Profile

Actions

Bug #351

closed

Vouchers backup

Added by Jirka Dutka about 14 years ago. Updated about 9 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
Captive Portal
Target version:
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 #1

Updated by Ermal Luçi about 14 years ago

  • Status changed from New to Feedback

Committed.
There is no need for sprintf actually and this avoids the limit.

Thanks.

Actions #2

Updated by Chris Buechler about 14 years ago

Jirka - can you please test and report back if this fixes the issues reported?

Actions #3

Updated by Jirka Dutka about 14 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 :-)

Actions #4

Updated by Chris Buechler almost 14 years ago

  • Status changed from Feedback to Resolved
Actions #5

Updated by Kill Bill about 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.

https://forum.pfsense.org/index.php/topic,72418.0.html

Actions

Also available in: Atom PDF