diff --git a/src/ts/@overflow/app/config/index.ts b/src/ts/@overflow/app/config/index.ts index 82ba000..e20d6ab 100644 --- a/src/ts/@overflow/app/config/index.ts +++ b/src/ts/@overflow/app/config/index.ts @@ -43,6 +43,7 @@ import MetaSensorItemReadAllReducer from '@overflow/meta/redux/reducer/sensor_it import MetaSensorItemTypeReadAllReducer from '@overflow/meta/redux/reducer/sensor_item_type_read_all'; import DiscoveryInfraTargetRegistAllReducer from '@overflow/discovery/redux/reducer/infra_target_regist_all'; +import DiscoveryIngReducer from '@overflow/discovery/redux/reducer/ing'; import HistoryReadAllByProbeReducer from '@overflow/history/redux/reducer/read_all_by_probe'; import HistoryReadAllByProbeAndTypeReducer from '@overflow/history/redux/reducer/read_all_by_probe_and_type'; @@ -132,6 +133,7 @@ const reduxConfig: ReduxConfig = { noauthDenyReducer, modifyProbeReducer, DiscoveryInfraTargetRegistAllReducer, + DiscoveryIngReducer, HistoryReadAllByProbeReducer, HistoryReadAllByProbeAndTypeReducer, readAllTargetByInfraReducer, diff --git a/src/ts/@overflow/discovery/api/service/DiscoveryService.ts b/src/ts/@overflow/discovery/api/service/DiscoveryService.ts index 9bb18cc..6fd30ed 100644 --- a/src/ts/@overflow/discovery/api/service/DiscoveryService.ts +++ b/src/ts/@overflow/discovery/api/service/DiscoveryService.ts @@ -1,6 +1,6 @@ import { Service } from '@overflow/commons/api/service'; -import DiscoveryIngActions from '../../redux/action/ing'; +import * as DiscoveryIngActions from '../../redux/action/ing'; import Host from '../model/Host'; import Port from '../model/Port'; @@ -17,6 +17,10 @@ export class DiscoveryService extends Service { // state change test } + public discoveryIngTest(params: any): void { + console.log(params); + } + public discoveryIngHost(params: any): void { let host: Host = params; diff --git a/src/ts/@overflow/discovery/react/Discovery.tsx b/src/ts/@overflow/discovery/react/Discovery.tsx index 176eb66..02a1059 100644 --- a/src/ts/@overflow/discovery/react/Discovery.tsx +++ b/src/ts/@overflow/discovery/react/Discovery.tsx @@ -26,6 +26,10 @@ export function mapDispatchToProps(dispatch: Dispatch): DiscoveryDispatchPr dispatch(asyncRequestActions.request('TargetDiscoveryService', 'saveAllTarget', InfraTargetRegistAllActionTypes.REQUEST, JSON.stringify(hosts), JSON.stringify(probe))); }, + onTestDiscovery: (types: string, obj: any) => { + dispatch(asyncRequestActions.request('DiscoveryService', 'testDiscovery', + 'DiscoveryTTTTTEEEESSSTTT', types, JSON.stringify(obj))); + }, }; } diff --git a/src/ts/@overflow/discovery/react/DiscoveryTree.tsx b/src/ts/@overflow/discovery/react/DiscoveryTree.tsx index fcf9b12..51bac72 100644 --- a/src/ts/@overflow/discovery/react/DiscoveryTree.tsx +++ b/src/ts/@overflow/discovery/react/DiscoveryTree.tsx @@ -17,6 +17,7 @@ export function mapStateToProps(state: any, props: any): DiscoveryTreeStateProps return { probeId: props.probeId, onSetTargetList: props.onSetTargetList, + hostList: state.hostList, }; } diff --git a/src/ts/@overflow/discovery/react/components/Discovery.tsx b/src/ts/@overflow/discovery/react/components/Discovery.tsx index fa78816..56e14a9 100644 --- a/src/ts/@overflow/discovery/react/components/Discovery.tsx +++ b/src/ts/@overflow/discovery/react/components/Discovery.tsx @@ -12,6 +12,9 @@ import DiscoveryTreeContainer from '../DiscoveryTree'; import Probe from '@overflow/probe/api/model/Probe'; import Host from '@overflow/discovery/api/model/Host'; +import Port from '@overflow/discovery/api/model/Port'; +import Service from '@overflow/discovery/api/model/Service'; +import * as _ from 'lodash'; export interface StateProps { probeId?: Number; @@ -23,6 +26,7 @@ export interface StateProps { export interface DispatchProps { onCreateTarget?(hosts: Host[], probe: Probe): void; + onTestDiscovery?(types: string, obj: any): void; } export type Props = StateProps & DispatchProps; @@ -38,12 +42,16 @@ export class Discovery extends React.Component { private submitData: any; private discoveryHosts: Array; + private exDisHosts: Array; + public constructor(props: Props, context: State) { super(props, context); this.handleProbeChange.bind(this); this.state = { startPopup: false, }; + + this.exDisHosts = hostListJson; } public componentWillMount(): void { @@ -68,7 +76,7 @@ export class Discovery extends React.Component { public handleSubmit(): void { // console.log(this.discoveryHosts); - this.setState({startPopup:false}); + this.setState({ startPopup: false }); this.props.onCreateTarget(this.discoveryHosts, { id: Number(this.props.probeId) }); } @@ -78,6 +86,95 @@ export class Discovery extends React.Component { public handleCancel = () => this.setState({ startPopup: false }); + public handleTest = () => { + + let min: number = 1; + let max: number = 2; + + let idx: number = Math.floor(Math.random() * (max - min + 1) + min); + + idx = 2; + + switch(idx) { + case 1: + this.testHost(); + break; + case 2: + this.testPort(); + break; + case 3: + this.testService(); + break; + default: + break; + } + } + public testHost(): void { + let min: number = 0; + let max: number = this.exDisHosts.length - 1; + + let idx: number = Math.floor(Math.random() * (max - min + 1) + min); + + console.log('idx ----' + idx); + let host: Host = this.exDisHosts[idx]; + console.log(host); + let chkObj: Object = host; + if(chkObj.hasOwnProperty('ports')) { + host.ports = null; + } + + this.props.onTestDiscovery('1', host); + } + public testPort(): void { + let min: number = 0; + let max: number = this.exDisHosts.length - 1; + + let idx: number = Math.floor(Math.random() * (max - min + 1) + min); + + console.log('host index - ' + idx); + let host: Host = this.exDisHosts[idx]; + + let checkObj: object = host; + if(checkObj.hasOwnProperty('ports') === false) { + return; + } + if(host.ports === null) { + return; + } + // if(host.ports === undefined || host.ports === null) { + // return; + // } + + let portmin: number = 0; + let portmax: number = host.ports.length - 1; + + let portIdx: number = Math.floor(Math.random() * (portmax - portmin + 1) + portmin); + + let port: Port = host.ports[portIdx]; + + let cHost: Host = _.clone(host); + + let chkObj: Object = cHost; + if(chkObj.hasOwnProperty('ports')) { + cHost.ports = null; + } + + port.host = cHost; + + this.props.onTestDiscovery('2', port); + } + public testService(): void { + let min: number = 0; + let max: number = this.exDisHosts.length - 1; + + let idx: number = Math.floor(Math.random() * (max - min + 1) + min); + + console.log('idx ----' + idx); + let host: Host = this.exDisHosts[idx]; + console.log(host); + this.props.onTestDiscovery('1', this.exDisHosts[idx]); + } + public handlePopupClose = () => this.setState({ startPopup: false }); public render(): JSX.Element { @@ -98,6 +195,7 @@ export class Discovery extends React.Component { + @@ -114,3 +212,180 @@ export class Discovery extends React.Component { ); } } + + + +const hostListJson: any = [ + { + 'firstScanRange': 1, + 'lastScanRange': 10000, + 'name': '', + 'ip': 3232235818, + 'mac': 91754662925, + 'os': 'Windows', + 'ports': [{ + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'services': [{ + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'portType': 'TCP', + 'serviceName': 'SSH', + 'target': true, + }], + 'portType': 'TCP', + 'portNumber': 22, + }, + { + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'services': [{ + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'portType': 'TCP', + 'serviceName': 'HTTP', + }], + 'portType': 'TCP', + 'portNumber': 443, + }, + { + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'services': [{ + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'portType': 'TCP', + 'serviceName': 'HTTP', + }], + 'portType': 'TCP', + 'portNumber': 80, + }], + 'createDate': 1498470178000, + 'updateDate': 1498470178000, + }, + { + 'firstScanRange': 1, + 'lastScanRange': 10000, + 'name': '', + 'ip': 3232235781, + 'mac': 91754660625, + 'os': 'Windows', + 'ports': [{ + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'services': [{ + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'portType': 'TCP', + 'serviceName': 'SSH', + }], + 'portType': 'TCP', + 'portNumber': 22, + }, + { + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'services': [{ + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'portType': 'TCP', + 'serviceName': 'HTTP', + }], + 'portType': 'TCP', + 'portNumber': 80, + }, + { + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'services': [{ + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'portType': 'TCP', + 'serviceName': 'HTTP', + }], + 'portType': 'TCP', + 'portNumber': 1936, + }, + { + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'services': null, + 'portType': 'TCP', + 'portNumber': 443, + }], + 'createDate': 1498470178000, + 'updateDate': 1498470178000, + }, + { + 'firstScanRange': 1, + 'lastScanRange': 10000, + 'name': '', + 'ip': 3232235797, + 'mac': 91754662913, + 'os': 'Windows', + 'target': true, + 'ports': [{ + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'services': [{ + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'portType': 'TCP', + 'serviceName': 'HTTP', + }], + 'portType': 'TCP', + 'portNumber': 80, + }, + { + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'services': [{ + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'portType': 'TCP', + 'serviceName': 'SSH', + }], + 'portType': 'TCP', + 'portNumber': 22, + }, + { + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'services': [{ + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'portType': 'TCP', + 'serviceName': 'HTTP', + }], + 'portType': 'TCP', + 'portNumber': 3343, + }, + { + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'services': [{ + 'createDate': -62135596800000, + 'updateDate': -62135596800000, + 'portType': 'TCP', + 'serviceName': 'HTTP', + }], + 'portType': 'TCP', + 'portNumber': 443, + }], + 'createDate': 1498470178000, + 'updateDate': 1498470178000, + }, + { + 'firstScanRange': 1, + 'lastScanRange': 10000, + 'name': '', + 'ip': 3232235877, + 'mac': 75361038758387, + 'os': 'Windows', + 'ports': null, + 'createDate': 1498470179000, + 'updateDate': 1498470179000, + }, + + +]; diff --git a/src/ts/@overflow/discovery/react/components/DiscoveryTree.tsx b/src/ts/@overflow/discovery/react/components/DiscoveryTree.tsx index 0c6239a..9f06788 100644 --- a/src/ts/@overflow/discovery/react/components/DiscoveryTree.tsx +++ b/src/ts/@overflow/discovery/react/components/DiscoveryTree.tsx @@ -25,6 +25,7 @@ import * as Utils from '@overflow/commons/util/Utils'; export interface DiscoveryTreeStateProps { probeId: number; + hostList: Host[]; onSetTargetList(discoveryHosts: Array): void; } @@ -65,7 +66,7 @@ export class DiscoveryTree extends React.Component + @@ -223,180 +228,6 @@ export class DiscoveryTree extends React.Component): DiscoveryIngState => { + let obj: any = action.payload; let hostList: Host[] = null; if(state.hostList === null || state.hostList === undefined) { hostList = new Array(); - hostList.push(action.payload); + hostList.push(JSON.parse(obj)); } else { hostList = _.clone(state.hostList); - hostList.push(action.payload); + hostList.push(JSON.parse(obj)); } return { @@ -36,9 +37,10 @@ const reducer: ReducersMapObject = { action: Action): DiscoveryIngState => { let hostList: Host[] = null; + let obj: any = action.payload; if(state.hostList === null || state.hostList === undefined) { hostList = new Array(); - let port: Port = action.payload; + let port: Port = JSON.parse(obj); let host: Host = _.clone(port.host); host.ports = new Array(); port.host = host; @@ -47,18 +49,33 @@ const reducer: ReducersMapObject = { } else { hostList = _.clone(state.hostList); - let port: Port = action.payload; + let port: Port = JSON.parse(obj); // let host: Host = _.clone(port.host); + let tHost: Host = null; for(let h of hostList) { if(h.ip === port.host.ip) { + tHost = h; port.host = h; if(h.ports === null || h.ports === undefined) { h.ports = new Array(); } h.ports.push(port); + break; } } + let dIdx: number = hostList.indexOf(tHost, 0); + if(dIdx > -1) { + hostList.slice(dIdx, 1); + hostList.push(tHost); + } else { + let host: Host = _.clone(port.host); + host.ports = new Array(); + port.host = host; + host.ports.push(port); + hostList.push(host); + } + }