PageRenderTime 346ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 1ms

/gforge/plugins/wiki/www/lib/WikiUserNew.php

https://github.com/neymanna/fusionforge
PHP | 2503 lines | 1919 code | 124 blank | 460 comment | 273 complexity | ce8ba0cf0b7f829ab12654b30abbb61a MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception
  1. <?php //-*-php-*-
  2. rcs_id('$Id: WikiUserNew.php,v 1.137 2006/05/03 06:05:37 rurban Exp $');
  3. /* Copyright (C) 2004,2005 $ThePhpWikiProgrammingTeam
  4. *
  5. * This file is part of PhpWiki.
  6. *
  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.
  11. *
  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.
  16. *
  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
  20. */
  21. /**
  22. * This is a complete OOP rewrite of the old WikiUser code with various
  23. * configurable external authentication methods.
  24. *
  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.
  32. *
  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.
  40. *
  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.
  51. *
  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.
  55. *
  56. * @author: Reini Urban (the tricky parts),
  57. * Carsten Klapp (started rolling the ball)
  58. *
  59. * Random architectural notes, sorted by date:
  60. * 2004-01-25 rurban
  61. * Test it by defining ENABLE_USER_NEW in config/config.ini
  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)
  68. * 2004-02-27 rurban:
  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.
  75. * 2004-03-18 rurban
  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))
  79. * $this = $user;
  80. * A /php5-patch.php is provided, which patches the src automatically
  81. * for php4 and php5. Default is php4.
  82. * Update: not needed anymore. we use eval to fool the load-time syntax checker.
  83. * 2004-03-24 rurban
  84. * 6) enforced new cookie policy: prefs don't get stored in cookies
  85. * anymore, only in homepage and/or database, but always in the
  86. * current session. old pref cookies will get deleted.
  87. * 2004-04-04 rurban
  88. * 7) Certain themes should be able to extend the predefined list
  89. * of preferences. Display/editing is done in the theme specific userprefs.tmpl,
  90. * but storage must be extended to the Get/SetPreferences methods.
  91. * <theme>/themeinfo.php must provide CustomUserPreferences:
  92. * A list of name => _UserPreference class pairs.
  93. */
  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
  100. //if (!defined('COOKIE_EXPIRATION_DAYS')) define('COOKIE_EXPIRATION_DAYS', 365);
  101. //if (!defined('COOKIE_DOMAIN')) define('COOKIE_DOMAIN', '/');
  102. if (!defined('EDITWIDTH_MIN_COLS')) define('EDITWIDTH_MIN_COLS', 30);
  103. if (!defined('EDITWIDTH_MAX_COLS')) define('EDITWIDTH_MAX_COLS', 150);
  104. if (!defined('EDITWIDTH_DEFAULT_COLS')) define('EDITWIDTH_DEFAULT_COLS', 80);
  105. if (!defined('EDITHEIGHT_MIN_ROWS')) define('EDITHEIGHT_MIN_ROWS', 5);
  106. if (!defined('EDITHEIGHT_MAX_ROWS')) define('EDITHEIGHT_MAX_ROWS', 80);
  107. if (!defined('EDITHEIGHT_DEFAULT_ROWS')) define('EDITHEIGHT_DEFAULT_ROWS', 22);
  108. define('TIMEOFFSET_MIN_HOURS', -26);
  109. define('TIMEOFFSET_MAX_HOURS', 26);
  110. if (!defined('TIMEOFFSET_DEFAULT_HOURS')) define('TIMEOFFSET_DEFAULT_HOURS', 0);
  111. /**
  112. * There are be the following constants in config/config.ini to
  113. * establish login parameters:
  114. *
  115. * ALLOW_ANON_USER default true
  116. * ALLOW_ANON_EDIT default true
  117. * ALLOW_BOGO_LOGIN default true
  118. * ALLOW_USER_PASSWORDS default true
  119. * PASSWORD_LENGTH_MINIMUM default 0
  120. *
  121. * To require user passwords for editing:
  122. * ALLOW_ANON_USER = true
  123. * ALLOW_ANON_EDIT = false (before named REQUIRE_SIGNIN_BEFORE_EDIT)
  124. * ALLOW_BOGO_LOGIN = false
  125. * ALLOW_USER_PASSWORDS = true
  126. *
  127. * To establish a COMPLETELY private wiki, such as an internal
  128. * corporate one:
  129. * ALLOW_ANON_USER = false
  130. * (and probably require user passwords as described above). In this
  131. * case the user will be prompted to login immediately upon accessing
  132. * any page.
  133. *
  134. * There are other possible combinations, but the typical wiki (such
  135. * as http://PhpWiki.sf.net/phpwiki) would usually just leave all four
  136. * enabled.
  137. *
  138. */
  139. // The last object in the row is the bad guy...
  140. if (!is_array($USER_AUTH_ORDER))
  141. $USER_AUTH_ORDER = array("Forbidden");
  142. else
  143. $USER_AUTH_ORDER[] = "Forbidden";
  144. // Local convenience functions.
  145. function _isAnonUserAllowed() {
  146. return (defined('ALLOW_ANON_USER') && ALLOW_ANON_USER);
  147. }
  148. function _isBogoUserAllowed() {
  149. return (defined('ALLOW_BOGO_LOGIN') && ALLOW_BOGO_LOGIN);
  150. }
  151. function _isUserPasswordsAllowed() {
  152. return (defined('ALLOW_USER_PASSWORDS') && ALLOW_USER_PASSWORDS);
  153. }
  154. // Possibly upgrade userobject functions.
  155. function _determineAdminUserOrOtherUser($UserName) {
  156. // Sanity check. User name is a condition of the definition of the
  157. // _AdminUser, _BogoUser and _passuser.
  158. if (!$UserName)
  159. return $GLOBALS['ForbiddenUser'];
  160. //FIXME: check admin membership later at checkPass. Now we cannot raise the level.
  161. //$group = &WikiGroup::getGroup($GLOBALS['request']);
  162. if ($UserName == ADMIN_USER)
  163. return new _AdminUser($UserName);
  164. /* elseif ($group->isMember(GROUP_ADMIN)) { // unneeded code
  165. return _determineBogoUserOrPassUser($UserName);
  166. }
  167. */
  168. else
  169. return _determineBogoUserOrPassUser($UserName);
  170. }
  171. function _determineBogoUserOrPassUser($UserName) {
  172. global $ForbiddenUser;
  173. // Sanity check. User name is a condition of the definition of
  174. // _BogoUser and _PassUser.
  175. if (!$UserName)
  176. return $ForbiddenUser;
  177. // Check for password and possibly upgrade user object.
  178. // $_BogoUser = new _BogoUser($UserName);
  179. if (_isBogoUserAllowed() and isWikiWord($UserName)) {
  180. include_once("lib/WikiUser/BogoLogin.php");
  181. $_BogoUser = new _BogoLoginPassUser($UserName);
  182. if ($_BogoUser->userExists() or $GLOBALS['request']->getArg('auth'))
  183. return $_BogoUser;
  184. }
  185. if (_isUserPasswordsAllowed()) {
  186. // PassUsers override BogoUsers if a password is stored
  187. if (isset($_BogoUser) and isset($_BogoUser->_prefs)
  188. and $_BogoUser->_prefs->get('passwd'))
  189. return new _PassUser($UserName, $_BogoUser->_prefs);
  190. else {
  191. $_PassUser = new _PassUser($UserName,
  192. isset($_BogoUser) ? $_BogoUser->_prefs : false);
  193. if ($_PassUser->userExists() or $GLOBALS['request']->getArg('auth'))
  194. return $_PassUser;
  195. }
  196. }
  197. // No Bogo- or PassUser exists, or
  198. // passwords are not allowed, and bogo is disallowed too.
  199. // (Only the admin can sign in).
  200. return $ForbiddenUser;
  201. }
  202. /**
  203. * Primary WikiUser function, called by lib/main.php.
  204. *
  205. * This determines the user's type and returns an appropriate user
  206. * object. lib/main.php then querys the resultant object for password
  207. * validity as necessary.
  208. *
  209. * If an _AnonUser object is returned, the user may only browse pages
  210. * (and save prefs in a cookie).
  211. *
  212. * To disable access but provide prefs the global $ForbiddenUser class
  213. * is returned. (was previously false)
  214. *
  215. */
  216. function WikiUser ($UserName = '') {
  217. global $ForbiddenUser;
  218. //Maybe: Check sessionvar for username & save username into
  219. //sessionvar (may be more appropriate to do this in lib/main.php).
  220. if ($UserName) {
  221. $ForbiddenUser = new _ForbiddenUser($UserName);
  222. // Found a user name.
  223. return _determineAdminUserOrOtherUser($UserName);
  224. }
  225. elseif (!empty($_SESSION['userid'])) {
  226. // Found a user name.
  227. $ForbiddenUser = new _ForbiddenUser($_SESSION['userid']);
  228. return _determineAdminUserOrOtherUser($_SESSION['userid']);
  229. }
  230. else {
  231. // Check for autologin pref in cookie and possibly upgrade
  232. // user object to another type.
  233. $_AnonUser = new _AnonUser();
  234. if ($UserName = $_AnonUser->_userid && $_AnonUser->_prefs->get('autologin')) {
  235. // Found a user name.
  236. $ForbiddenUser = new _ForbiddenUser($UserName);
  237. return _determineAdminUserOrOtherUser($UserName);
  238. }
  239. else {
  240. $ForbiddenUser = new _ForbiddenUser();
  241. if (_isAnonUserAllowed())
  242. return $_AnonUser;
  243. return $ForbiddenUser; // User must sign in to browse pages.
  244. }
  245. return $ForbiddenUser; // User must sign in with a password.
  246. }
  247. /*
  248. trigger_error("DEBUG: Note: End of function reached in WikiUser." . " "
  249. . "Unexpectedly, an appropriate user class could not be determined.");
  250. return $ForbiddenUser; // Failsafe.
  251. */
  252. }
  253. /**
  254. * WikiUser.php use the name 'WikiUser'
  255. */
  256. function WikiUserClassname() {
  257. return '_WikiUser';
  258. }
  259. /**
  260. * Upgrade olduser by copying properties from user to olduser.
  261. * We are not sure yet, for which php's a simple $this = $user works reliably,
  262. * (on php4 it works ok, on php5 it's currently disallowed on the parser level)
  263. * that's why try it the hard way.
  264. */
  265. function UpgradeUser ($olduser, $user) {
  266. if (isa($user,'_WikiUser') and isa($olduser,'_WikiUser')) {
  267. // populate the upgraded class $olduser with the values from the new user object
  268. //only _auth_level, _current_method, _current_index,
  269. if (!empty($user->_level) and
  270. $user->_level > $olduser->_level)
  271. $olduser->_level = $user->_level;
  272. if (!empty($user->_current_index) and
  273. $user->_current_index > $olduser->_current_index) {
  274. $olduser->_current_index = $user->_current_index;
  275. $olduser->_current_method = $user->_current_method;
  276. }
  277. if (!empty($user->_authmethod))
  278. $olduser->_authmethod = $user->_authmethod;
  279. /*
  280. foreach (get_object_vars($user) as $k => $v) {
  281. if (!empty($v)) $olduser->$k = $v;
  282. }
  283. */
  284. $olduser->hasHomePage(); // revive db handle, because these don't survive sessions
  285. //$GLOBALS['request']->_user = $olduser;
  286. return $olduser;
  287. } else {
  288. return false;
  289. }
  290. }
  291. /**
  292. * Probably not needed, since we use the various user objects methods so far.
  293. * Anyway, here it is, looping through all available objects.
  294. */
  295. function UserExists ($UserName) {
  296. global $request;
  297. if (!($user = $request->getUser()))
  298. $user = WikiUser($UserName);
  299. if (!$user)
  300. return false;
  301. if ($user->userExists($UserName)) {
  302. $request->_user = $user;
  303. return true;
  304. }
  305. if (isa($user,'_BogoUser'))
  306. $user = new _PassUser($UserName,$user->_prefs);
  307. $class = $user->nextClass();
  308. if ($user = new $class($UserName,$user->_prefs)) {
  309. return $user->userExists($UserName);
  310. }
  311. $request->_user = $GLOBALS['ForbiddenUser'];
  312. return false;
  313. }
  314. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  315. /**
  316. * Base WikiUser class.
  317. */
  318. class _WikiUser
  319. {
  320. var $_userid = '';
  321. var $_level = WIKIAUTH_ANON;
  322. var $_prefs = false;
  323. var $_HomePagehandle = false;
  324. // constructor
  325. function _WikiUser($UserName='', $prefs=false) {
  326. $this->_userid = $UserName;
  327. $this->_HomePagehandle = false;
  328. if ($UserName) {
  329. $this->hasHomePage();
  330. }
  331. if (empty($this->_prefs)) {
  332. if ($prefs) $this->_prefs = $prefs;
  333. else $this->getPreferences();
  334. }
  335. }
  336. function UserName() {
  337. if (!empty($this->_userid))
  338. return $this->_userid;
  339. }
  340. function getPreferences() {
  341. trigger_error("DEBUG: Note: undefined _WikiUser class trying to load prefs." . " "
  342. . "New subclasses of _WikiUser must override this function.");
  343. return false;
  344. }
  345. function setPreferences($prefs, $id_only) {
  346. trigger_error("DEBUG: Note: undefined _WikiUser class trying to save prefs."
  347. . " "
  348. . "New subclasses of _WikiUser must override this function.");
  349. return false;
  350. }
  351. function userExists() {
  352. return $this->hasHomePage();
  353. }
  354. function checkPass($submitted_password) {
  355. // By definition, an undefined user class cannot sign in.
  356. trigger_error("DEBUG: Warning: undefined _WikiUser class trying to sign in."
  357. . " "
  358. . "New subclasses of _WikiUser must override this function.");
  359. return false;
  360. }
  361. // returns page_handle to user's home page or false if none
  362. function hasHomePage() {
  363. if ($this->_userid) {
  364. if (!empty($this->_HomePagehandle) and is_object($this->_HomePagehandle)) {
  365. return $this->_HomePagehandle->exists();
  366. }
  367. else {
  368. // check db again (maybe someone else created it since
  369. // we logged in.)
  370. global $request;
  371. $this->_HomePagehandle = $request->getPage($this->_userid);
  372. return $this->_HomePagehandle->exists();
  373. }
  374. }
  375. // nope
  376. return false;
  377. }
  378. // innocent helper: case-insensitive position in _auth_methods
  379. function array_position ($string, $array) {
  380. $string = strtolower($string);
  381. for ($found = 0; $found < count($array); $found++) {
  382. if (strtolower($array[$found]) == $string)
  383. return $found;
  384. }
  385. return false;
  386. }
  387. function nextAuthMethodIndex() {
  388. if (empty($this->_auth_methods))
  389. $this->_auth_methods = $GLOBALS['USER_AUTH_ORDER'];
  390. if (empty($this->_current_index)) {
  391. if (strtolower(get_class($this)) != '_passuser') {
  392. $this->_current_method = substr(get_class($this),1,-8);
  393. $this->_current_index = $this->array_position($this->_current_method,
  394. $this->_auth_methods);
  395. } else {
  396. $this->_current_index = -1;
  397. }
  398. }
  399. $this->_current_index++;
  400. if ($this->_current_index >= count($this->_auth_methods))
  401. return false;
  402. $this->_current_method = $this->_auth_methods[$this->_current_index];
  403. return $this->_current_index;
  404. }
  405. function AuthMethod($index = false) {
  406. return $this->_auth_methods[ $index === false
  407. ? count($this->_auth_methods)-1
  408. : $index];
  409. }
  410. // upgrade the user object
  411. function nextClass() {
  412. $method = $this->AuthMethod($this->nextAuthMethodIndex());
  413. include_once("lib/WikiUser/$method.php");
  414. return "_".$method."PassUser";
  415. }
  416. //Fixme: for _HttpAuthPassUser
  417. function PrintLoginForm (&$request, $args, $fail_message = false,
  418. $seperate_page = false) {
  419. include_once('lib/Template.php');
  420. // Call update_locale in case the system's default language is not 'en'.
  421. // (We have no user pref for lang at this point yet, no one is logged in.)
  422. if ($GLOBALS['LANG'] != DEFAULT_LANGUAGE)
  423. update_locale(DEFAULT_LANGUAGE);
  424. $userid = $this->_userid;
  425. $require_level = 0;
  426. extract($args); // fixme
  427. $require_level = max(0, min(WIKIAUTH_ADMIN, (int)$require_level));
  428. $pagename = $request->getArg('pagename');
  429. $nocache = 1;
  430. $login = Template('login',
  431. compact('pagename', 'userid', 'require_level',
  432. 'fail_message', 'pass_required', 'nocache'));
  433. // check if the html template was already processed
  434. $seperate_page = $seperate_page ? true : !alreadyTemplateProcessed('html');
  435. if ($seperate_page) {
  436. $page = $request->getPage($pagename);
  437. $revision = $page->getCurrentRevision();
  438. return GeneratePage($login,_("Sign In"),$revision);
  439. } else {
  440. return $login->printExpansion();
  441. }
  442. }
  443. /** Signed in but not password checked or empty password.
  444. */
  445. function isSignedIn() {
  446. return (isa($this,'_BogoUser') or isa($this,'_PassUser'));
  447. }
  448. /** This is password checked for sure.
  449. */
  450. function isAuthenticated() {
  451. //return isa($this,'_PassUser');
  452. //return isa($this,'_BogoUser') || isa($this,'_PassUser');
  453. return $this->_level >= WIKIAUTH_BOGO;
  454. }
  455. function isAdmin () {
  456. static $group;
  457. if ($this->_level == WIKIAUTH_ADMIN) return true;
  458. if (!$this->isSignedIn()) return false;
  459. if (!$this->isAuthenticated()) return false;
  460. if (!$group) $group = &$GLOBALS['request']->getGroup();
  461. return ($this->_level > WIKIAUTH_BOGO and $group->isMember(GROUP_ADMIN));
  462. }
  463. /** Name or IP for a signed user. UserName could come from a cookie e.g.
  464. */
  465. function getId () {
  466. return ( $this->UserName()
  467. ? $this->UserName()
  468. : $GLOBALS['request']->get('REMOTE_ADDR') );
  469. }
  470. /** Name for an authenticated user. No IP here.
  471. */
  472. function getAuthenticatedId() {
  473. return ( $this->isAuthenticated()
  474. ? $this->_userid
  475. : ''); //$GLOBALS['request']->get('REMOTE_ADDR') );
  476. }
  477. function hasAuthority ($require_level) {
  478. return $this->_level >= $require_level;
  479. }
  480. /* This is quite restrictive and not according the login description online.
  481. Any word char (A-Za-z0-9_), ".", "@" and "-"
  482. The backends may loosen this.
  483. */
  484. function isValidName ($userid = false) {
  485. if (!$userid) $userid = $this->_userid;
  486. return true; // XXX TODO Hack for GForge
  487. return preg_match("/^[\w\.@\-]+$/",$userid) and strlen($userid) < 32;
  488. }
  489. /**
  490. * Called on an auth_args POST request, such as login, logout or signin.
  491. * TODO: Check BogoLogin users with empty password. (self-signed users)
  492. */
  493. function AuthCheck ($postargs) {
  494. // Normalize args, and extract.
  495. $keys = array('userid', 'passwd', 'require_level', 'login', 'logout',
  496. 'cancel');
  497. foreach ($keys as $key)
  498. $args[$key] = isset($postargs[$key]) ? $postargs[$key] : false;
  499. extract($args);
  500. $require_level = max(0, min(WIKIAUTH_ADMIN, (int)$require_level));
  501. if ($logout) { // Log out
  502. if (method_exists($GLOBALS['request']->_user, "logout")) { //_HttpAuthPassUser
  503. $GLOBALS['request']->_user->logout();
  504. }
  505. $user = new _AnonUser();
  506. $user->_userid = '';
  507. $user->_level = WIKIAUTH_ANON;
  508. return $user;
  509. } elseif ($cancel)
  510. return false; // User hit cancel button.
  511. elseif (!$login && !$userid)
  512. return false; // Nothing to do?
  513. if (!$this->isValidName($userid))
  514. return _("Invalid username.");;
  515. $authlevel = $this->checkPass($passwd === false ? '' : $passwd);
  516. if ($authlevel <= 0) { // anon or forbidden
  517. if ($passwd)
  518. return _("Invalid password.");
  519. else
  520. return _("Invalid password or userid.");
  521. } elseif ($authlevel < $require_level) { // auth ok, but not enough
  522. if (!empty($this->_current_method) and strtolower(get_class($this)) == '_passuser')
  523. {
  524. // upgrade class
  525. $class = "_" . $this->_current_method . "PassUser";
  526. include_once("lib/WikiUser/".$this->_current_method.".php");
  527. $user = new $class($userid,$this->_prefs);
  528. if (!check_php_version(5))
  529. eval("\$this = \$user;");
  530. // /*PHP5 patch*/$this = $user;
  531. $this->_level = $authlevel;
  532. return $user;
  533. }
  534. $this->_userid = $userid;
  535. $this->_level = $authlevel;
  536. return _("Insufficient permissions.");
  537. }
  538. // Successful login.
  539. //$user = $GLOBALS['request']->_user;
  540. if (!empty($this->_current_method) and
  541. strtolower(get_class($this)) == '_passuser')
  542. {
  543. // upgrade class
  544. $class = "_" . $this->_current_method . "PassUser";
  545. include_once("lib/WikiUser/".$this->_current_method.".php");
  546. $user = new $class($userid, $this->_prefs);
  547. if (!check_php_version(5))
  548. eval("\$this = \$user;");
  549. // /*PHP5 patch*/$this = $user;
  550. $user->_level = $authlevel;
  551. return $user;
  552. }
  553. $this->_userid = $userid;
  554. $this->_level = $authlevel;
  555. return $this;
  556. }
  557. }
  558. /**
  559. * Not authenticated in user, but he may be signed in. Basicly with view access only.
  560. * prefs are stored in cookies, but only the userid.
  561. */
  562. class _AnonUser
  563. extends _WikiUser
  564. {
  565. var $_level = WIKIAUTH_ANON; // var in php-5.0.0RC1 deprecated
  566. /** Anon only gets to load and save prefs in a cookie, that's it.
  567. */
  568. function getPreferences() {
  569. global $request;
  570. if (empty($this->_prefs))
  571. $this->_prefs = new UserPreferences;
  572. $UserName = $this->UserName();
  573. // Try to read deprecated 1.3.x style cookies
  574. if ($cookie = $request->cookies->get_old(WIKI_NAME)) {
  575. if (! $unboxedcookie = $this->_prefs->retrieve($cookie)) {
  576. trigger_error(_("Empty Preferences or format of UserPreferences cookie not recognised.")
  577. . "\n"
  578. . sprintf("%s='%s'", WIKI_NAME, $cookie)
  579. . "\n"
  580. . _("Default preferences will be used."),
  581. E_USER_NOTICE);
  582. }
  583. /**
  584. * Only set if it matches the UserName who is
  585. * signing in or if this really is an Anon login (no
  586. * username). (Remember, _BogoUser and higher inherit this
  587. * function too!).
  588. */
  589. if (! $UserName || $UserName == @$unboxedcookie['userid']) {
  590. $updated = $this->_prefs->updatePrefs($unboxedcookie);
  591. //$this->_prefs = new UserPreferences($unboxedcookie);
  592. $UserName = @$unboxedcookie['userid'];
  593. if (is_string($UserName) and (substr($UserName,0,2) != 's:'))
  594. $this->_userid = $UserName;
  595. else
  596. $UserName = false;
  597. }
  598. // v1.3.8 policy: don't set PhpWiki cookies, only plaintext WIKI_ID cookies
  599. if (!headers_sent())
  600. $request->deleteCookieVar(WIKI_NAME);
  601. }
  602. // Try to read deprecated 1.3.4 style cookies
  603. if (! $UserName and ($cookie = $request->cookies->get_old("WIKI_PREF2"))) {
  604. if (! $unboxedcookie = $this->_prefs->retrieve($cookie)) {
  605. if (! $UserName || $UserName == $unboxedcookie['userid']) {
  606. $updated = $this->_prefs->updatePrefs($unboxedcookie);
  607. //$this->_prefs = new UserPreferences($unboxedcookie);
  608. $UserName = $unboxedcookie['userid'];
  609. if (is_string($UserName) and (substr($UserName,0,2) != 's:'))
  610. $this->_userid = $UserName;
  611. else
  612. $UserName = false;
  613. }
  614. if (!headers_sent())
  615. $request->deleteCookieVar("WIKI_PREF2");
  616. }
  617. }
  618. if (! $UserName ) {
  619. // Try reading userid from old PhpWiki cookie formats:
  620. if ($cookie = $request->cookies->get_old(getCookieName())) {
  621. if (is_string($cookie) and (substr($cookie,0,2) != 's:'))
  622. $UserName = $cookie;
  623. elseif (is_array($cookie) and !empty($cookie['userid']))
  624. $UserName = $cookie['userid'];
  625. }
  626. if (! $UserName and !headers_sent())
  627. $request->deleteCookieVar(getCookieName());
  628. else
  629. $this->_userid = $UserName;
  630. }
  631. // initializeTheme() needs at least an empty object
  632. /*
  633. if (empty($this->_prefs))
  634. $this->_prefs = new UserPreferences;
  635. */
  636. return $this->_prefs;
  637. }
  638. /** _AnonUser::setPreferences(): Save prefs in a cookie and session and update all global vars
  639. *
  640. * Allow for multiple wikis in same domain. Encode only the
  641. * _prefs array of the UserPreference object. Ideally the
  642. * prefs array should just be imploded into a single string or
  643. * something so it is completely human readable by the end
  644. * user. In that case stricter error checking will be needed
  645. * when loading the cookie.
  646. */
  647. function setPreferences($prefs, $id_only=false) {
  648. if (!is_object($prefs)) {
  649. if (is_object($this->_prefs)) {
  650. $updated = $this->_prefs->updatePrefs($prefs);
  651. $prefs =& $this->_prefs;
  652. } else {
  653. // update the prefs values from scratch. This could leed to unnecessary
  654. // side-effects: duplicate emailVerified, ...
  655. $this->_prefs = new UserPreferences($prefs);
  656. $updated = true;
  657. }
  658. } else {
  659. if (!isset($this->_prefs))
  660. $this->_prefs =& $prefs;
  661. else
  662. $updated = $this->_prefs->isChanged($prefs);
  663. }
  664. if ($updated) {
  665. if ($id_only and !headers_sent()) {
  666. global $request;
  667. // new 1.3.8 policy: no array cookies, only plain userid string as in
  668. // the pre 1.3.x versions.
  669. // prefs should be stored besides the session in the homepagehandle or in a db.
  670. $request->setCookieVar(getCookieName(), $this->_userid,
  671. COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
  672. //$request->setCookieVar(WIKI_NAME, array('userid' => $prefs->get('userid')),
  673. // COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
  674. }
  675. }
  676. $packed = $prefs->store();
  677. $unpacked = $prefs->unpack($packed);
  678. if (count($unpacked)) {
  679. foreach (array('_method','_select','_update','_insert') as $param) {
  680. if (!empty($this->_prefs->{$param}))
  681. $prefs->{$param} = $this->_prefs->{$param};
  682. }
  683. $this->_prefs = $prefs;
  684. }
  685. return $updated;
  686. }
  687. function userExists() {
  688. return true;
  689. }
  690. function checkPass($submitted_password) {
  691. return false;
  692. // this might happen on a old-style signin button.
  693. // By definition, the _AnonUser does not HAVE a password
  694. // (compared to _BogoUser, who has an EMPTY password).
  695. trigger_error("DEBUG: Warning: _AnonUser unexpectedly asked to checkPass()." . " "
  696. . "Check isa(\$user, '_PassUser'), or: isa(\$user, '_AdminUser') etc. first." . " "
  697. . "New subclasses of _WikiUser must override this function.");
  698. return false;
  699. }
  700. }
  701. /**
  702. * Helper class to finish the PassUser auth loop.
  703. * This is added automatically to USER_AUTH_ORDER.
  704. */
  705. class _ForbiddenUser
  706. extends _AnonUser
  707. {
  708. var $_level = WIKIAUTH_FORBIDDEN;
  709. function checkPass($submitted_password) {
  710. return WIKIAUTH_FORBIDDEN;
  711. }
  712. function userExists() {
  713. if ($this->_HomePagehandle) return true;
  714. return false;
  715. }
  716. }
  717. /**
  718. * Do NOT extend _BogoUser to other classes, for checkPass()
  719. * security. (In case of defects in code logic of the new class!)
  720. * The intermediate step between anon and passuser.
  721. * We also have the _BogoLoginPassUser class with stricter
  722. * password checking, which fits into the auth loop.
  723. * Note: This class is not called anymore by WikiUser()
  724. */
  725. class _BogoUser
  726. extends _AnonUser
  727. {
  728. function userExists() {
  729. if (isWikiWord($this->_userid)) {
  730. $this->_level = WIKIAUTH_BOGO;
  731. return true;
  732. } else {
  733. $this->_level = WIKIAUTH_ANON;
  734. return false;
  735. }
  736. }
  737. function checkPass($submitted_password) {
  738. // By definition, BogoUser has an empty password.
  739. $this->userExists();
  740. return $this->_level;
  741. }
  742. }
  743. class _PassUser
  744. extends _AnonUser
  745. /**
  746. * Called if ALLOW_USER_PASSWORDS and Anon and Bogo failed.
  747. *
  748. * The classes for all subsequent auth methods extend from this class.
  749. * This handles the auth method type dispatcher according $USER_AUTH_ORDER,
  750. * the three auth method policies first-only, strict and stacked
  751. * and the two methods for prefs: homepage or database,
  752. * if $DBAuthParams['pref_select'] is defined.
  753. *
  754. * Default is PersonalPage auth and prefs.
  755. *
  756. * @author: Reini Urban
  757. * @tables: pref
  758. */
  759. {
  760. var $_auth_dbi, $_prefs;
  761. var $_current_method, $_current_index;
  762. // check and prepare the auth and pref methods only once
  763. function _PassUser($UserName='', $prefs=false) {
  764. //global $DBAuthParams, $DBParams;
  765. if ($UserName) {
  766. if (!$this->isValidName($UserName))
  767. return false;
  768. $this->_userid = $UserName;
  769. if ($this->hasHomePage())
  770. $this->_HomePagehandle = $GLOBALS['request']->getPage($this->_userid);
  771. }
  772. $this->_authmethod = substr(get_class($this),1,-8);
  773. if ($this->_authmethod == 'a') $this->_authmethod = 'admin';
  774. // Check the configured Prefs methods
  775. $dbi = $this->getAuthDbh();
  776. $dbh = $GLOBALS['request']->getDbh();
  777. if ( $dbi and !isset($this->_prefs->_select) and $dbh->getAuthParam('pref_select')) {
  778. if (!$this->_prefs) {
  779. $this->_prefs = new UserPreferences();
  780. $need_pref = true;
  781. }
  782. $this->_prefs->_method = $dbh->getParam('dbtype');
  783. $this->_prefs->_select = $this->prepare($dbh->getAuthParam('pref_select'), "userid");
  784. // read-only prefs?
  785. if ( !isset($this->_prefs->_update) and $dbh->getAuthParam('pref_update')) {
  786. $this->_prefs->_update = $this->prepare($dbh->getAuthParam('pref_update'),
  787. array("userid", "pref_blob"));
  788. }
  789. } else {
  790. if (!$this->_prefs) {
  791. $this->_prefs = new UserPreferences();
  792. $need_pref = true;
  793. }
  794. $this->_prefs->_method = 'HomePage';
  795. }
  796. if (! $this->_prefs or isset($need_pref) ) {
  797. if ($prefs) $this->_prefs = $prefs;
  798. else $this->getPreferences();
  799. }
  800. // Upgrade to the next parent _PassUser class. Avoid recursion.
  801. if ( strtolower(get_class($this)) === '_passuser' ) {
  802. //auth policy: Check the order of the configured auth methods
  803. // 1. first-only: Upgrade the class here in the constructor
  804. // 2. old: ignore USER_AUTH_ORDER and try to use all available methods as
  805. /// in the previous PhpWiki releases (slow)
  806. // 3. strict: upgrade the class after checking the user existance in userExists()
  807. // 4. stacked: upgrade the class after the password verification in checkPass()
  808. // Methods: PersonalPage, HttpAuth, DB, Ldap, Imap, File
  809. //if (!defined('USER_AUTH_POLICY')) define('USER_AUTH_POLICY','old');
  810. if (defined('USER_AUTH_POLICY')) {
  811. // policy 1: only pre-define one method for all users
  812. if (USER_AUTH_POLICY === 'first-only') {
  813. $class = $this->nextClass();
  814. return new $class($UserName,$this->_prefs);
  815. }
  816. // Use the default behaviour from the previous versions:
  817. elseif (USER_AUTH_POLICY === 'old') {
  818. // Default: try to be smart
  819. // On php5 we can directly return and upgrade the Object,
  820. // before we have to upgrade it manually.
  821. if (!empty($GLOBALS['PHP_AUTH_USER']) or !empty($_SERVER['REMOTE_USER'])) {
  822. include_once("lib/WikiUser/HttpAuth.php");
  823. if (check_php_version(5))
  824. return new _HttpAuthPassUser($UserName,$this->_prefs);
  825. else {
  826. $user = new _HttpAuthPassUser($UserName,$this->_prefs);
  827. eval("\$this = \$user;");
  828. // /*PHP5 patch*/$this = $user;
  829. return $user;
  830. }
  831. } elseif (in_array('Db', $dbh->getAuthParam('USER_AUTH_ORDER')) and
  832. $dbh->getAuthParam('auth_check') and
  833. ($dbh->getAuthParam('auth_dsn') or $dbh->getParam('dsn'))) {
  834. if (check_php_version(5))
  835. return new _DbPassUser($UserName,$this->_prefs);
  836. else {
  837. $user = new _DbPassUser($UserName,$this->_prefs);
  838. eval("\$this = \$user;");
  839. // /*PHP5 patch*/$this = $user;
  840. return $user;
  841. }
  842. } elseif (in_array('LDAP', $dbh->getAuthParam('USER_AUTH_ORDER')) and
  843. defined('LDAP_AUTH_HOST') and defined('LDAP_BASE_DN') and
  844. function_exists('ldap_connect')) {
  845. include_once("lib/WikiUser/LDAP.php");
  846. if (check_php_version(5))
  847. return new _LDAPPassUser($UserName,$this->_prefs);
  848. else {
  849. $user = new _LDAPPassUser($UserName,$this->_prefs);
  850. eval("\$this = \$user;");
  851. // /*PHP5 patch*/$this = $user;
  852. return $user;
  853. }
  854. } elseif (in_array('IMAP', $dbh->getAuthParam('USER_AUTH_ORDER')) and
  855. defined('IMAP_AUTH_HOST') and function_exists('imap_open')) {
  856. include_once("lib/WikiUser/IMAP.php");
  857. if (check_php_version(5))
  858. return new _IMAPPassUser($UserName,$this->_prefs);
  859. else {
  860. $user = new _IMAPPassUser($UserName,$this->_prefs);
  861. eval("\$this = \$user;");
  862. // /*PHP5 patch*/$this = $user;
  863. return $user;
  864. }
  865. } elseif (in_array('File', $dbh->getAuthParam('USER_AUTH_ORDER')) and
  866. defined('AUTH_USER_FILE') and file_exists(AUTH_USER_FILE)) {
  867. include_once("lib/WikiUser/File.php");
  868. if (check_php_version(5))
  869. return new _FilePassUser($UserName, $this->_prefs);
  870. else {
  871. $user = new _FilePassUser($UserName, $this->_prefs);
  872. eval("\$this = \$user;");
  873. // /*PHP5 patch*/$this = $user;
  874. return $user;
  875. }
  876. } else {
  877. include_once("lib/WikiUser/PersonalPage.php");
  878. if (check_php_version(5))
  879. return new _PersonalPagePassUser($UserName,$this->_prefs);
  880. else {
  881. $user = new _PersonalPagePassUser($UserName,$this->_prefs);
  882. eval("\$this = \$user;");
  883. // /*PHP5 patch*/$this = $user;
  884. return $user;
  885. }
  886. }
  887. }
  888. else
  889. // else use the page methods defined in _PassUser.
  890. return $this;
  891. }
  892. }
  893. }
  894. function getAuthDbh () {
  895. global $request; //, $DBParams, $DBAuthParams;
  896. $dbh = $request->getDbh();
  897. // session restauration doesn't re-connect to the database automatically,
  898. // so dirty it here, to force a reconnect.
  899. if (isset($this->_auth_dbi)) {
  900. if (($dbh->getParam('dbtype') == 'SQL') and empty($this->_auth_dbi->connection))
  901. unset($this->_auth_dbi);
  902. if (($dbh->getParam('dbtype') == 'ADODB') and empty($this->_auth_dbi->_connectionID))
  903. unset($this->_auth_dbi);
  904. }
  905. if (empty($this->_auth_dbi)) {
  906. if ($dbh->getParam('dbtype') != 'SQL'
  907. and $dbh->getParam('dbtype') != 'ADODB'
  908. and $dbh->getParam('dbtype') != 'PDO')
  909. return false;
  910. if (empty($GLOBALS['DBAuthParams']))
  911. return false;
  912. if (!$dbh->getAuthParam('auth_dsn')) {
  913. $dbh = $request->getDbh(); // use phpwiki database
  914. } elseif ($dbh->getAuthParam('auth_dsn') == $dbh->getParam('dsn')) {
  915. $dbh = $request->getDbh(); // same phpwiki database
  916. } else { // use another external database handle. needs PHP >= 4.1
  917. $local_params = array_merge($GLOBALS['DBParams'],$GLOBALS['DBAuthParams']);
  918. $local_params['dsn'] = $local_params['auth_dsn'];
  919. $dbh = WikiDB::open($local_params);
  920. }
  921. $this->_auth_dbi =& $dbh->_backend->_dbh;
  922. }
  923. return $this->_auth_dbi;
  924. }
  925. function _normalize_stmt_var($var, $oldstyle = false) {
  926. static $valid_variables = array('userid','password','pref_blob','groupname');
  927. // old-style: "'$userid'"
  928. // new-style: '"\$userid"' or just "userid"
  929. $new = str_replace(array("'",'"','\$','$'),'',$var);
  930. if (!in_array($new, $valid_variables)) {
  931. trigger_error("Unknown DBAuthParam statement variable: ". $new, E_USER_ERROR);
  932. return false;
  933. }
  934. return !$oldstyle ? "'$".$new."'" : '\$'.$new;
  935. }
  936. // TODO: use it again for the auth and member tables
  937. // sprintfstyle vs prepare style: %s or ?
  938. // multiple vars should be executed via prepare(?,?)+execute,
  939. // single vars with execute(sprintf(quote(var)))
  940. // help with position independency
  941. function prepare ($stmt, $variables, $oldstyle = false, $sprintfstyle = true) {
  942. global $request;
  943. $dbi = $request->getDbh();
  944. $this->getAuthDbh();
  945. // "'\$userid"' => %s
  946. // variables can be old-style: '"\$userid"' or new-style: "'$userid'" or just "userid"
  947. // old-style strings don't survive pear/Config/IniConfig treatment, that's why we changed it.
  948. $new = array();
  949. if (is_array($variables)) {
  950. //$sprintfstyle = false;
  951. for ($i=0; $i < count($variables); $i++) {
  952. $var = $this->_normalize_stmt_var($variables[$i], $oldstyle);
  953. if (!$var)
  954. trigger_error(sprintf("DbAuthParams: Undefined or empty statement variable %s in %s",
  955. $variables[$i], $stmt), E_USER_WARNING);
  956. $variables[$i] = $var;
  957. if (!$var) $new[] = '';
  958. else {
  959. $s = "%" . ($i+1) . "s";
  960. $new[] = $sprintfstyle ? $s : "?";
  961. }
  962. }
  963. } else {
  964. $var = $this->_normalize_stmt_var($variables, $oldstyle);
  965. if (!$var)
  966. trigger_error(sprintf("DbAuthParams: Undefined or empty statement variable %s in %s",
  967. $variables, $stmt), E_USER_WARNING);
  968. $variables = $var;
  969. if (!$var) $new = '';
  970. else $new = $sprintfstyle ? '%s' : "?";
  971. }
  972. $prefix = $dbi->getParam('prefix');
  973. // probably prefix table names if in same database
  974. if ($prefix and isset($this->_auth_dbi) and isset($dbi->_backend->_dbh) and
  975. ($dbi->getAuthParam('auth_dsn') and $dbi->getParam('dsn') == $dbi->getAuthParam('auth_dsn')))
  976. {
  977. if (!stristr($stmt, $prefix)) {
  978. $oldstmt = $stmt;
  979. $stmt = str_replace(array(" user "," pref "," member "),
  980. array(" ".$prefix."user ",
  981. " ".$prefix."pref ",
  982. " ".$prefix."member "), $stmt);
  983. //Do it automatically for the lazy admin? Esp. on sf.net it's nice to have
  984. trigger_error("Need to prefix the DBAUTH tablename in config/config.ini:\n $oldstmt \n=> $stmt",
  985. E_USER_WARNING);
  986. }
  987. }
  988. // Preparate the SELECT statement, for ADODB and PearDB (MDB not).
  989. // Simple sprintf-style.
  990. $new_stmt = str_replace($variables, $new, $stmt);
  991. if ($new_stmt == $stmt) {
  992. if ($oldstyle) {
  993. trigger_error(sprintf("DbAuthParams: Invalid statement in %s",
  994. $stmt), E_USER_WARNING);
  995. } else {
  996. trigger_error(sprintf("DbAuthParams: Old statement quoting style in %s",
  997. $stmt), E_USER_WARNING);
  998. $new_stmt = $this->prepare($stmt, $variables, 'oldstyle');
  999. }
  1000. }
  1001. return $new_stmt;
  1002. }
  1003. function getPreferences() {
  1004. if (!empty($this->_prefs->_method)) {
  1005. if ($this->_prefs->_method == 'ADODB') {
  1006. // FIXME: strange why this should be needed...
  1007. include_once("lib/WikiUser/Db.php");
  1008. include_once("lib/WikiUser/AdoDb.php");
  1009. _AdoDbPassUser::_AdoDbPassUser($this->_userid, $this->_prefs);
  1010. return _AdoDbPassUser::getPreferences();
  1011. } elseif ($this->_prefs->_method == 'SQL') {
  1012. include_once("lib/WikiUser/Db.php");
  1013. include_once("lib/WikiUser/PearDb.php");
  1014. _PearDbPassUser::_PearDbPassUser($this->_userid, $this->_prefs);
  1015. return _PearDbPassUser::getPreferences();
  1016. } elseif ($this->_prefs->_method == 'PDO') {
  1017. include_once("lib/WikiUser/Db.php");
  1018. include_once("lib/WikiUser/PdoDb.php");
  1019. _PdoDbPassUser::_PdoDbPassUser($this->_userid, $this->_prefs);
  1020. return _PdoDbPassUser::getPreferences();
  1021. }
  1022. }
  1023. // We don't necessarily have to read the cookie first. Since
  1024. // the user has a password, the prefs stored in the homepage
  1025. // cannot be arbitrarily altered by other Bogo users.
  1026. _AnonUser::getPreferences();
  1027. // User may have deleted cookie, retrieve from his
  1028. // PersonalPage if there is one.
  1029. if ($this->_HomePagehandle) {
  1030. if ($restored_from_page = $this->_prefs->retrieve
  1031. ($this->_HomePagehandle->get('pref'))) {
  1032. $updated = $this->_prefs->updatePrefs($restored_from_page,'init');
  1033. //$this->_prefs = new UserPreferences($restored_from_page);
  1034. return $this->_prefs;
  1035. }
  1036. }
  1037. return $this->_prefs;
  1038. }
  1039. function setPreferences($prefs, $id_only=false) {
  1040. if (!empty($this->_prefs->_method)) {
  1041. if ($this->_prefs->_method == 'ADODB') {
  1042. // FIXME: strange why this should be needed...
  1043. include_once("lib/WikiUser/Db.php");
  1044. include_once("lib/WikiUser/AdoDb.php");
  1045. _AdoDbPassUser::_AdoDbPassUser($this->_userid, $prefs);
  1046. return _AdoDbPassUser::setPreferences($prefs, $id_only);
  1047. }
  1048. elseif ($this->_prefs->_method == 'SQL') {
  1049. include_once("lib/WikiUser/Db.php");
  1050. include_once("lib/WikiUser/PearDb.php");
  1051. _PearDbPassUser::_PearDbPassUser($this->_userid, $prefs);
  1052. return _PearDbPassUser::setPreferences($prefs, $id_only);
  1053. }
  1054. elseif ($this->_prefs->_method == 'PDO') {
  1055. include_once("lib/WikiUser/Db.php");
  1056. include_once("lib/WikiUser/PdoDb.php");
  1057. _PdoDbPassUser::_PdoDbPassUser($this->_userid, $prefs);
  1058. return _PdoDbPassUser::setPreferences($prefs, $id_only);
  1059. }
  1060. }
  1061. if ($updated = _AnonUser::setPreferences($prefs, $id_only)) {
  1062. // Encode only the _prefs array of the UserPreference object
  1063. if (!empty($this->_HomePagehandle) and !$id_only) {
  1064. $this->_HomePagehandle->set('pref', $this->_prefs->store());
  1065. }
  1066. }
  1067. return $updated;
  1068. }
  1069. function mayChangePass() {
  1070. return true;
  1071. }
  1072. //The default method is getting the password from prefs.
  1073. // child methods obtain $stored_password from external auth.
  1074. function userExists() {
  1075. //if ($this->_HomePagehandle) return true;
  1076. $class = $this->nextClass();
  1077. while ($user = new $class($this->_userid, $this->_prefs)) {
  1078. if (!check_php_version(5))
  1079. eval("\$this = \$user;");
  1080. // /*PHP5 patch*/$this = $user;
  1081. UpgradeUser($this,$user);
  1082. if ($user->userExists()) {
  1083. return true;
  1084. }
  1085. // prevent endless loop. does this work on all PHP's?
  1086. // it just has to set the classname, what it correctly does.
  1087. $class = $user->nextClass();
  1088. if ($class == "_ForbiddenPassUser")
  1089. return false;
  1090. }
  1091. return false;
  1092. }
  1093. //The default method is getting the password from prefs.
  1094. // child methods obtain $stored_password from external auth.
  1095. function checkPass($submitted_password) {
  1096. $stored_password = $this->_prefs->get('passwd');
  1097. if ($this->_checkPass($submitted_password, $stored_password)) {
  1098. $this->_level = WIKIAUTH_USER;
  1099. return $this->_level;
  1100. } else {
  1101. if ((USER_AUTH_POLICY === 'strict') and $this->userExists()) {
  1102. $this->_level = WIKIAUTH_FORBIDDEN;
  1103. return $this->_level;
  1104. }
  1105. return $this->_tryNextPass($submitted_password);
  1106. }
  1107. }
  1108. function _checkPassLength($submitted_password) {
  1109. if (strlen($submitted_password) < PASSWORD_LENGTH_MINIMUM) {
  1110. trigger_error(_("The length of the password is shorter than the system policy allows."));
  1111. return false;
  1112. }
  1113. return true;
  1114. }
  1115. /**
  1116. * The basic password checker for all PassUser objects.
  1117. * Uses global ENCRYPTED_PASSWD and PASSWORD_LENGTH_MINIMUM.
  1118. * Empty passwords are always false!
  1119. * PASSWORD_LENGTH_MINIMUM is enforced here and in the preference set method.
  1120. * @see UserPreferences::set
  1121. *
  1122. * DBPassUser password's have their own crypt definition.
  1123. * That's why DBPassUser::checkPass() doesn't call this method, if
  1124. * the db password method is 'plain', which means that the DB SQL
  1125. * statement just returns 1 or 0. To use CRYPT() or PASSWORD() and
  1126. * don't store plain passwords in the DB.
  1127. *
  1128. * TODO: remove crypt() function check from config.php:396 ??
  1129. */
  1130. function _checkPass($submitted_password, $stored_password) {
  1131. if (!empty($submitted_password)) {
  1132. // This works only on plaintext passwords.
  1133. if (!ENCRYPTED_PASSWD and (strlen($stored_password) < PASSWORD_LENGTH_MINIMUM)) {
  1134. // With the EditMetaData plugin
  1135. 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."));
  1136. return false;
  1137. }
  1138. if (!$this->_checkPassLength($submitted_password)) {
  1139. return false;
  1140. }
  1141. if (ENCRYPTED_PASSWD) {
  1142. // Verify against encrypted password.
  1143. if (function_exists('crypt')) {
  1144. if (crypt($submitted_password, $stored_password) == $stored_password )
  1145. return true; // matches encrypted password
  1146. else
  1147. return false;
  1148. }
  1149. else {
  1150. trigger_error(_("The crypt function is not available in this version of PHP.") . " "
  1151. . _("Please set ENCRYPTED_PASSWD to false in config/config.ini and probably change ADMIN_PASSWD."),
  1152. E_USER_WARNING);
  1153. return false;
  1154. }
  1155. }
  1156. else {
  1157. // Verify against cleartext password.
  1158. if ($submitted_password == $stored_password)
  1159. return true;
  1160. else {
  1161. // Check whether we forgot to enable ENCRYPTED_PASSWD
  1162. if (function_exists('crypt')) {
  1163. if (crypt($submitted_password, $stored_password) == $stored_password) {
  1164. trigger_error(_("Please set ENCRYPTED_PASSWD to true in config/config.ini."),
  1165. E_USER_WARNING);
  1166. return true;
  1167. }
  1168. }
  1169. }
  1170. }
  1171. }
  1172. return false;
  1173. }
  1174. /** The default method is storing the password in prefs.
  1175. * Child methods (DB, File) may store in external auth also, but this
  1176. * must be explicitly enabled.
  1177. * This may be called by plugin/UserPreferences or by ->SetPreferences()
  1178. */
  1179. function changePass($submitted_password) {
  1180. $stored_password = $this->_prefs->get('passwd');
  1181. // check if authenticated
  1182. if (!$this->isAuthenticated()) return false;
  1183. if (ENCRYPTED_PASSWD) {
  1184. $submitted_password = crypt($submitted_password);
  1185. }
  1186. // check other restrictions, with side-effects only.
  1187. $result = $this->_checkPass($submitted_password, $stored_password);
  1188. if ($stored_password != $submitted_password) {
  1189. $this->_prefs->set('passwd', $submitted_password);
  1190. //update the storage (session, homepage, ...)
  1191. $this->SetPreferences($this->_prefs);
  1192. return true;
  1193. }
  1194. //Todo: return an error msg to the caller what failed?
  1195. // same password or no privilege
  1196. return ENCRYPTED_PASSWD ? true : false;
  1197. }
  1198. function _tryNextPass($submitted_password) {
  1199. if (DEBUG & _DEBUG_LOGIN) {
  1200. $class = strtolower(get_class($this));
  1201. if (substr($class,-10) == "dbpassuser") $class = "_dbpassuser";
  1202. $GLOBALS['USER_AUTH_ERROR'][$class] = 'wrongpass';
  1203. }
  1204. if (USER_AUTH_POLICY === 'strict') {
  1205. $class = $this->nextClass();
  1206. if ($user = new $class($this->_userid,$this->_prefs)) {
  1207. if ($user->userExists()) {
  1208. return $user->checkPass($submitted_password);
  1209. }
  1210. }
  1211. }
  1212. if (USER_AUTH_POLICY === 'stacked' or USER_AUTH_POLICY === 'old') {
  1213. $class = $this->nextClass();
  1214. if ($user = new $class($this->_userid,$this->_prefs))
  1215. return $user->checkPass($submitted_password);
  1216. }
  1217. return $this->_level;
  1218. }
  1219. function _tryNextUser() {
  1220. if (DEBUG & _DEBUG_LOGIN) {
  1221. $class = strtolower(get_class($this));
  1222. if (substr($class,-10) == "dbpassuser") $class = "_dbpassuser";
  1223. $GLOBALS['USER_AUTH_ERROR'][$class] = 'nosuchuser';
  1224. }
  1225. if (USER_AUTH_POLICY === 'strict') {
  1226. $class = $this->nextClass();
  1227. while ($user = new $class($this->_userid,$this->_prefs)) {
  1228. if (!check_php_version(5))
  1229. eval("\$this = \$user;");
  1230. // /*PHP5 patch*/$this = $user;
  1231. //$user = UpgradeUser($this, $user);
  1232. if ($user->userExists()) {
  1233. return true;
  1234. }
  1235. $class = $this->nextClass();
  1236. }
  1237. }
  1238. return false;
  1239. }
  1240. }
  1241. /**
  1242. * Insert more auth classes here...
  1243. * For example a customized db class for another db connection
  1244. * or a socket-based auth server.
  1245. *
  1246. */
  1247. /**
  1248. * For security, this class should not be extended. Instead, extend
  1249. * from _PassUser (think of this as unix "root").
  1250. *
  1251. * FIXME: This should be a singleton class. Only ADMIN_USER may be of class AdminUser!
  1252. * Other members of the Administrators group must raise their level otherwise somehow.
  1253. * Currently every member is a AdminUser, which will not work for the various
  1254. * storage methods.
  1255. */
  1256. class _AdminUser
  1257. extends _PassUser
  1258. {
  1259. function mayChangePass() {
  1260. return false;
  1261. }
  1262. function checkPass($submitted_password) {
  1263. if ($this->_userid == ADMIN_USER)
  1264. $stored_password = ADMIN_PASSWD;
  1265. else {
  1266. // Should not happen! Only ADMIN_USER should use this class.
  1267. // return $this->_tryNextPass($submitted_password); // ???
  1268. // TODO: safety check if really member of the ADMIN group?
  1269. $stored_password = $this->_pref->get('passwd');
  1270. }
  1271. if ($this->_checkPass($submitted_password, $stored_password)) {
  1272. $this->_level = WIKIAUTH_ADMIN;
  1273. if (!empty($GLOBALS['HTTP_SERVER_VARS']['PHP_AUTH_USER']) and class_exists("_HttpAuthPassUser")) {
  1274. // fake http auth
  1275. _HttpAuthPassUser::_fake_auth($this->_userid, $submitted_password);
  1276. }
  1277. return $this->_level;
  1278. } else {
  1279. return $this->_tryNextPass($submitted_password);
  1280. //$this->_level = WIKIAUTH_ANON;
  1281. //return $this->_level;
  1282. }
  1283. }
  1284. function storePass($submitted_password) {
  1285. if ($this->_userid == ADMIN_USER)
  1286. return false;
  1287. else {
  1288. // should not happen! only ADMIN_USER should use this class.
  1289. return parent::storePass($submitted_password);
  1290. }
  1291. }
  1292. }
  1293. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1294. /**
  1295. * Various data classes for the preference types,
  1296. * to support get, set, sanify (range checking, ...)
  1297. * update() will do the neccessary side-effects if a
  1298. * setting gets changed (theme, language, ...)
  1299. */
  1300. class _UserPreference
  1301. {
  1302. var $default_value;
  1303. function _UserPreference ($default_value) {
  1304. $this->default_value = $default_value;
  1305. }
  1306. function sanify ($value) {
  1307. return (string)$value;
  1308. }
  1309. function get ($name) {
  1310. if (isset($this->{$name}))
  1311. return $this->{$name};
  1312. else
  1313. return $this->default_value;
  1314. }
  1315. function getraw ($name) {
  1316. if (!empty($this->{$name}))
  1317. return $this->{$name};
  1318. }
  1319. // stores the value as $this->$name, and not as $this->value (clever?)
  1320. function set ($name, $value) {
  1321. $return = 0;
  1322. $value = $this->sanify($value);
  1323. if ($this->get($name) != $value) {
  1324. $this->update($value);
  1325. $return = 1;
  1326. }
  1327. if ($value != $this->default_value) {
  1328. $this->{$name} = $value;
  1329. } else {
  1330. unset($this->{$name});
  1331. }
  1332. return $return;
  1333. }
  1334. // default: no side-effects
  1335. function update ($value) {
  1336. ;
  1337. }
  1338. }
  1339. class _UserPreference_numeric
  1340. extends _UserPreference
  1341. {
  1342. function _UserPreference_numeric ($default, $minval = false,
  1343. $maxval = false) {
  1344. $this->_UserPreference((double)$default);
  1345. $this->_minval = (double)$minval;
  1346. $this->_maxval = (double)$maxval;
  1347. }
  1348. function sanify ($value) {
  1349. $value = (double)$value;
  1350. if ($this->_minval !== false && $value < $this->_minval)
  1351. $value = $this->_minval;
  1352. if ($this->_maxval !== false && $value > $this->_maxval)
  1353. $value = $this->_maxval;
  1354. return $value;
  1355. }
  1356. }
  1357. class _UserPreference_int
  1358. extends _UserPreference_numeric
  1359. {
  1360. function _UserPreference_int ($default, $minval = false, $maxval = false) {
  1361. $this->_UserPreference_numeric((int)$default, (int)$minval, (int)$maxval);
  1362. }
  1363. function sanify ($value) {
  1364. return (int)parent::sanify((int)$value);
  1365. }
  1366. }
  1367. class _UserPreference_bool
  1368. extends _UserPreference
  1369. {
  1370. function _UserPreference_bool ($default = false) {
  1371. $this->_UserPreference((bool)$default);
  1372. }
  1373. function sanify ($value) {
  1374. if (is_array($value)) {
  1375. /* This allows for constructs like:
  1376. *
  1377. * <input type="hidden" name="pref[boolPref][]" value="0" />
  1378. * <input type="checkbox" name="pref[boolPref][]" value="1" />
  1379. *
  1380. * (If the checkbox is not checked, only the hidden input
  1381. * gets sent. If the checkbox is sent, both inputs get
  1382. * sent.)
  1383. */
  1384. foreach ($value as $val) {
  1385. if ($val)
  1386. return true;
  1387. }
  1388. return false;
  1389. }
  1390. return (bool) $value;
  1391. }
  1392. }
  1393. class _UserPreference_language
  1394. extends _UserPreference
  1395. {
  1396. function _UserPreference_language ($default = DEFAULT_LANGUAGE) {
  1397. $this->_UserPreference($default);
  1398. }
  1399. // FIXME: check for valid locale
  1400. function sanify ($value) {
  1401. // Revert to DEFAULT_LANGUAGE if user does not specify
  1402. // language in UserPreferences or chooses <system language>.
  1403. if ($value == '' or empty($value))
  1404. $value = DEFAULT_LANGUAGE;
  1405. return (string) $value;
  1406. }
  1407. function update ($newvalue) {
  1408. if (! $this->_init ) {
  1409. // invalidate etag to force fresh output
  1410. $GLOBALS['request']->setValidators(array('%mtime' => false));
  1411. update_locale($newvalue ? $newvalue : $GLOBALS['LANG']);
  1412. }
  1413. }
  1414. }
  1415. class _UserPreference_theme
  1416. extends _UserPreference
  1417. {
  1418. function _UserPreference_theme ($default = THEME) {
  1419. $this->_UserPreference($default);
  1420. }
  1421. function sanify ($value) {
  1422. if (!empty($value) and FindFile($this->_themefile($value)))
  1423. return $value;
  1424. return $this->default_value;
  1425. }
  1426. function update ($newvalue) {
  1427. global $WikiTheme;
  1428. // invalidate etag to force fresh output
  1429. if (! $this->_init )
  1430. $GLOBALS['request']->setValidators(array('%mtime' => false));
  1431. if ($newvalue)
  1432. include_once($this->_themefile($newvalue));
  1433. if (empty($WikiTheme))
  1434. include_once($this->_themefile(THEME));
  1435. }
  1436. function _themefile ($theme) {
  1437. return "themes/$theme/themeinfo.php";
  1438. }
  1439. }
  1440. class _UserPreference_notify
  1441. extends _UserPreference
  1442. {
  1443. function sanify ($value) {
  1444. if (!empty($value))
  1445. return $value;
  1446. else
  1447. return $this->default_value;
  1448. }
  1449. /** update to global user prefs: side-effect on set notify changes
  1450. * use a global_data notify hash:
  1451. * notify = array('pagematch' => array(userid => ('email' => mail,
  1452. * 'verified' => 0|1),
  1453. * ...),
  1454. * ...);
  1455. */
  1456. function update ($value) {
  1457. if (!empty($this->_init)) return;
  1458. $dbh = $GLOBALS['request']->getDbh();
  1459. $notify = $dbh->get('notify');
  1460. if (empty($notify))
  1461. $data = array();
  1462. else
  1463. $data =& $notify;
  1464. // expand to existing pages only or store matches?
  1465. // for now we store (glob-style) matches which is easier for the user
  1466. $pages = $this->_page_split($value);
  1467. // Limitation: only current user.
  1468. $user = $GLOBALS['request']->getUser();
  1469. if (!$user or !method_exists($user,'UserName')) return;
  1470. // This fails with php5 and a WIKI_ID cookie:
  1471. $userid = $user->UserName();
  1472. $email = $user->_prefs->get('email');
  1473. $verified = $user->_prefs->_prefs['email']->getraw('emailVerified');
  1474. // check existing notify hash and possibly delete pages for email
  1475. if (!empty($data)) {
  1476. foreach ($data as $page => $users) {
  1477. if (isset($data[$page][$userid]) and !in_array($page, $pages)) {
  1478. unset($data[$page][$userid]);
  1479. }
  1480. if (count($data[$page]) == 0)
  1481. unset($data[$page]);
  1482. }
  1483. }
  1484. // add the new pages
  1485. if (!empty($pages)) {
  1486. foreach ($pages as $page) {
  1487. if (!isset($data[$page]))
  1488. $data[$page] = array();
  1489. if (!isset($data[$page][$userid])) {
  1490. // should we really store the verification notice here or
  1491. // check it dynamically at every page->save?
  1492. if ($verified) {
  1493. $data[$page][$userid] = array('email' => $email,
  1494. 'verified' => $verified);
  1495. } else {
  1496. $data[$page][$userid] = array('email' => $email);
  1497. }
  1498. }
  1499. }
  1500. }
  1501. // store users changes
  1502. $dbh->set('notify',$data);
  1503. }
  1504. /** split the user-given comma or whitespace delimited pagenames
  1505. * to array
  1506. */
  1507. function _page_split($value) {
  1508. return preg_split('/[\s,]+/',$value,-1,PREG_SPLIT_NO_EMPTY);
  1509. }
  1510. }
  1511. class _UserPreference_email
  1512. extends _UserPreference
  1513. {
  1514. function sanify($value) {
  1515. // check for valid email address
  1516. if ($this->get('email') == $value and $this->getraw('emailVerified'))
  1517. return $value;
  1518. // hack!
  1519. if ($value == 1 or $value === true)
  1520. return $value;
  1521. list($ok,$msg) = ValidateMail($value,'noconnect');
  1522. if ($ok) {
  1523. return $value;
  1524. } else {
  1525. trigger_error("E-Mail Validation Error: ".$msg, E_USER_WARNING);
  1526. return $this->default_value;
  1527. }
  1528. }
  1529. /** Side-effect on email changes:
  1530. * Send a verification mail or for now just a notification email.
  1531. * For true verification (value = 2), we'd need a mailserver hook.
  1532. */
  1533. function update($value) {
  1534. if (!empty($this->_init)) return;
  1535. $verified = $this->getraw('emailVerified');
  1536. // hack!
  1537. if (($value == 1 or $value === true) and $verified)
  1538. return;
  1539. if (!empty($value) and !$verified) {
  1540. list($ok,$msg) = ValidateMail($value);
  1541. if ($ok and mail($value,"[".WIKI_NAME ."] "._("Email Verification"),
  1542. sprintf(_("Welcome to %s!\nYour email account is verified and\nwill be used to send page change notifications.\nSee %s"),
  1543. WIKI_NAME, WikiURL($GLOBALS['request']->getArg('pagename'),'',true))))
  1544. $this->set('emailVerified',1);
  1545. }
  1546. }
  1547. }
  1548. /** Check for valid email address
  1549. fixed version from http://www.zend.com/zend/spotlight/ev12apr.php
  1550. Note: too strict, Bug #1053681
  1551. */
  1552. function ValidateMail($email, $noconnect=false) {
  1553. $HTTP_HOST = $GLOBALS['request']->get('HTTP_HOST');
  1554. // if this check is too strict (like invalid mail addresses in a local network only)
  1555. // uncomment the following line:
  1556. // return array(true,"not validated");
  1557. // see http://sourceforge.net/tracker/index.php?func=detail&aid=1053681&group_id=6121&atid=106121
  1558. $result = array();
  1559. // This is Paul Warren's (pdw@ex-parrot.com) monster regex for RFC822
  1560. // addresses, from the Perl module Mail::RFC822::Address, reduced to
  1561. // accept single RFC822 addresses without comments only. (The original
  1562. // accepts groups and properly commented addresses also.)
  1563. $lwsp = "(?:(?:\\r\\n)?[ \\t])";
  1564. $specials = '()<>@,;:\\\\".\\[\\]';
  1565. $controls = '\\000-\\031';
  1566. $dtext = "[^\\[\\]\\r\\\\]";
  1567. $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$lwsp*";
  1568. $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$lwsp)*\"$lwsp*";
  1569. $atom = "[^$specials $controls]+(?:$lwsp+|\\Z|(?=[\\[\"$specials]))";
  1570. $word = "(?:$atom|$quoted_string)";
  1571. $localpart = "$word(?:\\.$lwsp*$word)*";
  1572. $sub_domain = "(?:$atom|$domain_literal)";
  1573. $domain = "$sub_domain(?:\\.$lwsp*$sub_domain)*";
  1574. $addr_spec = "$localpart\@$lwsp*$domain";
  1575. $phrase = "$word*";
  1576. $route = "(?:\@$domain(?:,\@$lwsp*$domain)*:$lwsp*)";
  1577. $route_addr = "\\<$lwsp*$route?$addr_spec\\>$lwsp*";
  1578. $mailbox = "(?:$addr_spec|$phrase$route_addr)";
  1579. $rfc822re = "/$lwsp*$mailbox/";
  1580. if (!preg_match($rfc822re, $email)) {
  1581. $result[0] = false;
  1582. $result[1] = sprintf(_("E-Mail address '%s' is not properly formatted"), $email);
  1583. return $result;
  1584. }
  1585. if ($noconnect)
  1586. return array(true,sprintf(_("E-Mail address '%s' is properly formatted"), $email));
  1587. list ( $Username, $Domain ) = split ("@", $email);
  1588. //Todo: getmxrr workaround on windows or manual input field to verify it manually
  1589. if (!isWindows() and getmxrr($Domain, $MXHost)) { // avoid warning on Windows.
  1590. $ConnectAddress = $MXHost[0];
  1591. } else {
  1592. $ConnectAddress = $Domain;
  1593. }
  1594. $Connect = @fsockopen ( $ConnectAddress, 25 );
  1595. if ($Connect) {
  1596. if (ereg("^220", $Out = fgets($Connect, 1024))) {
  1597. fputs ($Connect, "HELO $HTTP_HOST\r\n");
  1598. $Out = fgets ( $Connect, 1024 );
  1599. fputs ($Connect, "MAIL FROM: <".$email.">\r\n");
  1600. $From = fgets ( $Connect, 1024 );
  1601. fputs ($Connect, "RCPT TO: <".$email.">\r\n");
  1602. $To = fgets ($Connect, 1024);
  1603. fputs ($Connect, "QUIT\r\n");
  1604. fclose($Connect);
  1605. if (!ereg ("^250", $From)) {
  1606. $result[0]=false;
  1607. $result[1]="Server rejected address: ". $From;
  1608. return $result;
  1609. }
  1610. if (!ereg ( "^250", $To )) {
  1611. $result[0]=false;
  1612. $result[1]="Server rejected address: ". $To;
  1613. return $result;
  1614. }
  1615. } else {
  1616. $result[0] = false;
  1617. $result[1] = "No response from server";
  1618. return $result;
  1619. }
  1620. } else {
  1621. $result[0]=false;
  1622. $result[1]="Can not connect E-Mail server.";
  1623. return $result;
  1624. }
  1625. $result[0]=true;
  1626. $result[1]="E-Mail address '$email' appears to be valid.";
  1627. return $result;
  1628. } // end of function
  1629. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1630. /**
  1631. * UserPreferences
  1632. *
  1633. * This object holds the $request->_prefs subobjects.
  1634. * A simple packed array of non-default values get's stored as cookie,
  1635. * homepage, or database, which are converted to the array of
  1636. * ->_prefs objects.
  1637. * We don't store the objects, because otherwise we will
  1638. * not be able to upgrade any subobject. And it's a waste of space also.
  1639. *
  1640. */
  1641. class UserPreferences
  1642. {
  1643. function UserPreferences($saved_prefs = false) {
  1644. // userid stored too, to ensure the prefs are being loaded for
  1645. // the correct (currently signing in) userid if stored in a
  1646. // cookie.
  1647. // Update: for db prefs we disallow passwd.
  1648. // userid is needed for pref reflexion. current pref must know its username,
  1649. // if some app needs prefs from different users, different from current user.
  1650. $this->_prefs
  1651. = array(
  1652. 'userid' => new _UserPreference(''),
  1653. 'passwd' => new _UserPreference(''),
  1654. 'autologin' => new _UserPreference_bool(),
  1655. //'emailVerified' => new _UserPreference_emailVerified(),
  1656. //fixed: store emailVerified as email parameter, 1.3.8
  1657. 'email' => new _UserPreference_email(''),
  1658. 'notifyPages' => new _UserPreference_notify(''), // 1.3.8
  1659. 'theme' => new _UserPreference_theme(THEME),
  1660. 'lang' => new _UserPreference_language(DEFAULT_LANGUAGE),
  1661. 'editWidth' => new _UserPreference_int(EDITWIDTH_DEFAULT_COLS,
  1662. EDITWIDTH_MIN_COLS,
  1663. EDITWIDTH_MAX_COLS),
  1664. 'noLinkIcons' => new _UserPreference_bool(), // 1.3.8
  1665. 'editHeight' => new _UserPreference_int(EDITHEIGHT_DEFAULT_ROWS,
  1666. EDITHEIGHT_MIN_ROWS,
  1667. EDITHEIGHT_MAX_ROWS),
  1668. 'timeOffset' => new _UserPreference_numeric(TIMEOFFSET_DEFAULT_HOURS,
  1669. TIMEOFFSET_MIN_HOURS,
  1670. TIMEOFFSET_MAX_HOURS),
  1671. 'relativeDates' => new _UserPreference_bool(),
  1672. 'googleLink' => new _UserPreference_bool(), // 1.3.10
  1673. 'doubleClickEdit' => new _UserPreference_bool(), // 1.3.11
  1674. );
  1675. // add custom theme-specific pref types:
  1676. // FIXME: on theme changes the wiki_user session pref object will fail.
  1677. // We will silently ignore this.
  1678. if (!empty($customUserPreferenceColumns))
  1679. $this->_prefs = array_merge($this->_prefs, $customUserPreferenceColumns);
  1680. /*
  1681. if (isset($this->_method) and $this->_method == 'SQL') {
  1682. //unset($this->_prefs['userid']);
  1683. unset($this->_prefs['passwd']);
  1684. }
  1685. */
  1686. if (is_array($saved_prefs)) {
  1687. foreach ($saved_prefs as $name => $value)
  1688. $this->set($name, $value);
  1689. }
  1690. }
  1691. function _getPref($name) {
  1692. if ($name == 'emailVerified')
  1693. $name = 'email';
  1694. if (!isset($this->_prefs[$name])) {
  1695. if ($name == 'passwd2') return false;
  1696. if ($name == 'passwd') return false;
  1697. trigger_error("$name: unknown preference", E_USER_NOTICE);
  1698. return false;
  1699. }
  1700. return $this->_prefs[$name];
  1701. }
  1702. // get the value or default_value of the subobject
  1703. function get($name) {
  1704. if ($_pref = $this->_getPref($name))
  1705. if ($name == 'emailVerified')
  1706. return $_pref->getraw($name);
  1707. else
  1708. return $_pref->get($name);
  1709. else
  1710. return false;
  1711. }
  1712. // check and set the new value in the subobject
  1713. function set($name, $value) {
  1714. $pref = $this->_getPref($name);
  1715. if ($pref === false)
  1716. return false;
  1717. /* do it here or outside? */
  1718. if ($name == 'passwd' and
  1719. defined('PASSWORD_LENGTH_MINIMUM') and
  1720. strlen($value) <= PASSWORD_LENGTH_MINIMUM ) {
  1721. //TODO: How to notify the user?
  1722. return false;
  1723. }
  1724. /*
  1725. if ($name == 'theme' and $value == '')
  1726. return true;
  1727. */
  1728. // Fix Fatal error for undefined value. Thanks to Jim Ford and Joel Schaubert
  1729. if ((!$value and $pref->default_value)
  1730. or ($value and !isset($pref->{$name})) // bug #1355533
  1731. or ($value and ($pref->{$name} != $pref->default_value)))
  1732. {
  1733. if ($name == 'emailVerified') $newvalue = $value;
  1734. else $newvalue = $pref->sanify($value);
  1735. $pref->set($name, $newvalue);
  1736. }
  1737. $this->_prefs[$name] =& $pref;
  1738. return true;
  1739. }
  1740. /**
  1741. * use init to avoid update on set
  1742. */
  1743. function updatePrefs($prefs, $init = false) {
  1744. $count = 0;
  1745. if ($init) $this->_init = $init;
  1746. if (is_object($prefs)) {
  1747. $type = 'emailVerified'; $obj =& $this->_prefs['email'];
  1748. $obj->_init = $init;
  1749. if ($obj->get($type) !== $prefs->get($type)) {
  1750. if ($obj->set($type, $prefs->get($type)))
  1751. $count++;
  1752. }
  1753. foreach (array_keys($this->_prefs) as $type) {
  1754. $obj =& $this->_prefs[$type];
  1755. $obj->_init = $init;
  1756. if ($prefs->get($type) !== $obj->get($type)) {
  1757. // special systemdefault prefs: (probably not needed)
  1758. if ($type == 'theme' and $prefs->get($type) == '' and
  1759. $obj->get($type) == THEME) continue;
  1760. if ($type == 'lang' and $prefs->get($type) == '' and
  1761. $obj->get($type) == DEFAULT_LANGUAGE) continue;
  1762. if ($this->_prefs[$type]->set($type, $prefs->get($type)))
  1763. $count++;
  1764. }
  1765. }
  1766. } elseif (is_array($prefs)) {
  1767. //unset($this->_prefs['userid']);
  1768. /*
  1769. if (isset($this->_method) and
  1770. ($this->_method == 'SQL' or $this->_method == 'ADODB')) {
  1771. unset($this->_prefs['passwd']);
  1772. }
  1773. */
  1774. // emailVerified at first, the rest later
  1775. $type = 'emailVerified'; $obj =& $this->_prefs['email'];
  1776. $obj->_init = $init;
  1777. if (isset($prefs[$type]) and $obj->get($type) !== $prefs[$type]) {
  1778. if ($obj->set($type,$prefs[$type]))
  1779. $count++;
  1780. }
  1781. foreach (array_keys($this->_prefs) as $type) {
  1782. $obj =& $this->_prefs[$type];
  1783. $obj->_init = $init;
  1784. if (!isset($prefs[$type]) and isa($obj,"_UserPreference_bool"))
  1785. $prefs[$type] = false;
  1786. if (isset($prefs[$type]) and isa($obj,"_UserPreference_int"))
  1787. $prefs[$type] = (int) $prefs[$type];
  1788. if (isset($prefs[$type]) and $obj->get($type) != $prefs[$type]) {
  1789. // special systemdefault prefs:
  1790. if ($type == 'theme' and $prefs[$type] == '' and
  1791. $obj->get($type) == THEME) continue;
  1792. if ($type == 'lang' and $prefs[$type] == '' and
  1793. $obj->get($type) == DEFAULT_LANGUAGE) continue;
  1794. if ($obj->set($type,$prefs[$type]))
  1795. $count++;
  1796. }
  1797. }
  1798. }
  1799. return $count;
  1800. }
  1801. // For now convert just array of objects => array of values
  1802. // Todo: the specialized subobjects must override this.
  1803. function store() {
  1804. $prefs = array();
  1805. foreach ($this->_prefs as $name => $object) {
  1806. if ($value = $object->getraw($name))
  1807. $prefs[$name] = $value;
  1808. if ($name == 'email' and ($value = $object->getraw('emailVerified')))
  1809. $prefs['emailVerified'] = $value;
  1810. if ($name == 'passwd' and $value and ENCRYPTED_PASSWD) {
  1811. if (strlen($value) != strlen(crypt('test')))
  1812. $prefs['passwd'] = crypt($value);
  1813. else // already crypted
  1814. $prefs['passwd'] = $value;
  1815. }
  1816. }
  1817. return $this->pack($prefs);
  1818. }
  1819. // packed string or array of values => array of values
  1820. // Todo: the specialized subobjects must override this.
  1821. function retrieve($packed) {
  1822. if (is_string($packed) and (substr($packed, 0, 2) == "a:"))
  1823. $packed = unserialize($packed);
  1824. if (!is_array($packed)) return false;
  1825. $prefs = array();
  1826. foreach ($packed as $name => $packed_pref) {
  1827. if (is_string($packed_pref) and substr($packed_pref, 0, 2) == "O:") {
  1828. //legacy: check if it's an old array of objects
  1829. // Looks like a serialized object.
  1830. // This might fail if the object definition does not exist anymore.
  1831. // object with ->$name and ->default_value vars.
  1832. $pref = @unserialize($packed_pref);
  1833. if (empty($pref))
  1834. $pref = @unserialize(base64_decode($packed_pref));
  1835. $prefs[$name] = $pref->get($name);
  1836. // fix old-style prefs
  1837. } elseif (is_numeric($name) and is_array($packed_pref)) {
  1838. if (count($packed_pref) == 1) {
  1839. list($name,$value) = each($packed_pref);
  1840. $prefs[$name] = $value;
  1841. }
  1842. } else {
  1843. $prefs[$name] = @unserialize($packed_pref);
  1844. if (empty($prefs[$name]))
  1845. $prefs[$name] = @unserialize(base64_decode($packed_pref));
  1846. // patched by frederik@pandora.be
  1847. if (empty($prefs[$name]))
  1848. $prefs[$name] = $packed_pref;
  1849. }
  1850. }
  1851. return $prefs;
  1852. }
  1853. /**
  1854. * Check if the given prefs object is different from the current prefs object
  1855. */
  1856. function isChanged($other) {
  1857. foreach ($this->_prefs as $type => $obj) {
  1858. if ($obj->get($type) !== $other->get($type))
  1859. return true;
  1860. }
  1861. return false;
  1862. }
  1863. function defaultPreferences() {
  1864. $prefs = array();
  1865. foreach ($this->_prefs as $key => $obj) {
  1866. $prefs[$key] = $obj->default_value;
  1867. }
  1868. return $prefs;
  1869. }
  1870. // array of objects
  1871. function getAll() {
  1872. return $this->_prefs;
  1873. }
  1874. function pack($nonpacked) {
  1875. return serialize($nonpacked);
  1876. }
  1877. function unpack($packed) {
  1878. if (!$packed)
  1879. return false;
  1880. //$packed = base64_decode($packed);
  1881. if (substr($packed, 0, 2) == "O:") {
  1882. // Looks like a serialized object
  1883. return unserialize($packed);
  1884. }
  1885. if (substr($packed, 0, 2) == "a:") {
  1886. return unserialize($packed);
  1887. }
  1888. //trigger_error("DEBUG: Can't unpack bad UserPreferences",
  1889. //E_USER_WARNING);
  1890. return false;
  1891. }
  1892. function hash () {
  1893. return wikihash($this->_prefs);
  1894. }
  1895. }
  1896. /** TODO: new pref storage classes
  1897. * These are currently user specific and should be rewritten to be pref specific.
  1898. * i.e. $this == $user->_prefs
  1899. */
  1900. /*
  1901. class CookieUserPreferences
  1902. extends UserPreferences
  1903. {
  1904. function CookieUserPreferences ($saved_prefs = false) {
  1905. //_AnonUser::_AnonUser('',$saved_prefs);
  1906. UserPreferences::UserPreferences($saved_prefs);
  1907. }
  1908. }
  1909. class PageUserPreferences
  1910. extends UserPreferences
  1911. {
  1912. function PageUserPreferences ($saved_prefs = false) {
  1913. UserPreferences::UserPreferences($saved_prefs);
  1914. }
  1915. }
  1916. class PearDbUserPreferences
  1917. extends UserPreferences
  1918. {
  1919. function PearDbUserPreferences ($saved_prefs = false) {
  1920. UserPreferences::UserPreferences($saved_prefs);
  1921. }
  1922. }
  1923. class AdoDbUserPreferences
  1924. extends UserPreferences
  1925. {
  1926. function AdoDbUserPreferences ($saved_prefs = false) {
  1927. UserPreferences::UserPreferences($saved_prefs);
  1928. }
  1929. function getPreferences() {
  1930. // override the generic slow method here for efficiency
  1931. _AnonUser::getPreferences();
  1932. $this->getAuthDbh();
  1933. if (isset($this->_select)) {
  1934. $dbh = & $this->_auth_dbi;
  1935. $rs = $dbh->Execute(sprintf($this->_select,$dbh->qstr($this->_userid)));
  1936. if ($rs->EOF) {
  1937. $rs->Close();
  1938. } else {
  1939. $prefs_blob = $rs->fields['pref_blob'];
  1940. $rs->Close();
  1941. if ($restored_from_db = $this->_prefs->retrieve($prefs_blob)) {
  1942. $updated = $this->_prefs->updatePrefs($restored_from_db);
  1943. //$this->_prefs = new UserPreferences($restored_from_db);
  1944. return $this->_prefs;
  1945. }
  1946. }
  1947. }
  1948. if (empty($this->_prefs->_prefs) and $this->_HomePagehandle) {
  1949. if ($restored_from_page = $this->_prefs->retrieve
  1950. ($this->_HomePagehandle->get('pref'))) {
  1951. $updated = $this->_prefs->updatePrefs($restored_from_page);
  1952. //$this->_prefs = new UserPreferences($restored_from_page);
  1953. return $this->_prefs;
  1954. }
  1955. }
  1956. return $this->_prefs;
  1957. }
  1958. }
  1959. */
  1960. // $Log: WikiUserNew.php,v $
  1961. // Revision 1.137 2006/05/03 06:05:37 rurban
  1962. // Fix default preferences for editheight maxrows, by Manuel Vacelet.
  1963. //
  1964. // Revision 1.136 2006/04/16 11:07:48 rurban
  1965. // Dont crypt the passwd twice on storing prefs. Patch by Thomas Harding.
  1966. // Fixes bug #1327470
  1967. //
  1968. // Revision 1.135 2006/03/19 16:26:39 rurban
  1969. // fix DBAUTH arguments to be position independent, fixes bug #1358973
  1970. //
  1971. // Revision 1.134 2006/03/19 15:01:00 rurban
  1972. // sf.net patch #1333957 by Matt Brown: Authentication cookie identical across all wikis on a host
  1973. //
  1974. // Revision 1.133 2006/03/07 18:39:21 rurban
  1975. // add PdoDb, rename hash to wikihash (php-5.1), fix output of Homepage prefs update
  1976. //
  1977. // Revision 1.132 2006/03/04 13:19:12 rurban
  1978. // fix for fatal error on empty pref value (sign out). Thanks to Jim Ford and Joel Schaubert. rename hash for php-5.1
  1979. //
  1980. // Revision 1.131 2005/10/12 06:16:48 rurban
  1981. // add new _insert statement
  1982. //
  1983. // Revision 1.129 2005/06/10 06:10:35 rurban
  1984. // ensure Update Preferences gets through
  1985. //
  1986. // Revision 1.128 2005/06/05 05:38:02 rurban
  1987. // Default ENABLE_DOUBLECLICKEDIT = false. Moved to UserPreferences
  1988. //
  1989. // Revision 1.127 2005/04/02 18:01:41 uckelman
  1990. // Fixed regex for RFC822 addresses.
  1991. //
  1992. // Revision 1.126 2005/02/28 20:30:46 rurban
  1993. // some stupid code for _AdminUser (probably not needed)
  1994. //
  1995. // Revision 1.125 2005/02/08 13:25:50 rurban
  1996. // encrypt password. fix strict logic.
  1997. // both bugs reported by Mikhail Vladimirov
  1998. //
  1999. // Revision 1.124 2005/01/30 23:11:00 rurban
  2000. // allow self-creating passuser on login
  2001. //
  2002. // Revision 1.123 2005/01/25 06:58:21 rurban
  2003. // reformatting
  2004. //
  2005. // Revision 1.122 2005/01/08 22:51:56 rurban
  2006. // remove deprecated workaround
  2007. //
  2008. // Revision 1.121 2004/12/19 00:58:01 rurban
  2009. // Enforce PASSWORD_LENGTH_MINIMUM in almost all PassUser checks,
  2010. // Provide an errormessage if so. Just PersonalPage and BogoLogin not.
  2011. // Simplify httpauth logout handling and set sessions for all methods.
  2012. // fix main.php unknown index "x" getLevelDescription() warning.
  2013. //
  2014. // Revision 1.120 2004/12/17 12:31:57 rurban
  2015. // better logout, fake httpauth not yet
  2016. //
  2017. // Revision 1.119 2004/11/21 11:59:17 rurban
  2018. // remove final \n to be ob_cache independent
  2019. //
  2020. // Revision 1.118 2004/11/19 19:22:03 rurban
  2021. // ModeratePage part1: change status
  2022. //
  2023. // Revision 1.117 2004/11/10 15:29:21 rurban
  2024. // * requires newer Pear_DB (as the internal one): quote() uses now escapeSimple for strings
  2025. // * ACCESS_LOG_SQL: fix cause request not yet initialized
  2026. // * WikiDB: moved SQL specific methods upwards
  2027. // * new Pear_DB quoting: same as ADODB and as newer Pear_DB.
  2028. // fixes all around: WikiGroup, WikiUserNew SQL methods, SQL logging
  2029. //
  2030. // Revision 1.116 2004/11/05 21:03:27 rurban
  2031. // new DEBUG flag: _DEBUG_LOGIN (64)
  2032. // verbose login debug-msg (settings and reason for failure)
  2033. //
  2034. // Revision 1.115 2004/11/05 20:53:35 rurban
  2035. // login cleanup: better debug msg on failing login,
  2036. // checked password less immediate login (bogo or anon),
  2037. // checked olduser pref session error,
  2038. // better PersonalPage without password warning on minimal password length=0
  2039. // (which is default now)
  2040. //
  2041. // Revision 1.114 2004/11/05 16:15:57 rurban
  2042. // forgot the BogoLogin inclusion with the latest rewrite
  2043. //
  2044. // Revision 1.113 2004/11/03 17:13:49 rurban
  2045. // make it easier to disable EmailVerification
  2046. // Bug #1053681
  2047. //
  2048. // Revision 1.112 2004/11/01 10:43:57 rurban
  2049. // seperate PassUser methods into seperate dir (memory usage)
  2050. // fix WikiUser (old) overlarge data session
  2051. // remove wikidb arg from various page class methods, use global ->_dbi instead
  2052. // ...
  2053. //
  2054. // Revision 1.111 2004/10/21 21:03:50 rurban
  2055. // isAdmin must be signed and authenticated
  2056. // comment out unused sections (memory)
  2057. //
  2058. // Revision 1.110 2004/10/14 19:19:33 rurban
  2059. // loadsave: check if the dumped file will be accessible from outside.
  2060. // and some other minor fixes. (cvsclient native not yet ready)
  2061. //
  2062. // Revision 1.109 2004/10/07 16:08:58 rurban
  2063. // fixed broken FileUser session handling.
  2064. // thanks to Arnaud Fontaine for detecting this.
  2065. // enable file user Administrator membership.
  2066. //
  2067. // Revision 1.108 2004/10/05 17:00:04 rurban
  2068. // support paging for simple lists
  2069. // fix RatingDb sql backend.
  2070. // remove pages from AllPages (this is ListPages then)
  2071. //
  2072. // Revision 1.107 2004/10/04 23:42:15 rurban
  2073. // HttpAuth admin group logic. removed old logs
  2074. //
  2075. // Revision 1.106 2004/07/01 08:49:38 rurban
  2076. // obsolete php5-patch.php: minor php5 login problem though
  2077. //
  2078. // Revision 1.105 2004/06/29 06:48:03 rurban
  2079. // Improve LDAP auth and GROUP_LDAP membership:
  2080. // no error message on false password,
  2081. // added two new config vars: LDAP_OU_USERS and LDAP_OU_GROUP with GROUP_METHOD=LDAP
  2082. // fixed two group queries (this -> user)
  2083. // stdlib: ConvertOldMarkup still flawed
  2084. //
  2085. // Revision 1.104 2004/06/28 15:39:37 rurban
  2086. // fixed endless recursion in WikiGroup: isAdmin()
  2087. //
  2088. // Revision 1.103 2004/06/28 15:01:07 rurban
  2089. // fixed LDAP_SET_OPTION handling, LDAP error on connection problem
  2090. //
  2091. // Revision 1.102 2004/06/27 10:23:48 rurban
  2092. // typo detected by Philippe Vanhaesendonck
  2093. //
  2094. // Revision 1.101 2004/06/25 14:29:19 rurban
  2095. // WikiGroup refactoring:
  2096. // global group attached to user, code for not_current user.
  2097. // improved helpers for special groups (avoid double invocations)
  2098. // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
  2099. // fixed a XHTML validation error on userprefs.tmpl
  2100. //
  2101. // Revision 1.100 2004/06/21 06:29:35 rurban
  2102. // formatting: linewrap only
  2103. //
  2104. // Revision 1.99 2004/06/20 15:30:05 rurban
  2105. // get_class case-sensitivity issues
  2106. //
  2107. // Revision 1.98 2004/06/16 21:24:31 rurban
  2108. // do not display no-connect warning: #2662
  2109. //
  2110. // Revision 1.97 2004/06/16 13:21:16 rurban
  2111. // stabilize on failing ldap queries or bind
  2112. //
  2113. // Revision 1.96 2004/06/16 12:42:06 rurban
  2114. // fix homepage prefs
  2115. //
  2116. // Revision 1.95 2004/06/16 10:38:58 rurban
  2117. // Disallow refernces in calls if the declaration is a reference
  2118. // ("allow_call_time_pass_reference clean").
  2119. // PhpWiki is now allow_call_time_pass_reference = Off clean,
  2120. // but several external libraries may not.
  2121. // In detail these libs look to be affected (not tested):
  2122. // * Pear_DB odbc
  2123. // * adodb oracle
  2124. //
  2125. // Revision 1.94 2004/06/15 10:40:35 rurban
  2126. // minor WikiGroup cleanup: no request param, start of current user independency
  2127. //
  2128. // Revision 1.93 2004/06/15 09:15:52 rurban
  2129. // IMPORTANT: fixed passwd handling for passwords stored in prefs:
  2130. // fix encrypted usage, actually store and retrieve them from db
  2131. // fix bogologin with passwd set.
  2132. // fix php crashes with call-time pass-by-reference (references wrongly used
  2133. // in declaration AND call). This affected mainly Apache2 and IIS.
  2134. // (Thanks to John Cole to detect this!)
  2135. //
  2136. // Revision 1.92 2004/06/14 11:31:36 rurban
  2137. // renamed global $Theme to $WikiTheme (gforge nameclash)
  2138. // inherit PageList default options from PageList
  2139. // default sortby=pagename
  2140. // use options in PageList_Selectable (limit, sortby, ...)
  2141. // added action revert, with button at action=diff
  2142. // added option regex to WikiAdminSearchReplace
  2143. //
  2144. // Revision 1.91 2004/06/08 14:57:43 rurban
  2145. // stupid ldap bug detected by John Cole
  2146. //
  2147. // Revision 1.90 2004/06/08 09:31:15 rurban
  2148. // fixed typo detected by lucidcarbon (line 1663 assertion)
  2149. //
  2150. // Revision 1.89 2004/06/06 16:58:51 rurban
  2151. // added more required ActionPages for foreign languages
  2152. // install now english ActionPages if no localized are found. (again)
  2153. // fixed default anon user level to be 0, instead of -1
  2154. // (wrong "required administrator to view this page"...)
  2155. //
  2156. // Revision 1.88 2004/06/04 20:32:53 rurban
  2157. // Several locale related improvements suggested by Pierrick Meignen
  2158. // LDAP fix by John Cole
  2159. // reanable admin check without ENABLE_PAGEPERM in the admin plugins
  2160. //
  2161. // Revision 1.87 2004/06/04 12:40:21 rurban
  2162. // Restrict valid usernames to prevent from attacks against external auth or compromise
  2163. // possible holes.
  2164. // Fix various WikiUser old issues with default IMAP,LDAP,POP3 configs. Removed these.
  2165. // Fxied more warnings
  2166. //
  2167. // Revision 1.86 2004/06/03 18:06:29 rurban
  2168. // fix file locking issues (only needed on write)
  2169. // fixed immediate LANG and THEME in-session updates if not stored in prefs
  2170. // advanced editpage toolbars (search & replace broken)
  2171. //
  2172. // Revision 1.85 2004/06/03 12:46:03 rurban
  2173. // fix signout, level must be 0 not -1
  2174. //
  2175. // Revision 1.84 2004/06/03 12:36:03 rurban
  2176. // fix eval warning on signin
  2177. //
  2178. // Revision 1.83 2004/06/03 10:18:19 rurban
  2179. // fix User locking issues, new config ENABLE_PAGEPERM
  2180. //
  2181. // Revision 1.82 2004/06/03 09:39:51 rurban
  2182. // fix LDAP injection (wildcard in username) detected by Steve Christey, MITRE
  2183. //
  2184. // Revision 1.81 2004/06/02 18:01:45 rurban
  2185. // init global FileFinder to add proper include paths at startup
  2186. // adds PHPWIKI_DIR if started from another dir, lib/pear also
  2187. // fix slashify for Windows
  2188. // fix USER_AUTH_POLICY=old, use only USER_AUTH_ORDER methods (besides HttpAuth)
  2189. //
  2190. // Revision 1.80 2004/06/02 14:20:27 rurban
  2191. // fix adodb DbPassUser login
  2192. //
  2193. // Revision 1.79 2004/06/01 15:27:59 rurban
  2194. // AdminUser only ADMIN_USER not member of Administrators
  2195. // some RateIt improvements by dfrankow
  2196. // edit_toolbar buttons
  2197. //
  2198. // Revision 1.78 2004/05/27 17:49:06 rurban
  2199. // renamed DB_Session to DbSession (in CVS also)
  2200. // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
  2201. // remove leading slash in error message
  2202. // added force_unlock parameter to File_Passwd (no return on stale locks)
  2203. // fixed adodb session AffectedRows
  2204. // added FileFinder helpers to unify local filenames and DATA_PATH names
  2205. // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
  2206. //
  2207. // Revision 1.77 2004/05/18 14:49:51 rurban
  2208. // Simplified strings for easier translation
  2209. //
  2210. // Revision 1.76 2004/05/18 13:30:04 rurban
  2211. // prevent from endless loop with oldstyle warnings
  2212. //
  2213. // Revision 1.75 2004/05/16 22:07:35 rurban
  2214. // check more config-default and predefined constants
  2215. // various PagePerm fixes:
  2216. // fix default PagePerms, esp. edit and view for Bogo and Password users
  2217. // implemented Creator and Owner
  2218. // BOGOUSERS renamed to BOGOUSER
  2219. // fixed syntax errors in signin.tmpl
  2220. //
  2221. // Revision 1.74 2004/05/15 19:48:33 rurban
  2222. // fix some too loose PagePerms for signed, but not authenticated users
  2223. // (admin, owner, creator)
  2224. // no double login page header, better login msg.
  2225. // moved action_pdf to lib/pdf.php
  2226. //
  2227. // Revision 1.73 2004/05/15 18:31:01 rurban
  2228. // some action=pdf Request fixes: With MSIE it works now. Now the work with the page formatting begins.
  2229. //
  2230. // Revision 1.72 2004/05/12 10:49:55 rurban
  2231. // require_once fix for those libs which are loaded before FileFinder and
  2232. // its automatic include_path fix, and where require_once doesn't grok
  2233. // dirname(__FILE__) != './lib'
  2234. // upgrade fix with PearDB
  2235. // navbar.tmpl: remove spaces for IE &nbsp; button alignment
  2236. //
  2237. // Revision 1.71 2004/05/10 12:34:47 rurban
  2238. // stabilize DbAuthParam statement pre-prozessor:
  2239. // try old-style and new-style (double-)quoting
  2240. // reject unknown $variables
  2241. // use ->prepare() for all calls (again)
  2242. //
  2243. // Revision 1.70 2004/05/06 19:26:16 rurban
  2244. // improve stability, trying to find the InlineParser endless loop on sf.net
  2245. //
  2246. // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
  2247. //
  2248. // Revision 1.69 2004/05/06 13:56:40 rurban
  2249. // Enable the Administrators group, and add the WIKIPAGE group default root page.
  2250. //
  2251. // Revision 1.68 2004/05/05 13:37:54 rurban
  2252. // Support to remove all UserPreferences
  2253. //
  2254. // Revision 1.66 2004/05/03 21:44:24 rurban
  2255. // fixed sf,net bug #947264: LDAP options are constants, not strings!
  2256. //
  2257. // Revision 1.65 2004/05/03 13:16:47 rurban
  2258. // fixed UserPreferences update, esp for boolean and int
  2259. //
  2260. // Revision 1.64 2004/05/02 15:10:06 rurban
  2261. // new finally reliable way to detect if /index.php is called directly
  2262. // and if to include lib/main.php
  2263. // new global AllActionPages
  2264. // SetupWiki now loads all mandatory pages: HOME_PAGE, action pages, and warns if not.
  2265. // WikiTranslation what=buttons for Carsten to create the missing MacOSX buttons
  2266. // PageGroupTestOne => subpages
  2267. // renamed PhpWikiRss to PhpWikiRecentChanges
  2268. // more docs, default configs, ...
  2269. //
  2270. // Revision 1.63 2004/05/01 15:59:29 rurban
  2271. // more php-4.0.6 compatibility: superglobals
  2272. //
  2273. // Revision 1.62 2004/04/29 18:31:24 rurban
  2274. // Prevent from warning where no db pref was previously stored.
  2275. //
  2276. // Revision 1.61 2004/04/29 17:18:19 zorloc
  2277. // 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.
  2278. //
  2279. // Revision 1.60 2004/04/27 18:20:54 rurban
  2280. // sf.net patch #940359 by rassie
  2281. //
  2282. // Revision 1.59 2004/04/26 12:35:21 rurban
  2283. // POP3_AUTH_PORT deprecated, use "host:port" similar to IMAP
  2284. // File_Passwd is already loaded
  2285. //
  2286. // Revision 1.58 2004/04/20 17:08:28 rurban
  2287. // Some IniConfig fixes: prepend our private lib/pear dir
  2288. // switch from " to ' in the auth statements
  2289. // use error handling.
  2290. // WikiUserNew changes for the new "'$variable'" syntax
  2291. // in the statements
  2292. // TODO: optimization to put config vars into the session.
  2293. //
  2294. // Revision 1.57 2004/04/19 18:27:45 rurban
  2295. // Prevent from some PHP5 warnings (ref args, no :: object init)
  2296. // php5 runs now through, just one wrong XmlElement object init missing
  2297. // Removed unneccesary UpgradeUser lines
  2298. // Changed WikiLink to omit version if current (RecentChanges)
  2299. //
  2300. // Revision 1.56 2004/04/19 09:13:24 rurban
  2301. // new pref: googleLink
  2302. //
  2303. // Revision 1.54 2004/04/18 00:24:45 rurban
  2304. // re-use our simple prepare: just for table prefix warnings
  2305. //
  2306. // Revision 1.53 2004/04/12 18:29:15 rurban
  2307. // exp. Session auth for already authenticated users from another app
  2308. //
  2309. // Revision 1.52 2004/04/12 13:04:50 rurban
  2310. // added auth_create: self-registering Db users
  2311. // fixed IMAP auth
  2312. // removed rating recommendations
  2313. // ziplib reformatting
  2314. //
  2315. // Revision 1.51 2004/04/11 10:42:02 rurban
  2316. // pgsrc/CreatePagePlugin
  2317. //
  2318. // Revision 1.50 2004/04/10 05:34:35 rurban
  2319. // sf bug#830912
  2320. //
  2321. // Revision 1.49 2004/04/07 23:13:18 rurban
  2322. // fixed pear/File_Passwd for Windows
  2323. // fixed FilePassUser sessions (filehandle revive) and password update
  2324. //
  2325. // Revision 1.48 2004/04/06 20:00:10 rurban
  2326. // Cleanup of special PageList column types
  2327. // Added support of plugin and theme specific Pagelist Types
  2328. // Added support for theme specific UserPreferences
  2329. // Added session support for ip-based throttling
  2330. // sql table schema change: ALTER TABLE session ADD sess_ip CHAR(15);
  2331. // Enhanced postgres schema
  2332. // Added DB_Session_dba support
  2333. //
  2334. // Revision 1.47 2004/04/02 15:06:55 rurban
  2335. // fixed a nasty ADODB_mysql session update bug
  2336. // improved UserPreferences layout (tabled hints)
  2337. // fixed UserPreferences auth handling
  2338. // improved auth stability
  2339. // improved old cookie handling: fixed deletion of old cookies with paths
  2340. //
  2341. // Revision 1.46 2004/04/01 06:29:51 rurban
  2342. // better wording
  2343. // RateIt also for ADODB
  2344. //
  2345. // Local Variables:
  2346. // mode: php
  2347. // tab-width: 8
  2348. // c-basic-offset: 4
  2349. // c-hanging-comment-ender-p: nil
  2350. // indent-tabs-mode: nil
  2351. // End:
  2352. ?>