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