Updates agents and small server fixes.

This commit is contained in:
Ylian Saint-Hilaire 2019-03-01 17:13:11 -08:00
parent e118075a08
commit 26496dfc42
24 changed files with 189 additions and 159 deletions

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

File diff suppressed because one or more lines are too long

View File

@ -430,7 +430,7 @@ function createMeshCore(agent) {
//sendConsoleText(JSON.stringify(woptions)); //sendConsoleText(JSON.stringify(woptions));
var tunnel = http.request(woptions); var tunnel = http.request(woptions);
tunnel.upgrade = onTunnelUpgrade; 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.sessionid = data.sessionid;
tunnel.rights = data.rights; tunnel.rights = data.rights;
tunnel.state = 0; tunnel.state = 0;
@ -1407,7 +1407,7 @@ function createMeshCore(agent) {
} catch (e) { response = 'Invalid HTTP websocket request'; } } catch (e) { response = 'Invalid HTTP websocket request'; }
if (httprequest != null) { if (httprequest != null) {
httprequest.upgrade = onWebSocketUpgrade; 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; var index = 1;
while (consoleWebSockets[index]) { index++; } while (consoleWebSockets[index]) { index++; }

File diff suppressed because one or more lines are too long

View File

@ -8,14 +8,14 @@
# Description: <DESCRIPTION> # Description: <DESCRIPTION>
### END INIT INFO ### END INIT INFO
SCRIPT=/usr/local/mesh/meshagent SCRIPT=/usr/local/mesh_services/meshagent/meshagent
RUNAS=root RUNAS=root
PIDFILE=/var/run/meshagent.pid PIDFILE=/var/run/meshagent.pid
LOGFILE=/var/log/meshagent.log LOGFILE=/var/log/meshagent.log
start() { 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 echo 'Service already running' >&2
return 1 return 1
fi fi
@ -26,53 +26,62 @@ start() {
} }
stop() { stop() {
if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then if [ ! -f "$PIDFILE" ]; then
echo 'Service not running' >&2 echo 'Service not running' >&2
return 1 return 1
fi else
echo 'Stopping service…' >&2 pid=$( cat "$PIDFILE" )
kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE" if kill -0 $pid 2>/dev/null; then
echo 'Service stopped' >&2 echo 'Stopping service…' >&2
} kill -16 $pid
echo 'Service stopped' >&2
uninstall() { else
echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] " echo 'Service not running'
local SURE fi
read SURE rm -f $"PIDFILE"
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"
fi fi
} }
restart(){
forceuninstall() { stop
stop start
rm -f "$PIDFILE"
rm -f "$LOGFILE"
update-rc.d -f <NAME> remove
rm -fv "$0"
} }
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 case "$1" in
start) start)
start start
;; ;;
stop) stop)
stop stop
;; ;;
uninstall) restart)
uninstall stop
;; start
forceuninstall) ;;
uninstall status)
;; status
restart) ;;
stop *)
start echo "Usage: service meshagent {start|stop|restart|status}"
;; ;;
*)
echo "Usage: $0 {start|stop|restart|uninstall}"
esac esac
exit 0

View File

