Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New functionality to change app logos #3503

Merged
merged 9 commits into from
Aug 18, 2021
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Added confirmation message when closing a form [#3221](https://github.com/wazuh/wazuh-kibana-app/pull/3221)
- Improvement to hide navbar Wazuh label. [#3240](https://github.com/wazuh/wazuh-kibana-app/pull/3240)
- Add modal creating new rule/decoder [#3274](https://github.com/wazuh/wazuh-kibana-app/pull/3274)
- New functionality to change app logos [#3503](https://github.com/wazuh/wazuh-kibana-app/pull/3503)

### Changed

Expand Down
7 changes: 6 additions & 1 deletion common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const WAZUH_CONFIGURATION_SETTINGS_NEED_HEALTH_CHECK = [
];
export const WAZUH_CONFIGURATION_SETTINGS_NEED_RELOAD = [
'hideManagerAlerts',
'customization.logo.sidebar'
];

// Reserved ids for Users/Role mapping
Expand Down Expand Up @@ -170,7 +171,11 @@ export const WAZUH_DEFAULT_APP_CONFIG = {
'alerts.sample.prefix': WAZUH_SAMPLE_ALERT_PREFIX,
hideManagerAlerts: false,
'logs.level': 'info',
'enrollment.dns': ''
'enrollment.dns': '',
'customization.logo.app':'logotype.svg',
'customization.logo.sidebar':'icon_blue.png',
'customization.logo.healthcheck':'icon_blue.svg',
'customization.logo.reports':'logo.png'
};

// Wazuh errors
Expand Down
2 changes: 1 addition & 1 deletion public/assets/icon_blue.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion public/assets/logotype.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ function HealthCheckComponent() {
setChecksReady(prev => ({...prev, [checkID]: isReady}));
}

const logoUrl = getHttp().basePath.prepend('/plugins/wazuh/assets/icon_blue.svg');

const logoUrl = getHttp().basePath.prepend(`/plugins/wazuh/assets/${appConfig.data['customization.logo.healthcheck']}`);
const thereAreErrors = Object.keys(checkErrors).length > 0;

const renderChecks = () => {
Expand Down
4 changes: 1 addition & 3 deletions public/components/wz-menu/wz-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,6 @@ export const WzMenu = withWindowSize(class WzMenu extends Component {
this.setState({ isSelectorsPopoverOpen: !this.state.isSelectorsPopoverOpen })
}


render() {
const currentAgent = store.getState().appStateReducers.currentAgentData;
const thereAreSelectors = this.thereAreSelectors();
Expand Down Expand Up @@ -900,8 +899,7 @@ export const WzMenu = withWindowSize(class WzMenu extends Component {
</div>
);


const logotype_url = getHttp().basePath.prepend('/plugins/wazuh/assets/logotype.svg');
const logotype_url = getHttp().basePath.prepend(`/plugins/wazuh/assets/${this.wazuhConfig.getConfig()['customization.logo.app']}`);
const mainButton = (
<button data-test-subj='menuWazuhButton' className="eui" onClick={() => this.switchMenuOpened()}>
<EuiFlexGroup
Expand Down
1 change: 0 additions & 1 deletion public/components/wz-menu/wz-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ wz-menu {

.navBarLogo {
width: 100px;
filter: brightness(0) saturate(100%) invert(24%) sepia(97%) saturate(1757%) hue-rotate(186deg) brightness(94%) contrast(101%);
}

.wz-menu-popover{
Expand Down
14 changes: 12 additions & 2 deletions public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,18 @@ export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlu

//Update if user has Wazuh disabled
this.stateUpdater.next(() => {
if(response.isWazuhDisabled) unmount();
return { status: response.isWazuhDisabled }
if (response.isWazuhDisabled) {
unmount();
}

return {
status: response.isWazuhDisabled,
category: {
id: 'wazuh',
label: 'Wazuh',
order: 0,
euiIconType: core.http.basePath.prepend( `/plugins/wazuh/assets/${response.logoSidebar}`),
}}
})
return () => {
unmount();
Expand Down
4 changes: 4 additions & 0 deletions public/services/resolves/get-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export async function getWzConfig($q, genericReq, wazuhConfig) {
'logs.level': 'info',
'enrollment.dns': '',
'enrollment.password': '',
'customization.logo.app':'logotype.svg',
'customization.logo.sidebar':'icon_blue.png',
'customization.logo.healthcheck':'icon_blue.svg',
'customization.logo.reports':'logo.png'
};

try {
Expand Down
1 change: 0 additions & 1 deletion public/styles/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,6 @@ wz-xml-file-editor {
height: 80px;
margin-bottom: 20px;
z-index: 1;
filter: brightness(0) saturate(100%) invert(24%) sepia(97%) saturate(1757%) hue-rotate(186deg) brightness(94%) contrast(101%);
margin-left: -100px;
}

Expand Down
23 changes: 20 additions & 3 deletions public/utils/config-equivalences.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export const configEquivalences = {
pattern: 'Default index pattern to use on the app.',
'customization.logo.app':'Define the name of the app logo saved in the path /plugins/wazuh/assets/',
'customization.logo.sidebar':'Define the name of the sidebar logo saved in the path /plugins/wazuh/assets/',
'customization.logo.healthcheck':'Define the name of the health-check logo saved in the path /plugins/wazuh/assets/',
'customization.logo.reports':'Define the name of the reports logo (.png) saved in the path /plugins/wazuh/assets/',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't it be any type of image (png,svg,jpg,etc)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, if the .png format is not used, it breaks when generating the report.

'checks.pattern':
'Enable or disable the index pattern health check when opening the app.',
'checks.template':
Expand Down Expand Up @@ -73,6 +77,10 @@ export const configEquivalences = {

export const nameEquivalence = {
pattern: 'Index pattern',
'customization.logo.app': 'Logo App',
'customization.logo.sidebar': 'Logo Sidebar',
'customization.logo.healthcheck': 'Logo Health Check',
'customization.logo.reports': 'Logo Reports',
'checks.pattern': 'Index pattern',
'checks.template': 'Index template',
'checks.api': 'API connection',
Expand Down Expand Up @@ -109,12 +117,17 @@ export const nameEquivalence = {
const HEALTH_CHECK = 'Health Check';
const GENERAL = 'General';
const SECURITY = 'Security';
const MONITORING = 'Monitoring'
const STATISTICS = 'Statistics'
export const categoriesNames = [HEALTH_CHECK, GENERAL, SECURITY, MONITORING, STATISTICS,];
const MONITORING = 'Monitoring';
const STATISTICS = 'Statistics';
const CUSTOMIZATION = 'Logo Customization';
export const categoriesNames = [HEALTH_CHECK, GENERAL, SECURITY, MONITORING, STATISTICS, CUSTOMIZATION];

export const categoriesEquivalence = {
pattern: GENERAL,
'customization.logo.app':CUSTOMIZATION,
'customization.logo.sidebar':CUSTOMIZATION,
'customization.logo.healthcheck':CUSTOMIZATION,
'customization.logo.reports':CUSTOMIZATION,
'checks.pattern': HEALTH_CHECK,
'checks.template': HEALTH_CHECK,
'checks.api': HEALTH_CHECK,
Expand Down Expand Up @@ -156,6 +169,10 @@ const INTERVAL = 'interval'

export const formEquivalence = {
pattern: { type: TEXT },
'customization.logo.app': { type: TEXT },
'customization.logo.sidebar': { type: TEXT },
'customization.logo.healthcheck': { type: TEXT },
'customization.logo.reports': { type: TEXT },
'checks.pattern': { type: BOOLEAN },
'checks.template': { type: BOOLEAN },
'checks.api': { type: BOOLEAN },
Expand Down
3 changes: 2 additions & 1 deletion server/controllers/wazuh-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1056,13 +1056,14 @@ export class WazuhApiCtrl {
try {

const disabledRoles = ( await getConfiguration() )['disabled_roles'] || [];
const logoSidebar = ( await getConfiguration() )['customization.logo.sidebar'] || 'icon_blue.png';
const wazuhSecurity = SecurityObj(context.wazuh.plugins);
const data = (await wazuhSecurity.getCurrentUser(request, context)).authContext;

const isWazuhDisabled = +(data.roles || []).some((role) => disabledRoles.includes(role));

return response.ok({
body: { isWazuhDisabled }
body: { isWazuhDisabled, logoSidebar }
});
} catch (error) {
log('wazuh-api:isWazuhDisabled', error.message || error);
Expand Down
15 changes: 15 additions & 0 deletions server/lib/initial-wazuh-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ export const initialWazuhConfig: string = `---
#cron.statistics.shards: 2
#cron.statistics.replicas: 0
#
# ------------------------------ wazuh-logo-customization -------------------------------
#
#Define the name of the app logo saved in the path /plugins/wazuh/assets/
#customization.logo.app: logotype.svg
#
#Define the name of the sideba logo saved in the path /plugins/wazuh/assets/
#customization.logo.sidebar: icon_blue.png
#
#Define the name of the health-check logo saved in the path /plugins/wazuh/assets/
#customization.logo.healthcheck: icon_blue.svg
#
#
#Define the name of the reports logo (.png) saved in the path /plugins/wazuh/assets/
#customization.logo.reports: logo.png
#
# ---------------------------- Hide manager alerts ------------------------------
# Hide the alerts of the manager in all dashboards and discover
#hideManagerAlerts: false
Expand Down
15 changes: 9 additions & 6 deletions server/lib/reporting/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import {
} from '../../integration-files/visualizations';
import { log } from '../logger';
import * as TimSort from 'timsort';
import { getConfiguration } from '../get-configuration';

const COLORS = {
PRIMARY: '#00a9e5'
};

const pageConfiguration = {
const pageConfiguration = (nameLogo) => ({
styles: {
h1: {
fontSize: 22,
Expand Down Expand Up @@ -52,7 +53,7 @@ const pageConfiguration = {
margin: [40, 20, 0, 0],
columns: [
{
image: path.join(__dirname, '../../../public/assets/logo.png'),
image: path.join(__dirname, `../../../public/assets/${nameLogo}`),
width: 190
},
{
Expand Down Expand Up @@ -96,7 +97,7 @@ const pageConfiguration = {
}
return false;
}
};
});

const fonts = {
Roboto: {
Expand Down Expand Up @@ -609,10 +610,12 @@ export class ReportPrinter{
);
}

async print(path: string){
const document = this._printer.createPdfKitDocument({...pageConfiguration, content: this._content});
async print(reportPath: string){
const nameLogo = ( await getConfiguration() )['customization.logo.reports'] || 'logo.png'

const document = this._printer.createPdfKitDocument({...pageConfiguration(nameLogo), content: this._content});
await document.pipe(
fs.createWriteStream(path)
fs.createWriteStream(reportPath)
);
document.end();
}
Expand Down