base.twig 25 KB

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