Merge branch 'MDL-48771-squashed' of git://github.com/timhunt/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 4 Apr 2017 02:37:26 +0000 (10:37 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 4 Apr 2017 02:37:26 +0000 (10:37 +0800)
257 files changed:
admin/auth_config.php
admin/oauth2callback.php
admin/tool/oauth2/classes/form/endpoint.php [new file with mode: 0644]
admin/tool/oauth2/classes/form/issuer.php [new file with mode: 0644]
admin/tool/oauth2/classes/form/user_field_mapping.php [new file with mode: 0644]
admin/tool/oauth2/classes/output/renderer.php [new file with mode: 0644]
admin/tool/oauth2/endpoints.php [new file with mode: 0644]
admin/tool/oauth2/issuers.php [new file with mode: 0644]
admin/tool/oauth2/lang/en/tool_oauth2.php [new file with mode: 0644]
admin/tool/oauth2/pix/auth.svg [new file with mode: 0644]
admin/tool/oauth2/pix/no.svg [new file with mode: 0644]
admin/tool/oauth2/pix/yes.svg [new file with mode: 0644]
admin/tool/oauth2/settings.php [new file with mode: 0644]
admin/tool/oauth2/userfieldmappings.php [new file with mode: 0644]
admin/tool/oauth2/version.php [new file with mode: 0644]
auth/cas/auth.php
auth/cas/config.html [deleted file]
auth/cas/db/upgrade.php
auth/cas/settings.php [new file with mode: 0644]
auth/cas/upgrade.txt [new file with mode: 0644]
auth/cas/version.php
auth/classes/output/login.php
auth/db/auth.php
auth/db/classes/admin_setting_special_auth_configtext.php [new file with mode: 0644]
auth/db/classes/task/sync_users.php
auth/db/config.html [deleted file]
auth/db/db/upgrade.php [new file with mode: 0644]
auth/db/settings.php [new file with mode: 0644]
auth/db/tests/db_test.php
auth/db/upgrade.txt
auth/db/version.php
auth/email/auth.php
auth/email/config.html [deleted file]
auth/email/db/upgrade.php [new file with mode: 0644]
auth/email/settings.php [new file with mode: 0644]
auth/email/upgrade.txt [new file with mode: 0644]
auth/email/version.php
auth/fc/auth.php
auth/fc/config.html [deleted file]
auth/fc/db/upgrade.php [new file with mode: 0644]
auth/fc/settings.php [new file with mode: 0644]
auth/fc/upgrade.txt [new file with mode: 0644]
auth/fc/version.php
auth/imap/auth.php
auth/imap/config.html [deleted file]
auth/imap/db/upgrade.php [new file with mode: 0644]
auth/imap/settings.php [new file with mode: 0644]
auth/imap/upgrade.txt [new file with mode: 0644]
auth/imap/version.php
auth/ldap/auth.php
auth/ldap/classes/admin_setting_special_contexts_configtext.php [new file with mode: 0644]
auth/ldap/classes/admin_setting_special_lowercase_configtext.php [new file with mode: 0644]
auth/ldap/classes/admin_setting_special_ntlm_configtext.php [new file with mode: 0644]
auth/ldap/config.html [deleted file]
auth/ldap/db/upgrade.php
auth/ldap/lang/en/auth_ldap.php
auth/ldap/settings.php [new file with mode: 0644]
auth/ldap/tests/plugin_test.php
auth/ldap/upgrade.txt
auth/ldap/version.php
auth/manual/auth.php
auth/manual/config.html [deleted file]
auth/manual/db/upgrade.php
auth/manual/settings.php [new file with mode: 0644]
auth/manual/tests/manual_test.php
auth/manual/upgrade.txt [new file with mode: 0644]
auth/manual/version.php
auth/mnet/auth.php
auth/mnet/config.html [deleted file]
auth/mnet/db/upgrade.php
auth/mnet/settings.php [new file with mode: 0644]
auth/mnet/upgrade.txt
auth/mnet/version.php
auth/nntp/auth.php
auth/nntp/config.html [deleted file]
auth/nntp/db/upgrade.php [new file with mode: 0644]
auth/nntp/settings.php [new file with mode: 0644]
auth/nntp/upgrade.txt [new file with mode: 0644]
auth/nntp/version.php
auth/none/auth.php
auth/none/config.html [deleted file]
auth/none/db/upgrade.php [new file with mode: 0644]
auth/none/settings.php [new file with mode: 0644]
auth/none/upgrade.txt [new file with mode: 0644]
auth/none/version.php
auth/oauth2/auth.php [new file with mode: 0644]
auth/oauth2/classes/api.php [new file with mode: 0644]
auth/oauth2/classes/auth.php [new file with mode: 0644]
auth/oauth2/classes/linked_login.php [new file with mode: 0644]
auth/oauth2/classes/output/renderer.php [new file with mode: 0644]
auth/oauth2/config.html [new file with mode: 0644]
auth/oauth2/confirm-account.php [new file with mode: 0644]
auth/oauth2/confirm-linkedlogin.php [new file with mode: 0644]
auth/oauth2/db/access.php [new file with mode: 0644]
auth/oauth2/db/install.xml [new file with mode: 0755]
auth/oauth2/db/upgrade.php [new file with mode: 0644]
auth/oauth2/lang/en/auth_oauth2.php [new file with mode: 0644]
auth/oauth2/lib.php [new file with mode: 0644]
auth/oauth2/linkedlogins.php [new file with mode: 0644]
auth/oauth2/login.php [new file with mode: 0644]
auth/oauth2/version.php [new file with mode: 0644]
auth/pam/auth.php
auth/pam/config.html [deleted file]
auth/pam/db/upgrade.php [new file with mode: 0644]
auth/pam/settings.php [new file with mode: 0644]
auth/pam/upgrade.txt [new file with mode: 0644]
auth/pam/version.php
auth/pop3/auth.php
auth/pop3/config.html [deleted file]
auth/pop3/db/upgrade.php [new file with mode: 0644]
auth/pop3/settings.php [new file with mode: 0644]
auth/pop3/upgrade.txt [new file with mode: 0644]
auth/pop3/version.php
auth/shibboleth/auth.php
auth/shibboleth/classes/admin_setting_special_idp_configtextarea.php [new file with mode: 0644]
auth/shibboleth/classes/admin_setting_special_wayf_select.php [new file with mode: 0644]
auth/shibboleth/config.html [deleted file]
auth/shibboleth/db/upgrade.php [new file with mode: 0644]
auth/shibboleth/index.php
auth/shibboleth/index_form.html
auth/shibboleth/lang/en/auth_shibboleth.php
auth/shibboleth/login.php
auth/shibboleth/settings.php [new file with mode: 0644]
auth/shibboleth/upgrade.txt [new file with mode: 0644]
auth/shibboleth/version.php
auth/upgrade.txt
auth/webservice/auth.php
availability/classes/info_module.php
availability/classes/info_section.php
availability/tests/fixtures/mock_info.php
availability/tests/info_test.php
backup/backupfilesedit_form.php
blocks/classes/external.php [new file with mode: 0644]
blocks/login/block_login.php
blocks/tests/externallib_test.php [new file with mode: 0644]
calendar/classes/export_form.php
calendar/export.php
course/tests/courseformat_test.php
files/renderer.php
lang/en/admin.php
lang/en/calendar.php
lang/en/repository.php
lang/en/role.php
lib/adminlib.php
lib/authlib.php
lib/blocklib.php
lib/classes/filetypes.php
lib/classes/oauth2/api.php [new file with mode: 0644]
lib/classes/oauth2/client.php [new file with mode: 0644]
lib/classes/oauth2/endpoint.php [new file with mode: 0644]
lib/classes/oauth2/issuer.php [new file with mode: 0644]
lib/classes/oauth2/refresh_system_tokens_task.php [new file with mode: 0644]
lib/classes/oauth2/rest.php [new file with mode: 0644]
lib/classes/oauth2/rest_exception.php [new file with mode: 0644]
lib/classes/oauth2/system_account.php [new file with mode: 0644]
lib/classes/oauth2/user_field_mapping.php [new file with mode: 0644]
lib/classes/plugin_manager.php
lib/classes/plugininfo/auth.php
lib/classes/user.php
lib/db/access.php
lib/db/install.xml [changed mode: 0644->0755]
lib/db/services.php
lib/db/tasks.php
lib/db/upgrade.php
lib/filelib.php
lib/filestorage/file_storage.php
lib/filestorage/stored_file.php
lib/form/editor.php
lib/form/filemanager.php
lib/grouplib.php
lib/modinfolib.php
lib/oauthlib.php
lib/templates/login.mustache
lib/tests/grouplib_test.php
lib/tests/oauth2_test.php [new file with mode: 0644]
lib/upgrade.txt
mod/assign/assignmentplugin.php
mod/assign/feedback/editpdf/classes/document_services.php
mod/assign/feedback/editpdf/classes/page_editor.php
mod/assign/feedback/editpdf/classes/pdf.php
mod/assign/feedback/editpdf/classes/renderer.php
mod/assign/feedback/editpdf/lang/en/assignfeedback_editpdf.php
mod/assign/feedback/editpdf/pix/comment_expcol.png [new file with mode: 0644]
mod/assign/feedback/editpdf/pix/comment_expcol.svg [new file with mode: 0644]
mod/assign/feedback/editpdf/styles.css
mod/assign/feedback/editpdf/yui/build/moodle-assignfeedback_editpdf-editor/moodle-assignfeedback_editpdf-editor-debug.js
mod/assign/feedback/editpdf/yui/build/moodle-assignfeedback_editpdf-editor/moodle-assignfeedback_editpdf-editor-min.js
mod/assign/feedback/editpdf/yui/build/moodle-assignfeedback_editpdf-editor/moodle-assignfeedback_editpdf-editor.js
mod/assign/feedback/editpdf/yui/src/editor/js/comment.js
mod/assign/feedback/editpdf/yui/src/editor/js/commentmenu.js
mod/assign/feedback/editpdf/yui/src/editor/js/commentsearch.js
mod/assign/feedback/editpdf/yui/src/editor/js/editor.js
mod/assign/feedback/editpdf/yui/src/editor/js/globals.js
mod/assign/lang/en/assign.php
mod/assign/lib.php
mod/assign/locallib.php
mod/assign/renderable.php
mod/assign/renderer.php
mod/assign/submission/file/locallib.php
mod/assign/submission/onlinetext/locallib.php
mod/data/backup/moodle2/backup_data_stepslib.php
mod/data/db/install.xml
mod/data/db/upgrade.php
mod/data/field/file/field.class.php
mod/data/lang/en/data.php
mod/data/lib.php
mod/data/mod_form.php
mod/data/styles.css
mod/data/tests/behat/completion_condition_entries.feature [new file with mode: 0644]
mod/data/tests/externallib_test.php
mod/data/tests/lib_test.php
mod/data/upgrade.txt
mod/data/version.php
mod/feedback/lib.php
mod/forum/classes/post_form.php
mod/forum/lib.php
mod/lesson/lib.php
mod/lti/lib.php
mod/quiz/lib.php
mod/scorm/lib.php
mod/survey/lib.php
mod/wiki/filesedit.php
mod/workshop/locallib.php
phpunit.xml.dist
pluginfile.php
question/type/essay/renderer.php
repository/areafiles/lib.php
repository/filepicker.js
repository/googledocs/classes/rest.php [new file with mode: 0644]
repository/googledocs/db/caches.php [new file with mode: 0644]
repository/googledocs/db/upgrade.php
repository/googledocs/lang/en/repository_googledocs.php
repository/googledocs/lib.php
repository/googledocs/tests/generator/lib.php
repository/googledocs/version.php
repository/lib.php
repository/onedrive/classes/access.php [new file with mode: 0644]
repository/onedrive/classes/remove_temp_access_task.php [new file with mode: 0644]
repository/onedrive/classes/rest.php [new file with mode: 0644]
repository/onedrive/db/access.php [new file with mode: 0644]
repository/onedrive/db/caches.php [new file with mode: 0644]
repository/onedrive/db/install.xml [new file with mode: 0644]
repository/onedrive/db/tasks.php [new file with mode: 0644]
repository/onedrive/db/upgrade.php [new file with mode: 0644]
repository/onedrive/importskydrive.php [new file with mode: 0644]
repository/onedrive/lang/en/repository_onedrive.php [new file with mode: 0644]
repository/onedrive/lib.php [new file with mode: 0644]
repository/onedrive/pix/icon.png [new file with mode: 0644]
repository/onedrive/version.php [new file with mode: 0644]
repository/repository_ajax.php
repository/skydrive/lang/en/repository_skydrive.php
repository/skydrive/lib.php
repository/upgrade.txt
theme/boost/templates/core/filemanager_modal_generallayout.mustache
theme/boost/templates/core/filemanager_selectlayout.mustache
theme/boost/templates/core/login.mustache
version.php

index b307cd7..0f9c7a0 100644 (file)
@@ -16,6 +16,9 @@ $err = array();
 
 $returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageauths";
 
