From: jerome Date: Tue, 31 Mar 2009 03:29:01 +0000 (+0000) Subject: web service MDL-12886 administration: implement settings for servers (add amf debug... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=f7631e73976cec8787bb56319bd7032ef1840b48;p=moodle.git web service MDL-12886 administration: implement settings for servers (add amf debug option) --- diff --git a/admin/wsprotocols.php b/admin/wsprotocols.php index 4ba279ad9a..401509db30 100644 --- a/admin/wsprotocols.php +++ b/admin/wsprotocols.php @@ -8,6 +8,7 @@ $CFG->pagepath = 'admin/managewsprotocols'; $hide = optional_param('hide', '', PARAM_ALPHANUM); $username = optional_param('username', '', PARAM_ALPHANUM); +$settings = optional_param('settings', '', PARAM_ALPHANUM); $pagename = 'managews'; @@ -44,6 +45,40 @@ if (!empty($hide)) { $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)) { diff --git a/lang/en_utf8/webservice.php b/lang/en_utf8/webservice.php index b8a38b8d1e..8f05c55ae1 100644 --- a/lang/en_utf8/webservice.php +++ b/lang/en_utf8/webservice.php @@ -37,4 +37,6 @@ $string['ok'] = 'OK'; $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.
Alert the Moodle administrator to set it Off.'; +$string['amfdebug'] = 'AMF server debug mode'; + ?> diff --git a/lib/adminlib.php b/lib/adminlib.php index 8bbd04a72e..f771db5af2 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -4886,19 +4886,27 @@ class admin_setting_managewsprotocols extends admin_setting { 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 = ' ' + $hidetitle = $i->get_protocolid() ? get_string('clicktohide', 'repository') : get_string('clicktoshow', 'repository'); + $hiddenshow = ' ' .'' . $hidetitle . '' .'' . "\n"; - $table->data[] = array($i->get_protocolname(), $hiddenshow); + $settingnames = $i->get_setting_names(); + if (!empty($settingnames)) { + $settingsshow = ' ' + .$settingsstr + .'' . "\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()){ diff --git a/webservice/amf/lib.php b/webservice/amf/lib.php index 084d765607..4e5fb0da4a 100644 --- a/webservice/amf/lib.php +++ b/webservice/amf/lib.php @@ -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"); } /** @@ -54,12 +55,33 @@ final class amf_server extends webservice_server { /// 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')); + } +} ?> diff --git a/webservice/lib.php b/webservice/lib.php index 13c13f9bb6..f1ef37139f 100644 --- a/webservice/lib.php +++ b/webservice/lib.php @@ -400,9 +400,9 @@ final class webservice_lib { } } -// echo "
";
-//                var_dump($description);
-//                echo "
"; + // echo "
";
+        //                var_dump($description);
+        //                echo "
"; return $description; } @@ -501,9 +501,9 @@ final class webservice_lib { echo "
"; 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 "".get_string('ok','webservice').""; } else { echo "".get_string('fail','webservice').""; @@ -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() { } @@ -545,16 +551,35 @@ abstract class webservice_server { 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) { } } @@ -591,8 +616,6 @@ final class wsuser_form extends moodleform { $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; @@ -605,4 +628,39 @@ final class wsuser_form extends moodleform { } } +/** + * 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')); + } +} + ?> diff --git a/webservice/rest/lib.php b/webservice/rest/lib.php index 0d49a124a5..324ce2f457 100644 --- a/webservice/rest/lib.php +++ b/webservice/rest/lib.php @@ -33,6 +33,7 @@ final class rest_server extends webservice_server { public function __construct() { $this->set_protocolname("Rest"); + $this->set_protocolid("rest"); } /** diff --git a/webservice/soap/lib.php b/webservice/soap/lib.php index 4f13d9a137..5b0d530009 100644 --- a/webservice/soap/lib.php +++ b/webservice/soap/lib.php @@ -34,6 +34,7 @@ final class soap_server extends webservice_server { public function __construct() { $this->set_protocolname("Soap"); + $this->set_protocolid("soap"); } diff --git a/webservice/xmlrpc/lib.php b/webservice/xmlrpc/lib.php index 82fea052ce..f693c8f8f7 100644 --- a/webservice/xmlrpc/lib.php +++ b/webservice/xmlrpc/lib.php @@ -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() {