diff --git a/db/pull.php b/db/pull.php index faf18fc84b07b8f03240c69645e7bb4fb6614c79..d339d88ad59e20e9eb92d706c2498c35412bc306 100644 --- a/db/pull.php +++ b/db/pull.php @@ -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('')); $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); +} diff --git a/tabledata.php b/tabledata.php index d0362d662c8efc455d93075e8da8a23bf1a6e903..6e59eb71a2c2b78f163a2418859a3887456990cc 100644 --- a/tabledata.php +++ b/tabledata.php @@ -77,7 +77,7 @@ foreach ($pods as $pod) { } echo '' . $pod['city'] . ''; echo '' . $pod['state'] . ''; - echo '' . ($pod['detectedlanguage'] ?: '') . ''; + echo '' . ($pod['detectedlanguage'] ? strtoupper($pod['detectedlanguage']) : '') . ''; echo ''; $pod['service_facebook'] && print ''; $pod['service_twitter'] && print '';