webfinger.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. header("Access-Control-Allow-Origin: *");
  3. header("Content-Type: application/xrd+json");
  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. $userName = '';
  20. $hostName = '';
  21. $request = strip_tags(urldecode($_GET['q']));
  22. if($_GET['q']) {
  23. $reqParts = explode('@', $request);
  24. if(count($reqParts)==2) {
  25. $userName = $reqParts[0];
  26. $hostName = $reqParts[1];
  27. }
  28. }
  29. if(substr($userName, 0, 5) == 'acct:') {
  30. $userName = substr($userName, 5);
  31. }
  32. if($userName == "") {
  33. $id = "";
  34. } else {
  35. $id = $userName . '@' . $hostName;
  36. }
  37. if(isset($_SERVER['HTTPS'])) {
  38. $baseAddress = 'https://';
  39. } else {
  40. $baseAddress = 'http://';
  41. }
  42. $baseAddress .= $_SERVER['SERVER_NAME'].OC::$WEBROOT;
  43. if(empty($id)) {
  44. header("HTTP/1.0 400 Bad Request");
  45. }
  46. define('WF_USER', $userName);
  47. define('WF_ID', $id);
  48. define('WF_BASEURL', $baseAddress);
  49. echo "{\"links\":[";
  50. $apps = OC_Appconfig::getApps();
  51. foreach($apps as $app) {
  52. if(OCP\App::isEnabled($app)) {
  53. if(is_file(OC::$APPSROOT . '/apps/' . $app . '/appinfo/webfinger.php')) {
  54. require($app . '/appinfo/webfinger.php');
  55. }
  56. }
  57. }
  58. echo "]}";
  59. ?>