]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/POP3.php
Reformat code
[SourceForge/phpwiki.git] / lib / WikiUser / POP3.php
1 <?php
2
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     /**
29      * Define the var POP3_AUTH_HOST in config/config.ini
30      * Preferences are handled in _PassUser
31      */
32     function checkPass($submitted_password)
33     {
34         if (!$this->isValidName()) {
35             trigger_error(_("Invalid username."), E_USER_WARNING);
36             if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this) . "::checkPass => failed isValidName", E_USER_WARNING);
37             return $this->_tryNextPass($submitted_password);
38         }
39         if (!$this->_checkPassLength($submitted_password)) {
40             if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this) . "::checkPass => failed checkPassLength", E_USER_WARNING);
41             return WIKIAUTH_FORBIDDEN;
42         }
43         $userid = $this->_userid;
44         $pass = $submitted_password;
45         $host = defined('POP3_AUTH_HOST') ? POP3_AUTH_HOST : 'localhost:110';
46         if (defined('POP3_AUTH_PORT'))
47             $port = POP3_AUTH_PORT;
48         elseif (strstr($host, ':')) {
49             list(, $port) = explode(':', $host);
50         } else {
51             $port = 110;
52         }
53         $retval = false;
54         $fp = fsockopen($host, $port, $errno, $errstr, 10);
55         if ($fp) {
56             // Get welcome string
57             $line = fgets($fp, 1024);
58             if (!strncmp("+OK", $line, 3)) {
59                 // Send user name
60                 fputs($fp, "user $userid\n");
61                 // Get response
62                 $line = fgets($fp, 1024);
63                 if (!strncmp("+OK", $line, 3)) {
64                     // Send password
65                     fputs($fp, "pass $pass\n");
66                     // Get response
67                     $line = fgets($fp, 1024);
68                     if (!strncmp("+OK", $line, 3)) {
69                         $retval = true;
70                     }
71                 }
72             }
73             // quit the connection
74             fputs($fp, "quit\n");
75             // Get the sayonara message
76             $line = fgets($fp, 1024);
77             fclose($fp);
78         } else {
79             trigger_error(_("Couldn't connect to %s", "POP3_AUTH_HOST " . $host . ':' . $port),
80                 E_USER_WARNING);
81         }
82         $this->_authmethod = 'POP3';
83         if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this) . "::checkPass => $retval", E_USER_WARNING);
84         if ($retval) {
85             $this->_level = WIKIAUTH_USER;
86         } else {
87             $this->_level = WIKIAUTH_ANON;
88         }
89         return $this->_level;
90     }
91
92     function __userExists()
93     {
94         if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this) . "::userExists => true (dummy)", E_USER_WARNING);
95         return true;
96     }
97 }
98
99 // Local Variables:
100 // mode: php
101 // tab-width: 8
102 // c-basic-offset: 4
103 // c-hanging-comment-ender-p: nil
104 // indent-tabs-mode: nil
105 // End: