]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUserNew.php
PageList enhanced and improved.
[SourceForge/phpwiki.git] / lib / WikiUserNew.php
1 <?php //-*-php-*-
2 rcs_id('$Id: WikiUserNew.php,v 1.15 2004-02-15 21:34:37 rurban Exp $');
3
4 // This is a complete OOP rewrite of the old WikiUser code with various
5 // configurable external authentification methods.
6 //
7 // There's only one entry point, the function WikiUser which returns 
8 // a WikiUser object, which contains the user's preferences.
9 // This object might get upgraded during the login step and later also.
10 // There exist three preferences storage methods: cookie, homepage and db,
11 // and multiple password checking methods.
12 // See index.php for $USER_AUTH_ORDER[] and USER_AUTH_POLICY if 
13 // ALLOW_USER_PASSWORDS is defined.
14 //
15 // Each user object must define the two preferences methods 
16 //  getPreferences(), setPreferences(), 
17 // and the following 1-3 auth methods
18 //  checkPass()  must be defined by all classes,
19 //  userExists() only if USER_AUTH_POLICY'=='strict' 
20 //  mayChangePass()  only if the password is storable.
21 //  storePass()  only if the password is storable.
22 //
23 // WikiUser() given no name, returns an _AnonUser (anonymous user)
24 // object, who may or may not have a cookie. 
25 // However, if the there's a cookie with the userid or a session, 
26 // the user is upgraded to the matching user object.
27 // Given a user name, returns a _BogoUser object, who may or may not 
28 // have a cookie and/or PersonalPage, a _PassUser object or an 
29 // _AdminUser object.
30 //
31 // Takes care of passwords, all preference loading/storing in the
32 // user's page and any cookies. lib/main.php will query the user object to
33 // verify the password as appropriate.
34 //
35 // Notes by 2004-01-25 03:43:45 rurban
36 // Currently this library doesn't look good enough with 
37 // the current configuration options.
38 // Test it by defining ENABLE_USER_NEW in index.php
39 // The problem is that the previous code was written to do auth checks 
40 // only on action != browse, and this code requires a good enough 
41 // user object even for browse. I don't think that this is a good idea.
42 // 1) Now a ForbiddenUser is returned instead of false.
43 // 2) Previously ALLOW_ANON_USER = false meant that anon users cannot edit, 
44 // but may browse. Now with ALLOW_ANON_USER = false he may not browse, 
45 // which is needed to disable browse PagePermissions. Hmm...
46 // I added now ALLOW_ANON_EDIT = true to makes things clear. 
47 // (which replaces REQUIRE_SIGNIN_BEFORE_EDIT)
48 /*
49  * Fixme: 2004-02-06 15:42:24 rurban
50  *   dbprefs edit with anonuser fails.
51 */
52
53 define('WIKIAUTH_FORBIDDEN', -1); // Completely not allowed.
54 define('WIKIAUTH_ANON', 0);       // Not signed in.
55 define('WIKIAUTH_BOGO', 1);       // Any valid WikiWord is enough.
56 define('WIKIAUTH_USER', 2);       // Bogo user with a password.
57 define('WIKIAUTH_ADMIN', 10);     // UserName == ADMIN_USER.
58
59 if (!defined('COOKIE_EXPIRATION_DAYS')) define('COOKIE_EXPIRATION_DAYS', 365);
60 if (!defined('COOKIE_DOMAIN'))          define('COOKIE_DOMAIN', '/');
61
62 if (!defined('EDITWIDTH_MIN_COLS'))     define('EDITWIDTH_MIN_COLS',     30);
63 if (!defined('EDITWIDTH_MAX_COLS'))     define('EDITWIDTH_MAX_COLS',    150);
64 if (!defined('EDITWIDTH_DEFAULT_COLS')) define('EDITWIDTH_DEFAULT_COLS', 80);
65
66 if (!defined('EDITHEIGHT_MIN_ROWS'))     define('EDITHEIGHT_MIN_ROWS',      5);
67 if (!defined('EDITHEIGHT_MAX_ROWS'))     define('EDITHEIGHT_MAX_ROWS',     80);
68 if (!defined('EDITHEIGHT_DEFAULT_ROWS')) define('EDITHEIGHT_DEFAULT_ROWS', 22);
69
70 define('TIMEOFFSET_MIN_HOURS', -26);
71 define('TIMEOFFSET_MAX_HOURS',  26);
72 if (!defined('TIMEOFFSET_DEFAULT_HOURS')) define('TIMEOFFSET_DEFAULT_HOURS', 0);
73
74 /**
75  * There are be the following constants in index.php to 
76  * establish login parameters:
77  *
78  * ALLOW_ANON_USER         default true
79  * ALLOW_ANON_EDIT         default true
80  * ALLOW_BOGO_LOGIN        default true
81  * ALLOW_USER_PASSWORDS    default true
82  * PASSWORD_LENGTH_MINIMUM default 6?
83  *
84  * To require user passwords for editing:
85  * ALLOW_ANON_USER  = true
86  * ALLOW_ANON_EDIT  = false   (before named REQUIRE_SIGNIN_BEFORE_EDIT)
87  * ALLOW_BOGO_LOGIN = false
88  * ALLOW_USER_PASSWORDS = true
89  *
90  * To establish a COMPLETELY private wiki, such as an internal
91  * corporate one:
92  * ALLOW_ANON_USER = false
93  * (and probably require user passwords as described above). In this
94  * case the user will be prompted to login immediately upon accessing
95  * any page.
96  *
97  * There are other possible combinations, but the typical wiki (such
98  * as PhpWiki.sf.net) would usually just leave all four enabled.
99  *
100  */
101
102 // The last object in the row is the bad guy...
103 if (!is_array($USER_AUTH_ORDER))
104     $USER_AUTH_ORDER = array("Forbidden");
105 else
106     $USER_AUTH_ORDER[] = "Forbidden";
107
108 // Local convenience functions.
109 function _isAnonUserAllowed() {
110     return (defined('ALLOW_ANON_USER') && ALLOW_ANON_USER);
111 }
112 function _isBogoUserAllowed() {
113     return (defined('ALLOW_BOGO_LOGIN') && ALLOW_BOGO_LOGIN);
114 }
115 function _isUserPasswordsAllowed() {
116     return (defined('ALLOW_USER_PASSWORDS') && ALLOW_USER_PASSWORDS);
117 }
118
119
120 // Possibly upgrade userobject functions.
121 function _determineAdminUserOrOtherUser($UserName) {
122     // Sanity check. User name is a condition of the definition of the
123     // _AdminUser, _BogoUser and _passuser.
124     if (!$UserName)
125         return $GLOBALS['ForbiddenUser'];
126
127     if ($UserName == ADMIN_USER)
128         return new _AdminUser($UserName);
129     else
130         return _determineBogoUserOrPassUser($UserName);
131 }
132
133 function _determineBogoUserOrPassUser($UserName) {
134     global $ForbiddenUser;
135
136     // Sanity check. User name is a condition of the definition of
137     // _BogoUser and _PassUser.
138     if (!$UserName)
139         return $ForbiddenUser;
140
141     // Check for password and possibly upgrade user object.
142     $_BogoUser = new _BogoUser($UserName);
143     if (_isUserPasswordsAllowed()) {
144         if (/*$has_password =*/ $_BogoUser->_prefs->get('passwd'))
145             return new _PassUser($UserName);
146         else { // PassUsers override BogoUsers if they exist
147             $_PassUser = new _PassUser($UserName);
148             if ($_PassUser->userExists())
149                 return $_PassUser;
150         }
151     }
152     // User has no password.
153     if (_isBogoUserAllowed())
154         return $_BogoUser;
155
156     // Passwords are not allowed, and Bogo is disallowed too. (Only
157     // the admin can sign in).
158     return $ForbiddenUser;
159 }
160
161 /**
162  * Primary WikiUser function, called by main.php.
163  * 
164  * This determines the user's type and returns an appropriate user
165  * object. main.php then querys the resultant object for password
166  * validity as necessary.
167  *
168  * If an _AnonUser object is returned, the user may only browse pages
169  * (and save prefs in a cookie).
170  *
171  * To disable access but provide prefs the global $ForbiddenUser class 
172  * is returned. (was previously false)
173  * 
174  */
175 function WikiUser ($UserName = '') {
176     global $ForbiddenUser;
177
178     //TODO: Check sessionvar for username & save username into
179     //sessionvar (may be more appropriate to do this in main.php).
180     if ($UserName) {
181         $ForbiddenUser = new _ForbiddenUser($UserName);
182         // Found a user name.
183         return _determineAdminUserOrOtherUser($UserName);
184     }
185     elseif (!empty($_SESSION['userid'])) {
186         // Found a user name.
187         $ForbiddenUser = new _ForbiddenUser($_SESSION['userid']);
188         return _determineAdminUserOrOtherUser($_SESSION['userid']);
189     }
190     else {
191         // Check for autologin pref in cookie and possibly upgrade
192         // user object to another type.
193         $_AnonUser = new _AnonUser();
194         if ($UserName = $_AnonUser->_userid && $_AnonUser->_prefs->get('autologin')) {
195             // Found a user name.
196             $ForbiddenUser = new _ForbiddenUser($UserName);
197             return _determineAdminUserOrOtherUser($UserName);
198         }
199         else {
200             $ForbiddenUser = new _ForbiddenUser();
201             if (_isAnonUserAllowed())
202                 return $_AnonUser;
203             return $ForbiddenUser; // User must sign in to browse pages.
204         }
205         return $ForbiddenUser;     // User must sign in with a password.
206     }
207     /*
208     trigger_error("DEBUG: Note: End of function reached in WikiUser." . " "
209                   . "Unexpectedly, an appropriate user class could not be determined.");
210     return $ForbiddenUser; // Failsafe.
211     */
212 }
213
214 function WikiUserClassname() {
215     return '_WikiUser';
216 }
217
218 function UpgradeUser ($olduser, $user) {
219     if (isa($user,'_WikiUser') and isa($olduser,'_WikiUser')) {
220         // populate the upgraded class $olduser with the values from the new user object
221         foreach (get_object_vars($user) as $k => $v) {
222             if (!empty($v)) $olduser->$k = $v;  
223         }
224         $GLOBALS['request']->_user = $olduser;
225         return $olduser;
226     } else {
227         return false;
228     }
229 }
230
231 function UserExists ($UserName) {
232     global $request;
233     if (!($user = $request->getUser()))
234         $user = WikiUser($UserName);
235     if (!$user) 
236         return false;
237     if ($user->userExists($UserName)) {
238         $request->_user = $user;
239         return true;
240     }
241     if (isa($user,'_BogoUser'))
242       $user = new _PassUser($UserName);
243     while ($user = $user->nextClass()) {
244         return $user->userExists($UserName);
245     }
246     $request->_user = $GLOBALS['ForbiddenUser'];
247     return false;
248 }
249
250 function CheckPass ($UserName, $Password) {
251     global $request;
252     if (!($user = $request->getUser()))
253         $user = WikiUser($UserName);
254     if (!$user) 
255         return false;
256     if ($user->checkPass($Password)) {
257         $request->_user = $user;
258         return true;
259     }
260     if (isa($user,'_BogoUser'))
261       $user = new _PassUser($UserName);
262     while ($user = $user->nextClass()) {
263         return $user->checkPass($Password);
264     }
265     $request->_user = $GLOBALS['ForbiddenUser'];
266     return false;
267 }
268
269
270 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
271
272 // Base WikiUser class.
273 class _WikiUser
274 {
275     var $_userid = '';
276
277     var $_level = WIKIAUTH_FORBIDDEN;
278     var $_prefs = false;
279     var $_HomePagehandle = false;
280
281     // constructor
282     function _WikiUser($UserName = '') {
283
284         $this->_userid = $UserName;
285         if ($UserName) {
286             $this->_HomePagehandle = $this->hasHomePage();
287         }
288         $this->getPreferences();
289     }
290
291     function UserName() {
292         if (!empty($this->_userid))
293             return $this->_userid;
294     }
295
296     function getPreferences() {
297         trigger_error("DEBUG: Note: undefined _WikiUser class trying to load prefs." . " "
298                       . "New subclasses of _WikiUser must override this function.");
299         return false;
300     }
301
302     function setPreferences($prefs, $id_only) {
303         trigger_error("DEBUG: Note: undefined _WikiUser class trying to save prefs." . " "
304                       . "New subclasses of _WikiUser must override this function.");
305         return false;
306     }
307
308     function userExists() {
309         return $this->hasHomePage();
310     }
311
312     function checkPass($submitted_password) {
313         // By definition, an undefined user class cannot sign in.
314         trigger_error("DEBUG: Warning: undefined _WikiUser class trying to sign in." . " "
315                       . "New subclasses of _WikiUser must override this function.");
316         return false;
317     }
318
319     // returns page_handle to user's home page or false if none
320     function hasHomePage() {
321         if ($this->_userid) {
322             if ($this->_HomePagehandle) {
323                 return $this->_HomePagehandle;
324             }
325             else {
326                 // check db again (maybe someone else created it since
327                 // we logged in.)
328                 global $request;
329                 $this->_HomePagehandle = $request->getPage($this->_userid);
330                 return $this->_HomePagehandle;
331             }
332         }
333         // nope
334         return false;
335     }
336
337     function nextAuthMethod() {
338         if (! $this->_current_method) {
339             if (get_class($this) != '_passuser') {
340                 $this->_current_method = substr(get_class($this),1,-8);
341             }
342             $this->_auth_methods = $GLOBALS['USER_AUTH_ORDER'];
343             $this->_current_index = -1;
344         }
345         $this->_current_index++;
346         if ($this->_current_index >= count($this->_auth_methods))
347             return false;
348         $this->_current_method = $this->_auth_methods[$this->_current_index];
349         return $this->_current_method;
350     }
351
352     // upgrade the user object
353     function nextClass() {
354         if ($method = $this->nextAuthMethod()) {
355             $class = "_".$method."PassUser";
356             if ($user = new $class($this->_userid)) {
357                 // prevent from endless recursion.
358                 //$user->_current_method = $this->_current_method;
359                 //$user->_current_index = $this->_current_index;
360                 $user = UpgradeUser($user, $this);
361             }
362             return $user;
363         }
364     }
365
366     function PrintLoginForm (&$request, $args, $fail_message = false,
367                              $seperate_page = true) {
368         include_once('lib/Template.php');
369         // Call update_locale in case the system's default language is not 'en'.
370         // (We have no user pref for lang at this point yet, no one is logged in.)
371         update_locale(DEFAULT_LANGUAGE);
372         $userid = $this->_userid;
373         $require_level = 0;
374         extract($args); // fixme
375
376         $require_level = max(0, min(WIKIAUTH_ADMIN, (int)$require_level));
377
378         $pagename = $request->getArg('pagename');
379         $nocache = 1;
380         $login = new Template('login', $request,
381                               compact('pagename', 'userid', 'require_level',
382                                       'fail_message', 'pass_required', 'nocache'));
383         if ($seperate_page) {
384             $top = new Template('html', $request,
385                                 array('TITLE' => _("Sign In")));
386             return $top->printExpansion($login);
387         } else {
388             return $login;
389         }
390     }
391
392     // signed in but probably not password checked
393     function isSignedIn() {
394         return (isa($this,'_BogoUser') or isa($this,'_PassUser'));
395     }
396
397     function isAuthenticated () {
398         //return isa($this,'_PassUser');
399         //return isa($this,'_BogoUser') || isa($this,'_PassUser');
400         return $this->_level >= WIKIAUTH_BOGO;
401     }
402
403     function isAdmin () {
404         return $this->_level == WIKIAUTH_ADMIN;
405     }
406
407     function getId () {
408         return ( $this->UserName()
409                  ? $this->UserName()
410                  : $GLOBALS['request']->get('REMOTE_ADDR') ); // FIXME: globals
411     }
412
413     function getAuthenticatedId() {
414         return ( $this->isAuthenticated()
415                  ? $this->_userid
416                  : ''); //$GLOBALS['request']->get('REMOTE_ADDR') ); // FIXME: globals
417     }
418
419     function hasAuthority ($require_level) {
420         return $this->_level >= $require_level;
421     }
422
423     function AuthCheck ($postargs) {
424         // Normalize args, and extract.
425         $keys = array('userid', 'passwd', 'require_level', 'login', 'logout',
426                       'cancel');
427         foreach ($keys as $key)
428             $args[$key] = isset($postargs[$key]) ? $postargs[$key] : false;
429         extract($args);
430         $require_level = max(0, min(WIKIAUTH_ADMIN, (int)$require_level));
431
432         if ($logout) { // Log out
433             $GLOBALS['request']->_user = new _AnonUser();
434             return $GLOBALS['request']->_user; 
435         } elseif ($cancel)
436             return false;        // User hit cancel button.
437         elseif (!$login && !$userid)
438             return false;       // Nothing to do?
439
440         $authlevel = checkPass($userid,$passwd);
441         if (!$authlevel)
442             return _("Invalid password or userid.");
443         elseif ($authlevel < $require_level)
444             return _("Insufficient permissions.");
445
446         // Successful login.
447         $user = $GLOBALS['request']->_user;
448         $user->_userid = $userid;
449         $user->_level = $authlevel;
450         return $user;
451     }
452
453 }
454
455 class _AnonUser
456 extends _WikiUser
457 {
458     var $_level = WIKIAUTH_ANON;
459
460     // Anon only gets to load and save prefs in a cookie, that's it.
461     function getPreferences() {
462         global $request;
463
464         if (empty($this->_prefs))
465             $this->_prefs = new UserPreferences;
466         $UserName = $this->UserName();
467         if ($cookie = $request->getCookieVar(WIKI_NAME)) {
468             if (! $unboxedcookie = $this->_prefs->retrieve($cookie)) {
469                 trigger_error(_("Format of UserPreferences cookie not recognised.") . " "
470                               . _("Default preferences will be used."),
471                               E_USER_WARNING);
472             }
473             // TODO: try reading userid from old PhpWiki cookie
474             // formats, then delete old cookie from browser!
475             //
476             //else {
477                 // try old cookie format.
478                 //$cookie = $request->getCookieVar('WIKI_ID');
479             //}
480
481             /**
482              * Only keep the cookie if it matches the UserName who is
483              * signing in or if this really is an Anon login (no
484              * username). (Remember, _BogoUser and higher inherit this
485              * function too!).
486              */
487             if (! $UserName || $UserName == $unboxedcookie['userid']) {
488                 $this->_prefs = new UserPreferences($unboxedcookie);
489                 $this->_userid = $unboxedcookie['userid'];
490             }
491         }
492         // initializeTheme() needs at least an empty object
493         if (! $this->_prefs )
494             $this->_prefs = new UserPreferences;
495         return $this->_prefs;
496     }
497
498     function setPreferences($prefs, $id_only=false) {
499         // Allow for multiple wikis in same domain. Encode only the
500         // _prefs array of the UserPreference object. Ideally the
501         // prefs array should just be imploded into a single string or
502         // something so it is completely human readable by the end
503         // user. In that case stricter error checking will be needed
504         // when loading the cookie.
505         if (!is_object($prefs)) {
506             $prefs = new UserPreferences($prefs);
507         }
508         $packed = $prefs->store();
509         $unpacked = $prefs->unpack($packed);
510         if (!empty($unpacked)) { // check how many are different from the default_value
511             setcookie(WIKI_NAME, $packed,
512                       COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
513         }
514         if (count($unpacked)) {
515             global $request;
516             $this->_prefs = $prefs;
517             $request->_prefs =& $this->_prefs; 
518             $request->_user->_prefs =& $this->_prefs; 
519             //$request->setSessionVar('wiki_prefs', $this->_prefs);
520             $request->setSessionVar('wiki_user', $request->_user);
521         }
522         return count($unpacked);
523     }
524
525     function userExists() {
526         return true;
527     }
528
529     function checkPass($submitted_password) {
530         // By definition, the _AnonUser does not HAVE a password
531         // (compared to _BogoUser, who has an EMPTY password).
532         trigger_error("DEBUG: Warning: _AnonUser unexpectedly asked to checkPass()." . " "
533                       . "Check isa(\$user, '_PassUser'), or: isa(\$user, '_AdminUser') etc. first." . " "
534                       . "New subclasses of _WikiUser must override this function.");
535         return false;
536     }
537
538 }
539
540 class _ForbiddenUser
541 extends _AnonUser
542 {
543     var $_level = WIKIAUTH_FORBIDDEN;
544
545     function checkPass($submitted_password) {
546         return false;
547     }
548
549     function userExists() {
550         if ($this->_HomePagehandle) return true;
551         return false;
552     }
553 }
554 class _ForbiddenPassUser
555 extends _ForbiddenUser
556 {
557     function dummy() {
558         return;
559     }
560 }
561
562 /**
563  * Do NOT extend _BogoUser to other classes, for checkPass()
564  * security. (In case of defects in code logic of the new class!)
565  */
566 class _BogoUser
567 extends _AnonUser
568 {
569     function userExists() {
570         if (isWikiWord($this->_userid)) {
571             $this->_level = WIKIAUTH_BOGO;
572             return true;
573         } else {
574             $this->_level = WIKIAUTH_ANON;
575             return false;
576         }
577     }
578
579     function checkPass($submitted_password) {
580         // By definition, BogoUser has an empty password.
581         $this->userExists();
582         return $this->_level;
583     }
584 }
585
586 class _PassUser
587 extends _AnonUser
588 /**
589  * Called if ALLOW_USER_PASSWORDS and Anon and Bogo failed.
590  *
591  * The classes for all subsequent auth methods extend from
592  * this class. 
593  * This handles the auth method type dispatcher according $USER_AUTH_ORDER, 
594  * the three auth method policies first-only, strict and stacked
595  * and the two methods for prefs: homepage or database, 
596  * if $DBAuthParams['pref_select'] is defined.
597  *
598  * Default is PersonalPage auth and prefs.
599  * 
600  */
601 {
602     var $_auth_dbi, $_prefmethod, $_prefselect, $_prefupdate;
603     var $_current_method, $_current_index;
604
605     // check and prepare the auth and pref methods only once
606     function _PassUser($UserName = '') {
607         global $DBAuthParams, $DBParams;
608
609         if ($UserName) {
610             $this->_userid = $UserName;
611             $this->_HomePagehandle = $this->hasHomePage();
612         }
613         // Check the configured Prefs methods
614         if (  !empty($DBAuthParams['pref_select']) ) {
615             if ( $DBParams['dbtype'] == 'SQL' and !@is_int($this->_prefselect)) {
616                 $this->_prefmethod = 'SQL'; // really pear db
617                 $this->getAuthDbh();
618                 // preparate the SELECT statement
619                 $this->_prefselect = $this->_auth_dbi->prepare(
620                     str_replace('"$userid"','?',$DBAuthParams['pref_select'])
621                 );
622             }
623             if (  $DBParams['dbtype'] == 'ADODB' and !isset($this->_prefselect)) {
624                 $this->_prefmethod = 'ADODB'; // uses a simplier execute syntax
625                 $this->getAuthDbh();
626                 // preparate the SELECT statement
627                 $this->_prefselect = str_replace('"$userid"','%s',$DBAuthParams['pref_select']);
628             }
629         } else {
630             unset($this->_prefselect);
631         }
632         if (  !empty($DBAuthParams['pref_update']) and 
633               $DBParams['dbtype'] == 'SQL' and
634               !@is_int($this->_prefupdate)) {
635             $this->_prefmethod = 'SQL';
636             $this->getAuthDbh();
637             $this->_prefupdate = $this->_auth_dbi->prepare(
638                 str_replace(array('"$userid"','"$pref_blob"'),array('?','?'),$DBAuthParams['pref_update'])
639             );
640         }
641         if (  !empty($DBAuthParams['pref_update']) and 
642               $DBParams['dbtype'] == 'ADODB' and
643               !isset($this->_prefupdate)) {
644             $this->_prefmethod = 'ADODB'; // uses a simplier execute syntax
645             $this->getAuthDbh();
646             // preparate the SELECT statement
647             $this->_prefupdate = str_replace(array('"$userid"','"$pref_blob"'),array('%s','%s'),
648                                              $DBAuthParams['pref_update']);
649         }
650         $this->getPreferences();
651
652         // Upgrade to the next parent _PassUser class. Avoid recursion.
653         if ( get_class($this) === '_passuser' ) { // hopefully PHP will keep this lowercase
654             //auth policy: Check the order of the configured auth methods
655             // 1. first-only: Upgrade the class here in the constructor
656             // 2. old:       ignore USER_AUTH_ORDER and try to use all available methods as in the previous PhpWiki releases (slow)
657             // 3. strict:    upgrade the class after checking the user existance in userExists()
658             // 4. stacked:   upgrade the class after the password verification in checkPass()
659             // Methods: PersonalPage, HTTP_AUTH, DB, LDAP, IMAP, File
660             if (!defined('USER_AUTH_POLICY')) define('USER_AUTH_POLICY','old');
661             if (defined('USER_AUTH_POLICY')) {
662                 // policy 1: only pre-define one method for all users
663                 if (USER_AUTH_POLICY === 'first-only') {
664                     if ($user = $this->nextClass())
665                         return $user;
666                     else 
667                         return $GLOBALS['ForbiddenUser'];
668                 }
669                 // use the default behaviour from the previous versions:
670                 elseif (USER_AUTH_POLICY === 'old') {
671                     // default: try to be smart
672                     if (!empty($GLOBALS['PHP_AUTH_USER'])) {
673                         return new _HttpAuthPassUser($UserName);
674                     } elseif (!empty($DBAuthParams['auth_check']) and ($DBAuthParams['auth_dsn'] or $GLOBALS ['DBParams']['dsn'])) {
675                         return new _DbPassUser($UserName);
676                     } elseif (defined('LDAP_AUTH_HOST') and defined('LDAP_BASE_DN') and function_exists('ldap_open')) {
677                         return new _LDAPPassUser($UserName);
678                     } elseif (defined('IMAP_AUTH_HOST') and function_exists('imap_open')) {
679                         return new _IMAPPassUser($UserName);
680                     } elseif (defined('AUTH_USER_FILE')) {
681                         return new _FilePassUser($UserName);
682                     } else {
683                         return new _PersonalPagePassUser($UserName);
684                     }
685                 }
686                 else 
687                     // else use the page methods defined in _PassUser.
688                     return $this;
689             }
690         }
691     }
692
693     function getAuthDbh () {
694         global $request, $DBParams, $DBAuthParams;
695
696         // session restauration doesn't re-connect to the database automatically, so dirty it here.
697         if (($DBParams['dbtype'] == 'SQL') and isset($this->_auth_dbi) and empty($this->_auth_dbi->connection))
698             unset($this->_auth_dbi);
699         if (($DBParams['dbtype'] == 'ADODB') and isset($this->_auth_dbi) and empty($this->_auth_dbi->_connectionID))
700             unset($this->_auth_dbi);
701
702         if (empty($this->_auth_dbi)) {
703             if (empty($DBAuthParams['auth_dsn'])) {
704                 if ($DBParams['dbtype'] == 'SQL')
705                     $dbh = $request->getDbh(); // use phpwiki database 
706                 else 
707                     return false;
708             }
709             elseif ($DBAuthParams['auth_dsn'] == $DBParams['dsn'])
710                 $dbh = $request->getDbh(); // same phpwiki database 
711             else // use another external database handle. needs PHP >= 4.1
712                 $dbh = WikiDB::open($DBAuthParams);
713                 
714             $this->_auth_dbi =& $dbh->_backend->_dbh;    
715         }
716         return $this->_auth_dbi;
717     }
718
719     function prepare ($stmt, $variables) {
720         global $DBParams, $request;
721         // preparate the SELECT statement, for ADODB and PearDB (MDB not)
722         $this->getAuthDbh();
723         $place = ($DBParams['dbtype'] == 'ADODB') ? '%s' : '?';
724         if (is_array($variables)) {
725             $new = array();
726             foreach ($variables as $v) { $new[] = $place; }
727         } else {
728             $new = $place;
729         }
730         // probably prefix table names if in same database
731         if (!empty($DBParams['prefix']) and 
732             $this->_auth_dbi === $request->_dbi->_backend->_dbh) {
733             if (!stristr($DBParams['prefix'],$stmt)) {
734                 //Do it automatically for the lazy admin? Esp. on sf.net it's nice to have
735                 trigger_error("TODO: Need to prefix the DBAuthParam tablename in index.php: $stmt",
736                               E_USER_WARNING);
737                 $stmt = str_replace(array(" user "," pref "," member "),
738                                     array(" ".$prefix."user ",
739                                           " ".$prefix."prefs ",
740                                           " ".$prefix."member "),$stmt);
741             }
742         }
743         return $this->_auth_dbi->prepare(str_replace($variables,$new,$stmt));
744     }
745
746     //TODO: password changing
747     //TODO: email verification
748
749     function getPreferences() {
750         if ($this->_prefmethod == 'ADODB') {
751             _AdoDbPassUser::_AdoDbPassUser();
752             return _AdoDbPassUser::getPreferences();
753         } elseif ($this->_prefmethod == 'SQL') {
754             _PearDbPassUser::_PearDbPassUser();
755             return _PearDbPassUser::getPreferences();
756         }
757
758         // We don't necessarily have to read the cookie first. Since
759         // the user has a password, the prefs stored in the homepage
760         // cannot be arbitrarily altered by other Bogo users.
761         _AnonUser::getPreferences();
762         // User may have deleted cookie, retrieve from his
763         // PersonalPage if there is one.
764         if (! $this->_prefs && $this->_HomePagehandle) {
765             if ($restored_from_page = $this->_prefs->retrieve($this->_HomePagehandle->get('pref'))) {
766                 $this->_prefs = new UserPreferences($restored_from_page);
767                 return $this->_prefs;
768             }
769         }
770         return $this->_prefs;
771     }
772
773     function setPreferences($prefs, $id_only=false) {
774         if ($this->_prefmethod == 'ADODB') {
775             _AdoDbPassUser::_AdoDbPassUser();
776             return _AdoDbPassUser::setPreferences($prefs, $id_only);
777         }
778         elseif ($this->_prefmethod == 'SQL') {
779             _PearDbPassUser::_PearDbPassUser();
780             return _PearDbPassUser::setPreferences($prefs, $id_only);
781         }
782
783         _AnonUser::setPreferences($prefs, $id_only);
784         // Encode only the _prefs array of the UserPreference object
785         if (!is_object($prefs)) {
786             $prefs = new UserPreferences($prefs);
787         }
788         $packed = $prefs->store();
789         $unpacked = $prefs->unpack($packed);
790         if (count($unpacked)) {
791             global $request;
792             $this->_prefs = $prefs;
793             $request->_prefs =& $this->_prefs; 
794             $request->_user->_prefs =& $this->_prefs; 
795             //$request->setSessionVar('wiki_prefs', $this->_prefs);
796             $request->setSessionVar('wiki_user', $request->_user);
797         }
798         $this->_HomePagehandle->set('pref', $packed);
799         return count($unpacked);    
800     }
801
802     function mayChangePass() {
803         return true;
804     }
805
806     //The default method is getting the password from prefs. 
807     // child methods obtain $stored_password from external auth.
808     function userExists() {
809         //if ($this->_HomePagehandle) return true;
810         while ($user = $this->nextClass()) {
811               if ($user->userExists())
812                   return true;
813         }
814         return false;
815     }
816
817     //The default method is getting the password from prefs. 
818     // child methods obtain $stored_password from external auth.
819     function checkPass($submitted_password) {
820         $stored_password = $this->_prefs->get('passwd');
821         $result = $this->_checkPass($submitted_password, $stored_password);
822         if ($result) $this->_level = WIKIAUTH_USER;
823
824         if (!$result) {
825             if (USER_AUTH_POLICY === 'strict') {
826                 if ($user = $this->nextClass()) {
827                     if ($user = $user->userExists())
828                         return $user->checkPass($submitted_password);
829                 }
830             }
831             if (USER_AUTH_POLICY === 'stacked' or USER_AUTH_POLICY === 'old') {
832                 if ($user = $this->nextClass())
833                     return $user->checkPass($submitted_password);
834             }
835         }
836         return $this->_level;
837     }
838
839     //TODO: remove crypt() function check from config.php:396 ??
840     function _checkPass($submitted_password, $stored_password) {
841         if(!empty($submitted_password)) {
842             if (defined('ENCRYPTED_PASSWD') && ENCRYPTED_PASSWD) {
843                 // Verify against encrypted password.
844                 if (function_exists('crypt')) {
845                     if (crypt($submitted_password, $stored_password) == $stored_password )
846                         return true; // matches encrypted password
847                     else
848                         return false;
849                 }
850                 else {
851                     trigger_error(_("The crypt function is not available in this version of PHP.") . " "
852                                   . _("Please set ENCRYPTED_PASSWD to false in index.php and change ADMIN_PASSWD."),
853                                   E_USER_WARNING);
854                     return false;
855                 }
856             }
857             else {
858                 // Verify against cleartext password.
859                 if ($submitted_password == $stored_password)
860                     return true;
861                 else {
862                     // Check whether we forgot to enable ENCRYPTED_PASSWD
863                     if (function_exists('crypt')) {
864                         if (crypt($submitted_password, $stored_password) == $stored_password) {
865                             trigger_error(_("Please set ENCRYPTED_PASSWD to true in index.php."),
866                                           E_USER_WARNING);
867                             return true;
868                         }
869                     }
870                 }
871             }
872         }
873         return false;
874     }
875 }
876
877 class _BogoLoginUser
878 extends _PassUser
879 {
880     function userExists() {
881         if (isWikiWord($this->_userid)) {
882             $this->_level = WIKIAUTH_BOGO;
883             return true;
884         } else {
885             $this->_level = WIKIAUTH_ANON;
886             return false;
887         }
888     }
889
890     function checkPass($submitted_password) {
891         // A BogoLoginUser requires PASSWORD_LENGTH_MINIMUM.
892         if ($this->userExists())
893             return $this->_level;
894     }
895 }
896
897
898 class _PersonalPagePassUser
899 extends _PassUser
900 /**
901  * This class is only to simplify the auth method dispatcher.
902  * It inherits all methods from _PassUser.
903  */
904 {
905     function dummy() {}
906 }
907
908 class _DbPassUser
909 extends _PassUser
910 /**
911  * Authenticate against a database, to be able to use shared users.
912  *   internal: no different $DbAuthParams['dsn'] defined, or
913  *   external: different $DbAuthParams['dsn']
914  * The magic is done in the symbolic SQL statements in index.php
915  *
916  * We support only the SQL and ADODB backends.
917  * The other WikiDB backends (flat, cvs, dba, ...) should be used for pages, 
918  * not for auth stuff. If one would like to use e.g. dba for auth, he should 
919  * use PearDB (SQL) with the right $DBAuthParam['auth_dsn'].
920  * Flat files for auth use is handled by the auth method "File".
921  *
922  * Preferences are handled in the parent class.
923  */
924 {
925     var $_authselect, $_authupdate;
926
927     // This can only be called from _PassUser, because the parent class 
928     // sets the auth_dbi and pref methods, before this class is initialized.
929     function _DbPassUser($UserName='') {
930         if (!$this->_prefs)
931             _PassUser::_PassUser($UserName);
932         $this->_authmethod = 'DB';
933         $this->getAuthDbh();
934         $this->_auth_crypt_method = $GLOBALS['DBAuthParams']['auth_crypt_method'];
935
936         if ($GLOBALS['DBParams']['dbtype'] == 'ADODB') 
937             return new _AdoDbPassUser($UserName);
938         else 
939             return new _PearDbPassUser($UserName);
940     }
941
942     function mayChangePass() {
943         return !isset($this->_authupdate);
944     }
945
946 }
947
948 class _PearDbPassUser
949 extends _DbPassUser
950 /**
951  * Pear DB methods
952  */
953 {
954     function _PearDbPassUser($UserName='') {
955         global $DBAuthParams;
956         if (!$this->_prefs)
957             _PassUser::_PassUser($UserName);
958         $this->getAuthDbh();
959         $this->_auth_crypt_method = $GLOBALS['DBAuthParams']['auth_crypt_method'];
960         // Prepare the configured auth statements
961         if (!empty($DBAuthParams['auth_check']) and !@is_int($this->_authselect)) {
962             $this->_authselect = $this->_auth_dbi->prepare (
963                      str_replace(array('"$userid"','"$password"'),array('?','?'),
964                                   $DBAuthParams['auth_check'])
965                      );
966         }
967         if (!empty($DBAuthParams['auth_update']) and !@is_int($this->_authupdate)) {
968             $this->_authupdate = $this->_auth_dbi->prepare(
969                     str_replace(array('"$userid"','"$password"'),array('?','?'),
970                                 $DBAuthParams['auth_update'])
971                     );
972         }
973         return $this;
974     }
975
976     function getPreferences() {
977         // override the generic slow method here for efficiency and not to 
978         // clutter the homepage metadata with prefs.
979         _AnonUser::getPreferences();
980         $this->getAuthDbh();
981         if ((! $this->_prefs) && @is_int($this->_prefselect)) {
982             $db_result = $this->_auth_dbi->execute($this->_prefselect,$this->_userid);
983             list($prefs_blob) = $db_result->fetchRow();
984             if ($restored_from_db = $this->_prefs->retrieve($prefs_blob)) {
985                 $this->_prefs = new UserPreferences($restored_from_db);
986                 return $this->_prefs;
987             }
988         }
989         if ((! $this->_prefs) && $this->_HomePagehandle) {
990             if ($restored_from_page = $this->_prefs->retrieve($this->_HomePagehandle->get('pref'))) {
991                 $this->_prefs = new UserPreferences($restored_from_page);
992                 return $this->_prefs;
993             }
994         }
995         return $this->_prefs;
996     }
997
998     function setPreferences($prefs, $id_only=false) {
999         // Encode only the _prefs array of the UserPreference object
1000         $this->getAuthDbh();
1001         if (!is_object($prefs)) {
1002             $prefs = new UserPreferences($prefs);
1003         }
1004         $packed = $prefs->store();
1005         $unpacked = $prefs->unpack($packed);
1006         if (count($unpacked)) {
1007             global $request;
1008             $this->_prefs = $prefs;
1009             $request->_prefs =& $this->_prefs; 
1010             $request->_user->_prefs =& $this->_prefs; 
1011             //$request->setSessionVar('wiki_prefs', $this->_prefs);
1012             $request->setSessionVar('wiki_user', $request->_user);
1013         }
1014         if (@is_int($this->_prefupdate)) {
1015             $db_result = $this->_auth_dbi->execute($this->_prefupdate,
1016                                                    array($packed,$this->_userid));
1017         } else {
1018             _AnonUser::setPreferences($prefs, $id_only);
1019             $this->_HomePagehandle->set('pref', $packed);
1020         }
1021         return count($unpacked);
1022     }
1023
1024     function userExists() {
1025         if (!$this->_authselect)
1026             trigger_error("Either \$DBAuthParams['auth_check'] is missing or \$DBParams['dbtype'] != 'SQL'",
1027                           E_USER_WARNING);
1028         $this->getAuthDbh();
1029         $dbh = &$this->_auth_dbi;
1030         //NOTE: for auth_crypt_method='crypt' no special auth_user_exists is needed
1031         if ($this->_auth_crypt_method == 'crypt') {
1032             $rs = $dbh->Execute($this->_authselect,$this->_userid) ;
1033             if ($rs->numRows())
1034                 return true;
1035         }
1036         else {
1037             if (! $GLOBALS['DBAuthParams']['auth_user_exists'])
1038                 trigger_error("\$DBAuthParams['auth_user_exists'] is missing",
1039                               E_USER_WARNING);
1040             $this->_authcheck = str_replace('"$userid"','?',
1041                                              $GLOBALS['DBAuthParams']['auth_user_exists']);
1042             $rs = $dbh->Execute($this->_authcheck,$this->_userid) ;
1043             if ($rs->numRows())
1044                 return true;
1045         }
1046         
1047         if (USER_AUTH_POLICY === 'strict') {
1048             if ($user = $this->nextClass()) {
1049                 return $user->userExists();
1050             }
1051         }
1052     }
1053  
1054     function checkPass($submitted_password) {
1055         if (!@is_int($this->_authselect))
1056             trigger_error("Either \$DBAuthParams['auth_check'] is missing or \$DBParams['dbtype'] != 'SQL'",
1057                           E_USER_WARNING);
1058
1059         //NOTE: for auth_crypt_method='crypt'  defined('ENCRYPTED_PASSWD',true) must be set
1060         $this->getAuthDbh();
1061         if ($this->_auth_crypt_method == 'crypt') {
1062             $db_result = $this->_auth_dbi->execute($this->_authselect,$this->_userid);
1063             list($stored_password) = $db_result->fetchRow();
1064             $result = $this->_checkPass($submitted_password, $stored_password);
1065         } else {
1066             //Fixme: The prepared params get reversed somehow! 
1067             //cannot find the pear bug for now
1068             $db_result = $this->_auth_dbi->execute($this->_authselect,
1069                                                    array($submitted_password,$this->_userid));
1070             list($okay) = $db_result->fetchRow();
1071             $result = !empty($okay);
1072         }
1073
1074         if ($result) {
1075             $this->_level = WIKIAUTH_USER;
1076         } else {
1077             if (USER_AUTH_POLICY === 'strict') {
1078                 if ($user = $this->nextClass()) {
1079                     if ($user = $user->userExists())
1080                         return $user->checkPass($submitted_password);
1081                 }
1082             }
1083             if (USER_AUTH_POLICY === 'stacked' or USER_AUTH_POLICY === 'old') {
1084                 if ($user = $this->nextClass())
1085                     return $user->checkPass($submitted_password);
1086             }
1087         }
1088         return $this->_level;
1089     }
1090
1091     function storePass($submitted_password) {
1092         if (!@is_int($this->_authupdate)) {
1093             //CHECKME
1094             trigger_warning("Either \$DBAuthParams['auth_update'] not defined or \$DBParams['dbtype'] != 'SQL'",
1095                           E_USER_WARNING);
1096             return false;
1097         }
1098
1099         if ($this->_auth_crypt_method == 'crypt') {
1100             if (function_exists('crypt'))
1101                 $submitted_password = crypt($submitted_password);
1102         }
1103         //Fixme: The prepared params get reversed somehow! 
1104         //cannot find the pear bug for now
1105         $db_result = $this->_auth_dbi->execute($this->_authupdate,
1106                                                array($submitted_password,$this->_userid));
1107     }
1108
1109 }
1110
1111 class _AdoDbPassUser
1112 extends _DbPassUser
1113 /**
1114  * ADODB methods
1115  */
1116 {
1117     function _AdoDbPassUser($UserName='') {
1118         global $DBAuthParams;
1119         if (!$this->_prefs)
1120             _PassUser::_PassUser($UserName);
1121         $this->getAuthDbh();
1122         $this->_auth_crypt_method = $GLOBALS['DBAuthParams']['auth_crypt_method'];
1123         // Prepare the configured auth statements
1124         if (!empty($DBAuthParams['auth_check'])) {
1125             $this->_authselect = str_replace(array('"$userid"','"$password"'),array('%s','%s'),
1126                                               $DBAuthParams['auth_check']);
1127         }
1128         if (!empty($DBAuthParams['auth_update'])) {
1129             $this->_authupdate = str_replace(array('"$userid"','"$password"'),array("%s","%s"),
1130                                               $DBAuthParams['auth_update']);
1131         }
1132         return $this;
1133     }
1134
1135     function getPreferences() {
1136         // override the generic slow method here for efficiency
1137         _AnonUser::getPreferences();
1138         $this->getAuthDbh();
1139         if ((! $this->_prefs) and isset($this->_prefselect)) {
1140             $dbh = & $this->_auth_dbi;
1141             $rs = $dbh->Execute(sprintf($this->_prefselect,$dbh->qstr($this->_userid)));
1142             if ($rs->EOF) {
1143                 $rs->Close();
1144             } else {
1145                 $prefs_blob = $rs->fields['pref_blob'];
1146                 $rs->Close();
1147                 if ($restored_from_db = $this->_prefs->retrieve($prefs_blob)) {
1148                     $this->_prefs = new UserPreferences($restored_from_db);
1149                     return $this->_prefs;
1150                 }
1151             }
1152         }
1153         if ((! $this->_prefs) && $this->_HomePagehandle) {
1154             if ($restored_from_page = $this->_prefs->retrieve($this->_HomePagehandle->get('pref'))) {
1155                 $this->_prefs = new UserPreferences($restored_from_page);
1156                 return $this->_prefs;
1157             }
1158         }
1159         return $this->_prefs;
1160     }
1161
1162     function setPreferences($prefs, $id_only=false) {
1163         if (!is_object($prefs)) {
1164             $prefs = new UserPreferences($prefs);
1165         }
1166         $this->getAuthDbh();
1167         $packed = $prefs->store();
1168         $unpacked = $prefs->unpack($packed);
1169         if (count($unpacked)) {
1170             global $request;
1171             $this->_prefs = $prefs;
1172             $request->_prefs =& $this->_prefs; 
1173             $request->_user->_prefs =& $this->_prefs; 
1174             //$request->setSessionVar('wiki_prefs', $this->_prefs);
1175             $request->setSessionVar('wiki_user', $request->_user);
1176         }
1177         if (isset($this->_prefupdate)) {
1178             $dbh = & $this->_auth_dbi;
1179             $db_result = $dbh->Execute(sprintf($this->_prefupdate,
1180                                                $dbh->qstr($packed),$dbh->qstr($this->_userid)));
1181             $db_result->Close();
1182         } else {
1183             _AnonUser::setPreferences($prefs, $id_only);
1184             $this->_HomePagehandle->set('pref', $serialized);
1185         }
1186         return count($unpacked);
1187     }
1188  
1189     function userExists() {
1190         if (!$this->_authselect)
1191             trigger_error("Either \$DBAuthParams['auth_check'] is missing or \$DBParams['dbtype'] != 'ADODB'",
1192                           E_USER_WARNING);
1193         $this->getAuthDbh();
1194         $dbh = &$this->_auth_dbi;
1195         //NOTE: for auth_crypt_method='crypt' no special auth_user_exists is needed
1196         if ($this->_auth_crypt_method == 'crypt') {
1197             $rs = $dbh->Execute(sprintf($this->_authselect,$dbh->qstr($this->_userid)));
1198             if (!$rs->EOF) {
1199                 $rs->Close();
1200                 return true;
1201             } else {
1202                 $rs->Close();
1203             }
1204         }
1205         else {
1206             if (! $GLOBALS['DBAuthParams']['auth_user_exists'])
1207                 trigger_error("\$DBAuthParams['auth_user_exists'] is missing",
1208                               E_USER_WARNING);
1209             $this->_authcheck = str_replace('"$userid"','%s',
1210                                              $GLOBALS['DBAuthParams']['auth_user_exists']);
1211             $rs = $dbh->Execute(sprintf($this->_authcheck,$dbh->qstr($this->_userid)));
1212             if (!$rs->EOF) {
1213                 $rs->Close();
1214                 return true;
1215             } else {
1216                 $rs->Close();
1217             }
1218         }
1219         
1220         if (USER_AUTH_POLICY === 'strict') {
1221             if ($user = $this->nextClass())
1222                 return $user->userExists();
1223         }
1224         return false;
1225     }
1226
1227     function checkPass($submitted_password) {
1228         if (!isset($this->_authselect))
1229             trigger_error("Either \$DBAuthParams['auth_check'] is missing or \$DBParams['dbtype'] != 'ADODB'",
1230                           E_USER_WARNING);
1231         $this->getAuthDbh();
1232         $dbh = &$this->_auth_dbi;
1233         //NOTE: for auth_crypt_method='crypt'  defined('ENCRYPTED_PASSWD',true) must be set
1234         if ($this->_auth_crypt_method == 'crypt') {
1235             $rs = $dbh->Execute(sprintf($this->_authselect,$dbh->qstr($this->_userid)));
1236             if (!$rs->EOF) {
1237                 $stored_password = $rs->fields['password'];
1238                 $rs->Close();
1239                 $result = $this->_checkPass($submitted_password, $stored_password);
1240             } else {
1241                 $rs->Close();
1242                 $result = false;
1243             }
1244         }
1245         else {
1246             $rs = $dbh->Execute(sprintf($this->_authselect,
1247                                         $dbh->qstr($submitted_password),
1248                                         $dbh->qstr($this->_userid)));
1249             $okay = $rs->fields['ok'];
1250             $rs->Close();
1251             $result = !empty($okay);
1252         }
1253
1254         if ($result) { 
1255             $this->_level = WIKIAUTH_USER;
1256         } else {
1257             if (USER_AUTH_POLICY === 'strict') {
1258                 if ($user = $this->nextClass()) {
1259                     if ($user = $user->userExists())
1260                         return $user->checkPass($submitted_password);
1261                 }
1262             }
1263             if (USER_AUTH_POLICY === 'stacked' or USER_AUTH_POLICY === 'old') {
1264                 if ($user = $this->nextClass())
1265                     return $user->checkPass($submitted_password);
1266             }
1267         }
1268         return $this->_level;
1269     }
1270
1271     function storePass($submitted_password) {
1272         if (!isset($this->_authupdate)) {
1273             //CHECKME
1274             trigger_warning("Either \$DBAuthParams['auth_update'] not defined or \$DBParams['dbtype'] != 'ADODB'",
1275                           E_USER_WARNING);
1276             return false;
1277         }
1278
1279         if ($this->_auth_crypt_method == 'crypt') {
1280             if (function_exists('crypt'))
1281                 $submitted_password = crypt($submitted_password);
1282         }
1283         $this->getAuthDbh();
1284         $dbh = &$this->_auth_dbi;
1285         $rs = $dbh->Execute(sprintf($this->_authupdate,
1286                                     $dbh->qstr($submitted_password),
1287                                     $dbh->qstr($this->_userid)));
1288         $rs->Close();
1289     }
1290
1291 }
1292
1293 class _LDAPPassUser
1294 extends _PassUser
1295 /**
1296  * Define the vars LDAP_HOST and LDAP_BASE_DN in index.php
1297  *
1298  * Preferences are handled in _PassUser
1299  */
1300 {
1301     function checkPass($submitted_password) {
1302         $this->_authmethod = 'LDAP';
1303         $userid = $this->_userid;
1304         if ($ldap = ldap_connect(LDAP_AUTH_HOST)) { // must be a valid LDAP server!
1305             $r = @ldap_bind($ldap); // this is an anonymous bind
1306             // Need to set the right root search information. see ../index.php
1307             $sr = ldap_search($ldap, LDAP_BASE_DN, "uid=$userid");
1308             $info = ldap_get_entries($ldap, $sr); // there may be more hits with this userid. try every
1309             for ($i = 0; $i < $info["count"]; $i++) {
1310                 $dn = $info[$i]["dn"];
1311                 // The password is still plain text.
1312                 if ($r = @ldap_bind($ldap, $dn, $passwd)) {
1313                     // ldap_bind will return TRUE if everything matches
1314                     ldap_close($ldap);
1315                     $this->_level = WIKIAUTH_USER;
1316                     return $this->_level;
1317                 }
1318             }
1319         } else {
1320             trigger_error(_("Unable to connect to LDAP server "). LDAP_AUTH_HOST, E_USER_WARNING);
1321         }
1322
1323         if (USER_AUTH_POLICY === 'strict') {
1324             if ($user = $this->nextClass()) {
1325                 if ($user = $user->userExists())
1326                     return $user->checkPass($submitted_password);
1327             }
1328         }
1329         if (USER_AUTH_POLICY === 'stacked' or USER_AUTH_POLICY === 'old') {
1330             if ($user = $this->nextClass())
1331                 return $user->checkPass($submitted_password);
1332         }
1333         return false;
1334     }
1335
1336     function userExists() {
1337         $userid = $this->_userid;
1338         if ($ldap = ldap_connect(LDAP_AUTH_HOST)) { // must be a valid LDAP server!
1339             $r = @ldap_bind($ldap);                 // this is an anonymous bind
1340             $sr = ldap_search($ldap, LDAP_BASE_DN, "uid=$userid");
1341             $info = ldap_get_entries($ldap, $sr);
1342             if ($info["count"] > 0) {
1343                 ldap_close($ldap);
1344                 return true;
1345             }
1346         } else {
1347             trigger_error(_("Unable to connect to LDAP server "). LDAP_AUTH_HOST, E_USER_WARNING);
1348         }
1349
1350         if (USER_AUTH_POLICY === 'strict') {
1351             if ($user = $this->nextClass())
1352                 return $user->userExists();
1353         }
1354         return false;
1355     }
1356
1357     function mayChangePass() {
1358         return false;
1359     }
1360
1361 }
1362
1363 class _IMAPPassUser
1364 extends _PassUser
1365 /**
1366  * Define the var IMAP_HOST in index.php
1367  *
1368  * Preferences are handled in _PassUser
1369  */
1370 {
1371     function checkPass($submitted_password) {
1372         $userid = $this->_userid;
1373         $mbox = @imap_open( "{" . IMAP_AUTH_HOST . "}",
1374                             $userid, $submitted_password, OP_HALFOPEN );
1375         if ($mbox) {
1376             imap_close($mbox);
1377             $this->_authmethod = 'IMAP';
1378             $this->_level = WIKIAUTH_USER;
1379             return $this->_level;
1380         } else {
1381             trigger_error(_("Unable to connect to IMAP server "). IMAP_AUTH_HOST, E_USER_WARNING);
1382         }
1383         if (USER_AUTH_POLICY === 'strict') {
1384             if ($user = $this->nextClass()) {
1385                 if ($user = $user->userExists())
1386                     return $user->checkPass($submitted_password);
1387             }
1388         }
1389         if (USER_AUTH_POLICY === 'stacked' or USER_AUTH_POLICY === 'old') {
1390             if ($user = $this->nextClass())
1391                 return $user->checkPass($submitted_password);
1392         }
1393         return false;
1394     }
1395
1396     //CHECKME: this will not be okay for the auth policy strict
1397     function userExists() {
1398         if (checkPass($this->_prefs->get('passwd')))
1399             return true;
1400             
1401         if (USER_AUTH_POLICY === 'strict') {
1402             if ($user = $this->nextClass())
1403                 return $user->userExists();
1404         }
1405     }
1406
1407     function mayChangePass() {
1408         return false;
1409     }
1410
1411 }
1412
1413 class _FilePassUser
1414 extends _PassUser
1415 /**
1416  * Check users defined in a .htaccess style file
1417  * username:crypt\n...
1418  *
1419  * Preferences are handled in _PassUser
1420  */
1421 {
1422     var $_file, $_may_change;
1423
1424     // This can only be called from _PassUser, because the parent class 
1425     // sets the pref methods, before this class is initialized.
1426     function _FilePassUser($UserName='',$file='') {
1427         if (!$this->_prefs)
1428             _PassUser::_PassUser($UserName);
1429
1430         // read the .htaccess style file. We use our own copy of the standard pear class.
1431         require 'lib/pear/File_Passwd.php';
1432         // if passwords may be changed we have to lock them:
1433         $this->_may_change = defined('AUTH_USER_FILE_STORABLE') && AUTH_USER_FILE_STORABLE;
1434         if (empty($file) and defined('AUTH_USER_FILE'))
1435             $this->_file = File_Passwd(AUTH_USER_FILE, !empty($this->_may_change));
1436         elseif (!empty($file))
1437             $this->_file = File_Passwd($file, !empty($this->_may_change));
1438         else
1439             return false;
1440         return $this;
1441     }
1442  
1443     function mayChangePass() {
1444         return $this->_may_change;
1445     }
1446
1447     function userExists() {
1448         if (isset($this->_file->users[$this->_userid]))
1449             return true;
1450             
1451         if (USER_AUTH_POLICY === 'strict') {
1452             if ($user = $this->nextClass())
1453                 return $user->userExists();
1454         }
1455     }
1456
1457     function checkPass($submitted_password) {
1458         if ($this->_file->verifyPassword($this->_userid,$submitted_password)) {
1459             $this->_authmethod = 'File';
1460             $this->_level = WIKIAUTH_USER;
1461             return $this->_level;
1462         }
1463         
1464         if (USER_AUTH_POLICY === 'strict') {
1465             if ($user = $this->nextClass()) {
1466                 if ($user = $user->userExists())
1467                     return $user->checkPass($submitted_password);
1468             }
1469         }
1470         if (USER_AUTH_POLICY === 'stacked' or USER_AUTH_POLICY === 'old') {
1471             if ($user = $this->nextClass())
1472                 return $user->checkPass($submitted_password);
1473         }
1474         return false;
1475     }
1476
1477     function storePass($submitted_password) {
1478         if ($this->_may_change)
1479             return $this->_file->modUser($this->_userid,$submitted_password);
1480         else 
1481             return false;
1482     }
1483
1484 }
1485
1486 /**
1487  * Insert more auth classes here...
1488  *
1489  */
1490
1491
1492 /**
1493  * For security, this class should not be extended. Instead, extend
1494  * from _PassUser (think of this as unix "root").
1495  */
1496 class _AdminUser
1497 extends _PassUser
1498 {
1499     //var $_level = WIKIAUTH_ADMIN;
1500
1501     function checkPass($submitted_password) {
1502         $stored_password = ADMIN_PASSWD;
1503         if ($this->_checkPass($submitted_password, $stored_password)) {
1504             $this->_level = WIKIAUTH_ADMIN;
1505             return $this->_level;
1506         } else {
1507             $this->_level = WIKIAUTH_ANON;
1508             return false;
1509         }
1510     }
1511
1512 }
1513
1514 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1515 /**
1516  * Various data classes for the preference types, 
1517  * to support get, set, sanify (range checking, ...)
1518  * update() will do the neccessary side-effects if a 
1519  * setting gets changed (theme, language, ...)
1520 */
1521
1522 class _UserPreference
1523 {
1524     var $default_value;
1525
1526     function _UserPreference ($default_value) {
1527         $this->default_value = $default_value;
1528     }
1529
1530     function sanify ($value) {
1531         return (string)$value;
1532     }
1533
1534     function get ($name) {
1535         if (isset($this->{$name}))
1536             return $this->{$name};
1537         else 
1538             return $this->default_value;
1539     }
1540
1541     function getraw ($name) {
1542         if (!empty($this->{$name}))
1543             return $this->{$name};
1544     }
1545
1546     // stores the value as $this->$name, and not as $this->value (clever?)
1547     function set ($name, $value) {
1548         if ($this->get($name) != $value) {
1549             $this->update($value);
1550         }
1551         if ($value != $this->default_value) {
1552             $this->{$name} = $value;
1553         }
1554         else 
1555             unset($this->{$name});
1556     }
1557
1558     // default: no side-effects 
1559     function update ($value) {
1560         ;
1561     }
1562 }
1563
1564 class _UserPreference_numeric
1565 extends _UserPreference
1566 {
1567     function _UserPreference_numeric ($default, $minval = false,
1568                                       $maxval = false) {
1569         $this->_UserPreference((double)$default);
1570         $this->_minval = (double)$minval;
1571         $this->_maxval = (double)$maxval;
1572     }
1573
1574     function sanify ($value) {
1575         $value = (double)$value;
1576         if ($this->_minval !== false && $value < $this->_minval)
1577             $value = $this->_minval;
1578         if ($this->_maxval !== false && $value > $this->_maxval)
1579             $value = $this->_maxval;
1580         return $value;
1581     }
1582 }
1583
1584 class _UserPreference_int
1585 extends _UserPreference_numeric
1586 {
1587     function _UserPreference_int ($default, $minval = false, $maxval = false) {
1588         $this->_UserPreference_numeric((int)$default, (int)$minval,
1589                                        (int)$maxval);
1590     }
1591
1592     function sanify ($value) {
1593         return (int)parent::sanify((int)$value);
1594     }
1595 }
1596
1597 class _UserPreference_bool
1598 extends _UserPreference
1599 {
1600     function _UserPreference_bool ($default = false) {
1601         $this->_UserPreference((bool)$default);
1602     }
1603
1604     function sanify ($value) {
1605         if (is_array($value)) {
1606             /* This allows for constructs like:
1607              *
1608              *   <input type="hidden" name="pref[boolPref][]" value="0" />
1609              *   <input type="checkbox" name="pref[boolPref][]" value="1" />
1610              *
1611              * (If the checkbox is not checked, only the hidden input
1612              * gets sent. If the checkbox is sent, both inputs get
1613              * sent.)
1614              */
1615             foreach ($value as $val) {
1616                 if ($val)
1617                     return true;
1618             }
1619             return false;
1620         }
1621         return (bool) $value;
1622     }
1623 }
1624
1625 class _UserPreference_language
1626 extends _UserPreference
1627 {
1628     function _UserPreference_language ($default = DEFAULT_LANGUAGE) {
1629         $this->_UserPreference($default);
1630     }
1631
1632     // FIXME: check for valid locale
1633     function sanify ($value) {
1634         // Revert to DEFAULT_LANGUAGE if user does not specify
1635         // language in UserPreferences or chooses <system language>.
1636         if ($value == '' or empty($value))
1637             $value = DEFAULT_LANGUAGE;
1638
1639         return (string) $value;
1640     }
1641 }
1642
1643 class _UserPreference_theme
1644 extends _UserPreference
1645 {
1646     function _UserPreference_theme ($default = THEME) {
1647         $this->_UserPreference($default);
1648     }
1649
1650     function sanify ($value) {
1651         if (file_exists($this->_themefile($value)))
1652             return $value;
1653         return $this->default_value;
1654     }
1655
1656     function update ($newvalue) {
1657         global $Theme;
1658         include_once($this->_themefile($newvalue));
1659         if (empty($Theme))
1660             include_once($this->_themefile(THEME));
1661     }
1662
1663     function _themefile ($theme) {
1664         return "themes/$theme/themeinfo.php";
1665     }
1666 }
1667
1668 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1669
1670 /**
1671  * UserPreferences
1672  * 
1673  * This object holds the $request->_prefs subobjects.
1674  * A simple packed array of non-default values get's stored as cookie,
1675  * homepage, or database, which are converted to the array of 
1676  * ->_prefs objects.
1677  * We don't store the objects, because otherwise we will
1678  * not be able to upgrade any subobject. And it's a waste of space also.
1679  */
1680 class UserPreferences
1681 {
1682     function UserPreferences ($saved_prefs = false) {
1683         // userid stored too, to ensure the prefs are being loaded for
1684         // the correct (currently signing in) userid if stored in a
1685         // cookie.
1686         $this->_prefs
1687             = array(
1688                     'userid'        => new _UserPreference(''),
1689                     'passwd'        => new _UserPreference(''),
1690                     'autologin'     => new _UserPreference_bool(),
1691                     'email'         => new _UserPreference(''),
1692                     'emailVerified' => new _UserPreference_bool(),
1693                     'notifyPages'   => new _UserPreference(''),
1694                     'theme'         => new _UserPreference_theme(THEME),
1695                     'lang'          => new _UserPreference_language(DEFAULT_LANGUAGE),
1696                     'editWidth'     => new _UserPreference_int(EDITWIDTH_DEFAULT_COLS,
1697                                                                EDITWIDTH_MIN_COLS,
1698                                                                EDITWIDTH_MAX_COLS),
1699                     'noLinkIcons'   => new _UserPreference_bool(),
1700                     'editHeight'    => new _UserPreference_int(EDITHEIGHT_DEFAULT_ROWS,
1701                                                                EDITHEIGHT_MIN_ROWS,
1702                                                                EDITHEIGHT_DEFAULT_ROWS),
1703                     'timeOffset'    => new _UserPreference_numeric(TIMEOFFSET_DEFAULT_HOURS,
1704                                                                    TIMEOFFSET_MIN_HOURS,
1705                                                                    TIMEOFFSET_MAX_HOURS),
1706                     'relativeDates' => new _UserPreference_bool()
1707                     );
1708
1709         if (is_array($saved_prefs)) {
1710             foreach ($saved_prefs as $name => $value)
1711                 $this->set($name, $value);
1712         }
1713     }
1714
1715     function _getPref ($name) {
1716         if (!isset($this->_prefs[$name])) {
1717             if ($name == 'passwd2') return false;
1718             trigger_error("$name: unknown preference", E_USER_NOTICE);
1719             return false;
1720         }
1721         return $this->_prefs[$name];
1722     }
1723     
1724     // get the value or default_value of the subobject
1725     function get ($name) {
1726         if ($_pref = $this->_getPref($name))
1727           return $_pref->get($name);
1728         else 
1729           return false;  
1730         /*      
1731         if (is_object($this->_prefs[$name]))
1732             return $this->_prefs[$name]->get($name);
1733         elseif (($value = $this->_getPref($name)) === false)
1734             return false;
1735         elseif (!isset($value))
1736             return $this->_prefs[$name]->default_value;
1737         else return $value;
1738         */
1739     }
1740
1741     // check and set the new value in the subobject
1742     function set ($name, $value) {
1743         $pref = $this->_getPref($name);
1744         if ($pref === false)
1745             return false;
1746
1747         /* do it here or outside? */
1748         if ($name == 'passwd' and 
1749             defined('PASSWORD_LENGTH_MINIMUM') and 
1750             strlen($value) <= PASSWORD_LENGTH_MINIMUM ) {
1751             //TODO: How to notify the user?
1752             return false;
1753         }
1754
1755         $newvalue = $pref->sanify($value);
1756         $pref->set($name,$newvalue);
1757         $this->_prefs[$name] = $pref;
1758         return true;
1759
1760         // don't set default values to save space (in cookies, db and
1761         // sesssion)
1762         /*
1763         if ($value == $pref->default_value)
1764             unset($this->_prefs[$name]);
1765         else
1766             $this->_prefs[$name] = $pref;
1767         */
1768     }
1769
1770     // array of objects => array of values
1771     function store() {
1772         $prefs = array();
1773         foreach ($this->_prefs as $name => $object) {
1774             if ($value = $object->getraw($name))
1775                 $prefs[] = array($name => $value);
1776         }
1777         return $this->pack($prefs);
1778     }
1779
1780     // packed string or array of values => array of values
1781     function retrieve($packed) {
1782         if (is_string($packed) and (substr($packed, 0, 2) == "a:"))
1783             $packed = unserialize($packed);
1784         if (!is_array($packed)) return false;
1785         $prefs = array();
1786         foreach ($packed as $name => $packed_pref) {
1787             if (substr($packed_pref, 0, 2) == "O:") {
1788                 //legacy: check if it's an old array of objects
1789                 // Looks like a serialized object. 
1790                 // This might fail if the object definition does not exist anymore.
1791                 // object with ->$name and ->default_value vars.
1792                 $pref = unserialize($packed_pref);
1793                 $prefs[$name] = $pref->get($name);
1794             } else {
1795                 $prefs[$name] = unserialize($packed_pref);
1796             }
1797         }
1798         return $prefs;
1799     }
1800     
1801     // array of objects
1802     function getAll() {
1803         return $this->_prefs;
1804     }
1805
1806     function pack($nonpacked) {
1807         return serialize($nonpacked);
1808     }
1809
1810     function unpack($packed) {
1811         if (!$packed)
1812             return false;
1813         if (substr($packed, 0, 2) == "O:") {
1814             // Looks like a serialized object
1815             return unserialize($packed);
1816         }
1817         if (substr($packed, 0, 2) == "a:") {
1818             return unserialize($packed);
1819         }
1820         //trigger_error("DEBUG: Can't unpack bad UserPreferences",
1821         //E_USER_WARNING);
1822         return false;
1823     }
1824
1825     function hash () {
1826         return hash($this->_prefs);
1827     }
1828 }
1829
1830 class CookieUserPreferences
1831 extends UserPreferences
1832 {
1833     function CookieUserPreferences ($saved_prefs = false) {
1834         UserPreferences::UserPreferences($saved_prefs);
1835     }
1836 }
1837
1838 class PageUserPreferences
1839 extends UserPreferences
1840 {
1841     function PageUserPreferences ($saved_prefs = false) {
1842         UserPreferences::UserPreferences($saved_prefs);
1843     }
1844 }
1845
1846 class PearDbUserPreferences
1847 extends UserPreferences
1848 {
1849     function PearDbUserPreferences ($saved_prefs = false) {
1850         UserPreferences::UserPreferences($saved_prefs);
1851     }
1852 }
1853
1854 class AdoDbUserPreferences
1855 extends UserPreferences
1856 {
1857     function AdoDbUserPreferences ($saved_prefs = false) {
1858         UserPreferences::UserPreferences($saved_prefs);
1859     }
1860     function getPreferences() {
1861         // override the generic slow method here for efficiency
1862         _AnonUser::getPreferences();
1863         $this->getAuthDbh();
1864         if ((! $this->_prefs) and isset($this->_prefselect)) {
1865             $dbh = & $this->_auth_dbi;
1866             $rs = $dbh->Execute(sprintf($this->_prefselect,$dbh->qstr($this->_userid)));
1867             if ($rs->EOF) {
1868                 $rs->Close();
1869             } else {
1870                 $prefs_blob = $rs->fields['pref_blob'];
1871                 $rs->Close();
1872                 if ($restored_from_db = $this->_prefs->retrieve($prefs_blob)) {
1873                     $this->_prefs = new UserPreferences($restored_from_db);
1874                     return $this->_prefs;
1875                 }
1876             }
1877         }
1878         if ((! $this->_prefs) && $this->_HomePagehandle) {
1879             if ($restored_from_page = $this->_prefs->retrieve($this->_HomePagehandle->get('pref'))) {
1880                 $this->_prefs = new UserPreferences($restored_from_page);
1881                 return $this->_prefs;
1882             }
1883         }
1884         return $this->_prefs;
1885     }
1886 }
1887
1888
1889 // $Log: not supported by cvs2svn $
1890 // Revision 1.14  2004/02/15 17:30:13  rurban
1891 // workaround for lost db connnection handle on session restauration (->_auth_dbi)
1892 // fixed getPreferences() (esp. from sessions)
1893 // fixed setPreferences() (update and set),
1894 // fixed AdoDb DB statements,
1895 // update prefs only at UserPreferences POST (for testing)
1896 // unified db prefs methods (but in external pref classes yet)
1897 //
1898 // Revision 1.13  2004/02/09 03:58:12  rurban
1899 // for now default DB_SESSION to false
1900 // PagePerm:
1901 //   * not existing perms will now query the parent, and not
1902 //     return the default perm
1903 //   * added pagePermissions func which returns the object per page
1904 //   * added getAccessDescription
1905 // WikiUserNew:
1906 //   * added global ->prepare (not yet used) with smart user/pref/member table prefixing.
1907 //   * force init of authdbh in the 2 db classes
1908 // main:
1909 //   * fixed session handling (not triple auth request anymore)
1910 //   * don't store cookie prefs with sessions
1911 // stdlib: global obj2hash helper from _AuthInfo, also needed for PagePerm
1912 //
1913 // Revision 1.12  2004/02/07 10:41:25  rurban
1914 // fixed auth from session (still double code but works)
1915 // fixed GroupDB
1916 // fixed DbPassUser upgrade and policy=old
1917 // added GroupLdap
1918 //
1919 // Revision 1.11  2004/02/03 09:45:39  rurban
1920 // LDAP cleanup, start of new Pref classes
1921 //
1922 // Revision 1.10  2004/02/01 09:14:11  rurban
1923 // Started with Group_Ldap (not yet ready)
1924 // added new _AuthInfo plugin to help in auth problems (warning: may display passwords)
1925 // fixed some configurator vars
1926 // renamed LDAP_AUTH_SEARCH to LDAP_BASE_DN
1927 // changed PHPWIKI_VERSION from 1.3.8a to 1.3.8pre
1928 // USE_DB_SESSION defaults to true on SQL
1929 // changed GROUP_METHOD definition to string, not constants
1930 // changed sample user DBAuthParams from UPDATE to REPLACE to be able to
1931 //   create users. (Not to be used with external databases generally, but
1932 //   with the default internal user table)
1933 //
1934 // fixed the IndexAsConfigProblem logic. this was flawed:
1935 //   scripts which are the same virtual path defined their own lib/main call
1936 //   (hmm, have to test this better, phpwiki.sf.net/demo works again)
1937 //
1938 // Revision 1.9  2004/01/30 19:57:58  rurban
1939 // fixed DBAuthParams['pref_select']: wrong _auth_dbi object used.
1940 //
1941 // Revision 1.8  2004/01/30 18:46:15  rurban
1942 // fix "lib/WikiUserNew.php:572: Notice[8]: Undefined variable: DBParams"
1943 //
1944 // Revision 1.7  2004/01/27 23:23:39  rurban
1945 // renamed ->Username => _userid for consistency
1946 // renamed mayCheckPassword => mayCheckPass
1947 // fixed recursion problem in WikiUserNew
1948 // fixed bogo login (but not quite 100% ready yet, password storage)
1949 //
1950 // Revision 1.6  2004/01/26 09:17:49  rurban
1951 // * changed stored pref representation as before.
1952 //   the array of objects is 1) bigger and 2)
1953 //   less portable. If we would import packed pref
1954 //   objects and the object definition was changed, PHP would fail.
1955 //   This doesn't happen with an simple array of non-default values.
1956 // * use $prefs->retrieve and $prefs->store methods, where retrieve
1957 //   understands the interim format of array of objects also.
1958 // * simplified $prefs->get() and fixed $prefs->set()
1959 // * added $user->_userid and class '_WikiUser' portability functions
1960 // * fixed $user object ->_level upgrading, mostly using sessions.
1961 //   this fixes yesterdays problems with loosing authorization level.
1962 // * fixed WikiUserNew::checkPass to return the _level
1963 // * fixed WikiUserNew::isSignedIn
1964 // * added explodePageList to class PageList, support sortby arg
1965 // * fixed UserPreferences for WikiUserNew
1966 // * fixed WikiPlugin for empty defaults array
1967 // * UnfoldSubpages: added pagename arg, renamed pages arg,
1968 //   removed sort arg, support sortby arg
1969 //
1970 // Revision 1.5  2004/01/25 03:05:00  rurban
1971 // First working version, but has some problems with the current main loop.
1972 // Implemented new auth method dispatcher and policies, all the external
1973 // _PassUser classes (also for ADODB and Pear DB).
1974 // The two global funcs UserExists() and CheckPass() are probably not needed,
1975 // since the auth loop is done recursively inside the class code, upgrading
1976 // the user class within itself.
1977 // Note: When a higher user class is returned, this doesn't mean that the user
1978 // is authorized, $user->_level is still low, and only upgraded on successful
1979 // login.
1980 //
1981 // Revision 1.4  2003/12/07 19:29:48  carstenklapp
1982 // Code Housecleaning: fixed syntax errors. (php -l *.php)
1983 //
1984 // Revision 1.3  2003/12/06 19:10:46  carstenklapp
1985 // Finished off logic for determining user class, including
1986 // PassUser. Removed ability of BogoUser to save prefs into a page.
1987 //
1988 // Revision 1.2  2003/12/03 21:45:48  carstenklapp
1989 // Added admin user, password user, and preference classes. Added
1990 // password checking functions for users and the admin. (Now the easy
1991 // parts are nearly done).
1992 //
1993 // Revision 1.1  2003/12/02 05:46:36  carstenklapp
1994 // Complete rewrite of WikiUser.php.
1995 //
1996 // This should make it easier to hook in user permission groups etc. some
1997 // time in the future. Most importantly, to finally get UserPreferences
1998 // fully working properly for all classes of users: AnonUser, BogoUser,
1999 // AdminUser; whether they have a NamesakePage (PersonalHomePage) or not,
2000 // want a cookie or not, and to bring back optional AutoLogin with the
2001 // UserName stored in a cookie--something that was lost after PhpWiki had
2002 // dropped the default http auth login method.
2003 //
2004 // Added WikiUser classes which will (almost) work together with existing
2005 // UserPreferences class. Other parts of PhpWiki need to be updated yet
2006 // before this code can be hooked up.
2007 //
2008
2009 // Local Variables:
2010 // mode: php
2011 // tab-width: 8
2012 // c-basic-offset: 4
2013 // c-hanging-comment-ender-p: nil
2014 // indent-tabs-mode: nil
2015 // End:
2016 ?>