From 4b8736fb4e562c78505daaee042bcd798242c3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanka=20Rodr=C3=ADguez?= Date: Fri, 17 May 2019 10:13:46 +0200 Subject: [PATCH] Add timezone offset to dates (#1406) --- public/controllers/agent/agents-preview.js | 4 +- public/controllers/agent/agents.js | 37 +++-- public/controllers/management/logs.js | 21 ++- public/controllers/misc/reporting.js | 11 +- public/directives/wz-table/lib/parse-value.js | 18 ++- .../directives/wz-table/wz-table-directive.js | 5 +- public/services/index.js | 2 + public/services/time-service.js | 28 ++++ public/templates/agents-prev/agents-prev.html | 2 +- public/templates/agents/agents-sca.html | 4 +- .../templates/agents/agents-syscollector.html | 8 +- public/templates/agents/agents-welcome.html | 135 ++++++++---------- public/templates/management/reporting.html | 4 +- 13 files changed, 170 insertions(+), 109 deletions(-) create mode 100644 public/services/time-service.js diff --git a/public/controllers/agent/agents-preview.js b/public/controllers/agent/agents-preview.js index 610831a7f0..44526012bb 100644 --- a/public/controllers/agent/agents-preview.js +++ b/public/controllers/agent/agents-preview.js @@ -35,7 +35,8 @@ export class AgentsPreviewController { wzTableFilter, commonData, wazuhConfig, - $window + $window, + timeService ) { this.$scope = $scope; this.genericReq = genericReq; @@ -49,6 +50,7 @@ export class AgentsPreviewController { this.wazuhConfig = wazuhConfig; this.errorInit = false; this.$window = $window; + this.timeService = timeService; } /** diff --git a/public/controllers/agent/agents.js b/public/controllers/agent/agents.js index 45173810a0..bea123d933 100644 --- a/public/controllers/agent/agents.js +++ b/public/controllers/agent/agents.js @@ -58,7 +58,8 @@ export class AgentsController { wzTableFilter, $mdDialog, groupHandler, - wazuhConfig + wazuhConfig, + timeService ) { this.$scope = $scope; this.$location = $location; @@ -76,6 +77,7 @@ export class AgentsController { this.$mdDialog = $mdDialog; this.groupHandler = groupHandler; this.wazuhConfig = wazuhConfig; + this.timeService = timeService; // Config on-demand this.$scope.isArray = Array.isArray; @@ -267,6 +269,7 @@ export class AgentsController { this.$scope.isString = item => typeof item === 'string'; this.$scope.hasSize = obj => obj && typeof obj === 'object' && Object.keys(obj).length; + this.$scope.offsetTimestamp = (text, time) => this.offsetTimestamp(text, time); this.$scope.switchConfigTab = ( configurationTab, sections, @@ -545,7 +548,7 @@ export class AgentsController { (((agentInfo || {}).data || {}).data || {}).status || this.$scope.agent.status; } - } catch (error) {} // eslint-disable-line + } catch (error) { } // eslint-disable-line try { this.$scope.showSyscheckFiles = false; @@ -580,7 +583,7 @@ export class AgentsController { if (tab === 'syscollector') try { await this.loadSyscollector(this.$scope.agent.id); - } catch (error) {} // eslint-disable-line + } catch (error) { } // eslint-disable-line if (tab === 'configuration') { this.$scope.switchConfigurationTab('welcome'); } else { @@ -708,7 +711,7 @@ export class AgentsController { {} ); netifaceResponse = ((resultNetiface || {}).data || {}).data || false; - } catch (error) {} // eslint-disable-line + } catch (error) { } // eslint-disable-line // This API call may fail so we put it out of Promise.all let netaddrResponse = false; @@ -720,7 +723,7 @@ export class AgentsController { ); netaddrResponse = ((resultNetaddrResponse || {}).data || {}).data || false; - } catch (error) {} // eslint-disable-line + } catch (error) { } // eslint-disable-line // Before proceeding, syscollector data is an empty object this.$scope.syscollector = {}; @@ -736,7 +739,7 @@ export class AgentsController { this.$scope.syscollector = { hardware: typeof hardwareResponse === 'object' && - Object.keys(hardwareResponse).length + Object.keys(hardwareResponse).length ? { ...hardwareResponse } : false, os: @@ -779,7 +782,7 @@ export class AgentsController { try { data[0] = await this.apiReq.request('GET', `/agents/${id}`, {}); - } catch (error) {} //eslint-disable-line + } catch (error) { } //eslint-disable-line try { data[1] = await this.apiReq.request( @@ -787,7 +790,7 @@ export class AgentsController { `/syscheck/${id}/last_scan`, {} ); - } catch (error) {} //eslint-disable-line + } catch (error) { } //eslint-disable-line try { data[2] = await this.apiReq.request( @@ -795,7 +798,7 @@ export class AgentsController { `/rootcheck/${id}/last_scan`, {} ); - } catch (error) {} //eslint-disable-line + } catch (error) { } //eslint-disable-line const result = data.map(item => ((item || {}).data || {}).data || false); @@ -891,6 +894,20 @@ export class AgentsController { this.$scope.editGroup = !!!this.$scope.editGroup; this.$scope.$applyAsync(); } + + /** + * This adds timezone offset to a given date + * @param {String} binding_text + * @param {String} date + */ + offsetTimestamp = (text, time) => { + try { + return text + this.timeService.offset(time); + } catch (error) { + return `${text}${time} (UTC)`; + } + } + /** * Navigate to the groups of an agent * @param {*} agent @@ -964,7 +981,7 @@ export class AgentsController { ); this.errorHandler.info( `Policy monitoring scan launched successfully on agent ${ - this.$scope.agent.id + this.$scope.agent.id }`, '' ); diff --git a/public/controllers/management/logs.js b/public/controllers/management/logs.js index a30bae2aa2..c5d7bd61df 100644 --- a/public/controllers/management/logs.js +++ b/public/controllers/management/logs.js @@ -21,7 +21,15 @@ export class LogsController { * @param {*} appState * @param {*} wzTableFilter */ - constructor($scope, apiReq, errorHandler, csvReq, appState, wzTableFilter) { + constructor( + $scope, + apiReq, + errorHandler, + csvReq, + appState, + wzTableFilter, + timeService + ) { this.$scope = $scope; this.apiReq = apiReq; this.errorHandler = errorHandler; @@ -32,6 +40,7 @@ export class LogsController { this.type_log = 'all'; this.category = 'all'; this.sortFilter = false; + this.timeService = timeService; } /** @@ -61,18 +70,18 @@ export class LogsController { parseLogsToText(logs) { let result = ''; - logs.forEach(function(log, idx) { + logs.forEach((log, idx) => { if (log) { result = result.concat( - `${log.timestamp} ${log.tag} ${(log.level || '').toUpperCase()}: ${ - log.description - }` + `${this.timeService.offset(log.timestamp)} ${log.tag} ${( + log.level || '' + ).toUpperCase()}: ${log.description}` ); if (idx !== logs.length - 1) { result = result.concat('\n'); } } - }); + }, this); return result; } /** diff --git a/public/controllers/misc/reporting.js b/public/controllers/misc/reporting.js index 8c87f7d9d4..9294234957 100644 --- a/public/controllers/misc/reporting.js +++ b/public/controllers/misc/reporting.js @@ -17,7 +17,7 @@ export class ReportingController { * @param {*} errorHandler * @param {*} genericReq */ - constructor($scope, errorHandler, genericReq, $window) { + constructor($scope, errorHandler, genericReq, $window, timeService) { this.$scope = $scope; this.$window = $window; this.errorHandler = errorHandler; @@ -28,6 +28,7 @@ export class ReportingController { this.currentPage = 0; this.items = []; this.gap = 0; + this.timeService = timeService; } /** @@ -46,6 +47,14 @@ export class ReportingController { this.groupToPages(); } + offsetTimestamp(time) { + try { + return this.timeService.offset(time); + } catch (error) { + return `${time} (UTC)`; + } + } + /** * This delete a report with a given name */ diff --git a/public/directives/wz-table/lib/parse-value.js b/public/directives/wz-table/lib/parse-value.js index 88801a0b8c..9bc6b37bbb 100644 --- a/public/directives/wz-table/lib/parse-value.js +++ b/public/directives/wz-table/lib/parse-value.js @@ -23,7 +23,13 @@ const checkIfArray = item => { return typeof item === 'object' ? splitArray(item) : item === 0 ? '0' : item; }; -export function parseValue(key, item, instancePath, $sce = null) { +export function parseValue( + key, + item, + instancePath, + $sce = false, + timeService = false +) { if ( (key === 'event' || (key.value && key.value === 'event')) && instancePath.includes('rootcheck') && @@ -45,6 +51,15 @@ export function parseValue(key, item, instancePath, $sce = null) { } } } + if (key.offset && timeService) { + const date = (item || {})[key.value]; + if (!item[`${key.value}offset`]) { + item[`${key.value}offset`] = date; + } + if (date) { + item[key.value] = timeService.offset(item[`${key.value}offset`]); + } + } if (key === 'state' && instancePath.includes('processes')) { return ProcessEquivalence[item.state] || '-'; } @@ -54,7 +69,6 @@ export function parseValue(key, item, instancePath, $sce = null) { ) { return '-'; } - if ((item || {})[key] === '(null)') { return '-'; } diff --git a/public/directives/wz-table/wz-table-directive.js b/public/directives/wz-table/wz-table-directive.js index 7789a856dc..90390a4aa3 100644 --- a/public/directives/wz-table/wz-table-directive.js +++ b/public/directives/wz-table/wz-table-directive.js @@ -53,7 +53,8 @@ app.directive('wzTable', function() { groupHandler, rulesetHandler, wazuhConfig, - $sce + $sce, + timeService ) { $scope.showColumns = false; $scope.scapepath = $scope.path.split('/').join(''); @@ -268,7 +269,7 @@ app.directive('wzTable', function() { }; $scope.parseValue = (key, item) => - parseValue(key, item, instance.path, $sce); + parseValue(key, item, instance.path, $sce, timeService); /** * On controller loads diff --git a/public/services/index.js b/public/services/index.js index 9b25f6249b..f8ea4ca1e3 100644 --- a/public/services/index.js +++ b/public/services/index.js @@ -27,6 +27,7 @@ import { uiModules } from 'ui/modules'; import { GroupHandler } from './group-handler'; import { RulesetHandler } from './ruleset-handler'; import { ConfigHandler } from './config-handler'; +import { TimeService } from './time-service'; import { CheckDaemonsStatus } from './check-daemon-status'; const app = uiModules.get('app/wazuh', []); @@ -45,4 +46,5 @@ app .service('groupHandler', GroupHandler) .service('rulesetHandler', RulesetHandler) .service('configHandler', ConfigHandler) + .service('timeService', TimeService) .service('checkDaemonsStatus', CheckDaemonsStatus); diff --git a/public/services/time-service.js b/public/services/time-service.js new file mode 100644 index 0000000000..1c374f2839 --- /dev/null +++ b/public/services/time-service.js @@ -0,0 +1,28 @@ +/* + * Wazuh app - Time and date functions + * Copyright (C) 2015-2019 Wazuh, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Find more information about this on the LICENSE file. + */ + +export class TimeService { + /** + * Returns given date adding the timezone offset + * @param {string} date Date + */ + offset(d) { + try { + const date = new Date(d); + const offset = new Date().getTimezoneOffset(); + const offsetTime = new Date(date.getTime() - offset * 60000); + return offsetTime.toLocaleString('en-ZA').replace(',', ''); + } catch (error) { + throw new Error(error); + } + } +} diff --git a/public/templates/agents-prev/agents-prev.html b/public/templates/agents-prev/agents-prev.html index cef7970a4e..7198ea7d61 100644 --- a/public/templates/agents-prev/agents-prev.html +++ b/public/templates/agents-prev/agents-prev.html @@ -138,7 +138,7 @@
diff --git a/public/templates/agents/agents-sca.html b/public/templates/agents/agents-sca.html index 8d37311c01..89df34408b 100644 --- a/public/templates/agents/agents-sca.html +++ b/public/templates/agents/agents-sca.html @@ -96,9 +96,7 @@
- {{policy.end_scan - || '-' - }} +
diff --git a/public/templates/agents/agents-syscollector.html b/public/templates/agents/agents-syscollector.html index 267ebc8dc5..b93caa567f 100644 --- a/public/templates/agents/agents-syscollector.html +++ b/public/templates/agents/agents-syscollector.html @@ -62,7 +62,7 @@ Network interfaces - Last scan: {{syscollector.netiface.items[0].scan.time}} + @@ -113,7 +113,7 @@ Network ports - Last scan: {{syscollector.ports.items[0].scan.time}} + Packages - Last scan: {{syscollector.packagesDate}} +
@@ -197,7 +197,7 @@ Processes - Last scan: {{syscollector.processesDate}} +
diff --git a/public/templates/agents/agents-welcome.html b/public/templates/agents/agents-welcome.html index 6b945194f4..f5cb096abd 100644 --- a/public/templates/agents/agents-welcome.html +++ b/public/templates/agents/agents-welcome.html @@ -7,8 +7,7 @@ not fetch data for this agent. Reason: {{emptyAgent}}
- + Try again
@@ -22,14 +21,11 @@ {{ agent.name || '-' }} -    -
@@ -38,9 +34,8 @@
Cancel -
@@ -49,8 +44,7 @@
-
+
@@ -88,7 +82,7 @@

Registration date

-

{{agent.dateAdd || '-'}}

+

@@ -96,7 +90,7 @@

Last keep alive

-

{{agent.lastKeepAlive || '-' }}

+

@@ -106,12 +100,13 @@

Scan in progress

-

{{agent.syscheck.end - || '-'}} + - Start time: {{ agent.syscheck.start || '-'}}
- End time: {{ agent.syscheck.end || '-'}}
+ Start time: {{ agent.syscheck.start ? offsetTimestamp('', agent.syscheck.start) : + '-'}} | + End time: {{ agent.syscheck.end ? offsetTimestamp('', agent.syscheck.end) : '-'}} | Duration time: {{ agent.syscheck.duration +' minutes' || '-'}}

@@ -124,13 +119,14 @@

Scan in progress

-

{{agent.rootcheck.end - || '-'}} - + - Start time: {{ agent.rootcheck.start || '-'}}
- End time: {{ agent.rootcheck.end || '-'}}
+ Start time: {{ agent.rootcheck.start ? offsetTimestamp('', agent.rootcheck.start) : + '-'}} | + End time: {{ agent.rootcheck.end ? offsetTimestamp('', agent.rootcheck.end) : '-'}} + | Duration time: {{ agent.rootcheck.duration +' minutes' || '-'}}

@@ -145,8 +141,8 @@
- Groups - + Groups + @@ -157,18 +153,17 @@ Available groups:
- {{ group }}
- +
@@ -178,18 +173,17 @@
Cancel - Confirm + Confirm
-
- {{ - group - }} -
+
+ {{ + group + }} +
@@ -204,19 +198,15 @@

Security Information Management

- - - + + + - +
@@ -226,22 +216,17 @@

Security Information Management

Auditing and Policy Monitoring

- - - + + - + + card-title="'CIS-CAT'" switch-tab="switchTab('ciscat')" current-tab="'ciscat'" description="TabDescription.ciscat.description">
@@ -256,12 +241,10 @@

Auditing and Policy Monitoring

Threat Detection and Response

- - + Regulatory Compliance
+ card-title="'PCI DSS'" switch-tab="switchTab('pci')" current-tab="'pci'" description="TabDescription.pci.description"> + card-title="'GDPR'" switch-tab="switchTab('gdpr')" current-tab="'gdpr'" description="TabDescription.gdpr.description">
diff --git a/public/templates/management/reporting.html b/public/templates/management/reporting.html index 91637fc41e..f067e41c7a 100644 --- a/public/templates/management/reporting.html +++ b/public/templates/management/reporting.html @@ -48,7 +48,7 @@ - +
{{item.name}} {{item.size / 1024 | number: 2}}KB{{item.date.split('T')[0]}} {{item.date.split('T')[1].split('.')[0]}} - \ No newline at end of file +