From 2c02c4d09aac8186e739cc9fe08afcaba91dc237 Mon Sep 17 00:00:00 2001 From: Ermal Date: Mon, 24 Feb 2014 14:57:04 +0000 Subject: [PATCH] Properly detect when there are issues with communicating with syncip and to use the local DB for this. Otherwise detect if the remote says the voucher is not valid say its not valid. --- etc/inc/voucher.inc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/etc/inc/voucher.inc b/etc/inc/voucher.inc index 4b8398cacd..695857d833 100644 --- a/etc/inc/voucher.inc +++ b/etc/inc/voucher.inc @@ -188,24 +188,26 @@ EOF; $error = "A communications error occurred while attempting CaptivePortalVoucherSync XMLRPC sync with {$url}:{$port} (pfsense.exec_php)."; log_error($error); file_notice("CaptivePortalVoucherSync", $error, "Communications error occurred", ""); - return 0; // $timeleft + return null; // $timeleft } elseif($resp->faultCode()) { $error = "An error code was received while attempting CaptivePortalVoucherSync XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString(); log_error($error); file_notice("CaptivePortalVoucherSync", $error, "Error code received", ""); - return 0; // $timeleft + return null; // $timeleft } else { log_error("CaptivePortalVoucherSync XMLRPC reload data success with {$url}:{$port} (pfsense.exec_php)."); } $toreturn = XML_RPC_Decode($resp->value()); if (!is_array($config['voucher'])) $config['voucher'] = array(); + if (is_array($toreturn['voucher']) && (count($toreturn['voucher']['roll']) <> count($config['voucher'][$cpzone]['roll']))) { $config['voucher'][$cpzone]['roll'] = $toreturn['voucher']['roll']; write_config("Captive Portal Voucher database synchronized with {$url}"); voucher_configure_zone(true); unset($toreturn['voucher']); - } + } else if (!isset($toreturn['timeleft'])) + return null; return $toreturn['timeleft']; } @@ -437,9 +439,12 @@ function voucher_auth($voucher_received, $test = 0) { } // If we did a XMLRPC sync earlier check the timeleft - if (!empty($config['voucher'][$cpzone]['vouchersyncdbip'])) - if($remote_time_used < $total_minutes) + if (!empty($config['voucher'][$cpzone]['vouchersyncdbip'])) { + if (!is_null($remote_time_used)) + $total_minutes = $remote_time_used; + else if ($remote_time_used < $total_minutes) $total_minutes -= $remote_time_used; + } // All given vouchers were valid and this isn't simply a test. // Write back the used DB's