base.twig 21 KB

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