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