2 rcs_id('$Id: WikiUserNew.php,v 1.78 2004-05-27 17:49:06 rurban Exp $');
3 /* Copyright (C) 2004 $ThePhpWikiProgrammingTeam
5 * This file is part of PhpWiki.
7 * PhpWiki is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * PhpWiki is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with PhpWiki; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * This is a complete OOP rewrite of the old WikiUser code with various
23 * configurable external authentication methods.
25 * There's only one entry point, the function WikiUser which returns
26 * a WikiUser object, which contains the name, authlevel and user's preferences.
27 * This object might get upgraded during the login step and later also.
28 * There exist three preferences storage methods: cookie, homepage and db,
29 * and multiple password checking methods.
30 * See index.php for $USER_AUTH_ORDER[] and USER_AUTH_POLICY if
31 * ALLOW_USER_PASSWORDS is defined.
33 * Each user object must define the two preferences methods
34 * getPreferences(), setPreferences(),
35 * and the following 1-4 auth methods
36 * checkPass() must be defined by all classes,
37 * userExists() only if USER_AUTH_POLICY'=='strict'
38 * mayChangePass() only if the password is storable.
39 * storePass() only if the password is storable.
41 * WikiUser() given no name, returns an _AnonUser (anonymous user)
42 * object, who may or may not have a cookie.
43 * However, if the there's a cookie with the userid or a session,
44 * the user is upgraded to the matching user object.
45 * Given a user name, returns a _BogoUser object, who may or may not
46 * have a cookie and/or PersonalPage, one of the various _PassUser objects
47 * or an _AdminUser object.
48 * BTW: A BogoUser is a userid (loginname) as valid WikiWord, who might
49 * have stored a password or not. If so, his account is secure, if not
50 * anybody can use it, because the username is visible e.g. in RecentChanges.
52 * Takes care of passwords, all preference loading/storing in the
53 * user's page and any cookies. lib/main.php will query the user object to
54 * verify the password as appropriate.
56 * @author: Reini Urban (the tricky parts),
57 * Carsten Klapp (started rolling the ball)
59 * Random architectural notes, sorted by date:
61 * Test it by defining ENABLE_USER_NEW in index.php
62 * 1) Now a ForbiddenUser is returned instead of false.
63 * 2) Previously ALLOW_ANON_USER = false meant that anon users cannot edit,
64 * but may browse. Now with ALLOW_ANON_USER = false he may not browse,
65 * which is needed to disable browse PagePermissions.
66 * I added now ALLOW_ANON_EDIT = true to makes things clear.
67 * (which replaces REQUIRE_SIGNIN_BEFORE_EDIT)
69 * 3) Removed pear prepare. Performance hog, and using integers as
70 * handler doesn't help. Do simple sprintf as with adodb. And a prepare
71 * in the object init is no advantage, because in the init loop a lot of
72 * objects are tried, but not used.
73 * 4) Already gotten prefs are passed to the next object to avoid
74 * duplicate getPreferences() calls.
76 * 5) Major php-5 problem: $this re-assignment is disallowed by the parser
77 * So we cannot just discrimate with
78 * if (!check_php_version(5))
80 * A /php5-patch.php is provided, which patches the src automatically
81 * for php4 and php5. Default is php4.
83 * 6) enforced new cookie policy: prefs don't get stored in cookies
84 * anymore, only in homepage and/or database, but always in the
85 * current session. old pref cookies will get deleted.
87 * 7) Certain themes should be able to extend the predefined list
88 * of preferences. Display/editing is done in the theme specific userprefs.tmpl,
89 * but storage must be extended to the Get/SetPreferences methods.
90 * <theme>/themeinfo.php must provide CustomUserPreferences:
91 * A list of name => _UserPreference class pairs.
94 define('WIKIAUTH_FORBIDDEN', -1); // Completely not allowed.
95 define('WIKIAUTH_ANON', 0); // Not signed in.
96 define('WIKIAUTH_BOGO', 1); // Any valid WikiWord is enough.
97 define('WIKIAUTH_USER', 2); // Bogo user with a password.
98 define('WIKIAUTH_ADMIN', 10); // UserName == ADMIN_USER.
99 define('WIKIAUTH_UNOBTAINABLE', 100); // Permissions that no user can achieve
101 if (!defined('COOKIE_EXPIRATION_DAYS')) define('COOKIE_EXPIRATION_DAYS', 365);
102 if (!defined('COOKIE_DOMAIN')) define('COOKIE_DOMAIN', '/');
104 if (!defined('EDITWIDTH_MIN_COLS')) define('EDITWIDTH_MIN_COLS', 30);
105 if (!defined('EDITWIDTH_MAX_COLS')) define('EDITWIDTH_MAX_COLS', 150);
106 if (!defined('EDITWIDTH_DEFAULT_COLS')) define('EDITWIDTH_DEFAULT_COLS', 80);
108 if (!defined('EDITHEIGHT_MIN_ROWS')) define('EDITHEIGHT_MIN_ROWS', 5);
109 if (!defined('EDITHEIGHT_MAX_ROWS')) define('EDITHEIGHT_MAX_ROWS', 80);
110 if (!defined('EDITHEIGHT_DEFAULT_ROWS')) define('EDITHEIGHT_DEFAULT_ROWS', 22);
112 define('TIMEOFFSET_MIN_HOURS', -26);
113 define('TIMEOFFSET_MAX_HOURS', 26);
114 if (!defined('TIMEOFFSET_DEFAULT_HOURS')) define('TIMEOFFSET_DEFAULT_HOURS', 0);
117 * There are be the following constants in index.php to
118 * establish login parameters:
120 * ALLOW_ANON_USER default true
121 * ALLOW_ANON_EDIT default true
122 * ALLOW_BOGO_LOGIN default true
123 * ALLOW_USER_PASSWORDS default true
124 * PASSWORD_LENGTH_MINIMUM default 6 ?
126 * To require user passwords for editing:
127 * ALLOW_ANON_USER = true
128 * ALLOW_ANON_EDIT = false (before named REQUIRE_SIGNIN_BEFORE_EDIT)
129 * ALLOW_BOGO_LOGIN = false
130 * ALLOW_USER_PASSWORDS = true
132 * To establish a COMPLETELY private wiki, such as an internal
134 * ALLOW_ANON_USER = false
135 * (and probably require user passwords as described above). In this
136 * case the user will be prompted to login immediately upon accessing
139 * There are other possible combinations, but the typical wiki (such
140 * as http://PhpWiki.sf.net/phpwiki) would usually just leave all four
145 // The last object in the row is the bad guy...
146 if (!is_array($USER_AUTH_ORDER))
147 $USER_AUTH_ORDER = array("Forbidden");
149 $USER_AUTH_ORDER[] = "Forbidden";
151 // Local convenience functions.
152 function _isAnonUserAllowed() {
153 return (defined('ALLOW_ANON_USER') && ALLOW_ANON_USER);
155 function _isBogoUserAllowed() {
156 return (defined('ALLOW_BOGO_LOGIN') && ALLOW_BOGO_LOGIN);
158 function _isUserPasswordsAllowed() {
159 return (defined('ALLOW_USER_PASSWORDS') && ALLOW_USER_PASSWORDS);
162 // Possibly upgrade userobject functions.
163 function _determineAdminUserOrOtherUser($UserName) {
164 // Sanity check. User name is a condition of the definition of the
165 // _AdminUser, _BogoUser and _passuser.
167 return $GLOBALS['ForbiddenUser'];
169 $group = &WikiGroup::getGroup($GLOBALS['request']);
170 if ($UserName == ADMIN_USER or $group->isMember(GROUP_ADMIN))
171 return new _AdminUser($UserName);
173 return _determineBogoUserOrPassUser($UserName);
176 function _determineBogoUserOrPassUser($UserName) {
177 global $ForbiddenUser;
179 // Sanity check. User name is a condition of the definition of
180 // _BogoUser and _PassUser.
182 return $ForbiddenUser;
184 // Check for password and possibly upgrade user object.
185 // $_BogoUser = new _BogoUser($UserName);
186 if (_isBogoUserAllowed()) {
187 $_BogoUser = new _BogoLoginPassUser($UserName);
188 if ($_BogoUser->userExists())
191 if (_isUserPasswordsAllowed()) {
192 // PassUsers override BogoUsers if a password is stored
193 if (isset($_BogoUser) and $_BogoUser->_prefs->get('passwd'))
194 return new _PassUser($UserName,$_BogoUser->_prefs);
196 $_PassUser = new _PassUser($UserName,isset($_BogoUser) ? $_BogoUser->_prefs : false);
197 if ($_PassUser->userExists())
201 // No Bogo- or PassUser exists, or
202 // passwords are not allowed, and bogo is disallowed too.
203 // (Only the admin can sign in).
204 return $ForbiddenUser;
208 * Primary WikiUser function, called by lib/main.php.
210 * This determines the user's type and returns an appropriate user
211 * object. lib/main.php then querys the resultant object for password
212 * validity as necessary.
214 * If an _AnonUser object is returned, the user may only browse pages
215 * (and save prefs in a cookie).
217 * To disable access but provide prefs the global $ForbiddenUser class
218 * is returned. (was previously false)
221 function WikiUser ($UserName = '') {
222 global $ForbiddenUser;
224 //Maybe: Check sessionvar for username & save username into
225 //sessionvar (may be more appropriate to do this in lib/main.php).
227 $ForbiddenUser = new _ForbiddenUser($UserName);
228 // Found a user name.
229 return _determineAdminUserOrOtherUser($UserName);
231 elseif (!empty($_SESSION['userid'])) {
232 // Found a user name.
233 $ForbiddenUser = new _ForbiddenUser($_SESSION['userid']);
234 return _determineAdminUserOrOtherUser($_SESSION['userid']);
237 // Check for autologin pref in cookie and possibly upgrade
238 // user object to another type.
239 $_AnonUser = new _AnonUser();
240 if ($UserName = $_AnonUser->_userid && $_AnonUser->_prefs->get('autologin')) {
241 // Found a user name.
242 $ForbiddenUser = new _ForbiddenUser($UserName);
243 return _determineAdminUserOrOtherUser($UserName);
246 $ForbiddenUser = new _ForbiddenUser();
247 if (_isAnonUserAllowed())
249 return $ForbiddenUser; // User must sign in to browse pages.
251 return $ForbiddenUser; // User must sign in with a password.
254 trigger_error("DEBUG: Note: End of function reached in WikiUser." . " "
255 . "Unexpectedly, an appropriate user class could not be determined.");
256 return $ForbiddenUser; // Failsafe.
261 * WikiUser.php use the name 'WikiUser'
263 function WikiUserClassname() {
269 * Upgrade olduser by copying properties from user to olduser.
270 * We are not sure yet, for which php's a simple $this = $user works reliably,
271 * (on php4 it works ok, on php5 it's currently disallowed on the parser level)
272 * that's why try it the hard way.
274 function UpgradeUser ($olduser, $user) {
275 if (isa($user,'_WikiUser') and isa($olduser,'_WikiUser')) {
276 // populate the upgraded class $olduser with the values from the new user object
277 //only _auth_level, _current_method, _current_index,
278 if (!empty($user->_level) and
279 $user->_level > $olduser->_level)
280 $olduser->_level = $user->_level;
281 if (!empty($user->_current_index) and
282 $user->_current_index > $olduser->_current_index) {
283 $olduser->_current_index = $user->_current_index;
284 $olduser->_current_method = $user->_current_method;
286 if (!empty($user->_authmethod))
287 $olduser->_authmethod = $user->_authmethod;
289 foreach (get_object_vars($user) as $k => $v) {
290 if (!empty($v)) $olduser->$k = $v;
293 $olduser->hasHomePage(); // revive db handle, because these don't survive sessions
294 //$GLOBALS['request']->_user = $olduser;
302 * Probably not needed, since we use the various user objects methods so far.
303 * Anyway, here it is, looping through all available objects.
305 function UserExists ($UserName) {
307 if (!($user = $request->getUser()))
308 $user = WikiUser($UserName);
311 if ($user->userExists($UserName)) {
312 $request->_user = $user;
315 if (isa($user,'_BogoUser'))
316 $user = new _PassUser($UserName,$user->_prefs);
317 $class = $user->nextClass();
318 if ($user = new $class($UserName,$user->_prefs)) {
319 return $user->userExists($UserName);
321 $request->_user = $GLOBALS['ForbiddenUser'];
325 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
328 * Base WikiUser class.
333 var $_level = WIKIAUTH_FORBIDDEN;
335 var $_HomePagehandle = false;
338 function _WikiUser($UserName='', $prefs=false) {
340 $this->_userid = $UserName;
341 $this->_HomePagehandle = false;
343 $this->hasHomePage();
345 $this->_level = WIKIAUTH_FORBIDDEN;
346 if (empty($this->_prefs)) {
347 if ($prefs) $this->_prefs = $prefs;
348 else $this->getPreferences();
352 function UserName() {
353 if (!empty($this->_userid))
354 return $this->_userid;
357 function getPreferences() {
358 trigger_error("DEBUG: Note: undefined _WikiUser class trying to load prefs." . " "
359 . "New subclasses of _WikiUser must override this function.");
363 function setPreferences($prefs, $id_only) {
364 trigger_error("DEBUG: Note: undefined _WikiUser class trying to save prefs." . " "
365 . "New subclasses of _WikiUser must override this function.");
369 function userExists() {
370 return $this->hasHomePage();
373 function checkPass($submitted_password) {
374 // By definition, an undefined user class cannot sign in.
375 trigger_error("DEBUG: Warning: undefined _WikiUser class trying to sign in." . " "
376 . "New subclasses of _WikiUser must override this function.");
380 // returns page_handle to user's home page or false if none
381 function hasHomePage() {
382 if ($this->_userid) {
383 if (!empty($this->_HomePagehandle) and is_object($this->_HomePagehandle)) {
384 return $this->_HomePagehandle->exists();
387 // check db again (maybe someone else created it since
390 $this->_HomePagehandle = $request->getPage($this->_userid);
391 return $this->_HomePagehandle->exists();
398 // innocent helper: case-insensitive position in _auth_methods
399 function array_position ($string, $array) {
400 $string = strtolower($string);
401 for ($found = 0; $found < count($array); $found++) {
402 if (strtolower($array[$found]) == $string)
408 function nextAuthMethodIndex() {
409 if (empty($this->_auth_methods))
410 $this->_auth_methods = $GLOBALS['USER_AUTH_ORDER'];
411 if (empty($this->_current_index)) {
412 if (get_class($this) != '_passuser') {
413 $this->_current_method = substr(get_class($this),1,-8);
414 $this->_current_index = $this->array_position($this->_current_method,
415 $this->_auth_methods);
417 $this->_current_index = -1;
420 $this->_current_index++;
421 if ($this->_current_index >= count($this->_auth_methods))
423 $this->_current_method = $this->_auth_methods[$this->_current_index];
424 return $this->_current_index;
427 function AuthMethod($index = false) {
428 return $this->_auth_methods[ $index === false ? 0 : $index];
431 // upgrade the user object
432 function nextClass() {
433 if (($next = $this->nextAuthMethodIndex()) !== false) {
434 $method = $this->AuthMethod($next);
435 return "_".$method."PassUser";
437 if ($user = new $class($this->_userid)) {
438 // prevent from endless recursion.
439 //$user->_current_method = $this->_current_method;
440 //$user->_current_index = $this->_current_index;
441 $user = UpgradeUser($user, $this);
446 return "_ForbiddenPassUser";
449 //Fixme: for _HttpAuthPassUser
450 function PrintLoginForm (&$request, $args, $fail_message = false,
451 $seperate_page = false) {
452 include_once('lib/Template.php');
453 // Call update_locale in case the system's default language is not 'en'.
454 // (We have no user pref for lang at this point yet, no one is logged in.)
455 if ($GLOBALS['LANG'] != DEFAULT_LANGUAGE)
456 update_locale(DEFAULT_LANGUAGE);
457 $userid = $this->_userid;
459 extract($args); // fixme
461 $require_level = max(0, min(WIKIAUTH_ADMIN, (int)$require_level));
463 $pagename = $request->getArg('pagename');
465 $login = Template('login',
466 compact('pagename', 'userid', 'require_level',
467 'fail_message', 'pass_required', 'nocache'));
468 // check if the html template was already processed
469 $seperate_page = $seperate_page ? true : !alreadyTemplateProcessed('html');
470 if ($seperate_page) {
471 $top = Template('html', array('TITLE' => _("Sign In")));
472 return $top->printExpansion($login);
474 return $login->printExpansion();
478 /** Signed in but probably not password checked.
480 function isSignedIn() {
481 return (isa($this,'_BogoUser') or isa($this,'_PassUser'));
484 /** This is password checked for sure.
486 function isAuthenticated () {
487 //return isa($this,'_PassUser');
488 //return isa($this,'_BogoUser') || isa($this,'_PassUser');
489 return $this->_level >= WIKIAUTH_BOGO; // hmm.
492 function isAdmin () {
493 return $this->_level == WIKIAUTH_ADMIN;
496 /** Name or IP for a signed user. UserName could come from a cookie e.g.
499 return ( $this->UserName()
501 : $GLOBALS['request']->get('REMOTE_ADDR') ); // FIXME: globals
504 /** Name for an authenticated user. No IP here.
506 function getAuthenticatedId() {
507 return ( $this->isAuthenticated()
509 : ''); //$GLOBALS['request']->get('REMOTE_ADDR') ); // FIXME: globals
512 function hasAuthority ($require_level) {
513 return $this->_level >= $require_level;
517 * Called on an auth_args POST request, such as login, logout or signin.
519 function AuthCheck ($postargs) {
520 // Normalize args, and extract.
521 $keys = array('userid', 'passwd', 'require_level', 'login', 'logout',
523 foreach ($keys as $key)
524 $args[$key] = isset($postargs[$key]) ? $postargs[$key] : false;
526 $require_level = max(0, min(WIKIAUTH_ADMIN, (int)$require_level));
528 if ($logout) { // Log out
529 $GLOBALS['request']->_user = new _AnonUser();
530 return $GLOBALS['request']->_user;
532 return false; // User hit cancel button.
533 elseif (!$login && !$userid)
534 return false; // Nothing to do?
536 $authlevel = $this->checkPass($passwd === false ? '' : $passwd);
538 return _("Invalid password or userid.");
539 elseif ($authlevel < $require_level)
540 return _("Insufficient permissions.");
543 //$user = $GLOBALS['request']->_user;
544 if (!empty($this->_current_method) and
545 strtolower(get_class($this)) == '_passuser')
548 $class = "_" . $this->_current_method . "PassUser";
549 $user = new $class($userid,$this->_prefs);
550 /*PHP5 patch*/$this = $user;
551 $this->_level = $authlevel;
554 $this->_userid = $userid;
555 $this->_level = $authlevel;
562 * Not authenticated in user, but he may be signed in. Basicly with view access only.
563 * prefs are stored in cookies, but only the userid.
568 var $_level = WIKIAUTH_ANON; // var in php-5.0.0RC1 deprecated
570 /** Anon only gets to load and save prefs in a cookie, that's it.
572 function getPreferences() {
575 if (empty($this->_prefs))
576 $this->_prefs = new UserPreferences;
577 $UserName = $this->UserName();
579 // Try to read deprecated 1.3.x style cookies
580 if ($cookie = $request->cookies->get_old(WIKI_NAME)) {
581 if (! $unboxedcookie = $this->_prefs->retrieve($cookie)) {
582 trigger_error(_("Empty Preferences or format of UserPreferences cookie not recognised.")
584 . sprintf("%s='%s'", WIKI_NAME, $cookie)
586 . _("Default preferences will be used."),
590 * Only set if it matches the UserName who is
591 * signing in or if this really is an Anon login (no
592 * username). (Remember, _BogoUser and higher inherit this
595 if (! $UserName || $UserName == @$unboxedcookie['userid']) {
596 $updated = $this->_prefs->updatePrefs($unboxedcookie);
597 //$this->_prefs = new UserPreferences($unboxedcookie);
598 $UserName = @$unboxedcookie['userid'];
599 if (is_string($UserName) and (substr($UserName,0,2) != 's:'))
600 $this->_userid = $UserName;
604 // v1.3.8 policy: don't set PhpWiki cookies, only plaintext WIKI_ID cookies
605 $request->deleteCookieVar(WIKI_NAME);
607 // Try to read deprecated 1.3.4 style cookies
608 if (! $UserName and ($cookie = $request->cookies->get_old("WIKI_PREF2"))) {
609 if (! $unboxedcookie = $this->_prefs->retrieve($cookie)) {
610 if (! $UserName || $UserName == $unboxedcookie['userid']) {
611 $updated = $this->_prefs->updatePrefs($unboxedcookie);
612 //$this->_prefs = new UserPreferences($unboxedcookie);
613 $UserName = $unboxedcookie['userid'];
614 if (is_string($UserName) and (substr($UserName,0,2) != 's:'))
615 $this->_userid = $UserName;
619 $request->deleteCookieVar("WIKI_PREF2");
623 // Try reading userid from old PhpWiki cookie formats:
624 if ($cookie = $request->cookies->get_old('WIKI_ID')) {
625 if (is_string($cookie) and (substr($cookie,0,2) != 's:'))
627 elseif (is_array($cookie) and !empty($cookie['userid']))
628 $UserName = $cookie['userid'];
631 $request->deleteCookieVar("WIKI_ID");
633 $this->_userid = $UserName;
636 // initializeTheme() needs at least an empty object
638 if (empty($this->_prefs))
639 $this->_prefs = new UserPreferences;
641 return $this->_prefs;
644 /** _AnonUser::setPreferences(): Save prefs in a cookie and session and update all global vars
646 * Allow for multiple wikis in same domain. Encode only the
647 * _prefs array of the UserPreference object. Ideally the
648 * prefs array should just be imploded into a single string or
649 * something so it is completely human readable by the end
650 * user. In that case stricter error checking will be needed
651 * when loading the cookie.
653 function setPreferences($prefs, $id_only=false) {
654 if (!is_object($prefs)) {
655 if (is_object($this->_prefs)) {
656 $updated = $this->_prefs->updatePrefs($prefs);
657 $prefs =& $this->_prefs;
659 // update the prefs values from scratch. This could leed to unnecessary
660 // side-effects: duplicate emailVerified, ...
661 $this->_prefs = new UserPreferences($prefs);
665 if (!isset($this->_prefs))
666 $this->_prefs =& $prefs;
668 $updated = $this->_prefs->isChanged($prefs);
673 // new 1.3.8 policy: no array cookies, only plain userid string as in
674 // the pre 1.3.x versions.
675 // prefs should be stored besides the session in the homepagehandle or in a db.
676 $request->setCookieVar('WIKI_ID', $this->_userid,
677 COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
678 //$request->setCookieVar(WIKI_NAME, array('userid' => $prefs->get('userid')),
679 // COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
682 $packed = $prefs->store();
683 $unpacked = $prefs->unpack($packed);
684 if (count($unpacked)) {
685 foreach (array('_method','_select','_update') as $param) {
686 if (!empty($this->_prefs->{$param}))
687 $prefs->{$param} = $this->_prefs->{$param};
689 $this->_prefs = $prefs;
690 //FIXME! The following must be done in $request->_setUser(), not here,
691 // to be able to iterate over multiple users, without tampering the current user.
694 $request->_prefs =& $this->_prefs;
695 $request->_user->_prefs =& $this->_prefs;
696 if (isset($request->_user->_auth_dbi)) {
697 $user = $request->_user;
698 unset($user->_auth_dbi);
699 $request->setSessionVar('wiki_user', $user);
701 //$request->setSessionVar('wiki_prefs', $this->_prefs);
702 $request->setSessionVar('wiki_user', $request->_user);
709 function userExists() {
713 function checkPass($submitted_password) {
715 // this might happen on a old-style signin button.
717 // By definition, the _AnonUser does not HAVE a password
718 // (compared to _BogoUser, who has an EMPTY password).
719 trigger_error("DEBUG: Warning: _AnonUser unexpectedly asked to checkPass()." . " "
720 . "Check isa(\$user, '_PassUser'), or: isa(\$user, '_AdminUser') etc. first." . " "
721 . "New subclasses of _WikiUser must override this function.");
728 * Helper class to finish the PassUser auth loop.
729 * This is added automatically to USER_AUTH_ORDER.
734 var $_level = WIKIAUTH_FORBIDDEN;
736 function checkPass($submitted_password) {
737 return WIKIAUTH_FORBIDDEN;
740 function userExists() {
741 if ($this->_HomePagehandle) return true;
746 * The PassUser name gets created automatically.
747 * That's why this class is empty, but must exist.
749 class _ForbiddenPassUser
750 extends _ForbiddenUser
758 * Do NOT extend _BogoUser to other classes, for checkPass()
759 * security. (In case of defects in code logic of the new class!)
760 * The intermediate step between anon and passuser.
761 * We also have the _BogoLoginPassUser class with stricter
762 * password checking, which fits into the auth loop.
763 * Note: This class is not called anymore by WikiUser()
768 function userExists() {
769 if (isWikiWord($this->_userid)) {
770 $this->_level = WIKIAUTH_BOGO;
773 $this->_level = WIKIAUTH_ANON;
778 function checkPass($submitted_password) {
779 // By definition, BogoUser has an empty password.
781 return $this->_level;
788 * Called if ALLOW_USER_PASSWORDS and Anon and Bogo failed.
790 * The classes for all subsequent auth methods extend from this class.
791 * This handles the auth method type dispatcher according $USER_AUTH_ORDER,
792 * the three auth method policies first-only, strict and stacked
793 * and the two methods for prefs: homepage or database,
794 * if $DBAuthParams['pref_select'] is defined.
796 * Default is PersonalPage auth and prefs.
798 * TODO: email verification
800 * @author: Reini Urban
804 var $_auth_dbi, $_prefs;
805 var $_current_method, $_current_index;
807 // check and prepare the auth and pref methods only once
808 function _PassUser($UserName='', $prefs=false) {
809 //global $DBAuthParams, $DBParams;
811 $this->_userid = $UserName;
812 if ($this->hasHomePage())
813 $this->_HomePagehandle = $GLOBALS['request']->getPage($this->_userid);
815 $this->_authmethod = substr(get_class($this),1,-8);
816 if ($this->_authmethod == 'a') $this->_authmethod = 'admin';
817 if (! $this->_prefs) {
818 if ($prefs) $this->_prefs = $prefs;
819 else $this->getPreferences();
822 // Check the configured Prefs methods
823 $dbi = $this->getAuthDbh();
824 $dbh = $GLOBALS['request']->getDbh();
825 if ( $dbi and !isset($this->_prefs->_select) and $dbh->getAuthParam('pref_select')) {
826 $this->_prefs->_method = $dbh->getParam('dbtype');
827 $this->_prefs->_select = $this->prepare($dbh->getAuthParam('pref_select'), "userid");
829 if ( !isset($this->_prefs->_update) and $dbh->getAuthParam('pref_update')) {
830 $this->_prefs->_update = $this->prepare($dbh->getAuthParam('pref_update'),
831 array("userid", "pref_blob"));
834 $this->_prefs->_method = 'HomePage';
837 // Upgrade to the next parent _PassUser class. Avoid recursion.
838 if ( strtolower(get_class($this)) === '_passuser' ) {
839 //auth policy: Check the order of the configured auth methods
840 // 1. first-only: Upgrade the class here in the constructor
841 // 2. old: ignore USER_AUTH_ORDER and try to use all available methods as
842 /// in the previous PhpWiki releases (slow)
843 // 3. strict: upgrade the class after checking the user existance in userExists()
844 // 4. stacked: upgrade the class after the password verification in checkPass()
845 // Methods: PersonalPage, HttpAuth, DB, Ldap, Imap, File
846 if (!defined('USER_AUTH_POLICY')) define('USER_AUTH_POLICY','old');
847 if (defined('USER_AUTH_POLICY')) {
848 // policy 1: only pre-define one method for all users
849 if (USER_AUTH_POLICY === 'first-only') {
850 $class = $this->nextClass();
851 return new $class($UserName,$this->_prefs);
853 // use the default behaviour from the previous versions:
854 elseif (USER_AUTH_POLICY === 'old') {
855 // default: try to be smart
856 // On php5 we can directly return and upgrade the Object,
857 // before we have to upgrade it manually.
858 if (!empty($GLOBALS['PHP_AUTH_USER'])) {
859 if (check_php_version(5))
860 return new _HttpAuthPassUser($UserName,$this->_prefs);
862 $user = new _HttpAuthPassUser($UserName,$this->_prefs);
863 //todo: with php5 comment the following line.
864 /*PHP5 patch*/$this = $user;
867 } elseif ($dbh->getAuthParam('auth_check') and
868 ($dbh->getAuthParam('auth_dsn') or $dbh->getParam('dsn'))) {
869 if (check_php_version(5))
870 return new _DbPassUser($UserName,$this->_prefs);
872 $user = new _DbPassUser($UserName,$this->_prefs);
873 //todo: with php5 comment the following line.
874 /*PHP5 patch*/$this = $user;
877 } elseif (defined('LDAP_AUTH_HOST') and defined('LDAP_BASE_DN') and
878 function_exists('ldap_open')) {
879 if (check_php_version(5))
880 return new _LDAPPassUser($UserName,$this->_prefs);
882 $user = new _LDAPPassUser($UserName,$this->_prefs);
883 //todo: with php5 comment the following line.
884 /*PHP5 patch*/$this = $user;
887 } elseif (defined('IMAP_AUTH_HOST') and function_exists('imap_open')) {
888 if (check_php_version(5))
889 return new _IMAPPassUser($UserName,$this->_prefs);
891 $user = new _IMAPPassUser($UserName,$this->_prefs);
892 //todo: with php5 comment the following line.
893 /*PHP5 patch*/$this = $user;
896 } elseif (defined('AUTH_USER_FILE') and file_exists(AUTH_USER_FILE)) {
897 if (check_php_version(5))
898 return new _FilePassUser($UserName, $this->_prefs);
900 $user = new _FilePassUser($UserName, $this->_prefs);
901 //todo: with php5 comment the following line.
902 /*PHP5 patch*/$this = $user;
906 if (check_php_version(5))
907 return new _PersonalPagePassUser($UserName,$this->_prefs);
909 $user = new _PersonalPagePassUser($UserName,$this->_prefs);
910 //todo: with php5 comment the following line.
911 /*PHP5 patch*/$this = $user;
917 // else use the page methods defined in _PassUser.
923 function getAuthDbh () {
924 global $request; //, $DBParams, $DBAuthParams;
926 $dbh = $request->getDbh();
927 // session restauration doesn't re-connect to the database automatically,
929 if (($dbh->getParam('dbtype') == 'SQL') and isset($this->_auth_dbi) and
930 empty($this->_auth_dbi->connection))
931 unset($this->_auth_dbi);
932 if (($dbh->getParam('dbtype') == 'ADODB') and isset($this->_auth_dbi) and
933 empty($this->_auth_dbi->_connectionID))
934 unset($this->_auth_dbi);
936 if (empty($this->_auth_dbi)) {
937 if ($dbh->getParam('dbtype') != 'SQL' and $dbh->getParam('dbtype') != 'ADODB')
939 if (empty($GLOBALS['DBAuthParams']))
941 if (!$dbh->getAuthParam('auth_dsn')) {
942 $dbh = $request->getDbh(); // use phpwiki database
943 } elseif ($dbh->getAuthParam('auth_dsn') == $dbh->getParam('dsn')) {
944 $dbh = $request->getDbh(); // same phpwiki database
945 } else { // use another external database handle. needs PHP >= 4.1
946 $local_params = array_merge($GLOBALS['DBParams'],$GLOBALS['DBAuthParams']);
947 $local_params['dsn'] = $local_params['auth_dsn'];
948 $dbh = WikiDB::open($local_params);
950 $this->_auth_dbi =& $dbh->_backend->_dbh;
952 return $this->_auth_dbi;
955 function _normalize_stmt_var($var, $oldstyle = false) {
956 static $valid_variables = array('userid','password','pref_blob','groupname');
957 // old-style: "'$userid'"
958 // new-style: '"\$userid"' or just "userid"
959 $new = str_replace(array("'",'"','\$','$'),'',$var);
960 if (!in_array($new,$valid_variables)) {
961 trigger_error("Unknown DBAuthParam statement variable: ". $new, E_USER_ERROR);
964 return !$oldstyle ? "'$".$new."'" : '"\$'.$new.'"';
967 // TODO: use it again for the auth and member tables
968 function prepare ($stmt, $variables, $oldstyle = false) {
970 $dbi = $request->getDbh();
972 // "'\$userid"' => '%s'
973 // variables can be old-style: '"\$userid"' or new-style: "'$userid'" or just "userid"
974 // old-style strings don't survive pear/Config/IniConfig treatment, that's why we changed it.
976 if (is_array($variables)) {
977 for ($i=0; $i < count($variables); $i++) {
978 $var = $this->_normalize_stmt_var($variables[$i],$oldstyle);
980 trigger_error(sprintf("DbAuthParams: Undefined or empty statement variable %s in %s",
981 $variables[$i], $stmt), E_USER_WARNING);
982 $variables[$i] = $var;
983 if (!$var) $new[] = '';
987 $var = $this->_normalize_stmt_var($variables,$oldstyle);
989 trigger_error(sprintf("DbAuthParams: Undefined or empty statement variable %s in %s",
990 $variables,$stmt), E_USER_WARNING);
992 if (!$var) $new = '';
995 $prefix = $dbi->getParam('prefix');
996 // probably prefix table names if in same database
997 if ($prefix and isset($this->_auth_dbi) and isset($dbi->_backend->_dbh) and
998 ($dbi->getAuthParam('auth_dsn') and $dbi->getParam('dsn') == $dbi->getAuthParam('auth_dsn')))
1000 if (!stristr($stmt, $prefix)) {
1001 //Do it automatically for the lazy admin? Esp. on sf.net it's nice to have
1002 trigger_error("TODO: Need to prefix the DBAuthParam tablename in index.php:\n $stmt",
1004 $stmt = str_replace(array(" user "," pref "," member "),
1005 array(" ".$prefix."user ",
1006 " ".$prefix."prefs ",
1007 " ".$prefix."member "),$stmt);
1010 // Preparate the SELECT statement, for ADODB and PearDB (MDB not).
1011 // Simple sprintf-style.
1012 $new_stmt = str_replace($variables,$new,$stmt);
1013 if ($new_stmt == $stmt) {
1015 trigger_error(sprintf("DbAuthParams: Invalid statement in %s",
1016 $stmt), E_USER_WARNING);
1018 trigger_error(sprintf("DbAuthParams: Old statement quoting style in %s",
1019 $stmt), E_USER_WARNING);
1020 $new_stmt = $this->prepare($stmt, $variables, 'oldstyle');
1026 function getPreferences() {
1027 if (!empty($this->_prefs->_method)) {
1028 if ($this->_prefs->_method == 'ADODB') {
1029 _AdoDbPassUser::_AdoDbPassUser($this->_userid,$this->_prefs);
1030 return _AdoDbPassUser::getPreferences();
1031 } elseif ($this->_prefs->_method == 'SQL') {
1032 _PearDbPassUser::_PearDbPassUser($this->_userid,$this->_prefs);
1033 return _PearDbPassUser::getPreferences();
1037 // We don't necessarily have to read the cookie first. Since
1038 // the user has a password, the prefs stored in the homepage
1039 // cannot be arbitrarily altered by other Bogo users.
1040 _AnonUser::getPreferences();
1041 // User may have deleted cookie, retrieve from his
1042 // PersonalPage if there is one.
1043 if ($this->_HomePagehandle) {
1044 if ($restored_from_page = $this->_prefs->retrieve($this->_HomePagehandle->get('pref'))) {
1045 $updated = $this->_prefs->updatePrefs($restored_from_page,'init');
1046 //$this->_prefs = new UserPreferences($restored_from_page);
1047 return $this->_prefs;
1050 return $this->_prefs;
1053 function setPreferences($prefs, $id_only=false) {
1054 if (!empty($this->_prefs->_method)) {
1055 if ($this->_prefs->_method == 'ADODB') {
1056 _AdoDbPassUser::_AdoDbPassUser($this->_userid,$prefs);
1057 return _AdoDbPassUser::setPreferences($prefs, $id_only);
1059 elseif ($this->_prefs->_method == 'SQL') {
1060 _PearDbPassUser::_PearDbPassUser($this->_userid,$prefs);
1061 return _PearDbPassUser::setPreferences($prefs, $id_only);
1064 if (_AnonUser::setPreferences($prefs, $id_only)) {
1065 // Encode only the _prefs array of the UserPreference object
1066 if ($this->_HomePagehandle and !$id_only) {
1067 $this->_HomePagehandle->set('pref', $this->_prefs->store());
1073 function mayChangePass() {
1077 //The default method is getting the password from prefs.
1078 // child methods obtain $stored_password from external auth.
1079 function userExists() {
1080 //if ($this->_HomePagehandle) return true;
1081 $class = $this->nextClass();
1082 while ($user = new $class($this->_userid,$this->_prefs)) {
1083 //todo: with php5 comment the following line:
1084 /*PHP5 patch*/$this = $user;
1085 //UpgradeUser($this,$user);
1086 if ($user->userExists()) {
1089 // prevent endless loop. does this work on all PHP's?
1090 // it just has to set the classname, what it correctly does.
1091 $class = $user->nextClass();
1092 if ($class == "_ForbiddenPassUser")
1098 //The default method is getting the password from prefs.
1099 // child methods obtain $stored_password from external auth.
1100 function checkPass($submitted_password) {
1101 $stored_password = $this->_prefs->get('passwd');
1102 if ($this->_checkPass($submitted_password, $stored_password)) {
1103 $this->_level = WIKIAUTH_USER;
1104 return $this->_level;
1106 return $this->_tryNextPass($submitted_password);
1111 * The basic password checker for all PassUser objects.
1112 * Uses global ENCRYPTED_PASSWD and PASSWORD_LENGTH_MINIMUM.
1113 * Empty passwords are always false!
1114 * PASSWORD_LENGTH_MINIMUM is enforced here and in the preference set method.
1115 * @see UserPreferences::set
1117 * DBPassUser password's have their own crypt definition.
1118 * That's why DBPassUser::checkPass() doesn't call this method, if
1119 * the db password method is 'plain', which means that the DB SQL
1120 * statement just returns 1 or 0. To use CRYPT() or PASSWORD() and
1121 * don't store plain passwords in the DB.
1123 * TODO: remove crypt() function check from config.php:396 ??
1125 function _checkPass($submitted_password, $stored_password) {
1126 if(!empty($submitted_password)) {
1127 if (strlen($stored_password) < PASSWORD_LENGTH_MINIMUM) {
1129 trigger_error(_("The length of the stored password is shorter than the system policy allows. Sorry, you cannot login.\n You have to ask the System Administrator to reset your password."));
1132 if (strlen($submitted_password) < PASSWORD_LENGTH_MINIMUM)
1134 if (defined('ENCRYPTED_PASSWD') && ENCRYPTED_PASSWD) {
1135 // Verify against encrypted password.
1136 if (function_exists('crypt')) {
1137 if (crypt($submitted_password, $stored_password) == $stored_password )
1138 return true; // matches encrypted password
1143 trigger_error(_("The crypt function is not available in this version of PHP.") . " "
1144 . _("Please set ENCRYPTED_PASSWD to false in index.php and probably change ADMIN_PASSWD."),
1150 // Verify against cleartext password.
1151 if ($submitted_password == $stored_password)
1154 // Check whether we forgot to enable ENCRYPTED_PASSWD
1155 if (function_exists('crypt')) {
1156 if (crypt($submitted_password, $stored_password) == $stored_password) {
1157 trigger_error(_("Please set ENCRYPTED_PASSWD to true in index.php."),
1168 /** The default method is storing the password in prefs.
1169 * Child methods (DB,File) may store in external auth also, but this
1170 * must be explicitly enabled.
1171 * This may be called by plugin/UserPreferences or by ->SetPreferences()
1173 function changePass($submitted_password) {
1174 $stored_password = $this->_prefs->get('passwd');
1175 // check if authenticated
1176 if ($this->isAuthenticated() and $stored_password != $submitted_password) {
1177 $this->_prefs->set('passwd',$submitted_password);
1178 //update the storage (session, homepage, ...)
1179 $this->SetPreferences($this->_prefs);
1182 //Todo: return an error msg to the caller what failed?
1183 // same password or no privilege
1187 function _tryNextPass($submitted_password) {
1188 if (USER_AUTH_POLICY === 'strict') {
1189 $class = $this->nextClass();
1190 if ($user = new $class($this->_userid,$this->_prefs)) {
1191 if ($user->userExists()) {
1192 return $user->checkPass($submitted_password);
1196 if (USER_AUTH_POLICY === 'stacked' or USER_AUTH_POLICY === 'old') {
1197 $class = $this->nextClass();
1198 if ($user = new $class($this->_userid,$this->_prefs))
1199 return $user->checkPass($submitted_password);
1201 return $this->_level;
1204 function _tryNextUser() {
1205 if (USER_AUTH_POLICY === 'strict') {
1206 $class = $this->nextClass();
1207 while ($user = new $class($this->_userid,$this->_prefs)) {
1208 //todo: with php5 comment the following line:
1209 /*PHP5 patch*/$this = $user;
1210 //$user = UpgradeUser($this, $user);
1211 if ($user->userExists()) {
1214 $class = $this->nextClass();
1222 /** Without stored password. A _BogoLoginPassUser with password
1223 * is automatically upgraded to a PersonalPagePassUser.
1225 class _BogoLoginPassUser
1228 var $_authmethod = 'BogoLogin';
1229 function userExists() {
1230 if (isWikiWord($this->_userid)) {
1231 $this->_level = WIKIAUTH_BOGO;
1234 $this->_level = WIKIAUTH_ANON;
1239 /** A BogoLoginUser requires no password at all
1240 * But if there's one stored, we should prefer PersonalPage instead
1242 function checkPass($submitted_password) {
1243 if ($this->_prefs->get('passwd')) {
1244 $user = new _PersonalPagePassUser($this->_userid);
1245 if ($user->checkPass($submitted_password)) {
1246 //todo: with php5 comment the following line:
1247 /*PHP5 patch*/$this = $user;
1248 $user = UpgradeUser($this, $user);
1249 $this->_level = WIKIAUTH_USER;
1250 return $this->_level;
1252 $this->_level = WIKIAUTH_ANON;
1253 return $this->_level;
1256 $this->userExists();
1257 return $this->_level;
1263 * This class is only to simplify the auth method dispatcher.
1264 * It inherits almost all all methods from _PassUser.
1266 class _PersonalPagePassUser
1269 var $_authmethod = 'PersonalPage';
1271 function userExists() {
1272 return $this->_HomePagehandle and $this->_HomePagehandle->exists();
1275 /** A PersonalPagePassUser requires PASSWORD_LENGTH_MINIMUM.
1276 * BUT if the user already has a homepage with an empty password
1277 * stored, allow login but warn him to change it.
1279 function checkPass($submitted_password) {
1280 if ($this->userExists()) {
1281 $stored_password = $this->_prefs->get('passwd');
1282 if (empty($stored_password)) {
1283 trigger_error(sprintf(
1284 _("\nYou stored an empty password in your '%s' page.\n").
1285 _("Your access permissions are only for a BogoUser.\n").
1286 _("Please set your password in UserPreferences."),
1287 $this->_userid), E_USER_NOTICE);
1288 $this->_level = WIKIAUTH_BOGO;
1289 return $this->_level;
1291 if ($this->_checkPass($submitted_password, $stored_password))
1292 return ($this->_level = WIKIAUTH_USER);
1293 return _PassUser::checkPass($submitted_password);
1295 return WIKIAUTH_ANON;
1300 * We have two possibilities here.
1301 * 1) The webserver location is already HTTP protected (usually Basic). Then just
1302 * use the username and do nothing
1303 * 2) The webserver location is not protected, so we enforce basic HTTP Protection
1304 * by sending a 401 error and let the client display the login dialog.
1305 * This makes only sense if HttpAuth is the last method in USER_AUTH_ORDER,
1306 * since the other methods cannot be transparently called after this enforced
1308 * Try the available auth methods (most likely Bogo) and sent this header back.
1309 * header('Authorization: Basic '.base64_encode("$userid:$passwd")."\r\n";
1311 class _HttpAuthPassUser
1314 function _HttpAuthPassUser($UserName='',$prefs=false) {
1315 if ($prefs) $this->_prefs = $prefs;
1316 if (!isset($this->_prefs->_method))
1317 _PassUser::_PassUser($UserName);
1318 if ($UserName) $this->_userid = $UserName;
1319 $this->_authmethod = 'HttpAuth';
1320 if ($this->userExists())
1323 return $GLOBALS['ForbiddenUser'];
1326 function _http_username() {
1327 if (!isset($_SERVER))
1328 $_SERVER =& $GLOBALS['HTTP_SERVER_VARS'];
1329 if (!empty($_SERVER['PHP_AUTH_USER']))
1330 return $_SERVER['PHP_AUTH_USER'];
1331 if (!empty($_SERVER['REMOTE_USER']))
1332 return $_SERVER['REMOTE_USER'];
1333 if (!empty($GLOBALS['HTTP_ENV_VARS']['REMOTE_USER']))
1334 return $GLOBALS['HTTP_ENV_VARS']['REMOTE_USER'];
1335 if (!empty($GLOBALS['REMOTE_USER']))
1336 return $GLOBALS['REMOTE_USER'];
1340 //force http auth authorization
1341 function userExists() {
1342 // todo: older php's
1343 $username = $this->_http_username();
1344 if (empty($username) or $username != $this->_userid) {
1345 header('WWW-Authenticate: Basic realm="'.WIKI_NAME.'"');
1346 header('HTTP/1.0 401 Unauthorized');
1349 $this->_userid = $username;
1350 $this->_level = WIKIAUTH_USER;
1354 function checkPass($submitted_password) {
1355 return $this->userExists() ? WIKIAUTH_USER : WIKIAUTH_ANON;
1358 function mayChangePass() {
1362 // hmm... either the server dialog or our own.
1363 function PrintLoginForm (&$request, $args, $fail_message = false,
1364 $seperate_page = true) {
1365 header('WWW-Authenticate: Basic realm="'.WIKI_NAME.'"');
1366 header('HTTP/1.0 401 Unauthorized');
1373 * Support reuse of existing user session from another application.
1374 * You have to define which session variable holds the userid, and
1375 * at what level is that user then. 1: BogoUser, 2: PassUser
1376 * define('AUTH_SESS_USER','userid');
1377 * define('AUTH_SESS_LEVEL',2);
1379 class _SessionPassUser
1382 function _SessionPassUser($UserName='',$prefs=false) {
1383 if ($prefs) $this->_prefs = $prefs;
1384 if (!defined("AUTH_SESS_USER") or !defined("AUTH_SESS_LEVEL")) {
1386 "AUTH_SESS_USER or AUTH_SESS_LEVEL is not defined for the SessionPassUser method",
1390 $sess =& $GLOBALS['HTTP_SESSION_VARS'];
1391 // user hash: "[user][userid]" or object "user->id"
1392 if (strstr(AUTH_SESS_USER,"][")) {
1393 $sess = $GLOBALS['HTTP_SESSION_VARS'];
1394 // recurse into hashes: "[user][userid]", sess = sess[user] => sess = sess[userid]
1395 foreach (split("][",AUTH_SESS_USER) as $v) {
1396 $v = str_replace(array("[","]"),'',$v);
1399 $this->_userid = $sess;
1400 } elseif (strstr(AUTH_SESS_USER,"->")) {
1401 // object "user->id" (no objects inside hashes supported!)
1402 list($obj,$key) = split("->",AUTH_SESS_USER);
1403 $this->_userid = $sess[$obj]->$key;
1405 $this->_userid = $sess[AUTH_SESS_USER];
1407 if (!isset($this->_prefs->_method))
1408 _PassUser::_PassUser($this->_userid);
1409 $this->_level = AUTH_SESS_LEVEL;
1410 $this->_authmethod = 'Session';
1412 function userExists() {
1413 return !empty($this->_userid);
1415 function checkPass($submitted_password) {
1416 return $this->userExists() and $this->_level;
1418 function mayChangePass() {
1424 * Baseclass for PearDB and ADODB PassUser's
1425 * Authenticate against a database, to be able to use shared users.
1426 * internal: no different $DbAuthParams['dsn'] defined, or
1427 * external: different $DbAuthParams['dsn']
1428 * The magic is done in the symbolic SQL statements in index.php, similar to
1431 * We support only the SQL and ADODB backends.
1432 * The other WikiDB backends (flat, cvs, dba, ...) should be used for pages,
1433 * not for auth stuff. If one would like to use e.g. dba for auth, he should
1434 * use PearDB (SQL) with the right $DBAuthParam['auth_dsn'].
1435 * (Not supported yet, since we require SQL. SQLite would make since when
1436 * it will come to PHP)
1438 * @tables: user, pref
1440 * Preferences are handled in the parent class _PassUser, because the
1441 * previous classes may also use DB pref_select and pref_update.
1443 * Flat files auth is handled by the auth method "File".
1448 var $_authselect, $_authupdate, $_authcreate;
1450 // This can only be called from _PassUser, because the parent class
1451 // sets the auth_dbi and pref methods, before this class is initialized.
1452 function _DbPassUser($UserName='',$prefs=false) {
1453 if (!$this->_prefs) {
1454 if ($prefs) $this->_prefs = $prefs;
1456 if (!isset($this->_prefs->_method))
1457 _PassUser::_PassUser($UserName);
1458 $this->_authmethod = 'Db';
1459 //$this->getAuthDbh();
1460 //$this->_auth_crypt_method = @$GLOBALS['DBAuthParams']['auth_crypt_method'];
1461 $dbi =& $GLOBALS['request']->_dbi;
1462 $dbtype = $dbi->getParam('dbtype');
1463 if ($dbtype == 'ADODB') {
1464 if (check_php_version(5))
1465 return new _AdoDbPassUser($UserName,$this->_prefs);
1467 $user = new _AdoDbPassUser($UserName,$this->_prefs);
1468 //todo: with php5 comment the following line:
1469 /*PHP5 patch*/$this = $user;
1473 elseif ($dbtype == 'SQL') {
1474 if (check_php_version(5))
1475 return new _PearDbPassUser($UserName,$this->_prefs);
1477 $user = new _PearDbPassUser($UserName,$this->_prefs);
1478 //todo: with php5 comment the following line:
1479 /*PHP5 patch*/$this = $user;
1486 function mayChangePass() {
1487 return !isset($this->_authupdate);
1492 class _PearDbPassUser
1496 * Now optimized not to use prepare, ...query(sprintf($sql,quote())) instead.
1497 * We use FETCH_MODE_ROW, so we don't need aliases in the auth_* SQL statements.
1503 var $_authmethod = 'PearDb';
1504 function _PearDbPassUser($UserName='',$prefs=false) {
1505 //global $DBAuthParams;
1506 if (!$this->_prefs and isa($this,"_PearDbPassUser")) {
1507 if ($prefs) $this->_prefs = $prefs;
1509 if (!isset($this->_prefs->_method))
1510 _PassUser::_PassUser($UserName);
1511 $this->_userid = $UserName;
1512 // make use of session data. generally we only initialize this every time,
1513 // but do auth checks only once
1514 $this->_auth_crypt_method = $GLOBALS['request']->_dbi->getAuthParam('auth_crypt_method');
1518 function getPreferences() {
1519 // override the generic slow method here for efficiency and not to
1520 // clutter the homepage metadata with prefs.
1521 _AnonUser::getPreferences();
1522 $this->getAuthDbh();
1523 if (isset($this->_prefs->_select)) {
1524 $dbh = &$this->_auth_dbi;
1525 $db_result = $dbh->query(sprintf($this->_prefs->_select,$dbh->quote($this->_userid)));
1526 // patched by frederik@pandora.be
1527 $prefs = $db_result->fetchRow();
1528 $prefs_blob = @$prefs["prefs"];
1529 if ($restored_from_db = $this->_prefs->retrieve($prefs_blob)) {
1530 $updated = $this->_prefs->updatePrefs($restored_from_db);
1531 //$this->_prefs = new UserPreferences($restored_from_db);
1532 return $this->_prefs;
1535 if ($this->_HomePagehandle) {
1536 if ($restored_from_page = $this->_prefs->retrieve($this->_HomePagehandle->get('pref'))) {
1537 $updated = $this->_prefs->updatePrefs($restored_from_page);
1538 //$this->_prefs = new UserPreferences($restored_from_page);
1539 return $this->_prefs;
1542 return $this->_prefs;
1545 function setPreferences($prefs, $id_only=false) {
1546 // if the prefs are changed
1547 if ($count = _AnonUser::setPreferences($prefs, 1)) {
1549 //$user = $request->_user;
1550 //unset($user->_auth_dbi);
1551 // this must be done in $request->_setUser, not here!
1552 //$request->setSessionVar('wiki_user', $user);
1553 $this->getAuthDbh();
1554 $packed = $this->_prefs->store();
1555 if (!$id_only and isset($this->_prefs->_update)) {
1556 $dbh = &$this->_auth_dbi;
1557 $dbh->simpleQuery(sprintf($this->_prefs->_update,
1558 $dbh->quote($packed),
1559 $dbh->quote($this->_userid)));
1561 if ($this->_HomePagehandle and $this->_HomePagehandle->get('pref'))
1562 $this->_HomePagehandle->set('pref', '');
1564 //store prefs in homepage, not in cookie
1565 if ($this->_HomePagehandle and !$id_only)
1566 $this->_HomePagehandle->set('pref', $packed);
1568 return $count; //count($this->_prefs->unpack($packed));
1573 function userExists() {
1574 //global $DBAuthParams;
1575 $this->getAuthDbh();
1576 $dbh = &$this->_auth_dbi;
1577 if (!$dbh) { // needed?
1578 return $this->_tryNextUser();
1580 $dbi =& $GLOBALS['request']->_dbi;
1581 // Prepare the configured auth statements
1582 if ($dbi->getAuthParam('auth_check') and empty($this->_authselect)) {
1583 $this->_authselect = $this->prepare($dbi->getAuthParam('auth_check'),
1584 array("userid", "password"));
1586 if (empty($this->_authselect))
1587 trigger_error(fmt("Either %s is missing or DATABASE_TYPE != '%s'",
1588 'DBAUTH_AUTH_CHECK', 'SQL'),
1590 //NOTE: for auth_crypt_method='crypt' no special auth_user_exists is needed
1591 if ($this->_auth_crypt_method == 'crypt') {
1592 $rs = $dbh->query(sprintf($this->_authselect, $dbh->quote($this->_userid)));
1597 if (! $dbi->getAuthParam('auth_user_exists'))
1598 trigger_error(fmt("%s is missing",'DBAUTH_AUTH_USER_EXISTS'),
1600 $this->_authcheck = $this->prepare($dbi->getAuthParam('auth_user_exists'),"userid");
1601 $rs = $dbh->query(sprintf($this->_authcheck, $dbh->quote($this->_userid)));
1605 // maybe the user is allowed to create himself. Generally not wanted in
1606 // external databases, but maybe wanted for the wiki database, for performance
1608 if (empty($this->_authcreate) and $dbi->getAuthParam('auth_create')) {
1609 $this->_authcreate = $this->prepare($dbh->getAuthParam('auth_create'),
1610 array("userid", "password"));
1612 if (!empty($this->_authcreate)) {
1613 $dbh->simpleQuery(sprintf($this->_authcreate,
1614 $dbh->quote($GLOBALS['HTTP_POST_VARS']['auth']['passwd']),
1615 $dbh->quote($this->_userid)
1619 return $this->_tryNextUser();
1622 function checkPass($submitted_password) {
1623 //global $DBAuthParams;
1624 $this->getAuthDbh();
1625 if (!$this->_auth_dbi) { // needed?
1626 return $this->_tryNextPass($submitted_password);
1628 if (!isset($this->_authselect))
1629 $this->userExists();
1630 if (!isset($this->_authselect))
1631 trigger_error(fmt("Either %s is missing or DATABASE_TYPE != '%s'",
1632 'DBAUTH_AUTH_CHECK','SQL'),
1635 //NOTE: for auth_crypt_method='crypt' defined('ENCRYPTED_PASSWD',true) must be set
1636 $dbh = &$this->_auth_dbi;
1637 if ($this->_auth_crypt_method == 'crypt') {
1638 $stored_password = $dbh->getOne(sprintf($this->_authselect, $dbh->quote($this->_userid)));
1639 $result = $this->_checkPass($submitted_password, $stored_password);
1641 $okay = $dbh->getOne(sprintf($this->_authselect,
1642 $dbh->quote($submitted_password),
1643 $dbh->quote($this->_userid)));
1644 $result = !empty($okay);
1648 $this->_level = WIKIAUTH_USER;
1649 return $this->_level;
1651 return $this->_tryNextPass($submitted_password);
1655 function mayChangePass() {
1656 return $GLOBALS['request']->_dbi->getAuthParam('auth_update');
1659 function storePass($submitted_password) {
1660 $this->getAuthDbh();
1661 $dbh = &$this->_auth_dbi;
1662 $dbi =& $GLOBALS['request']->_dbi;
1663 if ($dbi->getAuthParam('auth_update') and empty($this->_authupdate)) {
1664 $this->_authupdate = $this->prepare($dbi->getAuthParam('auth_update'),
1665 array("userid", "password"));
1667 if (empty($this->_authupdate)) {
1668 trigger_error(fmt("Either %s is missing or DATABASE_TYPE != '%s'",
1669 'DBAUTH_AUTH_UPDATE','SQL'),
1674 if ($this->_auth_crypt_method == 'crypt') {
1675 if (function_exists('crypt'))
1676 $submitted_password = crypt($submitted_password);
1678 $dbh->simpleQuery(sprintf($this->_authupdate,
1679 $dbh->quote($submitted_password),
1680 $dbh->quote($this->_userid)
1685 class _AdoDbPassUser
1689 * Simple sprintf, no prepare.
1691 * Warning: Since we use FETCH_MODE_ASSOC (string hash) and not the also faster
1692 * FETCH_MODE_ROW (numeric), we have to use the correct aliases in auth_* sql statements!
1694 * TODO: Change FETCH_MODE in adodb WikiDB sublasses.
1699 var $_authmethod = 'AdoDb';
1700 function _AdoDbPassUser($UserName='',$prefs=false) {
1701 if (!$this->_prefs and isa($this,"_AdoDbPassUser")) {
1702 if ($prefs) $this->_prefs = $prefs;
1703 if (!isset($this->_prefs->_method))
1704 _PassUser::_PassUser($UserName);
1706 $this->_userid = $UserName;
1707 $this->getAuthDbh();
1708 $this->_auth_crypt_method = $GLOBALS['request']->_dbi->getAuthParam('auth_crypt_method');
1709 // Don't prepare the configured auth statements anymore
1713 function getPreferences() {
1714 // override the generic slow method here for efficiency
1715 _AnonUser::getPreferences();
1716 $this->getAuthDbh();
1717 if (isset($this->_prefs->_select)) {
1718 $dbh = & $this->_auth_dbi;
1719 $rs = $dbh->Execute(sprintf($this->_prefs->_select, $dbh->qstr($this->_userid)));
1723 $prefs_blob = @$rs->fields['prefs'];
1725 if ($restored_from_db = $this->_prefs->retrieve($prefs_blob)) {
1726 $updated = $this->_prefs->updatePrefs($restored_from_db);
1727 //$this->_prefs = new UserPreferences($restored_from_db);
1728 return $this->_prefs;
1732 if ($this->_HomePagehandle) {
1733 if ($restored_from_page = $this->_prefs->retrieve($this->_HomePagehandle->get('pref'))) {
1734 $updated = $this->_prefs->updatePrefs($restored_from_page);
1735 //$this->_prefs = new UserPreferences($restored_from_page);
1736 return $this->_prefs;
1739 return $this->_prefs;
1742 function setPreferences($prefs, $id_only=false) {
1743 // if the prefs are changed
1744 if (_AnonUser::setPreferences($prefs, 1)) {
1746 $packed = $this->_prefs->store();
1747 //$user = $request->_user;
1748 //unset($user->_auth_dbi);
1749 if (!$id_only and isset($this->_prefs->_update)) {
1750 $this->getAuthDbh();
1751 $dbh = &$this->_auth_dbi;
1752 $db_result = $dbh->Execute(sprintf($this->_prefs->_update,
1753 $dbh->qstr($packed),
1754 $dbh->qstr($this->_userid)));
1755 $db_result->Close();
1757 if ($this->_HomePagehandle and $this->_HomePagehandle->get('pref'))
1758 $this->_HomePagehandle->set('pref', '');
1760 //store prefs in homepage, not in cookie
1761 if ($this->_HomePagehandle and !$id_only)
1762 $this->_HomePagehandle->set('pref', $packed);
1764 return count($this->_prefs->unpack($packed));
1769 function userExists() {
1770 $this->getAuthDbh();
1771 $dbh = &$this->_auth_dbi;
1772 if (!$dbh) { // needed?
1773 return $this->_tryNextUser();
1775 $dbi =& $GLOBALS['request']->_dbi;
1776 if (empty($this->_authselect) and $dbi->getAuthParam('auth_check')) {
1777 $this->_authselect = $this->prepare($dbi->getAuthParam('auth_check'),
1778 array("userid","password"));
1780 if (empty($this->_authselect))
1781 trigger_error(fmt("Either %s is missing or DATABASE_TYPE != '%s'",
1782 'DBAUTH_AUTH_CHECK', 'ADODB'),
1784 //NOTE: for auth_crypt_method='crypt' no special auth_user_exists is needed
1785 if ($this->_auth_crypt_method == 'crypt') {
1786 $rs = $dbh->Execute(sprintf($this->_authselect, $dbh->qstr($this->_userid)));
1795 if (! $dbi->getAuthParam('auth_user_exists'))
1796 trigger_error(fmt("%s is missing", 'DBAUTH_AUTH_USER_EXISTS'),
1798 $this->_authcheck = $this->prepare($dbi->getAuthParam('auth_user_exists'), 'userid');
1799 $rs = $dbh->Execute(sprintf($this->_authcheck, $dbh->qstr($this->_userid)));
1807 // maybe the user is allowed to create himself. Generally not wanted in
1808 // external databases, but maybe wanted for the wiki database, for performance
1810 if (empty($this->_authcreate) and $dbi->getAuthParam('auth_create')) {
1811 $this->_authcreate = $this->prepare($dbi->getAuthParam('auth_create'),
1812 array("userid", "password"));
1814 if (!empty($this->_authcreate) and
1815 isset($GLOBALS['HTTP_POST_VARS']['auth']) and
1816 isset($GLOBALS['HTTP_POST_VARS']['auth']['passwd']))
1818 $dbh->Execute(sprintf($this->_authcreate,
1819 $dbh->qstr($GLOBALS['HTTP_POST_VARS']['auth']['passwd']),
1820 $dbh->qstr($this->_userid)));
1824 return $this->_tryNextUser();
1827 function checkPass($submitted_password) {
1828 //global $DBAuthParams;
1829 $this->getAuthDbh();
1830 if (!$this->_auth_dbi) { // needed?
1831 return $this->_tryNextPass($submitted_password);
1833 $dbh =& $this->_auth_dbi;
1834 $dbi =& $GLOBALS['request']->_dbi;
1835 if (empty($this->_authselect) and $dbi->getAuthParam('auth_check')) {
1836 $this->_authselect = $this->prepare($dbi->getAuthParam('auth_check'),
1837 array("userid", "password"));
1839 if (!isset($this->_authselect))
1840 $this->userExists();
1841 if (!isset($this->_authselect))
1842 trigger_error(fmt("Either %s is missing or DATABASE_TYPE != '%s'",
1843 'DBAUTH_AUTH_CHECK', 'ADODB'),
1845 //NOTE: for auth_crypt_method='crypt' defined('ENCRYPTED_PASSWD',true) must be set
1846 if ($this->_auth_crypt_method == 'crypt') {
1847 $rs = $dbh->Execute(sprintf($this->_authselect, $dbh->qstr($this->_userid)));
1849 $stored_password = $rs->fields['password'];
1851 $result = $this->_checkPass($submitted_password, $stored_password);
1857 $rs = $dbh->Execute(sprintf($this->_authselect,
1858 $dbh->qstr($submitted_password),
1859 $dbh->qstr($this->_userid)));
1860 $okay = $rs->fields['ok'];
1862 $result = !empty($okay);
1866 $this->_level = WIKIAUTH_USER;
1867 return $this->_level;
1869 return $this->_tryNextPass($submitted_password);
1873 function mayChangePass() {
1874 return $GLOBALS['request']->_dbi->getAuthParam('auth_update');
1877 function storePass($submitted_password) {
1878 $this->getAuthDbh();
1879 $dbh = &$this->_auth_dbi;
1880 $dbi =& $GLOBALS['request']->_dbi;
1881 if ($dbi->getAuthParam('auth_update') and empty($this->_authupdate)) {
1882 $this->_authupdate = $this->prepare($dbi->getAuthParam('auth_update'),
1883 array("userid", "password"));
1885 if (!isset($this->_authupdate)) {
1886 trigger_error(fmt("Either %s is missing or DATABASE_TYPE != '%s'",
1887 'DBAUTH_AUTH_UPDATE', 'ADODB'),
1892 if ($this->_auth_crypt_method == 'crypt') {
1893 if (function_exists('crypt'))
1894 $submitted_password = crypt($submitted_password);
1896 $rs = $dbh->Execute(sprintf($this->_authupdate,
1897 $dbh->qstr($submitted_password),
1898 $dbh->qstr($this->_userid)
1909 * Define the vars LDAP_AUTH_HOST and LDAP_BASE_DN in index.php
1911 * Preferences are handled in _PassUser
1914 function checkPass($submitted_password) {
1915 global $LDAP_SET_OPTION;
1917 $this->_authmethod = 'LDAP';
1918 $userid = $this->_userid;
1919 if ($ldap = ldap_connect(LDAP_AUTH_HOST)) { // must be a valid LDAP server!
1920 if (defined('LDAP_AUTH_USER'))
1921 if (defined('LDAP_AUTH_PASSWORD'))
1922 // Windows Active Directory Server is strict
1923 $r = @ldap_bind($ldap,LDAP_AUTH_USER,LDAP_AUTH_PASSWORD);
1925 $r = @ldap_bind($ldap,LDAP_AUTH_USER);
1927 $r = @ldap_bind($ldap); // this is an anonymous bind
1928 if (!empty($LDAP_SET_OPTION)) {
1929 foreach ($LDAP_SET_OPTION as $key => $value) {
1930 if (is_string($key) and defined($key))
1931 $key = constant($key);
1932 ldap_set_option($ldap,$key,$value);
1935 // Need to set the right root search information. see ../index.php
1936 $st_search = defined('LDAP_SEARCH_FIELD')
1937 ? LDAP_SEARCH_FIELD."=$userid"
1939 $sr = ldap_search($ldap, LDAP_BASE_DN, $st_search);
1940 $info = ldap_get_entries($ldap, $sr);
1941 // there may be more hits with this userid.
1942 // of course it would be better to narrow down the BASE_DN
1943 for ($i = 0; $i < $info["count"]; $i++) {
1944 $dn = $info[$i]["dn"];
1945 // The password is still plain text.
1946 if ($r = @ldap_bind($ldap, $dn, $submitted_password)) {
1947 // ldap_bind will return TRUE if everything matches
1949 $this->_level = WIKIAUTH_USER;
1950 return $this->_level;
1954 trigger_error(fmt("Unable to connect to LDAP server %s", LDAP_AUTH_HOST),
1959 return $this->_tryNextPass($submitted_password);
1962 function userExists() {
1963 global $LDAP_SET_OPTION;
1965 $userid = $this->_userid;
1966 if ($ldap = ldap_connect(LDAP_AUTH_HOST)) { // must be a valid LDAP server!
1967 if (defined('LDAP_AUTH_USER'))
1968 if (defined('LDAP_AUTH_PASSWORD'))
1969 // Windows Active Directory Server is strict
1970 $r = @ldap_bind($ldap,LDAP_AUTH_USER,LDAP_AUTH_PASSWORD);
1972 $r = @ldap_bind($ldap,LDAP_AUTH_USER);
1974 $r = @ldap_bind($ldap); // this is an anonymous bind
1975 if (!empty($LDAP_SET_OPTION)) {
1976 foreach ($LDAP_SET_OPTION as $key => $value) {
1977 ldap_set_option($ldap,$key,$value);
1980 // Need to set the right root search information. see ../index.php
1981 $st_search = defined('LDAP_SEARCH_FIELD')
1982 ? LDAP_SEARCH_FIELD."=$userid"
1984 $sr = ldap_search($ldap, LDAP_BASE_DN, $st_search);
1985 $info = ldap_get_entries($ldap, $sr);
1987 if ($info["count"] > 0) {
1992 trigger_error(_("Unable to connect to LDAP server "). LDAP_AUTH_HOST, E_USER_WARNING);
1995 return $this->_tryNextUser();
1998 function mayChangePass() {
2007 * Define the var IMAP_AUTH_HOST in index.php (with port probably)
2009 * Preferences are handled in _PassUser
2012 function checkPass($submitted_password) {
2013 $userid = $this->_userid;
2014 $mbox = @imap_open( "{" . IMAP_AUTH_HOST . "}",
2015 $userid, $submitted_password, OP_HALFOPEN );
2018 $this->_authmethod = 'IMAP';
2019 $this->_level = WIKIAUTH_USER;
2020 return $this->_level;
2022 trigger_error(_("Unable to connect to IMAP server "). IMAP_AUTH_HOST, E_USER_WARNING);
2025 return $this->_tryNextPass($submitted_password);
2028 //CHECKME: this will not be okay for the auth policy strict
2029 function userExists() {
2031 if (checkPass($this->_prefs->get('passwd')))
2034 return $this->_tryNextUser();
2037 function mayChangePass() {
2044 extends _IMAPPassUser {
2046 * Define the var POP3_AUTH_HOST in index.php
2047 * Preferences are handled in _PassUser
2049 function checkPass($submitted_password) {
2050 $userid = $this->_userid;
2051 $pass = $submitted_password;
2052 $host = defined('POP3_AUTH_HOST') ? POP3_AUTH_HOST : 'localhost:110';
2053 if (defined('POP3_AUTH_PORT'))
2054 $port = POP3_AUTH_PORT;
2055 elseif (strstr($host,':')) {
2056 list(,$port) = split(':',$host);
2061 $fp = fsockopen($host, $port, $errno, $errstr, 10);
2063 // Get welcome string
2064 $line = fgets($fp, 1024);
2065 if (! strncmp("+OK ", $line, 4)) {
2067 fputs($fp, "user $userid\n");
2069 $line = fgets($fp, 1024);
2070 if (! strncmp("+OK ", $line, 4)) {
2072 fputs($fp, "pass $pass\n");
2074 $line = fgets($fp, 1024);
2075 if (! strncmp("+OK ", $line, 4)) {
2080 // quit the connection
2081 fputs($fp, "quit\n");
2082 // Get the sayonara message
2083 $line = fgets($fp, 1024);
2086 trigger_error(_("Couldn't connect to %s","POP3_AUTH_HOST ".$host.':'.$port),
2089 $this->_authmethod = 'POP3';
2091 $this->_level = WIKIAUTH_USER;
2093 $this->_level = WIKIAUTH_ANON;
2095 return $this->_level;
2102 * Check users defined in a .htaccess style file
2103 * username:crypt\n...
2105 * Preferences are handled in _PassUser
2108 var $_file, $_may_change;
2110 // This can only be called from _PassUser, because the parent class
2111 // sets the pref methods, before this class is initialized.
2112 function _FilePassUser($UserName='', $prefs=false, $file='') {
2113 if (!$this->_prefs and isa($this, "_FilePassUser")) {
2114 if ($prefs) $this->_prefs = $prefs;
2115 if (!isset($this->_prefs->_method))
2116 _PassUser::_PassUser($UserName);
2119 $this->_userid = $UserName;
2120 // read the .htaccess style file. We use our own copy of the standard pear class.
2121 //include_once 'lib/pear/File_Passwd.php';
2122 $this->_may_change = defined('AUTH_USER_FILE_STORABLE') && AUTH_USER_FILE_STORABLE;
2123 if (empty($file) and defined('AUTH_USER_FILE'))
2124 $file = AUTH_USER_FILE;
2125 // if passwords may be changed we have to lock them:
2126 if ($this->_may_change) {
2128 $lockfile = $file . ".lock";
2133 include_once(dirname(__FILE__)."/pear/File_Passwd.php"); // same style as in main.php
2134 // "__PHP_Incomplete_Class"
2135 if (!empty($file) or empty($this->_file) or !isa($this->_file,"File_Passwd"))
2136 $this->_file = new File_Passwd($file, $lock, $lockfile);
2142 function mayChangePass() {
2143 return $this->_may_change;
2146 function userExists() {
2147 $this->_authmethod = 'File';
2148 if (isset($this->_file->users[$this->_userid]))
2151 return $this->_tryNextUser();
2154 function checkPass($submitted_password) {
2155 //include_once 'lib/pear/File_Passwd.php';
2156 if ($this->_file->verifyPassword($this->_userid,$submitted_password)) {
2157 $this->_authmethod = 'File';
2158 $this->_level = WIKIAUTH_USER;
2159 return $this->_level;
2162 return $this->_tryNextPass($submitted_password);
2165 function storePass($submitted_password) {
2166 if ($this->_may_change) {
2167 if ($this->_file->modUser($this->_userid,$submitted_password)) {
2168 $this->_file->close();
2169 $this->_file = new File_Passwd($this->_file->_filename, true, $this->_file->lockfile);
2179 * Insert more auth classes here...
2180 * For example a customized db class for another db connection
2181 * or a socket-based auth server.
2187 * For security, this class should not be extended. Instead, extend
2188 * from _PassUser (think of this as unix "root").
2193 function mayChangePass() {
2196 function checkPass($submitted_password) {
2197 $stored_password = ADMIN_PASSWD;
2198 if ($this->_checkPass($submitted_password, $stored_password)) {
2199 $this->_level = WIKIAUTH_ADMIN;
2200 return $this->_level;
2202 $this->_level = WIKIAUTH_ANON;
2203 return $this->_level;
2206 function storePass($submitted_password) {
2211 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2213 * Various data classes for the preference types,
2214 * to support get, set, sanify (range checking, ...)
2215 * update() will do the neccessary side-effects if a
2216 * setting gets changed (theme, language, ...)
2219 class _UserPreference
2223 function _UserPreference ($default_value) {
2224 $this->default_value = $default_value;
2227 function sanify ($value) {
2228 return (string)$value;
2231 function get ($name) {
2232 if (isset($this->{$name}))
2233 return $this->{$name};
2235 return $this->default_value;
2238 function getraw ($name) {
2239 if (!empty($this->{$name}))
2240 return $this->{$name};
2243 // stores the value as $this->$name, and not as $this->value (clever?)
2244 function set ($name, $value) {
2246 $value = $this->sanify($value);
2247 if ($this->get($name) != $value) {
2248 $this->update($value);
2251 if ($value != $this->default_value) {
2252 $this->{$name} = $value;
2254 unset($this->{$name});
2259 // default: no side-effects
2260 function update ($value) {
2265 class _UserPreference_numeric
2266 extends _UserPreference
2268 function _UserPreference_numeric ($default, $minval = false,
2270 $this->_UserPreference((double)$default);
2271 $this->_minval = (double)$minval;
2272 $this->_maxval = (double)$maxval;
2275 function sanify ($value) {
2276 $value = (double)$value;
2277 if ($this->_minval !== false && $value < $this->_minval)
2278 $value = $this->_minval;
2279 if ($this->_maxval !== false && $value > $this->_maxval)
2280 $value = $this->_maxval;
2285 class _UserPreference_int
2286 extends _UserPreference_numeric
2288 function _UserPreference_int ($default, $minval = false, $maxval = false) {
2289 $this->_UserPreference_numeric((int)$default, (int)$minval, (int)$maxval);
2292 function sanify ($value) {
2293 return (int)parent::sanify((int)$value);
2297 class _UserPreference_bool
2298 extends _UserPreference
2300 function _UserPreference_bool ($default = false) {
2301 $this->_UserPreference((bool)$default);
2304 function sanify ($value) {
2305 if (is_array($value)) {
2306 /* This allows for constructs like:
2308 * <input type="hidden" name="pref[boolPref][]" value="0" />
2309 * <input type="checkbox" name="pref[boolPref][]" value="1" />
2311 * (If the checkbox is not checked, only the hidden input
2312 * gets sent. If the checkbox is sent, both inputs get
2315 foreach ($value as $val) {
2321 return (bool) $value;
2325 class _UserPreference_language
2326 extends _UserPreference
2328 function _UserPreference_language ($default = DEFAULT_LANGUAGE) {
2329 $this->_UserPreference($default);
2332 // FIXME: check for valid locale
2333 function sanify ($value) {
2334 // Revert to DEFAULT_LANGUAGE if user does not specify
2335 // language in UserPreferences or chooses <system language>.
2336 if ($value == '' or empty($value))
2337 $value = DEFAULT_LANGUAGE;
2339 return (string) $value;
2342 function update ($newvalue) {
2343 if (! $this->_init ) {
2344 // invalidate etag to force fresh output
2345 $GLOBALS['request']->setValidators(array('%mtime' => false));
2346 update_locale($newvalue ? $newvalue : $GLOBALS['LANG']);
2351 class _UserPreference_theme
2352 extends _UserPreference
2354 function _UserPreference_theme ($default = THEME) {
2355 $this->_UserPreference($default);
2358 function sanify ($value) {
2359 if (!empty($value) and FindFile($this->_themefile($value)))
2361 return $this->default_value;
2364 function update ($newvalue) {
2366 // invalidate etag to force fresh output
2367 if (! $this->_init )
2368 $GLOBALS['request']->setValidators(array('%mtime' => false));
2370 include_once($this->_themefile($newvalue));
2372 include_once($this->_themefile(THEME));
2375 function _themefile ($theme) {
2376 return "themes/$theme/themeinfo.php";
2380 class _UserPreference_notify
2381 extends _UserPreference
2383 function sanify ($value) {
2387 return $this->default_value;
2390 /** update to global user prefs: side-effect on set notify changes
2391 * use a global_data notify hash:
2392 * notify = array('pagematch' => array(userid => ('email' => mail,
2393 * 'verified' => 0|1),
2397 function update ($value) {
2398 if (!empty($this->_init)) return;
2399 $dbh = $GLOBALS['request']->getDbh();
2400 $notify = $dbh->get('notify');
2405 // expand to existing pages only or store matches?
2406 // for now we store (glob-style) matches which is easier for the user
2407 $pages = $this->_page_split($value);
2408 // Limitation: only current user.
2409 $user = $GLOBALS['request']->getUser();
2410 if (!$user or !method_exists($user,'UserName')) return;
2411 // This fails with php5 and a WIKI_ID cookie:
2412 $userid = $user->UserName();
2413 $email = $user->_prefs->get('email');
2414 $verified = $user->_prefs->_prefs['email']->getraw('emailVerified');
2415 // check existing notify hash and possibly delete pages for email
2416 if (!empty($data)) {
2417 foreach ($data as $page => $users) {
2418 if (isset($data[$page][$userid]) and !in_array($page, $pages)) {
2419 unset($data[$page][$userid]);
2421 if (count($data[$page]) == 0)
2422 unset($data[$page]);
2425 // add the new pages
2426 if (!empty($pages)) {
2427 foreach ($pages as $page) {
2428 if (!isset($data[$page]))
2429 $data[$page] = array();
2430 if (!isset($data[$page][$userid])) {
2431 // should we really store the verification notice here or
2432 // check it dynamically at every page->save?
2434 $data[$page][$userid] = array('email' => $email,
2435 'verified' => $verified);
2437 $data[$page][$userid] = array('email' => $email);
2442 // store users changes
2443 $dbh->set('notify',$data);
2446 /** split the user-given comma or whitespace delimited pagenames
2449 function _page_split($value) {
2450 return preg_split('/[\s,]+/',$value,-1,PREG_SPLIT_NO_EMPTY);
2454 class _UserPreference_email
2455 extends _UserPreference
2457 function sanify($value) {
2458 // check for valid email address
2459 if ($this->get('email') == $value and $this->getraw('emailVerified'))
2462 if ($value == 1 or $value === true)
2464 list($ok,$msg) = ValidateMail($value,'noconnect');
2468 trigger_error("E-Mail Validation Error: ".$msg, E_USER_WARNING);
2469 return $this->default_value;
2473 /** Side-effect on email changes:
2474 * Send a verification mail or for now just a notification email.
2475 * For true verification (value = 2), we'd need a mailserver hook.
2477 function update($value) {
2478 if (!empty($this->_init)) return;
2479 $verified = $this->getraw('emailVerified');
2481 if (($value == 1 or $value === true) and $verified)
2483 if (!empty($value) and !$verified) {
2484 list($ok,$msg) = ValidateMail($value);
2485 if ($ok and mail($value,"[".WIKI_NAME ."] "._("Email Verification"),
2486 sprintf(_("Welcome to %s!\nYou email account is verified and\nwill be used to send pagechange notifications.\nSee %s"),
2487 WIKI_NAME, WikiURL($GLOBALS['request']->getArg('pagename'),'',true))))
2488 $this->set('emailVerified',1);
2493 /** Check for valid email address
2494 fixed version from http://www.zend.com/zend/spotlight/ev12apr.php
2496 function ValidateMail($email, $noconnect=false) {
2497 $HTTP_HOST = $GLOBALS['request']->get('HTTP_HOST');
2499 // well, technically ".a.a.@host.com" is also valid
2500 if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
2502 $result[1] = sprintf(_("E-Mail address '%s' is not properly formatted"), $email);
2506 return array(true,sprintf(_("E-Mail address '%s' is properly formatted"), $email));
2508 list ( $Username, $Domain ) = split ("@",$email);
2509 //Todo: getmxrr workaround on windows or manual input field to verify it manually
2510 if (!isWindows() and getmxrr($Domain, $MXHost)) { // avoid warning on Windows.
2511 $ConnectAddress = $MXHost[0];
2513 $ConnectAddress = $Domain;
2515 $Connect = fsockopen ( $ConnectAddress, 25 );
2517 if (ereg("^220", $Out = fgets($Connect, 1024))) {
2518 fputs ($Connect, "HELO $HTTP_HOST\r\n");
2519 $Out = fgets ( $Connect, 1024 );
2520 fputs ($Connect, "MAIL FROM: <".$email.">\r\n");
2521 $From = fgets ( $Connect, 1024 );
2522 fputs ($Connect, "RCPT TO: <".$email.">\r\n");
2523 $To = fgets ($Connect, 1024);
2524 fputs ($Connect, "QUIT\r\n");
2526 if (!ereg ("^250", $From)) {
2528 $result[1]="Server rejected address: ". $From;
2531 if (!ereg ( "^250", $To )) {
2533 $result[1]="Server rejected address: ". $To;
2538 $result[1] = "No response from server";
2543 $result[1]="Can not connect E-Mail server.";
2547 $result[1]="E-Mail address '$email' appears to be valid.";
2549 } // end of function
2551 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2556 * This object holds the $request->_prefs subobjects.
2557 * A simple packed array of non-default values get's stored as cookie,
2558 * homepage, or database, which are converted to the array of
2560 * We don't store the objects, because otherwise we will
2561 * not be able to upgrade any subobject. And it's a waste of space also.
2564 class UserPreferences
2566 function UserPreferences($saved_prefs = false) {
2567 // userid stored too, to ensure the prefs are being loaded for
2568 // the correct (currently signing in) userid if stored in a
2570 // Update: for db prefs we disallow passwd.
2571 // userid is needed for pref reflexion. current pref must know its username,
2572 // if some app needs prefs from different users, different from current user.
2575 'userid' => new _UserPreference(''),
2576 'passwd' => new _UserPreference(''),
2577 'autologin' => new _UserPreference_bool(),
2578 //'emailVerified' => new _UserPreference_emailVerified(),
2579 //fixed: store emailVerified as email parameter, 1.3.8
2580 'email' => new _UserPreference_email(''),
2581 'notifyPages' => new _UserPreference_notify(''), // 1.3.8
2582 'theme' => new _UserPreference_theme(THEME),
2583 'lang' => new _UserPreference_language(DEFAULT_LANGUAGE),
2584 'editWidth' => new _UserPreference_int(EDITWIDTH_DEFAULT_COLS,
2586 EDITWIDTH_MAX_COLS),
2587 'noLinkIcons' => new _UserPreference_bool(), // 1.3.8
2588 'editHeight' => new _UserPreference_int(EDITHEIGHT_DEFAULT_ROWS,
2589 EDITHEIGHT_MIN_ROWS,
2590 EDITHEIGHT_DEFAULT_ROWS),
2591 'timeOffset' => new _UserPreference_numeric(TIMEOFFSET_DEFAULT_HOURS,
2592 TIMEOFFSET_MIN_HOURS,
2593 TIMEOFFSET_MAX_HOURS),
2594 'relativeDates' => new _UserPreference_bool(),
2595 'googleLink' => new _UserPreference_bool(), // 1.3.10
2597 // add custom theme-specific pref types:
2598 // FIXME: on theme changes the wiki_user session pref object will fail.
2599 // We will silently ignore this.
2600 if (!empty($customUserPreferenceColumns))
2601 $this->_prefs = array_merge($this->_prefs,$customUserPreferenceColumns);
2603 if (isset($this->_method) and $this->_method == 'SQL') {
2604 //unset($this->_prefs['userid']);
2605 unset($this->_prefs['passwd']);
2608 if (is_array($saved_prefs)) {
2609 foreach ($saved_prefs as $name => $value)
2610 $this->set($name, $value);
2614 function _getPref($name) {
2615 if ($name == 'emailVerified')
2617 if (!isset($this->_prefs[$name])) {
2618 if ($name == 'passwd2') return false;
2619 if ($name == 'passwd') return false;
2620 trigger_error("$name: unknown preference", E_USER_NOTICE);
2623 return $this->_prefs[$name];
2626 // get the value or default_value of the subobject
2627 function get($name) {
2628 if ($_pref = $this->_getPref($name))
2629 if ($name == 'emailVerified')
2630 return $_pref->getraw($name);
2632 return $_pref->get($name);
2637 // check and set the new value in the subobject
2638 function set($name, $value) {
2639 $pref = $this->_getPref($name);
2640 if ($pref === false)
2643 /* do it here or outside? */
2644 if ($name == 'passwd' and
2645 defined('PASSWORD_LENGTH_MINIMUM') and
2646 strlen($value) <= PASSWORD_LENGTH_MINIMUM ) {
2647 //TODO: How to notify the user?
2651 if ($name == 'theme' and $value == '')
2654 if (!isset($pref->{$value}) or $pref->{$value} != $pref->default_value) {
2655 if ($name == 'emailVerified') $newvalue = $value;
2656 else $newvalue = $pref->sanify($value);
2657 $pref->set($name,$newvalue);
2659 $this->_prefs[$name] =& $pref;
2663 * use init to avoid update on set
2665 function updatePrefs($prefs, $init = false) {
2667 if ($init) $this->_init = $init;
2668 if (is_object($prefs)) {
2669 $type = 'emailVerified'; $obj =& $this->_prefs['email'];
2670 $obj->_init = $init;
2671 if ($obj->get($type) !== $prefs->get($type)) {
2672 if ($obj->set($type,$prefs->get($type)))
2675 foreach (array_keys($this->_prefs) as $type) {
2676 $obj =& $this->_prefs[$type];
2677 $obj->_init = $init;
2678 if ($prefs->get($type) !== $obj->get($type)) {
2679 // special systemdefault prefs: (probably not needed)
2680 if ($type == 'theme' and $prefs->get($type) == '' and $obj->get($type) == THEME) continue;
2681 if ($type == 'lang' and $prefs->get($type) == '' and $obj->get($type) == DEFAULT_LANGUAGE) continue;
2682 if ($this->_prefs[$type]->set($type,$prefs->get($type)))
2686 } elseif (is_array($prefs)) {
2687 //unset($this->_prefs['userid']);
2688 if (isset($this->_method) and
2689 ($this->_method == 'SQL' or $this->_method == 'ADODB')) {
2690 unset($this->_prefs['passwd']);
2692 // emailVerified at first, the rest later
2693 $type = 'emailVerified'; $obj =& $this->_prefs['email'];
2694 $obj->_init = $init;
2695 if (isset($prefs[$type]) and $obj->get($type) !== $prefs[$type]) {
2696 if ($obj->set($type,$prefs[$type]))
2699 foreach (array_keys($this->_prefs) as $type) {
2700 $obj =& $this->_prefs[$type];
2701 $obj->_init = $init;
2702 if (!isset($prefs[$type]) and isa($obj,"_UserPreference_bool"))
2703 $prefs[$type] = false;
2704 if (isset($prefs[$type]) and isa($obj,"_UserPreference_int"))
2705 $prefs[$type] = (int) $prefs[$type];
2706 if (isset($prefs[$type]) and $obj->get($type) != $prefs[$type]) {
2707 // special systemdefault prefs:
2708 if ($type == 'theme' and $prefs[$type] == '' and $obj->get($type) == THEME) continue;
2709 if ($type == 'lang' and $prefs[$type] == '' and $obj->get($type) == DEFAULT_LANGUAGE) continue;
2710 if ($obj->set($type,$prefs[$type]))
2718 // for now convert just array of objects => array of values
2719 // Todo: the specialized subobjects must override this.
2722 foreach ($this->_prefs as $name => $object) {
2723 if ($value = $object->getraw($name))
2724 $prefs[$name] = $value;
2725 if ($name == 'email' and ($value = $object->getraw('emailVerified')))
2726 $prefs['emailVerified'] = $value;
2728 return $this->pack($prefs);
2731 // packed string or array of values => array of values
2732 // Todo: the specialized subobjects must override this.
2733 function retrieve($packed) {
2734 if (is_string($packed) and (substr($packed, 0, 2) == "a:"))
2735 $packed = unserialize($packed);
2736 if (!is_array($packed)) return false;
2738 foreach ($packed as $name => $packed_pref) {
2739 if (is_string($packed_pref) and substr($packed_pref, 0, 2) == "O:") {
2740 //legacy: check if it's an old array of objects
2741 // Looks like a serialized object.
2742 // This might fail if the object definition does not exist anymore.
2743 // object with ->$name and ->default_value vars.
2744 $pref = @unserialize($packed_pref);
2746 $pref = @unserialize(base64_decode($packed_pref));
2747 $prefs[$name] = $pref->get($name);
2748 // fix old-style prefs
2749 } elseif (is_numeric($name) and is_array($packed_pref)) {
2750 if (count($packed_pref) == 1) {
2751 list($name,$value) = each($packed_pref);
2752 $prefs[$name] = $value;
2755 $prefs[$name] = @unserialize($packed_pref);
2756 if (empty($prefs[$name]))
2757 $prefs[$name] = @unserialize(base64_decode($packed_pref));
2758 // patched by frederik@pandora.be
2759 if (empty($prefs[$name]))
2760 $prefs[$name] = $packed_pref;
2767 * Check if the given prefs object is different from the current prefs object
2769 function isChanged($other) {
2770 foreach ($this->_prefs as $type => $obj) {
2771 if ($obj->get($type) !== $other->get($type))
2777 function defaultPreferences() {
2779 foreach ($this->_prefs as $key => $obj) {
2780 $prefs[$key] = $obj->default_value;
2787 return $this->_prefs;
2790 function pack($nonpacked) {
2791 return serialize($nonpacked);
2794 function unpack($packed) {
2797 //$packed = base64_decode($packed);
2798 if (substr($packed, 0, 2) == "O:") {
2799 // Looks like a serialized object
2800 return unserialize($packed);
2802 if (substr($packed, 0, 2) == "a:") {
2803 return unserialize($packed);
2805 //trigger_error("DEBUG: Can't unpack bad UserPreferences",
2811 return hash($this->_prefs);
2815 /** TODO: new pref storage classes
2816 * These are currently user specific and should be rewritten to be pref specific.
2817 * i.e. $this == $user->_prefs
2819 class CookieUserPreferences
2820 extends UserPreferences
2822 function CookieUserPreferences ($saved_prefs = false) {
2823 //_AnonUser::_AnonUser('',$saved_prefs);
2824 UserPreferences::UserPreferences($saved_prefs);
2828 class PageUserPreferences
2829 extends UserPreferences
2831 function PageUserPreferences ($saved_prefs = false) {
2832 UserPreferences::UserPreferences($saved_prefs);
2836 class PearDbUserPreferences
2837 extends UserPreferences
2839 function PearDbUserPreferences ($saved_prefs = false) {
2840 UserPreferences::UserPreferences($saved_prefs);
2844 class AdoDbUserPreferences
2845 extends UserPreferences
2847 function AdoDbUserPreferences ($saved_prefs = false) {
2848 UserPreferences::UserPreferences($saved_prefs);
2850 function getPreferences() {
2851 // override the generic slow method here for efficiency
2852 _AnonUser::getPreferences();
2853 $this->getAuthDbh();
2854 if (isset($this->_select)) {
2855 $dbh = & $this->_auth_dbi;
2856 $rs = $dbh->Execute(sprintf($this->_select,$dbh->qstr($this->_userid)));
2860 $prefs_blob = $rs->fields['pref_blob'];
2862 if ($restored_from_db = $this->_prefs->retrieve($prefs_blob)) {
2863 $updated = $this->_prefs->updatePrefs($restored_from_db);
2864 //$this->_prefs = new UserPreferences($restored_from_db);
2865 return $this->_prefs;
2869 if (empty($this->_prefs->_prefs) and $this->_HomePagehandle) {
2870 if ($restored_from_page = $this->_prefs->retrieve($this->_HomePagehandle->get('pref'))) {
2871 $updated = $this->_prefs->updatePrefs($restored_from_page);
2872 //$this->_prefs = new UserPreferences($restored_from_page);
2873 return $this->_prefs;
2876 return $this->_prefs;
2881 // $Log: not supported by cvs2svn $
2882 // Revision 1.77 2004/05/18 14:49:51 rurban
2883 // Simplified strings for easier translation
2885 // Revision 1.76 2004/05/18 13:30:04 rurban
2886 // prevent from endless loop with oldstyle warnings
2888 // Revision 1.75 2004/05/16 22:07:35 rurban
2889 // check more config-default and predefined constants
2890 // various PagePerm fixes:
2891 // fix default PagePerms, esp. edit and view for Bogo and Password users
2892 // implemented Creator and Owner
2893 // BOGOUSERS renamed to BOGOUSER
2894 // fixed syntax errors in signin.tmpl
2896 // Revision 1.74 2004/05/15 19:48:33 rurban
2897 // fix some too loose PagePerms for signed, but not authenticated users
2898 // (admin, owner, creator)
2899 // no double login page header, better login msg.
2900 // moved action_pdf to lib/pdf.php
2902 // Revision 1.73 2004/05/15 18:31:01 rurban
2903 // some action=pdf Request fixes: With MSIE it works now. Now the work with the page formatting begins.
2905 // Revision 1.72 2004/05/12 10:49:55 rurban
2906 // require_once fix for those libs which are loaded before FileFinder and
2907 // its automatic include_path fix, and where require_once doesn't grok
2908 // dirname(__FILE__) != './lib'
2909 // upgrade fix with PearDB
2910 // navbar.tmpl: remove spaces for IE button alignment
2912 // Revision 1.71 2004/05/10 12:34:47 rurban
2913 // stabilize DbAuthParam statement pre-prozessor:
2914 // try old-style and new-style (double-)quoting
2915 // reject unknown $variables
2916 // use ->prepare() for all calls (again)
2918 // Revision 1.70 2004/05/06 19:26:16 rurban
2919 // improve stability, trying to find the InlineParser endless loop on sf.net
2921 // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
2923 // Revision 1.69 2004/05/06 13:56:40 rurban
2924 // Enable the Administrators group, and add the WIKIPAGE group default root page.
2926 // Revision 1.68 2004/05/05 13:37:54 rurban
2927 // Support to remove all UserPreferences
2929 // Revision 1.66 2004/05/03 21:44:24 rurban
2930 // fixed sf,net bug #947264: LDAP options are constants, not strings!
2932 // Revision 1.65 2004/05/03 13:16:47 rurban
2933 // fixed UserPreferences update, esp for boolean and int
2935 // Revision 1.64 2004/05/02 15:10:06 rurban
2936 // new finally reliable way to detect if /index.php is called directly
2937 // and if to include lib/main.php
2938 // new global AllActionPages
2939 // SetupWiki now loads all mandatory pages: HOME_PAGE, action pages, and warns if not.
2940 // WikiTranslation what=buttons for Carsten to create the missing MacOSX buttons
2941 // PageGroupTestOne => subpages
2942 // renamed PhpWikiRss to PhpWikiRecentChanges
2943 // more docs, default configs, ...
2945 // Revision 1.63 2004/05/01 15:59:29 rurban
2946 // more php-4.0.6 compatibility: superglobals
2948 // Revision 1.62 2004/04/29 18:31:24 rurban
2949 // Prevent from warning where no db pref was previously stored.
2951 // Revision 1.61 2004/04/29 17:18:19 zorloc
2952 // Fixes permission failure issues. With PagePermissions and Disabled Actions when user did not have permission WIKIAUTH_FORBIDDEN was returned. In WikiUser this was ok because WIKIAUTH_FORBIDDEN had a value of 11 -- thus no user could perform that action. But WikiUserNew has a WIKIAUTH_FORBIDDEN value of -1 -- thus a user without sufficent permission to do anything. The solution is a new high value permission level (WIKIAUTH_UNOBTAINABLE) to be the default level for access failure.
2954 // Revision 1.60 2004/04/27 18:20:54 rurban
2955 // sf.net patch #940359 by rassie
2957 // Revision 1.59 2004/04/26 12:35:21 rurban
2958 // POP3_AUTH_PORT deprecated, use "host:port" similar to IMAP
2959 // File_Passwd is already loaded
2961 // Revision 1.58 2004/04/20 17:08:28 rurban
2962 // Some IniConfig fixes: prepend our private lib/pear dir
2963 // switch from " to ' in the auth statements
2964 // use error handling.
2965 // WikiUserNew changes for the new "'$variable'" syntax
2966 // in the statements
2967 // TODO: optimization to put config vars into the session.
2969 // Revision 1.57 2004/04/19 18:27:45 rurban
2970 // Prevent from some PHP5 warnings (ref args, no :: object init)
2971 // php5 runs now through, just one wrong XmlElement object init missing
2972 // Removed unneccesary UpgradeUser lines
2973 // Changed WikiLink to omit version if current (RecentChanges)
2975 // Revision 1.56 2004/04/19 09:13:24 rurban
2976 // new pref: googleLink
2978 // Revision 1.54 2004/04/18 00:24:45 rurban
2979 // re-use our simple prepare: just for table prefix warnings
2981 // Revision 1.53 2004/04/12 18:29:15 rurban
2982 // exp. Session auth for already authenticated users from another app
2984 // Revision 1.52 2004/04/12 13:04:50 rurban
2985 // added auth_create: self-registering Db users
2987 // removed rating recommendations
2988 // ziplib reformatting
2990 // Revision 1.51 2004/04/11 10:42:02 rurban
2991 // pgsrc/CreatePagePlugin
2993 // Revision 1.50 2004/04/10 05:34:35 rurban
2996 // Revision 1.49 2004/04/07 23:13:18 rurban
2997 // fixed pear/File_Passwd for Windows
2998 // fixed FilePassUser sessions (filehandle revive) and password update
3000 // Revision 1.48 2004/04/06 20:00:10 rurban
3001 // Cleanup of special PageList column types
3002 // Added support of plugin and theme specific Pagelist Types
3003 // Added support for theme specific UserPreferences
3004 // Added session support for ip-based throttling
3005 // sql table schema change: ALTER TABLE session ADD sess_ip CHAR(15);
3006 // Enhanced postgres schema
3007 // Added DB_Session_dba support
3009 // Revision 1.47 2004/04/02 15:06:55 rurban
3010 // fixed a nasty ADODB_mysql session update bug
3011 // improved UserPreferences layout (tabled hints)
3012 // fixed UserPreferences auth handling
3013 // improved auth stability
3014 // improved old cookie handling: fixed deletion of old cookies with paths
3016 // Revision 1.46 2004/04/01 06:29:51 rurban
3018 // RateIt also for ADODB
3020 // Revision 1.45 2004/03/30 02:14:03 rurban
3021 // fixed yet another Prefs bug
3022 // added generic PearDb_iter
3023 // $request->appendValidators no so strict as before
3024 // added some box plugin methods
3025 // PageList commalist for condensed output
3027 // Revision 1.44 2004/03/27 22:01:03 rurban
3028 // two catches by Konstantin Zadorozhny
3030 // Revision 1.43 2004/03/27 19:40:09 rurban
3031 // init fix and validator reset
3033 // Revision 1.40 2004/03/25 22:54:31 rurban
3036 // Revision 1.38 2004/03/25 17:37:36 rurban
3037 // helper to patch to and from php5 (workaround for stricter parser, no macros in php)
3039 // Revision 1.37 2004/03/25 17:00:31 rurban
3040 // more code to convert old-style pref array to new hash
3042 // Revision 1.36 2004/03/24 19:39:02 rurban
3043 // php5 workaround code (plus some interim debugging code in XmlElement)
3044 // php5 doesn't work yet with the current XmlElement class constructors,
3045 // WikiUserNew does work better than php4.
3046 // rewrote WikiUserNew user upgrading to ease php5 update
3047 // fixed pref handling in WikiUserNew
3048 // added Email Notification
3049 // added simple Email verification
3050 // removed emailVerify userpref subclass: just a email property
3051 // changed pref binary storage layout: numarray => hash of non default values
3052 // print optimize message only if really done.
3053 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
3054 // prefs should be stored in db or homepage, besides the current session.
3056 // Revision 1.35 2004/03/18 22:18:31 rurban
3057 // workaround for php5 object upgrading problem
3059 // Revision 1.34 2004/03/18 21:41:09 rurban
3060 // fixed sqlite support
3061 // WikiUserNew: PHP5 fixes: don't assign $this (untested)
3063 // Revision 1.33 2004/03/16 15:42:04 rurban
3064 // more fixes for undefined property warnings
3066 // Revision 1.32 2004/03/14 16:30:52 rurban
3067 // db-handle session revivification, dba fixes
3069 // Revision 1.31 2004/03/12 23:20:58 rurban
3070 // pref fixes (base64)
3072 // Revision 1.30 2004/03/12 20:59:17 rurban
3073 // important cookie fix by Konstantin Zadorozhny
3074 // new editpage feature: JS_SEARCHREPLACE
3076 // Revision 1.29 2004/03/11 13:30:47 rurban
3077 // fixed File Auth for user and group
3078 // missing only getMembersOf(Authenticated Users),getMembersOf(Every),getMembersOf(Signed Users)
3080 // Revision 1.28 2004/03/08 18:17:09 rurban
3081 // added more WikiGroup::getMembersOf methods, esp. for special groups
3082 // fixed $LDAP_SET_OPTIONS
3083 // fixed _AuthInfo group methods
3085 // Revision 1.27 2004/03/01 09:35:13 rurban
3086 // fixed DbPassuser pref init; lost userid
3088 // Revision 1.26 2004/02/29 04:10:56 rurban
3089 // new POP3 auth (thanks to BiloBilo: pentothal at despammed dot com)
3090 // fixed syntax error in index.php
3092 // Revision 1.25 2004/02/28 22:25:07 rurban
3093 // First PagePerm implementation:
3095 // $Theme->setAnonEditUnknownLinks(false);
3097 // Layout improvement with dangling links for mostly closed wiki's:
3098 // If false, only users with edit permissions will be presented the
3099 // special wikiunknown class with "?" and Tooltip.
3100 // If true (default), any user will see the ?, but will be presented
3101 // the PrintLoginForm on a click.
3103 // Revision 1.24 2004/02/28 21:14:08 rurban
3104 // generally more PHPDOC docs
3105 // see http://xarch.tu-graz.ac.at/home/rurban/phpwiki/xref/
3106 // fxied WikiUserNew pref handling: empty theme not stored, save only
3107 // changed prefs, sql prefs improved, fixed password update,
3108 // removed REPLACE sql (dangerous)
3109 // moved gettext init after the locale was guessed
3110 // + some minor changes
3112 // Revision 1.23 2004/02/27 13:21:17 rurban
3113 // several performance improvements, esp. with peardb
3115 // storepass seperated from prefs if defined so
3116 // stacked and strict still not working
3118 // Revision 1.22 2004/02/27 05:15:40 rurban
3119 // more stability. detected by Micki
3121 // Revision 1.21 2004/02/26 20:43:49 rurban
3122 // new HttpAuthPassUser class (forces http auth if in the auth loop)
3123 // fixed user upgrade: don't return _PassUser in the first hand.
3125 // Revision 1.20 2004/02/26 01:29:11 rurban
3126 // important fixes: endless loops in certain cases. minor rewrite
3128 // Revision 1.19 2004/02/25 17:15:17 rurban
3129 // improve stability
3131 // Revision 1.18 2004/02/24 15:20:05 rurban
3132 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
3134 // Revision 1.17 2004/02/17 12:16:42 rurban
3135 // started with changePass support. not yet used.
3137 // Revision 1.16 2004/02/15 22:23:45 rurban
3138 // oops, fixed showstopper (endless recursion)
3140 // Revision 1.15 2004/02/15 21:34:37 rurban
3141 // PageList enhanced and improved.
3142 // fixed new WikiAdmin... plugins
3143 // editpage, Theme with exp. htmlarea framework
3144 // (htmlarea yet committed, this is really questionable)
3145 // WikiUser... code with better session handling for prefs
3146 // enhanced UserPreferences (again)
3147 // RecentChanges for show_deleted: how should pages be deleted then?
3149 // Revision 1.14 2004/02/15 17:30:13 rurban
3150 // workaround for lost db connnection handle on session restauration (->_auth_dbi)
3151 // fixed getPreferences() (esp. from sessions)
3152 // fixed setPreferences() (update and set),
3153 // fixed AdoDb DB statements,
3154 // update prefs only at UserPreferences POST (for testing)
3155 // unified db prefs methods (but in external pref classes yet)
3157 // Revision 1.13 2004/02/09 03:58:12 rurban
3158 // for now default DB_SESSION to false
3160 // * not existing perms will now query the parent, and not
3161 // return the default perm
3162 // * added pagePermissions func which returns the object per page
3163 // * added getAccessDescription
3165 // * added global ->prepare (not yet used) with smart user/pref/member table prefixing.
3166 // * force init of authdbh in the 2 db classes
3168 // * fixed session handling (not triple auth request anymore)
3169 // * don't store cookie prefs with sessions
3170 // stdlib: global obj2hash helper from _AuthInfo, also needed for PagePerm
3172 // Revision 1.12 2004/02/07 10:41:25 rurban
3173 // fixed auth from session (still double code but works)
3175 // fixed DbPassUser upgrade and policy=old
3178 // Revision 1.11 2004/02/03 09:45:39 rurban
3179 // LDAP cleanup, start of new Pref classes
3181 // Revision 1.10 2004/02/01 09:14:11 rurban
3182 // Started with Group_Ldap (not yet ready)
3183 // added new _AuthInfo plugin to help in auth problems (warning: may display passwords)
3184 // fixed some configurator vars
3185 // renamed LDAP_AUTH_SEARCH to LDAP_BASE_DN
3186 // changed PHPWIKI_VERSION from 1.3.8a to 1.3.8pre
3187 // USE_DB_SESSION defaults to true on SQL
3188 // changed GROUP_METHOD definition to string, not constants
3189 // changed sample user DBAuthParams from UPDATE to REPLACE to be able to
3190 // create users. (Not to be used with external databases generally, but
3191 // with the default internal user table)
3193 // fixed the IndexAsConfigProblem logic. this was flawed:
3194 // scripts which are the same virtual path defined their own lib/main call
3195 // (hmm, have to test this better, phpwiki.sf.net/demo works again)
3197 // Revision 1.9 2004/01/30 19:57:58 rurban
3198 // fixed DBAuthParams['pref_select']: wrong _auth_dbi object used.
3200 // Revision 1.8 2004/01/30 18:46:15 rurban
3201 // fix "lib/WikiUserNew.php:572: Notice[8]: Undefined variable: DBParams"
3203 // Revision 1.7 2004/01/27 23:23:39 rurban
3204 // renamed ->Username => _userid for consistency
3205 // renamed mayCheckPassword => mayCheckPass
3206 // fixed recursion problem in WikiUserNew
3207 // fixed bogo login (but not quite 100% ready yet, password storage)
3209 // Revision 1.6 2004/01/26 09:17:49 rurban
3210 // * changed stored pref representation as before.
3211 // the array of objects is 1) bigger and 2)
3212 // less portable. If we would import packed pref
3213 // objects and the object definition was changed, PHP would fail.
3214 // This doesn't happen with an simple array of non-default values.
3215 // * use $prefs->retrieve and $prefs->store methods, where retrieve
3216 // understands the interim format of array of objects also.
3217 // * simplified $prefs->get() and fixed $prefs->set()
3218 // * added $user->_userid and class '_WikiUser' portability functions
3219 // * fixed $user object ->_level upgrading, mostly using sessions.
3220 // this fixes yesterdays problems with loosing authorization level.
3221 // * fixed WikiUserNew::checkPass to return the _level
3222 // * fixed WikiUserNew::isSignedIn
3223 // * added explodePageList to class PageList, support sortby arg
3224 // * fixed UserPreferences for WikiUserNew
3225 // * fixed WikiPlugin for empty defaults array
3226 // * UnfoldSubpages: added pagename arg, renamed pages arg,
3227 // removed sort arg, support sortby arg
3229 // Revision 1.5 2004/01/25 03:05:00 rurban
3230 // First working version, but has some problems with the current main loop.
3231 // Implemented new auth method dispatcher and policies, all the external
3232 // _PassUser classes (also for ADODB and Pear DB).
3233 // The two global funcs UserExists() and CheckPass() are probably not needed,
3234 // since the auth loop is done recursively inside the class code, upgrading
3235 // the user class within itself.
3236 // Note: When a higher user class is returned, this doesn't mean that the user
3237 // is authorized, $user->_level is still low, and only upgraded on successful
3240 // Revision 1.4 2003/12/07 19:29:48 carstenklapp
3241 // Code Housecleaning: fixed syntax errors. (php -l *.php)
3243 // Revision 1.3 2003/12/06 19:10:46 carstenklapp
3244 // Finished off logic for determining user class, including
3245 // PassUser. Removed ability of BogoUser to save prefs into a page.
3247 // Revision 1.2 2003/12/03 21:45:48 carstenklapp
3248 // Added admin user, password user, and preference classes. Added
3249 // password checking functions for users and the admin. (Now the easy
3250 // parts are nearly done).
3252 // Revision 1.1 2003/12/02 05:46:36 carstenklapp
3253 // Complete rewrite of WikiUser.php.
3255 // This should make it easier to hook in user permission groups etc. some
3256 // time in the future. Most importantly, to finally get UserPreferences
3257 // fully working properly for all classes of users: AnonUser, BogoUser,
3258 // AdminUser; whether they have a NamesakePage (PersonalHomePage) or not,
3259 // want a cookie or not, and to bring back optional AutoLogin with the
3260 // UserName stored in a cookie--something that was lost after PhpWiki had
3261 // dropped the default http auth login method.
3263 // Added WikiUser classes which will (almost) work together with existing
3264 // UserPreferences class. Other parts of PhpWiki need to be updated yet
3265 // before this code can be hooked up.
3271 // c-basic-offset: 4
3272 // c-hanging-comment-ender-p: nil
3273 // indent-tabs-mode: nil