您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

login.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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$
  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. * token
  27. * lang
  28. */
  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. check_db_version(); # check if the database layout is up to date (and error out if not)
  35. if ($_SERVER['REQUEST_METHOD'] == "POST") {
  36. if (safepost('token') != $_SESSION['PFA_token']) {
  37. die('Invalid token!');
  38. }
  39. $lang = safepost('lang');
  40. $fUsername = trim(safepost('fUsername'));
  41. $fPassword = safepost('fPassword');
  42. if ($lang != check_language(0)) { # only set cookie if language selection was changed
  43. setcookie('lang', $lang, time() + 60*60*24*30); # language cookie, lifetime 30 days
  44. # (language preference cookie is processed even if username and/or password are invalid)
  45. }
  46. $h = new AdminHandler;
  47. if ($h->login($fUsername, $fPassword)) {
  48. init_session($fUsername, true);
  49. # they've logged in, so see if they are a domain admin, as well.
  50. if (!$h->init($fUsername)) {
  51. flash_error($PALANG['pLogin_failed']);
  52. }
  53. if (!$h->view()) {
  54. flash_error($PALANG['pLogin_failed']);
  55. }
  56. $adminproperties = $h->result();
  57. if ($adminproperties['superadmin'] == 1) {
  58. $_SESSION['sessid']['roles'][] = 'global-admin';
  59. }
  60. header("Location: main.php");
  61. exit(0);
  62. } else { # $h->login failed
  63. error_log("PostfixAdmin login failed (username: $fUsername, ip_address: {$_SERVER['REMOTE_ADDR']})");
  64. flash_error($PALANG['pLogin_failed']);
  65. }
  66. }
  67. session_unset();
  68. session_destroy();
  69. session_start();
  70. $_SESSION['PFA_token'] = md5(uniqid(rand(), true));
  71. $smarty->assign('language_selector', language_selector(), false);
  72. $smarty->assign('smarty_template', 'login');
  73. $smarty->assign('logintype', 'admin');
  74. $smarty->assign('forgotten_password_reset', Config::read('forgotten_admin_password_reset'));
  75. $smarty->display('index.tpl');
  76. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */