Commit a9d160a7 authored by David Morley's avatar David Morley Committed by Armando Lüscher

curl all the calls in pull so timeouts work and it does not take so long.

parent 4212d85f
......@@ -94,28 +94,24 @@ foreach ($pods as $pod) {
// Default link to fetch node info.
$link = "https://{$domain}/nodeinfo/1.0";
if (($infos = @file_get_contents("https://{$domain}/.well-known/nodeinfo")) !== false) {
$info = json_decode($infos, true);
extract(_curl("https://{$domain}/.well-known/nodeinfo"));
$outputwellknown = $curl_body;
if ($outputwellknown !== false) {
$info = json_decode($outputwellknown, true);
$link = max($info['links'])['href'];
}
_debug('Nodeinfo link', $link);
extract(_curl($link));
$chss = curl_init();
curl_setopt($chss, CURLOPT_URL, $link);
curl_setopt($chss, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($chss, CURLOPT_TIMEOUT, 30);
curl_setopt($chss, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($chss, CURLOPT_CERTINFO, 1);
curl_setopt($chss, CURLOPT_CAINFO, c('cafullpath'));
$outputssl = curl_exec($chss);
$outputsslerror = curl_error($chss);
$info = curl_getinfo($chss, CURLINFO_CERTINFO);
$conntime = curl_getinfo($chss, CURLINFO_CONNECT_TIME);
$nstime = curl_getinfo($chss, CURLINFO_NAMELOOKUP_TIME);
$outputssl = $curl_body;
$outputsslerror = $curl_error;
$info = $curl_info;
$conntime = $curl_conntime;
$nstime = $curl_nstime;
$latency = $conntime - $nstime;
$sslexpire = $info[0]['Expire date'] ?? null;
curl_close($chss);
_debug('Nodeinfo output', $outputssl, true);
_debug('Nodeinfo output error', $outputsslerror, true);
......@@ -252,12 +248,14 @@ foreach ($pods as $pod) {
$d = new DOMDocument;
libxml_use_internal_errors(true);
$d->loadHTMLFile('https://' . $domain);
extract(_curl("https://{$domain}/"));
$outputbody = $curl_body;
($outputbody ? $d->loadHTML($outputbody) : $d->loadHTML('<html></html>'));
$body = $d->getElementsByTagName('html')->item(0);
if ($body) {
$ld = new Language;
$detectedlanguage = strtoupper(key($ld->detect($body->nodeValue)->bestResults()->close()));
$detectedlanguage = key($ld->detect($body->nodeValue)->bestResults()->close());
} else {
$score -= 1;
$detectedlanguage = null;
......@@ -448,3 +446,24 @@ function _debug($label, $var = null, $dump = false)
printf('%s: %s%s', $label, $output, $newline);
}
function _curl($url)
{
global $cafullpath;
$chss = curl_init();
curl_setopt($chss, CURLOPT_URL, $url);
curl_setopt($chss, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($chss, CURLOPT_TIMEOUT, 20);
curl_setopt($chss, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($chss, CURLOPT_CERTINFO, 1);
curl_setopt($chss, CURLOPT_CAINFO, $cafullpath);
return [
'curl_body' => curl_exec($chss),
'curl_error' => curl_error($chss),
'curl_info' => curl_getinfo($chss, CURLINFO_CERTINFO),
'curl_conntime' => curl_getinfo($chss, CURLINFO_CONNECT_TIME),
'curl_nstime' => curl_getinfo($chss, CURLINFO_NAMELOOKUP_TIME)
];
curl_close($chss);
}
......@@ -77,7 +77,7 @@ foreach ($pods as $pod) {
}
echo '<td>' . $pod['city'] . '</td>';
echo '<td>' . $pod['state'] . '</td>';
echo '<td>' . ($pod['detectedlanguage'] ?: '') . '</td>';
echo '<td>' . ($pod['detectedlanguage'] ? strtoupper($pod['detectedlanguage']) : '') . '</td>';
echo '<td class="text-truncate">';
$pod['service_facebook'] && print '<div class="smlogo smlogo-facebook" data-toggle="tooltip" title="Publish to Facebook"></div>';
$pod['service_twitter'] && print '<div class="smlogo smlogo-twitter" data-toggle="tooltip" title="Publish to Twitter"></div>';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment