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,84 +274,89 @@ function voucher_configure($sync = false) ...@@ -274,84 +274,89 @@ function voucher_configure($sync = false)
{ {
global $config, $cpzone; global $config, $cpzone;
if (is_array($config['voucher'])) { $ret = true;
foreach ($config['voucher'] as $voucherzone => $vcfg) {
if (file_exists("/var/run/booting")) if (!is_array($config['voucher'])) {
echo gettext("Enabling voucher support... "); return $ret;
$cpzone = $voucherzone; }
$error = voucher_configure_zone($sync);
if (file_exists("/var/run/booting")) { foreach ($config['voucher'] as $voucherzone => $vcfg) {
if ($error) $cpzone = $voucherzone;
echo "error\n"; $error = voucher_configure_zone($sync);
else if ($error) {
echo "done\n"; $ret = false;
}
} }
} }
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);
/* write public key used to verify vouchers */ /* write public key used to verify vouchers */
$pubkey = base64_decode($config['voucher'][$cpzone]['publickey']); $pubkey = base64_decode($config['voucher'][$cpzone]['publickey']);
$fd = fopen("{$g['varetc_path']}/voucher_{$cpzone}.public", "w"); $fd = fopen("{$g['varetc_path']}/voucher_{$cpzone}.public", "w");
if (!$fd) { if (!$fd) {
captiveportal_syslog("Voucher error: cannot write voucher.public\n"); captiveportal_syslog("Voucher error: cannot write voucher.public\n");
unlock($voucherlck); unlock($voucherlck);
return 1; return 1;
} }
fwrite($fd, $pubkey); fwrite($fd, $pubkey);
fclose($fd); fclose($fd);
@chmod("{$g['varetc_path']}/voucher_{$cpzone}.public", 0600); @chmod("{$g['varetc_path']}/voucher_{$cpzone}.public", 0600);
/* 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;
} }
fwrite($fd, "{$config['voucher'][$cpzone]['rollbits']},{$config['voucher'][$cpzone]['ticketbits']},{$config['voucher'][$cpzone]['checksumbits']},{$config['voucher'][$cpzone]['magic']},{$config['voucher'][$cpzone]['charset']}\n"); fwrite($fd, "{$config['voucher'][$cpzone]['rollbits']},{$config['voucher'][$cpzone]['ticketbits']},{$config['voucher'][$cpzone]['checksumbits']},{$config['voucher'][$cpzone]['magic']},{$config['voucher'][$cpzone]['charset']}\n");
fclose($fd); fclose($fd);
@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']; $active_vouchers = array();
$active_vouchers = array(); $a_active = &$rollent['active'];
$a_active = &$rollent['active']; if (is_array($a_active)) {
if (is_array($a_active)) { foreach ($a_active as $activent) {
foreach ($a_active as $activent) { $voucher = $activent['voucher'];
$voucher = $activent['voucher']; $timestamp = $activent['timestamp'];
$timestamp = $activent['timestamp']; $minutes = $activent['minutes'];
$minutes = $activent['minutes']; // its tempting to check for expired timestamps, but during
// its tempting to check for expired timestamps, but during // bootup, we most likely don't have the correct time time.
// bootup, we most likely don't have the correct time time. $active_vouchers[$voucher] = "$timestamp,$minutes";
$active_vouchers[$voucher] = "$timestamp,$minutes"; }
} }
}
voucher_write_active_db($roll, $active_vouchers); voucher_write_active_db($roll, $active_vouchers);
} }
unlock($voucherlck); unlock($voucherlck);
} }
return 0; return 0;
} }
......
...@@ -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