|
|
|
@ -1,4 +1,6 @@
@@ -1,4 +1,6 @@
|
|
|
|
|
import pprint |
|
|
|
|
import os |
|
|
|
|
import pickle |
|
|
|
|
import re |
|
|
|
|
|
|
|
|
|
from collections import OrderedDict |
|
|
|
|
from pyramid.config import Configurator |
|
|
|
@ -22,6 +24,74 @@ def _dict_helper(dict_like):
@@ -22,6 +24,74 @@ def _dict_helper(dict_like):
|
|
|
|
|
return [' %s: %s' % (k, v) for k, v in dict_like.items()] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def raw_wiki_definition(line): |
|
|
|
|
for quote in ('"', "'"): |
|
|
|
|
parts = line.split(quote) |
|
|
|
|
if len(parts) == 5: |
|
|
|
|
return parts |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_moin_wikis(request): |
|
|
|
|
moin_config_path = '/var/www/moin/config/farmconfig.py' |
|
|
|
|
wiki_definitions = [] |
|
|
|
|
with open(moin_config_path, 'r') as fh: |
|
|
|
|
for line in fh: |
|
|
|
|
if line.startwith('wikis = [') |
|
|
|
|
break |
|
|
|
|
for line in fh: |
|
|
|
|
if ']' in line: |
|
|
|
|
return wiki_definitions |
|
|
|
|
parts = raw_wiki_definition(line) |
|
|
|
|
if parts is None: |
|
|
|
|
continue |
|
|
|
|
_, wiki_name, _, wiki_url, _ = parts |
|
|
|
|
wiki_definitions.append( (wiki_name, wiki_url) ) |
|
|
|
|
return wiki_definitions |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_wiki_name(request, wiki_definitions): |
|
|
|
|
for wiki_name, wiki_url in wiki_definitions: |
|
|
|
|
if re.match(wiki_url, request.url): |
|
|
|
|
return wiki_name |
|
|
|
|
|
|
|
|
|
def get_session_dir(request, wiki_definitions): |
|
|
|
|
base_path = '/var/www/moin/wikis' |
|
|
|
|
wiki_name = get_wiki_name(request, wiki_definitions) |
|
|
|
|
sub_path = 'data/cache/__session__' |
|
|
|
|
return os.path.join(base_path, wiki_name, sub_path) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_session_path(request, wiki_definitions): |
|
|
|
|
session_dir = get_session_dir(request, wiki_definitions) |
|
|
|
|
for key, value in request.cookies.items(): |
|
|
|
|
if key.lower().startswith('moin'): |
|
|
|
|
session_path = os.path.join(sesssion_dir, value) |
|
|
|
|
if os.path.is_file(session_path): |
|
|
|
|
return session_path |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
def get_moin_user_id(request, wiki_definitions): |
|
|
|
|
session_path = get_session_path(request, wiki_definitions) |
|
|
|
|
if session_path is not None: |
|
|
|
|
with open(session_path, 'rb') as fh |
|
|
|
|
session_data = pickle.load(fh) |
|
|
|
|
return session_data.get('user.id') |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_moin_user_name(request, wiki_definitions): |
|
|
|
|
user_id = get_moin_user_id(request, wiki_definitions) |
|
|
|
|
path = os.path.join('/var/www/moin/wikis/cpi/data/user', user_id) |
|
|
|
|
with open(path, 'r') as fh: |
|
|
|
|
if line.startwith('email='): |
|
|
|
|
email = line.split('=', 1)[1] |
|
|
|
|
if line.statswith('name='): |
|
|
|
|
name = line.split('=', 1)[1] |
|
|
|
|
return email, name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@view_config(context=RootResource) |
|
|
|
|
def the_view(context, request): |
|
|
|
|
|
|
|
|
|