Skip to content

Commit

Permalink
Issure, nack-end
Browse files Browse the repository at this point in the history
  • Loading branch information
veniware committed Aug 15, 2024
1 parent 4a719a8 commit 1c4eac9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 37 deletions.
15 changes: 8 additions & 7 deletions Protest/Http/Auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,6 @@ private static HashSet<string> PopulateAccessPath(string[] accessList) {
path.Add("/notifications/save");
break;

case "issues:write":
path.Add("/ws/issues");
path.Add("/issues/list");
path.Add("/issues/start");
path.Add("/issues/status");
break;

case "network utilities:write":
path.Add("/ws/ping");
path.Add("/ws/dhcp");
Expand Down Expand Up @@ -385,6 +378,14 @@ private static HashSet<string> PopulateAccessPath(string[] accessList) {
path.Add("/rproxy/stop");
break;

case "issues:write":
path.Add("/ws/issues");
path.Add("/issues/list");
path.Add("/issues/start");
path.Add("/issues/stop");
path.Add("/issues/status");
break;

case "settings:write":
path.Add("/config/zones/list");
path.Add("/config/zones/save");
Expand Down
6 changes: 6 additions & 0 deletions Protest/Http/Listener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//#define DEFLATE
#define BROTLI
#endif
using Protest.Workers;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
Expand Down Expand Up @@ -118,6 +119,11 @@ private static readonly Dictionary<string, Func<HttpListenerContext, Dictionary<
{ "/rproxy/start", (ctx, parameters, username)=> Proxy.ReverseProxy.Start(parameters, username) },
{ "/rproxy/stop", (ctx, parameters, username)=> Proxy.ReverseProxy.Stop(parameters, username) },

{ "/issues/list", (ctx, parameters, username)=> Issues.List() },
{ "/issues/start", (ctx, parameters, username)=> Issues.Start(username) },
{ "/issues/stop", (ctx, parameters, username)=> Issues.Stop(username) },
{ "/issues/status", (ctx, parameters, username)=> Issues.Status() },

{ "/rbac/list", (ctx, parameters, username) => Auth.ListUsers() },
{ "/rbac/create", (ctx, parameters, username) => Auth.CreateUser(ctx, parameters, username) },
{ "/rbac/delete", (ctx, parameters, username) => Auth.DeleteUser(parameters, username) },
Expand Down
70 changes: 40 additions & 30 deletions Protest/Workers/Issues.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using System.Net;
using System.Net.WebSockets;
using System.Reflection.Emit;
using System.Runtime.Versioning;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Lextm.SharpSnmpLib;
using Lextm.SharpSnmpLib.Security;

using Protest.Http;
using Protest.Protocols;
using Protest.Tools;
Expand All @@ -37,6 +32,44 @@ public static byte[] ToJsonBytes(this Issue issue) => JsonSerializer.SerializeTo

public static TaskWrapper task;

public static byte[] List() {
//TODO:
return null;
}

public static byte[] Start(string origin) {
if (task is not null) return Data.CODE_OTHER_TASK_IN_PROGRESS.Array;

Thread thread = new Thread(() => Scan());

task = new TaskWrapper("Issues")
{
thread = thread,
origin = origin,
TotalSteps = 0,
CompletedSteps = 0
};

task.thread.Start();

return "{\"status\":\"running\"}"u8.ToArray(); ;
}

public static byte[] Stop(string origin) {
if (task is null) return "{\"error\":\"Scanning task is not running\"}"u8.ToArray();
task.RequestCancel(origin);
return "{\"status\":\"stopped\"}"u8.ToArray();
}

public static byte[] Status() {
if (task is null) {
return "{\"status\":\"running\"}"u8.ToArray();
}
else {
return "{\"status\":\"stopped\"}"u8.ToArray();
}
}

private static async Task WsWriteText(WebSocket ws, string data) {
if (ws.State == WebSocketState.Open) {
await ws.SendAsync(new ArraySegment<byte>(Encoding.ASCII.GetBytes(data), 0, data.Length), WebSocketMessageType.Text, true, CancellationToken.None);
Expand Down Expand Up @@ -87,31 +120,8 @@ public static async void WebSocketHandler(HttpListenerContext ctx) {
}
}

public static bool StartTask(string origin) {
if (task is not null) return false;

Thread thread = new Thread(() => Scan());

task = new TaskWrapper("Issues") {
thread = thread,
origin = origin,
TotalSteps = 0,
CompletedSteps = 0
};

task.thread.Start();

return true;
}

public static bool StopTask(string origin) {
if (task is null) return false;
task.RequestCancel(origin);
return true;
}

private static void Scan() {

//
}

public static bool CheckPasswordStrength(Database.Entry entry, out Issue? issue) {
Expand Down

0 comments on commit 1c4eac9

Please sign in to comment.