webfinger.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. header("Access-Control-Allow-Origin: *");
  3. header("Content-Type: application/xrd+xml");
  4. /**
  5. * To include your app in the webfinger XML, add a new script with file name
  6. * 'webfinger.php' to /apps/yourapp/appinfo/, which prints out the XML parts
  7. * to be included. That script can make use of the constants WF_USER (e. g.
  8. * "user"), WF_ID (user@host) and WF_BASEURL (e. g. https://host/owncloud).
  9. * An example could look like this:
  10. *
  11. * <Link
  12. * rel="myProfile"
  13. * type="text/html"
  14. * href="<?php echo WF_BASEURL; ?>/apps/myApp/profile.php?user=<?php echo WF_USER; ?>">
  15. * </Link>
  16. *
  17. '* but can also use complex database queries to generate the webfinger result
  18. **/
  19. // calculate the documentroot
  20. // modified version of the one in lib/base.php that takes the .well-known symlink into account
  21. /*$DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']);
  22. $SERVERROOT=str_replace("\\",'/',dirname(dirname(dirname(dirname(__FILE__)))));
  23. $SUBURI=substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen($SERVERROOT));
  24. $WEBROOT=substr($SUBURI,0,-34);
  25. */
  26. require_once('../../lib/base.php');
  27. $request = urldecode($_GET['q']);
  28. if($_GET['q']) {
  29. $reqParts = explode('@', $request);
  30. $userName = $reqParts[0];
  31. $hostName = $reqParts[1];
  32. } else {
  33. $userName = '';
  34. $hostName = '';
  35. }
  36. if(substr($userName, 0, 5) == 'acct:') {
  37. $userName = substr($userName, 5);
  38. }
  39. if($userName == "") {
  40. $id = "";
  41. } else {
  42. $id = $userName . '@' . $hostName;
  43. }
  44. if(isset($_SERVER['HTTPS'])) {
  45. $baseAddress = 'https://';
  46. } else {
  47. $baseAddress = 'http://';
  48. }
  49. $baseAddress .= $_SERVER['SERVER_NAME'].OC::$WEBROOT;
  50. define('WF_USER', $userName);
  51. define('WF_ID', $id);
  52. define('WF_BASEURL', $baseAddress);
  53. echo "<";
  54. ?>
  55. ?xml version="1.0" encoding="UTF-8"?>
  56. <XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0" xmlns:hm="http://host-meta.net/xrd/1.0">
  57. <hm:Host xmlns="http://host-meta.net/xrd/1.0"><?php echo $_SERVER['SERVER_NAME']; ?></hm:Host>
  58. <Subject>acct:<?php echo $id ?></Subject>
  59. <?php
  60. $apps = OC_Appconfig::getApps();
  61. foreach($apps as $app) {
  62. if(OC_App::isEnabled($app)) {
  63. if(is_file(OC::$APPSROOT . '/apps/' . $app . '/appinfo/webfinger.php')) {
  64. require($app . '/appinfo/webfinger.php');
  65. }
  66. }
  67. }
  68. ?>
  69. </XRD>