triggers.user.inc.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. // handle iam authentication
  3. if ($iam_provider){
  4. if (isset($_GET['iam_sso'])){
  5. // redirect for sso
  6. $redirect_uri = identity_provider('get-redirect');
  7. $redirect_uri = !empty($redirect_uri) ? $redirect_uri : '/';
  8. header('Location: ' . $redirect_uri);
  9. die();
  10. }
  11. if ($_SESSION['iam_token'] && $_SESSION['iam_refresh_token']) {
  12. // Session found, try to refresh
  13. $isRefreshed = identity_provider('refresh-token');
  14. if (!$isRefreshed){
  15. // Session could not be refreshed, redirect to provider
  16. $redirect_uri = identity_provider('get-redirect');
  17. $redirect_uri = !empty($redirect_uri) ? $redirect_uri : '/';
  18. header('Location: ' . $redirect_uri);
  19. die();
  20. }
  21. } elseif ($_GET['code'] && $_GET['state'] === $_SESSION['oauth2state']) {
  22. // Check given state against previously stored one to mitigate CSRF attack
  23. // Recieved access token in $_GET['code']
  24. // extract info and verify user
  25. identity_provider('verify-sso');
  26. }
  27. }
  28. if (isset($_POST["pw_reset_request"]) && !empty($_POST['username'])) {
  29. reset_password("issue", $_POST['username']);
  30. header("Location: /");
  31. exit;
  32. }
  33. if (isset($_POST["pw_reset"])) {
  34. $username = reset_password("check", $_POST['token']);
  35. $reset_result = reset_password("reset", array(
  36. 'new_password' => $_POST['new_password'],
  37. 'new_password2' => $_POST['new_password2'],
  38. 'token' => $_POST['token'],
  39. 'username' => $username,
  40. 'check_tfa' => True
  41. ));
  42. if ($reset_result){
  43. header("Location: /");
  44. exit;
  45. }
  46. }
  47. if (isset($_POST["verify_tfa_login"])) {
  48. if (verify_tfa_login($_SESSION['pending_mailcow_cc_username'], $_POST)) {
  49. if ($_SESSION['pending_mailcow_cc_role'] == "user") {
  50. if (isset($_SESSION['pending_pw_reset_token']) && isset($_SESSION['pending_pw_new_password'])) {
  51. reset_password("reset", array(
  52. 'new_password' => $_SESSION['pending_pw_new_password'],
  53. 'new_password2' => $_SESSION['pending_pw_new_password'],
  54. 'token' => $_SESSION['pending_pw_reset_token'],
  55. 'username' => $_SESSION['pending_mailcow_cc_username']
  56. ));
  57. unset($_SESSION['pending_pw_reset_token']);
  58. unset($_SESSION['pending_pw_new_password']);
  59. unset($_SESSION['pending_mailcow_cc_username']);
  60. unset($_SESSION['pending_tfa_methods']);
  61. header("Location: /");
  62. die();
  63. } else {
  64. set_user_loggedin_session($_SESSION['pending_mailcow_cc_username']);
  65. $user_details = mailbox("get", "mailbox_details", $_SESSION['mailcow_cc_username']);
  66. $is_dual = (!empty($_SESSION["dual-login"]["username"])) ? true : false;
  67. if (intval($user_details['attributes']['sogo_access']) == 1 && !$is_dual) {
  68. header("Location: /SOGo/so/{$_SESSION['mailcow_cc_username']}");
  69. die();
  70. } else {
  71. header("Location: /user");
  72. die();
  73. }
  74. }
  75. }
  76. }
  77. unset($_SESSION['pending_mailcow_cc_username']);
  78. unset($_SESSION['pending_mailcow_cc_role']);
  79. unset($_SESSION['pending_tfa_methods']);
  80. }
  81. if (isset($_GET["cancel_tfa_login"])) {
  82. unset($_SESSION['pending_pw_reset_token']);
  83. unset($_SESSION['pending_pw_new_password']);
  84. unset($_SESSION['pending_mailcow_cc_username']);
  85. unset($_SESSION['pending_mailcow_cc_role']);
  86. unset($_SESSION['pending_tfa_methods']);
  87. header("Location: /");
  88. }
  89. if (isset($_POST["login_user"]) && isset($_POST["pass_user"])) {
  90. $login_user = strtolower(trim($_POST["login_user"]));
  91. $as = check_login($login_user, $_POST["pass_user"], false, array("role" => "user"));
  92. if ($as == "user") {
  93. set_user_loggedin_session($login_user);
  94. $http_parameters = explode('&', $_SESSION['index_query_string']);
  95. unset($_SESSION['index_query_string']);
  96. if (in_array('mobileconfig', $http_parameters)) {
  97. if (in_array('only_email', $http_parameters)) {
  98. header("Location: /mobileconfig.php?only_email");
  99. die();
  100. }
  101. header("Location: /mobileconfig.php");
  102. die();
  103. }
  104. $user_details = mailbox("get", "mailbox_details", $login_user);
  105. $is_dual = (!empty($_SESSION["dual-login"]["username"])) ? true : false;
  106. if (intval($user_details['attributes']['sogo_access']) == 1 && !$is_dual) {
  107. header("Location: /SOGo/so/{$login_user}");
  108. die();
  109. } else {
  110. header("Location: /user");
  111. die();
  112. }
  113. }
  114. elseif ($as != "pending") {
  115. unset($_SESSION['pending_mailcow_cc_username']);
  116. unset($_SESSION['pending_mailcow_cc_role']);
  117. unset($_SESSION['pending_tfa_methods']);
  118. unset($_SESSION['mailcow_cc_username']);
  119. unset($_SESSION['mailcow_cc_role']);
  120. }
  121. }
  122. ?>