login.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Postfix Admin
  4. *
  5. * LICENSE
  6. * This source file is subject to the GPL license that is bundled with
  7. * this package in the file LICENSE.TXT.
  8. *
  9. * Further details on the project are available at http://postfixadmin.sf.net
  10. *
  11. * @version $Id: login.php 1665 2014-05-01 22:52:47Z christian_boltz $
  12. * @license GNU GPL v2 or later.
  13. *
  14. * File: login.php
  15. * Used to authenticate want-to-be users.
  16. * Template File: login.tpl
  17. *
  18. * Template Variables:
  19. *
  20. * tUsername
  21. *
  22. * Form POST \ GET Variables:
  23. *
  24. * fUsername
  25. * fPassword
  26. * lang
  27. */
  28. $rel_path = '../';
  29. define('POSTFIXADMIN_LOGOUT', 1);
  30. require_once("../common.php");
  31. if ($_SERVER['REQUEST_METHOD'] == "POST")
  32. {
  33. $lang = safepost('lang');
  34. $fUsername = trim(safepost('fUsername'));
  35. $fPassword = safepost('fPassword');
  36. if ( $lang != check_language(0) ) { # only set cookie if language selection was changed
  37. setcookie('lang', $lang, time() + 60*60*24*30); # language cookie, lifetime 30 days
  38. # (language preference cookie is processed even if username and/or password are invalid)
  39. }
  40. $h = new MailboxHandler();
  41. if($h->login($fUsername, $fPassword)) {
  42. session_regenerate_id();
  43. $_SESSION['sessid'] = array();
  44. $_SESSION['sessid']['roles'] = array();
  45. $_SESSION['sessid']['roles'][] = 'user';
  46. $_SESSION['sessid']['username'] = $fUsername;
  47. $_SESSION['PFA_token'] = md5(uniqid(rand(), true));
  48. header("Location: main.php");
  49. exit;
  50. } else {
  51. error_log("PostfixAdmin login failed (username: $fUsername)");
  52. flash_error($PALANG['pLogin_failed']);
  53. }
  54. }
  55. $smarty->assign ('language_selector', language_selector(), false);
  56. $smarty->assign ('smarty_template', 'login');
  57. $smarty->assign ('logintype', 'user');
  58. $smarty->display ('index.tpl');
  59. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  60. ?>