diff --git a/ykval-common.php b/ykval-common.php index 0809861..98ce99a 100644 --- a/ykval-common.php +++ b/ykval-common.php @@ -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", diff --git a/ykval-synclib.php b/ykval-synclib.php index 29ece23..7822d04 100644 --- a/ykval-synclib.php +++ b/ykval-synclib.php @@ -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); } /* diff --git a/ykval-verify.php b/ykval-verify.php index a5a5944..6743840 100644 --- a/ykval-verify.php +++ b/ykval-verify.php @@ -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;