Created
April 14, 2021 15:20
-
-
Save Andy-Knight/f6191a25bf4e9a5891b9c05d98792753 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os, sys, cgi | |
import requests | |
print "Content-type:text/html\n\n"; | |
print "<head><title>Company Phone Directory</title></head>\n" | |
print "<body>\n" | |
print "<h1>Directory Lookup</h1>\n" | |
remote = os.getenv("REMOTE_ADDR") | |
form = cgi.FieldStorage() | |
querystring = form.getvalue("querystring") | |
print "Accessed via:",remote,"\n<p>" | |
if querystring != None: | |
url = 'http://{{ grains['databaseServer'] }}/cgi-bin/database.py?querystring=' + querystring | |
else: | |
url = 'http://{{ grains['databaseServer'] }}/cgi-bin/database.py' | |
querystring = "" | |
r = requests.get(url) | |
print '<form action="/cgi-bin/app.py">' | |
print ' Name Filter (blank for all records):' | |
print ' <input type="text" name="querystring" value="'+querystring+'">' | |
print ' <input type="submit" value="Apply">' | |
print '</form>' | |
print "\n<table border=1 bordercolor=black cellpadding=5 cellspacing=0>" | |
print "\n<th>Phone Number</th><th>First Name</th><th>Surname</th><th>Department</th>" | |
#deal with the data coming across the wire | |
a = r.text.split("|\n#") | |
for row in a: | |
if len(row) != 1: | |
print "<tr>" | |
splitrow = row.split("|") | |
for item in splitrow: | |
if item != None: | |
print "<td>",item,"</td>" | |
print "</tr>\n" | |
print "</body></html>\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment