API to resolve instances hostname to URL

This commit is contained in:
Bofh 2022-11-22 02:42:07 +01:00
parent 0a65457586
commit 5419192079
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
<?php chdir('../../../../') ?>
<?php require 'base.php' ?>
<?php
$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) {
apiresult([
'error' => 'Could not find /.well-known/webfinger URL in instance given XML'
]);
}
apiresult([
'instance' => 'https://'.parse_url($m[0], PHP_URL_HOST),
]);