mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-02-03 18:05:58 -05:00
updated to add support for freebsd() self update
This commit is contained in:
parent
0f9c71e1bc
commit
fb9c146ccc
@ -56,6 +56,63 @@ function sendAgentMessage(msg, icon)
|
|||||||
require('MeshAgent').SendCommand({ action: 'sessions', type: 'msg', value: sendAgentMessage.messages });
|
require('MeshAgent').SendCommand({ action: 'sessions', type: 'msg', value: sendAgentMessage.messages });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bsd_execv(name, agentfilename, sessionid)
|
||||||
|
{
|
||||||
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
|
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
|
||||||
|
child.stdin.write("cat /usr/lib/libc.so | awk '");
|
||||||
|
child.stdin.write('{');
|
||||||
|
child.stdin.write(' a=split($0, tok, "(");');
|
||||||
|
child.stdin.write(' if(a>1)');
|
||||||
|
child.stdin.write(' {');
|
||||||
|
child.stdin.write(' split(tok[2], b, ")");');
|
||||||
|
child.stdin.write(' split(b[1], c, " ");');
|
||||||
|
child.stdin.write(' print c[1];');
|
||||||
|
child.stdin.write(' }');
|
||||||
|
child.stdin.write("}'\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
if (child.stdout.str.trim() == '')
|
||||||
|
{
|
||||||
|
if (sessionid != null) { sendConsoleText('Self Update failed because cannot find libc.so', sessionid) }
|
||||||
|
sendAgentMessage('Self Update failed because cannot find libc.so', 3);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var libc = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
libc = require('_GenericMarshal').CreateNativeProxy(child.stdout.str.trim());
|
||||||
|
libc.CreateMethod('execv');
|
||||||
|
}
|
||||||
|
catch(e)
|
||||||
|
{
|
||||||
|
if (sessionid != null) { sendConsoleText('Self Update failed: ' + e.toString(), sessionid) }
|
||||||
|
sendAgentMessage('Self Update failed: ' + e.toString(), 3);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var i;
|
||||||
|
var path = require('_GenericMarshal').CreateVariable(process.execPath);
|
||||||
|
var argarr = [];
|
||||||
|
var args;
|
||||||
|
var options = require('MeshAgent').getStartupOptions();
|
||||||
|
for(i in options)
|
||||||
|
{
|
||||||
|
argarr.push('--' + i + '="' + options[i] + '"');
|
||||||
|
}
|
||||||
|
args = require('_GenericMarshal').CreateVariable((1 + argarr.length) * require('_GenericMarshal').PointerSize);
|
||||||
|
for (i = 0; i < argarr.length; ++i)
|
||||||
|
{
|
||||||
|
var arg = require('_GenericMarshal').CreateVariable(argarr[i]);
|
||||||
|
arg.pointerBuffer().copy(args.toBuffer(), i * require('_GenericMarshal').PointerSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
libc.execv(path, args);
|
||||||
|
if (sessionid != null) { sendConsoleText('Self Update failed because execv() failed', sessionid) }
|
||||||
|
sendAgentMessage('Self Update failed because execv() failed', 3);
|
||||||
|
}
|
||||||
|
|
||||||
function windows_execve(name, agentfilename, sessionid)
|
function windows_execve(name, agentfilename, sessionid)
|
||||||
{
|
{
|
||||||
var libc;
|
var libc;
|
||||||
@ -180,7 +237,7 @@ function agentUpdate_Start(updateurl, updateoptions)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send an indication to the server that we got the update download correctly.
|
// Send an indication to the server that we got the update download correctly.
|
||||||
try { mesh.SendCommand({ action: 'agentupdatedownloaded' }); } catch (e) { }
|
try { require('MeshAgent').SendCommand({ action: 'agentupdatedownloaded' }); } catch (e) { }
|
||||||
|
|
||||||
if (sessionid != null) { sendConsoleText('Updating and restarting agent...', sessionid); }
|
if (sessionid != null) { sendConsoleText('Updating and restarting agent...', sessionid); }
|
||||||
if (process.platform == 'win32')
|
if (process.platform == 'win32')
|
||||||
@ -198,11 +255,18 @@ function agentUpdate_Start(updateurl, updateoptions)
|
|||||||
|
|
||||||
// copy update
|
// copy update
|
||||||
require('fs').copyFileSync(process.cwd() + agentfilename + '.update', process.execPath);
|
require('fs').copyFileSync(process.cwd() + agentfilename + '.update', process.execPath);
|
||||||
|
require('fs').chmodSync(process.execPath, m);
|
||||||
|
|
||||||
// erase update
|
// erase update
|
||||||
require('fs').unlinkSync(process.cwd() + agentfilename + '.update');
|
require('fs').unlinkSync(process.cwd() + agentfilename + '.update');
|
||||||
|
|
||||||
if (sessionid != null) { sendConsoleText('Restarting service...', sessionid); }
|
if (sessionid != null) { sendConsoleText('Restarting service...', sessionid); }
|
||||||
|
if (process.platform == 'freebsd')
|
||||||
|
{
|
||||||
|
bsd_execv(name, agentfilename, sessionid);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// restart service
|
// restart service
|
||||||
@ -215,6 +279,7 @@ function agentUpdate_Start(updateurl, updateoptions)
|
|||||||
sendAgentMessage('Self Update encountered an error trying to restart service', 3);
|
sendAgentMessage('Self Update encountered an error trying to restart service', 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
img.pipe(this._file);
|
img.pipe(this._file);
|
||||||
img.pipe(this._filehash);
|
img.pipe(this._filehash);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user