From 032194970b0f172f0b393d3f8513fdb1cb236daa Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 13 Jul 2017 15:29:03 +0800 Subject: [PATCH 1/6] MDL-50925 auth_fc: Remove from core and into plugins DB --- .eslintignore | 1 - .stylelintignore | 1 - auth/fc/Readme.txt | 71 ----------- auth/fc/auth.php | 216 ------------------------------- auth/fc/db/install.php | 6 - auth/fc/db/upgrade.php | 49 ------- auth/fc/fcFPP.php | 226 --------------------------------- auth/fc/lang/en/auth_fc.php | 38 ------ auth/fc/settings.php | 61 --------- auth/fc/thirdpartylibs.xml | 10 -- auth/fc/upgrade.txt | 8 -- auth/fc/version.php | 29 ----- lib/classes/plugin_manager.php | 4 +- 13 files changed, 2 insertions(+), 718 deletions(-) delete mode 100644 auth/fc/Readme.txt delete mode 100644 auth/fc/auth.php delete mode 100644 auth/fc/db/install.php delete mode 100644 auth/fc/db/upgrade.php delete mode 100644 auth/fc/fcFPP.php delete mode 100644 auth/fc/lang/en/auth_fc.php delete mode 100644 auth/fc/settings.php delete mode 100644 auth/fc/thirdpartylibs.xml delete mode 100644 auth/fc/upgrade.txt delete mode 100644 auth/fc/version.php diff --git a/.eslintignore b/.eslintignore index e62d3294f43..1505c62d6a7 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,7 +6,6 @@ vendor/ admin/tool/usertours/amd/src/tour.js admin/tool/usertours/amd/src/popper.js auth/cas/CAS/ -auth/fc/fcFPP.php enrol/lti/ims-blti/ filter/algebra/AlgParser.pm filter/tex/mimetex.* diff --git a/.stylelintignore b/.stylelintignore index 8c3d147c6c0..73c69be6b16 100644 --- a/.stylelintignore +++ b/.stylelintignore @@ -7,7 +7,6 @@ vendor/ admin/tool/usertours/amd/src/tour.js admin/tool/usertours/amd/src/popper.js auth/cas/CAS/ -auth/fc/fcFPP.php enrol/lti/ims-blti/ filter/algebra/AlgParser.pm filter/tex/mimetex.* diff --git a/auth/fc/Readme.txt b/auth/fc/Readme.txt deleted file mode 100644 index c40e7ffe976..00000000000 --- a/auth/fc/Readme.txt +++ /dev/null @@ -1,71 +0,0 @@ -Moodle - FirstClass authentication module ------------------------------------------ -This module uses the FirstClass Flexible Provisining Protocol (FPP) to communicate between the FirstClass server -and the Moodle host. - -Installation ------------- - -1. Enable FPP on the FirstClass server -FPP is not doumented in the FirstClass documentation and is not enable by default. -To enable the protocol you need to edit the file \FCPO\Server\Netinfo. Open the file and insert the -following lines. - -// TCP port for Flexible Provisioning Protocol (FPP). -TCPFPPPORT = 3333 - - -2. Create an account on the FirstClass server with privilege "Subadministrator". -Using the FPP protocoll this module logs in to the FirstClass server and issuess batch admin commands. -Batch admin command can only be issued in the context of a user with subadministrative privileges. - -Default account name is "fcMoodle". - - -3. Check that the FPP protocoll is working by running a Telnet session. If everyting is working you -should get a "+0" answer from the server. - -> telnet yourhost.domain.com 3333 -+0 - -Check that the "fcMoodle" is working by entering the following sequens of commands: - -> telnet yourhost.domain.com 3333 -+0 -fcMoodle -+0 - -the_password_you_gave_fcmoodle -+0 - -Get user some_user_id 1201 - -1201 0 some_user_id -+0 - - - -4. On the Moodle host go to the directory where you have installed Moodle. -Open the folder "auth", where all other authentication modules are installed, - and create a new directory with the name "fc". - -Copy the files "config.html", "fcFPP.php" and "lib.php" to the "auth" directory. - -Now you need to add som strings to the language file. This distribution contains -string for the English (en) and Swedish (sv) translation. - -Open the file "auth.php" in the folder "lang/sv" and paste the text from the file -"auth.php - sv.txt" at the end of the file above the line "?>" - -Open the file "auth.php" in the folder "lang/en" and paste the text from the file -"auth.php - en.txt" at the end of the file above the line "?>" - - - - - - - - - - diff --git a/auth/fc/auth.php b/auth/fc/auth.php deleted file mode 100644 index 31b1b20b37a..00000000000 --- a/auth/fc/auth.php +++ /dev/null @@ -1,216 +0,0 @@ -. - -/** - * Authentication Plugin: FirstClass Authentication - * Authentication using a FirstClass server. - - * @package auth_fc - * @author Martin Dougiamas - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - */ - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->libdir.'/authlib.php'); - -require_once 'fcFPP.php'; - -/** - * FirstClass authentication plugin. - */ -class auth_plugin_fc extends auth_plugin_base { - - /** - * Constructor. - */ - public function __construct() { - $this->authtype = 'fc'; - $this->config = get_config('auth_fc'); - } - - /** - * Old syntax of class constructor. Deprecated in PHP7. - * - * @deprecated since Moodle 3.1 - */ - public function auth_plugin_fc() { - 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) { - global $CFG; - $retval = false; - - // Don't allow blank usernames or passwords - if (!$username or !$password) { - return $retval; - } - - $fpp = new fcFPP($this->config->host, $this->config->fppport); - if ($fpp->open()) { - if ($fpp->login($username, $password)) { - $retval = true; - } - } - $fpp->close(); - - return $retval; - } - - /** - * Get user information from FirstCLass server and return it in an array. - * Localize this routine to fit your needs. - */ - function get_userinfo($username) { - /* - Moodle FirstCLass fieldID in UserInfo form - ------ ----------------------------------- - firstname 1202 - lastname 1204 - email 1252 - icq - - phone1 1206 - phone2 1207 (Fax) - institution - - department - - address 1205 - city - - country - - lang - - timezone 8030 (Not used yet. Need to figure out how FC codes timezones) - - description Get data from users resume. Pictures will be removed. - - */ - - $userinfo = array(); - - $fpp = new fcFPP($this->config->host, $this->config->fppport); - if ($fpp->open()) { - if ($fpp->login($this->config->userid, $this->config->passwd)) { - $userinfo['firstname'] = $fpp->getUserInfo($username,"1202"); - $userinfo['lastname'] = $fpp->getUserInfo($username,"1204"); - $userinfo['email'] = strtok($fpp->getUserInfo($username,"1252"),','); - $userinfo['phone1'] = $fpp->getUserInfo($username,"1206"); - $userinfo['phone2'] = $fpp->getUserInfo($username,"1207"); - $userinfo['description'] = $fpp->getResume($username); - } - } - $fpp->close(); - - foreach($userinfo as $key => $value) { - if (!$value) { - unset($userinfo[$key]); - } - } - - return $userinfo; - } - - /** - * Get users group membership from the FirstClass server user and check if - * user is member of one of the groups of creators. - */ - function iscreator($username) { - if (! $this->config->creators) { - return null; - } - - $fcgroups = array(); - - $fpp = new fcFPP($this->config->host, $this->config->fppport); - if ($fpp->open()) { - if ($fpp->login($this->config->userid, $this->config->passwd)) { - $fcgroups = $fpp->getGroups($username); - } - } - $fpp->close(); - - if ((! $fcgroups)) { - return false; - } - - $creators = explode(";", $this->config->creators); - - foreach($creators as $creator) { - if (in_array($creator, $fcgroups)) { - return true; - } - } - - return false; - } - - 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 false; - } - - /** - * Sync roles for this user - * - * @param $user object user object (without system magic quotes) - */ - function sync_roles($user) { - $iscreator = $this->iscreator($user->username); - if ($iscreator === null) { - return; //nothing to sync - creators not configured - } - - if ($roles = get_archetype_roles('coursecreator')) { - $creatorrole = array_shift($roles); // We can only use one, let's use the first one - $systemcontext = context_system::instance(); - - if ($iscreator) { // Following calls will not create duplicates - role_assign($creatorrole->id, $user->id, $systemcontext->id, 'auth_fc'); - } else { - //unassign only if previously assigned by this plugin! - role_unassign($creatorrole->id, $user->id, $systemcontext->id, 'auth_fc'); - } - } - } - -} - - diff --git a/auth/fc/db/install.php b/auth/fc/db/install.php deleted file mode 100644 index 543f4f0140d..00000000000 --- a/auth/fc/db/install.php +++ /dev/null @@ -1,6 +0,0 @@ -. - -/** - * 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. - upgrade_fix_config_auth_plugin_names('fc'); - upgrade_fix_config_auth_plugin_defaults('fc'); - upgrade_plugin_savepoint(true, 2017020700, 'auth', 'fc'); - } - - // Automatically generated Moodle v3.3.0 release upgrade line. - // Put any upgrade step following this. - - return true; -} diff --git a/auth/fc/fcFPP.php b/auth/fc/fcFPP.php deleted file mode 100644 index 2adc309c712..00000000000 --- a/auth/fc/fcFPP.php +++ /dev/null @@ -1,226 +0,0 @@ -_hostname = $host; - $this->_port = $port; - $this->_user = ""; - $this->_pwd = ""; - } - - function fcFPP($host="localhost", $port="3333") - { - debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER); - self::__construct($host, $port); - } - - // open a connection to the FirstClass server - function open() - { - if ($this->_debug) echo "Connecting to host "; - $host = $this->_hostname; - $port = $this->_port; - - if ($this->_debug) echo "[$host:$port].."; - - // open the connection to the FirstClass server - $conn = fsockopen($host, $port, $errno, $errstr, 5); - if (!$conn) - { - print_error('auth_fcconnfail','auth_fc', '', array('no'=>$errno, 'str'=>$errstr)); - return false; - } - - // We are connected - if ($this->_debug) echo "connected!"; - - // Read connection message. - $line = fgets ($conn); //+0 - $line = fgets ($conn); //new line - - // store the connection in this class, so we can use it later - $this->_conn = & $conn; - - return true; - } - - // close any open connections - function close() - { - // get the current connection - $conn = &$this->_conn; - - // close it if it's open - if ($conn) - { - fclose($conn); - - // cleanup the variable - unset($this->_conn); - return true; - } - return; - } - - - // Authenticate to the FirstClass server - function login($userid, $passwd) - { - // we did have a connection right?! - if ($this->_conn) - { - # Send username - fputs($this->_conn,"$userid\r\n"); - - $line = fgets ($this->_conn); //new line - $line = fgets ($this->_conn); //+0 - $line = fgets ($this->_conn); //new line - - # Send password - fputs($this->_conn,"$passwd\r\n"); - $line = fgets ($this->_conn); //new line - $line = fgets ($this->_conn); //+0 - $line = fgets ($this->_conn); //+0 or message - - if ($this->_debug) echo $line; - - if (preg_match ("/^\+0/", $line)) { //+0, user with subadmin privileges - $this->_user = $userid; - $this->_pwd = $passwd; - return TRUE; - } elseif (strpos($line, 'You are not allowed')) { // Denied access but a valid user and password - // "Sorry. You are not allowed to login with the FPP interface" - return TRUE; - } else { //Invalid user or password - return FALSE; - } - - - } - return FALSE; - } - - // Get the list of groups the user is a member of - function getGroups($userid) { - - $groups = array(); - - // we must be logged in as a user with subadmin privileges - if ($this->_conn AND $this->_user) { - # Send BA-command to get groups - fputs($this->_conn,"GET USER '" . $userid . "' 4 -1\r"); - $line = ""; - while (!$line) { - $line = trim(fgets ($this->_conn)); - } - $n = 0; - while ($line AND !preg_match("/^\+0/", $line) AND $line != "-1003") { - list( , , $groups[$n++]) = explode(" ",$line,3); - $line = trim(fgets ($this->_conn)); - } - if ($this->_debug) echo "getGroups:" . implode(",",$groups); - } - - return $groups; - } - - // Check if the user is member of any of the groups. - // Return the list of groups the user is member of. - function isMemberOf($userid, $groups) { - - $usergroups = array_map("strtolower",$this->getGroups($userid)); - $groups = array_map("strtolower",$groups); - - $result = array_intersect($groups,$usergroups); - - if ($this->_debug) echo "isMemberOf:" . implode(",",$result); - - return $result; - - } - - function getUserInfo($userid, $field) { - - $userinfo = ""; - - if ($this->_conn AND $this->_user) { - # Send BA-command to get data - fputs($this->_conn,"GET USER '" . $userid . "' " . $field . "\r"); - $line = ""; - while (!$line) { - $line = trim(fgets ($this->_conn)); - } - $n = 0; - while ($line AND !preg_match("/^\+0/", $line)) { - list( , , $userinfo) = explode(" ",$line,3); - $line = trim(fgets ($this->_conn)); - } - if ($this->_debug) echo "getUserInfo:" . $userinfo; - } - - return str_replace('\r',' ',trim($userinfo,'"')); - - } - - function getResume($userid) { - - $resume = ""; - - $pattern = "/\[.+:.+\..+\]/"; // Remove references to pictures in resumes - - if ($this->_conn AND $this->_user) { - # Send BA-command to get data - fputs($this->_conn,"GET RESUME '" . $userid . "' 6\r"); - $line = ""; - while (!$line) { - $line = trim(fgets ($this->_conn)); - } - $n = 0; - while ($line AND !preg_match("/^\+0/", $line)) { - $resume .= preg_replace($pattern,"",str_replace('\r',"\n",trim($line,'6 '))); - $line = trim(fgets ($this->_conn)); - //print $line; - - } - if ($this->_debug) echo "getResume:" . $resume; - } - - return $resume; - - } - - -} - - -?> diff --git a/auth/fc/lang/en/auth_fc.php b/auth/fc/lang/en/auth_fc.php deleted file mode 100644 index 46e75fcbbbc..00000000000 --- a/auth/fc/lang/en/auth_fc.php +++ /dev/null @@ -1,38 +0,0 @@ -. - -/** - * Strings for component 'auth_fc', language 'en'. - * - * @package auth_fc - * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -$string['auth_fcconnfail'] = 'Connection failed with Errno: {$a->no} and Error String: {$a->str}'; -$string['auth_fccreators'] = 'List of groups whose members are allowed to create new courses. Separate multiple groups with \';\'. Names must be spelled exactly as on FirstClass server. System is case-sensitive.'; -$string['auth_fccreators_key'] = 'Creators'; -$string['auth_fcdescription'] = 'This method uses a FirstClass server to check whether a given username and password is valid.'; -$string['auth_fcfppport'] = 'Server port (3333 is the most common)'; -$string['auth_fcfppport_key'] = 'Port'; -$string['auth_fcchangepasswordurl'] = 'Password-change URL'; -$string['auth_fcpasswd'] = 'Password for the account above.'; -$string['auth_fcpasswd_key'] = 'Password'; -$string['auth_fcuserid'] = 'Userid for FirstClass account with privilege \'Subadministrator\' set.'; -$string['auth_fcuserid_key'] = 'User ID'; -$string['auth_fchost'] = 'The FirstClass server address. Use the IP number or DNS name.'; -$string['auth_fchost_key'] = 'Host'; -$string['pluginname'] = 'FirstClass server'; diff --git a/auth/fc/settings.php b/auth/fc/settings.php deleted file mode 100644 index ff3aa3f2dac..00000000000 --- a/auth/fc/settings.php +++ /dev/null @@ -1,61 +0,0 @@ -. - -/** - * 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('fc'); - display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields, - get_string('auth_fieldlocks_help', 'auth'), false, false); -} diff --git a/auth/fc/thirdpartylibs.xml b/auth/fc/thirdpartylibs.xml deleted file mode 100644 index 191a2812937..00000000000 --- a/auth/fc/thirdpartylibs.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - fcFPP.php - fcFPP - GPL - - 2.0+ - - diff --git a/auth/fc/upgrade.txt b/auth/fc/upgrade.txt deleted file mode 100644 index 312f797d326..00000000000 --- a/auth/fc/upgrade.txt +++ /dev/null @@ -1,8 +0,0 @@ -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'. - diff --git a/auth/fc/version.php b/auth/fc/version.php deleted file mode 100644 index 386950af2c9..00000000000 --- a/auth/fc/version.php +++ /dev/null @@ -1,29 +0,0 @@ -. - -/** - * Version details - * - * @package auth_fc - * @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_fc'; // Full name of the plugin (used for diagnostics) diff --git a/lib/classes/plugin_manager.php b/lib/classes/plugin_manager.php index 5451edb2dee..817678ecc9d 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'), + 'auth' => array('radius', 'fc'), 'block' => array('course_overview'), 'enrol' => array('authorize'), 'report' => array('search'), @@ -1701,7 +1701,7 @@ class core_plugin_manager { ), 'auth' => array( - 'cas', 'db', 'email', 'fc', 'imap', 'ldap', 'lti', 'manual', 'mnet', + 'cas', 'db', 'email', 'imap', 'ldap', 'lti', 'manual', 'mnet', 'nntp', 'nologin', 'none', 'oauth2', 'pam', 'pop3', 'shibboleth', 'webservice' ), From db6ba965100f9d93f603ed7cd8c4326f71251d0a Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 13 Jul 2017 15:29:16 +0800 Subject: [PATCH 2/6] MDL-50925 auth_nntp: Remove from core and into plugins DB --- auth/README.txt | 9 --- auth/nntp/auth.php | 111 -------------------------------- auth/nntp/db/install.php | 6 -- auth/nntp/db/upgrade.php | 49 -------------- auth/nntp/lang/en/auth_nntp.php | 32 --------- auth/nntp/settings.php | 50 -------------- auth/nntp/upgrade.txt | 7 -- auth/nntp/version.php | 29 --------- lib/classes/plugin_manager.php | 4 +- 9 files changed, 2 insertions(+), 295 deletions(-) delete mode 100644 auth/nntp/auth.php delete mode 100644 auth/nntp/db/install.php delete mode 100644 auth/nntp/db/upgrade.php delete mode 100644 auth/nntp/lang/en/auth_nntp.php delete mode 100644 auth/nntp/settings.php delete mode 100644 auth/nntp/upgrade.txt delete mode 100644 auth/nntp/version.php diff --git a/auth/README.txt b/auth/README.txt index 48337b4e7f4..1cbe2eca270 100644 --- a/auth/README.txt +++ b/auth/README.txt @@ -78,15 +78,6 @@ pop3 - Uses an external POP3 server a new account is created -nntp - Uses an external NNTP server - - - user logs in using username and password - - these are checked against an NNTP 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/nntp/auth.php b/auth/nntp/auth.php deleted file mode 100644 index 2ee31dccf04..00000000000 --- a/auth/nntp/auth.php +++ /dev/null @@ -1,111 +0,0 @@ -. - -/** - * Authentication Plugin: NNTP Authentication - * Authenticates against an NNTP server. - * - * @package auth_nntp - * @author Martin Dougiamas - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - */ - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->libdir.'/authlib.php'); - -/** - * NNTP authentication plugin. - */ -class auth_plugin_nntp extends auth_plugin_base { - - /** - * Constructor. - */ - public function __construct() { - $this->authtype = 'nntp'; - $this->config = get_config('auth_nntp'); - } - - /** - * Old syntax of class constructor. Deprecated in PHP7. - * - * @deprecated since Moodle 3.1 - */ - public function auth_plugin_nntp() { - 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_nntpnotinstalled','auth_nntp'); - exit; - } - - global $CFG; - - // try each multiple host - $hosts = explode(';', $this->config->host); - foreach ($hosts as $host) { - $host = '{' . trim($host) . ':' . $this->config->port . '/nntp}'; - - error_reporting(0); - $connection = imap_open($host, $username, $password, OP_HALFOPEN); - error_reporting($CFG->debug); - - if ($connection) { - imap_close($connection); - return true; - } - } - return false; - } - - 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 false; - } - -} - - diff --git a/auth/nntp/db/install.php b/auth/nntp/db/install.php deleted file mode 100644 index 18d66b9a14a..00000000000 --- a/auth/nntp/db/install.php +++ /dev/null @@ -1,6 +0,0 @@ -. - -/** - * NNTP authentication plugin upgrade code - * - * @package auth_nntp - * @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_nntp. - * @param int $oldversion the version we are upgrading from - * @return bool result - */ -function xmldb_auth_nntp_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/nntp to auth_nntp. - upgrade_fix_config_auth_plugin_names('nntp'); - upgrade_fix_config_auth_plugin_defaults('nntp'); - upgrade_plugin_savepoint(true, 2017020700, 'auth', 'nntp'); - } - - // Automatically generated Moodle v3.3.0 release upgrade line. - // Put any upgrade step following this. - - return true; -} diff --git a/auth/nntp/lang/en/auth_nntp.php b/auth/nntp/lang/en/auth_nntp.php deleted file mode 100644 index fa10cacce66..00000000000 --- a/auth/nntp/lang/en/auth_nntp.php +++ /dev/null @@ -1,32 +0,0 @@ -. - -/** - * Strings for component 'auth_nntp', language 'en'. - * - * @package auth_nntp - * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -$string['auth_nntpdescription'] = 'This method uses an NNTP server to check whether a given username and password is valid.'; -$string['auth_nntphost'] = 'The NNTP server address. Use the IP number, not DNS name.'; -$string['auth_nntphost_key'] = 'Host'; -$string['auth_nntpchangepasswordurl_key'] = 'Password-change URL'; -$string['auth_nntpnotinstalled'] = 'Cannot use NNTP authentication. The PHP IMAP module is not installed.'; -$string['auth_nntpport'] = 'Server port (119 is the most common)'; -$string['auth_nntpport_key'] = 'Port'; -$string['pluginname'] = 'NNTP server'; diff --git a/auth/nntp/settings.php b/auth/nntp/settings.php deleted file mode 100644 index bf475ee2e95..00000000000 --- a/auth/nntp/settings.php +++ /dev/null @@ -1,50 +0,0 @@ -. - -/** - * Admin settings and defaults. - * - * @package auth_nntp - * @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_nntp/pluginname', '', new lang_string('auth_nntpdescription', 'auth_nntp'))); - - // Host. - $settings->add(new admin_setting_configtext('auth_nntp/host', get_string('auth_nntphost_key', 'auth_nntp'), - get_string('auth_nntphost', 'auth_nntp') . ' ' .get_string('auth_multiplehosts', 'auth'), - '127.0.0.1', PARAM_RAW)); - - // Port. - $settings->add(new admin_setting_configtext('auth_nntp/port', get_string('auth_nntpport_key', 'auth_nntp'), - get_string('auth_nntpport', 'auth_nntp'), '119', PARAM_INT)); - - // Password change URL. - $settings->add(new admin_setting_configtext('auth_nntp/changepasswordurl', - get_string('auth_nntpchangepasswordurl_key', 'auth_nntp'), - get_string('changepasswordhelp', 'auth'), '', PARAM_URL)); - - // Display locking / mapping of profile fields. - $authplugin = get_auth_plugin('nntp'); - display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields, - get_string('auth_fieldlocks_help', 'auth'), false, false); -} diff --git a/auth/nntp/upgrade.txt b/auth/nntp/upgrade.txt deleted file mode 100644 index 18376afda15..00000000000 --- a/auth/nntp/upgrade.txt +++ /dev/null @@ -1,7 +0,0 @@ -This files describes API changes in /auth/nntp/*, -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/nntp' to 'auth_nntp'. diff --git a/auth/nntp/version.php b/auth/nntp/version.php deleted file mode 100644 index 4ee22dca4ad..00000000000 --- a/auth/nntp/version.php +++ /dev/null @@ -1,29 +0,0 @@ -. - -/** - * Version information - * - * @package auth_nntp - * @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_nntp'; // Full name of the plugin (used for diagnostics) diff --git a/lib/classes/plugin_manager.php b/lib/classes/plugin_manager.php index 817678ecc9d..89c9525855c 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'), + 'auth' => array('radius', 'fc', 'nntp'), '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', - 'nntp', 'nologin', 'none', 'oauth2', 'pam', 'pop3', 'shibboleth', 'webservice' + 'nologin', 'none', 'oauth2', 'pam', 'pop3', 'shibboleth', 'webservice' ), 'availability' => array( From f9d12a2d1e56a34f0f7dbe547ca0f7e0615fb291 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 13 Jul 2017 15:27:51 +0800 Subject: [PATCH 3/6] MDL-50925 auth_pam: Remove from core and into plugins DB --- auth/pam/auth.php | 123 --------------------------------- auth/pam/db/install.php | 6 -- auth/pam/db/upgrade.php | 49 ------------- auth/pam/lang/en/auth_pam.php | 28 -------- auth/pam/settings.php | 37 ---------- auth/pam/upgrade.txt | 7 -- auth/pam/version.php | 29 -------- lib/classes/plugin_manager.php | 4 +- 8 files changed, 2 insertions(+), 281 deletions(-) delete mode 100644 auth/pam/auth.php delete mode 100644 auth/pam/db/install.php delete mode 100644 auth/pam/db/upgrade.php delete mode 100644 auth/pam/lang/en/auth_pam.php delete mode 100644 auth/pam/settings.php delete mode 100644 auth/pam/upgrade.txt delete mode 100644 auth/pam/version.php diff --git a/auth/pam/auth.php b/auth/pam/auth.php deleted file mode 100644 index 35e0abf9df8..00000000000 --- a/auth/pam/auth.php +++ /dev/null @@ -1,123 +0,0 @@ -. - -/** - * Authentication Plugin: PAM Authentication - * - * PAM (Pluggable Authentication Modules) for Moodle - * - * Description: - * Authentication by using the PHP4 PAM module: - * http://www.math.ohio-state.edu/~ccunning/pam_auth/ - * - * Version 0.3 2006/09/07 by Jonathan Harker (plugin class) - * Version 0.2: 2004/09/01 by Martin V�geli (stable version) - * Version 0.1: 2004/08/30 by Martin V�geli (first draft) - * - * Contact: martinvoegeli@gmx.ch - * Website 1: http://elearning.zhwin.ch/ - * Website 2: http://birdy1976.com/ - * - * @package auth_pam - * @author Martin Dougiamas - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - */ - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->libdir.'/authlib.php'); - -/** - * PAM authentication plugin. - */ -class auth_plugin_pam extends auth_plugin_base { - - /** - * Store error messages from pam authentication attempts. - */ - var $lasterror; - - /** - * Constructor. - */ - public function __construct() { - $this->authtype = 'pam'; - $this->config = get_config('auth_pam'); - $this->errormessage = ''; - } - - /** - * Old syntax of class constructor. Deprecated in PHP7. - * - * @deprecated since Moodle 3.1 - */ - public function auth_plugin_pam() { - 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) { - // variable to store possible errors during authentication - $errormessage = str_repeat(' ', 2048); - - // just for testing and debugging - // error_reporting(E_ALL); - - // call_time_pass_reference of errormessage is deprecated - throws warnings in multiauth - //if (pam_auth($username, $password, &$errormessage)) { - if (pam_auth($username, $password)) { - return true; - } - else { - $this->lasterror = $errormessage; - return false; - } - } - - 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 false; - } - -} - - diff --git a/auth/pam/db/install.php b/auth/pam/db/install.php deleted file mode 100644 index c519486c2a4..00000000000 --- a/auth/pam/db/install.php +++ /dev/null @@ -1,6 +0,0 @@ -. - -/** - * PAM authentication plugin upgrade code - * - * @package auth_pam - * @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_pam. - * @param int $oldversion the version we are upgrading from - * @return bool result - */ -function xmldb_auth_pam_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/pam to auth_pam. - upgrade_fix_config_auth_plugin_names('pam'); - upgrade_fix_config_auth_plugin_defaults('pam'); - upgrade_plugin_savepoint(true, 2017020700, 'auth', 'pam'); - } - - // Automatically generated Moodle v3.3.0 release upgrade line. - // Put any upgrade step following this. - - return true; -} diff --git a/auth/pam/lang/en/auth_pam.php b/auth/pam/lang/en/auth_pam.php deleted file mode 100644 index e4159be8329..00000000000 --- a/auth/pam/lang/en/auth_pam.php +++ /dev/null @@ -1,28 +0,0 @@ -. - -/** - * Strings for component 'auth_pam', language 'en'. - * - * @package auth_pam - * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -$string['auth_pamdescription'] = 'This method uses PAM to access the native usernames on this server. You have to install PHP4 PAM Authentication in order to use this module.'; -$string['auth_passwordisexpired'] = 'Your password has expired. Do you want to change your password now?'; -$string['auth_passwordwillexpire'] = 'Your password will expire in {$a} days. Do you want to change your password now?'; -$string['pluginname'] = 'PAM (Pluggable Authentication Modules)'; diff --git a/auth/pam/settings.php b/auth/pam/settings.php deleted file mode 100644 index 7a053a3f10e..00000000000 --- a/auth/pam/settings.php +++ /dev/null @@ -1,37 +0,0 @@ -. - -/** - * Admin settings and defaults. - * - * @package auth_pam - * @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_pam/pluginname', '', - new lang_string('auth_pamdescription', 'auth_pam'))); - - // Display locking / mapping of profile fields. - $authplugin = get_auth_plugin('pam'); - display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields, - get_string('auth_fieldlocks_help', 'auth'), false, false); -} diff --git a/auth/pam/upgrade.txt b/auth/pam/upgrade.txt deleted file mode 100644 index 19972b60b9e..00000000000 --- a/auth/pam/upgrade.txt +++ /dev/null @@ -1,7 +0,0 @@ -This files describes API changes in /auth/pam/*, -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/pam' to 'auth_pam'. diff --git a/auth/pam/version.php b/auth/pam/version.php deleted file mode 100644 index 35896816a5d..00000000000 --- a/auth/pam/version.php +++ /dev/null @@ -1,29 +0,0 @@ -. - -/** - * Version information - * - * @package auth_pam - * @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_pam'; // Full name of the plugin (used for diagnostics) diff --git a/lib/classes/plugin_manager.php b/lib/classes/plugin_manager.php index 89c9525855c..5a255be33ea 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'), + 'auth' => array('radius', 'fc', 'nntp', 'pam'), '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', 'pam', 'pop3', 'shibboleth', 'webservice' + 'nologin', 'none', 'oauth2', 'pop3', 'shibboleth', 'webservice' ), 'availability' => array( From 36eaa963327c07ba772f1a39de9e9e4bc695dedc Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 13 Jul 2017 15:20:20 +0800 Subject: [PATCH 4/6] 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, From abc25c01b8aa3efb650038ac892885e66c6b0e37 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 14 Jul 2017 08:11:45 +0800 Subject: [PATCH 5/6] 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), From 8d46ce81077fc264817c1e0c73f0b84db834c306 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 14 Jul 2017 08:19:05 +0800 Subject: [PATCH 6/6] MDL-50925 auth: Remove old README This is much better and more accurately documented in the Moodle Docs at https://docs.moodle.org/dev/Authentication_plugins. --- auth/README.txt | 153 ------------------------------------------------ 1 file changed, 153 deletions(-) delete mode 100644 auth/README.txt diff --git a/auth/README.txt b/auth/README.txt deleted file mode 100644 index 9805697c020..00000000000 --- a/auth/README.txt +++ /dev/null @@ -1,153 +0,0 @@ -This directory contains authentication modules. - -Each of these modules describes a different way to -check that a user has provided a correct - - - username, and - - password. - -Even when external forms of authentication are being used, Moodle still -maintains the internal "user" table with all the associated information about -that user such as name, email address and so on. - - -Multiauthentication in Moodle 1.8 -------------------------------------- - -The active methods are set by the admin on the Configuration page. Multiple -authentication plugins can now be used and ordered in a fail-through sequence. -One plugin can be selected for interactive login as well (which will need to be -part of the enabled plugin sequence). - - -email - authentication by email (DEFAULT METHOD) - - - user fills out form with email address - - email sent to user with link - - user clicks on link in email to confirm - - user account is created - - user can log in - - -none - no authentication at all .. very insecure!! - - - user logs in using ANY username and password - - if the username doesn't already exist then - a new account is created - - when user tries to access a course they - are forced to set up their account details - - -nologin - user can not log in, login as is possible - - - this plugin can be used to prevent normal user login - - -manual - internal authentication only - - - user logs in using username and password - - no way for user to make their own account - - -ldap - Uses an external LDAP server - - - user logs in using username and password - - these are checked against an LDAP server - - if correct, user is logged in - - optionally, info is copied from the LDAP - database to the Moodle user database - - (see the ldap/README for more details on config etc...) - - -db - Uses an external database to check username/password - - - user logs in using username and password - - these are checked against an external database - - if correct, user is logged in - - if the username doesn't already exist then - a new Moodle account is created - - --------------------------------------------------------------------------------- - -Authentication API ------------------- - - -AUTHENTICATION PLUGINS ----------------------- -Each authentication plugin is now contained in a subfolder as a class definition -in the auth.php file. For instance, the LDAP authentication plugin is the class -called auth_plugin_ldap defined in: - - /auth/ldap/auth.php - -To instantiate the class, there is a function in lib/moodlelib called -get_auth_plugin() that does the work for you: - - $ldapauth = get_auth_plugin('ldap'); - -Auth plugin classes are pretty basic and should be extending auth_plugin_base class. -They contain the same functions that were previously in each plugin's lib.php file, -but refactored to become class methods, and tweaked to reference the plugin's instantiated -config to get at the settings, rather than the global $CFG variable. - -When creating new plugins you can either extend the abstract auth_plugin_base class -(defined in lib/authlib.php) or create a new one and implement all methods from -auth_plugin_base. - -The new plugin architecture allows creating of more advanced types such as custom SSO -without the need to patch login and logout pages (see *_hook() methods in existing plugins). - -Configuration ------------------ - -All auth plugins must have a config property that contains the name value pairs -from the config_plugins table. This is populated using the get_config() function -in the constructor. The settings keys have also had the "auth_" prefix, as well -as the auth plugin name, trimmed. For instance, what used to be - - echo $CFG->auth_ldapversion; - -is now accessed as - - echo $ldapauth->config->version; - -Authentication settings have been moved to the config_plugins database table, -with the plugin field set to "auth/foo" (for instance, "auth/ldap"). - - -Method Names ------------------ - -When the functions from lib.php were ported to methods in auth.php, the "auth_" -prefix was dropped. For instance, calls to - - auth_user_login($user, $pass); - -now become - - $ldapauth->user_login($user, $pass); - -this also avoids having to worry about which auth/lib file to include since -Moodle takes care of it for you when you create an instance with -get_auth_plugin(). - -The basic class defines all applicable methods that moodle uses, you can find -more information in lib/authlib.php file. - - -Upgrading from Moodle 1.7 ------------------------------ - -Moodle will upgrade the old auth settings (in $CFG->auth_foobar where foo is the -auth plugin and bar is the setting) to the new style in the config_plugin -database table. - - - -Upgrading from Moodle 1.8 ------------------------------- - -user_activate() method was removed from public API because it was used only from user_confirm() in LDAP