mailbox.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  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_null").click(function( event ) {
  89. if ($("#goto_null").is(":checked")) {
  90. $('#textarea_alias_goto').prop('disabled', true);
  91. }
  92. else {
  93. $("#textarea_alias_goto").removeAttr('disabled');
  94. }
  95. });
  96. // Log modal
  97. $('#syncjobLogModal').on('show.bs.modal', function(e) {
  98. var syncjob_id = $(e.relatedTarget).data('syncjob-id');
  99. $.ajax({
  100. url: '/inc/ajax/syncjob_logs.php',
  101. data: { id: syncjob_id },
  102. dataType: 'text',
  103. success: function(data){
  104. $(e.currentTarget).find('#logText').text(data);
  105. },
  106. error: function(xhr, status, error) {
  107. $(e.currentTarget).find('#logText').text(xhr.responseText);
  108. }
  109. });
  110. });
  111. // Log modal
  112. $('#dnsInfoModal').on('show.bs.modal', function(e) {
  113. var domain = $(e.relatedTarget).data('domain');
  114. $('.dns-modal-body').html('<center><span style="font-size:18pt;margin:50px" class="glyphicon glyphicon-refresh glyphicon-spin"></span></center>');
  115. $.ajax({
  116. url: '/inc/ajax/dns_diagnostics.php',
  117. data: { domain: domain },
  118. dataType: 'text',
  119. success: function(data){
  120. $('.dns-modal-body').html(data);
  121. },
  122. error: function(xhr, status, error) {
  123. $('.dns-modal-body').html(xhr.responseText);
  124. }
  125. });
  126. });
  127. // Sieve data modal
  128. $('#sieveDataModal').on('show.bs.modal', function(e) {
  129. var sieveScript = $(e.relatedTarget).data('sieve-script');
  130. $(e.currentTarget).find('#sieveDataText').html('<pre style="font-size:14px;line-height:1.1">' + sieveScript + '</pre>');
  131. });
  132. // Set line numbers for textarea
  133. $("#script_data").numberedtextarea({allowTabChar: true});
  134. // Disable submit button on script change
  135. $('#script_data').on('keyup', function() {
  136. $('#add_filter_btns > #add_item').attr({"disabled": true});
  137. $('#validation_msg').html('-');
  138. });
  139. // Validate script data
  140. $("#validate_sieve").click(function( event ) {
  141. event.preventDefault();
  142. var script = $('#script_data').val();
  143. $.ajax({
  144. dataType: 'jsonp',
  145. url: "/inc/ajax/sieve_validation.php",
  146. type: "get",
  147. data: { script: script },
  148. complete: function(data) {
  149. var response = (data.responseText);
  150. response_obj = JSON.parse(response);
  151. if (response_obj.type == "success") {
  152. $('#add_filter_btns > #add_item').attr({"disabled": false});
  153. }
  154. mailcow_alert_box(response_obj.msg, response_obj.type);
  155. },
  156. });
  157. });
  158. // $(document).on('DOMNodeInserted', '#prefilter_table', function () {
  159. // $("#active-script").closest('td').css('background-color','#b0f0a0');
  160. // $("#inactive-script").closest('td').css('background-color','#b0f0a0');
  161. // });
  162. });
  163. jQuery(function($){
  164. // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
  165. var entityMap = {
  166. '&': '&amp;',
  167. '<': '&lt;',
  168. '>': '&gt;',
  169. '"': '&quot;',
  170. "'": '&#39;',
  171. '/': '&#x2F;',
  172. '`': '&#x60;',
  173. '=': '&#x3D;'
  174. };
  175. function escapeHtml(string) {
  176. return String(string).replace(/[&<>"'`=\/]/g, function (s) {
  177. return entityMap[s];
  178. });
  179. }
  180. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  181. function validateEmail(email) {
  182. 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,}))$/;
  183. return re.test(email);
  184. }
  185. // Calculation human readable file sizes
  186. function humanFileSize(bytes) {
  187. if(Math.abs(bytes) < 1024) {
  188. return bytes + ' B';
  189. }
  190. var units = ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
  191. var u = -1;
  192. do {
  193. bytes /= 1024;
  194. ++u;
  195. } while(Math.abs(bytes) >= 1024 && u < units.length - 1);
  196. return bytes.toFixed(1)+' '+units[u];
  197. }
  198. function unix_time_format(tm) {
  199. var date = new Date(tm ? tm * 1000 : 0);
  200. return date.toLocaleString();
  201. }
  202. function draw_domain_table() {
  203. ft_domain_table = FooTable.init('#domain_table', {
  204. "columns": [
  205. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  206. {"sorted": true,"name":"domain_name","title":lang.domain,"style":{"width":"250px"}},
  207. {"name":"aliases","title":lang.aliases,"breakpoints":"xs sm"},
  208. {"name":"mailboxes","title":lang.mailboxes},
  209. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  210. res = value.split("/");
  211. return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
  212. },
  213. "sortValue": function(value){
  214. res = value.split("/");
  215. return Number(res[0]);
  216. },
  217. },
  218. {"name":"max_quota_for_mbox","title":lang.mailbox_quota,"breakpoints":"xs sm","style":{"width":"125px"}},
  219. {"name":"backupmx","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.backup_mx,"breakpoints":"xs sm"},
  220. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  221. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"240px","width":"240px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  222. ],
  223. "rows": $.ajax({
  224. dataType: 'json',
  225. url: '/api/v1/get/domain/all',
  226. jsonp: false,
  227. error: function (data) {
  228. console.log('Cannot draw domain table');
  229. },
  230. success: function (data) {
  231. $.each(data, function (i, item) {
  232. item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
  233. item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
  234. item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain;
  235. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  236. item.chkbox = '<input type="checkbox" data-id="domain" name="multi_select" value="' + encodeURIComponent(item.domain_name) + '" />';
  237. item.action = '<div class="btn-group">';
  238. if (role == "admin") {
  239. 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>' +
  240. '<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>';
  241. }
  242. else {
  243. 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>';
  244. }
  245. 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>';
  246. });
  247. }
  248. }),
  249. "empty": lang.empty,
  250. "paging": {
  251. "enabled": true,
  252. "limit": 5,
  253. "size": pagination_size
  254. },
  255. "filtering": {
  256. "enabled": true,
  257. "delay": 100,
  258. "position": "left",
  259. "connectors": false,
  260. "placeholder": lang.filter_table
  261. },
  262. "sorting": {
  263. "enabled": true
  264. }
  265. });
  266. }
  267. function draw_mailbox_table() {
  268. ft_mailbox_table = FooTable.init('#mailbox_table', {
  269. "columns": [
  270. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  271. {"sorted": true,"name":"username","style":{"word-break":"break-all","min-width":"120px"},"title":lang.username},
  272. {"name":"name","title":lang.fname,"style":{"word-break":"break-all","min-width":"120px"},"breakpoints":"xs sm"},
  273. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  274. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  275. res = value.split("/");
  276. return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
  277. },
  278. "sortValue": function(value){
  279. res = value.split("/");
  280. return Number(res[0]);
  281. },
  282. },
  283. {"name":"spam_aliases","filterable": false,"title":lang.spam_aliases,"breakpoints":"xs sm md"},
  284. {"name":"in_use","filterable": false,"type":"html","title":lang.in_use,"sortValue": function(value){
  285. return Number($(value).find(".progress-bar").attr('aria-valuenow'));
  286. },
  287. },
  288. {"name":"messages","filterable": false,"title":lang.msg_num,"breakpoints":"xs sm md"},
  289. {"name":"active","filterable": false,"title":lang.active},
  290. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
  291. ],
  292. "empty": lang.empty,
  293. "rows": $.ajax({
  294. dataType: 'json',
  295. url: '/api/v1/get/mailbox/all',
  296. jsonp: false,
  297. error: function () {
  298. console.log('Cannot draw mailbox table');
  299. },
  300. success: function (data) {
  301. $.each(data, function (i, item) {
  302. item.quota = item.quota_used + "/" + item.quota;
  303. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  304. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
  305. if (role == "admin") {
  306. item.action = '<div class="btn-group">' +
  307. '<a href="/edit.php?mailbox=' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  308. '<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>' +
  309. '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-success"><span class="glyphicon glyphicon-user"></span> Login</a>' +
  310. '</div>';
  311. }
  312. else {
  313. item.action = '<div class="btn-group">' +
  314. '<a href="/edit.php?mailbox=' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  315. '<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>' +
  316. '</div>';
  317. }
  318. item.in_use = '<div class="progress">' +
  319. '<div class="progress-bar progress-bar-' + item.percent_class + ' role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
  320. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  321. item.username = escapeHtml(item.username);
  322. });
  323. }
  324. }),
  325. "paging": {
  326. "enabled": true,
  327. "limit": 5,
  328. "size": pagination_size
  329. },
  330. "filtering": {
  331. "enabled": true,
  332. "delay": 100,
  333. "position": "left",
  334. "connectors": false,
  335. "placeholder": lang.filter_table
  336. },
  337. "components": {
  338. "filtering": FooTable.domainFilter
  339. },
  340. "sorting": {
  341. "enabled": true
  342. }
  343. });
  344. }
  345. function draw_resource_table() {
  346. ft_resource_table = FooTable.init('#resource_table', {
  347. "columns": [
  348. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  349. {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
  350. {"name":"kind","title":lang.kind},
  351. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  352. {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"150px","width":"140px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
  353. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  354. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  355. ],
  356. "empty": lang.empty,
  357. "rows": $.ajax({
  358. dataType: 'json',
  359. url: '/api/v1/get/resource/all',
  360. jsonp: false,
  361. error: function () {
  362. console.log('Cannot draw resource table');
  363. },
  364. success: function (data) {
  365. $.each(data, function (i, item) {
  366. if (item.multiple_bookings == '0') {
  367. item.multiple_bookings = '<span id="active-script" class="label label-success">' + lang.booking_0_short + '</span>';
  368. } else if (item.multiple_bookings == '-1') {
  369. item.multiple_bookings = '<span id="active-script" class="label label-warning">' + lang.booking_lt0_short + '</span>';
  370. } else {
  371. item.multiple_bookings = '<span id="active-script" class="label label-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
  372. }
  373. item.action = '<div class="btn-group">' +
  374. '<a href="/edit.php?resource=' + encodeURIComponent(item.name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  375. '<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>' +
  376. '</div>';
  377. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
  378. item.name = escapeHtml(item.name);
  379. });
  380. }
  381. }),
  382. "paging": {
  383. "enabled": true,
  384. "limit": 5,
  385. "size": pagination_size
  386. },
  387. "filtering": {
  388. "enabled": true,
  389. "delay": 100,
  390. "position": "left",
  391. "connectors": false,
  392. "placeholder": lang.filter_table
  393. },
  394. "components": {
  395. "filtering": FooTable.domainFilter
  396. },
  397. "sorting": {
  398. "enabled": true
  399. }
  400. });
  401. }
  402. function draw_bcc_table() {
  403. ft_bcc_table = FooTable.init('#bcc_table', {
  404. "columns": [
  405. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  406. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  407. {"name":"type","title":lang.bcc_type},
  408. {"name":"local_dest","title":lang.bcc_local_dest},
  409. {"name":"bcc_dest","title":lang.bcc_destinations},
  410. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  411. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  412. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  413. ],
  414. "empty": lang.empty,
  415. "rows": $.ajax({
  416. dataType: 'json',
  417. url: '/api/v1/get/bcc/all',
  418. jsonp: false,
  419. error: function () {
  420. console.log('Cannot draw bcc table');
  421. },
  422. success: function (data) {
  423. $.each(data, function (i, item) {
  424. item.action = '<div class="btn-group">' +
  425. '<a href="/edit.php?bcc=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  426. '<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>' +
  427. '</div>';
  428. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  429. item.local_dest = escapeHtml(item.local_dest);
  430. item.bcc_dest = escapeHtml(item.bcc_dest);
  431. if (item.type == 'sender') {
  432. item.type = '<span id="active-script" class="label label-success">Sender</span>';
  433. } else {
  434. item.type = '<span id="inactive-script" class="label label-warning">Recipient</span>';
  435. }
  436. });
  437. }
  438. }),
  439. "paging": {
  440. "enabled": true,
  441. "limit": 5,
  442. "size": pagination_size
  443. },
  444. "filtering": {
  445. "enabled": true,
  446. "delay": 100,
  447. "position": "left",
  448. "connectors": false,
  449. "placeholder": lang.filter_table
  450. },
  451. "sorting": {
  452. "enabled": true
  453. }
  454. });
  455. }
  456. function draw_recipient_map_table() {
  457. ft_recipient_map_table = FooTable.init('#recipient_map_table', {
  458. "columns": [
  459. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  460. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  461. {"name":"recipient_map_old","title":lang.recipient_map_old},
  462. {"name":"recipient_map_new","title":lang.recipient_map_new},
  463. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  464. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  465. ],
  466. "empty": lang.empty,
  467. "rows": $.ajax({
  468. dataType: 'json',
  469. url: '/api/v1/get/recipient_map/all',
  470. jsonp: false,
  471. error: function () {
  472. console.log('Cannot draw recipient map table');
  473. },
  474. success: function (data) {
  475. if (role == "admin") {
  476. $.each(data, function (i, item) {
  477. item.recipient_map_old = escapeHtml(item.recipient_map_old);
  478. item.recipient_map_new = escapeHtml(item.recipient_map_new);
  479. item.action = '<div class="btn-group">' +
  480. '<a href="/edit.php?recipient_map=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  481. '<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>' +
  482. '</div>';
  483. item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  484. });
  485. }
  486. }
  487. }),
  488. "paging": {
  489. "enabled": true,
  490. "limit": 5,
  491. "size": pagination_size
  492. },
  493. "filtering": {
  494. "enabled": true,
  495. "delay": 100,
  496. "position": "left",
  497. "connectors": false,
  498. "placeholder": lang.filter_table
  499. },
  500. "sorting": {
  501. "enabled": true
  502. }
  503. });
  504. }
  505. function draw_alias_table() {
  506. ft_alias_table = FooTable.init('#alias_table', {
  507. "columns": [
  508. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  509. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  510. {"name":"goto","title":lang.target_address},
  511. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  512. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  513. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  514. ],
  515. "empty": lang.empty,
  516. "rows": $.ajax({
  517. dataType: 'json',
  518. url: '/api/v1/get/alias/all',
  519. jsonp: false,
  520. error: function () {
  521. console.log('Cannot draw alias table');
  522. },
  523. success: function (data) {
  524. $.each(data, function (i, item) {
  525. item.action = '<div class="btn-group">' +
  526. '<a href="/edit.php?alias=' + encodeURIComponent(item.address) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  527. '<a href="#" id="delete_selected" data-id="single-alias" data-api-url="delete/alias" data-item="' + encodeURIComponent(item.address) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  528. '</div>';
  529. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.address) + '" />';
  530. item.goto = escapeHtml(item.goto.replace(/,/g, " "));
  531. if (item.is_catch_all == 1) {
  532. item.address = '<div class="label label-default">Catch-All</div> ' + escapeHtml(item.address);
  533. }
  534. else {
  535. item.address = escapeHtml(item.address);
  536. }
  537. if (item.goto == "null@localhost") {
  538. item.goto = '⤷ <span style="font-size:12px" class="glyphicon glyphicon-trash" aria-hidden="true"></span>';
  539. }
  540. if (item.in_primary_domain !== "") {
  541. item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")";
  542. }
  543. });
  544. }
  545. }),
  546. "paging": {
  547. "enabled": true,
  548. "limit": 5,
  549. "size": pagination_size
  550. },
  551. "filtering": {
  552. "enabled": true,
  553. "delay": 100,
  554. "position": "left",
  555. "connectors": false,
  556. "placeholder": lang.filter_table
  557. },
  558. "components": {
  559. "filtering": FooTable.domainFilter
  560. },
  561. "sorting": {
  562. "enabled": true
  563. }
  564. });
  565. }
  566. function draw_aliasdomain_table() {
  567. ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
  568. "columns": [
  569. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  570. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  571. {"name":"target_domain","title":lang.target_domain},
  572. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  573. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  574. ],
  575. "empty": lang.empty,
  576. "rows": $.ajax({
  577. dataType: 'json',
  578. url: '/api/v1/get/alias-domain/all',
  579. jsonp: false,
  580. error: function () {
  581. console.log('Cannot draw alias domain table');
  582. },
  583. success: function (data) {
  584. $.each(data, function (i, item) {
  585. item.action = '<div class="btn-group">' +
  586. '<a href="/edit.php?aliasdomain=' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  587. '<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>' +
  588. '<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>' +
  589. '</div>';
  590. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
  591. });
  592. }
  593. }),
  594. "paging": {
  595. "enabled": true,
  596. "limit": 5,
  597. "size": pagination_size
  598. },
  599. "filtering": {
  600. "enabled": true,
  601. "delay": 100,
  602. "position": "left",
  603. "connectors": false,
  604. "placeholder": lang.filter_table
  605. },
  606. "components": {
  607. "filtering": FooTable.domainFilter
  608. },
  609. "sorting": {
  610. "enabled": true
  611. }
  612. });
  613. }
  614. function draw_sync_job_table() {
  615. ft_syncjob_table = FooTable.init('#sync_job_table', {
  616. "columns": [
  617. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  618. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  619. {"name":"user2","title":lang.owner},
  620. {"name":"server_w_port","title":"Server","breakpoints":"xs"},
  621. {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
  622. {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
  623. {"name":"last_run","title":lang.last_run,"breakpoints":"all"},
  624. {"name":"log","title":"Log"},
  625. {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active},
  626. {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
  627. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  628. ],
  629. "empty": lang.empty,
  630. "rows": $.ajax({
  631. dataType: 'json',
  632. url: '/api/v1/get/syncjobs/all/no_log',
  633. jsonp: false,
  634. error: function () {
  635. console.log('Cannot draw sync job table');
  636. },
  637. success: function (data) {
  638. $.each(data, function (i, item) {
  639. item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">Open logs</a>'
  640. item.user2 = escapeHtml(item.user2);
  641. if (!item.exclude > 0) {
  642. item.exclude = '-';
  643. } else {
  644. item.exclude = '<code>' + item.exclude + '</code>';
  645. }
  646. item.server_w_port = escapeHtml(item.user1) + '@' + item.host1 + ':' + item.port1;
  647. item.action = '<div class="btn-group">' +
  648. '<a href="/edit.php?syncjob=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  649. '<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>' +
  650. '</div>';
  651. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  652. if (item.is_running == 1) {
  653. item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
  654. } else {
  655. item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
  656. }
  657. if (!item.last_run > 0) {
  658. item.last_run = lang.waiting;
  659. }
  660. });
  661. }
  662. }),
  663. "paging": {
  664. "enabled": true,
  665. "limit": 5,
  666. "size": pagination_size
  667. },
  668. "filtering": {
  669. "enabled": true,
  670. "delay": 100,
  671. "position": "left",
  672. "connectors": false,
  673. "placeholder": lang.filter_table
  674. },
  675. "sorting": {
  676. "enabled": true
  677. }
  678. });
  679. }
  680. function draw_filter_table() {
  681. ft_filter_table = FooTable.init('#filter_table', {
  682. "columns": [
  683. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  684. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  685. {"name":"active","style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  686. {"name":"filter_type","style":{"maxWidth":"80px","width":"80px"},"title":"Type"},
  687. {"sorted": true,"name":"username","title":lang.owner,"style":{"maxWidth":"550px","width":"350px"}},
  688. {"name":"script_desc","title":lang.description,"breakpoints":"xs"},
  689. {"name":"script_data","title":"Script","breakpoints":"all"},
  690. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  691. ],
  692. "empty": lang.empty,
  693. "rows": $.ajax({
  694. dataType: 'json',
  695. url: '/api/v1/get/filters/all',
  696. jsonp: false,
  697. error: function () {
  698. console.log('Cannot draw filter table');
  699. },
  700. success: function (data) {
  701. $.each(data, function (i, item) {
  702. if (item.active_int == 1) {
  703. item.active = '<span id="active-script" class="label label-success">' + lang.active + '</span>';
  704. } else {
  705. item.active = '<span id="inactive-script" class="label label-warning">' + lang.inactive + '</span>';
  706. }
  707. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  708. item.filter_type = '<div class="label label-default">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  709. item.action = '<div class="btn-group">' +
  710. '<a href="/edit.php?filter=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  711. '<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>' +
  712. '</div>';
  713. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  714. });
  715. }
  716. }),
  717. "paging": {
  718. "enabled": true,
  719. "limit": 5,
  720. "size": pagination_size
  721. },
  722. "filtering": {
  723. "enabled": true,
  724. "delay": 100,
  725. "position": "left",
  726. "connectors": false,
  727. "placeholder": lang.filter_table
  728. },
  729. "sorting": {
  730. "enabled": true
  731. }
  732. });
  733. };
  734. draw_domain_table();
  735. draw_mailbox_table();
  736. draw_resource_table();
  737. draw_alias_table();
  738. draw_aliasdomain_table();
  739. draw_sync_job_table();
  740. draw_filter_table();
  741. draw_bcc_table();
  742. draw_recipient_map_table();
  743. });