summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtupkg/client/tupkg3
-rwxr-xr-xtupkg/server/tupkgs47
-rw-r--r--tupkg/server/tupkgs.conf1
3 files changed, 41 insertions, 10 deletions
diff --git a/tupkg/client/tupkg b/tupkg/client/tupkg
index 14eb1c0..125288a 100755
--- a/tupkg/client/tupkg
+++ b/tupkg/client/tupkg
@@ -130,11 +130,12 @@ def main(argv=None):
usage()
return 1
- cs = ClientSocket(files, 'localhost', 1034, "bfinch@example.net", "B0b")
+ cs = ClientSocket(files, 'localhost', 1034, "tu", "tu")
cs.connect()
if not cs.auth():
print "Error authenticating you, you bastard"
+ return 1
cs.sendFileMeta()
diff --git a/tupkg/server/tupkgs b/tupkg/server/tupkgs
index 213e462..a1d343c 100755
--- a/tupkg/server/tupkgs
+++ b/tupkg/server/tupkgs
@@ -58,11 +58,12 @@ class ClientFile:
self.md5 = md5sum.hexdigest()
class ClientSocket(threading.Thread):
- def __init__(self, sock, **other):
+ def __init__(self, sock, db, **other):
threading.Thread.__init__(self, *other)
self.socket = sock
self.running = 1
self.files = []
+ self.db = db
def close(self):
self.running = 0
@@ -95,10 +96,26 @@ class ClientSocket(threading.Thread):
return data
def auth(self):
- authdata = self.readMsg()
+ authdata = self.readMsg(1)
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")
+ return 1
def readFileMeta(self):
files = self.readMsg(1)
@@ -136,18 +153,21 @@ class ClientSocket(threading.Thread):
print self.readMsg()
def run(self):
- self.auth()
+ if not self.auth():
+ self.close()
+ return
self.readFileMeta()
self.readFiles()
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)
self.running = 1
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.bind(('', port))
self.socket.listen(maxqueue)
self.clients = []
+ self.db = db
def _clean(self, client):
if not client.isAlive():
@@ -160,11 +180,11 @@ class ServerSocket(threading.Thread):
def run(self):
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:
(clientsocket, address) = self.socket.accept()
print "New connection from " + str(address)
- ct = ClientSocket(clientsocket)
+ ct = ClientSocket(clientsocket, self.db)
ct.start()
self.clients.append(ct)
@@ -202,8 +222,14 @@ def main(argv=None):
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"
- servsock = ServerSocket()
+ servsock = ServerSocket(dbconn)
servsock.start()
try:
@@ -213,12 +239,15 @@ def main(argv=None):
except KeyboardInterrupt:
running = 0
- print "Cleaning up stuff"
+ print "Waiting for threads to die"
servsock.close()
servsock.join()
+ print "Closing DB"
+ dbconn.close()
+
return 0
if __name__ == "__main__":
diff --git a/tupkg/server/tupkgs.conf b/tupkg/server/tupkgs.conf
index 7e0ecbf..94b6fad 100644
--- a/tupkg/server/tupkgs.conf
+++ b/tupkg/server/tupkgs.conf
@@ -2,3 +2,4 @@
username = aur
password = aur
host = localhost
+db = AUR