annotate MoinMoin/request/__init__.py @ 2369:ccf996479233

fix a suid bug: force switched-to user valid
author Johannes Berg <johannes AT sipsolutions DOT net>
date Thu, 12 Jul 2007 11:41:35 +0200
parents 39d11cf4af6c
children 609ef7393a14
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
640
80d0ad85a2d8 splitted request.py into request/*, please help fixing/testing, see CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 637
diff changeset
3 MoinMoin - RequestBase Implementation
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1870
diff changeset
5 @copyright: 2001-2003 Juergen Hermann <jh@web.de>,
640
80d0ad85a2d8 splitted request.py into request/*, please help fixing/testing, see CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 637
diff changeset
6 2003-2006 MoinMoin:ThomasWaldmann
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
8 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
9
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
10 import os, re, time, sys, cgi, StringIO
1590
56bf38d79ba8 added missing logging import
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1586
diff changeset
11 import logging
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
12 import copy
1931
7f87f9d0159e move cookie parsing to request and pass the cookie object (or None) to the
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1918
diff changeset
13 import Cookie
1148
301575ccf95f added set import for py 2.3 compatibility
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1132
diff changeset
14
301575ccf95f added set import for py 2.3 compatibility
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1132
diff changeset
15 try:
301575ccf95f added set import for py 2.3 compatibility
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1132
diff changeset
16 set
301575ccf95f added set import for py 2.3 compatibility
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1132
diff changeset
17 except:
301575ccf95f added set import for py 2.3 compatibility
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1132
diff changeset
18 from sets import Set as set
301575ccf95f added set import for py 2.3 compatibility
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1132
diff changeset
19
1071
64e513264aed cleanup, less header logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1070
diff changeset
20 from MoinMoin import config, wikiutil, user, caching, error
1567
2e1aff91a0a5 use 404 instead of ConfigurationError when no config is matched for some URL
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1557
diff changeset
21 from MoinMoin.config import multiconfig
618
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
22 from MoinMoin.util import IsWin9x
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
23 from MoinMoin import auth
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
24 from urllib import quote, quote_plus
618
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
25
1317
76a76def8687 remove most chmod calls, use 1 os.umask() call in request module instead (port from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1245
diff changeset
26 # umask setting --------------------------------------------------------
1761
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
27 def set_umask(new_mask=0777^config.umask):
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
28 """ Set the OS umask value (and ignore potential failures on OSes where
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
29 this is not supported).
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
30 Default: the bitwise inverted value of config.umask
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
31 """
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
32 try:
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
33 old_mask = os.umask(new_mask)
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
34 except:
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
35 # maybe we are on win32?
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
36 pass
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
37
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
38 # We do this at least once per Python process, when request is imported.
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
39 # If other software parts (like twistd's daemonize() function) set an
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
40 # unwanted umask, we have to call this again to set the correct one:
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
41 set_umask()
618
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
42
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
43 # Exceptions -----------------------------------------------------------
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
44
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
45 class MoinMoinFinish(Exception):
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
46 """ Raised to jump directly to end of run() function, where finish is called """
1086
db7863d7a45e Fixed bug in request.py that avoided showing a traceback if there was a fault after the first headers were sent.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1071
diff changeset
47
db7863d7a45e Fixed bug in request.py that avoided showing a traceback if there was a fault after the first headers were sent.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1071
diff changeset
48
db7863d7a45e Fixed bug in request.py that avoided showing a traceback if there was a fault after the first headers were sent.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1071
diff changeset
49 class HeadersAlreadySentException(Exception):
db7863d7a45e Fixed bug in request.py that avoided showing a traceback if there was a fault after the first headers were sent.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1071
diff changeset
50 """ Is raised if the headers were already sent when emit_http_headers is called."""
db7863d7a45e Fixed bug in request.py that avoided showing a traceback if there was a fault after the first headers were sent.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1071
diff changeset
51
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
52
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53 # Timing ---------------------------------------------------------------
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
54
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
55 class Clock:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
56 """ Helper class for code profiling
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
57 we do not use time.clock() as this does not work across threads
1144
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
58 This is not thread-safe when it comes to multiple starts for one timer.
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
59 It is possible to recursively call the start and stop methods, you
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
60 should just ensure that you call them often enough :)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
61 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
62
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
63 def __init__(self):
1130
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
64 self.timings = {}
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
65 self.states = {}
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
66
1144
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
67 def _get_name(timer, generation):
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
68 if generation == 0:
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
69 return timer
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
70 else:
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
71 return "%s|%i" % (timer, generation)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
72 _get_name = staticmethod(_get_name)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
73
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
74 def start(self, timer):
1144
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
75 state = self.states.setdefault(timer, -1)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
76 new_level = state + 1
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
77 name = Clock._get_name(timer, new_level)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
78 self.timings[name] = time.time() - self.timings.get(name, 0)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
79 self.states[timer] = new_level
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
80
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
81 def stop(self, timer):
1144
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
82 state = self.states.setdefault(timer, -1)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
83 if state >= 0: # timer is active
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
84 name = Clock._get_name(timer, state)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
85 self.timings[name] = time.time() - self.timings[name]
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
86 self.states[timer] = state - 1
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
87
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
88 def value(self, timer):
1144
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
89 base_timer = timer.split("|")[0]
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
90 state = self.states.get(base_timer, None)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
91 if state == -1:
1130
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
92 result = "%.3fs" % self.timings[timer]
1144
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
93 elif state is None:
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
94 result = "- (%s)" % state
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
95 else:
1147
637d90f1209d Oops, removed a debug print.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1144
diff changeset
96 #print "Got state %r" % state
1130
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
97 result = "%.3fs (still running)" % (time.time() - self.timings[timer])
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
98 return result
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
99
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
100 def dump(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
101 outlist = []
1870
9406e02388cf reduce usage of .keys()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
102 for timer in self.timings:
1130
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
103 value = self.value(timer)
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
104 outlist.append("%s = %s" % (timer, value))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
105 outlist.sort()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
106 return outlist
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
107
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
108
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
109 # Utilities
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
110
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
111 def cgiMetaVariable(header, scheme='http'):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
112 """ Return CGI meta variable for header name
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
113
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
114 e.g 'User-Agent' -> 'HTTP_USER_AGENT'
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
115 See http://www.faqs.org/rfcs/rfc3875.html section 4.1.18
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
116 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
117 var = '%s_%s' % (scheme, header)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
118 return var.upper().replace('-', '_')
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
119
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
120
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
121 # Request Base ----------------------------------------------------------
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
122
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
123 class RequestBase(object):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
124 """ A collection for all data associated with ONE request. """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
125
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
126 # Defaults (used by sub classes)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
127 http_accept_language = 'en'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
128 server_name = 'localhost'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
129 server_port = '80'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
130
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
131 # Extra headers we support. Both standalone and twisted store
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
132 # headers as lowercase.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
133 moin_location = 'x-moin-location'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
134 proxy_host = 'x-forwarded-host'
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
135
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
136 def __init__(self, properties={}):
1761
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
137
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
138 # twistd's daemonize() overrides our umask, so we reset it here every
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
139 # request. we do it for all request types to avoid similar problems.
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
140 set_umask()
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
141
2007
6cc2e0544657 add finish handlers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1988
diff changeset
142 self._finishers = []
6cc2e0544657 add finish handlers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1988
diff changeset
143
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
144 self._auth_redirected = False
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
145
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
146 # Decode values collected by sub classes
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
147 self.path_info = self.decodePagename(self.path_info)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
148
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
149 self.failed = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
150 self._available_actions = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
151 self._known_actions = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
152
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
153 # Pages meta data that we collect in one request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
154 self.pages = {}
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
155
2008
52c474b8c02f allow translating things early
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2007
diff changeset
156 self._page_headings = {}
52c474b8c02f allow translating things early
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2007
diff changeset
157
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
158 self.user_headers = []
15
5a2a8201bb6f make moin friendlier to proxies, thanks to ASF
Thomas Waldmann <tw@waldmann-edv.de>
parents: 9
diff changeset
159 self.cacheable = 0 # may this output get cached by http proxies/caches?
1580
1393f9e111f4 cleanup disabling of http caching, avoid usage of no-cache because it breaks attachment download on IE6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1567
diff changeset
160 self.http_caching_disabled = 0 # see disableHttpCaching()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
161 self.page = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
162 self._dicts = None
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
163
1933
19e3af7cabcd change the set user functionality to use the session storage and keep track
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1932
diff changeset
164 # setuid handling requires an attribute in the request
19e3af7cabcd change the set user functionality to use the session storage and keep track
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1932
diff changeset
165 # that stores the real user
19e3af7cabcd change the set user functionality to use the session storage and keep track
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1932
diff changeset
166 self._setuid_real_user = None
19e3af7cabcd change the set user functionality to use the session storage and keep track
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1932
diff changeset
167
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
168 # Check for dumb proxy requests
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
169 # TODO relying on request_uri will not work on all servers, especially
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
170 # not on external non-Apache servers
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
171 self.forbidden = False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
172 if self.request_uri.startswith('http://'):
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
173 self.makeForbidden403()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
174
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
175 # Init
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
176 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
177 self.writestack = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
178 self.clock = Clock()
1130
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
179 self.clock.start('total')
1131
67044a2a0224 add some more timers, fix wrong path in i18n_init
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1130
diff changeset
180 self.clock.start('base__init__')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
181 # order is important here!
397
1a7f4e1f3e4d Fixed MoinMoinBugs/ RewritingAndCookieUrl/
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 393
diff changeset
182 self.__dict__.update(properties)
1567
2e1aff91a0a5 use 404 instead of ConfigurationError when no config is matched for some URL
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1557
diff changeset
183 try:
2e1aff91a0a5 use 404 instead of ConfigurationError when no config is matched for some URL
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1557
diff changeset
184 self._load_multi_cfg()
2e1aff91a0a5 use 404 instead of ConfigurationError when no config is matched for some URL
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1557
diff changeset
185 except error.NoConfigMatchedError:
2e1aff91a0a5 use 404 instead of ConfigurationError when no config is matched for some URL
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1557
diff changeset
186 self.makeForbidden(404, 'No wiki configuration matching the URL found!\r\n')
2e1aff91a0a5 use 404 instead of ConfigurationError when no config is matched for some URL
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1557
diff changeset
187 return
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
188
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
189 self.isSpiderAgent = self.check_spider()
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
190
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
191 # Set decode charsets. Input from the user is always in
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
192 # config.charset, which is the page charsets. Except
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
193 # path_info, which may use utf-8, and handled by decodePagename.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
194 self.decode_charsets = [config.charset]
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
195
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
196 if self.query_string.startswith('action=xmlrpc'):
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
197 self.args = {}
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
198 self.form = {}
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
199 self.action = 'xmlrpc'
1682
30116d7d098a request.rev is either revision integer (when given in form) or None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1666
diff changeset
200 self.rev = None
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
201 else:
305
5ed08461ab7d trying to fix xmlrpc not working on cgi due to setup_args call eating POST data
Thomas Waldmann <tw@waldmann-edv.de>
parents: 298
diff changeset
202 self.args = self.form = self.setup_args()
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
203 self.action = self.form.get('action', ['show'])[0]
1682
30116d7d098a request.rev is either revision integer (when given in form) or None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1666
diff changeset
204 try:
30116d7d098a request.rev is either revision integer (when given in form) or None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1666
diff changeset
205 self.rev = int(self.form['rev'][0])
30116d7d098a request.rev is either revision integer (when given in form) or None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1666
diff changeset
206 except:
30116d7d098a request.rev is either revision integer (when given in form) or None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1666
diff changeset
207 self.rev = None
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
208
1618
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1595
diff changeset
209 from MoinMoin.Page import RootPage
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1595
diff changeset
210 self.rootpage = RootPage(self)
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1595
diff changeset
211
1857
659070e5e4d3 introduce request.editlog and use it for ItemCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1816
diff changeset
212 from MoinMoin.logfile import editlog
659070e5e4d3 introduce request.editlog and use it for ItemCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1816
diff changeset
213 self.editlog = editlog.EditLog(self)
659070e5e4d3 introduce request.editlog and use it for ItemCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1816
diff changeset
214
688
15c55ecd7ccb fix some i18n bugs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 684
diff changeset
215 from MoinMoin import i18n
15c55ecd7ccb fix some i18n bugs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 684
diff changeset
216 self.i18n = i18n
15c55ecd7ccb fix some i18n bugs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 684
diff changeset
217 i18n.i18n_init(self)
15c55ecd7ccb fix some i18n bugs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 684
diff changeset
218
2008
52c474b8c02f allow translating things early
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2007
diff changeset
219 # authentication might require translated forms, so
52c474b8c02f allow translating things early
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2007
diff changeset
220 # have a try at guessing the language from the browser
52c474b8c02f allow translating things early
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2007
diff changeset
221 lang = i18n.requestLanguage(self, try_user=False)
52c474b8c02f allow translating things early
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2007
diff changeset
222 self.getText = lambda text, i18n=self.i18n, request=self, lang=lang, **kv: i18n.getText(text, request, lang, kv.get('formatted', True))
52c474b8c02f allow translating things early
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2007
diff changeset
223
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
224 # session handler start, auth
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
225 self.parse_cookie()
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
226 user_obj = self.cfg.session_handler.start(self, self._cookie)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
227 shfinisher = lambda request: self.cfg.session_handler.finish(request, self._cookie, request.user)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
228 self.add_finisher(shfinisher)
2026
5aa49f81db45 finishers: execute only once and make sure request.user is set
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2025
diff changeset
229 # set self.user even if _handle_auth_form raises an Exception
5aa49f81db45 finishers: execute only once and make sure request.user is set
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2025
diff changeset
230 self.user = None
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
231 self.user = self._handle_auth_form(user_obj)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
232 del user_obj
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
233 self.cfg.session_handler.after_auth(self, self._cookie, self.user)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
234 if not self.user:
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
235 self.user = user.User(self, auth_method='request:invalid')
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
236
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
237 # setuid handling, check isSuperUser() because the user
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
238 # might have lost the permission between requests
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
239 if 'setuid' in self.session and self.user.isSuperUser():
1933
19e3af7cabcd change the set user functionality to use the session storage and keep track
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1932
diff changeset
240 self._setuid_real_user = self.user
19e3af7cabcd change the set user functionality to use the session storage and keep track
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1932
diff changeset
241 uid = self.session['setuid']
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
242 self.user = user.User(self, uid, auth_method='setuid')
2369
ccf996479233 fix a suid bug: force switched-to user valid
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2299
diff changeset
243 # set valid to True so superusers can even switch
ccf996479233 fix a suid bug: force switched-to user valid
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2299
diff changeset
244 # to disable accounts
ccf996479233 fix a suid bug: force switched-to user valid
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2299
diff changeset
245 self.user.valid = True
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
246
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
247 if self.action != 'xmlrpc':
440
0f07dcad6614 reorderer 1. bot 2. surge protection, add sleep time for forbidden requests, add surge prot. value for recall action
Thomas Waldmann <tw@waldmann-edv.de>
parents: 434
diff changeset
248 if not self.forbidden and self.isForbidden():
0f07dcad6614 reorderer 1. bot 2. surge protection, add sleep time for forbidden requests, add surge prot. value for recall action
Thomas Waldmann <tw@waldmann-edv.de>
parents: 434
diff changeset
249 self.makeForbidden403()
0f07dcad6614 reorderer 1. bot 2. surge protection, add sleep time for forbidden requests, add surge prot. value for recall action
Thomas Waldmann <tw@waldmann-edv.de>
parents: 434
diff changeset
250 if not self.forbidden and self.surge_protect():
406
0ff631c36afb surge protection: use userid of logged in users, reorder surge-log entry format, fix error handling
Thomas Waldmann <tw@waldmann-edv.de>
parents: 405
diff changeset
251 self.makeUnavailable503()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
252
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
253 self.pragma = {}
1595
3a63c9b31d7e avoid infinite recursion in parsePageLinks
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1590
diff changeset
254 self.mode_getpagelinks = 0 # is > 0 as long as we are in a getPageLinks call
3a63c9b31d7e avoid infinite recursion in parsePageLinks
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1590
diff changeset
255 self.parsePageLinks_running = {} # avoid infinite recursion by remembering what we are already running
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
256
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
257 self.lang = i18n.requestLanguage(self)
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
258 # Language for content. Page content should use the wiki default lang,
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
259 # but generated content like search results should use the user language.
131
1738cbba372c new cfg settings: language_ignore_browser and language_default (was: default_lang)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
260 self.content_lang = self.cfg.language_default
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
261 self.getText = lambda text, i18n=self.i18n, request=self, lang=self.lang, **kv: i18n.getText(text, request, lang, kv.get('formatted', True))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
262
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
263 self.reset()
2217
f8dcc3232e8b move html_formatter creation to RequestBase.__init__ so it also works for CLI requests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2208
diff changeset
264
f8dcc3232e8b move html_formatter creation to RequestBase.__init__ so it also works for CLI requests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2208
diff changeset
265 from MoinMoin.formatter.text_html import Formatter
f8dcc3232e8b move html_formatter creation to RequestBase.__init__ so it also works for CLI requests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2208
diff changeset
266 self.html_formatter = Formatter(self)
f8dcc3232e8b move html_formatter creation to RequestBase.__init__ so it also works for CLI requests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2208
diff changeset
267 self.formatter = self.html_formatter
f8dcc3232e8b move html_formatter creation to RequestBase.__init__ so it also works for CLI requests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2208
diff changeset
268
1131
67044a2a0224 add some more timers, fix wrong path in i18n_init
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1130
diff changeset
269 self.clock.stop('base__init__')
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
270
1553
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
271 def surge_protect(self, kick_him=False):
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
272 """ check if someone requesting too much from us,
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
273 if kick_him is True, we unconditionally blacklist the current user/ip
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
274 """
1245
5b6031179fef allow disabling surge protection by surge_action_limits = None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1183
diff changeset
275 limits = self.cfg.surge_action_limits
5b6031179fef allow disabling surge protection by surge_action_limits = None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1183
diff changeset
276 if not limits:
5b6031179fef allow disabling surge protection by surge_action_limits = None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1183
diff changeset
277 return False
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
278
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
279 validuser = self.user.valid
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
280 current_id = validuser and self.user.name or self.remote_addr
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
281 if not validuser and current_id.startswith('127.'): # localnet
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
282 return False
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
283 current_action = self.action
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
284
420
b4ff26eb2c43 adjusting some surge protection limits
Thomas Waldmann <tw@waldmann-edv.de>
parents: 412
diff changeset
285 default_limit = self.cfg.surge_action_limits.get('default', (30, 60))
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
286
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
287 now = int(time.time())
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
288 surgedict = {}
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
289 surge_detected = False
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
290
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
291 try:
682
1314fdb74689 refactor CacheEntry usage to use scope param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 640
diff changeset
292 # if we have common farm users, we could also use scope='farm':
2239
0232aa023881 fixed encoding/decoding for surge-log data, fixes leftoever surge-logXXXXX.tmp files in data/cache/surgeprotect (ported from 1.5 changeset 817: 4b9425f89248)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2217
diff changeset
293 cache = caching.CacheEntry(self, 'surgeprotect', 'surge-log', scope='wiki', use_encode=True)
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
294 if cache.exists():
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
295 data = cache.content()
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
296 data = data.split("\n")
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
297 for line in data:
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
298 try:
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
299 id, t, action, surge_indicator = line.split("\t")
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
300 t = int(t)
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
301 maxnum, dt = limits.get(action, default_limit)
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
302 if t >= now - dt:
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
303 events = surgedict.setdefault(id, copy.copy({}))
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
304 timestamps = events.setdefault(action, copy.copy([]))
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
305 timestamps.append((t, surge_indicator))
1805
ebcebba1afb3 removed some unused attributes, used 'dummy' for dummies
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1801
diff changeset
306 except StandardError:
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
307 pass
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
308
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
309 maxnum, dt = limits.get(current_action, default_limit)
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
310 events = surgedict.setdefault(current_id, copy.copy({}))
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
311 timestamps = events.setdefault(current_action, copy.copy([]))
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
312 surge_detected = len(timestamps) > maxnum
441
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
313
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
314 surge_indicator = surge_detected and "!" or ""
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
315 timestamps.append((now, surge_indicator))
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
316 if surge_detected:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
317 if len(timestamps) < maxnum * 2:
441
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
318 timestamps.append((now + self.cfg.surge_lockout_time, surge_indicator)) # continue like that and get locked out
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
319
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
320 if current_action != 'AttachFile': # don't add AttachFile accesses to all or picture galleries will trigger SP
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
321 current_action = 'all' # put a total limit on user's requests
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
322 maxnum, dt = limits.get(current_action, default_limit)
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
323 events = surgedict.setdefault(current_id, copy.copy({}))
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
324 timestamps = events.setdefault(current_action, copy.copy([]))
1553
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
325
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
326 if kick_him: # ban this guy, NOW
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
327 timestamps.extend([(now + self.cfg.surge_lockout_time, "!")] * (2*maxnum))
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
328
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
329 surge_detected = surge_detected or len(timestamps) > maxnum
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
330
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
331 surge_indicator = surge_detected and "!" or ""
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
332 timestamps.append((now, surge_indicator))
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
333 if surge_detected:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
334 if len(timestamps) < maxnum * 2:
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
335 timestamps.append((now + self.cfg.surge_lockout_time, surge_indicator)) # continue like that and get locked out
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
336
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
337 data = []
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
338 for id, events in surgedict.items():
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
339 for action, timestamps in events.items():
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
340 for t, surge_indicator in timestamps:
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
341 data.append("%s\t%d\t%s\t%s" % (id, t, action, surge_indicator))
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
342 data = "\n".join(data)
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
343 cache.update(data)
1805
ebcebba1afb3 removed some unused attributes, used 'dummy' for dummies
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1801
diff changeset
344 except StandardError:
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
345 pass
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
346
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
347 return surge_detected
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
348
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
349 def getDicts(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
350 """ Lazy initialize the dicts on the first access """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
351 if self._dicts is None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
352 from MoinMoin import wikidicts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
353 dicts = wikidicts.GroupDict(self)
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2239
diff changeset
354 dicts.load_dicts()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
355 self._dicts = dicts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
356 return self._dicts
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
357
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
358 def delDicts(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
359 """ Delete the dicts, used by some tests """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
360 del self._dicts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
361 self._dicts = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
362
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
363 dicts = property(getDicts, None, delDicts)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
364
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
365 def _load_multi_cfg(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
366 # protect against calling multiple times
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
367 if not hasattr(self, 'cfg'):
1130
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
368 self.clock.start('load_multi_cfg')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
369 self.cfg = multiconfig.getConfig(self.url)
1130
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
370 self.clock.stop('load_multi_cfg')
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
371
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
372 def setAcceptedCharsets(self, accept_charset):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
373 """ Set accepted_charsets by parsing accept-charset header
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
374
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
375 Set self.accepted_charsets to an ordered list based on http_accept_charset.
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
376
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
377 Reference: http://www.w3.org/Protocols/rfc2616/rfc2616.txt
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
378
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
379 TODO: currently no code use this value.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
380
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
381 @param accept_charset: accept-charset header
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
382 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
383 charsets = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
384 if accept_charset:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
385 accept_charset = accept_charset.lower()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
386 # Add iso-8859-1 if needed
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
387 if (not '*' in accept_charset and
1183
bc84eae93f8c replace usage of find by 'in' operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1149
diff changeset
388 'iso-8859-1' not in accept_charset):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
389 accept_charset += ',iso-8859-1'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
390
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
391 # Make a list, sorted by quality value, using Schwartzian Transform
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
392 # Create list of tuples (value, name) , sort, extract names
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
393 for item in accept_charset.split(','):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
394 if ';' in item:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
395 name, qval = item.split(';')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
396 qval = 1.0 - float(qval.split('=')[1])
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
397 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
398 name, qval = item, 0
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
399 charsets.append((qval, name))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
400 charsets.sort()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
401 # Remove *, its not clear what we should do with it later
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
402 charsets = [name for qval, name in charsets if name != '*']
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
403
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
404 self.accepted_charsets = charsets
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
405
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
406 def _setup_vars_from_std_env(self, env):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
407 """ Set common request variables from CGI environment
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
408
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
409 Parse a standard CGI environment as created by common web servers.
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
410 Reference: http://www.faqs.org/rfcs/rfc3875.html
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
411
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
412 @param env: dict like object containing cgi meta variables
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
413 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
414 # Values we can just copy
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
415 self.env = env
1116
4aae51ce0172 support if-modified-since and if-none-match for Twisted, Standalone and CLI, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1113
diff changeset
416 self.http_accept_language = env.get('HTTP_ACCEPT_LANGUAGE', self.http_accept_language)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
417 self.server_name = env.get('SERVER_NAME', self.server_name)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
418 self.server_port = env.get('SERVER_PORT', self.server_port)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
419 self.saved_cookie = env.get('HTTP_COOKIE', '')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
420 self.script_name = env.get('SCRIPT_NAME', '')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
421 self.path_info = env.get('PATH_INFO', '')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
422 self.query_string = env.get('QUERY_STRING', '')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
423 self.request_method = env.get('REQUEST_METHOD', None)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
424 self.remote_addr = env.get('REMOTE_ADDR', '')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
425 self.http_user_agent = env.get('HTTP_USER_AGENT', '')
1116
4aae51ce0172 support if-modified-since and if-none-match for Twisted, Standalone and CLI, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1113
diff changeset
426 self.if_modified_since = env.get('If-modified-since') or env.get(cgiMetaVariable('If-modified-since'))
4aae51ce0172 support if-modified-since and if-none-match for Twisted, Standalone and CLI, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1113
diff changeset
427 self.if_none_match = env.get('If-none-match') or env.get(cgiMetaVariable('If-none-match'))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
428
298
6c74345f4d55 cleaned up and moved moin's cookie stuff to auth.moin_cookie
Thomas Waldmann <tw@waldmann-edv.de>
parents: 295
diff changeset
429 # REQUEST_URI is not part of CGI spec, but an addition of Apache.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
430 self.request_uri = env.get('REQUEST_URI', '')
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
431
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
432 # Values that need more work
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
433 self.setHttpReferer(env.get('HTTP_REFERER'))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
434 self.setIsSSL(env)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
435 self.setHost(env.get('HTTP_HOST'))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
436 self.fixURI(env)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
437 self.setURL(env)
1113
9485500daadf read if-modified-since and if-none-match headers, first use for rss_rc action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1103
diff changeset
438 #self.debugEnvironment(env)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
439
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
440 def setHttpReferer(self, referer):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
441 """ Set http_referer, making sure its ascii
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
442
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
443 IE might send non-ascii value.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
444 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
445 value = ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
446 if referer:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
447 value = unicode(referer, 'ascii', 'replace')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
448 value = value.encode('ascii', 'replace')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
449 self.http_referer = value
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
450
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
451 def setIsSSL(self, env):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
452 """ Set is_ssl
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
453
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
454 @param env: dict like object containing cgi meta variables
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
455 """
149
c5b967d9d1e6 fixed MoinMoinBugs/TypeErrorOnHttpsPageChangeEmail
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
456 self.is_ssl = bool(env.get('SSL_PROTOCOL') or
c5b967d9d1e6 fixed MoinMoinBugs/TypeErrorOnHttpsPageChangeEmail
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
457 env.get('SSL_PROTOCOL_VERSION') or
c5b967d9d1e6 fixed MoinMoinBugs/TypeErrorOnHttpsPageChangeEmail
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
458 env.get('HTTPS') == 'on')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
459
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
460 def setHost(self, host=None):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
461 """ Set http_host
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
462
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
463 Create from server name and port if missing. Previous code
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
464 default to localhost.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
465 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
466 if not host:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
467 port = ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
468 standardPort = ('80', '443')[self.is_ssl]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
469 if self.server_port != standardPort:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
470 port = ':' + self.server_port
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
471 host = self.server_name + port
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
472 self.http_host = host
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
473
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
474 def fixURI(self, env):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
475 """ Fix problems with script_name and path_info
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
476
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
477 Handle the strange charset semantics on Windows and other non
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
478 posix systems. path_info is transformed into the system code
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
479 page by the web server. Additionally, paths containing dots let
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
480 most webservers choke.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
481
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
482 Broken environment variables in different environments:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
483 path_info script_name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
484 Apache1 X X PI does not contain dots
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
485 Apache2 X X PI is not encoded correctly
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
486 IIS X X path_info include script_name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
487 Other ? - ? := Possible and even RFC-compatible.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
488 - := Hopefully not.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
489
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
490 @param env: dict like object containing cgi meta variables
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
491 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
492 # Fix the script_name when using Apache on Windows.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
493 server_software = env.get('SERVER_SOFTWARE', '')
1183
bc84eae93f8c replace usage of find by 'in' operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1149
diff changeset
494 if os.name == 'nt' and 'Apache/' in server_software:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
495 # Removes elements ending in '.' from the path.
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
496 self.script_name = '/'.join([x for x in self.script_name.split('/')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
497 if not x.endswith('.')])
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
498
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
499 # Fix path_info
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
500 if os.name != 'posix' and self.request_uri != '':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
501 # Try to recreate path_info from request_uri.
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 85
diff changeset
502 import urlparse
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
503 scriptAndPath = urlparse.urlparse(self.request_uri)[2]
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
504 path = scriptAndPath.replace(self.script_name, '', 1)
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 85
diff changeset
505 self.path_info = wikiutil.url_unquote(path, want_unicode=False)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
506 elif os.name == 'nt':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
507 # Recode path_info to utf-8
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
508 path = wikiutil.decodeWindowsPath(self.path_info)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
509 self.path_info = path.encode("utf-8")
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
510
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
511 # Fix bug in IIS/4.0 when path_info contain script_name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
512 if self.path_info.startswith(self.script_name):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
513 self.path_info = self.path_info[len(self.script_name):]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
514
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
515 def setURL(self, env):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
516 """ Set url, used to locate wiki config
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
517
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
518 This is the place to manipulate url parts as needed.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
519
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
520 @param env: dict like object containing cgi meta variables or http headers.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
521 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
522 # If we serve on localhost:8000 and use a proxy on
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
523 # example.com/wiki, our urls will be example.com/wiki/pagename
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
524 # Same for the wiki config - they must use the proxy url.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
525 self.rewriteHost(env)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
526 self.rewriteURI(env)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
527
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
528 if not self.request_uri:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
529 self.request_uri = self.makeURI()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
530 self.url = self.http_host + self.request_uri
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
531
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
532 def rewriteHost(self, env):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
533 """ Rewrite http_host transparently
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
534
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
535 Get the proxy host using 'X-Forwarded-Host' header, added by
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
536 Apache 2 and other proxy software.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
537
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
538 TODO: Will not work for Apache 1 or others that don't add this header.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
539
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
540 TODO: If we want to add an option to disable this feature it
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
541 should be in the server script, because the config is not
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
542 loaded at this point, and must be loaded after url is set.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
543
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
544 @param env: dict like object containing cgi meta variables or http headers.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
545 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
546 proxy_host = (env.get(self.proxy_host) or
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
547 env.get(cgiMetaVariable(self.proxy_host)))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
548 if proxy_host:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
549 self.http_host = proxy_host
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
550
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
551 def rewriteURI(self, env):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
552 """ Rewrite request_uri, script_name and path_info transparently
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
553
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
554 Useful when running mod python or when running behind a proxy,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
555 e.g run on localhost:8000/ and serve as example.com/wiki/.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
556
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
557 Uses private 'X-Moin-Location' header to set the script name.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
558 This allow setting the script name when using Apache 2
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
559 <location> directive::
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
560
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
561 <Location /my/wiki/>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
562 RequestHeader set X-Moin-Location /my/wiki/
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
563 </location>
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
564
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
565 TODO: does not work for Apache 1 and others that do not allow
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
566 setting custom headers per request.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
567
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
568 @param env: dict like object containing cgi meta variables or http headers.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
569 """
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
570 location = (env.get(self.moin_location) or
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
571 env.get(cgiMetaVariable(self.moin_location)))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
572 if location is None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
573 return
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
574
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
575 scriptAndPath = self.script_name + self.path_info
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
576 location = location.rstrip('/')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
577 self.script_name = location
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
578
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
579 # This may happen when using mod_python
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
580 if scriptAndPath.startswith(location):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
581 self.path_info = scriptAndPath[len(location):]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
582
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
583 # Recreate the URI from the modified parts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
584 if self.request_uri:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
585 self.request_uri = self.makeURI()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
586
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
587 def makeURI(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
588 """ Return uri created from uri parts """
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 85
diff changeset
589 uri = self.script_name + wikiutil.url_quote(self.path_info)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
590 if self.query_string:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
591 uri += '?' + self.query_string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
592 return uri
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
593
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
594 def splitURI(self, uri):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
595 """ Return path and query splited from uri
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
596
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
597 Just like CGI environment, the path is unquoted, the query is not.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
598 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
599 if '?' in uri:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
600 path, query = uri.split('?', 1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
601 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
602 path, query = uri, ''
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
603 return wikiutil.url_unquote(path, want_unicode=False), query
456
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
604
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
605 def _handle_auth_form(self, user_obj):
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
606 username = self.form.get('name', [None])[0]
295
91d47ebee530 make posted UserPreferences form values easily available for auth methods
Thomas Waldmann <tw@waldmann-edv.de>
parents: 290
diff changeset
607 password = self.form.get('password', [None])[0]
2299
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
608 oid = self.form.get('openid_identifier', [None])[0]
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1857
diff changeset
609 login = 'login' in self.form
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1857
diff changeset
610 logout = 'logout' in self.form
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
611 stage = self.form.get('stage', [None])[0]
2030
00f52826b5df allow unattended login (for xmlrpc)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2029
diff changeset
612 return self.handle_auth(user_obj, attended=True, username=username,
00f52826b5df allow unattended login (for xmlrpc)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2029
diff changeset
613 password=password, login=login, logout=logout,
2299
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
614 stage=stage, openid_identifier=oid)
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
615
2030
00f52826b5df allow unattended login (for xmlrpc)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2029
diff changeset
616 def handle_auth(self, user_obj, attended=False, **kw):
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
617 username = kw.get('username')
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
618 password = kw.get('password')
2299
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
619 oid = kw.get('openid_identifier')
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
620 login = kw.get('login')
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
621 logout = kw.get('logout')
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
622 stage = kw.get('stage')
2040
68e302934c77 add cookie back to auth keyword arguments
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2030
diff changeset
623 extra = {
68e302934c77 add cookie back to auth keyword arguments
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2030
diff changeset
624 'cookie': self._cookie,
68e302934c77 add cookie back to auth keyword arguments
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2030
diff changeset
625 }
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
626 if login:
2030
00f52826b5df allow unattended login (for xmlrpc)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2029
diff changeset
627 extra['attended'] = attended
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
628 extra['username'] = username
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
629 extra['password'] = password
2299
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
630 extra['openid_identifier'] = oid
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
631 if stage:
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
632 extra['multistage'] = True
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
633 login_msgs = []
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
634 self._login_multistage = None
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
635
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
636 if logout and 'setuid' in self.session:
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
637 del self.session['setuid']
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
638 return user_obj
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
639
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
640 for authmethod in self.cfg.auth:
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
641 if logout:
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
642 user_obj, cont = authmethod.logout(self, user_obj, **extra)
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
643 elif login:
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
644 if stage and authmethod.name != stage:
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
645 continue
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
646 ret = authmethod.login(self, user_obj, **extra)
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
647 user_obj = ret.user_obj
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
648 cont = ret.continue_flag
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
649 if stage:
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
650 stage = None
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
651 del extra['multistage']
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
652 if ret.multistage:
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
653 self._login_multistage = ret.multistage
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
654 self._login_multistage_name = authmethod.name
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
655 return user_obj
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
656 if ret.redirect_to:
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
657 nextstage = auth.get_multistage_continuation_url(self, authmethod.name)
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
658 url = ret.redirect_to
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
659 url = url.replace('%return_form', quote_plus(nextstage))
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
660 url = url.replace('%return', quote(nextstage))
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
661 self._auth_redirected = True
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
662 self.http_redirect(url)
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
663 return user_obj
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
664 msg = ret.message
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
665 if msg and not msg in login_msgs:
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
666 login_msgs.append(msg)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
667 else:
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
668 user_obj, cont = authmethod.request(self, user_obj, **extra)
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
669 if not cont:
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
670 break
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
671
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
672 self._login_messages = login_msgs
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
673 return user_obj
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
674
2122
69412724ce93 Make it possible to get an auth token using jid and shared secret.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2040
diff changeset
675 def handle_jid_auth(self, jid):
69412724ce93 Make it possible to get an auth token using jid and shared secret.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2040
diff changeset
676 return user.get_by_jabber_id(self, jid)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
677
1931
7f87f9d0159e move cookie parsing to request and pass the cookie object (or None) to the
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1918
diff changeset
678 def parse_cookie(self):
7f87f9d0159e move cookie parsing to request and pass the cookie object (or None) to the
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1918
diff changeset
679 try:
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
680 self._cookie = Cookie.SimpleCookie(self.saved_cookie)
1931
7f87f9d0159e move cookie parsing to request and pass the cookie object (or None) to the
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1918
diff changeset
681 except Cookie.CookieError:
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
682 self._cookie = None
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
683
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
684 def reset(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
685 """ Reset request state.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
686
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
687 Called after saving a page, before serving the updated
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
688 page. Solves some practical problems with request state
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
689 modified during saving.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
690
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
691 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
692 # This is the content language and has nothing to do with
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
693 # The user interface language. The content language can change
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
694 # during the rendering of a page by lang macros
131
1738cbba372c new cfg settings: language_ignore_browser and language_default (was: default_lang)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
695 self.current_lang = self.cfg.language_default
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
696
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
697 # caches unique ids
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
698 self._page_ids = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
699 # keeps track of pagename/heading combinations
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
700 # parsers should use this dict and not a local one, so that
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
701 # macros like TableOfContents in combination with Include can work
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
702 self._page_headings = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
703
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
704 if hasattr(self, "_fmt_hd_counters"):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
705 del self._fmt_hd_counters
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
706
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
707 def loadTheme(self, theme_name):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
708 """ Load the Theme to use for this request.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
709
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
710 @param theme_name: the name of the theme
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
711 @type theme_name: str
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
712 @rtype: int
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
713 @return: success code
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 483
diff changeset
714 0 on success
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 483
diff changeset
715 1 if user theme could not be loaded,
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 483
diff changeset
716 2 if a hard fallback to modern theme was required.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
717 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
718 fallback = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
719 if theme_name == "<default>":
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
720 theme_name = self.cfg.theme_default
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
721
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 49
diff changeset
722 try:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
723 Theme = wikiutil.importPlugin(self.cfg, 'theme', theme_name, 'Theme')
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
724 except wikiutil.PluginMissingError:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
725 fallback = 1
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 49
diff changeset
726 try:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
727 Theme = wikiutil.importPlugin(self.cfg, 'theme', self.cfg.theme_default, 'Theme')
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
728 except wikiutil.PluginMissingError:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
729 fallback = 2
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
730 from MoinMoin.theme.modern import Theme
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
731
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
732 self.theme = Theme(self)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
733 return fallback
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
734
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
735 def setContentLanguage(self, lang):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
736 """ Set the content language, used for the content div
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
737
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
738 Actions that generate content in the user language, like search,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
739 should set the content direction to the user language before they
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
740 call send_title!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
741 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
742 self.content_lang = lang
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
743 self.current_lang = lang
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
744
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
745 def getPragma(self, key, defval=None):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
746 """ Query a pragma value (#pragma processing instruction)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
747
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
748 Keys are not case-sensitive.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
749 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
750 return self.pragma.get(key.lower(), defval)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
751
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
752 def setPragma(self, key, value):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
753 """ Set a pragma value (#pragma processing instruction)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
754
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
755 Keys are not case-sensitive.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
756 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
757 self.pragma[key.lower()] = value
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
758
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
759 def getPathinfo(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
760 """ Return the remaining part of the URL. """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
761 return self.path_info
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
762
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
763 def getScriptname(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
764 """ Return the scriptname part of the URL ('/path/to/my.cgi'). """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
765 if self.script_name == '/':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
766 return ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
767 return self.script_name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
768
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
769 def getKnownActions(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
770 """ Create a dict of avaiable actions
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
771
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
772 Return cached version if avaiable.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
773
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
774 @rtype: dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
775 @return: dict of all known actions
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
776 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
777 try:
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1549
diff changeset
778 self.cfg.cache.known_actions # check
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
779 except AttributeError:
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 623
diff changeset
780 from MoinMoin import action
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1549
diff changeset
781 self.cfg.cache.known_actions = set(action.getNames(self.cfg))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
782
1132
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1131
diff changeset
783 # Return a copy, so clients will not change the set.
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1549
diff changeset
784 return self.cfg.cache.known_actions.copy()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
785
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
786 def getAvailableActions(self, page):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
787 """ Get list of avaiable actions for this request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
788
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
789 The dict does not contain actions that starts with lower case.
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
790 Themes use this dict to display the actions to the user.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
791
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
792 @param page: current page, Page object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
793 @rtype: dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
794 @return: dict of avaiable actions
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
795 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
796 if self._available_actions is None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
797 # Add actions for existing pages only, including deleted pages.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
798 # Fix *OnNonExistingPage bugs.
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
799 if not (page.exists(includeDeleted=1) and self.user.may.read(page.page_name)):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
800 return []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
801
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
802 # Filter non ui actions (starts with lower case letter)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
803 actions = self.getKnownActions()
1132
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1131
diff changeset
804 actions = [action for action in actions if not action[0].islower()]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
805
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
806 # Filter wiki excluded actions
1132
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1131
diff changeset
807 actions = [action for action in actions if not action in self.cfg.actions_excluded]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
808
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
809 # Filter actions by page type, acl and user state
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
810 excluded = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
811 if ((page.isUnderlayPage() and not page.isStandardPage()) or
236
81620fd76cac fix minor UI bug: DeletePage/RenamePage was shown active in menu although user missed delete rights. We also stop checking for user.valid as this should be driven by ACLs only.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 158
diff changeset
812 not self.user.may.write(page.page_name) or
81620fd76cac fix minor UI bug: DeletePage/RenamePage was shown active in menu although user missed delete rights. We also stop checking for user.valid as this should be driven by ACLs only.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 158
diff changeset
813 not self.user.may.delete(page.page_name)):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
814 # Prevent modification of underlay only pages, or pages
236
81620fd76cac fix minor UI bug: DeletePage/RenamePage was shown active in menu although user missed delete rights. We also stop checking for user.valid as this should be driven by ACLs only.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 158
diff changeset
815 # the user can't write and can't delete
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
816 excluded = [u'RenamePage', u'DeletePage', ] # AttachFile must NOT be here!
1132
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1131
diff changeset
817 actions = [action for action in actions if not action in excluded]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
818
1132
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1131
diff changeset
819 self._available_actions = set(actions)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
820
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
821 # Return a copy, so clients will not change the dict.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
822 return self._available_actions.copy()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
823
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
824 def redirectedOutput(self, function, *args, **kw):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
825 """ Redirect output during function, return redirected output """
1986
3475126f78c6 fix some builtin names used as attribute names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
826 buf = StringIO.StringIO()
3475126f78c6 fix some builtin names used as attribute names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
827 self.redirect(buf)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
828 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
829 function(*args, **kw)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
830 finally:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
831 self.redirect()
1986
3475126f78c6 fix some builtin names used as attribute names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
832 text = buf.getvalue()
3475126f78c6 fix some builtin names used as attribute names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
833 buf.close()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
834 return text
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
835
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
836 def redirect(self, file=None):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
837 """ Redirect output to file, or restore saved output """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
838 if file:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
839 self.writestack.append(self.write)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
840 self.write = file.write
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
841 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
842 self.write = self.writestack.pop()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
843
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
844 def reset_output(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
845 """ restore default output method
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
846 destroy output stack
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
847 (useful for error messages)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
848 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
849 if self.writestack:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
850 self.write = self.writestack[0]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
851 self.writestack = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
852
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
853 def log(self, msg):
1585
a843bc5793fb introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1580
diff changeset
854 """ Log msg to logging framework """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
855 msg = msg.strip()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
856 # Encode unicode msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
857 if isinstance(msg, unicode):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
858 msg = msg.encode(config.charset)
1585
a843bc5793fb introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1580
diff changeset
859 logging.info(msg)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
860
2208
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
861 def timing_log(self, start, action):
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
862 """ Log to timing log (for performance analysis) """
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
863 indicator = ''
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
864 if start:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
865 total = "vvv"
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
866 else:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
867 self.clock.stop('total') # make sure it is stopped
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
868 total_secs = self.clock.timings['total']
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
869 # we add some stuff that is easy to grep when searching for peformance problems:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
870 if total_secs > 50:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
871 indicator += '!4!'
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
872 elif total_secs > 20:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
873 indicator += '!3!'
2208
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
874 elif total_secs > 10:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
875 indicator += '!2!'
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
876 elif total_secs > 2:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
877 indicator += '!1!'
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
878 total = self.clock.value('total')
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
879 # use + for existing pages, - for non-existing pages
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
880 indicator += self.page.exists() and '+' or '-'
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
881 if self.isSpiderAgent:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
882 indicator += "B"
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
883
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
884 # Add time stamp and process ID
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
885 pid = os.getpid()
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
886 t = time.time()
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
887 timestr = time.strftime("%Y%m%d %H%M%S", time.gmtime(t))
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
888 msg = '%s %5d %-6s %4s %-10s %s\n' % (timestr, pid, total, indicator, action, self.url)
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
889 self.log(msg)
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
890
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
891 def write(self, *data):
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 615
diff changeset
892 """ Write to output stream. """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
893 raise NotImplementedError
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
894
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
895 def encode(self, data):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
896 """ encode data (can be both unicode strings and strings),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
897 preparing for a single write()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
898 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
899 wd = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
900 for d in data:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
901 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
902 if isinstance(d, unicode):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
903 # if we are REALLY sure, we can use "strict"
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
904 d = d.encode(config.charset, 'replace')
1398
fe8facfcb439 avoid trouble when write data contains None, just skip it - thanks to Juergen Hermann for patch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1339
diff changeset
905 elif d is None:
fe8facfcb439 avoid trouble when write data contains None, just skip it - thanks to Juergen Hermann for patch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1339
diff changeset
906 continue
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
907 wd.append(d)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
908 except UnicodeError:
910
1730c8e75ade use self.log instead stderr in request
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 909
diff changeset
909 self.log("Unicode error on: %s" % repr(d))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
910 return ''.join(wd)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
911
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
912 def decodePagename(self, name):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
913 """ Decode path, possibly using non ascii characters
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
914
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
915 Does not change the name, only decode to Unicode.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
916
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
917 First split the path to pages, then decode each one. This enables
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
918 us to decode one page using config.charset and another using
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
919 utf-8. This situation happens when you try to add to a name of
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
920 an existing page.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
921
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
922 See http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.2.1
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
923
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
924 @param name: page name, string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
925 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
926 @return decoded page name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
927 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
928 # Split to pages and decode each one
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
929 pages = name.split('/')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
930 decoded = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
931 for page in pages:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
932 # Recode from utf-8 into config charset. If the path
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
933 # contains user typed parts, they are encoded using 'utf-8'.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
934 if config.charset != 'utf-8':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
935 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
936 page = unicode(page, 'utf-8', 'strict')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
937 # Fit data into config.charset, replacing what won't
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
938 # fit. Better have few "?" in the name than crash.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
939 page = page.encode(config.charset, 'replace')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
940 except UnicodeError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
941 pass
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
942
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
943 # Decode from config.charset, replacing what can't be decoded.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
944 page = unicode(page, config.charset, 'replace')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
945 decoded.append(page)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
946
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
947 # Assemble decoded parts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
948 name = u'/'.join(decoded)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
949 return name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
950
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
951 def normalizePagename(self, name):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
952 """ Normalize page name
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
953
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
954 Prevent creating page names with invisible characters or funny
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
955 whitespace that might confuse the users or abuse the wiki, or
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
956 just does not make sense.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
957
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
958 Restrict even more group pages, so they can be used inside acl lines.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
959
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
960 @param name: page name, unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
961 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
962 @return: decoded and sanitized page name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
963 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
964 # Strip invalid characters
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
965 name = config.page_invalid_chars_regex.sub(u'', name)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
966
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
967 # Split to pages and normalize each one
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
968 pages = name.split(u'/')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
969 normalized = []
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
970 for page in pages:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
971 # Ignore empty or whitespace only pages
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
972 if not page or page.isspace():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
973 continue
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
974
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
975 # Cleanup group pages.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
976 # Strip non alpha numeric characters, keep white space
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
977 if wikiutil.isGroupPage(self, page):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
978 page = u''.join([c for c in page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
979 if c.isalnum() or c.isspace()])
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
980
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
981 # Normalize white space. Each name can contain multiple
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
982 # words separated with only one space. Split handle all
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
983 # 30 unicode spaces (isspace() == True)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
984 page = u' '.join(page.split())
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
985
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
986 normalized.append(page)
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
987
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
988 # Assemble components into full pagename
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
989 name = u'/'.join(normalized)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
990 return name
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
991
1988
dbf2b7426385 fixed some pylint warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1986
diff changeset
992 def read(self, n=None):
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 615
diff changeset
993 """ Read n bytes from input stream. """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
994 raise NotImplementedError
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
995
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
996 def flush(self):
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 615
diff changeset
997 """ Flush output stream. """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
998 raise NotImplementedError
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
999
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
1000 def check_spider(self):
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
1001 """ check if the user agent for current request is a spider/bot """
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
1002 isSpider = False
1549
e36313297589 introduce request.cfg.cache object, start using it for some precompiled regexes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1541
diff changeset
1003 ua = self.getUserAgent()
1557
60067807cf9a Allow empty strings for ua_spiders.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1553
diff changeset
1004 if ua and self.cfg.cache.ua_spiders:
1549
e36313297589 introduce request.cfg.cache object, start using it for some precompiled regexes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1541
diff changeset
1005 isSpider = self.cfg.cache.ua_spiders.search(ua) is not None
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
1006 return isSpider
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
1007
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1008 def isForbidden(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1009 """ check for web spiders and refuse anything except viewing """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1010 forbidden = 0
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
1011 # we do not have a parsed query string here, so we can just do simple matching
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
1012 qs = self.query_string
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
1013 action = self.action
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
1014 if ((qs != '' or self.request_method != 'GET') and
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
1015 action != 'rss_rc' and
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1016 # allow spiders to get attachments and do 'show'
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
1017 not (action == 'AttachFile' and 'do=get' in qs) and
1666
debeeba5cce6 allow sitemap action for spiders
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1657
diff changeset
1018 action != 'show' and
debeeba5cce6 allow sitemap action for spiders
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1657
diff changeset
1019 action != 'sitemap'
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1020 ):
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
1021 forbidden = self.isSpiderAgent
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1022
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1023 if not forbidden and self.cfg.hosts_deny:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1024 ip = self.remote_addr
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1025 for host in self.cfg.hosts_deny:
441
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
1026 if host[-1] == '.' and ip.startswith(host):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1027 forbidden = 1
441
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
1028 #self.log("hosts_deny (net): %s" % str(forbidden))
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
1029 break
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
1030 if ip == host:
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
1031 forbidden = 1
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
1032 #self.log("hosts_deny (ip): %s" % str(forbidden))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1033 break
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1034 return forbidden
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1035
1012
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
1036 def setup_args(self):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
1037 """ Return args dict
623
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
1038 First, we parse the query string (usually this is used in GET methods,
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
1039 but TwikiDraw uses ?action=AttachFile&do=savedrawing plus posted stuff).
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
1040 Second, we update what we got in first step by the stuff we get from
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
1041 the form (or by a POST). We invoke _setup_args_from_cgi_form to handle
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
1042 possible file uploads.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1043 """
623
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
1044 args = cgi.parse_qs(self.query_string, keep_blank_values=1)
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
1045 args = self.decodeArgs(args)
1012
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
1046 # if we have form data (in a POST), those override the stuff we already have:
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
1047 if self.request_method == 'POST':
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
1048 postargs = self._setup_args_from_cgi_form()
623
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
1049 args.update(postargs)
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
1050 return args
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1051
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1052 def _setup_args_from_cgi_form(self, form=None):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1053 """ Return args dict from a FieldStorage
1012
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
1054
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
1055 Create the args from a given form. Each key contain a list of values.
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
1056 This method usually gets overridden in classes derived from this - it
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
1057 is their task to call this method with an appropriate form parameter.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1058
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 483
diff changeset
1059 @param form: a cgi.FieldStorage
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1060 @rtype: dict
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 483
diff changeset
1061 @return: dict with form keys, each contains a list of values
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1062 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1063 args = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1064 for key in form:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1065 values = form[key]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1066 if not isinstance(values, list):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1067 values = [values]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1068 fixedResult = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1069 for item in values:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1070 fixedResult.append(item.value)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1071 if isinstance(item, cgi.FieldStorage) and item.filename:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1072 # Save upload file name in a separate key
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
1073 args[key + '__filename__'] = item.filename
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1074 args[key] = fixedResult
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
1075
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1076 return self.decodeArgs(args)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1077
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1078 def decodeArgs(self, args):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
1079 """ Decode args dict
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
1080
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1081 Decoding is done in a separate path because it is reused by
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1082 other methods and sub classes.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1083 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1084 decode = wikiutil.decodeUserInput
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1085 result = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1086 for key in args:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1087 if key + '__filename__' in args:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1088 # Copy file data as is
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1089 result[key] = args[key]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1090 elif key.endswith('__filename__'):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1091 result[key] = decode(args[key], self.decode_charsets)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1092 else:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
1093 result[key] = [decode(value, self.decode_charsets) for value in args[key]]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1094 return result
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1095
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1096 def getBaseURL(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1097 """ Return a fully qualified URL to this script. """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1098 return self.getQualifiedURL(self.getScriptname())
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1099
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1100 def getQualifiedURL(self, uri=''):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1101 """ Return an absolute URL starting with schema and host.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1102
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1103 Already qualified urls are returned unchanged.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1104
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
1105 @param uri: server rooted uri e.g /scriptname/pagename.
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
1106 It must start with a slash. Must be ascii and url encoded.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1107 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1108 import urlparse
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1109 scheme = urlparse.urlparse(uri)[0]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1110 if scheme:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1111 return uri
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1112
481
285b42d58a45 minor change: fixed some typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 462
diff changeset
1113 scheme = ('http', 'https')[self.is_ssl]
285b42d58a45 minor change: fixed some typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 462
diff changeset
1114 result = "%s://%s%s" % (scheme, self.http_host, uri)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1115
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1116 # This might break qualified urls in redirects!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1117 # e.g. mapping 'http://netloc' -> '/'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1118 return wikiutil.mapURL(self, result)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1119
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1120 def getUserAgent(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1121 """ Get the user agent. """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1122 return self.http_user_agent
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1123
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1124 def makeForbidden(self, resultcode, msg):
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1125 statusmsg = {
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
1126 401: 'Authorization required',
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1127 403: 'FORBIDDEN',
1567
2e1aff91a0a5 use 404 instead of ConfigurationError when no config is matched for some URL
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1557
diff changeset
1128 404: 'Not found',
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1129 503: 'Service unavailable',
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1130 }
984
311492a91530 add a Retry-After header for 503 result code (surge protection)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 944
diff changeset
1131 headers = [
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1132 'Status: %d %s' % (resultcode, statusmsg[resultcode]),
1067
5bf357a720e7 deprecated setResponseCode method, replaced by emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1064
diff changeset
1133 'Content-Type: text/plain; charset=utf-8'
984
311492a91530 add a Retry-After header for 503 result code (surge protection)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 944
diff changeset
1134 ]
311492a91530 add a Retry-After header for 503 result code (surge protection)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 944
diff changeset
1135 # when surge protection triggered, tell bots to come back later...
311492a91530 add a Retry-After header for 503 result code (surge protection)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 944
diff changeset
1136 if resultcode == 503:
311492a91530 add a Retry-After header for 503 result code (surge protection)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 944
diff changeset
1137 headers.append('Retry-After: %d' % self.cfg.surge_lockout_time)
1061
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1138 self.emit_http_headers(headers)
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1139 self.write(msg)
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1140 self.forbidden = True
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1141
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1142 def makeForbidden403(self):
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1143 self.makeForbidden(403, 'You are not allowed to access this!\r\n')
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1144
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1145 def makeUnavailable503(self):
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1146 self.makeForbidden(503, "Warning:\r\n"
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1147 "You triggered the wiki's surge protection by doing too many requests in a short time.\r\n"
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1148 "Please make a short break reading the stuff you already got.\r\n"
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1149 "When you restart doing requests AFTER that, slow down or you might get locked out for a longer time!\r\n")
250
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1150
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1151 def initTheme(self):
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1152 """ Set theme - forced theme, user theme or wiki default """
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1153 if self.cfg.theme_force:
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1154 theme_name = self.cfg.theme_default
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1155 else:
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1156 theme_name = self.user.theme_name
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1157 self.loadTheme(theme_name)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
1158
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1159 def run(self):
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1160 # Exit now if __init__ failed or request is forbidden
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
1161 if self.failed or self.forbidden or self._auth_redirected:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
1162 # Don't sleep() here, it binds too much of our resources!
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1163 return self.finish()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1164
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1165 _ = self.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1166 self.clock.start('run')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1167
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1168 from MoinMoin.Page import Page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1169
2124
005938143378 Initialize theme eariler, so that it works with xmlrpc getPageHTML
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2122
diff changeset
1170 self.initTheme()
005938143378 Initialize theme eariler, so that it works with xmlrpc getPageHTML
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2122
diff changeset
1171
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
1172 action_name = self.action
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
1173 if action_name == 'xmlrpc':
637
35f0f8584a57 move wikirpc.py to xmlrpc/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 636
diff changeset
1174 from MoinMoin import xmlrpc
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
1175 if self.query_string == 'action=xmlrpc':
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
1176 xmlrpc.xmlrpc(self)
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
1177 elif self.query_string == 'action=xmlrpc2':
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
1178 xmlrpc.xmlrpc2(self)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1179 return self.finish()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1180
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1181 # parse request data
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1182 try:
2208
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
1183 if self.cfg.log_timing:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
1184 self.timing_log(True, action)
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
1185
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1186 # The last component in path_info is the page name, if any
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1187 path = self.getPathinfo()
1339
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1188
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1189 # we can have all action URLs like this: /action/ActionName/PageName?action=ActionName&...
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1190 # this is just for robots.txt being able to forbid them for crawlers
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1191 prefix = self.cfg.url_prefix_action
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1192 if prefix is not None:
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1193 prefix = '/%s/' % prefix # e.g. '/action/'
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1194 if path.startswith(prefix):
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1195 # remove prefix and action name
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1196 path = path[len(prefix):]
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1197 action, path = path.split('/', 1)
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1198 path = '/' + path
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1199
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1200 if path.startswith('/'):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1201 pagename = self.normalizePagename(path)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1202 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1203 pagename = None
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1204
941
16f7b6728b4e move vary: header code to request module and fix it (multiple headers of same type don't work!)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
1205 # need to inform caches that content changes based on:
16f7b6728b4e move vary: header code to request module and fix it (multiple headers of same type don't work!)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
1206 # * cookie (even if we aren't sending one now)
16f7b6728b4e move vary: header code to request module and fix it (multiple headers of same type don't work!)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
1207 # * User-Agent (because a bot might be denied and get no content)
16f7b6728b4e move vary: header code to request module and fix it (multiple headers of same type don't work!)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
1208 # * Accept-Language (except if moin is told to ignore browser language)
16f7b6728b4e move vary: header code to request module and fix it (multiple headers of same type don't work!)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
1209 if self.cfg.language_ignore_browser:
944
7c8e8d370740 use comma-separated Vary header items
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 942
diff changeset
1210 self.setHttpHeader("Vary: Cookie,User-Agent")
941
16f7b6728b4e move vary: header code to request module and fix it (multiple headers of same type don't work!)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
1211 else:
944
7c8e8d370740 use comma-separated Vary header items
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 942
diff changeset
1212 self.setHttpHeader("Vary: Cookie,User-Agent,Accept-Language")
941
16f7b6728b4e move vary: header code to request module and fix it (multiple headers of same type don't work!)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
1213
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1214 # Handle request. We have these options:
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
1215 # 1. jump to page where user left off
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
1216 if not pagename and self.user.remember_last_visit:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1217 pagetrail = self.user.getTrail()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1218 if pagetrail:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1219 # Redirect to last page visited
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1220 if ":" in pagetrail[-1]:
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
1221 wikitag, wikiurl, wikitail, error = wikiutil.resolve_wiki(self, pagetrail[-1])
57
546541209681 fix remember_last_visit(ed page) root url redirect
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
1222 url = wikiurl + wikiutil.quoteWikinameURL(wikitail)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1223 else:
1816
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
1224 url = Page(self, pagetrail[-1]).url(self, relative=False)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1225 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1226 # Or to localized FrontPage
1816
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
1227 url = wikiutil.getFrontPage(self).url(self, relative=False)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1228 self.http_redirect(url)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1229 return self.finish()
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
1230
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
1231 # 2. handle action
614
95fb435b72aa refactor: use show action when no action is given
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 613
diff changeset
1232 else:
95fb435b72aa refactor: use show action when no action is given
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 613
diff changeset
1233 # pagename could be empty after normalization e.g. '///' -> ''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1234 # Use localized FrontPage if pagename is empty
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1235 if not pagename:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1236 self.page = wikiutil.getFrontPage(self)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1237 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1238 self.page = Page(self, pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1239
1013
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1240 msg = None
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1241 # Complain about unknown actions
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 623
diff changeset
1242 if not action_name in self.getKnownActions():
1013
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1243 msg = _("Unknown action %(action_name)s.") % {
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1244 'action_name': wikiutil.escape(action_name), }
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1245
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1246 # Disallow non available actions
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 623
diff changeset
1247 elif action_name[0].isupper() and not action_name in self.getAvailableActions(self.page):
1013
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1248 msg = _("You are not allowed to do %(action_name)s on this page.") % {
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1249 'action_name': wikiutil.escape(action_name), }
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1250 if not self.user.valid:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1251 # Suggest non valid user to login
613
1ba2c3686e98 more comment and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 612
diff changeset
1252 msg += " " + _("Login and try again.", formatted=0)
1013
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1253
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1254 if msg:
1789
8da1d5df4b90 send_page: remove some more call's request param (see cs 1777)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1784
diff changeset
1255 self.page.send_page(msg=msg)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1256
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1257 # Try action
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1258 else:
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 623
diff changeset
1259 from MoinMoin import action
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 623
diff changeset
1260 handler = action.getHandler(self, action_name)
1541
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1261 if handler is None:
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1262 msg = _("You are not allowed to do %(action_name)s on this page.") % {
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1263 'action_name': wikiutil.escape(action_name), }
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1264 if not self.user.valid:
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1265 # Suggest non valid user to login
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1266 msg += " " + _("Login and try again.", formatted=0)
1789
8da1d5df4b90 send_page: remove some more call's request param (see cs 1777)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1784
diff changeset
1267 self.page.send_page(msg=msg)
1541
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1268 else:
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1269 handler(self.page.page_name, self)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1270
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
1271 # every action that didn't use to raise MoinMoinFinish must call this now:
617
cf420addd95c removed MoinMoinNoFooter at many places, added call to theme.send_closing_html() where needed
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 616
diff changeset
1272 # self.theme.send_closing_html()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1273
618
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
1274 except MoinMoinFinish:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1275 pass
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1276 except Exception, err:
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
1277 self.finish()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1278 self.fail(err)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1279
2208
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
1280 if self.cfg.log_timing:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
1281 self.timing_log(False, action)
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
1282
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1283 return self.finish()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1284
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1285 def http_redirect(self, url):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1286 """ Redirect to a fully qualified, or server-rooted URL
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
1287
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1288 @param url: relative or absolute url, ascii using url encoding.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1289 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1290 url = self.getQualifiedURL(url)
1061
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1291 self.emit_http_headers(["Status: 302 Found", "Location: %s" % url])
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1292
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1293 def emit_http_headers(self, more_headers=[]):
1064
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1294 """ emit http headers after some preprocessing / checking
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1295
1103
fe874e9e72c7 fix comments in emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1102
diff changeset
1296 Makes sure we only emit headers once.
1064
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1297 Encodes to ASCII if it gets unicode headers.
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1298 Make sure we have exactly one Content-Type and one Status header.
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1299 Make sure Status header string begins with a integer number.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
1300
1064
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1301 For emitting, it calls the server specific _emit_http_headers
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1302 method.
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1303
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1304 @param more_headers: list of additional header strings
1061
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1305 """
1073
a6bb4df3888d fix http headers bug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1071
diff changeset
1306 user_headers = getattr(self, 'user_headers', [])
1071
64e513264aed cleanup, less header logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1070
diff changeset
1307 self.user_headers = []
1073
a6bb4df3888d fix http headers bug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1071
diff changeset
1308 all_headers = more_headers + user_headers
1071
64e513264aed cleanup, less header logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1070
diff changeset
1309
1061
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1310 # Send headers only once
1070
054a3d3d8dfe fix http headers for edit, RenamePage, DeletePage action, raise exception when http_headers is called multiple times
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1067
diff changeset
1311 sent_headers = getattr(self, 'sent_headers', 0)
1699
66f2ea899da7 fckdialog action: don't call emit_http_headers twice, fix wrong attribute name in emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1312