Browse Source

store reports in subdirectory with a more proper name

Helge Jung 7 years ago
parent
commit
2504bb6e53
2 changed files with 13 additions and 6 deletions
  1. 2 0
      reports/.gitignore
  2. 11 6
      server.py

+ 2 - 0
reports/.gitignore

@@ -0,0 +1,2 @@
+*
+!.gitignore

+ 11 - 6
server.py

@@ -1,4 +1,6 @@
 #!/usr/bin/python
+from __future__ import print_function
+import datetime
 import socket
 import random, string
 
@@ -9,16 +11,17 @@ if __name__ == '__main__':
     TCP_IP = '::'
     TCP_PORT = 1337
     BUFFER_SIZE = 1024
-    
+ 
     s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
     s.bind((TCP_IP, TCP_PORT))
     s.listen(1)
     while 1:
         conn, addr = s.accept()
-        print 'Connection address:', addr
-        filename = myrandom(10)
-        filename +=".txt"
-        f = open(filename,'w')
+ 
+	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
@@ -27,7 +30,9 @@ if __name__ == '__main__':
             f.write(data) # python will convert \n to os.linesep
         f.flush()
         f.close() 
-        conn.send(filename)  
+
+        # send reply to reportee
+        conn.send(report_id)
         conn.close()
         print 'new report:', filename
     pass