Example #1
0
 def get_public_list(self, hide_insecure=False):
     """Return a list of publicly available information about the
     configuration.  This list is safe to share because dangerous keys
     are either hidden or cloaked.
     """
     from pyClanSphere.database import secure_database_uri
     result = []
     for key, field in self.config_vars.iteritems():
         value = self[key]
         if hide_insecure:
             if key in HIDDEN_KEYS:
                 value = '****'
             elif key == 'database_uri':
                 value = repr(secure_database_uri(value))
             else:
                 for sender, rv in signals.cloak_insecure_configuration_var.send(
                         key=key, value=value):
                     if rv is not None:
                         value = rv
                         break
                 else:
                     value = repr(value)
         else:
             value = repr(value)
         result.append({
             'key':          key,
             'default':      repr(field.get_default()),
             'value':        value
         })
     result.sort(key=lambda x: x['key'].lower())
     return result
Example #2
0
def information(request):
    """Shows some details about this pyClanSphere installation.  It's useful for
    debugging and checking configurations.  If severe errors in a pyClanSphere
    installation occur it's a good idea to dump this page and attach it to
    a bug report mail.
    """
    from platform import platform
    from sys import version as python_version
    from threading import activeCount
    from jinja2.defaults import DEFAULT_NAMESPACE, DEFAULT_FILTERS
    from pyClanSphere import environment, __version__ as pyClanSphere_version

    export = request.args.get('do') == 'export'
    database_uri = request.app.cfg['database_uri']
    if export:
        database_uri = secure_database_uri(database_uri)

    content_types = {}
    for name, funcs in request.app.admin_content_type_handlers.iteritems():
        if name in content_types:
            for action, func in funcs.iteritems():
                content_types[name][action] = get_object_name(func)
    content_types = sorted(content_types.values(), key=lambda x: x['name'])

    response = render_admin_response('admin/information.html', 'system.information',
        apis=[{
            'name':         name,
            'clan_id':      clan_id,
            'preferred':    preferred,
            'endpoint':     endpoint
        } for name, (clan_id, preferred, endpoint) in request.app.apis.iteritems()],
        endpoints=[{
            'name':         rule.endpoint,
            'rule':         unicode(rule)
        } for rule in sorted(request.app.url_map._rules, key=lambda x: x.endpoint)],
        views=sorted([{
            'endpoint':     endpoint,
            'handler':      get_object_name(view)
        } for endpoint, view
            in request.app.views.iteritems()], key=lambda x: x['endpoint']),
        absolute_url_handlers=[get_object_name(handler) for handler
                               in request.app._absolute_url_handlers],
        content_types=content_types,
        privileges=request.app.list_privileges(),
        servicepoints=sorted([{
            'name':         name,
            'handler':      get_object_name(service)
        } for name, service in request.app._services.iteritems()],
            key=lambda x: x['name']),
        configuration=request.app.cfg.get_public_list(export),
        hosting_env={
            'persistent':       not request.is_run_once,
            'multithreaded':    request.is_multithread,
            'thread_count':     activeCount(),
            'multiprocess':     request.is_multiprocess,
            'wsgi_version':     '.'.join(map(str, request.environ['wsgi.version']))
        },
        plugins=sorted(request.app.plugins.values(), key=lambda x: not x.active and x.name),
        python_version='<br>'.join(map(escape, python_version.splitlines())),
        pyClanSphere_env=environment,
        pyClanSphere_version=pyClanSphere_version,
        template_globals=[name for name, obj in
                          sorted(request.app.template_env.globals.items())
                          if name not in DEFAULT_NAMESPACE],
        template_filters=[name for name, obj in
                          sorted(request.app.template_env.filters.items())
                          if name not in DEFAULT_FILTERS],
        instance_path=request.app.instance_folder,
        database_uri=database_uri,
        platform=platform(),
        export=export
    )

    if export:
        response.headers['Content-Disposition'] = 'attachment; ' \
            'filename="pyClanSphere-environment.html"'

    return response