From 28ace991db1a61d978ff3381f55b2dd63365d1af Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 8 Sep 2025 19:01:19 +0200 Subject: Add stripping of ipv4 addresses --- MatrixLogFwd/Program.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'MatrixLogFwd') 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 -- cgit 1.5.1