mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-11-22 22:17:31 +03:00
More base updates, including web socket handling and display logic
This commit is contained in:
parent
aa32bac323
commit
ef79477d25
30
agents/meshcore.min.js
vendored
30
agents/meshcore.min.js
vendored
@ -1491,6 +1491,36 @@ function createMeshCore(agent)
|
||||
// Unknown action, ignore it.
|
||||
break;
|
||||
}
|
||||
} else if (this.httprequest.protocol == 7) { // plugin data exchange
|
||||
var cmd = null;
|
||||
try { cmd = JSON.parse(data); } catch (e) { };
|
||||
if (cmd == null) { return; }
|
||||
if ((cmd.ctrlChannel == '102938') || ((cmd.type == 'offer') && (cmd.sdp != null))) { onTunnelControlData(cmd, this); return; } // If this is control data, handle it now.
|
||||
if (cmd.action == undefined) { return; }
|
||||
//sendConsoleText('CMD: ' + JSON.stringify(cmd));
|
||||
|
||||
if ((cmd.path != null) && (process.platform != 'win32') && (cmd.path[0] != '/')) { cmd.path = '/' + cmd.path; } // Add '/' to paths on non-windows
|
||||
//console.log(objToString(cmd, 0, ' '));
|
||||
|
||||
switch (cmd.action) {
|
||||
case 'plugin': {
|
||||
try {
|
||||
require(cmd.plugin).consoleaction(cmd, null, null, this);
|
||||
} catch (e) {
|
||||
/*var fs = require('fs');
|
||||
var logStream = fs.createWriteStream('log.txt', {'flags': 'a'});
|
||||
logStream.write('\nCouldnt load plugin '+e+e.stack);
|
||||
logStream.end('\n')*/
|
||||
throw e;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
// probably shouldn't happen, but just in case this feature is expanded
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//sendConsoleText("Got tunnel #" + this.httprequest.index + " data: " + data, this.httprequest.sessionid);
|
||||
}
|
||||
|
11
meshuser.js
11
meshuser.js
@ -2963,6 +2963,17 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'plugin': {
|
||||
command.userid = user._id;
|
||||
|
||||
if (command.routeToNode === true) {
|
||||
routeCommandToNode(command);
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
// Unknown user action
|
||||
console.log('Unknown action from user ' + user.name + ': ' + command.action + '.');
|
||||
|
@ -33,7 +33,7 @@ module.exports.pluginHandler = function (parent) {
|
||||
obj.plugins[plugin] = require(obj.pluginPath + '/' + plugin + '/' + plugin + '.js')[plugin](obj);
|
||||
obj.exports[plugin] = obj.plugins[plugin].exports;
|
||||
} catch (e) {
|
||||
console.log("Error loading plugin: " + plugin + " (" + e + "). It has been disabled");
|
||||
console.log("Error loading plugin: " + plugin + " (" + e + "). It has been disabled.", e.stack);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -49,7 +49,27 @@ module.exports.pluginHandler = function (parent) {
|
||||
str += ' obj.'+ p +'.'+ l + ' = '+ obj.plugins[p][l].toString()+'\r\n';
|
||||
}
|
||||
}
|
||||
str += 'return obj; };\r\n';
|
||||
|
||||
str += 'obj.enabled = '+ obj.enabled +';\r\n';
|
||||
str += `obj.onDeviceRefeshEnd = function(nodeid, panel, refresh, event) {
|
||||
for (const p of Object.keys(obj)) {
|
||||
if (typeof obj[p].onDeviceRefreshEnd == 'function') {
|
||||
obj[p].onDeviceRefreshEnd(nodeid, panel, refresh, event);
|
||||
}
|
||||
}
|
||||
};
|
||||
obj.registerPluginTab = function(pluginRegInfo) {
|
||||
var d = pluginRegInfo();
|
||||
QA('p19headers', '<span onclick="return pluginHandler.callPluginPage(\\''+d.tabId+'\\');">'+d.tabTitle+'</span>');
|
||||
};
|
||||
obj.callPluginPage = function(id) {
|
||||
var pages = Q('p19pages').querySelectorAll("#p19pages>div");
|
||||
for (const i of pages) {
|
||||
i.style.display = 'none';
|
||||
}
|
||||
QV(id, true);
|
||||
};
|
||||
return obj; };`;
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -844,9 +844,23 @@
|
||||
</div>
|
||||
<div id=p19 style="display:none">
|
||||
<h1>Plugins - <span id=p19deviceName></span></h1>
|
||||
<div class="p19headers">
|
||||
</div>
|
||||
<div id=p19pages style=""></div>
|
||||
<style>
|
||||
#p19headers {
|
||||
padding-right: 7px;
|
||||
padding-bottom: 10px;
|
||||
font-weight: bold;
|
||||
border-bottom: 1px dotted blue;
|
||||
}
|
||||
#p19headers > span:nth-child(n+2) {
|
||||
border-left: 1px solid black;
|
||||
}
|
||||
#p19headers > span {
|
||||
padding-left: 4px;
|
||||
padding-right: 4px;
|
||||
}
|
||||
</style>
|
||||
<div id="p19headers"></div>
|
||||
<div id=p19pages></div>
|
||||
</div>
|
||||
<br id="column_l_bottomgap" />
|
||||
</div>
|
||||
@ -1015,7 +1029,8 @@
|
||||
var nightMode = (getstore('_nightMode', '0') == '1');
|
||||
var sessionActivity = Date.now();
|
||||
var updateSessionTimer = null;
|
||||
var pluginHandler = {{{pluginHandler}}};
|
||||
var pluginHandlerBuilder = {{{pluginHandler}}};
|
||||
var pluginHandler = new pluginHandlerBuilder();
|
||||
|
||||
// Console Message Display Timers
|
||||
var p11DeskConsoleMsgTimer = null;
|
||||
@ -2309,8 +2324,7 @@
|
||||
case 'plugin': {
|
||||
if (typeof message.plugin == 'string') {
|
||||
try {
|
||||
var ph = pluginHandler();
|
||||
ph[message.plugin][message.method](server, message);
|
||||
pluginHandler[message.plugin][message.method](server, message);
|
||||
} catch (e) {
|
||||
console.log('Error loading plugin handler ('+ e + ')');
|
||||
}
|
||||
@ -4149,6 +4163,7 @@
|
||||
QH('p15deviceName', 'Console - ' + nname);
|
||||
QH('p16deviceName', nname);
|
||||
QH('p17deviceName', nname);
|
||||
QH('p19deviceName', nname);
|
||||
|
||||
// Node attributes
|
||||
var x = '<table style=width:100%>';
|
||||
@ -4404,6 +4419,8 @@
|
||||
p11clearConsoleMsg();
|
||||
p12clearConsoleMsg();
|
||||
p13clearConsoleMsg();
|
||||
|
||||
pluginHandler.onDeviceRefeshEnd(nodeid, panel, refresh, event);
|
||||
}
|
||||
setupDesktop(); // Always refresh the desktop, even if we are on the same device, we need to do some canvas switching.
|
||||
if (!panel) panel = 10;
|
||||
|
Loading…
Reference in New Issue
Block a user