diff options
-rw-r--r-- | blahajRoom.html | 6 | ||||
-rwxr-xr-x | cgi-bin/blahaj_list.cgi | 107 | ||||
-rwxr-xr-x | cgi-bin/submit_blahaj_info.cgi | 112 | ||||
-rw-r--r-- | submit_blahaj_info.html | 49 | ||||
-rwxr-xr-x | test_server.sh | 3 |
5 files changed, 275 insertions, 2 deletions
diff --git a/blahajRoom.html b/blahajRoom.html index 2aebcbc..dbac348 100644 --- a/blahajRoom.html +++ b/blahajRoom.html @@ -31,9 +31,11 @@ table { <table border="1" width="60%"> <tr> <td> + <h2><a href="cgi-bin/blahaj_list.cgi">!!!USER SUBMITTED BLAHAJ LIST HERE!!!</a></h2> <h2>If you don't have a blahaj BUY ONE NOW!!</h2> - <a href="https://blahaj.quest" target="_blank">Look here to find your blahaj today!</a> - <p>It will improve your life</p> + <p> + <a href="https://blahaj.quest" target="_blank">Look here to find your blahaj today!</a>. It will improve your life (: + </p> </td> </tr> diff --git a/cgi-bin/blahaj_list.cgi b/cgi-bin/blahaj_list.cgi new file mode 100755 index 0000000..5342a98 --- /dev/null +++ b/cgi-bin/blahaj_list.cgi @@ -0,0 +1,107 @@ +#!/usr/bin/env python + +import cgi +import json + +# Worse code here. Prepare your eyes for this monster. +# Its almost as bad as programming anything in php or even worse javascript. + +print('Content-Type: text/html') + +def create_blahaj_tables(): + try: + tables_html = """ + <h1>Blahaj list!!!!!</h1> + <table border="1" width="50%"> + <tr> + <td> + <h3><a href=\"../submit_blahaj_info.html\">Submit yours here if you haven't already!</a></h3> + <h3><a href=\"../blahajRoom.html\">Back to blahaj room</a></h3> + </td> + </tr> + </table> + <br/> + """ + + with open("blahaj_info.json", "r") as fp: + blahaj_list = json.load(fp) + + for blahaj in blahaj_list: + current_table = """ + <table border="1" width="50%"> + <tr> + <td> + <!-- Great place for an injection hint hint --> + <h2>put_name_here</h2> + <p>Date submitted: put_date_here</p> + </td> + </tr> + + <tr> + <td> + <p>put_info_here</p> + </td> + </tr> + </table> + """ + + current_table = current_table.replace("put_name_here", blahaj["name"]) + current_table = current_table.replace("put_info_here", blahaj["info"]) + current_table = current_table.replace("put_date_here", blahaj["date"]) + + tables_html += current_table + + return tables_html + + except FileNotFoundError: # No blahaj's yet + return """ + <table border="1"> + <tr> + <td> + <h1>No blahaj's found ):</h2> + <h2>Yours could be first tho :3</h2> + <h3><a href=\"../submit_blahaj_info.html\">Submit yours here</a></h3> + </td> + </tr> + </table> + """ + +html_text = """ +<!DOCTYPE html> +<html> + +<head> + <title>hehehe</title> + +<style> + +body { + color: black; + background-image: url('../images/blahaj_background.jpg'); +} + +table { + color: black; + background-color: #bebebe; + margin-top: 10px; + margin-bottom: 10px; + margin-left: 10px; + margin-right: 10px; +} + +</style> +</head> + +<body> + <center> + thing_to_replace + </center> +</body> + +</html> +""" + +tables = create_blahaj_tables() +html_text = html_text.replace("thing_to_replace", tables) + +print(html_text) diff --git a/cgi-bin/submit_blahaj_info.cgi b/cgi-bin/submit_blahaj_info.cgi new file mode 100755 index 0000000..c0e5f78 --- /dev/null +++ b/cgi-bin/submit_blahaj_info.cgi @@ -0,0 +1,112 @@ +#!/usr/bin/env python + +import cgi +import json +import datetime + +# Get the information given and dump it into a file. +def handle_fields(): + form = cgi.FieldStorage() + + blahaj_name = form.getvalue("blahaj_name") + blahaj_info = form.getvalue("blahaj_info") + + if blahaj_name == None: + return "Blahaj name is required" + + if blahaj_info == None: + blahaj_info = "" + + blahaj_list = [] + + # Get existing data. + try: + with open("blahaj_info.json", "r") as fp: + blahaj_list = json.load(fp) + except FileNotFoundError: + pass + + date = datetime.datetime.now() + blahaj_entry = {"name": blahaj_name, "info": blahaj_info, "date": date.strftime("%B, %d %Y")} + + if blahaj_entry in blahaj_list: + return "Already exists" + + # Dump new data. + with open("blahaj_info.json", "w") as fp: + blahaj_list.append(blahaj_entry) + json.dump(blahaj_list, fp) + + return "submitted" + +def display_context(fields_reponse): + print('Content-Type: text/html') + + html_text = """ + <!DOCTYPE html> + <html> + + <head> + <title>hehehe</title> + + <style> + + body { + color: black; + background-image: url('../images/blahaj_background.jpg'); + } + + table { + color: black; + background-color: #bebebe; + margin-top: 10px; + margin-bottom: 10px; + margin-left: 10px; + margin-right: 10px; + } + + </style> + </head> + + <body> + <center> + <table border="1" width="40%"> + <tr> + <td> + thing_to_replace + </td> + </tr> + </table> + </center> + </body> + + </html> + """ + + # Place html tags in the "thing_to_replace" spot + replace_text = "" + + if fields_reponse == "Blahaj name is required": + replace_text = """ + <h1>Blahaj name required</h1> + <h2><a href=\"../submit_blahaj_info.html\">Go back</a></h2> + """ + elif fields_reponse == "Already exists": + replace_text = """ + <h1>Blahaj already added</h1> + <h2><a href=\"../submit_blahaj_info.html\">Go back</a></h2> + """ + elif fields_reponse == "submitted": + replace_text = """ + <h1>Blahaj submitted!</h1> + <img src="https://media1.tenor.com/m/FKtdcMXKBhsAAAAC/yippee-happy.gif" alt="yippee!" width="90%"> + <h2><a href=\"blahaj_list.cgi\">See it in the list!</a></h2> + """ + + html_text = html_text.replace("thing_to_replace", replace_text) + + print(html_text) + + +fields_reponse = handle_fields() +display_context(fields_reponse) diff --git a/submit_blahaj_info.html b/submit_blahaj_info.html new file mode 100644 index 0000000..377a81c --- /dev/null +++ b/submit_blahaj_info.html @@ -0,0 +1,49 @@ +<!DOCTYPE html> +<html> + +<head> + <title>Submit your blahaj!</title> + +<style> + +body { + color: black; + background-image: url('images/blahaj_background.jpg'); +} + +table { + color: black; + background-color: #bebebe; + margin-top: 10px; + margin-bottom: 10px; + margin-left: 10px; + margin-right: 10px; +} + +</style> + +</head> + +<body> + <center> + <h1>Submit your blahaj!</h1> + + <table border="1" width="60%"> + <tr> + <td> + <form action = "cgi-bin/submit_blahaj_info.cgi" method = "get"> + <lable for = "blahaj_name" maxlength="256">The name of your blahaj</lable> + <input type = "text" name = "blahaj_name"/> + <br/><br/> + <lable for = "blahaj_info">Tell us about your blahaj</lable> + <textarea type = "text" name = "blahaj_info" rows="12" cols="40" maxlength="512"></textarea> + <p>It has a max character count of 512 characters</p> + <br/> + <input type = "submit" value = "Submit this fucker!"> + </form> + </td> + </tr> + </table> + </center> +</body> +</html> diff --git a/test_server.sh b/test_server.sh new file mode 100755 index 0000000..318c612 --- /dev/null +++ b/test_server.sh @@ -0,0 +1,3 @@ +#! /usr/bin/sh + +python3 -m http.server --cgi |