mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-03-09 15:40:18 +00:00
Added terminal start command option
This commit is contained in:
parent
5a174a2230
commit
adae944146
5 changed files with 45 additions and 24 deletions
|
@ -87,7 +87,7 @@ if (require('MeshAgent').ARCHID == null) {
|
||||||
}
|
}
|
||||||
if (id != null) { Object.defineProperty(require('MeshAgent'), 'ARCHID', { value: id }); }
|
if (id != null) { Object.defineProperty(require('MeshAgent'), 'ARCHID', { value: id }); }
|
||||||
}
|
}
|
||||||
var obj = {};
|
var obj = { serverInfo: {} };
|
||||||
var agentFileHttpRequests = {}; // Currently active agent HTTPS GET requests from the server.
|
var agentFileHttpRequests = {}; // Currently active agent HTTPS GET requests from the server.
|
||||||
var agentFileHttpPendingRequests = []; // Pending HTTPS GET requests from the server.
|
var agentFileHttpPendingRequests = []; // Pending HTTPS GET requests from the server.
|
||||||
var debugConsole = (global._MSH && (_MSH().debugConsole == 1));
|
var debugConsole = (global._MSH && (_MSH().debugConsole == 1));
|
||||||
|
@ -1375,6 +1375,10 @@ function handleServerCommand(data) {
|
||||||
agentFileHttpPendingRequests.push(data);
|
agentFileHttpPendingRequests.push(data);
|
||||||
serverFetchFile();
|
serverFetchFile();
|
||||||
break;
|
break;
|
||||||
|
case 'serverInfo': // Server information
|
||||||
|
obj.serverInfo = data;
|
||||||
|
delete obj.serverInfo.action;
|
||||||
|
break;
|
||||||
case 'errorlog': // Return agent error log
|
case 'errorlog': // Return agent error log
|
||||||
try { mesh.SendCommand(JSON.stringify({ action: 'errorlog', log: require('util-agentlog').read(data.startTime) })); } catch (ex) { }
|
try { mesh.SendCommand(JSON.stringify({ action: 'errorlog', log: require('util-agentlog').read(data.startTime) })); } catch (ex) { }
|
||||||
break;
|
break;
|
||||||
|
@ -1922,14 +1926,7 @@ function onTunnelData(data) {
|
||||||
// The above line is commented out, because there is a bug with ClosePseudoConsole() API, so this is the workaround
|
// The above line is commented out, because there is a bug with ClosePseudoConsole() API, so this is the workaround
|
||||||
this.httprequest._dispatcher = require('win-dispatcher').dispatch({ modules: [{ name: 'win-virtual-terminal', script: getJSModule('win-virtual-terminal') }], launch: { module: 'win-virtual-terminal', method: (this.httprequest.protocol == 6 ? 'StartPowerShell' : 'Start'), args: [cols, rows] } });
|
this.httprequest._dispatcher = require('win-dispatcher').dispatch({ modules: [{ name: 'win-virtual-terminal', script: getJSModule('win-virtual-terminal') }], launch: { module: 'win-virtual-terminal', method: (this.httprequest.protocol == 6 ? 'StartPowerShell' : 'Start'), args: [cols, rows] } });
|
||||||
this.httprequest._dispatcher.httprequest = this.httprequest;
|
this.httprequest._dispatcher.httprequest = this.httprequest;
|
||||||
this.httprequest._dispatcher.on('connection', function (c) {
|
this.httprequest._dispatcher.on('connection', function (c) { if (this.httprequest.connectionPromise.completed) { c.end(); } else { this.httprequest.connectionPromise._res(c); } });
|
||||||
if (this.httprequest.connectionPromise.completed) {
|
|
||||||
c.end();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.httprequest.connectionPromise._res(c);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Legacy Terminal
|
// Legacy Terminal
|
||||||
|
@ -1954,14 +1951,7 @@ function onTunnelData(data) {
|
||||||
that.httprequest._dispatcher = require('win-dispatcher').dispatch({ user: username, modules: [{ name: 'win-terminal', script: getJSModule('win-terminal') }], launch: { module: 'win-terminal', method: (that.httprequest.protocol == 9 ? 'StartPowerShell' : 'Start'), args: [cols, rows] } });
|
that.httprequest._dispatcher = require('win-dispatcher').dispatch({ user: username, modules: [{ name: 'win-terminal', script: getJSModule('win-terminal') }], launch: { module: 'win-terminal', method: (that.httprequest.protocol == 9 ? 'StartPowerShell' : 'Start'), args: [cols, rows] } });
|
||||||
}
|
}
|
||||||
that.httprequest._dispatcher.ws = that;
|
that.httprequest._dispatcher.ws = that;
|
||||||
that.httprequest._dispatcher.on('connection', function (c) {
|
that.httprequest._dispatcher.on('connection', function (c) { if (this.ws.httprequest.connectionPromise.completed) { c.end(); } else { this.ws.httprequest.connectionPromise._res(c); } });
|
||||||
if (this.ws.httprequest.connectionPromise.completed) {
|
|
||||||
c.end();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.ws.httprequest.connectionPromise._res(c);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1992,13 +1982,15 @@ function onTunnelData(data) {
|
||||||
else if (bash) {
|
else if (bash) {
|
||||||
var p = childProcess.execFile(bash, ['bash'], options); // Start bash
|
var p = childProcess.execFile(bash, ['bash'], options); // Start bash
|
||||||
// Spaces at the beginning of lines are needed to hide commands from the command history
|
// Spaces at the beginning of lines are needed to hide commands from the command history
|
||||||
if (process.platform == 'linux') { p.stdin.write(' alias ls=\'ls --color=auto\';clear\n'); }
|
if ((obj.serverInfo.termlaunchcommand != null) && (typeof obj.serverInfo.termlaunchcommand[process.platform] == 'string')) { p.stdin.write(obj.serverInfo.termlaunchcommand[process.platform]); }
|
||||||
|
else if (process.platform == 'linux') { p.stdin.write(' alias ls=\'ls --color=auto\';clear\n'); }
|
||||||
this.httprequest.connectionPromise._res(p);
|
this.httprequest.connectionPromise._res(p);
|
||||||
}
|
}
|
||||||
else if (sh) {
|
else if (sh) {
|
||||||
var p = childProcess.execFile(sh, ['sh'], options); // Start sh
|
var p = childProcess.execFile(sh, ['sh'], options); // Start sh
|
||||||
// Spaces at the beginning of lines are needed to hide commands from the command history
|
// Spaces at the beginning of lines are needed to hide commands from the command history
|
||||||
if (process.platform == 'linux') { p.stdin.write(' alias ls=\'ls --color=auto\';clear\n'); }
|
if ((obj.serverInfo.termlaunchcommand != null) && (typeof obj.serverInfo.termlaunchcommand[process.platform] == 'string')) { p.stdin.write(obj.serverInfo.termlaunchcommand[process.platform]); }
|
||||||
|
else if (process.platform == 'linux') { p.stdin.write(' alias ls=\'ls --color=auto\';clear\n'); }
|
||||||
this.httprequest.connectionPromise._res(p);
|
this.httprequest.connectionPromise._res(p);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
6
db.js
6
db.js
|
@ -1970,7 +1970,7 @@ module.exports.CreateDB = function (parent, func) {
|
||||||
var output = parent.fs.createWriteStream(newAutoBackupPath + '.zip');
|
var output = parent.fs.createWriteStream(newAutoBackupPath + '.zip');
|
||||||
var archive = null;
|
var archive = null;
|
||||||
if (parent.config.settings.autobackup && (typeof parent.config.settings.autobackup.zippassword == 'string')) {
|
if (parent.config.settings.autobackup && (typeof parent.config.settings.autobackup.zippassword == 'string')) {
|
||||||
try { archiver.registerFormat('zip-encrypted', require("archiver-zip-encrypted")); } catch (ex) { }
|
try { archiver.registerFormat('zip-encrypted', require('archiver-zip-encrypted')); } catch (ex) { }
|
||||||
archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword });
|
archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword });
|
||||||
} else {
|
} else {
|
||||||
archive = archiver('zip', { zlib: { level: 9 } });
|
archive = archiver('zip', { zlib: { level: 9 } });
|
||||||
|
@ -2009,7 +2009,7 @@ module.exports.CreateDB = function (parent, func) {
|
||||||
var output = parent.fs.createWriteStream(newAutoBackupPath + '.zip');
|
var output = parent.fs.createWriteStream(newAutoBackupPath + '.zip');
|
||||||
var archive = null;
|
var archive = null;
|
||||||
if (parent.config.settings.autobackup && (typeof parent.config.settings.autobackup.zippassword == 'string')) {
|
if (parent.config.settings.autobackup && (typeof parent.config.settings.autobackup.zippassword == 'string')) {
|
||||||
try { archiver.registerFormat('zip-encrypted', require("archiver-zip-encrypted")); } catch (ex) { }
|
try { archiver.registerFormat('zip-encrypted', require('archiver-zip-encrypted')); } catch (ex) { }
|
||||||
archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword });
|
archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword });
|
||||||
} else {
|
} else {
|
||||||
archive = archiver('zip', { zlib: { level: 9 } });
|
archive = archiver('zip', { zlib: { level: 9 } });
|
||||||
|
@ -2036,7 +2036,7 @@ module.exports.CreateDB = function (parent, func) {
|
||||||
var output = parent.fs.createWriteStream(newAutoBackupPath + '.zip');
|
var output = parent.fs.createWriteStream(newAutoBackupPath + '.zip');
|
||||||
var archive = null;
|
var archive = null;
|
||||||
if (parent.config.settings.autobackup && (typeof parent.config.settings.autobackup.zippassword == 'string')) {
|
if (parent.config.settings.autobackup && (typeof parent.config.settings.autobackup.zippassword == 'string')) {
|
||||||
try { archiver.registerFormat('zip-encrypted', require("archiver-zip-encrypted")); } catch (ex) { }
|
try { archiver.registerFormat('zip-encrypted', require('archiver-zip-encrypted')); } catch (ex) { }
|
||||||
archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword });
|
archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword });
|
||||||
} else {
|
} else {
|
||||||
archive = archiver('zip', { zlib: { level: 9 } });
|
archive = archiver('zip', { zlib: { level: 9 } });
|
||||||
|
|
13
meshagent.js
13
meshagent.js
|
@ -1076,6 +1076,19 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Indicate server information to the agent.
|
||||||
|
var serverInfo = { action: 'serverInfo' };
|
||||||
|
if ((typeof domain.terminal == 'object') && (typeof domain.terminal.launchcommand == 'object')) {
|
||||||
|
// Send terminal starting command
|
||||||
|
serverInfo.termlaunchcommand = {};
|
||||||
|
if (typeof domain.terminal.launchcommand.linux == 'string') { serverInfo.termlaunchcommand.linux = domain.terminal.launchcommand.linux; }
|
||||||
|
if (typeof domain.terminal.launchcommand.darwin == 'string') { serverInfo.termlaunchcommand.darwin = domain.terminal.launchcommand.darwin; }
|
||||||
|
if (typeof domain.terminal.launchcommand.freebsd == 'string') { serverInfo.termlaunchcommand.freebsd = domain.terminal.launchcommand.freebsd; }
|
||||||
|
}
|
||||||
|
obj.send(JSON.stringify(serverInfo));
|
||||||
|
|
||||||
|
// Plug in handler
|
||||||
if (parent.parent.pluginHandler != null) {
|
if (parent.parent.pluginHandler != null) {
|
||||||
parent.parent.pluginHandler.callHook('hook_agentCoreIsStable', obj, parent);
|
parent.parent.pluginHandler.callHook('hook_agentCoreIsStable', obj, parent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -507,10 +507,18 @@
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Values that affect the terminal feature",
|
"description": "Values that affect the terminal feature",
|
||||||
"properties": {
|
"properties": {
|
||||||
"linuxshell": {
|
"linuxShell": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [ "any", "root", "user", "login" ],
|
"enum": [ "any", "root", "user", "login" ],
|
||||||
"default": "any"
|
"default": "any",
|
||||||
|
"description": "Indicate what terminal options are available when the user clicks the right mouse button on the terminal connect button."
|
||||||
|
},
|
||||||
|
"launchCommand": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "Indicate what string the agent must write to the shell after starting a terminal session",
|
||||||
|
"linux": { "type": "string", "default": " alias ls=\\'ls --color=auto\\';clear\\n", "description": "String to write after opening a Linux terminal." },
|
||||||
|
"darwin": { "type": "string", "default": null, "description": "String to write after opening a macOS terminal." },
|
||||||
|
"freebsd": { "type": "string", "default": null, "description": "String to write after opening a FreeBSD terminal." },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -262,6 +262,14 @@
|
||||||
"_maxAgentSessions": 100,
|
"_maxAgentSessions": 100,
|
||||||
"maxSingleUserSessions": 10
|
"maxSingleUserSessions": 10
|
||||||
},
|
},
|
||||||
|
"_terminal": {
|
||||||
|
"_linuxshell": "login",
|
||||||
|
"launchCommand": {
|
||||||
|
"linux": "clear\necho \"Hello Linux\"\n",
|
||||||
|
"darwin": "clear\necho \"Hello MacOS\"\n",
|
||||||
|
"freebsd": "clear\necho \"Hello FreeBSD\"\n"
|
||||||
|
}
|
||||||
|
},
|
||||||
"_amtScanOptions": [
|
"_amtScanOptions": [
|
||||||
"LabNetwork 192.168.15.0/23",
|
"LabNetwork 192.168.15.0/23",
|
||||||
"SalesNetwork 192.168.8.0/24"
|
"SalesNetwork 192.168.8.0/24"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue