From 445e8084b0ae168ce8982503d16c69a64ebc5871 Mon Sep 17 00:00:00 2001 From: Andreas Gohr <andi@splitbrain.org> Date: Tue, 3 Mar 2009 20:36:08 +0100 Subject: [PATCH] Support login in XMLRCP and added API version info A simple version number was added to the XMLRPC API to make it easy for clients to check if the remote endpoint supports certain features. The login function will take credentials and set cookies on successful login. This is useful when HTTP Basic auth is not available. darcs-hash:20090303193608-7ad00-45b1cd7a5165656796df25ed5c4ebc6e8ef7f95a.gz --- lib/exe/xmlrpc.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/exe/xmlrpc.php b/lib/exe/xmlrpc.php index ee0ab52ed..24338da8b 100644 --- a/lib/exe/xmlrpc.php +++ b/lib/exe/xmlrpc.php @@ -4,6 +4,10 @@ if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); // fix when '<?xml' isn't on the very first line if(isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA); +/** + * Increased whenever the API is changed + */ +define('DOKU_XMLRPC_API_VERSION',1); require_once(DOKU_INC.'inc/init.php'); require_once(DOKU_INC.'inc/common.php'); @@ -32,6 +36,13 @@ class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { $this->IXR_IntrospectionServer(); /* DokuWiki's own methods */ + $this->addCallback( + 'dokuwiki.getXMLRPCAPIVersion', + 'this:getAPIVersion', + array('integer'), + 'Returns the XMLRPC API version.' + ); + $this->addCallback( 'dokuwiki.getVersion', 'getVersion', @@ -39,6 +50,13 @@ class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { 'Returns the running DokuWiki version.' ); + $this->addCallback( + 'dokuwiki.login', + 'this:login', + array('integer','string','string'), + 'Tries to login with the given credentials and sets auth cookies.' + ); + $this->addCallback( 'dokuwiki.getPagelist', 'this:readNamespace', @@ -825,6 +843,21 @@ dbglog($data); ); } + function getAPIVersion(){ + return DOKU_XMLRPC_API_VERSION; + } + + function login($user,$pass){ + global $conf; + global $auth; + if(!$conf['useacl']) return 0; + if(!$auth) return 0; + if($auth->canDo('external')){ + return $auth->trustExternal($user,$pass,false); + }else{ + return auth_login($user,$pass,false,true); + } + } } $server = new dokuwiki_xmlrpc_server(); -- GitLab