user.js 11 KB

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