From c94affd1d9b6930a71054b88c8a1d7057353d4ff Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Mon, 17 May 2010 13:08:48 +0000 Subject: [PATCH] When there is only one KSM, use more portable code without async. Patch from arte42.ripe in issue #7. --- NEWS | 3 +++ ykval-common.php | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index d790129..9e17cf7 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,9 @@ * When number of sync servers equals zero, set sync result to success. Patch from arte42.ripe in issue #7. + * When there is only one KSM, use more portable code without async. + Patch from arte42.ripe in issue #7. + * Add files COPYING and AUTHORS. * Version 2.4 released 2010-03-16 diff --git a/ykval-common.php b/ykval-common.php index e794149..76073b9 100644 --- a/ykval-common.php +++ b/ykval-common.php @@ -195,10 +195,25 @@ function retrieveURLasync ($urls, $ans_req=1, $match="^OK", $returl=False) { return $str; } +function retrieveURLsimple ($url, $match="^OK") { + foreach (file($url) as $line) { + if (preg_match("/".$match."/", $line)) { + return $line; + } + } + return false; +} + // $otp: A yubikey OTP function KSMdecryptOTP($urls) { $ret = array(); - $response = retrieveURLasync ($urls); + if (!is_array($urls)) { + $response = retrieveURLsimple ($urls); + } elseif (count($urls) == 1) { + $response = retrieveURLsimple ($urls[0]); + } else { + $response = retrieveURLasync ($urls); + } if ($response) { debug("YK-KSM response: " . $response); }