base.twig 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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 }}</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. <li class="dropdown">
  68. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="bi bi-link-45deg"></i> {{ ui_texts.apps_name }} <span class="caret"></span></a>
  69. <ul class="dropdown-menu" role="menu">
  70. {% for app in mailcow_apps %}
  71. {% if not skip_sogo or not is_uri('SOGo', app.link) %}
  72. <li {% if app.description %}title="{{ app.description }}"{% endif %}>
  73. <a href="{{ app.link }}">{{ app.name }}</a>
  74. </li>
  75. {% endif %}
  76. {% endfor %}
  77. {% for row in app_links %}
  78. {% for key, val in row %}
  79. <li><a href="{{ val }}">{{ key }}</a></li>
  80. {% endfor %}
  81. {% endfor %}
  82. </ul>
  83. </li>
  84. {% if not dual_login and mailcow_cc_username %}
  85. <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>
  86. {% elseif dual_login %}
  87. <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>
  88. {% endif %}
  89. {% if not is_master %}
  90. <li class="text-warning slave-info">[ slave ]</li>
  91. {% endif %}
  92. </ul>
  93. </div><!--/.nav-collapse -->
  94. </div><!--/.container-fluid -->
  95. </nav>
  96. {% endblock navbar %}
  97. <form action="/" method="post" id="logout"><input type="hidden" name="logout"></form>
  98. {% if ui_texts.ui_announcement_text and ui_texts.ui_announcement_active and not is_root_uri %}
  99. <div class="container">
  100. <div class="alert alert-{{ ui_texts.ui_announcement_type }}">{{ ui_texts.ui_announcement_text }}</div>
  101. </div>
  102. {% endif %}
  103. <div class="container">
  104. {% block content %}{% endblock %}
  105. </div>
  106. {% include 'modals/footer.twig' %}
  107. <script src="{{ js_path }}"></script>
  108. <script>
  109. var lang_footer = {{ lang_footer|raw }};
  110. var lang_acl = {{ lang_acl|raw }};
  111. var lang_tfa = {{ lang_tfa|raw }};
  112. var lang_fido2 = {{ lang_fido2|raw }};
  113. var docker_timeout = {{ docker_timeout|raw }} * 1000;
  114. $(window).scroll(function() {
  115. sessionStorage.scrollTop = $(this).scrollTop();
  116. });
  117. // Select language and reopen active URL without POST
  118. function setLang(sel) {
  119. $.post( '{{ uri }}', {lang: sel} );
  120. window.location.href = window.location.pathname + window.location.search;
  121. }
  122. // FIDO2 functions
  123. function arrayBufferToBase64(buffer) {
  124. let binary = '';
  125. let bytes = new Uint8Array(buffer);
  126. let len = bytes.byteLength;
  127. for (let i = 0; i < len; i++) {
  128. binary += String.fromCharCode( bytes[ i ] );
  129. }
  130. return window.btoa(binary);
  131. }
  132. function recursiveBase64StrToArrayBuffer(obj) {
  133. let prefix = '=?BINARY?B?';
  134. let suffix = '?=';
  135. if (typeof obj === 'object') {
  136. for (let key in obj) {
  137. if (typeof obj[key] === 'string') {
  138. let str = obj[key];
  139. if (str.substring(0, prefix.length) === prefix && str.substring(str.length - suffix.length) === suffix) {
  140. str = str.substring(prefix.length, str.length - suffix.length);
  141. let binary_string = window.atob(str);
  142. let len = binary_string.length;
  143. let bytes = new Uint8Array(len);
  144. for (let i = 0; i < len; i++) {
  145. bytes[i] = binary_string.charCodeAt(i);
  146. }
  147. obj[key] = bytes.buffer;
  148. }
  149. } else {
  150. recursiveBase64StrToArrayBuffer(obj[key]);
  151. }
  152. }
  153. }
  154. }
  155. $(window).load(function() {
  156. $(".overlay").hide();
  157. });
  158. $(document).ready(function() {
  159. $(document).on('shown.bs.modal', function(e) {
  160. modal_id = $(e.relatedTarget).data('target');
  161. $(modal_id).attr("aria-hidden","false");
  162. });
  163. // TFA, CSRF, Alerts in footer.inc.php
  164. // Other general functions in mailcow.js
  165. {% for alert_type, alert_msg in alerts %}
  166. mailcow_alert_box('{{ alert_msg|raw }}', '{{ alert_type }}');
  167. {% endfor %}
  168. // Confirm TFA modal
  169. {% if pending_tfa_method %}
  170. $('#ConfirmTFAModal').modal({
  171. backdrop: 'static',
  172. keyboard: false
  173. });
  174. $('#u2f_status_auth').html('<p><i class="bi bi-arrow-repeat icon-spin"></i> ' + lang_tfa.init_u2f + '</p>');
  175. $('#ConfirmTFAModal').on('shown.bs.modal', function(){
  176. $(this).find('input[name=token]').focus();
  177. // If U2F
  178. if(document.getElementById("u2f_auth_data") !== null) {
  179. $.ajax({
  180. type: "GET",
  181. cache: false,
  182. dataType: 'script',
  183. url: "/api/v1/get/u2f-authentication/{{ pending_mailcow_cc_username|url_encode(true)|default('null') }}",
  184. complete: function(data){
  185. $('#u2f_status_auth').html(lang_tfa.waiting_usb_auth);
  186. data;
  187. setTimeout(function() {
  188. console.log("Ready to authenticate");
  189. u2f.sign(appId, challenge, registeredKeys, function(data) {
  190. var form = document.getElementById('u2f_auth_form');
  191. var auth = document.getElementById('u2f_auth_data');
  192. console.log("Authenticate callback", data);
  193. auth.value = JSON.stringify(data);
  194. form.submit();
  195. });
  196. }, 1000);
  197. }
  198. });
  199. }
  200. });
  201. $('#ConfirmTFAModal').on('hidden.bs.modal', function(){
  202. $.ajax({
  203. type: "GET",
  204. cache: false,
  205. dataType: 'script',
  206. url: '/inc/ajax/destroy_tfa_auth.php',
  207. complete: function(data){
  208. window.location = window.location.href.split("#")[0];
  209. }
  210. });
  211. });
  212. {% endif %}
  213. // Validate FIDO2
  214. $("#fido2-login").click(function(){
  215. $('#fido2-alerts').html();
  216. if (!window.fetch || !navigator.credentials || !navigator.credentials.create) {
  217. window.alert('Browser not supported.');
  218. return;
  219. }
  220. window.fetch("/api/v1/get/fido2-get-args", {method:'GET',cache:'no-cache'}).then(function(response) {
  221. return response.json();
  222. }).then(function(json) {
  223. if (json.success === false) {
  224. throw new Error();
  225. }
  226. recursiveBase64StrToArrayBuffer(json);
  227. return json;
  228. }).then(function(getCredentialArgs) {
  229. return navigator.credentials.get(getCredentialArgs);
  230. }).then(function(cred) {
  231. return {
  232. id: cred.rawId ? arrayBufferToBase64(cred.rawId) : null,
  233. clientDataJSON: cred.response.clientDataJSON ? arrayBufferToBase64(cred.response.clientDataJSON) : null,
  234. authenticatorData: cred.response.authenticatorData ? arrayBufferToBase64(cred.response.authenticatorData) : null,
  235. signature : cred.response.signature ? arrayBufferToBase64(cred.response.signature) : null
  236. };
  237. }).then(JSON.stringify).then(function(AuthenticatorAttestationResponse) {
  238. return window.fetch("/api/v1/process/fido2-args", {method:'POST', body: AuthenticatorAttestationResponse, cache:'no-cache'});
  239. }).then(function(response) {
  240. return response.json();
  241. }).then(function(json) {
  242. if (json.success) {
  243. window.location = window.location.href.split("#")[0];
  244. } else {
  245. throw new Error();
  246. }
  247. }).catch(function(err) {
  248. if (typeof err.message === 'undefined') {
  249. mailcow_alert_box(lang_fido2.fido2_validation_failed, "danger");
  250. } else {
  251. mailcow_alert_box(lang_fido2.fido2_validation_failed + ":<br><i>" + err.message + "</i>", "danger");
  252. }
  253. });
  254. });
  255. // Set TFA/FIDO2
  256. $("#register-fido2, #register-fido2-touchid").click(function(){
  257. let t = $(this);
  258. $("option:selected").prop("selected", false);
  259. if (!window.fetch || !navigator.credentials || !navigator.credentials.create) {
  260. window.alert('Browser not supported.');
  261. return;
  262. }
  263. window.fetch("/api/v1/get/fido2-registration/{{ mailcow_cc_username|url_encode(true)|default('null') }}", {method:'GET',cache:'no-cache'}).then(function(response) {
  264. return response.json();
  265. }).then(function(json) {
  266. if (json.success === false) {
  267. throw new Error(json.msg);
  268. }
  269. recursiveBase64StrToArrayBuffer(json);
  270. // set attestation to node if we are registering apple touch id
  271. if(t.attr('id') === 'register-fido2-touchid') {
  272. json.publicKey.attestation = 'none';
  273. json.publicKey.authenticatorSelection.authenticatorAttachment = "platform";
  274. }
  275. return json;
  276. }).then(function(createCredentialArgs) {
  277. console.log(createCredentialArgs);
  278. return navigator.credentials.create(createCredentialArgs);
  279. }).then(function(cred) {
  280. return {
  281. clientDataJSON: cred.response.clientDataJSON ? arrayBufferToBase64(cred.response.clientDataJSON) : null,
  282. attestationObject: cred.response.attestationObject ? arrayBufferToBase64(cred.response.attestationObject) : null
  283. };
  284. }).then(JSON.stringify).then(function(AuthenticatorAttestationResponse) {
  285. return window.fetch("/api/v1/add/fido2-registration", {method:'POST', body: AuthenticatorAttestationResponse, cache:'no-cache'});
  286. }).then(function(response) {
  287. return response.json();
  288. }).then(function(json) {
  289. if (json.success) {
  290. window.location = window.location.href.split("#")[0];
  291. } else {
  292. throw new Error(json.msg);
  293. }
  294. }).catch(function(err) {
  295. $('#fido2-alerts').html('<span class="text-danger"><b>' + err.message + '</b></span>');
  296. });
  297. });
  298. $('#selectTFA').change(function () {
  299. if ($(this).val() == "yubi_otp") {
  300. $('#YubiOTPModal').modal('show');
  301. $("option:selected").prop("selected", false);
  302. }
  303. if ($(this).val() == "totp") {
  304. $('#TOTPModal').modal('show');
  305. request_token = $('#tfa-qr-img').data('totp-secret');
  306. $.ajax({
  307. url: '/inc/ajax/qr_gen.php',
  308. data: {
  309. token: request_token,
  310. },
  311. }).done(function (result) {
  312. $("#tfa-qr-img").attr("src", result);
  313. });
  314. $("option:selected").prop("selected", false);
  315. }
  316. if ($(this).val() == "u2f") {
  317. $('#U2FModal').modal('show');
  318. $("option:selected").prop("selected", false);
  319. $("#start_u2f_register").click(function(){
  320. $('#u2f_return_code').html('');
  321. $('#u2f_return_code').hide();
  322. $('#u2f_status_reg').html('<p><i class="bi bi-arrow-repeat icon-spin"></i> ' + lang_tfa.init_u2f + '</p>');
  323. $.ajax({
  324. type: "GET",
  325. cache: false,
  326. dataType: 'script',
  327. url: "/api/v1/get/u2f-registration/{{ mailcow_cc_username|url_encode(true)|default('null') }}",
  328. complete: function(data){
  329. data;
  330. setTimeout(function() {
  331. console.log("Ready to register");
  332. $('#u2f_status_reg').html(lang_tfa.waiting_usb_register);
  333. u2f.register(appId, registerRequests, registeredKeys, function(deviceResponse) {
  334. var form = document.getElementById('u2f_reg_form');
  335. var reg = document.getElementById('u2f_register_data');
  336. console.log("Register callback: ", data);
  337. if (deviceResponse.errorCode && deviceResponse.errorCode != 0) {
  338. var u2f_return_code = document.getElementById('u2f_return_code');
  339. u2f_return_code.style.display = u2f_return_code.style.display === 'none' ? '' : null;
  340. if (deviceResponse.errorCode == "4") {
  341. deviceResponse.errorCode = "4 - The presented device is not eligible for this request. For a registration request this may mean that the token is already registered, and for a sign request it may mean that the token does not know the presented key handle";
  342. }
  343. else if (deviceResponse.errorCode == "5") {
  344. deviceResponse.errorCode = "5 - Timeout reached before request could be satisfied.";
  345. }
  346. u2f_return_code.innerHTML = lang_tfa.error_code + ': ' + deviceResponse.errorCode + ' ' + lang_tfa.reload_retry;
  347. return;
  348. }
  349. reg.value = JSON.stringify(deviceResponse);
  350. form.submit();
  351. });
  352. }, 1000);
  353. }
  354. });
  355. });
  356. }
  357. if ($(this).val() == "none") {
  358. $('#DisableTFAModal').modal('show');
  359. $("option:selected").prop("selected", false);
  360. }
  361. });
  362. {% if mailcow_cc_username %}
  363. // Reload after session timeout
  364. var session_lifetime = {{ (session_lifetime * 1000) + 15000 }};
  365. setTimeout(function() {
  366. location.reload();
  367. }, session_lifetime);
  368. {% endif %}
  369. // CSRF
  370. $('<input type="hidden" value="{{ csrf_token }}">').attr('name', 'csrf_token').appendTo('form');
  371. if (sessionStorage.scrollTop != "undefined") {
  372. $(window).scrollTop(sessionStorage.scrollTop);
  373. }
  374. });
  375. </script>
  376. <div class="container footer">
  377. {% if ui_texts.ui_footer %}
  378. <hr><span class="rot-enc">{{ ui_texts.ui_footer|rot13|raw }}</span>
  379. {% endif %}
  380. </div>
  381. </body>
  382. </html>