user.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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).addClass('active').siblings().removeClass('active');});
  79. function last_logins(action, days = 7) {
  80. if (action == 'get') {
  81. $('.last-login').html('<i class="bi bi-hourglass"></i>' + lang.waiting);
  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-login').html();
  91. if (data.ui.time) {
  92. $('.last-login').html('<i class="bi bi-person-fill"></i> ' + lang.last_ui_login + ': ' + unix_time_format(data.ui.time));
  93. } else {
  94. $('.last-login').text(lang.no_last_login);
  95. }
  96. if (data.sasl) {
  97. $('.last-login').append('<ul class="list-group">');
  98. $.each(data.sasl, function (i, item) {
  99. var datetime = new Date(item.datetime.replace(/-/g, "/"));
  100. var local_datetime = datetime.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
  101. var service = '<div class="badge fs-6 bg-secondary">' + item.service.toUpperCase() + '</div>';
  102. 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>' : '';
  103. var real_rip = item.real_rip.startsWith("Web") ? item.real_rip : '<a href="https://bgp.he.net/ip/' + item.real_rip + '" target="_blank">' + item.real_rip + "</a>";
  104. var ip_location = item.location ? ' <span class="flag-icon flag-icon-' + item.location.toLowerCase() + '"></span>' : '';
  105. var ip_data = real_rip + ip_location + app_password;
  106. $(".last-login").append('<li class="list-group-item">' + local_datetime + " " + service + " " + lang.from + " " + ip_data + "</li>");
  107. })
  108. $('.last-login').append('</ul>');
  109. }
  110. }
  111. })
  112. } else if (action == 'reset') {
  113. $.ajax({
  114. dataType: 'json',
  115. url: '/api/v1/get/reset-last-login/' + encodeURIComponent(mailcow_cc_username),
  116. jsonp: false,
  117. error: function () {
  118. console.log('cannot reset last logins');
  119. },
  120. success: function (data) {
  121. last_logins('get');
  122. }
  123. })
  124. }
  125. }
  126. function draw_tla_table() {
  127. // just recalc width if instance already exists
  128. if ($.fn.DataTable.isDataTable('#tla_table') ) {
  129. $('#tla_table').DataTable().columns.adjust().responsive.recalc();
  130. return;
  131. }
  132. $('#tla_table').DataTable({
  133. processing: true,
  134. serverSide: false,
  135. language: lang_datatables,
  136. ajax: {
  137. type: "GET",
  138. url: "/api/v1/get/time_limited_aliases",
  139. dataSrc: function(data){
  140. console.log(data);
  141. $.each(data, function (i, item) {
  142. if (acl_data.spam_alias === 1) {
  143. item.action = '<div class="btn-group">' +
  144. '<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>' +
  145. '</div>';
  146. item.chkbox = '<input type="checkbox" data-id="tla" name="multi_select" value="' + encodeURIComponent(item.address) + '" />';
  147. item.address = escapeHtml(item.address);
  148. }
  149. else {
  150. item.chkbox = '<input type="checkbox" disabled />';
  151. item.action = '<span>-</span>';
  152. }
  153. });
  154. return data;
  155. }
  156. },
  157. columns: [
  158. {
  159. // placeholder, so checkbox will not block child row toggle
  160. title: '',
  161. data: null,
  162. searchable: false,
  163. orderable: false,
  164. defaultContent: ''
  165. },
  166. {
  167. title: '',
  168. data: 'chkbox',
  169. searchable: false,
  170. orderable: false,
  171. defaultContent: ''
  172. },
  173. {
  174. title: lang.alias,
  175. data: 'address',
  176. defaultContent: ''
  177. },
  178. {
  179. title: lang.alias_valid_until,
  180. data: 'validity',
  181. defaultContent: '',
  182. render: function (data, type) {
  183. var date = new Date(data ? data * 1000 : 0);
  184. return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
  185. }
  186. },
  187. {
  188. title: lang.created_on,
  189. data: 'created',
  190. defaultContent: '',
  191. render: function (data, type) {
  192. var date = new Date(data.replace(/-/g, "/"));
  193. return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
  194. }
  195. },
  196. {
  197. title: lang.action,
  198. data: 'action',
  199. className: 'text-md-end dt-sm-head-hidden dt-body-right',
  200. defaultContent: ''
  201. }
  202. ]
  203. });
  204. }
  205. function draw_sync_job_table() {
  206. // just recalc width if instance already exists
  207. if ($.fn.DataTable.isDataTable('#sync_job_table') ) {
  208. $('#sync_job_table').DataTable().columns.adjust().responsive.recalc();
  209. return;
  210. }
  211. $('#sync_job_table').DataTable({
  212. processing: true,
  213. serverSide: false,
  214. language: lang_datatables,
  215. ajax: {
  216. type: "GET",
  217. url: '/api/v1/get/syncjobs/' + encodeURIComponent(mailcow_cc_username) + '/no_log',
  218. dataSrc: function(data){
  219. console.log(data);
  220. $.each(data, function (i, item) {
  221. item.user1 = escapeHtml(item.user1);
  222. item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + item.id + '">' + lang.open_logs + '</a>'
  223. if (!item.exclude > 0) {
  224. item.exclude = '-';
  225. } else {
  226. item.exclude = '<code>' + escapeHtml(item.exclude) + '</code>';
  227. }
  228. item.server_w_port = escapeHtml(item.user1 + '@' + item.host1 + ':' + item.port1);
  229. if (acl_data.syncjobs === 1) {
  230. item.action = '<div class="btn-group">' +
  231. '<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>' +
  232. '<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>' +
  233. '</div>';
  234. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  235. }
  236. else {
  237. item.action = '<span>-</span>';
  238. item.chkbox = '<input type="checkbox" disabled />';
  239. }
  240. if (item.is_running == 1) {
  241. item.is_running = '<span id="active-script" class="badge fs-6 bg-success">' + lang.running + '</span>';
  242. } else {
  243. item.is_running = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.waiting + '</span>';
  244. }
  245. if (!item.last_run > 0) {
  246. item.last_run = lang.waiting;
  247. }
  248. if (item.success == null) {
  249. item.success = '-';
  250. item.exit_status = '';
  251. } else {
  252. item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  253. }
  254. if (lang['syncjob_'+item.exit_status]) {
  255. item.exit_status = lang['syncjob_'+item.exit_status];
  256. } else if (item.success != '-') {
  257. item.exit_status = lang.syncjob_check_log;
  258. }
  259. item.exit_status = item.success + ' ' + item.exit_status;
  260. });
  261. return data;
  262. }
  263. },
  264. columns: [
  265. {
  266. // placeholder, so checkbox will not block child row toggle
  267. title: '',
  268. data: null,
  269. searchable: false,
  270. orderable: false,
  271. defaultContent: '',
  272. responsivePriority: 1
  273. },
  274. {
  275. title: '',
  276. data: 'chkbox',
  277. searchable: false,
  278. orderable: false,
  279. defaultContent: '',
  280. responsivePriority: 2
  281. },
  282. {
  283. title: 'ID',
  284. data: 'id',
  285. defaultContent: '',
  286. responsivePriority: 3
  287. },
  288. {
  289. title: 'Server',
  290. data: 'server_w_port',
  291. defaultContent: ''
  292. },
  293. {
  294. title: lang.username,
  295. data: 'user1',
  296. defaultContent: '',
  297. responsivePriority: 3
  298. },
  299. {
  300. title: lang.last_run,
  301. data: 'last_run',
  302. defaultContent: ''
  303. },
  304. {
  305. title: lang.syncjob_last_run_result,
  306. data: 'exit_status',
  307. defaultContent: ''
  308. },
  309. {
  310. title: 'Log',
  311. data: 'log',
  312. defaultContent: ''
  313. },
  314. {
  315. title: lang.active,
  316. data: 'active',
  317. defaultContent: '',
  318. render: function (data, type) {
  319. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>'
  320. }
  321. },
  322. {
  323. title: lang.status,
  324. data: 'is_running',
  325. defaultContent: '',
  326. responsivePriority: 5
  327. },
  328. {
  329. title: lang.encryption,
  330. data: 'enc1',
  331. defaultContent: ''
  332. },
  333. {
  334. title: lang.excludes,
  335. data: 'exclude',
  336. defaultContent: ''
  337. },
  338. {
  339. title: lang.interval + " (min)",
  340. data: 'mins_interval',
  341. defaultContent: ''
  342. },
  343. {
  344. title: lang.action,
  345. data: 'action',
  346. className: 'text-md-end dt-sm-head-hidden dt-body-right',
  347. defaultContent: '',
  348. responsivePriority: 5
  349. }
  350. ]
  351. });
  352. }
  353. function draw_app_passwd_table() {
  354. // just recalc width if instance already exists
  355. if ($.fn.DataTable.isDataTable('#app_passwd_table') ) {
  356. $('#app_passwd_table').DataTable().columns.adjust().responsive.recalc();
  357. return;
  358. }
  359. $('#app_passwd_table').DataTable({
  360. processing: true,
  361. serverSide: false,
  362. language: lang_datatables,
  363. ajax: {
  364. type: "GET",
  365. url: '/api/v1/get/app-passwd/all',
  366. dataSrc: function(data){
  367. console.log(data);
  368. $.each(data, function (i, item) {
  369. item.name = escapeHtml(item.name)
  370. item.protocols = []
  371. if (item.imap_access == 1) { item.protocols.push("<code>IMAP</code>"); }
  372. if (item.smtp_access == 1) { item.protocols.push("<code>SMTP</code>"); }
  373. if (item.eas_access == 1) { item.protocols.push("<code>EAS/ActiveSync</code>"); }
  374. if (item.dav_access == 1) { item.protocols.push("<code>DAV</code>"); }
  375. if (item.pop3_access == 1) { item.protocols.push("<code>POP3</code>"); }
  376. if (item.sieve_access == 1) { item.protocols.push("<code>Sieve</code>"); }
  377. item.protocols = item.protocols.join(" ")
  378. if (acl_data.app_passwds === 1) {
  379. item.action = '<div class="btn-group">' +
  380. '<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>' +
  381. '<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>' +
  382. '</div>';
  383. item.chkbox = '<input type="checkbox" data-id="apppasswd" name="multi_select" value="' + item.id + '" />';
  384. }
  385. else {
  386. item.action = '<span>-</span>';
  387. item.chkbox = '<input type="checkbox" disabled />';
  388. }
  389. });
  390. return data;
  391. }
  392. },
  393. columns: [
  394. {
  395. // placeholder, so checkbox will not block child row toggle
  396. title: '',
  397. data: null,
  398. searchable: false,
  399. orderable: false,
  400. defaultContent: ''
  401. },
  402. {
  403. title: '',
  404. data: 'chkbox',
  405. searchable: false,
  406. orderable: false,
  407. defaultContent: ''
  408. },
  409. {
  410. title: 'ID',
  411. data: 'id',
  412. defaultContent: ''
  413. },
  414. {
  415. title: lang.app_name,
  416. data: 'name',
  417. defaultContent: ''
  418. },
  419. {
  420. title: lang.allowed_protocols,
  421. data: 'protocols',
  422. defaultContent: ''
  423. },
  424. {
  425. title: lang.active,
  426. data: 'active',
  427. defaultContent: '',
  428. render: function (data, type) {
  429. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>'
  430. }
  431. },
  432. {
  433. title: lang.action,
  434. data: 'action',
  435. className: 'text-md-end dt-sm-head-hidden dt-body-right',
  436. defaultContent: ''
  437. }
  438. ]
  439. });
  440. }
  441. function draw_wl_policy_mailbox_table() {
  442. // just recalc width if instance already exists
  443. if ($.fn.DataTable.isDataTable('#wl_policy_mailbox_table') ) {
  444. $('#wl_policy_mailbox_table').DataTable().columns.adjust().responsive.recalc();
  445. return;
  446. }
  447. $('#wl_policy_mailbox_table').DataTable({
  448. processing: true,
  449. serverSide: false,
  450. language: lang_datatables,
  451. ajax: {
  452. type: "GET",
  453. url: '/api/v1/get/policy_wl_mailbox',
  454. dataSrc: function(data){
  455. console.log(data);
  456. $.each(data, function (i, item) {
  457. if (validateEmail(item.object)) {
  458. item.chkbox = '<input type="checkbox" data-id="policy_wl_mailbox" name="multi_select" value="' + item.prefid + '" />';
  459. }
  460. else {
  461. item.chkbox = '<input type="checkbox" disabled title="' + lang.spamfilter_table_domain_policy + '" />';
  462. }
  463. if (acl_data.spam_policy === 0) {
  464. item.chkbox = '<input type="checkbox" disabled />';
  465. }
  466. });
  467. return data;
  468. }
  469. },
  470. columns: [
  471. {
  472. // placeholder, so checkbox will not block child row toggle
  473. title: '',
  474. data: null,
  475. searchable: false,
  476. orderable: false,
  477. defaultContent: ''
  478. },
  479. {
  480. title: '',
  481. data: 'chkbox',
  482. searchable: false,
  483. orderable: false,
  484. defaultContent: ''
  485. },
  486. {
  487. title: 'ID',
  488. data: 'prefid',
  489. defaultContent: ''
  490. },
  491. {
  492. title: lang.spamfilter_table_rule,
  493. data: 'value',
  494. defaultContent: ''
  495. },
  496. {
  497. title:'Scope',
  498. data: 'object',
  499. defaultContent: ''
  500. }
  501. ]
  502. });
  503. }
  504. function draw_bl_policy_mailbox_table() {
  505. // just recalc width if instance already exists
  506. if ($.fn.DataTable.isDataTable('#bl_policy_mailbox_table') ) {
  507. $('#bl_policy_mailbox_table').DataTable().columns.adjust().responsive.recalc();
  508. return;
  509. }
  510. $('#bl_policy_mailbox_table').DataTable({
  511. processing: true,
  512. serverSide: false,
  513. language: lang_datatables,
  514. ajax: {
  515. type: "GET",
  516. url: '/api/v1/get/policy_bl_mailbox',
  517. dataSrc: function(data){
  518. console.log(data);
  519. $.each(data, function (i, item) {
  520. if (validateEmail(item.object)) {
  521. item.chkbox = '<input type="checkbox" data-id="policy_bl_mailbox" name="multi_select" value="' + item.prefid + '" />';
  522. }
  523. else {
  524. item.chkbox = '<input type="checkbox" disabled tooltip="' + lang.spamfilter_table_domain_policy + '" />';
  525. }
  526. if (acl_data.spam_policy === 0) {
  527. item.chkbox = '<input type="checkbox" disabled />';
  528. }
  529. });
  530. return data;
  531. }
  532. },
  533. columns: [
  534. {
  535. // placeholder, so checkbox will not block child row toggle
  536. title: '',
  537. data: null,
  538. searchable: false,
  539. orderable: false,
  540. defaultContent: ''
  541. },
  542. {
  543. title: '',
  544. data: 'chkbox',
  545. searchable: false,
  546. orderable: false,
  547. defaultContent: ''
  548. },
  549. {
  550. title: 'ID',
  551. data: 'prefid',
  552. defaultContent: ''
  553. },
  554. {
  555. title: lang.spamfilter_table_rule,
  556. data: 'value',
  557. defaultContent: ''
  558. },
  559. {
  560. title:'Scope',
  561. data: 'object',
  562. defaultContent: ''
  563. }
  564. ]
  565. });
  566. }
  567. // FIDO2 friendly name modal
  568. $('#fido2ChangeFn').on('show.bs.modal', function (e) {
  569. rename_link = $(e.relatedTarget)
  570. if (rename_link != null) {
  571. $('#fido2_cid').val(rename_link.data('cid'));
  572. $('#fido2_subject_desc').text(Base64.decode(rename_link.data('subject')));
  573. }
  574. })
  575. // Sieve data modal
  576. $('#userFilterModal').on('show.bs.modal', function(e) {
  577. $('#user_sieve_filter').text(lang.loading);
  578. $.ajax({
  579. dataType: 'json',
  580. url: '/api/v1/get/active-user-sieve/' + encodeURIComponent(mailcow_cc_username),
  581. jsonp: false,
  582. error: function () {
  583. console.log('Cannot get active sieve script');
  584. },
  585. complete: function (data) {
  586. if (data.responseText == '{}') {
  587. $('#user_sieve_filter').text(lang.no_active_filter);
  588. } else {
  589. $('#user_sieve_filter').text(JSON.parse(data.responseText));
  590. }
  591. }
  592. })
  593. });
  594. $('#userFilterModal').on('hidden.bs.modal', function () {
  595. $('#user_sieve_filter').text(lang.loading);
  596. });
  597. // detect element visibility changes
  598. function onVisible(element, callback) {
  599. $(document).ready(function() {
  600. element_object = document.querySelector(element);
  601. if (element_object === null) return;
  602. new IntersectionObserver((entries, observer) => {
  603. entries.forEach(entry => {
  604. if(entry.intersectionRatio > 0) {
  605. callback(element_object);
  606. }
  607. });
  608. }).observe(element_object);
  609. });
  610. }
  611. // Load only if the tab is visible
  612. onVisible("[id^=tla_table]", () => draw_tla_table());
  613. onVisible("[id^=bl_policy_mailbox_table]", () => draw_bl_policy_mailbox_table());
  614. onVisible("[id^=wl_policy_mailbox_table]", () => draw_wl_policy_mailbox_table());
  615. onVisible("[id^=sync_job_table]", () => draw_sync_job_table());
  616. onVisible("[id^=app_passwd_table]", () => draw_app_passwd_table());
  617. last_logins('get');
  618. });