1
2 """
3
4 @author: Fabio Erculiani <lxnay@sabayonlinux.org>
5 @contact: lxnay@sabayonlinux.org
6 @copyright: Fabio Erculiani
7 @license: GPL-2
8
9 B{Entropy Services Authenticators Interface}.
10
11 """
12
13 from __future__ import with_statement
14
15 from entropy.services.skel import Authenticator
16 from entropy.services.auth_interfaces import phpBB3Auth
17 from entropy.services.skel import SocketAuthenticator
18 from entropy.exceptions import *
19
20
21 -class phpBB3(phpBB3Auth,SocketAuthenticator):
22
23 import entropy.tools as entropyTools
24 - def __init__(self, HostInterface, *args, **kwargs):
29
31 self.session = session
32 session_data = self.HostInterface.sessions.get(self.session)
33 if not session_data:
34 return
35 auth_id = session_data['auth_uid']
36 if auth_id:
37 self.logged_in = True
38
39 self.login_data = {'username': self.FAKE_USERNAME, 'password': 'look elsewhere, this is not a password', 'user_id': auth_id}
40 ip_address = session_data.get('ip_address')
41 if ip_address and self.do_update_session_table:
42 self._update_session_table(auth_id, ip_address)
43
45
46
47 if not arguments or (len(arguments) != 2):
48 return False,None,None,'wrong arguments'
49
50 ip_address = None
51 session_data = self.HostInterface.sessions.get(self.session)
52 if session_data:
53 ip_address = session_data.get('ip_address')
54 user = arguments[0]
55 password = arguments[1]
56
57 if ip_address:
58 if self._is_ip_banned(ip_address):
59 return False,user,None,"banned IP"
60
61 login_data = {'username': user, 'password': password}
62 self.set_login_data(login_data)
63 rc = False
64 try:
65 rc = self.login()
66 except PermissionDenied, e:
67 return rc,user,None,e.value
68
69 if rc:
70 uid = self.get_user_id()
71 is_admin = self.is_administrator()
72 is_dev = self.is_developer()
73 is_mod = self.is_moderator()
74 is_user = self.is_user()
75 self.HostInterface.sessions[self.session]['admin'] = is_admin
76 self.HostInterface.sessions[self.session]['developer'] = is_dev
77 self.HostInterface.sessions[self.session]['moderator'] = is_mod
78 self.HostInterface.sessions[self.session]['user'] = is_user
79 if ip_address and uid and self.do_update_session_table:
80 self._update_session_table(uid, ip_address)
81 return True,user,uid,"ok"
82 return rc,user,None,"login failed"
83
84
88
90
91
92 if (len(myargs) < 1) or (len(myargs) > 1):
93 return False,None,'wrong arguments'
94
95 user = myargs[0]
96
97 if not user or not isinstance(user,basestring):
98 return False,None,"wrong user"
99
100 if not self.is_logged_in():
101 return False,user,"already logged out"
102
103 return True,user,"ok"
104
107
109 myargs = args[:]
110 myargs[-1] = 'hidden'
111 return myargs
112
115