test
This commit is contained in:
parent
f794bb1d35
commit
d094c0bfca
|
@ -12,21 +12,26 @@ const styles = {
|
|||
},
|
||||
};
|
||||
|
||||
|
||||
export class DiscoveryResult extends React.Component<any, any> {
|
||||
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<any, any> {
|
|||
}
|
||||
|
||||
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 <div style={{ marginLeft: 20 }}>
|
||||
{zone.hosts.map((host: any, index: number) => (
|
||||
<div key={index}>
|
||||
<Row type='host' host={host} name={Utils.int2ip(host.ip)} desc={host.mac} onCheck={this.handleHostCheck.bind(this)} />
|
||||
{this.renderPorts(host)}
|
||||
<Row type='host' id={num++} host={host} name={Utils.int2ip(host.ip)} desc={host.mac} onCheck={this.handleTargetCheck.bind(this)} />
|
||||
{this.renderPorts(host, num)}
|
||||
</div>
|
||||
))}
|
||||
</div>;
|
||||
}
|
||||
|
||||
renderPorts = (host: any) => {
|
||||
renderPorts = (host: any, num: number) => {
|
||||
if (host.ports === null || host.ports.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return <div style={{ marginLeft: 20 }}>
|
||||
{host.ports.map((port: any, index: number) => (
|
||||
<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>;
|
||||
}
|
||||
|
||||
render() {
|
||||
var num = 0;
|
||||
return (
|
||||
<div style={{ margin: 20 }}>
|
||||
<div>
|
||||
|
@ -161,7 +133,7 @@ export class DiscoveryResult extends React.Component<any, any> {
|
|||
</div>
|
||||
|
||||
<div>
|
||||
Iface : {this.state.result.zone.iface}
|
||||
checked: boolean, host: any, port: any Iface : {this.state.result.zone.iface}
|
||||
</div>
|
||||
<div>
|
||||
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 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 }} />
|
||||
</div>
|
||||
|
@ -187,11 +159,7 @@ export class Row extends React.Component<any, any> {
|
|||
}
|
||||
|
||||
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() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user