soselo/api/v1/network/resolve-instance/mod.php

24 lines
597 B
PHP

<?php
$_ = function() {
$hostname = trim($_GET['hostname']);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://$hostname/.well-known/host-meta");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($ch);
curl_close($ch);
preg_match('/(?<=")[^"]+\/.well-known\/webfinger/', $output, $m);
if (count($m) === 0) {
return apiresult([
'error' => 'Could not find /.well-known/webfinger URL in instance given XML'
]);
}
return apiresult([
'instance' => 'https://'.parse_url($m[0], PHP_URL_HOST),
]);
};
$_();