This commit is contained in:
insanity 2018-06-05 22:01:01 +09:00
parent 27b3490d39
commit d82a4beef7
5 changed files with 47 additions and 59 deletions

View File

@ -15,7 +15,7 @@
<!-- HOST node template --> <!-- HOST node template -->
<ng-template let-node pTemplate="HOST"> <ng-template let-node pTemplate="HOST">
<div @discoveryResultAnim> <div @discoveryResultAnim>
<div *ngIf="checkHighligt(node.label) else unhighlightHost"> <div *ngIf="checkHighlight(node.label) else unhighlightHost">
<p-toggleButton onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check" offIcon="fa-square" [style]="{'width':'200px'}" <p-toggleButton onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check" offIcon="fa-square" [style]="{'width':'200px'}"
(onChange)="onTargetSelect($event, node)"></p-toggleButton> (onChange)="onTargetSelect($event, node)"></p-toggleButton>
</div> </div>

View File

@ -6,8 +6,8 @@ import {
OnInit, OnInit,
OnChanges, OnChanges,
} from '@angular/core'; } from '@angular/core';
import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators';
import { Subscription } from 'rxjs'; import { Subscription, Observable, of } from 'rxjs';
import { DiscoverZone, Zone, Host, Port, Service } from '@overflow/commons-typescript/model/discovery'; import { DiscoverZone, Zone, Host, Port, Service } from '@overflow/commons-typescript/model/discovery';
import { TreeNode, Message, Tree } from 'primeng/primeng'; import { TreeNode, Message, Tree } from 'primeng/primeng';
@ -17,6 +17,8 @@ import { ProbeHost } from '@overflow/commons-typescript/model/probe';
import { Anim } from './animation'; import { Anim } from './animation';
import { DiscoveryNotify } from '../subscriber/discovery.subscriber'; import { DiscoveryNotify } from '../subscriber/discovery.subscriber';
import { InfraHost, InfraService } from '@overflow/commons-typescript/model/infra'; import { InfraHost, InfraService } from '@overflow/commons-typescript/model/infra';
import { TargetService } from '../../target/service/target.service';
import { Target } from '@overflow/commons-typescript/model/target';
@Component({ @Component({
selector: 'of-discovery-result', selector: 'of-discovery-result',
@ -33,13 +35,12 @@ export class SearchResultComponent implements OnInit, OnChanges {
discoverySubscription: Subscription; discoverySubscription: Subscription;
zoneNode: TreeNode[] = []; zoneNode: TreeNode[] = [];
hostNode: TreeNode[] = []; hostNode: TreeNode[] = [];
selectedItems: TreeNode[] = []; selectedItems = [];
msgs: Message[]; msgs: Message[];
error$: Observable<any>;
discoveredHosts: Host[] = [];
discoveredServices: Service[] = [];
constructor( constructor(
private targetService: TargetService
) { ) {
} }
@ -56,8 +57,6 @@ export class SearchResultComponent implements OnInit, OnChanges {
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
if (changes['finished'] && changes['finished'].currentValue === true) { if (changes['finished'] && changes['finished'].currentValue === true) {
this.saveInfras();
// TODO: Comes after save infra
this.msgs = []; this.msgs = [];
this.msgs.push({ this.msgs.push({
severity: 'success', severity: 'success',
@ -68,12 +67,23 @@ export class SearchResultComponent implements OnInit, OnChanges {
addHost(host: Host) { addHost(host: Host) {
this.discoveredHosts.push(host); // this.targetService.findExistHostTarget(this.probeHost.probe.id, host.ipv4)
// .pipe(
// map((target: Target) => {
// }),
// catchError(error => {
// this.error$ = of(error);
// return of();
// }),
// ).subscribe();
const idx = this.findHostIndex(host); const idx = this.findHostIndex(host);
this.hostNode.splice(idx, 0, { this.hostNode.splice(idx, 0, {
type: 'HOST', type: 'HOST',
label: host.ipv4, label: host.ipv4,
data: { data: {
exist: false,
ip: this.convertIPtoNumber(host.ipv4), ip: this.convertIPtoNumber(host.ipv4),
ipv6: host.ipv6, ipv6: host.ipv6,
mac: host.mac, mac: host.mac,
@ -86,7 +96,6 @@ export class SearchResultComponent implements OnInit, OnChanges {
} }
addService(service: Service) { addService(service: Service) {
this.discoveredServices.push(service);
const targetHostNode = this.findHostNodeByService(service); const targetHostNode = this.findHostNodeByService(service);
const idx = this.findServiceIndex(targetHostNode.children, service); const idx = this.findServiceIndex(targetHostNode.children, service);
targetHostNode.children.splice(idx, 0, { targetHostNode.children.splice(idx, 0, {
@ -162,7 +171,7 @@ export class SearchResultComponent implements OnInit, OnChanges {
}); });
} }
checkHighligt(label: string) { checkHighlight(label: string) {
let highlight = true; let highlight = true;
if (this.filterWord && (label.toUpperCase().indexOf(this.filterWord.toUpperCase()) < 0)) { if (this.filterWord && (label.toUpperCase().indexOf(this.filterWord.toUpperCase()) < 0)) {
highlight = false; highlight = false;
@ -173,46 +182,18 @@ export class SearchResultComponent implements OnInit, OnChanges {
return highlight; return highlight;
} }
saveInfras() {
this.discoveredHosts.forEach(host => {
const infraHost: InfraHost = {
probe: this.probeHost.probe,
infraType: {
id: 2
},
os: {},
ipv4: host.ipv4,
ipv6: host.ipv6,
mac: host.mac,
};
});
this.discoveredServices.forEach(service => {
const infraService: InfraService = {
probe: this.probeHost.probe,
infraType: {
id: 7
},
host: {
},
portType: service.port.portType,
port: service.port.portNumber,
vendor: {
}
};
});
}
saveTargets() { saveTargets() {
console.log(this.selectedItems); console.log(this.selectedItems);
let node: TreeNode; const hosts: Host[] = [];
for (node of this.selectedItems) { const services: Service[] = [];
if (node.type === 'HOST') { this.selectedItems.forEach(value => {
// InfraHost if (value.ipv4) {
} else if (node.type === 'SERVICE') { hosts.push(value);
// InfraService } else {
// InfraOSPort? services.push(value);
} }
} });
this.targetService.registDiscoveredTargets(this.probeHost.probe.id, null, null);
} }
} }

View File

@ -156,7 +156,7 @@ export class InfraMapComponent implements OnInit, AfterContentInit {
for (const sensor of sensorList) { for (const sensor of sensorList) {
const st = { const st = {
label: 'Sensors - ' + sensor.crawler.name, label: 'Sensors - ' + sensor.metaCrawler.name,
type: 'sensor', type: 'sensor',
obj: sensor, obj: sensor,
expanded: true expanded: true
@ -254,7 +254,7 @@ export class InfraMapComponent implements OnInit, AfterContentInit {
for (let i = 0; i < ifsl.length; ++i) { for (let i = 0; i < ifsl.length; ++i) {
const ts = { const ts = {
label: 'Service - ' + ifsl[i].vendor.name, label: 'Service - ' + ifsl[i].metaInfraVendor.name,
type: 'service', type: 'service',
expandedIcon: 'fa-folder-open', expandedIcon: 'fa-folder-open',
collapsedIcon: 'fa-folder', collapsedIcon: 'fa-folder',
@ -285,7 +285,7 @@ export class InfraMapComponent implements OnInit, AfterContentInit {
sortInfraToMap(probeMap: Map<number, InfraHost[]>, hostMap: Map<string, InfraService[]>, filterStr: string) { sortInfraToMap(probeMap: Map<number, InfraHost[]>, hostMap: Map<string, InfraService[]>, filterStr: string) {
for (const infra of this.totalList) { for (const infra of this.totalList) {
const infraType = infra.infraType.name; const infraType = infra.metaInfraType.name;
if (infraType === 'HOST') { if (infraType === 'HOST') {
const infraHost: InfraHost = infra; const infraHost: InfraHost = infra;
if (filterStr && String(infraHost.ipv4).indexOf(filterStr) < 0) { if (filterStr && String(infraHost.ipv4).indexOf(filterStr) < 0) {
@ -306,11 +306,11 @@ export class InfraMapComponent implements OnInit, AfterContentInit {
continue; continue;
} }
if (hostMap.has(infraService.host.ipv4) === false) { if (hostMap.has(infraService.infraHost.ipv4) === false) {
hostMap.set(infraService.host.ipv4, []); hostMap.set(infraService.infraHost.ipv4, []);
} }
const isl = hostMap.get(infraService.host.ipv4); const isl = hostMap.get(infraService.infraHost.ipv4);
isl.push(infraService); isl.push(infraService);
} }
@ -335,7 +335,7 @@ export class InfraMapComponent implements OnInit, AfterContentInit {
checkFilterString(infraService: InfraService, filterStr: string) { checkFilterString(infraService: InfraService, filterStr: string) {
const upperCased = filterStr.toUpperCase().toUpperCase(); const upperCased = filterStr.toUpperCase().toUpperCase();
if (infraService.vendor.name.toUpperCase().indexOf(upperCased) < 0 && if (infraService.metaInfraVendor.name.toUpperCase().indexOf(upperCased) < 0 &&
String(infraService.port).toUpperCase().indexOf(upperCased) < 0 && String(infraService.port).toUpperCase().indexOf(upperCased) < 0 &&
infraService.portType.toUpperCase().indexOf(upperCased)) { infraService.portType.toUpperCase().indexOf(upperCased)) {
return true; return true;

View File

@ -23,4 +23,11 @@ export class TargetService {
return this.rpcService.call<Target>('TargetService.modify', target); return this.rpcService.call<Target>('TargetService.modify', target);
} }
public findExistHostTarget(probeID: number, hostIP: string): Observable<Target> {
return this.rpcService.call<Target>('TargetService.readExistHostTarget', probeID, hostIP);
}
public findExistServiceTarget(hostID: number, portNumber: number, portType: string): Observable<Target> {
return this.rpcService.call<Target>('TargetService.readExistServiceTarget', hostID, portNumber, portType);
}
} }

6
package-lock.json generated
View File

@ -453,9 +453,9 @@
} }
}, },
"@overflow/commons-typescript": { "@overflow/commons-typescript": {
"version": "0.0.7", "version": "0.0.8",
"resolved": "https://nexus.loafle.net/repository/npm-all/@overflow/commons-typescript/-/commons-typescript-0.0.7.tgz", "resolved": "https://nexus.loafle.net/repository/npm-all/@overflow/commons-typescript/-/commons-typescript-0.0.8.tgz",
"integrity": "sha512-qbrNlHEZjUfmuExcHEQ1Bf+PNQfkAZsbinDSGU4ndD4H8hNg/Cv2i4TWaLSWVqXrbIEZkKmv4AZJC9WQTUcFPA==" "integrity": "sha512-yaN3kYofzzJjRJsMuRHbryWVQU6AdsmVbGBmvdKvXQrI/xZzss2K5ZRTqDAOAHEXpyk1Ty+yeXMEPihfLv5bqw=="
}, },
"@schematics/angular": { "@schematics/angular": {
"version": "0.6.5", "version": "0.6.5",