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