blob: 7c077e27b5ab50ac9c135b7252705af99ea11a76 [file] [log] [blame]
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001$(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(LOCALE, DATETIME_FORMAT);
11 $(this).text(started_local_date);
12 } else {
13 $(this).text('-');
14 }
15 }
16 });
17 // Parse general dates
18 $('.parse_date').each(function(i, parse_date) {
19 var started_date = new Date(Date.parse($(this).text()));
20 if (typeof started_date != 'NaN') {
21 var started_local_date = started_date.toLocaleDateString(LOCALE, DATETIME_FORMAT);
22 $(this).text(started_local_date);
23 }
24 });
25
26 // set update loop container list
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010027 containersToUpdate = {};
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010028 // set default ChartJs Font Color
29 Chart.defaults.color = '#999';
30 // create host cpu and mem charts
31 createHostCpuAndMemChart();
32 // check for new version
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020033 if (mailcow_info.branch === "master" && mailcow_cc_role === "admin"){
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010034 check_update(mailcow_info.version_tag, mailcow_info.project_url);
35 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010036 $("#mailcow_version").click(function(){
37 if (mailcow_cc_role !== "admin" && mailcow_cc_role !== "domainadmin" || mailcow_info.branch !== "master")
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010038 return;
39
40 showVersionModal("Version " + mailcow_info.version_tag, mailcow_info.version_tag);
41 })
42 // get public ips
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010043 $("#host_show_ip").click(function(){
44 $("#host_show_ip").find(".text").addClass("d-none");
45 $("#host_show_ip").find(".spinner-border").removeClass("d-none");
46
47 window.fetch("/api/v1/get/status/host/ip", { method:'GET', cache:'no-cache' }).then(function(response) {
48 return response.json();
49 }).then(function(data) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010050 // display host ips
51 if (data.ipv4)
52 $("#host_ipv4").text(data.ipv4);
53 if (data.ipv6)
54 $("#host_ipv6").text(data.ipv6);
55
56 $("#host_show_ip").addClass("d-none");
57 $("#host_show_ip").find(".text").removeClass("d-none");
58 $("#host_show_ip").find(".spinner-border").addClass("d-none");
59 $("#host_ipv4").removeClass("d-none");
60 $("#host_ipv6").removeClass("d-none");
61 $("#host_ipv6").removeClass("text-danger");
62 $("#host_ipv4").addClass("d-block");
63 $("#host_ipv6").addClass("d-block");
64 }).catch(function(error){
65 console.log(error);
66
67 $("#host_ipv6").removeClass("d-none");
68 $("#host_ipv6").addClass("d-block");
69 $("#host_ipv6").addClass("text-danger");
70 $("#host_ipv6").text(lang_debug.error_show_ip);
71 $("#host_show_ip").find(".text").removeClass("d-none");
72 $("#host_show_ip").find(".spinner-border").addClass("d-none");
73 });
74 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010075 update_container_stats();
76});
77jQuery(function($){
78 if (localStorage.getItem("current_page") === null) {
79 var current_page = {};
80 } else {
81 var current_page = JSON.parse(localStorage.getItem('current_page'));
82 }
83 // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
84 var entityMap={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};
85 function escapeHtml(n){return String(n).replace(/[&<>"'`=\/]/g,function(n){return entityMap[n]})}
86 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]}
87 function hashCode(t){for(var n=0,r=0;r<t.length;r++)n=t.charCodeAt(r)+((n<<5)-n);return n}
88 function intToRGB(t){var n=(16777215&t).toString(16).toUpperCase();return"00000".substring(0,6-n.length)+n}
89 $(".refresh_table").on('click', function(e) {
90 e.preventDefault();
91 var table_name = $(this).data('table');
92 $('#' + table_name).DataTable().ajax.reload();
93 });
94 function createSortableDate(td, cellData) {
95 $(td).attr({
96 "data-order": cellData,
97 "data-sort": cellData
98 });
99 $(td).html(convertTimestampToLocalFormat(cellData));
100 }
101 function draw_autodiscover_logs() {
102 // just recalc width if instance already exists
103 if ($.fn.DataTable.isDataTable('#autodiscover_log') ) {
104 $('#autodiscover_log').DataTable().columns.adjust().responsive.recalc();
105 return;
106 }
107
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100108 var table = $('#autodiscover_log').DataTable({
109 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100110 processing: true,
111 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100112 stateSave: true,
113 pageLength: log_pagination_size,
114 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
115 "tr" +
116 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100117 language: lang_datatables,
118 order: [[0, 'desc']],
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100119 initComplete: function(){
120 hideTableExpandCollapseBtn('#tab-autodiscover-logs', '#autodiscover_log');
121 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100122 ajax: {
123 type: "GET",
124 url: "/api/v1/get/logs/autodiscover/100",
125 dataSrc: function(data){
126 return process_table_data(data, 'autodiscover_log');
127 }
128 },
129 columns: [
130 {
131 title: lang.time,
132 data: 'time',
133 defaultContent: '',
134 responsivePriority: 1,
135 createdCell: function(td, cellData) {
136 createSortableDate(td, cellData)
137 }
138 },
139 {
140 title: 'User-Agent',
141 data: 'ua',
142 defaultContent: '',
143 className: 'dtr-col-md',
144 responsivePriority: 5
145 },
146 {
147 title: 'Username',
148 data: 'user',
149 defaultContent: '',
150 responsivePriority: 4
151 },
152 {
153 title: 'IP',
154 data: 'ip',
155 defaultContent: '',
156 responsivePriority: 2
157 },
158 {
159 title: 'Service',
160 data: 'service',
161 defaultContent: '',
162 responsivePriority: 3
163 }
164 ]
165 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100166
167 table.on('responsive-resize', function (e, datatable, columns){
168 hideTableExpandCollapseBtn('#tab-autodiscover-logs', '#autodiscover_log');
169 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100170 }
171 function draw_postfix_logs() {
172 // just recalc width if instance already exists
173 if ($.fn.DataTable.isDataTable('#postfix_log') ) {
174 $('#postfix_log').DataTable().columns.adjust().responsive.recalc();
175 return;
176 }
177
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100178 var table = $('#postfix_log').DataTable({
179 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100180 processing: true,
181 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100182 stateSave: true,
183 pageLength: log_pagination_size,
184 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
185 "tr" +
186 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100187 language: lang_datatables,
188 order: [[0, 'desc']],
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100189 initComplete: function(){
190 hideTableExpandCollapseBtn('#tab-postfix-logs', '#postfix_log');
191 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100192 ajax: {
193 type: "GET",
194 url: "/api/v1/get/logs/postfix",
195 dataSrc: function(data){
196 return process_table_data(data, 'general_syslog');
197 }
198 },
199 columns: [
200 {
201 title: lang.time,
202 data: 'time',
203 defaultContent: '',
204 createdCell: function(td, cellData) {
205 createSortableDate(td, cellData)
206 }
207 },
208 {
209 title: lang.priority,
210 data: 'priority',
211 defaultContent: ''
212 },
213 {
214 title: lang.message,
215 data: 'message',
216 defaultContent: '',
217 className: 'dtr-col-md text-break'
218 }
219 ]
220 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100221
222 table.on('responsive-resize', function (e, datatable, columns){
223 hideTableExpandCollapseBtn('#tab-postfix-logs', '#postfix_log');
224 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100225 }
226 function draw_watchdog_logs() {
227 // just recalc width if instance already exists
228 if ($.fn.DataTable.isDataTable('#watchdog_log') ) {
229 $('#watchdog_log').DataTable().columns.adjust().responsive.recalc();
230 return;
231 }
232
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100233 var table = $('#watchdog_log').DataTable({
234 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100235 processing: true,
236 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100237 stateSave: true,
238 pageLength: log_pagination_size,
239 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
240 "tr" +
241 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100242 language: lang_datatables,
243 order: [[0, 'desc']],
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100244 initComplete: function(){
245 hideTableExpandCollapseBtn('#tab-watchdog-logs', '#watchdog_log');
246 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100247 ajax: {
248 type: "GET",
249 url: "/api/v1/get/logs/watchdog",
250 dataSrc: function(data){
251 return process_table_data(data, 'watchdog');
252 }
253 },
254 columns: [
255 {
256 title: lang.time,
257 data: 'time',
258 defaultContent: '',
259 createdCell: function(td, cellData) {
260 createSortableDate(td, cellData)
261 }
262 },
263 {
264 title: 'Service',
265 data: 'service',
266 defaultContent: ''
267 },
268 {
269 title: 'Trend',
270 data: 'trend',
271 defaultContent: ''
272 },
273 {
274 title: lang.message,
275 data: 'message',
276 defaultContent: ''
277 }
278 ]
279 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100280
281 table.on('responsive-resize', function (e, datatable, columns){
282 hideTableExpandCollapseBtn('#tab-watchdog-logs', '#watchdog_log');
283 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100284 }
285 function draw_api_logs() {
286 // just recalc width if instance already exists
287 if ($.fn.DataTable.isDataTable('#api_log') ) {
288 $('#api_log').DataTable().columns.adjust().responsive.recalc();
289 return;
290 }
291
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100292 var table = $('#api_log').DataTable({
293 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100294 processing: true,
295 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100296 stateSave: true,
297 pageLength: log_pagination_size,
298 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
299 "tr" +
300 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100301 language: lang_datatables,
302 order: [[0, 'desc']],
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100303 initComplete: function(){
304 hideTableExpandCollapseBtn('#tab-api-logs', '#api_log');
305 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100306 ajax: {
307 type: "GET",
308 url: "/api/v1/get/logs/api",
309 dataSrc: function(data){
310 return process_table_data(data, 'apilog');
311 }
312 },
313 columns: [
314 {
315 title: lang.time,
316 data: 'time',
317 defaultContent: '',
318 createdCell: function(td, cellData) {
319 createSortableDate(td, cellData)
320 }
321 },
322 {
323 title: 'URI',
324 data: 'uri',
325 defaultContent: '',
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200326 className: 'dtr-col-md dtr-break-all',
327 render: function (data, type) {
328 return escapeHtml(data);
329 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100330 },
331 {
332 title: 'Method',
333 data: 'method',
334 defaultContent: ''
335 },
336 {
337 title: 'IP',
338 data: 'remote',
339 defaultContent: ''
340 },
341 {
342 title: 'Data',
343 data: 'data',
344 defaultContent: '',
345 className: 'dtr-col-md dtr-break-all'
346 }
347 ]
348 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100349
350 table.on('responsive-resize', function (e, datatable, columns){
351 hideTableExpandCollapseBtn('#tab-api-logs', '#api_log');
352 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100353 }
354 function draw_rl_logs() {
355 // just recalc width if instance already exists
356 if ($.fn.DataTable.isDataTable('#rl_log') ) {
357 $('#rl_log').DataTable().columns.adjust().responsive.recalc();
358 return;
359 }
360
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100361 var table = $('#rl_log').DataTable({
362 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100363 processing: true,
364 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100365 stateSave: true,
366 pageLength: log_pagination_size,
367 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
368 "tr" +
369 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100370 language: lang_datatables,
371 order: [[0, 'desc']],
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100372 initComplete: function(){
373 hideTableExpandCollapseBtn('#tab-rl-logs', '#rl_log');
374 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100375 ajax: {
376 type: "GET",
377 url: "/api/v1/get/logs/ratelimited",
378 dataSrc: function(data){
379 return process_table_data(data, 'rllog');
380 }
381 },
382 columns: [
383 {
384 title: ' ',
385 data: 'indicator',
386 defaultContent: ''
387 },
388 {
389 title: lang.time,
390 data: 'time',
391 defaultContent: '',
392 createdCell: function(td, cellData) {
393 createSortableDate(td, cellData)
394 }
395 },
396 {
397 title: lang.rate_name,
398 data: 'rl_name',
399 defaultContent: ''
400 },
401 {
402 title: lang.sender,
403 data: 'from',
404 defaultContent: ''
405 },
406 {
407 title: lang.recipients,
408 data: 'rcpt',
409 defaultContent: ''
410 },
411 {
412 title: lang.authed_user,
413 data: 'user',
414 defaultContent: ''
415 },
416 {
417 title: 'Msg ID',
418 data: 'message_id',
419 defaultContent: ''
420 },
421 {
422 title: 'Header From',
423 data: 'header_from',
424 defaultContent: ''
425 },
426 {
427 title: 'Subject',
428 data: 'header_subject',
429 defaultContent: ''
430 },
431 {
432 title: 'Hash',
433 data: 'rl_hash',
434 defaultContent: ''
435 },
436 {
437 title: 'Rspamd QID',
438 data: 'qid',
439 defaultContent: ''
440 },
441 {
442 title: 'IP',
443 data: 'ip',
444 defaultContent: ''
445 },
446 {
447 title: lang.action,
448 data: 'action',
449 defaultContent: ''
450 }
451 ]
452 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100453
454 table.on('responsive-resize', function (e, datatable, columns){
455 hideTableExpandCollapseBtn('#tab-rl-logs', '#rl_log');
456 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100457 }
458 function draw_ui_logs() {
459 // just recalc width if instance already exists
460 if ($.fn.DataTable.isDataTable('#ui_logs') ) {
461 $('#ui_logs').DataTable().columns.adjust().responsive.recalc();
462 return;
463 }
464
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100465 var table = $('#ui_logs').DataTable({
466 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100467 processing: true,
468 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100469 stateSave: true,
470 pageLength: log_pagination_size,
471 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
472 "tr" +
473 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100474 language: lang_datatables,
475 order: [[0, 'desc']],
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100476 initComplete: function(){
477 hideTableExpandCollapseBtn('#tab-ui-logs', '#ui_logs');
478 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100479 ajax: {
480 type: "GET",
481 url: "/api/v1/get/logs/ui",
482 dataSrc: function(data){
483 return process_table_data(data, 'mailcow_ui');
484 }
485 },
486 columns: [
487 {
488 title: lang.time,
489 data: 'time',
490 defaultContent: '',
491 createdCell: function(td, cellData) {
492 createSortableDate(td, cellData)
493 }
494 },
495 {
496 title: 'Type',
497 data: 'type',
498 defaultContent: ''
499 },
500 {
501 title: 'Task',
502 data: 'task',
503 defaultContent: ''
504 },
505 {
506 title: 'User',
507 data: 'user',
508 defaultContent: '',
509 className: 'dtr-col-sm'
510 },
511 {
512 title: 'Role',
513 data: 'role',
514 defaultContent: '',
515 className: 'dtr-col-sm'
516 },
517 {
518 title: 'IP',
519 data: 'remote',
520 defaultContent: '',
521 className: 'dtr-col-md dtr-break-all'
522 },
523 {
524 title: lang.message,
525 data: 'msg',
526 defaultContent: '',
527 className: 'dtr-col-md dtr-break-all'
528 },
529 {
530 title: 'Call',
531 data: 'call',
532 defaultContent: '',
533 className: 'none dtr-col-md dtr-break-all'
534 }
535 ]
536 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100537
538 table.on('responsive-resize', function (e, datatable, columns){
539 hideTableExpandCollapseBtn('#tab-ui-logs', '#ui_log');
540 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100541 }
542 function draw_sasl_logs() {
543 // just recalc width if instance already exists
544 if ($.fn.DataTable.isDataTable('#sasl_logs') ) {
545 $('#sasl_logs').DataTable().columns.adjust().responsive.recalc();
546 return;
547 }
548
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100549 var table = $('#sasl_logs').DataTable({
550 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100551 processing: true,
552 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100553 stateSave: true,
554 pageLength: log_pagination_size,
555 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
556 "tr" +
557 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100558 language: lang_datatables,
559 order: [[0, 'desc']],
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100560 initComplete: function(){
561 hideTableExpandCollapseBtn('#tab-sasl-logs', '#sasl_logs');
562 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100563 ajax: {
564 type: "GET",
565 url: "/api/v1/get/logs/sasl",
566 dataSrc: function(data){
567 return process_table_data(data, 'sasl_log_table');
568 }
569 },
570 columns: [
571 {
572 title: lang.username,
573 data: 'username',
574 defaultContent: ''
575 },
576 {
577 title: lang.service,
578 data: 'service',
579 defaultContent: ''
580 },
581 {
582 title: 'IP',
583 data: 'real_rip',
584 defaultContent: '',
585 className: 'dtr-col-md text-break'
586 },
587 {
588 title: lang.login_time,
589 data: 'datetime',
590 defaultContent: '',
591 createdCell: function(td, cellData) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100592 cellData = Math.floor((new Date(cellData.replace(/-/g, "/"))).getTime() / 1000);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100593 createSortableDate(td, cellData)
594 }
595 }
596 ]
597 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100598
599 table.on('responsive-resize', function (e, datatable, columns){
600 hideTableExpandCollapseBtn('#tab-sasl-logs', '#sasl_logs');
601 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100602 }
603 function draw_acme_logs() {
604 // just recalc width if instance already exists
605 if ($.fn.DataTable.isDataTable('#acme_log') ) {
606 $('#acme_log').DataTable().columns.adjust().responsive.recalc();
607 return;
608 }
609
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100610 var table = $('#acme_log').DataTable({
611 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100612 processing: true,
613 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100614 stateSave: true,
615 pageLength: log_pagination_size,
616 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
617 "tr" +
618 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100619 language: lang_datatables,
620 order: [[0, 'desc']],
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100621 initComplete: function(){
622 hideTableExpandCollapseBtn('#tab-acme-logs', '#acme_log');
623 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100624 ajax: {
625 type: "GET",
626 url: "/api/v1/get/logs/acme",
627 dataSrc: function(data){
628 return process_table_data(data, 'general_syslog');
629 }
630 },
631 columns: [
632 {
633 title: lang.time,
634 data: 'time',
635 defaultContent: '',
636 createdCell: function(td, cellData) {
637 createSortableDate(td, cellData)
638 }
639 },
640 {
641 title: lang.message,
642 data: 'message',
643 defaultContent: '',
644 className: 'dtr-col-md dtr-break-all'
645 }
646 ]
647 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100648
649 table.on('responsive-resize', function (e, datatable, columns){
650 hideTableExpandCollapseBtn('#tab-acme-logs', '#acme_log');
651 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100652 }
653 function draw_netfilter_logs() {
654 // just recalc width if instance already exists
655 if ($.fn.DataTable.isDataTable('#netfilter_log') ) {
656 $('#netfilter_log').DataTable().columns.adjust().responsive.recalc();
657 return;
658 }
659
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100660 var table = $('#netfilter_log').DataTable({
661 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100662 processing: true,
663 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100664 stateSave: true,
665 pageLength: log_pagination_size,
666 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
667 "tr" +
668 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100669 language: lang_datatables,
670 order: [[0, 'desc']],
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100671 initComplete: function(){
672 hideTableExpandCollapseBtn('#tab-netfilter-logs', '#netfilter_log');
673 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100674 ajax: {
675 type: "GET",
676 url: "/api/v1/get/logs/netfilter",
677 dataSrc: function(data){
678 return process_table_data(data, 'general_syslog');
679 }
680 },
681 columns: [
682 {
683 title: lang.time,
684 data: 'time',
685 defaultContent: '',
686 createdCell: function(td, cellData) {
687 createSortableDate(td, cellData)
688 }
689 },
690 {
691 title: lang.priority,
692 data: 'priority',
693 defaultContent: ''
694 },
695 {
696 title: lang.message,
697 data: 'message',
698 defaultContent: '',
699 className: 'dtr-col-md text-break'
700 }
701 ]
702 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100703
704 table.on('responsive-resize', function (e, datatable, columns){
705 hideTableExpandCollapseBtn('#tab-netfilter-logs', '#netfilter_log');
706 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100707 }
708 function draw_sogo_logs() {
709 // just recalc width if instance already exists
710 if ($.fn.DataTable.isDataTable('#sogo_log') ) {
711 $('#sogo_log').DataTable().columns.adjust().responsive.recalc();
712 return;
713 }
714
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100715 var table = $('#sogo_log').DataTable({
716 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100717 processing: true,
718 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100719 stateSave: true,
720 pageLength: log_pagination_size,
721 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
722 "tr" +
723 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100724 language: lang_datatables,
725 order: [[0, 'desc']],
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100726 initComplete: function(){
727 hideTableExpandCollapseBtn('#tab-sogo-logs', '#sogo_log');
728 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100729 ajax: {
730 type: "GET",
731 url: "/api/v1/get/logs/sogo",
732 dataSrc: function(data){
733 return process_table_data(data, 'general_syslog');
734 }
735 },
736 columns: [
737 {
738 title: lang.time,
739 data: 'time',
740 defaultContent: '',
741 createdCell: function(td, cellData) {
742 createSortableDate(td, cellData)
743 }
744 },
745 {
746 title: lang.priority,
747 data: 'priority',
748 defaultContent: ''
749 },
750 {
751 title: lang.message,
752 data: 'message',
753 defaultContent: '',
754 className: 'dtr-col-md text-break'
755 }
756 ]
757 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100758
759 table.on('responsive-resize', function (e, datatable, columns){
760 hideTableExpandCollapseBtn('#tab-sogo-logs', '#sogo_log');
761 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100762 }
763 function draw_dovecot_logs() {
764 // just recalc width if instance already exists
765 if ($.fn.DataTable.isDataTable('#dovecot_log') ) {
766 $('#dovecot_log').DataTable().columns.adjust().responsive.recalc();
767 return;
768 }
769
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100770 var table = $('#dovecot_log').DataTable({
771 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100772 processing: true,
773 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100774 stateSave: true,
775 pageLength: log_pagination_size,
776 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
777 "tr" +
778 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100779 language: lang_datatables,
780 order: [[0, 'desc']],
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100781 initComplete: function(){
782 hideTableExpandCollapseBtn('#tab-dovecot-logs', '#dovecot_log');
783 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100784 ajax: {
785 type: "GET",
786 url: "/api/v1/get/logs/dovecot",
787 dataSrc: function(data){
788 return process_table_data(data, 'general_syslog');
789 }
790 },
791 columns: [
792 {
793 title: lang.time,
794 data: 'time',
795 defaultContent: '',
796 createdCell: function(td, cellData) {
797 createSortableDate(td, cellData)
798 }
799 },
800 {
801 title: lang.priority,
802 data: 'priority',
803 defaultContent: ''
804 },
805 {
806 title: lang.message,
807 data: 'message',
808 defaultContent: '',
809 className: 'dtr-col-md text-break'
810 }
811 ]
812 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100813
814 table.on('responsive-resize', function (e, datatable, columns){
815 hideTableExpandCollapseBtn('#tab-dovecot-logs', '#dovecot_log');
816 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100817 }
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200818 function draw_cron_logs() {
819 // just recalc width if instance already exists
820 if ($.fn.DataTable.isDataTable('#cron_log') ) {
821 $('#cron_log').DataTable().columns.adjust().responsive.recalc();
822 return;
823 }
824
825 var table = $('#cron_log').DataTable({
826 responsive: true,
827 processing: true,
828 serverSide: false,
829 stateSave: true,
830 pageLength: log_pagination_size,
831 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
832 "tr" +
833 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
834 language: lang_datatables,
835 order: [[0, 'desc']],
836 initComplete: function(){
837 hideTableExpandCollapseBtn('#tab-cron-logs', '#cron_log');
838 },
839 ajax: {
840 type: "GET",
841 url: "/api/v1/get/logs/cron",
842 dataSrc: function(data){
843 return process_table_data(data, 'general_syslog');
844 }
845 },
846 columns: [
847 {
848 title: lang.time,
849 data: 'time',
850 defaultContent: '',
851 createdCell: function(td, cellData) {
852 createSortableDate(td, cellData)
853 }
854 },
855 {
856 title: lang.task,
857 data: 'task',
858 defaultContent: ''
859 },
860 {
861 title: lang.priority,
862 data: 'priority',
863 defaultContent: ''
864 },
865 {
866 title: lang.message,
867 data: 'message',
868 defaultContent: '',
869 className: 'dtr-col-md text-break'
870 }
871 ]
872 });
873
874 table.on('responsive-resize', function (e, datatable, columns){
875 hideTableExpandCollapseBtn('#tab-cron-logs', '#cron_log');
876 });
877 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100878 function rspamd_pie_graph() {
879 $.ajax({
880 url: '/api/v1/get/rspamd/actions',
881 async: true,
882 success: function(data){
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100883 var total = 0;
884 $(data).map(function(){total += this[1];});
885 var labels = $.makeArray($(data).map(function(){return this[0] + ' ' + Math.round(this[1]/total * 100) + '%';}));
886 var values = $.makeArray($(data).map(function(){return this[1];}));
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100887
888 var graphdata = {
889 labels: labels,
890 datasets: [{
891 data: values,
892 backgroundColor: ['#DC3023', '#59ABE3', '#FFA400', '#FFA400', '#26A65B']
893 }]
894 };
895
896 var options = {
897 responsive: true,
898 maintainAspectRatio: false,
899 plugins: {
900 datalabels: {
901 color: '#FFF',
902 font: {
903 weight: 'bold'
904 },
905 display: function(context) {
906 return context.dataset.data[context.dataIndex] !== 0;
907 },
908 formatter: function(value, context) {
909 return Math.round(value/total*100) + '%';
910 }
911 }
912 }
913 };
914 var chartcanvas = document.getElementById('rspamd_donut');
915 Chart.register('ChartDataLabels');
916 if(typeof chart == 'undefined') {
917 chart = new Chart(chartcanvas.getContext("2d"), {
918 plugins: [ChartDataLabels],
919 type: 'doughnut',
920 data: graphdata,
921 options: options
922 });
923 }
924 else {
925 chart.destroy();
926 chart = new Chart(chartcanvas.getContext("2d"), {
927 plugins: [ChartDataLabels],
928 type: 'doughnut',
929 data: graphdata,
930 options: options
931 });
932 }
933 }
934 });
935 }
936 function draw_rspamd_history() {
937 // just recalc width if instance already exists
938 if ($.fn.DataTable.isDataTable('#rspamd_history') ) {
939 $('#rspamd_history').DataTable().columns.adjust().responsive.recalc();
940 return;
941 }
942
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100943 var table = $('#rspamd_history').DataTable({
944 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100945 processing: true,
946 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100947 stateSave: true,
948 pageLength: log_pagination_size,
949 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
950 "tr" +
951 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100952 language: lang_datatables,
953 order: [[0, 'desc']],
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100954 initComplete: function(){
955 hideTableExpandCollapseBtn('#tab-rspamd-logs', '#rspamd_history');
956 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100957 ajax: {
958 type: "GET",
959 url: "/api/v1/get/logs/rspamd-history",
960 dataSrc: function(data){
961 return process_table_data(data, 'rspamd_history');
962 }
963 },
964 columns: [
965 {
966 title: lang.time,
967 data: 'unix_time',
968 defaultContent: '',
969 createdCell: function(td, cellData) {
970 createSortableDate(td, cellData)
971 }
972 },
973 {
974 title: 'IP address',
975 data: 'ip',
976 defaultContent: ''
977 },
978 {
979 title: 'From',
980 data: 'sender_mime',
981 defaultContent: ''
982 },
983 {
984 title: 'To',
985 data: 'rcpt',
986 defaultContent: ''
987 },
988 {
989 title: 'Subject',
990 data: 'subject',
991 defaultContent: ''
992 },
993 {
994 title: 'Action',
995 data: 'action',
996 defaultContent: ''
997 },
998 {
999 title: 'Score',
1000 data: 'score',
1001 defaultContent: '',
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001002 class: 'text-nowrap',
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001003 createdCell: function(td, cellData) {
1004 $(td).attr({
1005 "data-order": cellData.sortBy,
1006 "data-sort": cellData.sortBy
1007 });
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001008 },
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001009 render: function (data) {
1010 return data.value;
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001011 }
1012 },
1013 {
1014 title: 'Symbols',
1015 data: 'symbols',
1016 defaultContent: '',
1017 className: 'none dtr-col-md'
1018 },
1019 {
1020 title: 'Msg size',
1021 data: 'size',
1022 defaultContent: ''
1023 },
1024 {
1025 title: 'Scan Time',
1026 data: 'scan_time',
1027 defaultContent: '',
1028 createdCell: function(td, cellData) {
1029 $(td).attr({
1030 "data-order": cellData.sortBy,
1031 "data-sort": cellData.sortBy
1032 });
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001033 },
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001034 render: function (data) {
1035 return data.value;
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001036 }
1037 },
1038 {
1039 title: 'ID',
1040 data: 'message-id',
1041 defaultContent: ''
1042 },
1043 {
1044 title: 'Authenticated user',
1045 data: 'user',
1046 defaultContent: ''
1047 }
1048 ]
1049 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001050
1051 table.on('responsive-resize', function (e, datatable, columns){
1052 hideTableExpandCollapseBtn('#tab-rspamd-history', '#rspamd_history');
1053 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001054 }
1055 function process_table_data(data, table) {
1056 if (table == 'rspamd_history') {
1057 $.each(data, function (i, item) {
1058 if (item.rcpt_mime != "") {
1059 item.rcpt = escapeHtml(item.rcpt_mime.join(", "));
1060 }
1061 else {
1062 item.rcpt = escapeHtml(item.rcpt_smtp.join(", "));
1063 }
1064 item.symbols = Object.keys(item.symbols).sort(function (a, b) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001065 if (item.symbols[a].score === 0) return 1;
1066 if (item.symbols[b].score === 0) return -1;
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001067 if (item.symbols[b].score < 0 && item.symbols[a].score < 0) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001068 return item.symbols[a].score - item.symbols[b].score;
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001069 }
1070 if (item.symbols[b].score > 0 && item.symbols[a].score > 0) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001071 return item.symbols[b].score - item.symbols[a].score;
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001072 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001073 return item.symbols[b].score - item.symbols[a].score;
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001074 }).map(function(key) {
1075 var sym = item.symbols[key];
1076 if (sym.score < 0) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001077 sym.score_formatted = '(<span class="text-success"><b>' + sym.score + '</b></span>)';
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001078 }
1079 else if (sym.score === 0) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001080 sym.score_formatted = '(<span><b>' + sym.score + '</b></span>)';
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001081 }
1082 else {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001083 sym.score_formatted = '(<span class="text-danger"><b>' + sym.score + '</b></span>)';
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001084 }
1085 var str = '<strong>' + key + '</strong> ' + sym.score_formatted;
1086 if (sym.options) {
1087 str += ' [' + escapeHtml(sym.options.join(", ")) + "]";
1088 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001089 return str;
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001090 }).join('<br>\n');
1091 item.subject = escapeHtml(item.subject);
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001092 if (item.sender_mime != null) item.sender_mime = escapeHtml(item.sender_mime);
1093 if (item['message-id'] != null) item['message-id'] = escapeHtml(item['message-id']);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001094 var scan_time = item.time_real.toFixed(3);
1095 if (item.time_virtual) {
1096 scan_time += ' / ' + item.time_virtual.toFixed(3);
1097 }
1098 item.scan_time = {
1099 "sortBy": item.time_real,
1100 "value": scan_time
1101 };
1102 if (item.action === 'clean' || item.action === 'no action') {
1103 item.action = "<div class='badge fs-6 bg-success'>" + item.action + "</div>";
1104 } else if (item.action === 'rewrite subject' || item.action === 'add header' || item.action === 'probable spam') {
1105 item.action = "<div class='badge fs-6 bg-warning'>" + item.action + "</div>";
1106 } else if (item.action === 'spam' || item.action === 'reject') {
1107 item.action = "<div class='badge fs-6 bg-danger'>" + item.action + "</div>";
1108 } else {
1109 item.action = "<div class='badge fs-6 bg-info'>" + item.action + "</div>";
1110 }
1111 var score_content;
1112 if (item.score < item.required_score) {
1113 score_content = "[ <span class='text-success'>" + item.score.toFixed(2) + " / " + item.required_score + "</span> ]";
1114 } else {
1115 score_content = "[ <span class='text-danger'>" + item.score.toFixed(2) + " / " + item.required_score + "</span> ]";
1116 }
1117 item.score = {
1118 "sortBy": item.score,
1119 "value": score_content
1120 };
1121 if (item.user == null) {
1122 item.user = "none";
1123 }
1124 });
1125 } else if (table == 'autodiscover_log') {
1126 $.each(data, function (i, item) {
1127 if (item.ua == null) {
1128 item.ua = 'unknown';
1129 } else {
1130 item.ua = escapeHtml(item.ua);
1131 }
1132 item.ua = '<span style="font-size:small">' + item.ua + '</span>';
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001133 if (item.user == null) {
1134 item.user = 'unknown';
1135 } else {
1136 item.user = escapeHtml(item.user);
1137 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001138 if (item.service == "activesync") {
1139 item.service = '<span class="badge fs-6 bg-info">ActiveSync</span>';
1140 }
1141 else if (item.service == "imap") {
1142 item.service = '<span class="badge fs-6 bg-success">IMAP, SMTP, Cal-/CardDAV</span>';
1143 }
1144 else {
1145 item.service = '<span class="badge fs-6 bg-danger">' + escapeHtml(item.service) + '</span>';
1146 }
1147 });
1148 } else if (table == 'watchdog') {
1149 $.each(data, function (i, item) {
1150 if (item.message == null) {
1151 item.message = 'Health level: ' + item.lvl + '% (' + item.hpnow + '/' + item.hptotal + ')';
1152 if (item.hpdiff < 0) {
1153 item.trend = '<span class="badge fs-6 bg-danger"><i class="bi bi-caret-down-fill"></i> ' + item.hpdiff + '</span>';
1154 }
1155 else if (item.hpdiff == 0) {
1156 item.trend = '<span class="badge fs-6 bg-info"><i class="bi bi-caret-right-fill"></i> ' + item.hpdiff + '</span>';
1157 }
1158 else {
1159 item.trend = '<span class="badge fs-6 bg-success"><i class="bi bi-caret-up-fill"></i> ' + item.hpdiff + '</span>';
1160 }
1161 }
1162 else {
1163 item.trend = '';
1164 item.service = '';
1165 }
1166 });
1167 } else if (table == 'mailcow_ui') {
1168 $.each(data, function (i, item) {
1169 if (item === null) { return true; }
1170 item.user = escapeHtml(item.user);
1171 item.call = escapeHtml(item.call);
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001172 if (item.msg) item.msg = escapeHtml(item.msg);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001173 item.task = '<code>' + item.task + '</code>';
1174 item.type = '<span class="badge fs-6 bg-' + item.type + '">' + item.type + '</span>';
1175 });
1176 } else if (table == 'sasl_log_table') {
1177 $.each(data, function (i, item) {
1178 if (item === null) { return true; }
1179 item.username = escapeHtml(item.username);
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001180 item.real_rip = escapeHtml(item.real_rip);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001181 item.service = '<div class="badge fs-6 bg-secondary">' + item.service.toUpperCase() + '</div>';
1182 });
1183 } else if (table == 'general_syslog') {
1184 $.each(data, function (i, item) {
1185 if (item === null) { return true; }
1186 if (item.message.match("^base64,")) {
1187 try {
1188 item.message = atob(item.message.slice(7)).replace(/\\n/g, "<br />");
1189 } catch(e) {
1190 item.message = item.message.slice(7);
1191 }
1192 } else {
1193 item.message = escapeHtml(item.message);
1194 }
1195 item.call = escapeHtml(item.call);
1196 var danger_class = ["emerg", "alert", "crit", "err"];
1197 var warning_class = ["warning", "warn"];
1198 var info_class = ["notice", "info", "debug"];
1199 if (jQuery.inArray(item.priority, danger_class) !== -1) {
1200 item.priority = '<span class="badge fs-6 bg-danger">' + item.priority + '</span>';
1201 } else if (jQuery.inArray(item.priority, warning_class) !== -1) {
1202 item.priority = '<span class="badge fs-6 bg-warning">' + item.priority + '</span>';
1203 } else if (jQuery.inArray(item.priority, info_class) !== -1) {
1204 item.priority = '<span class="badge fs-6 bg-info">' + item.priority + '</span>';
1205 }
1206 });
1207 } else if (table == 'apilog') {
1208 $.each(data, function (i, item) {
1209 if (item === null) { return true; }
1210 if (item.method == 'GET') {
1211 item.method = '<span class="badge fs-6 bg-success">' + item.method + '</span>';
1212 } else if (item.method == 'POST') {
1213 item.method = '<span class="badge fs-6 bg-warning">' + item.method + '</span>';
1214 }
1215 item.data = escapeHtml(item.data);
1216 });
1217 } else if (table == 'rllog') {
1218 $.each(data, function (i, item) {
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001219 if (item.header_from != null) item.header_from = escapeHtml(item.header_from);
1220 if (item.header_subject != null) item.header_subject = escapeHtml(item.header_subject);
1221 if (item.from != null) item.from = escapeHtml(item.from);
1222 if (item.rcpt != null) item.rcpt = escapeHtml(item.rcpt);
1223 if (item.message_id != null) item.message_id = escapeHtml(item.message_id);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001224 if (item.user == null) {
1225 item.user = "none";
1226 }
1227 if (item.rl_hash == null) {
1228 item.rl_hash = "err";
1229 }
1230 item.indicator = '<span style="border-right:6px solid #' + intToRGB(hashCode(item.rl_hash)) + ';padding-left:5px;">&nbsp;</span>';
1231 if (item.rl_hash != 'err') {
1232 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>';
1233 }
1234 });
1235 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001236 return data;
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001237 };
1238 $('.add_log_lines').on('click', function (e) {
1239 e.preventDefault();
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001240 var log_table= $(this).data("table");
1241 var new_nrows = $(this).data("nrows");
1242 var post_process = $(this).data("post-process");
1243 var log_url = $(this).data("log-url");
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001244 if (log_table === undefined || new_nrows === undefined || post_process === undefined || log_url === undefined) {
1245 console.log("no data-table or data-nrows or log_url or data-post-process attr found");
1246 return;
1247 }
1248
1249 if (table = $('#' + log_table).DataTable()) {
1250 var heading = $('#' + log_table).closest('.card').find('.card-header');
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001251 var load_rows = (table.data().count() + 1) + '-' + (table.data().count() + new_nrows)
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001252
1253 $.get('/api/v1/get/logs/' + log_url + '/' + load_rows).then(function(data){
1254 if (data.length === undefined) { mailcow_alert_box(lang.no_new_rows, "info"); return; }
1255 var rows = process_table_data(data, post_process);
1256 var rows_now = (table.page.len() + data.length);
1257 $(heading).children('.table-lines').text(rows_now)
1258 mailcow_alert_box(data.length + lang.additional_rows, "success");
1259 table.rows.add(rows).draw();
1260 });
1261 }
1262 })
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001263 function hideTableExpandCollapseBtn(tab, table){
1264 if ($(table).hasClass('collapsed'))
1265 $(tab).find(".table_collapse_option").show();
1266 else
1267 $(tab).find(".table_collapse_option").hide();
1268 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001269
1270 // detect element visibility changes
1271 function onVisible(element, callback) {
1272 $(document).ready(function() {
1273 element_object = document.querySelector(element);
1274 if (element_object === null) return;
1275
1276 new IntersectionObserver((entries, observer) => {
1277 entries.forEach(entry => {
1278 if(entry.intersectionRatio > 0) {
1279 callback(element_object);
1280 }
1281 });
1282 }).observe(element_object);
1283 });
1284 }
1285 // Draw Table if tab is active
1286 onVisible("[id^=postfix_log]", () => draw_postfix_logs());
1287 onVisible("[id^=dovecot_log]", () => draw_dovecot_logs());
1288 onVisible("[id^=sogo_log]", () => draw_sogo_logs());
1289 onVisible("[id^=watchdog_log]", () => draw_watchdog_logs());
1290 onVisible("[id^=autodiscover_log]", () => draw_autodiscover_logs());
1291 onVisible("[id^=acme_log]", () => draw_acme_logs());
1292 onVisible("[id^=api_log]", () => draw_api_logs());
1293 onVisible("[id^=rl_log]", () => draw_rl_logs());
1294 onVisible("[id^=ui_logs]", () => draw_ui_logs());
1295 onVisible("[id^=sasl_logs]", () => draw_sasl_logs());
1296 onVisible("[id^=netfilter_log]", () => draw_netfilter_logs());
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001297 onVisible("[id^=cron_log]", () => draw_cron_logs());
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001298 onVisible("[id^=rspamd_history]", () => draw_rspamd_history());
1299 onVisible("[id^=rspamd_donut]", () => rspamd_pie_graph());
1300
1301
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001302 // start polling host stats if tab is active
1303 onVisible("[id^=tab-containers]", () => update_stats());
1304 // start polling container stats if collapse is active
1305 var containerElements = document.querySelectorAll(".container-details-collapse");
1306 for (let i = 0; i < containerElements.length; i++){
1307 new IntersectionObserver((entries, observer) => {
1308 entries.forEach(entry => {
1309 if(entry.intersectionRatio > 0) {
1310
1311 if (!containerElements[i].classList.contains("show")){
1312 var container = containerElements[i].id.replace("Collapse", "");
1313 var container_id = containerElements[i].getAttribute("data-id");
1314
1315 // check if chart exists or needs to be created
1316 if (!Chart.getChart(container + "_DiskIOChart"))
1317 createReadWriteChart(container + "_DiskIOChart", "Read", "Write");
1318 if (!Chart.getChart(container + "_NetIOChart"))
1319 createReadWriteChart(container + "_NetIOChart", "Recv", "Sent");
1320
1321 // add container to polling list
1322 containersToUpdate[container] = {
1323 id: container_id,
1324 state: "idle"
1325 }
1326
1327 // stop polling if collapse is closed
1328 containerElements[i].addEventListener('hidden.bs.collapse', function () {
1329 var diskIOCtx = Chart.getChart(container + "_DiskIOChart");
1330 var netIOCtx = Chart.getChart(container + "_NetIOChart");
1331
1332 diskIOCtx.data.datasets[0].data = [];
1333 diskIOCtx.data.datasets[1].data = [];
1334 diskIOCtx.data.labels = [];
1335 netIOCtx.data.datasets[0].data = [];
1336 netIOCtx.data.datasets[1].data = [];
1337 netIOCtx.data.labels = [];
1338
1339 diskIOCtx.update();
1340 netIOCtx.update();
1341
1342 delete containersToUpdate[container];
1343 });
1344 }
1345
1346 }
1347 });
1348 }).observe(containerElements[i]);
1349 }
1350});
1351
1352
1353// update system stats - every 5 seconds if system & container tab is active
1354function update_stats(timeout=5){
1355 if (!$('#tab-containers').hasClass('active')) {
1356 // tab not active - dont fetch stats - run again in n seconds
1357 return;
1358 }
1359
1360 window.fetch("/api/v1/get/status/host", {method:'GET',cache:'no-cache'}).then(function(response) {
1361 return response.json();
1362 }).then(function(data) {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001363 if (data){
1364 // display table data
1365 $("#host_date").text(data.system_time);
1366 $("#host_uptime").text(formatUptime(data.uptime));
1367 $("#host_cpu_cores").text(data.cpu.cores);
1368 $("#host_cpu_usage").text(parseInt(data.cpu.usage).toString() + "%");
1369 $("#host_memory_total").text((data.memory.total / (1024 ** 3)).toFixed(2).toString() + "GB");
1370 $("#host_memory_usage").text(parseInt(data.memory.usage).toString() + "%");
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001371 $("#host_architecture").html(data.architecture);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001372 // update cpu and mem chart
1373 var cpu_chart = Chart.getChart("host_cpu_chart");
1374 var mem_chart = Chart.getChart("host_mem_chart");
1375
1376 cpu_chart.data.labels.push(data.system_time.split(" ")[1]);
1377 if (cpu_chart.data.labels.length > 30) cpu_chart.data.labels.shift();
1378 mem_chart.data.labels.push(data.system_time.split(" ")[1]);
1379 if (mem_chart.data.labels.length > 30) mem_chart.data.labels.shift();
1380
1381 cpu_chart.data.datasets[0].data.push(data.cpu.usage);
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001382 if (cpu_chart.data.datasets[0].data.length > 30) cpu_chart.data.datasets[0].data.shift();
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001383 mem_chart.data.datasets[0].data.push(data.memory.usage);
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001384 if (mem_chart.data.datasets[0].data.length > 30) mem_chart.data.datasets[0].data.shift();
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001385
1386 cpu_chart.update();
1387 mem_chart.update();
1388 }
1389
1390 // run again in n seconds
1391 setTimeout(update_stats, timeout * 1000);
1392 });
1393}
1394// update specific container stats - every n (default 5s) seconds
1395function update_container_stats(timeout=5){
1396
1397 if ($('#tab-containers').hasClass('active')) {
1398 for (let container in containersToUpdate){
1399 container_id = containersToUpdate[container].id;
1400 // check if container update stats is already running
1401 if (containersToUpdate[container].state == "running")
1402 continue;
1403 containersToUpdate[container].state = "running";
1404
1405
1406 window.fetch("/api/v1/get/status/container/" + container_id, {method:'GET',cache:'no-cache'}).then(function(response) {
1407 return response.json();
1408 }).then(function(data) {
1409 var diskIOCtx = Chart.getChart(container + "_DiskIOChart");
1410 var netIOCtx = Chart.getChart(container + "_NetIOChart");
1411
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001412 prev_stats = null;
1413 if (data.length >= 2){
1414 prev_stats = data[data.length -2];
1415
1416 // hide spinners if we collected enough data
1417 $('#' + container + "_DiskIOChart").removeClass('d-none');
1418 $('#' + container + "_DiskIOChart").prev().addClass('d-none');
1419 $('#' + container + "_NetIOChart").removeClass('d-none');
1420 $('#' + container + "_NetIOChart").prev().addClass('d-none');
1421 }
1422
1423 data = data[data.length -1];
1424
1425 if (prev_stats != null){
1426 // calc time diff
1427 var time_diff = (new Date(data.read) - new Date(prev_stats.read)) / 1000;
1428
1429 // calc disk io b/s
1430 if ('io_service_bytes_recursive' in prev_stats.blkio_stats && prev_stats.blkio_stats.io_service_bytes_recursive !== null){
1431 var prev_read_bytes = 0;
1432 var prev_write_bytes = 0;
1433 for (var i = 0; i < prev_stats.blkio_stats.io_service_bytes_recursive.length; i++){
1434 if (prev_stats.blkio_stats.io_service_bytes_recursive[i].op == "read")
1435 prev_read_bytes = prev_stats.blkio_stats.io_service_bytes_recursive[i].value;
1436 else if (prev_stats.blkio_stats.io_service_bytes_recursive[i].op == "write")
1437 prev_write_bytes = prev_stats.blkio_stats.io_service_bytes_recursive[i].value;
1438 }
1439 var read_bytes = 0;
1440 var write_bytes = 0;
1441 for (var i = 0; i < data.blkio_stats.io_service_bytes_recursive.length; i++){
1442 if (data.blkio_stats.io_service_bytes_recursive[i].op == "read")
1443 read_bytes = data.blkio_stats.io_service_bytes_recursive[i].value;
1444 else if (data.blkio_stats.io_service_bytes_recursive[i].op == "write")
1445 write_bytes = data.blkio_stats.io_service_bytes_recursive[i].value;
1446 }
1447 var diff_bytes_read = (read_bytes - prev_read_bytes) / time_diff;
1448 var diff_bytes_write = (write_bytes - prev_write_bytes) / time_diff;
1449 }
1450
1451 // calc net io b/s
1452 if ('networks' in prev_stats){
1453 var prev_recv_bytes = 0;
1454 var prev_sent_bytes = 0;
1455 for (var key in prev_stats.networks){
1456 prev_recv_bytes += prev_stats.networks[key].rx_bytes;
1457 prev_sent_bytes += prev_stats.networks[key].tx_bytes;
1458 }
1459 var recv_bytes = 0;
1460 var sent_bytes = 0;
1461 for (var key in data.networks){
1462 recv_bytes += data.networks[key].rx_bytes;
1463 sent_bytes += data.networks[key].tx_bytes;
1464 }
1465 var diff_bytes_recv = (recv_bytes - prev_recv_bytes) / time_diff;
1466 var diff_bytes_sent = (sent_bytes - prev_sent_bytes) / time_diff;
1467 }
1468
1469 addReadWriteChart(diskIOCtx, diff_bytes_read, diff_bytes_write, "");
1470 addReadWriteChart(netIOCtx, diff_bytes_recv, diff_bytes_sent, "");
1471 }
1472
1473 // run again in n seconds
1474 containersToUpdate[container].state = "idle";
1475 }).catch(err => {
1476 console.log(err);
1477 });
1478 }
1479 }
1480
1481 // run again in n seconds
1482 setTimeout(update_container_stats, timeout * 1000);
1483}
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001484// format hosts uptime seconds to readable string
1485function formatUptime(seconds){
1486 seconds = Number(seconds);
1487 var d = Math.floor(seconds / (3600*24));
1488 var h = Math.floor(seconds % (3600*24) / 3600);
1489 var m = Math.floor(seconds % 3600 / 60);
1490 var s = Math.floor(seconds % 60);
1491
1492 var dFormat = d > 0 ? d + "D " : "";
1493 var hFormat = h > 0 ? h + "H " : "";
1494 var mFormat = m > 0 ? m + "M " : "";
1495 var sFormat = s > 0 ? s + "S" : "";
1496 return dFormat + hFormat + mFormat + sFormat;
1497}
1498// format bytes to readable string
1499function formatBytes(bytes){
1500 // b
1501 if (bytes < 1000) return bytes.toFixed(2).toString()+' B/s';
1502 // b to kb
1503 bytes = bytes / 1024;
1504 if (bytes < 1000) return bytes.toFixed(2).toString()+' KB/s';
1505 // kb to mb
1506 bytes = bytes / 1024;
1507 if (bytes < 1000) return bytes.toFixed(2).toString()+' MB/s';
1508 // final mb to gb
1509 return (bytes / 1024).toFixed(2).toString()+' GB/s';
1510}
1511// create read write line chart
1512function createReadWriteChart(chart_id, read_lable, write_lable){
1513 var ctx = document.getElementById(chart_id);
1514
1515 var dataNet = {
1516 labels: [],
1517 datasets: [{
1518 label: read_lable,
1519 backgroundColor: "rgba(41, 187, 239, 0.3)",
1520 borderColor: "rgba(41, 187, 239, 0.6)",
1521 pointRadius: 1,
1522 pointHitRadius: 6,
1523 borderWidth: 2,
1524 fill: true,
1525 tension: 0.2,
1526 data: []
1527 }, {
1528 label: write_lable,
1529 backgroundColor: "rgba(239, 60, 41, 0.3)",
1530 borderColor: "rgba(239, 60, 41, 0.6)",
1531 pointRadius: 1,
1532 pointHitRadius: 6,
1533 borderWidth: 2,
1534 fill: true,
1535 tension: 0.2,
1536 data: []
1537 }]
1538 };
1539 var optionsNet = {
1540 interaction: {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001541 mode: 'index'
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001542 },
1543 scales: {
1544 yAxis: {
1545 min: 0,
1546 grid: {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001547 display: false
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001548 },
1549 ticks: {
1550 callback: function(i, index, ticks) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001551 return formatBytes(i);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001552 }
1553 }
1554 },
1555 xAxis: {
1556 grid: {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001557 display: false
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001558 }
1559 }
1560 }
1561 };
1562
1563 return new Chart(ctx, {
1564 type: 'line',
1565 data: dataNet,
1566 options: optionsNet
1567 });
1568}
1569// add to read write line chart
1570function addReadWriteChart(chart_context, read_point, write_point, time, limit = 30){
1571 // push time label for x-axis
1572 chart_context.data.labels.push(time);
1573 if (chart_context.data.labels.length > limit) chart_context.data.labels.shift();
1574
1575 // push datapoints
1576 chart_context.data.datasets[0].data.push(read_point);
1577 chart_context.data.datasets[1].data.push(write_point);
1578 // shift data if more than 20 entires exists
1579 if (chart_context.data.datasets[0].data.length > limit) chart_context.data.datasets[0].data.shift();
1580 if (chart_context.data.datasets[1].data.length > limit) chart_context.data.datasets[1].data.shift();
1581
1582 chart_context.update();
1583}
1584// create host cpu and mem chart
1585function createHostCpuAndMemChart(){
1586 var cpu_ctx = document.getElementById("host_cpu_chart");
1587 var mem_ctx = document.getElementById("host_mem_chart");
1588
1589 var dataCpu = {
1590 labels: [],
1591 datasets: [{
1592 label: "CPU %",
1593 backgroundColor: "rgba(41, 187, 239, 0.3)",
1594 borderColor: "rgba(41, 187, 239, 0.6)",
1595 pointRadius: 1,
1596 pointHitRadius: 6,
1597 borderWidth: 2,
1598 fill: true,
1599 tension: 0.2,
1600 data: []
1601 }]
1602 };
1603 var optionsCpu = {
1604 interaction: {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001605 mode: 'index'
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001606 },
1607 scales: {
1608 yAxis: {
1609 min: 0,
1610 grid: {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001611 display: false
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001612 },
1613 ticks: {
1614 callback: function(i, index, ticks) {
1615 return i.toFixed(0).toString() + "%";
1616 }
1617 }
1618 },
1619 xAxis: {
1620 grid: {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001621 display: false
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001622 }
1623 }
1624 }
1625 };
1626
1627 var dataMem = {
1628 labels: [],
1629 datasets: [{
1630 label: "MEM %",
1631 backgroundColor: "rgba(41, 187, 239, 0.3)",
1632 borderColor: "rgba(41, 187, 239, 0.6)",
1633 pointRadius: 1,
1634 pointHitRadius: 6,
1635 borderWidth: 2,
1636 fill: true,
1637 tension: 0.2,
1638 data: []
1639 }]
1640 };
1641 var optionsMem = {
1642 interaction: {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001643 mode: 'index'
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001644 },
1645 scales: {
1646 yAxis: {
1647 min: 0,
1648 grid: {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001649 display: false
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001650 },
1651 ticks: {
1652 callback: function(i, index, ticks) {
1653 return i.toFixed(0).toString() + "%";
1654 }
1655 }
1656 },
1657 xAxis: {
1658 grid: {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001659 display: false
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001660 }
1661 }
1662 }
1663 };
1664
1665
1666 var net_io_chart = new Chart(cpu_ctx, {
1667 type: 'line',
1668 data: dataCpu,
1669 options: optionsCpu
1670 });
1671 var disk_io_chart = new Chart(mem_ctx, {
1672 type: 'line',
1673 data: dataMem,
1674 options: optionsMem
1675 });
1676}
1677// check for mailcow updates
1678function check_update(current_version, github_repo_url){
1679 if (!current_version || !github_repo_url) return false;
1680
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001681
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001682 window.fetch("/inc/ajax/update_check.php", {method:'GET',cache:'no-cache'}).then(function(response) {
1683 if (!response.ok) throw new Error("update check returned " + response.status);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001684 return response.json();
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001685 }).then(function(data) {
1686 if (data.status === "no_update") {
1687 $("#mailcow_update").removeClass("text-warning text-danger").addClass("text-success");
1688 $("#mailcow_update").html("<b>" + lang_debug.no_update_available + "</b>");
1689 } else if (data.status === "update_available") {
1690 $("#mailcow_update").removeClass("text-danger text-success").addClass("text-warning");
1691 $("#mailcow_update").html(lang_debug.update_available + ` <a href="#" id="mailcow_update_changelog">`+data.latest_tag+`</a>`);
1692 $("#mailcow_update_changelog").click(function(){
1693 if (mailcow_cc_role !== "admin" && mailcow_cc_role !== "domainadmin")
1694 return;
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001695
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001696 showVersionModal("New Release " + data.latest_tag, data.latest_tag);
1697 })
1698 } else {
1699 throw new Error(data.message || "update check failed");
1700 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001701 }).catch(err => {
1702 // err
1703 console.log(err);
1704 $("#mailcow_update").removeClass("text-success text-warning").addClass("text-danger");
1705 $("#mailcow_update").html("<b>"+ lang_debug.update_failed +"</b>");
1706 });
1707}
1708// show version changelog modal
1709function showVersionModal(title, version){
1710 $.ajax({
1711 type: 'GET',
1712 url: 'https://api.github.com/repos/' + mailcow_info.project_owner + '/' + mailcow_info.project_repo + '/releases/tags/' + version,
1713 dataType: 'json',
1714 success: function (data) {
1715 var md = window.markdownit();
1716 var result = md.render(data.body);
1717 result = parseGithubMarkdownLinks(result);
1718
1719 $('#showVersionModal').find(".modal-title").html(title);
1720 $('#showVersionModal').find(".modal-body").html(`
1721 <h3>` + data.name + `</h3>
1722 <span class="mt-4">` + result + `</span>
1723 <span><b>Github Link:</b>
1724 <a target="_blank" href="https://github.com/` + mailcow_info.project_owner + `/` + mailcow_info.project_repo + `/releases/tag/` + version + `">` + version + `</a>
1725 </span>
1726 `);
1727
1728 new bootstrap.Modal(document.getElementById("showVersionModal"), {
1729 backdrop: 'static',
1730 keyboard: false
1731 }).show();
1732 }
1733 });
1734}
1735function parseGithubMarkdownLinks(inputText) {
1736 var replacedText, replacePattern1;
1737
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001738 replacePattern1 = /(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])(?![^<]*>)/gim;
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001739 replacedText = inputText.replace(replacePattern1, (matched, index, original, input_string) => {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001740 if (matched.includes('github.com')){
1741 // return short link if it's github link
1742 last_uri_path = matched.split('/');
1743 last_uri_path = last_uri_path[last_uri_path.length - 1];
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001744
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001745 // adjust Full Changelog link to match last git version and new git version, if link is a compare link
1746 if (matched.includes('/compare/') && mailcow_info.last_version_tag !== ''){
1747 matched = matched.replace(last_uri_path, mailcow_info.last_version_tag + '...' + mailcow_info.version_tag);
1748 last_uri_path = mailcow_info.last_version_tag + '...' + mailcow_info.version_tag;
1749 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001750
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001751 return '<a href="' + matched + '" target="_blank">' + last_uri_path + '</a><br>';
1752 };
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001753
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001754 // if it's not a github link, return complete link
1755 return '<a href="' + matched + '" target="_blank">' + matched + '</a>';
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001756 });
1757
1758 return replacedText;
1759}
1760
1761function convertTimestampToLocalFormat(timestamp) {
1762 var date = new Date(timestamp ? timestamp * 1000 : 0);
1763 return date.toLocaleDateString(LOCALE, DATETIME_FORMAT);
1764}