+debugging("Use of config.html files in authentication plugins have been depreciated. " .
+          " Please migrate your plugin to use the admin settings API", DEBUG_DEVELOPER);
+
 // save configuration changes
 if ($frm = data_submitted() and confirm_sesskey()) {
 
@@ -86,12 +89,28 @@ exit;
 
 /// Functions /////////////////////////////////////////////////////////////////
 
-// Good enough for most auth plugins
-// but some may want a custom one if they are offering
-// other options
-// Note: lockconfig_ fields have special handling.
+
+/**
+ * auth field locking
+ * Good enough for most auth plugins
+ * but some may want a custom one if they are offering
+ * other options
+ * Note: lockconfig_ fields have special handling.
+ *
+ * @param string $auth authentication plugin shortname
+ * @param array $user_fields user profile fields
+ * @param string $helptext help text to be displayed at top of form
+ * @param boolean $retrieveopts Map fields or lock only.
+ * @param boolean $updateopts Allow remote updates
+ * @param array $customfields list of custom profile fields
+ * @deprecated since Moodle 3.3
+ */
 function print_auth_lock_options($auth, $user_fields, $helptext, $retrieveopts, $updateopts, $customfields = array()) {
     global $DB, $OUTPUT;
+    debugging("The function 'print_auth_lock_options' has been depreciated, " .
+              "Please migrate your code to use the admin settings API and use the function 'display_auth_lock_options' instead. ",
+              DEBUG_DEVELOPER);
+
     echo '<tr><td colspan="3">';
     if ($retrieveopts) {
         echo $OUTPUT->heading(get_string('auth_data_mapping', 'auth'));
index 08bb01d..709e28c 100644 (file)
 
 require_once(__DIR__ . '/../config.php');
 
+$error = optional_param('error', '', PARAM_RAW);
+if ($error) {
+    $message = optional_param('error_description', '', PARAM_RAW);
+    if ($message) {
+        print_error($message);
+    } else {
+        print_error($error);
+    }
+    die();
+}
+
 // The authorization code generated by the authorization server.
 $code = required_param('code', PARAM_RAW);
 // The state parameter we've given (used in moodle as a redirect url).
diff --git a/admin/tool/oauth2/classes/form/endpoint.php b/admin/tool/oauth2/classes/form/endpoint.php
new file mode 100644 (file)
index 0000000..d033f3b
--- /dev/null
@@ -0,0 +1,81 @@
+<?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/>.
+
+/**
+ * This file contains the form add/update oauth2 endpoint.
+ *
+ * @package   tool_oauth2
+ * @copyright 2017 Damyon Wiese
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_oauth2\form;
+defined('MOODLE_INTERNAL') || die();
+
+use stdClass;
+use core\form\persistent;
+
+/**
+ * Issuer form.
+ *
+ * @package   tool_oauth2
+ * @copyright 2017 Damyon Wiese
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class endpoint extends persistent {
+
+    /** @var string $persistentclass */
+    protected static $persistentclass = 'core\\oauth2\\endpoint';
+
+    /** @var array $fieldstoremove */
+    protected static $fieldstoremove = array('submitbutton', 'action');
+
+    /**
+     * Define the form - called by parent constructor
+     */
+    public function definition() {
+        global $PAGE;
+
+        $mform = $this->_form;
+        $endpoint = $this->get_persistent();
+
+        // Name.
+        $mform->addElement('text', 'name', get_string('endpointname', 'tool_oauth2'));
+        $mform->addRule('name', null, 'required', null, 'client');
+        $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+        $mform->addHelpButton('name', 'endpointname', 'tool_oauth2');
+
+        // Url.
+        $mform->addElement('text', 'url', get_string('endpointurl', 'tool_oauth2'));
+        $mform->addRule('url', null, 'required', null, 'client');
+        $mform->addRule('url', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client');
+        $mform->addHelpButton('url', 'endpointurl', 'tool_oauth2');
+
+        $mform->addElement('hidden', 'action', 'edit');
+        $mform->setType('action', PARAM_ALPHA);
+
+        $mform->addElement('hidden', 'issuerid', $endpoint->get('issuerid'));
+        $mform->setType('issuerid', PARAM_INT);
+        $mform->setConstant('issuerid', $this->_customdata['issuerid']);
+
+        $mform->addElement('hidden', 'id', $endpoint->get('id'));
+        $mform->setType('id', PARAM_INT);
+
+        $this->add_action_buttons(true, get_string('savechanges', 'tool_oauth2'));
+    }
+
+}
+
diff --git a/admin/tool/oauth2/classes/form/issuer.php b/admin/tool/oauth2/classes/form/issuer.php
new file mode 100644 (file)
index 0000000..3a0b64d
--- /dev/null
@@ -0,0 +1,138 @@
+<?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/>.
+
+/**
+ * This file contains the form add/update oauth2 issuer.
+ *
+ * @package   tool_oauth2
+ * @copyright 2017 Damyon Wiese
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_oauth2\form;
+defined('MOODLE_INTERNAL') || die();
+
+use stdClass;
+use core\form\persistent;
+
+/**
+ * Issuer form.
+ *
+ * @package   tool_oauth2
+ * @copyright 2017 Damyon Wiese
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class issuer extends persistent {
+
+    /** @var string $persistentclass */
+    protected static $persistentclass = 'core\\oauth2\\issuer';
+
+    /** @var array $fieldstoremove */
+    protected static $fieldstoremove = array('submitbutton', 'action');
+
+    /**
+     * Define the form - called by parent constructor
+     */
+    public function definition() {
+        global $PAGE, $OUTPUT;
+
+        $mform = $this->_form;
+        $issuer = $this->get_persistent();
+
+        $docslink = optional_param('docslink', '', PARAM_ALPHAEXT);
+        if ($docslink) {
+            $name = s($issuer->get('name'));
+            $mform->addElement('html', $OUTPUT->doc_link($docslink, get_string('issuersetuptype', 'tool_oauth2', $name)));
+        } else {
+            $mform->addElement('html', $OUTPUT->page_doc_link(get_string('issuersetup', 'tool_oauth2')));
+        }
+
+        // Name.
+        $mform->addElement('text', 'name', get_string('issuername', 'tool_oauth2'));
+        $mform->addRule('name', null, 'required', null, 'client');
+        $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+        $mform->addHelpButton('name', 'issuername', 'tool_oauth2');
+
+        // Client ID.
+        $mform->addElement('text', 'clientid', get_string('issuerclientid', 'tool_oauth2'));
+        $mform->addRule('clientid', null, 'required', null, 'client');
+        $mform->addRule('clientid', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+        $mform->addHelpButton('clientid', 'issuerclientid', 'tool_oauth2');
+
+        // Client Secret.
+        $mform->addElement('text', 'clientsecret', get_string('issuerclientsecret', 'tool_oauth2'));
+        $mform->addRule('clientsecret', null, 'required', null, 'client');
+        $mform->addRule('clientsecret', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+        $mform->addHelpButton('clientsecret', 'issuerclientsecret', 'tool_oauth2');
+
+        // Login scopes.
+        $mform->addElement('text', 'loginscopes', get_string('issuerloginscopes', 'tool_oauth2'));
+        $mform->addRule('loginscopes', null, 'required', null, 'client');
+        $mform->addRule('loginscopes', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+        $mform->addHelpButton('loginscopes', 'issuerloginscopes', 'tool_oauth2');
+
+        // Login scopes offline.
+        $mform->addElement('text', 'loginscopesoffline', get_string('issuerloginscopesoffline', 'tool_oauth2'));
+        $mform->addRule('loginscopesoffline', null, 'required', null, 'client');
+        $mform->addRule('loginscopesoffline', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+        $mform->addHelpButton('loginscopesoffline', 'issuerloginscopesoffline', 'tool_oauth2');
+
+        // Login params.
+        $mform->addElement('text', 'loginparams', get_string('issuerloginparams', 'tool_oauth2'));
+        $mform->addRule('loginparams', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+        $mform->addHelpButton('loginparams', 'issuerloginparams', 'tool_oauth2');
+
+        // Login params offline.
+        $mform->addElement('text', 'loginparamsoffline', get_string('issuerloginparamsoffline', 'tool_oauth2'));
+        $mform->addRule('loginparamsoffline', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+        $mform->addHelpButton('loginparamsoffline', 'issuerloginparamsoffline', 'tool_oauth2');
+
+        // Base Url.
+        $mform->addElement('text', 'baseurl', get_string('issuerbaseurl', 'tool_oauth2'));
+        $mform->addRule('baseurl', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client');
+        $mform->addHelpButton('baseurl', 'issuerbaseurl', 'tool_oauth2');
+
+        // Allowed Domains.
+        $mform->addElement('text', 'alloweddomains', get_string('issueralloweddomains', 'tool_oauth2'));
+        $mform->addRule('alloweddomains', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client');
+        $mform->addHelpButton('alloweddomains', 'issueralloweddomains', 'tool_oauth2');
+
+        // Image.
+        $mform->addElement('text', 'image', get_string('issuerimage', 'tool_oauth2'), 'maxlength="1024"');
+        $mform->addRule('image', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client');
+        $mform->addHelpButton('image', 'issuername', 'tool_oauth2');
+
+        // Show on login page.
+        $mform->addElement('checkbox', 'showonloginpage', get_string('issuershowonloginpage', 'tool_oauth2'));
+        $mform->addHelpButton('showonloginpage', 'issuershowonloginpage', 'tool_oauth2');
+
+        $mform->addElement('hidden', 'sortorder');
+        $mform->setType('sortorder', PARAM_INT);
+
+        $mform->addElement('hidden', 'action', 'edit');
+        $mform->setType('action', PARAM_ALPHA);
+
+        $mform->addElement('hidden', 'enabled', $issuer->get('enabled'));
+        $mform->setType('enabled', PARAM_BOOL);
+
+        $mform->addElement('hidden', 'id', $issuer->get('id'));
+        $mform->setType('id', PARAM_INT);
+
+        $this->add_action_buttons(true, get_string('savechanges', 'tool_oauth2'));
+    }
+
+}
+
diff --git a/admin/tool/oauth2/classes/form/user_field_mapping.php b/admin/tool/oauth2/classes/form/user_field_mapping.php
new file mode 100644 (file)
index 0000000..aa118e8
--- /dev/null
@@ -0,0 +1,80 @@
+<?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/>.
+
+/**
+ * This file contains the form add/update oauth2 user_field_mapping.
+ *
+ * @package   tool_oauth2
+ * @copyright 2017 Damyon Wiese
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_oauth2\form;
+defined('MOODLE_INTERNAL') || die();
+
+use stdClass;
+use core\form\persistent;
+
+/**
+ * Issuer form.
+ *
+ * @package   tool_oauth2
+ * @copyright 2017 Damyon Wiese
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class user_field_mapping extends persistent {
+
+    /** @var string $persistentclass */
+    protected static $persistentclass = 'core\\oauth2\\user_field_mapping';
+
+    /** @var array $fieldstoremove */
+    protected static $fieldstoremove = array('submitbutton', 'action');
+
+    /**
+     * Define the form - called by parent constructor
+     */
+    public function definition() {
+        global $PAGE;
+
+        $mform = $this->_form;
+        $userfieldmapping = $this->get_persistent();
+
+        // External.
+        $mform->addElement('text', 'externalfield', get_string('userfieldexternalfield', 'tool_oauth2'));
+        $mform->addRule('externalfield', null, 'required', null, 'client');
+        $mform->addRule('externalfield', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+        $mform->addHelpButton('externalfield', 'userfieldexternalfield', 'tool_oauth2');
+
+        // Internal.
+        $choices = $userfieldmapping->get_internalfield_list();
+        $mform->addElement('select', 'internalfield', get_string('userfieldinternalfield', 'tool_oauth2'), $choices);
+        $mform->addHelpButton('internalfield', 'userfieldinternalfield', 'tool_oauth2');
+
+        $mform->addElement('hidden', 'action', 'edit');
+        $mform->setType('action', PARAM_ALPHA);
+
+        $mform->addElement('hidden', 'issuerid', $userfieldmapping->get('issuerid'));
+        $mform->setConstant('issuerid', $this->_customdata['issuerid']);
+        $mform->setType('issuerid', PARAM_INT);
+
+        $mform->addElement('hidden', 'id', $userfieldmapping->get('id'));
+        $mform->setType('id', PARAM_INT);
+
+        $this->add_action_buttons(true, get_string('savechanges', 'tool_oauth2'));
+    }
+
+}
+
diff --git a/admin/tool/oauth2/classes/output/renderer.php b/admin/tool/oauth2/classes/output/renderer.php
new file mode 100644 (file)
index 0000000..b838d0a
--- /dev/null
@@ -0,0 +1,319 @@
+<?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/>.
+
+/**
+ * Output rendering for the plugin.
+ *
+ * @package     tool_oauth2
+ * @copyright   2017 Damyon Wiese
+ * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+namespace tool_oauth2\output;
+
+use plugin_renderer_base;
+use html_table;
+use html_table_cell;
+use html_table_row;
+use html_writer;
+use core\oauth2\issuer;
+use core\oauth2\api;
+use moodle_url;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Implements the plugin renderer
+ *
+ * @copyright 2017 Damyon Wiese
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class renderer extends plugin_renderer_base {
+    /**
+     * This function will render one beautiful table with all the issuers.
+     *
+     * @param \core\oauth2\issuer[] $issuers - list of all issuers.
+     * @return string HTML to output.
+     */
+    public function issuers_table($issuers) {
+        global $CFG;
+
+        $table = new html_table();
+        $table->head  = [
+            get_string('name'),
+            get_string('configuredstatus', 'tool_oauth2'),
+            get_string('loginissuer', 'tool_oauth2'),
+            get_string('discoverystatus', 'tool_oauth2') . ' ' . $this->help_icon('discovered', 'tool_oauth2'),
+            get_string('systemauthstatus', 'tool_oauth2') . ' ' . $this->help_icon('systemaccountconnected', 'tool_oauth2'),
+            get_string('edit'),
+        ];
+        $table->attributes['class'] = 'admintable generaltable';
+        $data = [];
+
+        $index = 0;
+
+        foreach ($issuers as $issuer) {
+            // We need to handle the first and last ones specially.
+            $first = false;
+            if ($index == 0) {
+                $first = true;
+            }
+            $last = false;
+            if ($index == count($issuers) - 1) {
+                $last = true;
+            }
+
+            // Name.
+            $name = $issuer->get('name');
+            $image = $issuer->get('image');
+            if ($image) {
+                $name = '<img width="24" height="24" alt="" src="' . s($image) . '"> ' . s($name);
+            }
+            $namecell = new html_table_cell($name);
+            $namecell->header = true;
+
+            // Configured.
+            if ($issuer->is_configured()) {
+                $configured = $this->pix_icon('yes', get_string('configured', 'tool_oauth2'), 'tool_oauth2');
+            } else {
+                $configured = $this->pix_icon('no', get_string('notconfigured', 'tool_oauth2'), 'tool_oauth2');
+            }
+            $configuredstatuscell = new html_table_cell($configured);
+
+            // Login issuer.
+            if (!empty($issuer->get('showonloginpage'))) {
+                $loginissuer = $this->pix_icon('yes', get_string('loginissuer', 'tool_oauth2'), 'tool_oauth2');
+            } else {
+                $loginissuer = $this->pix_icon('no', get_string('notloginissuer', 'tool_oauth2'), 'tool_oauth2');
+            }
+            $loginissuerstatuscell = new html_table_cell($loginissuer);
+
+            // Discovered.
+            if (!empty($issuer->get('scopessupported'))) {
+                $discovered = $this->pix_icon('yes', get_string('discovered', 'tool_oauth2'), 'tool_oauth2');
+            } else {
+                if (!empty($issuer->get_endpoint_url('discovery'))) {
+                    $discovered = $this->pix_icon('no', get_string('notdiscovered', 'tool_oauth2'), 'tool_oauth2');
+                } else {
+                    $discovered = '-';
+                }
+            }
+
+            $discoverystatuscell = new html_table_cell($discovered);
+
+            // Connected.
+            if ($issuer->is_system_account_connected()) {
+                $systemaccount = \core\oauth2\api::get_system_account($issuer);
+                $systemauth = s($systemaccount->get('email')) . ' (' . s($systemaccount->get('username')). ') ';
+                $systemauth .= $this->pix_icon('yes', get_string('systemaccountconnected', 'tool_oauth2'), 'tool_oauth2');
+            } else {
+                $systemauth = $this->pix_icon('no', get_string('systemaccountnotconnected', 'tool_oauth2'), 'tool_oauth2');
+            }
+
+            $params = ['id' => $issuer->get('id'), 'action' => 'auth'];
+            $authurl = new moodle_url('/admin/tool/oauth2/issuers.php', $params);
+            $icon = $this->pix_icon('auth', get_string('connectsystemaccount', 'tool_oauth2'), 'tool_oauth2');
+            $authlink = html_writer::link($authurl, $icon);
+            $systemauth .= ' ' . $authlink;
+
+            $systemauthstatuscell = new html_table_cell($systemauth);
+
+            $links = '';
+            // Action links.
+            $editurl = new moodle_url('/admin/tool/oauth2/issuers.php', ['id' => $issuer->get('id'), 'action' => 'edit']);
+            $editlink = html_writer::link($editurl, $this->pix_icon('t/edit', get_string('edit')));
+            $links .= ' ' . $editlink;
+
+            // Endpoints.
+            $editendpointsurl = new moodle_url('/admin/tool/oauth2/endpoints.php', ['issuerid' => $issuer->get('id')]);
+            $str = get_string('editendpoints', 'tool_oauth2');
+            $editendpointlink = html_writer::link($editendpointsurl, $this->pix_icon('t/viewdetails', $str));
+            $links .= ' ' . $editendpointlink;
+
+            // User field mapping.
+            $params = ['issuerid' => $issuer->get('id')];
+            $edituserfieldmappingsurl = new moodle_url('/admin/tool/oauth2/userfieldmappings.php', $params);
+            $str = get_string('edituserfieldmappings', 'tool_oauth2');
+            $edituserfieldmappinglink = html_writer::link($edituserfieldmappingsurl, $this->pix_icon('t/user', $str));
+            $links .= ' ' . $edituserfieldmappinglink;
+
+            // Delete.
+            $deleteurl = new moodle_url('/admin/tool/oauth2/issuers.php', ['id' => $issuer->get('id'), 'action' => 'delete']);
+            $deletelink = html_writer::link($deleteurl, $this->pix_icon('t/delete', get_string('delete')));
+            $links .= ' ' . $deletelink;
+            // Enable / Disable.
+            if ($issuer->get('enabled')) {
+                // Disable.
+                $disableparams = ['id' => $issuer->get('id'), 'sesskey' => sesskey(), 'action' => 'disable'];
+                $disableurl = new moodle_url('/admin/tool/oauth2/issuers.php', $disableparams);
+                $disablelink = html_writer::link($disableurl, $this->pix_icon('t/hide', get_string('disable')));
+                $links .= ' ' . $disablelink;
+            } else {
+                // Enable.
+                $enableparams = ['id' => $issuer->get('id'), 'sesskey' => sesskey(), 'action' => 'enable'];
+                $enableurl = new moodle_url('/admin/tool/oauth2/issuers.php', $enableparams);
+                $enablelink = html_writer::link($enableurl, $this->pix_icon('t/show', get_string('enable')));
+                $links .= ' ' . $enablelink;
+            }
+            if (!$last) {
+                // Move down.
+                $params = ['id' => $issuer->get('id'), 'action' => 'movedown', 'sesskey' => sesskey()];
+                $movedownurl = new moodle_url('/admin/tool/oauth2/issuers.php', $params);
+                $movedownlink = html_writer::link($movedownurl, $this->pix_icon('t/down', get_string('movedown')));
+                $links .= ' ' . $movedownlink;
+            }
+            if (!$first) {
+                // Move up.
+                $params = ['id' => $issuer->get('id'), 'action' => 'moveup', 'sesskey' => sesskey()];
+                $moveupurl = new moodle_url('/admin/tool/oauth2/issuers.php', $params);
+                $moveuplink = html_writer::link($moveupurl, $this->pix_icon('t/up', get_string('moveup')));
+                $links .= ' ' . $moveuplink;
+            }
+
+            $editcell = new html_table_cell($links);
+
+            $row = new html_table_row([
+                $namecell,
+                $configuredstatuscell,
+                $loginissuerstatuscell,
+                $discoverystatuscell,
+                $systemauthstatuscell,
+                $editcell,
+            ]);
+
+            $data[] = $row;
+            $index++;
+        }
+        $table->data = $data;
+        return html_writer::table($table);
+    }
+
+    /**
+     * This function will render one beautiful table with all the endpoints.
+     *
+     * @param \core\oauth2\endpoint[] $endpoints - list of all endpoints.
+     * @param int $issuerid
+     * @return string HTML to output.
+     */
+    public function endpoints_table($endpoints, $issuerid) {
+        global $CFG;
+
+        $table = new html_table();
+        $table->head  = [
+            get_string('name'),
+            get_string('url'),
+            get_string('edit'),
+        ];
+        $table->attributes['class'] = 'admintable generaltable';
+        $data = [];
+
+        $index = 0;
+
+        foreach ($endpoints as $endpoint) {
+            // Name.
+            $name = $endpoint->get('name');
+            $namecell = new html_table_cell(s($name));
+            $namecell->header = true;
+
+            // Url.
+            $url = $endpoint->get('url');
+            $urlcell = new html_table_cell(s($url));
+
+            $links = '';
+            // Action links.
+            $editparams = ['issuerid' => $issuerid, 'endpointid' => $endpoint->get('id'), 'action' => 'edit'];
+            $editurl = new moodle_url('/admin/tool/oauth2/endpoints.php', $editparams);
+            $editlink = html_writer::link($editurl, $this->pix_icon('t/edit', get_string('edit')));
+            $links .= ' ' . $editlink;
+
+            // Delete.
+            $deleteparams = ['issuerid' => $issuerid, 'endpointid' => $endpoint->get('id'), 'action' => 'delete'];
+            $deleteurl = new moodle_url('/admin/tool/oauth2/endpoints.php', $deleteparams);
+            $deletelink = html_writer::link($deleteurl, $this->pix_icon('t/delete', get_string('delete')));
+            $links .= ' ' . $deletelink;
+
+            $editcell = new html_table_cell($links);
+
+            $row = new html_table_row([
+                $namecell,
+                $urlcell,
+                $editcell,
+            ]);
+
+            $data[] = $row;
+            $index++;
+        }
+        $table->data = $data;
+        return html_writer::table($table);
+    }
+
+    /**
+     * This function will render one beautiful table with all the user_field_mappings.
+     *
+     * @param \core\oauth2\user_field_mapping[] $userfieldmappings - list of all user_field_mappings.
+     * @param int $issuerid
+     * @return string HTML to output.
+     */
+    public function user_field_mappings_table($userfieldmappings, $issuerid) {
+        global $CFG;
+
+        $table = new html_table();
+        $table->head  = [
+            get_string('userfieldexternalfield', 'tool_oauth2'),
+            get_string('userfieldinternalfield', 'tool_oauth2'),
+            get_string('edit'),
+        ];
+        $table->attributes['class'] = 'admintable generaltable';
+        $data = [];
+
+        $index = 0;
+
+        foreach ($userfieldmappings as $userfieldmapping) {
+            // External field.
+            $externalfield = $userfieldmapping->get('externalfield');
+            $externalfieldcell = new html_table_cell(s($externalfield));
+
+            // Internal field.
+            $internalfield = $userfieldmapping->get('internalfield');
+            $internalfieldcell = new html_table_cell(s($internalfield));
+
+            $links = '';
+            // Action links.
+            $editparams = ['issuerid' => $issuerid, 'userfieldmappingid' => $userfieldmapping->get('id'), 'action' => 'edit'];
+            $editurl = new moodle_url('/admin/tool/oauth2/userfieldmappings.php', $editparams);
+            $editlink = html_writer::link($editurl, $this->pix_icon('t/edit', get_string('edit')));
+            $links .= ' ' . $editlink;
+
+            // Delete.
+            $deleteparams = ['issuerid' => $issuerid, 'userfieldmappingid' => $userfieldmapping->get('id'), 'action' => 'delete'];
+            $deleteurl = new moodle_url('/admin/tool/oauth2/userfieldmappings.php', $deleteparams);
+            $deletelink = html_writer::link($deleteurl, $this->pix_icon('t/delete', get_string('delete')));
+            $links .= ' ' . $deletelink;
+
+            $editcell = new html_table_cell($links);
+
+            $row = new html_table_row([
+                $externalfieldcell,
+                $internalfieldcell,
+                $editcell,
+            ]);
+
+            $data[] = $row;
+            $index++;
+        }
+        $table->data = $data;
+        return html_writer::table($table);
+    }
+}
diff --git a/admin/tool/oauth2/endpoints.php b/admin/tool/oauth2/endpoints.php
new file mode 100644 (file)
index 0000000..cf3a3fe
--- /dev/null
@@ -0,0 +1,128 @@
+<?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/>.
+
+/**
+ * OAuth 2 Endpoing Configuration page.
+ *
+ * @package    tool_oauth2
+ * @copyright  2017 Damyon Wiese <damyon@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(__DIR__ . '/../../../config.php');
+require_once($CFG->libdir.'/adminlib.php');
+require_once($CFG->libdir.'/tablelib.php');
+
+$PAGE->set_url('/admin/tool/oauth2/endpoints.php', ['issuerid' => required_param('issuerid', PARAM_INT)]);
+$PAGE->set_context(context_system::instance());
+$PAGE->set_pagelayout('admin');
+$strheading = get_string('pluginname', 'tool_oauth2');
+$PAGE->set_title($strheading);
+$PAGE->set_heading($strheading);
+
+require_login();
+
+require_capability('moodle/site:config', context_system::instance());
+
+$renderer = $PAGE->get_renderer('tool_oauth2');
+
+$action = optional_param('action', '', PARAM_ALPHAEXT);
+$issuerid = required_param('issuerid', PARAM_INT);
+$endpointid = optional_param('endpointid', '', PARAM_INT);
+$endpoint = null;
+$mform = null;
+
+$issuer = \core\oauth2\api::get_issuer($issuerid);
+if (!$issuer) {
+    print_error('invaliddata');
+}
+$PAGE->navbar->override_active_url(new moodle_url('/admin/tool/oauth2/issuers.php'), true);
+
+if (!empty($endpointid)) {
+    $endpoint = \core\oauth2\api::get_endpoint($endpointid);
+}
+
+if ($action == 'edit') {
+    if ($endpoint) {
+        $strparams = [ 'issuer' => s($issuer->get('name')), 'endpoint' => s($endpoint->get('name')) ];
+        $PAGE->navbar->add(get_string('editendpoint', 'tool_oauth2', $strparams));
+    } else {
+        $PAGE->navbar->add(get_string('createnewendpoint', 'tool_oauth2', s($issuer->get('name'))));
+    }
+
+    $mform = new \tool_oauth2\form\endpoint(null, ['persistent' => $endpoint, 'issuerid' => $issuerid]);
+}
+
+if ($mform && $mform->is_cancelled()) {
+    redirect(new moodle_url('/admin/tool/oauth2/endpoints.php', ['issuerid' => $issuerid]));
+} else if ($action == 'edit') {
+
+    if ($data = $mform->get_data()) {
+
+        try {
+            if (!empty($data->id)) {
+                core\oauth2\api::update_endpoint($data);
+            } else {
+                core\oauth2\api::create_endpoint($data);
+            }
+            redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
+        } catch (Exception $e) {
+            redirect($PAGE->url, $e->getMessage(), null, \core\output\notification::NOTIFY_ERROR);
+        }
+    } else {
+        echo $OUTPUT->header();
+        if ($endpoint) {
+            $strparams = [ 'issuer' => s($issuer->get('name')), 'endpoint' => s($endpoint->get('name')) ];
+            echo $OUTPUT->heading(get_string('editendpoint', 'tool_oauth2', $strparams));
+        } else {
+            echo $OUTPUT->heading(get_string('createnewendpoint', 'tool_oauth2', s($issuer->get('name'))));
+        }
+        $mform->display();
+        echo $OUTPUT->footer();
+    }
+
+} else if ($action == 'delete') {
+
+    if (!optional_param('confirm', false, PARAM_BOOL)) {
+        $continueparams = [
+            'action' => 'delete',
+            'issuerid' => $issuerid,
+            'endpointid' => $endpointid,
+            'sesskey' => sesskey(),
+            'confirm' => true
+        ];
+        $continueurl = new moodle_url('/admin/tool/oauth2/endpoints.php', $continueparams);
+        $cancelurl = new moodle_url('/admin/tool/oauth2/endpoints.php');
+        echo $OUTPUT->header();
+        $strparams = [ 'issuer' => s($issuer->get('name')), 'endpoint' => s($endpoint->get('name')) ];
+        echo $OUTPUT->confirm(get_string('deleteendpointconfirm', 'tool_oauth2', $strparams), $continueurl, $cancelurl);
+        echo $OUTPUT->footer();
+    } else {
+        require_sesskey();
+        core\oauth2\api::delete_endpoint($endpointid);
+        redirect($PAGE->url, get_string('endpointdeleted', 'tool_oauth2'), null, \core\output\notification::NOTIFY_SUCCESS);
+    }
+
+} else {
+    echo $OUTPUT->header();
+    echo $OUTPUT->heading(get_string('endpointsforissuer', 'tool_oauth2', s($issuer->get('name'))));
+    $endpoints = core\oauth2\api::get_endpoints($issuer);
+    echo $renderer->endpoints_table($endpoints, $issuerid);
+
+    $addurl = new moodle_url('/admin/tool/oauth2/endpoints.php', ['action' => 'edit', 'issuerid' => $issuerid]);
+    echo $renderer->single_button($addurl, get_string('createnewendpoint', 'tool_oauth2', s($issuer->get('name'))));
+    echo $OUTPUT->footer();
+}
diff --git a/admin/tool/oauth2/issuers.php b/admin/tool/oauth2/issuers.php
new file mode 100644 (file)
index 0000000..5bb4c4f
--- /dev/null
@@ -0,0 +1,177 @@
+<?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/>.
+
+/**
+ * OAuth 2 Configuration page.
+ *
+ * @package    tool_oauth2
+ * @copyright  2017 Damyon Wiese <damyon@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(__DIR__ . '/../../../config.php');
+require_once($CFG->libdir.'/adminlib.php');
+require_once($CFG->libdir.'/tablelib.php');
+
+$PAGE->set_url('/admin/tool/oauth2/issuers.php');
+$PAGE->set_context(context_system::instance());
+$PAGE->set_pagelayout('admin');
+$strheading = get_string('pluginname', 'tool_oauth2');
+$PAGE->set_title($strheading);
+$PAGE->set_heading($strheading);
+
+require_login();
+
+require_capability('moodle/site:config', context_system::instance());
+
+$renderer = $PAGE->get_renderer('tool_oauth2');
+
+$action = optional_param('action', '', PARAM_ALPHAEXT);
+$issuerid = optional_param('id', '', PARAM_RAW);
+$issuer = null;
+$mform = null;
+
+if ($issuerid) {
+    $issuer = \core\oauth2\api::get_issuer($issuerid);
+    if (!$issuer) {
+        print_error('invaliddata');
+    }
+}
+
+if ($action == 'edit') {
+    if ($issuer) {
+        $PAGE->navbar->add(get_string('editissuer', 'tool_oauth2', s($issuer->get('name'))));
+    } else {
+        $PAGE->navbar->add(get_string('createnewissuer', 'tool_oauth2'));
+    }
+
+    $mform = new \tool_oauth2\form\issuer(null, ['persistent' => $issuer]);
+}
+
+if ($mform && $mform->is_cancelled()) {
+    redirect(new moodle_url('/admin/tool/oauth2/issuers.php'));
+} else if ($action == 'edit') {
+
+    if ($data = $mform->get_data()) {
+        try {
+            if (!empty($data->id)) {
+                core\oauth2\api::update_issuer($data);
+            } else {
+                core\oauth2\api::create_issuer($data);
+            }
+            redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
+        } catch (Exception $e) {
+            redirect($PAGE->url, $e->getMessage(), null, \core\output\notification::NOTIFY_ERROR);
+        }
+    } else {
+        echo $OUTPUT->header();
+        if ($issuer) {
+            echo $OUTPUT->heading(get_string('editissuer', 'tool_oauth2', s($issuer->get('name'))));
+        } else {
+            echo $OUTPUT->heading(get_string('createnewissuer', 'tool_oauth2'));
+        }
+        $mform->display();
+        echo $OUTPUT->footer();
+    }
+} else if ($action == 'edittemplate') {
+
+    $type = required_param('type', PARAM_ALPHA);
+    $docs = required_param('docslink', PARAM_ALPHAEXT);
+    require_sesskey();
+    $issuer = core\oauth2\api::create_standard_issuer($type);
+    $params = ['action' => 'edit', 'id' => $issuer->get('id'), 'docslink' => $docs];
+    $editurl = new moodle_url('/admin/tool/oauth2/issuers.php', $params);
+    redirect($editurl, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
+} else if ($action == 'enable') {
+
+    require_sesskey();
+    core\oauth2\api::enable_issuer($issuerid);
+    redirect($PAGE->url, get_string('issuerenabled', 'tool_oauth2'), null, \core\output\notification::NOTIFY_SUCCESS);
+
+} else if ($action == 'disable') {
+
+    require_sesskey();
+    core\oauth2\api::disable_issuer($issuerid);
+    redirect($PAGE->url, get_string('issuerdisabled', 'tool_oauth2'), null, \core\output\notification::NOTIFY_SUCCESS);
+
+} else if ($action == 'delete') {
+
+    if (!optional_param('confirm', false, PARAM_BOOL)) {
+        $continueparams = ['action' => 'delete', 'id' => $issuerid, 'sesskey' => sesskey(), 'confirm' => true];
+        $continueurl = new moodle_url('/admin/tool/oauth2/issuers.php', $continueparams);
+        $cancelurl = new moodle_url('/admin/tool/oauth2/issuers.php');
+        echo $OUTPUT->header();
+        echo $OUTPUT->confirm(get_string('deleteconfirm', 'tool_oauth2', s($issuer->get('name'))), $continueurl, $cancelurl);
+        echo $OUTPUT->footer();
+    } else {
+        require_sesskey();
+        core\oauth2\api::delete_issuer($issuerid);
+        redirect($PAGE->url, get_string('issuerdeleted', 'tool_oauth2'), null, \core\output\notification::NOTIFY_SUCCESS);
+    }
+
+} else if ($action == 'auth') {
+
+    if (!optional_param('confirm', false, PARAM_BOOL)) {
+        $continueparams = ['action' => 'auth', 'id' => $issuerid, 'sesskey' => sesskey(), 'confirm' => true];
+        $continueurl = new moodle_url('/admin/tool/oauth2/issuers.php', $continueparams);
+        $cancelurl = new moodle_url('/admin/tool/oauth2/issuers.php');
+        echo $OUTPUT->header();
+        echo $OUTPUT->confirm(get_string('authconfirm', 'tool_oauth2', s($issuer->get('name'))), $continueurl, $cancelurl);
+        echo $OUTPUT->footer();
+    } else {
+        require_sesskey();
+        $params = ['sesskey' => sesskey(), 'id' => $issuerid, 'action' => 'auth', 'confirm' => true, 'response' => true];
+        if (core\oauth2\api::connect_system_account($issuer, new moodle_url('/admin/tool/oauth2/issuers.php', $params))) {
+            redirect($PAGE->url, get_string('authconnected', 'tool_oauth2'), null, \core\output\notification::NOTIFY_SUCCESS);
+        } else {
+            redirect($PAGE->url, get_string('authnotconnected', 'tool_oauth2'), null, \core\output\notification::NOTIFY_ERROR);
+        }
+    }
+} else if ($action == 'moveup') {
+    require_sesskey();
+    core\oauth2\api::move_up_issuer($issuerid);
+    redirect($PAGE->url);
+
+} else if ($action == 'movedown') {
+    require_sesskey();
+    core\oauth2\api::move_down_issuer($issuerid);
+    redirect($PAGE->url);
+
+} else {
+    echo $OUTPUT->header();
+    echo $OUTPUT->heading(get_string('pluginname', 'tool_oauth2'));
+    echo $OUTPUT->doc_link('OAuth2_Services', get_string('serviceshelp', 'tool_oauth2'));
+    $issuers = core\oauth2\api::get_all_issuers();
+    echo $renderer->issuers_table($issuers);
+
+    $docs = 'admin/tool/oauth2/issuers/google';
+    $params = ['action' => 'edittemplate', 'type' => 'google', 'sesskey' => sesskey(), 'docslink' => $docs];
+    $addurl = new moodle_url('/admin/tool/oauth2/issuers.php', $params);
+    echo $renderer->single_button($addurl, get_string('createnewgoogleissuer', 'tool_oauth2'));
+    $docs = 'admin/tool/oauth2/issuers/microsoft';
+    $params = ['action' => 'edittemplate', 'type' => 'microsoft', 'sesskey' => sesskey(), 'docslink' => $docs];
+    $addurl = new moodle_url('/admin/tool/oauth2/issuers.php', $params);
+    echo $renderer->single_button($addurl, get_string('createnewmicrosoftissuer', 'tool_oauth2'));
+    $docs = 'admin/tool/oauth2/issuers/facebook';
+    $params = ['action' => 'edittemplate', 'type' => 'microsoft', 'sesskey' => sesskey(), 'docslink' => $docs];
+    $params = ['action' => 'edittemplate', 'type' => 'facebook', 'sesskey' => sesskey(), 'docslink' => $docs];
+    $addurl = new moodle_url('/admin/tool/oauth2/issuers.php', $params);
+    echo $renderer->single_button($addurl, get_string('createnewfacebookissuer', 'tool_oauth2'));
+    $addurl = new moodle_url('/admin/tool/oauth2/issuers.php', ['action' => 'edit']);
+    echo $renderer->single_button($addurl, get_string('createnewissuer', 'tool_oauth2'));
+    echo $OUTPUT->footer();
+
+}
diff --git a/admin/tool/oauth2/lang/en/tool_oauth2.php b/admin/tool/oauth2/lang/en/tool_oauth2.php
new file mode 100644 (file)
index 0000000..d2c9a2a
--- /dev/null
@@ -0,0 +1,101 @@
+<?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 'tool_oauth2', language 'en'
+ *
+ * @package    tool_oauth2
+ * @copyright  2017 Damyon Wiese
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$string['authconfirm'] = 'This action will grant permanent API access to Moodle for the authenticated account. This is intended to be used as a system account for managing files owned by Moodle.';
+$string['authconnected'] = 'The system account is now connected for offline access';
+$string['authnotconnected'] = 'The system account was not connected for offline access';
+$string['configured'] = 'Configured';
+$string['configuredstatus'] = 'Configured';
+$string['connectsystemaccount'] = 'Connect to a system account';
+$string['createfromtemplate'] = 'Create an OAuth 2 service from a template';
+$string['createfromtemplatedesc'] = 'Choose one of the OAuth 2 service template below to create an OAuth service with a valid configuration for one of the known service types. This will create the OAuth 2 service, with all the correct end points and parameters required for authentication, but you will still need to enter the client ID and secret for the new service before it can be used.';
+$string['createnewendpoint'] = 'Create new endpoint for issuer "{$a}"';
+$string['createnewfacebookissuer'] = 'Create new Facebook service';
+$string['createnewgoogleissuer'] = 'Create new Google service';
+$string['createnewissuer'] = 'Create new custom service';
+$string['createnewmicrosoftissuer'] = 'Create new Microsoft service';
+$string['createnewuserfieldmapping'] = 'Create new user field mapping for issuer "{$a}"';
+$string['deleteconfirm'] = 'Are you sure you want to delete the identity issuer "{$a}"? Any plugins relying on this issuer will stop working.';
+$string['deleteendpointconfirm'] = 'Are you sure you want to delete the endpoint "{$a->endpoint}" for issuer "{$a->issuer}"? Any plugins relying on this endpoint will stop working.';
+$string['deleteuserfieldmappingconfirm'] = 'Are you sure you want to delete the user field mapping for issuer "{$a}"?';
+$string['discovered_help'] = 'Discovery means that the OAuth2 endpoints could be automatically determined from the base url for the OAuth service. Not all services are required to be "discovered", but if they are not, then the endpoints and user mapping information will need to be entered manually.';
+$string['discovered'] = 'Service discovery successful';
+$string['discoverystatus'] = 'Discovery';
+$string['editendpoint'] = 'Edit endpoint: {$a->endpoint} for issuer {$a->issuer}';
+$string['editendpoints'] = 'Configure endpoints';
+$string['editissuer'] = 'Edit identity issuer: {$a}';
+$string['edituserfieldmapping'] = 'Edit user field mapping for issuer {$a}';
+$string['edituserfieldmappings'] = 'Configure user field mappings';
+$string['endpointdeleted'] = 'Endpoint deleted';
+$string['endpointname_help'] = 'Key used to search for this endpoint. Must end with "_endpoint".';
+$string['endpointname'] = 'Name';
+$string['endpointsforissuer'] = 'Endpoints for issuer: {$a}';
+$string['endpointurl_help'] = 'URL for this endpoint. Must use https:// protocol.';
+$string['endpointurl'] = 'Url';
+$string['issuersetup'] = 'Detailed instructions on configuring the common OAuth 2 Services';
+$string['issuersetuptype'] = 'Detailed instructions on setting up the {$a} OAuth 2 provider';
+$string['issueralloweddomains_help'] = 'If set, this setting is a comma separated list of domains that logins will be restricted to when using this provider.';
+$string['issueralloweddomains_link'] = 'OAuth_2_login_domains';
+$string['issueralloweddomains'] = 'Login domains';
+$string['issuerbaseurl_help'] = 'Base url used to access the service.';
+$string['issuerbaseurl'] = 'Service base url';
+$string['issuerclientid'] = 'Client Id';
+$string['issuerclientid_help'] = 'The OAuth client ID for this issuer.';
+$string['issuerclientsecret'] = 'Client Secret';
+$string['issuerclientsecret_help'] = 'The OAuth client secret for this issuer.';
+$string['issuerdeleted'] = 'Identity issuer deleted';
+$string['issuerdisabled'] = 'Identity issuer disabled';
+$string['issuerenabled'] = 'Identity issuer enabled';
+$string['issuerimage_help'] = 'An image url used to show a logo for this issuer. May be displayed on login page.';
+$string['issuerimage'] = 'Logo URL';
+$string['issuerloginparams'] = 'Additional parameters included in a login request.';
+$string['issuerloginparams_help'] = 'Some systems require additional parameters for a login request in order to read the users basic profile.';
+$string['issuerloginparamsoffline'] = 'Additional parameters included in a login request for offline access.';
+$string['issuerloginparamsoffline_help'] = 'Each OAuth system defines a different way to request offline access. E.g. Google requires the additional params: "access_type=offline&prompt=consent" these parameters should be in url query parameter format.';
+$string['issuerloginscopes_help'] = 'Some systems require additional scopes for a login request in order to read the users basic profile. The standard scopes for an OpenID Connect compliant system are "openid profile email".';
+$string['issuerloginscopesoffline_help'] = 'Each OAuth system defines a different way to request offline access. E.g. Microsoft requires an additional scope "offline_access"';
+$string['issuerloginscopesoffline'] = 'Scopes included in a login request for offline access.';
+$string['issuerloginscopes'] = 'Scopes included in a login request.';
+$string['issuername_help'] = 'Name of the identity issuer. May be displayed on login page.';
+$string['issuername'] = 'Name';
+$string['issuershowonloginpage_help'] = 'If the OpenID Connect Authentication plugin is enabled, this login issuer will be listed on the login page to allow users to login with accounts from this issuer.';
+$string['issuershowonloginpage'] = 'Show on login page.';
+$string['issuers'] = 'Issuers';
+$string['loginissuer'] = 'Allow login';
+$string['notconfigured'] = 'Not configured';
+$string['notdiscovered'] = 'Service discovery not successful';
+$string['notloginissuer'] = 'Do not allow login';
+$string['pluginname'] = 'OAuth 2 Services';
+$string['savechanges'] = 'Save changes';
+$string['serviceshelp'] = 'Service provider setup instructions.';
+$string['systemaccountconnected_help'] = 'System accounts are used to provide advanced functionality for plugins. They are not required for login functionality only, but other plugins using the OAuth service may offer a reduced set of features if the system account has not been connected. For example repositories cannot support "controlled links" without a system account to perform file operations.';
+$string['systemaccountconnected'] = 'System account connected';
+$string['systemaccountnotconnected'] = 'System account not connected';
+$string['systemauthstatus'] = 'System account connected';
+$string['userfieldexternalfield'] = 'External field name';
+$string['userfieldexternalfield_help'] = 'Name of the field provided by the external OAuth system.';
+$string['userfieldinternalfield_help'] = 'Name of the Moodle user field that should be mapped from the external field.';
+$string['userfieldinternalfield'] = 'Internal field name';
+$string['userfieldmappingdeleted'] = 'User field mapping deleted';
+$string['userfieldmappingsforissuer'] = 'User field mappings for issuer: {$a}';
diff --git a/admin/tool/oauth2/pix/auth.svg b/admin/tool/oauth2/pix/auth.svg
new file mode 100644 (file)
index 0000000..409824a
--- /dev/null
@@ -0,0 +1,3 @@
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [\r
+       <!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">\r
+]><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" preserveAspectRatio="xMinYMid meet" overflow="visible"><path d="M9 16H1c-.5 0-1-.5-1-1V1c0-.5.5-1 1-1h8v2H3c-.6 0-1 .4-1 1v10c0 .6.4 1 1 1h6v2zM5 7.5v1c0 .5.5 1 1 1h4.7l-1.1 1.1c-.4.4-.4 1 0 1.4l.7.7c.4.4 1 .4 1.4 0l4-4c.4-.4.4-1 0-1.4l-4-4c-.4-.4-1-.4-1.4 0l-.7.7c-.4.4-.4 1 0 1.4l1 1H6c-.5.1-1 .6-1 1.1z" fill="#989898"/></svg>
\ No newline at end of file
diff --git a/admin/tool/oauth2/pix/no.svg b/admin/tool/oauth2/pix/no.svg
new file mode 100644 (file)
index 0000000..0185d86
--- /dev/null
@@ -0,0 +1,3 @@
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [\r
+       <!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">\r
+]><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="-1.6 -0.5 16 16" preserveAspectRatio="xMinYMid meet" overflow="visible"><path d="M12.8 2.7L10.1 0S8.5 1.5 6.4 4C4.3 1.5 2.7 0 2.7 0L0 2.7S1.9 4 4.6 6.4C3 8.7 1.3 11.6 0 14.9c2.2-2.7 4.4-5 6.4-6.9 2 1.9 4.2 4.2 6.4 6.9-1.3-3.3-3-6.2-4.6-8.6 2.7-2.3 4.6-3.6 4.6-3.6z" fill="#FF403C"/></svg>
\ No newline at end of file
diff --git a/admin/tool/oauth2/pix/yes.svg b/admin/tool/oauth2/pix/yes.svg
new file mode 100644 (file)
index 0000000..714d4c7
--- /dev/null
@@ -0,0 +1,3 @@
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [\r
+       <!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">\r
+]><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="-0.1 0 16 16" preserveAspectRatio="xMinYMid meet" overflow="visible"><path d="M6.4 11.1c-2-2.5-3.7-4-3.7-4L0 9.8C5 13.1 8.1 16 8.1 16s.2-.7.6-1.8c.9-2.7 3.2-8.1 7.1-14.2-4.6 3.7-7.7 8.2-9.4 11.1z" fill="#9C3"/></svg>
\ No newline at end of file
diff --git a/admin/tool/oauth2/settings.php b/admin/tool/oauth2/settings.php
new file mode 100644 (file)
index 0000000..947f79c
--- /dev/null
@@ -0,0 +1,30 @@
+<?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/>.
+
+/**
+ * Oauth2 system configuration.
+ *
+ * @package    tool_oauth2
+ * @copyright  2017 Damyon Wiese
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+if ($hassiteconfig) {
+    $ADMIN->add('server', new admin_externalpage('oauth2', new lang_string('pluginname', 'tool_oauth2'),
+         "$CFG->wwwroot/$CFG->admin/tool/oauth2/issuers.php"));
+}
diff --git a/admin/tool/oauth2/userfieldmappings.php b/admin/tool/oauth2/userfieldmappings.php
new file mode 100644 (file)
index 0000000..d0961ce
--- /dev/null
@@ -0,0 +1,126 @@
+<?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/>.
+
+/**
+ * OAuth 2 Endpoint Configuration page.
+ *
+ * @package    tool_oauth2
+ * @copyright  2017 Damyon Wiese <damyon@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(__DIR__ . '/../../../config.php');
+require_once($CFG->libdir.'/adminlib.php');
+require_once($CFG->libdir.'/tablelib.php');
+
+$PAGE->set_url('/admin/tool/oauth2/userfieldmappings.php', ['issuerid' => required_param('issuerid', PARAM_INT)]);
+$PAGE->set_context(context_system::instance());
+$PAGE->set_pagelayout('admin');
+$strheading = get_string('pluginname', 'tool_oauth2');
+$PAGE->set_title($strheading);
+$PAGE->set_heading($strheading);
+
+require_login();
+
+require_capability('moodle/site:config', context_system::instance());
+
+$renderer = $PAGE->get_renderer('tool_oauth2');
+
+$action = optional_param('action', '', PARAM_ALPHAEXT);
+$issuerid = required_param('issuerid', PARAM_INT);
+$userfieldmappingid = optional_param('userfieldmappingid', '', PARAM_INT);
+$userfieldmapping = null;
+$mform = null;
+
+$issuer = \core\oauth2\api::get_issuer($issuerid);
+if (!$issuer) {
+    print_error('invaliddata');
+}
+$PAGE->navbar->override_active_url(new moodle_url('/admin/tool/oauth2/issuers.php'), true);
+
+if (!empty($userfieldmappingid)) {
+    $userfieldmapping = \core\oauth2\api::get_user_field_mapping($userfieldmappingid);
+}
+
+if ($action == 'edit') {
+    if ($userfieldmapping) {
+        $PAGE->navbar->add(get_string('edituserfieldmapping', 'tool_oauth2', s($issuer->get('name'))));
+    } else {
+        $PAGE->navbar->add(get_string('createnewuserfieldmapping', 'tool_oauth2', s($issuer->get('name'))));
+    }
+
+    $mform = new \tool_oauth2\form\user_field_mapping(null, ['persistent' => $userfieldmapping, 'issuerid' => $issuerid]);
+}
+
+if ($mform && $mform->is_cancelled()) {
+    redirect(new moodle_url('/admin/tool/oauth2/userfieldmappings.php', ['issuerid' => $issuerid]));
+} else if ($action == 'edit') {
+
+    if ($data = $mform->get_data()) {
+
+        try {
+            if (!empty($data->id)) {
+                core\oauth2\api::update_user_field_mapping($data);
+            } else {
+                core\oauth2\api::create_user_field_mapping($data);
+            }
+            redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
+        } catch (Exception $e) {
+            redirect($PAGE->url, $e->getMessage(), null, \core\output\notification::NOTIFY_ERROR);
+        }
+    } else {
+        echo $OUTPUT->header();
+        if ($issuer) {
+            echo $OUTPUT->heading(get_string('edituserfieldmapping', 'tool_oauth2', s($issuer->get('name'))));
+        } else {
+            echo $OUTPUT->heading(get_string('createnewuserfieldmapping', 'tool_oauth2', s($issuer->get('name'))));
+        }
+        $mform->display();
+        echo $OUTPUT->footer();
+    }
+
+} else if ($action == 'delete') {
+
+    if (!optional_param('confirm', false, PARAM_BOOL)) {
+        $continueparams = [
+            'action' => 'delete',
+            'issuerid' => $issuerid,
+            'userfieldmappingid' => $userfieldmappingid,
+            'sesskey' => sesskey(),
+            'confirm' => true
+        ];
+        $continueurl = new moodle_url('/admin/tool/oauth2/userfieldmappings.php', $continueparams);
+        $cancelurl = new moodle_url('/admin/tool/oauth2/userfieldmappings.php');
+        echo $OUTPUT->header();
+        $str = get_string('deleteuserfieldmappingconfirm', 'tool_oauth2', s($issuer->get('name')));
+        echo $OUTPUT->confirm($str, $continueurl, $cancelurl);
+        echo $OUTPUT->footer();
+    } else {
+        require_sesskey();
+        core\oauth2\api::delete_user_field_mapping($userfieldmappingid);
+        redirect($PAGE->url, get_string('userfieldmappingdeleted', 'tool_oauth2'), null, \core\output\notification::NOTIFY_SUCCESS);
+    }
+
+} else {
+    echo $OUTPUT->header();
+    echo $OUTPUT->heading(get_string('userfieldmappingsforissuer', 'tool_oauth2', s($issuer->get('name'))));
+    $userfieldmappings = core\oauth2\api::get_user_field_mappings($issuer);
+    echo $renderer->user_field_mappings_table($userfieldmappings, $issuerid);
+
+    $addurl = new moodle_url('/admin/tool/oauth2/userfieldmappings.php', ['action' => 'edit', 'issuerid' => $issuerid]);
+    echo $renderer->single_button($addurl, get_string('createnewuserfieldmapping', 'tool_oauth2', s($issuer->get('name'))));
+    echo $OUTPUT->footer();
+}
diff --git a/admin/tool/oauth2/version.php b/admin/tool/oauth2/version.php
new file mode 100644 (file)
index 0000000..22ed6ee
--- /dev/null
@@ -0,0 +1,30 @@
+<?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/>.
+
+/**
+ * Plugin version info
+ *
+ * @package    tool_oauth2
+ * @copyright  2017 Damyon Wiese
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$plugin->version   = 2016120500; // The current plugin version (Date: YYYYMMDDXX).
+$plugin->requires  = 2016112900; // Requires this Moodle version.
+$plugin->component = 'tool_oauth2'; // Full name of the plugin (used for diagnostics).
+
index 4439bcb..d94c396 100644 (file)
@@ -230,47 +230,6 @@ class auth_plugin_cas extends auth_plugin_ldap {
         }
     }
 
-    /**
-     * Prints a form for configuring this authentication plugin.
-     *
-     * This function is called from admin/auth.php, and outputs a full page with
-     * a form for configuring this plugin.
-     *
-     * @param array $page An object containing all the data for this page.
-     */
-    function config_form($config, $err, $user_fields) {
-        global $CFG, $OUTPUT;
-
-        if (!function_exists('ldap_connect')) { // Is php-ldap really there?
-            echo $OUTPUT->notification(get_string('auth_ldap_noextension', 'auth_ldap'));
-
-            // Don't return here, like we do in auth/ldap. We cas use CAS without LDAP.
-            // So just warn the user (done above) and define the LDAP constants we use
-            // in config.html, to silence the warnings.
-            if (!defined('LDAP_DEREF_NEVER')) {
-                define ('LDAP_DEREF_NEVER', 0);
-            }
-            if (!defined('LDAP_DEREF_ALWAYS')) {
-                define ('LDAP_DEREF_ALWAYS', 3);
-            }
-        }
-
-        include($CFG->dirroot.'/auth/cas/config.html');
-    }
-
-    /**
-     * A chance to validate form data, and last chance to
-     * do stuff before it is inserted in config_plugin
-     * @param object object with submitted configuration settings (without system magic quotes)
-     * @param array $err array of error messages
-     */
-    function validate_form($form, &$err) {
-        $certificate_path = trim($form->certificate_path);
-        if ($form->certificate_check && empty($certificate_path)) {
-            $err['certificate_path'] = get_string('auth_cas_certificate_path_empty', 'auth_cas');
-        }
-    }
-
     /**
      * Returns the URL for changing the user's pw, or empty if the default can
      * be used.
@@ -281,143 +240,6 @@ class auth_plugin_cas extends auth_plugin_ldap {
         return null;
     }
 
-    /**
-     * Processes and stores configuration data for this authentication plugin.
-     */
-    function process_config($config) {
-
-        // CAS settings
-        if (!isset($config->hostname)) {
-            $config->hostname = '';
-        }
-        if (!isset($config->port)) {
-            $config->port = '';
-        }
-        if (!isset($config->casversion)) {
-            $config->casversion = '';
-        }
-        if (!isset($config->baseuri)) {
-            $config->baseuri = '';
-        }
-        if (!isset($config->language)) {
-            $config->language = '';
-        }
-        if (!isset($config->proxycas)) {
-            $config->proxycas = '';
-        }
-        if (!isset($config->logoutcas)) {
-            $config->logoutcas = '';
-        }
-        if (!isset($config->multiauth)) {
-            $config->multiauth = '';
-        }
-        if (!isset($config->certificate_check)) {
-            $config->certificate_check = '';
-        }
-        if (!isset($config->certificate_path)) {
-            $config->certificate_path = '';
-        }
-        if (!isset($config->curl_ssl_version)) {
-            $config->curl_ssl_version = '';
-        }
-        if (!isset($config->logout_return_url)) {
-            $config->logout_return_url = '';
-        }
-
-        // LDAP settings
-        if (!isset($config->host_url)) {
-            $config->host_url = '';
-        }
-        if (!isset($config->start_tls)) {
-             $config->start_tls = false;
-        }
-        if (empty($config->ldapencoding)) {
-            $config->ldapencoding = 'utf-8';
-        }
-        if (!isset($config->pagesize)) {
-            $config->pagesize = LDAP_DEFAULT_PAGESIZE;
-        }
-        if (!isset($config->contexts)) {
-            $config->contexts = '';
-        }
-        if (!isset($config->user_type)) {
-            $config->user_type = 'default';
-        }
-        if (!isset($config->user_attribute)) {
-            $config->user_attribute = '';
-        }
-        if (!isset($config->search_sub)) {
-            $config->search_sub = '';
-        }
-        if (!isset($config->opt_deref)) {
-            $config->opt_deref = LDAP_DEREF_NEVER;
-        }
-        if (!isset($config->bind_dn)) {
-            $config->bind_dn = '';
-        }
-        if (!isset($config->bind_pw)) {
-            $config->bind_pw = '';
-        }
-        if (!isset($config->ldap_version)) {
-            $config->ldap_version = '3';
-        }
-        if (!isset($config->objectclass)) {
-            $config->objectclass = '';
-        }
-        if (!isset($config->memberattribute)) {
-            $config->memberattribute = '';
-        }
-
-        if (!isset($config->memberattribute_isdn)) {
-            $config->memberattribute_isdn = '';
-        }
-        if (!isset($config->attrcreators)) {
-            $config->attrcreators = '';
-        }
-        if (!isset($config->groupecreators)) {
-            $config->groupecreators = '';
-        }
-        if (!isset($config->removeuser)) {
-            $config->removeuser = AUTH_REMOVEUSER_KEEP;
-        }
-
-        // save CAS settings
-        set_config('hostname', trim($config->hostname), $this->pluginconfig);
-        set_config('port', trim($config->port), $this->pluginconfig);
-        set_config('casversion', $config->casversion, $this->pluginconfig);
-        set_config('baseuri', trim($config->baseuri), $this->pluginconfig);
-        set_config('language', $config->language, $this->pluginconfig);
-        set_config('proxycas', $config->proxycas, $this->pluginconfig);
-        set_config('logoutcas', $config->logoutcas, $this->pluginconfig);
-        set_config('multiauth', $config->multiauth, $this->pluginconfig);
-        set_config('certificate_check', $config->certificate_check, $this->pluginconfig);
-        set_config('certificate_path', $config->certificate_path, $this->pluginconfig);
-        set_config('curl_ssl_version', $config->curl_ssl_version, $this->pluginconfig);
-        set_config('logout_return_url', $config->logout_return_url, $this->pluginconfig);
-
-        // save LDAP settings
-        set_config('host_url', trim($config->host_url), $this->pluginconfig);
-        set_config('start_tls', $config->start_tls, $this->pluginconfig);
-        set_config('ldapencoding', trim($config->ldapencoding), $this->pluginconfig);
-        set_config('pagesize', (int)trim($config->pagesize), $this->pluginconfig);
-        set_config('contexts', trim($config->contexts), $this->pluginconfig);
-        set_config('user_type', core_text::strtolower(trim($config->user_type)), $this->pluginconfig);
-        set_config('user_attribute', core_text::strtolower(trim($config->user_attribute)), $this->pluginconfig);
-        set_config('search_sub', $config->search_sub, $this->pluginconfig);
-        set_config('opt_deref', $config->opt_deref, $this->pluginconfig);
-        set_config('bind_dn', trim($config->bind_dn), $this->pluginconfig);
-        set_config('bind_pw', $config->bind_pw, $this->pluginconfig);
-        set_config('ldap_version', $config->ldap_version, $this->pluginconfig);
-        set_config('objectclass', trim($config->objectclass), $this->pluginconfig);
-        set_config('memberattribute', core_text::strtolower(trim($config->memberattribute)), $this->pluginconfig);
-        set_config('memberattribute_isdn', $config->memberattribute_isdn, $this->pluginconfig);
-        set_config('attrcreators', trim($config->attrcreators), $this->pluginconfig);
-        set_config('groupecreators', trim($config->groupecreators), $this->pluginconfig);
-        set_config('removeuser', $config->removeuser, $this->pluginconfig);
-
-        return true;
-    }
-
     /**
      * Returns true if user should be coursecreator.
      *
diff --git a/auth/cas/config.html b/auth/cas/config.html
deleted file mode 100644 (file)
index 6279950..0000000
+++ /dev/null
@@ -1,553 +0,0 @@
-<?php
-
-include($CFG->dirroot.'/auth/cas/languages.php');
-
-// set to defaults if undefined (CAS)
-if (!isset ($config->hostname)) {
-    $config->hostname = '';
-}
-if (!isset ($config->port)) {
-    $config->port = '';
-}
-if (!isset ($config->casversion)) {
-    $config->casversion = CAS_VERSION_2_0;
-}
-if (!isset ($config->baseuri)) {
-    $config->baseuri = '';
-}
-if (!isset ($config->language)) {
-    $config->language = '';
-}
-if (!isset ($config->proxycas)) {
-    $config->proxycas = '';
-}
-if (!isset ($config->logoutcas)) {
-    $config->logoutcas = '';
-}
-if (!isset ($config->multiauth)) {
-    $config->multiauth = '';
-}
-if (!isset ($config->certificate_check)) {
-    $config->certificate_check = '';
-}
-if (!isset ($config->certificate_path)) {
-    $config->certificate_path = '';
-}
-if (!isset($config->curl_ssl_version)) {
-    $config->curl_ssl_version = '';
-}
-if (!isset($config->logout_return_url)) {
-    $config->logout_return_url = '';
-}
-
-// set to defaults if undefined (LDAP)
-if (!isset($config->host_url)) {
-     $config->host_url = '';
-}
-if (!isset($config->start_tls)) {
-    $config->start_tls = false;
-}
-if (empty($config->ldapencoding)) {
-    $config->ldapencoding = 'utf-8';
-}
-if (!isset($config->pagesize)) {
-    $config->pagesize = LDAP_DEFAULT_PAGESIZE;
-}
-if (!isset($config->contexts)) {
-    $config->contexts = '';
-}
-if (!isset($config->user_type)) {
-    $config->user_type = 'default';
-}
-if (!isset($config->user_attribute)) {
-    $config->user_attribute = '';
-}
-if (!isset($config->search_sub)) {
-    $config->search_sub = '';
-}
-if (!isset($config->opt_deref)) {
-    $config->opt_deref = LDAP_DEREF_NEVER;
-}
-if (!isset($config->bind_dn)) {
-    $config->bind_dn = '';
-}
-if (!isset($config->bind_pw)) {
-    $config->bind_pw = '';
-}
-if (!isset($config->ldap_version)) {
-    $config->ldap_version = '3';
-}
-if (!isset($config->objectclass)) {
-    $config->objectclass = '';
-}
-if (!isset($config->memberattribute)) {
-    $config->memberattribute = '';
-}
-if (!isset($config->memberattribute_isdn)) {
-    $config->memberattribute_isdn = '';
-}
-if (!isset($config->groupecreators)) {
-    $config->groupecreators = '';
-}
-if (!isset($config->attrcreators)) {
-    $config->attrcreators = '';
-}
-if (!isset($config->removeuser)) {
-    $config->removeuser = AUTH_REMOVEUSER_KEEP;
-}
-
-$yesno = array( get_string('no'), get_string('yes') );
-
-$disabled = '';
-$pagedresultssupported = false;
-if ($config->host_url !== '') {
-    /**
-     * We try to connect each and every time we open the config, because we want to set the Page
-     * Size setting as enabled or disabled depending on the configured LDAP server supporting
-     * pagination or not, and to notify the user about it. If the user changed the LDAP server (or
-     * the LDAP protocol version) last time, it might happen that paged results are no longer
-     * available and we want to show that to the user the next time she goes to the settings page.
-     */
-    try {
-        $ldapconn = $this->ldap_connect();
-        $pagedresultssupported = ldap_paged_results_supported($config->ldap_version, $ldapconn);
-    } catch (Exception $e) {
-        // If we couldn't connect and get the supported options, we can only assume we don't support paged results.
-        $pagedresultssupported = false;
-    }
-}
-/* Make sure we only disable the paged result size setting and show the notification about it if
- * there is a configured server that we tried to contact.  Othersiwe, if someone's LDAP server does
- * support paged results, they won't be able to turn it on the first time they set it up (because
- * the field will be disabled).
- */
-if (($config->host_url !== '') && (!$pagedresultssupported)) {
-    $disabled = ' disabled="disabled"';
-    echo $OUTPUT->notification(get_string('pagedresultsnotsupp', 'auth_ldap'), \core\output\notification::NOTIFY_INFO);
-}
-
-?>
-<table cellspacing="0" cellpadding="5" border="0">
-<tr>
-    <td colspan="2">
-        <h4><?php print_string('auth_cas_server_settings', 'auth_cas') ?></h4>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right"><label for="hostname"><?php print_string('auth_cas_hostname_key', 'auth_cas') ?>: </label></td>
-    <td>
-        <input name="hostname" id="hostname" type="text" size="30" value="<?php echo $config->hostname ?>" />
-        <?php if (isset($err['hostname'])) { echo $OUTPUT->error_text($err['hostname']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_cas_hostname', 'auth_cas') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="baseuri"><?php print_string('auth_cas_baseuri_key', 'auth_cas') ?>: </label>
-    </td>
-    <td>
-        <input name="baseuri" id="baseuri" type="text" size="30" value="<?php echo $config->baseuri ?>" />
-        <?php if (isset($err['baseuri'])) { echo $OUTPUT->error_text($err['baseuri']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_cas_baseuri', 'auth_cas') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="port"><?php print_string('auth_cas_port_key', 'auth_cas') ?>: </label>
-    </td>
-    <td>
-        <input name="port" id="port" type="text" size="30" value="<?php echo $config->port ?>" />
-        <?php if (isset($err['port'])) { echo $OUTPUT->error_text($err['port']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_cas_port', 'auth_cas') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <?php echo html_writer::label(get_string('auth_cas_casversion', 'auth_cas'), 'menucasversion'); ?>:
-    </td>
-    <td>
-        <?php
-             $casversions = array();
-             $casversions[CAS_VERSION_1_0] = 'CAS 1.0';
-             $casversions[CAS_VERSION_2_0] = 'CAS 2.0';
-             echo html_writer::select($casversions, 'casversion', $config->casversion, false);
-             if (isset($err['casversion'])) { echo $OUTPUT->error_text($err['casversion']); }
-        ?>
-    </td>
-    <td>
-        <?php print_string('auth_cas_version', 'auth_cas') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right"><?php echo html_writer::label(get_string('auth_cas_language_key', 'auth_cas'), 'menulanguage'); ?>:</td>
-    <td>
-        <?php echo html_writer::select($CASLANGUAGES, 'language', $config->language, false); ?>
-    </td>
-    <td>
-        <?php print_string('auth_cas_language', 'auth_cas') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <?php echo html_writer::label(get_string('auth_cas_proxycas_key', 'auth_cas'), 'menuproxycas'); ?>:
-    </td>
-    <td>
-        <?php echo html_writer::select($yesno, 'proxycas', $config->proxycas, false); ?>
-    </td>
-    <td>
-        <?php print_string('auth_cas_proxycas', 'auth_cas') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right"><?php echo html_writer::label(get_string('auth_cas_logoutcas_key', 'auth_cas'), 'menulogoutcas'); ?>:</td>
-    <td>
-        <?php echo html_writer::select($yesno, 'logoutcas', $config->logoutcas, false); ?>
-    </td>
-    <td>
-        <?php print_string('auth_cas_logoutcas', 'auth_cas') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right"><?php echo html_writer::label(get_string('auth_cas_multiauth_key', 'auth_cas'), 'menumultiauth'); ?>:</td>
-    <td>
-        <?php echo html_writer::select($yesno, 'multiauth', $config->multiauth, false); ?>
-    </td>
-    <td>
-        <?php print_string('auth_cas_multiauth', 'auth_cas') ?>
-    </td>
-</tr>
-<tr valign="top"  class="required">
-    <td align="right"><?php echo html_writer::label(get_string('auth_cas_certificate_check_key', 'auth_cas'), 'menucertificate_check'); ?>:</td>
-    <td>
-        <?php echo html_writer::select($yesno, 'certificate_check', $config->certificate_check, false); ?>
-    </td>
-    <td>
-        <?php print_string('auth_cas_certificate_check', 'auth_cas') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right"><label for="certificate_path"><?php print_string('auth_cas_certificate_path_key', 'auth_cas') ?>: </label></td>
-    <td>
-        <input name="certificate_path" id="certificate_path" type="text" size="30" value="<?php echo $config->certificate_path ?>" />
-        <?php if (isset($err['certificate_path'])) echo $OUTPUT->error_text($err['certificate_path']); ?>
-    </td>
-    <td>
-        <?php print_string('auth_cas_certificate_path', 'auth_cas') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right"><label for="curl_ ssl_version"><?php print_string('auth_cas_curl_ssl_version_key', 'auth_cas') ?>: </label></td>
-    <td>
-        <?php
-            $sslversions = array();
-            $sslversions[''] = get_string('auth_cas_curl_ssl_version_default', 'auth_cas');
-            if (defined('CURL_SSLVERSION_TLSv1')) {
-                $sslversions[CURL_SSLVERSION_TLSv1] = get_string('auth_cas_curl_ssl_version_TLSv1x', 'auth_cas');
-            }
-            if (defined('CURL_SSLVERSION_TLSv1_0')) {
-                $sslversions[CURL_SSLVERSION_TLSv1_0] = get_string('auth_cas_curl_ssl_version_TLSv10', 'auth_cas');
-            }
-            if (defined('CURL_SSLVERSION_TLSv1_1')) {
-                $sslversions[CURL_SSLVERSION_TLSv1_1] = get_string('auth_cas_curl_ssl_version_TLSv11', 'auth_cas');
-            }
-            if (defined('CURL_SSLVERSION_TLSv1_2')) {
-                $sslversions[CURL_SSLVERSION_TLSv1_2] = get_string('auth_cas_curl_ssl_version_TLSv12', 'auth_cas');
-            }
-            if (defined('CURL_SSLVERSION_SSLv2')) {
-                $sslversions[CURL_SSLVERSION_SSLv2] = get_string('auth_cas_curl_ssl_version_SSLv2', 'auth_cas');
-            }
-            if (defined('CURL_SSLVERSION_SSLv3')) {
-                $sslversions[CURL_SSLVERSION_SSLv3] = get_string('auth_cas_curl_ssl_version_SSLv3', 'auth_cas');
-            }
-            echo html_writer::select($sslversions, 'curl_ssl_version', $config->curl_ssl_version, false);
-            if (isset($err['curl_ssl_version'])) echo $OUTPUT->error_text($err['curl_ssl_version']);
-        ?>
-    </td>
-    <td>
-        <?php print_string('auth_cas_curl_ssl_version', 'auth_cas') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right"><?php print_string('auth_cas_logout_return_url_key', 'auth_cas') ?>:</td>
-    <td>
-       <input name="logout_return_url" type="text" size="30" value="<?php echo $config->logout_return_url ?>" />
-       <?php if (isset($err['logout_return_url'])) { echo $OUTPUT->error_text($err['logout_return_url']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_cas_logout_return_url', 'auth_cas') ?>
-    </td>
-</tr>
-<tr>
-   <td colspan="2">
-        <h4><?php print_string('auth_ldap_server_settings', 'auth_ldap') ?></h4>
-   </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="host_url"><?php print_string('auth_ldap_host_url_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="host_url" id="host_url" type="text" size="30" value="<?php echo $config->host_url?>" />
-        <?php if (isset($err['host_url'])) { echo $OUTPUT->error_text($err['host_url']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_host_url', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right"><label for="ldap_version"><?php print_string('auth_ldap_version_key', 'auth_ldap') ?></label></td>
-    <td>
-        <?php
-             $versions = array();
-             $versions[2] = '2';
-             $versions[3] = '3';
-             echo html_writer::select($versions, 'ldap_version', $config->ldap_version, false);
-             if (isset($err['ldap_version'])) { echo $OUTPUT->error_text($err['ldap_version']); }
-        ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_version', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right">
-        <label for="start_tls"><?php print_string('start_tls_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <?php echo html_writer::select($yesno, 'start_tls', $config->start_tls, false); ?>
-    </td>
-    <td>
-        <?php print_string('start_tls', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="ldapencoding"><?php print_string('auth_ldap_ldap_encoding_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input id="ldapencoding" name="ldapencoding" type="text" value="<?php echo $config->ldapencoding ?>" />
-        <?php if (isset($err['ldapencoding'])) { echo $OUTPUT->error_text($err['ldapencoding']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_ldap_encoding', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right">
-        <label for="pagesize"><?php print_string('pagesize_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input id="pagesize" name="pagesize" type="text" value="<?php echo $config->pagesize ?>" <?php echo $disabled ?>/>
-        <?php
-            if (isset($err['pagesize'])) { echo $OUTPUT->error_text($err['pagesize']); }
-            if ($disabled) {
-                // Don't loose the page size value (disabled fields are not submitted!)
-        ?>
-            <input id="pagesize" name="pagesize" type="hidden" value="<?php echo $config->pagesize ?>" />
-        <?php } ?>
-    </td>
-    <td>
-        <?php print_string('pagesize', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr>
-    <td colspan="2">
-        <h4><?php print_string('auth_ldap_bind_settings', 'auth_ldap') ?></h4>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="bind_dn"><?php print_string('auth_ldap_bind_dn_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="bind_dn" id="bind_dn" type="text" size="30" value="<?php echo $config->bind_dn?>" />
-        <?php if (isset($err['bind_dn'])) { echo $OUTPUT->error_text($err['bind_dn']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_bind_dn', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="bind_pw"><?php print_string('auth_ldap_bind_pw_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="bind_pw" id="bind_pw" type="password" size="30" value="<?php echo $config->bind_pw?>" autocomplete="off"/>
-        <?php if (isset($err['bind_pw'])) { echo $OUTPUT->error_text($err['bind_pw']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_bind_pw', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr>
-    <td colspan="2">
-        <h4><?php print_string('auth_ldap_user_settings', 'auth_ldap') ?></h4>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="menuuser_type"><?php print_string('auth_ldap_user_type_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <?php
-            echo html_writer::select(ldap_supported_usertypes(), 'user_type', $config->user_type, false);
-            if (isset($err['user_type'])) { echo $OUTPUT->error_text($err['user_type']); }
-        ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_user_type', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="contexts"><?php print_string('auth_ldap_contexts_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="contexts" id="contexts" type="text" size="30" value="<?php echo $config->contexts?>" />
-        <?php if (isset($err['contexts'])) { echo $OUTPUT->error_text($err['contexts']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_contexts', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="menusearch_sub"><?php print_string('auth_ldap_search_sub_key', 'auth_ldap') ?></label></td>
-    <td>
-        <?php echo html_writer::select($yesno, 'search_sub', $config->search_sub, false); ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_search_sub', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right"><label for="menuopt_deref"><?php print_string('auth_ldap_opt_deref_key', 'auth_ldap') ?></label></td>
-    <td>
-        <?php
-             $opt_deref = array();
-             $opt_deref[LDAP_DEREF_NEVER] = get_string('no');
-             $opt_deref[LDAP_DEREF_ALWAYS] = get_string('yes');
-             echo html_writer::select($opt_deref, 'opt_deref', $config->opt_deref, false);
-             if (isset($err['opt_deref'])) { echo $OUTPUT->error_text($err['opt_deref']); }
-        ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_opt_deref', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="user_attribute"><?php print_string('auth_ldap_user_attribute_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="user_attribute" id="user_attribute" type="text" size="30" value="<?php echo $config->user_attribute?>" />
-        <?php if (isset($err['user_attribute'])) { echo $OUTPUT->error_text($err['user_attribute']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_user_attribute', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="memberattribute"><?php print_string('auth_ldap_memberattribute_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="memberattribute" id="memberattribute" type="text" size="30" value="<?php echo $config->memberattribute?>" />
-        <?php if (isset($err['memberattribute'])) { echo $OUTPUT->error_text($err['memberattribute']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_memberattribute', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="memberattribute_isdn"><?php print_string('auth_ldap_memberattribute_isdn_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="memberattribute_isdn" id="memberattribute_isdn" type="text" size="30" value="<?php echo $config->memberattribute_isdn?>" />
-        <?php if (isset($err['memberattribute_isdn'])) { echo $OUTPUT->error_text($err['memberattribute_isdn']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_memberattribute_isdn', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="objectclass"><?php print_string('auth_ldap_objectclass_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="objectclass" id="objectclass" type="text" size="30" value="<?php echo $config->objectclass?>" />
-        <?php if (isset($err['objectclass'])) { echo $OUTPUT->error_text($err['objectclass']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_objectclass', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr>
-    <td colspan="2">
-        <h4><?php print_string('coursecreators') ?></h4>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="attrcreators"><?php print_string('auth_ldap_attrcreators_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="attrcreators" id="attrcreators" type="text" size="30" value="<?php echo $config->attrcreators?>" />
-        <?php if (isset($err['attrcreators'])) { echo $OUTPUT->error_text($err['attrcreators']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_attrcreators', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="groupecreators"><?php print_string('auth_ldap_groupecreators_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="groupecreators" id="groupecreators" type="text" size="30" value="<?php echo $config->groupecreators?>" />
-        <?php if (isset($err['groupecreators'])) { echo $OUTPUT->error_text($err['groupecreators']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_groupecreators', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr>
-    <td colspan="2">
-        <h4><?php print_string('auth_sync_script', 'auth') ?></h4>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right">
-        <label for="menuremoveuser"><?php print_string('auth_remove_user_key', 'auth') ?></label>
-    </td>
-    <td>
-        <?php
-             $deleteopt = array();
-             $deleteopt[AUTH_REMOVEUSER_KEEP] = get_string('auth_remove_keep', 'auth');
-             $deleteopt[AUTH_REMOVEUSER_SUSPEND] = get_string('auth_remove_suspend', 'auth');
-             $deleteopt[AUTH_REMOVEUSER_FULLDELETE] = get_string('auth_remove_delete', 'auth');
-             echo html_writer::select($deleteopt, 'removeuser', $config->removeuser, false);
-        ?>
-    </td>
-    <td>
-        <?php print_string('auth_remove_user', 'auth') ?>
-    </td>
-</tr>
-<?php
-$help  = get_string('auth_ldapextrafields', 'auth_ldap');
-$help .= get_string('auth_updatelocal_expl', 'auth');
-$help .= get_string('auth_fieldlock_expl', 'auth');
-$help .= get_string('auth_updateremote_expl', 'auth');
-$help .= '<hr />';
-$help .= get_string('auth_updateremote_ldap', 'auth');
-
-print_auth_lock_options($this->authtype, $user_fields, $help, true, true, $this->get_custom_user_profile_fields());
-?>
-</table>
index 81eefd0..9de6515 100644 (file)
@@ -25,6 +25,7 @@
 defined('MOODLE_INTERNAL') || die();
 
 /**
+ * Function to upgrade auth_cas.
  * @param int $oldversion the version we are upgrading from
  * @return bool result
  */
@@ -58,5 +59,11 @@ function xmldb_auth_cas_upgrade($oldversion) {
     // Automatically generated Moodle v3.2.0 release upgrade line.
     // Put any upgrade step following this.
 
+    if ($oldversion < 2017020700) {
+        // Convert info in config plugins from auth/cas to auth_cas.
+        $DB->set_field('config_plugins', 'plugin', 'auth_cas', array('plugin' => 'auth/cas'));
+        upgrade_plugin_savepoint(true, 2017020700, 'auth', 'cas');
+    }
+
     return true;
 }
diff --git a/auth/cas/settings.php b/auth/cas/settings.php
new file mode 100644 (file)
index 0000000..2e8c197
--- /dev/null
@@ -0,0 +1,273 @@
+<?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/>.
+
+/**
+ * Admin settings and defaults.
+ *
+ * @package auth_cas
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+if ($ADMIN->fulltree) {
+
+    // We use a couple of custom admin settings since we need to massage the data before it is inserted into the DB.
+    require_once($CFG->dirroot.'/auth/ldap/classes/admin_setting_special_lowercase_configtext.php');
+    require_once($CFG->dirroot.'/auth/ldap/classes/admin_setting_special_contexts_configtext.php');
+
+    // Include needed files.
+    require_once($CFG->dirroot.'/auth/cas/auth.php');
+    require_once($CFG->dirroot.'/auth/cas/languages.php');
+
+    // Introductory explanation.
+    $settings->add(new admin_setting_heading('auth_cas/pluginname', '',
+            new lang_string('auth_casdescription', 'auth_cas')));
+
+    // CAS server configuration label.
+    $settings->add(new admin_setting_heading('auth_cas/casserversettings',
+            new lang_string('auth_cas_server_settings', 'auth_cas'), ''));
+
+    // Hostname.
+    $settings->add(new admin_setting_configtext('auth_cas/hostname',
+            get_string('auth_cas_hostname_key', 'auth_cas'),
+            get_string('auth_cas_hostname', 'auth_cas'), '', PARAM_RAW_TRIMMED));
+
+    // Base URI.
+    $settings->add(new admin_setting_configtext('auth_cas/baseuri',
+            get_string('auth_cas_baseuri_key', 'auth_cas'),
+            get_string('auth_cas_baseuri', 'auth_cas'), '', PARAM_RAW_TRIMMED));
+
+    // Port.
+    $settings->add(new admin_setting_configtext('auth_cas/port',
+            get_string('auth_cas_port_key', 'auth_cas'),
+            get_string('auth_cas_port', 'auth_cas'), '', PARAM_INT));
+
+    // CAS Version.
+    $casversions = array();
+    $casversions[CAS_VERSION_1_0] = 'CAS 1.0';
+    $casversions[CAS_VERSION_2_0] = 'CAS 2.0';
+    $settings->add(new admin_setting_configselect('auth_cas/casversion',
+            new lang_string('auth_cas_casversion', 'auth_cas'),
+            new lang_string('auth_cas_version', 'auth_cas'), CAS_VERSION_2_0, $casversions));
+
+    // Language.
+    if (!isset($CASLANGUAGES) || empty($CASLANGUAGES)) {
+        // Prevent warnings on other admin pages.
+        // $CASLANGUAGES is defined in /auth/cas/languages.php.
+        $CASLANGUAGES = array();
+        $CASLANGUAGES[PHPCAS_LANG_ENGLISH] = 'English';
+        $CASLANGUAGES[PHPCAS_LANG_FRENCH] = 'French';
+    }
+    $settings->add(new admin_setting_configselect('auth_cas/language',
+            new lang_string('auth_cas_language_key', 'auth_cas'),
+            new lang_string('auth_cas_language', 'auth_cas'), '', $CASLANGUAGES));
+
+    // Proxy.
+    $yesno = array(
+        new lang_string('no'),
+        new lang_string('yes'),
+    );
+    $settings->add(new admin_setting_configselect('auth_cas/proxycas',
+            new lang_string('auth_cas_proxycas_key', 'auth_cas'),
+            new lang_string('auth_cas_proxycas', 'auth_cas'), 0 , $yesno));
+
+    // Logout option.
+    $settings->add(new admin_setting_configselect('auth_cas/logoutcas',
+            new lang_string('auth_cas_logoutcas_key', 'auth_cas'),
+            new lang_string('auth_cas_logoutcas', 'auth_cas'), 0 , $yesno));
+
+    // Multi-auth.
+    $settings->add(new admin_setting_configselect('auth_cas/multiauth',
+            new lang_string('auth_cas_multiauth_key', 'auth_cas'),
+            new lang_string('auth_cas_multiauth', 'auth_cas'), 0 , $yesno));
+
+    // Server validation.
+    $settings->add(new admin_setting_configselect('auth_cas/certificate_check',
+            new lang_string('auth_cas_certificate_check_key', 'auth_cas'),
+            new lang_string('auth_cas_certificate_check', 'auth_cas'), 0 , $yesno));
+
+    // Certificate path.
+    $settings->add(new admin_setting_configfile('auth_cas/certificate_path',
+            get_string('auth_cas_certificate_path_key', 'auth_cas'),
+            get_string('auth_cas_certificate_path', 'auth_cas'), ''));
+
+    // CURL SSL version.
+    $sslversions = array();
+    $sslversions[''] = get_string('auth_cas_curl_ssl_version_default', 'auth_cas');
+    if (defined('CURL_SSLVERSION_TLSv1')) {
+        $sslversions[CURL_SSLVERSION_TLSv1] = get_string('auth_cas_curl_ssl_version_TLSv1x', 'auth_cas');
+    }
+    if (defined('CURL_SSLVERSION_TLSv1_0')) {
+        $sslversions[CURL_SSLVERSION_TLSv1_0] = get_string('auth_cas_curl_ssl_version_TLSv10', 'auth_cas');
+    }
+    if (defined('CURL_SSLVERSION_TLSv1_1')) {
+        $sslversions[CURL_SSLVERSION_TLSv1_1] = get_string('auth_cas_curl_ssl_version_TLSv11', 'auth_cas');
+    }
+    if (defined('CURL_SSLVERSION_TLSv1_2')) {
+        $sslversions[CURL_SSLVERSION_TLSv1_2] = get_string('auth_cas_curl_ssl_version_TLSv12', 'auth_cas');
+    }
+    if (defined('CURL_SSLVERSION_SSLv2')) {
+        $sslversions[CURL_SSLVERSION_SSLv2] = get_string('auth_cas_curl_ssl_version_SSLv2', 'auth_cas');
+    }
+    if (defined('CURL_SSLVERSION_SSLv3')) {
+        $sslversions[CURL_SSLVERSION_SSLv3] = get_string('auth_cas_curl_ssl_version_SSLv3', 'auth_cas');
+    }
+    $settings->add(new admin_setting_configselect('auth_cas/curl_ssl_version',
+            new lang_string('auth_cas_curl_ssl_version_key', 'auth_cas'),
+            new lang_string('auth_cas_curl_ssl_version', 'auth_cas'), '' , $sslversions));
+
+    // Alt Logout URL.
+    $settings->add(new admin_setting_configtext('auth_cas/logout_return_url',
+            get_string('auth_cas_logout_return_url_key', 'auth_cas'),
+            get_string('auth_cas_logout_return_url', 'auth_cas'), '', PARAM_URL));
+
+    // LDAP server settings.
+    $settings->add(new admin_setting_heading('auth_cas/ldapserversettings',
+            new lang_string('auth_ldap_server_settings', 'auth_ldap'), ''));
+
+    // Host.
+    $settings->add(new admin_setting_configtext('auth_cas/host_url',
+            get_string('auth_ldap_host_url_key', 'auth_ldap'),
+            get_string('auth_ldap_host_url', 'auth_ldap'), '', PARAM_RAW_TRIMMED));
+
+    // Version.
+    $versions = array();
+    $versions[2] = '2';
+    $versions[3] = '3';
+    $settings->add(new admin_setting_configselect('auth_cas/ldap_version',
+            new lang_string('auth_ldap_version_key', 'auth_ldap'),
+            new lang_string('auth_ldap_version', 'auth_ldap'), 3, $versions));
+
+    // Start TLS.
+    $settings->add(new admin_setting_configselect('auth_cas/start_tls',
+            new lang_string('start_tls_key', 'auth_ldap'),
+            new lang_string('start_tls', 'auth_ldap'), 0 , $yesno));
+
+
+    // Encoding.
+    $settings->add(new admin_setting_configtext('auth_cas/ldapencoding',
+            get_string('auth_ldap_ldap_encoding_key', 'auth_ldap'),
+            get_string('auth_ldap_ldap_encoding', 'auth_ldap'), 'utf-8', PARAM_RAW_TRIMMED));
+
+    // Page Size. (Hide if not available).
+    $settings->add(new admin_setting_configtext('auth_cas/pagesize',
+            get_string('pagesize_key', 'auth_ldap'),
+            get_string('pagesize', 'auth_ldap'), '250', PARAM_INT));
+
+    // Bind settings.
+    $settings->add(new admin_setting_heading('auth_cas/ldapbindsettings',
+            new lang_string('auth_ldap_bind_settings', 'auth_ldap'), ''));
+
+    // User ID.
+    $settings->add(new admin_setting_configtext('auth_cas/bind_dn',
+            get_string('auth_ldap_bind_dn_key', 'auth_ldap'),
+            get_string('auth_ldap_bind_dn', 'auth_ldap'), '', PARAM_RAW_TRIMMED));
+
+    // Password.
+    $settings->add(new admin_setting_configpasswordunmask('auth_cas/bind_pw',
+            get_string('auth_ldap_bind_pw_key', 'auth_ldap'),
+            get_string('auth_ldap_bind_pw', 'auth_ldap'), ''));
+
+    // User Lookup settings.
+    $settings->add(new admin_setting_heading('auth_cas/ldapuserlookup',
+            new lang_string('auth_ldap_user_settings', 'auth_ldap'), ''));
+
+    // User Type.
+    $settings->add(new admin_setting_configselect('auth_cas/user_type',
+            new lang_string('auth_ldap_user_type_key', 'auth_ldap'),
+            new lang_string('auth_ldap_user_type', 'auth_ldap'), 'default', ldap_supported_usertypes()));
+
+    // Contexts.
+    $settings->add(new auth_ldap_admin_setting_special_contexts_configtext('auth_cas/contexts',
+            get_string('auth_ldap_contexts_key', 'auth_ldap'),
+            get_string('auth_ldap_contexts', 'auth_ldap'), '', PARAM_RAW_TRIMMED));
+
+    // Search subcontexts.
+    $settings->add(new admin_setting_configselect('auth_cas/search_sub',
+            new lang_string('auth_ldap_search_sub_key', 'auth_ldap'),
+            new lang_string('auth_ldap_search_sub', 'auth_ldap'), 0 , $yesno));
+
+    // Dereference aliases.
+    $optderef = array();
+    $optderef[LDAP_DEREF_NEVER] = get_string('no');
+    $optderef[LDAP_DEREF_ALWAYS] = get_string('yes');
+
+    $settings->add(new admin_setting_configselect('auth_cas/opt_deref',
+            new lang_string('auth_ldap_opt_deref_key', 'auth_ldap'),
+            new lang_string('auth_ldap_opt_deref', 'auth_ldap'), LDAP_DEREF_NEVER , $optderef));
+
+    // User attribute.
+    $settings->add(new auth_ldap_admin_setting_special_lowercase_configtext('auth_cas/user_attribute',
+            get_string('auth_ldap_user_attribute_key', 'auth_ldap'),
+            get_string('auth_ldap_user_attribute', 'auth_ldap'), '', PARAM_RAW));
+
+    // Member attribute.
+    $settings->add(new auth_ldap_admin_setting_special_lowercase_configtext('auth_cas/memberattribute',
+            get_string('auth_ldap_memberattribute_key', 'auth_ldap'),
+            get_string('auth_ldap_memberattribute', 'auth_ldap'), '', PARAM_RAW));
+
+    // Member attribute uses dn.
+    $settings->add(new admin_setting_configtext('auth_cas/memberattribute_isdn',
+            get_string('auth_ldap_memberattribute_isdn_key', 'auth_ldap'),
+            get_string('auth_ldap_memberattribute_isdn', 'auth_ldap'), '', PARAM_RAW));
+
+    // Object class.
+    $settings->add(new admin_setting_configtext('auth_cas/objectclass',
+            get_string('auth_ldap_objectclass_key', 'auth_ldap'),
+            get_string('auth_ldap_objectclass', 'auth_ldap'), '', PARAM_RAW_TRIMMED));
+
+    // Course Creators Header.
+    $settings->add(new admin_setting_heading('auth_cas/coursecreators',
+            new lang_string('coursecreators'), ''));
+
+    // Course creators attribute field mapping.
+    $settings->add(new admin_setting_configtext('auth_cas/attrcreators',
+            get_string('auth_ldap_attrcreators_key', 'auth_ldap'),
+            get_string('auth_ldap_attrcreators', 'auth_ldap'), '', PARAM_RAW_TRIMMED));
+
+    // Course creator group field mapping.
+    $settings->add(new admin_setting_configtext('auth_cas/groupecreators',
+            get_string('auth_ldap_groupecreators_key', 'auth_ldap'),
+            get_string('auth_ldap_groupecreators', 'auth_ldap'), '', PARAM_RAW_TRIMMED));
+
+    // User Account Sync.
+    $settings->add(new admin_setting_heading('auth_cas/syncusers',
+            new lang_string('auth_sync_script', 'auth'), ''));
+
+    // Remove external user.
+    $deleteopt = array();
+    $deleteopt[AUTH_REMOVEUSER_KEEP] = get_string('auth_remove_keep', 'auth');
+    $deleteopt[AUTH_REMOVEUSER_SUSPEND] = get_string('auth_remove_suspend', 'auth');
+    $deleteopt[AUTH_REMOVEUSER_FULLDELETE] = get_string('auth_remove_delete', 'auth');
+
+    $settings->add(new admin_setting_configselect('auth_cas/removeuser',
+            new lang_string('auth_remove_user_key', 'auth'),
+            new lang_string('auth_remove_user', 'auth'), AUTH_REMOVEUSER_KEEP, $deleteopt));
+
+    // Display locking / mapping of profile fields.
+    $authplugin = get_auth_plugin($this->name);
+    $help  = get_string('auth_ldapextrafields', 'auth_ldap');
+    $help .= get_string('auth_updatelocal_expl', 'auth');
+    $help .= get_string('auth_fieldlock_expl', 'auth');
+    $help .= get_string('auth_updateremote_expl', 'auth');
+    $help .= '<hr />';
+    $help .= get_string('auth_updateremote_ldap', 'auth');
+    display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields, $help, true, true,
+            $authplugin->get_custom_user_profile_fields());
+
+}
diff --git a/auth/cas/upgrade.txt b/auth/cas/upgrade.txt
new file mode 100644 (file)
index 0000000..91adb9e
--- /dev/null
@@ -0,0 +1,7 @@
+This files describes API changes in /auth/cas/*,
+information provided here is intended especially for developers.
+
+=== 3.3 ===
+
+* The config.html file was migrated to use the admin settings API.
+  The identifier for configuration data stored in config_plugins table was converted from 'auth/cas' to 'auth_cas'.
index 6ccab58..26f3bc5 100644 (file)
@@ -26,8 +26,8 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version   = 2016120500;        // The current plugin version (Date: YYYYMMDDXX)
+$plugin->version   = 2017020700;        // The current plugin version (Date: YYYYMMDDXX)
 $plugin->requires  = 2016112900;        // Requires this Moodle version
 $plugin->component = 'auth_cas';        // Full name of the plugin (used for diagnostics)
 
-$plugin->dependencies = array('auth_ldap' => 2016112900);
+$plugin->dependencies = array('auth_ldap' => 2017020700);
index a58dfe6..421171a 100644 (file)
@@ -124,7 +124,13 @@ class login implements renderable, templatable {
         global $CFG;
 
         $identityproviders = array_map(function($idp) use ($output) {
-            $idp['icon'] = $idp['icon']->export_for_template($output);
+
+            if (!empty($idp['icon'])) {
+                $idp['iconurl'] = $output->pix_url($idp['icon']->key, $idp['icon']->component);
+            } else if ($idp['iconurl'] instanceof moodle_url) {
+                $idp['iconurl'] = $idp['iconurl']->out(false);
+            }
+            unset($idp['icon']);
             if ($idp['url'] instanceof moodle_url) {
                 $idp['url'] = $idp['url']->out(false);
             }
index 5660978..90e0fa9 100644 (file)
@@ -41,7 +41,7 @@ class auth_plugin_db extends auth_plugin_base {
         require_once($CFG->libdir.'/adodb/adodb.inc.php');
 
         $this->authtype = 'db';
-        $this->config = get_config('auth/db');
+        $this->config = get_config('auth_db');
         if (empty($this->config->extencoding)) {
             $this->config->extencoding = 'utf-8';
         }
@@ -661,21 +661,6 @@ class auth_plugin_db extends auth_plugin_base {
         return true;
     }
 
-    /**
-     * A chance to validate form data, and last chance to
-     * do stuff before it is inserted in config_plugin
-     *
-     * @param stfdClass $form
-     * @param array $err errors
-     * @return void
-     */
-     function validate_form($form, &$err) {
-        if ($form->passtype === 'internal') {
-            $this->config->changepasswordurl = '';
-            set_config('changepasswordurl', '', 'auth/db');
-        }
-    }
-
     function prevent_local_passwords() {
         return !$this->is_internal();
     }
@@ -752,95 +737,6 @@ class auth_plugin_db extends auth_plugin_base {
         return $this->is_internal();
     }
 
-    /**
-     * Prints a form for configuring this authentication plugin.
-     *
-     * This function is called from admin/auth.php, and outputs a full page with
-     * a form for configuring this plugin.
-     *
-     * @param stdClass $config
-     * @param array $err errors
-     * @param array $user_fields
-     * @return void
-     */
-    function config_form($config, $err, $user_fields) {
-        include 'config.html';
-    }
-
-    /**
-     * Processes and stores configuration data for this authentication plugin.
-     *
-     * @param srdClass $config
-     * @return bool always true or exception
-     */
-    function process_config($config) {
-        // set to defaults if undefined
-        if (!isset($config->host)) {
-            $config->host = 'localhost';
-        }
-        if (!isset($config->type)) {
-            $config->type = 'mysql';
-        }
-        if (!isset($config->sybasequoting)) {
-            $config->sybasequoting = 0;
-        }
-        if (!isset($config->name)) {
-            $config->name = '';
-        }
-        if (!isset($config->user)) {
-            $config->user = '';
-        }
-        if (!isset($config->pass)) {
-            $config->pass = '';
-        }
-        if (!isset($config->table)) {
-            $config->table = '';
-        }
-        if (!isset($config->fielduser)) {
-            $config->fielduser = '';
-        }
-        if (!isset($config->fieldpass)) {
-            $config->fieldpass = '';
-        }
-        if (!isset($config->passtype)) {
-            $config->passtype = 'plaintext';
-        }
-        if (!isset($config->extencoding)) {
-            $config->extencoding = 'utf-8';
-        }
-        if (!isset($config->setupsql)) {
-            $config->setupsql = '';
-        }
-        if (!isset($config->debugauthdb)) {
-            $config->debugauthdb = 0;
-        }
-        if (!isset($config->removeuser)) {
-            $config->removeuser = AUTH_REMOVEUSER_KEEP;
-        }
-        if (!isset($config->changepasswordurl)) {
-            $config->changepasswordurl = '';
-        }
-
-        // Save settings.
-        set_config('host',          $config->host,          'auth/db');
-        set_config('type',          $config->type,          'auth/db');
-        set_config('sybasequoting', $config->sybasequoting, 'auth/db');
-        set_config('name',          $config->name,          'auth/db');
-        set_config('user',          $config->user,          'auth/db');
-        set_config('pass',          $config->pass,          'auth/db');
-        set_config('table',         $config->table,         'auth/db');
-        set_config('fielduser',     $config->fielduser,     'auth/db');
-        set_config('fieldpass',     $config->fieldpass,     'auth/db');
-        set_config('passtype',      $config->passtype,      'auth/db');
-        set_config('extencoding',   trim($config->extencoding), 'auth/db');
-        set_config('setupsql',      trim($config->setupsql),'auth/db');
-        set_config('debugauthdb',   $config->debugauthdb,   'auth/db');
-        set_config('removeuser',    $config->removeuser,    'auth/db');
-        set_config('changepasswordurl', trim($config->changepasswordurl), 'auth/db');
-
-        return true;
-    }
-
     /**
      * Add slashes, we can not use placeholders or system functions.
      *
diff --git a/auth/db/classes/admin_setting_special_auth_configtext.php b/auth/db/classes/admin_setting_special_auth_configtext.php
new file mode 100644 (file)
index 0000000..50cd89a
--- /dev/null
@@ -0,0 +1,51 @@
+<?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/>.
+
+/**
+ * Special settings for auth_db password_link.
+ *
+ * @package    auth_db
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Special settings for auth_db password_link.
+ *
+ * @package    auth_db
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class auth_db_admin_setting_special_auth_configtext extends admin_setting_configtext {
+
+    /**
+     * We need to overwrite the global "alternate login url" setting if wayf is enabled.
+     *
+     * @param string $data Form data.
+     * @return string Empty when no errors.
+     */
+    public function write_setting($data) {
+
+        if (get_config('auth_db', 'passtype') === 'internal') {
+            // We need to clear the auth_db change password link.
+            $data = '';
+        }
+
+        return parent::write_setting($data);
+    }
+}
index 59b7bc1..a7ac128 100644 (file)
@@ -54,7 +54,7 @@ class sync_users extends \core\task\scheduled_task {
         }
 
         $dbauth = get_auth_plugin('db');
-        $config = get_config('auth/db');
+        $config = get_config('auth_db');
         $trace = new \text_progress_trace();
         $update = !empty($config->updateusers);
         $dbauth->sync_users($trace, $update);
diff --git a/auth/db/config.html b/auth/db/config.html
deleted file mode 100644 (file)
index fb751d0..0000000
+++ /dev/null
@@ -1,289 +0,0 @@
-<?php
-    global $OUTPUT;
-    // set to defaults if undefined
-    if (!isset($config->host)) {
-        $config->host = 'localhost';
-    }
-    if (!isset($config->type)) {
-        $config->type = 'mysql';
-    }
-    if (!isset($config->sybasequoting)) {
-        $config->sybasequoting = 0;
-    }
-    if (!isset($config->name)) {
-        $config->name = '';
-    }
-    if (!isset($config->user)) {
-        $config->user = '';
-    }
-    if (!isset($config->pass)) {
-        $config->pass = '';
-    }
-    if (!isset($config->table)) {
-        $config->table = '';
-    }
-    if (!isset($config->fielduser)) {
-        $config->fielduser = '';
-    }
-    if (!isset($config->fieldpass)) {
-        $config->fieldpass = '';
-    }
-    if (!isset($config->passtype)) {
-        $config->passtype = 'plaintext';
-    }
-    if (!isset($config->changepasswordurl)) {
-        $config->changepasswordurl = '';
-    }
-    if (empty($config->extencoding)) {
-        $config->extencoding = 'utf-8';
-    }
-    if (empty($config->debugauthdb)) {
-        $config->debugauthdb = 0;
-    }
-    if (!isset($config->setupsql)) {
-        $config->setupsql = '';
-    }
-    if (!isset($config->removeuser)) {
-        $config->removeuser = AUTH_REMOVEUSER_KEEP;
-    }
-    if (!isset($config->updateusers)) {
-        $config->updateusers = 0;
-    }
-
-    $yesno = array( get_string('no'), get_string('yes') );
-
-?>
-<table cellspacing="0" cellpadding="5" border="0">
-
-<tr valign="top" class="required">
-    <td align="right"><label for="host"><?php print_string("auth_dbhost_key", "auth_db") ?></label></td>
-    <td>
-        <input id="host" name="host" type="text" class="text-ltr" size="30" value="<?php echo $config->host?>" />
-        <?php
-
-        if (isset($err["host"])) {
-            echo $OUTPUT->error_text($err["host"]);
-        }
-
-        ?>
-    </td>
-    <td><?php print_string("auth_dbhost", "auth_db") ?></td>
-</tr>
-
-<tr valign="top" class="required">
-    <td align="right"><label for="menutype"><?php print_string("auth_dbtype_key", "auth_db") ?></label></td>
-    <td>
-    <?php  $dbtypes = array("access","ado_access", "ado", "ado_mssql", "borland_ibase", "csv", "db2", "fbsql", "firebird", "ibase", "informix72", "informix", "mssql", "mssql_n", "mssqlnative", "mysql", "mysqli", "mysqlt", "oci805", "oci8", "oci8po", "odbc", "odbc_mssql", "odbc_oracle", "oracle", "postgres64", "postgres7", "postgres", "proxy", "sqlanywhere", "sybase", "vfp");
-       foreach ($dbtypes as $dbtype) {
-           $dboptions[$dbtype] = $dbtype;
-       }
-       echo html_writer::select($dboptions, "type", $config->type, false);
-    ?>
-
-    </td>
-    <td>
-    <?php print_string("auth_dbtype","auth_db") ?>
-    </td>
-</tr>
-
-<tr valign="top" class="required">
-    <td align="right"><label for="menusybasequoting"><?php print_string("auth_dbsybasequoting", "auth_db") ?></label></td>
-    <td>
-        <?php echo html_writer::select($yesno, 'sybasequoting', $config->sybasequoting, false); ?>
-    </td>
-    <td><?php print_string("auth_dbsybasequotinghelp", "auth_db") ?></td>
-</tr>
-
-<tr valign="top" class="required">
-    <td align="right"><label for="name"><?php print_string("auth_dbname_key", "auth_db") ?></label></td>
-    <td>
-        <input id="name" name="name" type="text" class="text-ltr" size="30" value="<?php echo $config->name?>" />
-        <?php
-
-        if (isset($err["name"])) {
-            echo $OUTPUT->error_text($err["name"]);
-        }
-
-        ?>
-    </td>
-    <td><?php print_string("auth_dbname", "auth_db") ?></td>
-</tr>
-
-<tr valign="top" class="required">
-    <td align="right"><label for="user"><?php print_string("auth_dbuser_key", "auth_db") ?></label></td>
-    <td>
-        <input id="user" name="user" type="text" class="text-ltr" size="30" value="<?php echo $config->user?>" />
-        <?php
-
-        if (isset($err["user"])) {
-            echo $OUTPUT->error_text($err["user"]);
-        }
-
-        ?>
-    </td>
-    <td><?php print_string("auth_dbuser", "auth_db") ?></td>
-</tr>
-
-<tr valign="top" class="required">
-    <td align="right"><label for="pass"><?php print_string("auth_dbpass_key", "auth_db") ?></label></td>
-    <td>
-        <input id="pass" name="pass" type="password" class="text-ltr" size="30" value="<?php p($config->pass)?>" autocomplete="off"/>
-        <?php
-
-        if (isset($err["pass"])) {
-            echo $OUTPUT->error_text($err["pass"]);
-        }
-
-        ?>
-    </td>
-    <td>
-    <?php print_string("auth_dbpass", "auth_db") ?>
-    </td>
-</tr>
-
-<tr valign="top" class="required">
-    <td align="right"><label for="table"><?php print_string("auth_dbtable_key", "auth_db") ?></label></td>
-    <td>
-        <input id="table" name="table" type="text" class="text-ltr" size="30" value="<?php echo $config->table?>" />
-        <?php
-
-        if (isset($err["table"])) {
-            echo $OUTPUT->error_text($err["table"]);
-        }
-
-        ?>
-    </td>
-    <td><?php print_string("auth_dbtable", "auth_db") ?></td>
-</tr>
-
-<tr valign="top" class="required">
-    <td align="right"><label for="fielduser"><?php print_string("auth_dbfielduser_key", "auth_db") ?></label></td>
-    <td>
-        <input id="fielduser" name="fielduser" type="text" class="text-ltr" size="30" value="<?php echo $config->fielduser?>" />
-        <?php
-
-        if (isset($err["fielduser"])) {
-            echo $OUTPUT->error_text($err["fielduser"]);
-        }
-
-        ?>
-    </td>
-    <td><?php print_string("auth_dbfielduser", "auth_db") ?></td>
-</tr>
-
-<tr valign="top" class="required">
-    <td align="right"><label for="fieldpass"><?php print_string("auth_dbfieldpass_key", "auth_db") ?></label></td>
-    <td>
-        <input id="fieldpass" name="fieldpass" type="text" class="text-ltr" size="30" value="<?php echo $config->fieldpass?>" />
-        <?php
-
-        if (isset($err["fieldpass"])) {
-            echo $OUTPUT->error_text($err["fieldpass"]);
-        }
-
-        ?>
-    </td>
-    <td><?php print_string("auth_dbfieldpass", "auth_db") ?></td>
-</tr>
-
-<tr valign="top" class="required">
-    <td align="right"><label for="menupasstype"><?php print_string("auth_dbpasstype_key", "auth_db") ?></label></td>
-    <td>
-        <?php
-        $passtype = array();
-        $passtype["plaintext"] = get_string("plaintext", "auth");
-        $passtype["md5"]       = get_string("md5", "auth");
-        $passtype["sha1"]      = get_string("sha1", "auth");
-        $passtype["saltedcrypt"]      = get_string("auth_dbsaltedcrypt", "auth_db");
-        $passtype["internal"]  = get_string("internal", "auth");
-        echo html_writer::select($passtype, "passtype", $config->passtype, false);
-
-        ?>
-    </td>
-    <td><?php print_string("auth_dbpasstype", "auth_db") ?></td>
-</tr>
-
-<tr valign="top" class="required">
-    <td align="right"><label for="extencoding"><?php print_string("auth_dbextencoding", "auth_db") ?></label></td>
-    <td>
-        <input id="extencoding" name="extencoding" type="text" class="text-ltr" value="<?php echo $config->extencoding ?>" />
-        <?php
-
-        if (isset($err['extencoding'])) {
-            echo $OUTPUT->error_text($err['extencoding']);
-        }
-
-        ?>
-    </td>
-    <td><?php print_string('auth_dbextencodinghelp', 'auth_db') ?></td>
-</tr>
-
-<tr valign="top">
-    <td align="right"><label for="setupsql"><?php print_string("auth_dbsetupsql", "auth_db") ?></label></td>
-    <td>
-        <input id="setupsql" name="setupsql" type="text" class="text-ltr" value="<?php echo $config->setupsql ?>" />
-    </td>
-    <td><?php print_string('auth_dbsetupsqlhelp', 'auth_db') ?></td>
-</tr>
-
-<tr valign="top">
-    <td align="right"><label for="menudebugauthdb"><?php print_string("auth_dbdebugauthdb", "auth_db") ?></label></td>
-    <td>
-        <?php echo html_writer::select($yesno, 'debugauthdb', $config->debugauthdb, false); ?>
-    </td>
-    <td><?php print_string("auth_dbdebugauthdbhelp", "auth_db") ?></td>
-</tr>
-
-<tr valign="top">
-    <td align="right"><label for="changepasswordurl"><?php print_string("auth_dbchangepasswordurl_key", "auth_db") ?></label></td>
-    <td>
-        <input id="changepasswordurl" name="changepasswordurl" type="text" class="text-ltr" value="<?php echo $config->changepasswordurl ?>" />
-        <?php
-
-        if (isset($err['changepasswordurl'])) {
-            echo $OUTPUT->error_text($err['changepasswordurl']);
-        }
-
-        ?>
-    </td>
-    <td><?php print_string('changepasswordhelp', 'auth') ?></td>
-</tr>
-
-<tr>
-   <td colspan="2">
-        <h4><?php print_string('auth_sync_script', 'auth') ?> </h4>
-   </td>
-</tr>
-
-<tr valign="top">
-    <td align="right"><label for="menuremoveuser"><?php print_string('auth_remove_user_key','auth') ?></label></td>
-    <td>
-    <?php
-       $deleteopt = array();
-       $deleteopt[AUTH_REMOVEUSER_KEEP] = get_string('auth_remove_keep','auth');
-       $deleteopt[AUTH_REMOVEUSER_SUSPEND] = get_string('auth_remove_suspend','auth');
-       $deleteopt[AUTH_REMOVEUSER_FULLDELETE] = get_string('auth_remove_delete','auth');
-       echo html_writer::select($deleteopt, 'removeuser', $config->removeuser, false);
-    ?>
-    </td>
-    <td>
-    <?php print_string('auth_remove_user','auth') ?>
-    </td>
-</tr>
-
-<tr valign="top">
-    <td align="right"><label for="menuupdateusers"><?php print_string('auth_dbupdateusers', 'auth_db') ?></label></td>
-    <td>
-        <?php echo html_writer::select($yesno, 'updateusers', $config->updateusers, false); ?>
-    </td>
-    <td>
-        <?php print_string('auth_dbupdateusers_description','auth_db') ?>
-    </td>
-</tr>
-
-<?php
-
-print_auth_lock_options($this->authtype, $user_fields, get_string('auth_dbextrafields', 'auth_db'), true, true, $this->get_custom_user_profile_fields());
-
-?>
-</table>
diff --git a/auth/db/db/upgrade.php b/auth/db/db/upgrade.php
new file mode 100644 (file)
index 0000000..08db727
--- /dev/null
@@ -0,0 +1,45 @@
+<?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/>.
+
+/**
+ * DB authentication plugin upgrade code
+ *
+ * @package    auth_db
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Function to upgrade auth_db.
+ * @param int $oldversion the version we are upgrading from
+ * @return bool result
+ */
+function xmldb_auth_db_upgrade($oldversion) {
+    global $CFG, $DB;
+
+    // Automatically generated Moodle v3.2.0 release upgrade line.
+    // Put any upgrade step following this.
+
+    if ($oldversion < 2017032800) {
+        // Convert info in config plugins from auth/db to auth_db
+        $DB->set_field('config_plugins', 'plugin', 'auth_db', array('plugin' => 'auth/db'));
+        upgrade_plugin_savepoint(true, 2017032800, 'auth', 'db');
+    }
+
+    return true;
+}
diff --git a/auth/db/settings.php b/auth/db/settings.php
new file mode 100644 (file)
index 0000000..64479d1
--- /dev/null
@@ -0,0 +1,143 @@
+<?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/>.
+
+/**
+ * Admin settings and defaults.
+ *
+ * @package auth_db
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+if ($ADMIN->fulltree) {
+
+    // We use a couple of custom admin settings since we need to massage the data before it is inserted into the DB.
+    require_once($CFG->dirroot.'/auth/db/classes/admin_setting_special_auth_configtext.php');
+
+    // Needed for constants.
+    require_once($CFG->libdir.'/authlib.php');
+
+    // Introductory explanation.
+    $settings->add(new admin_setting_heading('auth_db/pluginname', '', new lang_string('auth_dbdescription', 'auth_db')));
+
+    // Host.
+    $settings->add(new admin_setting_configtext('auth_db/host', get_string('auth_dbhost_key', 'auth_db'),
+            get_string('auth_dbhost', 'auth_db') . ' ' .get_string('auth_multiplehosts', 'auth'),
+            '127.0.0.1', PARAM_RAW));
+
+    // Type.
+    $dboptions = array();
+    $dbtypes = array("access", "ado_access", "ado", "ado_mssql", "borland_ibase", "csv", "db2",
+        "fbsql", "firebird", "ibase", "informix72", "informix", "mssql", "mssql_n", "mssqlnative",
+        "mysql", "mysqli", "mysqlt", "oci805", "oci8", "oci8po", "odbc", "odbc_mssql", "odbc_oracle",
+        "oracle", "postgres64", "postgres7", "postgres", "proxy", "sqlanywhere", "sybase", "vfp");
+    foreach ($dbtypes as $dbtype) {
+        $dboptions[$dbtype] = $dbtype;
+    }
+
+    $settings->add(new admin_setting_configselect('auth_db/type',
+        new lang_string('auth_dbtype_key', 'auth_db'),
+        new lang_string('auth_dbtype', 'auth_db'), 'mysqli', $dboptions));
+
+    // Sybase quotes.
+    $yesno = array(
+        new lang_string('no'),
+        new lang_string('yes'),
+    );
+
+    $settings->add(new admin_setting_configselect('auth_db/sybasequoting',
+        new lang_string('auth_dbsybasequoting', 'auth_db'), new lang_string('auth_dbsybasequotinghelp', 'auth_db'), 0, $yesno));
+
+    // DB Name.
+    $settings->add(new admin_setting_configtext('auth_db/name', get_string('auth_dbname_key', 'auth_db'),
+            get_string('auth_dbname', 'auth_db'), '', PARAM_RAW_TRIMMED));
+
+    // DB Username.
+    $settings->add(new admin_setting_configtext('auth_db/user', get_string('auth_dbuser_key', 'auth_db'),
+            get_string('auth_dbuser', 'auth_db'), '', PARAM_RAW_TRIMMED));
+
+    // Password.
+    $settings->add(new admin_setting_configpasswordunmask('auth_db/pass', get_string('auth_dbpass_key', 'auth_db'),
+            get_string('auth_dbpass', 'auth_db'), ''));
+
+    // DB Table.
+    $settings->add(new admin_setting_configtext('auth_db/table', get_string('auth_dbtable_key', 'auth_db'),
+            get_string('auth_dbtable', 'auth_db'), '', PARAM_RAW_TRIMMED));
+
+    // DB User field.
+    $settings->add(new admin_setting_configtext('auth_db/fielduser', get_string('auth_dbfielduser_key', 'auth_db'),
+            get_string('auth_dbfielduser', 'auth_db'), '', PARAM_RAW_TRIMMED));
+
+    // DB User password.
+    $settings->add(new admin_setting_configtext('auth_db/fieldpass', get_string('auth_dbfieldpass_key', 'auth_db'),
+            get_string('auth_dbfieldpass', 'auth_db'), '', PARAM_RAW_TRIMMED));
+
+
+    // DB Password Type.
+    $passtype = array();
+    $passtype["plaintext"]   = get_string("plaintext", "auth");
+    $passtype["md5"]         = get_string("md5", "auth");
+    $passtype["sha1"]        = get_string("sha1", "auth");
+    $passtype["saltedcrypt"] = get_string("auth_dbsaltedcrypt", "auth_db");
+    $passtype["internal"]    = get_string("internal", "auth");
+
+    $settings->add(new admin_setting_configselect('auth_db/passtype',
+        new lang_string('auth_dbpasstype_key', 'auth_db'), new lang_string('auth_dbpasstype', 'auth_db'), 'plaintext', $passtype));
+
+    // Encoding.
+    $settings->add(new admin_setting_configtext('auth_db/extencoding', get_string('auth_dbextencoding', 'auth_db'),
+            get_string('auth_dbextencodinghelp', 'auth_db'), 'utf-8', PARAM_RAW_TRIMMED));
+
+    // DB SQL SETUP.
+    $settings->add(new admin_setting_configtext('auth_db/setupsql', get_string('auth_dbsetupsql', 'auth_db'),
+            get_string('auth_dbsetupsqlhelp', 'auth_db'), '', PARAM_RAW_TRIMMED));
+
+    // Debug ADOOB.
+    $settings->add(new admin_setting_configselect('auth_db/debugauthdb',
+        new lang_string('auth_dbdebugauthdb', 'auth_db'), new lang_string('auth_dbdebugauthdbhelp', 'auth_db'), 0, $yesno));
+
+    // Password change URL.
+    $settings->add(new auth_db_admin_setting_special_auth_configtext('auth_db/changepasswordurl',
+            get_string('auth_dbchangepasswordurl_key', 'auth_db'),
+            get_string('changepasswordhelp', 'auth'), '', PARAM_URL));
+
+    // Label and Sync Options.
+    $settings->add(new admin_setting_heading('auth_db/usersync', new lang_string('auth_sync_script', 'auth'), ''));
+
+    // Sync Options.
+    $deleteopt = array();
+    $deleteopt[AUTH_REMOVEUSER_KEEP] = get_string('auth_remove_keep', 'auth');
+    $deleteopt[AUTH_REMOVEUSER_SUSPEND] = get_string('auth_remove_suspend', 'auth');
+    $deleteopt[AUTH_REMOVEUSER_FULLDELETE] = get_string('auth_remove_delete', 'auth');
+
+    $settings->add(new admin_setting_configselect('auth_db/removeuser',
+        new lang_string('auth_remove_user_key', 'auth'),
+        new lang_string('auth_remove_user', 'auth'), AUTH_REMOVEUSER_KEEP, $deleteopt));
+
+    // Update users.
+    $settings->add(new admin_setting_configselect('auth_db/updateusers',
+        new lang_string('auth_dbupdateusers', 'auth_db'),
+        new lang_string('auth_dbupdateusers_description', 'auth_db'), 0, $yesno));
+
+    // Display locking / mapping of profile fields.
+    $authplugin = get_auth_plugin($this->name);
+    display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
+            get_string('auth_dbextrafields', 'auth_db'),
+            true, true, $authplugin->get_custom_user_profile_fields());
+
+}
index 1c9e6de..2900719 100644 (file)
@@ -44,65 +44,65 @@ class auth_db_testcase extends advanced_testcase {
 
         $dbman = $DB->get_manager();
 
-        set_config('extencoding', 'utf-8', 'auth/db');
+        set_config('extencoding', 'utf-8', 'auth_db');
 
-        set_config('host', $CFG->dbhost, 'auth/db');
-        set_config('user', $CFG->dbuser, 'auth/db');
-        set_config('pass', $CFG->dbpass, 'auth/db');
-        set_config('name', $CFG->dbname, 'auth/db');
+        set_config('host', $CFG->dbhost, 'auth_db');
+        set_config('user', $CFG->dbuser, 'auth_db');
+        set_config('pass', $CFG->dbpass, 'auth_db');
+        set_config('name', $CFG->dbname, 'auth_db');
 
         if (!empty($CFG->dboptions['dbport'])) {
-            set_config('host', $CFG->dbhost.':'.$CFG->dboptions['dbport'], 'auth/db');
+            set_config('host', $CFG->dbhost.':'.$CFG->dboptions['dbport'], 'auth_db');
         }
 
         switch ($DB->get_dbfamily()) {
 
             case 'mysql':
-                set_config('type', 'mysqli', 'auth/db');
-                set_config('setupsql', "SET NAMES 'UTF-8'", 'auth/db');
-                set_config('sybasequoting', '0', 'auth/db');
+                set_config('type', 'mysqli', 'auth_db');
+                set_config('setupsql', "SET NAMES 'UTF-8'", 'auth_db');
+                set_config('sybasequoting', '0', 'auth_db');
                 if (!empty($CFG->dboptions['dbsocket'])) {
                     $dbsocket = $CFG->dboptions['dbsocket'];
                     if ((strpos($dbsocket, '/') === false and strpos($dbsocket, '\\') === false)) {
                         $dbsocket = ini_get('mysqli.default_socket');
                     }
-                    set_config('type', 'mysqli://'.rawurlencode($CFG->dbuser).':'.rawurlencode($CFG->dbpass).'@'.rawurlencode($CFG->dbhost).'/'.rawurlencode($CFG->dbname).'?socket='.rawurlencode($dbsocket), 'auth/db');
+                    set_config('type', 'mysqli://'.rawurlencode($CFG->dbuser).':'.rawurlencode($CFG->dbpass).'@'.rawurlencode($CFG->dbhost).'/'.rawurlencode($CFG->dbname).'?socket='.rawurlencode($dbsocket), 'auth_db');
                 }
                 break;
 
             case 'oracle':
-                set_config('type', 'oci8po', 'auth/db');
-                set_config('sybasequoting', '1', 'auth/db');
+                set_config('type', 'oci8po', 'auth_db');
+                set_config('sybasequoting', '1', 'auth_db');
                 break;
 
             case 'postgres':
-                set_config('type', 'postgres7', 'auth/db');
+                set_config('type', 'postgres7', 'auth_db');
                 $setupsql = "SET NAMES 'UTF-8'";
                 if (!empty($CFG->dboptions['dbschema'])) {
                     $setupsql .= "; SET search_path = '".$CFG->dboptions['dbschema']."'";
                 }
-                set_config('setupsql', $setupsql, 'auth/db');
-                set_config('sybasequoting', '0', 'auth/db');
+                set_config('setupsql', $setupsql, 'auth_db');
+                set_config('sybasequoting', '0', 'auth_db');
                 if (!empty($CFG->dboptions['dbsocket']) and ($CFG->dbhost === 'localhost' or $CFG->dbhost === '127.0.0.1')) {
                     if (strpos($CFG->dboptions['dbsocket'], '/') !== false) {
                         $socket = $CFG->dboptions['dbsocket'];
                         if (!empty($CFG->dboptions['dbport'])) {
                             $socket .= ':' . $CFG->dboptions['dbport'];
                         }
-                        set_config('host', $socket, 'auth/db');
+                        set_config('host', $socket, 'auth_db');
                     } else {
-                        set_config('host', '', 'auth/db');
+                        set_config('host', '', 'auth_db');
                     }
                 }
                 break;
 
             case 'mssql':
                 if (get_class($DB) == 'mssql_native_moodle_database') {
-                    set_config('type', 'mssql_n', 'auth/db');
+                    set_config('type', 'mssql_n', 'auth_db');
                 } else {
-                    set_config('type', 'mssqlnative', 'auth/db');
+                    set_config('type', 'mssqlnative', 'auth_db');
                 }
-                set_config('sybasequoting', '1', 'auth/db');
+                set_config('sybasequoting', '1', 'auth_db');
                 break;
 
             default:
@@ -121,24 +121,24 @@ class auth_db_testcase extends advanced_testcase {
             $dbman->drop_table($table);
         }
         $dbman->create_table($table);
-        set_config('table', $CFG->prefix.'auth_db_users', 'auth/db');
-        set_config('fielduser', 'name', 'auth/db');
-        set_config('fieldpass', 'pass', 'auth/db');
-        set_config('field_map_lastname', 'lastname', 'auth/db');
-        set_config('field_updatelocal_lastname', 'oncreate', 'auth/db');
-        set_config('field_lock_lastname', 'unlocked', 'auth/db');
+        set_config('table', $CFG->prefix.'auth_db_users', 'auth_db');
+        set_config('fielduser', 'name', 'auth_db');
+        set_config('fieldpass', 'pass', 'auth_db');
+        set_config('field_map_lastname', 'lastname', 'auth_db');
+        set_config('field_updatelocal_lastname', 'oncreate', 'auth_db');
+        set_config('field_lock_lastname', 'unlocked', 'auth_db');
         // Setu up field mappings.
 
-        set_config('field_map_email', 'email', 'auth/db');
-        set_config('field_updatelocal_email', 'oncreate', 'auth/db');
-        set_config('field_updateremote_email', '0', 'auth/db');
-        set_config('field_lock_email', 'unlocked', 'auth/db');
+        set_config('field_map_email', 'email', 'auth_db');
+        set_config('field_updatelocal_email', 'oncreate', 'auth_db');
+        set_config('field_updateremote_email', '0', 'auth_db');
+        set_config('field_lock_email', 'unlocked', 'auth_db');
 
         // Init the rest of settings.
-        set_config('passtype', 'plaintext', 'auth/db');
-        set_config('changepasswordurl', '', 'auth/db');
-        set_config('debugauthdb', 0, 'auth/db');
-        set_config('removeuser', AUTH_REMOVEUSER_KEEP, 'auth/db');
+        set_config('passtype', 'plaintext', 'auth_db');
+        set_config('changepasswordurl', '', 'auth_db');
+        set_config('debugauthdb', 0, 'auth_db');
+        set_config('removeuser', AUTH_REMOVEUSER_KEEP, 'auth_db');
     }
 
     protected function cleanup_auth_database() {
@@ -226,7 +226,7 @@ class auth_db_testcase extends advanced_testcase {
         $u2 = $DB->get_record('user', array('username'=>$user2->name));
         $this->assertSame($user2->email, $u2->email);
 
-        set_config('field_updatelocal_email', 'onlogin', 'auth/db');
+        set_config('field_updatelocal_email', 'onlogin', 'auth_db');
         $auth->config->field_updatelocal_email = 'onlogin';
 
         $auth->sync_users($trace, false);
@@ -252,7 +252,7 @@ class auth_db_testcase extends advanced_testcase {
         $this->assertEquals(0, $DB->count_records('user', array('deleted'=>1)));
         $this->assertEquals(0, $DB->count_records('user', array('suspended'=>1)));
 
-        set_config('removeuser', AUTH_REMOVEUSER_SUSPEND, 'auth/db');
+        set_config('removeuser', AUTH_REMOVEUSER_SUSPEND, 'auth_db');
         $auth->config->removeuser = AUTH_REMOVEUSER_SUSPEND;
 
         $auth->sync_users($trace, false);
@@ -270,7 +270,7 @@ class auth_db_testcase extends advanced_testcase {
 
         $DB->delete_records('auth_db_users', array('id'=>$user2->id));
 
-        set_config('removeuser', AUTH_REMOVEUSER_FULLDELETE, 'auth/db');
+        set_config('removeuser', AUTH_REMOVEUSER_FULLDELETE, 'auth_db');
         $auth->config->removeuser = AUTH_REMOVEUSER_FULLDELETE;
 
         $auth->sync_users($trace, false);
@@ -299,25 +299,25 @@ class auth_db_testcase extends advanced_testcase {
         $this->assertTrue($auth->user_login('u3', 'heslo'));
         $this->assertFalse($DB->record_exists('user', array('username'=>'u3', 'auth'=>'db')));
 
-        set_config('passtype', 'md5', 'auth/db');
+        set_config('passtype', 'md5', 'auth_db');
         $auth->config->passtype = 'md5';
         $user3->pass = md5('heslo');
         $DB->update_record('auth_db_users', $user3);
         $this->assertTrue($auth->user_login('u3', 'heslo'));
 
-        set_config('passtype', 'sh1', 'auth/db');
+        set_config('passtype', 'sh1', 'auth_db');
         $auth->config->passtype = 'sha1';
         $user3->pass = sha1('heslo');
         $DB->update_record('auth_db_users', $user3);
         $this->assertTrue($auth->user_login('u3', 'heslo'));
 
-        set_config('passtype', 'saltedcrypt', 'auth/db');
+        set_config('passtype', 'saltedcrypt', 'auth_db');
         $auth->config->passtype = 'saltedcrypt';
         $user3->pass = password_hash('heslo', PASSWORD_BCRYPT);
         $DB->update_record('auth_db_users', $user3);
         $this->assertTrue($auth->user_login('u3', 'heslo'));
 
-        set_config('passtype', 'internal', 'auth/db');
+        set_config('passtype', 'internal', 'auth_db');
         $auth->config->passtype = 'internal';
         create_user_record('u3', 'heslo', 'db');
         $this->assertTrue($auth->user_login('u3', 'heslo'));
@@ -325,19 +325,19 @@ class auth_db_testcase extends advanced_testcase {
 
         $DB->delete_records('auth_db_users', array('id'=>$user3->id));
 
-        set_config('removeuser', AUTH_REMOVEUSER_KEEP, 'auth/db');
+        set_config('removeuser', AUTH_REMOVEUSER_KEEP, 'auth_db');
         $auth->config->removeuser = AUTH_REMOVEUSER_KEEP;
         $this->assertTrue($auth->user_login('u3', 'heslo'));
 
-        set_config('removeuser', AUTH_REMOVEUSER_SUSPEND, 'auth/db');
+        set_config('removeuser', AUTH_REMOVEUSER_SUSPEND, 'auth_db');
         $auth->config->removeuser = AUTH_REMOVEUSER_SUSPEND;
         $this->assertFalse($auth->user_login('u3', 'heslo'));
 
-        set_config('removeuser', AUTH_REMOVEUSER_FULLDELETE, 'auth/db');
+        set_config('removeuser', AUTH_REMOVEUSER_FULLDELETE, 'auth_db');
         $auth->config->removeuser = AUTH_REMOVEUSER_FULLDELETE;
         $this->assertFalse($auth->user_login('u3', 'heslo'));
 
-        set_config('passtype', 'sh1', 'auth/db');
+        set_config('passtype', 'sh1', 'auth_db');
         $auth->config->passtype = 'sha1';
         $this->assertFalse($auth->user_login('u3', 'heslo'));
 
@@ -347,7 +347,7 @@ class auth_db_testcase extends advanced_testcase {
         $user4 = (object)array('name'=>'u4', 'pass'=>'heslo', 'email'=>'u4@example.com');
         $user4->id = $DB->insert_record('auth_db_users', $user4);
 
-        set_config('passtype', 'plaintext', 'auth/db');
+        set_config('passtype', 'plaintext', 'auth_db');
         $auth->config->passtype = 'plaintext';
 
         $iuser4 = create_user_record('u4', 'heslo', 'db');
@@ -361,14 +361,14 @@ class auth_db_testcase extends advanced_testcase {
         $user4b->email = 'u4b@example.com';
         $DB->update_record('auth_db_users', $user4b);
 
-        set_config('field_updatelocal_email', 'oncreate', 'auth/db');
+        set_config('field_updatelocal_email', 'oncreate', 'auth_db');
         $auth->config->field_updatelocal_email = 'oncreate';
 
         update_user_record('u4');
         $iuser4 = $DB->get_record('user', array('id'=>$iuser4->id));
         $this->assertSame($user4->email, $iuser4->email);
 
-        set_config('field_updatelocal_email', 'onlogin', 'auth/db');
+        set_config('field_updatelocal_email', 'onlogin', 'auth_db');
         $auth->config->field_updatelocal_email = 'onlogin';
 
         update_user_record('u4');
@@ -461,7 +461,7 @@ class auth_db_testcase extends advanced_testcase {
         $auth->db_init();
 
         // Set to delete from moodle when missing from DB.
-        set_config('removeuser', AUTH_REMOVEUSER_FULLDELETE, 'auth/db');
+        set_config('removeuser', AUTH_REMOVEUSER_FULLDELETE, 'auth_db');
         $auth->config->removeuser = AUTH_REMOVEUSER_FULLDELETE;
 
         // Create users.
index b9475fa..f482d55 100644 (file)
@@ -1,6 +1,11 @@
 This files describes API changes in /auth/db/*,
 information provided here is intended especially for developers.
 
+=== 3.3 ===
+
+* The config.html file was migrated to use the admin settings API.
+  The identifier for configuration data stored in config_plugins table was converted from 'auth/db' to 'auth_db'.
+
 === 3.1 ===
 
 * The auth_plugin_db::clean_data() has been deprecated and will be removed
index ccb61d0..f291cf8 100644 (file)
@@ -24,6 +24,6 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version   = 2017022200;        // The current plugin version (Date: YYYYMMDDXX)
+$plugin->version   = 2017032800;        // The current plugin version (Date: YYYYMMDDXX)
 $plugin->requires  = 2016112900;        // Requires this Moodle version
 $plugin->component = 'auth_db';         // Full name of the plugin (used for diagnostics)
index e9c1da1..f1cbc11 100644 (file)
@@ -36,7 +36,7 @@ class auth_plugin_email extends auth_plugin_base {
      */
     public function __construct() {
         $this->authtype = 'email';
-        $this->config = get_config('auth/email');
+        $this->config = get_config('auth_email');
     }
 
     /**
@@ -236,38 +236,12 @@ class auth_plugin_email extends auth_plugin_base {
         return true;
     }
 
-    /**
-     * Prints a form for configuring this authentication plugin.
-     *
-     * This function is called from admin/auth.php, and outputs a full page with
-     * a form for configuring this plugin.
-     *
-     * @param array $page An object containing all the data for this page.
-     */
-    function config_form($config, $err, $user_fields) {
-        include "config.html";
-    }
-
-    /**
-     * Processes and stores configuration data for this authentication plugin.
-     */
-    function process_config($config) {
-        // set to defaults if undefined
-        if (!isset($config->recaptcha)) {
-            $config->recaptcha = false;
-        }
-
-        // save settings
-        set_config('recaptcha', $config->recaptcha, 'auth/email');
-        return true;
-    }
-
     /**
      * Returns whether or not the captcha element is enabled.
      * @return bool
      */
     function is_captcha_enabled() {
-        return get_config("auth/{$this->authtype}", 'recaptcha');
+        return get_config("auth_{$this->authtype}", 'recaptcha');
     }
 
 }
diff --git a/auth/email/config.html b/auth/email/config.html
deleted file mode 100644 (file)
index 1b26e3f..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<!-- No config needed -->
-<?php
-    // set to defaults if undefined
-    if (!isset($config->recaptcha)) {
-        $config->recaptcha = false;
-    }
-
-    $yesno = array( get_string('no'), get_string('yes') );
-
-?>
-
-<table cellspacing="0" cellpadding="5" border="0">
-<tr>
-   <td colspan="3">
-        <h2 class="main"><?php print_string('auth_emailsettings', 'auth_email') ?> </h2>
-   </td>
-</tr>
-<tr>
-    <td align="right"><label for="menurecaptcha"><?php print_string('auth_emailrecaptcha_key', 'auth_email') ?></label></td>
-    <td><?php
-        global $OUTPUT;
-        echo html_writer::select($yesno, 'recaptcha', $config->recaptcha, false);
-        ?></td>
-    <td><?php print_string('auth_emailrecaptcha', 'auth_email') ?></td>
-</tr>
-<?php
-
-print_auth_lock_options($this->authtype, $user_fields, get_string('auth_fieldlocks_help', 'auth'), false, false);
-
-?>
-</table>
diff --git a/auth/email/db/upgrade.php b/auth/email/db/upgrade.php
new file mode 100644 (file)
index 0000000..36d6d1f
--- /dev/null
@@ -0,0 +1,46 @@
+<?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/>.
+
+/**
+ * No authentication plugin upgrade code
+ *
+ * @package    auth_email
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Function to upgrade auth_email.
+ * @param int $oldversion the version we are upgrading from
+ * @return bool result
+ */
+function xmldb_auth_email_upgrade($oldversion) {
+    global $CFG, $DB;
+
+    // Automatically generated Moodle v3.2.0 release upgrade line.
+    // Put any upgrade step following this.
+
+    if ($oldversion < 2017020700) {
+        // Convert info in config plugins from auth/email to auth_email.
+        $DB->set_field('config_plugins', 'plugin', 'auth_email', array('plugin' => 'auth/email'));
+        upgrade_plugin_savepoint(true, 2017020700, 'auth', 'email');
+    }
+
+    return true;
+}
+
diff --git a/auth/email/settings.php b/auth/email/settings.php
new file mode 100644 (file)
index 0000000..88d7bc2
--- /dev/null
@@ -0,0 +1,46 @@
+<?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/>.
+
+/**
+ * Admin settings and defaults.
+ *
+ * @package auth_email
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+if ($ADMIN->fulltree) {
+
+    // Introductory explanation.
+    $settings->add(new admin_setting_heading('auth_email/pluginname', '',
+        new lang_string('auth_emaildescription', 'auth_email')));
+
+    $options = array(
+        new lang_string('no'),
+        new lang_string('yes'),
+    );
+
+    $settings->add(new admin_setting_configselect('auth_email/recaptcha',
+        new lang_string('auth_emailrecaptcha_key', 'auth_email'),
+        new lang_string('auth_emailrecaptcha', 'auth_email'), 0, $options));
+
+    // Display locking / mapping of profile fields.
+    $authplugin = get_auth_plugin($this->name);
+    display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
+            get_string('auth_fieldlocks_help', 'auth'), false, false);
+}
diff --git a/auth/email/upgrade.txt b/auth/email/upgrade.txt
new file mode 100644 (file)
index 0000000..3184565
--- /dev/null
@@ -0,0 +1,8 @@
+This files describes API changes in /auth/email/*,
+information provided here is intended especially for developers.
+
+=== 3.3 ===
+
+* The config.html file was migrated to use the admin settings API.
+  The identifier for configuration data stored in config_plugins table was converted from 'auth/email' to 'auth_email'.
+
index 4ed6214..5787477 100644 (file)
@@ -24,6 +24,6 @@
 
 defined('MOODLE_INTERNAL') || die;
 
-$plugin->version   = 2016120500;        // The current plugin version (Date: YYYYMMDDXX)
+$plugin->version   = 2017020700;        // The current plugin version (Date: YYYYMMDDXX)
 $plugin->requires  = 2016112900;        // Requires this Moodle version
 $plugin->component = 'auth_email';      // Full name of the plugin (used for diagnostics)
index b987992..31b1b20 100644 (file)
@@ -39,7 +39,7 @@ class auth_plugin_fc extends auth_plugin_base {
      */
     public function __construct() {
         $this->authtype = 'fc';
-        $this->config = get_config('auth/fc');
+        $this->config = get_config('auth_fc');
     }
 
     /**
@@ -211,53 +211,6 @@ class auth_plugin_fc extends auth_plugin_base {
         }
     }
 
-    /**
-     * Prints a form for configuring this authentication plugin.
-     *
-     * This function is called from admin/auth.php, and outputs a full page with
-     * a form for configuring this plugin.
-     *
-     * @param array $page An object containing all the data for this page.
-     */
-    function config_form($config, $err, $user_fields) {
-        include "config.html";
-    }
-
-    /**
-     * Processes and stores configuration data for this authentication plugin.
-     */
-    function process_config($config) {
-        // set to defaults if undefined
-        if (!isset($config->host)) {
-            $config->host = "127.0.0.1";
-        }
-        if (!isset($config->fppport)) {
-            $config->fppport = "3333";
-        }
-        if (!isset($config->userid)) {
-            $config->userid = "fcMoodle";
-        }
-        if (!isset($config->passwd)) {
-            $config->passwd = "";
-        }
-        if (!isset($config->creators)) {
-            $config->creators = "";
-        }
-        if (!isset($config->changepasswordurl)) {
-            $config->changepasswordurl = '';
-        }
-
-        // save settings
-        set_config('host',      $config->host,     'auth/fc');
-        set_config('fppport',   $config->fppport,  'auth/fc');
-        set_config('userid',    $config->userid,   'auth/fc');
-        set_config('passwd',    $config->passwd,   'auth/fc');
-        set_config('creators',  $config->creators, 'auth/fc');
-        set_config('changepasswordurl', $config->changepasswordurl, 'auth/fc');
-
-        return true;
-    }
-
 }
 
 
diff --git a/auth/fc/config.html b/auth/fc/config.html
deleted file mode 100644 (file)
index 6029411..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-<?php
-
-    // set to defaults if undefined
-    if (!isset($config->host)) {
-        $config->host = "127.0.0.1";
-    }
-    if (!isset($config->fppport)) {
-        $config->fppport = "3333";
-    }
-    if (!isset($config->userid)) {
-        $config->userid = "fcMoodle";
-    }
-    if (!isset($config->passwd)) {
-        $config->passwd = "";
-    }
-    if (!isset($config->creators)) {
-        $config->creators = "";
-    }
-    if (!isset($config->changepasswordurl)) {
-        $config->changepasswordurl = '';
-    }
-    if (!isset($config->changepasswordurl)) {
-        $config->changepasswordurl = '';
-    }
-
-?>
-<table cellspacing="0" cellpadding="5" border="0">
-
-<tr valign="top" class="required">
-    <td align="right"><label for="host"><?php print_string("auth_fchost_key", "auth_fc") ?>:</label></td>
-    <td>
-        <input name="host" id="host" type="text" size="30" value="<?php echo $config->host?>" />
-    <?php  if (isset($err["host"])) echo $OUTPUT->error_text($err["host"]); ?>
-    </td>
-    <td>
-    <?php  print_string("auth_fchost", "auth_fc") ?>
-    </td>
-</tr>
-
-<tr valign="top" class="required">
-    <td align="right"><label for="fppport"><?php  print_string("auth_fcfppport_key", "auth_fc") ?>: </label></td>
-    <td>
-        <input name="fppport" id="fppport" type="text" size="30" value="<?php echo $config->fppport?>" />
-    <?php  if (isset($err["fppport"])) echo $OUTPUT->error_text($err["host"]); ?>
-    </td>
-    <td>
-    <?php  print_string("auth_fcfppport", "auth_fc") ?>
-    </td>
-</tr>
-
-<tr valign="top" class="required">
-    <td align="right"><label for="userid"><?php  print_string("auth_fcuserid_key", "auth_fc") ?>:</label></td>
-    <td>
-        <input name="userid" id="userid" type="text" size="30" maxlength="15" value="<?php echo $config->userid?>" />
-    <?php  if (isset($err["userid"])) echo $OUTPUT->error_text($err["userid"]); ?>
-    </td>
-    <td>
-    <?php  print_string("auth_fcuserid", "auth_fc") ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right"><label for="passwd"><?php print_string("auth_fcpasswd_key", "auth_fc") ?>:</label></td>
-    <td>
-        <input name="passwd" id="passwd" type="password" size="30" maxlength="12" value="<?php echo $config->passwd?>" autocomplete="off"/>
-    <?php  if (isset($err["passwd"])) echo $OUTPUT->error_text($err["passwd"]); ?>
-    </td>
-    <td>
-    <?php  print_string("auth_fcpasswd", "auth_fc") ?>
-    </td>
-</tr>
-
-<tr valign="top" class="required">
-    <td align="right"><label for="creators"><?php  print_string("auth_fccreators_key", "auth_fc") ?>: </label></td>
-    <td>
-        <input name="creators" id="creators" type="text" size="30" value="<?php echo $config->creators?>" />
-    <?php  if (isset($err["creators"])) echo $OUTPUT->error_text($err["creators"]); ?>
-    </td>
-    <td>
-    <?php  print_string("auth_fccreators", "auth_fc") ?>
-    </td>
-</tr>
-
-<tr valign="top">
-    <td align="right"><label for="changepasswordurl"><?php print_string('auth_fcchangepasswordurl', 'auth_fc') ?>: </label></td>
-    <td>
-        <input name="changepasswordurl" id="changepasswordurl" type="text" value="<?php echo $config->changepasswordurl ?>" />
-        <?php
-
-        if (isset($err['changepasswordurl'])) {
-            echo $OUTPUT->error_text($err['changepasswordurl']);
-        }
-
-        ?>
-    </td>
-    <td><?php print_string('changepasswordhelp', 'auth') ?></td>
-</tr>
-
-<?php
-
-print_auth_lock_options($this->authtype, $user_fields, get_string('auth_fieldlocks_help', 'auth'), false, false);
-
-?>
-</table>
diff --git a/auth/fc/db/upgrade.php b/auth/fc/db/upgrade.php
new file mode 100644 (file)
index 0000000..6909e6c
--- /dev/null
@@ -0,0 +1,45 @@
+<?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/>.
+
+/**
+ * First Class authentication plugin upgrade code
+ *
+ * @package    auth_fc
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Function to upgrade auth_fc.
+ * @param int $oldversion the version we are upgrading from
+ * @return bool result
+ */
+function xmldb_auth_fc_upgrade($oldversion) {
+    global $CFG, $DB;
+
+    // Automatically generated Moodle v3.2.0 release upgrade line.
+    // Put any upgrade step following this.
+
+    if ($oldversion < 2017020700) {
+        // Convert info in config plugins from auth/fc to auth_fc.
+        $DB->set_field('config_plugins', 'plugin', 'auth_fc', array('plugin' => 'auth/fc'));
+        upgrade_plugin_savepoint(true, 2017020700, 'auth', 'fc');
+    }
+
+    return true;
+}
diff --git a/auth/fc/settings.php b/auth/fc/settings.php
new file mode 100644 (file)
index 0000000..6039a64
--- /dev/null
@@ -0,0 +1,61 @@
+<?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/>.
+
+/**
+ * Admin settings and defaults.
+ *
+ * @package    auth_fc
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+if ($ADMIN->fulltree) {
+
+    // Introductory explanation.
+    $settings->add(new admin_setting_heading('auth_fc/pluginname', '', new lang_string('auth_fcdescription', 'auth_fc')));
+
+    // Host.
+    $settings->add(new admin_setting_configtext('auth_fc/host', get_string('auth_fchost_key', 'auth_fc'),
+            get_string('auth_fchost', 'auth_fc'), '127.0.0.1', PARAM_HOST));
+
+    // Port.
+    $settings->add(new admin_setting_configtext('auth_fc/fppport', get_string('auth_fcfppport_key', 'auth_fc'),
+            get_string('auth_fcfppport', 'auth_fc'), '3333', PARAM_INT));
+
+    // User ID.
+    $settings->add(new admin_setting_configtext('auth_fc/userid', get_string('auth_fcuserid_key', 'auth_fc'),
+            get_string('auth_fcuserid', 'auth_fc'), 'fcMoodle', PARAM_RAW));
+
+    // Password.
+    $settings->add(new admin_setting_configpasswordunmask('auth_fc/passwd', get_string('auth_fcpasswd_key', 'auth_fc'),
+            get_string('auth_fcpasswd', 'auth_fc'), ''));
+
+    // Creators.
+    $settings->add(new admin_setting_configtext('auth_fc/creators', get_string('auth_fccreators_key', 'auth_fc'),
+            get_string('auth_fccreators', 'auth_fc'), '', PARAM_RAW));
+
+    // Password change URL.
+    $settings->add(new admin_setting_configtext('auth_fc/changepasswordurl',
+            get_string('auth_fcchangepasswordurl', 'auth_fc'),
+            get_string('changepasswordhelp', 'auth'), '', PARAM_URL));
+
+    // Display locking / mapping of profile fields.
+    $authplugin = get_auth_plugin($this->name);
+    display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
+            get_string('auth_fieldlocks_help', 'auth'), false, false);
+}
diff --git a/auth/fc/upgrade.txt b/auth/fc/upgrade.txt
new file mode 100644 (file)
index 0000000..312f797
--- /dev/null
@@ -0,0 +1,8 @@
+This files describes API changes in /auth/fc/*,
+information provided here is intended especially for developers.
+
+=== 3.3 ===
+
+* The config.html file was migrated to use the admin settings API.
+  The identifier for configuration data stored in config_plugins table was converted from 'auth/fc' to 'auth_fc'.
+
index a700d9c..55fc7e5 100644 (file)
@@ -24,6 +24,6 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version   = 2016120500;        // The current plugin version (Date: YYYYMMDDXX)
+$plugin->version   = 2017020700;        // The current plugin version (Date: YYYYMMDDXX)
 $plugin->requires  = 2016112900;        // Requires this Moodle version
 $plugin->component = 'auth_fc';         // Full name of the plugin (used for diagnostics)
index 3e3e2da..6d6590c 100644 (file)
@@ -37,7 +37,7 @@ class auth_plugin_imap extends auth_plugin_base {
      */
     public function __construct() {
         $this->authtype = 'imap';
-        $this->config = get_config('auth/imap');
+        $this->config = get_config('auth_imap');
     }
 
     /**
@@ -141,47 +141,6 @@ class auth_plugin_imap extends auth_plugin_base {
         }
     }
 
-    /**
-     * Prints a form for configuring this authentication plugin.
-     *
-     * This function is called from admin/auth.php, and outputs a full page with
-     * a form for configuring this plugin.
-     *
-     * @param array $page An object containing all the data for this page.
-     */
-    function config_form($config, $err, $user_fields) {
-        global $OUTPUT;
-
-        include "config.html";
-    }
-
-    /**
-     * Processes and stores configuration data for this authentication plugin.
-     */
-    function process_config($config) {
-        // set to defaults if undefined
-        if (!isset ($config->host)) {
-            $config->host = '127.0.0.1';
-        }
-        if (!isset ($config->type)) {
-            $config->type = 'imap';
-        }
-        if (!isset ($config->port)) {
-            $config->port = '143';
-        }
-        if (!isset($config->changepasswordurl)) {
-            $config->changepasswordurl = '';
-        }
-
-        // save settings
-        set_config('host', $config->host, 'auth/imap');
-        set_config('type', $config->type, 'auth/imap');
-        set_config('port', $config->port, 'auth/imap');
-        set_config('changepasswordurl', $config->changepasswordurl, 'auth/imap');
-
-        return true;
-    }
-
 }
 
 
diff --git a/auth/imap/config.html b/auth/imap/config.html
deleted file mode 100644 (file)
index 914d14f..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-<?php
-
-// set to defaults if undefined
-if (!isset($config->host)) {
-    $config->host = '127.0.0.1';
-}
-if (!isset($config->type)) {
-    $config->type = 'imap';
-}
-if (!isset($config->port)) {
-    $config->port = '143';
-}
-if (!isset($config->changepasswordurl)) {
-    $config->changepasswordurl = '';
-}
-
-?>
-<table cellspacing="0" cellpadding="5" border="0">
-
-<tr valign="top" class="required">
-    <td align="right"><label for="host"><?php print_string('auth_imaphost_key', 'auth_imap') ?>: </label></td>
-    <td>
-        <input name="host" id="host" type="text" size="30" value="<?php echo $config->host ?>" />
-        <?php
-
-        if (isset($err['host'])) {
-            echo $OUTPUT->error_text($err['host']);
-        }
-
-        ?>
-    </td>
-    <td>
-        <?php
-
-        print_string('auth_imaphost', 'auth_imap');
-        print_string('auth_multiplehosts', 'auth');
-
-        ?>
-    </td>
-</tr>
-
-<tr valign="top" class="required">
-    <td align="right"><?php echo html_writer::label(get_string('auth_imaptype_key', 'auth_imap'), 'menutype'); ?>: </td>
-    <td>
-        <?php
-
-        $imaptypes = array('imap', 'imapssl', 'imapcert', 'imapnosslcert', 'imaptls');
-        foreach ($imaptypes as $imaptype) {
-            $imapoptions[$imaptype] = $imaptype;
-        }
-        echo html_writer::select($imapoptions, 'type', $config->type, false);
-
-        ?>
-    </td>
-    <td><?php print_string('auth_imaptype', 'auth_imap') ?></td>
-</tr>
-
-<tr valign="top" class="required">
-    <td align="right"><label for="port"><?php print_string('auth_imapport_key', 'auth_imap') ?>: </label></td>
-    <td>
-        <input name="port" id="port" type="text" size="6" value="<?php echo $config->port ?>" />
-        <?php
-
-        if (isset($err['port'])) {
-            echo $OUTPUT->error_text($err['port']);
-        }
-
-        ?>
-    </td>
-    <td><?php print_string('auth_imapport', 'auth_imap') ?></td>
-</tr>
-
-<tr valign="top">
-    <td align="right"><label for="changepasswordurl"><?php print_string('auth_imapchangepasswordurl_key', 'auth_imap') ?>: </label></td>
-    <td>
-        <input name="changepasswordurl" id="changepasswordurl" type="text" value="<?php echo $config->changepasswordurl ?>" />
-        <?php
-
-        if (isset($err['changepasswordurl'])) {
-            echo $OUTPUT->error_text($err['changepasswordurl']);
-        }
-
-        ?>
-    </td>
-    <td><?php print_string('changepasswordhelp', 'auth') ?></td>
-</tr>
-
-<?php
-
-print_auth_lock_options($this->authtype, $user_fields, get_string('auth_fieldlocks_help', 'auth'), false, false);
-
-?>
-</table>
diff --git a/auth/imap/db/upgrade.php b/auth/imap/db/upgrade.php
new file mode 100644 (file)
index 0000000..96dc3df
--- /dev/null
@@ -0,0 +1,46 @@
+<?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/>.
+
+/**
+ * Imap authentication plugin upgrade code
+ *
+ * @package    auth_imap
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Function to upgrade auth_imap.
+ * @param int $oldversion the version we are upgrading from
+ * @return bool result
+ */
+function xmldb_auth_imap_upgrade($oldversion) {
+    global $CFG, $DB;
+
+    // Automatically generated Moodle v3.2.0 release upgrade line.
+    // Put any upgrade step following this.
+
+    if ($oldversion < 2017020700) {
+        // Convert info in config plugins from auth/imap to auth_imap.
+        $DB->set_field('config_plugins', 'plugin', 'auth_imap', array('plugin' => 'auth/imap'));
+        upgrade_plugin_savepoint(true, 2017020700, 'auth', 'imap');
+    }
+
+    return true;
+}
+
diff --git a/auth/imap/settings.php b/auth/imap/settings.php
new file mode 100644 (file)
index 0000000..b2478bd
--- /dev/null
@@ -0,0 +1,62 @@
+<?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/>.
+
+/**
+ * Admin settings and defaults.
+ *
+ * @package auth_imap
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+if ($ADMIN->fulltree) {
+
+    // Introductory explanation.
+    $settings->add(new admin_setting_heading('auth_imap/pluginname', '', new lang_string('auth_imapdescription', 'auth_imap')));
+
+    // Host.
+    $settings->add(new admin_setting_configtext('auth_imap/host', get_string('auth_imaphost_key', 'auth_imap'),
+            get_string('auth_imaphost', 'auth_imap') . ' ' .get_string('auth_multiplehosts', 'auth'),
+            '127.0.0.1', PARAM_RAW));
+
+    // Type.
+    $imapoptions = array();
+    $imaptypes = array('imap', 'imapssl', 'imapcert', 'imapnosslcert', 'imaptls');
+    foreach ($imaptypes as $imaptype) {
+        $imapoptions[$imaptype] = $imaptype;
+    }
+
+    $settings->add(new admin_setting_configselect('auth_imap/type',
+        new lang_string('auth_imaptype_key', 'auth_imap'),
+        new lang_string('auth_imaptype', 'auth_imap'), 'imap', $imapoptions));
+
+    // Port.
+    $settings->add(new admin_setting_configtext('auth_imap/port', get_string('auth_imapport_key', 'auth_imap'),
+            get_string('auth_imapport', 'auth_imap'), '143', PARAM_INT));
+
+    // Password change URL.
+    $settings->add(new admin_setting_configtext('auth_imap/changepasswordurl',
+            get_string('auth_imapchangepasswordurl_key', 'auth_imap'),
+            get_string('changepasswordhelp', 'auth'), '', PARAM_URL));
+
+    // Display locking / mapping of profile fields.
+    $authplugin = get_auth_plugin($this->name);
+    display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
+            get_string('auth_fieldlocks_help', 'auth'), false, false);
+
+}
diff --git a/auth/imap/upgrade.txt b/auth/imap/upgrade.txt
new file mode 100644 (file)
index 0000000..c6e6a95
--- /dev/null
@@ -0,0 +1,7 @@
+This files describes API changes in /auth/imap/*,
+information provided here is intended especially for developers.
+
+=== 3.3 ===
+
+* The config.html file was migrated to use the admin settings API.
+  The identifier for configuration data stored in config_plugins table was converted from 'auth/imap' to 'auth_imap'.
index 95fb3df..5c102b0 100644 (file)
@@ -24,6 +24,6 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version   = 2016120500;        // The current plugin version (Date: YYYYMMDDXX)
+$plugin->version   = 2017020700;        // The current plugin version (Date: YYYYMMDDXX)
 $plugin->requires  = 2016112900;        // Requires this Moodle version
 $plugin->component = 'auth_imap';       // Full name of the plugin (used for diagnostics)
index b23c9ec..7e6fd3b 100644 (file)
@@ -89,7 +89,7 @@ class auth_plugin_ldap extends auth_plugin_base {
      * Init plugin config from database settings depending on the plugin auth type.
      */
     function init_plugin($authtype) {
-        $this->pluginconfig = 'auth/'.$authtype;
+        $this->pluginconfig = 'auth_'.$authtype;
         $this->config = get_config($this->pluginconfig);
         if (empty($this->config->ldapencoding)) {
             $this->config->ldapencoding = 'utf-8';
@@ -1815,186 +1815,6 @@ class auth_plugin_ldap extends auth_plugin_base {
         }
     }
 
-    /**
-     * Prints a form for configuring this authentication plugin.
-     *
-     * This function is called from admin/auth.php, and outputs a full page with
-     * a form for configuring this plugin.
-     *
-     * @param array $page An object containing all the data for this page.
-     */
-    function config_form($config, $err, $user_fields) {
-        global $CFG, $OUTPUT;
-
-        if (!function_exists('ldap_connect')) { // Is php-ldap really there?
-            echo $OUTPUT->notification(get_string('auth_ldap_noextension', 'auth_ldap'));
-            return;
-        }
-
-        include($CFG->dirroot.'/auth/ldap/config.html');
-    }
-
-    /**
-     * Processes and stores configuration data for this authentication plugin.
-     */
-    function process_config($config) {
-        // Set to defaults if undefined
-        if (!isset($config->host_url)) {
-             $config->host_url = '';
-        }
-        if (!isset($config->start_tls)) {
-             $config->start_tls = false;
-        }
-        if (empty($config->ldapencoding)) {
-         $config->ldapencoding = 'utf-8';
-        }
-        if (!isset($config->pagesize)) {
-            $config->pagesize = LDAP_DEFAULT_PAGESIZE;
-        }
-        if (!isset($config->contexts)) {
-             $config->contexts = '';
-        }
-        if (!isset($config->user_type)) {
-             $config->user_type = 'default';
-        }
-        if (!isset($config->user_attribute)) {
-             $config->user_attribute = '';
-        }
-        if (!isset($config->suspended_attribute)) {
-            $config->suspended_attribute = '';
-        }
-        if (!isset($config->sync_suspended)) {
-            $config->sync_suspended = false;
-        }
-        if (!isset($config->search_sub)) {
-             $config->search_sub = '';
-        }
-        if (!isset($config->opt_deref)) {
-             $config->opt_deref = LDAP_DEREF_NEVER;
-        }
-        if (!isset($config->preventpassindb)) {
-             $config->preventpassindb = 0;
-        }
-        if (!isset($config->bind_dn)) {
-            $config->bind_dn = '';
-        }
-        if (!isset($config->bind_pw)) {
-            $config->bind_pw = '';
-        }
-        if (!isset($config->ldap_version)) {
-            $config->ldap_version = '3';
-        }
-        if (!isset($config->objectclass)) {
-            $config->objectclass = '';
-        }
-        if (!isset($config->memberattribute)) {
-            $config->memberattribute = '';
-        }
-        if (!isset($config->memberattribute_isdn)) {
-            $config->memberattribute_isdn = '';
-        }
-        if (!isset($config->creators)) {
-            $config->creators = '';
-        }
-        if (!isset($config->create_context)) {
-            $config->create_context = '';
-        }
-        if (!isset($config->expiration)) {
-            $config->expiration = '';
-        }
-        if (!isset($config->expiration_warning)) {
-            $config->expiration_warning = '10';
-        }
-        if (!isset($config->expireattr)) {
-            $config->expireattr = '';
-        }
-        if (!isset($config->gracelogins)) {
-            $config->gracelogins = '';
-        }
-        if (!isset($config->graceattr)) {
-            $config->graceattr = '';
-        }
-        if (!isset($config->auth_user_create)) {
-            $config->auth_user_create = '';
-        }
-        if (!isset($config->forcechangepassword)) {
-            $config->forcechangepassword = 0;
-        }
-        if (!isset($config->stdchangepassword)) {
-            $config->stdchangepassword = 0;
-        }
-        if (!isset($config->passtype)) {
-            $config->passtype = 'plaintext';
-        }
-        if (!isset($config->changepasswordurl)) {
-            $config->changepasswordurl = '';
-        }
-        if (!isset($config->removeuser)) {
-            $config->removeuser = AUTH_REMOVEUSER_KEEP;
-        }
-        if (!isset($config->ntlmsso_enabled)) {
-            $config->ntlmsso_enabled = 0;
-        }
-        if (!isset($config->ntlmsso_subnet)) {
-            $config->ntlmsso_subnet = '';
-        }
-        if (!isset($config->ntlmsso_ie_fastpath)) {
-            $config->ntlmsso_ie_fastpath = 0;
-        }
-        if (!isset($config->ntlmsso_type)) {
-            $config->ntlmsso_type = 'ntlm';
-        }
-        if (!isset($config->ntlmsso_remoteuserformat)) {
-            $config->ntlmsso_remoteuserformat = '';
-        }
-
-        // Try to remove duplicates before storing the contexts (to avoid problems in sync_users()).
-        $config->contexts = explode(';', $config->contexts);
-        $config->contexts = array_map(create_function('$x', 'return core_text::strtolower(trim($x));'),
-                                      $config->contexts);
-        $config->contexts = implode(';', array_unique($config->contexts));
-
-        // Save settings
-        set_config('host_url', trim($config->host_url), $this->pluginconfig);
-        set_config('start_tls', $config->start_tls, $this->pluginconfig);
-        set_config('ldapencoding', trim($config->ldapencoding), $this->pluginconfig);
-        set_config('pagesize', (int)trim($config->pagesize), $this->pluginconfig);
-        set_config('contexts', $config->contexts, $this->pluginconfig);
-        set_config('user_type', core_text::strtolower(trim($config->user_type)), $this->pluginconfig);
-        set_config('user_attribute', core_text::strtolower(trim($config->user_attribute)), $this->pluginconfig);
-        set_config('suspended_attribute', core_text::strtolower(trim($config->suspended_attribute)), $this->pluginconfig);
-        set_config('sync_suspended', $config->sync_suspended, $this->pluginconfig);
-        set_config('search_sub', $config->search_sub, $this->pluginconfig);
-        set_config('opt_deref', $config->opt_deref, $this->pluginconfig);
-        set_config('preventpassindb', $config->preventpassindb, $this->pluginconfig);
-        set_config('bind_dn', trim($config->bind_dn), $this->pluginconfig);
-        set_config('bind_pw', $config->bind_pw, $this->pluginconfig);
-        set_config('ldap_version', $config->ldap_version, $this->pluginconfig);
-        set_config('objectclass', trim($config->objectclass), $this->pluginconfig);
-        set_config('memberattribute', core_text::strtolower(trim($config->memberattribute)), $this->pluginconfig);
-        set_config('memberattribute_isdn', $config->memberattribute_isdn, $this->pluginconfig);
-        set_config('creators', trim($config->creators), $this->pluginconfig);
-        set_config('create_context', trim($config->create_context), $this->pluginconfig);
-        set_config('expiration', $config->expiration, $this->pluginconfig);
-        set_config('expiration_warning', trim($config->expiration_warning), $this->pluginconfig);
-        set_config('expireattr', core_text::strtolower(trim($config->expireattr)), $this->pluginconfig);
-        set_config('gracelogins', $config->gracelogins, $this->pluginconfig);
-        set_config('graceattr', core_text::strtolower(trim($config->graceattr)), $this->pluginconfig);
-        set_config('auth_user_create', $config->auth_user_create, $this->pluginconfig);
-        set_config('forcechangepassword', $config->forcechangepassword, $this->pluginconfig);
-        set_config('stdchangepassword', $config->stdchangepassword, $this->pluginconfig);
-        set_config('passtype', $config->passtype, $this->pluginconfig);
-        set_config('changepasswordurl', trim($config->changepasswordurl), $this->pluginconfig);
-        set_config('removeuser', $config->removeuser, $this->pluginconfig);
-        set_config('ntlmsso_enabled', (int)$config->ntlmsso_enabled, $this->pluginconfig);
-        set_config('ntlmsso_subnet', trim($config->ntlmsso_subnet), $this->pluginconfig);
-        set_config('ntlmsso_ie_fastpath', (int)$config->ntlmsso_ie_fastpath, $this->pluginconfig);
-        set_config('ntlmsso_type', $config->ntlmsso_type, 'auth/ldap');
-        set_config('ntlmsso_remoteuserformat', trim($config->ntlmsso_remoteuserformat), 'auth/ldap');
-
-        return true;
-    }
-
     /**
      * Get password expiration time for a given user from Active Directory
      *
@@ -2211,24 +2031,6 @@ class auth_plugin_ldap extends auth_plugin_base {
                                 $this->config->user_attribute, $this->config->search_sub);
     }
 
-
-    /**
-     * A chance to validate form data, and last chance to do stuff
-     * before it is inserted in config_plugin
-     *
-     * @param object object with submitted configuration settings (without system magic quotes)
-     * @param array $err array of error messages (passed by reference)
-     */
-    function validate_form($form, &$err) {
-        if ($form->ntlmsso_type == 'ntlm') {
-            $format = trim($form->ntlmsso_remoteuserformat);
-            if (!empty($format) && !preg_match('/%username%/i', $format)) {
-                $err['ntlmsso_remoteuserformat'] = get_string('auth_ntlmsso_missing_username', 'auth_ldap');
-            }
-        }
-    }
-
-
     /**
      * When using NTLM SSO, the format of the remote username we get in
      * $_SERVER['REMOTE_USER'] may vary, depending on where from and how the web
@@ -2312,4 +2114,41 @@ class auth_plugin_ldap extends auth_plugin_base {
         return (bool)$user->suspended;
     }
 
+    /**
+     * Test if settings are correct, print info to output.
+     */
+    public function test_settings() {
+        global $OUTPUT;
+
+        if (!function_exists('ldap_connect')) { // Is php-ldap really there?
+            echo $OUTPUT->notification(get_string('auth_ldap_noextension', 'auth_ldap'));
+            return;
+        }
+
+        // Check to see if this is actually configured.
+        if ((isset($this->config->host_url)) && ($this->config->host_url !== '')) {
+
+            try {
+                $ldapconn = $this->ldap_connect();
+                // Try to connect to the LDAP server.  See if the page size setting is supported on this server.
+                $pagedresultssupported = ldap_paged_results_supported($this->config->ldap_version, $ldapconn);
+            } catch (Exception $e) {
+
+                // If we couldn't connect and get the supported options, we can only assume we don't support paged results.
+                $pagedresultssupported = false;
+            }
+
+            // Display paged file results.
+            if ((!$pagedresultssupported)) {
+                echo $OUTPUT->notification(get_string('pagedresultsnotsupp', 'auth_ldap'), \core\output\notification::NOTIFY_INFO);
+            } else if ($ldapconn) {
+                // We were able to connect successfuly.
+                echo $OUTPUT->notification(get_string('connectingldapsuccess', 'auth_ldap'), \core\output\notification::NOTIFY_SUCCESS);
+            }
+
+        } else {
+            // LDAP is not even configured.
+            echo $OUTPUT->notification(get_string('ldapnotconfigured', 'auth_ldap'), \core\output\notification::NOTIFY_INFO);
+        }
+    }
 } // End of the class
diff --git a/auth/ldap/classes/admin_setting_special_contexts_configtext.php b/auth/ldap/classes/admin_setting_special_contexts_configtext.php
new file mode 100644 (file)
index 0000000..6e5bc65
--- /dev/null
@@ -0,0 +1,50 @@
+<?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/>.
+
+/**
+ * Special setting for auth_ldap that cleans up context values on save..
+ *
+ * @package    auth_ldap
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Special setting for auth_ldap that cleans up context values on save..
+ *
+ * @package    auth_ldap
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class auth_ldap_admin_setting_special_contexts_configtext extends admin_setting_configtext {
+
+    /**
+     * We need to remove duplicates on save to prevent issues in other areas of Moodle.
+     *
+     * @param string $data Form data.
+     * @return string Empty when no errors.
+     */
+    public function write_setting($data) {
+        // Try to remove duplicates before storing the contexts (to avoid problems in sync_users()).
+        $data = explode(';', $data);
+        $data = array_map(create_function('$x', 'return core_text::strtolower(trim($x));'),
+                                      $data);
+        $data = implode(';', array_unique($data));
+        return parent::write_setting($data);
+    }
+}
diff --git a/auth/ldap/classes/admin_setting_special_lowercase_configtext.php b/auth/ldap/classes/admin_setting_special_lowercase_configtext.php
new file mode 100644 (file)
index 0000000..0dd37cf
--- /dev/null
@@ -0,0 +1,45 @@
+<?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/>.
+
+/**
+ * Special setting for auth_ldap that lowercases values on save..
+ *
+ * @package    auth_ldap
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Special setting for auth_ldap that lowercases values on save..
+ *
+ * @package    auth_ldap
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class auth_ldap_admin_setting_special_lowercase_configtext extends admin_setting_configtext {
+
+    /**
+     * We need to convert the data to lowercase prior to save.
+     *
+     * @param string $data Form data.
+     * @return string Empty when no errors.
+     */
+    public function write_setting($data) {
+        return parent::write_setting(core_text::strtolower($data));
+    }
+}
diff --git a/auth/ldap/classes/admin_setting_special_ntlm_configtext.php b/auth/ldap/classes/admin_setting_special_ntlm_configtext.php
new file mode 100644 (file)
index 0000000..fde131d
--- /dev/null
@@ -0,0 +1,53 @@
+<?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/>.
+
+/**
+ * Special admin setting for auth_ldap that validates ntlm usernames.
+ *
+ * @package    auth_ldap
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Special admin setting for auth_ldap that validates ntlm usernames.
+ *
+ * @package    auth_ldap
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class auth_ldap_admin_setting_special_ntlm_configtext extends admin_setting_configtext {
+
+    /**
+     * We need to validate the username format when using NTLM.
+     *
+     * @param string $data Form data.
+     * @return string Empty when no errors.
+     */
+    public function validate($data) {
+
+        if (get_config('auth_ldap', 'ntlmsso_type') === 'ntlm') {
+            $format = trim($data);
+            if (!empty($format) && !preg_match('/%username%/i', $format)) {
+                return get_string('auth_ntlmsso_missing_username', 'auth_ldap');
+            }
+        }
+
+        return parent::validate($data);
+    }
+}
diff --git a/auth/ldap/config.html b/auth/ldap/config.html
deleted file mode 100644 (file)
index 883eb9d..0000000
+++ /dev/null
@@ -1,664 +0,0 @@
-<?php
-
-// Set to defaults if undefined
-if (!isset($config->host_url)) {
-    $config->host_url = '';
-}
-if (!isset($config->start_tls)) {
-    $config->start_tls = false;
-}
-if (empty($config->ldapencoding)) {
-    $config->ldapencoding = 'utf-8';
-}
-if (!isset($config->pagesize)) {
-    $config->pagesize = LDAP_DEFAULT_PAGESIZE;
-}
-if (!isset($config->contexts)) {
-    $config->contexts = '';
-}
-if (!isset($config->user_type)) {
-    $config->user_type = 'default';
-}
-if (!isset($config->user_attribute)) {
-    $config->user_attribute = '';
-}
-if (!isset($config->suspended_attribute)) {
-    $config->suspended_attribute = '';
-}
-if (!isset($config->sync_suspended)) {
-    $config->sync_suspended = '';
-}
-if (!isset($config->search_sub)) {
-    $config->search_sub = '';
-}
-if (!isset($config->opt_deref)) {
-    $config->opt_deref = LDAP_DEREF_NEVER;
-}
-if (!isset($config->preventpassindb)) {
-    $config->preventpassindb = 0;
-}
-if (!isset($config->bind_dn)) {
-    $config->bind_dn = '';
-}
-if (!isset($config->bind_pw)) {
-    $config->bind_pw = '';
-}
-if (!isset($config->ldap_version)) {
-    $config->ldap_version = '3';
-}
-if (!isset($config->objectclass)) {
-    $config->objectclass = '';
-}
-if (!isset($config->memberattribute)) {
-    $config->memberattribute = '';
-}
-if (!isset($config->memberattribute_isdn)) {
-    $config->memberattribute_isdn = '';
-}
-if (!isset($config->creators)) {
-    $config->creators = '';
-}
-if (!isset($config->create_context)) {
-    $config->create_context = '';
-}
-if (!isset($config->expiration)) {
-    $config->expiration = '';
-}
-if (!isset($config->expiration_warning)) {
-    $config->expiration_warning = '10';
-}
-if (!isset($config->expireattr)) {
-    $config->expireattr = '';
-}
-if (!isset($config->gracelogins)) {
-    $config->gracelogins = '';
-}
-if (!isset($config->graceattr)) {
-    $config->graceattr = '';
-}
-if (!isset($config->auth_user_create)) {
-    $config->auth_user_create = '';
-}
-if (!isset($config->forcechangepassword)) {
-    $config->forcechangepassword = 0;
-}
-if (!isset($config->stdchangepassword)) {
-    $config->stdchangepassword = 0;
-}
-if (!isset($config->passtype)) {
-    $config->passtype = 'plaintext';
-}
-if (!isset($config->changepasswordurl)) {
-    $config->changepasswordurl = '';
-}
-if (!isset($config->removeuser)) {
-    $config->removeuser = AUTH_REMOVEUSER_KEEP;
-}
-if (!isset($config->ntlmsso_enabled)) {
-    $config->ntlmsso_enabled = 0;
-}
-if (!isset($config->ntlmsso_subnet)) {
-    $config->ntlmsso_subnet = '';
-}
-if (!isset($config->ntlmsso_ie_fastpath)) {
-    $config->ntlmsso_ie_fastpath = 0;
-}
-if (!isset($config->ntlmsso_type)) {
-    $config->ntlmsso_type = 'ntlm';
-}
-if (!isset($config->ntlmsso_remoteuserformat)) {
-    $config->ntlmsso_remoteuserformat = '';
-}
-
-$yesno = array(get_string('no'), get_string('yes'));
-
-$fastpathoptions = array(AUTH_NTLM_FASTPATH_YESFORM => get_string('auth_ntlmsso_ie_fastpath_yesform', 'auth_ldap'),
-                         AUTH_NTLM_FASTPATH_YESATTEMPT => get_string('auth_ntlmsso_ie_fastpath_yesattempt', 'auth_ldap'),
-                         AUTH_NTLM_FASTPATH_ATTEMPT => get_string('auth_ntlmsso_ie_fastpath_attempt', 'auth_ldap'));
-
-$disabled = '';
-$pagedresultssupported = false;
-if ($config->host_url !== '') {
-    /**
-     * We try to connect each and every time we open the config, because we want to set the Page
-     * Size setting as enabled or disabled depending on the configured LDAP server supporting
-     * pagination or not, and to notify the user about it. If the user changed the LDAP server (or
-     * the LDAP protocol version) last time, it might happen that paged results are no longer
-     * available and we want to show that to the user the next time she goes to the settings page.
-     */
-    try {
-        $ldapconn = $this->ldap_connect();
-        $pagedresultssupported = ldap_paged_results_supported($config->ldap_version, $ldapconn);
-    } catch (Exception $e) {
-        // If we couldn't connect and get the supported options, we can only assume we don't support paged results.
-        $pagedresultssupported = false;
-    }
-}
-/* Make sure we only disable the paged result size setting and show the notification about it if
- * there is a configured server that we tried to contact.  Othersiwe, if someone's LDAP server does
- * support paged results, they won't be able to turn it on the first time they set it up (because
- * the field will be disabled).
- */
-if (($config->host_url !== '') && (!$pagedresultssupported)) {
-    $disabled = ' disabled="disabled"';
-    echo $OUTPUT->notification(get_string('pagedresultsnotsupp', 'auth_ldap'), \core\output\notification::NOTIFY_INFO);
-}
-
-?>
-<table cellspacing="0" cellpadding="5" border="0">
-<tr>
-   <td colspan="2">
-       <h4><?php print_string('auth_ldap_server_settings', 'auth_ldap') ?></h4>
-   </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="host_url"><?php print_string('auth_ldap_host_url_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="host_url" id="host_url" type="text" class="text-ltr" size="30" value="<?php echo $config->host_url?>" />
-        <?php if (isset($err['host_url'])) { echo $OUTPUT->error_text($err['host_url']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_host_url', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="ldap_version"><?php print_string('auth_ldap_version_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <?php
-           $versions = array();
-           $versions[2] = '2';
-           $versions[3] = '3';
-           echo html_writer::select($versions, 'ldap_version', $config->ldap_version, false);
-           if (isset($err['ldap_version'])) { echo $OUTPUT->error_text($err['ldap_version']); }
-        ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_version', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right">
-        <label for="start_tls"><?php print_string('start_tls_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <?php echo html_writer::select($yesno, 'start_tls', $config->start_tls, false); ?>
-    </td>
-    <td>
-        <?php print_string('start_tls', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="ldapencoding"><?php print_string('auth_ldap_ldap_encoding_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input id="ldapencoding" name="ldapencoding" type="text" class="text-ltr" value="<?php echo $config->ldapencoding ?>" />
-        <?php if (isset($err['ldapencoding'])) { echo $OUTPUT->error_text($err['ldapencoding']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_ldap_encoding', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right">
-        <label for="pagesize"><?php print_string('pagesize_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input id="pagesize" name="pagesize" type="text" class="text-ltr" value="<?php echo $config->pagesize ?>" <?php echo $disabled ?>/>
-        <?php
-            if (isset($err['pagesize'])) { echo $OUTPUT->error_text($err['pagesize']); }
-            if ($disabled) {
-                // Don't loose the page size value (disabled fields are not submitted!)
-        ?>
-            <input id="pagesize" name="pagesize" type="hidden" value="<?php echo $config->pagesize ?>" />
-        <?php } ?>
-
-    </td>
-    <td>
-        <?php print_string('pagesize', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr>
-    <td colspan="2">
-        <h4><?php print_string('auth_ldap_bind_settings', 'auth_ldap') ?></h4>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="menupreventpassindb"><?php print_string('auth_ldap_preventpassindb_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <?php echo html_writer::select($yesno, 'preventpassindb', $config->preventpassindb, false); ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_preventpassindb', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="bind_dn"><?php print_string('auth_ldap_bind_dn_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="bind_dn" id="bind_dn" type="text" class="text-ltr" size="30" value="<?php echo $config->bind_dn?>" />
-        <?php if (isset($err['bind_dn'])) { echo $OUTPUT->error_text($err['bind_dn']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_bind_dn', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="bind_pw"><?php print_string('auth_ldap_bind_pw_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="bind_pw" id="bind_pw" type="password" class="text-ltr" size="30" value="<?php echo $config->bind_pw?>" autocomplete="off"/>
-        <?php if (isset($err['bind_pw'])) { echo $OUTPUT->error_text($err['bind_pw']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_bind_pw', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr>
-    <td colspan="2">
-        <h4><?php print_string('auth_ldap_user_settings', 'auth_ldap') ?></h4>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="menuuser_type"><?php print_string('auth_ldap_user_type_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <?php
-            echo html_writer::select(ldap_supported_usertypes(), 'user_type', $config->user_type, false);
-            if (isset($err['user_type'])) { echo $OUTPUT->error_text($err['user_type']); }
-        ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_user_type', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="contexts"><?php print_string('auth_ldap_contexts_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="contexts" id="contexts" type="text" class="text-ltr" size="30" value="<?php echo $config->contexts?>" />
-        <?php if (isset($err['contexts'])) { echo $OUTPUT->error_text($err['contexts']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_contexts', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="menusearch_sub"><?php print_string('auth_ldap_search_sub_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <?php echo html_writer::select($yesno, 'search_sub', $config->search_sub, false); ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_search_sub', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="menuopt_deref"><?php print_string('auth_ldap_opt_deref_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <?php
-           $opt_deref = array();
-           $opt_deref[LDAP_DEREF_NEVER] = get_string('no');
-           $opt_deref[LDAP_DEREF_ALWAYS] = get_string('yes');
-           echo html_writer::select($opt_deref, 'opt_deref', $config->opt_deref, false);
-           if (isset($err['opt_deref'])) { echo $OUTPUT->error_text($err['opt_deref']); }
-        ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_opt_deref', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="user_attribute"><?php print_string('auth_ldap_user_attribute_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="user_attribute" id="user_attribute" type="text" class="text-ltr" size="30" value="<?php echo $config->user_attribute?>" />
-        <?php if (isset($err['user_attribute'])) { echo $OUTPUT->error_text($err['user_attribute']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_user_attribute', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="suspended_attribute"><?php print_string('auth_ldap_suspended_attribute_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="suspended_attribute" id="suspended_attribute" type="text" class="text-ltr" size="30" value="<?php echo $config->suspended_attribute?>" />
-        <?php if (isset($err['suspended_attribute'])) { echo $OUTPUT->error_text($err['suspended_attribute']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_suspended_attribute', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="memberattribute"><?php print_string('auth_ldap_memberattribute_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="memberattribute" id="memberattribute" type="text" class="text-ltr" size="30" value="<?php echo $config->memberattribute?>" />
-        <?php if (isset($err['memberattribute'])) { echo $OUTPUT->error_text($err['memberattribute']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_memberattribute', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="memberattribute_isdn"><?php print_string('auth_ldap_memberattribute_isdn_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="memberattribute_isdn" id="memberattribute_isdn" type="text" class="text-ltr" size="30" value="<?php echo $config->memberattribute_isdn?>" />
-        <?php if (isset($err['memberattribute_isdn'])) { echo $OUTPUT->error_text($err['memberattribute_isdn']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_memberattribute_isdn', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="objectclass"><?php print_string('auth_ldap_objectclass_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="objectclass" id="objectclass" type="text" class="text-ltr" size="30" value="<?php echo $config->objectclass?>" />
-        <?php if (isset($err['objectclass'])) { echo $OUTPUT->error_text($err['objectclass']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_objectclass', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr>
-    <td colspan="2">
-        <h4><?php print_string('forcechangepassword', 'auth') ?></h4>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right" valign="top">
-        <label for="menuforcechangepassword"><?php print_string('forcechangepassword', 'auth') ?></label>
-    </td>
-    <td>
-        <?php echo html_writer::select($yesno, 'forcechangepassword', $config->forcechangepassword, false); ?>
-    </td>
-    <td align="left" valign="top">
-        <p><?php print_string('forcechangepasswordfirst_help', 'auth') ?></p>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right" valign="top">
-        <label for="menustdchangepassword"><?php print_string('stdchangepassword', 'auth') ?></label>
-    </td>
-    <td>
-        <?php echo html_writer::select($yesno, 'stdchangepassword', $config->stdchangepassword, false); ?>
-    </td>
-    <td align="left" valign="top">
-        <p><?php print_string('stdchangepassword_expl', 'auth') ?></p>
-        <p><?php print_string('stdchangepassword_explldap', 'auth') ?></p>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="menupasstype"><?php print_string('auth_ldap_passtype_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <?php
-            $passtype = array();
-            $passtype['plaintext'] = get_string('plaintext', 'auth');
-            $passtype['md5']       = get_string('md5', 'auth');
-            $passtype['sha1']      = get_string('sha1', 'auth');
-            echo html_writer::select($passtype, 'passtype', $config->passtype, false);
-        ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_passtype', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right">
-        <label for="changepasswordurl"><?php print_string('auth_ldap_changepasswordurl_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="changepasswordurl" id="changepasswordurl" type="text" class="text-ltr" value="<?php echo $config->changepasswordurl ?>" />
-        <?php if (isset($err['changepasswordurl'])) { echo $OUTPUT->error_text($err['changepasswordurl']); } ?>
-    </td>
-    <td>
-        <?php print_string('changepasswordhelp', 'auth') ?>
-    </td>
-</tr>
-<tr>
-    <td colspan="2">
-        <h4><?php print_string('auth_ldap_passwdexpire_settings', 'auth_ldap') ?></h4>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="menuexpiration"><?php print_string('auth_ldap_expiration_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <?php
-           $expiration = array();
-           $expiration['0'] = 'no';
-           $expiration['1'] = 'LDAP';
-           echo html_writer::select($expiration, 'expiration', $config->expiration, false);
-           if (isset($err['expiration'])) { echo $OUTPUT->error_text($err['expiration']); }
-        ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_expiration_desc', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="expiration_warning"><?php print_string('auth_ldap_expiration_warning_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="expiration_warning" id="expiration_warning" type="text" class="text-ltr" size="2" value="<?php echo $config->expiration_warning?>" />
-        <?php if (isset($err['expiration_warning'])) { echo $OUTPUT->error_text($err['expiration_warning']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_expiration_warning_desc', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="expireattr"><?php print_string('auth_ldap_expireattr_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="expireattr" id="expireattr" type="text" class="text-ltr" size="30" value="<?php echo $config->expireattr?>" />
-        <?php if (isset($err['expireattr'])) { echo $OUTPUT->error_text($err['expireattr']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_expireattr_desc', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="menugracelogins"><?php print_string('auth_ldap_gracelogins_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <?php echo html_writer::select($yesno, 'gracelogins', $config->gracelogins, false); ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_gracelogins_desc', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="graceattr"><?php print_string('auth_ldap_gracelogin_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="graceattr" id="graceattr" type="text" class="text-ltr" size="30" value="<?php echo $config->graceattr?>" />
-        <?php if (isset($err['graceattr'])) { echo $OUTPUT->error_text($err['graceattr']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_graceattr_desc', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr>
-    <td colspan="2">
-        <h4><?php print_string('auth_user_create', 'auth') ?></h4>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right">
-        <label for="menuauth_user_create"><?php print_string('auth_ldap_auth_user_create_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <?php echo html_writer::select($yesno, 'auth_user_create', $config->auth_user_create, false); ?>
-    </td>
-    <td>
-        <?php print_string('auth_user_creation', 'auth'); ?>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="create_context"><?php print_string('auth_ldap_create_context_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="create_context" id="create_context" type="text" class="text-ltr" size="30" value="<?php echo $config->create_context?>" />
-        <?php if (isset($err['create_context'])) { echo $OUTPUT->error_text($err['create_context']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_create_context', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr>
-    <td colspan="2">
-        <h4><?php print_string('coursecreators') ?></h4>
-    </td>
-</tr>
-<tr valign="top" class="required">
-    <td align="right">
-        <label for="creators"><?php print_string('auth_ldap_creators_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="creators" id="creators" type="text" class="text-ltr" size="30" value="<?php echo $config->creators?>" />
-        <?php if (isset($err['creators'])) { echo $OUTPUT->error_text($err['creators']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ldap_creators', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr>
-    <td colspan="2">
-        <h4><?php print_string('auth_sync_script', 'auth') ?></h4>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right">
-        <label for="menuremoveuser"><?php print_string('auth_remove_user_key', 'auth') ?></label>
-    </td>
-    <td>
-        <?php
-            $deleteopt = array();
-            $deleteopt[AUTH_REMOVEUSER_KEEP] = get_string('auth_remove_keep', 'auth');
-            $deleteopt[AUTH_REMOVEUSER_SUSPEND] = get_string('auth_remove_suspend', 'auth');
-            $deleteopt[AUTH_REMOVEUSER_FULLDELETE] = get_string('auth_remove_delete', 'auth');
-            echo html_writer::select($deleteopt, 'removeuser', $config->removeuser, false);
-        ?>
-    </td>
-    <td>
-        <?php print_string('auth_remove_user', 'auth') ?>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right">
-        <label for="menusync_suspended"><?php print_string('auth_sync_suspended_key', 'auth') ?></label>
-    </td>
-    <td>
-        <?php echo html_writer::select($yesno, 'sync_suspended', $config->sync_suspended, false); ?>
-    </td>
-    <td>
-        <?php print_string('auth_sync_suspended', 'auth'); ?>
-    </td>
-</tr>
-<tr>
-    <td colspan="2">
-        <h4><?php print_string('auth_ntlmsso', 'auth_ldap') ?></h4>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right">
-        <label for="menuntlmsso_enabled"><?php print_string('auth_ntlmsso_enabled_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <?php echo html_writer::select($yesno, 'ntlmsso_enabled', $config->ntlmsso_enabled, false); ?>
-    </td>
-    <td>
-        <?php print_string('auth_ntlmsso_enabled', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right">
-        <label for="ntlmsso_subnet"><?php print_string('auth_ntlmsso_subnet_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="ntlmsso_subnet" id="ntlmsso_subnet" type="text" class="text-ltr" size="30" value="<?php p($config->ntlmsso_subnet) ?>" />
-    </td>
-    <td>
-        <?php print_string('auth_ntlmsso_subnet', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right">
-        <label for="menuntlmsso_ie_fastpath"><?php print_string('auth_ntlmsso_ie_fastpath_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <?php echo html_writer::select($fastpathoptions, 'ntlmsso_ie_fastpath', $config->ntlmsso_ie_fastpath, false); ?>
-    </td>
-    <td>
-    <?php print_string('auth_ntlmsso_ie_fastpath', 'auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right">
-        <label for="menuntlmsso_type"><?php print_string('auth_ntlmsso_type_key', 'auth_ldap')?></label>
-    </td>
-    <td>
-        <?php
-            $types = array();
-            $types['ntlm'] = 'NTLM';
-            $types['kerberos'] = 'Kerberos';
-            echo html_writer::select($types, 'ntlmsso_type', $config->ntlmsso_type, false);
-        ?>
-    </td>
-    <td>
-        <?php print_string('auth_ntlmsso_type','auth_ldap') ?>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right">
-        <label for="ntlmsso_remoteuserformat"><?php print_string('auth_ntlmsso_remoteuserformat_key', 'auth_ldap') ?></label>
-    </td>
-    <td>
-        <input name="ntlmsso_remoteuserformat" id="ntlmsso_remoteuserformat" type="text" class="text-ltr" size="30" value="<?php echo $config->ntlmsso_remoteuserformat?>" />
-        <?php if (isset($err['ntlmsso_remoteuserformat'])) { echo $OUTPUT->error_text($err['ntlmsso_remoteuserformat']); } ?>
-    </td>
-    <td>
-        <?php print_string('auth_ntlmsso_remoteuserformat', 'auth_ldap') ?>
-    </td>
-</tr>
-<?php
-$help  = get_string('auth_ldapextrafields', 'auth_ldap');
-$help .= get_string('auth_updatelocal_expl', 'auth');
-$help .= get_string('auth_fieldlock_expl', 'auth');
-$help .= get_string('auth_updateremote_expl', 'auth');
-$help .= '<hr />';
-$help .= get_string('auth_updateremote_ldap', 'auth');
-
-print_auth_lock_options($this->authtype, $user_fields, $help, true, true, $this->get_custom_user_profile_fields());
-?>
-</table>
index c72b48f..e6c02cd 100644 (file)
@@ -25,6 +25,7 @@
 defined('MOODLE_INTERNAL') || die();
 
 /**
+ * Function to upgrade auth_ldap.
  * @param int $oldversion the version we are upgrading from
  * @return bool result
  */
@@ -58,5 +59,11 @@ function xmldb_auth_ldap_upgrade($oldversion) {
     // Automatically generated Moodle v3.2.0 release upgrade line.
     // Put any upgrade step following this.
 
+    if ($oldversion < 2017020700) {
+        // Convert info in config plugins from auth/ldap to auth_ldap.
+        $DB->set_field('config_plugins', 'plugin', 'auth_ldap', array('plugin' => 'auth/ldap'));
+        upgrade_plugin_savepoint(true, 2017020700, 'auth', 'ldap');
+    }
+
     return true;
 }
index a5285dd..c1c828b 100644 (file)
@@ -114,10 +114,12 @@ $string['auth_ntlmsso_subnet_key'] = 'Subnet';
 $string['auth_ntlmsso_type_key'] = 'Authentication type';
 $string['auth_ntlmsso_type'] = 'The authentication method configured in the web server to authenticate the users (if in doubt, choose NTLM)';
 $string['connectingldap'] = "Connecting to LDAP server...\n";
+$string['connectingldapsuccess'] = "Connecting to your LDAP server was successful";
 $string['creatingtemptable'] = "Creating temporary table {\$a}\n";
 $string['didntfindexpiretime'] = 'password_expire() didn\'t find expiration time.';
 $string['didntgetusersfromldap'] = "Did not get any users from LDAP -- error? -- exiting\n";
 $string['gotcountrecordsfromldap'] = "Got {\$a} records from LDAP\n";
+$string['ldapnotconfigured'] = 'The LDAP host url is currently not configured';
 $string['morethanoneuser'] = 'Strange! More than one user record found in ldap. Only using the first one.';
 $string['needbcmath'] = 'You need the BCMath extension to use grace logins with Active Directory';
 $string['needmbstring'] = 'You need the mbstring extension to change passwords in Active Directory';
diff --git a/auth/ldap/settings.php b/auth/ldap/settings.php
new file mode 100644 (file)
index 0000000..c631f31
--- /dev/null
@@ -0,0 +1,301 @@
+<?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/>.
+
+/**
+ * Admin settings and defaults.
+ *
+ * @package auth_ldap
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+if ($ADMIN->fulltree) {
+    // We use a couple of custom admin settings since we need to massage the data before it is inserted into the DB.
+    require_once($CFG->dirroot.'/auth/ldap/classes/admin_setting_special_lowercase_configtext.php');
+    require_once($CFG->dirroot.'/auth/ldap/classes/admin_setting_special_contexts_configtext.php');
+    require_once($CFG->dirroot.'/auth/ldap/classes/admin_setting_special_ntlm_configtext.php');
+
+    // We need to use some of the Moodle LDAP constants / functions to create the list of options.
+    require_once($CFG->dirroot.'/auth/ldap/auth.php');
+
+    // Introductory explanation.
+    $settings->add(new admin_setting_heading('auth_ldap/pluginname', '',
+            new lang_string('auth_ldapdescription', 'auth_ldap')));
+
+    // LDAP server settings.
+    $settings->add(new admin_setting_heading('auth_ldap/ldapserversettings',
+            new lang_string('auth_ldap_server_settings', 'auth_ldap'), ''));
+
+    // Host.
+    $settings->add(new admin_setting_configtext('auth_ldap/host_url',
+            get_string('auth_ldap_host_url_key', 'auth_ldap'),
+            get_string('auth_ldap_host_url', 'auth_ldap'), '', PARAM_RAW_TRIMMED));
+
+    // Version.
+    $versions = array();
+    $versions[2] = '2';
+    $versions[3] = '3';
+    $settings->add(new admin_setting_configselect('auth_ldap/ldap_version',
+            new lang_string('auth_ldap_version_key', 'auth_ldap'),
+            new lang_string('auth_ldap_version', 'auth_ldap'), 3, $versions));
+
+    // Start TLS.
+    $yesno = array(
+        new lang_string('no'),
+        new lang_string('yes'),
+    );
+    $settings->add(new admin_setting_configselect('auth_ldap/start_tls',
+            new lang_string('start_tls_key', 'auth_ldap'),
+            new lang_string('start_tls', 'auth_ldap'), 0 , $yesno));
+
+
+    // Encoding.
+    $settings->add(new admin_setting_configtext('auth_ldap/ldapencoding',
+            get_string('auth_ldap_ldap_encoding_key', 'auth_ldap'),
+            get_string('auth_ldap_ldap_encoding', 'auth_ldap'), 'utf-8', PARAM_RAW_TRIMMED));
+
+    // Page Size. (Hide if not available).
+    $settings->add(new admin_setting_configtext('auth_ldap/pagesize',
+            get_string('pagesize_key', 'auth_ldap'),
+            get_string('pagesize', 'auth_ldap'), '250', PARAM_INT));
+
+    // Bind settings.
+    $settings->add(new admin_setting_heading('auth_ldap/ldapbindsettings',
+            new lang_string('auth_ldap_bind_settings', 'auth_ldap'), ''));
+
+    // Store Password in DB.
+    $settings->add(new admin_setting_configselect('auth_ldap/preventpassindb',
+            new lang_string('auth_ldap_preventpassindb_key', 'auth_ldap'),
+            new lang_string('auth_ldap_preventpassindb', 'auth_ldap'), 0 , $yesno));
+
+    // User ID.
+    $settings->add(new admin_setting_configtext('auth_ldap/bind_dn',
+            get_string('auth_ldap_bind_dn_key', 'auth_ldap'),
+            get_string('auth_ldap_bind_dn', 'auth_ldap'), '', PARAM_RAW_TRIMMED));
+
+    // Password.
+    $settings->add(new admin_setting_configpasswordunmask('auth_ldap/bind_pw',
+            get_string('auth_ldap_bind_pw_key', 'auth_ldap'),
+            get_string('auth_ldap_bind_pw', 'auth_ldap'), ''));
+
+    // User Lookup settings.
+    $settings->add(new admin_setting_heading('auth_ldap/ldapuserlookup',
+            new lang_string('auth_ldap_user_settings', 'auth_ldap'), ''));
+
+    // User Type.
+    $settings->add(new admin_setting_configselect('auth_ldap/user_type',
+            new lang_string('auth_ldap_user_type_key', 'auth_ldap'),
+            new lang_string('auth_ldap_user_type', 'auth_ldap'), 'default', ldap_supported_usertypes()));
+
+    // Contexts.
+    $settings->add(new auth_ldap_admin_setting_special_contexts_configtext('auth_ldap/contexts',
+            get_string('auth_ldap_contexts_key', 'auth_ldap'),
+            get_string('auth_ldap_contexts', 'auth_ldap'), '', PARAM_RAW_TRIMMED));
+
+    // Search subcontexts.
+    $settings->add(new admin_setting_configselect('auth_ldap/search_sub',
+            new lang_string('auth_ldap_search_sub_key', 'auth_ldap'),
+            new lang_string('auth_ldap_search_sub', 'auth_ldap'), 0 , $yesno));
+
+    // Dereference aliases.
+    $optderef = array();
+    $optderef[LDAP_DEREF_NEVER] = get_string('no');
+    $optderef[LDAP_DEREF_ALWAYS] = get_string('yes');
+
+    $settings->add(new admin_setting_configselect('auth_ldap/opt_deref',
+            new lang_string('auth_ldap_opt_deref_key', 'auth_ldap'),
+            new lang_string('auth_ldap_opt_deref', 'auth_ldap'), LDAP_DEREF_NEVER , $optderef));
+
+    // User attribute.
+    $settings->add(new auth_ldap_admin_setting_special_lowercase_configtext('auth_ldap/user_attribute',
+            get_string('auth_ldap_user_attribute_key', 'auth_ldap'),
+            get_string('auth_ldap_user_attribute', 'auth_ldap'), '', PARAM_RAW));
+
+    // Suspended attribute.
+    $settings->add(new auth_ldap_admin_setting_special_lowercase_configtext('auth_ldap/suspended_attribute',
+            get_string('auth_ldap_suspended_attribute_key', 'auth_ldap'),
+            get_string('auth_ldap_suspended_attribute', 'auth_ldap'), '', PARAM_RAW));
+
+    // Member attribute.
+    $settings->add(new auth_ldap_admin_setting_special_lowercase_configtext('auth_ldap/memberattribute',
+            get_string('auth_ldap_memberattribute_key', 'auth_ldap'),
+            get_string('auth_ldap_memberattribute', 'auth_ldap'), '', PARAM_RAW));
+
+    // Member attribute uses dn.
+    $settings->add(new admin_setting_configtext('auth_ldap/memberattribute_isdn',
+            get_string('auth_ldap_memberattribute_isdn_key', 'auth_ldap'),
+            get_string('auth_ldap_memberattribute_isdn', 'auth_ldap'), '', PARAM_RAW));
+
+    // Object class.
+    $settings->add(new admin_setting_configtext('auth_ldap/objectclass',
+            get_string('auth_ldap_objectclass_key', 'auth_ldap'),
+            get_string('auth_ldap_objectclass', 'auth_ldap'), '', PARAM_RAW_TRIMMED));
+
+    // Force Password change Header.
+    $settings->add(new admin_setting_heading('auth_ldap/ldapforcepasswordchange',
+            new lang_string('forcechangepassword', 'auth'), ''));
+
+    // Force Password change.
+    $settings->add(new admin_setting_configselect('auth_ldap/forcechangepassword',
+            new lang_string('forcechangepassword', 'auth'),
+            new lang_string('forcechangepasswordfirst_help', 'auth'), 0 , $yesno));
+
+    // Standard Password Change.
+    $settings->add(new admin_setting_configselect('auth_ldap/stdchangepassword',
+            new lang_string('stdchangepassword', 'auth'), new lang_string('stdchangepassword_expl', 'auth') .' '.
+            get_string('stdchangepassword_explldap', 'auth'), 0 , $yesno));
+
+    // Password Type.
+    $passtype = array();
+    $passtype['plaintext'] = get_string('plaintext', 'auth');
+    $passtype['md5']       = get_string('md5', 'auth');
+    $passtype['sha1']      = get_string('sha1', 'auth');
+
+    $settings->add(new admin_setting_configselect('auth_ldap/passtype',
+            new lang_string('auth_ldap_passtype_key', 'auth_ldap'),
+            new lang_string('auth_ldap_passtype', 'auth_ldap'), 'plaintext', $passtype));
+
+    // Password change URL.
+    $settings->add(new admin_setting_configtext('auth_ldap/changepasswordurl',
+            get_string('auth_ldap_changepasswordurl_key', 'auth_ldap'),
+            get_string('changepasswordhelp', 'auth'), '', PARAM_URL));
+
+    // Password Expiration Header.
+    $settings->add(new admin_setting_heading('auth_ldap/passwordexpire',
+            new lang_string('auth_ldap_passwdexpire_settings', 'auth_ldap'), ''));
+
+    // Password Expiration.
+    $expiration = array();
+    $expiration['0'] = 'no';
+    $expiration['1'] = 'LDAP';
+    $settings->add(new admin_setting_configselect('auth_ldap/expiration',
+            new lang_string('auth_ldap_expiration_key', 'auth_ldap'),
+            new lang_string('auth_ldap_expiration_desc', 'auth_ldap'), 0 , $expiration));
+
+    // Password Expiration warning.
+    $settings->add(new admin_setting_configtext('auth_ldap/expiration_warning',
+            get_string('auth_ldap_expiration_warning_key', 'auth_ldap'),
+            get_string('auth_ldap_expiration_warning_desc', 'auth_ldap'), '', PARAM_RAW));
+
+    // Password Expiration attribute.
+    $settings->add(new auth_ldap_admin_setting_special_lowercase_configtext('auth_ldap/expireattr',
+            get_string('auth_ldap_expireattr_key', 'auth_ldap'),
+            get_string('auth_ldap_expireattr_desc', 'auth_ldap'), '', PARAM_RAW));
+
+    // Grace Logins.
+    $settings->add(new admin_setting_configselect('auth_ldap/gracelogins',
+            new lang_string('auth_ldap_gracelogins_key', 'auth_ldap'),
+            new lang_string('auth_ldap_gracelogins_desc', 'auth_ldap'), 0 , $yesno));
+
+    // Grace logins attribute.
+    $settings->add(new auth_ldap_admin_setting_special_lowercase_configtext('auth_ldap/graceattr',
+            get_string('auth_ldap_gracelogin_key', 'auth_ldap'),
+            get_string('auth_ldap_graceattr_desc', 'auth_ldap'), '', PARAM_RAW));
+
+    // User Creation.
+    $settings->add(new admin_setting_heading('auth_ldap/usercreation',
+            new lang_string('auth_user_create', 'auth'), ''));
+
+    // Create users externally.
+    $settings->add(new admin_setting_configselect('auth_ldap/auth_user_create',
+            new lang_string('auth_ldap_auth_user_create_key', 'auth_ldap'),
+            new lang_string('auth_user_creation', 'auth'), 0 , $yesno));
+
+    // Context for new users.
+    $settings->add(new admin_setting_configtext('auth_ldap/create_context',
+            get_string('auth_ldap_create_context_key', 'auth_ldap'),
+            get_string('auth_ldap_create_context', 'auth_ldap'), '', PARAM_RAW_TRIMMED));
+
+    // Course Creators Header.
+    $settings->add(new admin_setting_heading('auth_ldap/coursecreators',
+            new lang_string('coursecreators'), ''));
+
+    // Course creators field mapping.
+    $settings->add(new admin_setting_configtext('auth_ldap/creators',
+            get_string('auth_ldap_creators_key', 'auth_ldap'),
+            get_string('auth_ldap_creators', 'auth_ldap'), '', PARAM_RAW_TRIMMED));
+
+    // User Account Sync.
+    $settings->add(new admin_setting_heading('auth_ldap/syncusers',
+            new lang_string('auth_sync_script', 'auth'), ''));
+
+    // Remove external user.
+    $deleteopt = array();
+    $deleteopt[AUTH_REMOVEUSER_KEEP] = get_string('auth_remove_keep', 'auth');
+    $deleteopt[AUTH_REMOVEUSER_SUSPEND] = get_string('auth_remove_suspend', 'auth');
+    $deleteopt[AUTH_REMOVEUSER_FULLDELETE] = get_string('auth_remove_delete', 'auth');
+
+    $settings->add(new admin_setting_configselect('auth_ldap/removeuser',
+            new lang_string('auth_remove_user_key', 'auth'),
+            new lang_string('auth_remove_user', 'auth'), AUTH_REMOVEUSER_KEEP, $deleteopt));
+
+    // Sync Suspension.
+    $settings->add(new admin_setting_configselect('auth_ldap/sync_suspended',
+            new lang_string('auth_sync_suspended_key', 'auth'),
+            new lang_string('auth_sync_suspended', 'auth'), 0 , $yesno));
+
+    // NTLM SSO Header.
+    $settings->add(new admin_setting_heading('auth_ldap/ntlm',
+            new lang_string('auth_ntlmsso', 'auth_ldap'), ''));
+
+    // Enable NTLM.
+    $settings->add(new admin_setting_configselect('auth_ldap/ntlmsso_enabled',
+            new lang_string('auth_ntlmsso_enabled_key', 'auth_ldap'),
+            new lang_string('auth_ntlmsso_enabled', 'auth_ldap'), 0 , $yesno));
+
+    // Subnet.
+    $settings->add(new admin_setting_configtext('auth_ldap/ntlmsso_subnet',
+            get_string('auth_ntlmsso_subnet_key', 'auth_ldap'),
+            get_string('auth_ntlmsso_subnet', 'auth_ldap'), '', PARAM_RAW_TRIMMED));
+
+    // NTLM Fast Path.
+    $fastpathoptions = array();
+    $fastpathoptions[AUTH_NTLM_FASTPATH_YESFORM] = get_string('auth_ntlmsso_ie_fastpath_yesform', 'auth_ldap');
+    $fastpathoptions[AUTH_NTLM_FASTPATH_YESATTEMPT] = get_string('auth_ntlmsso_ie_fastpath_yesattempt', 'auth_ldap');
+    $fastpathoptions[AUTH_NTLM_FASTPATH_ATTEMPT] = get_string('auth_ntlmsso_ie_fastpath_attempt', 'auth_ldap');
+
+    $settings->add(new admin_setting_configselect('auth_ldap/ntlmsso_ie_fastpath',
+            new lang_string('auth_ntlmsso_ie_fastpath_key', 'auth_ldap'),
+            new lang_string('auth_ntlmsso_ie_fastpath', 'auth_ldap'),
+            AUTH_NTLM_FASTPATH_ATTEMPT, $fastpathoptions));
+
+    // Authentication type.
+    $types = array();
+    $types['ntlm'] = 'NTLM';
+    $types['kerberos'] = 'Kerberos';
+
+    $settings->add(new admin_setting_configselect('auth_ldap/ntlmsso_type',
+            new lang_string('auth_ntlmsso_type_key', 'auth_ldap'),
+            new lang_string('auth_ntlmsso_type', 'auth_ldap'), 'ntlm', $types));
+
+    // Remote Username format.
+    $settings->add(new auth_ldap_admin_setting_special_ntlm_configtext('auth_ldap/ntlmsso_remoteuserformat',
+            get_string('auth_ntlmsso_remoteuserformat_key', 'auth_ldap'),
+            get_string('auth_ntlmsso_remoteuserformat', 'auth_ldap'), '', PARAM_RAW_TRIMMED));
+
+    // Display locking / mapping of profile fields.
+    $authplugin = get_auth_plugin($this->name);
+    $help  = get_string('auth_ldapextrafields', 'auth_ldap');
+    $help .= get_string('auth_updatelocal_expl', 'auth');
+    $help .= get_string('auth_fieldlock_expl', 'auth');
+    $help .= get_string('auth_updateremote_expl', 'auth');
+    $help .= '<hr />';
+    $help .= get_string('auth_updateremote_ldap', 'auth');
+    display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
+            $help, true, true, $authplugin->get_custom_user_profile_fields());
+}
index dff1485..d50f67d 100644 (file)
@@ -96,37 +96,37 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
 
 
         // Configure the plugin a bit.
-        set_config('host_url', TEST_AUTH_LDAP_HOST_URL, 'auth/ldap');
-        set_config('start_tls', 0, 'auth/ldap');
-        set_config('ldap_version', 3, 'auth/ldap');
-        set_config('ldapencoding', 'utf-8', 'auth/ldap');
-        set_config('pagesize', '2', 'auth/ldap');
-        set_config('bind_dn', TEST_AUTH_LDAP_BIND_DN, 'auth/ldap');
-        set_config('bind_pw', TEST_AUTH_LDAP_BIND_PW, 'auth/ldap');
-        set_config('user_type', 'rfc2307', 'auth/ldap');
-        set_config('contexts', 'ou=users,'.$topdn, 'auth/ldap');
-        set_config('search_sub', 0, 'auth/ldap');
-        set_config('opt_deref', LDAP_DEREF_NEVER, 'auth/ldap');
-        set_config('user_attribute', 'cn', 'auth/ldap');
-        set_config('memberattribute', 'memberuid', 'auth/ldap');
-        set_config('memberattribute_isdn', 0, 'auth/ldap');
-        set_config('creators', 'cn=creators,'.$topdn, 'auth/ldap');
-        set_config('removeuser', AUTH_REMOVEUSER_KEEP, 'auth/ldap');
-
-        set_config('field_map_email', 'mail', 'auth/ldap');
-        set_config('field_updatelocal_email', 'oncreate', 'auth/ldap');
-        set_config('field_updateremote_email', '0', 'auth/ldap');
-        set_config('field_lock_email', 'unlocked', 'auth/ldap');
-
-        set_config('field_map_firstname', 'givenName', 'auth/ldap');
-        set_config('field_updatelocal_firstname', 'oncreate', 'auth/ldap');
-        set_config('field_updateremote_firstname', '0', 'auth/ldap');
-        set_config('field_lock_firstname', 'unlocked', 'auth/ldap');
-
-        set_config('field_map_lastname', 'sn', 'auth/ldap');
-        set_config('field_updatelocal_lastname', 'oncreate', 'auth/ldap');
-        set_config('field_updateremote_lastname', '0', 'auth/ldap');
-        set_config('field_lock_lastname', 'unlocked', 'auth/ldap');
+        set_config('host_url', TEST_AUTH_LDAP_HOST_URL, 'auth_ldap');
+        set_config('start_tls', 0, 'auth_ldap');
+        set_config('ldap_version', 3, 'auth_ldap');
+        set_config('ldapencoding', 'utf-8', 'auth_ldap');
+        set_config('pagesize', '2', 'auth_ldap');
+        set_config('bind_dn', TEST_AUTH_LDAP_BIND_DN, 'auth_ldap');
+        set_config('bind_pw', TEST_AUTH_LDAP_BIND_PW, 'auth_ldap');
+        set_config('user_type', 'rfc2307', 'auth_ldap');
+        set_config('contexts', 'ou=users,'.$topdn, 'auth_ldap');
+        set_config('search_sub', 0, 'auth_ldap');
+        set_config('opt_deref', LDAP_DEREF_NEVER, 'auth_ldap');
+        set_config('user_attribute', 'cn', 'auth_ldap');
+        set_config('memberattribute', 'memberuid', 'auth_ldap');
+        set_config('memberattribute_isdn', 0, 'auth_ldap');
+        set_config('creators', 'cn=creators,'.$topdn, 'auth_ldap');
+        set_config('removeuser', AUTH_REMOVEUSER_KEEP, 'auth_ldap');
+
+        set_config('field_map_email', 'mail', 'auth_ldap');
+        set_config('field_updatelocal_email', 'oncreate', 'auth_ldap');
+        set_config('field_updateremote_email', '0', 'auth_ldap');
+        set_config('field_lock_email', 'unlocked', 'auth_ldap');
+
+        set_config('field_map_firstname', 'givenName', 'auth_ldap');
+        set_config('field_updatelocal_firstname', 'oncreate', 'auth_ldap');
+        set_config('field_updateremote_firstname', '0', 'auth_ldap');
+        set_config('field_lock_firstname', 'unlocked', 'auth_ldap');
+
+        set_config('field_map_lastname', 'sn', 'auth_ldap');
+        set_config('field_updatelocal_lastname', 'oncreate', 'auth_ldap');
+        set_config('field_updateremote_lastname', '0', 'auth_ldap');
+        set_config('field_lock_lastname', 'unlocked', 'auth_ldap');
 
 
         $this->assertEquals(2, $DB->count_records('user'));
@@ -182,7 +182,7 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
         $this->assertEquals(2, $DB->count_records('role_assignments', array('roleid'=>$creatorrole->id)));
 
 
-        set_config('removeuser', AUTH_REMOVEUSER_SUSPEND, 'auth/ldap');
+        set_config('removeuser', AUTH_REMOVEUSER_SUSPEND, 'auth_ldap');
 
         /** @var auth_plugin_ldap $auth */
         $auth = get_auth_plugin('ldap');
@@ -246,7 +246,7 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
         $this->assertEquals(2, $DB->count_records('role_assignments'));
         $this->assertEquals(2, $DB->count_records('role_assignments', array('roleid'=>$creatorrole->id)));
 
-        set_config('removeuser', AUTH_REMOVEUSER_FULLDELETE, 'auth/ldap');
+        set_config('removeuser', AUTH_REMOVEUSER_FULLDELETE, 'auth_ldap');
 
         /** @var auth_plugin_ldap $auth */
         $auth = get_auth_plugin('ldap');
@@ -411,39 +411,39 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
         ldap_add($connection, 'ou='.$o['ou'].','.$topdn, $o);
 
         // Configure the plugin a bit.
-        set_config('host_url', TEST_AUTH_LDAP_HOST_URL, 'auth/ldap');
-        set_config('start_tls', 0, 'auth/ldap');
-        set_config('ldap_version', 3, 'auth/ldap');
-        set_config('ldapencoding', 'utf-8', 'auth/ldap');
-        set_config('pagesize', '2', 'auth/ldap');
-        set_config('bind_dn', TEST_AUTH_LDAP_BIND_DN, 'auth/ldap');
-        set_config('bind_pw', TEST_AUTH_LDAP_BIND_PW, 'auth/ldap');
-        set_config('user_type', 'rfc2307', 'auth/ldap');
-        set_config('contexts', 'ou=users,'.$topdn, 'auth/ldap');
-        set_config('search_sub', 0, 'auth/ldap');
-        set_config('opt_deref', LDAP_DEREF_NEVER, 'auth/ldap');
-        set_config('user_attribute', 'cn', 'auth/ldap');
-        set_config('memberattribute', 'memberuid', 'auth/ldap');
-        set_config('memberattribute_isdn', 0, 'auth/ldap');
-        set_config('creators', 'cn=creators,'.$topdn, 'auth/ldap');
-        set_config('removeuser', AUTH_REMOVEUSER_KEEP, 'auth/ldap');
-
-        set_config('field_map_email', 'mail', 'auth/ldap');
-        set_config('field_updatelocal_email', 'oncreate', 'auth/ldap');
-        set_config('field_updateremote_email', '0', 'auth/ldap');
-        set_config('field_lock_email', 'unlocked', 'auth/ldap');
-
-        set_config('field_map_firstname', 'givenName', 'auth/ldap');
-        set_config('field_updatelocal_firstname', 'oncreate', 'auth/ldap');
-        set_config('field_updateremote_firstname', '0', 'auth/ldap');
-        set_config('field_lock_firstname', 'unlocked', 'auth/ldap');
-
-        set_config('field_map_lastname', 'sn', 'auth/ldap');
-        set_config('field_updatelocal_lastname', 'oncreate', 'auth/ldap');
-        set_config('field_updateremote_lastname', '0', 'auth/ldap');
-        set_config('field_lock_lastname', 'unlocked', 'auth/ldap');
-        set_config('passtype', 'md5', 'auth/ldap');
-        set_config('create_context', 'ou=users,'.$topdn, 'auth/ldap');
+        set_config('host_url', TEST_AUTH_LDAP_HOST_URL, 'auth_ldap');
+        set_config('start_tls', 0, 'auth_ldap');
+        set_config('ldap_version', 3, 'auth_ldap');
+        set_config('ldapencoding', 'utf-8', 'auth_ldap');
+        set_config('pagesize', '2', 'auth_ldap');
+        set_config('bind_dn', TEST_AUTH_LDAP_BIND_DN, 'auth_ldap');
+        set_config('bind_pw', TEST_AUTH_LDAP_BIND_PW, 'auth_ldap');
+        set_config('user_type', 'rfc2307', 'auth_ldap');
+        set_config('contexts', 'ou=users,'.$topdn, 'auth_ldap');
+        set_config('search_sub', 0, 'auth_ldap');
+        set_config('opt_deref', LDAP_DEREF_NEVER, 'auth_ldap');
+        set_config('user_attribute', 'cn', 'auth_ldap');
+        set_config('memberattribute', 'memberuid', 'auth_ldap');
+        set_config('memberattribute_isdn', 0, 'auth_ldap');
+        set_config('creators', 'cn=creators,'.$topdn, 'auth_ldap');
+        set_config('removeuser', AUTH_REMOVEUSER_KEEP, 'auth_ldap');
+
+        set_config('field_map_email', 'mail', 'auth_ldap');
+        set_config('field_updatelocal_email', 'oncreate', 'auth_ldap');
+        set_config('field_updateremote_email', '0', 'auth_ldap');
+        set_config('field_lock_email', 'unlocked', 'auth_ldap');
+
+        set_config('field_map_firstname', 'givenName', 'auth_ldap');
+        set_config('field_updatelocal_firstname', 'oncreate', 'auth_ldap');
+        set_config('field_updateremote_firstname', '0', 'auth_ldap');
+        set_config('field_lock_firstname', 'unlocked', 'auth_ldap');
+
+        set_config('field_map_lastname', 'sn', 'auth_ldap');
+        set_config('field_updatelocal_lastname', 'oncreate', 'auth_ldap');
+        set_config('field_updateremote_lastname', '0', 'auth_ldap');
+        set_config('field_lock_lastname', 'unlocked', 'auth_ldap');
+        set_config('passtype', 'md5', 'auth_ldap');
+        set_config('create_context', 'ou=users,'.$topdn, 'auth_ldap');
 
         $this->assertEquals(2, $DB->count_records('user'));
         $this->assertEquals(0, $DB->count_records('role_assignments'));
index 8ac9073..d5cb801 100644 (file)
@@ -1,4 +1,10 @@
 This files describes API changes in the auth_ldap code.
+
+=== 3.3 ===
+
+* The config.html file was migrated to use the admin settings API.
+  The identifier for configuration data stored in config_plugins table was converted from 'auth/ldap' to 'auth_ldap'.
+
 === 2.9.1 ===
 * auth_plugin_ldap::update_user_record() accepts an additional (optional) param
   to trigger update event.
index b3eaaad..8afa03a 100644 (file)
@@ -25,6 +25,6 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version   = 2016120500;        // The current plugin version (Date: YYYYMMDDXX)
+$plugin->version   = 2017020700;        // The current plugin version (Date: YYYYMMDDXX)
 $plugin->requires  = 2016112900;        // Requires this Moodle version
 $plugin->component = 'auth_ldap';       // Full name of the plugin (used for diagnostics)
index c6df146..21a34d7 100644 (file)
@@ -157,21 +157,6 @@ class auth_plugin_manual extends auth_plugin_base {
         return true;
     }
 
-    /**
-     * Prints a form for configuring this authentication plugin.
-     *
-     * This function is called from admin/auth.php, and outputs a full page with
-     * a form for configuring this plugin.
-     *
-     * @param array $config An object containing all the data for this page.
-     * @param string $error
-     * @param array $user_fields
-     * @return void
-     */
-    function config_form($config, $err, $user_fields) {
-        include 'config.html';
-    }
-
     /**
      * Return number of days to user password expires.
      *
@@ -200,31 +185,6 @@ class auth_plugin_manual extends auth_plugin_base {
         return $result;
     }
 
-    /**
-     * Processes and stores configuration data for this authentication plugin.
-     *
-     * @param stdClass $config
-     * @return void
-     */
-    function process_config($config) {
-        // Set to defaults if undefined.
-        if (!isset($config->expiration)) {
-            $config->expiration = '';
-        }
-        if (!isset($config->expiration_warning)) {
-            $config->expiration_warning = '';
-        }
-        if (!isset($config->expirationtime)) {
-            $config->expirationtime = '';
-        }
-
-        // Save settings.
-        set_config('expiration', $config->expiration, self::COMPONENT_NAME);
-        set_config('expiration_warning', $config->expiration_warning, self::COMPONENT_NAME);
-        set_config('expirationtime', $config->expirationtime, self::COMPONENT_NAME);
-        return true;
-    }
-
    /**
     * Confirm the new user as registered. This should normally not be used,
     * but it may be necessary if the user auth_method is changed to manual
diff --git a/auth/manual/config.html b/auth/manual/config.html
deleted file mode 100644 (file)
index f622ab1..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-<?php
-    // Set to defaults if undefined.
-    if (!isset($config->expiration)) {
-        $config->expiration = '';
-    }
-    if (!isset($config->expiration_warning)) {
-        $config->expiration_warning = '';
-    }
-    if (!isset($config->expirationtime)) {
-        $config->expirationtime = '';
-    }
-    $expirationoptions = array(
-        new lang_string('no'),
-        new lang_string('yes'),
-    );
-    $expirationtimeoptions = array(
-        '30' => new lang_string('numdays', '', 30),
-        '60' => new lang_string('numdays', '', 60),
-        '90' => new lang_string('numdays', '', 90),
-        '120' => new lang_string('numdays', '', 120),
-        '150' => new lang_string('numdays', '', 150),
-        '180' => new lang_string('numdays', '', 180),
-        '365' => new lang_string('numdays', '', 365),
-    );
-    $expirationwarningoptions = array(
-        '0' => new lang_string('never'),
-        '1' => new lang_string('numdays', '', 1),
-        '2' => new lang_string('numdays', '', 2),
-        '3' => new lang_string('numdays', '', 3),
-        '4' => new lang_string('numdays', '', 4),
-        '5' => new lang_string('numdays', '', 5),
-        '6' => new lang_string('numdays', '', 6),
-        '7' => new lang_string('numdays', '', 7),
-        '10' => new lang_string('numdays', '', 10),
-        '14' => new lang_string('numdays', '', 14),
-    );
-?>
-<table cellspacing="0" cellpadding="5" border="0">
-    <tr>
-        <td colspan="3">
-            <h3><?php print_string('passwdexpire_settings', 'auth_manual') ?></h3>
-        </td>
-    </tr>
-    <tr>
-        <td align="right">
-            <label for="menuexpiration">
-                <?php print_string('expiration', 'auth_manual') ?>
-            </label>
-        </td>
-        <td>
-            <?php echo html_writer::select($expirationoptions, 'expiration', $config->expiration, false) ?>
-        </td>
-        <td><?php print_string('expiration_desc', 'auth_manual') ?></td>
-    </tr>
-    <tr>
-        <td align="right">
-            <label for="menuexpirationtime">
-                <?php print_string('passwdexpiretime', 'auth_manual') ?>
-            </label>
-        </td>
-        <td>
-            <?php echo html_writer::select($expirationtimeoptions, 'expirationtime', $config->expirationtime, false) ?>
-        </td>
-        <td><?php print_string('passwdexpiretime_desc', 'auth_manual') ?></td>
-    </tr>
-    <tr>
-        <td align="right">
-            <label for="menuexpiration_warning">
-                <?php print_string('expiration_warning', 'auth_manual') ?>
-            </label>
-        </td>
-        <td>
-            <?php echo html_writer::select($expirationwarningoptions, 'expiration_warning', $config->expiration_warning, false) ?>
-        </td>
-        <td><?php print_string('expiration_warning_desc', 'auth_manual') ?></td>
-    </tr>
-    <?php print_auth_lock_options($this->authtype, $user_fields, get_string('auth_fieldlocks_help', 'auth'), false, false) ?>
-</table>
index f56e337..d9c6e3c 100644 (file)
 defined('MOODLE_INTERNAL') || die();
 
 /**
+ * Function to upgrade auth_manual.
  * @param int $oldversion the version we are upgrading from
  * @return bool result
  */
 function xmldb_auth_manual_upgrade($oldversion) {
-    global $CFG;
+    global $CFG, $DB;
 
     // Moodle v2.8.0 release upgrade line.
     // Put any upgrade step following this.
@@ -46,5 +47,11 @@ function xmldb_auth_manual_upgrade($oldversion) {
     // Automatically generated Moodle v3.2.0 release upgrade line.
     // Put any upgrade step following this.
 
+    if ($oldversion < 2017020700) {
+        // Convert info in config plugins from auth/manual to auth_manual.
+        $DB->set_field('config_plugins', 'plugin', 'auth_manual', array('plugin' => 'auth/manual'));
+        upgrade_plugin_savepoint(true, 2017020700, 'auth', 'manual');
+    }
+
     return true;
 }
diff --git a/auth/manual/settings.php b/auth/manual/settings.php
new file mode 100644 (file)
index 0000000..cb546e0
--- /dev/null
@@ -0,0 +1,78 @@
+<?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/>.
+
+/**
+ * Admin settings and defaults
+ *
+ * @package auth_manual
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+if ($ADMIN->fulltree) {
+
+    // Introductory explanation.
+    $settings->add(new admin_setting_heading('auth_manual/pluginname',
+            new lang_string('passwdexpire_settings', 'auth_manual'),
+            new lang_string('auth_manualdescription', 'auth_manual')));
+
+    $expirationoptions = array(
+        new lang_string('no'),
+        new lang_string('yes'),
+    );
+
+    $settings->add(new admin_setting_configselect('auth_manual/expiration',
+        new lang_string('expiration', 'auth_manual'),
+        new lang_string('expiration_desc', 'auth_manual'), 0, $expirationoptions));
+
+    $expirationtimeoptions = array(
+        '30' => new lang_string('numdays', '', 30),
+        '60' => new lang_string('numdays', '', 60),
+        '90' => new lang_string('numdays', '', 90),
+        '120' => new lang_string('numdays', '', 120),
+        '150' => new lang_string('numdays', '', 150),
+        '180' => new lang_string('numdays', '', 180),
+        '365' => new lang_string('numdays', '', 365),
+    );
+
+    $settings->add(new admin_setting_configselect('auth_manual/expirationtime',
+        new lang_string('passwdexpiretime', 'auth_manual'),
+        new lang_string('passwdexpiretime_desc', 'auth_manual'), 30, $expirationtimeoptions));
+
+    $expirationwarningoptions = array(
+        '0' => new lang_string('never'),
+        '1' => new lang_string('numdays', '', 1),
+        '2' => new lang_string('numdays', '', 2),
+        '3' => new lang_string('numdays', '', 3),
+        '4' => new lang_string('numdays', '', 4),
+        '5' => new lang_string('numdays', '', 5),
+        '6' => new lang_string('numdays', '', 6),
+        '7' => new lang_string('numdays', '', 7),
+        '10' => new lang_string('numdays', '', 10),
+        '14' => new lang_string('numdays', '', 14),
+    );
+
+    $settings->add(new admin_setting_configselect('auth_manual/expiration_warning',
+        new lang_string('expiration_warning', 'auth_manual'),
+        new lang_string('expiration_warning_desc', 'auth_manual'), 0, $expirationwarningoptions));
+
+    // Display locking / mapping of profile fields.
+    $authplugin = get_auth_plugin($this->name);
+    display_auth_lock_options($settings, $authplugin->authtype,
+        $authplugin->userfields, get_string('auth_fieldlocks_help', 'auth'), false, false);
+}
index 087721a..156a997 100644 (file)
@@ -41,20 +41,15 @@ class auth_manual_testcase extends advanced_testcase {
     /** @var auth_plugin_manual Keeps the authentication plugin. */
     protected $authplugin;
 
-    /** @var stdClass Keeps authentication plugin config */
-    protected $config;
-
     /**
      * Setup test data.
      */
     protected function setUp() {
         $this->resetAfterTest(true);
         $this->authplugin = new auth_plugin_manual();
-        $this->config = new stdClass();
-        $this->config->expiration = '1';
-        $this->config->expiration_warning = '2';
-        $this->config->expirationtime = '30';
-        $this->authplugin->process_config($this->config);
+        set_config('expiration', '1', 'auth_manual');
+        set_config('expiration_warning', '2', 'auth_manual');
+        set_config('expirationtime', '30', 'auth_manual');
         $this->authplugin->config = get_config(auth_plugin_manual::COMPONENT_NAME);
     }
 
@@ -95,14 +90,4 @@ class auth_manual_testcase extends advanced_testcase {
         $this->assertEquals(30, $this->authplugin->password_expire($user1->username));
     }
 
-    /**
-     * Test test_process_config method.
-     */
-    public function test_process_config() {
-        $this->assertTrue($this->authplugin->process_config($this->config));
-        $config = get_config(auth_plugin_manual::COMPONENT_NAME);
-        $this->assertEquals($this->config->expiration, $config->expiration);
-        $this->assertEquals($this->config->expiration_warning, $config->expiration_warning);
-        $this->assertEquals($this->config->expirationtime, $config->expirationtime);
-    }
 }
diff --git a/auth/manual/upgrade.txt b/auth/manual/upgrade.txt
new file mode 100644 (file)
index 0000000..da135f8
--- /dev/null
@@ -0,0 +1,7 @@
+This files describes API changes in /auth/manual/*,
+information provided here is intended especially for developers.
+
+=== 3.3 ===
+
+* The config.html file was migrated to use the admin settings API.
+  The identifier for configuration data stored in config_plugins table was converted from 'auth/manual' to 'auth_manual'.
index bc0a7a7..794366f 100644 (file)
@@ -24,6 +24,6 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version   = 2016120500;        // The current plugin version (Date: YYYYMMDDXX)
+$plugin->version   = 2017020700;        // The current plugin version (Date: YYYYMMDDXX)
 $plugin->requires  = 2016112900;        // Requires this Moodle version
 $plugin->component = 'auth_manual';     // Full name of the plugin (used for diagnostics)
index 6f1cf0f..b318772 100644 (file)
@@ -616,98 +616,6 @@ class auth_plugin_mnet extends auth_plugin_base {
         return null;
     }
 
-    /**
-     * Prints a form for configuring this authentication plugin.
-     *
-     * This function is called from admin/auth.php, and outputs a full page with
-     * a form for configuring this plugin.
-     *
-     * @param object $config
-     * @param object $err
-     * @param array $user_fields
-     */
-    function config_form($config, $err, $user_fields) {
-        global $CFG, $DB;
-
-         $query = "
-            SELECT
-                h.id,
-                h.name as hostname,
-                h.wwwroot,
-                h2idp.publish as idppublish,
-                h2idp.subscribe as idpsubscribe,
-                idp.name as idpname,
-                h2sp.publish as sppublish,
-                h2sp.subscribe as spsubscribe,
-                sp.name as spname
-            FROM
-                {mnet_host} h
-            LEFT JOIN
-                {mnet_host2service} h2idp
-            ON
-               (h.id = h2idp.hostid AND
-               (h2idp.publish = 1 OR
-                h2idp.subscribe = 1))
-            INNER JOIN
-                {mnet_service} idp
-            ON
-               (h2idp.serviceid = idp.id AND
-                idp.name = 'sso_idp')
-            LEFT JOIN
-                {mnet_host2service} h2sp
-            ON
-               (h.id = h2sp.hostid AND
-               (h2sp.publish = 1 OR
-                h2sp.subscribe = 1))
-            INNER JOIN
-                {mnet_service} sp
-            ON
-               (h2sp.serviceid = sp.id AND
-                sp.name = 'sso_sp')
-            WHERE
-               ((h2idp.publish = 1 AND h2sp.subscribe = 1) OR
-               (h2sp.publish = 1 AND h2idp.subscribe = 1)) AND
-                h.id != ?
-            ORDER BY
-                h.name ASC";
-
-        $id_providers       = array();
-        $service_providers  = array();
-        if ($resultset = $DB->get_records_sql($query, array($CFG->mnet_localhost_id))) {
-            foreach($resultset as $hostservice) {
-                if(!empty($hostservice->idppublish) && !empty($hostservice->spsubscribe)) {
-                    $service_providers[]= array('id' => $hostservice->id, 'name' => $hostservice->hostname, 'wwwroot' => $hostservice->wwwroot);
-                }
-                if(!empty($hostservice->idpsubscribe) && !empty($hostservice->sppublish)) {
-                    $id_providers[]= array('id' => $hostservice->id, 'name' => $hostservice->hostname, 'wwwroot' => $hostservice->wwwroot);
-                }
-            }
-        }
-
-        include "config.html";
-    }
-
-    /**
-     * Processes and stores configuration data for this authentication plugin.
-     */
-    function process_config($config) {
-        // set to defaults if undefined
-        if (!isset ($config->rpc_negotiation_timeout)) {
-            $config->rpc_negotiation_timeout = '30';
-        }
-        /*
-        if (!isset ($config->auto_add_remote_users)) {
-            $config->auto_add_remote_users = '0';
-        } See MDL-21327   for why this is commented out
-        set_config('auto_add_remote_users',   $config->auto_add_remote_users,   'auth_mnet');
-        */
-
-        // save settings
-        set_config('rpc_negotiation_timeout', $config->rpc_negotiation_timeout, 'auth_mnet');
-
-        return true;
-    }
-
     /**
      * Poll the IdP server to let it know that a user it has authenticated is still
      * online
@@ -1203,4 +1111,120 @@ class auth_plugin_mnet extends auth_plugin_base {
         }
         return $idps;
     }
+
+    /**
+     * Test if settings are correct, print info to output.
+     */
+    public function test_settings() {
+        global $CFG, $OUTPUT, $DB;
+
+        // Generate warning if MNET is disabled.
+        if (empty($CFG->mnet_dispatcher_mode) || $CFG->mnet_dispatcher_mode !== 'strict') {
+                echo $OUTPUT->notification(get_string('mnetdisabled', 'mnet'), 'notifyproblem');
+                return;
+        }
+
+        // Generate full list of ID and service providers.
+        $query = "
+           SELECT
+               h.id,
+               h.name as hostname,
+               h.wwwroot,
+               h2idp.publish as idppublish,
+               h2idp.subscribe as idpsubscribe,
+               idp.name as idpname,
+               h2sp.publish as sppublish,
+               h2sp.subscribe as spsubscribe,
+               sp.name as spname
+           FROM
+               {mnet_host} h
+           LEFT JOIN
+               {mnet_host2service} h2idp
+           ON
+              (h.id = h2idp.hostid AND
+              (h2idp.publish = 1 OR
+               h2idp.subscribe = 1))
+           INNER JOIN
+               {mnet_service} idp
+           ON
+              (h2idp.serviceid = idp.id AND
+               idp.name = 'sso_idp')
+           LEFT JOIN
+               {mnet_host2service} h2sp
+           ON
+              (h.id = h2sp.hostid AND
+              (h2sp.publish = 1 OR
+               h2sp.subscribe = 1))
+           INNER JOIN
+               {mnet_service} sp
+           ON
+              (h2sp.serviceid = sp.id AND
+               sp.name = 'sso_sp')
+           WHERE
+              ((h2idp.publish = 1 AND h2sp.subscribe = 1) OR
+              (h2sp.publish = 1 AND h2idp.subscribe = 1)) AND
+               h.id != ?
+           ORDER BY
+               h.name ASC";
+
+        $idproviders = array();
+        $serviceproviders = array();
+        if ($resultset = $DB->get_records_sql($query, array($CFG->mnet_localhost_id))) {
+            foreach ($resultset as $hostservice) {
+                if (!empty($hostservice->idppublish) && !empty($hostservice->spsubscribe)) {
+                    $serviceproviders[] = array('id' => $hostservice->id,
+                        'name' => $hostservice->hostname,
+                        'wwwroot' => $hostservice->wwwroot);
+                }
+                if (!empty($hostservice->idpsubscribe) && !empty($hostservice->sppublish)) {
+                    $idproviders[] = array('id' => $hostservice->id,
+                        'name' => $hostservice->hostname,
+                        'wwwroot' => $hostservice->wwwroot);
+                }
+            }
+        }
+
+        // ID Providers.
+        $table = html_writer::start_tag('table', array('class' => 'generaltable'));
+
+        $count = 0;
+        foreach ($idproviders as $host) {
+            $table .= html_writer::start_tag('tr');
+            $table .= html_writer::start_tag('td');
+            $table .= $host['name'];
+            $table .= html_writer::end_tag('td');
+            $table .= html_writer::start_tag('td');
+            $table .= $host['wwwroot'];
+            $table .= html_writer::end_tag('td');
+            $table .= html_writer::end_tag('tr');
+            $count++;
+        }
+            $table .= html_writer::end_tag('table');
+
+        if ($count > 0) {
+            echo html_writer::tag('h3', get_string('auth_mnet_roamin', 'auth_mnet'));
+            echo $table;
+        }
+
+        // Service Providers.
+        unset($table);
+        $table = html_writer::start_tag('table', array('class' => 'generaltable'));
+        $count = 0;
+        foreach ($serviceproviders as $host) {
+            $table .= html_writer::start_tag('tr');
+            $table .= html_writer::start_tag('td');
+            $table .= $host['name'];
+            $table .= html_writer::end_tag('td');
+            $table .= html_writer::start_tag('td');
+            $table .= $host['wwwroot'];
+            $table .= html_writer::end_tag('td');
+            $table .= html_writer::end_tag('tr');
+            $count++;
+        }
+            $table .= html_writer::end_tag('table');
+        if ($count > 0) {
+            echo html_writer::tag('h3', get_string('auth_mnet_roamout', 'auth_mnet'));
+            echo $table;
+        }
+    }
 }
diff --git a/auth/mnet/config.html b/auth/mnet/config.html
deleted file mode 100644 (file)
index c25b314..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-<?php
-global $OUTPUT;
-// set to defaults if undefined
-if (!isset($config->rpc_negotiation_timeout)) {
-    $config->rpc_negotiation_timeout = '30';
-}
-/*
- See MDL-21327   for why this is commented out
-if (!isset ($config->auto_add_remote_users)) {
-    $config->auto_add_remote_users = '0';
-}
-*/
-
-$yesno = array(get_string('no'), get_string('yes'));
-
-if (empty($CFG->mnet_dispatcher_mode) || $CFG->mnet_dispatcher_mode !== 'strict') {
-    echo $OUTPUT->box(get_string('mnetdisabled','mnet'));
-}
-
-?>
-<div id="mnetconfig">
-<table cellspacing="0" cellpadding="5">
-
-<tr valign="top" class="required">
-    <td align="right"><label for="rpc_negotiation_timeout"><?php print_string('rpc_negotiation_timeout', 'auth_mnet'); ?>: </label></td>
-    <td>
-        <input name="rpc_negotiation_timeout" id="rpc_negotiation_timeout" type="text" size="5" value="<?php echo $config->rpc_negotiation_timeout ?>" />
-        <?php
-
-        if (isset($err['rpc_negotiation_timeout'])) {
-            echo $OUTPUT->error_text($err['rpc_negotiation_timeout']);
-        }
-
-        ?>
-    </td>
-    <td>
-        <?php
-
-        print_string('auth_mnet_rpc_negotiation_timeout', 'auth_mnet');
-
-        ?>
-    </td>
-</tr>
-
-<?php /*
- See MDL-21327   for why this is commented out
-<tr valign="top" class="required">
-    <td align="right"><?php echo html_writer::label(get_string('auto_add_remote_users', 'auth_mnet'), 'menuauto_add_remote_users'); ?>: </td>
-    <td>
-        <?php
-
-        echo html_writer::select($yesno, 'auto_add_remote_users', $config->auto_add_remote_users, false);
-
-        ?>
-    </td>
-    <td>
-        <?php
-
-        print_string('auth_mnet_auto_add_remote_users', 'auth_mnet');
-
-        ?>
-    </td>
-</tr>
-*/ ?>
-<tr valign="top" class="required">
-    <td colspan="3"><?php print_string('auth_mnet_roamin', 'auth_mnet'); ?>: </td>
-</tr>
-<?php
-foreach($id_providers as $host) {
-?>
-<tr valign="top" class="required">
-    <td align="right"><?php echo $host['name']; ?>: </td>
-    <td colspan="2"><?php echo $host['wwwroot']; ?> </td>
-</tr>
-<?php
-}
-?>
-<tr valign="top" class="required">
-    <td colspan="3"><?php print_string('auth_mnet_roamout', 'auth_mnet'); ?>: </td>
-</tr>
-<?php
-foreach($service_providers as $host) {
-?>
-<tr valign="top" class="required">
-    <td align="right"><?php echo $host['name']; ?>: </td>
-    <td colspan="2"><?php echo $host['wwwroot']; ?> </td>
-</tr>
-<?php
-}
-
-// print_auth_lock_options($this->authtype, $user_fields, get_string('auth_fieldlocks_help', 'auth'), false, false);
-
-?>
-</table>
-</div>
index 3d93aa2..5cccdeb 100644 (file)
 defined('MOODLE_INTERNAL') || die();
 
 /**
+ * Function to upgrade auth_mnet.
  * @param int $oldversion the version we are upgrading from
  * @return bool result
  */
 function xmldb_auth_mnet_upgrade($oldversion) {
-    global $CFG;
+    global $CFG, $DB;
 
     // Moodle v2.8.0 release upgrade line.
     // Put any upgrade step following this.
@@ -45,6 +46,11 @@ function xmldb_auth_mnet_upgrade($oldversion) {
 
     // Automatically generated Moodle v3.2.0 release upgrade line.
     // Put any upgrade step following this.
+    if ($oldversion < 2017020700) {
+        // Convert info in config plugins from auth/mnet to auth_mnet.
+        $DB->set_field('config_plugins', 'plugin', 'auth_mnet', array('plugin' => 'auth/mnet'));
+        upgrade_plugin_savepoint(true, 2017020700, 'auth', 'mnet');
+    }
 
     return true;
 }
diff --git a/auth/mnet/settings.php b/auth/mnet/settings.php
new file mode 100644 (file)
index 0000000..b7aa4a4
--- /dev/null
@@ -0,0 +1,39 @@
+<?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/>.
+
+/**
+ * Admin settings and defaults.
+ *
+ * @package    auth_mnet
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+if ($ADMIN->fulltree) {
+    require_once($CFG->dirroot.'/lib/outputlib.php');
+
+    // Introductory explanation.
+    $settings->add(new admin_setting_heading('auth_mnet/pluginname', '',
+            new lang_string('auth_mnetdescription', 'auth_mnet')));
+
+    // RPC Timeout.
+    $settings->add(new admin_setting_configtext('auth_mnet/rpc_negotiation_timeout',
+            get_string('rpc_negotiation_timeout', 'auth_mnet'),
+            get_string('auth_mnet_rpc_negotiation_timeout', 'auth_mnet'), '30', PARAM_INT));
+
+}