mailbox.js 31 KB

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