UNPKG

@parallaxcontrol/node-red-control

Version:

A comprehensive package of Node-RED nodes designed to seamlessly integrate with the Parallax Control Engine, offering enhanced control capabilities for AV Automation.

167 lines (153 loc) 7.07 kB
const { exec } = require('child_process'); module.exports = function(RED) { function SystemManagementNode(config) { RED.nodes.createNode(this, config); var node = this; this.selection = config.makeSelection; node.on('input', function(msg) { let command; if(typeof msg.payload.Value === 'boolean'){ if(msg.payload.Value){ switch(node.selection) { case "Run System Update": { node.status({ fill: "blue", shape: "dot", text:"Running System Update, Do Not Turn Off!"}); command=". /var/www/html/commands/updateLinuxServer.sh"; break; } case "Clear All Node-RED Flows": { node.status({ fill: "blue", shape: "dot", text: "Clearing ALl Node Red Flows!" }); command=". /var/www/html/commands/clearNodeRedFlows.sh"; break; } case "Restart Processor": { node.status({ fill: "blue", shape: "dot", text: "Restarting Processor!" }); command="python /var/www/html/commands/reboot.py"; break; } case "Restart Node-RED Server": { node.status({ fill: "blue", shape: "dot", text: "Restarting Node-RED Server!" }); command=". /var/www/html/commands/restartNodeRed.sh"; break; } case "Show Or Hide SSID": { node.status({ fill: "blue", shape: "dot", text: "Toggling Show/Hide SSID..." }); command=". /var/www/html/commands/displaySSID.sh"; break; } case "Clear Uploads Folder": { node.status({ fill: "blue", shape: "dot", text: "Clearing Uploads Folder..." }); command="python /var/www/html/commands/clearUploads.py"; break; } case "Get System Temp": { node.status({ fill: "blue", shape: "dot", text: "Getting System Temp..." }); command=". /var/www/html/commands/cpuTemp.sh"; break; } case "Get Board Model": { node.status({ fill: "blue", shape: "dot", text: "Getting Board Model..." }); command="python /var/www/html/commands/boardModel.py"; break; } case "Get Board Model": { node.status({ fill: "blue", shape: "dot", text: "Getting Board Model..." }); command="python /var/www/html/commands/boardModel.py"; break; } case "Get IP State": { node.status({ fill: "blue", shape: "dot", text: "Getting IP State..." }); command="python /var/www/html/commands/getIpState.py"; break; } case "Get IP State": { node.status({ fill: "blue", shape: "dot", text: "Getting IP State..." }); command="python /var/www/html/commands/getIpState.py"; break; } case "Get Mac Address": { node.status({ fill: "blue", shape: "dot", text: "Getting Mac Address..." }); command="python /var/www/html/commands/getMacAddress.py"; break; } case "Get Hostname": { node.status({ fill: "blue", shape: "dot", text: "Getting Hostname..." }); command="python /var/www/html/commands/hostname.py"; break; } case "Get OS Version": { node.status({ fill: "blue", shape: "dot", text: "Getting OS Version..." }); command=". /var/www/html/commands/osVersion.sh"; break; } case "Get Serial Number": { node.status({ fill: "blue", shape: "dot", text: "Getting Serial Number..." }); command="python /var/www/html/commands/serialNumber.py"; break; } case "Get IP Address": { node.status({ fill: "blue", shape: "dot", text: "Getting IP Address..." }); command="python /var/www/html/commands/showIpAddress.py"; break; } case "Get System Uptime": { node.status({ fill: "blue", shape: "dot", text: "Getting System Uptime..." }); command="python /var/www/html/commands/uptime.py"; break; } } } } else{ node.warn("Warning in Node: " + node.id + ", check node status for more information."); node.status({ fill: "red", shape: "ring", text:"Error: Expected type of Boolean value."}); return [[null]]; } // Execute the command if it's set if(command) { exec(command, (error, stdout, stderr) => { if (error) { node.error(`Error: ${stderr}`, msg); msg.payload = `Error: ${stderr}`; node.send(msg); node.warn(msg); return; } // Update status to show completion //node.status({fill:"green", shape:"dot", text:"done"}); // Set the output to the stdout of the command msg.payload = stdout; node.send(msg); // Send the msg object for the next node }); // Set the status to show it's running //node.status({fill:"yellow", shape:"ring", text:"running..."}); } else { // Handle invalid input node.warn("Warning in Node: " + node.id + ", check node status for more information."); node.status({ fill: "red", shape: "ring", text:"Error: No command set for the given selection."}); return [[null]]; //node.error("No command set for the given selection.", msg); //msg.payload = "Error: No command set for the given selection."; //node.send(msg); } }); } RED.nodes.registerType("system-management", SystemManagementNode); }