mirror of
https://github.com/Yubico/yubikey-val.git
synced 2025-04-09 20:53:50 +02:00
Move function into ykval-common.php
This commit is contained in:
parent
71442e7fd6
commit
99613cd5f4
@ -324,3 +324,61 @@ if (function_exists('hash_equals') === FALSE)
|
|||||||
return (0 === $result);
|
return (0 === $result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the total time taken to receive a response from a URL.
|
||||||
|
*
|
||||||
|
* @argument $url string
|
||||||
|
* @argument $ipresolve string whatever|ipv4|ipv6
|
||||||
|
*
|
||||||
|
* @return float|bool seconds or false on failure
|
||||||
|
*/
|
||||||
|
function total_time ($url, $ipresolve = 'whatever')
|
||||||
|
{
|
||||||
|
switch ($ipresolve)
|
||||||
|
{
|
||||||
|
case 'whatever':
|
||||||
|
$ipresolve = CURL_IPRESOLVE_WHATEVER;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'ipv4':
|
||||||
|
$ipresolve = CURL_IPRESOLVE_V4;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'ipv6':
|
||||||
|
$ipresolve = CURL_IPRESOLVE_V6;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$opts = array(
|
||||||
|
CURLOPT_URL => $url,
|
||||||
|
CURLOPT_IPRESOLVE => $ipresolve,
|
||||||
|
CURLOPT_TIMEOUT => 3,
|
||||||
|
CURLOPT_FORBID_REUSE => TRUE,
|
||||||
|
CURLOPT_FRESH_CONNECT => TRUE,
|
||||||
|
CURLOPT_RETURNTRANSFER => TRUE,
|
||||||
|
CURLOPT_USERAGENT => 'ykval-munin-vallatency/1.0',
|
||||||
|
);
|
||||||
|
|
||||||
|
if (($ch = curl_init()) === FALSE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (curl_setopt_array($ch, $opts) === FALSE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// we don't care about the actual response
|
||||||
|
if (curl_exec($ch) === FALSE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$total_time = curl_getinfo($ch, CURLINFO_TOTAL_TIME);
|
||||||
|
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if (is_float($total_time) === FALSE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return $total_time;
|
||||||
|
}
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
set_include_path(get_include_path() . PATH_SEPARATOR . "/etc/yubico/val:/usr/share/yubikey-val");
|
set_include_path(get_include_path() . PATH_SEPARATOR . "/etc/yubico/val:/usr/share/yubikey-val");
|
||||||
|
|
||||||
require_once 'ykval-config.php';
|
require_once 'ykval-config.php';
|
||||||
|
require_once 'ykval-common.php';
|
||||||
|
|
||||||
function url2shortname ($url)
|
function url2shortname ($url)
|
||||||
{
|
{
|
||||||
@ -91,61 +92,3 @@ foreach ($urls as $url)
|
|||||||
echo "$ipv${shortname}_avgwait.value $total_time\n";
|
echo "$ipv${shortname}_avgwait.value $total_time\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the total time taken to receive a response from a URL.
|
|
||||||
*
|
|
||||||
* @argument $url string
|
|
||||||
* @argument $ipresolve string whatever|ipv4|ipv6
|
|
||||||
*
|
|
||||||
* @return float|bool seconds or false on failure
|
|
||||||
*/
|
|
||||||
function total_time ($url, $ipresolve = 'whatever')
|
|
||||||
{
|
|
||||||
switch ($ipresolve)
|
|
||||||
{
|
|
||||||
case 'whatever':
|
|
||||||
$ipresolve = CURL_IPRESOLVE_WHATEVER;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'ipv4':
|
|
||||||
$ipresolve = CURL_IPRESOLVE_V4;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'ipv6':
|
|
||||||
$ipresolve = CURL_IPRESOLVE_V6;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$opts = array(
|
|
||||||
CURLOPT_URL => $url,
|
|
||||||
CURLOPT_IPRESOLVE => $ipresolve,
|
|
||||||
CURLOPT_TIMEOUT => 3,
|
|
||||||
CURLOPT_FORBID_REUSE => TRUE,
|
|
||||||
CURLOPT_FRESH_CONNECT => TRUE,
|
|
||||||
CURLOPT_RETURNTRANSFER => TRUE,
|
|
||||||
CURLOPT_USERAGENT => 'ykval-munin-vallatency/1.0',
|
|
||||||
);
|
|
||||||
|
|
||||||
if (($ch = curl_init()) === FALSE)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (curl_setopt_array($ch, $opts) === FALSE)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// we don't care about the actual response
|
|
||||||
if (curl_exec($ch) === FALSE)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
$total_time = curl_getinfo($ch, CURLINFO_TOTAL_TIME);
|
|
||||||
|
|
||||||
curl_close($ch);
|
|
||||||
|
|
||||||
if (is_float($total_time) === FALSE)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return $total_time;
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user