From 312b937e626d7576d68ada3bbeb1469fe1e6457d Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Mon, 27 Aug 2018 12:24:15 -0700 Subject: [PATCH] All JavaScript code is now 'strict' --- amtevents.js | 2 ++ amtscanner.js | 5 +-- amtscript.js | 2 ++ certoperations.js | 2 ++ common.js | 2 ++ db.js | 2 ++ exeHandler.js | 2 ++ interceptor.js | 2 ++ letsEncrypt.js | 2 ++ meshaccelerator.js | 2 ++ meshagent.js | 7 ++-- meshcentral.js | 9 ++--- meshmail.js | 2 ++ meshrelay.js | 2 ++ meshscanner.js | 8 +++-- meshuser.js | 2 ++ mpsserver.js | 2 ++ multiserver.js | 2 ++ package.json | 2 +- pass.js | 2 ++ public/commander.htm | 29 ++++++++-------- redirserver.js | 2 ++ swarmserver.js | 2 ++ views/default-mobile.handlebars | 61 +++++++++++++++++---------------- views/default.handlebars | 23 ++++++------- views/login-mobile.handlebars | 1 + views/login.handlebars | 1 + webserver.js | 25 +++++++++----- winservice.js | 2 ++ 29 files changed, 129 insertions(+), 78 deletions(-) diff --git a/amtevents.js b/amtevents.js index b93a3403..e3e37ef8 100644 --- a/amtevents.js +++ b/amtevents.js @@ -6,6 +6,8 @@ * @version v0.0.1 */ +'use strict'; + // Construct a MeshAgent object, called upon connection module.exports.CreateAmtEventsHandler = function (parent) { var obj = {}; diff --git a/amtscanner.js b/amtscanner.js index 37070a6c..fb7db186 100644 --- a/amtscanner.js +++ b/amtscanner.js @@ -6,6 +6,8 @@ * @version v0.0.1 */ +'use strict'; + // Construct a Intel AMT Scanner object module.exports.CreateAmtScanner = function (parent) { var obj = {}; @@ -68,11 +70,10 @@ module.exports.CreateAmtScanner = function (parent) { rangeinfo.server.on('listening', () => { for (var i = rangeinfo.min; i <= rangeinfo.max; i++) { rangeinfo.server.send(obj.rpacket, 623, obj.IPv4NumToStr(i)); } }); - rangeinfo.timer = setTimeout(function () { + rangeinfo.timer = setTimeout(function () { // ************************* USER OF OUTER VARS!!!!!!!!!!!!!!! obj.parent.DispatchEvent(['*', userid], obj, { action: 'scanamtdevice', range: rangeinfo.range, results: rangeinfo.results, nolog: 1 }); rangeinfo.server.close(); delete rangeinfo.server; - delete rangeinfo; }, 3000); return true; } diff --git a/amtscript.js b/amtscript.js index 1bc43f66..f2e4ade9 100644 --- a/amtscript.js +++ b/amtscript.js @@ -6,6 +6,8 @@ * @version v0.1.0e */ +'use strict'; + module.exports.CreateAmtScriptEngine = function () { var o = {}; diff --git a/certoperations.js b/certoperations.js index e87c0d88..7dd41f0f 100644 --- a/certoperations.js +++ b/certoperations.js @@ -6,6 +6,8 @@ * @version v0.0.1 */ +'use strict'; + module.exports.CertificateOperations = function () { var obj = {}; diff --git a/common.js b/common.js index f92d6dc9..b4453375 100644 --- a/common.js +++ b/common.js @@ -6,6 +6,8 @@ * @version v0.0.1 */ +'use strict'; + const crypto = require('crypto'); // Binary encoding and decoding functions diff --git a/db.js b/db.js index 882855b0..8c1b1ae0 100644 --- a/db.js +++ b/db.js @@ -6,6 +6,8 @@ * @version v0.0.2 */ +'use strict'; + // // Construct Meshcentral database object // diff --git a/exeHandler.js b/exeHandler.js index f45fd16b..10b7d51a 100644 --- a/exeHandler.js +++ b/exeHandler.js @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +'use strict'; + const exeJavaScriptGuid = 'B996015880544A19B7F7E9BE44914C18'; const exeMeshPolicyGuid = 'B996015880544A19B7F7E9BE44914C19'; diff --git a/interceptor.js b/interceptor.js index cf4e57fc..6fb93c8f 100644 --- a/interceptor.js +++ b/interceptor.js @@ -6,6 +6,8 @@ * @version v0.0.3 */ +'use strict'; + const crypto = require('crypto'); const common = require('./common.js'); diff --git a/letsEncrypt.js b/letsEncrypt.js index 61e5a51e..769a7698 100644 --- a/letsEncrypt.js +++ b/letsEncrypt.js @@ -6,6 +6,8 @@ * @version v0.0.2 */ +'use strict'; + module.exports.CreateLetsEncrypt = function (parent) { try { const greenlock = require('greenlock');; diff --git a/meshaccelerator.js b/meshaccelerator.js index 19a9d41e..43563abe 100644 --- a/meshaccelerator.js +++ b/meshaccelerator.js @@ -6,6 +6,8 @@ * @version v0.0.1 */ +'use strict'; + const crypto = require('crypto'); var certStore = null; diff --git a/meshagent.js b/meshagent.js index 745ee376..71fce3d5 100644 --- a/meshagent.js +++ b/meshagent.js @@ -6,6 +6,8 @@ * @version v0.0.1 */ +'use strict'; + var AgentConnectCount = 0; // Construct a MeshAgent object, called upon connection @@ -423,9 +425,10 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { // Process incoming agent JSON data function processAgentData(msg) { - var str = msg.toString('utf8'); + var str = msg.toString('utf8'), command = null; if (str[0] == '{') { - try { command = JSON.parse(str) } catch (e) { console.log('Unable to parse agent JSON (' + obj.remoteaddr + '): ' + str); return; } // If the command can't be parsed, ignore it. + try { command = JSON.parse(str) } catch (ex) { console.log('Unable to parse agent JSON (' + obj.remoteaddr + '): ' + str, ex); return; } // If the command can't be parsed, ignore it. + if (typeof command != 'object') { return; } switch (command.action) { case 'msg': { diff --git a/meshcentral.js b/meshcentral.js index 3d0ec8d2..964bd410 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -6,6 +6,8 @@ * @version v0.0.1 */ +'use strict'; + // If app metrics is available if (process.argv[2] == '--launch') { try { require('appmetrics-dash').monitor({ url: '/', title: 'MeshCentral', port: 88, host: '127.0.0.1' }); } catch (e) { } } @@ -420,7 +422,7 @@ function CreateMeshCentralServer(config, args) { if ((obj.args.nousers == true) && (obj.args.userallowedip == null)) { obj.args.userallowedip = "::1,127.0.0.1"; } // Set the session length to 60 minutes if not set and set a random key if needed - if ((obj.args.sessiontime == null) || (typeof obj.args.sessiontime != 'number') || (obj.args.sessiontime < 1)) { obj.args.sessiontime = 60; } + if ((obj.args.sessiontime != null) && ((typeof obj.args.sessiontime != 'number') || (obj.args.sessiontime < 1))) { delete obj.args.sessiontime; } if (!obj.args.sessionkey) { obj.args.sessionkey = buf.toString('hex').toUpperCase(); } // Start eh web server and if needed, the redirection web server. @@ -594,7 +596,6 @@ function CreateMeshCentralServer(config, args) { } } if ((fromPeerServer == null) && (obj.multiServer != null) && ((typeof event != 'object') || (event.nopeers != 1))) { obj.multiServer.DispatchEvent(ids, source, event); } - delete targets; } // Get the connection state of a node @@ -742,6 +743,7 @@ function CreateMeshCentralServer(config, args) { if (obj.multiServer == null) { // Single server mode + var eventConnectChange = 0; // Remove the agent connection from the nodes connection list var state = obj.connectivityByNode[nodeid]; @@ -1082,7 +1084,7 @@ function CreateMeshCentralServer(config, args) { if ((name != null) && (meshServerState[name] != val)) { if ((val == null) && (meshServerState[name] != null)) { delete meshServerState[name]; changed = true; } else { if (meshServerState[name] != val) { meshServerState[name] = val; changed = true; } } } if (changed == false) return; } - r = 'time=' + Date.now() + '\r\n'; + var r = 'time=' + Date.now() + '\r\n'; for (var i in meshServerState) { r += (i + '=' + meshServerState[i] + '\r\n'); } obj.fs.writeFileSync(obj.getConfigFilePath('serverstate.txt'), r); } @@ -1173,7 +1175,6 @@ function InstallModules(modules, func) { function InstallModule(modulename, func, tag1, tag2) { try { var module = require(modulename); - delete module; } catch (e) { console.log('Installing ' + modulename + '...'); var child_process = require('child_process'); diff --git a/meshmail.js b/meshmail.js index 70801db5..c38dcf5a 100644 --- a/meshmail.js +++ b/meshmail.js @@ -6,6 +6,8 @@ * @version v0.0.1 */ +'use strict'; + // Construct a MeshAgent object, called upon connection module.exports.CreateMeshMain = function (parent) { var obj = {}; diff --git a/meshrelay.js b/meshrelay.js index 3ddcb9b6..5f535a47 100644 --- a/meshrelay.js +++ b/meshrelay.js @@ -6,6 +6,8 @@ * @version v0.0.1 */ +'use strict'; + module.exports.CreateMeshRelay = function (parent, ws, req, domain) { var obj = {}; obj.ws = ws; diff --git a/meshscanner.js b/meshscanner.js index bbd6350c..d243c400 100644 --- a/meshscanner.js +++ b/meshscanner.js @@ -6,6 +6,8 @@ * @version v0.0.1 */ +'use strict'; + // Construct a Mesh Scanner object // TODO: We need once "server4" and "server6" per interface, or change the default multicast interface as we send. module.exports.CreateMeshScanner = function (parent) { @@ -27,9 +29,9 @@ module.exports.CreateMeshScanner = function (parent) { var ipv4 = ['*'], ipv6 = ['*']; // Bind to IN_ADDR_ANY always var interfaces = require('os').networkInterfaces(); for (var i in interfaces) { - var interface = interfaces[i]; - for (var j in interface) { - var interface2 = interface[j]; + var xinterface = interfaces[i]; + for (var j in xinterface) { + var interface2 = xinterface[j]; if ((interface2.mac != '00:00:00:00:00:00') && (interface2.internal == false)) { if (interface2.family == 'IPv4') { ipv4.push(interface2.address); } if (interface2.family == 'IPv6') { ipv6.push(interface2.address + '%' + i); } diff --git a/meshuser.js b/meshuser.js index 5e4977fa..94b14871 100644 --- a/meshuser.js +++ b/meshuser.js @@ -6,6 +6,8 @@ * @version v0.0.1 */ +'use strict'; + // Construct a MeshAgent object, called upon connection module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { var obj = {}; diff --git a/mpsserver.js b/mpsserver.js index b6fe898a..5b4f2385 100644 --- a/mpsserver.js +++ b/mpsserver.js @@ -6,6 +6,8 @@ * @version v0.0.1 */ +'use strict'; + // Construct a Intel AMT MPS server object module.exports.CreateMpsServer = function (parent, db, args, certificates) { var obj = {}; diff --git a/multiserver.js b/multiserver.js index b9db2900..d99cf430 100644 --- a/multiserver.js +++ b/multiserver.js @@ -6,6 +6,8 @@ * @version v0.0.1 */ +'use strict'; + // Construct a Mesh Multi-Server object. This is used for MeshCentral-to-MeshCentral communication. module.exports.CreateMultiServer = function (parent, args) { var obj = {}; diff --git a/package.json b/package.json index 804a7431..a417bf99 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.1.9-q", + "version": "0.1.9-r", "keywords": [ "Remote Management", "Intel AMT", diff --git a/pass.js b/pass.js index e8b8d9c2..9091e290 100644 --- a/pass.js +++ b/pass.js @@ -1,5 +1,7 @@ // check out https://github.com/tj/node-pwd +'use strict'; + // Module dependencies. const crypto = require('crypto'); diff --git a/public/commander.htm b/public/commander.htm index 9915314a..139b5727 100644 --- a/public/commander.htm +++ b/public/commander.htm @@ -754,21 +754,20 @@ function processSystemStatus(a,b,c,d){if(void 0==c.IPS_ScreenConfigurationServic QV("go13",!0);d=0;for(var f in c)null!=c[f]&&c[f].status>d&&(d=c[f].status);400!=d&&errcheck(d,a)||(amtsysstate=c,updateSystemStatus())}var DMTFPowerStates=";;Power on;Light sleep;Deep sleep;Power cycle (Soft off);Off - Hard;Hibernate (Off soft);Soft off;Power cycle (Off-hard);Master bus reset;Diagnostic interrupt (NMI);Not applicable;Off - Soft graceful;Off - Hard graceful;Master bus reset graceful;Power cycle (Off - Soft graceful);Power cycle (Off - Hard graceful);Diagnostic interrupt (INIT)".split(";"); function updateSystemStatus(){if(amtsysstate&&!(99None":EscapeHtml(b); d+=TableEntry("Name & Domain",addLinkConditional(b,"showEditNameDlg()",xxAccountAdminName));HardwareInventory&&(d+=TableEntry("System ID",guidToStr(HardwareInventory.CIM_ComputerSystemPackage.response.PlatformGUID.toLowerCase())));if(amtlogicalelements){var p="",r=getItem(amtlogicalelements,"CreationClassName","AMT_SetupAndConfigurationService");2==r.ProvisioningState&&5p.DefaultScreen&&(f=["Primary display","Secondary display","3rd display"][p.DefaultScreen]),f=''+f+"",1==p.Is5900PortEnabled&&(f+=", Port 5900 enabled"),1==p.OptInPolicy&&(f+=", "+p.OptInPolicyTimeout+" second"+(0"+TableEnd("
 "+AddRefreshButton("PullSystemStatus(1)")+" Changing network settings may cause this page to becaume unavailable."); -d=d+"

