2
0

user.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. // Base64 functions
  2. var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(r){var t,e,o,a,h,n,c,d="",C=0;for(r=Base64._utf8_encode(r);C<r.length;)a=(t=r.charCodeAt(C++))>>2,h=(3&t)<<4|(e=r.charCodeAt(C++))>>4,n=(15&e)<<2|(o=r.charCodeAt(C++))>>6,c=63&o,isNaN(e)?n=c=64:isNaN(o)&&(c=64),d=d+this._keyStr.charAt(a)+this._keyStr.charAt(h)+this._keyStr.charAt(n)+this._keyStr.charAt(c);return d},decode:function(r){var t,e,o,a,h,n,c="",d=0;for(r=r.replace(/[^A-Za-z0-9\+\/\=]/g,"");d<r.length;)t=this._keyStr.indexOf(r.charAt(d++))<<2|(a=this._keyStr.indexOf(r.charAt(d++)))>>4,e=(15&a)<<4|(h=this._keyStr.indexOf(r.charAt(d++)))>>2,o=(3&h)<<6|(n=this._keyStr.indexOf(r.charAt(d++))),c+=String.fromCharCode(t),64!=h&&(c+=String.fromCharCode(e)),64!=n&&(c+=String.fromCharCode(o));return c=Base64._utf8_decode(c)},_utf8_encode:function(r){r=r.replace(/\r\n/g,"\n");for(var t="",e=0;e<r.length;e++){var o=r.charCodeAt(e);o<128?t+=String.fromCharCode(o):o>127&&o<2048?(t+=String.fromCharCode(o>>6|192),t+=String.fromCharCode(63&o|128)):(t+=String.fromCharCode(o>>12|224),t+=String.fromCharCode(o>>6&63|128),t+=String.fromCharCode(63&o|128))}return t},_utf8_decode:function(r){for(var t="",e=0,o=c1=c2=0;e<r.length;)(o=r.charCodeAt(e))<128?(t+=String.fromCharCode(o),e++):o>191&&o<224?(c2=r.charCodeAt(e+1),t+=String.fromCharCode((31&o)<<6|63&c2),e+=2):(c2=r.charCodeAt(e+1),c3=r.charCodeAt(e+2),t+=String.fromCharCode((15&o)<<12|(63&c2)<<6|63&c3),e+=3);return t}};
  3. $(document).ready(function() {
  4. // Spam score slider
  5. var spam_slider = $('#spam_score')[0];
  6. if (typeof spam_slider !== 'undefined') {
  7. noUiSlider.create(spam_slider, {
  8. start: user_spam_score,
  9. connect: [true, true, true],
  10. range: {
  11. 'min': [0], //stepsize is 50.000
  12. '50%': [10],
  13. '70%': [20, 5],
  14. '80%': [50, 10],
  15. '90%': [100, 100],
  16. '95%': [1000, 1000],
  17. 'max': [5000]
  18. },
  19. });
  20. var connect = spam_slider.querySelectorAll('.noUi-connect');
  21. var classes = ['c-1-color', 'c-2-color', 'c-3-color'];
  22. for (var i = 0; i < connect.length; i++) {
  23. connect[i].classList.add(classes[i]);
  24. }
  25. spam_slider.noUiSlider.on('update', function (values, handle) {
  26. $('.spam-ham-score').text('< ' + Math.round(values[0] * 10) / 10);
  27. $('.spam-spam-score').text(Math.round(values[0] * 10) / 10 + ' - ' + Math.round(values[1] * 10) / 10);
  28. $('.spam-reject-score').text('> ' + Math.round(values[1] * 10) / 10);
  29. $('#spam_score_value').val((Math.round(values[0] * 10) / 10) + ',' + (Math.round(values[1] * 10) / 10));
  30. });
  31. }
  32. // syncjobLogModal
  33. $('#syncjobLogModal').on('show.bs.modal', function(e) {
  34. var syncjob_id = $(e.relatedTarget).data('syncjob-id');
  35. $.ajax({
  36. url: '/inc/ajax/syncjob_logs.php',
  37. data: { id: syncjob_id },
  38. dataType: 'text',
  39. success: function(data){
  40. $(e.currentTarget).find('#logText').text(data);
  41. },
  42. error: function(xhr, status, error) {
  43. $(e.currentTarget).find('#logText').text(xhr.responseText);
  44. }
  45. });
  46. });
  47. $(".arrow-toggle").on('click', function(e) { e.preventDefault(); $(this).find('.arrow').toggleClass("animation"); });
  48. $("#pushover_delete").click(function() { return confirm(lang.delete_ays); });
  49. });
  50. jQuery(function($){
  51. // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
  52. var entityMap = {
  53. '&': '&amp;',
  54. '<': '&lt;',
  55. '>': '&gt;',
  56. '"': '&quot;',
  57. "'": '&#39;',
  58. '/': '&#x2F;',
  59. '`': '&#x60;',
  60. '=': '&#x3D;'
  61. };
  62. function escapeHtml(string) {
  63. return String(string).replace(/[&<>"'`=\/]/g, function (s) {
  64. return entityMap[s];
  65. });
  66. }
  67. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  68. function validateEmail(email) {
  69. var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  70. return re.test(email);
  71. }
  72. function unix_time_format(tm) {
  73. var date = new Date(tm ? tm * 1000 : 0);
  74. return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
  75. }
  76. acl_data = JSON.parse(acl);
  77. $('.clear-last-logins').on('click', function () {if (confirm(lang.delete_ays)) {last_logins('reset');}})
  78. $(".login-history").on('click', function(e) {e.preventDefault(); last_logins('get', $(this).data('days'));$(this).parent().find('li a').removeClass('active');$(this).children(':first-child').addClass('active')});
  79. function last_logins(action, days = 7) {
  80. if (action == 'get') {
  81. $('#spinner-last-login').removeClass('d-none');
  82. $.ajax({
  83. dataType: 'json',
  84. url: '/api/v1/get/last-login/' + encodeURIComponent(mailcow_cc_username) + '/' + days,
  85. jsonp: false,
  86. error: function () {
  87. console.log('error reading last logins');
  88. },
  89. success: function (data) {
  90. $('.last-sasl-login').html('');
  91. if (data.sasl) {
  92. $('.last-sasl-login').append('<ul class="list-group">');
  93. $.each(data.sasl, function (i, item) {
  94. var datetime = new Date(item.datetime.replace(/-/g, "/"));
  95. var local_datetime = datetime.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
  96. var service = '<div class="badge bg-secondary">' + item.service.toUpperCase() + '</div>';
  97. var app_password = item.app_password ? ' <a href="/edit/app-passwd/' + item.app_password + '"><i class="bi bi-app-indicator"></i> ' + escapeHtml(item.app_password_name || "App") + '</a>' : '';
  98. var real_rip = item.real_rip.startsWith("Web") ? item.real_rip : '<a href="https://bgp.tools/prefix/' + item.real_rip + '" target="_blank">' + item.real_rip + "</a>";
  99. var ip_location = item.location ? ' <span class="flag-icon flag-icon-' + item.location.toLowerCase() + '"></span>' : '';
  100. var ip_data = real_rip + ip_location + app_password;
  101. $(".last-sasl-login").append(`
  102. <li class="list-group-item d-flex justify-content-between align-items-start">
  103. <div class="ms-2 me-auto d-flex flex-column">
  104. <div class="fw-bold">` + real_rip + `</div>
  105. <small class="fst-italic mt-2">` + service + ` ` + local_datetime + `</small>
  106. </div>
  107. <span>` + ip_location + `</span>
  108. </li>
  109. `);
  110. })
  111. $('.last-sasl-login').append('</ul>');
  112. }
  113. $('#spinner-last-login').addClass('d-none');
  114. }
  115. })
  116. } else if (action == 'reset') {
  117. $.ajax({
  118. dataType: 'json',
  119. url: '/api/v1/get/reset-last-login/' + encodeURIComponent(mailcow_cc_username),
  120. jsonp: false,
  121. error: function () {
  122. console.log('cannot reset last logins');
  123. },
  124. success: function (data) {
  125. last_logins('get');
  126. }
  127. })
  128. }
  129. }
  130. function createSortableDate(td, cellData, date_string = false) {
  131. if (date_string)
  132. var date = new Date(cellData);
  133. else
  134. var date = new Date(cellData ? cellData * 1000 : 0);
  135. var timestamp = date.getTime();
  136. $(td).attr({
  137. "data-order": timestamp,
  138. "data-sort": timestamp
  139. });
  140. $(td).html(date.toLocaleDateString(LOCALE, DATETIME_FORMAT));
  141. }
  142. function draw_tla_table() {
  143. // just recalc width if instance already exists
  144. if ($.fn.DataTable.isDataTable('#tla_table') ) {
  145. $('#tla_table').DataTable().columns.adjust().responsive.recalc();
  146. return;
  147. }
  148. $('#tla_table').DataTable({
  149. responsive: true,
  150. processing: true,
  151. serverSide: false,
  152. stateSave: true,
  153. pageLength: pagination_size,
  154. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  155. "tr" +
  156. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  157. language: lang_datatables,
  158. order: [[4, 'desc']],
  159. ajax: {
  160. type: "GET",
  161. url: "/api/v1/get/time_limited_aliases",
  162. dataSrc: function(data){
  163. console.log(data);
  164. $.each(data, function (i, item) {
  165. if (acl_data.spam_alias === 1) {
  166. item.action = '<div class="btn-group">' +
  167. '<a href="#" data-action="delete_selected" data-id="single-tla" data-api-url="delete/time_limited_alias" data-item="' + encodeURIComponent(item.address) + '" class="btn btn-xs btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  168. '</div>';
  169. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="tla" name="multi_select" value="' + encodeURIComponent(item.address) + '" />';
  170. item.address = escapeHtml(item.address);
  171. }
  172. else {
  173. item.chkbox = '<input type="checkbox" class="form-check-input" disabled />';
  174. item.action = '<span>-</span>';
  175. }
  176. });
  177. return data;
  178. }
  179. },
  180. columns: [
  181. {
  182. // placeholder, so checkbox will not block child row toggle
  183. title: '',
  184. data: null,
  185. searchable: false,
  186. orderable: false,
  187. defaultContent: ''
  188. },
  189. {
  190. title: '',
  191. data: 'chkbox',
  192. searchable: false,
  193. orderable: false,
  194. defaultContent: ''
  195. },
  196. {
  197. title: lang.alias,
  198. data: 'address',
  199. defaultContent: ''
  200. },
  201. {
  202. title: lang.description,
  203. data: 'description',
  204. defaultContent: '',
  205. render: function (data, type) {
  206. return escapeHtml(data);
  207. }
  208. },
  209. {
  210. title: lang.alias_valid_until,
  211. data: 'validity',
  212. defaultContent: '',
  213. createdCell: function(td, cellData) {
  214. createSortableDate(td, cellData)
  215. }
  216. },
  217. {
  218. title: lang.created_on,
  219. data: 'created',
  220. defaultContent: '',
  221. createdCell: function(td, cellData) {
  222. createSortableDate(td, cellData, true)
  223. }
  224. },
  225. {
  226. title: lang.action,
  227. data: 'action',
  228. className: 'dt-sm-head-hidden dt-text-right',
  229. defaultContent: ''
  230. }
  231. ]
  232. });
  233. }
  234. function draw_sync_job_table() {
  235. // just recalc width if instance already exists
  236. if ($.fn.DataTable.isDataTable('#sync_job_table') ) {
  237. $('#sync_job_table').DataTable().columns.adjust().responsive.recalc();
  238. return;
  239. }
  240. $('#sync_job_table').DataTable({
  241. responsive: true,
  242. processing: true,
  243. serverSide: false,
  244. stateSave: true,
  245. pageLength: pagination_size,
  246. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  247. "tr" +
  248. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  249. language: lang_datatables,
  250. ajax: {
  251. type: "GET",
  252. url: '/api/v1/get/syncjobs/' + encodeURIComponent(mailcow_cc_username) + '/no_log',
  253. dataSrc: function(data){
  254. console.log(data);
  255. $.each(data, function (i, item) {
  256. item.user1 = escapeHtml(item.user1);
  257. item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + item.id + '">' + lang.open_logs + '</a>'
  258. if (!item.exclude > 0) {
  259. item.exclude = '-';
  260. } else {
  261. item.exclude = '<code>' + escapeHtml(item.exclude) + '</code>';
  262. }
  263. item.server_w_port = escapeHtml(item.user1 + '@' + item.host1 + ':' + item.port1);
  264. if (acl_data.syncjobs === 1) {
  265. item.action = '<div class="btn-group">' +
  266. '<a href="/edit/syncjob/' + item.id + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  267. '<a href="#" data-action="delete_selected" data-id="single-syncjob" data-api-url="delete/syncjob" data-item="' + item.id + '" class="btn btn-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  268. '</div>';
  269. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  270. }
  271. else {
  272. item.action = '<span>-</span>';
  273. item.chkbox = '<input type="checkbox" class="form-check-input" disabled />';
  274. }
  275. if (item.is_running == 1) {
  276. item.is_running = '<span id="active-script" class="badge fs-6 bg-success">' + lang.running + '</span>';
  277. } else {
  278. item.is_running = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.waiting + '</span>';
  279. }
  280. if (!item.last_run > 0) {
  281. item.last_run = lang.waiting;
  282. }
  283. if (item.success == null) {
  284. item.success = '-';
  285. item.exit_status = '';
  286. } else {
  287. item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  288. }
  289. if (lang['syncjob_'+item.exit_status]) {
  290. item.exit_status = lang['syncjob_'+item.exit_status];
  291. } else if (item.success != '-') {
  292. item.exit_status = lang.syncjob_check_log;
  293. }
  294. item.exit_status = item.success + ' ' + item.exit_status;
  295. });
  296. return data;
  297. }
  298. },
  299. columns: [
  300. {
  301. // placeholder, so checkbox will not block child row toggle
  302. title: '',
  303. data: null,
  304. searchable: false,
  305. orderable: false,
  306. defaultContent: '',
  307. responsivePriority: 1
  308. },
  309. {
  310. title: '',
  311. data: 'chkbox',
  312. searchable: false,
  313. orderable: false,
  314. defaultContent: '',
  315. responsivePriority: 2
  316. },
  317. {
  318. title: 'ID',
  319. data: 'id',
  320. defaultContent: '',
  321. responsivePriority: 3
  322. },
  323. {
  324. title: 'Server',
  325. data: 'server_w_port',
  326. defaultContent: ''
  327. },
  328. {
  329. title: lang.username,
  330. data: 'user1',
  331. defaultContent: '',
  332. responsivePriority: 3
  333. },
  334. {
  335. title: lang.last_run,
  336. data: 'last_run',
  337. defaultContent: ''
  338. },
  339. {
  340. title: lang.syncjob_last_run_result,
  341. data: 'exit_status',
  342. defaultContent: ''
  343. },
  344. {
  345. title: 'Log',
  346. data: 'log',
  347. defaultContent: ''
  348. },
  349. {
  350. title: lang.active,
  351. data: 'active',
  352. defaultContent: '',
  353. render: function (data, type) {
  354. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>'
  355. }
  356. },
  357. {
  358. title: lang.status,
  359. data: 'is_running',
  360. defaultContent: '',
  361. responsivePriority: 5
  362. },
  363. {
  364. title: lang.encryption,
  365. data: 'enc1',
  366. defaultContent: ''
  367. },
  368. {
  369. title: lang.excludes,
  370. data: 'exclude',
  371. defaultContent: ''
  372. },
  373. {
  374. title: lang.interval + " (min)",
  375. data: 'mins_interval',
  376. defaultContent: ''
  377. },
  378. {
  379. title: lang.action,
  380. data: 'action',
  381. className: 'dt-sm-head-hidden dt-text-right',
  382. defaultContent: '',
  383. responsivePriority: 5
  384. }
  385. ]
  386. });
  387. }
  388. function draw_app_passwd_table() {
  389. // just recalc width if instance already exists
  390. if ($.fn.DataTable.isDataTable('#app_passwd_table') ) {
  391. $('#app_passwd_table').DataTable().columns.adjust().responsive.recalc();
  392. return;
  393. }
  394. $('#app_passwd_table').DataTable({
  395. responsive: true,
  396. processing: true,
  397. serverSide: false,
  398. stateSave: true,
  399. pageLength: pagination_size,
  400. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  401. "tr" +
  402. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  403. language: lang_datatables,
  404. ajax: {
  405. type: "GET",
  406. url: '/api/v1/get/app-passwd/all',
  407. dataSrc: function(data){
  408. console.log(data);
  409. $.each(data, function (i, item) {
  410. item.name = escapeHtml(item.name)
  411. item.protocols = []
  412. if (item.imap_access == 1) { item.protocols.push("<code>IMAP</code>"); }
  413. if (item.smtp_access == 1) { item.protocols.push("<code>SMTP</code>"); }
  414. if (item.eas_access == 1) { item.protocols.push("<code>EAS/ActiveSync</code>"); }
  415. if (item.dav_access == 1) { item.protocols.push("<code>DAV</code>"); }
  416. if (item.pop3_access == 1) { item.protocols.push("<code>POP3</code>"); }
  417. if (item.sieve_access == 1) { item.protocols.push("<code>Sieve</code>"); }
  418. item.protocols = item.protocols.join(" ")
  419. if (acl_data.app_passwds === 1) {
  420. item.action = '<div class="btn-group">' +
  421. '<a href="/edit/app-passwd/' + item.id + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  422. '<a href="#" data-action="delete_selected" data-id="single-apppasswd" data-api-url="delete/app-passwd" data-item="' + item.id + '" class="btn btn-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  423. '</div>';
  424. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="apppasswd" name="multi_select" value="' + item.id + '" />';
  425. }
  426. else {
  427. item.action = '<span>-</span>';
  428. item.chkbox = '<input type="checkbox" class="form-check-input" disabled />';
  429. }
  430. });
  431. return data;
  432. }
  433. },
  434. columns: [
  435. {
  436. // placeholder, so checkbox will not block child row toggle
  437. title: '',
  438. data: null,
  439. searchable: false,
  440. orderable: false,
  441. defaultContent: ''
  442. },
  443. {
  444. title: '',
  445. data: 'chkbox',
  446. searchable: false,
  447. orderable: false,
  448. defaultContent: ''
  449. },
  450. {
  451. title: 'ID',
  452. data: 'id',
  453. defaultContent: ''
  454. },
  455. {
  456. title: lang.app_name,
  457. data: 'name',
  458. defaultContent: ''
  459. },
  460. {
  461. title: lang.allowed_protocols,
  462. data: 'protocols',
  463. defaultContent: ''
  464. },
  465. {
  466. title: lang.active,
  467. data: 'active',
  468. defaultContent: '',
  469. render: function (data, type) {
  470. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>'
  471. }
  472. },
  473. {
  474. title: lang.action,
  475. data: 'action',
  476. className: 'dt-sm-head-hidden dt-text-right',
  477. defaultContent: ''
  478. }
  479. ]
  480. });
  481. }
  482. function draw_wl_policy_mailbox_table() {
  483. // just recalc width if instance already exists
  484. if ($.fn.DataTable.isDataTable('#wl_policy_mailbox_table') ) {
  485. $('#wl_policy_mailbox_table').DataTable().columns.adjust().responsive.recalc();
  486. return;
  487. }
  488. $('#wl_policy_mailbox_table').DataTable({
  489. responsive: true,
  490. processing: true,
  491. serverSide: false,
  492. stateSave: true,
  493. pageLength: pagination_size,
  494. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  495. "tr" +
  496. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  497. language: lang_datatables,
  498. ajax: {
  499. type: "GET",
  500. url: '/api/v1/get/policy_wl_mailbox',
  501. dataSrc: function(data){
  502. console.log(data);
  503. $.each(data, function (i, item) {
  504. if (validateEmail(item.object)) {
  505. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="policy_wl_mailbox" name="multi_select" value="' + item.prefid + '" />';
  506. }
  507. else {
  508. item.chkbox = '<input type="checkbox" class="form-check-input" disabled title="' + lang.spamfilter_table_domain_policy + '" />';
  509. }
  510. if (acl_data.spam_policy === 0) {
  511. item.chkbox = '<input type="checkbox" class="form-check-input" disabled />';
  512. }
  513. });
  514. return data;
  515. }
  516. },
  517. columns: [
  518. {
  519. // placeholder, so checkbox will not block child row toggle
  520. title: '',
  521. data: null,
  522. searchable: false,
  523. orderable: false,
  524. defaultContent: ''
  525. },
  526. {
  527. title: '',
  528. data: 'chkbox',
  529. searchable: false,
  530. orderable: false,
  531. defaultContent: ''
  532. },
  533. {
  534. title: 'ID',
  535. data: 'prefid',
  536. defaultContent: ''
  537. },
  538. {
  539. title: lang.spamfilter_table_rule,
  540. data: 'value',
  541. defaultContent: ''
  542. },
  543. {
  544. title:'Scope',
  545. data: 'object',
  546. defaultContent: ''
  547. }
  548. ]
  549. });
  550. }
  551. function draw_bl_policy_mailbox_table() {
  552. // just recalc width if instance already exists
  553. if ($.fn.DataTable.isDataTable('#bl_policy_mailbox_table') ) {
  554. $('#bl_policy_mailbox_table').DataTable().columns.adjust().responsive.recalc();
  555. return;
  556. }
  557. $('#bl_policy_mailbox_table').DataTable({
  558. responsive: true,
  559. processing: true,
  560. serverSide: false,
  561. stateSave: true,
  562. pageLength: pagination_size,
  563. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  564. "tr" +
  565. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  566. language: lang_datatables,
  567. ajax: {
  568. type: "GET",
  569. url: '/api/v1/get/policy_bl_mailbox',
  570. dataSrc: function(data){
  571. console.log(data);
  572. $.each(data, function (i, item) {
  573. if (validateEmail(item.object)) {
  574. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="policy_bl_mailbox" name="multi_select" value="' + item.prefid + '" />';
  575. }
  576. else {
  577. item.chkbox = '<input type="checkbox" class="form-check-input" disabled tooltip="' + lang.spamfilter_table_domain_policy + '" />';
  578. }
  579. if (acl_data.spam_policy === 0) {
  580. item.chkbox = '<input type="checkbox" class="form-check-input" disabled />';
  581. }
  582. });
  583. return data;
  584. }
  585. },
  586. columns: [
  587. {
  588. // placeholder, so checkbox will not block child row toggle
  589. title: '',
  590. data: null,
  591. searchable: false,
  592. orderable: false,
  593. defaultContent: ''
  594. },
  595. {
  596. title: '',
  597. data: 'chkbox',
  598. searchable: false,
  599. orderable: false,
  600. defaultContent: ''
  601. },
  602. {
  603. title: 'ID',
  604. data: 'prefid',
  605. defaultContent: ''
  606. },
  607. {
  608. title: lang.spamfilter_table_rule,
  609. data: 'value',
  610. defaultContent: ''
  611. },
  612. {
  613. title:'Scope',
  614. data: 'object',
  615. defaultContent: ''
  616. }
  617. ]
  618. });
  619. }
  620. // FIDO2 friendly name modal
  621. $('#fido2ChangeFn').on('show.bs.modal', function (e) {
  622. rename_link = $(e.relatedTarget)
  623. if (rename_link != null) {
  624. $('#fido2_cid').val(rename_link.data('cid'));
  625. $('#fido2_subject_desc').text(Base64.decode(rename_link.data('subject')));
  626. }
  627. })
  628. // Sieve data modal
  629. $('#userFilterModal').on('show.bs.modal', function(e) {
  630. $('#user_sieve_filter').text(lang.loading);
  631. $.ajax({
  632. dataType: 'json',
  633. url: '/api/v1/get/active-user-sieve/' + encodeURIComponent(mailcow_cc_username),
  634. jsonp: false,
  635. error: function () {
  636. console.log('Cannot get active sieve script');
  637. },
  638. complete: function (data) {
  639. if (data.responseText == '{}') {
  640. $('#user_sieve_filter').text(lang.no_active_filter);
  641. } else {
  642. $('#user_sieve_filter').text(JSON.parse(data.responseText));
  643. }
  644. }
  645. })
  646. });
  647. $('#userFilterModal').on('hidden.bs.modal', function () {
  648. $('#user_sieve_filter').text(lang.loading);
  649. });
  650. // detect element visibility changes
  651. function onVisible(element, callback) {
  652. $(document).ready(function() {
  653. element_object = document.querySelector(element);
  654. if (element_object === null) return;
  655. new IntersectionObserver((entries, observer) => {
  656. entries.forEach(entry => {
  657. if(entry.intersectionRatio > 0) {
  658. callback(element_object);
  659. }
  660. });
  661. }).observe(element_object);
  662. });
  663. }
  664. // Load only if the tab is visible
  665. onVisible("[id^=tla_table]", () => draw_tla_table());
  666. onVisible("[id^=bl_policy_mailbox_table]", () => draw_bl_policy_mailbox_table());
  667. onVisible("[id^=wl_policy_mailbox_table]", () => draw_wl_policy_mailbox_table());
  668. onVisible("[id^=sync_job_table]", () => draw_sync_job_table());
  669. onVisible("[id^=app_passwd_table]", () => draw_app_passwd_table());
  670. onVisible("[id^=recent-logins]", () => last_logins('get'));
  671. });