From d91ac1188db88d7b0739bb409329bd31be01bd0c Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Tue, 29 May 2018 17:28:58 +0200 Subject: [PATCH] trying to access moin moin data --- honeypot/__init__.py | 72 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/honeypot/__init__.py b/honeypot/__init__.py index 6da5de1..51da4a4 100644 --- a/honeypot/__init__.py +++ b/honeypot/__init__.py @@ -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): 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):