// make a list of all functions user is allowed to excecute
$this->init_service_class();
+ // TODO: solve debugging level somehow
+ Zend_XmlRpc_Server_Fault::attachFaultException('moodle_exception');
+
// start the server
$this->zend_server->setClass($this->service_class);
$response = $this->zend_server->handle();
+ //$grrr = ob_get_clean();
+ //error_log($grrr);
+
// session cleanup
$this->session_cleanup();
';
// load the virtual class definition into memory
eval($code);
-echo "<xmp>".$code."</xmp>";
$this->service_class = $classname;
}
}
$return = ' * @return '.$type.' '.$function->returns_desc->desc;
}
-
+
// now crate a virtual method that calls the ext implemenation
// TODO: add PHP docs and all missing info here
$this->restricted_context = get_context_instance(CONTEXT_SYSTEM);
if (!is_enabled_auth('webservice')) {
+ error_log('WS auth not enabled');
die('WS auth not enabled');
}
if (!$auth = get_auth_plugin('webservice')) {
+ error_log('WS auth missing');
die('WS auth missing');
}
--- /dev/null
+<?php
+
+$webservice_xmlrpc_capabilities = array(
+
+ 'webservice/xmlrpc:use' => array(
+ 'captype' => 'read', // in fact this may be considered read and write at the same time
+ 'contextlevel' => CONTEXT_COURSE, // the context level should be probably CONTEXT_MODULE
+ 'legacy' => array(
+ ),
+ ),
+
+);
+++ /dev/null
-<?php
-/**
- * Moodle - Modular Object-Oriented Dynamic Learning Environment
- * http://moodle.com
- *
- * LICENSE
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details:
- *
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @category Moodle
- * @package webservice
- * @copyright Copyright (c) 1999 onwards Martin Dougiamas http://dougiamas.com
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL License
- */
-
-/*
- * XML-RPC server class
- */
-
-require_once($CFG->dirroot.'/webservice/lib.php');
-
-final class xmlrpc_server extends webservice_server {
-
- public function __construct() {
-
- $this->set_protocolname("XML-RPC");
- $this->set_protocolid("xmlrpc");
- }
-
- public function run() {
- $enable = $this->get_enable();
- if (empty($enable)) {
- die;
- }
- include "Zend/Loader.php";
- Zend_Loader::registerAutoload();
-
- Zend_XmlRpc_Server_Fault::attachFaultException('moodle_exception');
-
- // retrieve the token from the url
- // if the token doesn't exist, set a class containing only get_token()
- $token = optional_param('token',null,PARAM_ALPHANUM);
- if (empty($token)) {
- $server = new Zend_XmlRpc_Server();
- $server->setClass("ws_authentication", "authentication");
- // Create a request object
- $request = new Zend_XmlRpc_Request_Http();
- $params = $request->getParams();
- $this->convertXmlrpcParams($params);
- $request->setParams($params);
- echo $server->handle($request);
- } else { // if token exist, do the authentication here
- /// TODO: following function will need to be modified
- $user = webservice_lib::mock_check_token($token);
- if (empty($user)) {
- throw new moodle_exception('wrongidentification');
- } else {
- /// TODO: probably change this
- global $USER;
- $USER = $user;
- }
-
- //retrieve the api name
- $classpath = optional_param('classpath', null, PARAM_SAFEDIR);
- require_once(dirname(__FILE__) . '/../../'.$classpath.'/external.php');
-
- /// run the server
- $server = new Zend_XmlRpc_Server();
- $server->setClass($classpath."_external", $classpath);
- $request = new Zend_XmlRpc_Request_Http();
- $params = $request->getParams();
- $this->convertXmlrpcParams($params);
- $request->setParams($params);
- echo $server->handle($request);
- }
- }
-
- private function convertXmlrpcParams(&$params) {
- if (is_array($params)) {
- //get the first key
- $key = key($params);
-
- reset($params);
-
- //if first key == 0 so do not change the params
- if (strcmp($key, "0") == 0) {
- foreach ($params as &$param) {
- $this->convertXmlrpcParams($param);
- }
- }
-
- //first key is a string, params need to be converted into an object
- //first go into
- else {
- foreach ($params as $paramkey => &$param) {
- $this->convertXmlrpcParams($param);
- }
- $params = (object) $params;
- }
- }
- }
-
-}
-
-
-?>
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * XML-RPC web service implementation classes and methods.
+ *
+ * @package webservice
+ * @copyright 2009 Moodle Pty Ltd (http://moodle.com)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once("$CFG->dirroot/webservice/lib.php");
+
+/**
+ * XML-RPC service server implementation.
+ * @author Petr Skoda (skodak)
+ */
+class webservice_xmlrpc_server extends webservice_zend_server {
+ /**
+ * Contructor
+ */
+ public function __construct() {
+ parent::__construct('Zend_XmlRpc_Server');
+ $this->wsname = 'xmlrpc';
+ }
+
+
+}
+
<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
/**
- * Moodle - Modular Object-Oriented Dynamic Learning Environment
- * http://moodle.com
- *
- * LICENSE
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details:
- *
- * http://www.gnu.org/copyleft/gpl.html
+ * XML-RPC web service entry point. The authentication is done via tokens.
*
- * @category Moodle
* @package webservice
- * @copyright Copyright (c) 1999 onwards Martin Dougiamas http://dougiamas.com
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL License
- */
-/**
- * Main script - XML-RPC server
- *
- * @author Jerome Mouneyrac <jerome@moodle.com>
- * @version 1.0
- * @package webservices
+ * @copyright 2009 Moodle Pty Ltd (http://moodle.com)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-/*
- * Zend XML-RPC server
- */
-require_once(dirname(__FILE__) . '/../../config.php');
-require_once('lib.php');
+define('NO_MOODLE_COOKIES', true);
+
+require('../../config.php');
+require_once("$CFG->dirroot/webservice/xmlrpc/locallib.php");
-if (empty($CFG->enablewebservices)) {
+if (!webservice_protocol_is_enabled('xmlrpc')) {
die;
}
-$server = new xmlrpc_server();
-$server->run();
+$server = new webservice_xmlrpc_server();
+$server->run(false);
+die;
-?>
\ No newline at end of file
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * XML-RPC web service entry point. The authentication is done via tokens.
+ *
+ * @package webservice
+ * @copyright 2009 Moodle Pty Ltd (http://moodle.com)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+define('NO_MOODLE_COOKIES', true);
+
+require('../../config.php');
+require_once("$CFG->dirroot/webservice/xmlrpc/locallib.php");
+
+//ob_start();
+
+//TODO: for now disable all mess in xml
+ini_set('display_errors', '0');
+ini_set('log_errors', '1');
+$CFG->debug = 0;
+$CFG->debugdisplay = false;
+
+//error_log('yy');
+//error_log(var_export($_SERVER, true));
+
+if (!webservice_protocol_is_enabled('xmlrpc')) {
+ die;
+}
+
+$server = new webservice_xmlrpc_server();
+$server->run(true);
+die;
+
+
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * XML-RPC web service test client.
+ *
+ * @package webservice
+ * @copyright 2009 Moodle Pty Ltd (http://moodle.com)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require('../../../config.php');
+require_once("$CFG->dirroot/webservice/testclient_forms.php");
+require_once("$CFG->dirroot/webservice/xmlrpc/locallib.php");
+
+$function = optional_param('function', '', PARAM_SAFEDIR);
+
+$PAGE->set_url('webservice/xmlrpc/testclient/index.php');
+
+require_login();
+require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); // TODO: do we need some new capability?
+
+$functions = array('moodle_group_get_groups');
+$functions = array_combine($functions, $functions);
+
+if (!isset($functions[$function])) {
+ $function = '';
+}
+
+if (!$function) {
+ $mform = new webservice_test_client_form(null, $functions);
+ echo $OUTPUT->header();
+ echo $OUTPUT->heading(get_string('pluginname', 'webservice_xmlrpc'));
+ $mform->display();
+ echo $OUTPUT->footer();
+ die;
+}
+
+$class = $function.'_form';
+
+$mform = new $class();
+
+if ($mform->is_cancelled()) {
+ redirect('index.php');
+
+} else if ($data = $mform->get_data()) {
+ unset($data->submitbutton);
+ $serverurl = "$CFG->wwwroot/webservice/xmlrpc/simpleserver.php";
+ $serverurl .= '?wsusername='.urlencode($data->wsusername);
+ unset($data->wsusername);
+ $serverurl .= '&wspassword='.urlencode($data->wspassword);
+ unset($data->wspassword);
+ unset($data->function);
+
+ // now get the function parameters
+ $params = array();
+ if ($function === 'moodle_group_get_groups') {
+ $params[0] = array();
+ //note: this could be placed into separate function lib file in the same dir
+ for ($i=0; $i<10; $i++) {
+ if (empty($data->groupids[$i])) {
+ continue;
+ }
+ $params[0][] = $data->groupids[$i];
+ }
+ } else {
+ die('notimplemented');
+ }
+
+ echo $OUTPUT->header();
+ echo $OUTPUT->heading(get_string('pluginname', 'webservice_xmlrpc').': '.$function);
+
+ echo 'URL: '.s($serverurl);
+ echo $OUTPUT->box_start();
+ echo '<code>';
+
+ include "Zend/Loader.php";
+ Zend_Loader::registerAutoload();
+ $client = new Zend_XmlRpc_Client($serverurl);
+ $response = $client->call($function, $params);
+ echo str_replace("\n", '<br />', s(var_export($response, true)));
+
+ echo '</code>';
+ echo $OUTPUT->box_end();
+ $mform->display();
+ echo $OUTPUT->footer();
+ die;
+
+} else {
+ echo $OUTPUT->header();
+ echo $OUTPUT->heading(get_string('pluginname', 'webservice_xmlrpc').': '.$function);
+ $mform->display();
+ echo $OUTPUT->footer();
+ die;
+}
\ No newline at end of file
+++ /dev/null
-<?php
-/**
- * Moodle - Modular Object-Oriented Dynamic Learning Environment
- * http://moodle.com
- *
- * LICENSE
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details:
- *
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @category Moodle
- * @package webservice
- * @copyright Copyright (c) 1999 onwards Martin Dougiamas http://dougiamas.com
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL License
- */
-
-/*
- * Zend XMLRPC sclient
- */
-require_once('../../../config.php');
-
-include "Zend/Loader.php";
-Zend_Loader::registerAutoload();
-
-
-//1. authentication
-$client = new Zend_XmlRpc_Client($CFG->wwwroot."/webservice/xmlrpc/server.php");
-$params = new stdClass();
-$params->username = 'wsuser';
-$params->password = 'wspassword';
-$token = $client->call('authentication.get_token', $params);
-var_dump($token);
-
-//2. test functions
-$client = new Zend_XmlRpc_Client($CFG->wwwroot."/webservice/xmlrpc/server.php?classpath=user&token=".$token);
-$params = new stdClass();
-$params->search = "admin";
-var_dump($users = $client->call('user.get_users', $params));
-print "<br/><br/>\n";
-$user = new stdClass();
-$user->password = "password6";
-$user->email = "mockuser6@mockuser6.com";
-$user->username = "mockuser66";
-$user->firstname = "firstname6";
-$user->lastname = "lastname6";
-$params = new stdClass();
-$params->users = array($user);
-var_dump($users = $client->call('user.create_users', $params));
-print "<br/><br/>\n";
-$usertoupdate = new stdClass();
-$usertoupdate->email = "mockuser6@mockuser6.com";
-$usertoupdate->username = "mockuser66";
-$usertoupdate->newusername = 'mockuser6b';
-$usertoupdate->firstname = "firstname6b";
-$params = new stdClass();
-$params->users = array($usertoupdate);
-var_dump($users = $client->call('user.update_users', $params));
-print "<br/><br/>\n";
-$params = new stdClass();
-$params->usernames = array("mockuser6b");
-var_dump($users = $client->call('user.delete_users', $params));
--- /dev/null
+<?php
+
+$plugin->version = 2009101900;