xref: /dokuwiki/lib/exe/xmlrpc.php (revision 3a6d76070be7220b8e5f7c04443aa923bc8cddf2)
1797c0d11SAndreas Gohr<?php
27aec69d1SGuy Brandif(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../');
3797c0d11SAndreas Gohr
4797c0d11SAndreas Gohr// fix when '< ?xml' isn't on the very first line
5797c0d11SAndreas Gohrif(isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
6797c0d11SAndreas Gohr
7797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php');
83a13cfe7SDominik Eckelmannrequire_once(DOKU_INC.'inc/remote.php');
9797c0d11SAndreas Gohrsession_write_close();  //close session
10593bf8f6SMichael Klier
113ee5b583SAndreas Gohrif(!$conf['xmlrpc']) die('XML-RPC server not enabled.');
12593bf8f6SMichael Klier
13797c0d11SAndreas Gohr/**
14797c0d11SAndreas Gohr * Contains needed wrapper functions and registers all available
15797c0d11SAndreas Gohr * XMLRPC functions.
16797c0d11SAndreas Gohr */
173a13cfe7SDominik Eckelmannclass dokuwiki_xmlrpc_server extends IXR_Server {
183f3bb97fSDominik Eckelmann    var $remote;
193ee5b583SAndreas Gohr
203ee5b583SAndreas Gohr    /**
21797c0d11SAndreas Gohr     * Constructor. Register methods and run Server
22797c0d11SAndreas Gohr     */
23797c0d11SAndreas Gohr    function dokuwiki_xmlrpc_server(){
243f3bb97fSDominik Eckelmann        $this->remote = new RemoteAPI();
25f9501785SDominik Eckelmann        $this->remote->setDateTransformation(array($this, 'toDate'));
26f9501785SDominik Eckelmann        $this->remote->setFileTransformation(array($this, 'toFile'));
273a13cfe7SDominik Eckelmann        $this->IXR_Server();
28797c0d11SAndreas Gohr    }
29797c0d11SAndreas Gohr
303a13cfe7SDominik Eckelmann    function call($methodname, $args){
313f3bb97fSDominik Eckelmann        try {
323a13cfe7SDominik Eckelmann            $result = $this->remote->call($methodname, $args);
333a13cfe7SDominik Eckelmann            return $result;
34e61127e4SDominik Eckelmann        } catch (RemoteAccessDeniedException $e) {
353a13cfe7SDominik Eckelmann            if (!isset($_SERVER['REMOTE_USER'])) {
363a13cfe7SDominik Eckelmann                header('HTTP/1.1 401 Unauthorized');
37f71f4f53SAndreas Gohr            } else {
383a13cfe7SDominik Eckelmann                header('HTTP/1.1 403 Forbidden');
39f71f4f53SAndreas Gohr            }
40*3a6d7607SDominik Eckelmann            return new IXR_Error(-32603, "server error. not authorized to call method $methodname");
413a13cfe7SDominik Eckelmann        } catch (RemoteException $e) {
423a13cfe7SDominik Eckelmann            return new IXR_Error($e->getCode(), $e->getMessage());
4326bec61eSMichael Klier        }
4426bec61eSMichael Klier    }
4526bec61eSMichael Klier
46f9501785SDominik Eckelmann    function toDate($data) {
47f9501785SDominik Eckelmann        return new IXR_Date($data);
48f9501785SDominik Eckelmann    }
49f9501785SDominik Eckelmann
50f9501785SDominik Eckelmann    function toFile($data) {
51f9501785SDominik Eckelmann        return new IXR_Base64($data);
52f9501785SDominik Eckelmann    }
53797c0d11SAndreas Gohr}
54797c0d11SAndreas Gohr
55797c0d11SAndreas Gohr$server = new dokuwiki_xmlrpc_server();
56797c0d11SAndreas Gohr
57e3776c06SMichael Hamann// vim:ts=4:sw=4:et:
58