General Settings

"+TableStart();f="";"None"!=b&&(1==n.SharedFQDN&&(f=", shared with OS"),0==n.SharedFQDN&&(f=", different from OS"));d+=TableEntry("Name & Domain",addLinkConditional(b+f,"showEditNameDlg(1)",xxAccountAdminName));b="Disabled";1==n.DDNSUpdateEnabled?b="Enabled each "+n.DDNSPeriodicUpdateInterval+" minutes, TTL is "+n.DDNSTTL+" minutes":1==n.DDNSUpdateByDHCPServerEnabled&&(b="Update by DHCP server");d+=TableEntry("Dynamic DNS",addLinkConditional(b,"showEditDnsDlg()", -xxAccountAdminName));d+=TableEnd();for(c in amtsysstate.AMT_EthernetPortSettings.responses){b=amtsysstate.AMT_EthernetPortSettings.responses[c];if(b.WLANLinkProtectionLevel||1==c)amtwirelessif=c;if(0!=c||amtwirelessif==c||"00-00-00-00-00-00"!=b.MACAddress){0==c&&a++;d+="

"+(amtwirelessif==c?"Wireless":"Wired")+" Interface

";d+=TableStart();d+=TableEntry("Link state",1==b.LinkIsUp?"Link is up":"Link is down");"00-00-00-00-00-00"!=b.MACAddress&&(d+=TableEntry("MAC address",b.MACAddress)); -amtwirelessif==c&&xxWireless&&xxWireless.CIM_WiFiPortCapabilities.response&&(d+=TableEntry("State",addLinkConditional(xxWifiState[xxWireless.CIM_WiFiPort.response.EnabledState],"showWifiStateDlg()",xxAccountAdminName)),s=xxWireless.CIM_WiFiEndpoint.response.LANID,d+=TableEntry("Radio State",xxRadioState[xxWireless.CIM_WiFiEndpoint.response.EnabledState]+", SSID: "+(s?s:"None")));amtwirelessif!=c&&(d+=TableEntry("Respond to ping",addLinkConditional(["Disabled","ICMP response","RMCP response", -"ICMP & RMCP response"][n.PingResponseEnabled+(n.RmcpPingResponseEnabled<<1)],"showPingActionDlg()",xxAccountAdminName)),d+=TableEntry("IPv4 state",addLinkConditional(1==b.DHCPEnabled?"Automatic using DHCP server":"Static IP address","showIPSetupDlg()",xxAccountAdminName)));d+=TableEntry("IPv4 address",isIpAddress(b.IPAddress,"None"));isIpAddress(b.DefaultGateway)&&(d+=TableEntry("IPv4 gateway / Mask",b.DefaultGateway+" / "+isIpAddress(b.SubnetMask,"None")));f=b.PrimaryDNS;isIpAddress(f)&&(b.SecondaryDNS&& -(f+=" / "+b.SecondaryDNS),d+=TableEntry("IPv4 domain name server",f));if(200==amtsysstate.IPS_IPv6PortSettings.status&&5p.DefaultScreen&&(f=["Primary display","Secondary display","3rd display"][p.DefaultScreen]),f=''+f+"",1==p.Is5900PortEnabled&&(f+=", Port 5900 enabled"),1==p.OptInPolicy&&(f+=", "+p.OptInPolicyTimeout+" second"+(0 "+AddRefreshButton("PullSystemStatus(1)")+" Changing network settings may cause this page to becaume unavailable.");d=d+"

General Settings

"+TableStart();f="";"None"!=b&&(1==n.SharedFQDN&&(f=", shared with OS"),0==n.SharedFQDN&&(f=", different from OS"));d+=TableEntry("Name & Domain",addLinkConditional(b+f,"showEditNameDlg(1)",xxAccountAdminName));b="Disabled";1==n.DDNSUpdateEnabled? +b="Enabled each "+n.DDNSPeriodicUpdateInterval+" minutes, TTL is "+n.DDNSTTL+" minutes":1==n.DDNSUpdateByDHCPServerEnabled&&(b="Update by DHCP server");d+=TableEntry("Dynamic DNS",addLinkConditional(b,"showEditDnsDlg()",xxAccountAdminName));d+=TableEnd();for(c in amtsysstate.AMT_EthernetPortSettings.responses){b=amtsysstate.AMT_EthernetPortSettings.responses[c];if(b.WLANLinkProtectionLevel||1==c)amtwirelessif=c;if(0!=c||amtwirelessif==c||"00-00-00-00-00-00"!=b.MACAddress){0==c&&a++;d+="

"+ +(amtwirelessif==c?"Wireless":"Wired")+" Interface

";d+=TableStart();d+=TableEntry("Link state",1==b.LinkIsUp?"Link is up":"Link is down");"00-00-00-00-00-00"!=b.MACAddress&&(d+=TableEntry("MAC address",b.MACAddress));amtwirelessif==c&&xxWireless&&xxWireless.CIM_WiFiPortCapabilities.response&&(d+=TableEntry("State",addLinkConditional(xxWifiState[xxWireless.CIM_WiFiPort.response.EnabledState],"showWifiStateDlg()",xxAccountAdminName)),s=xxWireless.CIM_WiFiEndpoint.response.LANID,d+=TableEntry("Radio State", +xxRadioState[xxWireless.CIM_WiFiEndpoint.response.EnabledState]+", SSID: "+(s?s:"None")));amtwirelessif!=c&&(d+=TableEntry("Respond to ping",addLinkConditional(["Disabled","ICMP response","RMCP response","ICMP & RMCP response"][n.PingResponseEnabled+(n.RmcpPingResponseEnabled<<1)],"showPingActionDlg()",xxAccountAdminName)),d+=TableEntry("IPv4 state",addLinkConditional(1==b.DHCPEnabled?"Automatic using DHCP server":"Static IP address","showIPSetupDlg()",xxAccountAdminName)));d+=TableEntry("IPv4 address", +isIpAddress(b.IPAddress,"None"));isIpAddress(b.DefaultGateway)&&(d+=TableEntry("IPv4 gateway / Mask",b.DefaultGateway+" / "+isIpAddress(b.SubnetMask,"None")));f=b.PrimaryDNS;isIpAddress(f)&&(b.SecondaryDNS&&(f+=" / "+b.SecondaryDNS),d+=TableEntry("IPv4 domain name server",f));if(200==amtsysstate.IPS_IPv6PortSettings.status&&5