mirror of
https://github.com/Yubico/yubikey-val.git
synced 2025-01-20 19:52:15 +01:00
Pass logger object to retrieveURLasync()
This commit is contained in:
parent
60bfa8ff1a
commit
c8e9eb828f
@ -63,6 +63,21 @@ function debug() {
|
|||||||
$ykval_common_log->log(LOG_DEBUG, $str);
|
$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
|
// Return eg. 2008-11-21T06:11:55Z0711
|
||||||
//
|
//
|
||||||
function getUTCTimeStamp() {
|
function getUTCTimeStamp() {
|
||||||
@ -117,13 +132,13 @@ function modhex2b64 ($modhex_str) {
|
|||||||
// long as one of the URLs given work, data will be returned. If all
|
// 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
|
// URLs fail, data from some URL that did not match parameter $match
|
||||||
// (defaults to ^OK) is returned, or if all URLs failed, false.
|
// (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();
|
$mh = curl_multi_init();
|
||||||
|
|
||||||
$ch = array();
|
$ch = array();
|
||||||
foreach ($urls as $id => $url) {
|
foreach ($urls as $id => $url) {
|
||||||
$handle = curl_init();
|
$handle = curl_init();
|
||||||
debug($ident . " adding URL : " . $url);
|
$logger->log($ident . " adding URL : " . $url);
|
||||||
curl_setopt($handle, CURLOPT_URL, $url);
|
curl_setopt($handle, CURLOPT_URL, $url);
|
||||||
curl_setopt($handle, CURLOPT_USERAGENT, "YK-VAL");
|
curl_setopt($handle, CURLOPT_USERAGENT, "YK-VAL");
|
||||||
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
|
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)) {
|
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) {
|
if ($info['result'] == CURLE_OK) {
|
||||||
$str = curl_multi_getcontent($info['handle']);
|
$str = curl_multi_getcontent($info['handle']);
|
||||||
debug($ident . " curl multi content : " . $str);
|
$logger->log($ident . " curl multi content : " . $str);
|
||||||
if (preg_match("/".$match."/", $str)) {
|
if (preg_match("/".$match."/", $str)) {
|
||||||
debug($ident . " response matches " . $match);
|
$logger->log($ident . " response matches " . $match);
|
||||||
$error = curl_error ($info['handle']);
|
$error = curl_error ($info['handle']);
|
||||||
$errno = curl_errno ($info['handle']);
|
$errno = curl_errno ($info['handle']);
|
||||||
$cinfo = curl_getinfo ($info['handle']);
|
$cinfo = curl_getinfo ($info['handle']);
|
||||||
debug($ident . " errno/error: " . $errno . "/" . $error, $cinfo);
|
$logger->log($ident . " errno/error: " . $errno . "/" . $error, $cinfo);
|
||||||
$ans_count++;
|
$ans_count++;
|
||||||
if ($returl) $ans_arr[]="url=" . $cinfo['url'] . "\n" . $str;
|
if ($returl) $ans_arr[]="url=" . $cinfo['url'] . "\n" . $str;
|
||||||
else $ans_arr[]=$str;
|
else $ans_arr[]=$str;
|
||||||
@ -198,20 +213,20 @@ function retrieveURLsimple ($url, $match="^OK") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// $otp: A yubikey OTP
|
// $otp: A yubikey OTP
|
||||||
function KSMdecryptOTP($urls) {
|
function KSMdecryptOTP($urls, $logger) {
|
||||||
$ret = array();
|
$ret = array();
|
||||||
if (!is_array($urls)) {
|
if (!is_array($urls)) {
|
||||||
$response = retrieveURLsimple ($urls);
|
$response = retrieveURLsimple ($urls);
|
||||||
} elseif (count($urls) == 1) {
|
} elseif (count($urls) == 1) {
|
||||||
$response = retrieveURLsimple ($urls[0]);
|
$response = retrieveURLsimple ($urls[0]);
|
||||||
} else {
|
} 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)) {
|
if (is_array($response)) {
|
||||||
$response = $response[0];
|
$response = $response[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($response) {
|
if ($response) {
|
||||||
debug("YK-KSM response: " . $response);
|
$logger->log(LOG_DEBUG, log_format("YK-KSM response: ", $response));
|
||||||
}
|
}
|
||||||
if (sscanf ($response,
|
if (sscanf ($response,
|
||||||
"OK counter=%04x low=%04x high=%02x use=%02x",
|
"OK counter=%04x low=%04x high=%02x use=%02x",
|
||||||
|
@ -518,7 +518,7 @@ class SyncLib
|
|||||||
|
|
||||||
function retrieveURLasync_wrap ($urls, $ans_req=1, $timeout=1.0)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -213,7 +213,7 @@ if (!is_array($urls)) {
|
|||||||
|
|
||||||
//// Decode OTP from input
|
//// Decode OTP from input
|
||||||
//
|
//
|
||||||
$otpinfo = KSMdecryptOTP($urls);
|
$otpinfo = KSMdecryptOTP($urls, $myLog);
|
||||||
if (!is_array($otpinfo)) {
|
if (!is_array($otpinfo)) {
|
||||||
sendResp(S_BAD_OTP, $context, $apiKey);
|
sendResp(S_BAD_OTP, $context, $apiKey);
|
||||||
exit;
|
exit;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user