Skip to content

Commit

Permalink
web service MDL-12886 administration: implement settings for servers …
Browse files Browse the repository at this point in the history
…(add amf debug option)
  • Loading branch information
jerome committed Mar 31, 2009
1 parent 214f585 commit f7631e7
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 17 deletions.
35 changes: 35 additions & 0 deletions admin/wsprotocols.php
Expand Up @@ -8,6 +8,7 @@

$hide = optional_param('hide', '', PARAM_ALPHANUM);
$username = optional_param('username', '', PARAM_ALPHANUM);
$settings = optional_param('settings', '', PARAM_ALPHANUM);

$pagename = 'managews';

Expand Down Expand Up @@ -44,6 +45,40 @@
$mform->display();
print_simple_box_end();

} else if (!empty($settings)) {
/// Server settings page
admin_externalpage_print_header();

$mform = new wssettings_form('', array('settings' => $settings)); // load the server settings form

if ($mform->is_cancelled()){
/// user pressed cancel button and return to the security web service page
redirect($baseurl);
exit;
}

$fromform = $mform->get_data();

if (!empty($fromform)) {
/// save the new setting
require_once($CFG->dirroot . '/webservice/'. $settings . '/lib.php');
$settingnames = call_user_func(array($settings.'_server', 'get_setting_names'));
foreach($settingnames as $settingname) {
if (empty($fromform->$settingname)) {
set_config($settingname, null, $settings);
} else {
set_config($settingname, $fromform->$settingname, $settings);
}
}

redirect($baseurl,get_string("changessaved")); // return to the security web service page
}
/// display the server settings form
print_simple_box_start();
$mform->display();
print_simple_box_end();
} else {
$return = true;
}

