user.js 11 KB

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