1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-03-09 15:40:18 +00:00

Database performance fix + Server side clipboard support.

This commit is contained in:
Ylian Saint-Hilaire 2019-02-16 21:16:39 -08:00
parent 7b47c24f5c
commit 9bb2b70341
10 changed files with 307 additions and 14 deletions

View file

@ -466,6 +466,21 @@ function createMeshCore(agent) {
if (data.url) { mesh.SendCommand({ "action": "msg", "type":"openUrl", "url": data.url, "sessionid": data.sessionid, "success": (openUserDesktopUrl(data.url) != null) }); }
break;
}
case 'getclip': {
// Send the load clipboard back to the user
sendConsoleText('getClip: ' + JSON.stringify(data));
require("clipboard").read().then(function (str) { mesh.SendCommand({ "action": "msg", "type": "getclip", "sessionid": data.sessionid, "data": str }); });
break;
}
case 'setclip': {
// Set the load clipboard to a user value
sendConsoleText('setClip: ' + JSON.stringify(data));
if (typeof data.data == 'string') {
require("clipboard")(data.data); // Set the clipboard
mesh.SendCommand({ "action": "msg", "type": "setclip", "sessionid": data.sessionid, "success": true });
}
break;
}
default:
// Unknown action, ignore it.
break;
@ -1108,7 +1123,7 @@ function createMeshCore(agent) {
var response = null;
switch (cmd) {
case 'help': { // Displays available commands
response = 'Available commands: help, info, osinfo,args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast, lock, users, sendcaps, openurl, amtreset, amtccm, amtdeactivate,\r\namtpolicy, getscript.';
response = 'Available commands: help, info, osinfo,args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast, lock, users, sendcaps, openurl, amtreset, amtccm, amtdeactivate,\r\namtpolicy, getscript, getclip, setclip.';
break;
}
/*
@ -1130,6 +1145,14 @@ function createMeshCore(agent) {
}
break;
*/
case 'getclip': {
require("clipboard").read().then(function (str) { sendConsoleText(str, sessionid); });
break;
}
case 'setclip': {
if (args['_'].length != 1) { response = 'Proper usage: setclip (text)'; } else { require("clipboard")(args['_'][0]); response = 'Setting clipboard to: ' + args['_'][0]; }
break;
}
case 'amtreset': {
resetMei();
resetMicroLms();

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,178 @@
/*
Copyright 2019 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var promise = require('promise');
function nativeAddModule(name)
{
var value = getJSModule(name);
var ret = "duk_peval_string_noresult(ctx, \"addModule('" + name + "', Buffer.from('" + Buffer.from(value).toString('base64') + "', 'base64').toString());\");";
module.exports(ret);
}
function lin_readtext()
{
var ret = new promise(function (res, rej) { this._res = res; this._rej = rej; });
try
{
require('monitor-info')
}
catch(exc)
{
ret._rej(exc);
return (ret);
}
var X11 = require('monitor-info')._X11;
if (!X11)
{
ret._rej('X11 required for Clipboard Manipulation');
}
else
{
var SelectionNotify = 31;
var AnyPropertyType = 0;
var GM = require('monitor-info')._gm;
ret._getInfoPromise = require('monitor-info').getInfo();
ret._getInfoPromise._masterPromise = ret;
ret._getInfoPromise.then(function (mon)
{
if (mon.length > 0)
{
var white = X11.XWhitePixel(mon[0].display, mon[0].screenId).Val;
this._masterPromise.CLIPID = X11.XInternAtom(mon[0].display, GM.CreateVariable('CLIPBOARD'), 0);
this._masterPromise.FMTID = X11.XInternAtom(mon[0].display, GM.CreateVariable('UTF8_STRING'), 0);
this._masterPromise.PROPID = X11.XInternAtom(mon[0].display, GM.CreateVariable('XSEL_DATA'), 0);
this._masterPromise.INCRID = X11.XInternAtom(mon[0].display, GM.CreateVariable('INCR'), 0);
this._masterPromise.ROOTWIN = X11.XRootWindow(mon[0].display, mon[0].screenId);
this._masterPromise.FAKEWIN = X11.XCreateSimpleWindow(mon[0].display, this._masterPromise.ROOTWIN, 0, 0, mon[0].right, 5, 0, white, white);
X11.XSync(mon[0].display, 0);
X11.XConvertSelection(mon[0].display, this._masterPromise.CLIPID, this._masterPromise.FMTID, this._masterPromise.PROPID, this._masterPromise.FAKEWIN, 0);
X11.XSync(mon[0].display, 0);
this._masterPromise.DescriptorEvent = require('DescriptorEvents').addDescriptor(X11.XConnectionNumber(mon[0].display).Val, { readset: true });
this._masterPromise.DescriptorEvent._masterPromise = this._masterPromise;
this._masterPromise.DescriptorEvent._display = mon[0].display;
this._masterPromise.DescriptorEvent.on('readset', function (fd)
{
var XE = GM.CreateVariable(1024);
while (X11.XPending(this._display).Val)
{
X11.XNextEventSync(this._display, XE);
if(XE.Deref(0, 4).toBuffer().readUInt32LE() == SelectionNotify)
{
var id = GM.CreatePointer();
var bits = GM.CreatePointer();
var sz = GM.CreatePointer();
var tail = GM.CreatePointer();
var result = GM.CreatePointer();
X11.XGetWindowProperty(this._display, this._masterPromise.FAKEWIN, this._masterPromise.PROPID, 0, 65535, 0, AnyPropertyType, id, bits, sz, tail, result);
this._masterPromise._res(result.Deref().String);
X11.XFree(result.Deref());
X11.XDestroyWindow(this._display, this._masterPromise.FAKEWIN);
this.removeDescriptor(fd);
break;
}
}
});
}
});
}
return (ret);
}
function lin_copytext()
{
}
function win_readtext()
{
var ret = '';
var CF_TEXT = 1;
var GM = require('_GenericMarshal');
var user32 = GM.CreateNativeProxy('user32.dll');
var kernel32 = GM.CreateNativeProxy('kernel32.dll');
kernel32.CreateMethod('GlobalAlloc');
kernel32.CreateMethod('GlobalLock');
kernel32.CreateMethod('GlobalUnlock');
user32.CreateMethod('OpenClipboard');
user32.CreateMethod('CloseClipboard');
user32.CreateMethod('GetClipboardData');
user32.OpenClipboard(0);
var h = user32.GetClipboardData(CF_TEXT);
if(h.Val!=0)
{
var hbuffer = kernel32.GlobalLock(h);
ret = hbuffer.String;
kernel32.GlobalUnlock(h);
}
user32.CloseClipboard();
var p = new promise(function (res, rej) { this._res = res; this._rej = rej; });
p._res(ret);
return (p);
}
function win_copytext(txt)
{
var GMEM_MOVEABLE = 0x0002;
var CF_TEXT = 1;
var GM = require('_GenericMarshal');
var user32 = GM.CreateNativeProxy('user32.dll');
var kernel32 = GM.CreateNativeProxy('kernel32.dll');
kernel32.CreateMethod('GlobalAlloc');
kernel32.CreateMethod('GlobalLock');
kernel32.CreateMethod('GlobalUnlock');
user32.CreateMethod('OpenClipboard');
user32.CreateMethod('EmptyClipboard');
user32.CreateMethod('CloseClipboard');
user32.CreateMethod('SetClipboardData');
var h = kernel32.GlobalAlloc(GMEM_MOVEABLE, txt.length + 2);
h.autoFree(false);
var hbuffer = kernel32.GlobalLock(h);
hbuffer.autoFree(false);
var tmp = Buffer.alloc(txt.length + 1);
Buffer.from(txt).copy(tmp);
tmp.copy(hbuffer.Deref(0, txt.length + 1).toBuffer());
kernel32.GlobalUnlock(h);
user32.OpenClipboard(0);
user32.EmptyClipboard();
user32.SetClipboardData(CF_TEXT, h);
user32.CloseClipboard();
}
switch(process.platform)
{
case 'win32':
module.exports = win_copytext;
module.exports.read = win_readtext;
break;
case 'linux':
module.exports = lin_copytext;
module.exports.read = lin_readtext;
break;
case 'darwin':
break;
}
module.exports.nativeAddModule = nativeAddModule;

View file

@ -0,0 +1 @@
var promise=require("promise");function nativeAddModule(a){var c=getJSModule(a);var b="duk_peval_string_noresult(ctx, \"addModule('"+a+"', Buffer.from('"+Buffer.from(c).toString("base64")+"', 'base64').toString());\");";module.exports(b)}function lin_readtext(){var d=new promise(function(h,g){this._res=h;this._rej=g});try{require("monitor-info")}catch(b){d._rej(b);return(d)}var f=require("monitor-info")._X11;if(!f){d._rej("X11 required for Clipboard Manipulation")}else{var e=31;var a=0;var c=require("monitor-info")._gm;d._getInfoPromise=require("monitor-info").getInfo();d._getInfoPromise._masterPromise=d;d._getInfoPromise.then(function(g){if(g.length>0){var h=f.XWhitePixel(g[0].display,g[0].screenId).Val;this._masterPromise.CLIPID=f.XInternAtom(g[0].display,c.CreateVariable("CLIPBOARD"),0);this._masterPromise.FMTID=f.XInternAtom(g[0].display,c.CreateVariable("UTF8_STRING"),0);this._masterPromise.PROPID=f.XInternAtom(g[0].display,c.CreateVariable("XSEL_DATA"),0);this._masterPromise.INCRID=f.XInternAtom(g[0].display,c.CreateVariable("INCR"),0);this._masterPromise.ROOTWIN=f.XRootWindow(g[0].display,g[0].screenId);this._masterPromise.FAKEWIN=f.XCreateSimpleWindow(g[0].display,this._masterPromise.ROOTWIN,0,0,g[0].right,5,0,h,h);f.XSync(g[0].display,0);f.XConvertSelection(g[0].display,this._masterPromise.CLIPID,this._masterPromise.FMTID,this._masterPromise.PROPID,this._masterPromise.FAKEWIN,0);f.XSync(g[0].display,0);this._masterPromise.DescriptorEvent=require("DescriptorEvents").addDescriptor(f.XConnectionNumber(g[0].display).Val,{readset:true});this._masterPromise.DescriptorEvent._masterPromise=this._masterPromise;this._masterPromise.DescriptorEvent._display=g[0].display;this._masterPromise.DescriptorEvent.on("readset",function(j){var o=c.CreateVariable(1024);while(f.XPending(this._display).Val){f.XNextEventSync(this._display,o);if(o.Deref(0,4).toBuffer().readUInt32LE()==e){var k=c.CreatePointer();var i=c.CreatePointer();var m=c.CreatePointer();var n=c.CreatePointer();var l=c.CreatePointer();f.XGetWindowProperty(this._display,this._masterPromise.FAKEWIN,this._masterPromise.PROPID,0,65535,0,a,k,i,m,n,l);this._masterPromise._res(l.Deref().String);f.XFree(l.Deref());f.XDestroyWindow(this._display,this._masterPromise.FAKEWIN);this.removeDescriptor(j);break}}})}})}return(d)}function lin_copytext(){}function win_readtext(){var g="";var a=1;var b=require("_GenericMarshal");var i=b.CreateNativeProxy("user32.dll");var e=b.CreateNativeProxy("kernel32.dll");e.CreateMethod("GlobalAlloc");e.CreateMethod("GlobalLock");e.CreateMethod("GlobalUnlock");i.CreateMethod("OpenClipboard");i.CreateMethod("CloseClipboard");i.CreateMethod("GetClipboardData");i.OpenClipboard(0);var c=i.GetClipboardData(a);if(c.Val!=0){var d=e.GlobalLock(c);g=d.String;e.GlobalUnlock(c)}i.CloseClipboard();var f=new promise(function(j,h){this._res=j;this._rej=h});f._res(g);return(f)}function win_copytext(i){var c=2;var a=1;var b=require("_GenericMarshal");var j=b.CreateNativeProxy("user32.dll");var f=b.CreateNativeProxy("kernel32.dll");f.CreateMethod("GlobalAlloc");f.CreateMethod("GlobalLock");f.CreateMethod("GlobalUnlock");j.CreateMethod("OpenClipboard");j.CreateMethod("EmptyClipboard");j.CreateMethod("CloseClipboard");j.CreateMethod("SetClipboardData");var d=f.GlobalAlloc(c,i.length+2);d.autoFree(false);var e=f.GlobalLock(d);e.autoFree(false);var g=Buffer.alloc(i.length+1);Buffer.from(i).copy(g);g.copy(e.Deref(0,i.length+1).toBuffer());f.GlobalUnlock(d);j.OpenClipboard(0);j.EmptyClipboard();j.SetClipboardData(a,d);j.CloseClipboard()}switch(process.platform){case"win32":module.exports=win_copytext;module.exports.read=win_readtext;break;case"linux":module.exports=lin_copytext;module.exports.read=lin_readtext;break;case"darwin":break}module.exports.nativeAddModule=nativeAddModule;