bookvotercgi/ 0000775 0001750 0001750 00000000000 13625212625 013207 5 ustar ubuntu ubuntu bookvotercgi/cgi-bin/ 0000775 0001750 0001750 00000000000 13625212606 014516 5 ustar ubuntu ubuntu bookvotercgi/cgi-bin/survey.py 0000775 0001750 0001750 00000004206 13625036577 016445 0 ustar ubuntu ubuntu #!/usr/bin/env python3
import cgi
import sys
from http import cookies
import os
def getBooks():
result = []
with open('books.txt', 'r') as file:
# read the file into lines
lines = file.readlines()
# iterate through lines, splitting each line into strings
for line in lines:
book = line.split(',')
result.append(book)
return result
#
# Main Program
#
def main():
# get the cookie
cookie = cookies.SimpleCookie()
cookie_string = os.environ.get('HTTP_COOKIE')
cookie.load(cookie_string)
userid = cookie['userid'].value
# get the form submission if there was one
form = cgi.FieldStorage()
isbn = form.getvalue('isbn')
# deal with form submit
if (isbn is not None):
# store isbn as a cookie
cookie['isbn']=isbn
# redirect to results page
print("Content-type: text/html")
print(cookie.output())
print()
print("")
print("")
print("
")
print("")
print("")
print("")
print("Please follow this link.
")
print("")
print("")
# first time on this page
else:
print("Content-type: text/html")
print()
print("")
print("")
print("Vote for a book!")
print("")
print("")
print("")
print("Vote for a book!
")
print()
print("")
print()
print("")
print("")
main()
bookvotercgi/cgi-bin/login.py 0000775 0001750 0001750 00000004572 13625036756 016225 0 ustar ubuntu ubuntu #!/usr/bin/env python3
import cgi
import cgitb
import sys
from http import cookies
#
# isValid()
#
def isValid(userid, password):
print('in isvalid',file=sys.stderr)
with open('users.txt', 'r') as file:
# read the file into lines
lines = file.readlines()
# iterate through lines, splitting each line into strings
for line in lines:
strings = line.split()
# process each string pair, return True if match
# otherwise when end of file reached, drop to return False
fileUserId = strings[0]
filePassword = strings[1]
# we have a match
if (userid == fileUserId) and (password == filePassword):
print('leaving isValid with userid/password match',file=sys.stderr)
return True
print('leaving isValid with no match',file=sys.stderr)
return False
#
# Main Program
#
def main():
form = cgi.FieldStorage()
userid = form.getvalue('userid')
password = form.getvalue('password')
if isValid(userid,password):
cookie = cookies.SimpleCookie()
cookie['userid']=userid
# NOTE: Could not get straight redirects to work
# print "Status: 201 (Created)"
# print "Location: http://54.191.137.34:5000/survey.py"
# print
print("Content-type: text/html")
print(cookie.output())
print()
print("")
print("")
print("")
print("")
print("")
print("")
print("Please follow this link.
")
print("")
print("")
print()
print()
else:
print("Content-type: text/html")
print()
print("")
print("")
print("Test CGI")
print("")
print("")
print("Login
")
print("")
print("")
print("