From b36c115f7062e5f5f280bf411be16ee07bed9908 Mon Sep 17 00:00:00 2001 From: Ermal Date: Wed, 6 Feb 2013 19:38:46 +0000 Subject: When going through the xmlrpc calls do not hold the lock since deadlock might occur. --- etc/inc/voucher.inc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'etc') diff --git a/etc/inc/voucher.inc b/etc/inc/voucher.inc index 760bc15..a1c5841 100644 --- a/etc/inc/voucher.inc +++ b/etc/inc/voucher.inc @@ -144,9 +144,10 @@ function xmlrpc_sync_used_voucher($voucher_received, $syncip, $port, $password, $method = 'pfsense.exec_php'; $execcmd = <<value()); + if (!is_array($config['voucher'])) + $config['voucher'] = array(); if (is_array($toreturn['voucher']) && (count($toreturn['voucher']['roll']) <> count($config['voucher']['roll']))) { $config['voucher']['roll'] = $toreturn['voucher']['roll']; write_config("Captive Portal Voucher database synchronized with {$url}"); @@ -304,8 +307,6 @@ function voucher_auth($voucher_received, $test = 0) { if (!isset($config['voucher']['enable'])) return 0; - $voucherlck = lock('voucher', LOCK_EX); - // XMLRPC Call over to the master Voucher node if(!empty($config['voucher']['vouchersyncdbip'])) { $syncip = $config['voucher']['vouchersyncdbip']; @@ -315,6 +316,8 @@ function voucher_auth($voucher_received, $test = 0) { $remote_time_used = xmlrpc_sync_used_voucher($voucher_received, $syncip, $syncport, $syncpass, $vouchersyncusername); } + $voucherlck = lock('voucher', LOCK_EX); + // read rolls into assoc array with rollid as key and minutes as value $tickets_per_roll = array(); $minutes_per_roll = array(); @@ -457,6 +460,9 @@ function voucher_auth($voucher_received, $test = 0) { function voucher_configure($sync = false) { global $config, $g; + if (!is_array($config['voucher'])) + return; + if (!isset($config['voucher']['enable'])) return 0; @@ -502,9 +508,8 @@ function voucher_configure($sync = false) { voucher_write_used_db($roll, $rollent['used']); $minutes = $rollent['minutes']; $active_vouchers = array(); - $a_active = &$rollent['active']; - if (is_array($a_active)) { - foreach ($a_active as $activent) { + if (is_array($rollent['active'])) { + foreach ($rollent['active'] as $activent) { $voucher = $activent['voucher']; $timestamp = $activent['timestamp']; $minutes = $activent['minutes']; @@ -546,7 +551,7 @@ function voucher_read_active_db($roll) { $active = array(); $dirty = 0; - $file = "{$g['vardb_path']}/voucher_active_$roll.db"; + $file = "{$g['vardb_path']}/voucher_active_{$roll}.db"; if (file_exists($file)) { $fd = fopen($file, "r"); if ($fd) { -- cgit v1.1