| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- const fs = require("fs");
- const path = require("path");
- const { NodeSSH } = require("node-ssh");
- const vorpal = require("vorpal")();
- const ssh = new NodeSSH();
- let shell;
- ssh.connect({
- host: "10.5.17.151",
- username: "swjmrhb_ggfw/10.4.115.9/any",
- password: "EqRa6KSd2kF%C&mj",
- onKeyboardInteractive(
- name,
- instructions,
- instructionsLang,
- prompts,
- finish
- ) {
- console.log("🔊🚀🚀🚀🔊 ~ RollbackCommand ~", prompts);
- if (
- prompts.length > 0 &&
- prompts[0].prompt.toLowerCase().includes("password")
- ) {
- prompts([
- {
- type: "password",
- name: "newPassword",
- message: `input the password of ${hostItem}:`,
- },
- ]).then(({ newPassword }) => {
- finish([newPassword]);
- });
- }
- },
- })
- .then(() => {
- return ssh.requestShell();
- })
- .then((stream) => {
- shell = stream;
- shell
- .on("close", () => {
- console.log("Stream :: close");
- conn.end();
- })
- .on("data", (data) => {
- let str = data.toString();
- process.stdout.write(data);
- if (/^login\:/.test(str)) {
- console.log("enter name");
- stream.write("admin\n");
- }
- if (/^admin@.*password:/.test(str)) {
- console.log("enter password");
- shell.write("yWfuA@4NTX!b#2kG\n");
- setTimeout(() => {
- shell.write("su root\n");
- setTimeout(() => {
- shell.write("yWfuA@4NTX!b#2kG\n");
- setTimeout(() => {
- shell.write("./deploy.sh\n");
- }, 100);
- }, 100);
- }, 100);
- }
- });
- })
- .catch((e) => {
- console.log(e);
- });
- vorpal.command("su").action(function (args, callback) {
- shell.write("su root\n");
- setTimeout(() => {
- shell.write("yWfuA@4NTX!b#2kG\n");
- callback();
- }, 500);
- });
- vorpal.command("upload").action(function (args, callback) {
- ssh.putFiles([
- {
- local: "/Users/drew/Desktop/building3.jpeg",
- remote: "/home/admin/1.png",
- },
- ]).then(
- function () {
- console.log("The File thing is done");
- callback();
- },
- function (error) {
- console.log("Something's wrong");
- console.log(error);
- callback();
- }
- );
- });
- vorpal.command("ls").action(function (args, callback) {
- ssh.execCommand("ls").then(function (result) {
- console.log("STDOUT: " + result.stdout);
- console.log("STDERR: " + result.stderr);
- callback();
- });
- shell;
- });
- vorpal.delimiter("deploy$").show();
|