You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

71 lines
1.9 KiB

  1. <?php
  2. namespace dokuwiki\Remote;
  3. use IXR\DataType\Base64;
  4. use IXR\DataType\Date;
  5. use IXR\Exception\ServerException;
  6. use IXR\Message\Error;
  7. use IXR\Server\Server;
  8. /**
  9. * Contains needed wrapper functions and registers all available XMLRPC functions.
  10. */
  11. class XmlRpcServer extends Server
  12. {
  13. protected $remote;
  14. /**
  15. * Constructor. Register methods and run Server
  16. */
  17. public function __construct($wait = false)
  18. {
  19. $this->remote = new Api();
  20. parent::__construct(false, false, $wait);
  21. }
  22. /** @inheritdoc */
  23. public function serve($data = false)
  24. {
  25. global $conf;
  26. if (!$conf['remote']) {
  27. throw new ServerException("XML-RPC server not enabled.", -32605);
  28. }
  29. if (!empty($conf['remotecors'])) {
  30. header('Access-Control-Allow-Origin: ' . $conf['remotecors']);
  31. }
  32. if (
  33. !isset($_SERVER['CONTENT_TYPE']) ||
  34. (
  35. strtolower($_SERVER['CONTENT_TYPE']) !== 'text/xml' &&
  36. strtolower($_SERVER['CONTENT_TYPE']) !== 'application/xml'
  37. )
  38. ) {
  39. throw new ServerException('XML-RPC server accepts XML requests only.', -32606);
  40. }
  41. parent::serve($data);
  42. }
  43. /**
  44. * @inheritdoc
  45. */
  46. protected function call($methodname, $args)
  47. {
  48. try {
  49. $result = $this->remote->call($methodname, $args);
  50. return $result;
  51. } catch (AccessDeniedException $e) {
  52. if (!isset($_SERVER['REMOTE_USER'])) {
  53. http_status(401);
  54. return new Error(-32603, "server error. not authorized to call method $methodname");
  55. } else {
  56. http_status(403);
  57. return new Error(-32604, "server error. forbidden to call the method $methodname");
  58. }
  59. } catch (RemoteException $e) {
  60. return new Error($e->getCode(), $e->getMessage());
  61. }
  62. }
  63. }