From 30e0e9f56c874eeca9d6cfe601e525f6235523d5 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Mon, 26 Jun 2017 11:30:00 +0200 Subject: Adds "replacement" option. --- jabberhive-regex.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/jabberhive-regex.py b/jabberhive-regex.py index 22885dd..4e4e543 100755 --- a/jabberhive-regex.py +++ b/jabberhive-regex.py @@ -40,7 +40,17 @@ def client_main (source, params): if ((valid == 1) and pattern.match(up_data)): if (t_connect != None): - t_connect.sendall(in_data) + if (params.replacement != None): + print("Transformed \"" + up_data + "\"") + up_data = re.sub( + pattern, + params.replacement, + up_data + ) + print("into \"" + up_data + "\"") + t_connect.sendall(up_data.encode("UTF-8")) + else: + t_connect.sendall(in_data) current_target = 't' state = ClientState.CLIENT_IS_SENDING_UPSTREAM print("[Matched] Sending upstream...") @@ -61,7 +71,6 @@ def client_main (source, params): c = b"\0" while (c != b"\n"): - print("67: sending upstream") if (current_target == 't'): c = t_connect.recv(1) else: @@ -143,6 +152,14 @@ parser.add_argument( help = 'The regex to test the message against.', ) +parser.add_argument( + '-x', + '--replacement', + type = str, + required = False, + help = 'The transformation regex to be applied', +) + args = parser.parse_args() ################################################################################ -- cgit v1.2.3-70-g09d2