]> git.mjollnir.org Git - moodle.git/commitdiff
web service MDL-12886 administration: implement settings for servers (add amf debug...
authorjerome <jerome>
Tue, 31 Mar 2009 03:29:01 +0000 (03:29 +0000)
committerjerome <jerome>
Tue, 31 Mar 2009 03:29:01 +0000 (03:29 +0000)
admin/wsprotocols.php
lang/en_utf8/webservice.php
lib/adminlib.php
webservice/amf/lib.php
webservice/lib.php
webservice/rest/lib.php
webservice/soap/lib.php
webservice/xmlrpc/lib.php

index 4ba279ad9a55f8efda1a80b5e604944081021aaf..401509db30b302172d2ff0324c253b201f827253 100644 (file)
@@ -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)) {
index b8a38b8d1e7f94e1743d4002d114dcb236414b32..8f05c55ae133211482c7fe0eaf29a3b7e9f3abdb 100644 (file)
@@ -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. <br/>Alert the Moodle administrator to set it Off.';
+$string['amfdebug'] = 'AMF server debug mode';
+
 ?>
index 8bbd04a72e5bc2ef45faa03c897aceeb76f307b9..f771db5af2a34b2b6fb3b5fe7110a372b8e570af 100644 (file)
@@ -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 = ' <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()){
index 084d765607f381afe8f545cbcb49d820a546858f..4e5fb0da4ac9f395d32a5ef303122a1d9d020fc7 100644 (file)
@@ -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'));
+    }
+}
 
 ?>
index 13c13f9bb6bbd0c1067080b851645f038f6040ff..f1ef37139f85a593b7192267ea970deac18f16eb 100644 (file)
@@ -400,9 +400,9 @@ final class webservice_lib {
 
             }
         }
-//                echo "<pre>";
-//                var_dump($description);
-//                echo "</pre>";
+        //                echo "<pre>";
+        //                var_dump($description);
+        //                echo "</pre>";
         return $description;
 
     }
@@ -501,9 +501,9 @@ final class webservice_lib {
         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>";
@@ -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'));
+    }
+}
+
 ?>
index 0d49a124a51b7945ad0ae82d9152dbef428ab15d..324ce2f457a17699c0c7d2e4face1cc923a0d314 100644 (file)
@@ -33,6 +33,7 @@ final class rest_server extends webservice_server {
     public function __construct() {
 
         $this->set_protocolname("Rest");
+        $this->set_protocolid("rest");
     }
 
     /**
index 4f13d9a13781f74f5ae11539a25bf012ea32cd4b..5b0d5300093d0efebe0b9b051e73448694bb5236 100644 (file)
@@ -34,6 +34,7 @@ final class soap_server extends webservice_server {
 
     public function __construct() {
         $this->set_protocolname("Soap");
+        $this->set_protocolid("soap");
     }
 
   
index 82fea052ceb7fae6a426afee7bce7009a2c928c1..f693c8f8f7c2de26453b36ff0ed0fb73f58b6f59 100644 (file)
@@ -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() {