From d094c0bfcadc564dd40a70303d4b79cdabbe1fb0 Mon Sep 17 00:00:00 2001 From: insanity Date: Wed, 7 Jun 2017 21:38:20 +0900 Subject: [PATCH] test --- .../containers/discovery/DiscoveryResult.tsx | 112 +++++++----------- 1 file changed, 40 insertions(+), 72 deletions(-) diff --git a/src/ts/containers/discovery/DiscoveryResult.tsx b/src/ts/containers/discovery/DiscoveryResult.tsx index 55f9f7b..d8f3dd9 100644 --- a/src/ts/containers/discovery/DiscoveryResult.tsx +++ b/src/ts/containers/discovery/DiscoveryResult.tsx @@ -12,21 +12,26 @@ const styles = { }, }; + export class DiscoveryResult extends React.Component { + targets : any; + constructor(props: any, context: any) { super(props, context); this.state = { result: [], + selected: [], + selectedHost: [], + selectedService: [], }; } componentWillMount() { let data = '{"startDate":1496812121000,"endDate":1496812155000,"result":true,"zone":{"ip":3232235985,"mask":24,"iface":"enp0s3","mac":8796753988883,"firstScanRange":3232235777,"lastScanRange":3232236030,"hosts":[{"firstScanRange":1,"lastScanRange":10000,"name":"","ip":3232235985,"mac":8796753988883,"ports":null,"createDate":1496812124000,"updateDate":1496812124000},{"firstScanRange":1,"lastScanRange":10000,"name":"","ip":3232235881,"mac":23084201235582,"ports":[{"createDate":-62135596800000,"updateDate":-62135596800000,"services":[{"createDate":-62135596800000,"updateDate":-62135596800000,"portType":"TCP","serviceName":"SMTP"}],"portType":"TCP","portNumber":25},{"createDate":-62135596800000,"updateDate":-62135596800000,"services":[{"createDate":-62135596800000,"updateDate":-62135596800000,"portType":"TCP","serviceName":"HTTP"}],"portType":"TCP","portNumber":3000},{"createDate":-62135596800000,"updateDate":-62135596800000,"services":[{"createDate":-62135596800000,"updateDate":-62135596800000,"portType":"TCP","serviceName":"HTTP"}],"portType":"TCP","portNumber":80}],"createDate":1496812124000,"updateDate":1496812124000}]}}'; let obj = JSON.parse(data); - + this.targets = new Array(); this.setState({ result: obj, - selected: [] }); } @@ -54,102 +59,69 @@ export class DiscoveryResult extends React.Component { } handleNext = () => { - let c: TargetCreator = new TargetCreator(); - for (var i = 0; i < this.state.selected.length; i++) { - var data = this.state.selected[i]; - c.Add(data.ip, data.port.portNumber, data.portType, data.vendorName); + for (var i = 0; i < this.targets.length; i++) { + var target = this.targets[i]; + console.log(target); } + + } - handleHostCheck = (checked: boolean, host: any) => { - let t = this.state.selected; - - let obj = { - "ip": host.ip, - "port": 0, - "portType": "", - "vendorName": host.name, - }; + handleTargetCheck = (type: string, checked: boolean, host: any, port: any) => { + let obj: any; + if (type === "host") { + obj = { + "ip": host.ip, + "port": 0, + "portType": "", + "vendorName": host.name, + }; + } else { + obj = { + "ip": host.ip, + "port": port.portNumber, + "portType": port.portType, + "vendorName": port.services[0].serviceName, + }; + } if (checked) { - for (var i = 0; i < t.length; i++) { - if (t[i] === obj) { - return; - } - } - t.push(obj); + this.targets.push(obj); } else { - for (var j = t.length - 1; j >= 0; j--) { - if (t[j] === obj) { - t.splice(j, 1); - } - } + this.targets.pop(obj); } - - this.setState({ - selected: t, - }); - } - - handleServiceCheck = (checked: boolean, host: any, port: any) => { - let t = this.state.selected; - - let obj = { - "ip": host.ip, - "port": port.portNumber, - "portType": port.portType, - "vendorName": port.services[0].serviceName, - }; - - if (checked) { - for (var i = 0; i < t.length; i++) { - if (t[i] === obj) { - return; - } - } - t.push(obj); - } else { - for (var j = t.length - 1; j >= 0; j--) { - if (t[j] === obj) { - t.splice(j, 1); - } - } - } - - this.setState({ - selected: t, - }); } - renderHosts = (zone: any) => { + renderHosts = (zone: any, num: number) => { if (zone.hosts === null || zone.hosts.length === 0) { return null; } return
{zone.hosts.map((host: any, index: number) => (
- - {this.renderPorts(host)} + + {this.renderPorts(host, num)}
))}
; } - renderPorts = (host: any) => { + renderPorts = (host: any, num: number) => { if (host.ports === null || host.ports.length === 0) { return null; } return
{host.ports.map((port: any, index: number) => (
- +
))}
; } render() { + var num = 0; return (
@@ -161,7 +133,7 @@ export class DiscoveryResult extends React.Component {
- Iface : {this.state.result.zone.iface} + checked: boolean, host: any, port: any Iface : {this.state.result.zone.iface}
IP : {Utils.int2ip(this.state.result.zone.ip)}/{this.state.result.zone.mask} @@ -171,7 +143,7 @@ export class DiscoveryResult extends React.Component {
Targets
- {this.renderHosts(this.state.result.zone)} + {this.renderHosts(this.state.result.zone, num)}
@@ -187,11 +159,7 @@ export class Row extends React.Component { } handleCheck(ev: any, checked: boolean) { - if (this.props.type === "host") { - this.props.onCheck(checked, this.props.host); - } else { - this.props.onCheck(checked, this.props.host, this.props.port); - } + this.props.onCheck(this.props.type, checked, this.props.host, this.props.port); } render() {