API to resolve instances hostname to URL
This commit is contained in:
parent
0a65457586
commit
5419192079
|
@ -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),
|
||||
]);
|
Loading…
Reference in New Issue