Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html lang="{{ mailcow_locale|default('en') }}"> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 5 | <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| 6 | <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"> |
| 7 | <meta name="theme-color" content="#F5D76E"/> |
| 8 | <meta http-equiv="Referrer-Policy" content="same-origin"> |
| 9 | <title>{{ ui_texts.title_name|raw }}</title> |
| 10 | |
| 11 | <link rel="stylesheet" href="{{ css_path }}"> |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 12 | <script> |
| 13 | // check if darkmode is preferred by OS or set by localStorage |
| 14 | if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches && localStorage.getItem("theme") !== "light" || |
| 15 | localStorage.getItem("theme") === "dark") { |
| 16 | var head = document.getElementsByTagName('head')[0]; |
| 17 | var link = document.createElement('link'); |
| 18 | link.id = 'dark-mode-theme'; |
| 19 | link.rel = 'stylesheet'; |
| 20 | link.type = 'text/css'; |
| 21 | link.href = '/css/themes/mailcow-darkmode.css'; |
| 22 | head.appendChild(link); |
| 23 | } |
| 24 | </script> |
| 25 | |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 26 | <link rel="shortcut icon" href="/favicon.png" type="image/png"> |
| 27 | <link rel="icon" href="/favicon.png" type="image/png"> |
| 28 | </head> |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 29 | <body> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 30 | <div class="overlay"></div> |
| 31 | {% block navbar %} |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 32 | <nav class="navbar navbar-expand-lg navbar-light bg-light navbar-fixed-top p-0"> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 33 | <div class="container-fluid"> |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 34 | <a class="navbar-brand" href="/"> |
| 35 | <img class="main-logo" alt="mailcow-logo" src="{{ logo|default('/img/cow_mailcow.svg') }}"> |
| 36 | <img class="main-logo-dark" alt="mailcow-logo-dark" src="{{ logo_dark|default('/img/cow_mailcow.svg') }}"> |
| 37 | </a> |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 38 | <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation"> |
| 39 | <i class="bi bi-list fs-3"></i> |
| 40 | </button> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 41 | <div id="navbar" class="navbar-collapse collapse"> |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 42 | <ul class="navbar-nav ms-auto"> |
| 43 | <li class="nav-item"> |
| 44 | <div class="nav-link form-check form-switch my-auto d-flex align-items-center"> |
| 45 | <label class="form-check-label"><i class="bi bi-moon-fill"></i></label> |
| 46 | <input class="form-check-input ms-2" type="checkbox" id="dark-mode-toggle"> |
| 47 | </div> |
| 48 | </li> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 49 | {% if mailcow_locale %} |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 50 | <li class="nav-item dropdown{% if available_languages|length == 1 %}lang-link-disabled{% endif %}"> |
| 51 | <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false"><span class="flag-icon flag-icon-{{ mailcow_locale[-2:] }}"></span></a> |
| 52 | <ul class="dropdown-menu" role="menu "aria-labelledby="languageDropdown"> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 53 | {% for key, val in available_languages %} |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 54 | <li> |
| 55 | <a class="dropdown-item {% if mailcow_locale == key %}active{% endif %}" href="?{{ query_string({'lang': key}) }}"> |
| 56 | <span class="flag-icon flag-icon-{{ key[-2:] }}"></span>{{ val }} |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 57 | </a> |
| 58 | </li> |
| 59 | {% endfor %} |
| 60 | </ul> |
| 61 | </li> |
| 62 | {% endif %} |
| 63 | {% if mailcow_cc_role %} |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 64 | <li class="nav-item dropdown"> |
| 65 | <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false">{{ lang.header.mailcow_system }}</a> |
| 66 | <ul class="dropdown-menu"> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 67 | {% if mailcow_cc_role == 'admin' %} |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 68 | <li><a href="/debug" class="dropdown-item {% if is_uri('debug') %}active{% endif %}">{{ lang.header.debug }}</a></li> |
| 69 | <li><a href="/admin" class="dropdown-item {% if is_uri('admin') %}active{% endif %}">{{ lang.header.mailcow_config }}</a></li> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 70 | {% endif %} |
| 71 | {% if mailcow_cc_role != 'admin' %} |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 72 | <li><a href="/user" class="dropdown-item {% if is_uri('user') %}active{% endif %}">{{ lang.header.user_settings }}</a></li> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 73 | {% endif %} |
| 74 | </ul> |
| 75 | </li> |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 76 | <li class="nav-item dropdown"> |
| 77 | <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false">{{ lang.header.email }}</a> |
| 78 | <ul class="dropdown-menu"> |
| 79 | {% if mailcow_cc_role == 'admin' or mailcow_cc_role == 'domainadmin' %} |
| 80 | <li><a href="/mailbox" class="dropdown-item {% if is_uri('mailbox') %}active{% endif %}">{{ lang.header.mailcow_config }}</a></li> |
| 81 | {% endif %} |
| 82 | <li><a href="/quarantine" class="dropdown-item {% if is_uri('quarantine') %}active{% endif %}">{{ lang.header.quarantine }}</a></li> |
| 83 | {% if mailcow_cc_role == 'admin' %} |
| 84 | <li><a href="/queue" class="dropdown-item {% if is_uri('queue') %}active{% endif %}">{{ lang.queue.queue_manager }}</a></li> |
| 85 | {% endif %} |
| 86 | {% if mailcow_cc_role == 'admin' %} |
| 87 | <li><a href="#" class="dropdown-item" data-bs-toggle="modal" data-container="sogo-mailcow" data-bs-target="#RestartContainer">{{ lang.header.restart_sogo }}</a></li> |
| 88 | {% endif %} |
| 89 | </ul> |
| 90 | </li> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 91 | {% endif %} |
| 92 | {% if mailcow_apps or app_links %} |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 93 | <li class="nav-item dropdown"> |
| 94 | <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false"><i class="bi bi-link-45deg me-2"></i> {{ ui_texts.apps_name|raw }}</a> |
| 95 | <ul class="dropdown-menu"> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 96 | {% for app in mailcow_apps %} |
| 97 | {% if not skip_sogo or not is_uri('SOGo', app.link) %} |
| 98 | <li {% if app.description %}title="{{ app.description }}"{% endif %}> |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 99 | <a href="{{ app.link }}" class="dropdown-item">{{ app.name }}</a> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 100 | </li> |
| 101 | {% endif %} |
| 102 | {% endfor %} |
| 103 | {% for row in app_links %} |
| 104 | {% for key, val in row %} |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 105 | <li><a href="{{ val }}" class="dropdown-item">{{ key }}</a></li> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 106 | {% endfor %} |
| 107 | {% endfor %} |
| 108 | </ul> |
| 109 | </li> |
| 110 | {% endif %} |
| 111 | {% if not dual_login and mailcow_cc_username %} |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 112 | <li class="logged-in-as nav-item"><a href="#" onclick="logout.submit()" class="nav-link"><b class="username-lia">{{ mailcow_cc_username }}</b> <i class="bi bi-power ms-2"></i></a></li> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 113 | {% elseif dual_login %} |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 114 | <li class="logged-in-as nav-item"><a href="#" onclick="logout.submit()" class="nav-link"><b class="username-lia">{{ mailcow_cc_username }} <span class="text-info">({{ dual_login.username }})</span> </b><i class="bi bi-power ms-2"></i></a></li> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 115 | {% endif %} |
| 116 | {% if not is_master %} |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 117 | <li class="text-warning slave-info nav-item">[ slave ]</li> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 118 | {% endif %} |
| 119 | </ul> |
| 120 | </div><!--/.nav-collapse --> |
| 121 | </div><!--/.container-fluid --> |
| 122 | </nav> |
| 123 | {% endblock navbar %} |
| 124 | |
| 125 | <form action="/" method="post" id="logout"><input type="hidden" name="logout"></form> |
| 126 | |
| 127 | {% if ui_texts.ui_announcement_text and ui_texts.ui_announcement_active and not is_root_uri %} |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 128 | <div class="container mt-4"> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 129 | <div class="alert alert-{{ ui_texts.ui_announcement_type }}">{{ ui_texts.ui_announcement_text }}</div> |
| 130 | </div> |
| 131 | {% endif %} |
| 132 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 133 | <div class="container my-4"> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 134 | {% block content %}{% endblock %} |
| 135 | </div> |
| 136 | |
| 137 | {% include 'modals/footer.twig' %} |
| 138 | |
| 139 | <script src="{{ js_path }}"></script> |
| 140 | <script> |
| 141 | var lang_footer = {{ lang_footer|raw }}; |
| 142 | var lang_acl = {{ lang_acl|raw }}; |
| 143 | var lang_tfa = {{ lang_tfa|raw }}; |
| 144 | var lang_fido2 = {{ lang_fido2|raw }}; |
| 145 | var docker_timeout = {{ docker_timeout|raw }} * 1000; |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 146 | var mailcow_cc_role = '{{ mailcow_cc_role }}'; |
| 147 | var last_login = '{{ last_login }}'; |
| 148 | var mailcow_info = { |
| 149 | version_tag: '{{ mailcow_info.version_tag }}', |
| 150 | last_version_tag: '{{ mailcow_info.last_version_tag }}', |
| 151 | updatedAt: '{{ mailcow_info.updated_at }}', |
| 152 | project_url: '{{ mailcow_info.git_project_url }}', |
| 153 | project_owner: '{{ mailcow_info.git_owner }}', |
| 154 | project_repo: '{{ mailcow_info.git_repo }}', |
| 155 | branch: '{{ mailcow_info.mailcow_branch }}' |
| 156 | }; |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 157 | |
| 158 | $(window).scroll(function() { |
| 159 | sessionStorage.scrollTop = $(this).scrollTop(); |
| 160 | }); |
| 161 | // Select language and reopen active URL without POST |
| 162 | function setLang(sel) { |
| 163 | $.post( '{{ uri }}', {lang: sel} ); |
| 164 | window.location.href = window.location.pathname + window.location.search; |
| 165 | } |
| 166 | // FIDO2 functions |
| 167 | function arrayBufferToBase64(buffer) { |
| 168 | let binary = ''; |
| 169 | let bytes = new Uint8Array(buffer); |
| 170 | let len = bytes.byteLength; |
| 171 | for (let i = 0; i < len; i++) { |
| 172 | binary += String.fromCharCode( bytes[ i ] ); |
| 173 | } |
| 174 | return window.btoa(binary); |
| 175 | } |
| 176 | function recursiveBase64StrToArrayBuffer(obj) { |
| 177 | let prefix = '=?BINARY?B?'; |
| 178 | let suffix = '?='; |
| 179 | if (typeof obj === 'object') { |
| 180 | for (let key in obj) { |
| 181 | if (typeof obj[key] === 'string') { |
| 182 | let str = obj[key]; |
| 183 | if (str.substring(0, prefix.length) === prefix && str.substring(str.length - suffix.length) === suffix) { |
| 184 | str = str.substring(prefix.length, str.length - suffix.length); |
| 185 | let binary_string = window.atob(str); |
| 186 | let len = binary_string.length; |
| 187 | let bytes = new Uint8Array(len); |
| 188 | for (let i = 0; i < len; i++) { |
| 189 | bytes[i] = binary_string.charCodeAt(i); |
| 190 | } |
| 191 | obj[key] = bytes.buffer; |
| 192 | } |
| 193 | } else { |
| 194 | recursiveBase64StrToArrayBuffer(obj[key]); |
| 195 | } |
| 196 | } |
| 197 | } |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 198 | } |
| 199 | $(window).on('load', function() { |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 200 | $(".overlay").hide(); |
| 201 | }); |
| 202 | $(document).ready(function() { |
| 203 | $(document).on('shown.bs.modal', function(e) { |
| 204 | modal_id = $(e.relatedTarget).data('target'); |
| 205 | $(modal_id).attr("aria-hidden","false"); |
| 206 | }); |
| 207 | // TFA, CSRF, Alerts in footer.inc.php |
| 208 | // Other general functions in mailcow.js |
| 209 | {% for alert_type, alert_msg in alerts %} |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 210 | mailcow_alert_box('{{ alert_msg|raw|e("js") }}', '{{ alert_type }}'); |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 211 | {% endfor %} |
| 212 | |
| 213 | // Confirm TFA modal |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 214 | {% if pending_tfa_methods %} |
| 215 | new bootstrap.Modal(document.getElementById("ConfirmTFAModal"), { |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 216 | backdrop: 'static', |
| 217 | keyboard: false |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 218 | }).show(); |
| 219 | |
| 220 | |
| 221 | // validate Time based OTP tfa |
| 222 | $("#pending_tfa_tab_totp").click(function(){ |
| 223 | $(".webauthn-authenticator-selection").removeClass("active"); |
| 224 | $("#collapseWebAuthnTFA").collapse('hide'); |
| 225 | |
| 226 | // select default if only one authenticator exists |
| 227 | if ($('.totp-authenticator-selection').length == 1){ |
| 228 | $('.totp-authenticator-selection').addClass("active"); |
| 229 | var id = $('.totp-authenticator-selection').children('input').first().val(); |
| 230 | $("#totp_selected_id").val(id); |
| 231 | $("#collapseTotpTFA").collapse('show'); |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 232 | } |
| 233 | }); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 234 | $(".totp-authenticator-selection").click(function(){ |
| 235 | $(".totp-authenticator-selection").removeClass("active"); |
| 236 | $(this).addClass("active"); |
| 237 | |
| 238 | var id = $(this).children('input').first().val(); |
| 239 | $("#totp_selected_id").val(id); |
| 240 | |
| 241 | $("#collapseTotpTFA").collapse('show'); |
| 242 | }); |
| 243 | if ($('.totp-authenticator-selection').length == 1 && |
| 244 | $('#pending_tfa_tab_yubi_otp').length == 0 && |
| 245 | $('.webauthn-authenticator-selection').length == 0){ |
| 246 | |
| 247 | // select default if only one authenticator exists |
| 248 | $('.totp-authenticator-selection').addClass("active"); |
| 249 | |
| 250 | var id = $('.totp-authenticator-selection').children('input').first().val(); |
| 251 | $("#totp_selected_id").val(id); |
| 252 | |
| 253 | $("#collapseTotpTFA").collapse('show'); |
| 254 | setTimeout(function() { $("#collapseTotpTFA").find('input[name="token"]').focus(); }, 1000); |
| 255 | } |
| 256 | $('#pending_tfa_tab_totp').on('shown.bs.tab', function() { |
| 257 | // autofocus |
| 258 | setTimeout(function() { $("#collapseTotpTFA").find('input[name="token"]').focus(); }, 200); |
| 259 | }); |
| 260 | // validate Yubi OTP tfa |
| 261 | if ($('.webauthn-authenticator-selection').length == 0){ |
| 262 | // autofocus |
| 263 | setTimeout(function() { $("#collapseYubiTFA").find('input[name="token"]').focus(); }, 1000); |
| 264 | } |
| 265 | $('#pending_tfa_tab_yubi_otp').on('shown.bs.tab', function() { |
| 266 | // autofocus |
| 267 | $("#collapseYubiTFA").find('input[name="token"]').focus(); |
| 268 | }); |
| 269 | // validate WebAuthn tfa |
| 270 | $("#pending_tfa_tab_webauthn").click(function(){ |
| 271 | $(".totp-authenticator-selection").removeClass("active"); |
| 272 | |
| 273 | $("#collapseTotpTFA").collapse('hide'); |
| 274 | }); |
| 275 | $(".webauthn-authenticator-selection").click(function(){ |
| 276 | $(".webauthn-authenticator-selection").removeClass("active"); |
| 277 | $(this).addClass("active"); |
| 278 | |
| 279 | var id = $(this).children('input').first().val(); |
| 280 | $("#webauthn_selected_id").val(id); |
| 281 | |
| 282 | var webauthn_status_auth = document.getElementById('webauthn_status_auth'); |
| 283 | webauthn_status_auth.style.setProperty('display', 'flex', 'important'); |
| 284 | var webauthn_return_code = document.getElementById('webauthn_return_code'); |
| 285 | webauthn_return_code.style.setProperty('display', 'none', 'important'); |
| 286 | |
| 287 | $("#collapseWebAuthnTFA").collapse('show'); |
| 288 | |
| 289 | $(this).find('input[name=token]').focus(); |
| 290 | if(document.getElementById("webauthn_auth_data") !== null) { |
| 291 | // Check Browser support |
| 292 | if (!window.fetch || !navigator.credentials || !navigator.credentials.create) { |
| 293 | window.alert('Browser not supported for WebAuthn.'); |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | // fetch webauthn auth args |
| 298 | window.fetch("/api/v1/get/webauthn-tfa-get-args", {method:'GET',cache:'no-cache'}).then(response => { |
| 299 | return response.json(); |
| 300 | }).then(json => { |
| 301 | console.log(json); |
| 302 | if (json.success === false) throw new Error(); |
| 303 | if (json.type === "error") throw new Error(json.msg); |
| 304 | |
| 305 | recursiveBase64StrToArrayBuffer(json); |
| 306 | return json; |
| 307 | }).then(getCredentialArgs => { |
| 308 | // get credentials |
| 309 | return navigator.credentials.get(getCredentialArgs); |
| 310 | }).then(cred => { |
| 311 | return { |
| 312 | id: cred.rawId ? arrayBufferToBase64(cred.rawId) : null, |
| 313 | clientDataJSON: cred.response.clientDataJSON ? arrayBufferToBase64(cred.response.clientDataJSON) : null, |
| 314 | authenticatorData: cred.response.authenticatorData ? arrayBufferToBase64(cred.response.authenticatorData) : null, |
| 315 | signature : cred.response.signature ? arrayBufferToBase64(cred.response.signature) : null |
| 316 | }; |
| 317 | }).then(JSON.stringify).then(function(AuthenticatorAttestationResponse) { |
| 318 | // send request by submit |
| 319 | var form = document.getElementById('webauthn_auth_form'); |
| 320 | var auth = document.getElementById('webauthn_auth_data'); |
| 321 | auth.value = AuthenticatorAttestationResponse; |
| 322 | form.submit(); |
| 323 | }).catch(function(err) { |
| 324 | var webauthn_status_auth = document.getElementById('webauthn_status_auth'); |
| 325 | webauthn_status_auth.style.setProperty('display', 'none', 'important'); |
| 326 | |
| 327 | var webauthn_return_code = document.getElementById('webauthn_return_code'); |
| 328 | webauthn_return_code.style.setProperty('display', 'block', 'important'); |
| 329 | webauthn_return_code.innerHTML = lang_tfa.error_code + ': ' + err + ' ' + lang_tfa.reload_retry; |
| 330 | }); |
| 331 | } |
| 332 | }); |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 333 | $('#ConfirmTFAModal').on('hidden.bs.modal', function(){ |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 334 | // cancel pending login |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 335 | $.ajax({ |
| 336 | type: "GET", |
| 337 | cache: false, |
| 338 | dataType: 'script', |
| 339 | url: '/inc/ajax/destroy_tfa_auth.php', |
| 340 | complete: function(data){ |
| 341 | window.location = window.location.href.split("#")[0]; |
| 342 | } |
| 343 | }); |
| 344 | }); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 345 | {% endif %} |
| 346 | |
| 347 | |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 348 | // Validate FIDO2 |
| 349 | $("#fido2-login").click(function(){ |
| 350 | $('#fido2-alerts').html(); |
| 351 | if (!window.fetch || !navigator.credentials || !navigator.credentials.create) { |
| 352 | window.alert('Browser not supported.'); |
| 353 | return; |
| 354 | } |
| 355 | window.fetch("/api/v1/get/fido2-get-args", {method:'GET',cache:'no-cache'}).then(function(response) { |
| 356 | return response.json(); |
| 357 | }).then(function(json) { |
| 358 | if (json.success === false) { |
| 359 | throw new Error(); |
| 360 | } |
| 361 | recursiveBase64StrToArrayBuffer(json); |
| 362 | return json; |
| 363 | }).then(function(getCredentialArgs) { |
| 364 | return navigator.credentials.get(getCredentialArgs); |
| 365 | }).then(function(cred) { |
| 366 | return { |
| 367 | id: cred.rawId ? arrayBufferToBase64(cred.rawId) : null, |
| 368 | clientDataJSON: cred.response.clientDataJSON ? arrayBufferToBase64(cred.response.clientDataJSON) : null, |
| 369 | authenticatorData: cred.response.authenticatorData ? arrayBufferToBase64(cred.response.authenticatorData) : null, |
| 370 | signature : cred.response.signature ? arrayBufferToBase64(cred.response.signature) : null |
| 371 | }; |
| 372 | }).then(JSON.stringify).then(function(AuthenticatorAttestationResponse) { |
| 373 | return window.fetch("/api/v1/process/fido2-args", {method:'POST', body: AuthenticatorAttestationResponse, cache:'no-cache'}); |
| 374 | }).then(function(response) { |
| 375 | return response.json(); |
| 376 | }).then(function(json) { |
| 377 | if (json.success) { |
| 378 | window.location = window.location.href.split("#")[0]; |
| 379 | } else { |
| 380 | throw new Error(); |
| 381 | } |
| 382 | }).catch(function(err) { |
| 383 | if (typeof err.message === 'undefined') { |
| 384 | mailcow_alert_box(lang_fido2.fido2_validation_failed, "danger"); |
| 385 | } else { |
| 386 | mailcow_alert_box(lang_fido2.fido2_validation_failed + ":<br><i>" + err.message + "</i>", "danger"); |
| 387 | } |
| 388 | }); |
| 389 | }); |
| 390 | // Set TFA/FIDO2 |
| 391 | $("#register-fido2, #register-fido2-touchid").click(function(){ |
| 392 | let t = $(this); |
| 393 | |
| 394 | $("option:selected").prop("selected", false); |
| 395 | if (!window.fetch || !navigator.credentials || !navigator.credentials.create) { |
| 396 | window.alert('Browser not supported.'); |
| 397 | return; |
| 398 | } |
| 399 | |
| 400 | window.fetch("/api/v1/get/fido2-registration/{{ mailcow_cc_username|url_encode(true)|default('null') }}", {method:'GET',cache:'no-cache'}).then(function(response) { |
| 401 | return response.json(); |
| 402 | }).then(function(json) { |
| 403 | if (json.success === false) { |
| 404 | throw new Error(json.msg); |
| 405 | } |
| 406 | recursiveBase64StrToArrayBuffer(json); |
| 407 | |
| 408 | // set attestation to node if we are registering apple touch id |
| 409 | if(t.attr('id') === 'register-fido2-touchid') { |
| 410 | json.publicKey.attestation = 'none'; |
| 411 | json.publicKey.authenticatorSelection.authenticatorAttachment = "platform"; |
| 412 | } |
| 413 | |
| 414 | return json; |
| 415 | }).then(function(createCredentialArgs) { |
| 416 | console.log(createCredentialArgs); |
| 417 | return navigator.credentials.create(createCredentialArgs); |
| 418 | }).then(function(cred) { |
| 419 | return { |
| 420 | clientDataJSON: cred.response.clientDataJSON ? arrayBufferToBase64(cred.response.clientDataJSON) : null, |
| 421 | attestationObject: cred.response.attestationObject ? arrayBufferToBase64(cred.response.attestationObject) : null |
| 422 | }; |
| 423 | }).then(JSON.stringify).then(function(AuthenticatorAttestationResponse) { |
| 424 | return window.fetch("/api/v1/add/fido2-registration", {method:'POST', body: AuthenticatorAttestationResponse, cache:'no-cache'}); |
| 425 | }).then(function(response) { |
| 426 | return response.json(); |
| 427 | }).then(function(json) { |
| 428 | if (json.success) { |
| 429 | window.location = window.location.href.split("#")[0]; |
| 430 | } else { |
| 431 | throw new Error(json.msg); |
| 432 | } |
| 433 | }).catch(function(err) { |
| 434 | $('#fido2-alerts').html('<span class="text-danger"><b>' + err.message + '</b></span>'); |
| 435 | }); |
| 436 | }); |
| 437 | $('#selectTFA').change(function () { |
| 438 | if ($(this).val() == "yubi_otp") { |
| 439 | $('#YubiOTPModal').modal('show'); |
| 440 | $("option:selected").prop("selected", false); |
| 441 | } |
| 442 | if ($(this).val() == "totp") { |
| 443 | $('#TOTPModal').modal('show'); |
| 444 | request_token = $('#tfa-qr-img').data('totp-secret'); |
| 445 | $.ajax({ |
| 446 | url: '/inc/ajax/qr_gen.php', |
| 447 | data: { |
| 448 | token: request_token, |
| 449 | }, |
| 450 | }).done(function (result) { |
| 451 | $("#tfa-qr-img").attr("src", result); |
| 452 | }); |
| 453 | $("option:selected").prop("selected", false); |
| 454 | } |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 455 | if ($(this).val() == "webauthn") { |
| 456 | // check if Browser is supported |
| 457 | if (!window.fetch || !navigator.credentials || !navigator.credentials.create) { |
| 458 | window.alert('Browser not supported.'); |
| 459 | return; |
| 460 | } |
| 461 | |
| 462 | // show modal |
| 463 | $('#WebAuthnModal').modal('show'); |
| 464 | $("option:selected").prop("selected", false); |
| 465 | |
| 466 | $("#start_webauthn_register").click(() => { |
| 467 | var key_id = document.getElementsByName('key_id')[1].value; |
| 468 | var confirm_password = document.getElementsByName('confirm_password')[1].value; |
| 469 | |
| 470 | // fetch WebAuthn create args |
| 471 | window.fetch("/api/v1/get/webauthn-tfa-registration/{{ mailcow_cc_username|url_encode(true)|default('null') }}", {method:'GET',cache:'no-cache'}).then(response => { |
| 472 | return response.json(); |
| 473 | }).then(json => { |
| 474 | console.log(json); |
| 475 | if (json.success === false) throw new Error(json.msg); |
| 476 | recursiveBase64StrToArrayBuffer(json); |
| 477 | |
| 478 | return json; |
| 479 | }).then(createCredentialArgs => { |
| 480 | // create credentials |
| 481 | return navigator.credentials.create(createCredentialArgs); |
| 482 | }).then(cred => { |
| 483 | return { |
| 484 | clientDataJSON: cred.response.clientDataJSON ? arrayBufferToBase64(cred.response.clientDataJSON) : null, |
| 485 | attestationObject: cred.response.attestationObject ? arrayBufferToBase64(cred.response.attestationObject) : null, |
| 486 | key_id: key_id, |
| 487 | tfa_method: "webauthn", |
| 488 | confirm_password: confirm_password |
| 489 | }; |
| 490 | }).then(JSON.stringify).then(AuthenticatorAttestationResponse => { |
| 491 | // send request |
| 492 | return window.fetch("/api/v1/add/webauthn-tfa-registration", {method:'POST', body: AuthenticatorAttestationResponse, cache:'no-cache'}); |
| 493 | }).then(response => { |
| 494 | return response.json(); |
| 495 | }).then(json => { |
| 496 | if (json.success) { |
| 497 | // reload on success |
| 498 | window.location = window.location.href.split("#")[0]; |
| 499 | } else { |
| 500 | throw new Error(json.msg); |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 501 | } |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 502 | }).catch(function(err) { |
| 503 | console.log(err); |
| 504 | var webauthn_return_code = document.getElementById('webauthn_return_code'); |
| 505 | webauthn_return_code.style.display = webauthn_return_code.style.display === 'none' ? '' : null; |
| 506 | webauthn_return_code.innerHTML = lang_tfa.error_code + ': ' + err + ' ' + lang_tfa.reload_retry; |
| 507 | }); |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 508 | }); |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 509 | } |
| 510 | if ($(this).val() == "none") { |
| 511 | $('#DisableTFAModal').modal('show'); |
| 512 | $("option:selected").prop("selected", false); |
| 513 | } |
| 514 | }); |
| 515 | |
| 516 | {% if mailcow_cc_username %} |
| 517 | // Reload after session timeout |
| 518 | var session_lifetime = {{ (session_lifetime * 1000) + 15000 }}; |
| 519 | setTimeout(function() { |
| 520 | location.reload(); |
| 521 | }, session_lifetime); |
| 522 | {% endif %} |
| 523 | |
| 524 | // CSRF |
| 525 | $('<input type="hidden" value="{{ csrf_token }}">').attr('name', 'csrf_token').appendTo('form'); |
| 526 | if (sessionStorage.scrollTop != "undefined") { |
| 527 | $(window).scrollTop(sessionStorage.scrollTop); |
| 528 | } |
| 529 | }); |
| 530 | </script> |
| 531 | |
| 532 | <div class="container footer"> |
| 533 | {% if ui_texts.ui_footer %} |
| 534 | <hr><span class="rot-enc">{{ ui_texts.ui_footer|rot13|raw }}</span> |
| 535 | {% endif %} |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 536 | {% if mailcow_cc_username and mailcow_info.mailcow_branch|lower == "master" and mailcow_info.version_tag|default %} |
| 537 | <span class="version"> |
| 538 | 🐮 + 🐋 = 💕 |
| 539 | Version: <a href="{{ mailcow_info.git_project_url }}/releases/tag/{{ mailcow_info.version_tag }}" target="_blank">{{ mailcow_info.version_tag }} |
| 540 | </a> |
| 541 | </span> |
| 542 | {% endif %} |
| 543 | {% if mailcow_cc_username and mailcow_info.mailcow_branch|lower == "nightly" and mailcow_info.version_tag|default %} |
| 544 | <span class="version"> |
| 545 | 🛠️🐮 + 🐋 = 💕 |
| 546 | Nightly: <a href="{{ mailcow_info.git_project_url }}/commit/{{ mailcow_info.git_commit }}" target="_blank">{{ mailcow_info.version_tag }} |
| 547 | </a><br> |
| 548 | <span style="text-align:right;display:block;">Build: {{ mailcow_info.git_commit_date }}</span> |
| 549 | </span> |
| 550 | {% endif %} |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 551 | </div> |
| 552 | </body> |
| 553 | </html> |