mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-20 18:23:21 +00:00
1. Fixed bug with clipboard.nativeAddCompressedModule for large files
2. Updated service-manager for better OpenBSD support
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -80,7 +80,8 @@ function nativeAddCompressedModule(name)
|
|||||||
ret += ('memcpy_s(_' + name.split('-').join('') + ' + ' + i + ', ' + (tmp.length - i) + ', "' + chunk + '", ' + chunk.length + ');\n');
|
ret += ('memcpy_s(_' + name.split('-').join('') + ' + ' + i + ', ' + (tmp.length - i) + ', "' + chunk + '", ' + chunk.length + ');\n');
|
||||||
i += chunk.length;
|
i += chunk.length;
|
||||||
}
|
}
|
||||||
ret += ('ILibDuktape_AddCompressedModule(ctx, "' + name + '", _' + name.split('-').join('') + valuex + ');\n');
|
valuex = valuex.split("'").join('"');
|
||||||
|
ret += ('ILibDuktape_AddCompressedModuleEx(ctx, "' + name + '", _' + name.split('-').join('') + valuex + ');\n');
|
||||||
ret += ('free(_' + name.split('-').join('') + ');\n');
|
ret += ('free(_' + name.split('-').join('') + ');\n');
|
||||||
}
|
}
|
||||||
module.exports(ret);
|
module.exports(ret);
|
||||||
|
|||||||
@@ -1059,6 +1059,8 @@ function serviceManager()
|
|||||||
this.getService = function getService(name)
|
this.getService = function getService(name)
|
||||||
{
|
{
|
||||||
var ret = { name: name, close: function () { } };
|
var ret = { name: name, close: function () { } };
|
||||||
|
Object.defineProperty(ret, "OpenBSD", { value: !require('fs').existsSync('/usr/sbin/daemon') });
|
||||||
|
|
||||||
if(require('fs').existsSync('/etc/rc.d/' + name))
|
if(require('fs').existsSync('/etc/rc.d/' + name))
|
||||||
{
|
{
|
||||||
Object.defineProperty(ret, 'rc', { value: '/etc/rc.d/' + name });
|
Object.defineProperty(ret, 'rc', { value: '/etc/rc.d/' + name });
|
||||||
@@ -1075,12 +1077,26 @@ function serviceManager()
|
|||||||
{
|
{
|
||||||
get: function ()
|
get: function ()
|
||||||
{
|
{
|
||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
if (!this.OpenBSD)
|
||||||
child.stderr.on('data', function (c) { });
|
{
|
||||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
// FreeBSD
|
||||||
child.stdin.write('service ' + this.name + ' rcvar | grep _enable= | awk \'{ a=split($0, b, "\\""); if(b[2]=="YES") { print "YES"; } }\'\nexit\n');
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.waitExit();
|
child.stderr.on('data', function (c) { });
|
||||||
return (child.stdout.str.trim() == '' ? 'DEMAND_START' : 'AUTO_START');
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
|
child.stdin.write('service ' + this.name + ' rcvar | grep _enable= | awk \'{ a=split($0, b, "\\""); if(b[2]=="YES") { print "YES"; } }\'\nexit\n');
|
||||||
|
child.waitExit();
|
||||||
|
return (child.stdout.str.trim() == '' ? 'DEMAND_START' : 'AUTO_START');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// OpenBSD
|
||||||
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
|
child.stderr.on('data', function (c) { });
|
||||||
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
|
child.stdin.write('rcctl ls on | awk \'{ if($0=="' + this.name + '") { print "AUTO_START"; } }\'\nexit\n');
|
||||||
|
child.waitExit();
|
||||||
|
return (child.stdout.str.trim() == '' ? 'DEMAND_START' : 'AUTO_START');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1117,6 +1133,16 @@ function serviceManager()
|
|||||||
|
|
||||||
ret.appLocation = function appLocation()
|
ret.appLocation = function appLocation()
|
||||||
{
|
{
|
||||||
|
if (this.OpenBSD)
|
||||||
|
{
|
||||||
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
|
child.stdin.write("cat " + this.rc + " | grep daemon= | awk '{ if($0 ~ /_loader\"$/) { gsub(/^daemon=/,\"\", $0); gsub(/_loader\"$/,\"\\\"\",$0); print $0; } else { gsub(/^daemon=/,\"\",$0); print $0; } }'\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
var ret = child.stdout.str.trim();
|
||||||
|
if (ret != '') { ret = ret.substring(1, ret.length - 1); }
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
child.stdin.write("cat " + this.rc + " | grep command= | awk -F= '{ print $2 }' | awk -F\\\" '{ print $2 }'\nexit\n");
|
child.stdin.write("cat " + this.rc + " | grep command= | awk -F= '{ print $2 }' | awk -F\\\" '{ print $2 }'\nexit\n");
|
||||||
@@ -1152,6 +1178,16 @@ function serviceManager()
|
|||||||
};
|
};
|
||||||
ret.isRunning = function isRunning()
|
ret.isRunning = function isRunning()
|
||||||
{
|
{
|
||||||
|
if (this.OpenBSD)
|
||||||
|
{
|
||||||
|
// OpenBSD
|
||||||
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
|
child.stderr.on('data', function (c) { });
|
||||||
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
|
child.stdin.write('rcctl ls started | awk \'{ if($0=="' + this.name + '") { print "STARTED"; } }\'\nexit\n');
|
||||||
|
child.waitExit();
|
||||||
|
return (child.stdout.str.trim() == '' ? false : true);
|
||||||
|
}
|
||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
child.stdin.write("service " + this.name + " onestatus | awk '{ print $3 }'\nexit\n");
|
child.stdin.write("service " + this.name + " onestatus | awk '{ print $3 }'\nexit\n");
|
||||||
@@ -1179,17 +1215,37 @@ function serviceManager()
|
|||||||
};
|
};
|
||||||
ret.stop = function stop()
|
ret.stop = function stop()
|
||||||
{
|
{
|
||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
if (this.OpenBSD)
|
||||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
{
|
||||||
child.stdin.write("service " + this.name + " onestop\nexit\n");
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.waitExit();
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
|
child.stdin.write("rcctl stop " + this.name + "\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
|
child.stdin.write("service " + this.name + " onestop\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
ret.start = function start()
|
ret.start = function start()
|
||||||
{
|
{
|
||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
if (this.OpenBSD)
|
||||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
{
|
||||||
child.stdin.write("service " + this.name + " onestart\nexit\n");
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.waitExit();
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
|
child.stdin.write("rcctl start " + this.name + "\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
|
child.stdin.write("service " + this.name + " onestart\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
ret.restart = function restart()
|
ret.restart = function restart()
|
||||||
{
|
{
|
||||||
@@ -2331,30 +2387,58 @@ function serviceManager()
|
|||||||
{
|
{
|
||||||
if (!this.isAdmin()) { console.log('Installing a Service requires root'); throw ('Installing as Service, requires root'); }
|
if (!this.isAdmin()) { console.log('Installing a Service requires root'); throw ('Installing as Service, requires root'); }
|
||||||
var parameters = options.parameters ? options.parameters.join(' ') : '';
|
var parameters = options.parameters ? options.parameters.join(' ') : '';
|
||||||
|
var m;
|
||||||
|
if (require('fs').existsSync('/usr/sbin/daemon'))
|
||||||
|
{
|
||||||
|
// FreeBSD
|
||||||
|
var rc = require('fs').createWriteStream('/usr/local/etc/rc.d/' + options.name, { flags: 'wb' });
|
||||||
|
rc.write('#!/bin/sh\n');
|
||||||
|
rc.write('# PROVIDE: ' + options.name + '\n');
|
||||||
|
rc.write('# REQUIRE: FILESYSTEMS NETWORKING\n');
|
||||||
|
rc.write('# KEYWORD: shutdown\n');
|
||||||
|
rc.write('. /etc/rc.subr\n\n');
|
||||||
|
rc.write('name="' + options.name + '"\n');
|
||||||
|
rc.write('desc="' + (options.description ? options.description : 'MeshCentral Agent') + '"\n');
|
||||||
|
rc.write('rcvar=${name}_enable\n');
|
||||||
|
rc.write('pidfile="/var/run/' + options.name + '.pid"\n');
|
||||||
|
rc.write(options.name + '_chdir="' + options.installPath.split(' ').join('\\ ') + '"\n');
|
||||||
|
|
||||||
var rc = require('fs').createWriteStream('/usr/local/etc/rc.d/' + options.name, { flags: 'wb' });
|
rc.write('command="/usr/sbin/daemon"\n');
|
||||||
rc.write('#!/bin/sh\n');
|
rc.write('command_args="-P ${pidfile} ' + ((options.failureRestart == null || options.failureRestart > 0) ? '-r' : '') + ' -f \\"' + options.installPath + options.target + '\\" ' + parameters.split('"').join('\\"') + '"\n');
|
||||||
rc.write('# PROVIDE: ' + options.name + '\n');
|
|
||||||
rc.write('# REQUIRE: FILESYSTEMS NETWORKING\n');
|
|
||||||
rc.write('# KEYWORD: shutdown\n');
|
|
||||||
rc.write('. /etc/rc.subr\n\n');
|
|
||||||
rc.write('name="' + options.name + '"\n');
|
|
||||||
rc.write('desc="' + (options.description ? options.description : 'MeshCentral Agent') + '"\n');
|
|
||||||
rc.write('rcvar=${name}_enable\n');
|
|
||||||
rc.write('pidfile="/var/run/' + options.name + '.pid"\n');
|
|
||||||
rc.write(options.name + '_chdir="' + options.installPath.split(' ').join('\\ ') + '"\n');
|
|
||||||
|
|
||||||
rc.write('command="/usr/sbin/daemon"\n');
|
rc.write('\n');
|
||||||
rc.write('command_args="-P ${pidfile} ' + ((options.failureRestart == null || options.failureRestart > 0) ? '-r' : '') + ' -f \\"' + options.installPath + options.target + '\\" ' + parameters.split('"').join('\\"') + '"\n');
|
rc.write('load_rc_config $name\n');
|
||||||
|
rc.write(': ${' + options.name + '_enable="' + ((options.startType == 'AUTO_START' || options.startType == 'BOOT_START') ? 'YES' : 'NO') + '"}\n');
|
||||||
|
rc.write('run_rc_command "$1"\n');
|
||||||
|
rc.end();
|
||||||
|
m = require('fs').statSync('/usr/local/etc/rc.d/' + options.name).mode;
|
||||||
|
m |= (require('fs').CHMOD_MODES.S_IXUSR | require('fs').CHMOD_MODES.S_IXGRP | require('fs').CHMOD_MODES.S_IXOTH);
|
||||||
|
require('fs').chmodSync('/usr/local/etc/rc.d/' + options.name, m);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// OpenBSD
|
||||||
|
var script = "require('service-manager').manager.daemonEx('" + options.installPath + options.target + "', " + JSON.stringify(options.parameters) + ", {crashRestart: " + ((options.failureRestart == null || options.failureRestart > 0) ? "true" : "false") + ', cwd: "' + options.installPath.split(' ').join('\\ ') + '"});';
|
||||||
|
script = Buffer.from(script).toString('base64');
|
||||||
|
|
||||||
rc.write('\n');
|
var rc = require('fs').createWriteStream('/etc/rc.d/' + options.name, { flags: 'wb' });
|
||||||
rc.write('load_rc_config $name\n');
|
rc.write('#!/bin/sh\n');
|
||||||
rc.write(': ${' + options.name + '_enable="' + ((options.startType == 'AUTO_START' || options.startType == 'BOOT_START')?'YES':'NO') + '"}\n');
|
rc.write('# PROVIDE: ' + options.name + '\n');
|
||||||
rc.write('run_rc_command "$1"\n');
|
rc.write('name="' + options.name + '"\n');
|
||||||
rc.end();
|
rc.write('desc="' + (options.description ? options.description : 'MeshCentral Agent') + '"\n');
|
||||||
var m = require('fs').statSync('/usr/local/etc/rc.d/' + options.name).mode;
|
rc.write(options.name + '_chdir="' + options.installPath.split(' ').join('\\ ') + '"\n');
|
||||||
m |= (require('fs').CHMOD_MODES.S_IXUSR | require('fs').CHMOD_MODES.S_IXGRP | require('fs').CHMOD_MODES.S_IXOTH);
|
rc.write('daemon="' + options.installPath + options.target + '_loader"\n');
|
||||||
require('fs').chmodSync('/usr/local/etc/rc.d/' + options.name, m);
|
rc.write('daemon_flags="-b64exec ' + script + ' &"\n');
|
||||||
|
rc.write('. /etc/rc.d/rc.subr\n\n');
|
||||||
|
rc.write('rc_cmd "$1"\n');
|
||||||
|
rc.end();
|
||||||
|
m = require('fs').statSync('/etc/rc.d/' + options.name).mode;
|
||||||
|
m |= (require('fs').CHMOD_MODES.S_IXUSR | require('fs').CHMOD_MODES.S_IXGRP | require('fs').CHMOD_MODES.S_IXOTH);
|
||||||
|
require('fs').chmodSync('/etc/rc.d/' + options.name, m);
|
||||||
|
|
||||||
|
require('fs').copyFileSync(process.execPath, options.installPath + options.target + '_loader');
|
||||||
|
require('fs').chmodSync(options.installPath + options.target + '_loader', m);
|
||||||
|
}
|
||||||
|
|
||||||
if ((this.pfSense || this.OPNsense) && (options.startType == 'AUTO_START' || options.startType == 'BOOT_START'))
|
if ((this.pfSense || this.OPNsense) && (options.startType == 'AUTO_START' || options.startType == 'BOOT_START'))
|
||||||
{
|
{
|
||||||
@@ -3185,6 +3269,42 @@ function serviceManager()
|
|||||||
var child = require('child_process').execFile(process.execPath, options._parms, options);
|
var child = require('child_process').execFile(process.execPath, options._parms, options);
|
||||||
if (!child) { throw ('Error spawning process'); }
|
if (!child) { throw ('Error spawning process'); }
|
||||||
}
|
}
|
||||||
|
this.daemonEx = function daemonEx(path, parameters, options)
|
||||||
|
{
|
||||||
|
parameters.unshift(process.platform == 'win32' ? path.split('\\').pop() : path.split('/').pop());
|
||||||
|
if (options.cwd) { process.chdir(options.cwd); }
|
||||||
|
|
||||||
|
function spawnChild()
|
||||||
|
{
|
||||||
|
global.child = require('child_process').execFile(path, parameters);
|
||||||
|
if(global.child)
|
||||||
|
{
|
||||||
|
global.child.stdout.on('data', function(c) { console.log(c.toString()); });
|
||||||
|
global.child.stderr.on('data', function(c) { console.log(c.toString()); });
|
||||||
|
global.child.once('exit', function (code)
|
||||||
|
{
|
||||||
|
if(options.crashRestart) { spawnChild(); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(options.logOutput)
|
||||||
|
{
|
||||||
|
console.setDestination(console.Destinations.LOGFILE);
|
||||||
|
console.log('Logging Outputs...');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
console.setDestination(console.Destinations.DISABLED);
|
||||||
|
}
|
||||||
|
if(options.cwd) { process.chdir(options.cwd); }
|
||||||
|
spawnChild();
|
||||||
|
process.on('SIGTERM', function()
|
||||||
|
{
|
||||||
|
if(global.child) { child.kill(); }
|
||||||
|
process.exit();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = serviceManager;
|
module.exports = serviceManager;
|
||||||
|
|||||||
Reference in New Issue
Block a user