This commit is contained in:
insanity 2017-06-07 21:38:20 +09:00
parent f794bb1d35
commit d094c0bfca

View File

@ -12,21 +12,26 @@ const styles = {
}, },
}; };
export class DiscoveryResult extends React.Component<any, any> { export class DiscoveryResult extends React.Component<any, any> {
targets : any;
constructor(props: any, context: any) { constructor(props: any, context: any) {
super(props, context); super(props, context);
this.state = { this.state = {
result: [], result: [],
selected: [],
selectedHost: [],
selectedService: [],
}; };
} }
componentWillMount() { 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 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); let obj = JSON.parse(data);
this.targets = new Array();
this.setState({ this.setState({
result: obj, result: obj,
selected: []
}); });
} }
@ -54,102 +59,69 @@ export class DiscoveryResult extends React.Component<any, any> {
} }
handleNext = () => { handleNext = () => {
let c: TargetCreator = new TargetCreator(); for (var i = 0; i < this.targets.length; i++) {
for (var i = 0; i < this.state.selected.length; i++) { var target = this.targets[i];
var data = this.state.selected[i]; console.log(target);
c.Add(data.ip, data.port.portNumber, data.portType, data.vendorName);
}
} }
handleHostCheck = (checked: boolean, host: any) => {
let t = this.state.selected;
let obj = { }
handleTargetCheck = (type: string, checked: boolean, host: any, port: any) => {
let obj: any;
if (type === "host") {
obj = {
"ip": host.ip, "ip": host.ip,
"port": 0, "port": 0,
"portType": "", "portType": "",
"vendorName": host.name, "vendorName": host.name,
}; };
if (checked) {
for (var i = 0; i < t.length; i++) {
if (t[i] === obj) {
return;
}
}
t.push(obj);
} else { } else {
for (var j = t.length - 1; j >= 0; j--) { obj = {
if (t[j] === obj) {
t.splice(j, 1);
}
}
}
this.setState({
selected: t,
});
}
handleServiceCheck = (checked: boolean, host: any, port: any) => {
let t = this.state.selected;
let obj = {
"ip": host.ip, "ip": host.ip,
"port": port.portNumber, "port": port.portNumber,
"portType": port.portType, "portType": port.portType,
"vendorName": port.services[0].serviceName, "vendorName": port.services[0].serviceName,
}; };
}
if (checked) { if (checked) {
for (var i = 0; i < t.length; i++) { this.targets.push(obj);
if (t[i] === obj) {
return;
}
}
t.push(obj);
} else { } else {
for (var j = t.length - 1; j >= 0; j--) { this.targets.pop(obj);
if (t[j] === obj) {
t.splice(j, 1);
}
} }
} }
this.setState({
selected: t,
});
}
renderHosts = (zone: any, num: number) => {
renderHosts = (zone: any) => {
if (zone.hosts === null || zone.hosts.length === 0) { if (zone.hosts === null || zone.hosts.length === 0) {
return null; return null;
} }
return <div style={{ marginLeft: 20 }}> return <div style={{ marginLeft: 20 }}>
{zone.hosts.map((host: any, index: number) => ( {zone.hosts.map((host: any, index: number) => (
<div key={index}> <div key={index}>
<Row type='host' host={host} name={Utils.int2ip(host.ip)} desc={host.mac} onCheck={this.handleHostCheck.bind(this)} /> <Row type='host' id={num++} host={host} name={Utils.int2ip(host.ip)} desc={host.mac} onCheck={this.handleTargetCheck.bind(this)} />
{this.renderPorts(host)} {this.renderPorts(host, num)}
</div> </div>
))} ))}
</div>; </div>;
} }
renderPorts = (host: any) => { renderPorts = (host: any, num: number) => {
if (host.ports === null || host.ports.length === 0) { if (host.ports === null || host.ports.length === 0) {
return null; return null;
} }
return <div style={{ marginLeft: 20 }}> return <div style={{ marginLeft: 20 }}>
{host.ports.map((port: any, index: number) => ( {host.ports.map((port: any, index: number) => (
<div key={index}> <div key={index}>
<Row type='service' host={host} port={port} name={port.portType + port.portNumber} desc={port.services[0].serviceName} onCheck={this.handleServiceCheck.bind(this)} /> <Row type='service' id={num++} host={host} port={port} name={port.portType + port.portNumber} desc={port.services[0].serviceName} onCheck={this.handleTargetCheck.bind(this)} />
</div> </div>
))} ))}
</div>; </div>;
} }
render() { render() {
var num = 0;
return ( return (
<div style={{ margin: 20 }}> <div style={{ margin: 20 }}>
<div> <div>
@ -161,7 +133,7 @@ export class DiscoveryResult extends React.Component<any, any> {
</div> </div>
<div> <div>
Iface : {this.state.result.zone.iface} checked: boolean, host: any, port: any Iface : {this.state.result.zone.iface}
</div> </div>
<div> <div>
IP : {Utils.int2ip(this.state.result.zone.ip)}/{this.state.result.zone.mask} IP : {Utils.int2ip(this.state.result.zone.ip)}/{this.state.result.zone.mask}
@ -171,7 +143,7 @@ export class DiscoveryResult extends React.Component<any, any> {
</div> </div>
<div style={{ margin: 20 }} > Targets </div> <div style={{ margin: 20 }} > Targets </div>
{this.renderHosts(this.state.result.zone)} {this.renderHosts(this.state.result.zone, num)}
<RaisedButton label="Next" primary={true} onClick={this.handleNext.bind(this)} style={{ margin: 20 }} /> <RaisedButton label="Next" primary={true} onClick={this.handleNext.bind(this)} style={{ margin: 20 }} />
</div> </div>
@ -187,11 +159,7 @@ export class Row extends React.Component<any, any> {
} }
handleCheck(ev: any, checked: boolean) { handleCheck(ev: any, checked: boolean) {
if (this.props.type === "host") { this.props.onCheck(this.props.type, checked, this.props.host, this.props.port);
this.props.onCheck(checked, this.props.host);
} else {
this.props.onCheck(checked, this.props.host, this.props.port);
}
} }
render() { render() {