-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.ts
125 lines (104 loc) · 4.37 KB
/
lib.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { MIBLoader } from '../../util/snmp/mibloader';
import { SNMPClient, SNMPClientConfig } from '../../util/snmp/snmp';
import { CiscoSSHClient, SSHCredential } from '../../util/ssh';
import { CiscoTFTPServer } from '../../util/tftp';
import { ControllerFactory as GenericControllerFactory } from '../generic/lib';
import { SwitchConfigurator as CiscoSwitchConfigurator } from './SwitchConfigurator';
import { SvcRunner } from '../../util/svcrunner';
import path from 'path';
import { NetTester } from '../efm/monitor/NetTester';
import { FirewallConfigurator } from '../generic/FirewallConfigurator';
import { Logman } from './Logman';
import { WLANConfigurator } from '../generic/wlan';
import { WLANUserDeviceStat } from '../generic/WLANUserDeviceStat';
import { AuthError, MethodNotImplementedError } from '../../error/MarilError';
import { SwitchQoS as CiscoSwitchQoS } from './SwitchQoS';
import { RouteConfigurator } from '../generic/RouteConfigurator';
import { TrafficStatMonitor } from '../generic/monitor/TrafficStatMonitor';
import { GenericAuthConfigurator } from '../generic/AuthConfigurator';
import { VPNConfigurator } from '../generic/VPNConfigurator';
import { GenericProfileManager } from '../generic/ProfileManager';
export interface CiscoCredential {
snmpCredential: SNMPClientConfig,
sshCredential: SSHCredential,
}
export class ControllerFactory extends GenericControllerFactory {
private snmp: SNMPClient | null = null;
private mibFile: string;
private tftpServer: CiscoTFTPServer;
private sshClient: CiscoSSHClient | undefined;
private svcRunner: SvcRunner;
constructor(deviceaddress: string, mibFile: string, tftpServer: CiscoTFTPServer) {
super(deviceaddress);
this.mibFile = mibFile;
this.tftpServer = tftpServer;
const launcherPath = path.join(__dirname, '../../../ciscocfg/launcher.sh');
this.svcRunner = new SvcRunner(launcherPath);
}
public async authenticate(credential: CiscoCredential) {
const mibLoader = new MIBLoader(this.mibFile);
await mibLoader.init();
this.snmp = new SNMPClient(this.deviceaddress, credential.snmpCredential, mibLoader);
this.snmp.connect();
this.sshClient = new CiscoSSHClient(this.deviceaddress, 22, credential.sshCredential, {
algorithms: {
kex: [
'diffie-hellman-group-exchange-sha1',
'diffie-hellman-group1-sha1',
'diffie-hellman-group14-sha1'
],
},
});
}
public async refreshAuth(): Promise<void> {
// Eat up
}
public async init() {
//await this.svcRunner.start();
}
public getSwitchConfigurator(): CiscoSwitchConfigurator {
if (this.snmp == null || this.sshClient == null) {
throw new AuthError('Not authenticated.');
}
return new CiscoSwitchConfigurator(this.snmp, this.sshClient, this.tftpServer);
}
public getSwitchQoS(): CiscoSwitchQoS {
if (this.snmp == null || this.sshClient == null) {
throw new AuthError('Not authenticated.');
}
return new CiscoSwitchQoS(this.snmp, this.sshClient, this.tftpServer);
}
public getWLANConfigurator(): WLANConfigurator {
throw new MethodNotImplementedError();
}
public getWLANUserDeviceStat(): WLANUserDeviceStat {
throw new MethodNotImplementedError();
}
public getLogman(): Logman {
if (this.snmp == null || this.sshClient == null) {
throw new AuthError('Not authenticated.');
}
return new Logman(this.snmp, this.sshClient, this.tftpServer);
}
public getFirewallConfigurator(): FirewallConfigurator {
throw new MethodNotImplementedError();
}
public getNetTester(): NetTester {
throw new MethodNotImplementedError();
}
public getRouteConfigurator(): RouteConfigurator {
throw new MethodNotImplementedError();
}
public getTrafficStatMonitor(): TrafficStatMonitor {
throw new MethodNotImplementedError();
}
public getAuthConfigurator(): GenericAuthConfigurator{
throw new MethodNotImplementedError();
}
public getVPNConfigurator(): VPNConfigurator {
throw new MethodNotImplementedError();
}
public getProfileManager(): GenericProfileManager {
throw new MethodNotImplementedError();
}
}