mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-21 18:53:32 +00:00
1. Fixed bug in process-manager.getProcessInfo() on linux
2. Updated agent-installer 3. Fixed JSON error in SimpleDataStore
This commit is contained in:
@@ -3901,14 +3901,17 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
|
|||||||
bufLen = ILibSimpleDataStore_Cached_GetJSONEx(agentHost->masterDb, NULL, 0);
|
bufLen = ILibSimpleDataStore_Cached_GetJSONEx(agentHost->masterDb, NULL, 0);
|
||||||
buf = (char*)ILibMemory_SmartAllocate(bufLen);
|
buf = (char*)ILibMemory_SmartAllocate(bufLen);
|
||||||
bufLen = ILibSimpleDataStore_Cached_GetJSONEx(agentHost->masterDb, buf, bufLen);
|
bufLen = ILibSimpleDataStore_Cached_GetJSONEx(agentHost->masterDb, buf, bufLen);
|
||||||
|
|
||||||
duk_eval_string(ctxx, "require('agent-installer');");
|
duk_eval_string(ctxx, "require('agent-installer');");
|
||||||
duk_get_prop_string(ctxx, -1, "fullInstall");
|
duk_get_prop_string(ctxx, -1, "fullInstall");
|
||||||
duk_swap_top(ctxx, -2);
|
duk_swap_top(ctxx, -2);
|
||||||
duk_push_string(ctxx, buf);
|
duk_push_string(ctxx, buf);
|
||||||
if (duk_pcall_method(ctxx, 1) != 0)
|
if (duk_pcall_method(ctxx, 1) != 0)
|
||||||
{
|
{
|
||||||
printf("%s\n", duk_safe_to_string(ctxx, -1));
|
if (strcmp(duk_safe_to_string(ctxx, -1), "Process.exit() forced script termination") != 0)
|
||||||
|
{
|
||||||
|
printf("%s\n", duk_safe_to_string(ctxx, -1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
duk_pop(ctxx);
|
duk_pop(ctxx);
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -188,7 +188,7 @@ void ILibSimpleDataStore_Cached_GetJSONEx_write(ILibHashtable sender, void *Key1
|
|||||||
memcpy_s(cache->buffer + cache->offset, cache->bufferLen - cache->offset, Key2, Key2Len); cache->offset += Key2Len;
|
memcpy_s(cache->buffer + cache->offset, cache->bufferLen - cache->offset, Key2, Key2Len); cache->offset += Key2Len;
|
||||||
cache->offset += sprintf_s(cache->buffer + cache->offset, cache->bufferLen - cache->offset, "=\\\"");
|
cache->offset += sprintf_s(cache->buffer + cache->offset, cache->bufferLen - cache->offset, "=\\\"");
|
||||||
memcpy_s(cache->buffer + cache->offset, cache->bufferLen - cache->offset, entry->value, entry->valueLength); cache->offset += entry->valueLength;
|
memcpy_s(cache->buffer + cache->offset, cache->bufferLen - cache->offset, entry->value, entry->valueLength); cache->offset += entry->valueLength;
|
||||||
cache->offset += sprintf_s(cache->buffer + cache->offset, cache->bufferLen - cache->offset, "\\\"");
|
cache->offset += sprintf_s(cache->buffer + cache->offset, cache->bufferLen - cache->offset, "\\\"\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
int ILibSimpleDataStore_Cached_GetJSONEx(ILibSimpleDataStore dataStore, char *buffer, int bufferLen)
|
int ILibSimpleDataStore_Cached_GetJSONEx(ILibSimpleDataStore dataStore, char *buffer, int bufferLen)
|
||||||
|
|||||||
215
modules/agent-installer.js
Normal file
215
modules/agent-installer.js
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2020 Intel Corporation
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
function installService(params)
|
||||||
|
{
|
||||||
|
process.stdout.write('...Installing service');
|
||||||
|
try
|
||||||
|
{
|
||||||
|
require('service-manager').manager.installService(
|
||||||
|
{
|
||||||
|
name: process.platform == 'win32' ? 'Mesh Agent' : 'meshagent',
|
||||||
|
target: process.platform == 'win32' ? 'MeshAgent' : 'meshagent',
|
||||||
|
displayName: 'Mesh Agent background service',
|
||||||
|
servicePath: process.execPath,
|
||||||
|
startType: 'AUTO_START',
|
||||||
|
parameters: params
|
||||||
|
});
|
||||||
|
process.stdout.write(' [DONE]\n');
|
||||||
|
}
|
||||||
|
catch(sie)
|
||||||
|
{
|
||||||
|
process.stdout.write(' [ERROR] ' + sie);
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
var svc = require('service-manager').manager.getService(process.platform=='win32'?'Mesh Agent':'meshagent');
|
||||||
|
|
||||||
|
if(process.platform == 'win32')
|
||||||
|
{
|
||||||
|
var loc = svc.appLocation();
|
||||||
|
process.stdout.write(' -> Writing firewall rules for Mesh Agent Service...');
|
||||||
|
|
||||||
|
var rule =
|
||||||
|
{
|
||||||
|
DisplayName: 'Mesh Agent Management Traffic (TCP-1)',
|
||||||
|
direction: 'inbound',
|
||||||
|
Program: loc,
|
||||||
|
Protocol: 'TCP',
|
||||||
|
Profile: 'Public, Private, Domain',
|
||||||
|
LocalPort: 16990,
|
||||||
|
Description: 'Mesh Central Agent Management Traffic',
|
||||||
|
EdgeTraversalPolicy: 'allow',
|
||||||
|
Enabled: true
|
||||||
|
};
|
||||||
|
require('win-firewall').addFirewallRule(rule);
|
||||||
|
|
||||||
|
rule =
|
||||||
|
{
|
||||||
|
DisplayName: 'Mesh Agent Management Traffic (TCP-2)',
|
||||||
|
direction: 'inbound',
|
||||||
|
Program: loc,
|
||||||
|
Protocol: 'TCP',
|
||||||
|
Profile: 'Public, Private, Domain',
|
||||||
|
LocalPort: 16991,
|
||||||
|
Description: 'Mesh Central Agent Management Traffic',
|
||||||
|
EdgeTraversalPolicy: 'allow',
|
||||||
|
Enabled: true
|
||||||
|
};
|
||||||
|
require('win-firewall').addFirewallRule(rule);
|
||||||
|
|
||||||
|
rule =
|
||||||
|
{
|
||||||
|
DisplayName: 'Mesh Agent Peer-to-Peer Traffic (UDP-1)',
|
||||||
|
direction: 'inbound',
|
||||||
|
Program: loc,
|
||||||
|
Protocol: 'UDP',
|
||||||
|
Profile: 'Public, Private, Domain',
|
||||||
|
LocalPort: 16990,
|
||||||
|
Description: 'Mesh Central Agent Peer-to-Peer Traffic',
|
||||||
|
EdgeTraversalPolicy: 'allow',
|
||||||
|
Enabled: true
|
||||||
|
};
|
||||||
|
require('win-firewall').addFirewallRule(rule);
|
||||||
|
|
||||||
|
rule =
|
||||||
|
{
|
||||||
|
DisplayName: 'Mesh Agent Peer-to-Peer Traffic (UDP-2)',
|
||||||
|
direction: 'inbound',
|
||||||
|
Program: loc,
|
||||||
|
Protocol: 'UDP',
|
||||||
|
Profile: 'Public, Private, Domain',
|
||||||
|
LocalPort: 16991,
|
||||||
|
Description: 'Mesh Central Agent Peer-to-Peer Traffic',
|
||||||
|
EdgeTraversalPolicy: 'allow',
|
||||||
|
Enabled: true
|
||||||
|
};
|
||||||
|
require('win-firewall').addFirewallRule(rule);
|
||||||
|
process.stdout.write(' [DONE]\n');
|
||||||
|
}
|
||||||
|
process.stdout.write(' -> Starting service...');
|
||||||
|
try
|
||||||
|
{
|
||||||
|
svc.start();
|
||||||
|
process.stdout.write(' [OK]\n');
|
||||||
|
}
|
||||||
|
catch(ee)
|
||||||
|
{
|
||||||
|
process.stdout.write(' [ERROR]\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.platform == 'win32') { svc.close(); }
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
function uninstallService2(params)
|
||||||
|
{
|
||||||
|
process.stdout.write(' -> Uninstalling previous installation...');
|
||||||
|
try
|
||||||
|
{
|
||||||
|
require('service-manager').manager.uninstallService(process.platform == 'win32' ? 'Mesh Agent' : 'meshagent');
|
||||||
|
process.stdout.write(' [DONE]\n');
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
process.stdout.write(' [ERROR]\n');
|
||||||
|
}
|
||||||
|
installService(params);
|
||||||
|
}
|
||||||
|
function uninstallService(params)
|
||||||
|
{
|
||||||
|
var svc = require('service-manager').manager.getService(process.platform == 'win32' ? 'Mesh Agent' : 'meshagent');
|
||||||
|
if (svc.isRunning())
|
||||||
|
{
|
||||||
|
process.stdout.write(' -> Stopping Service...');
|
||||||
|
if(process.platform=='win32')
|
||||||
|
{
|
||||||
|
svc.stop().then(function ()
|
||||||
|
{
|
||||||
|
process.stdout.write(' [STOPPED]\n');
|
||||||
|
svc.close();
|
||||||
|
uninstallService2(this._params);
|
||||||
|
}, function ()
|
||||||
|
{
|
||||||
|
process.stdout.write(' [ERROR]\n');
|
||||||
|
svc.close();
|
||||||
|
uninstallService2(this._params);
|
||||||
|
}).parentPromise._params = params;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
svc.stop();
|
||||||
|
process.stdout.write(' [STOPPED]\n');
|
||||||
|
uninstallService2(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (process.platform == 'win32') { svc.close(); }
|
||||||
|
uninstallService2(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function serviceExists(loc, params)
|
||||||
|
{
|
||||||
|
process.stdout.write(' [FOUND: ' + loc + ']\n');
|
||||||
|
if(process.platform == 'win32')
|
||||||
|
{
|
||||||
|
process.stdout.write(' -> Checking firewall rules for previous installation...');
|
||||||
|
require('win-firewall').removeFirewallRule({ program: loc }).then(function ()
|
||||||
|
{
|
||||||
|
// SUCCESS
|
||||||
|
process.stdout.write(' [DELETED]\n');
|
||||||
|
uninstallService(this._params);
|
||||||
|
}, function ()
|
||||||
|
{
|
||||||
|
// FAILED
|
||||||
|
process.stdout.write(' [No Rules Found]\n');
|
||||||
|
uninstallService(this._params);
|
||||||
|
}).parentPromise._params = params;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uninstallService(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function fullInstall(jsonString)
|
||||||
|
{
|
||||||
|
console.setDestination(console.Destinations.DISABLED);
|
||||||
|
var parms = JSON.parse(jsonString);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
process.stdout.write('...Checking for previous installation');
|
||||||
|
var s = require('service-manager').manager.getService(process.platform == 'win32' ? 'Mesh Agent' : 'meshagent');
|
||||||
|
var loc = s.appLocation();
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
process.stdout.write(' [NONE]\n');
|
||||||
|
installService(parms);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
serviceExists(loc, parms);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports =
|
||||||
|
{
|
||||||
|
fullInstall: fullInstall
|
||||||
|
};
|
||||||
@@ -133,7 +133,7 @@ function processManager() {
|
|||||||
var status = require('fs').readFileSync('/proc/' + pid + '/status');
|
var status = require('fs').readFileSync('/proc/' + pid + '/status');
|
||||||
var info = {};
|
var info = {};
|
||||||
var lines = status.toString().split('\n');
|
var lines = status.toString().split('\n');
|
||||||
for(var i in lines)
|
for(var i=0;i<lines.length;++i)
|
||||||
{
|
{
|
||||||
var tokens = lines[i].split(':');
|
var tokens = lines[i].split(':');
|
||||||
if (tokens.length > 1) { tokens[1] = tokens[1].trim(); }
|
if (tokens.length > 1) { tokens[1] = tokens[1].trim(); }
|
||||||
|
|||||||
Reference in New Issue
Block a user