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]
- self.data = self.data.split()
- inUser = self.data[0]
- inPassWd = self.data[1]
- userList = self._getUserList()
- try:
- SvPassWd = userList[inUser]
- self._auth(inPassWd, SvPassWd)
- except KeyError:
- print "failed login from %s at %s" % (self.client_address[0], ctime())
- logs.write("failed login from %s at %s" % (self.client_address[0], ctime()))
- def _auth(self, inPassWd, SvPassWd):
- if inPassWd == SvPassWd:
- print "user login from %s at %s" % (self.client_address[0], ctime)
- logs.write("user login from %s at %s" % (self.client_address[0], ctime))
- clientHandler(self)
- else:
- print "failed login from %s at %s" % (self.client_address[0], ctime)
- logs.write("failed login from %s at %s" % (self.client_address[0], ctime))
- def _getUserList(self):
- userList = []
- line = usersInfo.readline()
- while line:
- if len(line) > 1:
- print line
- fileUser = line.split(',')[0][2:-1]
- filePass = line.split(',')[1][2:-3]
- infoTpl = (fileUser, filePass)
- print infoTpl
- userList.append(infoTpl)
- line = usersInfo.readline()
- print dict(userList)
- return dict(userList)
- class clientHandler:
- def __init__(self, selfSocket):
- self.serverSocket = selfSocket
- print self.serverSocket.client_address
- if __name__ == "__main__":
- HOST, PORT = "localhost", 10001
- print HOST , PORT
- # 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