diff --git a/Protest/Front/about.js b/Protest/Front/about.js index a4e09cfe..5ce1cd62 100644 --- a/Protest/Front/about.js +++ b/Protest/Front/about.js @@ -162,7 +162,7 @@ class About extends Tabs { center.appendChild(document.createElement("br")); const icons = ["mono/logo.svg", "mono/copyleft.svg", "mono/opensource.svg","mono/gpl.svg"]; - for (let i = 0; i < icons.length; i++) { + for (let i=0; i -1) { @@ -706,6 +706,15 @@ class Monitor extends Window { canvas.height = height; inner.appendChild(canvas); + const dot = document.createElement("div"); + dot.style.position = "absolute"; + dot.style.right = "192px"; + dot.style.top = "10px"; + dot.style.width = "9px"; + dot.style.height = "9px"; + dot.style.borderRadius = "5px"; + inner.parentElement.appendChild(dot); + let min = Number.MAX_SAFE_INTEGER; let max = Number.MIN_SAFE_INTEGER; const list = []; @@ -768,6 +777,12 @@ class Monitor extends Window { } DrawGraph(); + + dot.style.backgroundColor = (list[list.length-1] < 0) ? "rgb(240,16,16)" : UI.PingColor(list[list.length-1]); + dot.style.boxShadow = `${dot.style.backgroundColor} 0 0 2px`; + + dot.style.animation = ""; + setTimeout(()=>{ dot.style.animation = "heart-beat .1s ease-out 1"; }, 0); }; return { diff --git a/Protest/Front/window.css b/Protest/Front/window.css index b2e51a20..53e2cc33 100644 --- a/Protest/Front/window.css +++ b/Protest/Front/window.css @@ -582,6 +582,11 @@ 100% { opacity: 1; } } +@keyframes heart-beat { + 0% { transform: none; } + 100% { transform: scale(1.2); } +} + @keyframes highlight { 0% { background: radial-gradient(circle, var(--clr-accent) 0%, transparent 100%); diff --git a/Protest/Program.cs b/Protest/Program.cs index cfe302a7..8379ec50 100644 --- a/Protest/Program.cs +++ b/Protest/Program.cs @@ -25,13 +25,6 @@ internal class Program { internal static readonly string[] alternativeUriPrefixes = new string[] { "http://127.0.0.1:8080/" }; static void Main(string[] args) { - - var res = Arp.ArpRequest("192.168.169.38"); - Console.WriteLine("result for 192.168.169.38: " + res); - - res = Arp.ArpRequest("192.168.19.1"); - Console.WriteLine("result for 192.168.19.1: " + res); - Console.Title = "Pro-test"; Console.WriteLine(@" _____"); diff --git a/Protest/Protocols/Arp.cs b/Protest/Protocols/Arp.cs index 0b991073..1b89ffc8 100644 --- a/Protest/Protocols/Arp.cs +++ b/Protest/Protocols/Arp.cs @@ -8,9 +8,11 @@ namespace Protest.Protocols; internal static partial class Arp { +#pragma warning disable SYSLIB1092 [SupportedOSPlatform("windows")] [LibraryImport("iphlpapi.dll")] private static partial int SendARP(uint destIP, uint srcIP, byte[] macAddr, ref int macAddrLen); +#pragma warning restore SYSLIB1092 [GeneratedRegex("^((?:[0-9]{1,3}\\.){3}[0-9]{1,3})(?:\\s+\\w+){2}\\s+((?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2}))")] private static partial Regex LinuxMacAddressRegex(); diff --git a/Protest/Tools/Monitor.cs b/Protest/Tools/Monitor.cs index 27348ba2..991285ba 100644 --- a/Protest/Tools/Monitor.cs +++ b/Protest/Tools/Monitor.cs @@ -1,16 +1,16 @@ -using System.Net; -using System.Net.WebSockets; -using System.Threading; -using System.Collections.Concurrent; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.Versioning; -using System.Net.NetworkInformation; -using System.Management; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Data; using System.Text; using System.Text.Json; using System.Text.Json.Serialization; +using System.Threading; +using System.Net; +using System.Net.WebSockets; +using System.Net.NetworkInformation; +using System.Management; +using System.Runtime.Versioning; +using System.Diagnostics.CodeAnalysis; using Protest.Http; namespace Protest.Tools; @@ -71,10 +71,8 @@ public static async void WebSocketHandler(HttpListenerContext ctx) { object sendSync = new object(); bool paused = false; bool ping = true; - bool cpu = true; - bool cores = true; int interval = 500; - ConcurrentDictionary wmiQueries = new ConcurrentDictionary(); + ConcurrentDictionary queries = new ConcurrentDictionary(); try { byte[] buff = new byte[2048]; @@ -165,21 +163,8 @@ public static async void WebSocketHandler(HttpListenerContext ctx) { long startTime = DateTime.UtcNow.Ticks; if (OperatingSystem.IsWindows()) { - if (cpu || cores) { - byte[] cpuResult = DoCpuCores(scope, cores); - if (cpu && cpuResult is not null && cpuResult.Length > 0) { - lock (sendSync) { - WsWriteText(ws, $"{{\"result\":\"cpu\",\"value\":{cpuResult[0]}}}"); - } - } - if (cores && cpuResult is not null && cpuResult.Length > 0) { - lock (sendSync) { - WsWriteText(ws, $"{{\"result\":\"cores\",\"value\":[{String.Join(",", cpuResult.Skip(1).ToArray())}]}}"); - } - } - } - DoWmi(scope, wmiQueries); + DoQuery(scope, queries); } long elapsedTime = (DateTime.UtcNow.Ticks - startTime) / 10_000; @@ -225,9 +210,8 @@ public static async void WebSocketHandler(HttpListenerContext ctx) { break; case Action.addwmi: - break; - case Action.addsnmp: + queries.TryAdd(query.id, query); break; case Action.remove: @@ -258,37 +242,7 @@ public static async void WebSocketHandler(HttpListenerContext ctx) { } catch {} } - private static long DoPing(string host, int timeout) { - Ping p = new Ping(); - try { - PingReply reply = p.Send(host, timeout); - - return (int)reply.Status switch { - (int)IPStatus.Success => reply.RoundtripTime, - - (int)IPStatus.DestinationUnreachable or - (int)IPStatus.DestinationHostUnreachable or - (int)IPStatus.DestinationNetworkUnreachable => -1, - - 11050 => -1, - - _ => -1, - }; - } - catch (ArgumentException) { - return -1; - } - catch (PingException) { - return -1; - } - catch (Exception) { - return -1; - } - finally { - p.Dispose(); - } - } - + /* [SupportedOSPlatform("windows")] private static byte[] DoCpuCores(ManagementScope scope, bool getCores) { List cores = new List(); @@ -298,9 +252,7 @@ private static byte[] DoCpuCores(ManagementScope scope, bool getCores) { IEnumerable perfTotalEnum = perfTotal.Cast(); if (perfTotalEnum is null) { return null; } foreach (ManagementObject o in perfTotalEnum) { - if (o is null) { - continue; - } + if (o is null) { continue; } ulong idle = (ulong)o!.GetPropertyValue("PercentIdleTime"); cores.Add((byte)(100 - idle)); } @@ -310,9 +262,7 @@ private static byte[] DoCpuCores(ManagementScope scope, bool getCores) { IEnumerable perfEnum = perf.Cast(); //if (perfEnum is null) { return null; } foreach (ManagementObject o in perfEnum) { - if (o is null) { - continue; - } + if (o is null) { continue; } ulong idle = (ulong)o!.GetPropertyValue("PercentIdleTime"); cores.Add((byte)(100 - idle)); } @@ -324,9 +274,41 @@ private static byte[] DoCpuCores(ManagementScope scope, bool getCores) { return null; } } + */ + + private static long DoPing(string host, int timeout) { + Ping p = new Ping(); + try { + PingReply reply = p.Send(host, timeout); + + return (int)reply.Status switch { + (int)IPStatus.Success => reply.RoundtripTime, + + (int)IPStatus.DestinationUnreachable or + (int)IPStatus.DestinationHostUnreachable or + (int)IPStatus.DestinationNetworkUnreachable => -1, + + 11050 => -1, + + _ => -1, + }; + } + catch (ArgumentException) { + return -1; + } + catch (PingException) { + return -1; + } + catch (Exception) { + return -1; + } + finally { + p.Dispose(); + } + } [SupportedOSPlatform("windows")] - private static byte[] DoWmi(ManagementScope scope, ConcurrentDictionary queries) { + private static byte[] DoQuery(ManagementScope scope, ConcurrentDictionary queries) { try { }