2
0

user.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. var last_login = $('.last_login_date').data('time');
  45. $('.last_login_date').text(unix_time_format(last_login));
  46. function draw_tla_table() {
  47. ft_tla_table = FooTable.init('#tla_table', {
  48. "columns": [
  49. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  50. {"sorted": true,"name":"address","title":lang.alias},
  51. {"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"}},
  52. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  53. ],
  54. "empty": lang.empty,
  55. "rows": $.ajax({
  56. dataType: 'json',
  57. url: '/api/v1/get/time_limited_aliases',
  58. jsonp: false,
  59. error: function () {
  60. console.log('Cannot draw tla table');
  61. },
  62. success: function (data) {
  63. $.each(data, function (i, item) {
  64. if (acl_data.spam_alias === 1) {
  65. item.action = '<div class="btn-group">' +
  66. '<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>' +
  67. '</div>';
  68. item.chkbox = '<input type="checkbox" data-id="tla" name="multi_select" value="' + encodeURIComponent(item.address) + '" />';
  69. item.address = escapeHtml(item.address);
  70. }
  71. else {
  72. item.chkbox = '<input type="checkbox" disabled />';
  73. item.action = '<span>-</span>';
  74. }
  75. });
  76. }
  77. }),
  78. "paging": {
  79. "enabled": true,
  80. "limit": 5,
  81. "size": pagination_size
  82. },
  83. "sorting": {
  84. "enabled": true
  85. }
  86. });
  87. }
  88. function draw_sync_job_table() {
  89. ft_syncjob_table = FooTable.init('#sync_job_table', {
  90. "columns": [
  91. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  92. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  93. {"name":"server_w_port","title":"Server"},
  94. {"name":"enc1","title":lang.encryption,"breakpoints":"xs sm"},
  95. {"name":"user1","title":lang.username},
  96. {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
  97. {"name":"mins_interval","title":lang.interval + " (min)","breakpoints":"all"},
  98. {"name":"last_run","title":lang.last_run,"breakpoints":"all"},
  99. {"name":"log","title":"Log"},
  100. {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active},
  101. {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
  102. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  103. ],
  104. "empty": lang.empty,
  105. "rows": $.ajax({
  106. dataType: 'json',
  107. url: '/api/v1/get/syncjobs/' + encodeURIComponent(mailcow_cc_username) + '/no_log',
  108. jsonp: false,
  109. error: function () {
  110. console.log('Cannot draw sync job table');
  111. },
  112. success: function (data) {
  113. $.each(data, function (i, item) {
  114. item.user1 = escapeHtml(item.user1);
  115. item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + item.id + '">Open logs</a>'
  116. if (!item.exclude > 0) {
  117. item.exclude = '-';
  118. } else {
  119. item.exclude = '<code>' + escapeHtml(item.exclude) + '</code>';
  120. }
  121. item.server_w_port = escapeHtml(item.user1 + '@' + item.host1 + ':' + item.port1);
  122. if (acl_data.syncjobs === 1) {
  123. item.action = '<div class="btn-group">' +
  124. '<a href="/edit.php?syncjob=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  125. '<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>' +
  126. '</div>';
  127. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  128. }
  129. else {
  130. item.action = '<span>-</span>';
  131. item.chkbox = '<input type="checkbox" disabled />';
  132. }
  133. if (item.is_running == 1) {
  134. item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
  135. } else {
  136. item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
  137. }
  138. if (!item.last_run > 0) {
  139. item.last_run = lang.waiting;
  140. }
  141. });
  142. }
  143. }),
  144. "paging": {
  145. "enabled": true,
  146. "limit": 5,
  147. "size": pagination_size
  148. },
  149. "sorting": {
  150. "enabled": true
  151. }
  152. });
  153. }
  154. function draw_wl_policy_mailbox_table() {
  155. ft_wl_policy_mailbox_table = FooTable.init('#wl_policy_mailbox_table', {
  156. "columns": [
  157. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  158. {"name":"prefid","style":{"maxWidth":"40px","width":"40px"},"title":"ID","filterable": false,"sortable": false},
  159. {"sorted": true,"name":"value","title":lang.spamfilter_table_rule},
  160. {"name":"object","title":"Scope"}
  161. ],
  162. "empty": lang.empty,
  163. "rows": $.ajax({
  164. dataType: 'json',
  165. url: '/api/v1/get/policy_wl_mailbox',
  166. jsonp: false,
  167. error: function () {
  168. console.log('Cannot draw mailbox policy wl table');
  169. },
  170. success: function (data) {
  171. $.each(data, function (i, item) {
  172. if (validateEmail(item.object)) {
  173. item.chkbox = '<input type="checkbox" data-id="policy_wl_mailbox" name="multi_select" value="' + item.prefid + '" />';
  174. }
  175. else {
  176. item.chkbox = '<input type="checkbox" disabled title="' + lang.spamfilter_table_domain_policy + '" />';
  177. }
  178. if (acl_data.spam_policy === 0) {
  179. item.chkbox = '<input type="checkbox" disabled />';
  180. }
  181. });
  182. }
  183. }),
  184. "paging": {
  185. "enabled": true,
  186. "limit": 5,
  187. "size": pagination_size
  188. },
  189. "sorting": {
  190. "enabled": true
  191. }
  192. });
  193. }
  194. function draw_bl_policy_mailbox_table() {
  195. ft_bl_policy_mailbox_table = FooTable.init('#bl_policy_mailbox_table', {
  196. "columns": [
  197. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  198. {"name":"prefid","style":{"maxWidth":"40px","width":"40px"},"title":"ID","filterable": false,"sortable": false},
  199. {"sorted": true,"name":"value","title":lang.spamfilter_table_rule},
  200. {"name":"object","title":"Scope"}
  201. ],
  202. "empty": lang.empty,
  203. "rows": $.ajax({
  204. dataType: 'json',
  205. url: '/api/v1/get/policy_bl_mailbox',
  206. jsonp: false,
  207. error: function () {
  208. console.log('Cannot draw mailbox policy bl table');
  209. },
  210. success: function (data) {
  211. $.each(data, function (i, item) {
  212. if (validateEmail(item.object)) {
  213. item.chkbox = '<input type="checkbox" data-id="policy_bl_mailbox" name="multi_select" value="' + item.prefid + '" />';
  214. }
  215. else {
  216. item.chkbox = '<input type="checkbox" disabled tooltip="' + lang.spamfilter_table_domain_policy + '" />';
  217. }
  218. if (acl_data.spam_policy === 0) {
  219. item.chkbox = '<input type="checkbox" disabled />';
  220. }
  221. });
  222. }
  223. }),
  224. "paging": {
  225. "enabled": true,
  226. "limit": 5,
  227. "size": pagination_size
  228. },
  229. "sorting": {
  230. "enabled": true
  231. }
  232. });
  233. }
  234. draw_sync_job_table();
  235. draw_tla_table();
  236. draw_wl_policy_mailbox_table();
  237. draw_bl_policy_mailbox_table();
  238. // Sieve data modal
  239. $('#userFilterModal').on('show.bs.modal', function(e) {
  240. $('#user_sieve_filter').text(lang.loading);
  241. $.ajax({
  242. dataType: 'json',
  243. url: '/api/v1/get/active-user-sieve/' + encodeURIComponent(mailcow_cc_username),
  244. jsonp: false,
  245. error: function () {
  246. console.log('Cannot get active sieve script');
  247. },
  248. complete: function (data) {
  249. if (data.responseText == '{}') {
  250. $('#user_sieve_filter').text(lang.no_active_filter);
  251. } else {
  252. $('#user_sieve_filter').text(JSON.parse(data.responseText));
  253. }
  254. }
  255. })
  256. });
  257. $('#userFilterModal').on('hidden.bs.modal', function () {
  258. $('#user_sieve_filter').text(lang.loading);
  259. });
  260. });