mailbox.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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_alias_table() {
  376. ft_alias_table = FooTable.init('#alias_table', {
  377. "columns": [
  378. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  379. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  380. {"name":"goto","title":lang.target_address},
  381. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  382. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  383. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  384. ],
  385. "empty": lang.empty,
  386. "rows": $.ajax({
  387. dataType: 'json',
  388. url: '/api/v1/get/alias/all',
  389. jsonp: false,
  390. error: function () {
  391. console.log('Cannot draw alias table');
  392. },
  393. success: function (data) {
  394. $.each(data, function (i, item) {
  395. item.action = '<div class="btn-group">' +
  396. '<a href="/edit.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  397. '<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>' +
  398. '</div>';
  399. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + item.address + '" />';
  400. if (item.is_catch_all == 1) {
  401. item.address = '<div class="label label-default">Catch-All</div> ' + item.address;
  402. }
  403. if (item.goto == "null@localhost") {
  404. item.goto = '⤷ <span style="font-size:12px" class="glyphicon glyphicon-trash" aria-hidden="true"></span>';
  405. }
  406. if (item.in_primary_domain !== "") {
  407. item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")";
  408. }
  409. });
  410. }
  411. }),
  412. "paging": {
  413. "enabled": true,
  414. "limit": 5,
  415. "size": pagination_size
  416. },
  417. "filtering": {
  418. "enabled": true,
  419. "position": "left",
  420. "connectors": false,
  421. "placeholder": lang.filter_table
  422. },
  423. "sorting": {
  424. "enabled": true
  425. }
  426. });
  427. }
  428. function draw_aliasdomain_table() {
  429. ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
  430. "columns": [
  431. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  432. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  433. {"name":"target_domain","title":lang.target_domain},
  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":"250px","width":"250px"},"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-domain/all',
  441. jsonp: false,
  442. error: function () {
  443. console.log('Cannot draw alias domain table');
  444. },
  445. success: function (data) {
  446. $.each(data, function (i, item) {
  447. item.action = '<div class="btn-group">' +
  448. '<a href="/edit.php?aliasdomain=' + encodeURI(item.alias_domain) + '" 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-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>' +
  450. '<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>' +
  451. '</div>';
  452. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + item.alias_domain + '" />';
  453. });
  454. }
  455. }),
  456. "paging": {
  457. "enabled": true,
  458. "limit": 5,
  459. "size": pagination_size
  460. },
  461. "filtering": {
  462. "enabled": true,
  463. "position": "left",
  464. "connectors": false,
  465. "placeholder": lang.filter_table
  466. },
  467. "sorting": {
  468. "enabled": true
  469. }
  470. });
  471. }
  472. function draw_sync_job_table() {
  473. ft_syncjob_table = FooTable.init('#sync_job_table', {
  474. "columns": [
  475. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  476. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  477. {"name":"user2","title":lang.owner},
  478. {"name":"server_w_port","title":"Server","breakpoints":"xs"},
  479. {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
  480. {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
  481. {"name":"last_run","title":lang.last_run,"breakpoints":"all"},
  482. {"name":"log","title":"Log"},
  483. {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active},
  484. {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
  485. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  486. ],
  487. "empty": lang.empty,
  488. "rows": $.ajax({
  489. dataType: 'json',
  490. url: '/api/v1/get/syncjobs/all/no_log',
  491. jsonp: false,
  492. error: function () {
  493. console.log('Cannot draw sync job table');
  494. },
  495. success: function (data) {
  496. $.each(data, function (i, item) {
  497. item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + encodeURI(item.id) + '">Open logs</a>'
  498. if (!item.exclude > 0) {
  499. item.exclude = '-';
  500. } else {
  501. item.exclude = '<code>' + item.exclude + '</code>';
  502. }
  503. item.server_w_port = item.user1 + '@' + item.host1 + ':' + item.port1;
  504. item.action = '<div class="btn-group">' +
  505. '<a href="/edit.php?syncjob=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  506. '<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>' +
  507. '</div>';
  508. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  509. if (item.is_running == 1) {
  510. item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
  511. } else {
  512. item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
  513. }
  514. if (!item.last_run > 0) {
  515. item.last_run = lang.waiting;
  516. }
  517. });
  518. }
  519. }),
  520. "paging": {
  521. "enabled": true,
  522. "limit": 5,
  523. "size": pagination_size
  524. },
  525. "filtering": {
  526. "enabled": true,
  527. "position": "left",
  528. "connectors": false,
  529. "placeholder": lang.filter_table
  530. },
  531. "sorting": {
  532. "enabled": true
  533. }
  534. });
  535. }
  536. function draw_filter_table() {
  537. ft_filter_table = FooTable.init('#filter_table', {
  538. "columns": [
  539. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  540. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  541. {"name":"active","style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  542. {"name":"filter_type","style":{"maxWidth":"80px","width":"80px"},"title":"Type"},
  543. {"sorted": true,"name":"username","title":lang.owner,"style":{"maxWidth":"550px","width":"350px"}},
  544. {"name":"script_desc","title":lang.description,"breakpoints":"xs"},
  545. {"name":"script_data","title":"Script","breakpoints":"all"},
  546. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  547. ],
  548. "empty": lang.empty,
  549. "rows": $.ajax({
  550. dataType: 'json',
  551. url: '/api/v1/get/filters/all',
  552. jsonp: false,
  553. error: function () {
  554. console.log('Cannot draw filter table');
  555. },
  556. success: function (data) {
  557. $.each(data, function (i, item) {
  558. if (item.active_int == 1) {
  559. item.active = '<span id="active-script" class="label label-success">' + lang.active + '</span>';
  560. } else {
  561. item.active = '<span id="inactive-script" class="label label-warning">' + lang.inactive + '</span>';
  562. }
  563. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  564. item.filter_type = '<div class="label label-default">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  565. item.action = '<div class="btn-group">' +
  566. '<a href="/edit.php?filter=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  567. '<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>' +
  568. '</div>';
  569. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  570. });
  571. }
  572. }),
  573. "paging": {
  574. "enabled": true,
  575. "limit": 5,
  576. "size": pagination_size
  577. },
  578. "filtering": {
  579. "enabled": true,
  580. "position": "left",
  581. "connectors": false,
  582. "placeholder": lang.filter_table
  583. },
  584. "sorting": {
  585. "enabled": true
  586. }
  587. });
  588. };
  589. draw_domain_table();
  590. draw_mailbox_table();
  591. draw_resource_table();
  592. draw_alias_table();
  593. draw_aliasdomain_table();
  594. draw_sync_job_table();
  595. draw_filter_table();
  596. draw_bcc_table();
  597. });