Commit abc25c01 authored by Andrew Nicols's avatar Andrew Nicols
Browse files

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

parent 36eaa963
......@@ -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
......
<?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: 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;
}
}
}
<?php
function xmldb_auth_imap_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/>.
/**
* 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;
}
<?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_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';
<?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('imap');
display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
get_string('auth_fieldlocks_help', 'auth'), false, false);
}
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'.
<?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 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)
......@@ -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'
),
......
......@@ -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),
......
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