]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/POP3.php
rcs_id no longer makes sense with Subversion global version number
[SourceForge/phpwiki.git] / lib / WikiUser / POP3.php
1 <?php //-*-php-*-
2 // rcs_id('$Id$');
3 /* Copyright (C) 2004 $ThePhpWikiProgrammingTeam
4  * This file is part of PhpWiki. Terms and Conditions see LICENSE. (GPL2)
5  */
6
7 require_once("lib/WikiUser/IMAP.php");
8
9 class _POP3PassUser
10 extends _IMAPPassUser {
11 /**
12  * Define the var POP3_AUTH_HOST in config/config.ini
13  * Preferences are handled in _PassUser
14  */
15     function checkPass($submitted_password) {
16         if (!$this->isValidName()) {
17             trigger_error(_("Invalid username."), E_USER_WARNING);
18             if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this)."::checkPass => failed isValidName", E_USER_WARNING);
19             return $this->_tryNextPass($submitted_password);
20         }
21         if (!$this->_checkPassLength($submitted_password)) {
22             if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this)."::checkPass => failed checkPassLength", E_USER_WARNING);
23             return WIKIAUTH_FORBIDDEN;
24         }
25         $userid = $this->_userid;
26         $pass = $submitted_password;
27         $host = defined('POP3_AUTH_HOST') ? POP3_AUTH_HOST : 'localhost:110';
28         if (defined('POP3_AUTH_PORT'))
29             $port = POP3_AUTH_PORT;
30         elseif (strstr($host,':')) {
31             list(,$port) = split(':',$host);
32         } else {
33             $port = 110;
34         }
35         $retval = false;
36         $fp = fsockopen($host, $port, $errno, $errstr, 10);
37         if ($fp) {
38             // Get welcome string
39             $line = fgets($fp, 1024);
40             if (! strncmp("+OK", $line, 3)) {
41                 // Send user name
42                 fputs($fp, "user $userid\n");
43                 // Get response
44                 $line = fgets($fp, 1024);
45                 if (! strncmp("+OK", $line, 3)) {
46                     // Send password
47                     fputs($fp, "pass $pass\n");
48                     // Get response
49                     $line = fgets($fp, 1024);
50                     if (! strncmp("+OK", $line, 3)) {
51                         $retval = true;
52                     }
53                 }
54             }
55             // quit the connection
56             fputs($fp, "quit\n");
57             // Get the sayonara message
58             $line = fgets($fp, 1024);
59             fclose($fp);
60         } else {
61             trigger_error(_("Couldn't connect to %s","POP3_AUTH_HOST ".$host.':'.$port),
62                           E_USER_WARNING);
63         }
64         $this->_authmethod = 'POP3';
65         if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this)."::checkPass => $retval", E_USER_WARNING);
66         if ($retval) {
67             $this->_level = WIKIAUTH_USER;
68         } else {
69             $this->_level = WIKIAUTH_ANON;
70         }
71         return $this->_level;
72     }
73
74     function __userExists() {
75         if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this)."::userExists => true (dummy)", E_USER_WARNING);
76         return true;
77     }
78 }
79
80 // Local Variables:
81 // mode: php
82 // tab-width: 8
83 // c-basic-offset: 4
84 // c-hanging-comment-ender-p: nil
85 // indent-tabs-mode: nil
86 // End:
87 ?>