diff --git a/commands/exec.js b/commands/exec.js index 8b6c7fc..29cc7ed 100644 --- a/commands/exec.js +++ b/commands/exec.js @@ -12,9 +12,14 @@ async function runCMD(key, cmd, pwd) { return requestData.body.stdout } -async function execute(key, cmd, pwd) { +async function execute(key, cmd, pwd, conns) { const stdout = await runCMD(key, cmd, pwd) console.log(stdout) + if (stdout.length > 1800) return console.log("I cannot send stdout to the swarm, its too large!") + for (const conn of conns) + conn.write(`${USERNAME}: ran ${cmd}\n${stdout}`) + } + module.exports = { execute, runCMD } \ No newline at end of file diff --git a/sshChat.js b/sshChat.js index 96e5c73..be48d29 100644 --- a/sshChat.js +++ b/sshChat.js @@ -1,8 +1,11 @@ +// Require the needed libs const Hyperswarm = require('hyperswarm') const crypto = require('hypercore-crypto') const b4a = require('b4a') const readline = require('readline') const fs = require("fs"); + +// Import our command const { login } = require('./commands/login'); const { execute } = require('./commands/exec'); const { stop } = require('./commands/stop'); @@ -21,8 +24,6 @@ let LOGGEDIN = false let MYKEY = [] let conns = [] - - function sleep(ms) { return new Promise((resolve) => { setTimeout(resolve, ms); @@ -54,8 +55,6 @@ for (const file of commandFiles) { } - - async function handleCommand(input) { if (input.startsWith("!") || input.startsWith(">")) { const command = input.split(" ") @@ -71,7 +70,7 @@ async function handleCommand(input) { stats(MYKEY[0]) break; case ">": - execute(MYKEY[0], command.slice(1), USERPWD); + execute(MYKEY[0], command.slice(1).join(" "), USERPWD, conns); break; case ">restart": restart(MYKEY[0]) @@ -90,15 +89,12 @@ async function handleCommand(input) { } } else { for (const conn of conns) - if (input.startsWith("!") || input.startsWith(">")){ - }else { conn.write(`${USERNAME}: ${input}`) - } + } console.log(`${USERNAME}: ${input}`) clearCursor() - } swarm.on('connection', conn => {