ryanblenis / meshcentral-scripttask Goto Github PK
View Code? Open in Web Editor NEWScripting plugin for MeshCentral
License: Apache License 2.0
Scripting plugin for MeshCentral
License: Apache License 2.0
Hi
I have tried to uninstall the plugin, when from the action when I click delete, and confirm the prompt to delete. The server disconnects. When I log back in the plugin is still shown.
I was trying to remove and install again to start afresh
Is it possible (if it is we could just update the doc), as I manage computers that are not always connected, to create a task for an agent (or a group) that get launched on this agent as soon as it connects to meshcentral?
Otherwise I'd need to schedule that task for every minute, that would work anyway, but there would be a slightly larger timeframe between the computer connecting to meshcentral and the script running, which is not optimal in my case.
Thanks in advance
Love the work
Where would I start to look if I wanted to add say VBS to the languages that can be used
Yes, I know that VBS is really only useful on Windows machines...
I have a large number of VBS scripts, and the concept of not loading them onto client machines, but instead running from my server is rather appealing
Hi i got 130 machines under meshcentral, since i moved to mongodb i got some strange memory leaks. It just takes whole ram and then crashes... restart ( every 2-3 minutes ):
Error i got:
terminate called after throwing an instance of 'std::bad_alloc'
Oct 12 09:51:04 poczta node[2773]: what(): std::bad_alloc
Oct 12 09:51:04 poczta node[2773]: at ChildProcess.exithandler (child_process.js:383:12)
Oct 12 09:51:04 poczta node[2773]: at ChildProcess.emit (events.js:412:35)
Oct 12 09:51:04 poczta node[2773]: at maybeClose (internal/child_process.js:1058:16)
Oct 12 09:51:04 poczta node[2773]: at Process.ChildProcess._handle.onexit (internal/child_process.js:293:5) {
Oct 12 09:51:04 poczta node[2773]: killed: false,
Oct 12 09:51:04 poczta node[2773]: code: null,
Oct 12 09:51:04 poczta node[2773]: signal: 'SIGABRT',
Oct 12 09:51:04 poczta node[2773]: cmd: '/usr/bin/node /home/REDACTED*/latest/node_modules/meshcentral/meshcentral --launch 2773'
I removed all db files under meshcentral-data and this didnt help at all.... ( i got 5 scripts there so not too much )
Any idea how to approach this kind of issue...??
Hello.
So i added a ps1 script and scheduled it. And got PSSecurityException.
Seems like i need to set ExecutionPolicy on every machine that i would like to run scripts on.
ScriptTask could just do something like this:
powershell.exe -executionpolicy bypass -file .\script.ps1
Please see the image https://i.imgur.com/ShOizFd.png
The Event Viewer plugin is clickable and works, however the ScriptTask does not appear to be a working link. Tested in multiple browsers, does not appear to be a browser issue. No errors in the server log.
Thanks.
Hi
Thanks for this plug-in, as this could help me in a unique requirement where I need to run a script on a machine, and just been trying to test with it.
I have uploaded a ps1 script. when I click run, it keeps running and copying the file locally, but the script never finishes.
How can I stop the task from the UI.
Hello, currently doing some testing with this plugin for MeshCentral so I can automate some tasks. From what I'm reading is any variable I have defined in the script I also need to define in the variables section. My question is, what is the difference between global variable and script variable?
And aside from that, all of my scripts either have similar or the same variables, will I need to ensure every single variable is defined in the plugin, some of the scripts rely on anywhere from 10-30 variables for a single script.
For example I have a variable called $start_time = Get-Time , will that need to be defined in the plugin variables? And if so, do I include the $ or just use start_time and then value is Get-Date ?
Hey there,
Is moving scripts between foldres supported? I can see references to dropMove in the code but when I try, the drag behaviour detects mouse over of another folder and shows the little arrow, but doesn't seem to move it. I've tried in Chrome & Firefox but doesn't seem to work. Am I doing something wrong? :)
Thanks!
While trying to install the plugin (any plugin) in meshcentral running in Docker (Dockerfile from MC repo), I got the following:
Error instantiating new plugin: Error: Cannot find module 'mongodb'
Require stack:
- /opt/meshcentral/meshcentral-data/plugins/scripttask/db.js
- /opt/meshcentral/meshcentral-data/plugins/scripttask/scripttask.js
- /opt/meshcentral/meshcentral/pluginHandler.js
- /opt/meshcentral/meshcentral/meshcentral.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
at Function.Module._load (node:internal/modules/cjs/loader:804:27)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.module.exports.CreateDB (/opt/meshcentral/meshcentral-data/plugins/scripttask/db.js:254:7)
at Object.obj.server_startup (/opt/meshcentral/meshcentral-data/plugins/scripttask/scripttask.js:38:85)
at Timeout._onTimeout (/opt/meshcentral/meshcentral/pluginHandler.js:427:146)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/opt/meshcentral/meshcentral-data/plugins/scripttask/db.js',
'/opt/meshcentral/meshcentral-data/plugins/scripttask/scripttask.js',
'/opt/meshcentral/meshcentral/pluginHandler.js',
'/opt/meshcentral/meshcentral/meshcentral.js'
]
}
I resolved it by copying
/opt/meshcentral/meshcentral/node_modules
to /opt/meshcentral/meshcentral-data/plugins/
Of course this is not a permanent solution, and I'd like to ask if it's possible to update plugins, to resolve node_modules from the original path.
Or is this something that meshcentral has to fix?
Hey,
is there a way to implement a "Run as" Option.
Currently everything script Run as System. But i have to send the User some Notifications or open Programs. The System User can not do that.
This would be as Option like the meshcentral agent operation. Send command as Agent or Current logged in User.
P.s. sorry for my bad sentences or English... that is not my native language
Hi Ryan. As always, thanks for a great product. I did find what I believe is an small issue on Linux. If a script finishes with sudo reboot
, the machine reboots, but the script then seems to run again and cause a reboot loop. I assume this is maybe because the machine reboots before the script can be cleared from cache or something? Is there a way around this?
I was able to install the plugin but when I go to the plugins tab for the remote machine I get the following error:
TypeError: Cannot read property 'getScriptTree' of null at Object.obj.handleAdminReq (/home/ec2-user/meshcentral-data/plugins/scripttask/scripttask.js:224:20) at Object.obj.handleAdminReq (/home/ec2-user/node_modules/meshcentral/pluginHandler.js:522:40) at obj.handlePluginAdminReq (/home/ec2-user/node_modules/meshcentral/webserver.js:5376:34) at Layer.handle [as handle_request] (/home/ec2-user/node_modules/express/lib/router/layer.js:95:5) at next (/home/ec2-user/node_modules/express/lib/router/route.js:137:13) at Route.dispatch (/home/ec2-user/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/home/ec2-user/node_modules/express/lib/router/layer.js:95:5) at /home/ec2-user/node_modules/express/lib/router/index.js:281:22 at Function.process_params (/home/ec2-user/node_modules/express/lib/router/index.js:335:12) at next (/home/ec2-user/node_modules/express/lib/router/index.js:275:10) at /home/ec2-user/node_modules/meshcentral/webserver.js:5622:20 at Layer.handle [as handle_request] (/home/ec2-user/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/home/ec2-user/node_modules/express/lib/router/index.js:317:13) at /home/ec2-user/node_modules/express/lib/router/index.js:284:7 at Function.process_params (/home/ec2-user/node_modules/express/lib/router/index.js:335:12) at next (/home/ec2-user/node_modules/express/lib/router/index.js:275:10)
Any ideas why that is?
(Running on Amazon Linux)
The fix linked in my original ticket (#19) did not resolve this issue for me. I'm still unable to install any plug-ins, receiving the "value not defined" error.
Any and all hints would be appreciated.
Server version 0.9.28
Download console text
versions
{
"http_parser": "2.9.3",
"node": "10.19.0",
"v8": "6.8.275.32-node.55",
"uv": "1.34.2",
"zlib": "1.2.11",
"brotli": "1.0.7",
"ares": "1.15.0",
"modules": "64",
"nghttp2": "1.40.0",
"napi": "5",
"openssl": "1.1.1d",
"icu": "66.1",
"unicode": "13.0",
"cldr": "36.1",
"tz": "2021a"
}
Originally posted by @mikecole79 in #19 (comment)
Hello,
Thanks for this. Scripting is a must have feature and you just make it work on MeshCentral.
I had some agents with Windows 7 x64 going offline when activating this. On affected agents, console shows:
uncaughtException1: Error: Error in Finalizer: [Invalid C function means you forgot to return 0] => EventEmitter.emit(): Event dispatch for '~' on 'win-message-pump' threw an exception: EventEmitter.on(): Event 'exit' not found in method '()'
Its a bug?
Hi,
Non scheduled tasks work fine and node history displays all expected information. But when it comes to scheduled tasks I can't get it to work.
Procedure:
'Script Schedules' list remains empty, same for Node Schedules and the tasks never run.
Anything I am doing wrong?
Thanks,
Christophe
Hi @ryanblenis I already asked this question in the main mesh cental GitHub but it seems like the script is not supported and was wondering if you could share any info related to my request.
A little background - I have already installed the plugin "Scriptask" and I usually run a Hyper-V reset PowerShell script once my client guest link has expired. However, I do this manually, and I have to do it on a weekly basis, which is becoming tedious as we have different clients. Is it possible to trigger a specific PowerShell script automatically when a guest link expires? For example, suppose I share "device1" for 24 hours, and once the link expires, it triggers the script from the "Scripttask" plugin on that device.
Thanks
Hey there,
I've been ramping up my use of ScriptTask for scheduling scripts across a reasonable number of agents, and had noticed mongod CPU usage burst to 100% very regularly.
Monitoring CPU usage of the server, disabling ScriptTask results in this drop in CPU:
I do have > 120k rows in the plugin_scripttask collection:
rs:PRIMARY> db.getCollection("plugin_scripttask").find({}).count()
122373
From looking at the code, I can see some spinning over the data each minute (updateFrontEnd, historyData). I haven't looked too hard to see how it can be solved, but I thought I'd log this as a heads up for others and if I find any improvements, I'll report back.
Thanks!
Anyone else having issues on 1.1.6? I can install the plugin, but when I go to the tab, I get an internal server error. It appears to install without raising any errors, but beyond that, not function.
Hi,
Many thanks for this excellent plugin.
I am facing an issue when the number of scripts exceeds 30+. The displayed list of scripts cannot be scrolled and no vertical scroll bar is displayed either.
I tried keyboard up and down arrow without success. Could a vertical scroll bar be added ?
Current workaround : create sub-folders to organize your scripts
Feature request :
It would be nice to be able filter the scripts on part of their name
Again thank you for this excellent plugin
Hello!
How can run script .ps1 or .bat with User Shell or User PowerShell.
I want to restrict this plugin to a specifci group, is this smh possible?
MeshCentral version: 0.9.7
OS Running: Ubuntu 18.04
Recent change: Did upgrade from 0.4.5 to 0.9.7
MechCentral runs without errors.
Issue: Cannot uninstall or install plugins. Its restart the service (first disconnects meshcentral and then starts again but plugins remains.)
Recent, error log:
/home//node_modules/meshcentral/db.js:1489
obj.getPlugin = function (id, func) { id = require('mongodb').ObjectID(id); obj.pluginsfile.find({ _id: id }).sort({ name: 1 }).toArray(func); }; // Get plugin
^
TypeError: require(...).ObjectID is not a function
at Object.obj.getPlugin (/home//node_modules/meshcentral/db.js:1489:79)
at Object.obj.installPlugin (/home//node_modules/meshcentral/pluginHandler.js:356:19)
at WebSocket.processWebSocketData (/home//node_modules/meshcentral/meshuser.js:4833:45)
at WebSocket.emit (events.js:400:28)
at Receiver.receiverOnMessage (/home//node_modules/ws/lib/websocket.js:720:20)
at Receiver.emit (events.js:400:28)
at Receiver.dataMessage (/home//node_modules/ws/lib/receiver.js:414:14)
at Receiver.getData (/home//node_modules/ws/lib/receiver.js:346:17)
at Receiver.startLoop (/home//node_modules/ws/lib/receiver.js:133:22)
at Receiver._write (/home//node_modules/ws/lib/receiver.js:69:10)
In the latest mesh central version. The Plugins not working its causes server disconnection during installation
Hi,
found out that after v0.9.19 you can no longer use it or even enable/disable/remove.
had to remove it the hard way through mongodb commands and physically removing the folder.
after removing the plugin, i was shocked when i discovered that not only it wasn't working but it was blocking some enhancement done over the meshcentral updates, so now i start seeing those fixes working in meshcentral.
one of those was, don't show empty groups in the (my devices tab) until they have clients joined, but of course it's showing in the groups tab.. with this plugin installed it used to show them all (empty & non empty groups) under (my devices tab). well i have 50 empty groups but i need to keep them for clients connected when needed and different settings and notes for each group. it's neater to have them hidden from (my devices tab) page until they get clients. scripttask was affecting this feature so that page was a mess.
i think guys you need to review the whole code of this plugin as 100% it's not in working order anymore and affecting other features. it's been a long time since it was reviewed or updated.
Thanks heaps for your hard work.
Would be nice if a node's tag where available from the script in some fashion. Like the #TAGS# or something similar.
It should be interesting to have option to use scripts already uploaded in personal folder (My files)
Ryan,
Does this work with the latest version of meshcentral?
Great plugin along with your other plugin RoutePlus.
When trying to load both of them at the same time the display for one overrides the other one depending on the order they were enabled.
EG. Loading the route plus plugin first will have its display override the Script task display. Loading the script task plugin first will have the script display override the route plus display.
Is there a way to prevent this from happening? I understand plugins are a pretty new thing in meshcentral2
thanks.
I have just setup a user account that can only view the Desktop because I don't trust them. However, the Plugins tab appears on their device view and it seems to allow them to upload and execute scripts. Is there a way to disable the plugin for this user?
Hi, thanks for the great plugin.
By any chance are you able to add a scroll bar so we can scroll down to see all the list of scripts we add. currently we can't view all the scripts we add as there is no scroll down option.
Thanks
Hi,
The meshcentral server is running in an orchestration environment with the meshcentral-data folder as persistent volume (1.1.20). The installation of the latest 'script task' module (0.0.19) seems to go well, but when I tried to use it, I had this problem from the mesh node client:
TypeError: Cannot read properties of null (reading 'getScriptTree')
at obj.handleAdminReq (/opt/meshcentral/meshcentral-data/plugins/scripttask/scripttask.js:224:20)
at obj.handleAdminReq (/opt/meshcentral/meshcentral/pluginHandler.js:521:40)
at obj.handlePluginAdminReq (/opt/meshcentral/meshcentral/webserver.js:5993:34)
at Layer.handle [as handle_request] (/opt/meshcentral/meshcentral/node_modules/express/lib/router/layer.js:95:5)
at next (/opt/meshcentral/meshcentral/node_modules/express/lib/router/route.js:144:13)
at Route.dispatch (/opt/meshcentral/meshcentral/node_modules/express/lib/router/route.js:114:3)
at Layer.handle [as handle_request] (/opt/meshcentral/meshcentral/node_modules/express/lib/router/layer.js:95:5)
at /opt/meshcentral/meshcentral/node_modules/express/lib/router/index.js:284:15
at Function.process_params (/opt/meshcentral/meshcentral/node_modules/express/lib/router/index.js:346:12)
at next (/opt/meshcentral/meshcentral/node_modules/express/lib/router/index.js:280:10)
Did anyone get this issue before?
Hi @ryanblenis,
Sorry for the dumb question but what are the chances of being able to pull data from meschentral into scripts?
Say you have a script that generates and emails HTML reports per computer.
Each group has a different user to email the reports to and a different mail server credentials to use.
Without being able to query meshagent for the group name, group admin user email address, is it possible to have a json or csv file somewhere that can be used in the script without exposing it to the internet or end user? Maybe under My Files / Root / Group Name?
I thought of using script to write windows registry entry but that limits usability to Windows devices.
Then thought of possibly generating local config file on each machine, but, that would potentially introduce security issues even if the file was encrypted. Using local DB would increase the complexity of the script.
Would be great to be able to target what nodes will run the script based on tags.
As this will provide more flexiblilty with granularity.
Scenario,
I have 3 diffrent scripts, and x amount of workstations.
wokrstation a should have script 1 and 3
wokrstation b should have script 2 and 3
wokrstation c should have script 1 and 3 and 2
Yes, this can be done manually, but having some mechanism for bulk assignment of this would be prefered, as a node cannot be a member of multiple groups at the same time. And creating groups for all the feasible combinations would also be very messy
Hi Ryan,
Any chance you are able to incorporate Python execution into the mix on the plugin? I ask because I have a large library of python code that usually I install to the machines manually, but would love to be able to use your plugin to execute the python code directly via input or upload of the python script file.
Any chance you could do this for me?
Thanks,
SomeGuru
Some random code like stuff I was thinking on, but couldn't implement. I also wrote for Ubuntu, but need it universal for all OSes like Windows, Apple, Linux (distros RHEL, Debian, etc).
import os
import subprocess
def executePythonScript(mesh, params):
# Check if Python is installed on the agent system
pythonCheck = subprocess.run(["python", "--version"], stdout=subprocess.PIPE)
if pythonCheck.returncode != 0:
# Python is not installed on the agent system, so we will install it
print("Python is not installed on the agent system. Installing...")
subprocess.run(["apt-get", "install", "-y", "python3"])
# Check if the required Python dependencies are present
# Replace "dependency1" and "dependency2" with the actual dependencies needed
dependencyCheck = subprocess.run(["pip3", "show", "dependency1"], stdout=subprocess.PIPE)
if dependencyCheck.returncode != 0:
# Dependency1 is not installed, so we will install it
print("Dependency1 is not installed. Installing...")
subprocess.run(["pip3", "install", "dependency1"])
dependencyCheck = subprocess.run(["pip3", "show", "dependency2"], stdout=subprocess.PIPE)
if dependencyCheck.returncode != 0:
# Dependency2 is not installed, so we will install it
print("Dependency2 is not installed. Installing...")
subprocess.run(["pip3", "install", "dependency2"])
# Check if a Python file or text input was provided
if "pythonFile" in params:
# A Python file was provided, so we will execute it
print("Executing Python file...")
subprocess.run(["python3", params["pythonFile"]])
else:
# No Python file was provided, so we will accept text input in a console window
print("Enter Python code to be executed:")
code = input()
print("Executing Python code...")
subprocess.run(["python3", "-c", code])
with a registration of the plugin via:
mesh.registerRpcMethod("executePythonScript", executePythonScript)
To use this plugin, the user can call the "executePythonScript" RPC method and pass in the parameters "pythonFile" (optional) and "text" (optional). If "pythonFile" is provided, the plugin will execute the specified Python file. If "text" is provided, the plugin will execute the provided Python code. If neither is provided, the plugin will accept text input in a console window.
Is it possible to create an option so that a script runs automatically as soon as the meshcentral agent is installed, then never again unless manually run?
The use case for this is to install anti-virus and other utilities when we install the agent.
If this is already a thing then apologies - I haven't seen it. Otherwise, great plugin, has made my life a LOT easier!!!
I'm not too sure this is actually a plug-in issue. I suspect there's some oddity of my configuration that isn't working quite right, but if anyone can give me a hint as to what that might be, it would be greatly appreciated.
Thanks!
Please see Ylianst/MeshCentral#5850
And console.txt
I discovered that a bunch of client devices had multiple Gigabytes worth of ps1 and txt files in the Mesh Agent folder on the C:\ drive going back a couple of years.
After posting to the MeshCentral issues page, we discovered that the most recent ps1 and txt files were from July 2023, which is around the time I stopped using this plugin because I switched to using Proactive Remediations in Microsoft Intune.
We figured out it had to be this plugin because it saves ps1 and txt files to, you guessed it, the Mesh Agent folder.
You probably should build in some garbage collection to prevent these files from filling up client disks.
It also might be a security issue leaving all these scripts in an easy to find location that users have access to.
The fix on my end was to stop using the plugin and purge the c:\Program Files\Mesh Agent\ folder of all the ps1 and txt files
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.