dicoveryIng bug fix

This commit is contained in:
snoop 2017-11-06 16:31:31 +09:00
parent adc99dc29a
commit d2b83563f4
5 changed files with 102 additions and 8 deletions

View File

@ -1,4 +1,5 @@
import Port from './Port'; import Port from './Port';
import Zone from './Zone';
interface Host { interface Host {
id?: number; id?: number;
@ -9,6 +10,7 @@ interface Host {
os: string; os: string;
target: boolean; target: boolean;
ports?: Port[]; ports?: Port[];
zone?: Zone;
} }
export default Host; export default Host;

View File

@ -1,11 +1,14 @@
import Host from './Host';
export interface Zone { export interface Zone {
id: number; id?: number;
network: string; network?: string;
ip: string; ip?: string;
iface: string; iface?: string;
mac: string; mac?: string;
firstScanRange: number; firstScanRange?: number;
lastScanRange: number; lastScanRange?: number;
hosts?: Host[];
} }
export default Zone; export default Zone;

View File

@ -14,6 +14,7 @@ import Probe from '@overflow/probe/api/model/Probe';
import Host from '@overflow/discovery/api/model/Host'; import Host from '@overflow/discovery/api/model/Host';
import Port from '@overflow/discovery/api/model/Port'; import Port from '@overflow/discovery/api/model/Port';
import Service from '@overflow/discovery/api/model/Service'; import Service from '@overflow/discovery/api/model/Service';
import Zone from '@overflow/discovery/api/model/Zone';
import * as _ from 'lodash'; import * as _ from 'lodash';
export interface StateProps { export interface StateProps {
@ -93,6 +94,7 @@ export class Discovery extends React.Component<Props, State> {
let idx: number = Math.floor(Math.random() * (max - min + 1) + min); let idx: number = Math.floor(Math.random() * (max - min + 1) + min);
idx = 2;
switch(idx) { switch(idx) {
case 1: case 1:
this.testHost(); this.testHost();
@ -121,6 +123,21 @@ export class Discovery extends React.Component<Props, State> {
host.ports = null; host.ports = null;
} }
// let zId: number = host.id / 2;
// zId += 1;
// let z: Zone = {
// id: zId,
// network: '192.168.1.205/24',
// ip: '192.168.1.209',
// iface: 'iface',
// mac: 'macaddress',
// firstScanRange: 1,
// lastScanRange: 254,
// };
// host.zone = z;
this.props.onTestDiscovery('1', host); this.props.onTestDiscovery('1', host);
} }
public testPort(): void { public testPort(): void {

View File

@ -18,6 +18,7 @@ import {
import Host from '@overflow/discovery/api/model/Host'; import Host from '@overflow/discovery/api/model/Host';
import Port from '@overflow/discovery/api/model/Port'; import Port from '@overflow/discovery/api/model/Port';
import Service from '@overflow/discovery/api/model/Service'; import Service from '@overflow/discovery/api/model/Service';
import Zone from '@overflow/discovery/api/model/Zone';
import Probe from '@overflow/probe/api/model/Probe'; import Probe from '@overflow/probe/api/model/Probe';
import * as Utils from '@overflow/commons/util/Utils'; import * as Utils from '@overflow/commons/util/Utils';
@ -26,6 +27,7 @@ import * as Utils from '@overflow/commons/util/Utils';
export interface DiscoveryTreeStateProps { export interface DiscoveryTreeStateProps {
probeId: number; probeId: number;
hostList: Host[]; hostList: Host[];
zoneList: Zone[];
onSetTargetList(discoveryHosts: Array<Host>): void; onSetTargetList(discoveryHosts: Array<Host>): void;
} }
@ -105,6 +107,74 @@ export class DiscoveryTree extends React.Component<DiscoveryTreeProps, Discovery
// } // }
} }
public renderZone(): JSX.Element[] {
if(this.props.zoneList === undefined) {
return null;
}
let elems: JSX.Element[] = new Array();
let zoneList: Zone[] = this.props.zoneList;
let zone: Zone;
for (let index: number = 0; index < zoneList.length; ++index) {
zone = zoneList[index];
let key: string = String(zone.ip) + 'zone';
elems.push(
<List.Item key={key + String(index)} >
<List.Icon name={zone.ip ? (this.state.portState[key] ? 'chevron up' : 'chevron down') : 'file'}
onClick={this.onClickHost.bind(this, key)} />
<List.Content>
<List.Header>
<Checkbox label={zone.ip} checked={this.state.checkHostState[key]} onChange={
(event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => {
{
this.onCheck(checkProps, this.state.checkHostState, key, 'checkHostState', this.selectedHostState, host);
}
}} />
</List.Header>
<List.Description style={{ marginLeft: '26px' }}>Host</List.Description>
{zone.hosts ? (this.state.portState[key] ? this.renderHost(zone.hosts, key) : null) : null}
</List.Content>
</List.Item>,
);
}
return null;
}
public renderHost(hostList: Host[], zoneKey: string): JSX.Element[] {
let elems: JSX.Element[] = new Array();
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 + String(index)} >
<List.Icon name={host.ports ? (this.state.portState[key] ? 'chevron up' : 'chevron down') : 'file'}
onClick={this.onClickHost.bind(this, key)} />
<List.Content>
<List.Header>
<Checkbox label={Utils.int2ip(host.ip) + ' ' + host.os} checked={this.state.checkHostState[key]} onChange={
(event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => {
{
this.onCheck(checkProps, this.state.checkHostState, key, 'checkHostState', this.selectedHostState, host);
}
}} />
</List.Header>
<List.Description style={{ marginLeft: '26px' }}>Host</List.Description>
{host.ports ? (this.state.portState[key] ? this.renderPort(host.ports, key) : null) : null}
</List.Content>
</List.Item>,
);
}
return elems;
}
public renderDiscovery(): JSX.Element[] { public renderDiscovery(): JSX.Element[] {
if(this.props.hostList === undefined) { if(this.props.hostList === undefined) {

View File

@ -124,6 +124,7 @@ const reducer: ReducersMapObject = {
} }
return { return {
...state, ...state,
hostList: hostList, hostList: hostList,
@ -283,8 +284,9 @@ const reducer: ReducersMapObject = {
function removeArray(array: any[], obj: any): any[] { function removeArray(array: any[], obj: any): any[] {
let dIdx: number = array.indexOf(obj, 0); let dIdx: number = array.indexOf(obj, 0);
if(dIdx > -1) { if(dIdx > -1) {
array.slice(dIdx, 1); array.splice(dIdx, 1 );
} }
return array; return array;