mailbox.js 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. $(document).ready(function() {
  2. acl_data = JSON.parse(acl);
  3. FooTable.domainFilter = FooTable.Filtering.extend({
  4. construct: function(instance){
  5. this._super(instance);
  6. this.def = 'All Domains';
  7. this.$domain = null;
  8. },
  9. $create: function(){
  10. this._super();
  11. var self = this;
  12. var domains = [];
  13. $.each(self.ft.rows.all, function(i, row){
  14. if((row.val().domain != null) && ($.inArray(row.val().domain, domains) === -1)) domains.push(row.val().domain);
  15. });
  16. $form_grp = $('<div/>', {'class': 'form-group'})
  17. .append($('<label/>', {'class': 'sr-only', text: 'Domain'}))
  18. .prependTo(self.$form);
  19. self.$domain = $('<select/>', { 'class': 'aform-control' })
  20. .on('change', {self: self}, self._onDomainDropdownChanged)
  21. .append($('<option/>', {text: self.def}))
  22. .appendTo($form_grp);
  23. $.each(domains, function(i, domain){
  24. self.$domain.append($('<option/>').text(domain));
  25. });
  26. },
  27. _onDomainDropdownChanged: function(e){
  28. var self = e.data.self,
  29. selected = $(this).val();
  30. if (selected !== self.def){
  31. self.addFilter('domain', selected, ['domain']);
  32. } else {
  33. self.removeFilter('domain');
  34. }
  35. self.filter();
  36. },
  37. draw: function(){
  38. this._super();
  39. var domain = this.find('domain');
  40. if (domain instanceof FooTable.Filter){
  41. this.$domain.val(domain.query.val());
  42. } else {
  43. this.$domain.val(this.def);
  44. }
  45. $(this.$domain).closest("select").selectpicker();
  46. }
  47. });
  48. // Set paging
  49. $('[data-page-size]').on('click', function(e){
  50. e.preventDefault();
  51. var new_size = $(this).data('page-size');
  52. var parent_ul = $(this).closest('ul');
  53. var table_id = $(parent_ul).data('table-id');
  54. FooTable.get('#' + table_id).pageSize(new_size);
  55. //$(this).parent().addClass('active').siblings().removeClass('active')
  56. heading = $(this).parents('.panel').find('.panel-heading')
  57. var n_results = $(heading).children('.table-lines').text().split(' / ')[1];
  58. $(heading).children('.table-lines').text(function(){
  59. if (new_size > n_results) {
  60. new_size = n_results;
  61. }
  62. return new_size + ' / ' + n_results;
  63. })
  64. });
  65. // Clone mailbox mass actions
  66. $("div").find("[data-actions-header='true'").each(function() {
  67. $(this).html($(this).nextAll('.mass-actions-mailbox:first').html());
  68. });
  69. // Auto-fill domain quota when adding new domain
  70. auto_fill_quota = function(domain) {
  71. $.get("/api/v1/get/domain/" + domain, function(data){
  72. var result = $.parseJSON(JSON.stringify(data));
  73. def_new_mailbox_quota = ( result.def_new_mailbox_quota / 1048576);
  74. max_new_mailbox_quota = ( result.max_new_mailbox_quota / 1048576);
  75. if (max_new_mailbox_quota != '0') {
  76. $('.addInputQuotaExhausted').hide();
  77. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  78. $('#addInputQuota').attr({"disabled": false, "value": "", "type": "number", "max": max_new_mailbox_quota});
  79. $('#addInputQuota').val(def_new_mailbox_quota);
  80. }
  81. else {
  82. $('.addInputQuotaExhausted').show();
  83. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  84. $('#addInputQuota').attr({"disabled": true, "value": "", "type": "text", "value": "n/a"});
  85. $('#addInputQuota').val(max_new_mailbox_quota);
  86. }
  87. });
  88. }
  89. $('#addSelectDomain').on('change', function() {
  90. auto_fill_quota($('#addSelectDomain').val());
  91. });
  92. auto_fill_quota($('#addSelectDomain').val());
  93. $(".goto_checkbox").click(function( event ) {
  94. $("form[data-id='add_alias'] .goto_checkbox").not(this).prop('checked', false);
  95. if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
  96. $('#textarea_alias_goto').prop('disabled', true);
  97. }
  98. else {
  99. $("#textarea_alias_goto").removeAttr('disabled');
  100. }
  101. });
  102. $('#addAliasModal').on('show.bs.modal', function(e) {
  103. if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
  104. $('#textarea_alias_goto').prop('disabled', true);
  105. }
  106. else {
  107. $("#textarea_alias_goto").removeAttr('disabled');
  108. }
  109. });
  110. // Log modal
  111. $('#syncjobLogModal').on('show.bs.modal', function(e) {
  112. var syncjob_id = $(e.relatedTarget).data('syncjob-id');
  113. $.ajax({
  114. url: '/inc/ajax/syncjob_logs.php',
  115. data: { id: syncjob_id },
  116. dataType: 'text',
  117. success: function(data){
  118. $(e.currentTarget).find('#logText').text(data);
  119. },
  120. error: function(xhr, status, error) {
  121. $(e.currentTarget).find('#logText').text(xhr.responseText);
  122. }
  123. });
  124. });
  125. // Log modal
  126. $('#dnsInfoModal').on('show.bs.modal', function(e) {
  127. var domain = $(e.relatedTarget).data('domain');
  128. $('.dns-modal-body').html('<center><i class="bi bi-arrow-repeat icon-spin"></i></center>');
  129. $.ajax({
  130. url: '/inc/ajax/dns_diagnostics.php',
  131. data: { domain: domain },
  132. dataType: 'text',
  133. success: function(data){
  134. $('.dns-modal-body').html(data);
  135. },
  136. error: function(xhr, status, error) {
  137. $('.dns-modal-body').html(xhr.responseText);
  138. }
  139. });
  140. });
  141. // Sieve data modal
  142. $('#sieveDataModal').on('show.bs.modal', function(e) {
  143. var sieveScript = $(e.relatedTarget).data('sieve-script');
  144. $(e.currentTarget).find('#sieveDataText').html('<pre style="font-size:14px;line-height:1.1">' + sieveScript + '</pre>');
  145. });
  146. // Disable submit button on script change
  147. $('.textarea-code').on('keyup', function() {
  148. // Disable all "save" buttons, could be a "related button only" function, todo
  149. $('.add_sieve_script').attr({"disabled": true});
  150. });
  151. // Validate script data
  152. $(".validate_sieve").click(function( event ) {
  153. event.preventDefault();
  154. var validation_button = $(this);
  155. // Get script_data textarea content from form the button was clicked in
  156. var script = $('textarea[name="script_data"]', $(this).parents('form:first')).val();
  157. $.ajax({
  158. dataType: 'json',
  159. url: "/inc/ajax/sieve_validation.php",
  160. type: "get",
  161. data: { script: script },
  162. complete: function(data) {
  163. var response = (data.responseText);
  164. response_obj = JSON.parse(response);
  165. if (response_obj.type == "success") {
  166. $(validation_button).next().attr({"disabled": false});
  167. }
  168. mailcow_alert_box(response_obj.msg, response_obj.type);
  169. },
  170. });
  171. });
  172. // $(document).on('DOMNodeInserted', '#prefilter_table', function () {
  173. // $("#active-script").closest('td').css('background-color','#b0f0a0');
  174. // $("#inactive-script").closest('td').css('background-color','#b0f0a0');
  175. // });
  176. $('#addResourceModal').on('shown.bs.modal', function() {
  177. $("#multiple_bookings").val($("#multiple_bookings_select").val());
  178. if ($("#multiple_bookings").val() == "custom") {
  179. $("#multiple_bookings_custom_div").show();
  180. $("#multiple_bookings").val($("#multiple_bookings_custom").val());
  181. }
  182. })
  183. $("#multiple_bookings_select").change(function() {
  184. $("#multiple_bookings").val($("#multiple_bookings_select").val());
  185. if ($("#multiple_bookings").val() == "custom") {
  186. $("#multiple_bookings_custom_div").show();
  187. }
  188. else {
  189. $("#multiple_bookings_custom_div").hide();
  190. }
  191. });
  192. $("#multiple_bookings_custom").bind ("change keypress keyup blur", function () {
  193. $("#multiple_bookings").val($("#multiple_bookings_custom").val());
  194. });
  195. });
  196. jQuery(function($){
  197. // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
  198. var entityMap={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};
  199. function escapeHtml(n){return String(n).replace(/[&<>"'`=\/]/g,function(n){return entityMap[n]})}
  200. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  201. function humanFileSize(i){if(Math.abs(i)<1024)return i+" B";var B=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],e=-1;do{i/=1024,++e}while(Math.abs(i)>=1024&&e<B.length-1);return i.toFixed(1)+" "+B[e]}
  202. function unix_time_format(i){return""==i?'<i class="bi bi-x-lg"></i>':new Date(i?1e3*i:0).toLocaleDateString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})}
  203. $(".refresh_table").on('click', function(e) {
  204. e.preventDefault();
  205. var table_name = $(this).data('table');
  206. $('#' + table_name).find("tr.footable-empty").remove();
  207. draw_table = $(this).data('draw');
  208. eval(draw_table + '()');
  209. });
  210. function table_mailbox_ready(ft, name) {
  211. if(is_dual) {
  212. $('.login_as').data("toggle", "tooltip")
  213. .attr("disabled", true)
  214. .removeAttr("href")
  215. .attr("title", "Dual login cannot be used twice")
  216. .tooltip();
  217. }
  218. $('.refresh_table').prop("disabled", false);
  219. heading = ft.$el.parents('.panel').find('.panel-heading')
  220. var ft_paging = ft.use(FooTable.Paging)
  221. $(heading).children('.table-lines').text(function(){
  222. var total_rows = ft_paging.totalRows;
  223. var size = ft_paging.size;
  224. if (size > total_rows) {
  225. size = total_rows;
  226. }
  227. return size + ' / ' + total_rows;
  228. })
  229. }
  230. function draw_domain_table() {
  231. ft_domain_table = FooTable.init('#domain_table', {
  232. "columns": [
  233. {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  234. {"sorted": true,"name":"domain_name","title":lang.domain,"style":{"width":"250px"}},
  235. {"name":"aliases","title":lang.aliases,"breakpoints":"xs sm"},
  236. {"name":"mailboxes","title":lang.mailboxes},
  237. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  238. res = value.split("/");
  239. return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
  240. },
  241. "sortValue": function(value){
  242. res = value.split("/");
  243. return Number(res[0]);
  244. }},
  245. {"name":"stats","sortable": false,"style":{"whiteSpace":"nowrap"},"title":lang.stats,"formatter": function(value){
  246. res = value.split("/");
  247. return '<i class="bi bi-files"></i> ' + res[0] + ' / ' + humanFileSize(res[1]);
  248. }},
  249. {"name":"def_quota_for_mbox","title":lang.mailbox_defquota,"breakpoints":"xs sm md","style":{"width":"125px"}},
  250. {"name":"max_quota_for_mbox","title":lang.mailbox_quota,"breakpoints":"xs sm","style":{"width":"125px"}},
  251. {"name":"rl","title":"RL","breakpoints":"xs sm md lg","style":{"maxWidth":"100px","width":"100px"}},
  252. {"name":"backupmx","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.backup_mx,"breakpoints":"xs sm md lg","formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
  253. {"name":"domain_admins","title":lang.domain_admins,"style":{"word-break":"break-all","min-width":"200px"},"breakpoints":"xs sm md lg","filterable":(role == "admin"),"visible":(role == "admin")},
  254. {"name":"xmpp","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":"XMPP","formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
  255. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
  256. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"240px","width":"240px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
  257. ],
  258. "rows": $.ajax({
  259. dataType: 'json',
  260. url: '/api/v1/get/domain/all',
  261. jsonp: false,
  262. error: function (data) {
  263. console.log('Cannot draw domain table');
  264. },
  265. success: function (data) {
  266. $.each(data, function (i, item) {
  267. item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
  268. item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
  269. item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain + "/" + item.bytes_total;
  270. item.stats = item.msgs_total + "/" + item.bytes_total;
  271. if (!item.rl) {
  272. item.rl = '∞';
  273. } else {
  274. item.rl = $.map(item.rl, function(e){
  275. return e;
  276. }).join('/1');
  277. }
  278. item.def_quota_for_mbox = humanFileSize(item.def_quota_for_mbox);
  279. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  280. item.chkbox = '<input type="checkbox" data-id="domain" name="multi_select" value="' + encodeURIComponent(item.domain_name) + '" />';
  281. item.action = '<div class="btn-group">';
  282. if (role == "admin") {
  283. item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  284. '<a href="#" data-action="delete_selected" data-id="single-domain" data-api-url="delete/domain" data-item="' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>';
  285. }
  286. else {
  287. item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>';
  288. }
  289. item.action += '<a href="#dnsInfoModal" class="btn btn-xs btn-info" data-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><i class="bi bi-globe2"></i> DNS</a></div>';
  290. if (item.backupmx == 1) {
  291. if (item.relay_unknown_only == 1) {
  292. item.domain_name = '<div class="label label-info">Relay Non-Local</div> ' + item.domain_name;
  293. } else if (item.relay_all_recipients == 1) {
  294. item.domain_name = '<div class="label label-info">Relay All</div> ' + item.domain_name;
  295. } else {
  296. item.domain_name = '<div class="label label-info">Relay</div> ' + item.domain_name;
  297. }
  298. }
  299. });
  300. }
  301. }),
  302. "empty": lang.empty,
  303. "paging": {
  304. "enabled": true,
  305. "limit": 5,
  306. "size": pagination_size
  307. },
  308. "state": {
  309. "enabled": true
  310. },
  311. "filtering": {
  312. "enabled": true,
  313. "delay": 1200,
  314. "position": "left",
  315. "connectors": false,
  316. "placeholder": lang.filter_table
  317. },
  318. "sorting": {
  319. "enabled": true
  320. },
  321. "on": {
  322. "destroy.ft.table": function(e, ft){
  323. $('.refresh_table').attr('disabled', 'true');
  324. },
  325. "ready.ft.table": function(e, ft){
  326. table_mailbox_ready(ft, 'domain_table');
  327. },
  328. "after.ft.filtering": function(e, ft){
  329. table_mailbox_ready(ft, 'domain_table');
  330. }
  331. },
  332. "toggleSelector": "table tbody span.footable-toggle"
  333. });
  334. }
  335. function draw_mailbox_table() {
  336. ft_mailbox_table = FooTable.init('#mailbox_table', {
  337. "columns": [
  338. {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  339. {"sorted": true,"name":"username","style":{"word-break":"break-all","min-width":"120px"},"title":lang.username},
  340. {"name":"name","title":lang.fname,"style":{"word-break":"break-all","min-width":"120px"},"breakpoints":"xs sm md lg"},
  341. {"name":"domain","title":lang.domain,"breakpoints":"xs sm md lg"},
  342. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  343. res = value.split("/");
  344. var of_q = (res[1] == 0 ? "∞" : humanFileSize(res[1]));
  345. return humanFileSize(res[0]) + " / " + of_q;
  346. },
  347. "sortValue": function(value){
  348. res = value.split("/");
  349. return Number(res[0]);
  350. },
  351. },
  352. /* {"name":"spam_aliases","filterable": false,"title":lang.spam_aliases,"breakpoints":"all"}, */
  353. {"name":"tls_enforce_in","filterable": false,"title":lang.tls_enforce_in,"breakpoints":"all"},
  354. {"name":"tls_enforce_out","filterable": false,"title":lang.tls_enforce_out,"breakpoints":"all"},
  355. {"name":"smtp_access","filterable": false,"title":"SMTP","breakpoints":"all"},
  356. {"name":"imap_access","filterable": false,"title":"IMAP","breakpoints":"all"},
  357. {"name":"pop3_access","filterable": false,"title":"POP3","breakpoints":"all"},
  358. {"name":"last_mail_login","breakpoints":"xs sm","title":lang.last_mail_login,"style":{"width":"170px"},
  359. "sortValue": function(value){
  360. res = value.split("/");
  361. return Math.max(res[0], res[1]);
  362. },
  363. "formatter": function(value){
  364. res = value.split("/");
  365. return '<div class="label label-last-login">IMAP @ ' + unix_time_format(Number(res[0])) + '</div><br>' +
  366. '<div class="label label-last-login">POP3 @ ' + unix_time_format(Number(res[1])) + '</div><br>' +
  367. '<div class="label label-last-login">SMTP @ ' + unix_time_format(Number(res[2])) + '</div>';
  368. }},
  369. {"name":"last_pw_change","filterable": false,"title":lang.last_pw_change,"breakpoints":"all"},
  370. {"name":"quarantine_notification","filterable": false,"title":lang.quarantine_notification,"breakpoints":"all"},
  371. {"name":"quarantine_category","filterable": false,"title":lang.quarantine_category,"breakpoints":"all"},
  372. {"name":"in_use","filterable": false,"type":"html","title":lang.in_use,"sortValue": function(value){
  373. return Number($(value).find(".progress-bar-mailbox").attr('aria-valuenow'));
  374. },
  375. },
  376. {"name":"messages","filterable": false,"title":lang.msg_num,"breakpoints":"xs sm md"},
  377. /* {"name":"rl","title":"RL","breakpoints":"all","style":{"width":"125px"}}, */
  378. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':(0==value?'<i class="bi bi-x-lg"></i>':2==value&&'&#8212;');}},
  379. {"name":"action","filterable": false,"sortable": false,"style":{"min-width":"290px","text-align":"right"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
  380. ],
  381. "empty": lang.empty,
  382. "rows": $.ajax({
  383. dataType: 'json',
  384. url: '/api/v1/get/mailbox/reduced',
  385. jsonp: false,
  386. error: function () {
  387. console.log('Cannot draw mailbox table');
  388. },
  389. success: function (data) {
  390. $.each(data, function (i, item) {
  391. item.quota = item.quota_used + "/" + item.quota;
  392. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  393. item.last_mail_login = item.last_imap_login + '/' + item.last_pop3_login + '/' + item.last_smtp_login;
  394. /*
  395. if (!item.rl) {
  396. item.rl = '∞';
  397. } else {
  398. item.rl = $.map(item.rl, function(e){
  399. return e;
  400. }).join('/1');
  401. if (item.rl_scope === 'domain') {
  402. item.rl = '<i class="bi bi-arrow-return-right"></i> ' + item.rl + ' (via ' + item.domain + ')';
  403. }
  404. }
  405. */
  406. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
  407. if (item.attributes.passwd_update != '0') {
  408. var last_pw_change = new Date(item.attributes.passwd_update.replace(/-/g, "/"));
  409. item.last_pw_change = last_pw_change.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
  410. } else {
  411. item.last_pw_change = '-';
  412. }
  413. item.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  414. item.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  415. item.pop3_access = '<i class="text-' + (item.attributes.pop3_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.pop3_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  416. item.imap_access = '<i class="text-' + (item.attributes.imap_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.imap_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  417. item.smtp_access = '<i class="text-' + (item.attributes.smtp_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.smtp_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  418. if (item.attributes.quarantine_notification === 'never') {
  419. item.quarantine_notification = lang.never;
  420. } else if (item.attributes.quarantine_notification === 'hourly') {
  421. item.quarantine_notification = lang.hourly;
  422. } else if (item.attributes.quarantine_notification === 'daily') {
  423. item.quarantine_notification = lang.daily;
  424. } else if (item.attributes.quarantine_notification === 'weekly') {
  425. item.quarantine_notification = lang.weekly;
  426. }
  427. if (item.attributes.quarantine_category === 'reject') {
  428. item.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
  429. } else if (item.attributes.quarantine_category === 'add_header') {
  430. item.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
  431. } else if (item.attributes.quarantine_category === 'all') {
  432. item.quarantine_category = lang.q_all;
  433. }
  434. if (acl_data.login_as === 1) {
  435. item.action = '<div class="btn-group">' +
  436. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  437. '<a href="#" data-action="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  438. '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="login_as btn btn-xs btn-success"><i class="bi bi-person-fill"></i> Login</a>';
  439. if (ALLOW_ADMIN_EMAIL_LOGIN) {
  440. item.action += '<a href="/sogo-auth.php?login=' + encodeURIComponent(item.username) + '" class="login_as btn btn-xs btn-primary" target="_blank"><i class="bi bi-envelope-fill"></i> SOGo</a>';
  441. }
  442. item.action += '</div>';
  443. }
  444. else {
  445. item.action = '<div class="btn-group">' +
  446. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  447. '<a href="#" data-action="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  448. '</div>';
  449. }
  450. item.in_use = '<div class="progress">' +
  451. '<div class="progress-bar-mailbox progress-bar progress-bar-' + item.percent_class + '" role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
  452. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  453. item.username = escapeHtml(item.username);
  454. });
  455. }
  456. }),
  457. "paging": {
  458. "enabled": true,
  459. "limit": 5,
  460. "size": pagination_size
  461. },
  462. "state": {
  463. "enabled": true
  464. },
  465. "filtering": {
  466. "enabled": true,
  467. "delay": 1200,
  468. "position": "left",
  469. "connectors": false,
  470. //"container": "#tab-mailboxes.panel",
  471. "placeholder": lang.filter_table
  472. },
  473. "components": {
  474. "filtering": FooTable.domainFilter
  475. },
  476. "sorting": {
  477. "enabled": true
  478. },
  479. "on": {
  480. "destroy.ft.table": function(e, ft){
  481. $('.refresh_table').attr('disabled', 'true');
  482. },
  483. "ready.ft.table": function(e, ft){
  484. table_mailbox_ready(ft, 'mailbox_table');
  485. },
  486. "after.ft.filtering": function(e, ft){
  487. table_mailbox_ready(ft, 'mailbox_table');
  488. }
  489. },
  490. "toggleSelector": "table tbody span.footable-toggle"
  491. });
  492. }
  493. function draw_resource_table() {
  494. ft_resource_table = FooTable.init('#resource_table', {
  495. "columns": [
  496. {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  497. {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
  498. {"name":"name","title":lang.alias},
  499. {"name":"kind","title":lang.kind},
  500. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  501. {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"150px","width":"140px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
  502. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
  503. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  504. ],
  505. "empty": lang.empty,
  506. "rows": $.ajax({
  507. dataType: 'json',
  508. url: '/api/v1/get/resource/all',
  509. jsonp: false,
  510. error: function () {
  511. console.log('Cannot draw resource table');
  512. },
  513. success: function (data) {
  514. $.each(data, function (i, item) {
  515. if (item.multiple_bookings == '0') {
  516. item.multiple_bookings = '<span id="active-script" class="label label-success">' + lang.booking_0_short + '</span>';
  517. } else if (item.multiple_bookings == '-1') {
  518. item.multiple_bookings = '<span id="active-script" class="label label-warning">' + lang.booking_lt0_short + '</span>';
  519. } else {
  520. item.multiple_bookings = '<span id="active-script" class="label label-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
  521. }
  522. item.action = '<div class="btn-group">' +
  523. '<a href="/edit/resource/' + encodeURIComponent(item.name) + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  524. '<a href="#" data-action="delete_selected" data-id="single-resource" data-api-url="delete/resource" data-item="' + item.name + '" class="btn btn-xs btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  525. '</div>';
  526. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
  527. item.name = escapeHtml(item.name);
  528. });
  529. }
  530. }),
  531. "paging": {
  532. "enabled": true,
  533. "limit": 5,
  534. "size": pagination_size
  535. },
  536. "state": {
  537. "enabled": true
  538. },
  539. "filtering": {
  540. "enabled": true,
  541. "delay": 1200,
  542. "position": "left",
  543. "connectors": false,
  544. "placeholder": lang.filter_table
  545. },
  546. "components": {
  547. "filtering": FooTable.domainFilter
  548. },
  549. "sorting": {
  550. "enabled": true
  551. },
  552. "on": {
  553. "destroy.ft.table": function(e, ft){
  554. $('.refresh_table').attr('disabled', 'true');
  555. },
  556. "ready.ft.table": function(e, ft){
  557. table_mailbox_ready(ft, 'resource_table');
  558. },
  559. "after.ft.filtering": function(e, ft){
  560. table_mailbox_ready(ft, 'resource_table');
  561. }
  562. },
  563. "toggleSelector": "table tbody span.footable-toggle"
  564. });
  565. }
  566. function draw_bcc_table() {
  567. ft_bcc_table = FooTable.init('#bcc_table', {
  568. "columns": [
  569. {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  570. {"sorted": true,"name":"id","title":"ID","style":{"min-width":"60px","width":"60px","text-align":"center"}},
  571. {"name":"type","title":lang.bcc_type},
  572. {"name":"local_dest","title":lang.bcc_local_dest},
  573. {"name":"bcc_dest","title":lang.bcc_destinations},
  574. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  575. {"name":"active","filterable": false,"style":{"min-width":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
  576. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  577. ],
  578. "empty": lang.empty,
  579. "rows": $.ajax({
  580. dataType: 'json',
  581. url: '/api/v1/get/bcc/all',
  582. jsonp: false,
  583. error: function () {
  584. console.log('Cannot draw bcc table');
  585. },
  586. success: function (data) {
  587. $.each(data, function (i, item) {
  588. item.action = '<div class="btn-group">' +
  589. '<a href="/edit/bcc/' + item.id + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  590. '<a href="#" data-action="delete_selected" data-id="single-bcc" data-api-url="delete/bcc" data-item="' + item.id + '" class="btn btn-xs btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  591. '</div>';
  592. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  593. item.local_dest = escapeHtml(item.local_dest);
  594. item.bcc_dest = escapeHtml(item.bcc_dest);
  595. if (item.type == 'sender') {
  596. item.type = '<span id="active-script" class="label label-success">Sender</span>';
  597. } else {
  598. item.type = '<span id="inactive-script" class="label label-warning">Recipient</span>';
  599. }
  600. });
  601. }
  602. }),
  603. "paging": {
  604. "enabled": true,
  605. "limit": 5,
  606. "size": pagination_size
  607. },
  608. "state": {
  609. "enabled": true
  610. },
  611. "filtering": {
  612. "enabled": true,
  613. "delay": 1200,
  614. "position": "left",
  615. "connectors": false,
  616. "placeholder": lang.filter_table
  617. },
  618. "sorting": {
  619. "enabled": true
  620. },
  621. "on": {
  622. "destroy.ft.table": function(e, ft){
  623. $('.refresh_table').attr('disabled', 'true');
  624. },
  625. "ready.ft.table": function(e, ft){
  626. table_mailbox_ready(ft, 'bcc_table');
  627. },
  628. "after.ft.filtering": function(e, ft){
  629. table_mailbox_ready(ft, 'bcc_table');
  630. }
  631. },
  632. "toggleSelector": "table tbody span.footable-toggle"
  633. });
  634. }
  635. function draw_recipient_map_table() {
  636. ft_recipient_map_table = FooTable.init('#recipient_map_table', {
  637. "columns": [
  638. {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  639. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  640. {"name":"recipient_map_old","title":lang.recipient_map_old},
  641. {"name":"recipient_map_new","title":lang.recipient_map_new},
  642. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
  643. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  644. ],
  645. "empty": lang.empty,
  646. "rows": $.ajax({
  647. dataType: 'json',
  648. url: '/api/v1/get/recipient_map/all',
  649. jsonp: false,
  650. error: function () {
  651. console.log('Cannot draw recipient map table');
  652. },
  653. success: function (data) {
  654. if (role == "admin") {
  655. $.each(data, function (i, item) {
  656. item.recipient_map_old = escapeHtml(item.recipient_map_old);
  657. item.recipient_map_new = escapeHtml(item.recipient_map_new);
  658. item.action = '<div class="btn-group">' +
  659. '<a href="/edit/recipient_map/' + item.id + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  660. '<a href="#" data-action="delete_selected" data-id="single-recipient_map" data-api-url="delete/recipient_map" data-item="' + item.id + '" class="btn btn-xs btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  661. '</div>';
  662. item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  663. });
  664. }
  665. }
  666. }),
  667. "paging": {
  668. "enabled": true,
  669. "limit": 5,
  670. "size": pagination_size
  671. },
  672. "state": {
  673. "enabled": true
  674. },
  675. "filtering": {
  676. "enabled": true,
  677. "delay": 1200,
  678. "position": "left",
  679. "connectors": false,
  680. "placeholder": lang.filter_table
  681. },
  682. "sorting": {
  683. "enabled": true
  684. },
  685. "on": {
  686. "destroy.ft.table": function(e, ft){
  687. $('.refresh_table').attr('disabled', 'true');
  688. },
  689. "ready.ft.table": function(e, ft){
  690. table_mailbox_ready(ft, 'recipient_map_table');
  691. },
  692. "after.ft.filtering": function(e, ft){
  693. table_mailbox_ready(ft, 'recipient_map_table');
  694. }
  695. },
  696. "toggleSelector": "table tbody span.footable-toggle"
  697. });
  698. }
  699. function draw_tls_policy_table() {
  700. ft_tls_policy_table = FooTable.init('#tls_policy_table', {
  701. "columns": [
  702. {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  703. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  704. {"name":"dest","title":lang.tls_map_dest},
  705. {"name":"policy","title":lang.tls_map_policy},
  706. {"name":"parameters","title":lang.tls_map_parameters},
  707. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
  708. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  709. ],
  710. "empty": lang.empty,
  711. "rows": $.ajax({
  712. dataType: 'json',
  713. url: '/api/v1/get/tls-policy-map/all',
  714. jsonp: false,
  715. error: function () {
  716. console.log('Cannot draw tls policy map table');
  717. },
  718. success: function (data) {
  719. if (role == "admin") {
  720. $.each(data, function (i, item) {
  721. item.dest = escapeHtml(item.dest);
  722. item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
  723. if (item.parameters == '') {
  724. item.parameters = '<code>-</code>';
  725. } else {
  726. item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
  727. }
  728. item.action = '<div class="btn-group">' +
  729. '<a href="/edit/tls_policy_map/' + item.id + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  730. '<a href="#" data-action="delete_selected" data-id="single-tls-policy-map" data-api-url="delete/tls-policy-map" data-item="' + item.id + '" class="btn btn-xs btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  731. '</div>';
  732. item.chkbox = '<input type="checkbox" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
  733. });
  734. }
  735. }
  736. }),
  737. "paging": {
  738. "enabled": true,
  739. "limit": 5,
  740. "size": pagination_size
  741. },
  742. "state": {
  743. "enabled": true
  744. },
  745. "filtering": {
  746. "enabled": true,
  747. "delay": 1200,
  748. "position": "left",
  749. "connectors": false,
  750. "placeholder": lang.filter_table
  751. },
  752. "sorting": {
  753. "enabled": true
  754. },
  755. "on": {
  756. "destroy.ft.table": function(e, ft){
  757. $('.refresh_table').attr('disabled', 'true');
  758. },
  759. "ready.ft.table": function(e, ft){
  760. table_mailbox_ready(ft, 'tls_policy_table');
  761. },
  762. "after.ft.filtering": function(e, ft){
  763. table_mailbox_ready(ft, 'tls_policy_table');
  764. }
  765. },
  766. "toggleSelector": "table tbody span.footable-toggle"
  767. });
  768. }
  769. function draw_alias_table() {
  770. ft_alias_table = FooTable.init('#alias_table', {
  771. "columns": [
  772. {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  773. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  774. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  775. {"name":"goto","title":lang.target_address},
  776. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  777. {"name":"public_comment","title":lang.public_comment,"breakpoints":"all"},
  778. {"name":"private_comment","title":lang.private_comment,"breakpoints":"all"},
  779. {"name":"sogo_visible","title":lang.sogo_visible,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';},"breakpoints":"all"},
  780. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
  781. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  782. ],
  783. "empty": lang.empty,
  784. "rows": $.ajax({
  785. dataType: 'json',
  786. url: '/api/v1/get/alias/all',
  787. jsonp: false,
  788. error: function () {
  789. console.log('Cannot draw alias table');
  790. },
  791. success: function (data) {
  792. $.each(data, function (i, item) {
  793. item.action = '<div class="btn-group">' +
  794. '<a href="/edit/alias/' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  795. '<a href="#" data-action="delete_selected" data-id="single-alias" data-api-url="delete/alias" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  796. '</div>';
  797. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  798. item.goto = escapeHtml(item.goto.replace(/,/g, " "));
  799. if (item.public_comment !== null) {
  800. item.public_comment = escapeHtml(item.public_comment);
  801. }
  802. else {
  803. item.public_comment = '-';
  804. }
  805. if (item.private_comment !== null) {
  806. item.private_comment = escapeHtml(item.private_comment);
  807. }
  808. else {
  809. item.private_comment = '-';
  810. }
  811. if (item.is_catch_all == 1) {
  812. item.address = '<div class="label label-default">Catch-All</div> ' + escapeHtml(item.address);
  813. }
  814. else {
  815. item.address = escapeHtml(item.address);
  816. }
  817. if (item.goto == "null@localhost") {
  818. item.goto = '⤷ <i class="bi bi-trash" style="font-size:12px"></i>';
  819. }
  820. else if (item.goto == "spam@localhost") {
  821. item.goto = '<span class="label label-danger">Learn as spam</span>';
  822. }
  823. else if (item.goto == "ham@localhost") {
  824. item.goto = '<span class="label label-success">Learn as ham</span>';
  825. }
  826. if (item.in_primary_domain !== "") {
  827. item.domain = '<i class="bi bi-info-circle-fill alias-domain-info text-info" data-toggle="tooltip" title="' + lang.target_domain + ': ' + item.in_primary_domain + '"></i> ' + item.domain;
  828. }
  829. });
  830. }
  831. }),
  832. "paging": {
  833. "enabled": true,
  834. "limit": 5,
  835. "size": pagination_size
  836. },
  837. "state": {
  838. "enabled": true
  839. },
  840. "filtering": {
  841. "enabled": true,
  842. "delay": 1200,
  843. "position": "left",
  844. "connectors": false,
  845. "placeholder": lang.filter_table
  846. },
  847. "components": {
  848. "filtering": FooTable.domainFilter
  849. },
  850. "sorting": {
  851. "enabled": true
  852. },
  853. "on": {
  854. "destroy.ft.table": function(e, ft){
  855. $('.refresh_table').attr('disabled', 'true');
  856. },
  857. "ready.ft.table": function(e, ft){
  858. table_mailbox_ready(ft, 'alias_table');
  859. $('.alias-domain-info').tooltip();
  860. },
  861. "after.ft.filtering": function(e, ft){
  862. table_mailbox_ready(ft, 'alias_table');
  863. }
  864. },
  865. "toggleSelector": "table tbody span.footable-toggle"
  866. });
  867. }
  868. function draw_aliasdomain_table() {
  869. ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
  870. "columns": [
  871. {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  872. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  873. {"name":"target_domain","title":lang.target_domain,"type":"html"},
  874. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
  875. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  876. ],
  877. "empty": lang.empty,
  878. "rows": $.ajax({
  879. dataType: 'json',
  880. url: '/api/v1/get/alias-domain/all',
  881. jsonp: false,
  882. error: function () {
  883. console.log('Cannot draw alias domain table');
  884. },
  885. success: function (data) {
  886. $.each(data, function (i, item) {
  887. item.action = '<div class="btn-group">' +
  888. '<a href="/edit/aliasdomain/' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  889. '<a href="#" data-action="delete_selected" data-id="single-alias-domain" data-api-url="delete/alias-domain" data-item="' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  890. '<a href="#dnsInfoModal" class="btn btn-xs btn-info" data-toggle="modal" data-domain="' + encodeURIComponent(item.alias_domain) + '"><i class="bi bi-question-lg"></i> DNS</a></div>' +
  891. '</div>';
  892. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
  893. if(item.parent_is_backupmx == '1') {
  894. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a> <div class="label label-warning">' + lang.alias_domain_backupmx + '</div></span>';
  895. } else {
  896. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
  897. }
  898. });
  899. }
  900. }),
  901. "paging": {
  902. "enabled": true,
  903. "limit": 5,
  904. "size": pagination_size
  905. },
  906. "state": {
  907. "enabled": true
  908. },
  909. "filtering": {
  910. "enabled": true,
  911. "delay": 1200,
  912. "position": "left",
  913. "connectors": false,
  914. "placeholder": lang.filter_table
  915. },
  916. "sorting": {
  917. "enabled": true
  918. },
  919. "on": {
  920. "destroy.ft.table": function(e, ft){
  921. $('.refresh_table').attr('disabled', 'true');
  922. },
  923. "ready.ft.table": function(e, ft){
  924. table_mailbox_ready(ft, 'aliasdomain_table');
  925. },
  926. "after.ft.filtering": function(e, ft){
  927. table_mailbox_ready(ft, 'aliasdomain_table');
  928. }
  929. },
  930. "toggleSelector": "table tbody span.footable-toggle"
  931. });
  932. }
  933. function draw_sync_job_table() {
  934. ft_syncjob_table = FooTable.init('#sync_job_table', {
  935. "columns": [
  936. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  937. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  938. {"name":"user2","title":lang.owner},
  939. {"name":"server_w_port","title":"Server","breakpoints":"xs sm md","style":{"word-break":"break-all"}},
  940. {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
  941. {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
  942. {"name":"last_run","title":lang.last_run,"breakpoints":"xs sm md"},
  943. {"name":"log","title":"Log"},
  944. {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
  945. {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
  946. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  947. ],
  948. "empty": lang.empty,
  949. "rows": $.ajax({
  950. dataType: 'json',
  951. url: '/api/v1/get/syncjobs/all/no_log',
  952. jsonp: false,
  953. error: function () {
  954. console.log('Cannot draw sync job table');
  955. },
  956. success: function (data) {
  957. $.each(data, function (i, item) {
  958. item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">Open logs</a>'
  959. item.user2 = escapeHtml(item.user2);
  960. if (!item.exclude > 0) {
  961. item.exclude = '-';
  962. } else {
  963. item.exclude = '<code>' + item.exclude + '</code>';
  964. }
  965. item.server_w_port = escapeHtml(item.user1) + '@' + item.host1 + ':' + item.port1;
  966. item.action = '<div class="btn-group">' +
  967. '<a href="/edit/syncjob/' + item.id + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  968. '<a href="#" data-action="delete_selected" data-id="single-syncjob" data-api-url="delete/syncjob" data-item="' + item.id + '" class="btn btn-xs btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  969. '</div>';
  970. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  971. if (item.is_running == 1) {
  972. item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
  973. } else {
  974. item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
  975. }
  976. if (!item.last_run > 0) {
  977. item.last_run = lang.waiting;
  978. }
  979. });
  980. }
  981. }),
  982. "paging": {
  983. "enabled": true,
  984. "limit": 5,
  985. "size": pagination_size
  986. },
  987. "state": {
  988. "enabled": true
  989. },
  990. "filtering": {
  991. "enabled": true,
  992. "delay": 1200,
  993. "position": "left",
  994. "connectors": false,
  995. "placeholder": lang.filter_table
  996. },
  997. "sorting": {
  998. "enabled": true
  999. },
  1000. "on": {
  1001. "destroy.ft.table": function(e, ft){
  1002. $('.refresh_table').attr('disabled', 'true');
  1003. },
  1004. "ready.ft.table": function(e, ft){
  1005. table_mailbox_ready(ft, 'sync_job_table');
  1006. },
  1007. "after.ft.filtering": function(e, ft){
  1008. table_mailbox_ready(ft, 'sync_job_table');
  1009. }
  1010. },
  1011. "toggleSelector": "table tbody span.footable-toggle"
  1012. });
  1013. }
  1014. function draw_filter_table() {
  1015. ft_filter_table = FooTable.init('#filter_table', {
  1016. "columns": [
  1017. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  1018. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  1019. {"name":"active","style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  1020. {"name":"filter_type","style":{"maxWidth":"80px","width":"80px"},"title":"Type"},
  1021. {"sorted": true,"name":"username","title":lang.owner,"style":{"maxWidth":"550px","width":"350px"}},
  1022. {"name":"script_desc","title":lang.description,"breakpoints":"xs"},
  1023. {"name":"script_data","title":"Script","breakpoints":"all"},
  1024. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  1025. ],
  1026. "empty": lang.empty,
  1027. "rows": $.ajax({
  1028. dataType: 'json',
  1029. url: '/api/v1/get/filters/all',
  1030. jsonp: false,
  1031. error: function () {
  1032. console.log('Cannot draw filter table');
  1033. },
  1034. success: function (data) {
  1035. $.each(data, function (i, item) {
  1036. if (item.active == 1) {
  1037. item.active = '<span id="active-script" class="label label-success">' + lang.active + '</span>';
  1038. } else {
  1039. item.active = '<span id="inactive-script" class="label label-warning">' + lang.inactive + '</span>';
  1040. }
  1041. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  1042. item.filter_type = '<div class="label label-default">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  1043. item.action = '<div class="btn-group">' +
  1044. '<a href="/edit/filter/' + item.id + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1045. '<a href="#" data-action="delete_selected" data-id="single-filter" data-api-url="delete/filter" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1046. '</div>';
  1047. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  1048. });
  1049. }
  1050. }),
  1051. "paging": {
  1052. "enabled": true,
  1053. "limit": 5,
  1054. "size": pagination_size
  1055. },
  1056. "state": {
  1057. "enabled": true
  1058. },
  1059. "filtering": {
  1060. "enabled": true,
  1061. "delay": 1200,
  1062. "position": "left",
  1063. "connectors": false,
  1064. "placeholder": lang.filter_table
  1065. },
  1066. "sorting": {
  1067. "enabled": true
  1068. },
  1069. "on": {
  1070. "destroy.ft.table": function(e, ft){
  1071. $('.refresh_table').attr('disabled', 'true');
  1072. },
  1073. "ready.ft.table": function(e, ft){
  1074. table_mailbox_ready(ft, 'filter_table');
  1075. },
  1076. "after.ft.filtering": function(e, ft){
  1077. table_mailbox_ready(ft, 'filter_table');
  1078. }
  1079. },
  1080. "toggleSelector": "table tbody span.footable-toggle"
  1081. });
  1082. };
  1083. $('body').on('click', 'span.footable-toggle', function () {
  1084. event.stopPropagation();
  1085. })
  1086. draw_domain_table();
  1087. draw_mailbox_table();
  1088. draw_resource_table();
  1089. draw_alias_table();
  1090. draw_aliasdomain_table();
  1091. draw_sync_job_table();
  1092. draw_filter_table();
  1093. draw_bcc_table();
  1094. draw_recipient_map_table();
  1095. draw_tls_policy_table();
  1096. });