Fixing small bugs from the refractor
This commit is contained in:
parent
aceead9064
commit
23b57275e5
@ -12,9 +12,14 @@ async function runCMD(key, cmd, pwd) {
|
|||||||
return requestData.body.stdout
|
return requestData.body.stdout
|
||||||
}
|
}
|
||||||
|
|
||||||
async function execute(key, cmd, pwd) {
|
async function execute(key, cmd, pwd, conns) {
|
||||||
const stdout = await runCMD(key, cmd, pwd)
|
const stdout = await runCMD(key, cmd, pwd)
|
||||||
console.log(stdout)
|
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 }
|
module.exports = { execute, runCMD }
|
14
sshChat.js
14
sshChat.js
@ -1,8 +1,11 @@
|
|||||||
|
// Require the needed libs
|
||||||
const Hyperswarm = require('hyperswarm')
|
const Hyperswarm = require('hyperswarm')
|
||||||
const crypto = require('hypercore-crypto')
|
const crypto = require('hypercore-crypto')
|
||||||
const b4a = require('b4a')
|
const b4a = require('b4a')
|
||||||
const readline = require('readline')
|
const readline = require('readline')
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
|
// Import our command
|
||||||
const { login } = require('./commands/login');
|
const { login } = require('./commands/login');
|
||||||
const { execute } = require('./commands/exec');
|
const { execute } = require('./commands/exec');
|
||||||
const { stop } = require('./commands/stop');
|
const { stop } = require('./commands/stop');
|
||||||
@ -21,8 +24,6 @@ let LOGGEDIN = false
|
|||||||
let MYKEY = []
|
let MYKEY = []
|
||||||
let conns = []
|
let conns = []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function sleep(ms) {
|
function sleep(ms) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
setTimeout(resolve, ms);
|
setTimeout(resolve, ms);
|
||||||
@ -54,8 +55,6 @@ for (const file of commandFiles) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function handleCommand(input) {
|
async function handleCommand(input) {
|
||||||
if (input.startsWith("!") || input.startsWith(">")) {
|
if (input.startsWith("!") || input.startsWith(">")) {
|
||||||
const command = input.split(" ")
|
const command = input.split(" ")
|
||||||
@ -71,7 +70,7 @@ async function handleCommand(input) {
|
|||||||
stats(MYKEY[0])
|
stats(MYKEY[0])
|
||||||
break;
|
break;
|
||||||
case ">":
|
case ">":
|
||||||
execute(MYKEY[0], command.slice(1), USERPWD);
|
execute(MYKEY[0], command.slice(1).join(" "), USERPWD, conns);
|
||||||
break;
|
break;
|
||||||
case ">restart":
|
case ">restart":
|
||||||
restart(MYKEY[0])
|
restart(MYKEY[0])
|
||||||
@ -90,15 +89,12 @@ async function handleCommand(input) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (const conn of conns)
|
for (const conn of conns)
|
||||||
if (input.startsWith("!") || input.startsWith(">")){
|
|
||||||
|
|
||||||
}else {
|
|
||||||
conn.write(`${USERNAME}: ${input}`)
|
conn.write(`${USERNAME}: ${input}`)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
console.log(`${USERNAME}: ${input}`)
|
console.log(`${USERNAME}: ${input}`)
|
||||||
clearCursor()
|
clearCursor()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
swarm.on('connection', conn => {
|
swarm.on('connection', conn => {
|
||||||
|
Loading…
Reference in New Issue
Block a user