login.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * Authenticates a user, and populates their $_SESSION as appropriate.
  16. * Template File: login.tpl
  17. *
  18. * Template Variables:
  19. *
  20. * none
  21. *
  22. * Form POST \ GET Variables:
  23. *
  24. * fUsername
  25. * fPassword
  26. * lang
  27. */
  28. define('POSTFIXADMIN_LOGOUT', 1);
  29. require_once('common.php');
  30. if($CONF['configured'] !== true) {
  31. print "Installation not yet configured; please edit config.inc.php or write your settings to config.local.php";
  32. exit;
  33. }
  34. if ($_SERVER['REQUEST_METHOD'] == "POST")
  35. {
  36. $lang = safepost('lang');
  37. $fUsername = trim(safepost('fUsername'));
  38. $fPassword = safepost('fPassword');
  39. if ( $lang != check_language(0) ) { # only set cookie if language selection was changed
  40. setcookie('lang', $lang, time() + 60*60*24*30); # language cookie, lifetime 30 days
  41. # (language preference cookie is processed even if username and/or password are invalid)
  42. }
  43. $h = new AdminHandler;
  44. if ( $h->login($fUsername, $fPassword) ) {
  45. session_regenerate_id();
  46. $_SESSION['sessid'] = array();
  47. $_SESSION['sessid']['roles'] = array();
  48. $_SESSION['sessid']['roles'][] = 'admin';
  49. $_SESSION['sessid']['username'] = $fUsername;
  50. $_SESSION['PFA_token'] = md5(uniqid(rand(), true));
  51. # they've logged in, so see if they are a domain admin, as well.
  52. if (!$h->init($fUsername)) {
  53. flash_error($PALANG['pLogin_failed']);
  54. }
  55. if (!$h->view()) {
  56. flash_error($PALANG['pLogin_failed']);
  57. }
  58. $adminproperties = $h->result();
  59. if ($adminproperties['superadmin'] == 1) {
  60. $_SESSION['sessid']['roles'][] = 'global-admin';
  61. }
  62. header("Location: main.php");
  63. exit(0);
  64. } else { # $h->login failed
  65. error_log("PostfixAdmin login failed (username: $fUsername)");
  66. flash_error($PALANG['pLogin_failed']);
  67. }
  68. }
  69. $smarty->assign ('language_selector', language_selector(), false);
  70. $smarty->assign ('smarty_template', 'login');
  71. $smarty->assign ('logintype', 'admin');
  72. $smarty->display ('index.tpl');
  73. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
  74. ?>