http://python.sandtner.org/viewtopic.php?p=16132#16132
Und hier eine erste Version einer "console":
Code: Alles auswählen
#!/usr/bin/python
import os, sys, locale
print "Content-type: text/html\n\n"
html='''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=%(charset)s" />
<title>console @ %(uname)s</title>
</head>
<body>
<form name="form1" id="form1" method="post" action="%(self)s">
<p><textarea name="stdout" cols="100" rows="30" id="stdout">%(stdout)s</textarea></p>
<p><input name="cls" type="checkbox" id="cls" />cls</p>
<p><input name="cmd" type="text" id="cmd" size="150" /></p>
</form>
</body>
</html>'''
def GetCGIdaten():
"CGI POST und GET Daten zur einfacheren Verarbeitung zusammen in ein Dict packen"
CGIdaten={}
if os.environ.has_key('QUERY_STRING'):
# POST URL-Parameter parsen
for i in os.environ['QUERY_STRING'].split("&"):
i=i.split("=")
if len(i)==1:
if i[0]!="":
CGIdaten[ i[0] ] = ""
else:
CGIdaten[ i[0] ] = i[1]
from cgi import FieldStorage
FieldStorageData = FieldStorage()
# GET Daten auswerten
for i in FieldStorageData.keys():
CGIdaten[i]=FieldStorageData.getvalue(i)
return CGIdaten
CGIdaten = GetCGIdaten()
txt = ""
if CGIdaten.has_key("stdout") and not CGIdaten.has_key("cls"):
# Alte Ausgaben wieder anzeigen
txt = CGIdaten["stdout"]
# "Prompt" hinzufügen
txt += os.getcwd()+"> "
if CGIdaten.has_key("cmd"):
# Befehl ausfühen
Befehl = CGIdaten["cmd"]
txt += Befehl+"\n"
txt += os.popen( Befehl ).read()
print html % {
"charset" : locale.getdefaultlocale()[1],
"uname" : os.popen("uname -a").read(),
"self" : os.environ['SCRIPT_NAME'],
"stdout" : txt
}