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 $this->remote = new Api(); 23 $this->remote->setDateTransformation(array($this, 'toDate')); 24 $this->remote->setFileTransformation(array($this, 'toFile')); 25 parent::__construct(false, false, $wait); 26 } 27 28 /** @inheritdoc */ 29 public function serve($data = false) 30 { 31 global $conf; 32 if (!$conf['remote']) { 33 throw new ServerException("XML-RPC server not enabled.", -32605); 34 } 35 parent::serve($data); 36 } 37 38 /** 39 * @inheritdoc 40 */ 41 public function call($methodname, $args) 42 { 43 try { 44 $result = $this->remote->call($methodname, $args); 45 return $result; 46 } catch (AccessDeniedException $e) { 47 if (!isset($_SERVER['REMOTE_USER'])) { 48 http_status(401); 49 return new ServerException("server error. not authorized to call method $methodname", -32603); 50 } else { 51 http_status(403); 52 return new ServerException("server error. forbidden to call the method $methodname", -32604); 53 } 54 } catch (RemoteException $e) { 55 return new ServerException($e->getMessage(), $e->getCode()); 56 } 57 } 58 59 /** 60 * @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp 61 * @return Date 62 */ 63 public function toDate($data) 64 { 65 return new Date($data); 66 } 67 68 /** 69 * @param string $data 70 * @return Base64 71 */ 72 public function toFile($data) 73 { 74 return new Base64($data); 75 } 76} 77