56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
|
|
import re
|
|
|
|
from quixote import redirect
|
|
|
|
from larpe.plugins import site_authentication_plugins
|
|
from larpe.site_authentication import SiteAuthentication
|
|
|
|
class CirilSiteAuthentication(SiteAuthentication):
|
|
plugin_name = 'ciril'
|
|
|
|
def auto_detect_site(cls, html_doc):
|
|
if re.search(
|
|
"""<form name="myForm" id="myForm" method="post" target="choixAppli" action="/cgi-bin/acces.exe" """,
|
|
html_doc):
|
|
return True
|
|
return False
|
|
auto_detect_site = classmethod(auto_detect_site)
|
|
|
|
def check_auth(self, status, data):
|
|
success = False
|
|
return_content = ''
|
|
|
|
# If status is 500, fail without checking other criterias
|
|
if status // 100 == 5:
|
|
success = False
|
|
return_content = redirect(self.host.get_return_url())
|
|
|
|
regexp = re.compile(
|
|
"""javascript\:window\.open\('(/net_rh/accueil.php\?.*?)', '_blank'\)""",
|
|
re.DOTALL | re.IGNORECASE)
|
|
match = regexp.findall(data)
|
|
if match:
|
|
success = True
|
|
return_content = redirect(match[0])
|
|
|
|
return success, return_content
|
|
|
|
def get_filters(self):
|
|
""" Rewrite the logout link """
|
|
filters = []
|
|
logout = {}
|
|
if not hasattr(self.host, 'base_url'):
|
|
return None
|
|
base_url_tokens = self.host.base_url.split('/')
|
|
base_url_tokens[-1] = 'logout'
|
|
new_logout_url = '/'.join(base_url_tokens)
|
|
logout["re"] = """(<a.*?href=["']).*?(["'].*?>D.*?connexion</a>)"""
|
|
logout["sub"] = r"\1%s\2" % new_logout_url
|
|
filters.append(logout)
|
|
return filters
|
|
|
|
|
|
site_authentication_plugins.register(CirilSiteAuthentication)
|
|
|