debug.js 33 KB

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