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.

This commit is contained in:
Ermal 2014-02-24 14:57:04 +00:00
parent 846bedf994
commit 2c02c4d09a

View File

@ -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