Skip to content

Commit

Permalink
SNMP front-end
Browse files Browse the repository at this point in the history
  • Loading branch information
veniware committed Mar 21, 2024
1 parent 52b07af commit fcc22d0
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Protest/Front/snmp.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
position: absolute;
left: 8px;
right: 40px;
max-width: 480px;
max-width: 640px;
top: 8px;
height: 122px;
display: grid;
grid-template-columns: 72px auto 80px;
grid-template-rows: 32px 32px 32px auto;
grid-template-columns: 96px auto minmax(96px, 112px) 64px 64px;
grid-template-rows: 32px 32px 32px 24px;
transition: .2s;
}

Expand Down
101 changes: 86 additions & 15 deletions Protest/Front/snmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,64 @@ class Snmp extends Window {
this.targetInput = document.createElement("input");
this.targetInput.type = "text";
this.targetInput.placeholder = "hostname or ip";
this.targetInput.style.gridArea = "1 / 2";
this.targetInput.style.gridArea = "1 / 2 / 1 / 4";
if (this.params.target != null) this.targetInput.value = this.params.target;
snmpInput.appendChild(this.targetInput);

const authLabel = document.createElement("div");
authLabel.style.lineHeight = "28px";
authLabel.style.gridArea = "2 / 1";
authLabel.textContent = "Community:";
snmpInput.appendChild(authLabel);

this.authInput = document.createElement("input");
this.authInput.type = "text";
this.authInput.placeholder = "public";
this.authInput.style.gridArea = "2 / 2";
this.authInput.style.marginRight = "0";
snmpInput.appendChild(this.authInput);

this.versionInput = document.createElement("select");
this.versionInput.style.gridArea = "2 / 3";
if (this.params.oid !== null) this.versionInput.value = this.params.oid;
snmpInput.appendChild(this.versionInput);

const versionOptions = [1, 2, 3];
for (let i=0; i<versionOptions.length; i++) {
const option = document.createElement("option");
option.value = versionOptions[i];
option.textContent = `Version ${versionOptions[i]}`;
this.versionInput.appendChild(option);
}

const oidLabel = document.createElement("div");
oidLabel.style.lineHeight = "28px";
oidLabel.style.gridArea = "2 / 1";
oidLabel.style.gridArea = "3 / 1";
oidLabel.textContent = "OID:";
snmpInput.appendChild(oidLabel);

this.oidInput = document.createElement("input");
this.oidInput.type = "text";
this.oidInput.style.gridArea = "2 / 2";
if (this.params.oid != null) this.oidInput.value = this.params.oid;
this.oidInput = document.createElement("textarea");
this.oidInput.placeholder = "1.3.6.1.2.1.1.5.0";
this.oidInput.style.gridArea = "3 / 2 / 5 / 4";
this.oidInput.style.resize = "none";
if (this.params.oid !== null) this.oidInput.value = this.params.oid;
snmpInput.appendChild(this.oidInput);

this.executeButton = document.createElement("input");
this.executeButton.type = "button";
this.executeButton.value = "Execute";
this.executeButton.style.height = "auto";
this.executeButton.style.gridArea = "1 / 3 / 3 / 3";
snmpInput.appendChild(this.executeButton);
this.getButton = document.createElement("input");
this.getButton.type = "button";
this.getButton.value = "Get";
this.getButton.style.width = this.getButton.style.minWidth = "58px";
this.getButton.style.height = "auto";
this.getButton.style.gridArea = "3 / 4 / 5 / 4";
snmpInput.appendChild(this.getButton);

this.setButton = document.createElement("input");
this.setButton.type = "button";
this.setButton.value = "Set";
this.setButton.style.width = this.setButton.style.minWidth = "58px";
this.setButton.style.height = "auto";
this.setButton.style.gridArea = "3 / 5 / 5 / 5";
snmpInput.appendChild(this.setButton);

const toggleButton = document.createElement("input");
toggleButton.type = "button";
Expand All @@ -59,7 +95,8 @@ class Snmp extends Window {
this.targetInput.oninput = ()=> { this.params.target = this.targetInput.value };
this.oidInput.oninput = ()=> { this.params.oid = this.oidInput.value };

this.executeButton.onclick = ()=> this.Query();
this.getButton.onclick = ()=> { this.GetQuery() };
this.setButton.onclick = ()=> { this.SetQuery() };

toggleButton.onclick = ()=> {
if (snmpInput.style.visibility === "hidden") {
Expand All @@ -81,12 +118,46 @@ class Snmp extends Window {
};

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

async Query() {
async GetQuery() {
if (this.targetInput.value.length == 0 || this.oidInput.value.length == 0) {
this.ConfirmBox("Incomplete query.", true);
return;
}

//TODO:
}

async SetQuery() {
const dialog = this.DialogBox("108px");
if (dialog === null) return;

dialog.innerBox.parentElement.style.maxWidth = "400px";
dialog.innerBox.style.textAlign = "center";

const valueInput = document.createElement("input");
valueInput.type = "text";
valueInput.placeholder = "value";
valueInput.style.marginTop = "20px";
valueInput.style.width = "min(calc(100% - 8px), 200px)";
dialog.innerBox.appendChild(valueInput);

valueInput.focus();
valueInput.select();

dialog.okButton.onclick = ()=> {
dialog.cancelButton.onclick();
//TODO:
};

valueInput.onkeydown = event=> {
if (event.key === "Enter") {
dialog.okButton.click();
}
}
}
}
2 changes: 1 addition & 1 deletion Protest/Front/wmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Wmi extends Window {
wmiInput.appendChild(queryLabel);

this.queryInput = document.createElement("textarea");
this.queryInput.placeholder = "e.g.: SELECT * FROM Win32_BIOS WHERE Status = \"OK\"";
this.queryInput.placeholder = "SELECT * FROM Win32_BIOS WHERE Status = \"OK\"";
this.queryInput.style.gridArea = "2 / 2 / 2 span / auto";
//this.queryInput.style.fontFamily = "monospace";
this.queryInput.style.resize = "none";
Expand Down
2 changes: 1 addition & 1 deletion Protest/Protocols/Snmp.Polling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal static class Polling {
public const string SYSTEM_LOCATION = "1.3.6.1.2.1.1.6.0";
public const string SYSTEM_SERVICES = "1.3.6.1.2.1.1.7.0";

public const string TOTAL_INTERFACES = "1.3.6.1.2.1.2.1.0";
public const string INTERFACE_TOTAL = "1.3.6.1.2.1.2.1.0";
public const string INTERFACE_DESCRIPTOR = "1.3.6.1.2.1.2.2.1.2.i";
public const string INTERFACE_SPEED = "1.3.6.1.2.1.2.2.1.5.i";
public const string INTERFACE_STATUS = "1.3.6.1.2.1.2.2.1.8.i";
Expand Down

0 comments on commit fcc22d0

Please sign in to comment.