Skip to content

Commit

Permalink
Issues
Browse files Browse the repository at this point in the history
  • Loading branch information
veniware committed Aug 19, 2024
1 parent db0e977 commit 14745e9
Show file tree
Hide file tree
Showing 15 changed files with 327 additions and 105 deletions.
1 change: 0 additions & 1 deletion Protest/Front/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,4 @@ class Backup extends List {
element.style.backgroundColor = "var(--clr-select)";
};
}

}
4 changes: 1 addition & 3 deletions Protest/Front/dhcpdiscover.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ class DhcpDiscover extends Window {
this.hexRecord = [];
this.result.textContent = "";

let server = window.location.href;
server = server.replace("https://", "");
server = server.replace("http://", "");
let server = window.location.href.replace("https://", "").replace("http://", "");
if (server.indexOf("/") > 0) server = server.substring(0, server.indexOf("/"));

this.ws = new WebSocket((KEEP.isSecure ? "wss://" : "ws://") + server + "/ws/dhcp");
Expand Down
2 changes: 1 addition & 1 deletion Protest/Front/gandalf.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Gandalf extends Window {
else if (this.thresholdRange.value < 128) strength = "Strong";
else strength = "Overkill";

thresholdValueLabel.textContent = `${this.thresholdRange.value}-bits (${strength} or bellow)`;
thresholdValueLabel.textContent = `${this.thresholdRange.value}-bits (${strength} or below)`;

if (this.entropy)
totalValueLabel.textContent = this.entropy.reduce((sum, entry)=> {
Expand Down
160 changes: 145 additions & 15 deletions Protest/Front/issues.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,48 @@
class Issues extends List {

static SEVERITY_TEXT = {
1 : "Info",
2 : "Warning",
3 : "Error",
4 : "Critical",
};

static SEVERITY_ICON = {
1 : "url(mono/info.svg)",
2 : "url(mono/warning.svg)",
3 : "url(mono/error.svg)",
4 : "url(mono/critical.svg)",
};

static SEVERITY_COLOR = {
1 : "var(--clr-dark)",
2 : "var(--clr-warning)",
3 : "var(--clr-error)",
4 : "var(--clr-critical)",
};

constructor() {
super();

this.AddCssDependencies("list.css");

const columns = ["host", "category", "issue", "last update"];
const columns = ["issue", "target", "category", "severity", "source"];
this.SetupColumns(columns);

this.columnsElements[0].style.width = "40%";

this.columnsElements[1].style.left = "40%";
this.columnsElements[1].style.width = "15%";

this.columnsElements[2].style.left = "55%";
this.columnsElements[2].style.width = "15%";

this.columnsElements[3].style.left = "70%";
this.columnsElements[3].style.width = "15%";

this.columnsElements[4].style.left = "85%";
this.columnsElements[4].style.width = "15%";

this.columnsOptions.style.display = "none";

this.SetTitle("Issues");
Expand All @@ -33,10 +69,19 @@ class Issues extends List {
super.UpdateAuthorization();
}

Close() { //overrides
super.Close();

if (this.ws != null) {
try {
this.ws.close();
}
catch (ex) {};
}
}

Connect() {
let server = window.location.href;
server = server.replace("https://", "");
server = server.replace("http://", "");
let server = window.location.href.replace("https://", "").replace("http://", "");
if (server.indexOf("/") > 0) server = server.substring(0, server.indexOf("/"));

if (this.ws != null) {
Expand All @@ -48,26 +93,42 @@ class Issues extends List {

this.ws = new WebSocket((KEEP.isSecure ? "wss://" : "ws://") + server + "/ws/issues");

this.ws.onopen = ()=> {
if (this.args.interval) {
this.ws.send(`interval=${this.args.interval}`);
}
this.ws.onopen = ()=> {};

if (this.args.select) {
this.UpdateSelected();
this.ws.onmessage = event=> {
const json = JSON.parse(event.data);
for (let i=0; i<json.length; i++) {
this.AddIssue(json[i]);
}

};

this.ws.onmessage = event=> {

this.ws.onclose = ()=> {
this.ws = null;
};

this.ws.onclose = ()=> {
this.ws.onerror = error=> {};
}

AddIssue(issue) {
const key = Date.now() + Math.random() * 1000;

const element = document.createElement("div");
element.id = key;
element.className = "list-element";
this.list.appendChild(element);

this.link.data[key] = {
key: key,
severity: {v: issue.severity},
issue : {v: issue.issue},
target : {v: issue.target},
category: {v: issue.category},
source : {v: issue.source},
isUser : {v: issue.isUser},
};

this.ws.onerror = error=> {};
this.InflateElement(element, this.link.data[key]);
this.link.length++;
}

ScanDialog(entry=null, isRunning=false) {
Expand All @@ -87,8 +148,77 @@ class Issues extends List {
innerBox.style.alignItems = "center";

okButton.onclick = async ()=> {
try {
const response = await fetch("issues/start");
if (response.status !== 200) LOADER.HttpErrorHandler(response.status);

const json = await response.json();
if (json.error) throw(json.error);

if (this.ws === null) {
this.Connect();
}
}
catch (ex) {
this.ConfirmBox(ex, true, "mono/error.svg")
}

dialog.Close();
};
}

InflateElement(element, entry) { //overrides
const icon = document.createElement("div");
icon.className = "list-element-icon";
icon.style.maskSize = "24px 24px";
icon.style.maskPosition = "center";
icon.style.maskRepeat = "no-repeat";
icon.style.maskImage = Issues.SEVERITY_ICON[entry.severity.v] ?? "url(mono/critical.svg)";
icon.style.backgroundColor = Issues.SEVERITY_COLOR[entry.severity.v] ?? "var(--clr-dark)";
icon.style.filter = "brightness(0.8)";
element.appendChild(icon);

for (let i = 0; i < this.columnsElements.length; i++) {
if (!(this.columnsElements[i].textContent in entry)) continue;
const propertyName = this.columnsElements[i].textContent;

let value;

if (propertyName === "severity") {
value = Issues.SEVERITY_TEXT[entry[this.columnsElements[i].textContent].v];
icon.style.left = this.columnsElements[i].style.left;
}
else {
value = entry[this.columnsElements[i].textContent].v
}

if (value.length === 0) continue;

const newAttr = document.createElement("div");
newAttr.textContent = value;
element.appendChild(newAttr);

if (propertyName === "severity") {
newAttr.style.left = `calc(28px + ${this.columnsElements[i].style.left})`;
newAttr.style.width = `calc(${this.columnsElements[i].style.width} - 28px)`;
}
else {
newAttr.style.left = this.columnsElements[i].style.left;
newAttr.style.width = this.columnsElements[i].style.width;
}
}

element.onclick = ()=> {
if (this.selected) this.selected.style.backgroundColor = "";

this.args.select = entry.key;

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

element.ondblclick = ()=> {

};
}
}
4 changes: 1 addition & 3 deletions Protest/Front/keepalive.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ const KEEP = {
sessionTtlMapping: { 1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:14, 9:21, 10:28, 11:60, 12:90 },

Initialize: ()=> {
let server = window.location.href;
server = server.replace("https://", "");
server = server.replace("http://", "");
let server = window.location.href.replace("https://", "").replace("http://", "");
if (server.endsWith("/")) server = server.substring(0, server.indexOf("/"));

KEEP.socket = new WebSocket((KEEP.isSecure ? "wss://" : "ws://") + server + "/ws/keepalive");
Expand Down
2 changes: 1 addition & 1 deletion Protest/Front/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ class List extends Window {
for (let i = 0; i < this.columnsElements.length; i++) {
if (!(this.columnsElements[i].textContent in entry)) continue;

let value = entry[this.columnsElements[i].textContent].v;
const value = entry[this.columnsElements[i].textContent].v;
if (value.length === 0) continue;

const newAttr = document.createElement("div");
Expand Down
4 changes: 1 addition & 3 deletions Protest/Front/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,7 @@ class Ping extends Console {
Connect() {
if (this.args.status !== "play") return;

let server = window.location.href;
server = server.replace("https://", "");
server = server.replace("http://", "");
let server = window.location.href.replace("https://", "").replace("http://", "");
if (server.indexOf("/") > 0) server = server.substring(0, server.indexOf("/"));

if (this.ws != null) {
Expand Down
4 changes: 1 addition & 3 deletions Protest/Front/portscan.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,7 @@ class PortScan extends Console {
}

Connect() {
let server = window.location.href;
server = server.replace("https://", "");
server = server.replace("http://", "");
let server = window.location.href.replace("https://", "").replace("http://", "");
if (server.indexOf("/") > 0) server = server.substring(0, server.indexOf("/"));

if (this.ws != null) {
Expand Down
4 changes: 1 addition & 3 deletions Protest/Front/reverseproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ class ReverseProxy extends List {
}

Connect() {
let server = window.location.href;
server = server.replace("https://", "");
server = server.replace("http://", "");
let server = window.location.href.replace("https://", "").replace("http://", "");
if (server.indexOf("/") > 0) server = server.substring(0, server.indexOf("/"));

if (this.ws != null) {
Expand Down
4 changes: 1 addition & 3 deletions Protest/Front/sitecheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ class SiteCheck extends Window {
}

Check() {
let server = window.location.href;
server = server.replace("https://", "");
server = server.replace("http://", "");
let server = window.location.href.replace("https://", "").replace("http://", "");
if (server.indexOf("/") > 0) server = server.substring(0, server.indexOf("/"));

this.ws = new WebSocket((KEEP.isSecure ? "wss://" : "ws://") + server + "/ws/sitecheck");
Expand Down
4 changes: 1 addition & 3 deletions Protest/Front/ssh.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ class Ssh extends Terminal {
this.statusBox.textContent = "Connecting...";
this.content.appendChild(this.statusBox);

let server = window.location.href;
server = server.replace("https://", "");
server = server.replace("http://", "");
let server = window.location.href.replace("https://", "").replace("http://", "");
if (server.indexOf("/") > 0) server = server.substring(0, server.indexOf("/"));

if (this.ws != null) {
Expand Down
4 changes: 1 addition & 3 deletions Protest/Front/telnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ class Telnet extends Terminal {
this.statusBox.textContent = "Connecting...";
this.content.appendChild(this.statusBox);

let server = window.location.href;
server = server.replace("https://", "");
server = server.replace("http://", "");
let server = window.location.href.replace("https://", "").replace("http://", "");
if (server.indexOf("/") > 0) server = server.substring(0, server.indexOf("/"));

if (this.ws != null) {
Expand Down
4 changes: 1 addition & 3 deletions Protest/Front/traceroute.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ class TraceRoute extends Console {
}

Connect() {
let server = window.location.href;
server = server.replace("https://", "");
server = server.replace("http://", "");
let server = window.location.href.replace("https://", "").replace("http://", "");
if (server.indexOf("/") > 0) server = server.substring(0, server.indexOf("/"));

if (this.ws != null) {
Expand Down
13 changes: 6 additions & 7 deletions Protest/Tools/LiveStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static async void UserStats(HttpListenerContext ctx) {
catch { }
}

if (Issues.CheckPasswordStrength(entry, out Issues.Issue? weakPsIssue)) {
if (Issues.CheckPasswordStrength(entry, true, out Issues.Issue? weakPsIssue)) {
WsWriteText(ws, weakPsIssue?.ToJsonBytes(), mutex);
}
}
Expand Down Expand Up @@ -133,14 +133,11 @@ public static async void DeviceStats(HttpListenerContext ctx) {
return;
}

string[] pingArray = Array.Empty<string>();
string firstAlive = null;
PingReply firstReply = null;

entry.attributes.TryGetValue("ip", out Database.Attribute _ip);
entry.attributes.TryGetValue("hostname", out Database.Attribute _hostname);
entry.attributes.TryGetValue("operating system", out Database.Attribute _os);

string[] pingArray = Array.Empty<string>();
if (_ip?.value?.Length > 0) {
pingArray = _ip.value.Split(';').Select(o => o.Trim()).ToArray();
}
Expand All @@ -150,6 +147,8 @@ public static async void DeviceStats(HttpListenerContext ctx) {

object mutex = new object();

string firstAlive = null;
PingReply firstReply = null;
if (pingArray.Length > 0) {
List<Task> pingTasks = new List<Task>();

Expand Down Expand Up @@ -295,7 +294,7 @@ public static async void DeviceStats(HttpListenerContext ctx) {
}
}

if (Issues.CheckPasswordStrength(entry, out Issues.Issue? weakPsIssue)) {
if (Issues.CheckPasswordStrength(entry, false, out Issues.Issue? weakPsIssue)) {
WsWriteText(ws, weakPsIssue?.ToJsonBytes(), mutex);
}
}
Expand Down Expand Up @@ -340,7 +339,7 @@ private static void WmiQuery(WebSocket ws, object mutex, string firstAlive, ref

WsWriteText(ws, $"{{\"drive\":\"{caption}\",\"total\":{nSize},\"used\":{nSize - nFree},\"path\":\"{Data.EscapeJsonText($"\\\\{firstAlive}\\{caption.Replace(":", String.Empty)}$")}\",\"source\":\"WMI\"}}", mutex);

if (Issues.CheckDiskCapacity(percent, caption, out Issues.Issue? diskIssue)) {
if (Issues.CheckDiskCapacity(firstAlive, percent, caption, out Issues.Issue? diskIssue)) {
WsWriteText(ws, diskIssue?.ToJsonBytes(), mutex);
}
}
Expand Down
Loading

0 comments on commit 14745e9

Please sign in to comment.