aboutsummaryrefslogtreecommitdiff
path: root/tools/recover.py
diff options
context:
space:
mode:
authorcasswarry0 <casswarry0@gmail.com>2023-01-17 17:14:53 -0700
committercasswarry0 <casswarry0@gmail.com>2023-01-17 17:14:53 -0700
commit7338b8730949ed027b3f8b31d7dca20687ebbb8b (patch)
treec2d171e6121818ab511460a786f69aab97a2a628 /tools/recover.py
parentcdecd3fa4427a382c0b09f8ad9d69ec14388960a (diff)
parent85501f9cf4918d5eee345f83aed7a31eecb26b8d (diff)
downloadtrackermap-server-7338b8730949ed027b3f8b31d7dca20687ebbb8b.tar.gz
trackermap-server-7338b8730949ed027b3f8b31d7dca20687ebbb8b.tar.bz2
trackermap-server-7338b8730949ed027b3f8b31d7dca20687ebbb8b.zip
Merge branch 'master' into develop
Diffstat (limited to 'tools/recover.py')
-rwxr-xr-xtools/recover.py49
1 files changed, 33 insertions, 16 deletions
diff --git a/tools/recover.py b/tools/recover.py
index 01e01f92e..32e3f8721 100755
--- a/tools/recover.py
+++ b/tools/recover.py
@@ -1,35 +1,52 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
import sys
import re
+import os
+import xml.etree.ElementTree
import socket
import binascii
+import time
if len(sys.argv) < 2:
sys.exit("log file is not provided")
path = sys.argv[1]
-p = re.compile(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} DEBUG: \[([0-9a-fA-F]{8}): (\d+) < [\d.]+] HEX: ([0-9a-fA-F]+)")
+p = re.compile(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} INFO: \[([TU][0-9a-fA-F]{8}): (\S+) < [\d.]+] ([0-9a-fA-F]+)")
-ports = {}
+def load_ports():
+ ports = {}
+ dir = os.path.dirname(os.path.abspath(__file__))
+ root = xml.etree.ElementTree.parse(dir + '/../setup/default.xml').getroot()
+ for entry in root.findall('entry'):
+ key = entry.attrib['key']
+ if key.endswith('.port'):
+ ports[key[:-5]] = int(entry.text)
+ return ports
+
+ports = load_ports()
+protocols = {}
messages = {}
for line in open(path):
- if "HEX:" in line:
- m = p.match(line)
- if m:
- session = m.group(1)
- port = m.group(2)
- message = m.group(3)
- ports[session] = port
- if session not in messages:
- messages[session] = []
- messages[session].append(message)
-
-for session in ports:
- port = ports[session]
+ print(line)
+ m = p.match(line)
+ if m:
+ session = m.group(1)
+ protocol = m.group(2)
+ message = m.group(3)
+ protocols[session] = protocol
+ if session not in messages:
+ messages[session] = []
+ messages[session].append(message)
+
+print('Total: %d' % len(messages))
+
+for session in protocols:
+ port = ports[protocols[session]]
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("localhost", int(port)))
for message in messages[session]:
s.send(binascii.unhexlify(message))
+ time.sleep(0.1)
s.close()