mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-22 19:23:31 +00:00
Add -state flag
This commit is contained in:
@@ -4027,10 +4027,16 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
|
|||||||
|
|
||||||
int ixr = 0;
|
int ixr = 0;
|
||||||
int installFlag = 0;
|
int installFlag = 0;
|
||||||
|
int fetchstate = 0;
|
||||||
|
|
||||||
for (ri = 0; ri < paramLen; ++ri)
|
for (ri = 0; ri < paramLen; ++ri)
|
||||||
{
|
{
|
||||||
int len = (int)strnlen_s(param[ri], 4096);
|
int len = (int)strnlen_s(param[ri], 4096);
|
||||||
int ix;
|
int ix;
|
||||||
|
if (strcmp("-state", param[ri]) == 0)
|
||||||
|
{
|
||||||
|
fetchstate = 1;
|
||||||
|
}
|
||||||
if (strcmp("-finstall", param[ri]) == 0 || strcmp("-fullinstall", param[ri]) == 0)
|
if (strcmp("-finstall", param[ri]) == 0 || strcmp("-fullinstall", param[ri]) == 0)
|
||||||
{
|
{
|
||||||
installFlag = 1;
|
installFlag = 1;
|
||||||
@@ -4060,7 +4066,13 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
paramLen -= ixr;
|
paramLen -= ixr;
|
||||||
if (installFlag != 0)
|
if (fetchstate != 0)
|
||||||
|
{
|
||||||
|
duk_context *ctxx = ILibDuktape_ScriptContainer_InitializeJavaScriptEngineEx(0, 0, agentHost->chain, NULL, NULL, agentHost->exePath, NULL, MeshAgent_AgentInstallerCTX_Finalizer, agentHost->chain);
|
||||||
|
duk_eval_string(ctxx, "require('_agentStatus').start();");
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
else if (installFlag != 0)
|
||||||
{
|
{
|
||||||
int bufLen = 0;
|
int bufLen = 0;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|||||||
@@ -527,7 +527,8 @@ int wmain(int argc, char* wargv[])
|
|||||||
|
|
||||||
if (argc > 1 && (strcasecmp(argv[1], "-finstall") == 0 || strcasecmp(argv[1], "-funinstall") == 0 ||
|
if (argc > 1 && (strcasecmp(argv[1], "-finstall") == 0 || strcasecmp(argv[1], "-funinstall") == 0 ||
|
||||||
strcasecmp(argv[1], "-fulluninstall") == 0 || strcasecmp(argv[1], "-fullinstall") == 0 ||
|
strcasecmp(argv[1], "-fulluninstall") == 0 || strcasecmp(argv[1], "-fullinstall") == 0 ||
|
||||||
strcasecmp(argv[1], "-install")==0 || strcasecmp(argv[1], "-uninstall") == 0))
|
strcasecmp(argv[1], "-install")==0 || strcasecmp(argv[1], "-uninstall") == 0) ||
|
||||||
|
strcasecmp(argv[1], "-state") == 0)
|
||||||
{
|
{
|
||||||
argv[argc] = argv[1];
|
argv[argc] = argv[1];
|
||||||
argv[1] = (char*)ILibMemory_SmartAllocate(4);
|
argv[1] = (char*)ILibMemory_SmartAllocate(4);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
72
modules/_agentStatus.js
Normal file
72
modules/_agentStatus.js
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
|
||||||
|
var promise = require('promise');
|
||||||
|
var nodeid = require('_agentNodeId')();
|
||||||
|
var ipcPath = process.platform == 'win32' ? ('\\\\.\\pipe\\' + nodeid + '-DAIPC') : (process.cwd() + '/DAIPC');
|
||||||
|
|
||||||
|
function queryAgent(obj)
|
||||||
|
{
|
||||||
|
var ret = new promise(function (res, rej) { this._res = res; this._rej = rej; });
|
||||||
|
ret._obj = { cmd: 'query', value: obj };
|
||||||
|
ret.client = require('net').createConnection({ path: ipcPath });
|
||||||
|
ret.client.promise = ret;
|
||||||
|
ret.client.on('connect', function ()
|
||||||
|
{
|
||||||
|
this.on('data', function (chunk)
|
||||||
|
{
|
||||||
|
var len;
|
||||||
|
if (chunk.length < 4) { this.unshift(chunk); return; }
|
||||||
|
if ((len = chunk.readUInt32LE(0)) > chunk.length) { this.unshift(chunk); return;}
|
||||||
|
|
||||||
|
var data = chunk.slice(4, len + 4);
|
||||||
|
var payload = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
payload = JSON.parse(data.toString());
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
this.promise._rej('Invalid Response Received');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//this.promise._res(payload.result?payload.result:'');
|
||||||
|
this.promise._res(payload.result);
|
||||||
|
}
|
||||||
|
catch(x)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
if ((len + 4) < chunk.length) { this.unshift(chunk.slice(4 + len)); }
|
||||||
|
});
|
||||||
|
this.on('end', function ()
|
||||||
|
{
|
||||||
|
this.promise._rej('closed');
|
||||||
|
});
|
||||||
|
|
||||||
|
var j = Buffer.from(JSON.stringify(this.promise._obj));
|
||||||
|
var buf = Buffer.alloc(4 + j.length);
|
||||||
|
buf.writeUInt32LE(j.length + 4, 0);
|
||||||
|
j.copy(buf, 4);
|
||||||
|
this.write(buf);
|
||||||
|
});
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
function start()
|
||||||
|
{
|
||||||
|
console.log('Querying Mesh Agent state...');
|
||||||
|
global._statustm = setTimeout(function ()
|
||||||
|
{
|
||||||
|
console.log('Unable to contact Mesh Agent...');
|
||||||
|
process._exit();
|
||||||
|
}, 3000);
|
||||||
|
|
||||||
|
queryAgent('connection').then(function (res)
|
||||||
|
{
|
||||||
|
if (res == null) { res = '[NOT CONNECTED]'; }
|
||||||
|
console.log('Mesh Agent connected to: ' + res);
|
||||||
|
return (queryAgent('descriptors'));
|
||||||
|
}).then(console.log).then(function () { process._exit(); }).catch(function () { process._exit(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { start: start };
|
||||||
Reference in New Issue
Block a user