mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-11-22 22:17:31 +03:00
Updates agents and small server fixes.
This commit is contained in:
parent
9f5a0340fd
commit
23185ced93
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
2
agents/meshcmd.min.js
vendored
2
agents/meshcmd.min.js
vendored
File diff suppressed because one or more lines are too long
@ -430,7 +430,7 @@ function createMeshCore(agent) {
|
||||
//sendConsoleText(JSON.stringify(woptions));
|
||||
var tunnel = http.request(woptions);
|
||||
tunnel.upgrade = onTunnelUpgrade;
|
||||
tunnel.onerror = function (e) { sendConsoleText('ERROR: ' + JSON.stringify(e)); }
|
||||
tunnel.on('error', function (e) { sendConsoleText('ERROR: ' + JSON.stringify(e)); });
|
||||
tunnel.sessionid = data.sessionid;
|
||||
tunnel.rights = data.rights;
|
||||
tunnel.state = 0;
|
||||
@ -1407,7 +1407,7 @@ function createMeshCore(agent) {
|
||||
} catch (e) { response = 'Invalid HTTP websocket request'; }
|
||||
if (httprequest != null) {
|
||||
httprequest.upgrade = onWebSocketUpgrade;
|
||||
httprequest.onerror = function (e) { sendConsoleText('ERROR: ' + JSON.stringify(e)); }
|
||||
httprequest.on('error', function (e) { sendConsoleText('ERROR: ' + JSON.stringify(e)); });
|
||||
|
||||
var index = 1;
|
||||
while (consoleWebSockets[index]) { index++; }
|
||||
|
2
agents/meshcore.min.js
vendored
2
agents/meshcore.min.js
vendored
File diff suppressed because one or more lines are too long
@ -8,14 +8,14 @@
|
||||
# Description: <DESCRIPTION>
|
||||
### END INIT INFO
|
||||
|
||||
SCRIPT=/usr/local/mesh/meshagent
|
||||
SCRIPT=/usr/local/mesh_services/meshagent/meshagent
|
||||
RUNAS=root
|
||||
|
||||
PIDFILE=/var/run/meshagent.pid
|
||||
LOGFILE=/var/log/meshagent.log
|
||||
|
||||
start() {
|
||||
if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE"); then
|
||||
if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE") 2>/dev/null; then
|
||||
echo 'Service already running' >&2
|
||||
return 1
|
||||
fi
|
||||
@ -26,53 +26,62 @@ start() {
|
||||
}
|
||||
|
||||
stop() {
|
||||
if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
|
||||
if [ ! -f "$PIDFILE" ]; then
|
||||
echo 'Service not running' >&2
|
||||
return 1
|
||||
fi
|
||||
echo 'Stopping service…' >&2
|
||||
kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
|
||||
echo 'Service stopped' >&2
|
||||
}
|
||||
|
||||
uninstall() {
|
||||
echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
|
||||
local SURE
|
||||
read SURE
|
||||
if [ "$SURE" = "yes" ]; then
|
||||
stop
|
||||
rm -f "$PIDFILE"
|
||||
echo "Notice: log file will not be removed: '$LOGFILE'" >&2
|
||||
update-rc.d -f <NAME> remove
|
||||
rm -fv "$0"
|
||||
else
|
||||
pid=$( cat "$PIDFILE" )
|
||||
if kill -0 $pid 2>/dev/null; then
|
||||
echo 'Stopping service…' >&2
|
||||
kill -16 $pid
|
||||
echo 'Service stopped' >&2
|
||||
else
|
||||
echo 'Service not running'
|
||||
fi
|
||||
rm -f $"PIDFILE"
|
||||
fi
|
||||
}
|
||||
|
||||
forceuninstall() {
|
||||
stop
|
||||
rm -f "$PIDFILE"
|
||||
rm -f "$LOGFILE"
|
||||
update-rc.d -f <NAME> remove
|
||||
rm -fv "$0"
|
||||
restart(){
|
||||
stop
|
||||
start
|
||||
}
|
||||
status(){
|
||||
if [ -f "$PIDFILE" ]
|
||||
then
|
||||
pid=$( cat "$PIDFILE" )
|
||||
if kill -0 $pid 2>/dev/null; then
|
||||
echo "meshagent start/running, process $pid"
|
||||
else
|
||||
echo 'meshagent stop/waiting'
|
||||
fi
|
||||
else
|
||||
echo 'meshagent stop/waiting'
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
uninstall)
|
||||
uninstall
|
||||
;;
|
||||
forceuninstall)
|
||||
uninstall
|
||||
;;
|
||||
restart)
|
||||
stop
|
||||
start
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|uninstall}"
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
restart)
|
||||
stop
|
||||
start
|
||||
;;
|
||||
status)
|
||||
status
|
||||
;;
|
||||
*)
|
||||
echo "Usage: service meshagent {start|stop|restart|status}"
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -3,18 +3,12 @@
|
||||
CheckStartupType() {
|
||||
# echo "Checking process autostart system..."
|
||||
starttype=`ps -p 1 | awk '/1/ {print $4}'`
|
||||
if [[ $starttype == 'systemd' ]]; then return 1; # systemd;
|
||||
elif [[ $starttype == 'init' ]]; then return 3; # sysv-init;
|
||||
elif [[ `/sbin/init --version` =~ upstart ]]; then return 2; # upstart;
|
||||
fi
|
||||
return 0;
|
||||
}
|
||||
|
||||
CheckStartupTypeOld() {
|
||||
# echo "Checking process autostart system..."
|
||||
if [[ `systemctl` =~ -\.mount ]]; then return 1; # systemd;
|
||||
elif [[ `/sbin/init --version` =~ upstart ]]; then return 2; # upstart;
|
||||
elif [[ -f /etc/init.d/cron && ! -h /etc/init.d/cron ]]; then return 3; # sysv-init;
|
||||
if [[ $starttype == 'systemd' ]]; then return 1; # systemd;
|
||||
elif [[ $starttype == 'init' ]];
|
||||
then
|
||||
if [[ `/sbin/init --version` =~ upstart ]]; then return 2; # upstart
|
||||
return 3; # sysv-init
|
||||
fi
|
||||
fi
|
||||
return 0;
|
||||
}
|
||||
@ -95,13 +89,13 @@ DownloadAgent() {
|
||||
mkdir -p /usr/local/mesh
|
||||
cd /usr/local/mesh
|
||||
echo "Downloading Mesh agent #$machineid..."
|
||||
wget $url/meshagents?id=$machineid --no-check-certificate {{{noproxy}}}-O /usr/local/mesh/meshagent
|
||||
wget $url/meshagents?id=$machineid --no-check-certificate -O /usr/local/mesh/meshagent
|
||||
|
||||
# If it did not work, try again using http
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
url=${url/"https://"/"http://"}
|
||||
wget $url/meshagents?id=$machineid {{{noproxy}}}-O /usr/local/mesh/meshagent
|
||||
wget $url/meshagents?id=$machineid -O /usr/local/mesh/meshagent
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]
|
||||
@ -109,12 +103,12 @@ DownloadAgent() {
|
||||
echo "Mesh agent downloaded."
|
||||
# TODO: We could check the meshagent sha256 hash, but best to authenticate the server.
|
||||
chmod 755 /usr/local/mesh/meshagent
|
||||
wget $url/meshsettings?id=$meshid --no-check-certificate {{{noproxy}}}-O /usr/local/mesh/meshagent.msh
|
||||
wget $url/meshsettings?id=$meshid --no-check-certificate -O /usr/local/mesh/meshagent.msh
|
||||
|
||||
# If it did not work, try again using http
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
wget $url/meshsettings?id=$meshid {{{noproxy}}}-O /usr/local/mesh/meshagent.msh
|
||||
wget $url/meshsettings?id=$meshid -O /usr/local/mesh/meshagent.msh
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]
|
||||
@ -137,22 +131,31 @@ DownloadAgent() {
|
||||
fi
|
||||
systemctl enable meshagent
|
||||
systemctl start meshagent
|
||||
else
|
||||
if [ $starttype -eq 3 ]
|
||||
then
|
||||
echo 'meshagent installed as systemd service.'
|
||||
echo 'To start service: sudo systemctl start meshagent'
|
||||
echo 'To stop service: sudo systemctl stop meshagent'
|
||||
elif [ $starttype -eq 3 ]
|
||||
then
|
||||
# initd
|
||||
wget $url/meshagents?script=2 --no-check-certificate {{{noproxy}}}-O /etc/init.d/meshagent
|
||||
wget $url/meshagents?script=2 --no-check-certificate -O /etc/init.d/meshagent
|
||||
chmod +x /etc/init.d/meshagent
|
||||
update-rc.d meshagent defaults # creates symlinks for rc.d
|
||||
service meshagent start
|
||||
else
|
||||
# upstart / others (???)
|
||||
./meshagent start
|
||||
ln -s /usr/local/mesh/meshagent /sbin/meshcmd
|
||||
ln -s /usr/local/mesh/meshagent /etc/rc2.d/S20mesh
|
||||
ln -s /usr/local/mesh/meshagent /etc/rc3.d/S20mesh
|
||||
ln -s /usr/local/mesh/meshagent /etc/rc5.d/S20mesh
|
||||
fi
|
||||
echo 'meshagent installed as init.d service.'
|
||||
echo 'To start service: sudo service meshagent start'
|
||||
echo 'To stop service: sudo service meshagent stop'
|
||||
elif [ $starttype -eq 2 ]
|
||||
then
|
||||
# upstart
|
||||
echo -e "start on runlevel [2345]\nstop on runlevel [016]\n\nrespawn\n\nchdir /usr/local/mesh\nexec /usr/local/mesh/meshagent\n\n" > /etc/init/meshagent.conf
|
||||
service meshagent start
|
||||
echo 'meshagent installed as upstart/init.d service.'
|
||||
echo 'To start service: sudo service meshagent start'
|
||||
echo 'To stop service: sudo service meshagent stop'
|
||||
else
|
||||
# unknown
|
||||
echo "Unknown Service Platform Type. (ie: init, systemd, etc)"
|
||||
echo "Unable to install meshagent as service."
|
||||
fi
|
||||
echo "Mesh agent started."
|
||||
else
|
||||
@ -179,24 +182,21 @@ UninstallAgent() {
|
||||
systemctl disable meshagent
|
||||
systemctl stop meshagent
|
||||
else
|
||||
if [ $starttype -eq 3 ]
|
||||
then
|
||||
if [ $starttype -eq 3 ]; then
|
||||
# initd
|
||||
service meshagent forceuninstall
|
||||
service meshagent stop
|
||||
update-rc.d -f meshagent remove
|
||||
rm -f /sbin/meshcmd /etc/init.d/meshagent
|
||||
else
|
||||
# upstart / others (???)
|
||||
rm -f /sbin/meshcmd /etc/rc2.d/S20mesh /etc/rc3.d/S20mesh /etc/rc5.d/S20mesh
|
||||
elif [ $starttype -eq 2 ]; then
|
||||
# upstart
|
||||
service meshagent stop
|
||||
rm -f /sbin/meshcmd
|
||||
rm -f /etc/init/meshagent.conf
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -e $installpath ]
|
||||
then
|
||||
cd $installpath
|
||||
if [ -e "$installpath/meshagent" ]
|
||||
then
|
||||
./meshagent stop
|
||||
fi
|
||||
rm -rf $installpath/*
|
||||
rmdir $installpath
|
||||
fi
|
||||
|
@ -2047,7 +2047,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
|
||||
if (obj.args.lanonly != true) { meshsettings += "MeshServer=ws" + (obj.args.notls ? '' : 's') + "://" + obj.getWebServerName(domain) + ":" + httpsPort + "/" + xdomain + "agent.ashx\r\n"; } else { meshsettings += "MeshServer=local"; }
|
||||
if (req.query.tag != null) { meshsettings += "Tag=" + req.query.tag + "\r\n"; }
|
||||
if ((req.query.installflags != null) && (req.query.installflags != 0)) { meshsettings += "InstallFlags=" + req.query.installflags + "\r\n"; }
|
||||
if (domain.agentnoproxy === true) { meshsettings += "ignoreProxyFile=1\r\n"; }
|
||||
if ((domain.agentnoproxy === true) || (obj.args.lanonly == true)) { meshsettings += "ignoreProxyFile=1\r\n"; }
|
||||
if (obj.args.agentconfig) { for (var i in obj.args.agentconfig) { meshsettings += obj.args.agentconfig[i] + "\r\n"; } }
|
||||
if (domain.agentconfig) { for (var i in domain.agentconfig) { meshsettings += domain.agentconfig[i] + "\r\n"; } }
|
||||
|
||||
@ -2179,15 +2179,18 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
|
||||
|
||||
var meshidhex = Buffer.from(req.query.meshid.replace(/\@/g, '+').replace(/\$/g, '/'), 'base64').toString('hex').toUpperCase();
|
||||
var serveridhex = Buffer.from(obj.agentCertificateHashBase64.replace(/\@/g, '+').replace(/\$/g, '/'), 'base64').toString('hex').toUpperCase();
|
||||
var httpsPort = ((obj.args.aliasport == null) ? obj.args.port : obj.args.aliasport); // Use HTTPS alias port is specified
|
||||
|
||||
// Build the agent connection URL. If we are using a sub-domain or one with a DNS, we need to craft the URL correctly.
|
||||
var xdomain = (domain.dns == null) ? domain.id : '';
|
||||
if (xdomain != '') xdomain += "/";
|
||||
var meshsettings = "MeshName=" + mesh.name + "\r\nMeshType=" + mesh.mtype + "\r\nMeshID=0x" + meshidhex + "\r\nServerID=" + serveridhex + "\r\n";
|
||||
var httpsPort = ((obj.args.aliasport == null) ? obj.args.port : obj.args.aliasport); // Use HTTPS alias port is specified
|
||||
if (obj.args.lanonly != true) { meshsettings += "MeshServer=ws" + (obj.args.notls ? '' : 's') + "://" + obj.getWebServerName(domain) + ":" + httpsPort + "/" + xdomain + "agent.ashx\r\n"; } else { meshsettings += "MeshServer=local"; }
|
||||
if (req.query.tag != null) { meshsettings += "Tag=" + req.query.tag + "\r\n"; }
|
||||
if ((req.query.installflags != null) && (req.query.installflags != 0)) { meshsettings += "InstallFlags=" + req.query.installflags + "\r\n"; }
|
||||
if ((domain.agentnoproxy === true) || (obj.args.lanonly == true)) { meshsettings += "ignoreProxyFile=1\r\n"; }
|
||||
if (obj.args.agentconfig) { for (var i in obj.args.agentconfig) { meshsettings += obj.args.agentconfig[i] + "\r\n"; } }
|
||||
if (domain.agentconfig) { for (var i in domain.agentconfig) { meshsettings += domain.agentconfig[i] + "\r\n"; } }
|
||||
|
||||
// Setup the response output
|
||||
var archive = require('archiver')('zip', { level: 5 }); // Sets the compression method.
|
||||
@ -2269,7 +2272,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
|
||||
if (obj.args.lanonly != true) { meshsettings += "MeshServer=ws" + (obj.args.notls ? '' : 's') + "://" + obj.getWebServerName(domain) + ":" + httpsPort + "/" + xdomain + "agent.ashx\r\n"; } else { meshsettings += "MeshServer=local"; }
|
||||
if (req.query.tag != null) { meshsettings += "Tag=" + req.query.tag + "\r\n"; }
|
||||
if ((req.query.installflags != null) && (req.query.installflags != 0)) { meshsettings += "InstallFlags=" + req.query.installflags + "\r\n"; }
|
||||
if (domain.agentnoproxy === true) { meshsettings += "ignoreProxyFile=1\r\n"; }
|
||||
if ((domain.agentnoproxy === true) || (obj.args.lanonly == true)) { meshsettings += "ignoreProxyFile=1\r\n"; }
|
||||
if (obj.args.agentconfig) { for (var i in obj.args.agentconfig) { meshsettings += obj.args.agentconfig[i] + "\r\n"; } }
|
||||
if (domain.agentconfig) { for (var i in domain.agentconfig) { meshsettings += domain.agentconfig[i] + "\r\n"; } }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user