Files
entropy/server/entropy-repository-daemon
T
lxnay 882a7f7bfb Entropy/SocketHostInterface/Repository Daemon:
- fix docmd_login arguments length


git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@2210 cd1c1023-2f26-0410-ae45-c471fc1f0318
2008-06-30 19:16:08 +00:00

155 lines
4.6 KiB
Python

#!/usr/bin/python
import sys, time
sys.path.insert(0,'/usr/lib/entropy/libraries')
sys.path.insert(0,'/usr/lib/entropy/client')
sys.path.insert(0,'../libraries')
sys.path.insert(0,'../client')
# disable pid management
sys.argv.append("--no-pid-handling")
do_ssl = False
do_stdout_logging = True
if "--ssl" in sys.argv:
do_ssl = True
if "--nostdout" in sys.argv:
do_stdout_logging = False
import entropyTools, exceptionTools
from entropy import RepositorySocketServerInterface, phpBB3AuthInterface
connection_data = {
'hostname': 'localhost',
'port': 3306,
'username': 'phpbb_user',
'password': 'mypassword',
'dbname': 'phpbb_db'
}
class phpbb3Authenticator(phpBB3AuthInterface):
import entropyTools
def __init__(self, HostInterface, *args, **kwargs):
self.HostInterface = HostInterface
phpBB3AuthInterface.__init__(self)
self.set_connection_data(kwargs)
self.connect()
self.session = None
def set_session(self, session):
self.session = session
session_data = self.HostInterface.sessions.get(self.session)
if not session_data:
return
auth_id = session_data['auth_uid']
if auth_id:
self.logged_in = True
# fill login_data with fake information
self.login_data = {'username': self.FAKE_USERNAME, 'password': 'look elsewhere, this is not a password'}
ip_address = session_data.get('ip_address')
if ip_address:
self._update_session_table(auth_id, ip_address)
def docmd_login(self, arguments):
# filter n00bs
if not arguments or (len(arguments) != 2):
return False,None,None,'wrong arguments'
ip_address = None
session_data = self.HostInterface.sessions.get(self.session)
if session_data:
ip_address = session_data.get('ip_address')
user = arguments[0]
password = arguments[1]
if ip_address:
if self._is_ip_banned(ip_address):
return False,user,None,"banned IP"
login_data = {'username': user, 'password': password}
self.set_login_data(login_data)
rc = False
try:
rc = self.login()
except exceptionTools.PermissionDenied, e:
return rc,user,None,e.value
if rc:
uid = self.get_user_id()
if ip_address and uid:
self._update_session_table(uid, ip_address)
return True,user,uid,"ok"
return rc,user,None,"login failed"
def docmd_logout(self, myargs):
# filter n00bs
if (len(myargs) < 1) or (len(myargs) > 1):
return False,None,'wrong arguments'
user = myargs[0]
# filter n00bs
if not user or not isinstance(user,basestring):
return False,None,"wrong user"
if not self.is_logged_in():
return False,user,"already logged out"
return True,user,"ok"
def set_exc_permissions(self, *args, **kwargs):
pass
def hide_login_data(self, args):
myargs = args[:]
myargs[-1] = 'hidden'
return myargs
def terminate_instance(self):
self.disconnect()
# configure my repositories
repositories = {
('sabayonlinux.org','amd64','standard',): {
'dbpath': '/home/fabio/new.sabayonlinux.org/standard/amd64',
'cmethod': 'bz2',
},
}
def run_srv(s):
try:
s.go()
except (KeyboardInterrupt, SystemExit,):
s.killall()
sock_auth = (phpbb3Authenticator,[],connection_data)
srv_ssl = None
srv = RepositorySocketServerInterface(do_ssl = False, repositories = repositories, stdout_logging = do_stdout_logging, sock_auth = sock_auth)
if do_ssl:
srv_ssl = RepositorySocketServerInterface(do_ssl = True, repositories = repositories, stdout_logging = do_stdout_logging, sock_auth = sock_auth)
task = entropyTools.parallelTask(run_srv, srv)
task.setName('repodaemon')
task.start()
if srv_ssl != None:
task = entropyTools.parallelTask(run_srv, srv_ssl)
task.setName('repodaemon_ssl')
task.start()
while 1:
try:
time.sleep(1)
found = False
threads = entropyTools.threading.enumerate()
for thread in threads:
if thread.getName() in ["repodaemon","repodaemon_ssl"]:
found = True
break
if not found:
break
except (KeyboardInterrupt, SystemExit,):
threads = entropyTools.threading.enumerate()
for thread in threads:
if thread.getName() in ["repodaemon","repodaemon_ssl"]:
thread.args[0].killall()
raise SystemExit