sessionauth.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php if (!defined('PmWiki')) exit();
  2. /* Copyright 2002-2003 Patrick R. Michaud (pmichaud@pobox.com)
  3. This file is part of PmWiki; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published
  5. by the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version. See pmwiki.php for full details.
  7. */
  8. session_start();
  9. $AuthFunction = 'SessionAuth';
  10. if (@$_POST['authpw'])
  11. $_SESSION['authpw'] = $_POST['authpw'];
  12. SDV($SessionAuthFmt,"<b>Password required</b><p>
  13. <form name='authform' action='{$_SERVER['REQUEST_URI']}'
  14. method='post'>Password:
  15. <input tabindex='1' type='password' name='authpw' value='' />
  16. <input type='submit' value='OK' />
  17. </form>");
  18. function SessionAuth($pagename,$level,$authprompt=true) {
  19. global $GroupAttributesFmt,$DefaultPasswords,
  20. $AllowPassword,$HTMLBodyFmt,$SessionAuthFmt;
  21. $page = ReadPage($pagename);
  22. if (!$page) { return false; }
  23. @$passwd = $page["passwd$level"];
  24. if ($passwd=="") {
  25. $grouppg = ReadPage(FmtPageName($GroupAttributesFmt,$pagename));
  26. @$passwd = $grouppg["passwd$level"];
  27. }
  28. if (crypt($AllowPassword,$passwd)==$passwd) return $page;
  29. if ($passwd=="") { $passwd=@$DefaultPasswords[$level]; }
  30. if ($passwd=="") return $page;
  31. $authpw = $_SESSION['authpw'];
  32. foreach(array_merge($DefaultPasswords['admin'],$passwd) as $pw)
  33. if (crypt($authpw,$pw)==$pw) return $page;
  34. if (!$authprompt) return false;
  35. $HTMLBodyFmt = str_replace('<body ',
  36. '<body onload="document.authform.authpw.focus()" ',$HTMLBodyFmt);
  37. $action = $GLOBALS['action'];
  38. StartHTML($pagename,"Authorization required");
  39. PrintFmt($pagename,$SessionAuthFmt);
  40. EndHTML();
  41. exit;
  42. }
  43. ?>