1797c0d11SAndreas Gohr<?php 27aec69d1SGuy Brandif(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); 3797c0d11SAndreas Gohr 4797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php'); 5797c0d11SAndreas Gohrsession_write_close(); //close session 6593bf8f6SMichael Klier 7b967e5fcSDominik Eckelmannif(!$conf['remote']) die('XML-RPC server not enabled.'); 8593bf8f6SMichael Klier 9797c0d11SAndreas Gohr/** 10797c0d11SAndreas Gohr * Contains needed wrapper functions and registers all available 11797c0d11SAndreas Gohr * XMLRPC functions. 12797c0d11SAndreas Gohr */ 133a13cfe7SDominik Eckelmannclass dokuwiki_xmlrpc_server extends IXR_Server { 143f3bb97fSDominik Eckelmann var $remote; 153ee5b583SAndreas Gohr 163ee5b583SAndreas Gohr /** 17797c0d11SAndreas Gohr * Constructor. Register methods and run Server 18797c0d11SAndreas Gohr */ 19797c0d11SAndreas Gohr function dokuwiki_xmlrpc_server(){ 203f3bb97fSDominik Eckelmann $this->remote = new RemoteAPI(); 21f9501785SDominik Eckelmann $this->remote->setDateTransformation(array($this, 'toDate')); 22f9501785SDominik Eckelmann $this->remote->setFileTransformation(array($this, 'toFile')); 233a13cfe7SDominik Eckelmann $this->IXR_Server(); 24797c0d11SAndreas Gohr } 25797c0d11SAndreas Gohr 263a13cfe7SDominik Eckelmann function call($methodname, $args){ 273f3bb97fSDominik Eckelmann try { 283a13cfe7SDominik Eckelmann $result = $this->remote->call($methodname, $args); 293a13cfe7SDominik Eckelmann return $result; 30e61127e4SDominik Eckelmann } catch (RemoteAccessDeniedException $e) { 313a13cfe7SDominik Eckelmann if (!isset($_SERVER['REMOTE_USER'])) { 323a13cfe7SDominik Eckelmann header('HTTP/1.1 401 Unauthorized'); 33*b2a3342aSTim Roes return new IXR_Error(-32603, "server error. not authorized to call method $methodname"); 34f71f4f53SAndreas Gohr } else { 353a13cfe7SDominik Eckelmann header('HTTP/1.1 403 Forbidden'); 36*b2a3342aSTim Roes return new IXR_Error(-32604, "server error. forbidden to call the method $methodname"); 37f71f4f53SAndreas Gohr } 383a13cfe7SDominik Eckelmann } catch (RemoteException $e) { 393a13cfe7SDominik Eckelmann return new IXR_Error($e->getCode(), $e->getMessage()); 4026bec61eSMichael Klier } 4126bec61eSMichael Klier } 4226bec61eSMichael Klier 43f9501785SDominik Eckelmann function toDate($data) { 44f9501785SDominik Eckelmann return new IXR_Date($data); 45f9501785SDominik Eckelmann } 46f9501785SDominik Eckelmann 47f9501785SDominik Eckelmann function toFile($data) { 48f9501785SDominik Eckelmann return new IXR_Base64($data); 49f9501785SDominik Eckelmann } 50797c0d11SAndreas Gohr} 51797c0d11SAndreas Gohr 52797c0d11SAndreas Gohr$server = new dokuwiki_xmlrpc_server(); 53797c0d11SAndreas Gohr 54e3776c06SMichael Hamann// vim:ts=4:sw=4:et: 55