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