admin.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. var Base64 = {
  2. _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
  3. encode: function(e) {
  4. var t = "";
  5. var n, r, i, s, o, u, a;
  6. var f = 0;
  7. e = Base64._utf8_encode(e);
  8. while (f < e.length) {
  9. n = e.charCodeAt(f++);
  10. r = e.charCodeAt(f++);
  11. i = e.charCodeAt(f++);
  12. s = n >> 2;
  13. o = (n & 3) << 4 | r >> 4;
  14. u = (r & 15) << 2 | i >> 6;
  15. a = i & 63;
  16. if (isNaN(r)) {
  17. u = a = 64
  18. } else if (isNaN(i)) {
  19. a = 64
  20. }
  21. t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) +
  22. this._keyStr.charAt(u) + this._keyStr.charAt(a)
  23. }
  24. return t
  25. },
  26. decode: function(e) {
  27. var t = "";
  28. var n, r, i;
  29. var s, o, u, a;
  30. var f = 0;
  31. e = e.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  32. while (f < e.length) {
  33. s = this._keyStr.indexOf(e.charAt(f++));
  34. o = this._keyStr.indexOf(e.charAt(f++));
  35. u = this._keyStr.indexOf(e.charAt(f++));
  36. a = this._keyStr.indexOf(e.charAt(f++));
  37. n = s << 2 | o >> 4;
  38. r = (o & 15) << 4 | u >> 2;
  39. i = (u & 3) << 6 | a;
  40. t = t + String.fromCharCode(n);
  41. if (u != 64) {
  42. t = t + String.fromCharCode(r)
  43. }
  44. if (a != 64) {
  45. t = t + String.fromCharCode(i)
  46. }
  47. }
  48. t = Base64._utf8_decode(t);
  49. return t
  50. },
  51. _utf8_encode: function(e) {
  52. e = e.replace(/\r\n/g, "\n");
  53. var t = "";
  54. for (var n = 0; n < e.length; n++) {
  55. var r = e.charCodeAt(n);
  56. if (r < 128) {
  57. t += String.fromCharCode(r)
  58. } else if (r > 127 && r < 2048) {
  59. t += String.fromCharCode(r >> 6 | 192);
  60. t += String.fromCharCode(r & 63 | 128)
  61. } else {
  62. t += String.fromCharCode(r >> 12 | 224);
  63. t += String.fromCharCode(r >> 6 & 63 | 128);
  64. t += String.fromCharCode(r & 63 | 128)
  65. }
  66. }
  67. return t
  68. },
  69. _utf8_decode: function(e) {
  70. var t = "";
  71. var n = 0;
  72. var r = c1 = c2 = 0;
  73. while (n < e.length) {
  74. r = e.charCodeAt(n);
  75. if (r < 128) {
  76. t += String.fromCharCode(r);
  77. n++
  78. } else if (r > 191 && r < 224) {
  79. c2 = e.charCodeAt(n + 1);
  80. t += String.fromCharCode((r & 31) << 6 | c2 & 63);
  81. n += 2
  82. } else {
  83. c2 = e.charCodeAt(n + 1);
  84. c3 = e.charCodeAt(n + 2);
  85. t += String.fromCharCode((r & 15) << 12 | (c2 & 63) <<
  86. 6 | c3 & 63);
  87. n += 3
  88. }
  89. }
  90. return t
  91. }
  92. }
  93. jQuery(function($){
  94. // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
  95. var entityMap = {
  96. '&': '&amp;',
  97. '<': '&lt;',
  98. '>': '&gt;',
  99. '"': '&quot;',
  100. "'": '&#39;',
  101. '/': '&#x2F;',
  102. '`': '&#x60;',
  103. '=': '&#x3D;'
  104. };
  105. function escapeHtml(string) {
  106. return String(string).replace(/[&<>"'`=\/]/g, function (s) {
  107. return entityMap[s];
  108. });
  109. }
  110. function humanFileSize(bytes) {
  111. if(Math.abs(bytes) < 1024) {
  112. return bytes + ' B';
  113. }
  114. var units = ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
  115. var u = -1;
  116. do {
  117. bytes /= 1024;
  118. ++u;
  119. } while(Math.abs(bytes) >= 1024 && u < units.length - 1);
  120. return bytes.toFixed(1)+' '+units[u];
  121. }
  122. $("#refresh_postfix_log").on('click', function(e) {
  123. e.preventDefault();
  124. draw_postfix_logs();
  125. });
  126. $("#refresh_dovecot_log").on('click', function(e) {
  127. e.preventDefault();
  128. draw_dovecot_logs();
  129. });
  130. $("#refresh_sogo_log").on('click', function(e) {
  131. e.preventDefault();
  132. draw_sogo_logs();
  133. });
  134. $("#refresh_fail2ban_log").on('click', function(e) {
  135. e.preventDefault();
  136. draw_fail2ban_logs();
  137. });
  138. $("#refresh_rspamd_history").on('click', function(e) {
  139. e.preventDefault();
  140. draw_rspamd_history();
  141. });
  142. $("#import_dkim_legend").on('click', function(e) {
  143. e.preventDefault();
  144. $('#import_dkim_arrow').toggleClass("animation");
  145. });
  146. function draw_postfix_logs() {
  147. ft_postfix_logs = FooTable.init('#postfix_log', {
  148. "columns": [
  149. {"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
  150. {"name":"priority","title":lang.priority,"style":{"width":"80px"}},
  151. {"name":"message","title":lang.message},
  152. ],
  153. "rows": $.ajax({
  154. dataType: 'json',
  155. url: '/api/v1/get/logs/postfix/1000',
  156. jsonp: false,
  157. error: function () {
  158. console.log('Cannot draw postfix log table');
  159. },
  160. success: function (data) {
  161. $.each(data, function (i, item) {
  162. item.message = escapeHtml(item.message);
  163. var danger_class = ["emerg", "alert", "crit", "err"];
  164. var warning_class = ["warning", "warn"];
  165. var info_class = ["notice", "info", "debug"];
  166. if (jQuery.inArray(item.priority, danger_class) !== -1) {
  167. item.priority = '<span class="label label-danger">' + item.priority + '</span>';
  168. }
  169. else if (jQuery.inArray(item.priority, warning_class) !== -1) {
  170. item.priority = '<span class="label label-warning">' + item.priority + '</span>';
  171. }
  172. else if (jQuery.inArray(item.priority, info_class) !== -1) {
  173. item.priority = '<span class="label label-info">' + item.priority + '</span>';
  174. }
  175. });
  176. }
  177. }),
  178. "empty": lang.empty,
  179. "paging": {
  180. "enabled": true,
  181. "limit": 5,
  182. "size": log_pagination_size
  183. },
  184. "filtering": {
  185. "enabled": true,
  186. "position": "left",
  187. "placeholder": lang.filter_table
  188. },
  189. "sorting": {
  190. "enabled": true
  191. }
  192. });
  193. }
  194. function draw_fail2ban_logs() {
  195. ft_fail2ban_logs = FooTable.init('#fail2ban_log', {
  196. "columns": [
  197. {"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
  198. {"name":"priority","title":lang.priority,"style":{"width":"80px"}},
  199. {"name":"message","title":lang.message},
  200. ],
  201. "rows": $.ajax({
  202. dataType: 'json',
  203. url: '/api/v1/get/logs/fail2ban/1000',
  204. jsonp: false,
  205. error: function () {
  206. console.log('Cannot draw fail2ban log table');
  207. },
  208. success: function (data) {
  209. $.each(data, function (i, item) {
  210. var danger_class = ["emerg", "alert", "crit", "err"];
  211. var warning_class = ["warning", "warn"];
  212. var info_class = ["notice", "info", "debug"];
  213. item.message = escapeHtml(item.message);
  214. if (jQuery.inArray(item.priority, danger_class) !== -1) {
  215. item.priority = '<span class="label label-danger">' + item.priority + '</span>';
  216. }
  217. else if (jQuery.inArray(item.priority, warning_class) !== -1) {
  218. item.priority = '<span class="label label-warning">' + item.priority + '</span>';
  219. }
  220. else if (jQuery.inArray(item.priority, info_class) !== -1) {
  221. item.priority = '<span class="label label-info">' + item.priority + '</span>';
  222. }
  223. });
  224. }
  225. }),
  226. "empty": lang.empty,
  227. "paging": {
  228. "enabled": true,
  229. "limit": 5,
  230. "size": log_pagination_size
  231. },
  232. "filtering": {
  233. "enabled": true,
  234. "position": "left",
  235. "connectors": false,
  236. "placeholder": lang.filter_table
  237. },
  238. "sorting": {
  239. "enabled": true
  240. }
  241. });
  242. }
  243. function draw_sogo_logs() {
  244. ft_sogo_logs = FooTable.init('#sogo_log', {
  245. "columns": [
  246. {"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
  247. {"name":"priority","title":lang.priority,"style":{"width":"80px"}},
  248. {"name":"message","title":lang.message},
  249. ],
  250. "rows": $.ajax({
  251. dataType: 'json',
  252. url: '/api/v1/get/logs/sogo/1000',
  253. jsonp: false,
  254. error: function () {
  255. console.log('Cannot draw sogo log table');
  256. },
  257. success: function (data) {
  258. $.each(data, function (i, item) {
  259. var danger_class = ["emerg", "alert", "crit", "err"];
  260. var warning_class = ["warning", "warn"];
  261. var info_class = ["notice", "info", "debug"];
  262. item.message = escapeHtml(item.message);
  263. if (jQuery.inArray(item.priority, danger_class) !== -1) {
  264. item.priority = '<span class="label label-danger">' + item.priority + '</span>';
  265. }
  266. else if (jQuery.inArray(item.priority, warning_class) !== -1) {
  267. item.priority = '<span class="label label-warning">' + item.priority + '</span>';
  268. }
  269. else if (jQuery.inArray(item.priority, info_class) !== -1) {
  270. item.priority = '<span class="label label-info">' + item.priority + '</span>';
  271. }
  272. });
  273. }
  274. }),
  275. "empty": lang.empty,
  276. "paging": {
  277. "enabled": true,
  278. "limit": 5,
  279. "size": log_pagination_size
  280. },
  281. "filtering": {
  282. "enabled": true,
  283. "position": "left",
  284. "connectors": false,
  285. "placeholder": lang.filter_table
  286. },
  287. "sorting": {
  288. "enabled": true
  289. }
  290. });
  291. }
  292. function draw_dovecot_logs() {
  293. ft_postfix_logs = FooTable.init('#dovecot_log', {
  294. "columns": [
  295. {"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
  296. {"name":"priority","title":lang.priority,"style":{"width":"80px"}},
  297. {"name":"message","title":lang.message},
  298. ],
  299. "rows": $.ajax({
  300. dataType: 'json',
  301. url: '/api/v1/get/logs/dovecot/1000',
  302. jsonp: false,
  303. error: function () {
  304. console.log('Cannot draw dovecot log table');
  305. },
  306. success: function (data) {
  307. $.each(data, function (i, item) {
  308. var danger_class = ["emerg", "alert", "crit", "err"];
  309. var warning_class = ["warning", "warn"];
  310. var info_class = ["notice", "info", "debug"];
  311. item.message = escapeHtml(item.message);
  312. if (jQuery.inArray(item.priority, danger_class) !== -1) {
  313. item.priority = '<span class="label label-danger">' + item.priority + '</span>';
  314. }
  315. else if (jQuery.inArray(item.priority, warning_class) !== -1) {
  316. item.priority = '<span class="label label-warning">' + item.priority + '</span>';
  317. }
  318. else if (jQuery.inArray(item.priority, info_class) !== -1) {
  319. item.priority = '<span class="label label-info">' + item.priority + '</span>';
  320. }
  321. });
  322. }
  323. }),
  324. "empty": lang.empty,
  325. "paging": {
  326. "enabled": true,
  327. "limit": 5,
  328. "size": log_pagination_size
  329. },
  330. "filtering": {
  331. "enabled": true,
  332. "position": "left",
  333. "connectors": false,
  334. "placeholder": lang.filter_table
  335. },
  336. "sorting": {
  337. "enabled": true
  338. }
  339. });
  340. }
  341. function draw_domain_admins() {
  342. ft_domainadmins = FooTable.init('#domainadminstable', {
  343. "columns": [
  344. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
  345. {"sorted": true,"name":"username","title":lang.username,"style":{"width":"250px"}},
  346. {"name":"selected_domains","title":lang.admin_domains,"breakpoints":"xs sm"},
  347. {"name":"tfa_active","title":"TFA", "filterable": false,"style":{"maxWidth":"80px","width":"80px"}},
  348. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  349. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  350. ],
  351. "rows": $.ajax({
  352. dataType: 'json',
  353. url: '/api/v1/get/domain-admin/all',
  354. jsonp: false,
  355. error: function () {
  356. console.log('Cannot draw domain admin table');
  357. },
  358. success: function (data) {
  359. $.each(data, function (i, item) {
  360. item.chkbox = '<input type="checkbox" data-id="domain_admins" name="multi_select" value="' + item.username + '" />';
  361. item.action = '<div class="btn-group">' +
  362. '<a href="/edit.php?domainadmin=' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  363. '<a href="#" id="delete_selected" data-id="single-domain-admin" data-api-url="delete/domain-admin" data-item="' + encodeURI(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  364. '</div>';
  365. });
  366. }
  367. }),
  368. "empty": lang.empty,
  369. "paging": {
  370. "enabled": true,
  371. "limit": 5,
  372. "size": log_pagination_size
  373. },
  374. "filtering": {
  375. "enabled": true,
  376. "position": "left",
  377. "connectors": false,
  378. "placeholder": lang.filter_table
  379. },
  380. "sorting": {
  381. "enabled": true
  382. }
  383. });
  384. }
  385. function draw_fwd_hosts() {
  386. ft_forwardinghoststable = FooTable.init('#forwardinghoststable', {
  387. "columns": [
  388. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
  389. {"name":"host","type":"text","title":lang.host,"style":{"width":"250px"}},
  390. {"name":"source","title":lang.source,"breakpoints":"xs sm"},
  391. {"name":"keep_spam","title":lang.spamfilter, "type": "text","style":{"maxWidth":"80px","width":"80px"}},
  392. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  393. ],
  394. "rows": $.ajax({
  395. dataType: 'json',
  396. url: '/api/v1/get/fwdhost/all',
  397. jsonp: false,
  398. error: function () {
  399. console.log('Cannot draw forwarding hosts table');
  400. },
  401. success: function (data) {
  402. $.each(data, function (i, item) {
  403. item.action = '<div class="btn-group">' +
  404. '<a href="#" id="delete_selected" data-id="single-fwdhost" data-api-url="delete/fwdhost" data-item="' + encodeURI(item.host) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  405. '</div>';
  406. if (item.keep_spam == "yes") {
  407. item.keep_spam = lang.no;
  408. }
  409. else {
  410. item.keep_spam = lang.yes;
  411. }
  412. item.chkbox = '<input type="checkbox" data-id="fwdhosts" name="multi_select" value="' + item.host + '" />';
  413. });
  414. }
  415. }),
  416. "empty": lang.empty,
  417. "paging": {
  418. "enabled": true,
  419. "limit": 5,
  420. "size": log_pagination_size
  421. },
  422. "sorting": {
  423. "enabled": true
  424. }
  425. });
  426. }
  427. function draw_relayhosts() {
  428. ft_forwardinghoststable = FooTable.init('#relayhoststable', {
  429. "columns": [
  430. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
  431. {"name":"id","type":"text","title":"ID","style":{"width":"50px"}},
  432. {"name":"hostname","type":"text","title":lang.host,"style":{"width":"250px"}},
  433. {"name":"username","title":lang.username,"breakpoints":"xs sm"},
  434. {"name":"used_by_domains","title":lang.in_use_by, "type": "text","breakpoints":"xs sm"},
  435. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  436. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"280px","width":"280px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  437. ],
  438. "rows": $.ajax({
  439. dataType: 'json',
  440. url: '/api/v1/get/relayhost/all',
  441. jsonp: false,
  442. error: function () {
  443. console.log('Cannot draw forwarding hosts table');
  444. },
  445. success: function (data) {
  446. $.each(data, function (i, item) {
  447. item.action = '<div class="btn-group">' +
  448. '<a href="#" data-toggle="modal" id="miau" data-target="#testRelayhostModal" data-relayhost-id="' + encodeURI(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-stats"></span> Test</a>' +
  449. '<a href="/edit.php?relayhost=' + encodeURI(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  450. '<a href="#" id="delete_selected" data-id="single-rlshost" data-api-url="delete/relayhost" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  451. '</div>';
  452. item.chkbox = '<input type="checkbox" data-id="rlyhosts" name="multi_select" value="' + item.id + '" />';
  453. });
  454. }
  455. }),
  456. "empty": lang.empty,
  457. "paging": {
  458. "enabled": true,
  459. "limit": 5,
  460. "size": log_pagination_size
  461. },
  462. "sorting": {
  463. "enabled": true
  464. }
  465. });
  466. }
  467. function draw_rspamd_history() {
  468. ft_postfix_logs = FooTable.init('#rspamd_history', {
  469. "columns": [{
  470. "name":"unix_time",
  471. "formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},
  472. "title":lang.time,
  473. "style":{
  474. "width":"170px"
  475. }
  476. }, {
  477. "name": "ip",
  478. "title": "IP address",
  479. "breakpoints": "all",
  480. "style": {
  481. "minWidth": 88
  482. }
  483. }, {
  484. "name": "sender_mime",
  485. "title": "From",
  486. "breakpoints": "xs sm md",
  487. "style": {
  488. "minWidth": 100
  489. }
  490. }, {
  491. "name": "rcpt_mime",
  492. "title": "To",
  493. "breakpoints": "xs sm md",
  494. "style": {
  495. "minWidth": 100
  496. }
  497. }, {
  498. "name": "subject",
  499. "title": "Subject",
  500. "breakpoints": "all",
  501. "style": {
  502. "word-break": "break-all",
  503. "minWidth": 150
  504. }
  505. }, {
  506. "name": "action",
  507. "title": "Action",
  508. "style": {
  509. "minwidth": 82
  510. }
  511. }, {
  512. "name": "score",
  513. "title": "Score",
  514. "style": {
  515. "maxWidth": 110
  516. },
  517. }, {
  518. "name": "symbols",
  519. "title": "Symbols",
  520. "breakpoints": "all",
  521. }, {
  522. "name": "size",
  523. "title": "Msg size",
  524. "breakpoints": "all",
  525. "style": {
  526. "minwidth": 50,
  527. },
  528. "formatter": function(value) { return humanFileSize(value); }
  529. }, {
  530. "name": "scan_time",
  531. "title": "Scan time",
  532. "breakpoints": "all",
  533. "style": {
  534. "maxWidth": 72
  535. },
  536. }, {
  537. "name": "message-id",
  538. "title": "ID",
  539. "breakpoints": "all",
  540. "style": {
  541. "minWidth": 130,
  542. "overflow": "hidden",
  543. "textOverflow": "ellipsis",
  544. "wordBreak": "break-all",
  545. "whiteSpace": "normal"
  546. }
  547. }, {
  548. "name": "user",
  549. "title": "Authenticated user",
  550. "breakpoints": "xs sm md",
  551. "style": {
  552. "minWidth": 100
  553. }
  554. }],
  555. "rows": $.ajax({
  556. dataType: 'json',
  557. url: '/api/v1/get/logs/rspamd-history',
  558. jsonp: false,
  559. error: function () {
  560. console.log('Cannot draw rspamd history table');
  561. },
  562. success: function (data) {
  563. $.each(data, function (i, item) {
  564. item.rcpt_mime = item.rcpt_mime.join(",&#8203;");
  565. Object.keys(item.symbols).map(function(key) {
  566. var sym = item.symbols[key];
  567. if (sym.score <= 0) {
  568. sym.score_formatted = '(<span class="text-success"><b>' + sym.score + '</b></span>)'
  569. }
  570. else {
  571. sym.score_formatted = '(<span class="text-danger"><b>' + sym.score + '</b></span>)'
  572. }
  573. var str = '<strong>' + key + '</strong> ' + sym.score_formatted;
  574. if (sym.options) {
  575. str += ' [' + sym.options.join(",") + "]";
  576. }
  577. item.symbols[key].str = str;
  578. });
  579. item.symbols = Object.keys(item.symbols).
  580. map(function(key) {
  581. return item.symbols[key];
  582. }).sort(function(e1, e2) {
  583. return Math.abs(e1.score) < Math.abs(e2.score);
  584. }).map(function(e) {
  585. return e.str;
  586. }).join("<br>\n");
  587. var scan_time = item.time_real.toFixed(3) + ' / ' + item.time_virtual.toFixed(3);
  588. item.scan_time = {
  589. "options": {
  590. "sortValue": item.time_real
  591. },
  592. "value": scan_time
  593. };
  594. if (item.action === 'clean' || item.action === 'no action') {
  595. item.action = "<div class='label label-success'>" + item.action + "</div>";
  596. } else if (item.action === 'rewrite subject' || item.action === 'add header' || item.action === 'probable spam') {
  597. item.action = "<div class='label label-warning'>" + item.action + "</div>";
  598. } else if (item.action === 'spam' || item.action === 'reject') {
  599. item.action = "<div class='label label-danger'>" + item.action + "</div>";
  600. } else {
  601. item.action = "<div class='label label-info'>" + item.action + "</div>";
  602. }
  603. var score_content;
  604. if (item.score < item.required_score) {
  605. score_content = "[ <span class='text-success'>" + item.score.toFixed(2) + " / " + item.required_score + "</span> ]";
  606. } else {
  607. score_content = "[ <span class='text-danger'>" + item.score.toFixed(2) + " / " + item.required_score + "</span> ]";
  608. }
  609. item.score = {
  610. "options": {
  611. "sortValue": item.score
  612. },
  613. "value": score_content
  614. };
  615. if (item.user == null) {
  616. item.user = "none";
  617. }
  618. });
  619. }
  620. }),
  621. "empty": lang.empty,
  622. "paging": {
  623. "enabled": true,
  624. "limit": 5,
  625. "size": log_pagination_size
  626. },
  627. "filtering": {
  628. "enabled": true,
  629. "position": "left",
  630. "connectors": false,
  631. "placeholder": lang.filter_table
  632. },
  633. "sorting": {
  634. "enabled": true
  635. }
  636. });
  637. }
  638. draw_postfix_logs();
  639. draw_dovecot_logs();
  640. draw_sogo_logs();
  641. draw_fail2ban_logs();
  642. draw_domain_admins();
  643. draw_fwd_hosts();
  644. draw_relayhosts();
  645. draw_rspamd_history();
  646. $('#testRelayhostModal').on('show.bs.modal', function (e) {
  647. $('#test_relayhost_result').text("-");
  648. button = $(e.relatedTarget)
  649. if (button != null) {
  650. $('#relayhost_id').val(button.data('relayhost-id'));
  651. }
  652. })
  653. $('#showDKIMprivKey').on('show.bs.modal', function (e) {
  654. $('#priv_key_pre').text("-");
  655. p_related = $(e.relatedTarget)
  656. if (p_related != null) {
  657. var decoded_key = Base64.decode((p_related.data('priv-key')));
  658. $('#priv_key_pre').text(decoded_key);
  659. }
  660. })
  661. $('#test_relayhost').on('click', function (e) {
  662. e.preventDefault();
  663. prev = $('#test_relayhost').text();
  664. $(this).prop("disabled",true);
  665. $(this).html('<span class="glyphicon glyphicon-refresh glyphicon-spin"></span> ');
  666. $.ajax({
  667. type: 'GET',
  668. url: 'inc/relay_check.php',
  669. dataType: 'text',
  670. data: $('#test_relayhost_form').serialize(),
  671. complete: function (data) {
  672. $('#test_relayhost_result').html(data.responseText);
  673. $('#test_relayhost').prop("disabled",false);
  674. $('#test_relayhost').text(prev);
  675. }
  676. });
  677. })
  678. });
  679. $(window).load(function(){
  680. initial_width = $("#sidebar-admin").width();
  681. $("#scrollbox").css("width", initial_width);
  682. $(window).bind('scroll', function() {
  683. if ($(window).scrollTop() > 70) {
  684. $('#scrollbox').addClass('scrollboxFixed');
  685. } else {
  686. $('#scrollbox').removeClass('scrollboxFixed');
  687. }
  688. });
  689. });
  690. function resizeScrollbox() {
  691. on_resize_width = $("#sidebar-admin").width();
  692. $("#scrollbox").removeAttr("style");
  693. $("#scrollbox").css("width", on_resize_width);
  694. }
  695. $(window).on('resize', resizeScrollbox);
  696. $('a[data-toggle="tab"]').on('shown.bs.tab', resizeScrollbox);