summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-09-08 19:01:19 +0200
committerRory& <root@rory.gay>2025-09-08 19:01:19 +0200
commit28ace991db1a61d978ff3381f55b2dd63365d1af (patch)
treeb7951919009eab725499acc359b7338fe927ea3a
parentUpdate LibMatri (diff)
downloadMatrixLogFwd-28ace991db1a61d978ff3381f55b2dd63365d1af.tar.xz
Add stripping of ipv4 addresses
-rw-r--r--MatrixLogFwd/Program.cs19
1 files changed, 19 insertions, 0 deletions
diff --git a/MatrixLogFwd/Program.cs b/MatrixLogFwd/Program.cs

index c3765b2..ec90a07 100644 --- a/MatrixLogFwd/Program.cs +++ b/MatrixLogFwd/Program.cs
@@ -2,6 +2,7 @@ using System.Text; using System.Text.Json; +using System.Text.RegularExpressions; using ArcaneLibs; using LibMatrix.Helpers; using LibMatrix.Homeservers; @@ -19,6 +20,7 @@ Console.WriteLine(hs); string mode = "lines"; int chunkSize = 1000; +bool stripIpv4 = false; string? command = null; GenericRoom? room = null; @@ -40,6 +42,9 @@ while (argsEnum.MoveNext()) return; } break; + case "--strip-ipv4": + stripIpv4 = true; + break; case "--chunk-size": argsEnum.MoveNext(); chunkSize = Conversions.ToInteger(argsEnum.Current); @@ -109,6 +114,14 @@ if (mode == "lines") linesInBuffer++; if (linesInBuffer > chunkSize) { + if (stripIpv4) + { + var lineStr = line.ToString(); + lineStr = Ipv4Regex().Replace(lineStr, "[REDACTED_IP]"); + line.Clear(); + line.Append(lineStr); + } + await room.SendMessageEventAsync(new MessageBuilder().WithCodeBlock(line.ToString()).Build()); line.Clear(); linesInBuffer = 0; @@ -142,4 +155,10 @@ else } } +partial class Program +{ + [GeneratedRegex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b")] + private static partial Regex Ipv4Regex(); +} + // await room.LeaveAsync(); \ No newline at end of file