user.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. $(document).ready(function() {
  2. // Log modal
  3. $('#logModal').on('show.bs.modal', function(e) {
  4. var logText = $(e.relatedTarget).data('log-text');
  5. $(e.currentTarget).find('#logText').html('<pre style="background:none;font-size:11px;line-height:1.1;border:0px">' + logText + '</pre>');
  6. });
  7. });
  8. jQuery(function($){
  9. // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
  10. var entityMap = {
  11. '&': '&amp;',
  12. '<': '&lt;',
  13. '>': '&gt;',
  14. '"': '&quot;',
  15. "'": '&#39;',
  16. '/': '&#x2F;',
  17. '`': '&#x60;',
  18. '=': '&#x3D;'
  19. };
  20. function escapeHtml(string) {
  21. return String(string).replace(/[&<>"'`=\/]/g, function (s) {
  22. return entityMap[s];
  23. });
  24. }
  25. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  26. function validateEmail(email) {
  27. 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,}))$/;
  28. return re.test(email);
  29. }
  30. function unix_time_format(tm) {
  31. var date = new Date(tm ? tm * 1000 : 0);
  32. return date.toLocaleString();
  33. }
  34. acl_data = JSON.parse(acl);
  35. function draw_tla_table() {
  36. ft_tla_table = FooTable.init('#tla_table', {
  37. "columns": [
  38. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  39. {"sorted": true,"name":"address","title":lang.alias},
  40. {"name":"validity","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.alias_valid_until,"style":{"width":"170px"}},
  41. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  42. ],
  43. "empty": lang.empty,
  44. "rows": $.ajax({
  45. dataType: 'json',
  46. url: '/api/v1/get/time_limited_aliases',
  47. jsonp: false,
  48. error: function () {
  49. console.log('Cannot draw tla table');
  50. },
  51. success: function (data) {
  52. $.each(data, function (i, item) {
  53. if (acl_data.spam_alias === 1) {
  54. item.action = '<div class="btn-group">' +
  55. '<a href="#" id="delete_selected" data-id="single-tla" data-api-url="delete/time_limited_alias" data-item="' + encodeURI(item.address) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  56. '</div>';
  57. item.chkbox = '<input type="checkbox" data-id="tla" name="multi_select" value="' + item.address + '" />';
  58. }
  59. else {
  60. item.chkbox = '<input type="checkbox" disabled />';
  61. item.action = '<span>-</span>';
  62. }
  63. });
  64. }
  65. }),
  66. "paging": {
  67. "enabled": true,
  68. "limit": 5,
  69. "size": pagination_size
  70. },
  71. "sorting": {
  72. "enabled": true
  73. }
  74. });
  75. }
  76. function draw_sync_job_table() {
  77. ft_syncjob_table = FooTable.init('#sync_job_table', {
  78. "columns": [
  79. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  80. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  81. {"name":"server_w_port","title":"Server"},
  82. {"name":"enc1","title":lang.encryption},
  83. {"name":"user1","title":lang.username},
  84. {"name":"exclude","title":lang.excludes},
  85. {"name":"mins_interval","title":lang.interval + " (min)"},
  86. {"name":"last_run","title":lang.last_run},
  87. {"name":"log","title":"Log"},
  88. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  89. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  90. ],
  91. "empty": lang.empty,
  92. "rows": $.ajax({
  93. dataType: 'json',
  94. url: '/api/v1/get/syncjobs/' + mailcow_cc_username,
  95. jsonp: false,
  96. error: function () {
  97. console.log('Cannot draw sync job table');
  98. },
  99. success: function (data) {
  100. $.each(data, function (i, item) {
  101. item.log = '<a href="#logModal" data-toggle="modal" data-log-text="' + escapeHtml(item.returned_text) + '">Open logs</a>'
  102. item.exclude = '<code>' + item.exclude + '</code>'
  103. item.server_w_port = item.user1 + '@' + item.host1 + ':' + item.port1;
  104. if (acl_data.syncjobs === 1) {
  105. item.action = '<div class="btn-group">' +
  106. '<a href="/edit.php?syncjob=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  107. '<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>' +
  108. '</div>';
  109. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  110. }
  111. else {
  112. item.action = '<span>-</span>';
  113. item.chkbox = '<input type="checkbox" disabled />';
  114. }
  115. });
  116. }
  117. }),
  118. "paging": {
  119. "enabled": true,
  120. "limit": 5,
  121. "size": pagination_size
  122. },
  123. "sorting": {
  124. "enabled": true
  125. }
  126. });
  127. }
  128. function draw_wl_policy_mailbox_table() {
  129. ft_wl_policy_mailbox_table = FooTable.init('#wl_policy_mailbox_table', {
  130. "columns": [
  131. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  132. {"name":"prefid","style":{"maxWidth":"40px","width":"40px"},"title":"ID","filterable": false,"sortable": false},
  133. {"sorted": true,"name":"value","title":lang.spamfilter_table_rule},
  134. {"name":"object","title":"Scope"}
  135. ],
  136. "empty": lang.empty,
  137. "rows": $.ajax({
  138. dataType: 'json',
  139. url: '/api/v1/get/policy_wl_mailbox',
  140. jsonp: false,
  141. error: function () {
  142. console.log('Cannot draw mailbox policy wl table');
  143. },
  144. success: function (data) {
  145. $.each(data, function (i, item) {
  146. if (validateEmail(item.object)) {
  147. item.chkbox = '<input type="checkbox" data-id="policy_wl_mailbox" name="multi_select" value="' + item.prefid + '" />';
  148. }
  149. else {
  150. item.chkbox = '<input type="checkbox" disabled title="' + lang.spamfilter_table_domain_policy + '" />';
  151. }
  152. if (acl_data.spam_policy === 0) {
  153. item.chkbox = '<input type="checkbox" disabled />';
  154. }
  155. });
  156. }
  157. }),
  158. "paging": {
  159. "enabled": true,
  160. "limit": 5,
  161. "size": pagination_size
  162. },
  163. "sorting": {
  164. "enabled": true
  165. }
  166. });
  167. }
  168. function draw_bl_policy_mailbox_table() {
  169. ft_bl_policy_mailbox_table = FooTable.init('#bl_policy_mailbox_table', {
  170. "columns": [
  171. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  172. {"name":"prefid","style":{"maxWidth":"40px","width":"40px"},"title":"ID","filterable": false,"sortable": false},
  173. {"sorted": true,"name":"value","title":lang.spamfilter_table_rule},
  174. {"name":"object","title":"Scope"}
  175. ],
  176. "empty": lang.empty,
  177. "rows": $.ajax({
  178. dataType: 'json',
  179. url: '/api/v1/get/policy_bl_mailbox',
  180. jsonp: false,
  181. error: function () {
  182. console.log('Cannot draw mailbox policy bl table');
  183. },
  184. success: function (data) {
  185. $.each(data, function (i, item) {
  186. if (validateEmail(item.object)) {
  187. item.chkbox = '<input type="checkbox" data-id="policy_bl_mailbox" name="multi_select" value="' + item.prefid + '" />';
  188. }
  189. else {
  190. item.chkbox = '<input type="checkbox" disabled tooltip="' + lang.spamfilter_table_domain_policy + '" />';
  191. }
  192. if (acl_data.spam_policy === 0) {
  193. item.chkbox = '<input type="checkbox" disabled />';
  194. }
  195. });
  196. }
  197. }),
  198. "paging": {
  199. "enabled": true,
  200. "limit": 5,
  201. "size": pagination_size
  202. },
  203. "sorting": {
  204. "enabled": true
  205. }
  206. });
  207. }
  208. draw_sync_job_table();
  209. draw_tla_table();
  210. draw_wl_policy_mailbox_table();
  211. draw_bl_policy_mailbox_table();
  212. });