|
|
@ -6,6 +6,7 @@ from collections import OrderedDict |
|
|
|
from pyramid.config import Configurator |
|
|
|
from pyramid.config import Configurator |
|
|
|
from pyramid.response import Response |
|
|
|
from pyramid.response import Response |
|
|
|
from pyramid.view import view_config |
|
|
|
from pyramid.view import view_config |
|
|
|
|
|
|
|
from pyramid_mailer.message import Message |
|
|
|
|
|
|
|
|
|
|
|
from . import utils |
|
|
|
from . import utils |
|
|
|
|
|
|
|
|
|
|
@ -15,6 +16,7 @@ class RootResource: |
|
|
|
|
|
|
|
|
|
|
|
moin_config_dir = None |
|
|
|
moin_config_dir = None |
|
|
|
moin_wiki_defs = [] |
|
|
|
moin_wiki_defs = [] |
|
|
|
|
|
|
|
admin_emails = [] |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, request): |
|
|
|
def __init__(self, request): |
|
|
|
''' initialization ''' |
|
|
|
''' initialization ''' |
|
|
@ -25,13 +27,14 @@ class RootResource: |
|
|
|
return self |
|
|
|
return self |
|
|
|
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
@classmethod |
|
|
|
def pre_init(cls, moin_config_dir): |
|
|
|
def configure(cls, settings): |
|
|
|
''' parses the moinmoin farmconfig file ''' |
|
|
|
''' parses the moinmoin farmconfig file ''' |
|
|
|
cls.moin_config_dir = moin_config_dir |
|
|
|
cls.moin_config_dir = settings['moin.config_path'] |
|
|
|
moin_farmconfig = os.path.join(moin_config_dir, 'farmconfig.py') |
|
|
|
moin_farmconfig = os.path.join(cls.moin_config_dir, 'farmconfig.py') |
|
|
|
encoding = utils.guess_encoding(moin_farmconfig) |
|
|
|
encoding = utils.guess_encoding(moin_farmconfig) |
|
|
|
with open(moin_farmconfig, 'r', encoding=encoding) as fh: |
|
|
|
with open(moin_farmconfig, 'r', encoding=encoding) as fh: |
|
|
|
cls.moin_wiki_defs = list(utils.extract_wiki_definitions(fh)) |
|
|
|
cls.moin_wiki_defs = list(utils.extract_wiki_definitions(fh)) |
|
|
|
|
|
|
|
cls.admin_emails = settings['mail.admin_email'].split() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_moin_user(self): |
|
|
|
def get_moin_user(self): |
|
|
@ -111,13 +114,21 @@ def the_view(context, request): |
|
|
|
headers = [' %s: %s' % (k, v) for k, v in request.headers.items()] |
|
|
|
headers = [' %s: %s' % (k, v) for k, v in request.headers.items()] |
|
|
|
body.extend(headers) |
|
|
|
body.extend(headers) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
message = Message( |
|
|
|
|
|
|
|
subject='[wikis]: HoneyPot Link Was Accessed', |
|
|
|
|
|
|
|
sender=event.request.registry.settings['mail.default_sender'], |
|
|
|
|
|
|
|
recipients=context.admin_emails, |
|
|
|
|
|
|
|
body=body |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
request.mailer.send(message) |
|
|
|
|
|
|
|
|
|
|
|
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. |
|
|
|
""" |
|
|
|
""" |
|
|
|
RootResource.pre_init(settings['moin.config_path']) |
|
|
|
RootResource.configure(settings) |
|
|
|
|
|
|
|
|
|
|
|
config = Configurator(settings=settings) |
|
|
|
config = Configurator(settings=settings) |
|
|
|
config.set_root_factory(RootResource) |
|
|
|
config.set_root_factory(RootResource) |
|
|
|