Beispiel #1
0
def getserverinfo():
    #This code establishes a connection to the DNS server to get the host's IP address.  This is to get the real IP address.
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.connect((finddnsresolver(), 53))  # sock.connect(("nameserver",53))
    ipaddress = (sock.getsockname()[0])
    sock.close()

    #This get the hostname as defined in /etc/hostname
    hostname = (socket.gethostname())

    #Use OS environment variables gather information
    serverport = getserverparam('SERVER_PORT')

    #Get EC2 hostname
    sock = urllib2.urlopen("http://169.254.169.254/latest/meta-data/hostname")
    ec2hostname = sock.read()
    sock.close()

    if getserverparam('REQUEST_SCHEME') != None:
        serverprotocol = str.upper(getserverparam('REQUEST_SCHEME'))

        return (hostname, ipaddress, serverprotocol, serverport, ec2hostname)
    else:
        serverprotocol = 'Unknown'
        return (hostname, ipaddress, serverprotocol, serverport, ec2hostname)

    #IF YOU WANT TO FIGURE OUT WHAT VARIABLES CAN BE USED, UNCOMMENT THE NEXT LINE TO ADD OTHER INFORMATION AND REFRESH THE WEBPAGE
    cgi.test()
def testcgi():
    """CGI program that can be used to test a browser's cookie support.
    Call this as the main program of a CGI script."""
    import cgi
    print("Set-Cookie: key=value")
    print("Set-Cookie: another=thing")
    cgi.test()
    print()
    print("<p> This is the <code>cookielib</code> module's")
    print("<code>testcgi()</code> function.")
Beispiel #3
0
def testcgi():
    """CGI program that can be used to test a browser's cookie support.
    Call this as the main program of a CGI script."""
    import cgi
    print "Set-Cookie: key=value"
    print "Set-Cookie: another=thing"
    cgi.test()
    print
    print "<p> This is the <code>cookielib</code> module's"
    print "<code>testcgi()</code> function."
Beispiel #4
0
def dumpstatepage(exhaustive=0):
    """
    for debugging: call me at top of a CGI to
    generate a new page with CGI state details
    """
    if exhaustive:
        cgi.test()                       # show page with form, environ, etc.
    else:
        pageheader(kind='state dump')
        form = cgi.FieldStorage()        # show just form fields names/values
        cgi.print_form(form)
        pagefooter()
    sys.exit()
Beispiel #5
0
def dumpstatepage(exhaustive=0):
    """
	для отладки: вызывается в начале сценарий CGI
	для создания новой страницы с информацией о состоянии CGI
	"""
    if exhaustive:
        cgi.test()  # вывести страницу с формой, окружностью и проч.
    else:
        pageheader(kind='state dump')
        form = cgi.FieldStorage()  # вывести только имена/значения полей формы
        cgi.print_form(form)
        pagefooter()
    sys.exit()
Beispiel #6
0
def dumpstatepage(exhaustive=0):
    """
    for debugging: call me at top of a CGI to
    generate a new page with CGI state details
    """
    if exhaustive:
        cgi.test()  # show page with form, environ, etc.
    else:
        pageheader(kind='state dump')
        form = cgi.FieldStorage()  # show just form fields names/values
        cgi.print_form(form)
        pagefooter()
    sys.exit()
Beispiel #7
0
def py_sql_test_cgi():
    import os, sys, time
    import cgi, cgitb
    cgi.test()
    print("\n\n", os.environ["REMOTE_ADDR"])
    print(cgi.FieldStorage())
    qr_string = cgi.FieldStorage()
    print(qr_string)
    #print("\n\nСтрока обработана cgi.parse_qs(query): ", cgi.parse_qs(qr_string))
    print("\n\nqr_string.keys:", qr_string.keys())
    i = 0
    for key in qr_string.keys():
        var_name = str(key)
        var_value = str(qr_string.getvalue(var_name))
        print(str(i) + ":" + var_name + "=" + var_value)
        i += 1
    print("\n\n")
    print("\nfunc_value=", qr_string.getvalue("func"))
    return ()
# http://...../wrapper.sh.cgi?s=minimal_wrapper_test.py
print 'Content-type: text/html\n'
import sys; print 'running python in',sys.prefix
import cgi; cgi.test()
Beispiel #9
0
#!/usr/bin/python
import cgi
import cgitb

cgitb.enable()  #for trouble shooting
cgi.test()  # cgi test output
Beispiel #10
0
def info():
	print cgi.test()
Beispiel #11
0
#!/usr/bin/env python

import cgi

