Compare commits

..

3 Commits

Author SHA1 Message Date
raven
744ab922d6 merge 2023-01-08 23:03:42 -05:00
raven
aa70725eaa update MD 2023-01-08 23:00:54 -05:00
raven
b8f039cb9e adding cd 2023-01-08 22:59:49 -05:00
2 changed files with 98 additions and 67 deletions

View File

@ -53,7 +53,13 @@ To connect to an altready made topic (room) pass the hash on start up:
/login [API KEY] - Login to the API
<<<<<<< HEAD
\> command here - Send a command to your container
\> cd /to/path - change working directory
=======
\>command here - Send a command to your container
>>>>>>> 1c32f1f2ca9f0e3c7ee8916ea10c7fd94a350054
/start - Start your container

View File

@ -17,6 +17,7 @@ goodbye(() => swarm.destroy())
// Keep track of all connections and USERNAMEs
const conns = []
const names = {}
let USERPWD = "/"
let DAPI_KEY = {}
let USERNAME = "annon" + rand
let LOGGEDIN = false
@ -35,45 +36,55 @@ async function getUSERNAME(key) {
return requestUSERNAME.body.message.replace("Hello, ", "").replace("!", "")
}
async function runCMD(key, cmd, pwd){
async function runCMD(key, cmd, pwd) {
let requestData = await unirest
.post('https://api.discord-linux.com/exec')
.headers({'Accept': 'application/json', 'Content-Type': 'application/json',
'x-discord-linux-auth': key})
.send({"cmd": cmd, "pwd": pwd})
.post('https://api.discord-linux.com/exec')
.headers({
'Accept': 'application/json', 'Content-Type': 'application/json',
'x-discord-linux-auth': key
})
.send({ "cmd": cmd, "pwd": pwd })
return requestData.body.stdout
}
async function startContainer(key){
async function startContainer(key) {
let startContainer = await unirest
.get('https://api.discord-linux.com/start')
.headers({'Accept': 'application/json', 'Content-Type': 'application/json',
'x-discord-linux-auth': key})
.get('https://api.discord-linux.com/start')
.headers({
'Accept': 'application/json', 'Content-Type': 'application/json',
'x-discord-linux-auth': key
})
return startContainer.body.completed
}
async function stopContainer(key){
async function stopContainer(key) {
let stopContainer = await unirest
.get('https://api.discord-linux.com/stop')
.headers({'Accept': 'application/json', 'Content-Type': 'application/json',
'x-discord-linux-auth': key})
.get('https://api.discord-linux.com/stop')
.headers({
'Accept': 'application/json', 'Content-Type': 'application/json',
'x-discord-linux-auth': key
})
return stopContainer.body.completed
}
async function restartContainer(key){
async function restartContainer(key) {
let restartContainer = await unirest
.get('https://api.discord-linux.com/restart')
.headers({'Accept': 'application/json', 'Content-Type': 'application/json',
'x-discord-linux-auth': key})
.get('https://api.discord-linux.com/restart')
.headers({
'Accept': 'application/json', 'Content-Type': 'application/json',
'x-discord-linux-auth': key
})
return restartContainer.body.completed
}
async function getStats(key){
async function getStats(key) {
let getStats = await unirest
.get('https://api.discord-linux.com/restart')
.headers({'Accept': 'application/json', 'Content-Type': 'application/json',
'x-discord-linux-auth': key})
.get('https://api.discord-linux.com/restart')
.headers({
'Accept': 'application/json', 'Content-Type': 'application/json',
'x-discord-linux-auth': key
})
console.log(getStats.body)
return getStats.body.data
}
@ -117,64 +128,78 @@ rl.on('line', input => {
});
}
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(">")
if (execute) {
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) => {
console.log(data)
for (const conn of conns) {
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+)$/)
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 stop = input.match(/^\/stop (\S+)$/)
if (stop) {
const cmdToRun = stop[1]
stopContainer(DAPI_KEY.key).then((data) => {
for (const conn of conns) {
console.log(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+)$/)
if (stop) {
const cmdToRun = stop[1]
stopContainer(DAPI_KEY.key).then((data) => {
for (const conn of conns) {
console.log(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 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)
}
})
}
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 {
// if (!LOGGEDIN) return console.log("Please login using /login [API KEY]")