mirror of
				https://github.com/Ylianst/MeshCentral.git
				synced 2025-10-29 15:25:01 -04:00 
			
		
		
		
	Improved My Files tab, new version of MeshCmd
This commit is contained in:
		
							parent
							
								
									63a165aac0
								
							
						
					
					
						commit
						8287997b2d
					
				
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| @ -52,7 +52,7 @@ function stream_bufferedWrite() { | ||||
|     var emitterUtils = require('events').inherits(this); | ||||
|     this.buffer = []; | ||||
|     this._readCheckImmediate = undefined; | ||||
|      | ||||
|     this._ObjectID = "bufferedWriteStream"; | ||||
|     // Writable Events
 | ||||
|     emitterUtils.createEvent('close'); | ||||
|     emitterUtils.createEvent('drain'); | ||||
| @ -115,17 +115,19 @@ function lme_heci(options) { | ||||
|     emitterUtils.createEvent('error'); | ||||
|     emitterUtils.createEvent('connect'); | ||||
|     emitterUtils.createEvent('notify'); | ||||
|     emitterUtils.createEvent('bind'); | ||||
|      | ||||
|     if ((options != null) && (options.debug == true)) { lme_port_offset = -100; } // LMS debug mode
 | ||||
| 
 | ||||
|     var heci = require('heci'); | ||||
|     this.INITIAL_RXWINDOW_SIZE = 4096; | ||||
|      | ||||
|     this._ObjectID = "lme"; | ||||
|     this._LME = heci.create(); | ||||
|     this._LME._binded = {}; | ||||
|     this._LME.LMS = this; | ||||
|     this._LME.on('error', function (e) { this.LMS.emit('error', e); }); | ||||
|     this._LME.on('connect', function () { | ||||
|         this.LMS.emit('connect'); | ||||
|         this.on('data', function (chunk) { | ||||
|             // this = HECI
 | ||||
|             var cmd = chunk.readUInt8(0); | ||||
| @ -166,7 +168,8 @@ function lme_heci(options) { | ||||
|                                     if (channel.localPort == port) { this.sockets[i].end(); delete this.sockets[i]; } // Close this socket
 | ||||
|                                 } | ||||
|                             } | ||||
|                             if (this[name][port] == null) { // Bind a new server socket if not already present
 | ||||
|                             if (this[name][port] == null) | ||||
|                             { // Bind a new server socket if not already present
 | ||||
|                                 this[name][port] = require('net').createServer(); | ||||
|                                 this[name][port].HECI = this; | ||||
|                                 if (lme_port_offset == 0) { | ||||
| @ -178,6 +181,8 @@ function lme_heci(options) { | ||||
|                                     //console.log('New [' + socket.remoteFamily + '] TCP Connection on: ' + socket.remoteAddress + ' :' + socket.localPort);
 | ||||
|                                     this.HECI.LMS.bindDuplexStream(socket, socket.remoteFamily, socket.localPort - lme_port_offset); | ||||
|                                 }); | ||||
|                                 this._binded[port] = true; | ||||
|                                 this.LMS.emit('bind', this._binded); | ||||
|                             } | ||||
|                             var outBuffer = Buffer.alloc(5); | ||||
|                             outBuffer.writeUInt8(81, 0); | ||||
| @ -388,6 +393,9 @@ function lme_heci(options) { | ||||
|                     break; | ||||
|             } | ||||
|         }); | ||||
|         this.LMS.emit('connect'); | ||||
|         this.resume(); | ||||
| 
 | ||||
|     }); | ||||
|      | ||||
|     this.bindDuplexStream = function (duplexStream, remoteFamily, localPort) { | ||||
|  | ||||
| @ -92,11 +92,12 @@ function amt_heci() { | ||||
|         for (var i = 1; i < arguments.length; ++i) { optional.push(arguments[i]); } | ||||
|         this.sendCommand(26, null, function (header, fn, opt) { | ||||
|             if (header.Status == 0) { | ||||
|                 var i, CodeVersion = header.Data, val = { BiosVersion: CodeVersion.slice(0, this._amt.BiosVersionLen), Versions: [] }, v = CodeVersion.slice(this._amt.BiosVersionLen + 4); | ||||
|                 var i, CodeVersion = header.Data, val = { BiosVersion: CodeVersion.slice(0, this._amt.BiosVersionLen).toString(), Versions: [] }, v = CodeVersion.slice(this._amt.BiosVersionLen + 4); | ||||
|                 for (i = 0; i < CodeVersion.readUInt32LE(this._amt.BiosVersionLen) ; ++i) { | ||||
|                     val.Versions[i] = { Description: v.slice(2, v.readUInt16LE(0) + 2).toString(), Version: v.slice(4 + this._amt.UnicodeStringLen, 4 + this._amt.UnicodeStringLen + v.readUInt16LE(2 + this._amt.UnicodeStringLen)).toString() }; | ||||
|                     v = v.slice(4 + (2 * this._amt.UnicodeStringLen)); | ||||
|                 } | ||||
|                 if (val.BiosVersion.indexOf('\0') > 0) { val.BiosVersion = val.BiosVersion.substring(0, val.BiosVersion.indexOf('\0')); } | ||||
|                 opt.unshift(val); | ||||
|             } else { | ||||
|                 opt.unshift(null); | ||||
|  | ||||
| @ -21,20 +21,33 @@ limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| // Construct a WSMAN communication object
 | ||||
| function CreateWsmanComm(host, port, user, pass, tls, extra) { | ||||
| function CreateWsmanComm(/*host, port, user, pass, tls, extra*/) | ||||
| { | ||||
|     var obj = {}; | ||||
|     obj.PendingAjax = [];               // List of pending AJAX calls. When one frees up, another will start.
 | ||||
|     obj.ActiveAjaxCount = 0;            // Number of currently active AJAX calls
 | ||||
|     obj.MaxActiveAjaxCount = 1;         // Maximum number of activate AJAX calls at the same time.
 | ||||
|     obj.FailAllError = 0;               // Set this to non-zero to fail all AJAX calls with that error status, 999 causes responses to be silent.
 | ||||
|     obj.host = host; | ||||
|     obj.port = port; | ||||
|     obj.user = user; | ||||
|     obj.pass = pass; | ||||
|     obj.tls = tls; | ||||
|     obj.digest = null; | ||||
|     obj.RequestCount = 0; | ||||
| 
 | ||||
|     if (arguments.length == 1 && typeof(arguments[0] == 'object')) | ||||
|     { | ||||
|         obj.host = arguments[0].host; | ||||
|         obj.port = arguments[0].port; | ||||
|         obj.authToken = arguments[0].authToken; | ||||
|         obj.tls = arguments[0].tls; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         obj.host = arguments[0]; | ||||
|         obj.port = arguments[1]; | ||||
|         obj.user = arguments[2]; | ||||
|         obj.pass = arguments[3]; | ||||
|         obj.tls = arguments[4]; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     // Private method
 | ||||
|     //   pri = priority, if set to 1, the call is high priority and put on top of the stack.
 | ||||
|     obj.PerformAjax = function (postdata, callback, tag, pri, url, action) { | ||||
| @ -62,7 +75,18 @@ function CreateWsmanComm(host, port, user, pass, tls, extra) { | ||||
|         //console.log("SEND: " + postdata); // DEBUG
 | ||||
| 
 | ||||
|         // We are in a DukTape environement
 | ||||
|         if (obj.digest == null) { obj.digest = require('http-digest').create(obj.user, obj.pass); obj.digest.http = require('http'); } | ||||
|         if (obj.digest == null) | ||||
|         { | ||||
|             if (obj.authToken) | ||||
|             { | ||||
|                 obj.digest = require('http-digest').create({ authToken: obj.authToken }); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 obj.digest = require('http-digest').create(obj.user, obj.pass); | ||||
|             } | ||||
|             obj.digest.http = require('http'); | ||||
|         } | ||||
|         var request = { protocol: (obj.tls == 1 ? 'https:' : 'http:'), method: 'POST', host: obj.host, path: '/wsman', port: obj.port, rejectUnauthorized: false, checkServerIdentity: function (cert) { console.log('checkServerIdentity', JSON.stringify(cert)); } }; | ||||
|         var req = obj.digest.request(request); | ||||
|         //console.log('Request ' + (obj.RequestCount++));
 | ||||
|  | ||||
| @ -21,15 +21,26 @@ limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| // Construct a MeshServer object
 | ||||
| function WsmanStackCreateService(CreateWsmanComm, host, port, user, pass, tls, extra) { | ||||
|     var obj = {}; | ||||
| function WsmanStackCreateService(/*CreateWsmanComm, host, port, user, pass, tls, extra*/) | ||||
| { | ||||
|     var obj = {_ObjectID: 'WSMAN'}; | ||||
|     //obj.onDebugMessage = null;          // Set to a function if you want to get debug messages.
 | ||||
|     obj.NextMessageId = 1;              // Next message number, used to label WSMAN calls.
 | ||||
|     obj.Address = '/wsman'; | ||||
|     obj.xmlParser = require('amt-xml'); | ||||
|     if (CreateWsmanComm) { obj.comm = new CreateWsmanComm(host, port, user, pass, tls, extra); } | ||||
| 
 | ||||
|     obj.PerformAjax = function (postdata, callback, tag, pri, namespaces) { | ||||
|     if (arguments.length == 1 && typeof (arguments[0] == 'object')) | ||||
|     { | ||||
|         var CreateWsmanComm = arguments[0].transport; | ||||
|         if (CreateWsmanComm) { obj.comm = new CreateWsmanComm(arguments[0]); } | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         var CreateWsmanComm = arguments[0]; | ||||
|         if (CreateWsmanComm) { obj.comm = new CreateWsmanComm(arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6]); } | ||||
|     } | ||||
| 
 | ||||
|     obj.PerformAjax = function PerformAjax(postdata, callback, tag, pri, namespaces) { | ||||
|         if (namespaces == null) namespaces = ''; | ||||
|         obj.comm.PerformAjax('<?xml version=\"1.0\" encoding=\"utf-8\"?><Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:w="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" xmlns=\"http://www.w3.org/2003/05/soap-envelope\" ' + namespaces + '><Header><a:Action>' + postdata, function (data, status, tag) { | ||||
|             if (status != 200) { callback(obj, null, { Header: { HttpError: status } }, status, tag); return; } | ||||
| @ -42,7 +53,7 @@ function WsmanStackCreateService(CreateWsmanComm, host, port, user, pass, tls, e | ||||
|     //obj.Debug = function (msg) { /*console.log(msg);*/ }
 | ||||
| 
 | ||||
|     // Cancel all pending queries with given status
 | ||||
|     obj.CancelAllQueries = function (s) { obj.comm.CancelAllQueries(s); } | ||||
|     obj.CancelAllQueries = function CancelAllQueries(s) { obj.comm.CancelAllQueries(s); } | ||||
| 
 | ||||
|     // Get the last element of a URI string
 | ||||
|     obj.GetNameFromUrl = function (resuri) { | ||||
| @ -51,7 +62,7 @@ function WsmanStackCreateService(CreateWsmanComm, host, port, user, pass, tls, e | ||||
|     } | ||||
| 
 | ||||
|     // Perform a WSMAN Subscribe operation
 | ||||
|     obj.ExecSubscribe = function (resuri, delivery, url, callback, tag, pri, selectors, opaque, user, pass) { | ||||
|     obj.ExecSubscribe = function ExecSubscribe(resuri, delivery, url, callback, tag, pri, selectors, opaque, user, pass) { | ||||
|         var digest = "", digest2 = "", opaque = ""; | ||||
|         if (user != null && pass != null) { digest = '<t:IssuedTokens xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust" xmlns:se="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><t:RequestSecurityTokenResponse><t:TokenType>http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken</t:TokenType><t:RequestedSecurityToken><se:UsernameToken><se:Username>' + user + '</se:Username><se:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd#PasswordText">' + pass + '</se:Password></se:UsernameToken></t:RequestedSecurityToken></t:RequestSecurityTokenResponse></t:IssuedTokens>'; digest2 = '<w:Auth Profile="http://schemas.dmtf.org/wbem/wsman/1/wsman/secprofile/http/digest"/>'; } | ||||
|         if (opaque != null) { opaque = '<a:ReferenceParameters><m:arg>' + opaque + '</m:arg></a:ReferenceParameters>'; } | ||||
| @ -61,19 +72,19 @@ function WsmanStackCreateService(CreateWsmanComm, host, port, user, pass, tls, e | ||||
|     } | ||||
| 
 | ||||
|     // Perform a WSMAN UnSubscribe operation
 | ||||
|     obj.ExecUnSubscribe = function (resuri, callback, tag, pri, selectors) { | ||||
|     obj.ExecUnSubscribe = function ExecUnSubscribe(resuri, callback, tag, pri, selectors) { | ||||
|         var data = "http://schemas.xmlsoap.org/ws/2004/08/eventing/Unsubscribe</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo>" + _PutObjToSelectorsXml(selectors) + '</Header><Body><e:Unsubscribe/>'; | ||||
|         obj.PerformAjax(data + "</Body></Envelope>", callback, tag, pri, 'xmlns:e="http://schemas.xmlsoap.org/ws/2004/08/eventing"'); | ||||
|     } | ||||
| 
 | ||||
|     // Perform a WSMAN PUT operation
 | ||||
|     obj.ExecPut = function (resuri, putobj, callback, tag, pri, selectors) { | ||||
|     obj.ExecPut = function ExecPut(resuri, putobj, callback, tag, pri, selectors) { | ||||
|         var data = "http://schemas.xmlsoap.org/ws/2004/09/transfer/Put</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><w:OperationTimeout>PT60.000S</w:OperationTimeout>" + _PutObjToSelectorsXml(selectors) + '</Header><Body>' + _PutObjToBodyXml(resuri, putobj); | ||||
|         obj.PerformAjax(data + "</Body></Envelope>", callback, tag, pri); | ||||
|     } | ||||
| 		 | ||||
|     // Perform a WSMAN CREATE operation
 | ||||
|     obj.ExecCreate = function (resuri, putobj, callback, tag, pri, selectors) { | ||||
|     obj.ExecCreate = function ExecCreate(resuri, putobj, callback, tag, pri, selectors) { | ||||
|         var objname = obj.GetNameFromUrl(resuri); | ||||
|         var data = "http://schemas.xmlsoap.org/ws/2004/09/transfer/Create</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><w:OperationTimeout>PT60S</w:OperationTimeout>" + _PutObjToSelectorsXml(selectors) + "</Header><Body><g:" + objname + " xmlns:g=\"" + resuri + "\">"; | ||||
|         for (var n in putobj) { data += "<g:" + n + ">" + putobj[n] + "</g:" + n + ">" }  | ||||
| @ -81,35 +92,35 @@ function WsmanStackCreateService(CreateWsmanComm, host, port, user, pass, tls, e | ||||
|     } | ||||
| 
 | ||||
|     // Perform a WSMAN DELETE operation
 | ||||
|     obj.ExecDelete = function (resuri, putobj, callback, tag, pri) { | ||||
|     obj.ExecDelete = function ExecDelete(resuri, putobj, callback, tag, pri) { | ||||
|         var data = "http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><w:OperationTimeout>PT60S</w:OperationTimeout>" + _PutObjToSelectorsXml(putobj) + "</Header><Body /></Envelope>"; | ||||
|         obj.PerformAjax(data, callback, tag, pri); | ||||
|     } | ||||
| 
 | ||||
|     // Perform a WSMAN GET operation
 | ||||
|     obj.ExecGet = function (resuri, callback, tag, pri) { | ||||
|     obj.ExecGet = function ExecGet(resuri, callback, tag, pri) { | ||||
|         obj.PerformAjax("http://schemas.xmlsoap.org/ws/2004/09/transfer/Get</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><w:OperationTimeout>PT60S</w:OperationTimeout></Header><Body /></Envelope>", callback, tag, pri); | ||||
|     } | ||||
| 
 | ||||
| 	// Perform a WSMAN method call operation
 | ||||
|     obj.ExecMethod = function (resuri, method, args, callback, tag, pri, selectors) { | ||||
|     obj.ExecMethod = function ExecMethod(resuri, method, args, callback, tag, pri, selectors) { | ||||
|         var argsxml = ""; | ||||
|         for (var i in args) { if (args[i] != null) { if (Array.isArray(args[i])) { for (var x in args[i]) { argsxml += "<r:" + i + ">" + args[i][x] + "</r:" + i + ">"; } } else { argsxml += "<r:" + i + ">" + args[i] + "</r:" + i + ">"; } } } | ||||
|         obj.ExecMethodXml(resuri, method, argsxml, callback, tag, pri, selectors); | ||||
|     } | ||||
| 	 | ||||
|     // Perform a WSMAN method call operation. The arguments are already formatted in XML.
 | ||||
|     obj.ExecMethodXml = function (resuri, method, argsxml, callback, tag, pri, selectors) { | ||||
|     obj.ExecMethodXml = function ExecMethodXml(resuri, method, argsxml, callback, tag, pri, selectors) { | ||||
|         obj.PerformAjax(resuri + "/" + method + "</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><w:OperationTimeout>PT60S</w:OperationTimeout>" + _PutObjToSelectorsXml(selectors) + "</Header><Body><r:" + method + '_INPUT' + " xmlns:r=\"" + resuri + "\">" + argsxml + "</r:" + method + "_INPUT></Body></Envelope>", callback, tag, pri); | ||||
|     } | ||||
| 
 | ||||
|     // Perform a WSMAN ENUM operation
 | ||||
|     obj.ExecEnum = function (resuri, callback, tag, pri) { | ||||
|     obj.ExecEnum = function ExecEnum(resuri, callback, tag, pri) { | ||||
|         obj.PerformAjax("http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><w:OperationTimeout>PT60S</w:OperationTimeout></Header><Body><Enumerate xmlns=\"http://schemas.xmlsoap.org/ws/2004/09/enumeration\" /></Body></Envelope>", callback, tag, pri); | ||||
|     } | ||||
| 
 | ||||
|     // Perform a WSMAN PULL operation
 | ||||
|     obj.ExecPull = function (resuri, enumctx, callback, tag, pri) { | ||||
|     obj.ExecPull = function ExecPull(resuri, enumctx, callback, tag, pri) { | ||||
|         obj.PerformAjax("http://schemas.xmlsoap.org/ws/2004/09/enumeration/Pull</a:Action><a:To>" + obj.Address + "</a:To><w:ResourceURI>" + resuri + "</w:ResourceURI><a:MessageID>" + (obj.NextMessageId++) + "</a:MessageID><a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo><w:OperationTimeout>PT60S</w:OperationTimeout></Header><Body><Pull xmlns=\"http://schemas.xmlsoap.org/ws/2004/09/enumeration\"><EnumerationContext>" + enumctx + "</EnumerationContext><MaxElements>999</MaxElements><MaxCharacters>99999</MaxCharacters></Pull></Body></Envelope>", callback, tag, pri); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -26,6 +26,7 @@ limitations under the License. | ||||
|  */ | ||||
| function AmtStackCreateService(wsmanStack) { | ||||
|     var obj = new Object(); | ||||
|     obj._ObjectID = 'AMT' | ||||
|     obj.wsman = wsmanStack; | ||||
|     obj.pfx = ["http://intel.com/wbem/wscim/1/amt-schema/1/", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/", "http://intel.com/wbem/wscim/1/ips-schema/1/"]; | ||||
|     obj.PendingEnums = []; | ||||
| @ -52,31 +53,31 @@ function AmtStackCreateService(wsmanStack) { | ||||
|     } | ||||
| 
 | ||||
|     // Perform a WSMAN "SUBSCRIBE" operation.
 | ||||
|     obj.Subscribe = function (name, delivery, url, callback, tag, pri, selectors, opaque, user, pass) { obj.wsman.ExecSubscribe(obj.CompleteName(name), delivery, url, function (ws, resuri, response, xstatus) { _up(); callback(obj, name, response, xstatus, tag); }, 0, pri, selectors, opaque, user, pass); _up(); } | ||||
|     obj.Subscribe = function Subscribe(name, delivery, url, callback, tag, pri, selectors, opaque, user, pass) { obj.wsman.ExecSubscribe(obj.CompleteName(name), delivery, url, function (ws, resuri, response, xstatus) { _up(); callback.call(obj, obj, name, response, xstatus, tag); }, 0, pri, selectors, opaque, user, pass); _up(); } | ||||
| 
 | ||||
|     // Perform a WSMAN "UNSUBSCRIBE" operation.
 | ||||
|     obj.UnSubscribe = function (name, callback, tag, pri, selectors) { obj.wsman.ExecUnSubscribe(obj.CompleteName(name), function (ws, resuri, response, xstatus) { _up(); callback(obj, name, response, xstatus, tag); }, 0, pri, selectors); _up(); } | ||||
|     obj.UnSubscribe = function UnSubscribe(name, callback, tag, pri, selectors) { obj.wsman.ExecUnSubscribe(obj.CompleteName(name), function (ws, resuri, response, xstatus) { _up(); callback.call(obj, obj, name, response, xstatus, tag); }, 0, pri, selectors); _up(); } | ||||
| 
 | ||||
|     // Perform a WSMAN "GET" operation.
 | ||||
|     obj.Get = function (name, callback, tag, pri) { obj.wsman.ExecGet(obj.CompleteName(name), function (ws, resuri, response, xstatus) { _up(); callback(obj, name, response, xstatus, tag); }, 0, pri); _up(); } | ||||
|     obj.Get = function Get(name, callback, tag, pri) { obj.wsman.ExecGet(obj.CompleteName(name), function (ws, resuri, response, xstatus) { _up(); callback.call(obj, obj, name, response, xstatus, tag); }, 0, pri); _up(); } | ||||
| 
 | ||||
|     // Perform a WSMAN "PUT" operation.
 | ||||
|     obj.Put = function (name, putobj, callback, tag, pri, selectors) { obj.wsman.ExecPut(obj.CompleteName(name), putobj, function (ws, resuri, response, xstatus) { _up(); callback(obj, name, response, xstatus, tag); }, 0, pri, selectors); _up(); } | ||||
|     obj.Put = function Put(name, putobj, callback, tag, pri, selectors) { obj.wsman.ExecPut(obj.CompleteName(name), putobj, function (ws, resuri, response, xstatus) { _up(); callback.call(obj, obj, name, response, xstatus, tag); }, 0, pri, selectors); _up(); } | ||||
| 	 | ||||
|     // Perform a WSMAN "CREATE" operation.
 | ||||
|     obj.Create = function (name, putobj, callback, tag, pri) { obj.wsman.ExecCreate(obj.CompleteName(name), putobj, function (ws, resuri, response, xstatus) { _up(); callback(obj, name, response, xstatus, tag); }, 0, pri); _up(); } | ||||
|     obj.Create = function Create(name, putobj, callback, tag, pri) { obj.wsman.ExecCreate(obj.CompleteName(name), putobj, function (ws, resuri, response, xstatus) { _up(); callback.call(obj, obj, name, response, xstatus, tag); }, 0, pri); _up(); } | ||||
| 
 | ||||
|     // Perform a WSMAN "DELETE" operation.
 | ||||
|     obj.Delete = function (name, putobj, callback, tag, pri) { obj.wsman.ExecDelete(obj.CompleteName(name), putobj, function (ws, resuri, response, xstatus) { _up(); callback(obj, name, response, xstatus, tag); }, 0, pri); _up(); } | ||||
|     obj.Delete = function Delete(name, putobj, callback, tag, pri) { obj.wsman.ExecDelete(obj.CompleteName(name), putobj, function (ws, resuri, response, xstatus) { _up(); callback.call(obj, obj, name, response, xstatus, tag); }, 0, pri); _up(); } | ||||
| 
 | ||||
|     // Perform a WSMAN method call operation.
 | ||||
|     obj.Exec = function (name, method, args, callback, tag, pri, selectors) { obj.wsman.ExecMethod(obj.CompleteName(name), method, args, function (ws, resuri, response, xstatus) { _up(); callback(obj, name, obj.CompleteExecResponse(response), xstatus, tag); }, 0, pri, selectors); _up(); } | ||||
|     obj.Exec = function Exec(name, method, args, callback, tag, pri, selectors) { obj.wsman.ExecMethod(obj.CompleteName(name), method, args, function (ws, resuri, response, xstatus) { _up(); callback.call(obj, obj, name, obj.CompleteExecResponse(response), xstatus, tag); }, 0, pri, selectors); _up(); } | ||||
| 	 | ||||
|     // Perform a WSMAN method call operation.
 | ||||
|     obj.ExecWithXml = function (name, method, args, callback, tag, pri, selectors) { obj.wsman.ExecMethodXml(obj.CompleteName(name), method, execArgumentsToXml(args), function (ws, resuri, response, xstatus) { _up(); callback(obj, name, obj.CompleteExecResponse(response), xstatus, tag); }, 0, pri, selectors); _up(); } | ||||
|     obj.ExecWithXml = function ExecWithXml(name, method, args, callback, tag, pri, selectors) { obj.wsman.ExecMethodXml(obj.CompleteName(name), method, execArgumentsToXml(args), function (ws, resuri, response, xstatus) { _up(); callback.call(obj, obj, name, obj.CompleteExecResponse(response), xstatus, tag); }, 0, pri, selectors); _up(); } | ||||
| 	 | ||||
|     // Perform a WSMAN "ENUMERATE" operation.
 | ||||
|     obj.Enum = function (name, callback, tag, pri) { | ||||
|     obj.Enum = function Enum(name, callback, tag, pri) { | ||||
|         if (obj.ActiveEnumsCount < obj.MaxActiveEnumsCount) { | ||||
|             obj.ActiveEnumsCount++; obj.wsman.ExecEnum(obj.CompleteName(name), function (ws, resuri, response, xstatus, tag0) { _up(); _EnumStartSink(name, response, callback, resuri, xstatus, tag0); }, tag, pri); | ||||
|         } else { | ||||
| @ -87,16 +88,16 @@ function AmtStackCreateService(wsmanStack) { | ||||
| 
 | ||||
|     // Private method
 | ||||
|     function _EnumStartSink(name, response, callback, resuri, status, tag, pri) { | ||||
|         if (status != 200) { callback(obj, name, null, status, tag); _EnumDoNext(1); return; } | ||||
|         if (response == null || response.Header["Method"] != "EnumerateResponse" || !response.Body["EnumerationContext"]) { callback(obj, name, null, 603, tag); _EnumDoNext(1); return; } | ||||
|         if (status != 200) { callback.call(obj, obj, name, null, status, tag); _EnumDoNext(1); return; } | ||||
|         if (response == null || response.Header["Method"] != "EnumerateResponse" || !response.Body["EnumerationContext"]) { callback.call(obj, obj, name, null, 603, tag); _EnumDoNext(1); return; } | ||||
|         var enumctx = response.Body["EnumerationContext"]; | ||||
|         obj.wsman.ExecPull(resuri, enumctx, function (ws, resuri, response, xstatus) { _EnumContinueSink(name, response, callback, resuri, [], xstatus, tag, pri); }); | ||||
|     } | ||||
| 
 | ||||
|     // Private method
 | ||||
|     function _EnumContinueSink(name, response, callback, resuri, items, status, tag, pri) { | ||||
|         if (status != 200) { callback(obj, name, null, status, tag); _EnumDoNext(1); return; } | ||||
|         if (response == null || response.Header["Method"] != "PullResponse") { callback(obj, name, null, 604, tag); _EnumDoNext(1); return; } | ||||
|         if (status != 200) { callback.call(obj, obj, name, null, status, tag); _EnumDoNext(1); return; } | ||||
|         if (response == null || response.Header["Method"] != "PullResponse") { callback.call(obj, obj, name, null, 604, tag); _EnumDoNext(1); return; } | ||||
|         for (var i in response.Body["Items"]) { | ||||
|             if (response.Body["Items"][i] instanceof Array) { | ||||
|                 for (var j in response.Body["Items"][i]) { items.push(response.Body["Items"][i][j]); } | ||||
| @ -109,7 +110,7 @@ function AmtStackCreateService(wsmanStack) { | ||||
|             obj.wsman.ExecPull(resuri, enumctx, function (ws, resuri, response, xstatus) { _EnumContinueSink(name, response, callback, resuri, items, xstatus, tag, 1); }); | ||||
|         } else { | ||||
|             _EnumDoNext(1); | ||||
|             callback(obj, name, items, status, tag); | ||||
|             callback.call(obj, obj, name, items, status, tag); | ||||
|             _up(); | ||||
|         } | ||||
|     } | ||||
| @ -140,7 +141,7 @@ function AmtStackCreateService(wsmanStack) { | ||||
|         // Perform a GET/ENUM action
 | ||||
|         f(n, function (stack, name, responses, status, tag0) { | ||||
|             tag0[2][name] = { response: (responses==null?null:responses.Body), responses: responses, status: status }; | ||||
|             if (tag0[1].length == 0 || status == 401 || (continueOnError != true && status != 200 && status != 400)) { obj.PendingBatchOperations -= (names.length * 2); _up(); callback(obj, batchname, tag0[2], status, tag); } | ||||
|             if (tag0[1].length == 0 || status == 401 || (continueOnError != true && status != 200 && status != 400)) { obj.PendingBatchOperations -= (names.length * 2); _up(); callback.call(obj, obj, batchname, tag0[2], status, tag); } | ||||
|             else { _up(); _BatchNextEnum(batchname, names, callback, tag, tag0[2], pri); } | ||||
|         }, [batchname, names, results], pri); | ||||
|         _up(); | ||||
| @ -154,7 +155,7 @@ function AmtStackCreateService(wsmanStack) { | ||||
|     // Private method
 | ||||
|     function _FetchNext(batch) { | ||||
|         if (batch.names.length <= batch.current) { | ||||
|             batch.callback(obj, batch.name, batch.responses, 200, batch.tag); | ||||
|             batch.callback.call(obj, obj, batch.name, batch.responses, 200, batch.tag); | ||||
|         } else { | ||||
|             obj.wsman.ExecGet(obj.CompleteName(batch.names[batch.current]), function (ws, resuri, response, xstatus) { _Fetched(batch, response, xstatus); }, batch.pri); | ||||
|             batch.current++; | ||||
| @ -165,7 +166,7 @@ function AmtStackCreateService(wsmanStack) { | ||||
|     // Private method
 | ||||
|     function _Fetched(batch, response, status) { | ||||
|         if (response == null || status != 200) { | ||||
|             batch.callback(obj, batch.name, null, status, batch.tag); | ||||
|             batch.callback.call(obj, obj, batch.name, null, status, batch.tag); | ||||
|         } else { | ||||
|             batch.responses[response.Header["Method"]] = response; | ||||
|             _FetchNext(batch); | ||||
| @ -209,6 +210,16 @@ function AmtStackCreateService(wsmanStack) { | ||||
|     obj.AMT_AgentPresenceWatchdogVA_AssertShutdown = function (SequenceNumber, callback_func) { obj.Exec("AMT_AgentPresenceWatchdogVA", "AssertShutdown", { "SequenceNumber": SequenceNumber }, callback_func); } | ||||
|     obj.AMT_AgentPresenceWatchdogVA_AddAction = function (OldState, NewState, EventOnTransition, ActionSd, ActionEac, callback_func) { obj.Exec("AMT_AgentPresenceWatchdogVA", "AddAction", { "OldState": OldState, "NewState": NewState, "EventOnTransition": EventOnTransition, "ActionSd": ActionSd, "ActionEac": ActionEac }, callback_func); } | ||||
|     obj.AMT_AgentPresenceWatchdogVA_DeleteAllActions = function (_method_dummy, callback_func) { obj.Exec("AMT_AgentPresenceWatchdogVA", "DeleteAllActions", { "_method_dummy": _method_dummy }, callback_func); } | ||||
|     obj.AMT_AlarmClockService_AddAlarm = function AlarmClockService_AddAlarm(alarmInstance, callback_func) | ||||
|     { | ||||
|         var id = alarmInstance.InstanceID; | ||||
|         var nm = alarmInstance.ElementName; | ||||
|         var start = alarmInstance.StartTime.Datetime; | ||||
|         var interval = alarmInstance.Interval ? alarmInstance.Interval.Datetime : undefined; | ||||
|         var doc = alarmInstance.DeleteOnCompletion; | ||||
|         var tpl = "<d:AlarmTemplate xmlns:d=\"http://intel.com/wbem/wscim/1/amt-schema/1/AMT_AlarmClockService\" xmlns:s=\"http://intel.com/wbem/wscim/1/ips-schema/1/IPS_AlarmClockOccurrence\"><s:InstanceID>" + id + "</s:InstanceID><s:ElementName>" + nm + "</s:ElementName><s:StartTime><p:Datetime xmlns:p=\"http://schemas.dmtf.org/wbem/wscim/1/common\">" + start + "</p:Datetime></s:StartTime>" + ((interval!=undefined)?("<s:Interval><p:Interval xmlns:p=\"http://schemas.dmtf.org/wbem/wscim/1/common\">" + interval + "</p:Interval></s:Interval>"):"") + "<s:DeleteOnCompletion>" + doc + "</s:DeleteOnCompletion></d:AlarmTemplate>" | ||||
|         obj.wsman.ExecMethodXml(obj.CompleteName("AMT_AlarmClockService"), "AddAlarm", tpl, callback_func); | ||||
|     }; | ||||
|     obj.AMT_AuditLog_ClearLog = function (callback_func) { obj.Exec("AMT_AuditLog", "ClearLog", {}, callback_func); } | ||||
|     obj.AMT_AuditLog_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("AMT_AuditLog", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); } | ||||
|     obj.AMT_AuditLog_ReadRecords = function (StartIndex, callback_func, tag) { obj.Exec("AMT_AuditLog", "ReadRecords", { "StartIndex": StartIndex }, callback_func, tag); } | ||||
| @ -279,7 +290,7 @@ function AmtStackCreateService(wsmanStack) { | ||||
|     obj.AMT_TimeSynchronizationService_GetLowAccuracyTimeSynch = function (callback_func, tag) { obj.Exec("AMT_TimeSynchronizationService", "GetLowAccuracyTimeSynch", {}, callback_func, tag); } | ||||
|     obj.AMT_TimeSynchronizationService_SetHighAccuracyTimeSynch = function (Ta0, Tm1, Tm2, callback_func, tag) { obj.Exec("AMT_TimeSynchronizationService", "SetHighAccuracyTimeSynch", { "Ta0": Ta0, "Tm1": Tm1, "Tm2": Tm2 }, callback_func, tag); } | ||||
|     obj.AMT_UserInitiatedConnectionService_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("AMT_UserInitiatedConnectionService", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); } | ||||
|     obj.AMT_WebUIService_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func) { obj.Exec("AMT_WebUIService", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func); } | ||||
|     obj.AMT_WebUIService_RequestStateChange = function (RequestedState, TimeoutPeriod, callback_func, tag) { obj.Exec("AMT_WebUIService", "RequestStateChange", { "RequestedState": RequestedState, "TimeoutPeriod": TimeoutPeriod }, callback_func, tag); } | ||||
|     obj.AMT_WiFiPortConfigurationService_AddWiFiSettings = function (WiFiEndpoint, WiFiEndpointSettingsInput, IEEE8021xSettingsInput, ClientCredential, CACredential, callback_func) { obj.ExecWithXml("AMT_WiFiPortConfigurationService", "AddWiFiSettings", { "WiFiEndpoint": WiFiEndpoint, "WiFiEndpointSettingsInput": WiFiEndpointSettingsInput, "IEEE8021xSettingsInput": IEEE8021xSettingsInput, "ClientCredential": ClientCredential, "CACredential": CACredential }, callback_func); } | ||||
|     obj.AMT_WiFiPortConfigurationService_UpdateWiFiSettings = function (WiFiEndpointSettings, WiFiEndpointSettingsInput, IEEE8021xSettingsInput, ClientCredential, CACredential, callback_func) { obj.ExecWithXml("AMT_WiFiPortConfigurationService", "UpdateWiFiSettings", { "WiFiEndpointSettings": WiFiEndpointSettings, "WiFiEndpointSettingsInput": WiFiEndpointSettingsInput, "IEEE8021xSettingsInput": IEEE8021xSettingsInput, "ClientCredential": ClientCredential, "CACredential": CACredential }, callback_func); } | ||||
|     obj.AMT_WiFiPortConfigurationService_DeleteAllITProfiles = function (_method_dummy, callback_func) { obj.Exec("AMT_WiFiPortConfigurationService", "DeleteAllITProfiles", { "_method_dummy": _method_dummy }, callback_func); } | ||||
| @ -356,8 +367,8 @@ function AmtStackCreateService(wsmanStack) { | ||||
|     obj.IPS_HostBasedSetupService_UpgradeClientToAdmin = function (McNonce, SigningAlgorithm, DigitalSignature, callback_func) { obj.Exec("IPS_HostBasedSetupService", "UpgradeClientToAdmin", { "McNonce": McNonce, "SigningAlgorithm": SigningAlgorithm, "DigitalSignature": DigitalSignature }, callback_func); } | ||||
|     obj.IPS_HostBasedSetupService_DisableClientControlMode = function (_method_dummy, callback_func) { obj.Exec("IPS_HostBasedSetupService", "DisableClientControlMode", { "_method_dummy": _method_dummy }, callback_func); } | ||||
|     obj.IPS_KVMRedirectionSettingData_TerminateSession = function (callback_func) { obj.Exec("IPS_KVMRedirectionSettingData", "TerminateSession", {}, callback_func); } | ||||
|     obj.IPS_KVMRedirectionSettingData_DataChannelRead = function (callback_func, tag) { obj.Exec("IPS_KVMRedirectionSettingData", "DataChannelRead", {}, callback_func, tag); } | ||||
|     obj.IPS_KVMRedirectionSettingData_DataChannelWrite = function (Data, callback_func, tag) { obj.Exec("IPS_KVMRedirectionSettingData", "DataChannelWrite", { "DataMessage": Data }, callback_func, tag); } | ||||
|     obj.IPS_KVMRedirectionSettingData_DataChannelRead = function (callback_func) { obj.Exec("IPS_KVMRedirectionSettingData", "DataChannelRead", {}, callback_func); } | ||||
|     obj.IPS_KVMRedirectionSettingData_DataChannelWrite = function (Data, callback_func) { obj.Exec("IPS_KVMRedirectionSettingData", "DataChannelWrite", { "DataMessage": Data }, callback_func); } | ||||
|     obj.IPS_OptInService_StartOptIn = function (callback_func) { obj.Exec("IPS_OptInService", "StartOptIn", {}, callback_func); } | ||||
|     obj.IPS_OptInService_CancelOptIn = function (callback_func) { obj.Exec("IPS_OptInService", "CancelOptIn", {}, callback_func); } | ||||
|     obj.IPS_OptInService_SendOptInCode = function (OptInCode, callback_func) { obj.Exec("IPS_OptInService", "SendOptInCode", { "OptInCode": OptInCode }, callback_func); } | ||||
|  | ||||
							
								
								
									
										111
									
								
								agents/modules_meshcmd/processManager.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								agents/modules_meshcmd/processManager.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,111 @@ | ||||
| // JavaScript source code
 | ||||
| var GM = require('_GenericMarshal'); | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| function processManager() | ||||
| { | ||||
|     this._ObjectID = 'processManager'; | ||||
|     switch(process.platform) | ||||
|     { | ||||
|         case 'win32': | ||||
|             this._kernel32 = GM.CreateNativeProxy('kernel32.dll'); | ||||
|             this._kernel32.CreateMethod('GetLastError'); | ||||
|             this._kernel32.CreateMethod('CreateToolhelp32Snapshot'); | ||||
|             this._kernel32.CreateMethod('Process32First'); | ||||
|             this._kernel32.CreateMethod('Process32Next'); | ||||
|             break; | ||||
|         case 'linux': | ||||
|             this._childProcess = require('child_process'); | ||||
|             break; | ||||
|         default: | ||||
|             throw (process.platform + ' not supported'); | ||||
|             break; | ||||
|     } | ||||
|     this.getProcesses = function getProcesses(callback) | ||||
|     { | ||||
|         switch(process.platform) | ||||
|         { | ||||
|             default: | ||||
|                 throw ('Enumerating processes on ' + process.platform + ' not supported'); | ||||
|                 break; | ||||
|             case 'win32': | ||||
|                 var retVal = []; | ||||
|                 var h = this._kernel32.CreateToolhelp32Snapshot(2, 0); | ||||
|                 var info = GM.CreateVariable(304); | ||||
|                 info.toBuffer().writeUInt32LE(304, 0); | ||||
|                 var nextProcess = this._kernel32.Process32First(h, info); | ||||
|                 while (nextProcess.Val)  | ||||
|                 { | ||||
|                     retVal.push({ pid: info.Deref(8, 4).toBuffer().readUInt32LE(0), command: info.Deref(GM.PointerSize == 4 ? 36 : 44, 260).String }); | ||||
|                     nextProcess = this._kernel32.Process32Next(h, info); | ||||
|                 } | ||||
|                 if (callback) { callback.apply(this, [retVal]); } | ||||
|                 break; | ||||
|             case 'linux': | ||||
|                 if (!this._psp) { this._psp = {}; } | ||||
|                 var p = this._childProcess.execFile("/bin/ps", ["ps", "-uxa"], { type: this._childProcess.SpawnTypes.TERM }); | ||||
|                 this._psp[p.pid] = p; | ||||
|                 p.Parent = this; | ||||
|                 p.ps = ''; | ||||
|                 p.callback = callback; | ||||
|                 p.args = []; | ||||
|                 for (var i = 1; i < arguments.length; ++i) { p.args.push(arguments[i]); } | ||||
|                 p.on('exit', function onGetProcesses() | ||||
|                 { | ||||
|                     delete this.Parent._psp[this.pid];  | ||||
|                     var retVal = []; | ||||
|                     var lines = this.ps.split('\x0D\x0A'); | ||||
|                     var key = {}; | ||||
|                     var keyi = 0; | ||||
|                     for (var i in lines) | ||||
|                     { | ||||
|                         var tokens = lines[i].split(' '); | ||||
|                         var tokenList = []; | ||||
|                         for(var x in tokens) | ||||
|                         { | ||||
|                             if (i == 0 && tokens[x]) { key[tokens[x]] = keyi++; } | ||||
|                             if (i > 0 && tokens[x]) { tokenList.push(tokens[x]);} | ||||
|                         } | ||||
|                         if(i>0) | ||||
|                         { | ||||
|                             if (tokenList[key.PID]) | ||||
|                             { | ||||
|                                 retVal.push({ pid: tokenList[key.PID], user: tokenList[key.USER], command: tokenList[key.COMMAND] }); | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                     if (this.callback) | ||||
|                     { | ||||
|                         this.args.unshift(retVal); | ||||
|                         this.callback.apply(this.parent, this.args); | ||||
|                     } | ||||
|                 }); | ||||
|                 p.stdout.on('data', function (chunk) { this.parent.ps += chunk.toString(); }); | ||||
|                 break; | ||||
|         } | ||||
|     }; | ||||
|     this.getProcessInfo = function getProcessInfo(pid) | ||||
|     { | ||||
|         switch(process.platform) | ||||
|         { | ||||
|             default: | ||||
|                 throw ('getProcessInfo() not supported for ' + process.platform); | ||||
|                 break; | ||||
|             case 'linux': | ||||
|                 var status = require('fs').readFileSync('/proc/' + pid + '/status'); | ||||
|                 var info = {}; | ||||
|                 var lines = status.toString().split('\n'); | ||||
|                 for(var i in lines) | ||||
|                 { | ||||
|                     var tokens = lines[i].split(':'); | ||||
|                     if (tokens.length > 1) { tokens[1] = tokens[1].trim(); } | ||||
|                     info[tokens[0]] = tokens[1]; | ||||
|                 } | ||||
|                 return (info); | ||||
|                 break; | ||||
|         } | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| module.exports = new processManager(); | ||||
							
								
								
									
										339
									
								
								agents/modules_meshcmd/serviceHost.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										339
									
								
								agents/modules_meshcmd/serviceHost.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,339 @@ | ||||
| 
 | ||||
| var SERVICE_WIN32 = 0x00000010 | 0x00000020; | ||||
| var SERVICE_STATE = { STOPPED: 0x00000001, SERVICE_START_PENDING: 0x00000002, SERVICE_STOP_PENDING: 0x00000003, RUNNING: 0x00000004 }; | ||||
| var SERVICE_ACCEPT = {SERVICE_ACCEPT_STOP: 0x00000001, SERVICE_ACCEPT_SHUTDOWN: 0x00000004}; | ||||
| var SERVICE_CONTROL = {SERVICE_CONTROL_SHUTDOWN: 0x00000005, SERVICE_CONTROL_STOP: 0x00000001}; | ||||
| var NO_ERROR = 0; | ||||
| 
 | ||||
| var serviceManager = require('serviceManager'); | ||||
| 
 | ||||
| function serviceHost(serviceName) | ||||
| { | ||||
|     this._ObjectID = 'serviceHost'; | ||||
|     var emitterUtils = require('events').inherits(this); | ||||
|     emitterUtils.createEvent('serviceStart'); | ||||
|     emitterUtils.createEvent('serviceStop'); | ||||
|     emitterUtils.createEvent('normalStart'); | ||||
| 
 | ||||
|     if (process.platform == 'win32') | ||||
|     { | ||||
|         this.GM = require('_GenericMarshal'); | ||||
|         this.Advapi = this.GM.CreateNativeProxy('Advapi32.dll'); | ||||
|         this.Advapi.CreateMethod({ method: 'StartServiceCtrlDispatcherA', threadDispatch: 1 }); | ||||
|         this.Advapi.CreateMethod('RegisterServiceCtrlHandlerA'); | ||||
|         this.Advapi.CreateMethod('SetServiceStatus'); | ||||
|         this.Kernel32 = this.GM.CreateNativeProxy('Kernel32.dll'); | ||||
|         this.Kernel32.CreateMethod('GetLastError'); | ||||
| 
 | ||||
|         this.Ole32 = this.GM.CreateNativeProxy('Ole32.dll'); | ||||
|         this.Ole32.CreateMethod('CoInitializeEx'); | ||||
|         this.Ole32.CreateMethod('CoUninitialize'); | ||||
| 
 | ||||
|         this._ServiceName = this.GM.CreateVariable(typeof (serviceName) == 'string' ? serviceName : serviceName.name); | ||||
|         this._ServiceMain = this.GM.GetGenericGlobalCallback(2); | ||||
|         this._ServiceMain.Parent = this; | ||||
|         this._ServiceMain.GM = this.GM; | ||||
|         this._ServiceMain.on('GlobalCallback', function onGlobalCallback(argc, argv) | ||||
|         { | ||||
|             //ToDo: Check to make sure this is for us
 | ||||
| 
 | ||||
|             this.Parent._ServiceStatus = this.GM.CreateVariable(28); | ||||
|             //typedef struct _SERVICE_STATUS {
 | ||||
|             //    DWORD   dwServiceType;
 | ||||
|             //    DWORD   dwCurrentState;
 | ||||
|             //    DWORD   dwControlsAccepted;
 | ||||
|             //    DWORD   dwWin32ExitCode;
 | ||||
|             //    DWORD   dwServiceSpecificExitCode;
 | ||||
|             //    DWORD   dwCheckPoint;
 | ||||
|             //    DWORD   dwWaitHint;
 | ||||
|             //} SERVICE_STATUS, *LPSERVICE_STATUS;
 | ||||
| 
 | ||||
|             // Initialise service status
 | ||||
|             this.Parent._ServiceStatus.toBuffer().writeUInt32LE(SERVICE_WIN32); | ||||
|             this.Parent._ServiceStatus.toBuffer().writeUInt32LE(SERVICE_STATE.SERVICE_STOPPED, 4); | ||||
|             this.Parent._ServiceStatusHandle = this.Parent.Advapi.RegisterServiceCtrlHandlerA(this.Parent._ServiceName, this.Parent._ServiceControlHandler); | ||||
|             if(this.Parent._ServiceStatusHandle.Val == 0) | ||||
|             { | ||||
|                 process.exit(1); | ||||
|             } | ||||
| 
 | ||||
|             // Service is starting
 | ||||
|             this.Parent._ServiceStatus.toBuffer().writeUInt32LE(SERVICE_STATE.SERVICE_START_PENDING, 4); | ||||
|             this.Parent.Advapi.SetServiceStatus(this.Parent._ServiceStatusHandle, this.Parent._ServiceStatus); | ||||
| 
 | ||||
|             // Service running
 | ||||
|             this.Parent._ServiceStatus.toBuffer().writeUInt32LE(SERVICE_STATE.RUNNING, 4); | ||||
|             this.Parent._ServiceStatus.toBuffer().writeUInt32LE(SERVICE_ACCEPT.SERVICE_ACCEPT_STOP, 8); | ||||
|             this.Parent.Advapi.SetServiceStatus(this.Parent._ServiceStatusHandle, this.Parent._ServiceStatus); | ||||
| 
 | ||||
|             this.Parent.Ole32.CoInitializeEx(0, 2); | ||||
|             this.Parent.on('~', function OnServiceHostFinalizer() | ||||
|             {             | ||||
|                 var GM = require('_GenericMarshal'); | ||||
|                 var Advapi = GM.CreateNativeProxy('Advapi32.dll'); | ||||
|                 Advapi.CreateMethod('SetServiceStatus'); | ||||
| 
 | ||||
|                 Kernel32 = this.GM.CreateNativeProxy('Kernel32.dll'); | ||||
|                 Kernel32.CreateMethod('GetLastError'); | ||||
| 
 | ||||
|                 var status = GM.CreateVariable(28); | ||||
| 
 | ||||
|                 // Service was stopped
 | ||||
|                 status.toBuffer().writeUInt32LE(SERVICE_WIN32); | ||||
|                 status.toBuffer().writeUInt32LE(0x00000001, 4); | ||||
|                 status.toBuffer().writeUInt32LE(0, 8); | ||||
| 
 | ||||
|                 Advapi.SetServiceStatus(this._ServiceStatusHandle, status); | ||||
| 
 | ||||
|                 this.Ole32.CoUninitialize(); | ||||
|             }); | ||||
|             this.Parent.emit('serviceStart'); | ||||
|         }); | ||||
|         this._ServiceControlHandler = this.GM.GetGenericGlobalCallback(1); | ||||
|         this._ServiceControlHandler.Parent = this; | ||||
|         this._ServiceControlHandler.GM = this.GM; | ||||
|         this._ServiceControlHandler.on('GlobalCallback', function onServiceControlHandler(code) | ||||
|         { | ||||
|             switch (code.Val) | ||||
|             { | ||||
|                 case SERVICE_CONTROL.SERVICE_CONTROL_SHUTDOWN: | ||||
|                 case SERVICE_CONTROL.SERVICE_CONTROL_STOP: | ||||
|                     this.Parent.emit('serviceStop'); | ||||
|                     return; | ||||
|                 default: | ||||
|                     break; | ||||
|             } | ||||
| 
 | ||||
|             this.Parent.Advapi.SetServiceStatus(this.Parent._ServiceStatusHandle, this.Parent._ServiceStatus); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     if (serviceName) { this._ServiceOptions = typeof (serviceName) == 'object' ? serviceName : { name: serviceName }; } | ||||
|     else | ||||
|     { | ||||
|         throw ('Must specify either ServiceName or Options'); | ||||
|     } | ||||
|     if (!this._ServiceOptions.servicePath) | ||||
|     { | ||||
|         this._ServiceOptions.servicePath = process.execPath; | ||||
|     } | ||||
|      | ||||
|     this.run = function run() | ||||
|     { | ||||
|         var serviceOperation = 0; | ||||
| 
 | ||||
|         for(var i = 0; i<process.argv.length; ++i) | ||||
|         { | ||||
|             switch(process.argv[i]) | ||||
|             { | ||||
|                 case '-install': | ||||
|                     if (!this._svcManager) { this._svcManager = new serviceManager(); } | ||||
|                     try | ||||
|                     { | ||||
|                         this._svcManager.installService(this._ServiceOptions); | ||||
|                     } | ||||
|                     catch(e) | ||||
|                     { | ||||
|                         console.log(e); | ||||
|                         process.exit(); | ||||
|                     } | ||||
|                     if (process.platform == 'win32') | ||||
|                     { | ||||
|                         // Only do this on Windows, becuase Linux is async... It'll complete later
 | ||||
|                         console.log(this._ServiceOptions.name + ' installed'); | ||||
|                         process.exit(); | ||||
|                     } | ||||
|                     i = process.argv.length; | ||||
|                     serviceOperation = 1; | ||||
|                     break; | ||||
|                 case '-uninstall': | ||||
|                     if (!this._svcManager) { this._svcManager = new serviceManager(); } | ||||
|                     try | ||||
|                     { | ||||
|                         this._svcManager.uninstallService(this._ServiceOptions); | ||||
|                     } | ||||
|                     catch(e) | ||||
|                     { | ||||
|                         console.log(e); | ||||
|                         process.exit(); | ||||
|                     } | ||||
|                     if (process.platform == 'win32') | ||||
|                     { | ||||
|                         // Only do this on Windows, becuase Linux is async... It'll complete later
 | ||||
|                         console.log(this._ServiceOptions.name + ' uninstalled'); | ||||
|                         process.exit(); | ||||
|                     } | ||||
|                     i = process.argv.length; | ||||
|                     serviceOperation = 1; | ||||
|                     break; | ||||
|                 case 'start': | ||||
|                 case '-d': | ||||
|                     if (!this._svcManager) { this._svcManager = new serviceManager(); } | ||||
|                     this._svcManager.getService(this._ServiceOptions.name).start(); | ||||
|                     console.log(this._ServiceOptions.name + ' starting...'); | ||||
|                     process.exit(); | ||||
|                     break; | ||||
|                 case 'stop': | ||||
|                 case '-s': | ||||
|                     if (!this._svcManager) { this._svcManager = new serviceManager(); } | ||||
|                     this._svcManager.getService(this._ServiceOptions.name).stop(); | ||||
|                     console.log(this._ServiceOptions.name + ' stopping...'); | ||||
|                     process.exit(); | ||||
|                     break; | ||||
| 
 | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         if (process.platform == 'win32') | ||||
|         { | ||||
|             var serviceTable = this.GM.CreateVariable(4 * this.GM.PointerSize); | ||||
|             this._ServiceName.pointerBuffer().copy(serviceTable.toBuffer()); | ||||
|             this._ServiceMain.pointerBuffer().copy(serviceTable.toBuffer(), this.GM.PointerSize); | ||||
|             this._sscd = this.Advapi.StartServiceCtrlDispatcherA(serviceTable); | ||||
|             this._sscd.parent = this; | ||||
|             this._sscd.on('done', function OnStartServiceCtrlDispatcherA(retVal) { | ||||
|                 if (retVal.Val == 0) | ||||
|                 { | ||||
|                     this.parent.emit('normalStart'); | ||||
|                 } | ||||
|             }); | ||||
|             return; | ||||
|         } | ||||
|          | ||||
|         var moduleName = this._ServiceOptions ? this._ServiceOptions.name : process.execPath.substring(1 + process.execPath.lastIndexOf('/')); | ||||
| 
 | ||||
|         for (var i = 0; i < process.argv.length; ++i) | ||||
|         { | ||||
|             switch(process.argv[i]) | ||||
|             { | ||||
|                 case 'start': | ||||
|                 case '-d': | ||||
|                     var child = require('child_process').execFile(process.execPath, [moduleName], { type: require('child_process').SpawnTypes.DETACHED }); | ||||
|                     var pstream = null; | ||||
|                     try | ||||
|                     { | ||||
|                         pstream = require('fs').createWriteStream('/var/run/' + moduleName + '.pid', { flags: 'w' }); | ||||
|                     } | ||||
|                     catch(e) | ||||
|                     { | ||||
|                     } | ||||
|                     if (pstream == null) | ||||
|                     { | ||||
|                         pstream = require('fs').createWriteStream('.' + moduleName + '.pid', { flags: 'w' }); | ||||
|                     } | ||||
|                     pstream.end(child.pid.toString()); | ||||
| 
 | ||||
|                     console.log(moduleName + ' started!'); | ||||
|                     process.exit(); | ||||
|                     break; | ||||
|                 case 'stop': | ||||
|                 case '-s': | ||||
|                     var pid = null; | ||||
|                     try | ||||
|                     { | ||||
|                         pid = parseInt(require('fs').readFileSync('/var/run/' + moduleName + '.pid', { flags: 'r' })); | ||||
|                         require('fs').unlinkSync('/var/run/' + moduleName + '.pid'); | ||||
|                     } | ||||
|                     catch(e) | ||||
|                     { | ||||
|                     } | ||||
|                     if(pid == null) | ||||
|                     { | ||||
|                         try | ||||
|                         { | ||||
|                             pid = parseInt(require('fs').readFileSync('.' + moduleName + '.pid', { flags: 'r' })); | ||||
|                             require('fs').unlinkSync('.' + moduleName + '.pid'); | ||||
|                         } | ||||
|                         catch(e) | ||||
|                         { | ||||
|                         } | ||||
|                     } | ||||
| 
 | ||||
|                     if(pid) | ||||
|                     { | ||||
|                         process.kill(pid); | ||||
|                         console.log(moduleName + ' stopped'); | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         console.log(moduleName + ' not running'); | ||||
|                     } | ||||
|                     process.exit(); | ||||
|                     break; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         if(serviceOperation == 0) | ||||
|         { | ||||
|             // This is non-windows, so we need to check how this binary was started to determine if this was a service start
 | ||||
| 
 | ||||
|             // Start by checking if we were started with start/stop
 | ||||
|             var pid = null; | ||||
|             try | ||||
|             { | ||||
|                 pid = parseInt(require('fs').readFileSync('/var/run/' + moduleName + '.pid', { flags: 'r' })); | ||||
|             } | ||||
|             catch (e) | ||||
|             { | ||||
|             } | ||||
|             if (pid == null) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     pid = parseInt(require('fs').readFileSync('.' + moduleName + '.pid', { flags: 'r' })); | ||||
|                 } | ||||
|                 catch (e) | ||||
|                 { | ||||
|                 } | ||||
|             } | ||||
|              | ||||
|             if (pid != null && pid == process.pid) | ||||
|             { | ||||
|                 this.emit('serviceStart'); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 // Now we need to check if we were started with systemd
 | ||||
|                 if (require('processManager').getProcessInfo(1).Name == 'systemd') | ||||
|                 { | ||||
|                     this._checkpid = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM }); | ||||
|                     this._checkpid.result = ''; | ||||
|                     this._checkpid.parent = this; | ||||
|                     this._checkpid.on('exit', function onCheckPIDExit() | ||||
|                     { | ||||
|                         var lines = this.result.split('\r\n'); | ||||
|                         for (i in lines) | ||||
|                         { | ||||
|                             if(lines[i].startsWith(' Main PID:')) | ||||
|                             { | ||||
|                                 var tokens = lines[i].split(' '); | ||||
|                                 if (parseInt(tokens[3]) == process.pid) | ||||
|                                 { | ||||
|                                     this.parent.emit('serviceStart'); | ||||
|                                 } | ||||
|                                 else | ||||
|                                 { | ||||
|                                     this.parent.emit('normalStart'); | ||||
|                                 } | ||||
|                                 delete this.parent._checkpid; | ||||
|                                 return; | ||||
|                             } | ||||
|                         } | ||||
|                         this.parent.emit('normalStart'); | ||||
|                         delete this.parent._checkpid; | ||||
|                     }); | ||||
|                     this._checkpid.stdout.on('data', function (chunk) { this.parent.result += chunk.toString(); }); | ||||
|                     this._checkpid.stdin.write("systemctl status " + moduleName + " | grep 'Main PID:'\n"); | ||||
|                     this._checkpid.stdin.write('exit\n'); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     // This isn't even a systemd platform, so this couldn't have been a service start
 | ||||
|                     this.emit('normalStart'); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| module.exports = serviceHost; | ||||
							
								
								
									
										394
									
								
								agents/modules_meshcmd/serviceManager.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										394
									
								
								agents/modules_meshcmd/serviceManager.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,394 @@ | ||||
| 
 | ||||
| 
 | ||||
| function parseServiceStatus(token) | ||||
| { | ||||
|     var j = {}; | ||||
|     var serviceType = token.Deref(0, 4).IntVal; | ||||
|     j.isFileSystemDriver = ((serviceType & 0x00000002) == 0x00000002); | ||||
|     j.isKernelDriver = ((serviceType & 0x00000001) == 0x00000001); | ||||
|     j.isSharedProcess = ((serviceType & 0x00000020) == 0x00000020); | ||||
|     j.isOwnProcess = ((serviceType & 0x00000010) == 0x00000010); | ||||
|     j.isInteractive = ((serviceType & 0x00000100) == 0x00000100); | ||||
|     switch (token.Deref((1 * 4), 4).toBuffer().readUInt32LE()) | ||||
|     { | ||||
|         case 0x00000005: | ||||
|             j.state = 'CONTINUE_PENDING'; | ||||
|             break; | ||||
|         case 0x00000006: | ||||
|             j.state = 'PAUSE_PENDING'; | ||||
|             break; | ||||
|         case 0x00000007: | ||||
|             j.state = 'PAUSED'; | ||||
|             break; | ||||
|         case 0x00000004: | ||||
|             j.state = 'RUNNING'; | ||||
|             break; | ||||
|         case 0x00000002: | ||||
|             j.state = 'START_PENDING'; | ||||
|             break; | ||||
|         case 0x00000003: | ||||
|             j.state = 'STOP_PENDING'; | ||||
|             break; | ||||
|         case 0x00000001: | ||||
|             j.state = 'STOPPED'; | ||||
|             break; | ||||
|     } | ||||
|     var controlsAccepted = token.Deref((2 * 4), 4).toBuffer().readUInt32LE(); | ||||
|     j.controlsAccepted = []; | ||||
|     if ((controlsAccepted & 0x00000010) == 0x00000010) | ||||
|     { | ||||
|         j.controlsAccepted.push('SERVICE_CONTROL_NETBINDADD'); | ||||
|         j.controlsAccepted.push('SERVICE_CONTROL_NETBINDREMOVE'); | ||||
|         j.controlsAccepted.push('SERVICE_CONTROL_NETBINDENABLE'); | ||||
|         j.controlsAccepted.push('SERVICE_CONTROL_NETBINDDISABLE'); | ||||
|     } | ||||
|     if ((controlsAccepted & 0x00000008) == 0x00000008) { j.controlsAccepted.push('SERVICE_CONTROL_PARAMCHANGE'); } | ||||
|     if ((controlsAccepted & 0x00000002) == 0x00000002) { j.controlsAccepted.push('SERVICE_CONTROL_PAUSE'); j.controlsAccepted.push('SERVICE_CONTROL_CONTINUE'); } | ||||
|     if ((controlsAccepted & 0x00000100) == 0x00000100) { j.controlsAccepted.push('SERVICE_CONTROL_PRESHUTDOWN'); } | ||||
|     if ((controlsAccepted & 0x00000004) == 0x00000004) { j.controlsAccepted.push('SERVICE_CONTROL_SHUTDOWN'); } | ||||
|     if ((controlsAccepted & 0x00000001) == 0x00000001) { j.controlsAccepted.push('SERVICE_CONTROL_STOP'); } | ||||
|     if ((controlsAccepted & 0x00000020) == 0x00000020) { j.controlsAccepted.push('SERVICE_CONTROL_HARDWAREPROFILECHANGE'); } | ||||
|     if ((controlsAccepted & 0x00000040) == 0x00000040) { j.controlsAccepted.push('SERVICE_CONTROL_POWEREVENT'); } | ||||
|     if ((controlsAccepted & 0x00000080) == 0x00000080) { j.controlsAccepted.push('SERVICE_CONTROL_SESSIONCHANGE'); } | ||||
|     j.pid = token.Deref((7 * 4), 4).toBuffer().readUInt32LE(); | ||||
|     return (j); | ||||
| } | ||||
| 
 | ||||
| function serviceManager() | ||||
| { | ||||
|     if (process.platform == 'win32')  | ||||
|     { | ||||
|         this.GM = require('_GenericMarshal'); | ||||
|         this.proxy = this.GM.CreateNativeProxy('Advapi32.dll'); | ||||
|         this.proxy.CreateMethod('OpenSCManagerA'); | ||||
|         this.proxy.CreateMethod('EnumServicesStatusExA'); | ||||
|         this.proxy.CreateMethod('OpenServiceA'); | ||||
|         this.proxy.CreateMethod('QueryServiceStatusEx'); | ||||
|         this.proxy.CreateMethod('ControlService'); | ||||
|         this.proxy.CreateMethod('StartServiceA'); | ||||
|         this.proxy.CreateMethod('CloseServiceHandle'); | ||||
|         this.proxy.CreateMethod('CreateServiceA'); | ||||
|         this.proxy.CreateMethod('ChangeServiceConfig2A'); | ||||
|         this.proxy.CreateMethod('DeleteService'); | ||||
|         this.proxy.CreateMethod('AllocateAndInitializeSid'); | ||||
|         this.proxy.CreateMethod('CheckTokenMembership'); | ||||
|         this.proxy.CreateMethod('FreeSid'); | ||||
| 
 | ||||
|         this.proxy2 = this.GM.CreateNativeProxy('Kernel32.dll'); | ||||
|         this.proxy2.CreateMethod('GetLastError'); | ||||
| 
 | ||||
|         this.isAdmin = function isAdmin() { | ||||
|             var NTAuthority = this.GM.CreateVariable(6); | ||||
|             NTAuthority.toBuffer().writeInt8(5, 5); | ||||
|             var AdministratorsGroup = this.GM.CreatePointer(); | ||||
|             var admin = false; | ||||
| 
 | ||||
|             if (this.proxy.AllocateAndInitializeSid(NTAuthority, 2, 32, 544, 0, 0, 0, 0, 0, 0, AdministratorsGroup).Val != 0) | ||||
|             { | ||||
|                 var member = this.GM.CreateInteger(); | ||||
|                 if (this.proxy.CheckTokenMembership(0, AdministratorsGroup.Deref(), member).Val != 0) | ||||
|                 { | ||||
|                     if (member.toBuffer().readUInt32LE() != 0) { admin = true; } | ||||
|                 } | ||||
|                 this.proxy.FreeSid(AdministratorsGroup.Deref()); | ||||
|             } | ||||
|             return admin; | ||||
|         }; | ||||
|         this.getServiceFolder = function getServiceFolder() | ||||
|         { | ||||
|             var destinationFolder = null; | ||||
|             if (require('os').arch() == 'x64') | ||||
|             { | ||||
|                 // 64 bit Windows
 | ||||
|                 if (this.GM.PointerSize == 4) | ||||
|                 { | ||||
|                     // 32 Bit App
 | ||||
|                     destinationFolder = process.env['ProgramFiles(x86)']; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     // 64 bit App
 | ||||
|                     destinationFolder = process.env['ProgramFiles']; | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 // 32 bit Windows
 | ||||
|                 destinationFolder = process.env['ProgramFiles']; | ||||
|             } | ||||
|             return (destinationFolder + '\\mesh'); | ||||
|         }; | ||||
| 
 | ||||
|         this.enumerateService = function () { | ||||
|             var machineName = this.GM.CreatePointer(); | ||||
|             var dbName = this.GM.CreatePointer(); | ||||
|             var handle = this.proxy.OpenSCManagerA(0x00, 0x00, 0x0001 | 0x0004); | ||||
| 
 | ||||
|             var bytesNeeded = this.GM.CreatePointer(); | ||||
|             var servicesReturned = this.GM.CreatePointer(); | ||||
|             var resumeHandle = this.GM.CreatePointer(); | ||||
|             //var services = this.proxy.CreateVariable(262144);
 | ||||
|             var success = this.proxy.EnumServicesStatusExA(handle, 0, 0x00000030, 0x00000003, 0x00, 0x00, bytesNeeded, servicesReturned, resumeHandle, 0x00); | ||||
|             if (bytesNeeded.IntVal <= 0) { | ||||
|                 throw ('error enumerating services'); | ||||
|             } | ||||
|             var sz = bytesNeeded.IntVal; | ||||
|             var services = this.GM.CreateVariable(sz); | ||||
|             this.proxy.EnumServicesStatusExA(handle, 0, 0x00000030, 0x00000003, services, sz, bytesNeeded, servicesReturned, resumeHandle, 0x00); | ||||
|             console.log("servicesReturned", servicesReturned.IntVal); | ||||
| 
 | ||||
|             var ptrSize = dbName._size; | ||||
|             var blockSize = 36 + (2 * ptrSize); | ||||
|             blockSize += ((ptrSize - (blockSize % ptrSize)) % ptrSize); | ||||
|             var retVal = []; | ||||
|             for (var i = 0; i < servicesReturned.IntVal; ++i) { | ||||
|                 var token = services.Deref(i * blockSize, blockSize); | ||||
|                 var j = {}; | ||||
|                 j.name = token.Deref(0, ptrSize).Deref().String; | ||||
|                 j.displayName = token.Deref(ptrSize, ptrSize).Deref().String; | ||||
|                 j.status = parseServiceStatus(token.Deref(2 * ptrSize, 36)); | ||||
|                 retVal.push(j); | ||||
|             } | ||||
|             this.proxy.CloseServiceHandle(handle); | ||||
|             return (retVal); | ||||
|         } | ||||
|         this.getService = function (name) { | ||||
|             var serviceName = this.GM.CreateVariable(name); | ||||
|             var ptr = this.GM.CreatePointer(); | ||||
|             var bytesNeeded = this.GM.CreateVariable(ptr._size); | ||||
|             var handle = this.proxy.OpenSCManagerA(0x00, 0x00, 0x0001 | 0x0004 | 0x0020 | 0x0010); | ||||
|             if (handle.Val == 0) { throw ('could not open ServiceManager'); } | ||||
|             var h = this.proxy.OpenServiceA(handle, serviceName, 0x0004 | 0x0020 | 0x0010 | 0x00010000); | ||||
|             if (h.Val != 0) { | ||||
|                 var success = this.proxy.QueryServiceStatusEx(h, 0, 0, 0, bytesNeeded); | ||||
|                 var status = this.GM.CreateVariable(bytesNeeded.toBuffer().readUInt32LE()); | ||||
|                 success = this.proxy.QueryServiceStatusEx(h, 0, status, status._size, bytesNeeded); | ||||
|                 if (success != 0) { | ||||
|                     retVal = {}; | ||||
|                     retVal.status = parseServiceStatus(status); | ||||
|                     retVal._scm = handle; | ||||
|                     retVal._service = h; | ||||
|                     retVal._GM = this.GM; | ||||
|                     retVal._proxy = this.proxy; | ||||
|                     require('events').inherits(retVal); | ||||
|                     retVal.on('~', function () { this._proxy.CloseServiceHandle(this); this._proxy.CloseServiceHandle(this._scm); }); | ||||
|                     retVal.name = name; | ||||
|                     retVal.stop = function () { | ||||
|                         if (this.status.state == 'RUNNING') { | ||||
|                             var newstate = this._GM.CreateVariable(36); | ||||
|                             var success = this._proxy.ControlService(this._service, 0x00000001, newstate); | ||||
|                             if (success == 0) { | ||||
|                                 throw (this.name + '.stop() failed'); | ||||
|                             } | ||||
|                         } | ||||
|                         else { | ||||
|                             throw ('cannot call ' + this.name + '.stop(), when current state is: ' + this.status.state); | ||||
|                         } | ||||
|                     } | ||||
|                     retVal.start = function () { | ||||
|                         if (this.status.state == 'STOPPED') { | ||||
|                             var success = this._proxy.StartServiceA(this._service, 0, 0); | ||||
|                             if (success == 0) { | ||||
|                                 throw (this.name + '.start() failed'); | ||||
|                             } | ||||
|                         } | ||||
|                         else { | ||||
|                             throw ('cannot call ' + this.name + '.start(), when current state is: ' + this.status.state); | ||||
|                         } | ||||
|                     } | ||||
|                     return (retVal); | ||||
|                 } | ||||
|                 else { | ||||
| 
 | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             this.proxy.CloseServiceHandle(handle); | ||||
|             throw ('could not find service: ' + name); | ||||
|         } | ||||
|     } | ||||
|     this.installService = function installService(options) | ||||
|     { | ||||
|         if (process.platform == 'win32') | ||||
|         { | ||||
|             if (!this.isAdmin()) { throw ('Installing as Service, requires admin'); } | ||||
| 
 | ||||
|             // Before we start, we need to copy the binary to the right place
 | ||||
|             var folder = this.getServiceFolder(); | ||||
|             if (!require('fs').existsSync(folder)) { require('fs').mkdirSync(folder); } | ||||
|             require('fs').copyFileSync(options.servicePath, folder + '\\' + options.name + '.exe'); | ||||
|             options.servicePath = folder + '\\' + options.name + '.exe'; | ||||
| 
 | ||||
|             var servicePath = this.GM.CreateVariable('"' + options.servicePath + '"'); | ||||
|             var handle = this.proxy.OpenSCManagerA(0x00, 0x00, 0x0002); | ||||
|             if (handle.Val == 0) { throw ('error opening SCManager'); } | ||||
|             var serviceName = this.GM.CreateVariable(options.name); | ||||
|             var displayName = this.GM.CreateVariable(options.name); | ||||
|             var allAccess = 0x000F01FF; | ||||
|             var serviceType; | ||||
|              | ||||
| 
 | ||||
|             switch (options.startType) { | ||||
|                 case 'BOOT_START': | ||||
|                     serviceType = 0x00; | ||||
|                     break; | ||||
|                 case 'SYSTEM_START': | ||||
|                     serviceType = 0x01; | ||||
|                     break; | ||||
|                 case 'AUTO_START': | ||||
|                     serviceType = 0x02; | ||||
|                     break; | ||||
|                 case 'DEMAND_START': | ||||
|                     serviceType = 0x03; | ||||
|                     break; | ||||
|                 default: | ||||
|                     serviceType = 0x04; // Disabled
 | ||||
|                     break; | ||||
|             } | ||||
| 
 | ||||
|             var h = this.proxy.CreateServiceA(handle, serviceName, displayName, allAccess, 0x10 | 0x100, serviceType, 0, servicePath, 0, 0, 0, 0, 0); | ||||
|             if (h.Val == 0) { this.proxy.CloseServiceHandle(handle); throw ('Error Creating Service: ' + this.proxy2.GetLastError().Val); } | ||||
|             if (options.description) { | ||||
|                 console.log(options.description); | ||||
| 
 | ||||
|                 var dscPtr = this.GM.CreatePointer(); | ||||
|                 dscPtr.Val = this.GM.CreateVariable(options.description); | ||||
| 
 | ||||
|                 if (this.proxy.ChangeServiceConfig2A(h, 1, dscPtr) == 0) { | ||||
|                     this.proxy.CloseServiceHandle(h); | ||||
|                     this.proxy.CloseServiceHandle(handle); | ||||
|                     throw ('Unable to set description'); | ||||
|                 } | ||||
|             } | ||||
|             this.proxy.CloseServiceHandle(h); | ||||
|             this.proxy.CloseServiceHandle(handle); | ||||
|             return (this.getService(options.name)); | ||||
|         } | ||||
|         if(process.platform == 'linux') | ||||
|         { | ||||
|             switch (this.getServiceType()) | ||||
|             { | ||||
|                 case 'init': | ||||
|                     require('fs').copyFileSync(options.servicePath, '/etc/init.d/' + options.name); | ||||
|                     console.log('copying ' + options.servicePath); | ||||
|                     var m = require('fs').statSync('/etc/init.d/' + options.name).mode; | ||||
|                     m |= (require('fs').CHMOD_MODES.S_IXUSR | require('fs').CHMOD_MODES.S_IXGRP); | ||||
|                     require('fs').chmodSync('/etc/init.d/' + options.name, m); | ||||
|                     this._update = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM }); | ||||
|                     this._update._moduleName = options.name; | ||||
|                     this._update.on('exit', function onUpdateRC_d() { console.log(this._moduleName + ' installed'); process.exit(); }); | ||||
|                     this._update.stdout.on('data', function (chunk) { }); | ||||
|                     this._update.stdin.write('update-rc.d ' + options.name + ' defaults\n'); | ||||
|                     this._update.stdin.write('exit\n'); | ||||
|                     //update-rc.d meshagent defaults # creates symlinks for rc.d
 | ||||
|                     //service meshagent start
 | ||||
| 
 | ||||
|                     break; | ||||
|                 case 'systemd': | ||||
|                     var serviceDescription = options.description ? options.description : 'MeshCentral Agent'; | ||||
|                     if (!require('fs').existsSync('/usr/local/mesh')) { require('fs').mkdirSync('/usr/local/mesh'); } | ||||
|                     require('fs').copyFileSync(options.servicePath, '/usr/local/mesh/' + options.name); | ||||
|                     var m = require('fs').statSync('/usr/local/mesh/' + options.name).mode; | ||||
|                     m |= (require('fs').CHMOD_MODES.S_IXUSR | require('fs').CHMOD_MODES.S_IXGRP); | ||||
|                     require('fs').chmodSync('/usr/local/mesh/' + options.name, m); | ||||
|                     require('fs').writeFileSync('/lib/systemd/system/' + options.name + '.service', '[Unit]\nDescription=' + serviceDescription + '\n[Service]\nExecStart=/usr/local/mesh/' + options.name + '\nStandardOutput=null\nRestart=always\nRestartSec=3\n[Install]\nWantedBy=multi-user.target\nAlias=' + options.name + '.service\n', { flags: 'w' }); | ||||
|                     this._update = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM }); | ||||
|                     this._update._moduleName = options.name; | ||||
|                     this._update.on('exit', function onUpdateRC_d() { console.log(this._moduleName + ' installed'); process.exit(); }); | ||||
|                     this._update.stdout.on('data', function (chunk) { }); | ||||
|                     this._update.stdin.write('systemctl enable ' + options.name + '.service\n'); | ||||
|                     this._update.stdin.write('exit\n'); | ||||
| 
 | ||||
|                     break; | ||||
|                 default: // unknown platform service type
 | ||||
|                     break; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     this.uninstallService = function uninstallService(name) | ||||
|     { | ||||
|         if (typeof (name) == 'object') { name = name.name; } | ||||
|         if (process.platform == 'win32') | ||||
|         { | ||||
|             if (!this.isAdmin()) { throw ('Uninstalling a service, requires admin'); } | ||||
| 
 | ||||
|             var service = this.getService(name); | ||||
|             if (service.status.state == undefined || service.status.state == 'STOPPED') | ||||
|             { | ||||
|                 if (this.proxy.DeleteService(service._service) == 0) | ||||
|                 { | ||||
|                     throw ('Uninstall Service for: ' + name + ', failed with error: ' + this.proxy2.GetLastError()); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     try | ||||
|                     { | ||||
|                         require('fs').unlinkSync(this.getServiceFolder() + '\\' + name + '.exe'); | ||||
|                     } | ||||
|                     catch(e) | ||||
|                     { | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 throw ('Cannot uninstall service: ' + name + ', because it is: ' + service.status.state); | ||||
|             } | ||||
|         } | ||||
|         else if(process.platform == 'linux') | ||||
|         { | ||||
|             switch (this.getServiceType()) | ||||
|             { | ||||
|                 case 'init': | ||||
|                     this._update = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM }); | ||||
|                     this._update._svcname = name; | ||||
|                     this._update.on('exit', function onUninstallExit() { | ||||
|                         try { | ||||
|                             require('fs').unlinkSync('/etc/init.d/' + this._svcname); | ||||
|                             console.log(this._svcname + ' uninstalled'); | ||||
| 
 | ||||
|                         } | ||||
|                         catch (e) { | ||||
|                             console.log(this._svcname + ' could not be uninstalled') | ||||
|                         } | ||||
|                         process.exit(); | ||||
|                     }); | ||||
|                     this._update.stdout.on('data', function (chunk) { }); | ||||
|                     this._update.stdin.write('service ' + name + ' stop\n'); | ||||
|                     this._update.stdin.write('update-rc.d -f ' + name + ' remove\n'); | ||||
|                     this._update.stdin.write('exit\n'); | ||||
|                     break; | ||||
|                 case 'systemd': | ||||
|                     this._update = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM }); | ||||
|                     this._update._svcname = name; | ||||
|                     this._update.on('exit', function onUninstallExit() { | ||||
|                         try { | ||||
|                             require('fs').unlinkSync('/usr/local/mesh/' + this._svcname); | ||||
|                             require('fs').unlinkSync('/lib/systemd/system/' + this._svcname + '.service'); | ||||
|                             console.log(this._svcname + ' uninstalled'); | ||||
|                         } | ||||
|                         catch (e) { | ||||
|                             console.log(this._svcname + ' could not be uninstalled') | ||||
|                         } | ||||
|                         process.exit(); | ||||
|                     }); | ||||
|                     this._update.stdout.on('data', function (chunk) { }); | ||||
|                     this._update.stdin.write('systemctl stop ' + name + '.service\n'); | ||||
|                     this._update.stdin.write('systemctl disable ' + name + '.service\n'); | ||||
|                     this._update.stdin.write('exit\n'); | ||||
|                     break; | ||||
|                 default: // unknown platform service type
 | ||||
|                     break; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     if(process.platform == 'linux') | ||||
|     { | ||||
|         this.getServiceType = function getServiceType() | ||||
|         { | ||||
|             return (require('processManager').getProcessInfo(1).Name); | ||||
|         }; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| module.exports = serviceManager; | ||||
							
								
								
									
										50
									
								
								meshuser.js
									
									
									
									
									
								
							
							
						
						
									
										50
									
								
								meshuser.js
									
									
									
									
									
								
							| @ -11,11 +11,12 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { | ||||
|     var obj = {}; | ||||
|     obj.db = db; | ||||
|     obj.ws = ws; | ||||
|     obj.fs = parent.fs; | ||||
|     obj.args = args; | ||||
|     obj.parent = parent; | ||||
|     obj.domain = domain; | ||||
|     obj.common = parent.common; | ||||
|     obj.fs = require('fs'); | ||||
|     obj.path = require('path'); | ||||
| 
 | ||||
|     // Send a message to the user
 | ||||
|     //obj.send = function (data) { try { if (typeof data == 'string') { obj.ws.send(new Buffer(data, 'binary')); } else { obj.ws.send(data); } } catch (e) { } }
 | ||||
| @ -26,6 +27,34 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { | ||||
|         if (arg == 2) { try { obj.ws._socket._parent.end(); obj.parent.parent.debug(1, 'Hard disconnect'); } catch (e) { console.log(e); } } // Hard close, close the TCP socket
 | ||||
|     } | ||||
| 
 | ||||
|     // Convert a mesh path array into a real path on the server side
 | ||||
|     function meshPathToRealPath(meshpath) { | ||||
|         var rootfolder = meshpath[0], rootfoldersplit = rootfolder.split('/'), domainx = 'domain'; | ||||
|         if (rootfoldersplit[1].length > 0) domainx = 'domain-' + rootfoldersplit[1]; | ||||
|         var path = obj.parent.path.join(obj.parent.filespath, domainx, rootfoldersplit[0] + "-" + rootfoldersplit[2]); | ||||
|         for (var i = 1; i < meshpath.length; i++) { if (obj.common.IsFilenameValid(meshpath[i]) == false) { path = null; break; } path += ("/" + meshpath[i]); } | ||||
|         return path; | ||||
|     } | ||||
| 
 | ||||
|     // 
 | ||||
|     function copyFile(src, dest, func, tag) { | ||||
| 		//var ss = obj.fs.createReadStream(src, { flags: 'rb' });
 | ||||
|         //var ds = obj.fs.createWriteStream(dest, { flags: 'wb' });
 | ||||
|         var ss = obj.fs.createReadStream(src); | ||||
|         var ds = obj.fs.createWriteStream(dest); | ||||
|         ss.fs = obj.fs; | ||||
| 		ss.pipe(ds); | ||||
|         ds.ss = ss; | ||||
|         /* | ||||
| 		if (!this._copyStreams) { this._copyStreams = {}; this._copyStreamID = 0; } | ||||
| 		ss.id = this._copyStreamID++; | ||||
| 		this._copyStreams[ss.id] = ss; | ||||
|         */ | ||||
| 		if (arguments.length == 3 && typeof arguments[2] === 'function') { ds.on('close', arguments[2]); } | ||||
| 		else if (arguments.length == 4 && typeof arguments[3] === 'function') { ds.on('close', arguments[3]); } | ||||
|         ds.on('close', function() { /*delete this.ss.fs._copyStreams[this.ss.id];*/ func(tag); }); | ||||
| 	}; | ||||
| 
 | ||||
|     try { | ||||
|         // Check if the user is logged in
 | ||||
|         if ((!req.session) || (!req.session.userid) || (req.session.domainid != domain.id)) { try { obj.ws.close(); } catch (e) { } return; } | ||||
| @ -176,18 +205,25 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { | ||||
|                         if ((user.siteadmin & 8) != 0) { | ||||
|                             // Perform a file operation (Create Folder, Delete Folder, Delete File...)
 | ||||
|                             if ((command.path != null) && (typeof command.path == 'object') && command.path.length > 0) { | ||||
|                                 var rootfolder = command.path[0]; | ||||
|                                 var rootfoldersplit = rootfolder.split('/'), domainx = 'domain'; | ||||
|                                 if (rootfoldersplit[1].length > 0) domainx = 'domain-' + rootfoldersplit[1]; | ||||
|                                 var path = obj.parent.path.join(obj.parent.filespath, domainx, rootfoldersplit[0] + "-" + rootfoldersplit[2]); | ||||
|                                 for (var i = 1; i < command.path.length; i++) { if (obj.common.IsFilenameValid(command.path[i]) == false) { path = null; break; } path += ("/" + command.path[i]); } | ||||
|                                 var sendUpdate = true; | ||||
|                                 var path = meshPathToRealPath(command.path); // TODO: Check mesh rights!!!!!
 | ||||
|                                 if (path == null) break; | ||||
| 
 | ||||
|                                 if ((command.fileop == 'createfolder') && (obj.common.IsFilenameValid(command.newfolder) == true)) { try { obj.fs.mkdirSync(path + "/" + command.newfolder); } catch (e) { } } // Create a new folder
 | ||||
|                                 else if (command.fileop == 'delete') { for (var i in command.delfiles) { if (obj.common.IsFilenameValid(command.delfiles[i]) == true) { var fullpath = path + "/" + command.delfiles[i]; try { obj.fs.rmdirSync(fullpath); } catch (e) { try { obj.fs.unlinkSync(fullpath); } catch (e) { } } } } } // Delete
 | ||||
|                                 else if ((command.fileop == 'rename') && (obj.common.IsFilenameValid(command.oldname) == true) && (obj.common.IsFilenameValid(command.newname) == true)) { try { obj.fs.renameSync(path + "/" + command.oldname, path + "/" + command.newname); } catch (e) { } } // Rename
 | ||||
|                                 else if ((command.fileop == 'copy') || (command.fileop == 'move')) { | ||||
|                                     var scpath = meshPathToRealPath(command.scpath); // TODO: Check mesh rights!!!!!
 | ||||
|                                     if (scpath == null) break; | ||||
|                                     // TODO: Check quota if this is a copy!!!!!!!!!!!!!!!!
 | ||||
|                                     for (var i in command.names) { | ||||
|                                         var s = obj.path.join(scpath, command.names[i]), d = obj.path.join(path, command.names[i]); | ||||
|                                         sendUpdate = false; | ||||
|                                         copyFile(s, d, function (op) { if (op != null) { obj.fs.unlink(op, function () { obj.parent.parent.DispatchEvent([user._id], obj, 'updatefiles'); }); } else { obj.parent.parent.DispatchEvent([user._id], obj, 'updatefiles'); } }, ((command.fileop == 'move') ? s : null)); | ||||
|                                     } | ||||
|                                 } | ||||
| 
 | ||||
|                                 obj.parent.parent.DispatchEvent([user._id], obj, 'updatefiles') // Fire an event causing this user to update this files
 | ||||
|                                 if (sendUpdate == true) { obj.parent.parent.DispatchEvent([user._id], obj, 'updatefiles'); } // Fire an event causing this user to update this files
 | ||||
|                             } | ||||
|                         } | ||||
|                         break; | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "meshcentral", | ||||
|   "version": "0.1.5-t", | ||||
|   "version": "0.1.5-u", | ||||
|   "keywords": [ | ||||
|     "Remote Management", | ||||
|     "Intel AMT", | ||||
|  | ||||
| @ -1,20 +1,20 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xrml="urn:mpeg:mpeg21:2003:01-REL-R-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2"> | ||||
|   <assemblyIdentity name="MeshMiniRouter.application" version="2.0.0.10" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" /> | ||||
|   <description asmv2:publisher="Meshcentral.com" asmv2:product="Meshcentral Mini-Router" asmv2:supportUrl="https://meshcentral.com/" xmlns="urn:schemas-microsoft-com:asm.v1" /> | ||||
|   <assemblyIdentity name="MeshMiniRouter.application" version="2.0.0.16" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" /> | ||||
|   <description asmv2:publisher="Meshcentral.com" asmv2:product="MeshCentral Mini-Router" asmv2:supportUrl="https://meshcentral.com/" xmlns="urn:schemas-microsoft-com:asm.v1" /> | ||||
|   <deployment install="false" mapFileExtensions="true" trustURLParameters="true" /> | ||||
|   <compatibleFrameworks xmlns="urn:schemas-microsoft-com:clickonce.v2"> | ||||
|     <framework targetVersion="4.5" profile="Full" supportedRuntime="4.0.30319" /> | ||||
|   </compatibleFrameworks> | ||||
|   <dependency> | ||||
|     <dependentAssembly dependencyType="install" codebase="Application Files\MeshMiniRouter_2_0_0_10\MeshMiniRouter.exe.manifest" size="4712"> | ||||
|       <assemblyIdentity name="MeshMiniRouter.exe" version="2.0.0.10" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" /> | ||||
|     <dependentAssembly dependencyType="install" codebase="Application Files\MeshMiniRouter_2_0_0_16\MeshMiniRouter.exe.manifest" size="4712"> | ||||
|       <assemblyIdentity name="MeshMiniRouter.exe" version="2.0.0.16" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" /> | ||||
|       <hash> | ||||
|         <dsig:Transforms> | ||||
|           <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" /> | ||||
|         </dsig:Transforms> | ||||
|         <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" /> | ||||
|         <dsig:DigestValue>nAtlMki8bI8WHgD0B1tC4ZVmxIYy41iUEGTj8OMxNmU=</dsig:DigestValue> | ||||
|         <dsig:DigestValue>uaxqCrqKPjDkZMXMlJ9pIvARsSxYXXLci7n8z3Q8hUU=</dsig:DigestValue> | ||||
|       </hash> | ||||
|     </dependentAssembly> | ||||
|   </dependency> | ||||
										
											Binary file not shown.
										
									
								
							| @ -1,10 +1,10 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2"> | ||||
|   <asmv1:assemblyIdentity name="MeshMiniRouter.exe" version="2.0.0.10" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" /> | ||||
|   <asmv1:assemblyIdentity name="MeshMiniRouter.exe" version="2.0.0.16" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" /> | ||||
|   <description asmv2:iconFile="MeshMiniRouter.ico" xmlns="urn:schemas-microsoft-com:asm.v1" /> | ||||
|   <application /> | ||||
|   <entryPoint> | ||||
|     <assemblyIdentity name="MeshMiniRouter" version="1.0.6507.17826" language="neutral" processorArchitecture="msil" /> | ||||
|     <assemblyIdentity name="MeshMiniRouter" version="1.0.6667.26398" language="neutral" processorArchitecture="msil" /> | ||||
|     <commandLine file="MeshMiniRouter.exe" parameters="" /> | ||||
|   </entryPoint> | ||||
|   <trustInfo> | ||||
| @ -44,13 +44,13 @@ | ||||
|   </dependency> | ||||
|   <dependency> | ||||
|     <dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="MeshMiniRouter.exe" size="193536"> | ||||
|       <assemblyIdentity name="MeshMiniRouter" version="1.0.6507.17826" language="neutral" processorArchitecture="msil" /> | ||||
|       <assemblyIdentity name="MeshMiniRouter" version="1.0.6667.26398" language="neutral" processorArchitecture="msil" /> | ||||
|       <hash> | ||||
|         <dsig:Transforms> | ||||
|           <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" /> | ||||
|         </dsig:Transforms> | ||||
|         <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" /> | ||||
|         <dsig:DigestValue>HHqrJ3vBMkqfPDfdzKBtZW4mtE/Sg5O5LdPB6KmBv3E=</dsig:DigestValue> | ||||
|         <dsig:DigestValue>2K6tEre6rIjqc6bZn7uhWlXLgAnZ82UP3jYzxNJ7WIk=</dsig:DigestValue> | ||||
|       </hash> | ||||
|     </dependentAssembly> | ||||
|   </dependency> | ||||
| Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB | 
| @ -1,20 +1,20 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xrml="urn:mpeg:mpeg21:2003:01-REL-R-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2"> | ||||
|   <assemblyIdentity name="MeshMiniRouter.application" version="2.0.0.10" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" /> | ||||
|   <description asmv2:publisher="Meshcentral.com" asmv2:product="Meshcentral Mini-Router" asmv2:supportUrl="https://meshcentral.com/" xmlns="urn:schemas-microsoft-com:asm.v1" /> | ||||
|   <assemblyIdentity name="MeshMiniRouter.application" version="2.0.0.16" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" /> | ||||
|   <description asmv2:publisher="Meshcentral.com" asmv2:product="MeshCentral Mini-Router" asmv2:supportUrl="https://meshcentral.com/" xmlns="urn:schemas-microsoft-com:asm.v1" /> | ||||
|   <deployment install="false" mapFileExtensions="true" trustURLParameters="true" /> | ||||
|   <compatibleFrameworks xmlns="urn:schemas-microsoft-com:clickonce.v2"> | ||||
|     <framework targetVersion="4.5" profile="Full" supportedRuntime="4.0.30319" /> | ||||
|   </compatibleFrameworks> | ||||
|   <dependency> | ||||
|     <dependentAssembly dependencyType="install" codebase="Application Files\MeshMiniRouter_2_0_0_10\MeshMiniRouter.exe.manifest" size="4712"> | ||||
|       <assemblyIdentity name="MeshMiniRouter.exe" version="2.0.0.10" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" /> | ||||
|     <dependentAssembly dependencyType="install" codebase="Application Files\MeshMiniRouter_2_0_0_16\MeshMiniRouter.exe.manifest" size="4712"> | ||||
|       <assemblyIdentity name="MeshMiniRouter.exe" version="2.0.0.16" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" /> | ||||
|       <hash> | ||||
|         <dsig:Transforms> | ||||
|           <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" /> | ||||
|         </dsig:Transforms> | ||||
|         <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" /> | ||||
|         <dsig:DigestValue>nAtlMki8bI8WHgD0B1tC4ZVmxIYy41iUEGTj8OMxNmU=</dsig:DigestValue> | ||||
|         <dsig:DigestValue>uaxqCrqKPjDkZMXMlJ9pIvARsSxYXXLci7n8z3Q8hUU=</dsig:DigestValue> | ||||
|       </hash> | ||||
|     </dependentAssembly> | ||||
|   </dependency> | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| <HTML> | ||||
|   <HEAD> | ||||
|     <TITLE>Meshcentral Mini-Router</TITLE> | ||||
|     <TITLE>MeshCentral Mini-Router</TITLE> | ||||
|     <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8" /> | ||||
|     <STYLE TYPE="text/css"> | ||||
| <!-- | ||||
| @ -51,7 +51,7 @@ FONT.key {font-weight: bold; color: darkgreen} | ||||
|     <TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"> | ||||
| 
 | ||||
| <!-- Begin Banner --> | ||||
| <TR><TD><TABLE CELLPADDING="2" CELLSPACING="0" BORDER="0" BGCOLOR="#cecece" WIDTH="100%"><TR><TD><TABLE BGCOLOR="#1c5280" WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR><TD CLASS="Banner" /></TR><TR><TD CLASS="Banner"><SPAN CLASS="BannerTextCompany">Meshcentral.com</SPAN></TD></TR><TR><TD CLASS="Banner"><SPAN CLASS="BannerTextApplication">Meshcentral Mini-Router</SPAN></TD></TR><TR><TD CLASS="Banner" ALIGN="RIGHT" /></TR></TABLE></TD></TR></TABLE></TD></TR> | ||||
| <TR><TD><TABLE CELLPADDING="2" CELLSPACING="0" BORDER="0" BGCOLOR="#cecece" WIDTH="100%"><TR><TD><TABLE BGCOLOR="#1c5280" WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR><TD CLASS="Banner" /></TR><TR><TD CLASS="Banner"><SPAN CLASS="BannerTextCompany">Meshcentral.com</SPAN></TD></TR><TR><TD CLASS="Banner"><SPAN CLASS="BannerTextApplication">MeshCentral Mini-Router</SPAN></TD></TR><TR><TD CLASS="Banner" ALIGN="RIGHT" /></TR></TABLE></TD></TR></TABLE></TD></TR> | ||||
| <!-- End Banner --> | ||||
| 
 | ||||
| 
 | ||||
| @ -59,7 +59,7 @@ FONT.key {font-weight: bold; color: darkgreen} | ||||
| <TR><TD ALIGN="LEFT"><TABLE CELLPADDING="2" CELLSPACING="0" BORDER="0" WIDTH="540"><TR><TD WIDTH="496"> | ||||
| 
 | ||||
| <!-- Begin AppInfo --> | ||||
| <TABLE><TR><TD COLSPAN="3"> </TD></TR><TR><TD><B>Name:</B></TD><TD WIDTH="5"><SPACER TYPE="block" WIDTH="10" /></TD><TD>Meshcentral Mini-Router</TD></TR><TR><TD COLSPAN="3"> </TD></TR><TR><TD><B>Version:</B></TD><TD WIDTH="5"><SPACER TYPE="block" WIDTH="10" /></TD><TD>2.0.0.10</TD></TR><TR><TD COLSPAN="3"> </TD></TR><TR><TD><B>Publisher:</B></TD><TD WIDTH="5"><SPACER TYPE="block" WIDTH="10" /></TD><TD>Meshcentral.com</TD></TR><tr><td colspan="3"> </td></tr></TABLE> | ||||
| <TABLE><TR><TD COLSPAN="3"> </TD></TR><TR><TD><B>Name:</B></TD><TD WIDTH="5"><SPACER TYPE="block" WIDTH="10" /></TD><TD>MeshCentral Mini-Router</TD></TR><TR><TD COLSPAN="3"> </TD></TR><TR><TD><B>Version:</B></TD><TD WIDTH="5"><SPACER TYPE="block" WIDTH="10" /></TD><TD>2.0.0.16</TD></TR><TR><TD COLSPAN="3"> </TD></TR><TR><TD><B>Publisher:</B></TD><TD WIDTH="5"><SPACER TYPE="block" WIDTH="10" /></TD><TD>Meshcentral.com</TD></TR><tr><td colspan="3"> </td></tr></TABLE> | ||||
| <!-- End AppInfo --> | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -249,12 +249,15 @@ | ||||
|                             <td style="width:100%;background-color:#d3d9d6;text-align:left;padding:4px" valign=bottom> | ||||
|                                 <div id="p5rightOfButtons" style="float:right;margin-top:3px"></div> | ||||
|                                 <div> | ||||
|                                     <input type="button" id="p5FolderUp" disabled="disabled" onclick="p5folderup();" value="Up" />  | ||||
|                                     <input type="button" id="p5SelectAllButton" disabled="disabled" onclick="p5selectallfile();" value="Select All" onkeypress="return false;" onkeydown="return false;" />  | ||||
|                                     <input type="button" id="p5RenameFileButton" disabled="disabled" value="Rename" onclick="p5renamefile();" onkeypress="return false;" onkeydown="return false;" />  | ||||
|                                     <input type="button" id="p5DeleteFileButton" disabled="disabled" value="Delete" onclick="p5deletefile();" onkeypress="return false;" onkeydown="return false;" />  | ||||
|                                     <input type="button" id="p5NewFolderButton" disabled="disabled" value="New Folder" onclick="p5createfolder();" onkeypress="return false;" onkeydown="return false;" />  | ||||
|                                     <input type="button" id="p5UploadButton" disabled="disabled" value="Upload" onclick="p5uploadFile()" onkeypress="return false;" onkeydown="return false;" />  | ||||
|                                     <input type=button id=p5FolderUp disabled="disabled" onclick="p5folderup();" value="Up" />  | ||||
|                                     <input type=button id=p5SelectAllButton disabled="disabled" onclick="p5selectallfile();" value="Select All" onkeypress="return false;" onkeydown="return false;" />  | ||||
|                                     <input type=button id=p5RenameFileButton disabled="disabled" value="Rename" onclick="p5renamefile();" onkeypress="return false;" onkeydown="return false;" />  | ||||
|                                     <input type=button id=p5DeleteFileButton disabled="disabled" value="Delete" onclick="p5deletefile();" onkeypress="return false;" onkeydown="return false;" />  | ||||
|                                     <input type=button id=p5NewFolderButton disabled="disabled" value="New Folder" onclick="p5createfolder();" onkeypress="return false;" onkeydown="return false;" />  | ||||
|                                     <input type=button id=p5UploadButton disabled="disabled" value="Upload" onclick="p5uploadFile()" onkeypress="return false;" onkeydown="return false;" />  | ||||
|                                     <input type=button id=p5CutButton disabled="disabled" value="Cut" onclick="p5copyFile(1)" onkeypress="return false" onkeydown="return false" />  | ||||
|                                     <input type=button id=p5CopyButton disabled="disabled" value="Copy" onclick="p5copyFile(0)" onkeypress="return false" onkeydown="return false" />  | ||||
|                                     <input type=button id=p5PasteButton disabled="disabled" value="Paste" onclick="p5pasteFile()" onkeypress="return false" onkeydown="return false" />  | ||||
|                                 </div> | ||||
|                             </td> | ||||
|                         </tr> | ||||
| @ -288,7 +291,7 @@ | ||||
|                         <span id="p5files"></span> | ||||
|                     </div> | ||||
|                     <table id="p5toolbarBottom" style=width:100% cellpadding=0 cellspacing=0> | ||||
|                         <tr><td class=style6 style="text-align:left"> <span id="p5bottomstatus"></span></td></tr> | ||||
|                         <tr><td class=style6 style="text-align:left;padding:3px"> <span id="p5bottomstatus"></span></td></tr> | ||||
|                     </table> | ||||
|                 </div> | ||||
|                 <div id=p10 style=display:none> | ||||
| @ -4535,13 +4538,13 @@ | ||||
|                 var h = ''; | ||||
|                 if (f.t < 3) { | ||||
|                     var right = (f.t == 1)?p5getQuotabar(f):'', title = ''; | ||||
|                     h = "<div class=filelist file=999><input style=float:left name=fc class=fcb type=checkbox onchange=p5setActions() value='" + name + "'> <span style=float:right title=\"" + title + "\">" + right + "</span><span><div class=fileIcon" + f.t + "></div><a style=cursor:pointer onclick=p5folderset(\"" + encodeURIComponent(f.nx) + "\")>" + shortname + "</a></span></div>"; | ||||
|                     h = "<div class=filelist file=999><input file=999 style=float:left name=fc class=fcb type=checkbox onchange=p5setActions() value='" + name + "'> <span style=float:right title=\"" + title + "\">" + right + "</span><span><div class=fileIcon" + f.t + "></div><a style=cursor:pointer onclick=p5folderset(\"" + encodeURIComponent(f.nx) + "\")>" + shortname + "</a></span></div>"; | ||||
|                 } else { | ||||
|                     var link = shortname; | ||||
|                     var publiclink = ''; | ||||
|                     if (publicfolder) { publiclink = ' (<a style=cursor:pointer title=\"Display public link\" onclick=\'p5showPublicLink(\"' + publicPath + '/' + f.nx + '\")\'>Link</a>)'; } | ||||
|                     if (f.s > 0) { link = "<a target=\"_blank\" href=\"downloadfile.ashx?link=" + encodeURIComponent(filetreelinkpath + '/' + f.nx) + "\">" + shortname + "</a>" + publiclink; } | ||||
|                     h = "<div class=filelist file=3><input style=float:left name=fc class=fcb type=checkbox onchange=p5setActions() value='" + f.nx + "'> <span class=fsize>" + fdatestr + "</span><span style=float:right>" + fsize + "</span><span><div class=fileIcon" + f.t + "></div>" + link + "</span></div>"; | ||||
|                     h = "<div class=filelist file=3><input file=3 style=float:left name=fc class=fcb type=checkbox onchange=p5setActions() value='" + f.nx + "'> <span class=fsize>" + fdatestr + "</span><span style=float:right>" + fsize + "</span><span><div class=fileIcon" + f.t + "></div>" + link + "</span></div>"; | ||||
|                 } | ||||
| 
 | ||||
|                 if (f.t < 3) { html1 += h; } else { html2 += h; } | ||||
| @ -4570,7 +4573,7 @@ | ||||
|             while (f.t > 1) { f = f.parent; } | ||||
|             if ((f.t != 1) || (f.maxbytes == null)) return ''; | ||||
|             var tf = Math.floor(f.s / 1024), tq = Math.floor((f.maxbytes - f.s) / 1024); | ||||
|             return '<span title="' + tf + "k in " + f.c + " file" + (f.c > 1?'s':'') + ". " + (Math.floor(f.maxbytes / 1024)) + 'k maxinum">' + ((tq < 0)?('Storage limit exceed'):(tq + 'k remaining')) + ' <progress style=height:10px;width:200px value=' + f.s + ' max=' + f.maxbytes + ' /></span>'; | ||||
|             return '<span title="' + tf + "k in " + f.c + " file" + (f.c > 1?'s':'') + ". " + (Math.floor(f.maxbytes / 1024)) + 'k maxinum">' + ((tq < 0)?('Storage limit exceed'):(tq + 'k remaining')) + ' <progress style=height:10px;width:100px value=' + f.s + ' max=' + f.maxbytes + ' /></span>'; | ||||
|         } | ||||
| 
 | ||||
|         function p5showPublicLink(u) { setDialogMode(2, "Public Link", 1, null, '<input type=text style=width:100% value="' + u + '" readonly />'); } | ||||
| @ -4592,16 +4595,19 @@ | ||||
|         } | ||||
| 
 | ||||
|         function p5setActions() { | ||||
|             var cc = getFileSelCount(), tc = getFileCount(); | ||||
|             var cc = getFileSelCount(), tc = getFileCount(), sfc = getFileSelCount(false); // In order: number of entires selected, number of total entries, number of selected entires that are files (not folders) | ||||
|             QE('p5DeleteFileButton', (cc > 0) && (filetreelocation.length > 0)); | ||||
|             QE('p5NewFolderButton', filetreelocation.length > 0); | ||||
|             QE('p5UploadButton', filetreelocation.length > 0); | ||||
|             QE('p5RenameFileButton', (cc == 1) && (filetreelocation.length > 0)); | ||||
|             QE('p5SelectAllButton', tc > 0) | ||||
|             QE('p5SelectAllButton', tc > 0); | ||||
|             Q('p5SelectAllButton').value = (cc > 0 ? 'Select None' : 'Select All'); | ||||
|             QE('p5CutButton', (sfc > 0) && (cc == sfc)); | ||||
|             QE('p5CopyButton', (sfc > 0) && (cc == sfc)); | ||||
|             QE('p5PasteButton', (p5clipboard != null) && (p5clipboard.length > 0)); | ||||
|         } | ||||
| 
 | ||||
|         function getFileSelCount() { var cc = 0; var checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) cc++; } return cc; } | ||||
|         function getFileSelCount(includeDirs) { var cc = 0; var checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && ((includeDirs != false) || (checkboxes[i].attributes.file.value == "3"))) cc++; } return cc; } | ||||
|         function getFileCount() { var cc = 0; var checkboxes = document.getElementsByName('fc'); return checkboxes.length; } | ||||
|         function p5selectallfile() { var nv = (getFileSelCount() == 0), checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { checkboxes[i].checked = nv; } p5setActions(); } | ||||
|         function setupBackPointers(x) { if (x.f != null) { var fs = 0, fc = 0; for (var i in x.f) { setupBackPointers(x.f[i]); x.f[i].parent = x; if (x.f[i].s) { fs += x.f[i].s; } if (x.f[i].c) { fc += x.f[i].c; } if (x.f[i].t == 3) { fc++; } } x.s = fs; x.c = fc; } return x; } | ||||
| @ -4620,6 +4626,13 @@ | ||||
|         function p5uploadFileEx() { Q('p5loginSubmit').click(); } | ||||
|         function updateUploadDialogOk(x) { QE('idx_dlgOkButton', Q(x).value != ''); } | ||||
| 
 | ||||
|         var p5clipboard = null, p5clipboardFolder = null, p5clipboardCut = 0; | ||||
|         function p5copyFile(cut) { var checkboxes = document.getElementsByName('fc'); p5clipboard = []; p5clipboardCut = cut, p5clipboardFolder = Clone(filetreelocation); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && (checkboxes[i].attributes.file.value == "3")) { p5clipboard.push(checkboxes[i].value); } } p5updateClipview(); } | ||||
|         function p5pasteFile() { var x = ''; if ((p5clipboard != null) && (p5clipboard.length > 0)) { x = 'Confim ' + (p5clipboardCut == 0?'copy':'move') + ' of ' + p5clipboard.length + ' entrie' + ((p5clipboard.length > 1)?'s':'') + ' to this location?' } setDialogMode(2, "Paste", 3, p5pasteFileEx, x); } | ||||
|         function p5pasteFileEx() { meshserver.send({ action: 'fileoperation', fileop: (p5clipboardCut == 0?'copy':'move'), scpath: p5clipboardFolder, path: filetreelocation, names: p5clipboard }); p5folderup(999); if (p5clipboardCut == 1) { p5clipboard = null, p5clipboardFolder = null, p5clipboardCut = 0; p5updateClipview(); } } | ||||
|         function p5updateClipview() { var x = ''; if ((p5clipboard != null) && (p5clipboard.length > 0)) { x = 'Holding ' + p5clipboard.length + ' entrie' + ((p5clipboard.length > 1)?'s':'') + ' for ' + (p5clipboardCut == 0?'copy':'move') + ', <a onclick=p5clearClip() style=cursor:pointer>Clear</a>.' } QH('p5bottomstatus', x); p5setActions(); } | ||||
|         function p5clearClip() { p5clipboard = null; p5clipboardFolder = null; p5clipboardCut = 0; p5updateClipview(); } | ||||
| 
 | ||||
|         function p5fileDragDrop(e) { | ||||
|             haltEvent(e); | ||||
|             QV('bigfail', false); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user