1
|
import re
|
2
|
|
3
|
from quixote import get_response, redirect
|
4
|
from quixote.html import htmltext
|
5
|
|
6
|
from larpe.plugins import site_authentication_plugins
|
7
|
from larpe.site_authentication import SiteAuthentication
|
8
|
|
9
|
class SympaSiteAuthentication(SiteAuthentication):
|
10
|
plugin_name = 'sympa'
|
11
|
|
12
|
def auto_detect_site(cls, html_doc):
|
13
|
if re.search("""<FORM ACTION="/wwsympa.fcgi" METHOD=POST>""", html_doc):
|
14
|
return True
|
15
|
return False
|
16
|
auto_detect_site = classmethod(auto_detect_site)
|
17
|
|
18
|
def check_auth(self, status, data):
|
19
|
success = False
|
20
|
return_content = ''
|
21
|
|
22
|
if self.host.auth_system == 'password':
|
23
|
# If there is a password field, authentication probably failed
|
24
|
regexp = re.compile(
|
25
|
"""<input[^>]*?type=["']?password["']?[^>]*?>""", re.DOTALL | re.IGNORECASE)
|
26
|
if not regexp.findall(data):
|
27
|
success = True
|
28
|
# The specific part is only these 2 lines
|
29
|
get_response().filter.update({'no_template': True})
|
30
|
return_content = htmltext(data)
|
31
|
elif self.host.auth_system == 'status':
|
32
|
match_status = int(self.host.auth_match_status)
|
33
|
if match_status == status:
|
34
|
success = True
|
35
|
return_content = redirect(self.host.return_url)
|
36
|
elif self.host.auth_system == 'match_text':
|
37
|
# If the auth_match_text is not matched, it means the authentication is successful
|
38
|
regexp = re.compile(self.host.auth_match_text, re.DOTALL)
|
39
|
if not regexp.findall(data):
|
40
|
success = True
|
41
|
return_content = redirect(self.host.get_return_url())
|
42
|
|
43
|
return success, return_content
|
44
|
|
45
|
site_authentication_plugins.register(SympaSiteAuthentication)
|