1
|
import re
|
2
|
|
3
|
def filter_page(filter, page):
|
4
|
current_form = re.compile('<form [^>]*?action="%(auth_form_action)s".*?>.*?</form>', re.DOTALL)
|
5
|
page = current_form.sub('<form method="post" action="/liberty/%(name)s/login"><input type="submit" value="Connexion" /></form>', page)
|
6
|
return page
|
7
|
|
8
|
def outputfilter(filter):
|
9
|
# Only filter html code
|
10
|
if filter.req.content_type is not None:
|
11
|
is_html = re.search('text/html', filter.req.content_type)
|
12
|
if filter.req.content_type is None or not is_html:
|
13
|
filter.pass_on()
|
14
|
else:
|
15
|
if not hasattr(filter.req, 'temp_doc'):
|
16
|
# Create a new attribute to hold the document
|
17
|
filter.req.temp_doc = []
|
18
|
# If content-length ended up wrong, Gecko browsers truncated data
|
19
|
if 'Content-Length' in filter.req.headers_out:
|
20
|
del filter.req.headers_out['Content-Length']
|
21
|
|
22
|
temp_doc = filter.req.temp_doc
|
23
|
s = filter.read()
|
24
|
# Could get '' at any point, but only get None at end
|
25
|
while s:
|
26
|
temp_doc.append(s)
|
27
|
s = filter.read()
|
28
|
|
29
|
# The end
|
30
|
if s is None:
|
31
|
page = ''.join(temp_doc)
|
32
|
page = filter_page(filter, page)
|
33
|
filter.write(page)
|
34
|
filter.close()
|
35
|
|