user.js 11 KB

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