Discovery Ing port

This commit is contained in:
snoop 2017-10-24 17:05:54 +09:00
parent 8e7af6db75
commit 8b130cbd90
7 changed files with 308 additions and 188 deletions

View File

@ -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,

View File

@ -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';

View File

@ -26,9 +26,9 @@ export function mapDispatchToProps(dispatch: Dispatch<any>): DiscoveryDispatchPr
dispatch(asyncRequestActions.request('TargetDiscoveryService', 'saveAllTarget',
InfraTargetRegistAllActionTypes.REQUEST, JSON.stringify(hosts), JSON.stringify(probe)));
},
onTestDiscovery: (types: string, obj: string) => {
onTestDiscovery: (types: string, obj: any) => {
dispatch(asyncRequestActions.request('DiscoveryService', 'testDiscovery',
'DiscoveryTTTTTEEEESSSTTT', types, obj));
'DiscoveryTTTTTEEEESSSTTT', types, JSON.stringify(obj)));
},
};
}

View File

@ -17,6 +17,7 @@ export function mapStateToProps(state: any, props: any): DiscoveryTreeStateProps
return {
probeId: props.probeId,
onSetTargetList: props.onSetTargetList,
hostList: state.hostList,
};
}

View File

@ -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,7 +26,7 @@ export interface StateProps {
export interface DispatchProps {
onCreateTarget?(hosts: Host[], probe: Probe): void;
onTestDiscovery?(types: string, obj: string): void;
onTestDiscovery?(types: string, obj: any): void;
}
export type Props = StateProps & DispatchProps;
@ -39,12 +42,16 @@ export class Discovery extends React.Component<Props, State> {
private submitData: any;
private discoveryHosts: Array<Host>;
private exDisHosts: Array<Host>;
public constructor(props: Props, context: State) {
super(props, context);
this.handleProbeChange.bind(this);
this.state = {
startPopup: false,
};
this.exDisHosts = hostListJson;
}
public componentWillMount(): void {
@ -69,7 +76,7 @@ export class Discovery extends React.Component<Props, State> {
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) });
}
@ -80,7 +87,92 @@ export class Discovery extends React.Component<Props, State> {
public handleCancel = () => this.setState({ startPopup: false });
public handleTest = () => {
this.props.onTestDiscovery('1', 'host json');
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 });
@ -120,3 +212,180 @@ export class Discovery extends React.Component<Props, State> {
);
}
}
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,
},
];

View File

@ -25,6 +25,7 @@ import * as Utils from '@overflow/commons/util/Utils';
export interface DiscoveryTreeStateProps {
probeId: number;
hostList: Host[];
onSetTargetList(discoveryHosts: Array<Host>): void;
}
@ -65,7 +66,7 @@ export class DiscoveryTree extends React.Component<DiscoveryTreeProps, Discovery
this.selectedHostState = new Map;
this.selectedPortState = new Map;
this.selectedServiceState = new Map;
this.discoveryHosts = hostListJson;
// this.discoveryHosts = hostListJson;
// fs.readFile('../../../../../dh.json', this.handlJSONFile);
}
@ -98,7 +99,7 @@ export class DiscoveryTree extends React.Component<DiscoveryTreeProps, Discovery
let checkObj: any = selectedObj;
checkObj.target = checkProps.checked;
}
this.props.onSetTargetList(this.discoveryHosts);
// this.props.onSetTargetList(this.discoveryHosts);
// if(selectedObj instanceof Host) {
// console.log(selectedObj);
// }
@ -106,15 +107,19 @@ export class DiscoveryTree extends React.Component<DiscoveryTreeProps, Discovery
public renderDiscovery(): JSX.Element[] {
if(this.props.hostList === undefined) {
return null;
}
let elems: JSX.Element[] = new Array();
let hostList: Host[] = this.discoveryHosts;
let hostList: Host[] = this.props.hostList;
let host: Host;
for (let index: number = 0; index < hostList.length; ++index) {
host = hostList[index];
let key: string = String(host.ip);
elems.push(
<List.Item key={key} >
<List.Item key={key + String(index)} >
<List.Icon name={host.ports ? (this.state.portState[key] ? 'chevron up' : 'chevron down') : 'file'}
onClick={this.onClickHost.bind(this, key)} />
<List.Content>
@ -223,180 +228,6 @@ export class DiscoveryTree extends React.Component<DiscoveryTreeProps, Discovery
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,
},
];
const hostListJsonMini: any = [

View File

@ -18,13 +18,14 @@ const reducer: ReducersMapObject = {
[IngActionTypes.RECEIVE_HOST]: (state: DiscoveryIngState = DiscoveryIngDefaultState,
action: Action<Host>): 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<Port>): 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);
}
}