summaryrefslogtreecommitdiffstats
path: root/larpe/trunk/larpe/plugins/site_authentication/ciril_net_rh.py
blob: d671ab392cc675a545d66680d93f7c2927315c45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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

site_authentication_plugins.register(CirilSiteAuthentication)