393 lines
9.9 KiB
TypeScript
393 lines
9.9 KiB
TypeScript
|
// import { Component, OnInit, AfterContentInit } from '@angular/core';
|
||
|
// import { Store, select } from '@ngrx/store';
|
||
|
// import { RPCClientError } from '@loafer/ng-rpc/protocol';
|
||
|
// import {
|
||
|
// DiscoveryStartInfo,
|
||
|
// DiscoveryZone,
|
||
|
// Zone,
|
||
|
// DiscoveryPort,
|
||
|
// DiscoveryService
|
||
|
// } from '../../model';
|
||
|
// import * as CIDR from 'ip-cidr';
|
||
|
// import * as DiscoveredStore from '../../store/setting';
|
||
|
// // import * as DiscoverStore from '../../store/discover';
|
||
|
|
||
|
// import { SettingSelector, DiscoverSelector } from '../../store';
|
||
|
// import * as DiscoverStore from '../../store/discover';
|
||
|
|
||
|
// import * as RegistStore from '../../store/regist';
|
||
|
// import { Host } from 'packages/discovery/model/Host';
|
||
|
// import { Port } from 'packages/discovery/model/Port';
|
||
|
// import { Service } from 'packages/discovery/model/Service';
|
||
|
// import * as ProbeDetailStore from 'packages/probe/store';
|
||
|
// import { Probe } from 'packages/probe/model';
|
||
|
|
||
|
// import { DetailSelector as ProbeDetailSelector } from 'packages/probe/store';
|
||
|
|
||
|
// @Component({
|
||
|
// selector: 'of-setting',
|
||
|
// templateUrl: './setting.component.html',
|
||
|
// styleUrls: ['./setting.component.scss']
|
||
|
// })
|
||
|
// export class SettingComponent implements OnInit, AfterContentInit {
|
||
|
|
||
|
|
||
|
// probe$ = this.probeDetailStore.pipe(select(ProbeDetailSelector.select('probe')));
|
||
|
|
||
|
// settingSucceed$: any;
|
||
|
// discoveryResult$: any;
|
||
|
// probe: Probe = null;
|
||
|
// started = false;
|
||
|
|
||
|
// cidr;
|
||
|
// startIP;
|
||
|
// endIP;
|
||
|
// startPort;
|
||
|
// endPort;
|
||
|
// // private settingForm: FormGroup;
|
||
|
// hostChecked = true;
|
||
|
// portChecked = true;
|
||
|
// serviceChecked = true;
|
||
|
// tcpChecked = true;
|
||
|
// udpChecked = true;
|
||
|
// includeServices = null;
|
||
|
|
||
|
// serviceItems = [
|
||
|
// { name: 'SSH' },
|
||
|
// { name: 'PostgreSQL' },
|
||
|
// { name: 'DNS' },
|
||
|
// { name: 'WMI'},
|
||
|
// { name: 'SMB' },
|
||
|
// { name: 'ActiveDirectory' },
|
||
|
// { name: 'Cassandra' },
|
||
|
// { name: 'FTP' },
|
||
|
// { name: 'HTTP' },
|
||
|
// { name: 'IMAP' },
|
||
|
// { name: 'LDAP' },
|
||
|
// { name: 'MongoDB' },
|
||
|
// { name: 'MySQL' },
|
||
|
// { name: 'NBSS' },
|
||
|
// ];
|
||
|
|
||
|
// treeNodes = [];
|
||
|
// zones: Map<string, Zone> = null;
|
||
|
|
||
|
// checkedSet = new Set();
|
||
|
|
||
|
// constructor(
|
||
|
// private discoverdstore: Store<DiscoveredStore.State>,
|
||
|
// private discoverstore: Store<DiscoverStore.State>,
|
||
|
// private registStore: Store<RegistStore.State>,
|
||
|
// private probeDetailStore: Store<ProbeDetailStore.State>
|
||
|
// ) {
|
||
|
// this.settingSucceed$ = discoverdstore.pipe(select(SettingSelector.select('isStart')));
|
||
|
// this.discoveryResult$ = this.discoverstore.pipe(select(DiscoverSelector.select('zones')));
|
||
|
// }
|
||
|
|
||
|
// ngOnInit() {
|
||
|
// this.settingSucceed$.subscribe(
|
||
|
// (succeed: boolean) => {
|
||
|
// if (succeed) {
|
||
|
// this.started = true;
|
||
|
// }
|
||
|
// },
|
||
|
// (error: RPCClientError) => {
|
||
|
// console.log(error.response.message);
|
||
|
// }
|
||
|
// );
|
||
|
|
||
|
// this.probe$.subscribe(
|
||
|
// (probe: Probe) => {
|
||
|
// if (probe != null) {
|
||
|
// this.probe = probe;
|
||
|
// }
|
||
|
// },
|
||
|
// (error: RPCClientError) => {
|
||
|
// console.log(error.response.message);
|
||
|
// }
|
||
|
// );
|
||
|
|
||
|
// this.discoveryResult$.subscribe(
|
||
|
// (zones: Map<string, Zone>) => {
|
||
|
// console.log('ZoneZoneZoneZoneZoneZoneZone');
|
||
|
// // console.log(JSON.stringify(zones));
|
||
|
// this.convertTreeViewZone(zones);
|
||
|
// this.zones = zones;
|
||
|
// },
|
||
|
// (error: RPCClientError) => {
|
||
|
// console.log(error.response.message);
|
||
|
// }
|
||
|
// );
|
||
|
|
||
|
// }
|
||
|
|
||
|
// isZone(zone: Zone): boolean {
|
||
|
|
||
|
// for (let i = 0; i < this.treeNodes.length; ++i) {
|
||
|
// if (zone.iface === this.treeNodes[i].iface) {
|
||
|
// return true;
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
// return false;
|
||
|
// }
|
||
|
|
||
|
// convertTreeViewZone(zones: Map<string, Zone>) {
|
||
|
|
||
|
// if (zones === undefined || zones === null) {
|
||
|
// return;
|
||
|
// }
|
||
|
|
||
|
// // console.log('convertTreeViewZone');
|
||
|
// const treeNodes: any[] = [];
|
||
|
|
||
|
// zones.forEach((value: Zone, key: string, map) => {
|
||
|
// if (this.isZone(value)) {
|
||
|
// return;
|
||
|
// }
|
||
|
// const jZone: any = {
|
||
|
// title: 'Zone - ' + value.iface,
|
||
|
// className: 'cn' + value.ip
|
||
|
// };
|
||
|
// jZone.obj = value;
|
||
|
// jZone.children = this.convertViewHost(value.hosts);
|
||
|
// treeNodes.push(jZone);
|
||
|
// });
|
||
|
|
||
|
// this.treeNodes = treeNodes;
|
||
|
// }
|
||
|
|
||
|
// ngAfterContentInit() {
|
||
|
// this.cidr = '192.168.1.0/24';
|
||
|
// this.hostRange();
|
||
|
// this.portRange();
|
||
|
// }
|
||
|
|
||
|
// hostRange() {
|
||
|
// const cidr = new CIDR(this.cidr);
|
||
|
// if (!cidr.isValid()) {
|
||
|
// alert('Invalid cidr : ' + this.cidr);
|
||
|
// return;
|
||
|
// }
|
||
|
// this.startIP = cidr.addressStart.address;
|
||
|
// this.endIP = cidr.addressEnd.address;
|
||
|
// }
|
||
|
|
||
|
// portRange() {
|
||
|
// this.startPort = '1';
|
||
|
// this.endPort = '1024';
|
||
|
// }
|
||
|
|
||
|
// handleHostCheckChange(e: MatCheckboxChange) {
|
||
|
// this.hostChecked = true;
|
||
|
// e.source.checked = true;
|
||
|
// }
|
||
|
|
||
|
// handlePortCheckChange(e: MatCheckboxChange) {
|
||
|
// this.serviceChecked = false;
|
||
|
// }
|
||
|
|
||
|
// handleServiceCheckChange(e: MatCheckboxChange) {
|
||
|
// if (e.checked) {
|
||
|
// this.portChecked = true;
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
// handleServiceChange(list: any) {
|
||
|
// this.includeServices = list;
|
||
|
// }
|
||
|
|
||
|
// discovery() {
|
||
|
// let discoveryPort: DiscoveryPort = null;
|
||
|
// let discoveryService: DiscoveryService = null;
|
||
|
|
||
|
// if (this.serviceChecked) {
|
||
|
// const services = new Array();
|
||
|
// for (const service of this.includeServices) {
|
||
|
// services.push(service.name);
|
||
|
// }
|
||
|
// discoveryService = {
|
||
|
// includeServices: services,
|
||
|
// };
|
||
|
// }
|
||
|
// if (this.portChecked) {
|
||
|
// discoveryPort = {
|
||
|
// firstScanRange: this.startPort,
|
||
|
// lastScanRange: this.endPort,
|
||
|
// includeTCP: this.tcpChecked,
|
||
|
// includeUDP: this.udpChecked,
|
||
|
// excludePorts: null,
|
||
|
// discoveryService: discoveryService
|
||
|
// };
|
||
|
// }
|
||
|
// const discoveryZone: DiscoveryZone = {
|
||
|
// discoveryHost: {
|
||
|
// firstScanRange: this.startIP,
|
||
|
// lastScanRange: this.endIP,
|
||
|
// discoveryPort: discoveryPort,
|
||
|
// },
|
||
|
// };
|
||
|
|
||
|
// console.log(discoveryZone);
|
||
|
|
||
|
// console.log('start discovery - ' + this.probe.probeKey);
|
||
|
// this.discoverstore.dispatch(new DiscoverStore.DiscoverZone(
|
||
|
// { probeID: this.probe.probeKey, discoveryZone: discoveryZone }));
|
||
|
|
||
|
// this.started = true;
|
||
|
// }
|
||
|
|
||
|
// checkDiscoveryResult(node) {
|
||
|
|
||
|
// node.toggleActivated(true);
|
||
|
|
||
|
// if (node.isActive) {
|
||
|
// if (node.data.obj !== undefined) {
|
||
|
// node.data.obj.target = true;
|
||
|
// }
|
||
|
// } else {
|
||
|
// if (node.data.obj !== undefined) {
|
||
|
// node.data.obj.target = false;
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
// console.log(this.zones);
|
||
|
|
||
|
// }
|
||
|
|
||
|
// convertMapToList(map: Map<any, any>): Array<any> {
|
||
|
|
||
|
// if (undefined === map || null === map || map.size < 0) {
|
||
|
// return null;
|
||
|
// }
|
||
|
|
||
|
// const retArr = new Array();
|
||
|
|
||
|
// map.forEach((v: any, k: any) => {
|
||
|
// retArr.push(v);
|
||
|
// });
|
||
|
|
||
|
// return retArr;
|
||
|
// }
|
||
|
|
||
|
|
||
|
// discoveryResultSave() {
|
||
|
// // console.log(this.checkedSet);
|
||
|
|
||
|
// // send discovery save this.zones;
|
||
|
|
||
|
// // this.registStore.dispatch(new DiscoverStore.DiscoverZone(
|
||
|
// // {probeID: '52abd6fd57e511e7ac52080027658d13', discoveryZone: discoveryZone}));
|
||
|
|
||
|
// this.zones.forEach((zone: Zone, key: string) => {
|
||
|
// if (zone.hosts !== undefined && zone.hosts !== null && zone.hosts.size > 0) {
|
||
|
// // FIXME: getHosts
|
||
|
// const hosts: Host[] = [];
|
||
|
// zone.hosts.forEach((h: Host, hKey: string) => {
|
||
|
|
||
|
// // if (h.ports !== undefined && h.ports !== null) {
|
||
|
// // h.portList = [];
|
||
|
// // h.ports.forEach((p: Port, pKey: number) => {
|
||
|
|
||
|
// // if (p.services !== undefined && p.services !== null) {
|
||
|
// // p.serviceList = [];
|
||
|
|
||
|
// // p.services.forEach((s: Service, sKey: string) => {
|
||
|
// // p.serviceList.push(s);
|
||
|
// // });
|
||
|
|
||
|
// // }
|
||
|
|
||
|
// // h.portList.push(p);
|
||
|
// // });
|
||
|
// // }
|
||
|
|
||
|
// hosts.push(h);
|
||
|
// });
|
||
|
|
||
|
// if (hosts.length > 0) {
|
||
|
// const sd: any = { hosts: hosts, probe: { id: 1 } };
|
||
|
// console.log(JSON.stringify(sd));
|
||
|
// console.log('--------');
|
||
|
// this.registStore.dispatch(new RegistStore.DiscoverySaveAllTarget(sd));
|
||
|
// }
|
||
|
|
||
|
// }
|
||
|
// });
|
||
|
// }
|
||
|
|
||
|
// convertViewHost(hosts): any[] {
|
||
|
|
||
|
// if (hosts === undefined || hosts === null) {
|
||
|
// return null;
|
||
|
// }
|
||
|
|
||
|
|
||
|
// const hostNodes: any[] = [];
|
||
|
|
||
|
// hosts.forEach((host, hostKey) => {
|
||
|
|
||
|
// const jHost: any = {
|
||
|
// title: 'Host - ' + host.ip,
|
||
|
// className: 'cn' + host.ip
|
||
|
// };
|
||
|
// jHost.obj = host;
|
||
|
|
||
|
// jHost.children = this.convertViewPort(host.ports);
|
||
|
|
||
|
// hostNodes.push(jHost);
|
||
|
|
||
|
// });
|
||
|
|
||
|
// return hostNodes;
|
||
|
|
||
|
// }
|
||
|
|
||
|
// convertViewPort(ports): any[] {
|
||
|
|
||
|
// if (ports === undefined || ports === null) {
|
||
|
// return null;
|
||
|
// }
|
||
|
|
||
|
// const portChildren: any[] = [];
|
||
|
|
||
|
// ports.forEach((port, portKey) => {
|
||
|
|
||
|
// const jPort: any = {
|
||
|
// title: 'Port - ' + port.portNumber,
|
||
|
// className: 'cn' + port.portNumber,
|
||
|
// };
|
||
|
// jPort.obj = port;
|
||
|
|
||
|
// jPort.children = this.convertViewService(port.services);
|
||
|
|
||
|
// portChildren.push(jPort);
|
||
|
// });
|
||
|
|
||
|
|
||
|
// return portChildren;
|
||
|
// }
|
||
|
|
||
|
// convertViewService(services): any[] {
|
||
|
|
||
|
// if (services === undefined || services === null || services.size <= 0) {
|
||
|
// return null;
|
||
|
// }
|
||
|
|
||
|
// const serviceChildren: any[] = [];
|
||
|
|
||
|
// services.forEach((service, serviceKey) => {
|
||
|
// const jService: any = {
|
||
|
// title: 'Service - ' + service.serviceName,
|
||
|
// className: 'cn' + service.serviceName,
|
||
|
// };
|
||
|
// jService.obj = service;
|
||
|
|
||
|
// serviceChildren.push(jService);
|
||
|
// });
|
||
|
|
||
|
// return serviceChildren;
|
||
|
// }
|
||
|
|
||
|
// }
|