mailbox.js 52 KB

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