webfinger.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. if (!OCP\App::isEnabled("user_webfinger")) {
  3. return;
  4. }
  5. header("Access-Control-Allow-Origin: *");
  6. header("Content-Type: application/xrd+json");
  7. /**
  8. * To include your app in the webfinger XML, add a new script with file name
  9. * 'webfinger.php' to /apps/yourapp/appinfo/, which prints out the XML parts
  10. * to be included. That script can make use of the constants WF_USER (e. g.
  11. * "user"), WF_ID (user@host) and WF_BASEURL (e. g. https://host/owncloud).
  12. * An example could look like this:
  13. *
  14. * <Link
  15. * rel="myProfile"
  16. * type="text/html"
  17. * href="<?php echo WF_BASEURL; ?>/apps/myApp/profile.php?user=<?php echo WF_USER; ?>">
  18. * </Link>
  19. *
  20. * but can also use complex database queries to generate the webfinger result
  21. **/
  22. $userName = '';
  23. $hostName = '';
  24. $request = strip_tags(urldecode($_GET['q']));
  25. if($_GET['q']) {
  26. $reqParts = explode('@', $request);
  27. if(count($reqParts)==2) {
  28. $userName = $reqParts[0];
  29. $hostName = $reqParts[1];
  30. }
  31. }
  32. if(substr($userName, 0, 5) == 'acct:') {
  33. $userName = substr($userName, 5);
  34. }
  35. if($userName == "") {
  36. $id = "";
  37. } else {
  38. $id = $userName . '@' . $hostName;
  39. }
  40. if(isset($_SERVER['HTTPS'])) {
  41. $baseAddress = 'https://';
  42. } else {
  43. $baseAddress = 'http://';
  44. }
  45. $baseAddress .= $_SERVER['SERVER_NAME'].OC::$WEBROOT;
  46. if(empty($id)) {
  47. header("HTTP/1.0 400 Bad Request");
  48. }
  49. define('WF_USER', $userName);
  50. define('WF_ID', $id);
  51. define('WF_BASEURL', $baseAddress);
  52. echo "{\"links\":[";
  53. $apps = OC_Appconfig::getApps();
  54. foreach($apps as $app) {
  55. if(OCP\App::isEnabled($app)) {
  56. if(is_file(OC_App::getAppPath($app). '/appinfo/webfinger.php')) {
  57. require($app . '/appinfo/webfinger.php');
  58. }
  59. }
  60. }
  61. echo "]}";