From d539eb4f6238a12d7271d0921e600f20c90bedc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Andr=C3=A9s=20P=C3=A9rez=20Ar=C3=A9valo?= Date: Fri, 13 Sep 2019 07:41:24 -0500 Subject: [PATCH] feat(ssh-connect): add new plugin for ssh connection (#3169) --- .../plugins/ssh-connect/index.ts | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/@ionic-native/plugins/ssh-connect/index.ts diff --git a/src/@ionic-native/plugins/ssh-connect/index.ts b/src/@ionic-native/plugins/ssh-connect/index.ts new file mode 100644 index 000000000..6146da701 --- /dev/null +++ b/src/@ionic-native/plugins/ssh-connect/index.ts @@ -0,0 +1,74 @@ +import { Injectable } from '@angular/core'; +import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core'; + +/** + * @name SSH Connect + * @description + * Cordova plugin to make connections and execute commands through SSH + * + * @usage + * ```typescript + * import { SSHConnect } from '@ionic-native/ssh-connect/ngx'; + * + * + * constructor(private sshConnect: SSHConnect) { } + * + * ... + * + * + * this.sshConnect.connect('user', 'password', 'host', port) + * .then(resp => console.log(resp)) + * .catch(error => console.error(error)); + * + * this.sshConnect.executeCommand('command') + * .then(resp => console.log(resp)) + * .catch(error => console.error(error)); + * + * this.sshConnect.disconnect() + * .then(resp => console.log(resp)) + * .catch(error => console.error(error)); + * + * ``` + */ +@Plugin({ + pluginName: 'SSHConnect', + plugin: 'cordova-plugin-ssh-connect', + pluginRef: 'cordova.plugins.sshConnect', + repo: 'https://github.com/JosePerez27/cordova-plugin-ssh-connect', + platforms: ['Android'] +}) +@Injectable() +export class SSHConnect extends IonicNativePlugin { + + /** + * Establish a remote ssh connection + * @param {user} user The remote host user + * @param {password} password The remote host password + * @param {host} host The remote device to connect + * @param {port} port The SSH port for connection (usually port 22) + * @return {Promise} Returns an promise that resolves with the success of the connection + */ + @Cordova() + connect(user: string, password: string, host: string, port: number): Promise { + return; + } + + /** + * Execute a command on the remote host connected by ssh + * @param {command} command The command to execute + * @return {Promise} Returns an promise that resolves with the printed text on the remote console + */ + @Cordova() + executeCommand(command: string): Promise { + return; + } + + /** + * Disconnect the SSH session + * @return {Promise} Returns an promise that resolves with the success of the disconnection + */ + @Cordova() + disconnect(): Promise { + return; + } +}