Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. #!/usr/bin/python
  2. # server rewrite
  3.  
  4. import sys, threading, SocketServer
  5. from time import ctime, sleep, time
  6. usersInfo = open("users/users.txt", "r")
  7. logs = open("logs/main.log", "w")
  8. adminLog = open("logs/admin.log","w")
  9. online = []
  10. threads = []
  11.  
  12. class ClientAuth(SocketServer.BaseRequestHandler):
  13.     def handle(self):
  14.         self.data = self.request.recv.(1024)
  15.         # ip is found with self.client_address[0]
  16.         inUser = self.data.split(',')[0][2:-1]
  17.         inPassWd = self.data.split(',')[1][1:-2]
  18.         userList = self._getUserList()
  19.         SvPassWd = userList[inUser]
  20.         if inPassWd == SvPassWd:
  21.             print "user loggedin from %s at %s" % (self.client_address[0], ctime)
  22.     def _getUserList(self):
  23.         userList = []
  24.         line = usersInfo.readline()
  25.         while line:
  26.             fileUser = line.split(',')[0][2:-1]
  27.             filePass = line.split(',')[1][1:-3]
  28.             infoTpl = (fileUser, filePass)
  29.             userList.append(infoTpl)
  30.             line = userInfo.readline()
  31.         return dict(userList)
  32.  
  33.  
  34. if __name__ == "__main__":
  35.     HOST, PORT = "localhost", 900
  36.  
  37.     # Create the server, binding to localhost on port 9999
  38.     server = SocketServer.TCPServer((HOST, PORT), ClientAuth)
  39.  
  40.     # Activate the server; this will keep running until you
  41.     # interrupt the program with Ctrl-C
  42.     server.serve_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement