mirror of
https://github.com/Ylianst/MeshAgent
synced 2026-02-09 21:20:04 +00:00
Added support for displayName
This commit is contained in:
@@ -1796,12 +1796,14 @@ void ILibDuktape_MeshAgent_PUSH(duk_context *ctx, void *chain)
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "hostname", ILibDuktape_MeshAgent_hostname, 0);
|
||||
|
||||
Duktape_CreateEnum(ctx, "ContainerPermissions", (char*[]) { "DEFAULT", "NO_AGENT", "NO_MARSHAL", "NO_PROCESS_SPAWNING", "NO_FILE_SYSTEM_ACCESS", "NO_NETWORK_ACCESS" }, (int[]) { 0x00, 0x10000000, 0x08000000, 0x04000000, 0x00000001, 0x00000002 }, 6);
|
||||
|
||||
duk_push_string(ctx, agent->displayName); ILibDuktape_CreateReadonlyProperty(ctx, "displayName");
|
||||
|
||||
if (agent->JSRunningAsService)
|
||||
{
|
||||
duk_push_string(ctx, agent->meshServiceName);
|
||||
ILibDuktape_CreateReadonlyProperty(ctx, "serviceName");
|
||||
}
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WINSERVICE
|
||||
@@ -4474,6 +4476,16 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((msnlen = ILibSimpleDataStore_Get(agentHost->masterDb, "displayName", NULL, 0)) != 0)
|
||||
{
|
||||
agentHost->displayName = (char*)ILibMemory_SmartAllocate(msnlen + 1);
|
||||
ILibSimpleDataStore_Get(agentHost->masterDb, "displayName", agentHost->displayName, msnlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
agentHost->displayName = "MeshCentral";
|
||||
}
|
||||
|
||||
duk_push_sprintf(tmpCtx, "require('service-manager').manager.getService('%s').isMe();", agentHost->meshServiceName);
|
||||
tmpString = (char*)duk_get_string(tmpCtx, -1);
|
||||
|
||||
@@ -5686,6 +5698,7 @@ void MeshAgent_Destroy(MeshAgentHostContainer* agent)
|
||||
if (agent->multicastDiscoveryKey != NULL) { free(agent->multicastDiscoveryKey); agent->multicastDiscoveryKey = NULL; }
|
||||
if (agent->multicastServerUrl != NULL) { free(agent->multicastServerUrl); agent->multicastServerUrl = NULL; }
|
||||
if (agent->meshServiceName != NULL) { ILibMemory_Free(agent->meshServiceName); agent->meshServiceName = NULL; }
|
||||
if (agent->displayName != NULL) { ILibMemory_Free(agent->displayName); agent->displayName = NULL; }
|
||||
if (agent->execparams != NULL) { ILibMemory_Free(agent->execparams); agent->execparams = NULL; }
|
||||
#ifdef WIN32
|
||||
if (agent->shCore != NULL)
|
||||
|
||||
@@ -240,6 +240,7 @@ typedef struct MeshAgentHostContainer
|
||||
int updaterVersion;
|
||||
char **execparams;
|
||||
char *meshServiceName;
|
||||
char *displayName;
|
||||
#if defined(_WINSERVICE)
|
||||
int runningAsConsole;
|
||||
#endif
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -64,6 +64,24 @@ limitations under the License.
|
||||
|
||||
/*****/
|
||||
|
||||
// The folloing line just below with 'msh=' needs to stay exactly like this since MeshCentral will replace it with the correct settings.
|
||||
//var msh = {};
|
||||
var displayName = msh.displayName ? msh.displayName : 'MeshCentral Agent';
|
||||
var s = null, buttons = ['Cancel'], skip = false;
|
||||
var serviceName = msh.meshServiceName ? msh.meshServiceName : 'meshagent';
|
||||
|
||||
try { s = require('service-manager').manager.getService(serviceName); } catch (e) { }
|
||||
|
||||
var connectArgs = [process.execPath.split('/').pop(), '--no-embedded=1', '--disableUpdate=1'];
|
||||
connectArgs.push('--MeshName="' + msh.MeshName + '"');
|
||||
connectArgs.push('--MeshType="' + msh.MeshType + '"');
|
||||
connectArgs.push('--MeshID="' + msh.MeshID + '"');
|
||||
connectArgs.push('--ServerID="' + msh.ServerID + '"');
|
||||
connectArgs.push('--MeshServer="' + msh.MeshServer + '"');
|
||||
connectArgs.push('--AgentCapabilities="0x00000020"');
|
||||
if (msh.displayName) { connectArgs.push('--displayName="' + msh.displayName + '"'); }
|
||||
if (msh.agentName) { connectArgs.push('--agentName="' + msh.agentName + '"'); }
|
||||
|
||||
function _install(parms)
|
||||
{
|
||||
var mstr = require('fs').createWriteStream(process.execPath + '.msh', { flags: 'wb' });
|
||||
@@ -72,9 +90,14 @@ limitations under the License.
|
||||
mstr.write('MeshID=' + msh.MeshID + '\n');
|
||||
mstr.write('ServerID=' + msh.ServerID + '\n');
|
||||
mstr.write('MeshServer=' + msh.MeshServer + '\n');
|
||||
if (msh.agentName) { mstr.write('agentName=' + msh.agentName + '\n'); }
|
||||
if (msh.meshServiceName) { mstr.write('meshServiceName=' + msh.meshServiceName + '\n'); }
|
||||
mstr.end();
|
||||
|
||||
if (parms == null) { parms = []; }
|
||||
if (msh.companyName) { parms.unshift('--companyName="' + msh.companyName + '"'); }
|
||||
if (msh.displayName) { parms.unshift('--displayName="' + msh.displayName + '"'); }
|
||||
if (msh.meshServiceName) { parms.unshift('--meshServiceName="' + msh.meshServiceName + '"'); }
|
||||
parms.unshift('--copy-msh=1');
|
||||
parms.unshift('--no-embedded=1');
|
||||
parms.unshift('-fullinstall');
|
||||
@@ -85,33 +108,49 @@ limitations under the License.
|
||||
global._child.stderr.on('data', function (c) { process.stdout.write(c.toString()); });
|
||||
global._child.waitExit();
|
||||
}
|
||||
|
||||
function _uninstall()
|
||||
{
|
||||
global._child = require('child_process').execFile(process.execPath,
|
||||
[process.execPath.split('/').pop(), '-fulluninstall', '--no-embedded=1']);
|
||||
[process.execPath.split('/').pop(), '-fulluninstall', '--no-embedded=1', '--meshServiceName="' + serviceName + '"']);
|
||||
|
||||
global._child.stdout.on('data', function (c) { process.stdout.write(c.toString()); });
|
||||
global._child.stderr.on('data', function (c) { process.stdout.write(c.toString()); });
|
||||
global._child.waitExit();
|
||||
}
|
||||
|
||||
var s = null;
|
||||
try { s = require('service-manager').manager.getService('meshagent'); } catch (e) { }
|
||||
var buttons = ['Cancel'];
|
||||
var skip = false;
|
||||
|
||||
if (msh.InstallFlags == null)
|
||||
{
|
||||
msh.InstallFlags = 3;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
msh.InstallFlags = parseInt(msh.InstallFlags.toString());
|
||||
}
|
||||
|
||||
if (process.argv.includes('-mesh'))
|
||||
{
|
||||
console.log(JSON.stringify(msh, null, 2));
|
||||
process.exit();
|
||||
}
|
||||
|
||||
if ((msh.InstallFlags & 1) == 1) { buttons.unshift('Connect'); }
|
||||
if ((msh.InstallFlags & 2) == 2)
|
||||
if ((msh.InstallFlags & 1) == 1)
|
||||
{
|
||||
buttons.unshift('Connect');
|
||||
if (process.argv.includes('-connect'))
|
||||
{
|
||||
global._child = require('child_process').execFile(process.execPath, connectArgs);
|
||||
global._child.stdout.on('data', function (c) { });
|
||||
global._child.stderr.on('data', function (c) { });
|
||||
global._child.on('exit', function (code) { process.exit(code); });
|
||||
|
||||
console.log("\nConnecting to: " + msh.MeshServer);
|
||||
console.log("Device Group: " + msh.MeshName);
|
||||
console.log('\nPress Ctrl-C to exit\n');
|
||||
skip = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ((!skip) && ((msh.InstallFlags & 2) == 2))
|
||||
{
|
||||
if (!require('user-sessions').isRoot())
|
||||
{
|
||||
@@ -121,32 +160,30 @@ limitations under the License.
|
||||
}
|
||||
if (s)
|
||||
{
|
||||
if (process.platform == 'darwin' || require('message-box').kdialog)
|
||||
if ((process.platform == 'darwin') || require('message-box').kdialog)
|
||||
{
|
||||
buttons.unshift("Setup");
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
buttons.unshift("Uninstall");
|
||||
buttons.unshift("Update");
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
buttons.unshift("Install");
|
||||
}
|
||||
}
|
||||
|
||||
if (process.platform != 'darwin')
|
||||
if (!skip)
|
||||
{
|
||||
if (!require('message-box').kdialog && (require('message-box').zenity == null || (!require('message-box').zenity.extra)))
|
||||
if (process.platform != 'darwin')
|
||||
{
|
||||
if (process.argv.includes('-install') || process.argv.includes('-update'))
|
||||
{
|
||||
var p = [];
|
||||
for (var i = 0; i < process.argv.length; ++i)
|
||||
{
|
||||
if(process.argv[i].startsWith('--installPath='))
|
||||
if (process.argv[i].startsWith('--installPath='))
|
||||
{
|
||||
p.push('--installPath="' + process.argv[i].split('=').pop() + '"');
|
||||
}
|
||||
@@ -154,60 +191,44 @@ limitations under the License.
|
||||
_install(p);
|
||||
process.exit();
|
||||
}
|
||||
else if(process.argv.includes('-uninstall'))
|
||||
else if (process.argv.includes('-uninstall'))
|
||||
{
|
||||
_uninstall();
|
||||
process.exit();
|
||||
}
|
||||
else if(process.argv.includes('-connect'))
|
||||
{
|
||||
global._child = require('child_process').execFile(process.execPath,
|
||||
[process.execPath.split('/').pop(), '--no-embedded=1', '--disableUpdate=1',
|
||||
'--MeshName="' + msh.MeshName + '"', '--MeshType="' + msh.MeshType + '"',
|
||||
'--MeshID="' + msh.MeshID + '"',
|
||||
'--ServerID="' + msh.ServerID + '"',
|
||||
'--MeshServer="' + msh.MeshServer + '"',
|
||||
'--AgentCapabilities="0x00000020"']);
|
||||
|
||||
global._child.stdout.on('data', function (c) { });
|
||||
global._child.stderr.on('data', function (c) { });
|
||||
global._child.on('exit', function (code) { process.exit(code); });
|
||||
|
||||
console.log("\nConnecting to: " + msh.MeshServer);
|
||||
console.log("Device Group: " + msh.MeshName);
|
||||
console.log('\nPress Ctrl-c to exit\n');
|
||||
skip = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log('\n' + "The graphical version of this installer cannot run on this system.");
|
||||
console.log("Try installing/updating Zenity, and run again." + '\n');
|
||||
console.log("You can also run the text version from the command line with the following command(s): ");
|
||||
if ((msh.InstallFlags & 1) == 1)
|
||||
if (!require('message-box').kdialog && ((require('message-box').zenity == null) || (!require('message-box').zenity.extra)))
|
||||
{
|
||||
console.log('./' + process.execPath.split('/').pop() + ' -connect');
|
||||
}
|
||||
if ((msh.InstallFlags & 2) == 2)
|
||||
{
|
||||
if (s)
|
||||
console.log('\n' + "The graphical version of this installer cannot run on this system.");
|
||||
console.log("Try installing/updating Zenity, and run again." + '\n');
|
||||
console.log("You can also run the text version from the command line with the following command(s): ");
|
||||
if ((msh.InstallFlags & 1) == 1)
|
||||
{
|
||||
console.log('./' + process.execPath.split('/').pop() + ' -update');
|
||||
console.log('./' + process.execPath.split('/').pop() + ' -uninstall');
|
||||
console.log('./' + process.execPath.split('/').pop() + ' -connect');
|
||||
}
|
||||
else
|
||||
if ((msh.InstallFlags & 2) == 2)
|
||||
{
|
||||
console.log('./' + process.execPath.split('/').pop() + ' -install');
|
||||
console.log('./' + process.execPath.split('/').pop() + ' -install --installPath="/alternate/path"');
|
||||
if (s)
|
||||
{
|
||||
console.log('./' + process.execPath.split('/').pop() + ' -update');
|
||||
console.log('./' + process.execPath.split('/').pop() + ' -uninstall');
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log('./' + process.execPath.split('/').pop() + ' -install');
|
||||
console.log('./' + process.execPath.split('/').pop() + ' -install --installPath="/alternate/path"');
|
||||
}
|
||||
}
|
||||
console.log('');
|
||||
process.exit();
|
||||
}
|
||||
console.log('');
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!require('user-sessions').isRoot()) { console.log('\n' + "This utility requires elevated permissions. Please try again with sudo."); process.exit(); }
|
||||
else
|
||||
{
|
||||
if (!require('user-sessions').isRoot()) { console.log('\n' + "This utility requires elevated permissions. Please try again with sudo."); process.exit(); }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -224,7 +245,7 @@ limitations under the License.
|
||||
msg += ("Device Group: " + msh.MeshName + '\n');
|
||||
msg += ("Server URL: " + msh.MeshServer + '\n');
|
||||
|
||||
var p = require('message-box').create("MeshCentral Agent Setup", msg, 99999, buttons);
|
||||
var p = require('message-box').create(displayName + " Setup", msg, 99999, buttons);
|
||||
p.then(function (v)
|
||||
{
|
||||
switch (v)
|
||||
@@ -233,7 +254,7 @@ limitations under the License.
|
||||
process.exit();
|
||||
break;
|
||||
case 'Setup':
|
||||
var d = require('message-box').create("MeshCentral Agent", msg, 99999, ['Update', 'Uninstall', 'Cancel']);
|
||||
var d = require('message-box').create(displayName, msg, 99999, ['Update', 'Uninstall', 'Cancel']);
|
||||
d.then(function (v)
|
||||
{
|
||||
switch (v)
|
||||
@@ -252,14 +273,7 @@ limitations under the License.
|
||||
}).catch(function (v) { process.exit(); });
|
||||
break;
|
||||
case "Connect":
|
||||
global._child = require('child_process').execFile(process.execPath,
|
||||
[process.execPath.split('/').pop(), '--no-embedded=1', '--disableUpdate=1',
|
||||
'--MeshName="' + msh.MeshName + '"', '--MeshType="' + msh.MeshType + '"',
|
||||
'--MeshID="' + msh.MeshID + '"',
|
||||
'--ServerID="' + msh.ServerID + '"',
|
||||
'--MeshServer="' + msh.MeshServer + '"',
|
||||
'--AgentCapabilities="0x00000020"']);
|
||||
|
||||
global._child = require('child_process').execFile(process.execPath, connectArgs);
|
||||
global._child.stdout.on('data', function (c) { });
|
||||
global._child.stderr.on('data', function (c) { });
|
||||
global._child.on('exit', function (code) { process.exit(code); });
|
||||
@@ -275,7 +289,7 @@ limitations under the License.
|
||||
}
|
||||
}
|
||||
|
||||
var d = require('message-box').create("MeshCentral Agent", msg, 99999, ['Disconnect']);
|
||||
var d = require('message-box').create(displayName, msg, 99999, ['Disconnect']);
|
||||
d.then(function (v) { process.exit(); }).catch(function (v) { process.exit(); });
|
||||
break;
|
||||
case "Uninstall":
|
||||
|
||||
@@ -55,6 +55,7 @@ function messageBox()
|
||||
this._ObjectID = 'message-box';
|
||||
this.create = function create(title, caption, timeout, layout, sid)
|
||||
{
|
||||
if (title == 'MeshCentral') { try { title = require('MeshAgent').displayName; } catch (x) { } }
|
||||
var ret = new promise(function (res, rej) { this._res = res; this._rej = rej; });
|
||||
ret.options = { launch: { module: 'message-box', method: 'slave', args: [] } };
|
||||
ret.title = title;
|
||||
@@ -344,6 +345,7 @@ function linux_messageBox()
|
||||
this.create = function create(title, caption, timeout, layout)
|
||||
{
|
||||
if (timeout == null) { timeout = 10; }
|
||||
if (title == 'MeshCentral') { try { title = require('MeshAgent').displayName; } catch (x) { } }
|
||||
var ret = new promise(function (res, rej) { this._res = res; this._rej = rej; });
|
||||
var uid;
|
||||
var xinfo;
|
||||
@@ -685,6 +687,7 @@ function macos_messageBox()
|
||||
|
||||
this.create = function create(title, caption, timeout, layout)
|
||||
{
|
||||
if (title == 'MeshCentral') { try { title = require('MeshAgent').displayName; } catch (x) { } }
|
||||
var userLayout = Array.isArray(layout);
|
||||
caption = caption.split('\n').join('\\n');
|
||||
if (Array.isArray(layout) && layout.length > 3)
|
||||
@@ -991,6 +994,7 @@ function macos_messageBox()
|
||||
};
|
||||
this.notify = function notify(title, caption)
|
||||
{
|
||||
if (title == 'MeshCentral') { try { title = require('MeshAgent').displayName; } catch (x) { } }
|
||||
if (require('user-sessions').isRoot())
|
||||
{
|
||||
var str = 'tell current application to display notification "' + caption + '" with title "' + title + '"';
|
||||
|
||||
@@ -45,6 +45,8 @@ function Toaster()
|
||||
{
|
||||
var retVal = new promise(function (res, rej) { this._res = res; this._rej = rej; });
|
||||
retVal.title = title;
|
||||
if (title == 'MeshCentral') { try { retVal.title = require('MeshAgent').displayName; } catch (x) { } }
|
||||
|
||||
retVal.caption = caption;
|
||||
|
||||
switch (process.platform)
|
||||
|
||||
Reference in New Issue
Block a user