Esempio n. 1
0
 def do_debug(self):
     self.prologue("FAQ Wizard Debugging")
     form = cgi.FieldStorage()
     cgi.print_form(form)
     cgi.print_environ(os.environ)
     cgi.print_directory()
     cgi.print_arguments()
def application(environ, start_response):
    global current
    status = '200 OK'
    headers = [('Content-type', 'text/html')]
    start_response(status, headers)
    ret = []
    ret.append('<title>Hello from Python</title>')
    for i in range(1, random.randint(2, 11)):
	ret.append('<h3>Hello, World No <span style="color: blue;">%0.2d</span></h3>' % i)
    
    f = open('current.txt', 'r')
    current = int(f.read())
    f.close()
    current += 1
    f = open('current.txt', 'w')
    f.write(str(current))
    f.close()
    ret.append('<p>&nbsp;</p><p>Current request: <strong>%s</strong></p>' % (current,))    
    form = cgi.FieldStorage(fp = environ['wsgi.input'], environ = environ, keep_blank_values = 1)
 
    ret.append('<ul>')
    
    try:
        if len(form.keys()) == 0:
            ret.append('<li style="color: red;">Got no data</li>')
        else:
            for key in form.keys():
                ret.append('<li>%s: <strong>%s</strong></li>' % (key, form[key].value))
    except:
        ret.append('<li style="color: red;">Got no data due to error.</li>')
      
    ret.append('</ul><hr/>')

    cgi.print_environ()
    
    return ret
Esempio n. 3
0
import cgi
import cgitb; cgitb.enable()

print('Content-Type: text/html')
print('')
arguments = cgi.FieldStorage()
for i in arguments.keys():
    print(arguments[i].value)

cgi.test()
cgi.print_environ()
print "Hello"
Esempio n. 4
0
#! /usr/bin/env python

import cgi

print "Content-type: text/html\n"
print cgi.print_environ ()
Esempio n. 5
0
def cgi_environ():
    import cgi
    cgi.print_environ()
Esempio n. 6
0
def debug_block():
	cgi.print_form(form)
	cgi.print_directory()
	cgi.print_environ()
Esempio n. 7
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)
Esempio n. 8
0
	else:
		id_ref_form = ''
	if id_ref_form:
		if not conexao:
			conexao = ODBC.Windows.Connect(dsn=DSN,clear_auto_commit=0)
			cursor = conexao.cursor()
		sql = """SELECT term_en, term_pt, defin 
				 FROM referencia
				 WHERE id_ref = "%s" """
		cursor.execute(sql % termo_form)
		dados = cursor.fetchall()
		if dados:
			for id_ref, term_en, term_pt in dados:
				print """
<TABLE BORDER=1 WIDTH="100%">
<TR><TH>EN<TD>%s</TR>
<TR><TH><FONT COLOR="green">PT</FONT><TD><FONT COLOR="green">%s</FONT></TR>
<TR><TD COLSPAN=2>%s</TR>
</TABLE>""" % (term_en, term_pt, defin)

	print '<HR>', cgi.print_environ()
  
except:
	import sys
	from traceback import print_exc
	sys.stderr = sys.stdout
	print '<HR><H3>Erro no CGI:</H3><PRE>'
	print_exc()
	print '</PRE>'

print '</BODY></HTML>'
Esempio n. 9
0
# coding: utf-8

import cgi
import sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding = "utf-8")

