Commit b2653d0e authored by Franco Fichtner's avatar Franco Fichtner

voucher: try to pin down where boot import fails; style update while at it

parent 14b3fa5c
...@@ -274,30 +274,30 @@ function voucher_configure($sync = false) ...@@ -274,30 +274,30 @@ function voucher_configure($sync = false)
{ {
global $config, $cpzone; global $config, $cpzone;
if (is_array($config['voucher'])) { $ret = true;
if (!is_array($config['voucher'])) {
return $ret;
}
foreach ($config['voucher'] as $voucherzone => $vcfg) { foreach ($config['voucher'] as $voucherzone => $vcfg) {
if (file_exists("/var/run/booting"))
echo gettext("Enabling voucher support... ");
$cpzone = $voucherzone; $cpzone = $voucherzone;
$error = voucher_configure_zone($sync); $error = voucher_configure_zone($sync);
if (file_exists("/var/run/booting")) { if ($error) {
if ($error) $ret = false;
echo "error\n";
else
echo "done\n";
}
} }
} }
return $ret;
} }
function voucher_configure_zone($sync = false) { function voucher_configure_zone($sync = false)
{
global $config, $g, $cpzone; global $config, $g, $cpzone;
if (!isset($config['voucher'][$cpzone]['enable'])) if (!isset($config['voucher'][$cpzone]['enable'])) {
return 0; return 0;
}
if ($sync == true)
captiveportal_syslog("Writing voucher db from sync data...");
$voucherlck = lock("voucher{$cpzone}", LOCK_EX); $voucherlck = lock("voucher{$cpzone}", LOCK_EX);
...@@ -316,7 +316,7 @@ function voucher_configure_zone($sync = false) { ...@@ -316,7 +316,7 @@ function voucher_configure_zone($sync = false) {
/* write config file used by voucher binary to decode vouchers */ /* write config file used by voucher binary to decode vouchers */
$fd = fopen("{$g['varetc_path']}/voucher_{$cpzone}.cfg", "w"); $fd = fopen("{$g['varetc_path']}/voucher_{$cpzone}.cfg", "w");
if (!$fd) { if (!$fd) {
printf(gettext("Error: cannot write voucher.cfg") . "\n"); captiveportal_syslog(gettext("Error: cannot write voucher.cfg") . "\n");
unlock($voucherlck); unlock($voucherlck);
return 1; return 1;
} }
...@@ -325,13 +325,17 @@ function voucher_configure_zone($sync = false) { ...@@ -325,13 +325,17 @@ function voucher_configure_zone($sync = false) {
@chmod("{$g['varetc_path']}/voucher_{$cpzone}.cfg", 0600); @chmod("{$g['varetc_path']}/voucher_{$cpzone}.cfg", 0600);
unlock($voucherlck); unlock($voucherlck);
if ((file_exists("/var/run/booting") || $sync == true) && is_array($config['voucher'][$cpzone]['roll'])) { if (!$sync) {
return 0;
}
captiveportal_syslog('Writing voucher db from sync data...');
if (isset($config['voucher'][$cpzone]['roll'])) {
$voucherlck = lock("voucher{$cpzone}", LOCK_EX); $voucherlck = lock("voucher{$cpzone}", LOCK_EX);
// create active and used DB per roll on ramdisk from config // create active and used DB per roll on ramdisk from config
foreach ($config['voucher'][$cpzone]['roll'] as $rollent) { foreach ($config['voucher'][$cpzone]['roll'] as $rollent) {
$roll = $rollent['number']; $roll = $rollent['number'];
voucher_write_used_db($roll, $rollent['used']); voucher_write_used_db($roll, $rollent['used']);
$minutes = $rollent['minutes']; $minutes = $rollent['minutes'];
...@@ -347,6 +351,7 @@ function voucher_configure_zone($sync = false) { ...@@ -347,6 +351,7 @@ function voucher_configure_zone($sync = false) {
$active_vouchers[$voucher] = "$timestamp,$minutes"; $active_vouchers[$voucher] = "$timestamp,$minutes";
} }
} }
voucher_write_active_db($roll, $active_vouchers); voucher_write_active_db($roll, $active_vouchers);
} }
......
...@@ -294,12 +294,12 @@ filter_configure_sync(); ...@@ -294,12 +294,12 @@ filter_configure_sync();
/* setup pppoe and pptp */ /* setup pppoe and pptp */
vpn_setup(); vpn_setup();
/* start Voucher support */
echo 'Enabling voucher support...' . (voucher_configure(true) ? 'done.' : 'failed.');
/* start the captive portal */ /* start the captive portal */
captiveportal_configure(); captiveportal_configure();
/* start Voucher support */
voucher_configure();
/* start IPsec tunnels */ /* start IPsec tunnels */
$ipsec_dynamic_hosts = vpn_ipsec_configure(); $ipsec_dynamic_hosts = vpn_ipsec_configure();
......
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