mailbox.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. $(document).ready(function() {
  2. FooTable.domainFilter = FooTable.Filtering.extend({
  3. construct: function(instance){
  4. this._super(instance);
  5. var domain_list = [];
  6. $.ajax({
  7. dataType: 'json',
  8. 'async': false,
  9. url: '/api/v1/get/domain/all',
  10. jsonp: false,
  11. error: function () {
  12. domain_list.push('Cannot read domain list');
  13. },
  14. success: function (data) {
  15. $.each(data, function (i, item) {
  16. domain_list.push(item.domain_name);
  17. });
  18. }
  19. });
  20. this.domains = domain_list;
  21. this.def = 'All Domains';
  22. this.$domain = null;
  23. },
  24. $create: function(){
  25. this._super();
  26. var self = this,
  27. $form_grp = $('<div/>', {'class': 'form-group'})
  28. .append($('<label/>', {'class': 'sr-only', text: 'Domain'}))
  29. .prependTo(self.$form);
  30. self.$domain = $('<select/>', { 'class': 'form-control' })
  31. .on('change', {self: self}, self._onDomainDropdownChanged)
  32. .append($('<option/>', {text: self.def}))
  33. .appendTo($form_grp);
  34. $.each(self.domains, function(i, domain){
  35. self.$domain.append($('<option/>').text(domain));
  36. });
  37. },
  38. _onDomainDropdownChanged: function(e){
  39. var self = e.data.self,
  40. selected = $(this).val();
  41. if (selected !== self.def){
  42. self.addFilter('domain', selected, ['domain']);
  43. } else {
  44. self.removeFilter('domain');
  45. }
  46. self.filter();
  47. },
  48. draw: function(){
  49. this._super();
  50. var domain = this.find('domain');
  51. if (domain instanceof FooTable.Filter){
  52. this.$domain.val(domain.query.val());
  53. } else {
  54. this.$domain.val(this.def);
  55. }
  56. $(this.$domain).closest("select").selectpicker();
  57. }
  58. });
  59. // Auto-fill domain quota when adding new domain
  60. auto_fill_quota = function(domain) {
  61. $.get("/api/v1/get/domain/" + domain, function(data){
  62. var result = $.parseJSON(JSON.stringify(data));
  63. max_new_mailbox_quota = ( result.max_new_mailbox_quota / 1048576);
  64. if (max_new_mailbox_quota != '0') {
  65. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  66. $('#addInputQuota').attr({"disabled": false, "value": "", "type": "number", "max": max_new_mailbox_quota});
  67. $('#addInputQuota').val(max_new_mailbox_quota);
  68. }
  69. else {
  70. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  71. $('#addInputQuota').attr({"disabled": true, "value": "", "type": "text", "value": "n/a"});
  72. $('#addInputQuota').val(max_new_mailbox_quota);
  73. }
  74. });
  75. }
  76. $('#addSelectDomain').on('change', function() {
  77. auto_fill_quota($('#addSelectDomain').val());
  78. });
  79. auto_fill_quota($('#addSelectDomain').val());
  80. $(".generate_password").click(function( event ) {
  81. event.preventDefault();
  82. var random_passwd = Math.random().toString(36).slice(-8)
  83. $('#password').prop('type', 'text');
  84. $('#password').val(random_passwd);
  85. $('#password2').prop('type', 'text');
  86. $('#password2').val(random_passwd);
  87. });
  88. $(".goto_checkbox").click(function( event ) {
  89. $("form[data-id='add_alias'] .goto_checkbox").not(this).prop('checked', false);
  90. if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
  91. $('#textarea_alias_goto').prop('disabled', true);
  92. }
  93. else {
  94. $("#textarea_alias_goto").removeAttr('disabled');
  95. }
  96. });
  97. $('#addAliasModal').on('show.bs.modal', function(e) {
  98. if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
  99. $('#textarea_alias_goto').prop('disabled', true);
  100. }
  101. else {
  102. $("#textarea_alias_goto").removeAttr('disabled');
  103. }
  104. });
  105. // Log modal
  106. $('#syncjobLogModal').on('show.bs.modal', function(e) {
  107. var syncjob_id = $(e.relatedTarget).data('syncjob-id');
  108. $.ajax({
  109. url: '/inc/ajax/syncjob_logs.php',
  110. data: { id: syncjob_id },
  111. dataType: 'text',
  112. success: function(data){
  113. $(e.currentTarget).find('#logText').text(data);
  114. },
  115. error: function(xhr, status, error) {
  116. $(e.currentTarget).find('#logText').text(xhr.responseText);
  117. }
  118. });
  119. });
  120. // Log modal
  121. $('#dnsInfoModal').on('show.bs.modal', function(e) {
  122. var domain = $(e.relatedTarget).data('domain');
  123. $('.dns-modal-body').html('<center><span style="font-size:18pt;margin:50px" class="glyphicon glyphicon-refresh glyphicon-spin"></span></center>');
  124. $.ajax({
  125. url: '/inc/ajax/dns_diagnostics.php',
  126. data: { domain: domain },
  127. dataType: 'text',
  128. success: function(data){
  129. $('.dns-modal-body').html(data);
  130. },
  131. error: function(xhr, status, error) {
  132. $('.dns-modal-body').html(xhr.responseText);
  133. }
  134. });
  135. });
  136. // Sieve data modal
  137. $('#sieveDataModal').on('show.bs.modal', function(e) {
  138. var sieveScript = $(e.relatedTarget).data('sieve-script');
  139. $(e.currentTarget).find('#sieveDataText').html('<pre style="font-size:14px;line-height:1.1">' + sieveScript + '</pre>');
  140. });
  141. // Set line numbers for textarea
  142. $("#script_data").numberedtextarea({allowTabChar: true});
  143. // Disable submit button on script change
  144. $('#script_data').on('keyup', function() {
  145. $('#add_filter_btns > #add_item').attr({"disabled": true});
  146. $('#validation_msg').html('-');
  147. });
  148. // Validate script data
  149. $("#validate_sieve").click(function( event ) {
  150. event.preventDefault();
  151. var script = $('#script_data').val();
  152. $.ajax({
  153. dataType: 'jsonp',
  154. url: "/inc/ajax/sieve_validation.php",
  155. type: "get",
  156. data: { script: script },
  157. complete: function(data) {
  158. var response = (data.responseText);
  159. response_obj = JSON.parse(response);
  160. if (response_obj.type == "success") {
  161. $('#add_filter_btns > #add_item').attr({"disabled": false});
  162. }
  163. mailcow_alert_box(response_obj.msg, response_obj.type);
  164. },
  165. });
  166. });
  167. // $(document).on('DOMNodeInserted', '#prefilter_table', function () {
  168. // $("#active-script").closest('td').css('background-color','#b0f0a0');
  169. // $("#inactive-script").closest('td').css('background-color','#b0f0a0');
  170. // });
  171. });
  172. jQuery(function($){
  173. // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
  174. var entityMap = {
  175. '&': '&amp;',
  176. '<': '&lt;',
  177. '>': '&gt;',
  178. '"': '&quot;',
  179. "'": '&#39;',
  180. '/': '&#x2F;',
  181. '`': '&#x60;',
  182. '=': '&#x3D;'
  183. };
  184. function escapeHtml(string) {
  185. return String(string).replace(/[&<>"'`=\/]/g, function (s) {
  186. return entityMap[s];
  187. });
  188. }
  189. if (localStorage.getItem("current_page") === null) {
  190. var current_page = {};
  191. } else {
  192. var current_page = JSON.parse(localStorage.getItem('current_page'));
  193. }
  194. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  195. function validateEmail(email) {
  196. var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  197. return re.test(email);
  198. }
  199. // Calculation human readable file sizes
  200. function humanFileSize(bytes) {
  201. if(Math.abs(bytes) < 1024) {
  202. return bytes + ' B';
  203. }
  204. var units = ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
  205. var u = -1;
  206. do {
  207. bytes /= 1024;
  208. ++u;
  209. } while(Math.abs(bytes) >= 1024 && u < units.length - 1);
  210. return bytes.toFixed(1)+' '+units[u];
  211. }
  212. function unix_time_format(tm) {
  213. var date = new Date(tm ? tm * 1000 : 0);
  214. return date.toLocaleString();
  215. }
  216. $(".refresh_table").on('click', function(e) {
  217. e.preventDefault();
  218. var table_name = $(this).data('table');
  219. $('#' + table_name).find("tr.footable-empty").remove();
  220. draw_table = $(this).data('draw');
  221. eval(draw_table + '()');
  222. });
  223. function table_mailbox_ready(ft, name) {
  224. heading = ft.$el.parents('.tab-pane').find('.panel-heading')
  225. var ft_paging = ft.use(FooTable.Paging)
  226. $(heading).children('.table-lines').text(function(){
  227. return ft_paging.totalRows;
  228. })
  229. if (current_page[name]) {
  230. ft_paging.goto(parseInt(current_page[name]))
  231. }
  232. }
  233. function paging_mailbox_after(ft, name) {
  234. var ft_paging = ft.use(FooTable.Paging)
  235. current_page[name] = ft_paging.current;
  236. localStorage.setItem('current_page', JSON.stringify(current_page));
  237. }
  238. function draw_domain_table() {
  239. ft_domain_table = FooTable.init('#domain_table', {
  240. "columns": [
  241. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  242. {"sorted": true,"name":"domain_name","title":lang.domain,"style":{"width":"250px"}},
  243. {"name":"aliases","title":lang.aliases,"breakpoints":"xs sm"},
  244. {"name":"mailboxes","title":lang.mailboxes},
  245. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  246. res = value.split("/");
  247. return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
  248. },
  249. "sortValue": function(value){
  250. res = value.split("/");
  251. return Number(res[0]);
  252. },
  253. },
  254. {"name":"max_quota_for_mbox","title":lang.mailbox_quota,"breakpoints":"xs sm","style":{"width":"125px"}},
  255. {"name":"rl","title":"RL","breakpoints":"xs sm md","style":{"width":"125px"}},
  256. {"name":"backupmx","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.backup_mx,"breakpoints":"xs sm"},
  257. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  258. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"240px","width":"240px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  259. ],
  260. "rows": $.ajax({
  261. dataType: 'json',
  262. url: '/api/v1/get/domain/all',
  263. jsonp: false,
  264. error: function (data) {
  265. console.log('Cannot draw domain table');
  266. },
  267. success: function (data) {
  268. $.each(data, function (i, item) {
  269. item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
  270. item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
  271. item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain;
  272. if (!item.rl) {
  273. item.rl = '∞';
  274. } else {
  275. item.rl = $.map(item.rl, function(e){
  276. return e;
  277. }).join('/1');
  278. }
  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.php?domain=' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  284. '<a href="#" id="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>';
  285. }
  286. else {
  287. item.action += '<a href="/edit.php?domain=' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + 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) + '"><span class="glyphicon glyphicon-question-sign"></span> DNS</a></div>';
  290. });
  291. }
  292. }),
  293. "empty": lang.empty,
  294. "paging": {
  295. "enabled": true,
  296. "limit": 5,
  297. "size": pagination_size
  298. },
  299. "filtering": {
  300. "enabled": true,
  301. "delay": 100,
  302. "position": "left",
  303. "connectors": false,
  304. "placeholder": lang.filter_table
  305. },
  306. "sorting": {
  307. "enabled": true
  308. },
  309. "on": {
  310. "ready.ft.table": function(e, ft){
  311. table_mailbox_ready(ft, 'domain_table');
  312. },
  313. "after.ft.paging": function(e, ft){
  314. paging_mailbox_after(ft, 'domain_table');
  315. }
  316. }
  317. });
  318. }
  319. function draw_mailbox_table() {
  320. ft_mailbox_table = FooTable.init('#mailbox_table', {
  321. "columns": [
  322. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  323. {"sorted": true,"name":"username","style":{"word-break":"break-all","min-width":"120px"},"title":lang.username},
  324. {"name":"name","title":lang.fname,"style":{"word-break":"break-all","min-width":"120px"},"breakpoints":"xs sm"},
  325. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  326. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  327. res = value.split("/");
  328. return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
  329. },
  330. "sortValue": function(value){
  331. res = value.split("/");
  332. return Number(res[0]);
  333. },
  334. },
  335. {"name":"spam_aliases","filterable": false,"title":lang.spam_aliases,"breakpoints":"xs sm md"},
  336. {"name":"in_use","filterable": false,"type":"html","title":lang.in_use,"sortValue": function(value){
  337. return Number($(value).find(".progress-bar").attr('aria-valuenow'));
  338. },
  339. },
  340. {"name":"messages","filterable": false,"title":lang.msg_num,"breakpoints":"xs sm md"},
  341. {"name":"rl","title":"RL","breakpoints":"xs sm md","style":{"width":"125px"}},
  342. {"name":"active","filterable": false,"title":lang.active},
  343. {"name":"action","filterable": false,"sortable": false,"style":{"min-width":"250px","text-align":"right"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
  344. ],
  345. "empty": lang.empty,
  346. "rows": $.ajax({
  347. dataType: 'json',
  348. url: '/api/v1/get/mailbox/all',
  349. jsonp: false,
  350. error: function () {
  351. console.log('Cannot draw mailbox table');
  352. },
  353. success: function (data) {
  354. $.each(data, function (i, item) {
  355. item.quota = item.quota_used + "/" + item.quota;
  356. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  357. if (!item.rl) {
  358. item.rl = '∞';
  359. } else {
  360. item.rl = $.map(item.rl, function(e){
  361. return e;
  362. }).join('/1');
  363. }
  364. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
  365. if (role == "admin") {
  366. item.action = '<div class="btn-group">' +
  367. '<a href="/edit.php?mailbox=' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  368. '<a href="#" id="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>' +
  369. '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-success"><span class="glyphicon glyphicon-user"></span> Login</a>' +
  370. '</div>';
  371. }
  372. else {
  373. item.action = '<div class="btn-group">' +
  374. '<a href="/edit.php?mailbox=' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  375. '<a href="#" id="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>' +
  376. '</div>';
  377. }
  378. item.in_use = '<div class="progress">' +
  379. '<div class="progress-bar progress-bar-' + item.percent_class + ' role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
  380. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  381. item.username = escapeHtml(item.username);
  382. });
  383. }
  384. }),
  385. "paging": {
  386. "enabled": true,
  387. "limit": 5,
  388. "size": pagination_size
  389. },
  390. "filtering": {
  391. "enabled": true,
  392. "delay": 100,
  393. "position": "left",
  394. "connectors": false,
  395. "placeholder": lang.filter_table
  396. },
  397. "components": {
  398. "filtering": FooTable.domainFilter
  399. },
  400. "sorting": {
  401. "enabled": true
  402. },
  403. "on": {
  404. "ready.ft.table": function(e, ft){
  405. table_mailbox_ready(ft, 'mailbox_table');
  406. },
  407. "after.ft.paging": function(e, ft){
  408. paging_mailbox_after(ft, 'mailbox_table');
  409. }
  410. }
  411. });
  412. }
  413. function draw_resource_table() {
  414. ft_resource_table = FooTable.init('#resource_table', {
  415. "columns": [
  416. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  417. {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
  418. {"name":"kind","title":lang.kind},
  419. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  420. {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"150px","width":"140px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
  421. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  422. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  423. ],
  424. "empty": lang.empty,
  425. "rows": $.ajax({
  426. dataType: 'json',
  427. url: '/api/v1/get/resource/all',
  428. jsonp: false,
  429. error: function () {
  430. console.log('Cannot draw resource table');
  431. },
  432. success: function (data) {
  433. $.each(data, function (i, item) {
  434. if (item.multiple_bookings == '0') {
  435. item.multiple_bookings = '<span id="active-script" class="label label-success">' + lang.booking_0_short + '</span>';
  436. } else if (item.multiple_bookings == '-1') {
  437. item.multiple_bookings = '<span id="active-script" class="label label-warning">' + lang.booking_lt0_short + '</span>';
  438. } else {
  439. item.multiple_bookings = '<span id="active-script" class="label label-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
  440. }
  441. item.action = '<div class="btn-group">' +
  442. '<a href="/edit.php?resource=' + encodeURIComponent(item.name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  443. '<a href="#" id="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>' +
  444. '</div>';
  445. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
  446. item.name = escapeHtml(item.name);
  447. });
  448. }
  449. }),
  450. "paging": {
  451. "enabled": true,
  452. "limit": 5,
  453. "size": pagination_size
  454. },
  455. "filtering": {
  456. "enabled": true,
  457. "delay": 100,
  458. "position": "left",
  459. "connectors": false,
  460. "placeholder": lang.filter_table
  461. },
  462. "components": {
  463. "filtering": FooTable.domainFilter
  464. },
  465. "sorting": {
  466. "enabled": true
  467. },
  468. "on": {
  469. "ready.ft.table": function(e, ft){
  470. table_mailbox_ready(ft, 'resource_table');
  471. },
  472. "after.ft.paging": function(e, ft){
  473. paging_mailbox_after(ft, 'resource_table');
  474. }
  475. }
  476. });
  477. }
  478. function draw_bcc_table() {
  479. ft_bcc_table = FooTable.init('#bcc_table', {
  480. "columns": [
  481. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  482. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  483. {"name":"type","title":lang.bcc_type},
  484. {"name":"local_dest","title":lang.bcc_local_dest},
  485. {"name":"bcc_dest","title":lang.bcc_destinations},
  486. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  487. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  488. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  489. ],
  490. "empty": lang.empty,
  491. "rows": $.ajax({
  492. dataType: 'json',
  493. url: '/api/v1/get/bcc/all',
  494. jsonp: false,
  495. error: function () {
  496. console.log('Cannot draw bcc table');
  497. },
  498. success: function (data) {
  499. $.each(data, function (i, item) {
  500. item.action = '<div class="btn-group">' +
  501. '<a href="/edit.php?bcc=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  502. '<a href="#" id="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>' +
  503. '</div>';
  504. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  505. item.local_dest = escapeHtml(item.local_dest);
  506. item.bcc_dest = escapeHtml(item.bcc_dest);
  507. if (item.type == 'sender') {
  508. item.type = '<span id="active-script" class="label label-success">Sender</span>';
  509. } else {
  510. item.type = '<span id="inactive-script" class="label label-warning">Recipient</span>';
  511. }
  512. });
  513. }
  514. }),
  515. "paging": {
  516. "enabled": true,
  517. "limit": 5,
  518. "size": pagination_size
  519. },
  520. "filtering": {
  521. "enabled": true,
  522. "delay": 100,
  523. "position": "left",
  524. "connectors": false,
  525. "placeholder": lang.filter_table
  526. },
  527. "sorting": {
  528. "enabled": true
  529. },
  530. "on": {
  531. "ready.ft.table": function(e, ft){
  532. table_mailbox_ready(ft, 'bcc_table');
  533. },
  534. "after.ft.paging": function(e, ft){
  535. paging_mailbox_after(ft, 'bcc_table');
  536. }
  537. }
  538. });
  539. }
  540. function draw_recipient_map_table() {
  541. ft_recipient_map_table = FooTable.init('#recipient_map_table', {
  542. "columns": [
  543. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  544. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  545. {"name":"recipient_map_old","title":lang.recipient_map_old},
  546. {"name":"recipient_map_new","title":lang.recipient_map_new},
  547. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  548. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  549. ],
  550. "empty": lang.empty,
  551. "rows": $.ajax({
  552. dataType: 'json',
  553. url: '/api/v1/get/recipient_map/all',
  554. jsonp: false,
  555. error: function () {
  556. console.log('Cannot draw recipient map table');
  557. },
  558. success: function (data) {
  559. if (role == "admin") {
  560. $.each(data, function (i, item) {
  561. item.recipient_map_old = escapeHtml(item.recipient_map_old);
  562. item.recipient_map_new = escapeHtml(item.recipient_map_new);
  563. item.action = '<div class="btn-group">' +
  564. '<a href="/edit.php?recipient_map=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  565. '<a href="#" id="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>' +
  566. '</div>';
  567. item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  568. });
  569. }
  570. }
  571. }),
  572. "paging": {
  573. "enabled": true,
  574. "limit": 5,
  575. "size": pagination_size
  576. },
  577. "filtering": {
  578. "enabled": true,
  579. "delay": 100,
  580. "position": "left",
  581. "connectors": false,
  582. "placeholder": lang.filter_table
  583. },
  584. "sorting": {
  585. "enabled": true
  586. },
  587. "on": {
  588. "ready.ft.table": function(e, ft){
  589. table_mailbox_ready(ft, 'recipient_map_table');
  590. },
  591. "after.ft.paging": function(e, ft){
  592. paging_mailbox_after(ft, 'recipient_map_table');
  593. }
  594. }
  595. });
  596. }
  597. function draw_alias_table() {
  598. ft_alias_table = FooTable.init('#alias_table', {
  599. "columns": [
  600. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  601. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  602. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  603. {"name":"goto","title":lang.target_address},
  604. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  605. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  606. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  607. ],
  608. "empty": lang.empty,
  609. "rows": $.ajax({
  610. dataType: 'json',
  611. url: '/api/v1/get/alias/all',
  612. jsonp: false,
  613. error: function () {
  614. console.log('Cannot draw alias table');
  615. },
  616. success: function (data) {
  617. $.each(data, function (i, item) {
  618. item.action = '<div class="btn-group">' +
  619. '<a href="/edit.php?alias=' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  620. '<a href="#" id="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>' +
  621. '</div>';
  622. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  623. item.goto = escapeHtml(item.goto.replace(/,/g, " "));
  624. if (item.is_catch_all == 1) {
  625. item.address = '<div class="label label-default">Catch-All</div> ' + escapeHtml(item.address);
  626. }
  627. else {
  628. item.address = escapeHtml(item.address);
  629. }
  630. if (item.goto == "null@localhost") {
  631. item.goto = '⤷ <span style="font-size:12px" class="glyphicon glyphicon-trash" aria-hidden="true"></span>';
  632. }
  633. else if (item.goto == "spam@localhost") {
  634. item.goto = '<span class="label label-danger">Learn as spam</span>';
  635. }
  636. else if (item.goto == "ham@localhost") {
  637. item.goto = '<span class="label label-success">Learn as ham</span>';
  638. }
  639. if (item.in_primary_domain !== "") {
  640. item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")";
  641. }
  642. });
  643. }
  644. }),
  645. "paging": {
  646. "enabled": true,
  647. "limit": 5,
  648. "size": pagination_size
  649. },
  650. "filtering": {
  651. "enabled": true,
  652. "delay": 100,
  653. "position": "left",
  654. "connectors": false,
  655. "placeholder": lang.filter_table
  656. },
  657. "components": {
  658. "filtering": FooTable.domainFilter
  659. },
  660. "sorting": {
  661. "enabled": true
  662. },
  663. "on": {
  664. "ready.ft.table": function(e, ft){
  665. table_mailbox_ready(ft, 'alias_table');
  666. },
  667. "after.ft.paging": function(e, ft){
  668. paging_mailbox_after(ft, 'alias_table');
  669. }
  670. }
  671. });
  672. }
  673. function draw_aliasdomain_table() {
  674. ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
  675. "columns": [
  676. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  677. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  678. {"name":"target_domain","title":lang.target_domain},
  679. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  680. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  681. ],
  682. "empty": lang.empty,
  683. "rows": $.ajax({
  684. dataType: 'json',
  685. url: '/api/v1/get/alias-domain/all',
  686. jsonp: false,
  687. error: function () {
  688. console.log('Cannot draw alias domain table');
  689. },
  690. success: function (data) {
  691. $.each(data, function (i, item) {
  692. item.action = '<div class="btn-group">' +
  693. '<a href="/edit.php?aliasdomain=' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  694. '<a href="#" id="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>' +
  695. '<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>' +
  696. '</div>';
  697. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
  698. });
  699. }
  700. }),
  701. "paging": {
  702. "enabled": true,
  703. "limit": 5,
  704. "size": pagination_size
  705. },
  706. "filtering": {
  707. "enabled": true,
  708. "delay": 100,
  709. "position": "left",
  710. "connectors": false,
  711. "placeholder": lang.filter_table
  712. },
  713. "sorting": {
  714. "enabled": true
  715. },
  716. "on": {
  717. "ready.ft.table": function(e, ft){
  718. table_mailbox_ready(ft, 'aliasdomain_table');
  719. },
  720. "after.ft.paging": function(e, ft){
  721. paging_mailbox_after(ft, 'aliasdomain_table');
  722. }
  723. }
  724. });
  725. }
  726. function draw_sync_job_table() {
  727. ft_syncjob_table = FooTable.init('#sync_job_table', {
  728. "columns": [
  729. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  730. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  731. {"name":"user2","title":lang.owner},
  732. {"name":"server_w_port","title":"Server","breakpoints":"xs","style":{"word-break":"break-all"}},
  733. {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
  734. {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
  735. {"name":"last_run","title":lang.last_run,"breakpoints":"sm"},
  736. {"name":"log","title":"Log"},
  737. {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active},
  738. {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
  739. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  740. ],
  741. "empty": lang.empty,
  742. "rows": $.ajax({
  743. dataType: 'json',
  744. url: '/api/v1/get/syncjobs/all/no_log',
  745. jsonp: false,
  746. error: function () {
  747. console.log('Cannot draw sync job table');
  748. },
  749. success: function (data) {
  750. $.each(data, function (i, item) {
  751. item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">Open logs</a>'
  752. item.user2 = escapeHtml(item.user2);
  753. if (!item.exclude > 0) {
  754. item.exclude = '-';
  755. } else {
  756. item.exclude = '<code>' + item.exclude + '</code>';
  757. }
  758. item.server_w_port = escapeHtml(item.user1) + '@' + item.host1 + ':' + item.port1;
  759. item.action = '<div class="btn-group">' +
  760. '<a href="/edit.php?syncjob=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  761. '<a href="#" id="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>' +
  762. '</div>';
  763. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  764. if (item.is_running == 1) {
  765. item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
  766. } else {
  767. item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
  768. }
  769. if (!item.last_run > 0) {
  770. item.last_run = lang.waiting;
  771. }
  772. });
  773. }
  774. }),
  775. "paging": {
  776. "enabled": true,
  777. "limit": 5,
  778. "size": pagination_size
  779. },
  780. "filtering": {
  781. "enabled": true,
  782. "delay": 100,
  783. "position": "left",
  784. "connectors": false,
  785. "placeholder": lang.filter_table
  786. },
  787. "sorting": {
  788. "enabled": true
  789. },
  790. "on": {
  791. "ready.ft.table": function(e, ft){
  792. table_mailbox_ready(ft, 'sync_job_table');
  793. },
  794. "after.ft.paging": function(e, ft){
  795. paging_mailbox_after(ft, 'sync_job_table');
  796. }
  797. }
  798. });
  799. }
  800. function draw_filter_table() {
  801. ft_filter_table = FooTable.init('#filter_table', {
  802. "columns": [
  803. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  804. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  805. {"name":"active","style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  806. {"name":"filter_type","style":{"maxWidth":"80px","width":"80px"},"title":"Type"},
  807. {"sorted": true,"name":"username","title":lang.owner,"style":{"maxWidth":"550px","width":"350px"}},
  808. {"name":"script_desc","title":lang.description,"breakpoints":"xs"},
  809. {"name":"script_data","title":"Script","breakpoints":"all"},
  810. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  811. ],
  812. "empty": lang.empty,
  813. "rows": $.ajax({
  814. dataType: 'json',
  815. url: '/api/v1/get/filters/all',
  816. jsonp: false,
  817. error: function () {
  818. console.log('Cannot draw filter table');
  819. },
  820. success: function (data) {
  821. $.each(data, function (i, item) {
  822. if (item.active_int == 1) {
  823. item.active = '<span id="active-script" class="label label-success">' + lang.active + '</span>';
  824. } else {
  825. item.active = '<span id="inactive-script" class="label label-warning">' + lang.inactive + '</span>';
  826. }
  827. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  828. item.filter_type = '<div class="label label-default">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  829. item.action = '<div class="btn-group">' +
  830. '<a href="/edit.php?filter=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  831. '<a href="#" id="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>' +
  832. '</div>';
  833. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  834. });
  835. }
  836. }),
  837. "paging": {
  838. "enabled": true,
  839. "limit": 5,
  840. "size": pagination_size
  841. },
  842. "filtering": {
  843. "enabled": true,
  844. "delay": 100,
  845. "position": "left",
  846. "connectors": false,
  847. "placeholder": lang.filter_table
  848. },
  849. "sorting": {
  850. "enabled": true
  851. },
  852. "on": {
  853. "ready.ft.table": function(e, ft){
  854. table_mailbox_ready(ft, 'filter_table');
  855. },
  856. "after.ft.paging": function(e, ft){
  857. paging_mailbox_after(ft, 'filter_table');
  858. }
  859. }
  860. });
  861. };
  862. draw_domain_table();
  863. draw_mailbox_table();
  864. draw_resource_table();
  865. draw_alias_table();
  866. draw_aliasdomain_table();
  867. draw_sync_job_table();
  868. draw_filter_table();
  869. draw_bcc_table();
  870. draw_recipient_map_table();
  871. });