add extra services information

Signed-off-by: si458 <simonsmith5521@gmail.com>

Simon Smith committed Jan 24, 2024 at 11:51 UTC b1451a1c8a18ea8d0f0f853b04bda24d7c9b1fd3
2 files changed +88 -23
agents/meshcore.js
+35
@@ -1304,6 +1304,41 @@ function handleServerCommand(data) {
1304 }
1305 break;
1306 }
1307 + case 'service': {
1308 + // return information about the service
1309 + try {
1310 + var service = require('service-manager').manager.getService(data.serviceName);
1311 + if (service != null) {
1312 + var reply = {
1313 + name: (service.name ? service.name : ''),
1314 + status: (service.status ? service.status : ''),
1315 + startType: (service.startType ? service.startType : ''),
1316 + failureActions: (service.failureActions ? service.failureActions : ''),
1317 + installedDate: (service.installedDate ? service.installedDate : ''),
1318 + installedBy: (service.installedBy ? service.installedBy : '') ,
1319 + user: (service.user ? service.user : '')
1320 + };
1321 + if(reply.installedBy.indexOf('S-1-5') != -1) {
1322 + var cmd = "(Get-WmiObject -Class win32_userAccount -Filter \"SID='"+service.installedBy+"'\").Caption";
1323 + var replydata = "";
1324 + var pws = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], {});
1325 + pws.descriptorMetadata = 'UserSIDPowerShell';
1326 + pws.stdout.on('data', function (c) { replydata += c.toString(); });
1327 + pws.stderr.on('data', function (c) { replydata += c.toString(); });
1328 + pws.stdin.write(cmd + '\r\nexit\r\n');
1329 + pws.on('exit', function () {
1330 + if (replydata != "") reply.installedBy = replydata;
1331 + mesh.SendCommand({ action: 'msg', type: 'service', value: JSON.stringify(reply), sessionid: data.sessionid });
1332 + delete pws;
1333 + });
1334 + } else {
1335 + mesh.SendCommand({ action: 'msg', type: 'service', value: JSON.stringify(reply), sessionid: data.sessionid });
1336 + }
1337 + }
1338 + } catch (ex) {
1339 + mesh.SendCommand({ action: 'msg', type: 'service', error: ex, sessionid: data.sessionid })
1340 + }
1341 + }
1342 case 'services': {
1343 // Return the list of installed services
1344 var services = null;
views/default.handlebars
+53 -23
@@ -2616,6 +2616,8 @@
2616 showDeskToolsProcesses(message);
2617 } else if (message.type === 'services') {
2618 showDeskToolsServices(message);
2619 + } else if (message.type === 'service') {
2620 + showServiceDetailsDialog(message);
2621 } else if ((message.type === 'getclip') && (currentNode != null) && (currentNode._id == message.nodeid)) {
2622 if ((message.tag == 1) && (xxdialogTag === 'clipboard')) {
2623 Q('d2clipText').value = message.data; // Put remote clipboard data into dialog box
@@ -10154,7 +10156,7 @@
10156 }
10157 function showProcessDetails(pid) {
10158 if (xxdialogMode) return;
10157 - setDialogMode(2, format("Process Details, #{0}", pid), 1, null, "Requesting details...", 'ps|' + currentNode._id + '|' + pid);
10159 + setDialogMode(2, format("Process Details, #{0}", pid), 1, null, "Requesting Process Details...", 'ps|' + currentNode._id + '|' + pid);
10160 meshserver.send({ action: 'msg', type: 'psinfo', nodeid: currentNode._id, pid: pid });
10161 }
10162 function showDeskToolsServices(message) {
@@ -10182,7 +10184,7 @@
10184 var c = s[i].d, ss = s[i].p;
10185 if (ss == 'Stopped') { ss = "Stopped"; } // TODO: Add all other states for translation
10186 else if (ss == 'Running') { ss = "Running"; }
10185 - x += '<div onclick=showServiceDetailsDialog(' + s[i].i + ') class=deskToolsBar>';
10187 + x += '<div onclick=showServiceWaitDialog(' + s[i].i + ') class=deskToolsBar>';
10188 x += '<div style=width:70px;float:left;padding-right:5px>' + EscapeHtml(ss) + '</div>';
10189 x += '<div style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis" title="' + c + '">' + EscapeHtml(c) + '</div>';
10190 x += '</div>';
@@ -10192,30 +10194,58 @@
10194 }
10195 }
10196
10195 - function showServiceDetailsDialog(index) {
10196 - if (xxdialogMode) return;
10197 + function showServiceDetailsDialog(data) {
10198 + if (xxdialogMode && (xxdialogTag.indexOf('service_') != -1)) {
10199 + var index = xxdialogTag.replace('service_','')
10200 + // var org_service = deskTools.services[index];
10201 + var service = data.value ? JSON.parse(data.value) : deskTools.services[index];
10202 + if(data.value) service.displayName = deskTools.services[index].displayName;
10203 + if (service != null) {
10204 + var x = '';
10205 + if (service.name) { x += addHtmlValue("Name", service.name); }
10206 + if (service.displayName) { x += addHtmlValue("Display name", service.displayName); }
10207 + if (service.status) {
10208 + var ss = capitalizeFirstLetter(service.status.state.toLowerCase());
10209 + if (ss == 'Stopped') { ss = "Stopped"; } // TODO: Add all other states for translation
10210 + else if (ss == 'Running') { ss = "Running"; }
10211 + if (service.status.state) { x += addHtmlValue("State", ss); }
10212 + if (service.status.pid) { x += addHtmlValue("PID", service.status.pid); }
10213 + var serviceTypes = [];
10214 + if (service.status.isFileSystemDriver === true) { serviceTypes.push("FileSystemDriver"); }
10215 + if (service.status.isInteractive === true) { serviceTypes.push("Interactive"); }
10216 + if (service.status.isKernelDriver === true) { serviceTypes.push("KernelDriver"); }
10217 + if (service.status.isOwnProcess === true) { serviceTypes.push("OwnProcess"); }
10218 + if (service.status.isSharedProcess === true) { serviceTypes.push("SharedProcess"); }
10219 + if (serviceTypes.length > 0) { x += addHtmlValue("Type", serviceTypes.join(', ')); }
10220 + }
10221 + if (service.startType) { x += addHtmlValue("Start Type", service.startType); }
10222 + if (service.user) { x += addHtmlValue("User", service.user); }
10223 + if (service.installedBy) { x += addHtmlValue("Installed By", service.installedBy); }
10224 + if (service.installedDate) { x += addHtmlValue("Installed Date", printDateTime(new Date(service.installedDate))); }
10225 + if (service.failureActions) {
10226 + if (service.failureActions.resetPeriod) {
10227 + var abc = ((service.failureActions.resetPeriod < 86400 ? 0 : service.failureActions.resetPeriod) / (24 * 60 * 60));
10228 + x += addHtmlValue("Restart Fail Count After ", abc + ' Day' + (abc != 1 ? 's': '')); }
10229 + if (service.failureActions.actions) {
10230 + if (service.failureActions.actions[0]) { x += addHtmlValue("First Failure",service.failureActions.actions[0].type); }
10231 + if (service.failureActions.actions[1]) { x += addHtmlValue("Second Failure",service.failureActions.actions[1].type); }
10232 + if (service.failureActions.actions[2]) { x += addHtmlValue("Subsequent Failures",service.failureActions.actions[2].type); }
10233 + }
10234 + }
10235 + x += '<br/><div style=float:right;margin-bottom:12px><input type=button value="' + "Close" + '" onclick=showServiceDetailsDialogEx(0,' + index + ')></div><div style=margin-bottom:12px><input type=button value="' + "Start" + '" onclick=showServiceDetailsDialogEx(1,' + index + ')><input type=button value="' + "Stop" + '" onclick=showServiceDetailsDialogEx(2,' + index + ')><input type=button value="' + "Restart" + '" onclick=showServiceDetailsDialogEx(3,' + index + ')></div>';
10236 + setDialogMode(2, "Service Details", 8, null, x, "service_"+index);
10237 + }
10238 + }
10239 + }
10240 +
10241 + function showServiceWaitDialog(index) {
10242 + if (xxdialogMode) return false;
10243 var service = deskTools.services[index];
10244 if (service != null) {
10199 - var x = '';
10200 - if (service.name) { x += addHtmlValue("Name", service.name); }
10201 - if (service.displayName) { x += addHtmlValue("Display name", service.displayName); }
10202 - if (service.status) {
10203 - var ss = capitalizeFirstLetter(service.status.state.toLowerCase());
10204 - if (ss == 'Stopped') { ss = "Stopped"; } // TODO: Add all other states for translation
10205 - else if (ss == 'Running') { ss = "Running"; }
10206 - if (service.status.state) { x += addHtmlValue("State", ss); }
10207 - if (service.status.pid) { x += addHtmlValue("PID", service.status.pid); }
10208 - var serviceTypes = [];
10209 - if (service.status.isFileSystemDriver === true) { serviceTypes.push("FileSystemDriver"); }
10210 - if (service.status.isInteractive === true) { serviceTypes.push("Interactive"); }
10211 - if (service.status.isKernelDriver === true) { serviceTypes.push("KernelDriver"); }
10212 - if (service.status.isOwnProcess === true) { serviceTypes.push("OwnProcess"); }
10213 - if (service.status.isSharedProcess === true) { serviceTypes.push("SharedProcess"); }
10214 - if (serviceTypes.length > 0) { x += addHtmlValue("Type", serviceTypes.join(', ')); }
10215 - }
10216 - x += '<br/><div style=float:right;margin-bottom:12px><input type=button value="' + "Close" + '" onclick=showServiceDetailsDialogEx(0,' + index + ')></div><div style=margin-bottom:12px><input type=button value="' + "Start" + '" onclick=showServiceDetailsDialogEx(1,' + index + ')><input type=button value="' + "Stop" + '" onclick=showServiceDetailsDialogEx(2,' + index + ')><input type=button value="' + "Restart" + '" onclick=showServiceDetailsDialogEx(3,' + index + ')></div>';
10217 - setDialogMode(2, "Service Details", 8, null, x, name);
10245 + meshserver.send({ action: 'msg', type: 'service', nodeid: currentNode._id, serviceName: service.name });
10246 + setDialogMode(2, "Service Details", 1, null, "Requesting Service Details...", "service_" + index);
10247 }
10248 + return false;
10249 }
10250
10251 function showServiceDetailsDialogEx(action, index) {