Blame view
sources/apps/user_webfinger/webfinger.php
1.78 KB
|
42e4f8d60
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
<?php
if (!OCP\App::isEnabled("user_webfinger")) {
return;
}
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/xrd+json");
/**
* To include your app in the webfinger JSON, add a new script with file name
* 'webfinger.php' to /apps/yourapp/appinfo/, which prints out the XML parts
* to be included. That script can make use of the constants WF_USER (e. g.
* "user"), WF_ID (user
*
* @host) and WF_BASEURL (e. g. https://host/owncloud).
* An example could look like this:
*
* {
* "rel":"myProfile",
* "type":"text/html",
* "href":"<?php echo WF_BASEURL; ?>/apps/myApp/profile.php?user=<?php echo WF_USER; ?>"
* }
*
* but can also use complex database queries to generate the webfinger result
**/
$userName = '';
$hostName = '';
$request = strip_tags(urldecode($_GET['q']));
if ($_GET['q']) {
$reqParts = explode('@', $request);
if (count($reqParts) == 2) {
$userName = $reqParts[0];
$hostName = $reqParts[1];
}
}
if (substr($userName, 0, 5) == 'acct:') {
$userName = substr($userName, 5);
}
if ($userName == "") {
$id = "";
} else {
$id = $userName . '@' . $hostName;
}
if (isset($_SERVER['HTTPS'])) {
$baseAddress = 'https://';
} else {
$baseAddress = 'http://';
}
$baseAddress .= $_SERVER['SERVER_NAME'] . OC::$WEBROOT;
if (empty($id)) {
header("HTTP/1.0 400 Bad Request");
}
define('WF_USER', $userName);
define('WF_ID', $id);
define('WF_BASEURL', $baseAddress);
$apps = OC_Appconfig::getApps();
$links = array();
foreach ($apps as $app) {
if (OCP\App::isEnabled($app)) {
if (is_file(OC_App::getAppPath($app) . '/appinfo/webfinger.php')) {
ob_start();
require $app . '/appinfo/webfinger.php';
$link = trim(ob_get_clean());
if ($link) {
$links[] = $link;
}
}
}
}
echo "{\"links\":[";
echo implode(',', $links);
echo "]}";
|