debug.js 33 KB

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