debug.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. jQuery(function($){
  2. if (localStorage.getItem("current_page") === null) {
  3. var current_page = {};
  4. } else {
  5. var current_page = JSON.parse(localStorage.getItem('current_page'));
  6. }
  7. // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
  8. var entityMap={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};
  9. function escapeHtml(n){return String(n).replace(/[&<>"'`=\/]/g,function(n){return entityMap[n]})}
  10. function humanFileSize(i){if(Math.abs(i)<1024)return i+" B";var B=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],e=-1;do{i/=1024,++e}while(Math.abs(i)>=1024&&e<B.length-1);return i.toFixed(1)+" "+B[e]}
  11. function hashCode(t){for(var n=0,r=0;r<t.length;r++)n=t.charCodeAt(r)+((n<<5)-n);return n}
  12. function intToRGB(t){var n=(16777215&t).toString(16).toUpperCase();return"00000".substring(0,6-n.length)+n}
  13. $(".refresh_table").on('click', function(e) {
  14. e.preventDefault();
  15. var table_name = $(this).data('table');
  16. $('#' + table_name).find("tr.footable-empty").remove();
  17. draw_table = $(this).data('draw');
  18. eval(draw_table + '()');
  19. });
  20. function table_log_ready(ft, name) {
  21. heading = ft.$el.parents('.panel').find('.panel-heading')
  22. var ft_paging = ft.use(FooTable.Paging)
  23. $('.refresh_table').prop("disabled", false);
  24. $(heading).children('.table-lines').text(function(){
  25. return ft_paging.totalRows;
  26. })
  27. if (current_page[name]) {
  28. ft_paging.goto(parseInt(current_page[name]))
  29. }
  30. }
  31. function table_log_paging(ft, name) {
  32. var ft_paging = ft.use(FooTable.Paging)
  33. current_page[name] = ft_paging.current;
  34. localStorage.setItem('current_page', JSON.stringify(current_page));
  35. }
  36. function draw_autodiscover_logs() {
  37. ft_autodiscover_logs = FooTable.init('#autodiscover_log', {
  38. "columns": [
  39. {"name":"time","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.time,"style":{"width":"170px"}},
  40. {"name":"ua","title":"User-Agent","style":{"min-width":"200px"}},
  41. {"name":"user","title":"Username","style":{"min-width":"200px"}},
  42. {"name":"service","title":"Service"},
  43. ],
  44. "rows": $.ajax({
  45. dataType: 'json',
  46. url: '/api/v1/get/logs/autodiscover/100',
  47. jsonp: false,
  48. error: function () {
  49. console.log('Cannot draw autodiscover log table');
  50. },
  51. success: function (data) {
  52. return process_table_data(data, 'autodiscover_log');
  53. }
  54. }),
  55. "empty": lang.empty,
  56. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  57. "filtering": {"enabled": true,"delay": 1200,"position": "left","placeholder": lang.filter_table},
  58. "sorting": {"enabled": true},
  59. "on": {
  60. "destroy.ft.table": function(e, ft){
  61. $('.refresh_table').attr('disabled', 'true');
  62. },
  63. "ready.ft.table": function(e, ft){
  64. table_log_ready(ft, 'autodiscover_logs');
  65. },
  66. "after.ft.paging": function(e, ft){
  67. table_log_paging(ft, 'autodiscover_logs');
  68. }
  69. }
  70. });
  71. }
  72. function draw_postfix_logs() {
  73. ft_postfix_logs = FooTable.init('#postfix_log', {
  74. "columns": [
  75. {"name":"time","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.time,"style":{"width":"170px"}},
  76. {"name":"priority","title":lang.priority,"style":{"width":"80px"}},
  77. {"name":"message","title":lang.message},
  78. ],
  79. "rows": $.ajax({
  80. dataType: 'json',
  81. url: '/api/v1/get/logs/postfix',
  82. jsonp: false,
  83. error: function () {
  84. console.log('Cannot draw postfix log table');
  85. },
  86. success: function (data) {
  87. return process_table_data(data, 'general_syslog');
  88. }
  89. }),
  90. "empty": lang.empty,
  91. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  92. "filtering": {"enabled": true,"delay": 1200,"position": "left","placeholder": lang.filter_table},
  93. "sorting": {"enabled": true},
  94. "on": {
  95. "destroy.ft.table": function(e, ft){
  96. $('.refresh_table').attr('disabled', 'true');
  97. },
  98. "ready.ft.table": function(e, ft){
  99. table_log_ready(ft, 'postfix_logs');
  100. },
  101. "after.ft.paging": function(e, ft){
  102. table_log_paging(ft, 'postfix_logs');
  103. }
  104. }
  105. });
  106. }
  107. function draw_watchdog_logs() {
  108. ft_watchdog_logs = FooTable.init('#watchdog_log', {
  109. "columns": [
  110. {"name":"time","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.time,"style":{"width":"170px"}},
  111. {"name":"service","title":"Service"},
  112. {"name":"trend","title":"Trend"},
  113. {"name":"message","title":lang.message},
  114. ],
  115. "rows": $.ajax({
  116. dataType: 'json',
  117. url: '/api/v1/get/logs/watchdog',
  118. jsonp: false,
  119. error: function () {
  120. console.log('Cannot draw watchdog log table');
  121. },
  122. success: function (data) {
  123. return process_table_data(data, 'watchdog');
  124. }
  125. }),
  126. "empty": lang.empty,
  127. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  128. "filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
  129. "sorting": {"enabled": true},
  130. "on": {
  131. "destroy.ft.table": function(e, ft){
  132. $('.refresh_table').attr('disabled', 'true');
  133. },
  134. "ready.ft.table": function(e, ft){
  135. table_log_ready(ft, 'postfix_logs');
  136. },
  137. "after.ft.paging": function(e, ft){
  138. table_log_paging(ft, 'postfix_logs');
  139. }
  140. }
  141. });
  142. }
  143. function draw_api_logs() {
  144. ft_api_logs = FooTable.init('#api_log', {
  145. "columns": [
  146. {"name":"time","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.time,"style":{"width":"170px"}},
  147. {"name":"uri","title":"URI","style":{"width":"310px"}},
  148. {"name":"method","title":"Method","style":{"width":"80px"}},
  149. {"name":"remote","title":"IP","style":{"width":"80px"}},
  150. {"name":"data","title":"Data","breakpoints": "all","style":{"word-break":"break-all"}},
  151. ],
  152. "rows": $.ajax({
  153. dataType: 'json',
  154. url: '/api/v1/get/logs/api',
  155. jsonp: false,
  156. error: function () {
  157. console.log('Cannot draw api log table');
  158. },
  159. success: function (data) {
  160. return process_table_data(data, 'apilog');
  161. }
  162. }),
  163. "empty": lang.empty,
  164. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  165. "filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
  166. "sorting": {"enabled": true},
  167. "on": {
  168. "destroy.ft.table": function(e, ft){
  169. $('.refresh_table').attr('disabled', 'true');
  170. },
  171. "ready.ft.table": function(e, ft){
  172. table_log_ready(ft, 'api_logs');
  173. },
  174. "after.ft.paging": function(e, ft){
  175. table_log_paging(ft, 'api_logs');
  176. }
  177. }
  178. });
  179. }
  180. function draw_rl_logs() {
  181. ft_rl_logs = FooTable.init('#rl_log', {
  182. "columns": [
  183. {"name":"indicator","title":" ","style":{"width":"50px"}},
  184. {"name":"time","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.last_applied,"style":{"width":"170px"}},
  185. {"name":"rl_name","title":lang.rate_name},
  186. {"name":"from","title":lang.sender},
  187. {"name":"rcpt","title":lang.recipients},
  188. {"name":"user","title":lang.authed_user},
  189. {"name":"message_id","title":"Msg ID","breakpoints": "all","style":{"word-break":"break-all"}},
  190. {"name":"header_from","title":"Header From","breakpoints": "all","style":{"word-break":"break-all"}},
  191. {"name":"header_subject","title":"Subject","breakpoints": "all","style":{"word-break":"break-all"}},
  192. {"name":"rl_hash","title":"Hash","breakpoints": "all","style":{"word-break":"break-all"}},
  193. {"name":"qid","title":"Rspamd QID","breakpoints": "all","style":{"word-break":"break-all"}},
  194. {"name":"ip","title":"IP","breakpoints": "all","style":{"word-break":"break-all"}},
  195. {"name":"action","title":lang.action,"breakpoints": "all","style":{"word-break":"break-all"}},
  196. ],
  197. "rows": $.ajax({
  198. dataType: 'json',
  199. url: '/api/v1/get/logs/ratelimited',
  200. jsonp: false,
  201. error: function () {
  202. console.log('Cannot draw rl log table');
  203. },
  204. success: function (data) {
  205. return process_table_data(data, 'rllog');
  206. }
  207. }),
  208. "empty": lang.empty,
  209. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  210. "filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
  211. "sorting": {"enabled": true},
  212. "on": {
  213. "destroy.ft.table": function(e, ft){
  214. $('.refresh_table').attr('disabled', 'true');
  215. },
  216. "ready.ft.table": function(e, ft){
  217. table_log_ready(ft, 'rl_logs');
  218. },
  219. "after.ft.paging": function(e, ft){
  220. table_log_paging(ft, 'rl_logs');
  221. }
  222. }
  223. });
  224. }
  225. function draw_ui_logs() {
  226. ft_api_logs = FooTable.init('#ui_logs', {
  227. "columns": [
  228. {"name":"time","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.time,"style":{"width":"170px"}},
  229. {"name":"type","title":"Type"},
  230. {"name":"task","title":"Task"},
  231. {"name":"user","title":"User"},
  232. {"name":"role","title":"Role"},
  233. {"name":"remote","title":"IP"},
  234. {"name":"msg","title":lang.message,"style":{"word-break":"break-all"}},
  235. {"name":"call","title":"Call","breakpoints": "all"},
  236. ],
  237. "rows": $.ajax({
  238. dataType: 'json',
  239. url: '/api/v1/get/logs/ui',
  240. jsonp: false,
  241. error: function () {
  242. console.log('Cannot draw ui log table');
  243. },
  244. success: function (data) {
  245. return process_table_data(data, 'mailcow_ui');
  246. }
  247. }),
  248. "empty": lang.empty,
  249. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  250. "filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
  251. "sorting": {"enabled": true},
  252. "on": {
  253. "destroy.ft.table": function(e, ft){
  254. $('.refresh_table').attr('disabled', 'true');
  255. },
  256. "ready.ft.table": function(e, ft){
  257. table_log_ready(ft, 'ui_logs');
  258. },
  259. "after.ft.paging": function(e, ft){
  260. table_log_paging(ft, 'ui_logs');
  261. }
  262. }
  263. });
  264. }
  265. function draw_acme_logs() {
  266. ft_acme_logs = FooTable.init('#acme_log', {
  267. "columns": [
  268. {"name":"time","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.time,"style":{"width":"170px"}},
  269. {"name":"message","title":lang.message,"style":{"word-break":"break-all"}},
  270. ],
  271. "rows": $.ajax({
  272. dataType: 'json',
  273. url: '/api/v1/get/logs/acme',
  274. jsonp: false,
  275. error: function () {
  276. console.log('Cannot draw acme log table');
  277. },
  278. success: function (data) {
  279. return process_table_data(data, 'general_syslog');
  280. }
  281. }),
  282. "empty": lang.empty,
  283. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  284. "filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
  285. "sorting": {"enabled": true},
  286. "on": {
  287. "destroy.ft.table": function(e, ft){
  288. $('.refresh_table').attr('disabled', 'true');
  289. },
  290. "ready.ft.table": function(e, ft){
  291. table_log_ready(ft, 'acme_logs');
  292. },
  293. "after.ft.paging": function(e, ft){
  294. table_log_paging(ft, 'acme_logs');
  295. }
  296. }
  297. });
  298. }
  299. function draw_netfilter_logs() {
  300. ft_netfilter_logs = FooTable.init('#netfilter_log', {
  301. "columns": [
  302. {"name":"time","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.time,"style":{"width":"170px"}},
  303. {"name":"priority","title":lang.priority,"style":{"width":"80px"}},
  304. {"name":"message","title":lang.message},
  305. ],
  306. "rows": $.ajax({
  307. dataType: 'json',
  308. url: '/api/v1/get/logs/netfilter',
  309. jsonp: false,
  310. error: function () {
  311. console.log('Cannot draw netfilter log table');
  312. },
  313. success: function (data) {
  314. return process_table_data(data, 'general_syslog');
  315. }
  316. }),
  317. "empty": lang.empty,
  318. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  319. "filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
  320. "sorting": {"enabled": true},
  321. "on": {
  322. "destroy.ft.table": function(e, ft){
  323. $('.refresh_table').attr('disabled', 'true');
  324. },
  325. "ready.ft.table": function(e, ft){
  326. table_log_ready(ft, 'netfilter_logs');
  327. },
  328. "after.ft.paging": function(e, ft){
  329. table_log_paging(ft, 'netfilter_logs');
  330. }
  331. }
  332. });
  333. }
  334. function draw_sogo_logs() {
  335. ft_sogo_logs = FooTable.init('#sogo_log', {
  336. "columns": [
  337. {"name":"time","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.time,"style":{"width":"170px"}},
  338. {"name":"priority","title":lang.priority,"style":{"width":"80px"}},
  339. {"name":"message","title":lang.message},
  340. ],
  341. "rows": $.ajax({
  342. dataType: 'json',
  343. url: '/api/v1/get/logs/sogo',
  344. jsonp: false,
  345. error: function () {
  346. console.log('Cannot draw sogo log table');
  347. },
  348. success: function (data) {
  349. return process_table_data(data, 'general_syslog');
  350. }
  351. }),
  352. "empty": lang.empty,
  353. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  354. "filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
  355. "sorting": {"enabled": true},
  356. "on": {
  357. "destroy.ft.table": function(e, ft){
  358. $('.refresh_table').attr('disabled', 'true');
  359. },
  360. "ready.ft.table": function(e, ft){
  361. table_log_ready(ft, 'sogo_logs');
  362. },
  363. "after.ft.paging": function(e, ft){
  364. table_log_paging(ft, 'sogo_logs');
  365. }
  366. }
  367. });
  368. }
  369. function draw_dovecot_logs() {
  370. ft_dovecot_logs = FooTable.init('#dovecot_log', {
  371. "columns": [
  372. {"name":"time","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.time,"style":{"width":"170px"}},
  373. {"name":"priority","title":lang.priority,"style":{"width":"80px"}},
  374. {"name":"message","title":lang.message},
  375. ],
  376. "rows": $.ajax({
  377. dataType: 'json',
  378. url: '/api/v1/get/logs/dovecot',
  379. jsonp: false,
  380. error: function () {
  381. console.log('Cannot draw dovecot log table');
  382. },
  383. success: function (data) {
  384. return process_table_data(data, 'general_syslog');
  385. }
  386. }),
  387. "empty": lang.empty,
  388. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  389. "filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
  390. "sorting": {"enabled": true},
  391. "on": {
  392. "destroy.ft.table": function(e, ft){
  393. $('.refresh_table').attr('disabled', 'true');
  394. },
  395. "ready.ft.table": function(e, ft){
  396. table_log_ready(ft, 'dovecot_logs');
  397. },
  398. "after.ft.paging": function(e, ft){
  399. table_log_paging(ft, 'dovecot_logs');
  400. }
  401. }
  402. });
  403. }
  404. function rspamd_pie_graph() {
  405. $.ajax({
  406. url: '/api/v1/get/rspamd/actions',
  407. async: true,
  408. success: function(data){
  409. var total = 0;
  410. $(data).map(function(){total += this[1];});
  411. var labels = $.makeArray($(data).map(function(){return this[0] + ' ' + Math.round(this[1]/total * 100) + '%';}));
  412. var values = $.makeArray($(data).map(function(){return this[1];}));
  413. var graphdata = {
  414. labels: labels,
  415. datasets: [{
  416. data: values,
  417. backgroundColor: ['#DC3023', '#59ABE3', '#FFA400', '#FFA400', '#26A65B']
  418. }]
  419. };
  420. var options = {
  421. responsive: true,
  422. maintainAspectRatio: false,
  423. plugins: {
  424. datalabels: {
  425. color: '#FFF',
  426. font: {
  427. weight: 'bold'
  428. },
  429. display: function(context) {
  430. return context.dataset.data[context.dataIndex] !== 0;
  431. },
  432. formatter: function(value, context) {
  433. return Math.round(value/total*100) + '%';
  434. }
  435. }
  436. }
  437. };
  438. var chartcanvas = document.getElementById('rspamd_donut');
  439. Chart.plugins.register('ChartDataLabels');
  440. if(typeof chart == 'undefined') {
  441. chart = new Chart(chartcanvas.getContext("2d"), {
  442. plugins: [ChartDataLabels],
  443. type: 'doughnut',
  444. data: graphdata,
  445. options: options
  446. });
  447. }
  448. else {
  449. chart.destroy();
  450. chart = new Chart(chartcanvas.getContext("2d"), {
  451. plugins: [ChartDataLabels],
  452. type: 'doughnut',
  453. data: graphdata,
  454. options: options
  455. });
  456. }
  457. }
  458. });
  459. }
  460. function draw_rspamd_history() {
  461. ft_rspamd_history = FooTable.init('#rspamd_history', {
  462. "columns": [
  463. {"name":"unix_time","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.time,"style":{"width":"170px"}},
  464. {"name": "ip","title": "IP address","breakpoints": "all","style": {"minWidth": 88}},
  465. {"name": "sender_mime","title": "From","breakpoints": "xs sm md","style": {"minWidth": 100}},
  466. {"name": "rcpt","title": "To","breakpoints": "xs sm md","style": {"minWidth": 100}},
  467. {"name": "subject","title": "Subject","breakpoints": "all","style": {"word-break": "break-all","minWidth": 150}},
  468. {"name": "action","title": "Action","style": {"minwidth": 82}},
  469. {"name": "score","title": "Score","style": {"maxWidth": 110},},
  470. {"name": "symbols","title": "Symbols","breakpoints": "all",},
  471. {"name": "size","title": "Msg size","breakpoints": "all","style": {"minwidth": 50},"formatter": function(value){return humanFileSize(value);}},
  472. {"name": "scan_time","title": "Scan time","breakpoints": "all","style": {"maxWidth": 72},},
  473. {"name": "message-id","title": "ID","breakpoints": "all","style": {"minWidth": 130,"overflow": "hidden","textOverflow": "ellipsis","wordBreak": "break-all","whiteSpace": "normal"}},
  474. {"name": "user","title": "Authenticated user","breakpoints": "xs sm md","style": {"minWidth": 100}}
  475. ],
  476. "rows": $.ajax({
  477. dataType: 'json',
  478. url: '/api/v1/get/logs/rspamd-history',
  479. jsonp: false,
  480. error: function () {
  481. console.log('Cannot draw rspamd history table');
  482. },
  483. success: function (data) {
  484. return process_table_data(data, 'rspamd_history');
  485. }
  486. }),
  487. "empty": lang.empty,
  488. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  489. "filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
  490. "sorting": {"enabled": true},
  491. "on": {
  492. "destroy.ft.table": function(e, ft){
  493. $('.refresh_table').attr('disabled', 'true');
  494. },
  495. "ready.ft.table": function(e, ft){
  496. table_log_ready(ft, 'rspamd_history');
  497. heading = ft.$el.parents('.panel').find('.panel-heading')
  498. $(heading).children('.table-lines').text(function(){
  499. var ft_paging = ft.use(FooTable.Paging)
  500. return ft_paging.totalRows;
  501. })
  502. rspamd_pie_graph();
  503. },
  504. "after.ft.paging": function(e, ft){
  505. table_log_paging(ft, 'rspamd_history');
  506. }
  507. }
  508. });
  509. }
  510. function process_table_data(data, table) {
  511. if (table == 'rspamd_history') {
  512. $.each(data, function (i, item) {
  513. if (item.rcpt_mime != "") {
  514. item.rcpt = escapeHtml(item.rcpt_mime.join(", "));
  515. }
  516. else {
  517. item.rcpt = escapeHtml(item.rcpt_smtp.join(", "));
  518. }
  519. item.symbols = Object.keys(item.symbols).sort(function (a, b) {
  520. if (item.symbols[a].score === 0) return 1
  521. if (item.symbols[b].score === 0) return -1
  522. if (item.symbols[b].score < 0 && item.symbols[a].score < 0) {
  523. return item.symbols[a].score - item.symbols[b].score
  524. }
  525. if (item.symbols[b].score > 0 && item.symbols[a].score > 0) {
  526. return item.symbols[b].score - item.symbols[a].score
  527. }
  528. return item.symbols[b].score - item.symbols[a].score
  529. }).map(function(key) {
  530. var sym = item.symbols[key];
  531. if (sym.score < 0) {
  532. sym.score_formatted = '(<span class="text-success"><b>' + sym.score + '</b></span>)'
  533. }
  534. else if (sym.score === 0) {
  535. sym.score_formatted = '(<span><b>' + sym.score + '</b></span>)'
  536. }
  537. else {
  538. sym.score_formatted = '(<span class="text-danger"><b>' + sym.score + '</b></span>)'
  539. }
  540. var str = '<strong>' + key + '</strong> ' + sym.score_formatted;
  541. if (sym.options) {
  542. str += ' [' + escapeHtml(sym.options.join(", ")) + "]";
  543. }
  544. return str
  545. }).join('<br>\n');
  546. item.subject = escapeHtml(item.subject);
  547. var scan_time = item.time_real.toFixed(3);
  548. if (item.time_virtual) {
  549. scan_time += ' / ' + item.time_virtual.toFixed(3);
  550. }
  551. item.scan_time = {
  552. "options": {
  553. "sortValue": item.time_real
  554. },
  555. "value": scan_time
  556. };
  557. if (item.action === 'clean' || item.action === 'no action') {
  558. item.action = "<div class='label label-success'>" + item.action + "</div>";
  559. } else if (item.action === 'rewrite subject' || item.action === 'add header' || item.action === 'probable spam') {
  560. item.action = "<div class='label label-warning'>" + item.action + "</div>";
  561. } else if (item.action === 'spam' || item.action === 'reject') {
  562. item.action = "<div class='label label-danger'>" + item.action + "</div>";
  563. } else {
  564. item.action = "<div class='label label-info'>" + item.action + "</div>";
  565. }
  566. var score_content;
  567. if (item.score < item.required_score) {
  568. score_content = "[ <span class='text-success'>" + item.score.toFixed(2) + " / " + item.required_score + "</span> ]";
  569. } else {
  570. score_content = "[ <span class='text-danger'>" + item.score.toFixed(2) + " / " + item.required_score + "</span> ]";
  571. }
  572. item.score = {
  573. "options": {
  574. "sortValue": item.score
  575. },
  576. "value": score_content
  577. };
  578. if (item.user == null) {
  579. item.user = "none";
  580. }
  581. });
  582. } else if (table == 'autodiscover_log') {
  583. $.each(data, function (i, item) {
  584. if (item.ua == null) {
  585. item.ua = 'unknown';
  586. } else {
  587. item.ua = escapeHtml(item.ua);
  588. }
  589. item.ua = '<span style="font-size:small">' + item.ua + '</span>';
  590. if (item.service == "activesync") {
  591. item.service = '<span class="label label-info">ActiveSync</span>';
  592. }
  593. else if (item.service == "imap") {
  594. item.service = '<span class="label label-success">IMAP, SMTP, Cal-/CardDAV</span>';
  595. }
  596. else {
  597. item.service = '<span class="label label-danger">' + escapeHtml(item.service) + '</span>';
  598. }
  599. });
  600. } else if (table == 'watchdog') {
  601. $.each(data, function (i, item) {
  602. if (item.message == null) {
  603. item.message = 'Health level: ' + item.lvl + '% (' + item.hpnow + '/' + item.hptotal + ')';
  604. if (item.hpdiff < 0) {
  605. item.trend = '<span class="label label-danger"><span class="glyphicon glyphicon-arrow-down"></span> ' + item.hpdiff + '</span>';
  606. }
  607. else if (item.hpdiff == 0) {
  608. item.trend = '<span class="label label-info"><span class="glyphicon glyphicon-arrow-right"></span> ' + item.hpdiff + '</span>';
  609. }
  610. else {
  611. item.trend = '<span class="label label-success"><span class="glyphicon glyphicon-arrow-up"></span> ' + item.hpdiff + '</span>';
  612. }
  613. }
  614. else {
  615. item.trend = '';
  616. item.service = '';
  617. }
  618. });
  619. } else if (table == 'mailcow_ui') {
  620. $.each(data, function (i, item) {
  621. if (item === null) { return true; }
  622. item.user = escapeHtml(item.user);
  623. item.call = escapeHtml(item.call);
  624. item.task = '<code>' + item.task + '</code>';
  625. item.type = '<span class="label label-' + item.type + '">' + item.type + '</span>';
  626. });
  627. } else if (table == 'general_syslog') {
  628. $.each(data, function (i, item) {
  629. if (item === null) { return true; }
  630. if (item.message.match("^base64,")) {
  631. item.message = atob(item.message.slice(7)).replace(/\\n/g, "<br />");
  632. } else {
  633. item.message = escapeHtml(item.message);
  634. }
  635. item.call = escapeHtml(item.call);
  636. var danger_class = ["emerg", "alert", "crit", "err"];
  637. var warning_class = ["warning", "warn"];
  638. var info_class = ["notice", "info", "debug"];
  639. if (jQuery.inArray(item.priority, danger_class) !== -1) {
  640. item.priority = '<span class="label label-danger">' + item.priority + '</span>';
  641. } else if (jQuery.inArray(item.priority, warning_class) !== -1) {
  642. item.priority = '<span class="label label-warning">' + item.priority + '</span>';
  643. } else if (jQuery.inArray(item.priority, info_class) !== -1) {
  644. item.priority = '<span class="label label-info">' + item.priority + '</span>';
  645. }
  646. });
  647. } else if (table == 'apilog') {
  648. $.each(data, function (i, item) {
  649. if (item === null) { return true; }
  650. if (item.method == 'GET') {
  651. item.method = '<span class="label label-success">' + item.method + '</span>';
  652. } else if (item.method == 'POST') {
  653. item.method = '<span class="label label-warning">' + item.method + '</span>';
  654. }
  655. item.data = escapeHtml(item.data);
  656. });
  657. } else if (table == 'rllog') {
  658. $.each(data, function (i, item) {
  659. if (item.user == null) {
  660. item.user = "none";
  661. }
  662. if (item.rl_hash == null) {
  663. item.rl_hash = "err";
  664. }
  665. item.indicator = '<span style="border-right:6px solid #' + intToRGB(hashCode(item.rl_hash)) + ';padding-left:5px;">&nbsp;</span>';
  666. if (item.rl_hash != 'err') {
  667. item.action = '<a href="#" data-action="delete_selected" data-id="single-hash" data-api-url="delete/rlhash" data-item="' + encodeURI(item.rl_hash) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.reset_limit + '</a>';
  668. }
  669. });
  670. }
  671. return data
  672. };
  673. $('.add_log_lines').on('click', function (e) {
  674. e.preventDefault();
  675. var log_table= $(this).data("table")
  676. var new_nrows = $(this).data("nrows")
  677. var post_process = $(this).data("post-process")
  678. var log_url = $(this).data("log-url")
  679. if (log_table === undefined || new_nrows === undefined || post_process === undefined || log_url === undefined) {
  680. console.log("no data-table or data-nrows or log_url or data-post-process attr found");
  681. return;
  682. }
  683. if (ft = FooTable.get($('#' + log_table))) {
  684. var heading = ft.$el.parents('.panel').find('.panel-heading')
  685. var ft_paging = ft.use(FooTable.Paging)
  686. var load_rows = (ft_paging.totalRows + 1) + '-' + (ft_paging.totalRows + new_nrows)
  687. $.get('/api/v1/get/logs/' + log_url + '/' + load_rows).then(function(data){
  688. if (data.length === undefined) { mailcow_alert_box(lang.no_new_rows, "info"); return; }
  689. var rows = process_table_data(data, post_process);
  690. var rows_now = (ft_paging.totalRows + data.length);
  691. $(heading).children('.table-lines').text(rows_now)
  692. mailcow_alert_box(data.length + lang.additional_rows, "success");
  693. ft.rows.load(rows, true);
  694. });
  695. }
  696. })
  697. // Initial table drawings
  698. draw_postfix_logs();
  699. draw_autodiscover_logs();
  700. draw_dovecot_logs();
  701. draw_sogo_logs();
  702. draw_watchdog_logs();
  703. draw_acme_logs();
  704. draw_api_logs();
  705. draw_rl_logs();
  706. draw_ui_logs();
  707. draw_netfilter_logs();
  708. draw_rspamd_history();
  709. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  710. var target = $(e.target).attr("href");
  711. if (target == '#tab-rspamd-history') {
  712. rspamd_pie_graph();
  713. }
  714. });
  715. });