|
|
|
@ -26,6 +26,7 @@ class RootResource:
@@ -26,6 +26,7 @@ class RootResource:
|
|
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
|
def pre_init(cls, moin_config_dir): |
|
|
|
|
''' parses the moinmoin farmconfig file ''' |
|
|
|
|
cls.moin_config_dir = moin_config_dir |
|
|
|
|
moin_farmconfig = os.path.join(moin_config_dir, 'farmconfig.py') |
|
|
|
|
encoding = utils.guess_encoding(moin_farmconfig) |
|
|
|
@ -34,7 +35,9 @@ class RootResource:
@@ -34,7 +35,9 @@ class RootResource:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_moin_user(self): |
|
|
|
|
email, name = '', '' |
|
|
|
|
''' returns a name and email address of the current wiki user''' |
|
|
|
|
name, email = '<unknown user>', '<unknown email>' |
|
|
|
|
try: |
|
|
|
|
moin_data_dir = self._get_wiki_data_dir() |
|
|
|
|
moin_session_dir = os.path.join( |
|
|
|
|
moin_data_dir, |
|
|
|
@ -49,9 +52,12 @@ class RootResource:
@@ -49,9 +52,12 @@ class RootResource:
|
|
|
|
|
email = line.split('=', 1)[1] |
|
|
|
|
if line.startswith('name='): |
|
|
|
|
name = line.split('=', 1)[1] |
|
|
|
|
except: |
|
|
|
|
pass |
|
|
|
|
return name, email |
|
|
|
|
|
|
|
|
|
def _get_wiki_data_dir(self): |
|
|
|
|
''' get the data directory by parsing a wiki config ''' |
|
|
|
|
wiki_name = self._get_wiki_name() |
|
|
|
|
wiki_config = os.path.join(self.moin_config_dir, wiki_name + '.py') |
|
|
|
|
encoding = utils.guess_encoding(wiki_config) |
|
|
|
@ -60,17 +66,20 @@ class RootResource:
@@ -60,17 +66,20 @@ class RootResource:
|
|
|
|
|
return data_dir |
|
|
|
|
|
|
|
|
|
def _get_wiki_name(self): |
|
|
|
|
''' return the internal wiki name for a url ''' |
|
|
|
|
for name, re_url in self.moin_wiki_defs: |
|
|
|
|
if re.match(re_url, self.request.url): |
|
|
|
|
return name |
|
|
|
|
|
|
|
|
|
def _get_user_id(self, session_dir): |
|
|
|
|
''' extract the user id from the session store ''' |
|
|
|
|
session_path = self._get_session_path(session_dir) |
|
|
|
|
with open(session_path, 'rb') as fh: |
|
|
|
|
session_data = pickle.load(fh) |
|
|
|
|
return session_data.get('user.id') |
|
|
|
|
|
|
|
|
|
def _get_session_path(self, session_dir): |
|
|
|
|
''' get the path to the session store for a given cookie ''' |
|
|
|
|
for key, value in self.request.cookies.items(): |
|
|
|
|
if key.lower().startswith('moin'): |
|
|
|
|
session_path = os.path.join(session_dir, value) |
|
|
|
@ -81,38 +90,30 @@ class RootResource:
@@ -81,38 +90,30 @@ class RootResource:
|
|
|
|
|
|
|
|
|
|
@view_config(context=RootResource) |
|
|
|
|
def the_view(context, request): |
|
|
|
|
''' the one and only view for the app ''' |
|
|
|
|
|
|
|
|
|
name, email = context.get_moin_user() |
|
|
|
|
|
|
|
|
|
body = [ |
|
|
|
|
'Someone Wanted Some Sweet Honey', |
|
|
|
|
'-------------------------------', |
|
|
|
|
'', |
|
|
|
|
'wiki user: %s (%s)' % (name, email), |
|
|
|
|
'', |
|
|
|
|
'requested url: %s' % request.url, |
|
|
|
|
'request method: %s' % request.method, |
|
|
|
|
'client ip address: %s' % request.client_addr, |
|
|
|
|
'remote ip address: %s' % request.remote_addr, |
|
|
|
|
'', |
|
|
|
|
'request.authorization: %s' % request.authorization, |
|
|
|
|
'request.remote_user: %s' % request.remote_user, |
|
|
|
|
'', |
|
|
|
|
'headers:' |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
body.extend(utils.dict_helper(request.headers)) |
|
|
|
|
|
|
|
|
|
body.extend(['', 'cookies:']) |
|
|
|
|
if request.cookies: |
|
|
|
|
body.extend(utils.dict_helper(request.cookies)) |
|
|
|
|
else: |
|
|
|
|
body.append(' (no cookies)') |
|
|
|
|
|
|
|
|
|
name, email = context.get_moin_user() |
|
|
|
|
if email or name: |
|
|
|
|
body.extend(['', 'MoinMoin user: %s (%s)' % (name, email) ]) |
|
|
|
|
headers = [' %s: %s' % (k, v) for k, v in request.headers.items()] |
|
|
|
|
body.extend(headers) |
|
|
|
|
|
|
|
|
|
return Response(body='\n'.join(body), content_type='text/plain') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(global_config, **settings): |
|
|
|
|
""" This function returns a Pyramid WSGI application. |
|
|
|
|
""" |
|
|
|
|