UNPKG

n8n-nodes-netdevices

Version:

n8n node to interact with network devices (Cisco, MikroTik, Arista, Extreme Networks, Dell, Juniper, HP, Aruba, Ubiquiti, Palo Alto, Fortinet - ISP, data center, campus, and edge)

135 lines 4.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UbiquitiEdgeSwitchConnection = void 0; const cisco_connection_1 = require("../cisco/cisco-connection"); class UbiquitiEdgeSwitchConnection extends cisco_connection_1.CiscoConnection { constructor(credentials) { super(credentials); } async sessionPreparation() { await this.createCiscoShellChannel(); if (this.fastMode) { await this.setBasePrompt(); } else { await this.setBasePrompt(); await this.checkAndEnterEnableMode(); await this.setBasePrompt(); await this.setTerminalWidth(); await this.disablePaging(); await new Promise(resolve => setTimeout(resolve, 300)); } } async checkConfigMode() { try { await this.writeChannel(this.returnChar); const output = await this.readChannel(2000); return output.includes(')#'); } catch (error) { return false; } } async enterConfigMode() { if (await this.checkConfigMode()) { this.inConfigMode = true; return; } if (!this.inEnableMode) { await this.enterEnableMode(); } try { await this.writeChannel('configure' + this.newline); const output = await this.readChannel(3000); if (output.includes(')#')) { this.inConfigMode = true; } else { throw new Error('Failed to enter configuration mode'); } } catch (error) { throw new Error(`Failed to enter configuration mode: ${error}`); } } async exitConfigMode() { if (!this.inConfigMode) { return; } try { await this.writeChannel('exit' + this.newline); const output = await this.readChannel(3000); if (output.includes('#') && !output.includes(')#')) { this.inConfigMode = false; } else { throw new Error('Failed to exit configuration mode'); } } catch (error) { throw new Error(`Failed to exit configuration mode: ${error}`); } } async getCurrentConfig() { return await this.sendCommand('show running-config'); } async saveConfig() { try { if (!this.isConnected || !this.currentChannel) { throw new Error('Not connected to device'); } if (!this.inEnableMode) { await this.enterEnableMode(); } await this.writeChannel('write memory' + this.newline); let output = await this.readChannel(5000); if (output.toLowerCase().includes('are you sure')) { await this.writeChannel('y' + this.newline); const additionalOutput = await this.readChannel(5000); output += additionalOutput; } return { command: 'write memory', output: this.sanitizeOutput(output, 'write memory'), success: true }; } catch (error) { return { command: 'write memory', output: '', success: false, error: error instanceof Error ? error.message : 'Unknown error' }; } } async exitEnableMode() { try { if (!this.inEnableMode) { return { command: 'exit', output: 'Already in user mode', success: true }; } await this.writeChannel('exit' + this.newline); const output = await this.readChannel(3000); this.inEnableMode = false; return { command: 'exit', output: output, success: true }; } catch (error) { return { command: 'exit', output: '', success: false, error: error instanceof Error ? error.message : 'Unknown error' }; } } } exports.UbiquitiEdgeSwitchConnection = UbiquitiEdgeSwitchConnection; //# sourceMappingURL=ubiquiti-edgeswitch-connection.js.map