Merge branch 'MDL-57896-master-clicfg' of git://github.com/mudrd8mz/moodle
[moodle.git] / auth / nntp / auth.php
blob9e8b24c5fe405c4810c234351eb95784af81a4b1
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Authentication Plugin: NNTP Authentication
19 * Authenticates against an NNTP server.
21 * @package auth_nntp
22 * @author Martin Dougiamas
23 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
26 defined('MOODLE_INTERNAL') || die();
28 require_once($CFG->libdir.'/authlib.php');
30 /**
31 * NNTP authentication plugin.
33 class auth_plugin_nntp extends auth_plugin_base {
35 /**
36 * Constructor.
38 public function __construct() {
39 $this->authtype = 'nntp';
40 $this->config = get_config('auth/nntp');
43 /**
44 * Old syntax of class constructor. Deprecated in PHP7.
46 * @deprecated since Moodle 3.1
48 public function auth_plugin_nntp() {
49 debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
50 self::__construct();
53 /**
54 * Returns true if the username and password work and false if they are
55 * wrong or don't exist.
57 * @param string $username The username
58 * @param string $password The password
59 * @return bool Authentication success or failure.
61 function user_login ($username, $password) {
62 if (! function_exists('imap_open')) {
63 print_error('auth_nntpnotinstalled','auth_nntp');
64 exit;
67 global $CFG;
69 // try each multiple host
70 $hosts = explode(';', $this->config->host);
71 foreach ($hosts as $host) {
72 $host = '{' . trim($host) . ':' . $this->config->port . '/nntp}';
74 error_reporting(0);
75 $connection = imap_open($host, $username, $password, OP_HALFOPEN);
76 error_reporting($CFG->debug);
78 if ($connection) {
79 imap_close($connection);
80 return true;
83 return false;
86 function prevent_local_passwords() {
87 return true;
90 /**
91 * Returns true if this authentication plugin is 'internal'.
93 * @return bool
95 function is_internal() {
96 return false;
99 /**
100 * Returns true if this authentication plugin can change the user's
101 * password.
103 * @return bool
105 function can_change_password() {
106 return false;
110 * Prints a form for configuring this authentication plugin.
112 * This function is called from admin/auth.php, and outputs a full page with
113 * a form for configuring this plugin.
115 * @param array $page An object containing all the data for this page.
117 function config_form($config, $err, $user_fields) {
118 include "config.html";
122 * Processes and stores configuration data for this authentication plugin.
124 function process_config($config) {
125 // set to defaults if undefined
126 if (!isset ($config->host)) {
127 $config->host = '127.0.0.1';
129 if (!isset ($config->port)) {
130 $config->port = '119';
132 if (!isset($config->changepasswordurl)) {
133 $config->changepasswordurl = '';
136 // save settings
137 set_config('host', $config->host, 'auth/nntp');
138 set_config('port', $config->port, 'auth/nntp');
139 set_config('changepasswordurl', $config->changepasswordurl, 'auth/nntp');
141 return true;