print(cgi.test());
Beispiel #12
0
def main():
    cgitb.enable()

    if APP_ROOT_URI is None:
        sys.stdout.write("Content-Type: text/plain; charset=UTF-8\r\n\r\n")
        print "Sovelluksen juuri-URI:tä (APP_ROOT_URI) ei ole asetettu."
        print
        print "APP_ROOT_URI määrittää, mistä rohmotin staattiset tiedostot,"
        print "kuten CSS-tyylit ja kuvat löytyvät."
        print
        print "Esim. APP_ROOT_URI='/~me/rohmotti'"
        print "  ==> tyylit: '/~me/rohmotti/styles'"
        print "  ==> kuvat: '/~me/rohmotti/images'"
        print
        print "Muokkaa asetuksia rohmotti.py:n alussa!"
        return 0

    form = cgi.FieldStorage()

    #
    # Muodosta tietokantayhteys. Aseta oletuspolku.
    #
    conn = psycopg2.connect(DSN)
    conn.cursor().execute("""SET search_path TO %s, "$user", public""" % (DBSCHEMA))
    conn.commit()

    #
    # Setup database connection for the object model
    #
    DatabaseObject.setDatabaseConnection(conn)

    #
    # PUT, DELETE -tukikikka: jos lomakkeessa on 'method_override'
    # arvolla 'PUT' tai 'DELETE' ja käytetty kyselymetodi on POST,
    # tulkitse kyselymetodiksi 'method_override':n arvo.
    #
    request_method = os.environ.get("REQUEST_METHOD")
    if request_method == "POST":
        method_override = form.getvalue("method_override")
        if method_override in ["PUT", "DELETE"]:
            request_method = method_override

    app_root_uri = APP_ROOT_URI
    script_name = os.environ.get("SCRIPT_NAME", "")
    path_info = os.environ.get("PATH_INFO", "")
    full_path = script_name + path_info
    request_uri = os.environ.get("REQUEST_URI", "")
    remote_addr = os.environ.get("REMOTE_ADDR")
    http_x_forwarded_for = os.environ.get("HTTP_X_FORWARDED_FOR")

    if http_x_forwarded_for is not None:
        effective_remote_addr = http_x_forwarded_for
    else:
        effective_remote_addr = remote_addr

    conf = {
        "request_method": request_method,
        "script_name": script_name,
        "app_root_uri": app_root_uri,
        "path_info": path_info,
        "full_path": full_path,
        "request_uri": request_uri,
        "remote_addr": remote_addr,
        "http_x_forwarded_for": http_x_forwarded_for,
        "effective_remote_addr": effective_remote_addr,
    }

    html_template_filename = get_html_template_filename()

    C = Cookie.SimpleCookie()
    C.load(os.environ.get("HTTP_COOKIE", ""))
    sessio = Sessio.new_from_cookie(C)
    conf["sessio"] = sessio

    navigation = (
        """\
        <span class="navigation">
            <ul class="navigation">
                <li class="navigation"><a href="%(script_name)s">Rohmotti</a></li>
                <li class="navigation"><a href="%(script_name)s/resepti">Reseptit</a></li>
                <li class="navigation"><a href="%(script_name)s/ruokaaine">Ruoka-aineet</a></li>
                <li class="navigation"><a href="%(script_name)s/henkilo">Henkilöt</a></li>
                <li class="navigation"><a href="%(script_name)s/haku">Haku</a></li>
                <li class="navigation"><a href="%(script_name)s/kirjautuminen">Kirjautuminen</a></li>
            </ul>
        </span>"""
        % conf
    )

    render_dict = {
        "REQUEST_URI": request_uri,
        "APP_ROOT_URI": app_root_uri,
        "FULL_PATH": full_path,
        "navigation": navigation,
    }

    mode = "development"

    module_to_load = get_handler_name()
    handler = None
    if module_to_load is not None:
        module = import_module(module_to_load)
        handler = module.Handler(form, conf)

    handler_return = None
    if handler is not None:
        try:
            handler_return = handler.handle()
        except Exception:
            if mode == "production":
                cgi.test()
            else:
                cgitb.handler()

        if handler_return is None:
            return

        render_dict.update(handler_return[1])
        sys.stdout.write("\r\n".join(handler_return[0]) + "\r\n\r\n")
    else:
        #
        # Oletusotsakkeet
        #
        sys.stdout.write("Content-Type: text/html; charset=UTF-8\r\n\r\n")

    debug = False
    try:
        debug = form.getvalue("debug")
    except Exception:
        pass

    if html_template_filename is not None:
        if debug:
            print cgi.print_environ()

    if html_template_filename is not None:
        f = open(get_html_template_filename(), "r")
        if f is None:
            print "Ei voinut avata tiedostoa!"
        html_template_string = f.read()
        s = Template(html_template_string)
        print s.safe_substitute(render_dict)
Beispiel #13
0
def main(args):
    cgi.test()
Beispiel #14
0
	def renderDebug(self):
		print '<div class="debug">'
		print "<p>request %s</p>" % str(self)
		cgi.test()
		print '</div>'
Beispiel #15
0
#!/Library/Frameworks/Python.framework/Versions/3.8/bin/python3

print("Content-Type: text/html")  # HTML is following
print()  # blank line, end of headers

import cgi
cgi.test()
Beispiel #16
0
 def update_event(self, inp=-1):
     self.set_output_val(0, cgi.test(self.input(0)))
Beispiel #17
0
#!/usr/bin/env python
import cgi

cgi.test()
Beispiel #18
0
#!/usr/bin/python
import cgi, os
import cgitb; cgitb.enable()
cgi.test();