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