user.js 25 KB

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