user.js 24 KB

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