Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
moved XMLRPC server class from lib/exe to inc/Remote
  • Loading branch information
splitbrain committed May 7, 2018
1 parent 272a98e commit 1cdd009
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 67 deletions.
10 changes: 5 additions & 5 deletions inc/Remote/Api.php
Expand Up @@ -120,13 +120,13 @@ private function coreMethodExist($name)
* @param string $method name of method
* @param array $args
* @return mixed
* @throws \dokuwiki\Remote\RemoteException if method not exists
* @throws RemoteException if method not exists
*/
private function callCustomCallPlugin($method, $args)
{
$customCalls = $this->getCustomCallPlugins();
if (!array_key_exists($method, $customCalls)) {
throw new \dokuwiki\Remote\RemoteException('Method does not exist', -32603);
throw new RemoteException('Method does not exist', -32603);
}
$customCall = $customCalls[$method];
return $this->callPlugin($customCall[0], $customCall[1], $args);
Expand Down Expand Up @@ -155,14 +155,14 @@ private function getCustomCallPlugins()
* @param string $method method name
* @param array $args
* @return mixed return of custom method
* @throws \dokuwiki\Remote\RemoteException
* @throws RemoteException
*/
private function callPlugin($pluginName, $method, $args)
{
$plugin = plugin_load('remote', $pluginName);
$methods = $this->getPluginMethods();
if (!$plugin) {
throw new \dokuwiki\Remote\RemoteException('Method does not exist', -32603);
throw new RemoteException('Method does not exist', -32603);
}
$this->checkAccess($methods[$method]);
$name = $this->getMethodName($methods, $method);
Expand All @@ -175,7 +175,7 @@ private function callPlugin($pluginName, $method, $args)
* @param string $method name of method
* @param array $args
* @return mixed
* @throws \dokuwiki\Remote\RemoteException if method not exist
* @throws RemoteException if method not exist
*/
private function callCoreMethod($method, $args)
{
Expand Down
61 changes: 61 additions & 0 deletions inc/Remote/XmlRpcServer.php
@@ -0,0 +1,61 @@
<?php

namespace dokuwiki\Remote;

/**
* Contains needed wrapper functions and registers all available XMLRPC functions.
*/
class XmlRpcServer extends \IXR_Server
{
protected $remote;

/**
* Constructor. Register methods and run Server
*/
public function __construct()
{
$this->remote = new Api();
$this->remote->setDateTransformation(array($this, 'toDate'));
$this->remote->setFileTransformation(array($this, 'toFile'));
parent::__construct();
}

/**
* @inheritdoc
*/
public function call($methodname, $args)
{
try {
$result = $this->remote->call($methodname, $args);
return $result;
} /** @noinspection PhpRedundantCatchClauseInspection */ catch (AccessDeniedException $e) {
if (!isset($_SERVER['REMOTE_USER'])) {
http_status(401);
return new \IXR_Error(-32603, "server error. not authorized to call method $methodname");
} else {
http_status(403);
return new \IXR_Error(-32604, "server error. forbidden to call the method $methodname");
}
} catch (RemoteException $e) {
return new \IXR_Error($e->getCode(), $e->getMessage());
}
}

/**
* @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp
* @return \IXR_Date
*/
public function toDate($data)
{
return new \IXR_Date($data);
}

/**
* @param string $data
* @return \IXR_Base64
*/
public function toFile($data)
{
return new \IXR_Base64($data);
}
}
67 changes: 5 additions & 62 deletions lib/exe/xmlrpc.php
@@ -1,8 +1,9 @@
<?php
/**
* XMLRPC API backend
*/

use dokuwiki\Remote\AccessDeniedException;
use dokuwiki\Remote\Api;
use dokuwiki\Remote\RemoteException;
use dokuwiki\Remote\XmlRpcServer;

if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/../../');

Expand All @@ -11,62 +12,4 @@

if(!$conf['remote']) die((new IXR_Error(-32605, "XML-RPC server not enabled."))->getXml());

/**
* Contains needed wrapper functions and registers all available
* XMLRPC functions.
*/
class dokuwiki_xmlrpc_server extends IXR_Server {
protected $remote;

/**
* Constructor. Register methods and run Server
*/
public function __construct(){
$this->remote = new Api();
$this->remote->setDateTransformation(array($this, 'toDate'));
$this->remote->setFileTransformation(array($this, 'toFile'));
parent::__construct();
}

/**
* @param string $methodname
* @param array $args
* @return IXR_Error|mixed
*/
public function call($methodname, $args){
try {
$result = $this->remote->call($methodname, $args);
return $result;
} catch (AccessDeniedException $e) {
if (!isset($_SERVER['REMOTE_USER'])) {
http_status(401);
return new IXR_Error(-32603, "server error. not authorized to call method $methodname");
} else {
http_status(403);
return new IXR_Error(-32604, "server error. forbidden to call the method $methodname");
}
} catch (RemoteException $e) {
return new IXR_Error($e->getCode(), $e->getMessage());
}
}

/**
* @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp
* @return IXR_Date
*/
public function toDate($data) {
return new IXR_Date($data);
}

/**
* @param string $data
* @return IXR_Base64
*/
public function toFile($data) {
return new IXR_Base64($data);
}
}

$server = new dokuwiki_xmlrpc_server();

// vim:ts=4:sw=4:et:
$server = new XmlRpcServer();

0 comments on commit 1cdd009

Please sign in to comment.