user.js 14 KB

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