Another CGI example
This commit is contained in:
parent
24907f821b
commit
44c91a859f
|
@ -0,0 +1,38 @@
|
||||||
|
#!/usr/local/bin/python3.7
|
||||||
|
"""
|
||||||
|
CGI script that requests user supplied text using the INPUT status, and
|
||||||
|
pipes it into the `cowsay` program.
|
||||||
|
|
||||||
|
_________________
|
||||||
|
< Gemini is cool! >
|
||||||
|
-----------------
|
||||||
|
\ ^__^
|
||||||
|
\ (oo)\_______
|
||||||
|
(__)\ )\/\
|
||||||
|
||----w |
|
||||||
|
|| ||
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
|
query = os.environ["QUERY_STRING"]
|
||||||
|
if not query:
|
||||||
|
print("10 Enter your cowsay message")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
text = urllib.parse.unquote(query)
|
||||||
|
try:
|
||||||
|
proc = subprocess.run(
|
||||||
|
["/usr/local/bin/cowsay"],
|
||||||
|
input=text,
|
||||||
|
capture_output=True,
|
||||||
|
check=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
print("42 Unexpected Error")
|
||||||
|
else:
|
||||||
|
print("20 text/plain")
|
||||||
|
print(proc.stdout)
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/local/bin/python3.7
|
||||||
"""
|
"""
|
||||||
This is a demo CGI script that prints a bunch of debug information about
|
This is a demo CGI script that prints a bunch of debug information about
|
||||||
the request as an HTML document. Place it in the cgi-bin/ directory of your
|
the request as an HTML document. Place it in the cgi-bin/ directory of your
|
||||||
|
@ -6,5 +6,5 @@ server.
|
||||||
"""
|
"""
|
||||||
import cgi
|
import cgi
|
||||||
|
|
||||||
print("200 text/html")
|
print("20 text/html")
|
||||||
cgi.test()
|
cgi.test()
|
|
@ -273,7 +273,7 @@ class StaticDirectoryApplication(JetforceApplication):
|
||||||
status_line = out.stdout.readline().strip()
|
status_line = out.stdout.readline().strip()
|
||||||
status_parts = status_line.split(maxsplit=1)
|
status_parts = status_line.split(maxsplit=1)
|
||||||
if len(status_parts) != 2 or not status_parts[0].isdecimal():
|
if len(status_parts) != 2 or not status_parts[0].isdecimal():
|
||||||
return Response(Status.CGI_ERROR, "Script generated invalid response")
|
return Response(Status.CGI_ERROR, "Unexpected Error")
|
||||||
|
|
||||||
status, meta = status_parts
|
status, meta = status_parts
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue