Skip to content

Commit

Permalink
WMI helper
Browse files Browse the repository at this point in the history
  • Loading branch information
veniware committed Mar 22, 2024
1 parent 195d94e commit 9e76044
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 69 deletions.
4 changes: 2 additions & 2 deletions Protest/Front/deviceview.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class DeviceView extends View {

const processesButton = this.CreateSideButton("mono/console.svg", "Processes");
processesButton.onclick = ()=> {
const wmi = new Wmi({target:host, query:"SELECT CreationDate, ExecutablePath, Name, ProcessId \nFROM Win32_Process"});
const wmi = new Wmi({target:host, query:"SELECT CreationDate, ExecutablePath, Name, ProcessId \nFROM Win32_Process", hideInput:true});
wmi.SetIcon("mono/console.svg");
if (!this.link.name || this.link.name.v.length == 0) {
wmi.SetTitle("[untitled] - Processes");
Expand All @@ -304,7 +304,7 @@ class DeviceView extends View {

const servicesButton = this.CreateSideButton("mono/service.svg", "Services");
servicesButton.onclick = ()=> {
const wmi = new Wmi({target: host, query:"SELECT DisplayName, Name, ProcessId, State \nFROM Win32_Service"});
const wmi = new Wmi({target: host, query:"SELECT DisplayName, Name, ProcessId, State \nFROM Win32_Service", hideInput:true});
wmi.SetIcon("mono/service.svg");
if (!this.link.name || this.link.name.v.length==0) {
wmi.SetTitle("[untitled] - Processes");
Expand Down
21 changes: 10 additions & 11 deletions Protest/Front/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ class Monitor extends Window {
classFilterInput.type = "text";
classFilterInput.placeholder = "Find..";
classFilterInput.style.gridArea = "1 / 1";

innerBox.append(classFilterInput);

const classesList = document.createElement("div");
Expand Down Expand Up @@ -896,10 +896,10 @@ class Monitor extends Window {
let className = null;
if (wmiClasses.classes) {
for (let i=0; i<words.length; i++) {
if (words[i].toUpperCase() === "FROM" && i !== words.length-1) {
className = words[i+1].toLowerCase();
break;
}
words[i] = words[i].trim().toUpperCase();
if (words[i] !== "FROM" || i === words.length-1) continue;
className = words[i+1].toLowerCase();
break;
}
}

Expand Down Expand Up @@ -934,15 +934,15 @@ class Monitor extends Window {
};

let selected = null;
let properties = [];
let propertyCheckboxes = [];

const ListProperties = classObject=> {
let properties = [];
let propertyCheckboxes = [];
properties = [];
propertyCheckboxes = [];

for (let j = 0; j < classObject.properties.length; j++) {

let value = lastProperties === "*" || className == null ||
className.toLowerCase() === classObject.class.toLowerCase() && lastPropertiesArray.includes(classObject.properties[j].toLowerCase());
let value = className && className.toLowerCase() === classObject.class.toLowerCase() && lastPropertiesArray.includes(classObject.properties[j].toLowerCase());

const propertyBox = document.createElement("div");
const propertyCheckbox = document.createElement("input");
Expand Down Expand Up @@ -981,7 +981,6 @@ class Monitor extends Window {
else {
query = `SELECT ${selectedList.join(", ")} FROM ${classObject.class}`;
}

queryInput.value = query;
};

Expand Down
7 changes: 6 additions & 1 deletion Protest/Front/snmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Snmp extends Window {

this.AddCssDependencies("snmp.css");

this.params = params ?? { target: "", oid: "" };
this.params = params ?? { target: "", community:"", oid: "" };

this.SetTitle("SNMP pooling");
this.SetIcon("mono/snmp.svg");
Expand Down Expand Up @@ -135,6 +135,7 @@ class Snmp extends Window {
snmpInput.style.opacity = "1";
snmpInput.style.transform = "none";
this.plotBox.style.top = "136px";
this.params.hideInput = false;
}
else {
toggleButton.style.top = "0px";
Expand All @@ -143,11 +144,15 @@ class Snmp extends Window {
snmpInput.style.opacity = "0";
snmpInput.style.transform = "translateY(-64px)";
this.plotBox.style.top = "36px";
this.params.hideInput = true;
}
};

if (this.params.target.length > 0 && this.params.oid.length > 0) {
this.getButton.onclick();
}

if (this.params.hideInput) {
toggleButton.onclick();
}
}
Expand Down
129 changes: 74 additions & 55 deletions Protest/Front/wmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Wmi extends Window {
wmiInput.style.opacity = "1";
wmiInput.style.transform = "none";
this.plotBox.style.top = "136px";
this.params.hideInput = false;
}
else {
toggleButton.style.top = "0px";
Expand All @@ -89,11 +90,16 @@ class Wmi extends Window {
wmiInput.style.opacity = "0";
wmiInput.style.transform = "translateY(-64px)";
this.plotBox.style.top = "36px";
this.params.hideInput = true;
}
};


if (this.params.target.length > 0 && this.params.query.length > 0) {
this.executeButton.onclick();
}

if (this.params.hideInput) {
toggleButton.onclick();
}
}
Expand All @@ -119,12 +125,13 @@ class Wmi extends Window {

let words = lastQuery.split(" ");
let className = null;

if (this.wmiClasses.classes) {
for (let i = 0; i < words.length; i++) {
if (words[i].toUpperCase() === "FROM" && i !== words.length-1) {
className = words[i+1].toLowerCase();
break;
}
words[i] = words[i].trim().toUpperCase();
if (words[i] !== "FROM" || i === words.length-1) continue;
className = words[i+1].toLowerCase();
break;
}
}

Expand Down Expand Up @@ -216,6 +223,51 @@ class Wmi extends Window {
let properties = [];
let propertyCheckboxes = [];

const ListProperties = classObject=> {
properties = [];
propertyCheckboxes = [];

for (let j = 0; j < classObject.properties.length; j++) {

let value = lastProperties === "*" || className == null ||
className.toLowerCase() === classObject.class.toLowerCase() && lastPropertiesArray.includes(classObject.properties[j].toLowerCase());

const propertyBox = document.createElement("div");
const propertyCheckbox = document.createElement("input");
propertyCheckbox.type = "checkbox";
propertyCheckbox.checked = value;
propertyCheckboxes.push(propertyCheckbox);
propertyBox.appendChild(propertyCheckbox);

properties.push(value);

this.AddCheckBoxLabel(propertyBox, propertyCheckbox, classObject.properties[j]);
propertiesList.appendChild(propertyBox);
}

const OnCheckedChange = ()=> {
let selectedList = [];
for (let j=0; j<classObject.properties.length; j++) {
if (propertyCheckboxes[j].checked) {
selectedList.push(classObject.properties[j]);
}
}

let query;
if (selectedList.length === 0 || selectedList.length === classObject.properties.length) {
query = `SELECT * FROM ${classObject.class}`;
}
else {
query = `SELECT ${selectedList.join(", ")} FROM ${classObject.class}`;
}
previewInput.value = query;
};

for (let j=0; j<propertyCheckboxes.length; j++) {
propertyCheckboxes[j].onchange = OnCheckedChange;
}
};

classFilterInput.oninput = ()=> {
if (!this.wmiClasses.classes) return;
let filter = classFilterInput.value.toLowerCase();
Expand Down Expand Up @@ -243,63 +295,28 @@ class Wmi extends Window {
newClass.textContent = this.wmiClasses.classes[i].class;
classesList.appendChild(newClass);

newClass.onclick = ()=> {
newClass.onclick = event=> {
if (selected != null) selected.style.backgroundColor = "";

properties = [];
propertyCheckboxes = [];

propertiesList.textContent = "";

for (let j = 0; j < this.wmiClasses.classes[i].properties.length; j++) {
let value = lastProperties === "*" || className == null ||
className.toLowerCase() === this.wmiClasses.classes[i].class.toLowerCase() &&
lastPropertiesArray.includes(this.wmiClasses.classes[i].properties[j].toLowerCase());

const propertyBox = document.createElement("div");
const propertyCheckbox = document.createElement("input");
propertyCheckbox.type = "checkbox";
propertyCheckbox.checked = value;
propertyCheckboxes.push(propertyCheckbox);
propertyBox.appendChild(propertyCheckbox);

properties.push(value);

propertyCheckbox.onchange = ()=> {
properties[j] = propertyCheckbox.checked;

let count = 0;
for (let k = 0; k < properties.length; k++) {
if (properties[k])
count++;
}
ListProperties(this.wmiClasses.classes[i]);

if (count === 0 || count === properties.length) {
previewInput.value = "SELECT * FROM " + this.wmiClasses.classes[i].class;
}
else {
let sel = "";
for (let k = 0; k < properties.length; k++)
if (properties[k])
sel += (sel.length == 0) ? this.wmiClasses.classes[i].properties[k] : ", " + this.wmiClasses.classes[i].properties[k];

previewInput.value = "SELECT " + sel + " FROM " + this.wmiClasses.classes[i].class;
}
};
selected = newClass;
selected.style.backgroundColor = "var(--clr-select)";

this.AddCheckBoxLabel(propertyBox, propertyCheckbox, this.wmiClasses.classes[i].properties[j]);
propertiesList.appendChild(propertyBox);

if (filter && this.wmiClasses.classes[i].properties[j].toLowerCase().indexOf(filter) > -1) {
propertyBox.scrollIntoView({ behavior: "smooth"});
setTimeout(()=>{propertyBox.style.animation = "highlight .8s 1"}, 500);
let selectedList = [];
for (let j=0; j<this.wmiClasses.classes[i].properties.length; j++) {
if (propertyCheckboxes[j].checked) {
selectedList.push(this.wmiClasses.classes[i].properties[j]);
}

selected = newClass;
selected.style.backgroundColor = "var(--clr-select)";
}

previewInput.value = "SELECT * FROM " + this.wmiClasses.classes[i].class;
if (selectedList.length === 0 || selectedList.length === this.wmiClasses.classes[i].properties.length) {
previewInput.value = `SELECT * FROM ${this.wmiClasses.classes[i].class}`;
} else {
previewInput.value = `SELECT ${selectedList.join(", ")} FROM ${this.wmiClasses.classes[i].class}`;
}
};

newClass.ondblclick = ()=> {
Expand All @@ -308,9 +325,11 @@ class Wmi extends Window {
};

if (className && className === this.wmiClasses.classes[i].class.toLowerCase()) {
newClass.onclick();
newClass.scrollIntoView();
className = null;
newClass.scrollIntoView({ behavior: "smooth"});

selected = newClass;
selected.style.backgroundColor = "var(--clr-select)";
selected.onclick();
}
}
}
Expand Down

0 comments on commit 9e76044

Please sign in to comment.