Browse Source

Log new reports to bot

Michael Schwarz 9 years ago
parent
commit
37532d66a0
1 changed files with 28 additions and 22 deletions
  1. 28 22
      server.py

+ 28 - 22
server.py

@@ -5,38 +5,44 @@ import socket
 import random, string
 import daemon, getopt, sys
 import daemon.pidlockfile
+import os
 
 def myrandom(length):
    return ''.join(random.choice(string.lowercase) for i in range(length))
 
 def server(port, bindTo):
-    BUFFER_SIZE = 1024
+	BUFFER_SIZE = 1024
  
-    s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
-    s.bind((bindTo, port))
-    s.listen(1)
-    print('DebugReport server listening on [{0}]:{1}'.format(bindTo, port))
+	s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
+	s.bind((bindTo, port))
+	s.listen(1)
+	print('DebugReport server listening on [{0}]:{1}'.format(bindTo, port))
 
-    while 1:
-        conn, addr = s.accept()
- 
-	report_id = myrandom(10)
-	filename = 'reports/' + datetime.date.today().strftime('%Y-%m-%d_') + report_id + '.gz'
+	while 1:
+		conn, addr = s.accept()
+
+		report_id = myrandom(10)
+		filename = 'reports/' + datetime.date.today().strftime('%Y-%m-%d_') + report_id + '.gz'
+
+		f = open(filename, 'w')
+		while 1:
+			data = conn.recv(BUFFER_SIZE)
+			if not data: break
+			f.write(data) # python will convert \n to os.linesep
+		f.flush()
+		f.close() 
 
-        f = open(filename, 'w')
-        while 1:
-            data = conn.recv(BUFFER_SIZE)
-            if not data: break
-            f.write(data) # python will convert \n to os.linesep
-        f.flush()
-        f.close() 
+		# send reply to reportee
+		conn.send(report_id)
+		conn.close()
 
-        # send reply to reportee
-        conn.send(report_id)
-        conn.close()
+		command = 'echo "'+'new report \\\"{0}\\\" from [{2}]:{3} stored as \\\"{1}\\\""'.format(report_id, filename, addr[0], addr[1])
+		command = command + ' | /usr/local/bin/ff_log_to_bot'
+		print(command)
+		os.system(command)
+		print('new report "{0}" from [{2}]:{3} stored as "{1}"'.format(report_id, filename, addr[0], addr[1]))
 
-        print('new report "{0}" from [{2}]:{3} stored as "{1}"'.format(report_id, filename, addr[0], addr[1]))
-    pass
+	pass
 
 if __name__ == '__main__':
 	try: