MeshCore cleanup.

Ylian Saint-Hilaire committed Jan 16, 2022 at 18:28 UTC 43682bf47f869705dff27361aa820d404279f409
1 file changed +110 -157
agents/meshcore.js
+110 -157
@@ -58,9 +58,7 @@ try {
58 return (-1);
59 }
60 });
61 -}
62 -catch (x) {
63 -}
61 +} catch (ex) { }
62
63 if (require('MeshAgent').ARCHID == null) {
64 var id = null;
@@ -74,10 +72,7 @@ if (require('MeshAgent').ARCHID == null) {
72 case 'darwin':
73 try {
74 id = require('os').arch() == 'x64' ? 16 : 29;
77 - }
78 - catch (xx) {
79 - id = 16;
80 - }
75 + } catch (ex) { id = 16; }
76 break;
77 }
78 if (id != null) { Object.defineProperty(require('MeshAgent'), 'ARCHID', { value: id }); }
@@ -180,23 +175,21 @@ if (process.platform == 'win32' && require('user-sessions').isRoot()) {
175 // Check the Agent Uninstall MetaData for correctness, as the installer may have written an incorrect value
176 try {
177 var writtenSize = 0, actualSize = Math.floor(require('fs').statSync(process.execPath).size / 1024);
183 - try { writtenSize = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize'); } catch (e) { }
184 - if (writtenSize != actualSize) { try { require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize', actualSize); } catch (e) { } }
185 - } catch (x) { }
178 + try { writtenSize = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize'); } catch (ex) { }
179 + if (writtenSize != actualSize) { try { require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize', actualSize); } catch (ex) { } }
180 + } catch (ex) { }
181
182 // Check to see if we are the Installed Mesh Agent Service, if we are, make sure we can run in Safe Mode
183 var svcname = process.platform == 'win32' ? 'Mesh Agent' : 'meshagent';
184 try {
185 svcname = require('MeshAgent').serviceName;
191 - }
192 - catch (x) {
193 - }
186 + } catch (ex) { }
187
188 try {
189 var meshCheck = false;
197 - try { meshCheck = require('service-manager').manager.getService(svcname).isMe(); } catch (e) { }
190 + try { meshCheck = require('service-manager').manager.getService(svcname).isMe(); } catch (ex) { }
191 if (meshCheck && require('win-bcd').isSafeModeService && !require('win-bcd').isSafeModeService(svcname)) { require('win-bcd').enableSafeModeService(svcname); }
199 - } catch (e) { }
192 + } catch (ex) { }
193 }
194
195 if (process.platform != 'win32') {
@@ -299,9 +292,9 @@ function zeroPad(num, size) { var s = '000000000' + num; return s.substr(s.lengt
292
293 // Create Secure IPC for Diagnostic Agent Communications
294 obj.DAIPC = require('net').createServer();
302 -if (process.platform != 'win32') { try { require('fs').unlinkSync(process.cwd() + '/DAIPC'); } catch (e) { } }
295 +if (process.platform != 'win32') { try { require('fs').unlinkSync(process.cwd() + '/DAIPC'); } catch (ex) { } }
296 obj.DAIPC.IPCPATH = process.platform == 'win32' ? ('\\\\.\\pipe\\' + require('_agentNodeId')() + '-DAIPC') : (process.cwd() + '/DAIPC');
304 -try { obj.DAIPC.listen({ path: obj.DAIPC.IPCPATH, writableAll: true, maxConnections: 5 }); } catch (e) { }
297 +try { obj.DAIPC.listen({ path: obj.DAIPC.IPCPATH, writableAll: true, maxConnections: 5 }); } catch (ex) { }
298 obj.DAIPC._daipc = [];
299 obj.DAIPC.on('connection', function (c) {
300 c._send = function (j) {
@@ -321,7 +314,7 @@ obj.DAIPC.on('connection', function (c) {
314 if (chunk.length < len) { this.unshift(chunk); return; }
315
316 var data = chunk.slice(4, len);
324 - try { data = JSON.parse(data.toString()); } catch (e) { }
317 + try { data = JSON.parse(data.toString()); } catch (ex) { }
318 if ((data == null) || (typeof data.cmd != 'string')) return;
319
320 try {
@@ -331,20 +324,20 @@ obj.DAIPC.on('connection', function (c) {
324 sendConsoleText('Request Help (' + this._registered + '): ' + data.value);
325 var help = {};
326 help[this._registered] = data.value;
334 - try { mesh.SendCommand({ action: 'sessions', type: 'help', value: help }); } catch (e) { }
327 + try { mesh.SendCommand({ action: 'sessions', type: 'help', value: help }); } catch (ex) { }
328 MeshServerLogEx(98, [this._registered, data.value], "Help Requested, user: " + this._registered + ", details: " + data.value, null);
329 break;
330 case 'cancelhelp':
331 if (this._registered == null) return;
332 sendConsoleText('Cancel Help (' + this._registered + ')');
340 - try { mesh.SendCommand({ action: 'sessions', type: 'help', value: {} }); } catch (e) { }
333 + try { mesh.SendCommand({ action: 'sessions', type: 'help', value: {} }); } catch (ex) { }
334 break;
335 case 'register':
336 if (typeof data.value == 'string') {
337 this._registered = data.value;
338 var apps = {};
339 apps[data.value] = 1;
347 - try { mesh.SendCommand({ action: 'sessions', type: 'app', value: apps }); } catch (e) { }
340 + try { mesh.SendCommand({ action: 'sessions', type: 'app', value: apps }); } catch (ex) { }
341 this._send({ cmd: 'serverstate', value: meshServerConnectionState, url: require('MeshAgent').ConnectedServer, amt: (amt != null) });
342 }
343 break;
@@ -376,10 +369,10 @@ obj.DAIPC.on('connection', function (c) {
369 this._send({ cmd: 'sessions', sessions: tunnelUserCount });
370 break;
371 case 'meshToolInfo':
379 - try { mesh.SendCommand({ action: 'meshToolInfo', name: data.name, hash: data.hash, cookie: data.cookie ? true : false, pipe: true }); } catch (e) { }
372 + try { mesh.SendCommand({ action: 'meshToolInfo', name: data.name, hash: data.hash, cookie: data.cookie ? true : false, pipe: true }); } catch (ex) { }
373 break;
374 case 'getUserImage':
382 - try { mesh.SendCommand({ action: 'getUserImage', userid: data.userid, pipe: true }); } catch (e) { }
375 + try { mesh.SendCommand({ action: 'getUserImage', userid: data.userid, pipe: true }); } catch (ex) { }
376 break;
377 case 'console':
378 if (debugConsole) {
@@ -389,7 +382,7 @@ obj.DAIPC.on('connection', function (c) {
382 break;
383 }
384 }
392 - catch (e) { removeRegisteredApp(this); this.end(); return; }
385 + catch (ex) { removeRegisteredApp(this); this.end(); return; }
386 });
387 });
388
@@ -1363,9 +1356,7 @@ function handleServerCommand(data) {
1356 var agentName = process.platform == 'win32' ? 'Mesh Agent' : 'meshagent';
1357 try {
1358 agentName = require('MeshAgent').serviceName;
1366 - }
1367 - catch (x) {
1368 - }
1359 + } catch (ex) { }
1360
1361 if (require('service-manager').manager.getService(agentName).isMe()) {
1362 try { diagnosticAgent_uninstall(); } catch (ex) { }
@@ -1880,9 +1871,7 @@ function onTunnelClosed() {
1871 receivedRatio: this.bytesReceived_ratio
1872 });
1873 }
1883 - }
1884 - catch (z) {
1885 - }
1874 + } catch (ex) { }
1875
1876 //sendConsoleText("Tunnel #" + this.httprequest.index + " closed. Sent -> " + this.bytesSent_uncompressed + ' bytes (uncompressed), ' + this.bytesSent_actual + ' bytes (actual), ' + this.bytesSent_ratio + '% compression', this.httprequest.sessionid);
1877 if (this.httprequest.index) { delete tunnels[this.httprequest.index]; }
@@ -2041,9 +2030,7 @@ function onTunnelData(data) {
2030 try {
2031 require('win-userconsent');
2032 enhanced = true;
2044 - }
2045 - catch (z) {
2046 - }
2033 + } catch (ex) { }
2034 if (enhanced) {
2035 var ipr = server_getUserImage(this.httprequest.userid);
2036 ipr.consentTitle = consentTitle;
@@ -2139,8 +2126,7 @@ function onTunnelData(data) {
2126 }
2127 });
2128 }
2142 - }
2143 - catch (ex) {
2129 + } catch (ex) {
2130 this.httprequest.connectionPromise._rej('Failed to start remote terminal session, ' + ex.toString());
2131 }
2132 }
@@ -2181,8 +2167,7 @@ function onTunnelData(data) {
2167 else {
2168 this.httprequest.connectionPromise._rej('Failed to start remote terminal session, no shell found');
2169 }
2184 - }
2185 - catch (ex) {
2170 + } catch (ex) {
2171 this.httprequest.connectionPromise._rej('Failed to start remote terminal session, ' + ex.toString());
2172 }
2173 }
@@ -2219,7 +2204,7 @@ function onTunnelData(data) {
2204 if (this.ws.httprequest.userid != null) {
2205 var userid = getUserIdAndGuestNameFromHttpRequest(this.ws.httprequest);
2206 if (tunnelUserCount.terminal[userid] == null) { tunnelUserCount.terminal[userid] = 1; } else { tunnelUserCount.terminal[userid]++; }
2222 - try { mesh.SendCommand({ action: 'sessions', type: 'terminal', value: tunnelUserCount.terminal }); } catch (e) { }
2207 + try { mesh.SendCommand({ action: 'sessions', type: 'terminal', value: tunnelUserCount.terminal }); } catch (ex) { }
2208 broadcastSessionsToRegisteredApps();
2209 }
2210
@@ -2232,7 +2217,7 @@ function onTunnelData(data) {
2217 if (this.ws.httprequest.soptions.notifyTitle != null) { notifyTitle = this.ws.httprequest.soptions.notifyTitle; }
2218 if (this.ws.httprequest.soptions.notifyMsgTerminal != null) { notifyMessage = this.ws.httprequest.soptions.notifyMsgTerminal.replace('{0}', this.ws.httprequest.realname).replace('{1}', this.ws.httprequest.username); }
2219 }
2235 - try { require('toaster').Toast(notifyTitle, notifyMessage); } catch (e) { }
2220 + try { require('toaster').Toast(notifyTitle, notifyMessage); } catch (ex) { }
2221 }
2222 },
2223 function (e) {
@@ -2287,10 +2272,10 @@ function onTunnelData(data) {
2272 } catch (ex) { sendConsoleText(ex); }
2273 }
2274 for (var i in this.httprequest.desktop.kvm.tunnels) {
2290 - try { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } catch (e) { }
2275 + try { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } catch (ex) { }
2276 }
2277 tunnelUserCount.desktop = users;
2293 - try { mesh.SendCommand({ action: 'sessions', type: 'kvm', value: users }); } catch (e) { }
2278 + try { mesh.SendCommand({ action: 'sessions', type: 'kvm', value: users }); } catch (ex) { }
2279 broadcastSessionsToRegisteredApps();
2280 }
2281
@@ -2311,10 +2296,10 @@ function onTunnelData(data) {
2296 } catch (ex) { sendConsoleText(ex); }
2297 }
2298 for (var i in this.httprequest.desktop.kvm.tunnels) {
2314 - try { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } catch (e) { }
2299 + try { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } catch (ex) { }
2300 }
2301 tunnelUserCount.desktop = users;
2317 - try { mesh.SendCommand({ action: 'sessions', type: 'kvm', value: users }); } catch (e) { }
2302 + try { mesh.SendCommand({ action: 'sessions', type: 'kvm', value: users }); } catch (ex) { }
2303 broadcastSessionsToRegisteredApps();
2304 }
2305
@@ -2322,8 +2307,7 @@ function onTunnelData(data) {
2307 try {
2308 this.unpipe(this.httprequest.desktop.kvm);
2309 this.httprequest.desktop.kvm.unpipe(this);
2325 - }
2326 - catch (e) { }
2310 + } catch (ex) { }
2311
2312 // Unpipe the WebRTC channel if needed (This will also be done when the WebRTC channel ends).
2313 if (this.rtcchannel) {
@@ -2331,7 +2315,7 @@ function onTunnelData(data) {
2315 this.rtcchannel.unpipe(this.httprequest.desktop.kvm);
2316 this.httprequest.desktop.kvm.unpipe(this.rtcchannel);
2317 }
2334 - catch (e) { }
2318 + catch (ex) { }
2319 }
2320
2321 // Place wallpaper back if needed
@@ -2339,7 +2323,7 @@ function onTunnelData(data) {
2323
2324 if (this.desktop.kvm.connectionCount == 0) {
2325 // Display a toast message. This may not be supported on all platforms.
2342 - // try { require('toaster').Toast('MeshCentral', 'Remote Desktop Control Ended.'); } catch (e) { }
2326 + // try { require('toaster').Toast('MeshCentral', 'Remote Desktop Control Ended.'); } catch (ex) { }
2327
2328 this.httprequest.desktop.kvm.end();
2329 if (this.httprequest.desktop.kvm.connectionBar) {
@@ -2406,9 +2390,7 @@ function onTunnelData(data) {
2390 try {
2391 require('win-userconsent');
2392 enhanced = true;
2409 - }
2410 - catch (z) {
2411 - }
2393 + } catch (ex) { }
2394 if (enhanced) {
2395 var ipr = server_getUserImage(this.httprequest.userid);
2396 ipr.consentTitle = consentTitle;
@@ -2453,7 +2435,7 @@ function onTunnelData(data) {
2435 if (this.ws.httprequest.soptions.notifyTitle != null) { notifyTitle = this.ws.httprequest.soptions.notifyTitle; }
2436 if (this.ws.httprequest.soptions.notifyMsgDesktop != null) { notifyMessage = this.ws.httprequest.soptions.notifyMsgDesktop.replace('{0}', this.ws.httprequest.realname).replace('{1}', this.ws.httprequest.username); }
2437 }
2456 - try { require('toaster').Toast(notifyTitle, notifyMessage, tsid); } catch (e) { }
2438 + try { require('toaster').Toast(notifyTitle, notifyMessage, tsid); } catch (ex) { }
2439 }
2440 if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 0x40)) {
2441 // Connection Bar is required
@@ -2465,7 +2447,7 @@ function onTunnelData(data) {
2447 this.ws.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')(this.ws.httprequest.privacybartext.replace('{0}', this.ws.httprequest.desktop.kvm.rusers.join(', ')).replace('{1}', this.ws.httprequest.desktop.kvm.users.join(', ')), require('MeshAgent')._tsid);
2448 MeshServerLogEx(31, null, "Remote Desktop Connection Bar Activated/Updated (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
2449 }
2468 - catch (e) {
2450 + catch (ex) {
2451 if (process.platform != 'darwin') {
2452 MeshServerLogEx(32, null, "Remote Desktop Connection Bar Failed or Not Supported (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
2453 }
@@ -2504,7 +2486,7 @@ function onTunnelData(data) {
2486 if (this.httprequest.soptions.notifyTitle != null) { notifyTitle = this.httprequest.soptions.notifyTitle; }
2487 if (this.httprequest.soptions.notifyMsgDesktop != null) { notifyMessage = this.httprequest.soptions.notifyMsgDesktop.replace('{0}', this.httprequest.realname).replace('{1}', this.httprequest.username); }
2488 }
2507 - try { require('toaster').Toast(notifyTitle, notifyMessage, tsid); } catch (e) { }
2489 + try { require('toaster').Toast(notifyTitle, notifyMessage, tsid); } catch (ex) { }
2490 } else {
2491 MeshServerLogEx(36, null, "Started remote desktop without notification (" + this.httprequest.remoteaddr + ")", this.httprequest);
2492 }
@@ -2518,7 +2500,7 @@ function onTunnelData(data) {
2500 this.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')(this.httprequest.privacybartext.replace('{0}', this.httprequest.desktop.kvm.rusers.join(', ')).replace('{1}', this.httprequest.desktop.kvm.users.join(', ')), require('MeshAgent')._tsid);
2501 MeshServerLogEx(31, null, "Remote Desktop Connection Bar Activated/Updated (" + this.httprequest.remoteaddr + ")", this.httprequest);
2502 }
2521 - catch (e) {
2503 + catch (ex) {
2504 MeshServerLogEx(32, null, "Remote Desktop Connection Bar Failed or not Supported (" + this.httprequest.remoteaddr + ")", this.httprequest);
2505 }
2506 if (this.httprequest.desktop.kvm.connectionBar) {
@@ -2562,7 +2544,7 @@ function onTunnelData(data) {
2544 if (this.httprequest.userid != null) {
2545 var userid = getUserIdAndGuestNameFromHttpRequest(this.httprequest);
2546 if (tunnelUserCount.files[userid] == null) { tunnelUserCount.files[userid] = 1; } else { tunnelUserCount.files[userid]++; }
2565 - try { mesh.SendCommand({ action: 'sessions', type: 'files', value: tunnelUserCount.files }); } catch (e) { }
2547 + try { mesh.SendCommand({ action: 'sessions', type: 'files', value: tunnelUserCount.files }); } catch (ex) { }
2548 broadcastSessionsToRegisteredApps();
2549 }
2550
@@ -2571,7 +2553,7 @@ function onTunnelData(data) {
2553 if (this.httprequest.userid != null) {
2554 var userid = getUserIdAndGuestNameFromHttpRequest(this.httprequest);
2555 if (tunnelUserCount.files[userid] != null) { tunnelUserCount.files[userid]--; if (tunnelUserCount.files[userid] <= 0) { delete tunnelUserCount.files[userid]; } }
2574 - try { mesh.SendCommand({ action: 'sessions', type: 'files', value: tunnelUserCount.files }); } catch (e) { }
2556 + try { mesh.SendCommand({ action: 'sessions', type: 'files', value: tunnelUserCount.files }); } catch (ex) { }
2557 broadcastSessionsToRegisteredApps();
2558 }
2559 };
@@ -2594,9 +2576,7 @@ function onTunnelData(data) {
2576 try {
2577 require('win-userconsent');
2578 enhanced = true;
2597 - }
2598 - catch (z) {
2599 - }
2579 + } catch (ex) { }
2580 if (enhanced) {
2581 var ipr = server_getUserImage(this.httprequest.userid);
2582 ipr.consentTitle = consentTitle;
@@ -2608,12 +2588,10 @@ function onTunnelData(data) {
2588 this.__childPromise.close = this.consent.close.bind(this.consent);
2589 return (this.consent);
2590 });
2611 - }
2612 - else {
2591 + } else {
2592 pr = require('message-box').create(consentTitle, consentMessage, 30, null);
2593 }
2615 - }
2616 - else {
2594 + } else {
2595 pr = require('message-box').create(consentTitle, consentMessage, 30, null);
2596 }
2597 pr.ws = this;
@@ -2636,7 +2614,7 @@ function onTunnelData(data) {
2614 if (this.ws.httprequest.soptions.notifyTitle != null) { notifyTitle = this.ws.httprequest.soptions.notifyTitle; }
2615 if (this.ws.httprequest.soptions.notifyMsgFiles != null) { notifyMessage = this.ws.httprequest.soptions.notifyMsgFiles.replace('{0}', this.ws.httprequest.realname).replace('{1}', this.ws.httprequest.username); }
2616 }
2639 - try { require('toaster').Toast(notifyTitle, notifyMessage); } catch (e) { }
2617 + try { require('toaster').Toast(notifyTitle, notifyMessage); } catch (ex) { }
2618 }
2619 this.ws.resume();
2620 },
@@ -2658,7 +2636,7 @@ function onTunnelData(data) {
2636 if (this.httprequest.soptions.notifyTitle != null) { notifyTitle = this.httprequest.soptions.notifyTitle; }
2637 if (this.httprequest.soptions.notifyMsgFiles != null) { notifyMessage = this.httprequest.soptions.notifyMsgFiles.replace('{0}', this.httprequest.realname).replace('{1}', this.httprequest.username); }
2638 }
2661 - try { require('toaster').Toast(notifyTitle, notifyMessage); } catch (e) { }
2639 + try { require('toaster').Toast(notifyTitle, notifyMessage); } catch (ex) { }
2640 } else {
2641 MeshServerLogEx(43, null, "Started remote files without notification (" + this.httprequest.remoteaddr + ")", this.httprequest);
2642 }
@@ -2682,7 +2660,7 @@ function onTunnelData(data) {
2660 } else if (this.httprequest.protocol == 5) {
2661 // Process files commands
2662 var cmd = null;
2685 - try { cmd = JSON.parse(data); } catch (e) { };
2663 + try { cmd = JSON.parse(data); } catch (ex) { };
2664 if (cmd == null) { return; }
2665 if ((cmd.ctrlChannel == '102938') || ((cmd.type == 'offer') && (cmd.sdp != null))) { onTunnelControlData(cmd, this); return; } // If this is control data, handle it now.
2666 if (cmd.action == undefined) { return; }
@@ -2729,7 +2707,7 @@ function onTunnelData(data) {
2707 // Delete, possibly recursive delete
2708 for (var i in cmd.delfiles) {
2709 var p = obj.path.join(cmd.path, cmd.delfiles[i]), delcount = 0;
2732 - try { delcount = deleteFolderRecursive(p, cmd.rec); } catch (e) { }
2710 + try { delcount = deleteFolderRecursive(p, cmd.rec); } catch (ex) { }
2711 if ((delcount == 1) && !cmd.rec) {
2712 MeshServerLogEx(45, [p], "Delete: \"" + p + "\"", this.httprequest);
2713 } else {
@@ -2759,7 +2737,7 @@ function onTunnelData(data) {
2737 var oldfullpath = obj.path.join(cmd.path, cmd.oldname);
2738 var newfullpath = obj.path.join(cmd.path, cmd.newname);
2739 MeshServerLogEx(48, [oldfullpath, cmd.newname], 'Rename: \"' + oldfullpath + '\" to \"' + cmd.newname + '\"', this.httprequest);
2762 - try { fs.renameSync(oldfullpath, newfullpath); } catch (e) { console.log(e); }
2740 + try { fs.renameSync(oldfullpath, newfullpath); } catch (ex) { console.log(ex); }
2741 break;
2742 }
2743 case 'findfile':
@@ -2795,7 +2773,7 @@ function onTunnelData(data) {
2773 MeshServerLogEx((cmd.ask == 'coredump') ? 104 : 49, [cmd.path], 'Download: \"' + cmd.path + '\"', this.httprequest);
2774 if ((cmd.path == null) || (this.filedownload != null)) { this.write({ action: 'download', sub: 'cancel', id: this.filedownload.id }); delete this.filedownload; }
2775 this.filedownload = { id: cmd.id, path: cmd.path, ptr: 0 }
2798 - try { this.filedownload.f = fs.openSync(this.filedownload.path, 'rbN'); } catch (e) { this.write({ action: 'download', sub: 'cancel', id: this.filedownload.id }); delete this.filedownload; }
2776 + try { this.filedownload.f = fs.openSync(this.filedownload.path, 'rbN'); } catch (ex) { this.write({ action: 'download', sub: 'cancel', id: this.filedownload.id }); delete this.filedownload; }
2777 if (this.filedownload) { this.write({ action: 'download', sub: 'start', id: cmd.id }); }
2778 } else if ((this.filedownload != null) && (cmd.id == this.filedownload.id)) { // Download commands
2779 if (cmd.sub == 'startack') { sendNextBlock = ((typeof cmd.ack == 'number') ? cmd.ack : 8); } else if (cmd.sub == 'stop') { delete this.filedownload; } else if (cmd.sub == 'ack') { sendNextBlock = 1; }
@@ -2819,7 +2797,7 @@ function onTunnelData(data) {
2797 var filepath = cmd.name ? obj.path.join(cmd.path, cmd.name) : cmd.path;
2798 this.httprequest.uploadFilePath = filepath;
2799 this.httprequest.uploadFileSize = 0;
2822 - try { this.httprequest.uploadFile = fs.openSync(filepath, cmd.append ? 'abN' : 'wbN'); } catch (e) { this.write(Buffer.from(JSON.stringify({ action: 'uploaderror', reqid: cmd.reqid }))); break; }
2800 + try { this.httprequest.uploadFile = fs.openSync(filepath, cmd.append ? 'abN' : 'wbN'); } catch (ex) { this.write(Buffer.from(JSON.stringify({ action: 'uploaderror', reqid: cmd.reqid }))); break; }
2801 this.httprequest.uploadFileid = cmd.reqid;
2802 if (this.httprequest.uploadFile) { this.write(Buffer.from(JSON.stringify({ action: 'uploadstart', reqid: this.httprequest.uploadFileid }))); }
2803 break;
@@ -2867,7 +2845,7 @@ function onTunnelData(data) {
2845 for (var i in cmd.names) {
2846 var sc = obj.path.join(cmd.scpath, cmd.names[i]), ds = obj.path.join(cmd.dspath, cmd.names[i]);
2847 MeshServerLogEx(51, [sc, ds], 'Copy: \"' + sc + '\" to \"' + ds + '\"', this.httprequest);
2870 - if (sc != ds) { try { fs.copyFileSync(sc, ds); } catch (e) { } }
2848 + if (sc != ds) { try { fs.copyFileSync(sc, ds); } catch (ex) { } }
2849 }
2850 break;
2851 }
@@ -2877,7 +2855,7 @@ function onTunnelData(data) {
2855 for (var i in cmd.names) {
2856 var sc = obj.path.join(cmd.scpath, cmd.names[i]), ds = obj.path.join(cmd.dspath, cmd.names[i]);
2857 MeshServerLogEx(52, [sc, ds], 'Move: \"' + sc + '\" to \"' + ds + '\"', this.httprequest);
2880 - if (sc != ds) { try { fs.copyFileSync(sc, ds); fs.unlinkSync(sc); } catch (e) { } }
2858 + if (sc != ds) { try { fs.copyFileSync(sc, ds); fs.unlinkSync(sc); } catch (ex) { } }
2859 }
2860 break;
2861 }
@@ -2887,7 +2865,7 @@ function onTunnelData(data) {
2865
2866 // Check that the specified files exist & build full paths
2867 var fp, stat, p = [];
2890 - for (var i in cmd.files) { fp = cmd.path + '/' + cmd.files[i]; stat = null; try { stat = fs.statSync(fp); } catch (e) { } if (stat != null) { p.push(fp); } }
2868 + for (var i in cmd.files) { fp = cmd.path + '/' + cmd.files[i]; stat = null; try { stat = fs.statSync(fp); } catch (ex) { } if (stat != null) { p.push(fp); } }
2869 if (p.length == 0) return; // No files, quit now.
2870
2871 // Setup file compression
@@ -2912,7 +2890,7 @@ function onTunnelData(data) {
2890 break;
2891 case 'cancel':
2892 // Cancel zip operation if present
2915 - try { this.zipcancel = true; this.zip.cancel(function () { }); } catch (e) { }
2893 + try { this.zipcancel = true; this.zip.cancel(function () { }); } catch (ex) { }
2894 this.zip = null;
2895 break;
2896 default:
@@ -2921,14 +2899,14 @@ function onTunnelData(data) {
2899 }
2900 } else if (this.httprequest.protocol == 7) { // Plugin data exchange
2901 var cmd = null;
2924 - try { cmd = JSON.parse(data); } catch (e) { };
2902 + try { cmd = JSON.parse(data); } catch (ex) { };
2903 if (cmd == null) { return; }
2904 if ((cmd.ctrlChannel == '102938') || ((cmd.type == 'offer') && (cmd.sdp != null))) { onTunnelControlData(cmd, this); return; } // If this is control data, handle it now.
2905 if (cmd.action == undefined) return;
2906
2907 switch (cmd.action) {
2908 case 'plugin': {
2931 - try { require(cmd.plugin).consoleaction(cmd, null, null, this); } catch (e) { throw e; }
2909 + try { require(cmd.plugin).consoleaction(cmd, null, null, this); } catch (ex) { throw e; }
2910 break;
2911 }
2912 default: {
@@ -2966,11 +2944,11 @@ function deleteFolderRecursive(path, rec) {
2944 function onTunnelWebRTCControlData(data) {
2945 if (typeof data != 'string') return;
2946 var obj;
2969 - try { obj = JSON.parse(data); } catch (e) { sendConsoleText('Invalid control JSON on WebRTC: ' + data); return; }
2947 + try { obj = JSON.parse(data); } catch (ex) { sendConsoleText('Invalid control JSON on WebRTC: ' + data); return; }
2948 if (obj.type == 'close') {
2949 //sendConsoleText('Tunnel #' + this.xrtc.websocket.tunnel.index + ' WebRTC control close');
2972 - try { this.close(); } catch (e) { }
2973 - try { this.xrtc.close(); } catch (e) { }
2950 + try { this.close(); } catch (ex) { }
2951 + try { this.xrtc.close(); } catch (ex) { }
2952 }
2953 }
2954
@@ -2978,7 +2956,7 @@ function onTunnelWebRTCControlData(data) {
2956 function onTunnelControlData(data, ws) {
2957 var obj;
2958 if (ws == null) { ws = this; }
2981 - if (typeof data == 'string') { try { obj = JSON.parse(data); } catch (e) { sendConsoleText('Invalid control JSON: ' + data); return; } }
2959 + if (typeof data == 'string') { try { obj = JSON.parse(data); } catch (ex) { sendConsoleText('Invalid control JSON: ' + data); return; } }
2960 else if (typeof data == 'object') { obj = data; } else { return; }
2961 //sendConsoleText('onTunnelControlData(' + ws.httprequest.protocol + '): ' + JSON.stringify(data));
2962 //console.log('onTunnelControlData: ' + JSON.stringify(data));
@@ -3029,7 +3007,7 @@ function onTunnelControlData(data, ws) {
3007 case 'close': {
3008 // We received the close on the websocket
3009 //sendConsoleText('Tunnel #' + ws.tunnel.index + ' WebSocket control close');
3032 - try { ws.close(); } catch (e) { }
3010 + try { ws.close(); } catch (ex) { }
3011 break;
3012 }
3013 case 'termsize': {
@@ -3081,7 +3059,7 @@ function onTunnelControlData(data, ws) {
3059 } else if (ws.httprequest.protocol == 2) { // Desktop
3060 // Switch the user input from websocket to webrtc at this point.
3061 ws.unpipe(ws.httprequest.desktop.kvm);
3084 - try { ws.webrtc.rtcchannel.pipe(ws.httprequest.desktop.kvm, { dataTypeSkip: 1, end: false }); } catch (e) { sendConsoleText('EX2'); } // 0 = Binary, 1 = Text.
3062 + try { ws.webrtc.rtcchannel.pipe(ws.httprequest.desktop.kvm, { dataTypeSkip: 1, end: false }); } catch (ex) { sendConsoleText('EX2'); } // 0 = Binary, 1 = Text.
3063 ws.resume(); // Resume the websocket to keep receiving control data
3064 }
3065 ws.write('{\"ctrlChannel\":\"102938\",\"type\":\"webrtc2\"}'); // Indicates we will no longer get any data on websocket, switching to WebRTC at this point.
@@ -3123,14 +3101,13 @@ function onTunnelControlData(data, ws) {
3101 try {
3102 this.unpipe(this.websocket.desktop.kvm);
3103 this.websocket.httprequest.desktop.kvm.unpipe(this);
3126 - }
3127 - catch (e) { }
3104 + } catch (ex) { }
3105 }
3106 });
3107 this.websocket.write('{\"ctrlChannel\":\"102938\",\"type\":\"webrtc0\"}'); // Indicate we are ready for WebRTC switch-over.
3108 });
3109 var sdp = null;
3133 - try { sdp = ws.webrtc.setOffer(obj.sdp); } catch (e) { }
3110 + try { sdp = ws.webrtc.setOffer(obj.sdp); } catch (ex) { }
3111 if (sdp != null) { ws.write({ type: 'answer', ctrlChannel: '102938', sdp: sdp }); }
3112 break;
3113 }
@@ -3203,7 +3180,7 @@ function openUserDesktopUrl(url) {
3180 // Unknown platform, ignore this command.
3181 break;
3182 }
3206 - } catch (e) { }
3183 + } catch (ex) { }
3184 return child;
3185 }
3186
@@ -3215,12 +3192,12 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3192 case 'help': { // Displays available commands
3193 var fin = '', f = '', availcommands = 'translations,agentupdate,errorlog,msh,timerinfo,coreinfo,coredump,service,fdsnapshot,fdcount,startupoptions,alert,agentsize,versions,help,info,osinfo,args,print,type,dbkeys,dbget,dbset,dbcompact,eval,parseuri,httpget,wslist,plugin,wsconnect,wssend,wsclose,notify,ls,ps,kill,netinfo,location,power,wakeonlan,setdebug,smbios,rawsmbios,toast,lock,users,openurl,getscript,getclip,setclip,log,av,cpuinfo,sysinfo,apf,scanwifi,wallpaper,agentmsg,task';
3194 if (require('os').dns != null) { availcommands += ',dnsinfo'; }
3218 - try { require('linux-dhcp'); availcommands += ',dhcp'; } catch (e) { }
3195 + try { require('linux-dhcp'); availcommands += ',dhcp'; } catch (ex) { }
3196 if (process.platform == 'win32') { availcommands += ',cs,safemode,wpfhwacceleration,uac'; }
3197 if (amt != null) { availcommands += ',amt,amtconfig,amtevents'; }
3198 if (process.platform != 'freebsd') { availcommands += ',vm'; }
3199 if (require('MeshAgent').maxKvmTileSize != null) { availcommands += ',kvmmode'; }
3223 - try { require('zip-reader'); availcommands += ',zip,unzip'; } catch (e) { }
3200 + try { require('zip-reader'); availcommands += ',zip,unzip'; } catch (ex) { }
3201
3202 availcommands = availcommands.split(',').sort();
3203 while (availcommands.length > 0) {
@@ -3237,7 +3214,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3214 }
3215 case 'dhcp': // This command is only supported on Linux, this is because Linux does not give us the DNS suffix for each network adapter independently so we have to ask the DHCP server.
3216 {
3240 - try { require('linux-dhcp'); } catch (e) { response = 'Unknown command "dhcp", type "help" for list of avaialble commands.'; break; }
3217 + try { require('linux-dhcp'); } catch (ex) { response = 'Unknown command "dhcp", type "help" for list of avaialble commands.'; break; }
3218 if (args['_'].length == 0) {
3219 var j = require('os').networkInterfaces();
3220 var ifcs = [];
@@ -3272,8 +3249,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3249 try {
3250 var cs = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Power', 'CsEnabled');
3251 response = "Connected Standby: " + (cs == 1 ? "ENABLED" : "DISABLED");
3275 - }
3276 - catch (e) {
3252 + } catch (ex) {
3253 response = "This machine does not support Connected Standby";
3254 }
3255 break;
@@ -3288,8 +3264,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3264
3265 cs = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Power', 'CsEnabled');
3266 response = "Connected Standby: " + (cs == 1 ? "ENABLED" : "DISABLED");
3291 - }
3292 - catch (e) {
3267 + } catch (ex) {
3268 response = "This machine does not support Connected Standby";
3269 }
3270 }
@@ -3388,7 +3363,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3363 } else {
3364 if ((args['_'][0] == 'add') && (args['_'].length > 1)) {
3365 var msgID, iconIndex = 0;
3391 - if (args['_'].length >= 3) { try { iconIndex = parseInt(args['_'][2]); } catch (e) { } }
3366 + if (args['_'].length >= 3) { try { iconIndex = parseInt(args['_'][2]); } catch (ex) { } }
3367 if (typeof iconIndex != 'number') { iconIndex = 0; }
3368 msgID = sendAgentMessage(args['_'][1], iconIndex);
3369 response = 'Agent message: ' + msgID + ' added.';
@@ -3451,14 +3426,11 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3426 case 'service':
3427 if (args['_'].length != 1) {
3428 response = "Proper usage: service status|restart"; // Display usage
3454 - }
3455 - else {
3429 + } else {
3430 var svcname = process.platform == 'win32' ? 'Mesh Agent' : 'meshagent';
3431 try {
3432 svcname = require('MeshAgent').serviceName;
3459 - }
3460 - catch (x) {
3461 - }
3433 + } catch (ex) { }
3434 var s = require('service-manager').manager.getService(svcname);
3435 switch (args['_'][0].toLowerCase()) {
3436 case 'status':
@@ -3467,8 +3439,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3439 case 'restart':
3440 if (s.isMe()) {
3441 s.restart();
3470 - }
3471 - else {
3442 + } else {
3443 response = 'Restarting another agent instance is not allowed';
3444 }
3445 break;
@@ -3549,8 +3520,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3520 try {
3521 require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System', 'PromptOnSecureDesktop', 0);
3522 response = 'UAC mode changed to: Interactive Desktop';
3552 - }
3553 - catch (e) {
3523 + } catch (ex) {
3524 response = "Unable to change UAC Mode";
3525 }
3526 break;
@@ -3558,8 +3528,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3528 try {
3529 require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System', 'PromptOnSecureDesktop', 1);
3530 response = 'UAC mode changed to: Secure Desktop';
3561 - }
3562 - catch (e) {
3531 + } catch (ex) {
3532 response = "Unable to change UAC Mode";
3533 }
3534 break;
@@ -3608,10 +3577,10 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3577 if (process.platform == 'win32') {
3578 // Check the Agent Uninstall MetaData for correctness, as the installer may have written an incorrect value
3579 var writtenSize = 0;
3611 - try { writtenSize = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize'); } catch (e) { response = e; }
3580 + try { writtenSize = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize'); } catch (ex) { response = e; }
3581 if (writtenSize != actualSize) {
3582 response = "Size updated from: " + writtenSize + " to: " + actualSize;
3614 - try { require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize', actualSize); } catch (e) { response = e; }
3583 + try { require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize', actualSize); } catch (ex) { response = e; }
3584 } else
3585 { response = "Agent Size: " + actualSize + " kb"; }
3586 } else
@@ -3638,21 +3607,21 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3607 try {
3608 reg.WriteKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration', 0);
3609 response = "OK";
3641 - } catch (e) { response = "FAILED"; }
3610 + } catch (ex) { response = "FAILED"; }
3611 break;
3612 case 'OFF':
3613 try {
3614 reg.WriteKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration', 1);
3615 response = 'OK';
3647 - } catch (e) { response = 'FAILED'; }
3616 + } catch (ex) { response = 'FAILED'; }
3617 break;
3618 case 'STATUS':
3619 var s;
3651 - try { s = reg.QueryKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration') == 1 ? 'DISABLED' : 'ENABLED'; } catch (e) { s = 'DEFAULT'; }
3620 + try { s = reg.QueryKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration') == 1 ? 'DISABLED' : 'ENABLED'; } catch (ex) { s = 'DEFAULT'; }
3621 response = "WPF Hardware Acceleration: " + s;
3622 break;
3623 case 'DEFAULT':
3655 - try { reg.DeleteKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration'); } catch (e) { }
3624 + try { reg.DeleteKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration'); } catch (ex) { }
3625 response = 'OK';
3626 break;
3627 }
@@ -3744,8 +3713,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3713 case 'safemode':
3714 if (process.platform != 'win32') {
3715 response = 'safemode only supported on Windows Platforms'
3747 - }
3748 - else {
3716 + } else {
3717 if (args['_'].length != 1) {
3718 response = 'Proper usage: safemode (ON|OFF|STATUS)'; // Display usage
3719 }
@@ -3753,9 +3721,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3721 var svcname = process.platform == 'win32' ? 'Mesh Agent' : 'meshagent';
3722 try {
3723 svcname = require('MeshAgent').serviceName;
3756 - }
3757 - catch (x) {
3758 - }
3724 + } catch (ex) { }
3725
3726 switch (args['_'][0].toUpperCase()) {
3727 default:
@@ -3933,14 +3899,12 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3899 var agentName = process.platform == 'win32' ? 'Mesh Agent' : 'meshagent';
3900 try {
3901 agentName = require('MeshAgent').serviceName;
3936 - }
3937 - catch (x) {
3938 - }
3902 + } catch (ex) { }
3903
3904 if (!require('service-manager').manager.getService(agentName).isMe()) {
3905 response = 'Uininstall failed, this instance is not the service instance';
3906 } else {
3943 - try { diagnosticAgent_uninstall(); } catch (e) { }
3907 + try { diagnosticAgent_uninstall(); } catch (ex) { }
3908 var js = "require('service-manager').manager.getService('" + agentName + "').stop(); require('service-manager').manager.uninstallService('" + agentName + "'); process.exit();";
3909 this.child = require('child_process').execFile(process.execPath, [process.platform == 'win32' ? (process.execPath.split('\\').pop()) : (process.execPath.split('/').pop()), '-b64exec', Buffer.from(js).toString('base64')], { type: 4, detached: true });
3910 }
@@ -4072,7 +4036,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
4036 if (options == null) {
4037 response = 'Invalid url.';
4038 } else {
4075 - try { consoleHttpRequest = http.request(options, consoleHttpResponse); } catch (e) { response = 'Invalid HTTP GET request'; }
4039 + try { consoleHttpRequest = http.request(options, consoleHttpResponse); } catch (ex) { response = 'Invalid HTTP GET request'; }
4040 consoleHttpRequest.sessionid = sessionid;
4041 if (consoleHttpRequest != null) {
4042 consoleHttpRequest.end();
@@ -4101,7 +4065,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
4065 var options = http.parseUri(args['_'][0].split('$').join('%24').split('@').join('%40')); // Escape the $ and @ characters in the URL
4066 options.rejectUnauthorized = 0;
4067 httprequest = http.request(options);
4104 - } catch (e) { response = 'Invalid HTTP websocket request'; }
4068 + } catch (ex) { response = 'Invalid HTTP websocket request'; }
4069 if (httprequest != null) {
4070 httprequest.upgrade = onWebSocketUpgrade;
4071 httprequest.on('error', function (e) { sendConsoleText("ERROR: Unable to connect to: " + this.url + ", " + JSON.stringify(e)); });
@@ -4170,7 +4134,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
4134 var results = fs.readdirSync(xpath);
4135 for (var i = 0; i < results.length; ++i) {
4136 var stat = null, p = obj.path.join(args['_'][0], results[i]);
4173 - try { stat = fs.statSync(p); } catch (e) { }
4137 + try { stat = fs.statSync(p); } catch (ex) { }
4138 if ((stat == null) || (stat == undefined)) {
4139 response += (results[i] + "\r\n");
4140 } else {
@@ -4368,16 +4332,16 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
4332 try {
4333 apftunnel.connect();
4334 response = "Started APF tunnel";
4371 - } catch (e) {
4372 - response = JSON.stringify(e);
4335 + } catch (ex) {
4336 + response = JSON.stringify(ex);
4337 }
4338 }
4339 } else if (connType == -2) { // Disconnect
4340 try {
4341 apftunnel.disconnect();
4342 response = "Stopped APF tunnel";
4379 - } catch (e) {
4380 - response = JSON.stringify(e);
4343 + } catch (ex) {
4344 + response = JSON.stringify(ex);
4345 }
4346 apftunnel = null;
4347 } else {
@@ -4406,8 +4370,8 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
4370 // for plugin creators, you'll want to have a plugindir/modules_meshcore/plugin.js
4371 // to control the output / actions here.
4372 response = require(args['_'][0]).consoleaction(args, rights, sessionid, mesh);
4409 - } catch (e) {
4410 - response = "There was an error in the plugin (" + e + ")";
4373 + } catch (ex) {
4374 + response = "There was an error in the plugin (" + ex + ")";
4375 }
4376 } else {
4377 response = "Proper usage: plugin [pluginName] [args].";
@@ -4419,7 +4383,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
4383 break;
4384 }
4385 }
4422 - } catch (e) { response = "Command returned an exception error: " + e; console.log(e); }
4386 + } catch (ex) { response = "Command returned an exception error: " + ex; console.log(ex); }
4387 if (response != null) { sendConsoleText(response, sessionid); }
4388 }
4389
@@ -4467,9 +4431,7 @@ function sendAgentMessage(msg, icon, serverid, first) {
4431 }
4432 try {
4433 require('MeshAgent').SendCommand({ action: 'sessions', type: 'msg', value: p });
4470 - }
4471 - catch (ex) {
4472 - }
4434 + } catch (ex) { }
4435 return (arguments.length > 0 ? sendAgentMessage.messages.peek().id : sendAgentMessage.messages);
4436 }
4437 function getOpenDescriptors() {
@@ -4549,17 +4511,14 @@ function linux_execv(name, agentfilename, sessionid) {
4511
4512 try {
4513 libs = JSON.parse(child.stdout.str.trim());
4552 - }
4553 - catch (e) {
4554 - }
4514 + } catch (ex) { }
4515 }
4516
4517 while (libs.length > 0) {
4518 try {
4519 libc = require('_GenericMarshal').CreateNativeProxy(libs.pop().path);
4520 break;
4561 - }
4562 - catch (e) {
4521 + } catch (ex) {
4522 libc = null;
4523 continue;
4524 }
@@ -4568,8 +4527,7 @@ function linux_execv(name, agentfilename, sessionid) {
4527 try {
4528 libc.CreateMethod('execv');
4529 libc.CreateMethod('close');
4571 - }
4572 - catch (e) {
4530 + } catch (ex) {
4531 libc = null;
4532 }
4533 }
@@ -4581,8 +4539,7 @@ function linux_execv(name, agentfilename, sessionid) {
4539 // restart service
4540 var s = require('service-manager').manager.getService(name);
4541 s.restart();
4584 - }
4585 - catch (zz) {
4542 + } catch (ex) {
4543 sendConsoleText('Self Update encountered an error trying to restart service', sessionid);
4544 sendAgentMessage('Self Update encountered an error trying to restart service', 3);
4545 }
@@ -4645,18 +4602,15 @@ function bsd_execv(name, agentfilename, sessionid) {
4602 libc = require('_GenericMarshal').CreateNativeProxy(child.stdout.str.trim());
4603 libc.CreateMethod('execv');
4604 libc.CreateMethod('close');
4648 - }
4649 - catch (e) {
4650 - if (sessionid != null) { sendConsoleText('Self Update failed: ' + e.toString(), sessionid) }
4651 - sendAgentMessage('Self Update failed: ' + e.toString(), 3);
4605 + } catch (ex) {
4606 + if (sessionid != null) { sendConsoleText('Self Update failed: ' + ex.toString(), sessionid) }
4607 + sendAgentMessage('Self Update failed: ' + ex.toString(), 3);
4608 return;
4609 }
4610
4655 - var i;
4611 var path = require('_GenericMarshal').CreateVariable(process.execPath);
4612 var argarr = [process.execPath];
4658 - var argtmp = [];
4659 - var args;
4613 + var args, i, argtmp = [];
4614 var options = require('MeshAgent').getStartupOptions();
4615 for (i in options) {
4616 argarr.push('--' + i + '="' + options[i] + '"');
@@ -4683,8 +4637,7 @@ function windows_execve(name, agentfilename, sessionid) {
4637 try {
4638 libc = require('_GenericMarshal').CreateNativeProxy('msvcrt.dll');
4639 libc.CreateMethod('_wexecve');
4686 - }
4687 - catch (xx) {
4640 + } catch (ex) {
4641 sendConsoleText('Self Update failed because msvcrt.dll is missing', sessionid);
4642 sendAgentMessage('Self Update failed because msvcrt.dll is missing', 3);
4643 return;
@@ -4736,7 +4689,7 @@ function agentUpdate_Start(updateurl, updateoptions) {
4689 }
4690 if (process.platform == 'win32') { s.close(); }
4691 }
4739 - catch (zz) {
4692 + catch (ex) {
4693 sendConsoleText('Self Update Failed because this agent is not an instance of (' + name + ')', sessionid);
4694 sendAgentMessage('Self Update Failed because this agent is not an instance of (' + name + ')', 3);
4695 return;
@@ -4804,7 +4757,7 @@ function agentUpdate_Start(updateurl, updateoptions) {
4757 }
4758
4759 // Send an indication to the server that we got the update download correctly.
4807 - try { require('MeshAgent').SendCommand({ action: 'agentupdatedownloaded' }); } catch (e) { }
4760 + try { require('MeshAgent').SendCommand({ action: 'agentupdatedownloaded' }); } catch (ex) { }
4761
4762 if (sessionid != null) { sendConsoleText('Updating and restarting agent...', sessionid); }
4763 if (process.platform == 'win32') {
@@ -4838,7 +4791,7 @@ function agentUpdate_Start(updateurl, updateoptions) {
4791 var s = require('service-manager').manager.getService(name);
4792 s.restart();
4793 }
4841 - catch (zz) {
4794 + catch (ex) {
4795 sendConsoleText('Self Update encountered an error trying to restart service', sessionid);
4796 sendAgentMessage('Self Update encountered an error trying to restart service', 3);
4797 }
@@ -4942,8 +4895,8 @@ function sendPeriodicServerUpdate(flags, force) {
4895 // Update anti-virus information
4896 if ((flags & 4) && (process.platform == 'win32')) {
4897 // Windows Command: "wmic /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct get /FORMAT:CSV"
4945 - try { meshCoreObj.av = require('win-info').av(); meshCoreObjChanged(); } catch (e) { av = null; } // Antivirus
4946 - //if (process.platform == 'win32') { try { meshCoreObj.pr = require('win-info').pendingReboot(); meshCoreObjChanged(); } catch (e) { meshCoreObj.pr = null; } } // Pending reboot
4898 + try { meshCoreObj.av = require('win-info').av(); meshCoreObjChanged(); } catch (ex) { av = null; } // Antivirus
4899 + //if (process.platform == 'win32') { try { meshCoreObj.pr = require('win-info').pendingReboot(); meshCoreObjChanged(); } catch (ex) { meshCoreObj.pr = null; } } // Pending reboot
4900 }
4901 if (process.platform == 'win32') {
4902 if (require('MeshAgent')._securitycenter == null) {
@@ -4955,7 +4908,7 @@ function sendPeriodicServerUpdate(flags, force) {
4908 meshCoreObj['wsc'] = require('MeshAgent')._securitycenter; // Windows Security Central (WSC)
4909 require('MeshAgent').SendCommand({ action: 'coreinfo', wsc: require('MeshAgent')._securitycenter });
4910 });
4958 - } catch (e) { }
4911 + } catch (ex) { }
4912 }
4913 }
4914