Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # server rewrite
- import sys, threading, SocketServer
- from time import ctime, sleep, time
- usersInfo = open("users/users.txt", "r")
- logs = open("logs/main.log", "w")
- adminLog = open("logs/admin.log","w")
- online = []
- threads = []
- class ClientAuth(SocketServer.BaseRequestHandler):
- def handle(self):
- self.data = self.request.recv.(1024)
- # ip is found with self.client_address[0]
- inUser = self.data.split(',')[0][2:-1]
- inPassWd = self.data.split(',')[1][1:-2]
- userList = self._getUserList()
- SvPassWd = userList[inUser]
- if inPassWd == SvPassWd:
- print "user loggedin from %s at %s" % (self.client_address[0], ctime)
- def _getUserList(self):
- userList = []
- line = usersInfo.readline()
- while line:
- fileUser = line.split(',')[0][2:-1]
- filePass = line.split(',')[1][1:-3]
- infoTpl = (fileUser, filePass)
- userList.append(infoTpl)
- line = userInfo.readline()
- return dict(userList)
- if __name__ == "__main__":
- HOST, PORT = "localhost", 900
- # Create the server, binding to localhost on port 9999
- server = SocketServer.TCPServer((HOST, PORT), ClientAuth)
- # Activate the server; this will keep running until you
- # interrupt the program with Ctrl-C
- server.serve_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement