print_env.py

Go to the documentation of this file.
00001 import sys
00002 import re
00003 import os
00004 import pwd
00005 import cgi
00006 import socket
00007 
00008 __copyright__ = """\
00009 (c). Copyright 1990-2008, Vyper Logix Corp., 
00010 
00011                    All Rights Reserved.
00012 
00013 Published under Creative Commons License 
00014 (http://creativecommons.org/licenses/by-nc/3.0/) 
00015 restricted to non-commercial educational use only., 
00016 
00017 See also: http://www.VyperLogix.com and http://www.pypi.info for details.
00018 
00019 THE AUTHOR VYPER LOGIX CORP DISCLAIMS ALL WARRANTIES WITH REGARD TO
00020 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
00021 FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
00022 INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
00023 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
00024 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
00025 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE !
00026 
00027 USE AT YOUR OWN RISK.
00028 """
00029 
00030 def print_env():
00031     print 'Content-type: text/html; charset=utf-8\n\n'
00032 
00033     print '<h2>Environment</h2>'
00034     print '<table cellpadding="1" cellspacing="1">'
00035     keys = os.environ.keys()
00036     keys.sort()
00037     for env in keys:
00038         print '<tr>'
00039         print '<th align="left">', env, '</th>'
00040         print '<td>', (os.environ[env] or "&lt;EMPTY&gt;"), '</td>'
00041         print '</tr>'
00042     print "</table>"
00043     print ''
00044 
00045     form = cgi.FieldStorage()
00046     print '<h2>Form Fields</h2>'
00047     if len(form) == 0:
00048         print "<p>No form fields given."
00049     else:
00050         print '<table cellpadding="1" cellspacing="1">'
00051         keys = form.keys()
00052         keys.sort()
00053         for var in keys:
00054             print '<tr>'
00055             print '<th align="left">', var, '</th>'
00056             print '<td>',
00057             x = form[var]
00058             if isinstance(type(x), list):
00059                 x = map(getattr, x, ["value"]*len(x))
00060                 print ", ".join(x),
00061             elif x.file:
00062                 print "(filename: %s, length: %d)" % (x.filename, len(x.value)),
00063             else:
00064                 x, punt, encoding = decode(x.value)
00065                 if isinstance(x, unicode):
00066                     x = x.encode("utf-8")
00067                 print x, "(encoding: %s)"% encoding
00068             print '</td>'
00069             print '</tr>'
00070         print '</table>'
00071 
00072     print '<h2>Compiled-in Python Modules</h2>'
00073     modules = list(sys.builtin_module_names)
00074     modules.sort()
00075     print '<p>'
00076     for i in range(0, len(modules), 8):
00077         print '   ', ", ".join(modules[i:i+8])
00078     print '</p>'
00079 
00080     print '<h2>Modules Currently Loaded</h2>'
00081     modules = sys.modules.keys()
00082     modules.sort()
00083     print '<p>'
00084     print ", ".join(modules)
00085     print '</p>'
00086 
00087     print '<h2>User Information</h2>'
00088     print '<table cellpadding="1" cellspacing="1">'
00089     print '<tr>'
00090     print '<th align="left">User ID</th>',
00091     print '<td>', os.getuid(), '</td>'
00092     print '</tr>'
00093     print '<tr>'
00094     print '<th align="left">Group ID</th>',
00095     print '<td>', os.getgid(), '</td>'
00096     print '</tr>'
00097     print '<tr>'
00098     print '<th align="left">Effective User ID</th>',
00099     print '<td>', os.geteuid(), '</td>'
00100     print '</tr>'
00101     print '<tr>'
00102     print '<th align="left">Effective Group ID</th>',
00103     print '<td>', os.getegid(), '</td>'
00104     print '</tr>'
00105     print '</table>'
00106 
00107     print '<h2>Machine Information</h2>'
00108     print '<table cellpadding="1" cellspacing="1">'
00109     print '<tr>'
00110     print '<th align="left">True Hostname</th>',
00111     print '<td>', socket.gethostbyaddr(socket.gethostbyname(socket.gethostname())), '</td>'
00112     print '<tr>'
00113     print '<th align="left">Virtual Hostname</th>',
00114     print '<td>', socket.gethostbyaddr(socket.gethostbyname(os.environ['SERVER_NAME'])), '</td>'
00115     print '</tr>'
00116     print '</table>'
00117 
00118 if (__name__ == '__main__'):
00119     import sys
00120     print >>sys.stdout, __copyright__
00121     print >>sys.stderr, __copyright__
00122 
00123 

© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved; If you reference this document or any part of this document you must use the citation verbatim (including the link) "© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved."

Notice: This source code contained in this document is NOT open source and is NOT being distributed as open source.

122,241 lines of code and growing...