]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/POP3.php
New FSF address
[SourceForge/phpwiki.git] / lib / WikiUser / POP3.php
1 <?php //-*-php-*-
2 // $Id$
3 /*
4  * Copyright (C) 2004 $ThePhpWikiProgrammingTeam
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 require_once("lib/WikiUser/IMAP.php");
24
25 class _POP3PassUser
26 extends _IMAPPassUser {
27 /**
28  * Define the var POP3_AUTH_HOST in config/config.ini
29  * Preferences are handled in _PassUser
30  */
31     function checkPass($submitted_password) {
32         if (!$this->isValidName()) {
33             trigger_error(_("Invalid username."), E_USER_WARNING);
34             if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this)."::checkPass => failed isValidName", E_USER_WARNING);
35             return $this->_tryNextPass($submitted_password);
36         }
37         if (!$this->_checkPassLength($submitted_password)) {
38             if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this)."::checkPass => failed checkPassLength", E_USER_WARNING);
39             return WIKIAUTH_FORBIDDEN;
40         }
41         $userid = $this->_userid;
42         $pass = $submitted_password;
43         $host = defined('POP3_AUTH_HOST') ? POP3_AUTH_HOST : 'localhost:110';
44         if (defined('POP3_AUTH_PORT'))
45             $port = POP3_AUTH_PORT;
46         elseif (strstr($host,':')) {
47             list(,$port) = explode(':', $host);
48         } else {
49             $port = 110;
50         }
51         $retval = false;
52         $fp = fsockopen($host, $port, $errno, $errstr, 10);
53         if ($fp) {
54             // Get welcome string
55             $line = fgets($fp, 1024);
56             if (! strncmp("+OK", $line, 3)) {
57                 // Send user name
58                 fputs($fp, "user $userid\n");
59                 // Get response
60                 $line = fgets($fp, 1024);
61                 if (! strncmp("+OK", $line, 3)) {
62                     // Send password
63                     fputs($fp, "pass $pass\n");
64                     // Get response
65                     $line = fgets($fp, 1024);
66                     if (! strncmp("+OK", $line, 3)) {
67                         $retval = true;
68                     }
69                 }
70             }
71             // quit the connection
72             fputs($fp, "quit\n");
73             // Get the sayonara message
74             $line = fgets($fp, 1024);
75             fclose($fp);
76         } else {
77             trigger_error(_("Couldn't connect to %s","POP3_AUTH_HOST ".$host.':'.$port),
78                           E_USER_WARNING);
79         }
80         $this->_authmethod = 'POP3';
81         if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this)."::checkPass => $retval", E_USER_WARNING);
82         if ($retval) {
83             $this->_level = WIKIAUTH_USER;
84         } else {
85             $this->_level = WIKIAUTH_ANON;
86         }
87         return $this->_level;
88     }
89
90     function __userExists() {
91         if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this)."::userExists => true (dummy)", E_USER_WARNING);
92         return true;
93     }
94 }
95
96 // Local Variables:
97 // mode: php
98 // tab-width: 8
99 // c-basic-offset: 4
100 // c-hanging-comment-ender-p: nil
101 // indent-tabs-mode: nil
102 // End:
103 ?>