Commit 36eaa963 authored by Andrew Nicols's avatar Andrew Nicols
Browse files

MDL-50925 auth_pop3: Remove from core and into plugins DB

parent f9d12a2d
......@@ -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
......
<?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/>.
/**
* 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;
}
}
}
<?php
function xmldb_auth_pop3_install() {
global $CFG, $DB;
}
<?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/>.
/**
* 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;
}
<?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 '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';
<?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_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);
}
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'.
<?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/>.
/**
* 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)
......@@ -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(
......
......@@ -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,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment