from cheshire3.utils import flattenTexts
from cheshire3 import cqlParser
from cheshire3 import internal
from cheshire3 import exceptions as c3errors

cheshirePath = os.environ.get('C3HOME', '/home/cheshire')

session = Session()
session.environment = "apache"
serv = SimpleServer(session, os.path.join(cheshirePath, 'cheshire3', 'configs', 'serverConfig.xml'))

configs = {}

# determine the root URL of this handler

for configitem in apache.config_tree():
    if configitem[0] == "DocumentRoot":
        docRoot = configitem[1].strip("\"'")
handlerUrl = apache.get_handler_root().replace(docRoot, "")


if len(serv.databaseConfigs) < 25:
    # relatively few dbs - we can safely cache them
    serv._cacheDatabases(session)
    for db in serv.databases.itervalues():
        if db.get_setting(session, 'SRW') or db.get_setting(session, 'srw'):
            db._cacheProtocolMaps(session)
            map = db.protocolMaps.get('http://www.loc.gov/zing/srw/', None)
            # check that there's a path and that it can actually be requested from this handler
            if (map is not None) and \
               (map.databaseUrl.startswith((handlerUrl + '/', handlerUrl[1:] + '/'))):
Example #2
0
def handler(req):
    req.form = util.FieldStorage(req)
    
    if req.form.getfirst('view_log'):
        log = file(os.path.join(apache.server_root(),req.server.error_fname),'rb')
        lines = bounded_buffer(100)
        for line in log:
            lines.append(line)
        log.close()
        req.content_type='text/plain'
        for line in lines:
            req.write(line)
        return apache.OK        

    req.add_common_vars()
    req.content_type = 'text/html'
    req.write('<html><head><title>mod_python test page</title></head><body>\n')
    
    req.write('<h3>General information</h3>\n')
    req.write('<table border="1">\n')
    req.write('<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n'%(
        'Apache version',
        req.subprocess_env.get('SERVER_SOFTWARE')
    ))
    req.write('<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n'%(
        'Apache threaded MPM',
        (
            apache.mpm_query(apache.AP_MPMQ_IS_THREADED) and
            'Yes, maximum %i threads / process'%
            apache.mpm_query(apache.AP_MPMQ_MAX_THREADS)
        ) or 'No (single thread MPM)'
    ))
    req.write('<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n'%(
        'Apache forked MPM',
        (
            apache.mpm_query(apache.AP_MPMQ_IS_FORKED) and
            'Yes, maximum %i processes'%
            apache.mpm_query(apache.AP_MPMQ_MAX_DAEMONS)
        ) or 'No (single process MPM)'
    ))
    req.write('<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n'%(
        'Apache server root',
        apache.server_root()
    ))
    req.write('<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n'%(
        'Apache document root',
        req.document_root()
    ))
    if req.server.error_fname:
        req.write('<tr><td><code>%s</code></td><td><code>%s</code> (<a href="?view_log=1" target="_new">view last 100 lines</a>)</td></tr>\n'%(
            'Apache error log',
            os.path.join(apache.server_root(),req.server.error_fname)
        ))
    else:
        req.write('<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n'%(
            'Apache error log',
            'None'
        ))
    req.write('<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n'%(
        'Python sys.version',
        sys.version
    ))
    req.write('<tr><td><code>%s</code></td><td><pre>%s</pre></td></tr>\n'%(
        'Python sys.path',
        '\n'.join(sys.path)
    ))
    req.write('<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n'%(
        'Python interpreter name',
        req.interpreter
    ))
    req.write('<tr><td><code>mod_python.publisher available</code></td><td><code>')
    try:
        from mod_python import publisher
        req.write('Yes')
    except:
        req.write('No')
    req.write('</code></td></tr>\n')
    req.write('<tr><td><code>mod_python.psp available</code></td><td><code>')
    try:
        from mod_python import psp
        req.write('Yes')
    except:
        req.write('No')
    req.write('</code></td></tr>\n')
    req.write('</table>\n')

    req.write('<h3>Request input headers</h3>\n')
    write_table(req,req.headers_in)    

    req.write('<h3>Request environment</h3>\n')
    write_table(req,req.subprocess_env)    

    req.write('<h3>Request configuration</h3>\n')
    write_table(req,req.get_config())    

    req.write('<h3>Request options</h3>\n')
    write_table(req,req.get_options())    

    req.write('<h3>Request notes</h3>\n')
    write_table(req,req.notes)

    req.write('<h3>Server configuration</h3>\n')
    write_table(req,req.server.get_config())

    req.write('<h3>Server options</h3>\n')
    write_table(req,req.server.get_options())

    req.write('<h3>Server configuration tree</h3>\n<pre>')
    write_tree(req,apache.config_tree(),0)
    req.write('</pre>\n')

    req.write('</body></html>')
    return apache.OK
Example #3
0
def handler(req):
    req.form = util.FieldStorage(req)

    if req.form.getfirst("view_log"):
        log = open(os.path.join(apache.server_root(), req.server.error_fname), "rb")
        lines = bounded_buffer(100)
        for line in log:
            lines.append(line)
        log.close()
        req.content_type = "text/plain"
        for line in lines:
            req.write(line)
        return apache.OK

    req.add_common_vars()
    req.content_type = "text/html"
    req.write("<html><head><title>mod_python test page</title></head><body>\n")

    req.write("<h3>General information</h3>\n")
    req.write('<table border="1">\n')
    req.write(
        "<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n"
        % ("Apache version", req.subprocess_env.get("SERVER_SOFTWARE"))
    )
    req.write(
        "<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n"
        % (
            "Apache threaded MPM",
            (
                apache.mpm_query(apache.AP_MPMQ_IS_THREADED)
                and "Yes, maximum %i threads / process" % apache.mpm_query(apache.AP_MPMQ_MAX_THREADS)
            )
            or "No (single thread MPM)",
        )
    )
    req.write(
        "<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n"
        % (
            "Apache forked MPM",
            (
                apache.mpm_query(apache.AP_MPMQ_IS_FORKED)
                and "Yes, maximum %i processes" % apache.mpm_query(apache.AP_MPMQ_MAX_DAEMONS)
            )
            or "No (single process MPM)",
        )
    )
    req.write(
        "<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n" % ("Apache server root", apache.server_root())
    )
    req.write(
        "<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n" % ("Apache document root", req.document_root())
    )
    if req.server.error_fname:
        req.write(
            '<tr><td><code>%s</code></td><td><code>%s</code> (<a href="?view_log=1" target="_new">view last 100 lines</a>)</td></tr>\n'
            % ("Apache error log", os.path.join(apache.server_root(), req.server.error_fname))
        )
    else:
        req.write("<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n" % ("Apache error log", "None"))
    req.write("<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n" % ("Python sys.version", sys.version))
    req.write("<tr><td><code>%s</code></td><td><pre>%s</pre></td></tr>\n" % ("Python sys.path", "\n".join(sys.path)))
    req.write(
        "<tr><td><code>%s</code></td><td><code>%s</code></td></tr>\n" % ("Python interpreter name", req.interpreter)
    )
    req.write("<tr><td><code>mod_python.publisher available</code></td><td><code>")
    try:
        from mod_python import publisher

        req.write("Yes")
    except:
        req.write("No")
    req.write("</code></td></tr>\n")
    req.write("<tr><td><code>mod_python.psp available</code></td><td><code>")
    try:
        from mod_python import psp

        req.write("Yes")
    except:
        req.write("No")
    req.write("</code></td></tr>\n")
    req.write("</table>\n")

    req.write("<h3>Request input headers</h3>\n")
    write_table(req, req.headers_in)

    req.write("<h3>Request environment</h3>\n")
    write_table(req, req.subprocess_env)

    req.write("<h3>Request configuration</h3>\n")
    write_table(req, req.get_config())

    req.write("<h3>Request options</h3>\n")
    write_table(req, req.get_options())

    req.write("<h3>Request notes</h3>\n")
    write_table(req, req.notes)

    req.write("<h3>Server configuration</h3>\n")
    write_table(req, req.server.get_config())

    req.write("<h3>Server options</h3>\n")
    write_table(req, req.server.get_options())

    req.write("<h3>Server configuration tree</h3>\n<pre>")
    write_tree(req, apache.config_tree(), 0)
    req.write("</pre>\n")

    req.write("</body></html>")
    return apache.OK
from cheshire3 import internal
from cheshire3 import exceptions as c3errors

cheshirePath = os.environ.get('C3HOME', '/home/cheshire')

session = Session()
session.environment = "apache"
serv = SimpleServer(
    session,
    os.path.join(cheshirePath, 'cheshire3', 'configs', 'serverConfig.xml'))

configs = {}

# determine the root URL of this handler

for configitem in apache.config_tree():
    if configitem[0] == "DocumentRoot":
        docRoot = configitem[1].strip("\"'")
handlerUrl = apache.get_handler_root().replace(docRoot, "")

if len(serv.databaseConfigs) < 25:
    # relatively few dbs - we can safely cache them
    serv._cacheDatabases(session)
    for db in serv.databases.itervalues():
        if db.get_setting(session, 'SRW') or db.get_setting(session, 'srw'):
            db._cacheProtocolMaps(session)
            map = db.protocolMaps.get('http://www.loc.gov/zing/srw/', None)
            # check that there's a path and that it can actually be requested from this handler
            if (map is not None) and \
               (map.databaseUrl.startswith((handlerUrl + '/', handlerUrl[1:] + '/'))):
                map2 = db.protocolMaps.get(