Commit 13ae7db2 authored by Cameron Ball's avatar Cameron Ball
Browse files

MDL-52210 webservices: Remove AMF webservice

parent ef343c32
......@@ -95,10 +95,6 @@ if (!$function or !$protocol) {
$descparams = new stdClass();
$descparams->atag = $atag;
$descparams->mode = get_string('debugnormal', 'admin');
$amfclienturl = new moodle_url('/webservice/amf/testclient/index.php');
$amfclientatag =html_writer::tag('a', get_string('amftestclient', 'webservice'),
array('href' => $amfclienturl));
$descparams->amfatag = $amfclientatag;
echo get_string('testclientdescription', 'webservice', $descparams);
echo $OUTPUT->box_end();
......
......@@ -35,7 +35,6 @@ $string['addrequiredcapability'] = 'Assign/unassign the required capability';
$string['addservice'] = 'Add a new service: {$a->name} (id: {$a->id})';
$string['addservicefunction'] = 'Add functions to the service "{$a}"';
$string['allusers'] = 'All users';
$string['amftestclient'] = 'AMF test client';
$string['apiexplorer'] = 'API explorer';
$string['apiexplorernotavalaible'] = 'API explorer not available yet.';
$string['arguments'] = 'Arguments';
......@@ -185,7 +184,7 @@ $string['step'] = 'Step';
$string['supplyinfo'] = 'More details';
$string['testauserwithtestclientdescription'] = 'Simulate external access to the service using the web service test client. Before doing so, log in as a user with the moodle/webservice:createtoken capability and obtain the security key (token) via the user\'s preferences page. You will use this token in the test client. In the test client, also choose an enabled protocol with the token authentication. <strong>WARNING: The functions that you test WILL BE EXECUTED for this user, so be careful what you choose to test!</strong>';
$string['testclient'] = 'Web service test client';
$string['testclientdescription'] = '* The web service test client <strong>executes</strong> the functions for <strong>REAL</strong>. Do not test functions that you don\'t know. <br/>* All existing web service functions are not yet implemented into the test client. <br/>* In order to check that a user cannot access some functions, you can test some functions that you didn\'t allow.<br/>* To see clearer error messages set the debugging to <strong>{$a->mode}</strong> into {$a->atag}<br/>* Access the {$a->amfatag}.';
$string['testclientdescription'] = '* The web service test client <strong>executes</strong> the functions for <strong>REAL</strong>. Do not test functions that you don\'t know. <br/>* All existing web service functions are not yet implemented into the test client. <br/>* In order to check that a user cannot access some functions, you can test some functions that you didn\'t allow.<br/>* To see clearer error messages set the debugging to <strong>{$a->mode}</strong> into {$a->atag}.';
$string['testwithtestclient'] = 'Test the service';
$string['testwithtestclientdescription'] = 'Simulate external access to the service using the web service test client. Use an enabled protocol with token authentication. <strong>WARNING: The functions that you test WILL BE EXECUTED, so be careful what you choose to test!</strong>';
$string['token'] = 'Token';
......
......@@ -1665,6 +1665,7 @@ class core_plugin_manager {
'theme' => array('mymobile', 'afterburner', 'anomaly', 'arialist', 'binarius', 'boxxie', 'brick', 'formal_white',
'formfactor', 'fusion', 'leatherbound', 'magazine', 'nimble', 'nonzero', 'overlay', 'serenity', 'sky_high',
'splash', 'standard', 'standardold'),
'webservice' => array('amf'),
);
if (!isset($plugins[$type])) {
......@@ -1897,7 +1898,7 @@ class core_plugin_manager {
),
'webservice' => array(
'amf', 'rest', 'soap', 'xmlrpc'
'rest', 'soap', 'xmlrpc'
),
'workshopallocation' => array(
......
......@@ -4606,6 +4606,17 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2015100800.01);
}
if ($oldversion < 2015123100.01) {
// Force uninstall of deleted tool.
if (!file_exists("$CFG->dirroot/webservice/amf")) {
// Remove capabilities.
capabilities_cleanup('webservice_amf');
// Remove all other associated config.
unset_all_config_for_plugin('webservice_amf');
}
upgrade_main_savepoint(true, 2015123100.01);
}
// Moodle v3.0.0 release upgrade line.
// Put any upgrade step following this.
......
......@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2015123100.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2015123100.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
......
<?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/>.
/**
* AMF server capabilities.
*
* @package webservice_amf
* @category access
* @copyright 2009 Petr Skodak
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$capabilities = array(
'webservice/amf: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
'archetypes' => array(
),
),
);
<?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/>.
/**
* Introspection for amf
*
* Figures out where all the services are and
* returns a list of their available methods.
* Requires $CFG->amf_introspection = true for security.
*
* @package webservice_amf
* @copyright 2009 Penny Leach <penny@liip.ch>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Provides a function to get details of methods available on another class.
*
* @package webservice_amf
* @copyright HP
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MethodDescriptor {
/** @var array The details of the methods*/
private $methods;
/** @var array Classes to introspect
* Note: setup() code has been written to introspect multiple classes.
* However the setup() only deal with $classnametointrospect.
*/
private $classes;
/** @var string Class to introspect */
static public $classnametointrospect;
/**
* constructor
*/
public function __construct() {
$this->setup();
}
/**
* Generate the class method descriptions.
* These description are assigned in the class properties
*
* @return void
*/
private function setup() {
global $CFG;
if (!empty($this->nothing)) {
return; // we've already tried, no classes.
}
if (!empty($this->classes)) { // we've already done it successfully.
return;
}
//TODO MDL-31148 most likely can be removed, but check if there is any interest, never know...
/*if (empty($CFG->amf_introspection)) {
throw new Exception(get_string('amfintrospectiondisabled', 'local'));
}*/
//TODO MDL-31148 just one class here, possibility for expansion in future
$classes = array(MethodDescriptor::$classnametointrospect);
$hugestructure = array();
foreach ($classes as $c) {
$r = new ReflectionClass($c);
if (!$methods = $r->getMethods()) {
continue;
}
$this->classes[] = $c;
$hugestructure[$c] = array('docs' => $r->getDocComment(), 'methods' => array());
foreach ($methods as $method) {
if (!$method->isPublic()) {
continue;
}
$params = array();
foreach ($method->getParameters() as $param) {
$params[] = array('name' => $param->getName(), 'required' => !$param->isOptional());
}
$hugestructure[$c]['methods'][$method->getName()] = array(
'docs' => $method->getDocComment(),
'params' => $params,
);
}
}
$this->methods = $hugestructure;
if (empty($this->classes)) {
$this->nothing = true;
}
}
/**
* Get the method descriptions
*
* @return array
*/
public function getMethods() {
$this->setup();
return $this->methods;
}
/**
* Get the class descriptions
*
* @return array
*/
public function getClasses() {
$this->setup();
return $this->classes;
}
/**
* As the class does not extend another class and as this function does nothing
* except return true,
* I guess this is just a function that was a copy/paste and it has been forgotten.
* TODO MDL-31148 this function is not called and most likely can be removed
*
* @return true
*/
public function isConnected() {
return true;
}
}
<?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/>.
/**
* Strings for component 'webservice_amf', language 'en', branch 'MOODLE_20_STABLE'
*
* @package webservice_amf
* @category string
* @copyright 2010 Petr Skodak
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['amf:use'] = 'Use AMF protocol';
$string['pluginname'] = 'AMF protocol';
<?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/>.
/**
* AMF web service implementation classes and methods.
*
* @package webservice_amf
* @copyright 2009 Petr Skodak
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("$CFG->dirroot/webservice/lib.php");
require_once( "{$CFG->dirroot}/webservice/amf/introspector.php");
require_once 'Zend/Amf/Server.php';
/**
* Exception indicating an invalid return value from a function.
*
* Used when an externallib function does not return values of the expected structure.
*
* @package webservice_amf
* @copyright 2010 Jamie Pratt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class invalid_return_value_exception extends moodle_exception {
/**
* Constructor
*
* @param string $debuginfo some detailed information
*/
function __construct($debuginfo=null) {
parent::__construct('invalidreturnvalue', 'webservice_amf', '', $debuginfo, $debuginfo);
}
}
/**
* AMF service server implementation.
*
* @package webservice_amf
* @copyright 2009 Petr Skodak
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class webservice_amf_server extends webservice_zend_server {
/**
* Contructor
*
* @param integer $authmethod authentication method - one of WEBSERVICE_AUTHMETHOD_*
*/
public function __construct($authmethod) {
parent::__construct($authmethod, 'Moodle_Amf_Server');
$this->wsname = 'amf';
}
/**
* Load virtual class needed for Zend api
*/
protected function init_service_class(){
parent::init_service_class();
//allow access to data about methods available.
$this->zend_server->setClass( "MethodDescriptor" );
MethodDescriptor::$classnametointrospect = $this->service_class;
}
/**
* Get the generated web service function code.
*
* @param stdClass $function contains function name and class name
* @param array $params all the function parameters
* @return string the generate web service function code
*/
protected function service_class_method_body($function, $params){
//cast the param from object to array (validate_parameters except array only)
$castingcode = '';
if ($params){
$paramstocast = explode(',', $params);
foreach ($paramstocast as $paramtocast) {
$paramtocast = trim($paramtocast);
$castingcode .= $paramtocast .
'=webservice_zend_server::cast_objects_to_array('.$paramtocast.');';
}
}
$externallibcall = $function->classname.'::'.$function->methodname.'('.$params.')';
$descriptionmethod = $function->methodname.'_returns()';
$callforreturnvaluedesc = $function->classname.'::'.$descriptionmethod;
return $castingcode .
' return webservice_amf_server::validate_and_cast_values('.$callforreturnvaluedesc.', '.$externallibcall.');';
}
/**
* Validates submitted value, comparing it to a description. If anything is incorrect
* invalid_return_value_exception is thrown. Also casts the values to the type specified in
* the description.
*
* @param external_description $description description of parameters or null if no return value
* @param mixed $value the actual values
* @return mixed params with added defaults for optional items
* @throws invalid_return_value_exception
*/
public static function validate_and_cast_values($description, $value) {
if (is_null($description)){
return;
}
if ($description instanceof external_value) {
if (is_array($value) or is_object($value)) {
throw new invalid_return_value_exception('Scalar type expected, array or object received.');
}
if ($description->type == PARAM_BOOL) {
// special case for PARAM_BOOL - we want true/false instead of the usual 1/0 - we can not be too strict here ;-)
if (is_bool($value) or $value === 0 or $value === 1 or $value === '0' or $value === '1') {
return (bool)$value;
}
}
return validate_param($value, $description->type, $description->allownull, 'Invalid external api parameter');
} else if ($description instanceof external_single_structure) {
if (!is_array($value)) {
throw new invalid_return_value_exception('Only arrays accepted.');
}
$result = array();
foreach ($description->keys as $key=>$subdesc) {
if (!array_key_exists($key, $value)) {
if ($subdesc->required == VALUE_REQUIRED) {
throw new invalid_return_value_exception('Missing required key in single structure: '.$key);
}
if ($subdesc instanceof external_value) {
if ($subdesc->required == VALUE_DEFAULT) {
$result[$key] = self::validate_and_cast_values($subdesc, $subdesc->default);
}
}
} else {
$result[$key] = self::validate_and_cast_values($subdesc, $value[$key]);
}
unset($value[$key]);
}
return (object)$result;
} else if ($description instanceof external_multiple_structure) {
if (!is_array($value)) {
throw new invalid_return_value_exception('Only arrays accepted.');
}
$result = array();
foreach ($value as $param) {
$result[] = self::validate_and_cast_values($description->content, $param);
}
return $result;
} else {
throw new invalid_return_value_exception('Invalid external api description.');
}
}
/**
* Set up zend service class
*/
protected function init_zend_server() {
parent::init_zend_server();
$this->zend_server->setProduction(false); //set to false for development mode
//(complete error message displayed into your AMF client)
}
}
/**
* Zend Amf server with a different fault management
*
* @package webservice_amf
* @copyright 2010 Jamie Pratt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class Moodle_Amf_Server extends Zend_Amf_Server{
/**
* Raise a server fault
*
* @param string|Exception $fault
* @param int $code fault code
*/
public function fault($fault = null, $code = 404)
{
if (!$fault instanceof Exception) {
$fault = new Exception($fault);
}
$request = $this->getRequest();
// Get the object encoding of the request.
$objectEncoding = $request->getObjectEncoding();
// create a response object to place the output from the services.
$response = $this->getResponse();
// set response encoding
$response->setObjectEncoding($objectEncoding);
$responseBody = $request->getAmfBodies();
foreach($responseBody as $body){
$return = $this->_errorMessage($objectEncoding, $fault->getMessage(),
$fault->getMessage(), $fault->getTraceAsString(),$fault->getCode(), $fault->getLine());
$responseType = Zend_AMF_Constants::STATUS_METHOD;
$responseURI = $body->getResponseURI() . $responseType;
$newBody = new Zend_Amf_Value_MessageBody($responseURI, null, $return);
$response->addAmfBody($newBody);
}
$response->finalize();
echo $response;
}
}
<?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/>.
/**
* AMF web service entry point. The authentication is done via tokens.
*
* @package webservice_amf
* @copyright 2009 Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* NO_DEBUG_DISPLAY - disable moodle specific debug messages and any errors in output
*/
define('NO_DEBUG_DISPLAY', true);
define('WS_SERVER', true);
// Make sure OPcache does not strip comments, we need them for Zend!
if (ini_get('opcache.enable') and strtolower(ini_get('opcache.enable')) !== 'off') {
if (!ini_get('opcache.save_comments') or strtolower(ini_get('opcache.save_comments')) === 'off') {
ini_set('opcache.enable', 0);
} else {
ini_set('opcache.load_comments', 1);
}
}
require('../../config.php');
require_once("$CFG->dirroot/webservice/amf/locallib.php");
if (!webservice_protocol_is_enabled('amf')) {
debugging('The server died because the web services or the AMF protocol are not enable',
DEBUG_DEVELOPER);
die;
}
$server = new webservice_amf_server(WEBSERVICE_AUTHMETHOD_PERMANENT_TOKEN);
$server->run();
die;
<?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/>.
/**
* AMF web service entry point. The authentication is done via username/password.
*
* @package webservice_amf
* @copyright 2009 Petr Skodak
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* NO_DEBUG_DISPLAY - disable moodle specific debug messages and any errors in output
*/
define('NO_DEBUG_DISPLAY', true);
define('WS_SERVER', true);
// Make sure OPcache does not strip comments, we need them for Zend!
if (ini_get('opcache.enable') and strtolower(ini_get('opcache.enable')) !== 'off') {
if (!ini_get('opcache.save_comments') or strtolower(ini_get('opcache.save_comments')) === 'off') {
ini_set('opcache.enable', 0);
} else {
ini_set('opcache.load_comments', 1);
}
}
require('../../config.php');
require_once("$CFG->dirroot/webservice/amf/locallib.php");
//disable all 'displayed error' mess in xml
ini_set('display_errors', '0');
ini_set('log_errors', '1');
$CFG->debugdisplay = false;
if (!webservice_protocol_is_enabled('amf')) {
die;