adding cd
This commit is contained in:
parent
e279f57be0
commit
b8f039cb9e
163
sshChat.mjs
163
sshChat.mjs
@ -17,6 +17,7 @@ goodbye(() => swarm.destroy())
|
|||||||
// Keep track of all connections and USERNAMEs
|
// Keep track of all connections and USERNAMEs
|
||||||
const conns = []
|
const conns = []
|
||||||
const names = {}
|
const names = {}
|
||||||
|
let USERPWD = "/"
|
||||||
let DAPI_KEY = {}
|
let DAPI_KEY = {}
|
||||||
let USERNAME = "annon" + rand
|
let USERNAME = "annon" + rand
|
||||||
let LOGGEDIN = false
|
let LOGGEDIN = false
|
||||||
@ -35,45 +36,55 @@ async function getUSERNAME(key) {
|
|||||||
return requestUSERNAME.body.message.replace("Hello, ", "").replace("!", "")
|
return requestUSERNAME.body.message.replace("Hello, ", "").replace("!", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runCMD(key, cmd, pwd){
|
async function runCMD(key, cmd, pwd) {
|
||||||
let requestData = await unirest
|
let requestData = await unirest
|
||||||
.post('https://api.discord-linux.com/exec')
|
.post('https://api.discord-linux.com/exec')
|
||||||
.headers({'Accept': 'application/json', 'Content-Type': 'application/json',
|
.headers({
|
||||||
'x-discord-linux-auth': key})
|
'Accept': 'application/json', 'Content-Type': 'application/json',
|
||||||
.send({"cmd": cmd, "pwd": pwd})
|
'x-discord-linux-auth': key
|
||||||
|
})
|
||||||
|
.send({ "cmd": cmd, "pwd": pwd })
|
||||||
return requestData.body.stdout
|
return requestData.body.stdout
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startContainer(key){
|
async function startContainer(key) {
|
||||||
let startContainer = await unirest
|
let startContainer = await unirest
|
||||||
.get('https://api.discord-linux.com/start')
|
.get('https://api.discord-linux.com/start')
|
||||||
.headers({'Accept': 'application/json', 'Content-Type': 'application/json',
|
.headers({
|
||||||
'x-discord-linux-auth': key})
|
'Accept': 'application/json', 'Content-Type': 'application/json',
|
||||||
|
'x-discord-linux-auth': key
|
||||||
|
})
|
||||||
return startContainer.body.completed
|
return startContainer.body.completed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function stopContainer(key){
|
async function stopContainer(key) {
|
||||||
let stopContainer = await unirest
|
let stopContainer = await unirest
|
||||||
.get('https://api.discord-linux.com/stop')
|
.get('https://api.discord-linux.com/stop')
|
||||||
.headers({'Accept': 'application/json', 'Content-Type': 'application/json',
|
.headers({
|
||||||
'x-discord-linux-auth': key})
|
'Accept': 'application/json', 'Content-Type': 'application/json',
|
||||||
|
'x-discord-linux-auth': key
|
||||||
|
})
|
||||||
return stopContainer.body.completed
|
return stopContainer.body.completed
|
||||||
}
|
}
|
||||||
|
|
||||||
async function restartContainer(key){
|
async function restartContainer(key) {
|
||||||
let restartContainer = await unirest
|
let restartContainer = await unirest
|
||||||
.get('https://api.discord-linux.com/restart')
|
.get('https://api.discord-linux.com/restart')
|
||||||
.headers({'Accept': 'application/json', 'Content-Type': 'application/json',
|
.headers({
|
||||||
'x-discord-linux-auth': key})
|
'Accept': 'application/json', 'Content-Type': 'application/json',
|
||||||
|
'x-discord-linux-auth': key
|
||||||
|
})
|
||||||
return restartContainer.body.completed
|
return restartContainer.body.completed
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getStats(key){
|
async function getStats(key) {
|
||||||
let getStats = await unirest
|
let getStats = await unirest
|
||||||
.get('https://api.discord-linux.com/restart')
|
.get('https://api.discord-linux.com/restart')
|
||||||
.headers({'Accept': 'application/json', 'Content-Type': 'application/json',
|
.headers({
|
||||||
'x-discord-linux-auth': key})
|
'Accept': 'application/json', 'Content-Type': 'application/json',
|
||||||
|
'x-discord-linux-auth': key
|
||||||
|
})
|
||||||
console.log(getStats.body)
|
console.log(getStats.body)
|
||||||
return getStats.body.data
|
return getStats.body.data
|
||||||
}
|
}
|
||||||
@ -112,69 +123,83 @@ rl.on('line', input => {
|
|||||||
conn.write(`${USERNAME} has logged in!`)
|
conn.write(`${USERNAME} has logged in!`)
|
||||||
}
|
}
|
||||||
clearCursor()
|
clearCursor()
|
||||||
console.log(`Weclcome ${USERNAME} you are now logged in!`)
|
console.log(`Welcome ${USERNAME} you are now logged in!`)
|
||||||
return LOGGEDIN = true
|
return LOGGEDIN = true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const changeDir = input.startsWith(">cd") || input.startsWith("> cd")
|
||||||
|
if (changeDir) {
|
||||||
|
const commandArgs = input.replace("> cd ", "").replace(">cd", "").replace(" ", "")
|
||||||
|
if (commandArgs.startsWith("/")) {
|
||||||
|
USERPWD = commandArgs;
|
||||||
|
console.log("Directory Changed to: " + USERPWD)
|
||||||
|
} else {
|
||||||
|
USERPWD = USERPWD + "/" + commandArgs;
|
||||||
|
console.log("Directory Changed to: " + USERPWD)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const execute = input.startsWith(">")
|
const execute = input.startsWith(">")
|
||||||
if (execute) {
|
if (execute) {
|
||||||
let inputdata = input.split(2)
|
let inputdata = input.split(2)
|
||||||
const cmdToRun = inputdata.join(" ").replace("> ", "").replace(">","")
|
const cmdToRun = inputdata.join(" ").replace("> ", "").replace(">", "")
|
||||||
|
if (cmdToRun.includes("cd")) return
|
||||||
runCMD(DAPI_KEY.key, cmdToRun, "/").then((data) => {
|
runCMD(DAPI_KEY.key, cmdToRun, "/").then((data) => {
|
||||||
console.log(data)
|
console.log(data)
|
||||||
for (const conn of conns) {
|
for (const conn of conns) {
|
||||||
conn.write(`${USERNAME} ran ${cmdToRun}: \n` + data)
|
conn.write(`${USERNAME} ran ${cmdToRun}: \n` + data)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const start = input.match(/^\/start (\S+)$/)
|
||||||
|
if (start) {
|
||||||
|
const cmdToRun = start[1]
|
||||||
|
startContainer(DAPI_KEY.key).then((data) => {
|
||||||
|
for (const conn of conns) {
|
||||||
|
console.log(data)
|
||||||
|
conn.write(`${USERNAME} ran start: \n` + data)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const start = input.match(/^\/start (\S+)$/)
|
const stop = input.match(/^\/stop (\S+)$/)
|
||||||
if (start) {
|
if (stop) {
|
||||||
const cmdToRun = start[1]
|
const cmdToRun = stop[1]
|
||||||
startContainer(DAPI_KEY.key).then((data) => {
|
stopContainer(DAPI_KEY.key).then((data) => {
|
||||||
for (const conn of conns) {
|
for (const conn of conns) {
|
||||||
console.log(data)
|
console.log(data)
|
||||||
conn.write(`${USERNAME} ran start: \n` + data)
|
conn.write(`${USERNAME} ran stop: \n` + data)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const restart = input.match(/^\/restart (\S+)$/)
|
||||||
|
if (restart) {
|
||||||
|
const restart = restart[1]
|
||||||
|
restartContainer(DAPI_KEY.key).then((data) => {
|
||||||
|
for (const conn of conns) {
|
||||||
|
console.log(data)
|
||||||
|
conn.write(`${USERNAME} ran restart: \n` + data)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const stop = input.match(/^\/stop (\S+)$/)
|
const stats = input.match(/^\/stats (\S+)$/)
|
||||||
if (stop) {
|
if (stats) {
|
||||||
const cmdToRun = stop[1]
|
const stats = stats[1]
|
||||||
stopContainer(DAPI_KEY.key).then((data) => {
|
getStats(DAPI_KEY.key).then((data) => {
|
||||||
for (const conn of conns) {
|
for (const conn of conns) {
|
||||||
console.log(data)
|
console.log(data)
|
||||||
conn.write(`${USERNAME} ran stop: \n` + data)
|
conn.write(`${USERNAME} ran stats: \n` + data)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const restart = input.match(/^\/restart (\S+)$/)
|
|
||||||
if (restart) {
|
|
||||||
const restart = restart[1]
|
|
||||||
restartContainer(DAPI_KEY.key).then((data) => {
|
|
||||||
for (const conn of conns) {
|
|
||||||
console.log(data)
|
|
||||||
conn.write(`${USERNAME} ran restart: \n` + data)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const stats = input.match(/^\/stats (\S+)$/)
|
|
||||||
if (stats) {
|
|
||||||
const stats = stats[1]
|
|
||||||
getStats(DAPI_KEY.key).then((data) => {
|
|
||||||
for (const conn of conns) {
|
|
||||||
console.log(data)
|
|
||||||
conn.write(`${USERNAME} ran stats: \n` + data)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
else {
|
||||||
// if (!LOGGEDIN) return console.log("Please login using /login [API KEY]")
|
// if (!LOGGEDIN) return console.log("Please login using /login [API KEY]")
|
||||||
|
Loading…
Reference in New Issue
Block a user