11cdd0090SAndreas Gohr<?php 21cdd0090SAndreas Gohr 31cdd0090SAndreas Gohrnamespace dokuwiki\Remote; 41cdd0090SAndreas Gohr 57f8f2456SAndreas Gohruse IXR\DataType\Base64; 67f8f2456SAndreas Gohruse IXR\DataType\Date; 77f8f2456SAndreas Gohruse IXR\Exception\ServerException; 84385690fSAndreas Gohruse IXR\Message\Error; 97f8f2456SAndreas Gohruse IXR\Server\Server; 107f8f2456SAndreas Gohr 111cdd0090SAndreas Gohr/** 121cdd0090SAndreas Gohr * Contains needed wrapper functions and registers all available XMLRPC functions. 131cdd0090SAndreas Gohr */ 147f8f2456SAndreas Gohrclass XmlRpcServer extends Server 151cdd0090SAndreas Gohr{ 161cdd0090SAndreas Gohr protected $remote; 171cdd0090SAndreas Gohr 181cdd0090SAndreas Gohr /** 191cdd0090SAndreas Gohr * Constructor. Register methods and run Server 201cdd0090SAndreas Gohr */ 21fe52a7caSMark Janssen public function __construct($wait = false) 221cdd0090SAndreas Gohr { 231cdd0090SAndreas Gohr $this->remote = new Api(); 24fe52a7caSMark Janssen parent::__construct(false, false, $wait); 251cdd0090SAndreas Gohr } 261cdd0090SAndreas Gohr 271498ac42SAndreas Gohr /** @inheritdoc */ 281498ac42SAndreas Gohr public function serve($data = false) 291498ac42SAndreas Gohr { 301498ac42SAndreas Gohr global $conf; 31*ba15f985SAndreas Gohr global $INPUT; 321498ac42SAndreas Gohr if (!$conf['remote']) { 331498ac42SAndreas Gohr throw new ServerException("XML-RPC server not enabled.", -32605); 341498ac42SAndreas Gohr } 353df364a3STimo Richter if (!empty($conf['remotecors'])) { 363df364a3STimo Richter header('Access-Control-Allow-Origin: ' . $conf['remotecors']); 37cc7691adSAndreas Gohr } 38*ba15f985SAndreas Gohr [$contentType] = explode(';', $INPUT->server->str('CONTENT_TYPE'), 2); // ignore charset 39*ba15f985SAndreas Gohr $contentType = strtolower($contentType); // mime types are case-insensitive 40*ba15f985SAndreas Gohr if ($contentType !== 'text/xml' && $contentType !== 'application/xml') { 41cc7691adSAndreas Gohr throw new ServerException('XML-RPC server accepts XML requests only.', -32606); 423df364a3STimo Richter } 433df364a3STimo Richter 441498ac42SAndreas Gohr parent::serve($data); 451498ac42SAndreas Gohr } 461498ac42SAndreas Gohr 471cdd0090SAndreas Gohr /** 481cdd0090SAndreas Gohr * @inheritdoc 491cdd0090SAndreas Gohr */ 50104a3b7cSAndreas Gohr protected function call($methodname, $args) 511cdd0090SAndreas Gohr { 521cdd0090SAndreas Gohr try { 531cdd0090SAndreas Gohr $result = $this->remote->call($methodname, $args); 541cdd0090SAndreas Gohr return $result; 557f8f2456SAndreas Gohr } catch (AccessDeniedException $e) { 561cdd0090SAndreas Gohr if (!isset($_SERVER['REMOTE_USER'])) { 571cdd0090SAndreas Gohr http_status(401); 584385690fSAndreas Gohr return new Error(-32603, "server error. not authorized to call method $methodname"); 591cdd0090SAndreas Gohr } else { 601cdd0090SAndreas Gohr http_status(403); 614385690fSAndreas Gohr return new Error(-32604, "server error. forbidden to call the method $methodname"); 621cdd0090SAndreas Gohr } 631cdd0090SAndreas Gohr } catch (RemoteException $e) { 644385690fSAndreas Gohr return new Error($e->getCode(), $e->getMessage()); 651cdd0090SAndreas Gohr } 661cdd0090SAndreas Gohr } 671cdd0090SAndreas Gohr} 68