Merge branch 'MDL-25881' of git://git.luns.net.uk/moodle
[moodle.git] / auth / nntp / auth.php
CommitLineData
b9ddb2d5 1<?php
2
3/**
4 * @author Martin Dougiamas
5 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
6 * @package moodle multiauth
7 *
8 * Authentication Plugin: NNTP Authentication
9 *
10 * Authenticates against an NNTP server.
11 *
12 * 2006-08-31 File created.
13 */
14
139ebfdb 15if (!defined('MOODLE_INTERNAL')) {
16 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
17}
b9ddb2d5 18
6bc1e5d5 19require_once($CFG->libdir.'/authlib.php');
20
b9ddb2d5 21/**
22 * NNTP authentication plugin.
23 */
6bc1e5d5 24class auth_plugin_nntp extends auth_plugin_base {
b9ddb2d5 25
26 /**
27 * Constructor.
28 */
29 function auth_plugin_nntp() {
6bc1e5d5 30 $this->authtype = 'nntp';
b9ddb2d5 31 $this->config = get_config('auth/nntp');
32 }
33
34 /**
35 * Returns true if the username and password work and false if they are
36 * wrong or don't exist.
37 *
be544ec3 38 * @param string $username The username
39 * @param string $password The password
139ebfdb 40 * @return bool Authentication success or failure.
b9ddb2d5 41 */
42 function user_login ($username, $password) {
43 if (! function_exists('imap_open')) {
2b06294b 44 print_error('auth_nntpnotinstalled','auth_nntp');
a57db6bd 45 exit;
b9ddb2d5 46 }
139ebfdb 47
b9ddb2d5 48 global $CFG;
139ebfdb 49
b9ddb2d5 50 // try each multiple host
7785dc2e 51 $hosts = explode(';', $this->config->host);
b9ddb2d5 52 foreach ($hosts as $host) {
53 $host = '{' . trim($host) . ':' . $this->config->port . '/nntp}';
54
55 error_reporting(0);
be544ec3 56 $connection = imap_open($host, $username, $password, OP_HALFOPEN);
139ebfdb 57 error_reporting($CFG->debug);
b9ddb2d5 58
59 if ($connection) {
60 imap_close($connection);
61 return true;
62 }
63 }
64 return false;
65 }
66
edb5da83
PS
67 function prevent_local_passwords() {
68 return true;
69 }
70
b9ddb2d5 71 /**
72 * Returns true if this authentication plugin is 'internal'.
73 *
139ebfdb 74 * @return bool
b9ddb2d5 75 */
76 function is_internal() {
77 return false;
78 }
79
80 /**
81 * Returns true if this authentication plugin can change the user's
82 * password.
83 *
139ebfdb 84 * @return bool
b9ddb2d5 85 */
86 function can_change_password() {
87 return false;
88 }
139ebfdb 89
b9ddb2d5 90 /**
91 * Prints a form for configuring this authentication plugin.
92 *
93 * This function is called from admin/auth.php, and outputs a full page with
94 * a form for configuring this plugin.
95 *
96 * @param array $page An object containing all the data for this page.
97 */
139ebfdb 98 function config_form($config, $err, $user_fields) {
b9ddb2d5 99 include "config.html";
100 }
101
102 /**
103 * Processes and stores configuration data for this authentication plugin.
104 */
105 function process_config($config) {
106 // set to defaults if undefined
107 if (!isset ($config->host)) {
108 $config->host = '127.0.0.1';
109 }
110 if (!isset ($config->port)) {
111 $config->port = '119';
112 }
113 if (!isset($config->changepasswordurl)) {
114 $config->changepasswordurl = '';
115 }
116
117 // save settings
118 set_config('host', $config->host, 'auth/nntp');
119 set_config('port', $config->port, 'auth/nntp');
120 set_config('changepasswordurl', $config->changepasswordurl, 'auth/nntp');
121
122 return true;
123 }
124
125}
126
5117d598 127