mailbox.js 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  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":"quarantine_notification","filterable": false,"title":lang.quarantine_notification,"breakpoints":"all"},
  370. {"name":"quarantine_category","filterable": false,"title":lang.quarantine_category,"breakpoints":"all"},
  371. {"name":"in_use","filterable": false,"type":"html","title":lang.in_use,"sortValue": function(value){
  372. return Number($(value).find(".progress-bar-mailbox").attr('aria-valuenow'));
  373. },
  374. },
  375. {"name":"messages","filterable": false,"title":lang.msg_num,"breakpoints":"xs sm md"},
  376. /* {"name":"rl","title":"RL","breakpoints":"all","style":{"width":"125px"}}, */
  377. {"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;');}},
  378. {"name":"action","filterable": false,"sortable": false,"style":{"min-width":"290px","text-align":"right"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
  379. ],
  380. "empty": lang.empty,
  381. "rows": $.ajax({
  382. dataType: 'json',
  383. url: '/api/v1/get/mailbox/reduced',
  384. jsonp: false,
  385. error: function () {
  386. console.log('Cannot draw mailbox table');
  387. },
  388. success: function (data) {
  389. $.each(data, function (i, item) {
  390. item.quota = item.quota_used + "/" + item.quota;
  391. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  392. item.last_mail_login = item.last_imap_login + '/' + item.last_pop3_login + '/' + item.last_smtp_login;
  393. /*
  394. if (!item.rl) {
  395. item.rl = '∞';
  396. } else {
  397. item.rl = $.map(item.rl, function(e){
  398. return e;
  399. }).join('/1');
  400. if (item.rl_scope === 'domain') {
  401. item.rl = '<i class="bi bi-arrow-return-right"></i> ' + item.rl + ' (via ' + item.domain + ')';
  402. }
  403. }
  404. */
  405. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
  406. item.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  407. item.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  408. 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>';
  409. 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>';
  410. 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>';
  411. if (item.attributes.quarantine_notification === 'never') {
  412. item.quarantine_notification = lang.never;
  413. } else if (item.attributes.quarantine_notification === 'hourly') {
  414. item.quarantine_notification = lang.hourly;
  415. } else if (item.attributes.quarantine_notification === 'daily') {
  416. item.quarantine_notification = lang.daily;
  417. } else if (item.attributes.quarantine_notification === 'weekly') {
  418. item.quarantine_notification = lang.weekly;
  419. }
  420. if (item.attributes.quarantine_category === 'reject') {
  421. item.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
  422. } else if (item.attributes.quarantine_category === 'add_header') {
  423. item.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
  424. } else if (item.attributes.quarantine_category === 'all') {
  425. item.quarantine_category = lang.q_all;
  426. }
  427. if (acl_data.login_as === 1) {
  428. item.action = '<div class="btn-group">' +
  429. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  430. '<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>' +
  431. '<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>';
  432. if (ALLOW_ADMIN_EMAIL_LOGIN) {
  433. 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>';
  434. }
  435. item.action += '</div>';
  436. }
  437. else {
  438. item.action = '<div class="btn-group">' +
  439. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  440. '<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>' +
  441. '</div>';
  442. }
  443. item.in_use = '<div class="progress">' +
  444. '<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" ' +
  445. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  446. item.username = escapeHtml(item.username);
  447. });
  448. }
  449. }),
  450. "paging": {
  451. "enabled": true,
  452. "limit": 5,
  453. "size": pagination_size
  454. },
  455. "state": {
  456. "enabled": true
  457. },
  458. "filtering": {
  459. "enabled": true,
  460. "delay": 1200,
  461. "position": "left",
  462. "connectors": false,
  463. //"container": "#tab-mailboxes.panel",
  464. "placeholder": lang.filter_table
  465. },
  466. "components": {
  467. "filtering": FooTable.domainFilter
  468. },
  469. "sorting": {
  470. "enabled": true
  471. },
  472. "on": {
  473. "destroy.ft.table": function(e, ft){
  474. $('.refresh_table').attr('disabled', 'true');
  475. },
  476. "ready.ft.table": function(e, ft){
  477. table_mailbox_ready(ft, 'mailbox_table');
  478. },
  479. "after.ft.filtering": function(e, ft){
  480. table_mailbox_ready(ft, 'mailbox_table');
  481. }
  482. },
  483. "toggleSelector": "table tbody span.footable-toggle"
  484. });
  485. }
  486. function draw_resource_table() {
  487. ft_resource_table = FooTable.init('#resource_table', {
  488. "columns": [
  489. {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  490. {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
  491. {"name":"name","title":lang.alias},
  492. {"name":"kind","title":lang.kind},
  493. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  494. {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"150px","width":"140px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
  495. {"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>';}},
  496. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  497. ],
  498. "empty": lang.empty,
  499. "rows": $.ajax({
  500. dataType: 'json',
  501. url: '/api/v1/get/resource/all',
  502. jsonp: false,
  503. error: function () {
  504. console.log('Cannot draw resource table');
  505. },
  506. success: function (data) {
  507. $.each(data, function (i, item) {
  508. if (item.multiple_bookings == '0') {
  509. item.multiple_bookings = '<span id="active-script" class="label label-success">' + lang.booking_0_short + '</span>';
  510. } else if (item.multiple_bookings == '-1') {
  511. item.multiple_bookings = '<span id="active-script" class="label label-warning">' + lang.booking_lt0_short + '</span>';
  512. } else {
  513. item.multiple_bookings = '<span id="active-script" class="label label-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
  514. }
  515. item.action = '<div class="btn-group">' +
  516. '<a href="/edit/resource/' + encodeURIComponent(item.name) + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  517. '<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>' +
  518. '</div>';
  519. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
  520. item.name = escapeHtml(item.name);
  521. });
  522. }
  523. }),
  524. "paging": {
  525. "enabled": true,
  526. "limit": 5,
  527. "size": pagination_size
  528. },
  529. "state": {
  530. "enabled": true
  531. },
  532. "filtering": {
  533. "enabled": true,
  534. "delay": 1200,
  535. "position": "left",
  536. "connectors": false,
  537. "placeholder": lang.filter_table
  538. },
  539. "components": {
  540. "filtering": FooTable.domainFilter
  541. },
  542. "sorting": {
  543. "enabled": true
  544. },
  545. "on": {
  546. "destroy.ft.table": function(e, ft){
  547. $('.refresh_table').attr('disabled', 'true');
  548. },
  549. "ready.ft.table": function(e, ft){
  550. table_mailbox_ready(ft, 'resource_table');
  551. },
  552. "after.ft.filtering": function(e, ft){
  553. table_mailbox_ready(ft, 'resource_table');
  554. }
  555. },
  556. "toggleSelector": "table tbody span.footable-toggle"
  557. });
  558. }
  559. function draw_bcc_table() {
  560. ft_bcc_table = FooTable.init('#bcc_table', {
  561. "columns": [
  562. {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  563. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  564. {"name":"type","title":lang.bcc_type},
  565. {"name":"local_dest","title":lang.bcc_local_dest},
  566. {"name":"bcc_dest","title":lang.bcc_destinations},
  567. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  568. {"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>';}},
  569. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  570. ],
  571. "empty": lang.empty,
  572. "rows": $.ajax({
  573. dataType: 'json',
  574. url: '/api/v1/get/bcc/all',
  575. jsonp: false,
  576. error: function () {
  577. console.log('Cannot draw bcc table');
  578. },
  579. success: function (data) {
  580. $.each(data, function (i, item) {
  581. item.action = '<div class="btn-group">' +
  582. '<a href="/edit/bcc/' + item.id + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  583. '<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>' +
  584. '</div>';
  585. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  586. item.local_dest = escapeHtml(item.local_dest);
  587. item.bcc_dest = escapeHtml(item.bcc_dest);
  588. if (item.type == 'sender') {
  589. item.type = '<span id="active-script" class="label label-success">Sender</span>';
  590. } else {
  591. item.type = '<span id="inactive-script" class="label label-warning">Recipient</span>';
  592. }
  593. });
  594. }
  595. }),
  596. "paging": {
  597. "enabled": true,
  598. "limit": 5,
  599. "size": pagination_size
  600. },
  601. "state": {
  602. "enabled": true
  603. },
  604. "filtering": {
  605. "enabled": true,
  606. "delay": 1200,
  607. "position": "left",
  608. "connectors": false,
  609. "placeholder": lang.filter_table
  610. },
  611. "sorting": {
  612. "enabled": true
  613. },
  614. "on": {
  615. "destroy.ft.table": function(e, ft){
  616. $('.refresh_table').attr('disabled', 'true');
  617. },
  618. "ready.ft.table": function(e, ft){
  619. table_mailbox_ready(ft, 'bcc_table');
  620. },
  621. "after.ft.filtering": function(e, ft){
  622. table_mailbox_ready(ft, 'bcc_table');
  623. }
  624. },
  625. "toggleSelector": "table tbody span.footable-toggle"
  626. });
  627. }
  628. function draw_recipient_map_table() {
  629. ft_recipient_map_table = FooTable.init('#recipient_map_table', {
  630. "columns": [
  631. {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  632. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  633. {"name":"recipient_map_old","title":lang.recipient_map_old},
  634. {"name":"recipient_map_new","title":lang.recipient_map_new},
  635. {"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>';}},
  636. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  637. ],
  638. "empty": lang.empty,
  639. "rows": $.ajax({
  640. dataType: 'json',
  641. url: '/api/v1/get/recipient_map/all',
  642. jsonp: false,
  643. error: function () {
  644. console.log('Cannot draw recipient map table');
  645. },
  646. success: function (data) {
  647. if (role == "admin") {
  648. $.each(data, function (i, item) {
  649. item.recipient_map_old = escapeHtml(item.recipient_map_old);
  650. item.recipient_map_new = escapeHtml(item.recipient_map_new);
  651. item.action = '<div class="btn-group">' +
  652. '<a href="/edit/recipient_map/' + item.id + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  653. '<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>' +
  654. '</div>';
  655. item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  656. });
  657. }
  658. }
  659. }),
  660. "paging": {
  661. "enabled": true,
  662. "limit": 5,
  663. "size": pagination_size
  664. },
  665. "state": {
  666. "enabled": true
  667. },
  668. "filtering": {
  669. "enabled": true,
  670. "delay": 1200,
  671. "position": "left",
  672. "connectors": false,
  673. "placeholder": lang.filter_table
  674. },
  675. "sorting": {
  676. "enabled": true
  677. },
  678. "on": {
  679. "destroy.ft.table": function(e, ft){
  680. $('.refresh_table').attr('disabled', 'true');
  681. },
  682. "ready.ft.table": function(e, ft){
  683. table_mailbox_ready(ft, 'recipient_map_table');
  684. },
  685. "after.ft.filtering": function(e, ft){
  686. table_mailbox_ready(ft, 'recipient_map_table');
  687. }
  688. },
  689. "toggleSelector": "table tbody span.footable-toggle"
  690. });
  691. }
  692. function draw_tls_policy_table() {
  693. ft_tls_policy_table = FooTable.init('#tls_policy_table', {
  694. "columns": [
  695. {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  696. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  697. {"name":"dest","title":lang.tls_map_dest},
  698. {"name":"policy","title":lang.tls_map_policy},
  699. {"name":"parameters","title":lang.tls_map_parameters},
  700. {"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>';}},
  701. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  702. ],
  703. "empty": lang.empty,
  704. "rows": $.ajax({
  705. dataType: 'json',
  706. url: '/api/v1/get/tls-policy-map/all',
  707. jsonp: false,
  708. error: function () {
  709. console.log('Cannot draw tls policy map table');
  710. },
  711. success: function (data) {
  712. if (role == "admin") {
  713. $.each(data, function (i, item) {
  714. item.dest = escapeHtml(item.dest);
  715. item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
  716. if (item.parameters == '') {
  717. item.parameters = '<code>-</code>';
  718. } else {
  719. item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
  720. }
  721. item.action = '<div class="btn-group">' +
  722. '<a href="/edit/tls_policy_map/' + item.id + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  723. '<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>' +
  724. '</div>';
  725. item.chkbox = '<input type="checkbox" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
  726. });
  727. }
  728. }
  729. }),
  730. "paging": {
  731. "enabled": true,
  732. "limit": 5,
  733. "size": pagination_size
  734. },
  735. "state": {
  736. "enabled": true
  737. },
  738. "filtering": {
  739. "enabled": true,
  740. "delay": 1200,
  741. "position": "left",
  742. "connectors": false,
  743. "placeholder": lang.filter_table
  744. },
  745. "sorting": {
  746. "enabled": true
  747. },
  748. "on": {
  749. "destroy.ft.table": function(e, ft){
  750. $('.refresh_table').attr('disabled', 'true');
  751. },
  752. "ready.ft.table": function(e, ft){
  753. table_mailbox_ready(ft, 'tls_policy_table');
  754. },
  755. "after.ft.filtering": function(e, ft){
  756. table_mailbox_ready(ft, 'tls_policy_table');
  757. }
  758. },
  759. "toggleSelector": "table tbody span.footable-toggle"
  760. });
  761. }
  762. function draw_alias_table() {
  763. ft_alias_table = FooTable.init('#alias_table', {
  764. "columns": [
  765. {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  766. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  767. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  768. {"name":"goto","title":lang.target_address},
  769. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  770. {"name":"public_comment","title":lang.public_comment,"breakpoints":"all"},
  771. {"name":"private_comment","title":lang.private_comment,"breakpoints":"all"},
  772. {"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"},
  773. {"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>';}},
  774. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  775. ],
  776. "empty": lang.empty,
  777. "rows": $.ajax({
  778. dataType: 'json',
  779. url: '/api/v1/get/alias/all',
  780. jsonp: false,
  781. error: function () {
  782. console.log('Cannot draw alias table');
  783. },
  784. success: function (data) {
  785. $.each(data, function (i, item) {
  786. item.action = '<div class="btn-group">' +
  787. '<a href="/edit/alias/' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  788. '<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>' +
  789. '</div>';
  790. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  791. item.goto = escapeHtml(item.goto.replace(/,/g, " "));
  792. if (item.public_comment !== null) {
  793. item.public_comment = escapeHtml(item.public_comment);
  794. }
  795. else {
  796. item.public_comment = '-';
  797. }
  798. if (item.private_comment !== null) {
  799. item.private_comment = escapeHtml(item.private_comment);
  800. }
  801. else {
  802. item.private_comment = '-';
  803. }
  804. if (item.is_catch_all == 1) {
  805. item.address = '<div class="label label-default">Catch-All</div> ' + escapeHtml(item.address);
  806. }
  807. else {
  808. item.address = escapeHtml(item.address);
  809. }
  810. if (item.goto == "null@localhost") {
  811. item.goto = '⤷ <i class="bi bi-trash" style="font-size:12px"></i>';
  812. }
  813. else if (item.goto == "spam@localhost") {
  814. item.goto = '<span class="label label-danger">Learn as spam</span>';
  815. }
  816. else if (item.goto == "ham@localhost") {
  817. item.goto = '<span class="label label-success">Learn as ham</span>';
  818. }
  819. if (item.in_primary_domain !== "") {
  820. 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;
  821. }
  822. });
  823. }
  824. }),
  825. "paging": {
  826. "enabled": true,
  827. "limit": 5,
  828. "size": pagination_size
  829. },
  830. "state": {
  831. "enabled": true
  832. },
  833. "filtering": {
  834. "enabled": true,
  835. "delay": 1200,
  836. "position": "left",
  837. "connectors": false,
  838. "placeholder": lang.filter_table
  839. },
  840. "components": {
  841. "filtering": FooTable.domainFilter
  842. },
  843. "sorting": {
  844. "enabled": true
  845. },
  846. "on": {
  847. "destroy.ft.table": function(e, ft){
  848. $('.refresh_table').attr('disabled', 'true');
  849. },
  850. "ready.ft.table": function(e, ft){
  851. table_mailbox_ready(ft, 'alias_table');
  852. $('.alias-domain-info').tooltip();
  853. },
  854. "after.ft.filtering": function(e, ft){
  855. table_mailbox_ready(ft, 'alias_table');
  856. }
  857. },
  858. "toggleSelector": "table tbody span.footable-toggle"
  859. });
  860. }
  861. function draw_aliasdomain_table() {
  862. ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
  863. "columns": [
  864. {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  865. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  866. {"name":"target_domain","title":lang.target_domain,"type":"html"},
  867. {"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>';}},
  868. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  869. ],
  870. "empty": lang.empty,
  871. "rows": $.ajax({
  872. dataType: 'json',
  873. url: '/api/v1/get/alias-domain/all',
  874. jsonp: false,
  875. error: function () {
  876. console.log('Cannot draw alias domain table');
  877. },
  878. success: function (data) {
  879. $.each(data, function (i, item) {
  880. item.action = '<div class="btn-group">' +
  881. '<a href="/edit/aliasdomain/' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  882. '<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>' +
  883. '<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>' +
  884. '</div>';
  885. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
  886. if(item.parent_is_backupmx == '1') {
  887. 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>';
  888. } else {
  889. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
  890. }
  891. });
  892. }
  893. }),
  894. "paging": {
  895. "enabled": true,
  896. "limit": 5,
  897. "size": pagination_size
  898. },
  899. "state": {
  900. "enabled": true
  901. },
  902. "filtering": {
  903. "enabled": true,
  904. "delay": 1200,
  905. "position": "left",
  906. "connectors": false,
  907. "placeholder": lang.filter_table
  908. },
  909. "sorting": {
  910. "enabled": true
  911. },
  912. "on": {
  913. "destroy.ft.table": function(e, ft){
  914. $('.refresh_table').attr('disabled', 'true');
  915. },
  916. "ready.ft.table": function(e, ft){
  917. table_mailbox_ready(ft, 'aliasdomain_table');
  918. },
  919. "after.ft.filtering": function(e, ft){
  920. table_mailbox_ready(ft, 'aliasdomain_table');
  921. }
  922. },
  923. "toggleSelector": "table tbody span.footable-toggle"
  924. });
  925. }
  926. function draw_sync_job_table() {
  927. ft_syncjob_table = FooTable.init('#sync_job_table', {
  928. "columns": [
  929. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  930. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  931. {"name":"user2","title":lang.owner},
  932. {"name":"server_w_port","title":"Server","breakpoints":"xs sm md","style":{"word-break":"break-all"}},
  933. {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
  934. {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
  935. {"name":"last_run","title":lang.last_run,"breakpoints":"xs sm md"},
  936. {"name":"log","title":"Log"},
  937. {"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>';}},
  938. {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
  939. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  940. ],
  941. "empty": lang.empty,
  942. "rows": $.ajax({
  943. dataType: 'json',
  944. url: '/api/v1/get/syncjobs/all/no_log',
  945. jsonp: false,
  946. error: function () {
  947. console.log('Cannot draw sync job table');
  948. },
  949. success: function (data) {
  950. $.each(data, function (i, item) {
  951. item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">Open logs</a>'
  952. item.user2 = escapeHtml(item.user2);
  953. if (!item.exclude > 0) {
  954. item.exclude = '-';
  955. } else {
  956. item.exclude = '<code>' + item.exclude + '</code>';
  957. }
  958. item.server_w_port = escapeHtml(item.user1) + '@' + item.host1 + ':' + item.port1;
  959. item.action = '<div class="btn-group">' +
  960. '<a href="/edit/syncjob/' + item.id + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  961. '<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>' +
  962. '</div>';
  963. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  964. if (item.is_running == 1) {
  965. item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
  966. } else {
  967. item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
  968. }
  969. if (!item.last_run > 0) {
  970. item.last_run = lang.waiting;
  971. }
  972. });
  973. }
  974. }),
  975. "paging": {
  976. "enabled": true,
  977. "limit": 5,
  978. "size": pagination_size
  979. },
  980. "state": {
  981. "enabled": true
  982. },
  983. "filtering": {
  984. "enabled": true,
  985. "delay": 1200,
  986. "position": "left",
  987. "connectors": false,
  988. "placeholder": lang.filter_table
  989. },
  990. "sorting": {
  991. "enabled": true
  992. },
  993. "on": {
  994. "destroy.ft.table": function(e, ft){
  995. $('.refresh_table').attr('disabled', 'true');
  996. },
  997. "ready.ft.table": function(e, ft){
  998. table_mailbox_ready(ft, 'sync_job_table');
  999. },
  1000. "after.ft.filtering": function(e, ft){
  1001. table_mailbox_ready(ft, 'sync_job_table');
  1002. }
  1003. },
  1004. "toggleSelector": "table tbody span.footable-toggle"
  1005. });
  1006. }
  1007. function draw_filter_table() {
  1008. ft_filter_table = FooTable.init('#filter_table', {
  1009. "columns": [
  1010. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  1011. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  1012. {"name":"active","style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  1013. {"name":"filter_type","style":{"maxWidth":"80px","width":"80px"},"title":"Type"},
  1014. {"sorted": true,"name":"username","title":lang.owner,"style":{"maxWidth":"550px","width":"350px"}},
  1015. {"name":"script_desc","title":lang.description,"breakpoints":"xs"},
  1016. {"name":"script_data","title":"Script","breakpoints":"all"},
  1017. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  1018. ],
  1019. "empty": lang.empty,
  1020. "rows": $.ajax({
  1021. dataType: 'json',
  1022. url: '/api/v1/get/filters/all',
  1023. jsonp: false,
  1024. error: function () {
  1025. console.log('Cannot draw filter table');
  1026. },
  1027. success: function (data) {
  1028. $.each(data, function (i, item) {
  1029. if (item.active == 1) {
  1030. item.active = '<span id="active-script" class="label label-success">' + lang.active + '</span>';
  1031. } else {
  1032. item.active = '<span id="inactive-script" class="label label-warning">' + lang.inactive + '</span>';
  1033. }
  1034. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  1035. item.filter_type = '<div class="label label-default">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  1036. item.action = '<div class="btn-group">' +
  1037. '<a href="/edit/filter/' + item.id + '" class="btn btn-xs btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1038. '<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>' +
  1039. '</div>';
  1040. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  1041. });
  1042. }
  1043. }),
  1044. "paging": {
  1045. "enabled": true,
  1046. "limit": 5,
  1047. "size": pagination_size
  1048. },
  1049. "state": {
  1050. "enabled": true
  1051. },
  1052. "filtering": {
  1053. "enabled": true,
  1054. "delay": 1200,
  1055. "position": "left",
  1056. "connectors": false,
  1057. "placeholder": lang.filter_table
  1058. },
  1059. "sorting": {
  1060. "enabled": true
  1061. },
  1062. "on": {
  1063. "destroy.ft.table": function(e, ft){
  1064. $('.refresh_table').attr('disabled', 'true');
  1065. },
  1066. "ready.ft.table": function(e, ft){
  1067. table_mailbox_ready(ft, 'filter_table');
  1068. },
  1069. "after.ft.filtering": function(e, ft){
  1070. table_mailbox_ready(ft, 'filter_table');
  1071. }
  1072. },
  1073. "toggleSelector": "table tbody span.footable-toggle"
  1074. });
  1075. };
  1076. $('body').on('click', 'span.footable-toggle', function () {
  1077. event.stopPropagation();
  1078. })
  1079. draw_domain_table();
  1080. draw_mailbox_table();
  1081. draw_resource_table();
  1082. draw_alias_table();
  1083. draw_aliasdomain_table();
  1084. draw_sync_job_table();
  1085. draw_filter_table();
  1086. draw_bcc_table();
  1087. draw_recipient_map_table();
  1088. draw_tls_policy_table();
  1089. });