Commit a9d160a7 authored by dmorley's avatar dmorley Committed by noplanman
Browse files

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) { ...@@ -94,28 +94,24 @@ foreach ($pods as $pod) {
// Default link to fetch node info. // Default link to fetch node info.
$link = "https://{$domain}/nodeinfo/1.0"; $link = "https://{$domain}/nodeinfo/1.0";
if (($infos = @file_get_contents("https://{$domain}/.well-known/nodeinfo")) !== false) { extract(_curl("https://{$domain}/.well-known/nodeinfo"));
$info = json_decode($infos, true); $outputwellknown = $curl_body;
if ($outputwellknown !== false) {
$info = json_decode($outputwellknown, true);
$link = max($info['links'])['href']; $link = max($info['links'])['href'];
} }
_debug('Nodeinfo link', $link); _debug('Nodeinfo link', $link);
extract(_curl($link));
$chss = curl_init(); $outputssl = $curl_body;
curl_setopt($chss, CURLOPT_URL, $link); $outputsslerror = $curl_error;
curl_setopt($chss, CURLOPT_CONNECTTIMEOUT, 10); $info = $curl_info;
curl_setopt($chss, CURLOPT_TIMEOUT, 30); $conntime = $curl_conntime;
curl_setopt($chss, CURLOPT_RETURNTRANSFER, 1); $nstime = $curl_nstime;
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);
$latency = $conntime - $nstime; $latency = $conntime - $nstime;
$sslexpire = $info[0]['Expire date'] ?? null; $sslexpire = $info[0]['Expire date'] ?? null;
curl_close($chss);
_debug('Nodeinfo output', $outputssl, true); _debug('Nodeinfo output', $outputssl, true);
_debug('Nodeinfo output error', $outputsslerror, true); _debug('Nodeinfo output error', $outputsslerror, true);
...@@ -252,12 +248,14 @@ foreach ($pods as $pod) { ...@@ -252,12 +248,14 @@ foreach ($pods as $pod) {
$d = new DOMDocument; $d = new DOMDocument;
libxml_use_internal_errors(true); 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); $body = $d->getElementsByTagName('html')->item(0);
if ($body) { if ($body) {
$ld = new Language; $ld = new Language;
$detectedlanguage = strtoupper(key($ld->detect($body->nodeValue)->bestResults()->close())); $detectedlanguage = key($ld->detect($body->nodeValue)->bestResults()->close());
} else { } else {
$score -= 1; $score -= 1;
$detectedlanguage = null; $detectedlanguage = null;
...@@ -448,3 +446,24 @@ function _debug($label, $var = null, $dump = false) ...@@ -448,3 +446,24 @@ function _debug($label, $var = null, $dump = false)
printf('%s: %s%s', $label, $output, $newline); 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) { ...@@ -77,7 +77,7 @@ foreach ($pods as $pod) {
} }
echo '<td>' . $pod['city'] . '</td>'; echo '<td>' . $pod['city'] . '</td>';
echo '<td>' . $pod['state'] . '</td>'; echo '<td>' . $pod['state'] . '</td>';
echo '<td>' . ($pod['detectedlanguage'] ?: '') . '</td>'; echo '<td>' . ($pod['detectedlanguage'] ? strtoupper($pod['detectedlanguage']) : '') . '</td>';
echo '<td class="text-truncate">'; echo '<td class="text-truncate">';
$pod['service_facebook'] && print '<div class="smlogo smlogo-facebook" data-toggle="tooltip" title="Publish to Facebook"></div>'; $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>'; $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