Skip to content

Commit

Permalink
Cleaned code
Browse files Browse the repository at this point in the history
  • Loading branch information
fastlorenzo committed Oct 18, 2020
1 parent 07909ad commit c0b3b05
Show file tree
Hide file tree
Showing 23 changed files with 81 additions and 59 deletions.
2 changes: 1 addition & 1 deletion public/components/alarmsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {useTopNav} from "../navHeaderHelper";
import {useTopNav} from "../helpers/nav_header_helper";
import {EmbeddedDashboard} from "./embeddedDashboard";

export const AlarmsPage = () => {
Expand Down
36 changes: 20 additions & 16 deletions public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
EuiLoadingSpinner,
EuiPopover
} from '@elastic/eui';
import {setNavHeader} from "../navHeaderHelper";
import {setNavHeader} from "../helpers/nav_header_helper";
import {useDispatch, useSelector} from 'react-redux';
import {PLUGIN_ID, PLUGIN_NAME} from "../../common";
import {
Expand All @@ -39,23 +39,24 @@ import {
import {History} from 'history';
import {ActionCreators} from "../redux/rootActions";
import {DEFAULT_ROUTE_ID, routes} from "../routes";
import {RedelkURLGenerator} from "../url_generator";
import {RedelkURLGenerator} from "../helpers/url_generator";
import {KbnCallStatus, RedelkInitStatus} from "../types";
import {getCurrentRoute, getInitStatus, getShowTopNav, getTopNavMenu} from "../selectors";
import {getCurrentRoute, getInitStatus, getShowTopNav, getTopNavMenu} from "../redux/selectors";
import {checkInit} from "../redux/config/configActions";
import {AppState, defaultAppState} from '../redux/types';
import {InitPage} from './initPage';
import {HomePage} from './homePage';
import {AlarmsPage} from "./alarmsPage";
import {CredentialsPage} from "./credentialsPage";
import { DownloadsPage } from './downloadsPage';
import {DownloadsPage} from './downloadsPage';
import {ImplantsPage} from "./implantsPage";
import {RtopsPage} from "./rtopsPage";
import {ScreenshotsPage} from "./screenshotsPage";
import {TasksPage} from "./tasksPage";
import {TrafficPage} from "./trafficPage";
import {TTPPage} from "./ttpPage";
import {IframePage} from "./iframePage";
import {initSettings} from "../helpers/settings_helper";

interface RedelkAppDeps {
basename: string;
Expand Down Expand Up @@ -197,6 +198,7 @@ const RedelkAppInternal = ({basename, navigation, data, core, history, kbnUrlSta
if (location.pathname !== currentRoute) {
dispatch(ActionCreators.setCurrentRoute(location.pathname));
}
initSettings(core);
});

// BEGIN top drop-down menu
Expand Down Expand Up @@ -420,18 +422,20 @@ const RedelkAppInternal = ({basename, navigation, data, core, history, kbnUrlSta
<Router history={history}>
{topNav}

<Route path="/" exact render={() => <Redirect to={routes.find(r => r.id === DEFAULT_ROUTE_ID)?.path || "/home"}/>}/>
<Route path="/home" exact component={HomePage} />
<Route path="/alarms" exact component={AlarmsPage} />
<Route path="/credentials" exact component={CredentialsPage} />
<Route path="/downloads" exact component={DownloadsPage} />
<Route path="/implants" exact component={ImplantsPage} />
<Route path="/rtops" exact component={RtopsPage} />
<Route path="/screenshots" exact component={ScreenshotsPage} />
<Route path="/tasks" exact component={TasksPage} />
<Route path="/traffic" exact component={TrafficPage} />
<Route path="/ttp" exact component={TTPPage} />
<Route path="/attack-navigator" exact component={() => IframePage({url:"/plugins/redelk/assets/attack-navigator/"})} />
<Route path="/" exact
render={() => <Redirect to={routes.find(r => r.id === DEFAULT_ROUTE_ID)?.path || "/home"}/>}/>
<Route path="/home" exact component={HomePage}/>
<Route path="/alarms" exact component={AlarmsPage}/>
<Route path="/credentials" exact component={CredentialsPage}/>
<Route path="/downloads" exact component={DownloadsPage}/>
<Route path="/implants" exact component={ImplantsPage}/>
<Route path="/rtops" exact component={RtopsPage}/>
<Route path="/screenshots" exact component={ScreenshotsPage}/>
<Route path="/tasks" exact component={TasksPage}/>
<Route path="/traffic" exact component={TrafficPage}/>
<Route path="/ttp" exact component={TTPPage}/>
<Route path="/attack-navigator" exact
component={() => IframePage({url: "/plugins/redelk/assets/attack-navigator/"})}/>

<Route path="/summary" exact
render={() =>
Expand Down
2 changes: 1 addition & 1 deletion public/components/credentialsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {useTopNav} from "../navHeaderHelper";
import {useTopNav} from "../helpers/nav_header_helper";
import {EmbeddedDashboard} from "./embeddedDashboard";

export const CredentialsPage = () => {
Expand Down
2 changes: 1 addition & 1 deletion public/components/downloadsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {useTopNav} from "../navHeaderHelper";
import {useTopNav} from "../helpers/nav_header_helper";
import {EmbeddedDashboard} from "./embeddedDashboard";

export const DownloadsPage = () => {
Expand Down
9 changes: 5 additions & 4 deletions public/components/embeddedDashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, {useEffect, useState} from 'react';
import {SimpleSavedObject} from "kibana/public";
import {DashboardContainerInput, SavedObjectDashboard} from '../../../../src/plugins/dashboard/public';
import {getAppState, getRtopsLastRefreshDate} from "../selectors";
import {getAppState, getRtopsLastRefreshDate} from "../redux/selectors";
import {useDispatch, useSelector} from 'react-redux';
import {savedObjectToDashboardContainerInput} from '../dashboard_helper';
import {savedObjectToDashboardContainerInput} from '../helpers/dashboard_helper';
import {useKibana} from '../../../../src/plugins/kibana_react/public';
import {ActionCreators} from "../redux/rootActions";
import {TopNavMenuData} from '../../../../src/plugins/navigation/public';
Expand All @@ -18,7 +18,7 @@ export const EmbeddedDashboard = ({dashboardId, extraTopNavMenu}: { dashboardId:
// const [dashboard, setDashboard] = useState<ReactElement>(<p>Loading dashboard</p>);

const dispatch = useDispatch();
const {services}: {services: RedelkKibanaService} = useKibana();
const {services}: { services: RedelkKibanaService } = useKibana();

const appState = useSelector(getAppState);
const rtopsLastRefreshDate = useSelector(getRtopsLastRefreshDate);
Expand Down Expand Up @@ -49,7 +49,8 @@ export const EmbeddedDashboard = ({dashboardId, extraTopNavMenu}: { dashboardId:

if (dashboardConfig) {
dashboard = (
<services.dashboard.DashboardContainerByValueRenderer input={dashboardConfig} onInputUpdated={setDashboardConfig} />
<services.dashboard.DashboardContainerByValueRenderer input={dashboardConfig}
onInputUpdated={setDashboardConfig}/>
);
}

Expand Down
2 changes: 1 addition & 1 deletion public/components/homePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {useTopNav} from "../navHeaderHelper";
import {useTopNav} from "../helpers/nav_header_helper";
import {EmbeddedDashboard} from "./embeddedDashboard";

export const HomePage = () => {
Expand Down
4 changes: 2 additions & 2 deletions public/components/iframePage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import {useTopNav} from "../navHeaderHelper";
import {useTopNav} from "../helpers/nav_header_helper";

export const IframePage = ({url}: {url: string}) => {
export const IframePage = ({url}: { url: string }) => {

useTopNav(false);

Expand Down
2 changes: 1 addition & 1 deletion public/components/implantsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {useTopNav} from "../navHeaderHelper";
import {useTopNav} from "../helpers/nav_header_helper";
import {EmbeddedDashboard} from "./embeddedDashboard";

export const ImplantsPage = () => {
Expand Down
4 changes: 2 additions & 2 deletions public/components/iocPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {EuiFlyout, EuiFlyoutBody, EuiFlyoutHeader, EuiTitle} from '@elastic/eui'
import {AddIOCForm} from "../features/rtops/addIocForm";
import {DataPublicPluginStart} from '../../../../src/plugins/data/public';
import {useDispatch, useSelector} from 'react-redux';
import {useTopNav} from "../navHeaderHelper";
import {getRtopsShowAddIOCForm} from "../selectors";
import {useTopNav} from "../helpers/nav_header_helper";
import {getRtopsShowAddIOCForm} from "../redux/selectors";
import {ActionCreators} from "../redux/rootActions";
import {EmbeddedDashboard} from "./embeddedDashboard";

Expand Down
2 changes: 1 addition & 1 deletion public/components/rtopsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {useTopNav} from "../navHeaderHelper";
import {useTopNav} from "../helpers/nav_header_helper";
import {EmbeddedDashboard} from "./embeddedDashboard";

export const RtopsPage = () => {
Expand Down
2 changes: 1 addition & 1 deletion public/components/screenshotsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {useTopNav} from "../navHeaderHelper";
import {useTopNav} from "../helpers/nav_header_helper";
import {EmbeddedDashboard} from "./embeddedDashboard";

export const ScreenshotsPage = () => {
Expand Down
4 changes: 2 additions & 2 deletions public/components/summaryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {KbnCallStatus} from "../types";
import {useSelector} from 'react-redux';
import {Axis, BarSeries, Chart, Partition, Settings} from '@elastic/charts';
import {EUI_CHARTS_THEME_DARK, EUI_CHARTS_THEME_LIGHT} from '@elastic/eui/dist/eui_charts_theme';
import {useTopNav} from "../navHeaderHelper";
import {getRtopsAggs, getRtopsStatus} from "../selectors";
import {useTopNav} from "../helpers/nav_header_helper";
import {getRtopsAggs, getRtopsStatus} from "../redux/selectors";
import {useKibana} from '../../../../src/plugins/kibana_react/public';

interface RedelkAppDeps {
Expand Down
2 changes: 1 addition & 1 deletion public/components/tasksPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {useTopNav} from "../navHeaderHelper";
import {useTopNav} from "../helpers/nav_header_helper";
import {EmbeddedDashboard} from "./embeddedDashboard";

export const TasksPage = () => {
Expand Down
2 changes: 1 addition & 1 deletion public/components/trafficPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {useTopNav} from "../navHeaderHelper";
import {useTopNav} from "../helpers/nav_header_helper";
import {EmbeddedDashboard} from "./embeddedDashboard";

export const TrafficPage = () => {
Expand Down
2 changes: 1 addition & 1 deletion public/components/ttpPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {useTopNav} from "../navHeaderHelper";
import {useTopNav} from "../helpers/nav_header_helper";
import {EmbeddedDashboard} from "./embeddedDashboard";

export const TTPPage = () => {
Expand Down
2 changes: 1 addition & 1 deletion public/features/rtops/iocTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@elastic/eui';

import {KbnCallStatus} from '../../types';
import {getRtopsFilteredIOC, getRtopsStatus} from "../../selectors";
import {getRtopsFilteredIOC, getRtopsStatus} from "../../redux/selectors";

export const IOCTable = () => {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {SimpleSavedObject} from "kibana/public";
import {GridData} from '../../../src/plugins/dashboard/common';
import {DashboardContainerInput, SavedObjectDashboard} from '../../../src/plugins/dashboard/public';
import {DashboardPanelState} from '../../../src/plugins/dashboard/public/application';
import {EmbeddableInput, ViewMode} from '../../../src/plugins/embeddable/public';
import {AppState} from "./redux/types";
import {GridData} from '../../../../src/plugins/dashboard/common';
import {DashboardContainerInput, SavedObjectDashboard} from '../../../../src/plugins/dashboard/public';
import {DashboardPanelState} from '../../../../src/plugins/dashboard/public/application';
import {EmbeddableInput, ViewMode} from '../../../../src/plugins/embeddable/public';
import {AppState} from "../redux/types";
import {find} from "lodash";

const uuidv4 = (): string => {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {EuiBreadcrumb} from '@elastic/eui';
import {ChromeBadge, ChromeBrand, ChromeHelpExtension, CoreStart} from "kibana/public";
import {useEffect} from 'react';
import {useDispatch} from 'react-redux';
import {PLUGIN_NAME} from "../common";
import {ActionCreators} from "./redux/rootActions";
import {PLUGIN_NAME} from "../../common";
import {ActionCreators} from "../redux/rootActions";

export const setNavHeader = (core: CoreStart, breadcrumbs: EuiBreadcrumb[]) => {
const darkMode: boolean = core.uiSettings.get('theme:darkMode');
Expand Down
16 changes: 16 additions & 0 deletions public/helpers/settings_helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {CoreStart} from "kibana/public";

export const initSettings = async (core: CoreStart) => {
const defaultRoute = await core.uiSettings.get("defaultRoute");
if (defaultRoute !== "/app/redelk/") {
await core.uiSettings.set("theme:darkMode", true);
await core.uiSettings.set("telemetry:optIn", false);
await core.uiSettings.set("telemetry:enabled", false);
await core.uiSettings.set("shortDots:enabled", true);
await core.uiSettings.set("siem:enableNewsFeed", false);
await core.uiSettings.set("siem:defaultIndex", ["apm-*-transaction*", "auditbeat-*", "endgame-*", "filebeat-*", "packetbeat-*", "winlogbeat-*", "rtops-*", "redirtraffic-*"]);
await core.uiSettings.set("defaultIndex", "195a3f00-d04f-11ea-9301-a30a04251ae9");
await core.uiSettings.set("defaultRoute", "/app/redelk/");
window.location.reload();
}
}
4 changes: 2 additions & 2 deletions public/url_generator.ts → public/helpers/url_generator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {setStateToKbnUrl} from '../../../src/plugins/kibana_utils/public';
import {esFilters, Filter, Query, QueryState, RefreshInterval, TimeRange} from '../../../src/plugins/data/public';
import {setStateToKbnUrl} from '../../../../src/plugins/kibana_utils/public';
import {esFilters, Filter, Query, QueryState, RefreshInterval, TimeRange} from '../../../../src/plugins/data/public';

export const REDELK_APP_URL_GENERATOR = 'REDELK_APP_URL_GENERATOR';

Expand Down
22 changes: 11 additions & 11 deletions public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ export class RedelkPlugin implements Plugin<RedelkPluginSetup, RedelkPluginStart
},
});

core.application.register({
id: 'redelk:attack-navigator',
title: 'MITRE ATT&CK Navigator',
category: redelkCategory,
async mount() {
window.open(window.location.protocol + '//' + window.location.host + '/attack-navigator', '_blank');
window.history.back();
return () => {
}
}
});
// core.application.register({
// id: 'redelk:attack-navigator',
// title: 'MITRE ATT&CK Navigator',
// category: redelkCategory,
// async mount() {
// window.open(window.location.protocol + '//' + window.location.host + '/attack-navigator', '_blank');
// window.history.back();
// return () => {
// }
// }
// });

core.application.register({
id: 'redelk:jupyter-notebook',
Expand Down
2 changes: 1 addition & 1 deletion public/selectors.ts → public/redux/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {RedELKState} from "./types";
import {RedELKState} from "../types";
import {createSelector} from 'reselect';
import {filter} from 'lodash';

Expand Down
1 change: 1 addition & 0 deletions public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface RedelkPluginStartDependencies {
share: SharePluginStart;
uiSettings: UiSettingsServiceStart;
}

export type RedelkKibanaService = RedelkPluginStartDependencies & CoreStart;

export interface RedelkPluginSetupDependencies {
Expand Down

0 comments on commit c0b3b05

Please sign in to comment.