1<?php 2 3namespace dokuwiki\Remote; 4 5use IXR\DataType\Base64; 6use IXR\DataType\Date; 7use IXR\Exception\ServerException; 8use IXR\Server\Server; 9 10/** 11 * Contains needed wrapper functions and registers all available XMLRPC functions. 12 */ 13class XmlRpcServer extends Server 14{ 15 protected $remote; 16 17 /** 18 * Constructor. Register methods and run Server 19 */ 20 public function __construct($wait=false) 21 { 22 global $conf; 23 if (!$conf['remote']) { 24 throw new ServerException("XML-RPC server not enabled.", -32605); 25 } 26 27 $this->remote = new Api(); 28 $this->remote->setDateTransformation(array($this, 'toDate')); 29 $this->remote->setFileTransformation(array($this, 'toFile')); 30 parent::__construct(false, false, $wait); 31 } 32 33 /** 34 * @inheritdoc 35 */ 36 public function call($methodname, $args) 37 { 38 try { 39 $result = $this->remote->call($methodname, $args); 40 return $result; 41 } catch (AccessDeniedException $e) { 42 if (!isset($_SERVER['REMOTE_USER'])) { 43 http_status(401); 44 return new ServerException("server error. not authorized to call method $methodname", -32603); 45 } else { 46 http_status(403); 47 return new ServerException("server error. forbidden to call the method $methodname", -32604); 48 } 49 } catch (RemoteException $e) { 50 return new ServerException($e->getMessage(), $e->getCode()); 51 } 52 } 53 54 /** 55 * @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp 56 * @return Date 57 */ 58 public function toDate($data) 59 { 60 return new Date($data); 61 } 62 63 /** 64 * @param string $data 65 * @return Base64 66 */ 67 public function toFile($data) 68 { 69 return new Base64($data); 70 } 71} 72