1
0
mirror of https://github.com/Yubico/yubikey-val.git synced 2025-01-20 10:52:15 +01:00

Pass logger object to retrieveURLasync()

This commit is contained in:
Fredrik Thulin 2012-06-14 15:19:04 +02:00
parent 60bfa8ff1a
commit c8e9eb828f
3 changed files with 26 additions and 11 deletions

View File

@ -63,6 +63,21 @@ function debug() {
$ykval_common_log->log(LOG_DEBUG, $str);
}
function log_format() {
$str = "";
foreach (func_get_args() as $msg)
{
if (is_array($msg)) {
foreach($msg as $key => $value){
$str .= "$key=$value ";
}
} else {
$str .= $msg . " ";
}
}
return $str;
}
// Return eg. 2008-11-21T06:11:55Z0711
//
function getUTCTimeStamp() {
@ -117,13 +132,13 @@ function modhex2b64 ($modhex_str) {
// long as one of the URLs given work, data will be returned. If all
// URLs fail, data from some URL that did not match parameter $match
// (defaults to ^OK) is returned, or if all URLs failed, false.
function retrieveURLasync ($ident, $urls, $ans_req=1, $match="^OK", $returl=False, $timeout=10) {
function retrieveURLasync ($ident, $urls, $logger, $ans_req=1, $match="^OK", $returl=False, $timeout=10) {
$mh = curl_multi_init();
$ch = array();
foreach ($urls as $id => $url) {
$handle = curl_init();
debug($ident . " adding URL : " . $url);
$logger->log($ident . " adding URL : " . $url);
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_USERAGENT, "YK-VAL");
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
@ -144,16 +159,16 @@ function retrieveURLasync ($ident, $urls, $ans_req=1, $match="^OK", $returl=Fals
;
while ($info = curl_multi_info_read($mh)) {
debug ($ident . " curl multi info : ", $info);
$logger->log($ident . " curl multi info : ", $info);
if ($info['result'] == CURLE_OK) {
$str = curl_multi_getcontent($info['handle']);
debug($ident . " curl multi content : " . $str);
$logger->log($ident . " curl multi content : " . $str);
if (preg_match("/".$match."/", $str)) {
debug($ident . " response matches " . $match);
$logger->log($ident . " response matches " . $match);
$error = curl_error ($info['handle']);
$errno = curl_errno ($info['handle']);
$cinfo = curl_getinfo ($info['handle']);
debug($ident . " errno/error: " . $errno . "/" . $error, $cinfo);
$logger->log($ident . " errno/error: " . $errno . "/" . $error, $cinfo);
$ans_count++;
if ($returl) $ans_arr[]="url=" . $cinfo['url'] . "\n" . $str;
else $ans_arr[]=$str;
@ -198,20 +213,20 @@ function retrieveURLsimple ($url, $match="^OK") {
}
// $otp: A yubikey OTP
function KSMdecryptOTP($urls) {
function KSMdecryptOTP($urls, $logger) {
$ret = array();
if (!is_array($urls)) {
$response = retrieveURLsimple ($urls);
} elseif (count($urls) == 1) {
$response = retrieveURLsimple ($urls[0]);
} else {
$response = retrieveURLasync ("YK-KSM", $urls, $ans_req=1, $match="^OK", $returl=False, $timeout=10);
$response = retrieveURLasync ("YK-KSM", $urls, $logger, $ans_req=1, $match="^OK", $returl=False, $timeout=10);
if (is_array($response)) {
$response = $response[0];
}
}
if ($response) {
debug("YK-KSM response: " . $response);
$logger->log(LOG_DEBUG, log_format("YK-KSM response: ", $response));
}
if (sscanf ($response,
"OK counter=%04x low=%04x high=%02x use=%02x",

View File

@ -518,7 +518,7 @@ class SyncLib
function retrieveURLasync_wrap ($urls, $ans_req=1, $timeout=1.0)
{
return retrieveURLasync("YK-VAL sync", $urls, $ans_req, $match="status=OK", $returl=True, $timeout);
return retrieveURLasync("YK-VAL sync", $urls, $this->myLog, $ans_req, $match="status=OK", $returl=True, $timeout);
}
/*

View File

@ -213,7 +213,7 @@ if (!is_array($urls)) {
//// Decode OTP from input
//
$otpinfo = KSMdecryptOTP($urls);
$otpinfo = KSMdecryptOTP($urls, $myLog);
if (!is_array($otpinfo)) {
sendResp(S_BAD_OTP, $context, $apiKey);
exit;