Files
entropy/server/entropy-repository-daemon
lxnay d3a957e02a Entropy/repository daemon template:
- check client IP address too
Entropy/phpbb3 Auth Interface:
- add _is_ip_banned() method


git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@2200 cd1c1023-2f26-0410-ae45-c471fc1f0318
2008-06-30 12:01:14 +00:00

147 lines
4.2 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
authed = session_data['auth_uid']
if authed:
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'}
def docmd_login(self, arguments):
# filter n00bs
if not arguments or (len(arguments) != 3):
return False,None,None,'wrong arguments'
ip_address = arguments[0][0]
user = arguments[1]
password = arguments[2]
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()
return True,user,uid,"ok"
return rc,user,None,"login failed"
def docmd_logout(self, myargs):
# filter n00bs
if (len(myargs) < 2) or (len(myargs) > 2):
return False,None,None,'wrong arguments'
session = myargs[0]
user = myargs[1]
# filter n00bs
if not user or (type(user) is not basestring):
return False,None,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