mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
tupkgs only connects to sql database for duration of auth
This commit is contained in:
parent
1c4883edba
commit
2d59d0d873
1 changed files with 13 additions and 15 deletions
|
@ -72,12 +72,11 @@ class ClientFile:
|
||||||
os.remove(self.pathname)
|
os.remove(self.pathname)
|
||||||
|
|
||||||
class ClientSocket(threading.Thread):
|
class ClientSocket(threading.Thread):
|
||||||
def __init__(self, sock, db, **other):
|
def __init__(self, sock, **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
|
||||||
|
@ -115,7 +114,14 @@ class ClientSocket(threading.Thread):
|
||||||
if (not authdata.has_key('username')) or (not authdata.has_key('password')):
|
if (not authdata.has_key('username')) or (not authdata.has_key('password')):
|
||||||
self.sendMsg("result=FAIL")
|
self.sendMsg("result=FAIL")
|
||||||
return 0
|
return 0
|
||||||
q = self.db.cursor()
|
|
||||||
|
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'))
|
||||||
|
|
||||||
|
q = dbconn.cursor()
|
||||||
m = md5.new()
|
m = md5.new()
|
||||||
m.update(authdata['password'][0])
|
m.update(authdata['password'][0])
|
||||||
encpw = m.hexdigest()
|
encpw = m.hexdigest()
|
||||||
|
@ -125,6 +131,7 @@ class ClientSocket(threading.Thread):
|
||||||
"' AND Passwd = '"+
|
"' AND Passwd = '"+
|
||||||
MySQLdb.escape_string(encpw)+
|
MySQLdb.escape_string(encpw)+
|
||||||
"'")
|
"'")
|
||||||
|
dbconn.close()
|
||||||
except MySQLdb.OperationalError:
|
except MySQLdb.OperationalError:
|
||||||
self.sendMsg("result=SQLERR")
|
self.sendMsg("result=SQLERR")
|
||||||
return 0
|
return 0
|
||||||
|
@ -193,14 +200,13 @@ class ClientSocket(threading.Thread):
|
||||||
return
|
return
|
||||||
|
|
||||||
class ServerSocket(threading.Thread):
|
class ServerSocket(threading.Thread):
|
||||||
def __init__(self, db, port, maxqueue, **other):
|
def __init__(self, port, maxqueue, **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():
|
||||||
|
@ -217,7 +223,7 @@ class ServerSocket(threading.Thread):
|
||||||
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, self.db)
|
ct = ClientSocket(clientsocket)
|
||||||
ct.start()
|
ct.start()
|
||||||
self.clients.append(ct)
|
self.clients.append(ct)
|
||||||
|
|
||||||
|
@ -279,12 +285,6 @@ def main(argv=None):
|
||||||
if config.has_option('tupkgs', 'incomingdir'):
|
if config.has_option('tupkgs', 'incomingdir'):
|
||||||
confdict['incomingdir'] = config.get('tupkgs', 'incomingdir')
|
confdict['incomingdir'] = config.get('tupkgs', 'incomingdir')
|
||||||
|
|
||||||
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 "Verifying "+confdict['cachedir']+" and "+confdict['incomingdir']+" exist"
|
print "Verifying "+confdict['cachedir']+" and "+confdict['incomingdir']+" exist"
|
||||||
if not os.path.isdir(confdict['cachedir']):
|
if not os.path.isdir(confdict['cachedir']):
|
||||||
print "Creating "+confdict['cachedir']
|
print "Creating "+confdict['cachedir']
|
||||||
|
@ -294,7 +294,7 @@ def main(argv=None):
|
||||||
os.mkdir(confdict['incomingdir'], 0755)
|
os.mkdir(confdict['incomingdir'], 0755)
|
||||||
|
|
||||||
print "Starting ServerSocket"
|
print "Starting ServerSocket"
|
||||||
servsock = ServerSocket(dbconn, confdict['port'], confdict['maxqueue'])
|
servsock = ServerSocket(confdict['port'], confdict['maxqueue'])
|
||||||
servsock.start()
|
servsock.start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -310,8 +310,6 @@ def main(argv=None):
|
||||||
|
|
||||||
servsock.join()
|
servsock.join()
|
||||||
|
|
||||||
print "Closing DB"
|
|
||||||
dbconn.close()
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue