nextcloud/apps/user_webfinger/webfinger.php

69 lines
2.1 KiB
PHP
Raw Normal View History

2011-09-12 02:12:34 +04:00
<?php
2012-03-31 04:42:41 +04:00
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/xrd+xml");
2012-03-31 04:42:41 +04: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_ADDRESS ("user@host") and WF_ROOT ("https://host/owncloud").
* An example could look like this:
*
* <Link
* rel="myProfile"
* type="text/html"
* href="<?php echo WF_ROOT; ?>/apps/myApp/profile.php?user=<?php echo WF_USER; ?>">
* </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 04:42:41 +04: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 04:42:41 +04:00
*/
require_once('../../lib/base.php');
2011-09-12 02:12:34 +04:00
2012-03-31 04:42:41 +04:00
$id = $_GET['q'];
2011-09-12 02:12:34 +04:00
if($_GET['q']) {
$bits = explode('@', $_GET['q']);
$userName = $bits[0];
} else {
2012-03-31 04:42:41 +04:00
$id = '';
2011-09-12 02:12:34 +04:00
$userName = '';
}
if(substr($userName, 0, 5) == 'acct:') {
$userName = substr($userName, 5);
}
if(isset($_SERVER['HTTPS'])) {
2012-03-31 04:42:41 +04:00
$baseAddress = 'https://';
} else {
2012-03-31 04:42:41 +04:00
$baseAddress = 'http://';
}
2012-03-31 04:42:41 +04:00
$baseAddress .= $_SERVER['SERVER_NAME'].OC::$WEBROOT;
define('WF_USER', $userName);
define('WF_ADDRESS', $id);
define('WF_ROOT', $baseAddress);
2011-09-12 02:12:34 +04:00
echo "<";
?>
2011-09-12 16:35:15 +04:00
?xml version="1.0" encoding="UTF-8"?>
2011-09-12 02:12:34 +04:00
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0" xmlns:hm="http://host-meta.net/xrd/1.0">
2012-03-31 04:42:41 +04:00
<hm:Host xmlns="http://host-meta.net/xrd/1.0"><?php echo $_SERVER['SERVER_NAME']; ?></hm:Host>
<Subject>acct:<?php echo $userName . '@' . $_SERVER['SERVER_NAME'] ?></Subject>
<?php
$apps = OC_Appconfig::getApps();
foreach($apps as $app) {
//echo "checking $app...\n";
if(OC_App::isEnabled($app)) {
//echo "is enabled\n";
if(is_file(OC::$APPSROOT . '/apps/' . $app . '/appinfo/webfinger.php')) {
//echo "has webfinger.php\n";
require($app . '/appinfo/webfinger.php');
}
}
}
?>
2011-09-12 02:12:34 +04:00
</XRD>