host-meta.php 959 B

123456789101112131415161718192021222324252627
  1. <?php
  2. $hostMetaHeader = array(
  3. 'Access-Control-Allow-Origin' => '*',
  4. 'Content-Type' => 'application/xrd+json'
  5. );
  6. $ownCloudDir = dirname(dirname(dirname(__FILE__)));
  7. $docRoot = $_SERVER['DOCUMENT_ROOT'];
  8. try {
  9. $webRoot = substr(realpath($ownCloudDir), strlen(realpath($docRoot)));
  10. } catch(Exception $e) {
  11. // some servers fail on realpath(), let's try it the unsecure way:
  12. $webRoot = substr($ownCloudDir, strlen($docRoot));
  13. }
  14. $serverName = $_SERVER['SERVER_NAME'];
  15. $lrddTmpl = 'http';
  16. if(isset($_SERVER['HTTPS'])) {
  17. $lrddTmpl .= 's';
  18. }
  19. $lrddTmpl .= '://' . $serverName . $webRoot . '/public.php?service=webfinger&q={uri}';
  20. $hostMetaPath = $docRoot . '/.well-known/host-meta';
  21. $hostMetaDir = $docRoot . '/.well-known';
  22. $hostMetaContents = "{\"links\":[{\"rel\":\"lrdd\",\"template\":\"http://mich.oc/public.php?service=webfinger&q={uri}\"}]}";
  23. foreach($hostMetaHeader as $header => $value) {
  24. header($header . ": " . $value);
  25. }
  26. echo $hostMetaContents;