summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjschneider <jschneider@3ed937ae-f919-0410-9a43-8e6f19e4ba6e>2009-09-23 13:33:49 (GMT)
committerjschneider <jschneider@3ed937ae-f919-0410-9a43-8e6f19e4ba6e>2009-09-23 13:33:49 (GMT)
commit4d37015708f3e38908aaaab3a389c61fd7550f38 (patch)
tree23732294d886dffc574a9b2051f92d57b1b4b4df
parent246198044e890655e219f3d77a6f7c21fa3630ea (diff)
downloadlarpe-4d37015708f3e38908aaaab3a389c61fd7550f38.zip
larpe-4d37015708f3e38908aaaab3a389c61fd7550f38.tar.gz
larpe-4d37015708f3e38908aaaab3a389c61fd7550f38.tar.bz2
Add filters feature for plugins
* larpe/admin/hosts.ptl: allows to add custom filters * larpe/plugins/site_authentication/ciril_net_rh.py: add logout support with a filter git-svn-id: svn+ssh://labs.libre-entreprise.org/svnroot/larpe@476 3ed937ae-f919-0410-9a43-8e6f19e4ba6e
-rw-r--r--larpe/trunk/larpe/admin/hosts.ptl39
-rw-r--r--larpe/trunk/larpe/plugins/site_authentication/ciril_net_rh.py18
-rw-r--r--larpe/trunk/larpe/site_authentication.ptl15
3 files changed, 52 insertions, 20 deletions
diff --git a/larpe/trunk/larpe/admin/hosts.ptl b/larpe/trunk/larpe/admin/hosts.ptl
index 06376cf..2c1c25f 100644
--- a/larpe/trunk/larpe/admin/hosts.ptl
+++ b/larpe/trunk/larpe/admin/hosts.ptl
@@ -791,8 +791,12 @@ POST request. You can desactivate some or all of them, or change their value.'''
self.host.http_headers[name] = old_value
self.host.store()
- def generate_apache_filter(self):
+ def generate_apache_filters(self):
# Set Python filter path for Apache configuration
+ site_auth = site_authentication.get_site_authentication(self.host)
+ filters = site_auth.get_filters()
+ replace_login_form = self.host.auth_form_places == 'form_everywhere' and \
+ self.host.auth_form_action
python_path = os.path.join(self.host.site_dir, 'filters')
if python_path not in self.host.apache_python_paths:
self.host.apache_python_paths.append(python_path)
@@ -800,16 +804,25 @@ POST request. You can desactivate some or all of them, or change their value.'''
# Write Python filter
python_file = open(os.path.join(self.host.site_dir, 'filters', 'output_replace_form.py'), 'w')
python_file.write(open(OUTPUT_FILTER_BASE).read())
- python_file.write('''\
-def filter_page(filter, page):
+ if filters or replace_login_form:
+ python_file.write("def filter_page(filter, page):\n")
+ if replace_login_form:
+ python_file.write('''\
current_form = re.compile('<form [^>]*?action="%(auth_form_action)s".*?>.*?</form>', re.DOTALL)
- return current_form.sub('<form method="post" action="/liberty/%(name)s/login"><input type="submit" value="Connexion" /></form>', page)
-''' % { 'auth_form_action': self.host.auth_form_action, 'name': self.host.name })
- python_file.close()
+ page = current_form.sub('<form method="post" action="/liberty/%(name)s/login"><input type="submit" value="Connexion" /></form>', page)'''
+ % { 'auth_form_action': self.host.auth_form_action, 'name': self.host.name })
+ for filter in filters:
+ python_file.write(" r = re.compile(r\"\"\"%s\"\"\", re.DOTALL)\n" % filter["re"])
+ python_file.write(" page = r.sub(r\"\"\"%s\"\"\", page)\n" % filter["sub"])
+ python_file.write(" return page\n")
+ python_file.close()
+ # Set Python filter for Apache configuration
+ if not 'output_replace_form' in self.host.apache_output_python_filters:
+ self.host.apache_output_python_filters.append('output_replace_form')
+ else:
+ if 'output_replace_form' in self.host.apache_output_python_filters:
+ self.host.apache_output_python_filters.remove('output_replace_form')
- # Set Python filter for Apache configuration
- if not 'output_replace_form' in self.host.apache_output_python_filters:
- self.host.apache_output_python_filters.append('output_replace_form')
def sso_init_link [html] (self):
form = self.form_sso_init_link()
@@ -859,13 +872,7 @@ authenticate on any of these pages, and don't need to be redirected to a separat
for f in fields:
setattr(self.host, f, form.get_widget(f).parse())
self.host.auth_form_url = self.host.auth_url
-
- if self.host.auth_form_places == 'form_everywhere' and self.host.auth_form_action:
- self.generate_apache_filter()
- else:
- if 'output_replace_form' in self.host.apache_output_python_filters:
- self.host.apache_output_python_filters.remove('output_replace_form')
-
+ self.generate_apache_filters()
self.host.store()
write_apache2_vhosts()
diff --git a/larpe/trunk/larpe/plugins/site_authentication/ciril_net_rh.py b/larpe/trunk/larpe/plugins/site_authentication/ciril_net_rh.py
index 100c1a5..8a00a22 100644
--- a/larpe/trunk/larpe/plugins/site_authentication/ciril_net_rh.py
+++ b/larpe/trunk/larpe/plugins/site_authentication/ciril_net_rh.py
@@ -1,3 +1,4 @@
+
import re
from quixote import redirect
@@ -31,9 +32,24 @@ class CirilSiteAuthentication(SiteAuthentication):
match = regexp.findall(data)
if match:
success = True
- return_content = '<script language="JavaScript" type="text/javascript">window.open("%s", "_parent")</script>' % match[0]
+ 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)
diff --git a/larpe/trunk/larpe/site_authentication.ptl b/larpe/trunk/larpe/site_authentication.ptl
index 3343b02..68f54aa 100644
--- a/larpe/trunk/larpe/site_authentication.ptl
+++ b/larpe/trunk/larpe/site_authentication.ptl
@@ -105,6 +105,18 @@ class SiteAuthentication:
value = values[0], options = options)
return form
+ def get_filters(self):
+ """ Allows to filters the page
+ Example with a logout link:
+ filters = []
+ filter = {}
+ filer["re"] = "<a.*?href=\"home.php\.*?\">Logout</a>"
+ filer["sub"] = "<a href=\"/logout\">Logout</a>" % logout_url
+ filters.append(filter)
+ return filters
+ """
+ return None
+
def submit_local_auth_form(self, form):
username = form.get_widget('username').parse()
password = form.get_widget('password').parse()
@@ -279,9 +291,6 @@ class SiteAuthentication:
return success, return_content
def local_logout(self, federation=None, user=None):
- """
- TODO : recode with twill
- """
if federation is None and user is not None:
federations = Federation.select(lambda x: user.name_identifiers[0] in x.name_identifiers)
if federations: