debug.js 35 KB

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