mailbox.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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 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="' + item.domain_name + '" />';
  180. item.action = '<div class="btn-group">';
  181. if (role == "admin") {
  182. item.action += '<a href="/edit.php?domain=' + encodeURI(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="' + encodeURI(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=' + encodeURI(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="' + encodeURI(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 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="' + item.username + '" />';
  244. if (role == "admin") {
  245. item.action = '<div class="btn-group">' +
  246. '<a href="/edit.php?mailbox=' + encodeURI(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="' + encodeURI(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  248. '<a href="/index.php?duallogin=' + encodeURI(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=' + encodeURI(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="' + encodeURI(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. });
  261. }
  262. }),
  263. "paging": {
  264. "enabled": true,
  265. "limit": 5,
  266. "size": pagination_size
  267. },
  268. "filtering": {
  269. "enabled": true,
  270. "position": "left",
  271. "connectors": false,
  272. "placeholder": lang.filter_table
  273. },
  274. "sorting": {
  275. "enabled": true
  276. }
  277. });
  278. }
  279. function draw_resource_table() {
  280. ft_resource_table = FooTable.init('#resource_table', {
  281. "columns": [
  282. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  283. {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
  284. {"name":"kind","title":lang.kind},
  285. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  286. {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
  287. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  288. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  289. ],
  290. "empty": lang.empty,
  291. "rows": $.ajax({
  292. dataType: 'json',
  293. url: '/api/v1/get/resource/all',
  294. jsonp: false,
  295. error: function () {
  296. console.log('Cannot draw resource table');
  297. },
  298. success: function (data) {
  299. $.each(data, function (i, item) {
  300. item.action = '<div class="btn-group">' +
  301. '<a href="/edit.php?resource=' + encodeURI(item.name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  302. '<a href="#" id="delete_selected" data-id="single-resource" data-api-url="delete/resource" data-item="' + encodeURI(item.name) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  303. '</div>';
  304. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + item.name + '" />';
  305. });
  306. }
  307. }),
  308. "paging": {
  309. "enabled": true,
  310. "limit": 5,
  311. "size": pagination_size
  312. },
  313. "filtering": {
  314. "enabled": true,
  315. "position": "left",
  316. "connectors": false,
  317. "placeholder": lang.filter_table
  318. },
  319. "sorting": {
  320. "enabled": true
  321. }
  322. });
  323. }
  324. function draw_bcc_table() {
  325. ft_bcc_table = FooTable.init('#bcc_table', {
  326. "columns": [
  327. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  328. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  329. {"name":"type","title":lang.bcc_type},
  330. {"name":"local_dest","title":lang.bcc_local_dest},
  331. {"name":"bcc_dest","title":lang.bcc_destinations},
  332. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  333. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  334. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  335. ],
  336. "empty": lang.empty,
  337. "rows": $.ajax({
  338. dataType: 'json',
  339. url: '/api/v1/get/bcc/all',
  340. jsonp: false,
  341. error: function () {
  342. console.log('Cannot draw bcc table');
  343. },
  344. success: function (data) {
  345. $.each(data, function (i, item) {
  346. item.action = '<div class="btn-group">' +
  347. '<a href="/edit.php?bcc=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  348. '<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>' +
  349. '</div>';
  350. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  351. if (item.type == 'sender') {
  352. item.type = '<span id="active-script" class="label label-success">Sender</span>';
  353. } else {
  354. item.type = '<span id="inactive-script" class="label label-warning">Recipient</span>';
  355. }
  356. });
  357. }
  358. }),
  359. "paging": {
  360. "enabled": true,
  361. "limit": 5,
  362. "size": pagination_size
  363. },
  364. "filtering": {
  365. "enabled": true,
  366. "position": "left",
  367. "connectors": false,
  368. "placeholder": lang.filter_table
  369. },
  370. "sorting": {
  371. "enabled": true
  372. }
  373. });
  374. }
  375. function draw_recipient_map_table() {
  376. ft_recipient_map_table = FooTable.init('#recipient_map_table', {
  377. "columns": [
  378. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  379. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  380. {"name":"recipient_map_old","title":lang.recipient_map_old},
  381. {"name":"recipient_map_new","title":lang.recipient_map_new},
  382. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  383. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  384. ],
  385. "empty": lang.empty,
  386. "rows": $.ajax({
  387. dataType: 'json',
  388. url: '/api/v1/get/recipient_map/all',
  389. jsonp: false,
  390. error: function () {
  391. console.log('Cannot draw recipient map table');
  392. },
  393. success: function (data) {
  394. if (role == "admin") {
  395. $.each(data, function (i, item) {
  396. item.action = '<div class="btn-group">' +
  397. '<a href="/edit.php?recipient_map=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  398. '<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>' +
  399. '</div>';
  400. item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  401. });
  402. }
  403. }
  404. }),
  405. "paging": {
  406. "enabled": true,
  407. "limit": 5,
  408. "size": pagination_size
  409. },
  410. "filtering": {
  411. "enabled": true,
  412. "position": "left",
  413. "connectors": false,
  414. "placeholder": lang.filter_table
  415. },
  416. "sorting": {
  417. "enabled": true
  418. }
  419. });
  420. }
  421. function draw_alias_table() {
  422. ft_alias_table = FooTable.init('#alias_table', {
  423. "columns": [
  424. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  425. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  426. {"name":"goto","title":lang.target_address},
  427. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  428. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  429. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  430. ],
  431. "empty": lang.empty,
  432. "rows": $.ajax({
  433. dataType: 'json',
  434. url: '/api/v1/get/alias/all',
  435. jsonp: false,
  436. error: function () {
  437. console.log('Cannot draw alias table');
  438. },
  439. success: function (data) {
  440. $.each(data, function (i, item) {
  441. item.action = '<div class="btn-group">' +
  442. '<a href="/edit.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  443. '<a href="#" id="delete_selected" data-id="single-alias" data-api-url="delete/alias" data-item="' + encodeURI(item.address) + '" 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="alias" name="multi_select" value="' + item.address + '" />';
  446. if (item.is_catch_all == 1) {
  447. item.address = '<div class="label label-default">Catch-All</div> ' + item.address;
  448. }
  449. if (item.goto == "null@localhost") {
  450. item.goto = '⤷ <span style="font-size:12px" class="glyphicon glyphicon-trash" aria-hidden="true"></span>';
  451. }
  452. if (item.in_primary_domain !== "") {
  453. item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")";
  454. }
  455. });
  456. }
  457. }),
  458. "paging": {
  459. "enabled": true,
  460. "limit": 5,
  461. "size": pagination_size
  462. },
  463. "filtering": {
  464. "enabled": true,
  465. "position": "left",
  466. "connectors": false,
  467. "placeholder": lang.filter_table
  468. },
  469. "sorting": {
  470. "enabled": true
  471. }
  472. });
  473. }
  474. function draw_aliasdomain_table() {
  475. ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
  476. "columns": [
  477. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  478. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  479. {"name":"target_domain","title":lang.target_domain},
  480. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  481. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  482. ],
  483. "empty": lang.empty,
  484. "rows": $.ajax({
  485. dataType: 'json',
  486. url: '/api/v1/get/alias-domain/all',
  487. jsonp: false,
  488. error: function () {
  489. console.log('Cannot draw alias domain table');
  490. },
  491. success: function (data) {
  492. $.each(data, function (i, item) {
  493. item.action = '<div class="btn-group">' +
  494. '<a href="/edit.php?aliasdomain=' + encodeURI(item.alias_domain) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  495. '<a href="#" id="delete_selected" data-id="single-alias-domain" data-api-url="delete/alias-domain" data-item="' + encodeURI(item.alias_domain) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  496. '<a href="#dnsInfoModal" class="btn btn-xs btn-info" data-toggle="modal" data-domain="' + encodeURI(item.alias_domain) + '"><span class="glyphicon glyphicon-question-sign"></span> DNS</a></div>' +
  497. '</div>';
  498. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + item.alias_domain + '" />';
  499. });
  500. }
  501. }),
  502. "paging": {
  503. "enabled": true,
  504. "limit": 5,
  505. "size": pagination_size
  506. },
  507. "filtering": {
  508. "enabled": true,
  509. "position": "left",
  510. "connectors": false,
  511. "placeholder": lang.filter_table
  512. },
  513. "sorting": {
  514. "enabled": true
  515. }
  516. });
  517. }
  518. function draw_sync_job_table() {
  519. ft_syncjob_table = FooTable.init('#sync_job_table', {
  520. "columns": [
  521. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  522. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  523. {"name":"user2","title":lang.owner},
  524. {"name":"server_w_port","title":"Server","breakpoints":"xs"},
  525. {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
  526. {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
  527. {"name":"last_run","title":lang.last_run,"breakpoints":"all"},
  528. {"name":"log","title":"Log"},
  529. {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active},
  530. {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
  531. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  532. ],
  533. "empty": lang.empty,
  534. "rows": $.ajax({
  535. dataType: 'json',
  536. url: '/api/v1/get/syncjobs/all/no_log',
  537. jsonp: false,
  538. error: function () {
  539. console.log('Cannot draw sync job table');
  540. },
  541. success: function (data) {
  542. $.each(data, function (i, item) {
  543. item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + encodeURI(item.id) + '">Open logs</a>'
  544. if (!item.exclude > 0) {
  545. item.exclude = '-';
  546. } else {
  547. item.exclude = '<code>' + item.exclude + '</code>';
  548. }
  549. item.server_w_port = item.user1 + '@' + item.host1 + ':' + item.port1;
  550. item.action = '<div class="btn-group">' +
  551. '<a href="/edit.php?syncjob=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  552. '<a href="#" id="delete_selected" data-id="single-syncjob" data-api-url="delete/syncjob" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  553. '</div>';
  554. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  555. if (item.is_running == 1) {
  556. item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
  557. } else {
  558. item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
  559. }
  560. if (!item.last_run > 0) {
  561. item.last_run = lang.waiting;
  562. }
  563. });
  564. }
  565. }),
  566. "paging": {
  567. "enabled": true,
  568. "limit": 5,
  569. "size": pagination_size
  570. },
  571. "filtering": {
  572. "enabled": true,
  573. "position": "left",
  574. "connectors": false,
  575. "placeholder": lang.filter_table
  576. },
  577. "sorting": {
  578. "enabled": true
  579. }
  580. });
  581. }
  582. function draw_filter_table() {
  583. ft_filter_table = FooTable.init('#filter_table', {
  584. "columns": [
  585. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  586. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  587. {"name":"active","style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  588. {"name":"filter_type","style":{"maxWidth":"80px","width":"80px"},"title":"Type"},
  589. {"sorted": true,"name":"username","title":lang.owner,"style":{"maxWidth":"550px","width":"350px"}},
  590. {"name":"script_desc","title":lang.description,"breakpoints":"xs"},
  591. {"name":"script_data","title":"Script","breakpoints":"all"},
  592. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  593. ],
  594. "empty": lang.empty,
  595. "rows": $.ajax({
  596. dataType: 'json',
  597. url: '/api/v1/get/filters/all',
  598. jsonp: false,
  599. error: function () {
  600. console.log('Cannot draw filter table');
  601. },
  602. success: function (data) {
  603. $.each(data, function (i, item) {
  604. if (item.active_int == 1) {
  605. item.active = '<span id="active-script" class="label label-success">' + lang.active + '</span>';
  606. } else {
  607. item.active = '<span id="inactive-script" class="label label-warning">' + lang.inactive + '</span>';
  608. }
  609. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  610. item.filter_type = '<div class="label label-default">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  611. item.action = '<div class="btn-group">' +
  612. '<a href="/edit.php?filter=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  613. '<a href="#" id="delete_selected" data-id="single-filter" data-api-url="delete/filter" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  614. '</div>';
  615. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  616. });
  617. }
  618. }),
  619. "paging": {
  620. "enabled": true,
  621. "limit": 5,
  622. "size": pagination_size
  623. },
  624. "filtering": {
  625. "enabled": true,
  626. "position": "left",
  627. "connectors": false,
  628. "placeholder": lang.filter_table
  629. },
  630. "sorting": {
  631. "enabled": true
  632. }
  633. });
  634. };
  635. draw_domain_table();
  636. draw_mailbox_table();
  637. draw_resource_table();
  638. draw_alias_table();
  639. draw_aliasdomain_table();
  640. draw_sync_job_table();
  641. draw_filter_table();
  642. draw_bcc_table();
  643. draw_recipient_map_table();
  644. });