"""
Show verbose server/client information.
From boodebr.appspot.com. May be freely used and modified for any purpose.
"""
import cherrypy
import wsgiref.handlers
import sys, os
from cherrypy.lib.static import serve_file
def unknown():
return "Unknown"
def makeinfo(args, kwargs):
h = ''
h += '
Request info'
h += '
'
# headers['Remote-Addr'] doesn't work in some environments
h += '| Remote IP | %s |
' % cherrypy.request.remote.ip
h += '| Remote port | %s |
' % cherrypy.request.remote.port
h += '| Browser | %s |
' % cherrypy.request.headers['User-Agent']
h += '| Request | %s |
' % cherrypy.request.request_line
h += '| args | %s |
' % str(args)
h += '| kwargs | %s |
' % str(kwargs)
h += '
'
h += 'Headers (cherrypy.request.headers)
'
h += ''
# use header_list instead of headers so that I can see any duplicate keys
for k,v in cherrypy.request.header_list:
h += '| %s | %s |
' % (k,v)
h += '
'
h += 'cherrypy.request.config
'
h += ''
for k,v in cherrypy.request.config.items():
h += '| %s | %s |
' % (k,v)
h += '
'
h += 'WSGI environment (cherrypy.request.wsgi_environ)
'
h += ''
for k,v in cherrypy.request.wsgi_environ.items():
h += '| %s | %s |
' % (k,v)
h += '
'
h += 'CherryPy Server (cherrypy.server)
'
h += ''
for k,v in cherrypy.server.__dict__.items():
h += '| %s | %s |
' % (k,v)
h += '
'
h += 'Host environment'
h += '
'
h += '| Python version | %s |
' % sys.version
h += '| CherryPy version | %s |
' % cherrypy.__version__
h += '| Server command | %s |
' % (' '.join(sys.argv))
h += '| os.getcwd() | %s |
' % os.getcwd()
h += '| OS/Platform | %s/%s |
' % (os.name,sys.platform)
f = getattr(os, 'uname', unknown)
h += '| os.uname() | %s |
' % str(f())
h += '
'
h += 'Environment variables (os.environ)
'
h += ''
for k,v in os.environ.items():
h += '| %s | %s |
' % (k,v)
h += '
'
h += ''
return h
class Root:
def index(self):
return makeinfo((),{})
index.exposed = True
def default(self, *args, **kwargs):
return makeinfo(args, kwargs)
default.exposed = True
def source(self):
buf = open(os.path.abspath(__file__)).read()
cherrypy.response.headers['Content-Type'] = 'text/plain'
return buf
source.exposed = True
#---------------------------------------------------------------------------
# Start the server under Google AppEngine
#---------------------------------------------------------------------------
# IMPORTANT! Make sure to mount at "/infodump" to match my actual URL.
app = cherrypy.tree.mount(Root(), "/infodump")
wsgiref.handlers.CGIHandler().run(app)