From 36eaa963327c07ba772f1a39de9e9e4bc695dedc Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 13 Jul 2017 15:20:20 +0800 Subject: [PATCH] MDL-50925 auth_pop3: Remove from core and into plugins DB --- auth/README.txt | 9 -- auth/pop3/auth.php | 142 -------------------------------- auth/pop3/db/install.php | 6 -- auth/pop3/db/upgrade.php | 49 ----------- auth/pop3/lang/en/auth_pop3.php | 36 -------- auth/pop3/settings.php | 65 --------------- auth/pop3/upgrade.txt | 7 -- auth/pop3/version.php | 29 ------- lib/classes/plugin_manager.php | 4 +- lib/db/install.php | 1 - 10 files changed, 2 insertions(+), 346 deletions(-) delete mode 100644 auth/pop3/auth.php delete mode 100644 auth/pop3/db/install.php delete mode 100644 auth/pop3/db/upgrade.php delete mode 100644 auth/pop3/lang/en/auth_pop3.php delete mode 100644 auth/pop3/settings.php delete mode 100644 auth/pop3/upgrade.txt delete mode 100644 auth/pop3/version.php diff --git a/auth/README.txt b/auth/README.txt index 1cbe2eca270..272b9997d0c 100644 --- a/auth/README.txt +++ b/auth/README.txt @@ -69,15 +69,6 @@ imap - Uses an external IMAP server a new account is created -pop3 - Uses an external POP3 server - - - user logs in using username and password - - these are checked against a POP3 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/pop3/auth.php b/auth/pop3/auth.php deleted file mode 100644 index 9434944ccca..00000000000 --- a/auth/pop3/auth.php +++ /dev/null @@ -1,142 +0,0 @@ -. - -/** - * Authentication Plugin: POP3 Authentication - * Authenticates against a POP3 server. - * - * @package auth_pop3 - * @author Martin Dougiamas - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - */ - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->libdir.'/authlib.php'); - -/** - * POP3 authentication plugin. - */ -class auth_plugin_pop3 extends auth_plugin_base { - - /** - * Constructor. - */ - public function __construct() { - $this->authtype = 'pop3'; - $this->config = get_config('auth_pop3'); - } - - /** - * Old syntax of class constructor. Deprecated in PHP7. - * - * @deprecated since Moodle 3.1 - */ - public function auth_plugin_pop3() { - 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 - * @param string $password The password - * @return bool Authentication success or failure. - */ - function user_login($username, $password) { - if (! function_exists('imap_open')) { - print_error('auth_pop3notinstalled','auth_pop3'); - exit; - } - - global $CFG; - $hosts = explode(';', $this->config->host); // Could be multiple hosts - foreach ($hosts as $host) { // Try each host in turn - $host = trim($host); - - // remove any trailing slash - if (substr($host, -1) == '/') { - $host = substr($host, 0, strlen($host) - 1); - } - - switch ($this->config->type) { - case 'pop3': - $host = '{'.$host.":{$this->config->port}/pop3}{$this->config->mailbox}"; - break; - - case 'pop3notls': - $host = '{'.$host.":{$this->config->port}/pop3/notls}{$this->config->mailbox}"; - break; - - case 'pop3cert': - $host = '{'.$host.":{$this->config->port}/pop3/ssl/novalidate-cert}{$this->config->mailbox}"; - break; - } - - error_reporting(0); - $connection = imap_open($host, $username, $password); - error_reporting($CFG->debug); - - if ($connection) { - imap_close($connection); - return true; - } - } - return false; // No matches found - } - - 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 false 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/pop3/db/install.php b/auth/pop3/db/install.php deleted file mode 100644 index 0bd3df65fbc..00000000000 --- a/auth/pop3/db/install.php +++ /dev/null @@ -1,6 +0,0 @@ -. - -/** - * POP authentication plugin upgrade code - * - * @package auth_pop3 - * @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_pop3. - * @param int $oldversion the version we are upgrading from - * @return bool result - */ -function xmldb_auth_pop3_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/pop3 to auth_pop3. - upgrade_fix_config_auth_plugin_names('pop3'); - upgrade_fix_config_auth_plugin_defaults('pop3'); - upgrade_plugin_savepoint(true, 2017020700, 'auth', 'pop3'); - } - - // Automatically generated Moodle v3.3.0 release upgrade line. - // Put any upgrade step following this. - - return true; -} diff --git a/auth/pop3/lang/en/auth_pop3.php b/auth/pop3/lang/en/auth_pop3.php deleted file mode 100644 index 4aa257a4489..00000000000 --- a/auth/pop3/lang/en/auth_pop3.php +++ /dev/null @@ -1,36 +0,0 @@ -. - -/** - * Strings for component 'auth_pop3', language 'en'. - * - * @package auth_pop3 - * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -$string['auth_pop3description'] = 'This method uses a POP3 server to check whether a given username and password is valid.'; -$string['auth_pop3host'] = 'The POP3 server address. Use the IP number, not DNS name.'; -$string['auth_pop3host_key'] = 'Host'; -$string['auth_pop3changepasswordurl_key'] = 'Password-change URL'; -$string['auth_pop3mailbox'] = 'Name of the mailbox to attempt a connection with. (usually INBOX)'; -$string['auth_pop3mailbox_key'] = 'Mailbox'; -$string['auth_pop3notinstalled'] = 'Cannot use POP3 authentication. The PHP IMAP module is not installed.'; -$string['auth_pop3port'] = 'Server port (110 is the most common, 995 is common for SSL)'; -$string['auth_pop3port_key'] = 'Port'; -$string['auth_pop3type'] = 'Server type. If your server uses certificate security, choose pop3cert.'; -$string['auth_pop3type_key'] = 'Type'; -$string['pluginname'] = 'POP3 server'; diff --git a/auth/pop3/settings.php b/auth/pop3/settings.php deleted file mode 100644 index fa9c6a90a80..00000000000 --- a/auth/pop3/settings.php +++ /dev/null @@ -1,65 +0,0 @@ -. - -/** - * Admin settings and defaults. - * - * @package auth_pop3 - * @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_pop3/pluginname', '', new lang_string('auth_pop3description', 'auth_pop3'))); - - // Host. - $settings->add(new admin_setting_configtext('auth_pop3/host', get_string('auth_pop3host_key', 'auth_pop3'), - get_string('auth_pop3host', 'auth_pop3') . ' ' .get_string('auth_multiplehosts', 'auth'), - '127.0.0.1', PARAM_RAW)); - - // Type. - $pop3options = array(); - $pop3types = array('pop3', 'pop3cert', 'pop3notls'); - foreach ($pop3types as $pop3type) { - $pop3options[$pop3type] = $pop3type; - } - - $settings->add(new admin_setting_configselect('auth_pop3/type', - new lang_string('auth_pop3type_key', 'auth_pop3'), - new lang_string('auth_pop3type', 'auth_pop3'), 'pop3', $pop3options)); - - // Port. - $settings->add(new admin_setting_configtext('auth_pop3/port', get_string('auth_pop3port_key', 'auth_pop3'), - get_string('auth_pop3port', 'auth_pop3'), '143', PARAM_INT)); - - // Mailbox. - $settings->add(new admin_setting_configtext('auth_pop3/mailbox', get_string('auth_pop3mailbox_key', 'auth_pop3'), - get_string('auth_pop3mailbox', 'auth_pop3'), 'INBOX', PARAM_ALPHANUMEXT)); - - // Password change URL. - $settings->add(new admin_setting_configtext('auth_pop3/changepasswordurl', - get_string('auth_pop3changepasswordurl_key', 'auth_pop3'), - get_string('changepasswordhelp', 'auth'), '', PARAM_URL)); - - // Display locking / mapping of profile fields. - $authplugin = get_auth_plugin('pop3'); - display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields, - get_string('auth_fieldlocks_help', 'auth'), false, false); -} diff --git a/auth/pop3/upgrade.txt b/auth/pop3/upgrade.txt deleted file mode 100644 index 4aee976049e..00000000000 --- a/auth/pop3/upgrade.txt +++ /dev/null @@ -1,7 +0,0 @@ -This files describes API changes in /auth/pop3/*, -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/pop3' to 'auth_pop3'. diff --git a/auth/pop3/version.php b/auth/pop3/version.php deleted file mode 100644 index a4b54ac623d..00000000000 --- a/auth/pop3/version.php +++ /dev/null @@ -1,29 +0,0 @@ -. - -/** - * Version information - * - * @package auth_pop3 - * @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_pop3'; // Full name of the plugin (used for diagnostics) diff --git a/lib/classes/plugin_manager.php b/lib/classes/plugin_manager.php index 5a255be33ea..0382bcf982a 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'), + 'auth' => array('radius', 'fc', 'nntp', 'pam', 'pop3'), 'block' => array('course_overview'), 'enrol' => array('authorize'), 'report' => array('search'), @@ -1702,7 +1702,7 @@ class core_plugin_manager { 'auth' => array( 'cas', 'db', 'email', 'imap', 'ldap', 'lti', 'manual', 'mnet', - 'nologin', 'none', 'oauth2', 'pop3', 'shibboleth', 'webservice' + 'nologin', 'none', 'oauth2', 'shibboleth', 'webservice' ), 'availability' => array( diff --git a/lib/db/install.php b/lib/db/install.php index 92c725210e6..32640f69238 100644 --- a/lib/db/install.php +++ b/lib/db/install.php @@ -118,7 +118,6 @@ function xmldb_main_install() { $defaults = array( 'rolesactive' => '0', // marks fully set up system 'auth' => 'email', - 'auth_pop3mailbox' => 'INBOX', 'enrol_plugins_enabled' => 'manual,guest,self,cohort', 'theme' => theme_config::DEFAULT_THEME, 'filter_multilang_converted' => 1,