server/apps/user_webfinger/webfinger.php

69 lines
1.9 KiB
PHP
Raw Normal View History

2011-09-11 22:12:34 +00:00
<?php
2012-03-31 00:42:41 +00:00
header("Access-Control-Allow-Origin: *");
2012-05-11 13:26:45 +00:00
header("Content-Type: application/xrd+json");
2012-03-31 00:42:41 +00:00
/**
* To include your app in the webfinger XML, 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).
2012-03-31 00:42:41 +00:00
* An example could look like this:
*
* <Link
* rel="myProfile"
* type="text/html"
* href="<?php echo WF_BASEURL; ?>/apps/myApp/profile.php?user=<?php echo WF_USER; ?>">
2012-03-31 00:42:41 +00:00
* </Link>
*
'* but can also use complex database queries to generate the webfinger result
**/
// calculate the documentroot
// modified version of the one in lib/base.php that takes the .well-known symlink into account
2012-03-31 00:42:41 +00:00
/*$DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']);
$SERVERROOT=str_replace("\\",'/',dirname(dirname(dirname(dirname(__FILE__)))));
$SUBURI=substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen($SERVERROOT));
$WEBROOT=substr($SUBURI,0,-34);
2012-03-31 00:42:41 +00:00
*/
2011-09-11 22:12:34 +00:00
$userName = '';
$hostName = '';
2012-05-07 07:26:54 +00:00
$request = strip_tags(urldecode($_GET['q']));
2011-09-11 22:12:34 +00:00
if($_GET['q']) {
$reqParts = explode('@', $request);
if(count($reqParts)==2) {
2012-05-07 07:51:37 +00:00
$userName = $reqParts[0];
$hostName = $reqParts[1];
}
2011-09-11 22:12:34 +00:00
}
if(substr($userName, 0, 5) == 'acct:') {
$userName = substr($userName, 5);
}
if($userName == "") {
$id = "";
} else {
$id = $userName . '@' . $hostName;
}
if(isset($_SERVER['HTTPS'])) {
2012-03-31 00:42:41 +00:00
$baseAddress = 'https://';
} else {
2012-03-31 00:42:41 +00:00
$baseAddress = 'http://';
}
2012-03-31 00:42:41 +00:00
$baseAddress .= $_SERVER['SERVER_NAME'].OC::$WEBROOT;
2012-05-07 09:15:24 +00:00
if(empty($id)) {
header("HTTP/1.0 400 Bad Request");
}
2012-03-31 00:42:41 +00:00
define('WF_USER', $userName);
define('WF_ID', $id);
define('WF_BASEURL', $baseAddress);
2012-05-11 13:26:45 +00:00
echo "{\"links\":[";
2012-03-31 00:42:41 +00:00
$apps = OC_Appconfig::getApps();
foreach($apps as $app) {
2012-05-01 22:50:26 +00:00
if(OCP\App::isEnabled($app)) {
2012-03-31 00:42:41 +00:00
if(is_file(OC::$APPSROOT . '/apps/' . $app . '/appinfo/webfinger.php')) {
require($app . '/appinfo/webfinger.php');
}
}
}
2012-05-11 13:26:45 +00:00
echo "]}";
2012-03-31 00:42:41 +00:00
?>