add extra services information

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
Simon Smith 2024-01-24 11:51:28 +00:00 committed by GitHub
parent b860981925
commit b1451a1c8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 88 additions and 23 deletions

View File

@ -1304,6 +1304,41 @@ function handleServerCommand(data) {
}
break;
}
case 'service': {
// return information about the service
try {
var service = require('service-manager').manager.getService(data.serviceName);
if (service != null) {
var reply = {
name: (service.name ? service.name : ''),
status: (service.status ? service.status : ''),
startType: (service.startType ? service.startType : ''),
failureActions: (service.failureActions ? service.failureActions : ''),
installedDate: (service.installedDate ? service.installedDate : ''),
installedBy: (service.installedBy ? service.installedBy : '') ,
user: (service.user ? service.user : '')
};
if(reply.installedBy.indexOf('S-1-5') != -1) {
var cmd = "(Get-WmiObject -Class win32_userAccount -Filter \"SID='"+service.installedBy+"'\").Caption";
var replydata = "";
var pws = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], {});
pws.descriptorMetadata = 'UserSIDPowerShell';
pws.stdout.on('data', function (c) { replydata += c.toString(); });
pws.stderr.on('data', function (c) { replydata += c.toString(); });
pws.stdin.write(cmd + '\r\nexit\r\n');
pws.on('exit', function () {
if (replydata != "") reply.installedBy = replydata;
mesh.SendCommand({ action: 'msg', type: 'service', value: JSON.stringify(reply), sessionid: data.sessionid });
delete pws;
});
} else {
mesh.SendCommand({ action: 'msg', type: 'service', value: JSON.stringify(reply), sessionid: data.sessionid });
}
}
} catch (ex) {
mesh.SendCommand({ action: 'msg', type: 'service', error: ex, sessionid: data.sessionid })
}
}
case 'services': {
// Return the list of installed services
var services = null;

View File

@ -2616,6 +2616,8 @@
showDeskToolsProcesses(message);
} else if (message.type === 'services') {
showDeskToolsServices(message);
} else if (message.type === 'service') {
showServiceDetailsDialog(message);
} else if ((message.type === 'getclip') && (currentNode != null) && (currentNode._id == message.nodeid)) {
if ((message.tag == 1) && (xxdialogTag === 'clipboard')) {
Q('d2clipText').value = message.data; // Put remote clipboard data into dialog box
@ -10154,7 +10156,7 @@
}
function showProcessDetails(pid) {
if (xxdialogMode) return;
setDialogMode(2, format("Process Details, #{0}", pid), 1, null, "Requesting details...", 'ps|' + currentNode._id + '|' + pid);
setDialogMode(2, format("Process Details, #{0}", pid), 1, null, "Requesting Process Details...", 'ps|' + currentNode._id + '|' + pid);
meshserver.send({ action: 'msg', type: 'psinfo', nodeid: currentNode._id, pid: pid });
}
function showDeskToolsServices(message) {
@ -10182,7 +10184,7 @@
var c = s[i].d, ss = s[i].p;
if (ss == 'Stopped') { ss = "Stopped"; } // TODO: Add all other states for translation
else if (ss == 'Running') { ss = "Running"; }
x += '<div onclick=showServiceDetailsDialog(' + s[i].i + ') class=deskToolsBar>';
x += '<div onclick=showServiceWaitDialog(' + s[i].i + ') class=deskToolsBar>';
x += '<div style=width:70px;float:left;padding-right:5px>' + EscapeHtml(ss) + '</div>';
x += '<div style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis" title="' + c + '">' + EscapeHtml(c) + '</div>';
x += '</div>';
@ -10192,30 +10194,58 @@
}
}
function showServiceDetailsDialog(index) {
if (xxdialogMode) return;
function showServiceDetailsDialog(data) {
if (xxdialogMode && (xxdialogTag.indexOf('service_') != -1)) {
var index = xxdialogTag.replace('service_','')
// var org_service = deskTools.services[index];
var service = data.value ? JSON.parse(data.value) : deskTools.services[index];
if(data.value) service.displayName = deskTools.services[index].displayName;
if (service != null) {
var x = '';
if (service.name) { x += addHtmlValue("Name", service.name); }
if (service.displayName) { x += addHtmlValue("Display name", service.displayName); }
if (service.status) {
var ss = capitalizeFirstLetter(service.status.state.toLowerCase());
if (ss == 'Stopped') { ss = "Stopped"; } // TODO: Add all other states for translation
else if (ss == 'Running') { ss = "Running"; }
if (service.status.state) { x += addHtmlValue("State", ss); }
if (service.status.pid) { x += addHtmlValue("PID", service.status.pid); }
var serviceTypes = [];
if (service.status.isFileSystemDriver === true) { serviceTypes.push("FileSystemDriver"); }
if (service.status.isInteractive === true) { serviceTypes.push("Interactive"); }
if (service.status.isKernelDriver === true) { serviceTypes.push("KernelDriver"); }
if (service.status.isOwnProcess === true) { serviceTypes.push("OwnProcess"); }
if (service.status.isSharedProcess === true) { serviceTypes.push("SharedProcess"); }
if (serviceTypes.length > 0) { x += addHtmlValue("Type", serviceTypes.join(', ')); }
}
if (service.startType) { x += addHtmlValue("Start Type", service.startType); }
if (service.user) { x += addHtmlValue("User", service.user); }
if (service.installedBy) { x += addHtmlValue("Installed By", service.installedBy); }
if (service.installedDate) { x += addHtmlValue("Installed Date", printDateTime(new Date(service.installedDate))); }
if (service.failureActions) {
if (service.failureActions.resetPeriod) {
var abc = ((service.failureActions.resetPeriod < 86400 ? 0 : service.failureActions.resetPeriod) / (24 * 60 * 60));
x += addHtmlValue("Restart Fail Count After ", abc + ' Day' + (abc != 1 ? 's': '')); }
if (service.failureActions.actions) {
if (service.failureActions.actions[0]) { x += addHtmlValue("First Failure",service.failureActions.actions[0].type); }
if (service.failureActions.actions[1]) { x += addHtmlValue("Second Failure",service.failureActions.actions[1].type); }
if (service.failureActions.actions[2]) { x += addHtmlValue("Subsequent Failures",service.failureActions.actions[2].type); }
}
}
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>';
setDialogMode(2, "Service Details", 8, null, x, "service_"+index);
}
}
}
function showServiceWaitDialog(index) {
if (xxdialogMode) return false;
var service = deskTools.services[index];
if (service != null) {
var x = '';
if (service.name) { x += addHtmlValue("Name", service.name); }
if (service.displayName) { x += addHtmlValue("Display name", service.displayName); }
if (service.status) {
var ss = capitalizeFirstLetter(service.status.state.toLowerCase());
if (ss == 'Stopped') { ss = "Stopped"; } // TODO: Add all other states for translation
else if (ss == 'Running') { ss = "Running"; }
if (service.status.state) { x += addHtmlValue("State", ss); }
if (service.status.pid) { x += addHtmlValue("PID", service.status.pid); }
var serviceTypes = [];
if (service.status.isFileSystemDriver === true) { serviceTypes.push("FileSystemDriver"); }
if (service.status.isInteractive === true) { serviceTypes.push("Interactive"); }
if (service.status.isKernelDriver === true) { serviceTypes.push("KernelDriver"); }
if (service.status.isOwnProcess === true) { serviceTypes.push("OwnProcess"); }
if (service.status.isSharedProcess === true) { serviceTypes.push("SharedProcess"); }
if (serviceTypes.length > 0) { x += addHtmlValue("Type", serviceTypes.join(', ')); }
}
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>';
setDialogMode(2, "Service Details", 8, null, x, name);
meshserver.send({ action: 'msg', type: 'service', nodeid: currentNode._id, serviceName: service.name });
setDialogMode(2, "Service Details", 1, null, "Requesting Service Details...", "service_" + index);
}
return false;
}
function showServiceDetailsDialogEx(action, index) {