diff options
| author | nathansmith117 <nathansmith117@sdf.org> | 2024-05-21 04:32:00 +0000 | 
|---|---|---|
| committer | nathansmith117 <nathansmith117@sdf.org> | 2024-05-21 04:32:00 +0000 | 
| commit | 4df21dd096b4d6fd25b11e0872c6329608204d62 (patch) | |
| tree | 8f158fcb78d43c0a2082cfc028bf4a4836a28941 /cgi-bin/submit_blahaj_info.cgi | |
| parent | 8944954d2c85325a7af3d531e7490afb5e5e55eb (diff) | |
| download | shittyweb-4df21dd096b4d6fd25b11e0872c6329608204d62.tar.gz shittyweb-4df21dd096b4d6fd25b11e0872c6329608204d62.tar.bz2 shittyweb-4df21dd096b4d6fd25b11e0872c6329608204d62.zip  | |
User submitted blahajs working well
Diffstat (limited to 'cgi-bin/submit_blahaj_info.cgi')
| -rwxr-xr-x | cgi-bin/submit_blahaj_info.cgi | 112 | 
1 files changed, 112 insertions, 0 deletions
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)  | 
