Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

login.php 2.5KB

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