2007-01-04 04:52:42 +00:00
|
|
|
<?php
|
2013-04-27 15:06:40 +02:00
|
|
|
// 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/>.
|
2007-01-04 04:52:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Authentication Plugin: POP3 Authentication
|
|
|
|
* Authenticates against a POP3 server.
|
|
|
|
*
|
2013-04-27 15:06:40 +02:00
|
|
|
* @package auth_pop3
|
|
|
|
* @author Martin Dougiamas
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
2007-01-04 04:52:42 +00:00
|
|
|
*/
|
|
|
|
|
2013-04-27 15:09:05 +02:00
|
|
|
defined('MOODLE_INTERNAL') || die();
|
2007-01-04 04:52:42 +00:00
|
|
|
|
2007-03-22 12:27:52 +00:00
|
|
|
require_once($CFG->libdir.'/authlib.php');
|
|
|
|
|
2007-01-04 04:52:42 +00:00
|
|
|
/**
|
|
|
|
* POP3 authentication plugin.
|
|
|
|
*/
|
2007-03-22 12:27:52 +00:00
|
|
|
class auth_plugin_pop3 extends auth_plugin_base {
|
2007-01-04 04:52:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
2015-11-27 09:01:25 +08:00
|
|
|
public function __construct() {
|
2007-03-22 12:27:52 +00:00
|
|
|
$this->authtype = 'pop3';
|
2017-04-03 10:50:09 -04:00
|
|
|
$this->config = get_config('auth_pop3');
|
2007-01-04 04:52:42 +00:00
|
|
|
}
|
|
|
|
|
2015-11-27 09:01:25 +08:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
|
|
|
|
2007-01-04 04:52:42 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the username and password work and false if they are
|
|
|
|
* wrong or don't exist.
|
|
|
|
*
|
2008-05-30 20:54:19 +00:00
|
|
|
* @param string $username The username
|
|
|
|
* @param string $password The password
|
2007-02-20 17:03:36 +00:00
|
|
|
* @return bool Authentication success or failure.
|
2007-01-04 04:52:42 +00:00
|
|
|
*/
|
|
|
|
function user_login($username, $password) {
|
|
|
|
if (! function_exists('imap_open')) {
|
2009-06-11 03:34:46 +00:00
|
|
|
print_error('auth_pop3notinstalled','auth_pop3');
|
2007-01-10 00:25:51 +00:00
|
|
|
exit;
|
2007-01-04 04:52:42 +00:00
|
|
|
}
|
2007-02-20 17:03:36 +00:00
|
|
|
|
2007-01-04 04:52:42 +00:00
|
|
|
global $CFG;
|
2010-07-20 01:38:54 +00:00
|
|
|
$hosts = explode(';', $this->config->host); // Could be multiple hosts
|
2007-01-04 04:52:42 +00:00
|
|
|
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);
|
2008-05-30 20:54:19 +00:00
|
|
|
$connection = imap_open($host, $username, $password);
|
2007-02-20 17:03:36 +00:00
|
|
|
error_reporting($CFG->debug);
|
|
|
|
|
2007-01-04 04:52:42 +00:00
|
|
|
if ($connection) {
|
|
|
|
imap_close($connection);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false; // No matches found
|
|
|
|
}
|
|
|
|
|
2009-11-23 21:50:40 +00:00
|
|
|
function prevent_local_passwords() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-01-04 04:52:42 +00:00
|
|
|
/**
|
|
|
|
* Returns true if this authentication plugin is 'internal'.
|
|
|
|
*
|
2007-02-20 17:03:36 +00:00
|
|
|
* @return bool
|
2007-01-04 04:52:42 +00:00
|
|
|
*/
|
|
|
|
function is_internal() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this authentication plugin can change the user's
|
|
|
|
* password.
|
|
|
|
*
|
2007-02-20 17:03:36 +00:00
|
|
|
* @return bool
|
2007-01-04 04:52:42 +00:00
|
|
|
*/
|
|
|
|
function can_change_password() {
|
2007-02-21 21:42:10 +00:00
|
|
|
return !empty($this->config->changepasswordurl);
|
2007-01-04 04:52:42 +00:00
|
|
|
}
|
2007-02-20 17:03:36 +00:00
|
|
|
|
2007-01-04 04:52:42 +00:00
|
|
|
/**
|
|
|
|
* Returns the URL for changing the user's pw, or false if the default can
|
|
|
|
* be used.
|
|
|
|
*
|
2010-08-18 22:07:00 +00:00
|
|
|
* @return moodle_url
|
2007-01-04 04:52:42 +00:00
|
|
|
*/
|
|
|
|
function change_password_url() {
|
2013-11-21 16:15:04 +08:00
|
|
|
if (!empty($this->config->changepasswordurl)) {
|
|
|
|
return new moodle_url($this->config->changepasswordurl);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2007-01-04 04:52:42 +00:00
|
|
|
}
|
2007-02-20 17:03:36 +00:00
|
|
|
|
2007-01-04 04:52:42 +00:00
|
|
|
}
|
|
|
|
|
2009-11-01 11:55:14 +00:00
|
|
|
|