mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
added authentication to tupkgs and updated info in tupkg
This commit is contained in:
parent
25b0104806
commit
03157ad239
3 changed files with 41 additions and 10 deletions
|
@ -130,11 +130,12 @@ def main(argv=None):
|
||||||
usage()
|
usage()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
cs = ClientSocket(files, 'localhost', 1034, "bfinch@example.net", "B0b")
|
cs = ClientSocket(files, 'localhost', 1034, "tu", "tu")
|
||||||
cs.connect()
|
cs.connect()
|
||||||
|
|
||||||
if not cs.auth():
|
if not cs.auth():
|
||||||
print "Error authenticating you, you bastard"
|
print "Error authenticating you, you bastard"
|
||||||
|
return 1
|
||||||
|
|
||||||
cs.sendFileMeta()
|
cs.sendFileMeta()
|
||||||
|
|
||||||
|
|
|
@ -58,11 +58,12 @@ class ClientFile:
|
||||||
self.md5 = md5sum.hexdigest()
|
self.md5 = md5sum.hexdigest()
|
||||||
|
|
||||||
class ClientSocket(threading.Thread):
|
class ClientSocket(threading.Thread):
|
||||||
def __init__(self, sock, **other):
|
def __init__(self, sock, db, **other):
|
||||||
threading.Thread.__init__(self, *other)
|
threading.Thread.__init__(self, *other)
|
||||||
self.socket = sock
|
self.socket = sock
|
||||||
self.running = 1
|
self.running = 1
|
||||||
self.files = []
|
self.files = []
|
||||||
|
self.db = db
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.running = 0
|
self.running = 0
|
||||||
|
@ -95,10 +96,26 @@ class ClientSocket(threading.Thread):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def auth(self):
|
def auth(self):
|
||||||
authdata = self.readMsg()
|
authdata = self.readMsg(1)
|
||||||
print authdata
|
print authdata
|
||||||
# Do auth stuff here
|
q = self.db.cursor()
|
||||||
|
q.execute("SELECT ID, Suspended, AccountTypeID FROM Users WHERE Username = '"+
|
||||||
|
MySQLdb.escape_string(authdata['username'][0])+
|
||||||
|
"' AND Passwd = '"+
|
||||||
|
MySQLdb.escape_string(authdata['password'][0])+
|
||||||
|
"'")
|
||||||
|
if q.rowcount == 0:
|
||||||
|
self.sendMsg("result=FAIL")
|
||||||
|
return 0
|
||||||
|
row = q.fetchone()
|
||||||
|
if row[1] != 0:
|
||||||
|
self.sendMsg("result=FAIL")
|
||||||
|
return 0
|
||||||
|
if row[2] not in (2, 3):
|
||||||
|
self.sendMsg("result=FAIL")
|
||||||
|
return 0
|
||||||
self.sendMsg("result=PASS")
|
self.sendMsg("result=PASS")
|
||||||
|
return 1
|
||||||
|
|
||||||
def readFileMeta(self):
|
def readFileMeta(self):
|
||||||
files = self.readMsg(1)
|
files = self.readMsg(1)
|
||||||
|
@ -136,18 +153,21 @@ class ClientSocket(threading.Thread):
|
||||||
print self.readMsg()
|
print self.readMsg()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.auth()
|
if not self.auth():
|
||||||
|
self.close()
|
||||||
|
return
|
||||||
self.readFileMeta()
|
self.readFileMeta()
|
||||||
self.readFiles()
|
self.readFiles()
|
||||||
|
|
||||||
class ServerSocket(threading.Thread):
|
class ServerSocket(threading.Thread):
|
||||||
def __init__(self, port=1034, maxqueue=5, **other):
|
def __init__(self, db, port=1034, maxqueue=5, **other):
|
||||||
threading.Thread.__init__(self, *other)
|
threading.Thread.__init__(self, *other)
|
||||||
self.running = 1
|
self.running = 1
|
||||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.socket.bind(('', port))
|
self.socket.bind(('', port))
|
||||||
self.socket.listen(maxqueue)
|
self.socket.listen(maxqueue)
|
||||||
self.clients = []
|
self.clients = []
|
||||||
|
self.db = db
|
||||||
|
|
||||||
def _clean(self, client):
|
def _clean(self, client):
|
||||||
if not client.isAlive():
|
if not client.isAlive():
|
||||||
|
@ -160,11 +180,11 @@ class ServerSocket(threading.Thread):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while self.running:
|
while self.running:
|
||||||
sread, swrite, serror = select.select([self.socket],[self.socket],[self.socket],5)
|
sread, swrite, serror = select.select([self.socket],[self.socket],[self.socket],1)
|
||||||
if sread:
|
if sread:
|
||||||
(clientsocket, address) = self.socket.accept()
|
(clientsocket, address) = self.socket.accept()
|
||||||
print "New connection from " + str(address)
|
print "New connection from " + str(address)
|
||||||
ct = ClientSocket(clientsocket)
|
ct = ClientSocket(clientsocket, self.db)
|
||||||
ct.start()
|
ct.start()
|
||||||
self.clients.append(ct)
|
self.clients.append(ct)
|
||||||
|
|
||||||
|
@ -202,8 +222,14 @@ def main(argv=None):
|
||||||
|
|
||||||
running = 1
|
running = 1
|
||||||
|
|
||||||
|
print "Connecting to MySQL database"
|
||||||
|
dbconn = MySQLdb.connect(host=config.get('mysql', 'host'),
|
||||||
|
user=config.get('mysql', 'username'),
|
||||||
|
passwd=config.get('mysql', 'password'),
|
||||||
|
db=config.get('mysql', 'db'))
|
||||||
|
|
||||||
print "Starting ServerSocket"
|
print "Starting ServerSocket"
|
||||||
servsock = ServerSocket()
|
servsock = ServerSocket(dbconn)
|
||||||
servsock.start()
|
servsock.start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -213,12 +239,15 @@ def main(argv=None):
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
running = 0
|
running = 0
|
||||||
|
|
||||||
print "Cleaning up stuff"
|
print "Waiting for threads to die"
|
||||||
|
|
||||||
servsock.close()
|
servsock.close()
|
||||||
|
|
||||||
servsock.join()
|
servsock.join()
|
||||||
|
|
||||||
|
print "Closing DB"
|
||||||
|
dbconn.close()
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -2,3 +2,4 @@
|
||||||
username = aur
|
username = aur
|
||||||
password = aur
|
password = aur
|
||||||
host = localhost
|
host = localhost
|
||||||
|
db = AUR
|
||||||
|
|
Loading…
Add table
Reference in a new issue