if (!empty($return)) {
Expand Down
2 changes: 2 additions & 0 deletions lang/en_utf8/webservice.php
Expand Up @@ -37,4 +37,6 @@
$string['fail'] = 'FAIL';
$string['wsuserreminder'] = 'Reminder: the Moodle administrator of this site needs to give you moodle/site:usewebservices capability.';
$string['debugdisplayon'] = '\"Display debug messages\" is set On. The XMLRPC server will not work. The other web service servers could also return some problems. <br/>Alert the Moodle administrator to set it Off.';
$string['amfdebug'] = 'AMF server debug mode';

?>
18 changes: 13 additions & 5 deletions lib/adminlib.php
Expand Up @@ -4886,19 +4886,27 @@ public function output_html($data, $query='') {
require_once("../webservice/lib.php");
$protocols = webservice_lib::get_list_protocols();
$table = new StdClass;
$table->head = array($namestr, $hiddenstr);
$table->align = array('left', 'center');
$table->head = array($namestr, $hiddenstr, $settingsstr);
$table->align = array('left', 'center', 'center');
$table->data = array();

foreach ($protocols as $i) {
$hidetitle = $i->get_protocolname() ? get_string('clicktohide', 'repository') : get_string('clicktoshow', 'repository');
$hiddenshow = ' <a href="' . $this->baseurl . '&amp;hide=' . $i->get_protocolname() . '">'
$hidetitle = $i->get_protocolid() ? get_string('clicktohide', 'repository') : get_string('clicktoshow', 'repository');
$hiddenshow = ' <a href="' . $this->baseurl . '&amp;hide=' . $i->get_protocolid() . '">'
.'<img src="' . $CFG->pixpath . '/i/' . ($i->get_enable() ? 'hide' : 'show') . '.gif"'
.' alt="' . $hidetitle . '" '
.' title="' . $hidetitle . '" />'
.'</a>' . "\n";

$table->data[] = array($i->get_protocolname(), $hiddenshow);
$settingnames = $i->get_setting_names();
if (!empty($settingnames)) {
$settingsshow = ' <a href="' . $this->baseurl . '&amp;settings=' . $i->get_protocolid() . '">'
.$settingsstr
.'</a>' . "\n";
} else {
$settingsshow = "";
}
$table->data[] = array($i->get_protocolname(), $hiddenshow, $settingsshow);

//display a grey row if the type is defined as not visible
if (!$i->get_enable()){
Expand Down
24 changes: 23 additions & 1 deletion webservice/amf/lib.php
Expand Up @@ -35,6 +35,7 @@ final class amf_server extends webservice_server {
public function __construct() {
//set web service proctol name
$this->set_protocolname("Amf");
$this->set_protocolid("amf");
}

/**
Expand All @@ -54,12 +55,33 @@ public function run() {

/// run the Zend AMF server
$server = new Zend_Amf_Server();
$debugmode = get_config($this->get_protocolid(),'debug');
if (!empty($debugmode)) {
$server->setProduction(false);
} else {
$server->setProduction(true);
}
$server->setClass($classpath."_external");
$response = $server->handle();
echo $response;
}
}

/**
* Names of the server settings
* @return array
*/
public static function get_setting_names() {
return array('debug');
}

public function settings_form(&$mform) {
$debug = get_config($this->get_protocolid(), 'debug');
$debug = true;
if (empty($debug)) {
$debug = false;
}
$mform->addElement('checkbox', 'debug', get_string('amfdebug', 'webservice'));
}
}

?>
78 changes: 68 additions & 10 deletions webservice/lib.php
Expand Up @@ -400,9 +400,9 @@ public static function generate_webservice_description($file, $class){

}
}
// echo "<pre>";
// var_dump($description);
// echo "</pre>";
// echo "<pre>";
// var_dump($description);
// echo "</pre>";
return $description;

}
Expand Down Expand Up @@ -501,9 +501,9 @@ function display_webservices_availability($protocol){
echo "<br/>";

foreach(webservice_lib::get_list_protocols() as $wsprotocol) {
if (strtolower($wsprotocol->get_protocolname()) == strtolower($protocol)) {
echo get_string('protocolenable','webservice',array($wsprotocol->get_protocolname())).": ";
if ( get_config($wsprotocol-> get_protocolname(), "enable")) {
if (strtolower($wsprotocol->get_protocolid()) == strtolower($protocol)) {
echo get_string('protocolenable','webservice',array($wsprotocol->get_protocolid())).": ";
if ( get_config($wsprotocol-> get_protocolid(), "enable")) {
echo "<strong style=\"color:green\">".get_string('ok','webservice')."</strong>";
} else {
echo "<strong style=\"color:red\">".get_string('fail','webservice')."</strong>";
Expand Down Expand Up @@ -536,6 +536,12 @@ abstract class webservice_server {
*/
private $protocolname;

/**
* Web Service Protocol id (eg. soap, rest, xmlrpc...)
* @var String
*/
private $protocolid;

public function __construct() {
}

Expand All @@ -545,16 +551,35 @@ public function get_protocolname() {
return $this->protocolname;
}

public function get_protocolid() {
return $this->protocolid;
}

public function set_protocolname($protocolname) {
$this->protocolname = $protocolname;
}

public function set_protocolid($protocolid) {
$this->protocolid = $protocolid;
}

public function get_enable() {
return get_config($this->get_protocolname(), "enable");
return get_config($this->get_protocolid(), "enable");
}

public function set_enable($enable) {
set_config("enable", $enable, $this->get_protocolname());
set_config("enable", $enable, $this->get_protocolid());
}

/**
* Names of the server settings
* @return array
*/
public static function get_setting_names() {
return array();
}

public function settings_form(&$mform) {
}

}
Expand Down Expand Up @@ -591,8 +616,6 @@ public function definition() {
$this->username = $this->_customdata['username'];
$mform =& $this->_form;

$strrequired = get_string('required');

$mform->addElement('hidden', 'username', $this->username);
$param = new stdClass();
$param->username = $this->username;
Expand All @@ -605,4 +628,39 @@ public function definition() {
}
}

/**
* Form for web service server settings (administration)
*/
final class wssettings_form extends moodleform {
protected $settings;

/**
* Definition of the moodleform
*/
public function definition() {
global $DB,$CFG;
$settings = $this->_customdata['settings'];
$mform =& $this->_form;

$mform->addElement('hidden', 'settings', $settings);
$param = new stdClass();

require_once($CFG->dirroot . '/webservice/'. $settings . '/lib.php');
$servername = $settings.'_server';
$server = new $servername();
$server->settings_form($mform);

// set the data if we have some.
$data = array();
$option_names = $server->get_setting_names();
foreach ($option_names as $config) {
$data[$config] = get_config($settings, $config);
}
$this->set_data($data);


$this->add_action_buttons(true, get_string('savechanges','admin'));
}
}

?>
1 change: 1 addition & 0 deletions webservice/rest/lib.php
Expand Up @@ -33,6 +33,7 @@ final class rest_server extends webservice_server {
public function __construct() {

$this->set_protocolname("Rest");
$this->set_protocolid("rest");
}

/**
Expand Down
1 change: 1 addition & 0 deletions webservice/soap/lib.php
Expand Up @@ -34,6 +34,7 @@ final class soap_server extends webservice_server {

public function __construct() {
$this->set_protocolname("Soap");
$this->set_protocolid("soap");
}


Expand Down
3 changes: 2 additions & 1 deletion webservice/xmlrpc/lib.php
Expand Up @@ -33,7 +33,8 @@ final class xmlrpc_server extends webservice_server {

public function __construct() {

$this->set_protocolname("XMLRPC");
$this->set_protocolname("XML-RPC");
$this->set_protocolid("xmlrpc");
}

public function run() {
Expand Down

0 comments on commit f7631e7

Please sign in to comment.