print("Content-type: text/html\n")
print(cgi.print_environ())
Esempio n. 10
0
def main():
    #Necassary Headers
    print "Content-Type: text/html"
    #blank line indicates end of headers
    print              
    
    form = cgi.FieldStorage()

    #The second line of checks shouldn't be necessary since empty values are not supposed
    # to be included in the dictionary (according to Python Docs), but for some reason they are...
    if "pwd_in" not in form or "pwd_out" not in form or "certificate" not in form\
    or form["pwd_in"].value == "" or form["pwd_out"].value == "" or not form["certificate"].filename:
        print "<H1>Error: Missing certificate or password(s)</H1>"
        cgi.print_environ()
        
    else:
        file = form["certificate"].file
        pkcs12_data = file.read()

        #The file descriptors for the password pipe
        rfd,wfd = os.pipe()
        
        #######Create the Private Key#######
        
        #The openSSL command, reading the PKCS12 from stdin (fd:0) and reading passwords from rfd end of a pipe
        #Passwords get input one per line (see openssl manpages under "PASS PHRASE ARGUMENTS" for details)
        arguments = [OPEN_SSL_PATH, "pkcs12", "-nocerts", "-passin", "fd:" + str(rfd), "-passout", "fd:" + str(rfd)]
        #Start the openssl process
        proc = subprocess.Popen(arguments, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        #Write passwords to the password pipe
        os.write(wfd, form["pwd_in"].value + "\n" + form["pwd_out"].value + "\n")
        #Write the data to stdin pipe for openssl and close it to send EOF
        proc.stdin.write(pkcs12_data)
        proc.stdin.close()

        privkey = proc.stdout.read()
        error = proc.stderr.read()
        
        if not privkey:
            print "openssl private key generation error: ",
            print error,
            return
        else:
            print privkey,
            
        ###########Create the Certificate########
        arguments = [OPEN_SSL_PATH, "pkcs12", "-clcerts", "-passin", "fd:" + str(rfd)]
        proc = subprocess.Popen(arguments, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        os.write(wfd, form["pwd_in"].value + "\n");
        proc.stdin.write(pkcs12_data)
        proc.stdin.close()
        
        cert_noText = proc.stdout.read()
        error = proc.stderr.read()
        
        if not cert_noText:
            print "openssl certificate generation error:"
            print error,

        ###########Create the Certificate WITH human readable text########
        arguments = [OPEN_SSL_PATH, "x509", "-text"]
        proc = subprocess.Popen(arguments, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        proc.stdin.write(cert_noText)
        proc.stdin.close()
        
        cert = proc.stdout.read()
        error = proc.stderr.read()
        
        if not cert:
            print "openssl cert with text generation error:"
            print error,
        else:
            print BORDER,
            print cert,
        
        ###########Log the current date/time and  DN + email for certificate ########
        if LOG_FILE:
            arguments = [OPEN_SSL_PATH, "x509", "-noout", "-issuer", "-subject", "-email"]
            proc = subprocess.Popen(arguments, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            proc.stdin.write(cert_noText)
            proc.stdin.close()

            data = proc.stdout.read()
            error = proc.stderr.read()

            logfile = open(LOG_FILE, "a")
            if not data:
                logfile.write(error)
            else:
                logfile.write("\n### " + str(datetime.now()) + " ###\n" + data)
            logfile.close()

        #We don't need the password pipe anymore, clean up the open file descriptors
        os.close(rfd)
        os.close(wfd)
Esempio n. 11
0
#!/usr/bin/python

import os
import cgi
import urllib


def br():
    print '<br>'


def p(s):
    print "<p>%s</p>" % s


#cgitb.enable()

print("Content-Type: text/html;charset=utf-8")
print('')
br()
print 'Request Method: ' + os.environ['REQUEST_METHOD']
br()
print 'Rsrc requested: ' + os.environ['PATH_INFO']
br()

p('Query: ' + urllib.unquote(os.environ['QUERY_STRING']))

cgi.print_environ()
Esempio n. 12
0
"""Generic FAQ Wizard.
Esempio n. 13
0
#!/usr/bin/env python
import cgi
print("Content-type: text/html\n")
print(cgi.print_environ())
Esempio n. 14
0
"""Generic FAQ Wizard.
Esempio n. 15
0
import cgi

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

print "<html>"
print "<head>"
print "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />"
print "<title>CGI script output</title>"
print "</head>"
print "<body>"
print "<H1>這是我的第一個應用程式</H1>"
print "哈嚕,大家早安!"
print cgi.print_environ()
print cgi.print_environ_usage()
print "</body>"
Esempio n. 16
0
    def printEnviron(self):
	"""Print environment as html"""
	cgi.print_environ()