From ee6a3fd65784bd2675e77ebe0a20e91d9039dedc Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Mon, 16 Sep 2019 11:11:53 -0700 Subject: [PATCH 1/2] 1. Added -E switch to sudo, to preserve proxy settings 2. Added uninstallAgent console command --- agents/meshcore.js | 12 ++++++++++++ views/default.handlebars | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/agents/meshcore.js b/agents/meshcore.js index eb6b4e78..e2293408 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1863,6 +1863,18 @@ function createMeshCore(agent) } break; } + case 'uninstallagent': + var agentName = process.platform == 'win32' ? 'Mesh Agent' : 'meshagent'; + if (!require('service-manager').manager.getService(agentName).isMe()) + { + response = 'Uininstall failed, this instance is not the service instance'; + } + else + { + var js = "require('service-manager').manager.getService('" + agentName + "').stop(); require('service-manager').manager.uninstallService('" + agentName + "'); process.exit();"; + this.child = require('child_process').execFile(process.execPath, [process.platform == 'win32' ? (process.execPath.split('\\').pop()) : (process.execPath.split('/').pop()), '-b64exec', Buffer.from(js).toString('base64')], { type: 4, detached: true }); + } + break; case 'notify': { // Send a notification message to the mesh if (args['_'].length != 1) { response = 'Proper usage: notify "message" [--session]'; // Display correct command usage diff --git a/views/default.handlebars b/views/default.handlebars index 6f764a2c..9291ad99 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -3026,7 +3026,7 @@ var portStr = (serverinfo.port == 443)?'':(":" + serverinfo.port); if ((features & 0x2000) == 0) { - Q('agins_linux_area').value = "(wget https://" + servername + portStr + domainUrl + "meshagents?script=1 --no-check-certificate -O ./meshinstall.sh || wget https://" + servername + portStr + domainUrl + "meshagents?script=1 --no-proxy --no-check-certificate -O ./meshinstall.sh) && chmod 755 ./meshinstall.sh && sudo ./meshinstall.sh https://" + servername + portStr + domainUrlNoSlash + " '" + meshid.split('/')[2] + "'\r\n"; + Q('agins_linux_area').value = "(wget https://" + servername + portStr + domainUrl + "meshagents?script=1 --no-check-certificate -O ./meshinstall.sh || wget https://" + servername + portStr + domainUrl + "meshagents?script=1 --no-proxy --no-check-certificate -O ./meshinstall.sh) && chmod 755 ./meshinstall.sh && sudo -E ./meshinstall.sh https://" + servername + portStr + domainUrlNoSlash + " '" + meshid.split('/')[2] + "'\r\n"; Q('agins_linux_area_un').value = "(wget https://" + servername + portStr + domainUrl + "meshagents?script=1 --no-check-certificate -O ./meshinstall.sh || wget https://" + servername + portStr + domainUrl + "meshagents?script=1 --no-proxy --no-check-certificate -O ./meshinstall.sh) && chmod 755 ./meshinstall.sh && sudo ./meshinstall.sh uninstall\r\n"; } else @@ -3041,7 +3041,7 @@ var portStr = (serverinfo.port == 80) ? '' : (":" + serverinfo.port); if ((features & 0x2000) == 0) { - Q('agins_linux_area').value = "(wget http://" + servername + portStr + domainUrl + "meshagents?script=1 -O ./meshinstall.sh || wget http://" + servername + portStr + domainUrl + "meshagents?script=1 --no-proxy -O ./meshinstall.sh) && chmod 755 ./meshinstall.sh && sudo ./meshinstall.sh http://" + servername + portStr + domainUrlNoSlash + " '" + meshid.split('/')[2] + "'\r\n"; + Q('agins_linux_area').value = "(wget http://" + servername + portStr + domainUrl + "meshagents?script=1 -O ./meshinstall.sh || wget http://" + servername + portStr + domainUrl + "meshagents?script=1 --no-proxy -O ./meshinstall.sh) && chmod 755 ./meshinstall.sh && sudo -E ./meshinstall.sh http://" + servername + portStr + domainUrlNoSlash + " '" + meshid.split('/')[2] + "'\r\n"; Q('agins_linux_area_un').value = "(wget http://" + servername + portStr + domainUrl + "meshagents?script=1 -O ./meshinstall.sh || wget http://" + servername + portStr + domainUrl + "meshagents?script=1 --no-proxy -O ./meshinstall.sh) && chmod 755 ./meshinstall.sh && sudo ./meshinstall.sh uninstall\r\n"; } else From 15d59ca30df7c202adfa98477ba4bbd4c9429aa4 Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Mon, 16 Sep 2019 13:08:29 -0700 Subject: [PATCH 2/2] Updated 'uninstallAgent' to try to uninstall secondary agent too. --- agents/meshcore.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/agents/meshcore.js b/agents/meshcore.js index 7690cb47..9f7d8978 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1861,6 +1861,13 @@ function createMeshCore(agent) } else { + try + { + diagnosticAgent_uninstall(); + } + catch(x) + { + } var js = "require('service-manager').manager.getService('" + agentName + "').stop(); require('service-manager').manager.uninstallService('" + agentName + "'); process.exit();"; this.child = require('child_process').execFile(process.execPath, [process.platform == 'win32' ? (process.execPath.split('\\').pop()) : (process.execPath.split('/').pop()), '-b64exec', Buffer.from(js).toString('base64')], { type: 4, detached: true }); }