From abc25c01b8aa3efb650038ac892885e66c6b0e37 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 14 Jul 2017 08:11:45 +0800 Subject: [PATCH] MDL-50925 auth_imap: Remove from core and into plugins DB --- auth/README.txt | 9 -- auth/imap/auth.php | 146 -------------------------------- auth/imap/db/install.php | 6 -- auth/imap/db/upgrade.php | 49 ----------- auth/imap/lang/en/auth_imap.php | 34 -------- auth/imap/settings.php | 62 -------------- auth/imap/upgrade.txt | 7 -- auth/imap/version.php | 29 ------- lib/classes/plugin_manager.php | 4 +- user/externallib.php | 6 +- 10 files changed, 5 insertions(+), 347 deletions(-) delete mode 100644 auth/imap/auth.php delete mode 100644 auth/imap/db/install.php delete mode 100644 auth/imap/db/upgrade.php delete mode 100644 auth/imap/lang/en/auth_imap.php delete mode 100644 auth/imap/settings.php delete mode 100644 auth/imap/upgrade.txt delete mode 100644 auth/imap/version.php diff --git a/auth/README.txt b/auth/README.txt index 272b9997d0c..9805697c020 100644 --- a/auth/README.txt +++ b/auth/README.txt @@ -60,15 +60,6 @@ ldap - Uses an external LDAP server (see the ldap/README for more details on config etc...) -imap - Uses an external IMAP server - - - user logs in using username and password - - these are checked against an IMAP server - - if correct, user is logged in - - if the username doesn't already exist then - a new account is created - - db - Uses an external database to check username/password - user logs in using username and password diff --git a/auth/imap/auth.php b/auth/imap/auth.php deleted file mode 100644 index 6d6590c611c..00000000000 --- a/auth/imap/auth.php +++ /dev/null @@ -1,146 +0,0 @@ -. - -/** - * Authentication Plugin: IMAP Authentication - * Authenticates against an IMAP server. - * - * @package auth_imap - * @author Martin Dougiamas - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - */ - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->libdir.'/authlib.php'); - -/** - * IMAP authentication plugin. - */ -class auth_plugin_imap extends auth_plugin_base { - - /** - * Constructor. - */ - public function __construct() { - $this->authtype = 'imap'; - $this->config = get_config('auth_imap'); - } - - /** - * Old syntax of class constructor. Deprecated in PHP7. - * - * @deprecated since Moodle 3.1 - */ - public function auth_plugin_imap() { - debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER); - self::__construct(); - } - - /** - * Returns true if the username and password work and false if they are - * wrong or don't exist. - * - * @param string $username The username (with system magic quotes) - * @param string $password The password (with system magic quotes) - * @return bool Authentication success or failure. - */ - function user_login ($username, $password) { - if (! function_exists('imap_open')) { - print_error('auth_imapnotinstalled','mnet'); - return false; - } - - global $CFG; - $hosts = explode(';', $this->config->host); // Could be multiple hosts - - foreach ($hosts as $host) { // Try each host in turn - $host = trim($host); - - switch ($this->config->type) { - case 'imapssl': - $host = '{'.$host.":{$this->config->port}/imap/ssl}"; - break; - - case 'imapcert': - $host = '{'.$host.":{$this->config->port}/imap/ssl/novalidate-cert}"; - break; - - case 'imaptls': - $host = '{'.$host.":{$this->config->port}/imap/tls}"; - break; - - case 'imapnosslcert': - $host = '{'.$host.":{$this->config->port}/imap/novalidate-cert}"; - break; - - default: - $host = '{'.$host.":{$this->config->port}/imap}"; - } - - error_reporting(0); - $connection = imap_open($host, $username, $password, OP_HALFOPEN); - error_reporting($CFG->debug); - - if ($connection) { - imap_close($connection); - return true; - } - } - - return false; // No match - } - - function prevent_local_passwords() { - return true; - } - - /** - * Returns true if this authentication plugin is 'internal'. - * - * @return bool - */ - function is_internal() { - return false; - } - - /** - * Returns true if this authentication plugin can change the user's - * password. - * - * @return bool - */ - function can_change_password() { - return !empty($this->config->changepasswordurl); - } - - /** - * Returns the URL for changing the user's pw, or empty if the default can - * be used. - * - * @return moodle_url - */ - function change_password_url() { - if (!empty($this->config->changepasswordurl)) { - return new moodle_url($this->config->changepasswordurl); - } else { - return null; - } - } - -} - - diff --git a/auth/imap/db/install.php b/auth/imap/db/install.php deleted file mode 100644 index 37b3c09d9f8..00000000000 --- a/auth/imap/db/install.php +++ /dev/null @@ -1,6 +0,0 @@ -. - -/** - * 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. - upgrade_fix_config_auth_plugin_names('imap'); - upgrade_fix_config_auth_plugin_defaults('imap'); - upgrade_plugin_savepoint(true, 2017020700, 'auth', 'imap'); - } - - // Automatically generated Moodle v3.3.0 release upgrade line. - // Put any upgrade step following this. - - return true; -} diff --git a/auth/imap/lang/en/auth_imap.php b/auth/imap/lang/en/auth_imap.php deleted file mode 100644 index ccfe27b590c..00000000000 --- a/auth/imap/lang/en/auth_imap.php +++ /dev/null @@ -1,34 +0,0 @@ -. - -/** - * Strings for component 'auth_imap', language 'en'. - * - * @package auth_imap - * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -$string['auth_imapdescription'] = 'This method uses an IMAP server to check whether a given username and password is valid.'; -$string['auth_imaphost'] = 'The IMAP server address. Use the IP number, not DNS name.'; -$string['auth_imaphost_key'] = 'Host'; -$string['auth_imapchangepasswordurl_key'] = 'Password-change URL'; -$string['auth_imapnotinstalled'] = 'Cannot use IMAP authentication. The PHP IMAP module is not installed.'; -$string['auth_imapport'] = 'IMAP server port number. Usually this is 143 or 993.'; -$string['auth_imapport_key'] = 'Port'; -$string['auth_imaptype'] = 'The IMAP server type. IMAP servers can have different types of authentication and negotiation.'; -$string['auth_imaptype_key'] = 'Type'; -$string['pluginname'] = 'IMAP server'; diff --git a/auth/imap/settings.php b/auth/imap/settings.php deleted file mode 100644 index fe8e7a13df6..00000000000 --- a/auth/imap/settings.php +++ /dev/null @@ -1,62 +0,0 @@ -. - -/** - * 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('imap'); - 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 deleted file mode 100644 index c6e6a954994..00000000000 --- a/auth/imap/upgrade.txt +++ /dev/null @@ -1,7 +0,0 @@ -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'. diff --git a/auth/imap/version.php b/auth/imap/version.php deleted file mode 100644 index b38709a451e..00000000000 --- a/auth/imap/version.php +++ /dev/null @@ -1,29 +0,0 @@ -. - -/** - * Version details - * - * @package auth_imap - * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -$plugin->version = 2017051500; // The current plugin version (Date: YYYYMMDDXX) -$plugin->requires = 2017050500; // Requires this Moodle version -$plugin->component = 'auth_imap'; // Full name of the plugin (used for diagnostics) diff --git a/lib/classes/plugin_manager.php b/lib/classes/plugin_manager.php index 0382bcf982a..dc8a6c8513e 100644 --- a/lib/classes/plugin_manager.php +++ b/lib/classes/plugin_manager.php @@ -1646,7 +1646,7 @@ class core_plugin_manager { // Moodle 2.3 supports upgrades from 2.2.x only. $plugins = array( 'qformat' => array('blackboard', 'learnwise'), - 'auth' => array('radius', 'fc', 'nntp', 'pam', 'pop3'), + 'auth' => array('radius', 'fc', 'nntp', 'pam', 'pop3', 'imap'), 'block' => array('course_overview'), 'enrol' => array('authorize'), 'report' => array('search'), @@ -1701,7 +1701,7 @@ class core_plugin_manager { ), 'auth' => array( - 'cas', 'db', 'email', 'imap', 'ldap', 'lti', 'manual', 'mnet', + 'cas', 'db', 'email', 'ldap', 'lti', 'manual', 'mnet', 'nologin', 'none', 'oauth2', 'shibboleth', 'webservice' ), diff --git a/user/externallib.php b/user/externallib.php index 2eea9f32a06..40576ed05a3 100644 --- a/user/externallib.php +++ b/user/externallib.php @@ -64,7 +64,7 @@ class core_user_external extends external_api { 'email' => new external_value(core_user::get_property_type('email'), 'A valid and unique email address'), 'auth' => - new external_value(core_user::get_property_type('auth'), 'Auth plugins include manual, ldap, imap, etc', VALUE_DEFAULT, + new external_value(core_user::get_property_type('auth'), 'Auth plugins include manual, ldap, etc', VALUE_DEFAULT, 'manual', core_user::get_property_null('auth')), 'idnumber' => new external_value(core_user::get_property_type('idnumber'), 'An arbitrary ID code number perhaps from the institution', @@ -445,7 +445,7 @@ class core_user_external extends external_api { new external_value(core_user::get_property_type('email'), 'A valid and unique email address', VALUE_OPTIONAL, '', NULL_NOT_ALLOWED), 'auth' => - new external_value(core_user::get_property_type('auth'), 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL, '', + new external_value(core_user::get_property_type('auth'), 'Auth plugins include manual, ldap, etc', VALUE_OPTIONAL, '', NULL_NOT_ALLOWED), 'suspended' => new external_value(core_user::get_property_type('suspended'), 'Suspend user account, either false to enable user login or true to disable it', VALUE_OPTIONAL), @@ -1030,7 +1030,7 @@ class core_user_external extends external_api { 'interests' => new external_value(PARAM_TEXT, 'user interests (separated by commas)', VALUE_OPTIONAL), 'firstaccess' => new external_value(core_user::get_property_type('firstaccess'), 'first access to the site (0 if never)', VALUE_OPTIONAL), 'lastaccess' => new external_value(core_user::get_property_type('lastaccess'), 'last access to the site (0 if never)', VALUE_OPTIONAL), - 'auth' => new external_value(core_user::get_property_type('auth'), 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL), + 'auth' => new external_value(core_user::get_property_type('auth'), 'Auth plugins include manual, ldap, etc', VALUE_OPTIONAL), 'suspended' => new external_value(core_user::get_property_type('suspended'), 'Suspend user account, either false to enable user login or true to disable it', VALUE_OPTIONAL), 'confirmed' => new external_value(core_user::get_property_type('confirmed'), 'Active user: 1 if confirmed, 0 otherwise', VALUE_OPTIONAL), 'lang' => new external_value(core_user::get_property_type('lang'), 'Language code such as "en", must exist on server', VALUE_OPTIONAL),