Added HTTP code check on “/api/v1/accounts/lookup” lookups

This commit is contained in:
pezcurrel 2024-07-28 09:33:59 +02:00
parent 77a1fbaf2f
commit 0ea1c7ede7

View file

@ -165,15 +165,20 @@ if ($errors=='' && $_GET['acctock']!='' && $_GET['host']!='') {
}
$acchostck=htmlentities($acchostck);
$http_response_header=null;
$httpcode=null;
$url=$_GET['host'].'/api/v1/accounts/lookup?acct='.urlencode($_GET['acctock']);
$hacctock=htmlentities($_GET['acctock']);
$hurl=htmlentities($url);
$res=@file_get_contents('https://'.$url,false,$context);
//echo preprint($http_response_header);
if (isset($http_response_header))
if (isset($http_response_header)) {
$httpcode=gethttpcode($http_response_header);
$rl=ckratelimit($http_response_header,'echofun',true,false);
}
if ($res===false) {
echo "<div class=\"error\">Error: could not connect to «{$hhost}».</div>\n";
} elseif (isset($httpcode) && $httpcode!='200') {
echo "<div class=\"error\">Error: «{$hurl}» returned an HTTP code that is different than «200»: <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/{$httpcode}\">{$httpcode}</a>.</div>\n";
} elseif (null===$res=@json_decode($res,true)) {
echo "<div class=\"error\">Error: «{$hurl}» returned data that could not be parsed as JSON (".json_last_error().': '.json_last_error_msg().").</div>\n";
} elseif (isset($res['error'])) {