Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | <?php |
| 2 | if (isset($_POST["verify_tfa_login"])) { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 3 | if (verify_tfa_login($_SESSION['pending_mailcow_cc_username'], $_POST)) { |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 4 | $_SESSION['mailcow_cc_username'] = $_SESSION['pending_mailcow_cc_username']; |
| 5 | $_SESSION['mailcow_cc_role'] = $_SESSION['pending_mailcow_cc_role']; |
| 6 | unset($_SESSION['pending_mailcow_cc_username']); |
| 7 | unset($_SESSION['pending_mailcow_cc_role']); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 8 | unset($_SESSION['pending_tfa_methods']); |
| 9 | |
| 10 | header("Location: /user"); |
| 11 | } else { |
| 12 | unset($_SESSION['pending_mailcow_cc_username']); |
| 13 | unset($_SESSION['pending_mailcow_cc_role']); |
| 14 | unset($_SESSION['pending_tfa_methods']); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 15 | } |
| 16 | } |
| 17 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 18 | if (isset($_GET["cancel_tfa_login"])) { |
| 19 | unset($_SESSION['pending_mailcow_cc_username']); |
| 20 | unset($_SESSION['pending_mailcow_cc_role']); |
| 21 | unset($_SESSION['pending_tfa_methods']); |
| 22 | |
| 23 | header("Location: /"); |
| 24 | } |
| 25 | |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 26 | if (isset($_POST["quick_release"])) { |
| 27 | quarantine('quick_release', $_POST["quick_release"]); |
| 28 | } |
| 29 | |
| 30 | if (isset($_POST["quick_delete"])) { |
| 31 | quarantine('quick_delete', $_POST["quick_delete"]); |
| 32 | } |
| 33 | |
| 34 | if (isset($_POST["login_user"]) && isset($_POST["pass_user"])) { |
| 35 | $login_user = strtolower(trim($_POST["login_user"])); |
| 36 | $as = check_login($login_user, $_POST["pass_user"]); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 37 | |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 38 | if ($as == "admin") { |
| 39 | $_SESSION['mailcow_cc_username'] = $login_user; |
| 40 | $_SESSION['mailcow_cc_role'] = "admin"; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 41 | header("Location: /admin"); |
| 42 | } |
| 43 | elseif ($as == "domainadmin") { |
| 44 | $_SESSION['mailcow_cc_username'] = $login_user; |
| 45 | $_SESSION['mailcow_cc_role'] = "domainadmin"; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 46 | header("Location: /mailbox"); |
| 47 | } |
| 48 | elseif ($as == "user") { |
| 49 | $_SESSION['mailcow_cc_username'] = $login_user; |
| 50 | $_SESSION['mailcow_cc_role'] = "user"; |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 51 | $http_parameters = explode('&', $_SESSION['index_query_string']); |
| 52 | unset($_SESSION['index_query_string']); |
| 53 | if (in_array('mobileconfig', $http_parameters)) { |
| 54 | if (in_array('only_email', $http_parameters)) { |
| 55 | header("Location: /mobileconfig.php?email_only"); |
| 56 | die(); |
| 57 | } |
| 58 | header("Location: /mobileconfig.php"); |
| 59 | die(); |
| 60 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 61 | header("Location: /user"); |
| 62 | } |
| 63 | elseif ($as != "pending") { |
| 64 | unset($_SESSION['pending_mailcow_cc_username']); |
| 65 | unset($_SESSION['pending_mailcow_cc_role']); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 66 | unset($_SESSION['pending_tfa_methods']); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 67 | unset($_SESSION['mailcow_cc_username']); |
| 68 | unset($_SESSION['mailcow_cc_role']); |
| 69 | } |
| 70 | } |
| 71 | |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 72 | if (isset($_SESSION['mailcow_cc_role']) && (isset($_SESSION['acl']['login_as']) && $_SESSION['acl']['login_as'] == "1")) { |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 73 | if (isset($_GET["duallogin"])) { |
| 74 | $duallogin = html_entity_decode(rawurldecode($_GET["duallogin"])); |
| 75 | if (filter_var($duallogin, FILTER_VALIDATE_EMAIL)) { |
| 76 | if (!empty(mailbox('get', 'mailbox_details', $duallogin))) { |
| 77 | $_SESSION["dual-login"]["username"] = $_SESSION['mailcow_cc_username']; |
| 78 | $_SESSION["dual-login"]["role"] = $_SESSION['mailcow_cc_role']; |
| 79 | $_SESSION['mailcow_cc_username'] = $duallogin; |
| 80 | $_SESSION['mailcow_cc_role'] = "user"; |
| 81 | header("Location: /user"); |
| 82 | } |
| 83 | } |
| 84 | else { |
| 85 | if (!empty(domain_admin('details', $duallogin))) { |
| 86 | $_SESSION["dual-login"]["username"] = $_SESSION['mailcow_cc_username']; |
| 87 | $_SESSION["dual-login"]["role"] = $_SESSION['mailcow_cc_role']; |
| 88 | $_SESSION['mailcow_cc_username'] = $duallogin; |
| 89 | $_SESSION['mailcow_cc_role'] = "domainadmin"; |
| 90 | header("Location: /user"); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 96 | if (isset($_SESSION['mailcow_cc_role'])) { |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 97 | if (isset($_POST["set_tfa"])) { |
| 98 | set_tfa($_POST); |
| 99 | } |
| 100 | if (isset($_POST["unset_tfa_key"])) { |
| 101 | unset_tfa_key($_POST); |
| 102 | } |
| 103 | if (isset($_POST["unset_fido2_key"])) { |
| 104 | fido2(array("action" => "unset_fido2_key", "post_data" => $_POST)); |
| 105 | } |
| 106 | } |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 107 | if (isset($_SESSION['mailcow_cc_role']) && $_SESSION['mailcow_cc_role'] == "admin" && !isset($_SESSION['mailcow_cc_api'])) { |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 108 | // TODO: Move file upload to API? |
| 109 | if (isset($_POST["submit_main_logo"])) { |
| 110 | if ($_FILES['main_logo']['error'] == 0) { |
| 111 | customize('add', 'main_logo', $_FILES); |
| 112 | } |
| 113 | } |
| 114 | if (isset($_POST["reset_main_logo"])) { |
| 115 | customize('delete', 'main_logo'); |
| 116 | } |
| 117 | // Some actions will not be available via API |
| 118 | if (isset($_POST["license_validate_now"])) { |
| 119 | license('verify'); |
| 120 | } |
| 121 | if (isset($_POST["admin_api"])) { |
| 122 | if (isset($_POST["admin_api"]["ro"])) { |
| 123 | admin_api('ro', 'edit', $_POST); |
| 124 | } |
| 125 | elseif (isset($_POST["admin_api"]["rw"])) { |
| 126 | admin_api('rw', 'edit', $_POST); |
| 127 | } |
| 128 | } |
| 129 | if (isset($_POST["admin_api_regen_key"])) { |
| 130 | if (isset($_POST["admin_api_regen_key"]["ro"])) { |
| 131 | admin_api('ro', 'regen_key', $_POST); |
| 132 | } |
| 133 | elseif (isset($_POST["admin_api_regen_key"]["rw"])) { |
| 134 | admin_api('rw', 'regen_key', $_POST); |
| 135 | } |
| 136 | } |
| 137 | if (isset($_POST["rspamd_ui"])) { |
| 138 | rspamd_ui('edit', $_POST); |
| 139 | } |
| 140 | if (isset($_POST["mass_send"])) { |
| 141 | sys_mail($_POST); |
| 142 | } |
| 143 | } |
| 144 | ?> |