base.twig 24 KB

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