@ -3,18 +3,12 @@
CheckStartupType() { CheckStartupType() {
# echo "Checking process autostart system..." # echo "Checking process autostart system..."
starttype=`ps -p 1 | awk '/1/ {print $4}'` starttype=`ps -p 1 | awk '/1/ {print $4}'`
if [[ $starttype == 'systemd' ]]; then return 1; # systemd; if [[ $starttype == 'systemd' ]]; then return 1; # systemd;
elif [[ $starttype == 'init' ]]; then return 3; # sysv-init; elif [[ $starttype == 'init' ]];
elif [[ `/sbin/init --version` =~ upstart ]]; then return 2; # upstart; then
fi if [[ `/sbin/init --version` =~ upstart ]]; then return 2; # upstart
return 0; return 3; # sysv-init
} fi
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;
fi fi
return 0; return 0;
} }
@ -95,13 +89,13 @@ DownloadAgent() {
mkdir -p /usr/local/mesh mkdir -p /usr/local/mesh
cd /usr/local/mesh cd /usr/local/mesh
echo "Downloading Mesh agent #$machineid..." 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 it did not work, try again using http
if [ $? != 0 ] if [ $? != 0 ]
then then
url=${url/"https://"/"http://"} 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 fi
if [ $? -eq 0 ] if [ $? -eq 0 ]
@ -109,12 +103,12 @@ DownloadAgent() {
echo "Mesh agent downloaded." echo "Mesh agent downloaded."
# TODO: We could check the meshagent sha256 hash, but best to authenticate the server. # TODO: We could check the meshagent sha256 hash, but best to authenticate the server.
chmod 755 /usr/local/mesh/meshagent 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 it did not work, try again using http
if [ $? -ne 0 ] if [ $? -ne 0 ]
then 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 fi
if [ $? -eq 0 ] if [ $? -eq 0 ]
@ -137,22 +131,31 @@ DownloadAgent() {
fi fi
systemctl enable meshagent systemctl enable meshagent
systemctl start meshagent systemctl start meshagent
else echo 'meshagent installed as systemd service.'
if [ $starttype -eq 3 ] echo 'To start service: sudo systemctl start meshagent'
then echo 'To stop service: sudo systemctl stop meshagent'
elif [ $starttype -eq 3 ]
then
# initd # 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 chmod +x /etc/init.d/meshagent
update-rc.d meshagent defaults # creates symlinks for rc.d update-rc.d meshagent defaults # creates symlinks for rc.d
service meshagent start service meshagent start
else echo 'meshagent installed as init.d service.'
# upstart / others (???) echo 'To start service: sudo service meshagent start'
./meshagent start echo 'To stop service: sudo service meshagent stop'
ln -s /usr/local/mesh/meshagent /sbin/meshcmd elif [ $starttype -eq 2 ]
ln -s /usr/local/mesh/meshagent /etc/rc2.d/S20mesh then
ln -s /usr/local/mesh/meshagent /etc/rc3.d/S20mesh # upstart
ln -s /usr/local/mesh/meshagent /etc/rc5.d/S20mesh 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
fi 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 fi
echo "Mesh agent started." echo "Mesh agent started."
else else
@ -179,24 +182,21 @@ UninstallAgent() {
systemctl disable meshagent systemctl disable meshagent
systemctl stop meshagent systemctl stop meshagent
else else
if [ $starttype -eq 3 ] if [ $starttype -eq 3 ]; then
then
# initd # initd
service meshagent forceuninstall service meshagent stop
update-rc.d -f meshagent remove
rm -f /sbin/meshcmd /etc/init.d/meshagent rm -f /sbin/meshcmd /etc/init.d/meshagent
else elif [ $starttype -eq 2 ]; then
# upstart / others (???) # upstart
rm -f /sbin/meshcmd /etc/rc2.d/S20mesh /etc/rc3.d/S20mesh /etc/rc5.d/S20mesh service meshagent stop
rm -f /sbin/meshcmd
rm -f /etc/init/meshagent.conf
fi fi
fi fi
if [ -e $installpath ] if [ -e $installpath ]
then then
cd $installpath
if [ -e "$installpath/meshagent" ]
then
./meshagent stop
fi
rm -rf $installpath/* rm -rf $installpath/*
rmdir $installpath rmdir $installpath
fi fi

View File

@ -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 (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.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 ((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 (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"; } } 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 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 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. // 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 : ''; var xdomain = (domain.dns == null) ? domain.id : '';
if (xdomain != '') xdomain += "/"; if (xdomain != '') xdomain += "/";
var meshsettings = "MeshName=" + mesh.name + "\r\nMeshType=" + mesh.mtype + "\r\nMeshID=0x" + meshidhex + "\r\nServerID=" + serveridhex + "\r\n"; 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 (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.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 ((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 // Setup the response output
var archive = require('archiver')('zip', { level: 5 }); // Sets the compression method. 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 (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.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 ((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 (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"; } } if (domain.agentconfig) { for (var i in domain.agentconfig) { meshsettings += domain.agentconfig[i] + "\r\n"; } }