2011-10-09 15:12:16 +00:00
|
|
|
<?php
|
2012-04-02 15:12:52 +00:00
|
|
|
$hostMetaHeader = array(
|
|
|
|
'Access-Control-Allow-Origin' => '*',
|
|
|
|
'Content-Type' => 'application/xml+xrd'
|
|
|
|
);
|
2011-10-09 15:24:18 +00:00
|
|
|
$appInfoDir = __DIR__;
|
|
|
|
$thisAppDir = dirname($appInfoDir);
|
2011-10-09 15:12:16 +00:00
|
|
|
$appsDir = dirname($thisAppDir);
|
|
|
|
$ownCloudDir = dirname($appsDir);
|
2012-03-28 14:07:50 +00:00
|
|
|
$docRoot = $_SERVER['DOCUMENT_ROOT'];
|
2012-03-30 19:35:09 +00:00
|
|
|
try {
|
|
|
|
$webRoot = substr(realpath($ownCloudDir), strlen(realpath($docRoot)));
|
|
|
|
} catch(Exception $e) {
|
|
|
|
// some servers fail on realpath(), let's try it the unsecure way:
|
|
|
|
$webRoot = substr($ownCloudDir, strlen($docRoot));
|
2012-03-28 14:07:50 +00:00
|
|
|
}
|
2012-03-30 19:35:09 +00:00
|
|
|
$serverName = $_SERVER['SERVER_NAME'];
|
|
|
|
$lrddTmpl = 'http';
|
|
|
|
if(isset($_SERVER['HTTPS'])) {
|
|
|
|
$lrddTmpl .= 's';
|
|
|
|
}
|
|
|
|
$lrddTmpl .= '://' . $serverName . $webRoot . '/apps/user_webfinger/webfinger.php?q={uri}';
|
|
|
|
$hostMetaPath = $docRoot . '/.well-known/host-meta';
|
2012-04-02 15:12:52 +00:00
|
|
|
$hostMetaDir = $docRoot . '/.well-known';
|
2012-03-30 19:35:09 +00:00
|
|
|
$hostMetaContents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
|
|
|
<XRD xmlns=\"http://docs.oasis-open.org/ns/xri/xrd-1.0\" xmlns:hm=\"http://host-meta.net/xrd/1.0\">
|
|
|
|
<hm:Host xmlns=\"http://host-meta.net/xrd/1.0\">" . $serverName . "</hm:Host>
|
|
|
|
<Link rel=\"lrdd\" template=\"" . $lrddTmpl . "\">
|
|
|
|
<Title>Resource Descriptor</Title>
|
|
|
|
</Link>
|
|
|
|
</XRD>";
|
2012-04-02 15:12:52 +00:00
|
|
|
@mkdir($hostMetaDir);
|
2012-03-30 19:35:09 +00:00
|
|
|
$hostMeta = fopen($hostMetaPath, 'w');
|
|
|
|
if(!$hostMeta) {
|
|
|
|
die("Could not open " . $hostMetaPath . " for writing, please check permissions!");
|
|
|
|
}
|
|
|
|
if(!fwrite($hostMeta, $hostMetaContents, strlen($hostMetaContents))) {
|
|
|
|
die("Could not write to " . $hostMetaPath . ", please check permissions!");
|
|
|
|
}
|
|
|
|
fclose($hostMeta);
|
2012-04-02 15:12:52 +00:00
|
|
|
|
|
|
|
// write custom headers into .htaccess:
|
|
|
|
$htaccess = fopen($hostMetaDir . '/.htaccess', 'w');
|
|
|
|
//TODO: check compatibility!
|
|
|
|
fwrite($htaccess, "<filesMatch \"^host-meta$\">
|
|
|
|
<ifModule mod_headers.c>\n");
|
|
|
|
foreach($hostMetaHeader as $header => $value) {
|
|
|
|
fwrite($htaccess, "Header set " . $header . " \"" . $value . "\"\n");
|
|
|
|
}
|
|
|
|
fwrite($htaccess, "</ifModule>\n</filesMatch>");
|
|
|
|
fclose($htaccess);
|