Run your commands without the Internet
-
I'm not sure how useful this is given that Internet is usually available, but here's something I've experimented with.
It allows you to trigger commands you've created with your TRIGGERcmd agent from a separate computer on your network.
Run the server.js script with this command:
node.exe server.jsThen run your commands from another computer on your network with curl commands like this:
curl -v -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" http://(IP address):3000/api?trigger=Calculatorserver.js contents:
var cp = require('child_process'); const http = require('http'); const url = require('url'); const os = require('os'); const path = require('path'); const homeFolder = os.homedir(); const fileName = '.TRIGGERcmdData\\commands.json'; const filePath = path.join(homeFolder, fileName); const data = require(filePath); // Define your authentication credentials const username = 'admin'; const password = 'password'; // Function to handle HTTP requests const server = http.createServer((req, res) => { const parsedUrl = url.parse(req.url, true); // Check if the request is for the API endpoint if (parsedUrl.pathname === '/api' && req.method === 'GET') { // Check if authentication credentials are provided const auth = req.headers['authorization']; if (!auth || auth !== `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`) { res.statusCode = 401; res.setHeader('WWW-Authenticate', 'Basic realm="Restricted"'); res.end('Unauthorized'); return; } // Get the trigger from the query string const trigger = parsedUrl.query.trigger; // Find the corresponding value in the array of objects const result = data.find(obj => obj.trigger === trigger); // Check if the trigger exists, and if it does, run the command. if (result) { theCommand = result.command envVars = {'TCMD_CLIENT': 'local-network'} var ChildProcess = cp.exec(theCommand, {env: envVars}); res.setHeader('Content-Type', 'application/json'); res.end(JSON.stringify("Command ran.")); } else { res.statusCode = 404; res.end('trigger not found'); } } else { res.statusCode = 404; res.end('Not Found'); } }); // Start the server const PORT = process.env.PORT || 3000; server.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); });I used this site to generate that YWRtaW46cGFzc3dvcmQ= string for authentication. It's basically "admin:password" converted to base64.
https://www.debugbear.com/basic-auth-header-generator
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login