1.0.9 • Published 3 years ago

nodemanager-server v1.0.9

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

NodeManager Server

NodeManager is an application which allows you to control your computer using a web-server.

https://nodemanager.tk/

Creating an example instance powered by ExpressJS

const express = require("express");
const app = express();
const nodemanager_server = require("nodemanager-server");
let server = null;

async function connect(n) {
    if (server === null || server === undefined) {
        if (n !== null && n !== undefined) {
            if ((n.id !== null && n.id !== undefined) && (n.key !== null && n.key !== undefined)) {
                server = new nodemanager_server({ key: n.key !== null && n.key !== undefined ? n.key : "" })
                server.onOpen = async () => {
                    console.log("Connected to PC");
                    server.sendCommand(`main`, `cmd`, `echo Hello World!`);
                };
                server.onClose = (exitCode) => {
                    console.log(`Connection to the PC has been closed`);
                };
                server.onHeartbeat = () => {
                    console.log("Heartbeat");
                };
                server.connect();
            }
        }
    }
}

app.post("/create", async (req, res, next) => {
    res.setHeader("Content-Type", "application/json");
    try {
        const body = req.body;
        if ((body !== null && body !== undefined)) {
            if ((body.node !== null && body.node !== undefined)) {
                if ((body.node.id !== null && body.node.id !== undefined) && (body.node.key !== null && body.node.key !== undefined)) {
                    try {
                        if (server === null || server === undefined) {
                            await connect(body.node);
                            return res.status(204).end();
                        } else {
                            return res.status(400).end(JSON.stringify({ "success": false, "errors": ["node already connected"] }));
                        }
                    } catch (e) {
                        console.log(e);
                        return res.status(400).end(JSON.stringify({ "success": false, "errors": ["an error has occured"] }));
                    }
                } else {
                    return res.status(400).end(JSON.stringify({ "success": false, "errors": ["no id or key found"] }));
                }
            } else {
                return res.status(400).end(JSON.stringify({ "success": false, "errors": ["no node found"] }));
            }
        } else {
            return res.status(400).end(JSON.stringify({ "success": false, "errors": ["no body found"] }));
        }
    } catch (e) {
        return res.status(400).end(JSON.stringify({ "success": false, "errors": ["an error has occured"] }));
    }
});

Options

key: The key given by nodemanager

removePromptWatermark: Removes the watermark and copyrights from the prompts

Methods of an instance

connect()

Makes a connection to the computer

const nodemanager_server = require("nodemanager-server");

const server = new nodemanager_server({
    key: "Key from example"
});

server.connect();

sendCommand(prompt_id, prompt_type, cmd)

Sends a command to the computer.

This method takes 3 arguments,

prompt_id: An ID which will be used to get the output of a command

prompt_type: Console to run the command, either cmd or powershell

cmd: The command to run

const nodemanager_server = require("nodemanager-server");

const server = new nodemanager_server({
    key: "Key from example"
});

server.sendCommand("main" , "cmd" , "echo Hello World!")

getOutputs()

Get the outputs of all prompts (commands ran), in a JSON format

const nodemanager_server = require("nodemanager-server");

const server = new nodemanager_server({
    key: "Key from example"
});

console.log(server.getOutputs());

getOutput(prompt_id)

Gets the output of the given prompt id (command ran), in a JSON format

This method takes 1 argument,

prompt_id: The ID of the prompt

const nodemanager_server = require("nodemanager-server");

const server = new nodemanager_server({
    key: "Key from example"
});

console.log(server.getOutput("main"));

restartClient()

Tells the node to restart it's self

const nodemanager_server = require("nodemanager-server");

const server = new nodemanager_server({
    key: "Key from example"
});

server.restartClient();

Utils

getIP()

Get's the node's IP

const nodemanager_server = require("nodemanager-server");

const server = new nodemanager_server({
    key: "Key from example"
});

server.onOpen = async () => {
    console.log(await server.getIP());
    // Any commands to run when the computer is connected
};

Events

onOpen()

Runs when the connection to the computer is open

const nodemanager_server = require("nodemanager-server");

const server = new nodemanager_server({
    key: "Key from example"
});

server.onOpen = async () => {
    console.log("Connected to PC");
    // Any commands to run when the computer is connected
};

onClose(exitCode)

Runs when the connection to the computer is closed

This event takes 1 argument,

exitCode: The code which identifies the reason the connection was closed

Exit codes:

0: Unknown reason

1: Computer disconnected, likely shutdown or manually disconnected

2: Heartbeat failed

3: Connection was forcefully temirnated

const nodemanager_server = require("nodemanager-server");

const server = new nodemanager_server({
    key: "Key from example"
});

server.onClose = (exitCode) => {
    console.log(`Connection to the PC has been closed`);
};

onHeartbeat()

Runs when a heartbeat is received by the computer

const nodemanager_server = require("nodemanager-server");

const server = new nodemanager_server({
    key: "Key from example"
});

server.onHeartbeat = () => {
    console.log("Heartbeat");
};
1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago