]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/POP3.php
Activated Id substitution for Subversion
[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 // $Log: not supported by cvs2svn $
81 // Revision 1.6  2005/04/23 11:17:41  rurban
82 // bug #1186291
83 //
84 // Revision 1.5  2005/03/19 07:30:52  rurban
85 // fixed missing IMAP dependency. Thanks to sun-man
86 //
87 // Revision 1.4  2004/12/26 17:11:17  rurban
88 // just copyright
89 //
90 // Revision 1.3  2004/12/20 16:05:01  rurban
91 // gettext msg unification
92 //
93 // Revision 1.2  2004/12/19 00:58:02  rurban
94 // Enforce PASSWORD_LENGTH_MINIMUM in almost all PassUser checks,
95 // Provide an errormessage if so. Just PersonalPage and BogoLogin not.
96 // Simplify httpauth logout handling and set sessions for all methods.
97 // fix main.php unknown index "x" getLevelDescription() warning.
98 //
99 // Revision 1.1  2004/11/01 10:43:58  rurban
100 // seperate PassUser methods into seperate dir (memory usage)
101 // fix WikiUser (old) overlarge data session
102 // remove wikidb arg from various page class methods, use global ->_dbi instead
103 // ...
104 //
105
106 // Local Variables:
107 // mode: php
108 // tab-width: 8
109 // c-basic-offset: 4
110 // c-hanging-comment-ender-p: nil
111 // indent-tabs-mode: nil
112 // End:
113 ?>