From 2992323e8dc5fb229f201e4292cf818f99f48416 Mon Sep 17 00:00:00 2001 From: bplanica Date: Sun, 9 Aug 2020 12:08:30 -0500 Subject: [PATCH] cgi activity --- cgi-bin/cgi_1.py | 4 ++++ cgi-bin/cgi_2.py | 12 +++++++----- cgi-bin/cgi_sums.py | 11 ++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cgi-bin/cgi_1.py b/cgi-bin/cgi_1.py index baa5c3e..80be548 100644 --- a/cgi-bin/cgi_1.py +++ b/cgi-bin/cgi_1.py @@ -1,5 +1,9 @@ #!/usr/bin/env python import cgi +import cgitb +cgitb.enable() + +# 1/0 cgi.test() diff --git a/cgi-bin/cgi_2.py b/cgi-bin/cgi_2.py index ae4ed0d..a2f13ec 100644 --- a/cgi-bin/cgi_2.py +++ b/cgi-bin/cgi_2.py @@ -1,7 +1,9 @@ #!/usr/bin/env python + import cgi import cgitb cgitb.enable() + import os import datetime @@ -23,10 +25,10 @@ """.format( software=os.environ.get('SERVER_SOFTWARE', default), - script='aaaa', - month='bbbb', - date='cccc', - year='dddd', - client_ip='eeee' + script=os.environ.get('SCRIPT_NAME', default), + month=datetime.datetime.now().strftime('%B'), + date=datetime.datetime.now().day, + year=datetime.datetime.now().year, + client_ip=os.environ.get('REMOTE_ADDR', default), ) print(body) diff --git a/cgi-bin/cgi_sums.py b/cgi-bin/cgi_sums.py index feed2bc..349d629 100644 --- a/cgi-bin/cgi_sums.py +++ b/cgi-bin/cgi_sums.py @@ -1,9 +1,18 @@ #!/usr/bin/env python + import cgi import cgitb - cgitb.enable() +form = cgi.FieldStorage() +operands = form.getlist('operand') + +try: + total = sum(map(int, operands)) + body = "Your total is: {}".format(total) +except (ValueError, TypeError): + body = "Unable to calculate a sum: please provide integer operands" + print("Content-type: text/plain") print() print("Your job is to make this work")