summaryrefslogtreecommitdiff
path: root/embed.cgi
blob: c0f11c78330393d3a2f70e38115df100f82bbb14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3

from georgedata import george 
order = list(george.keys()) # dicts guarantee key order as of 3.7

from urllib.parse import urlparse, parse_qs
import sys

from os import getenv
if __name__ == "__main__":
    colors = {
        "bg": 'white',
        "fg": 'black',
        "george": '#3d3db8',
        "links": 'blue',
        "underline": "blue",
        
    }

    print("Content-Type: text/html")
    qs = getenv("QUERY_STRING")
    member,real_qs = (qs.split('&', 1) + [''])[:2]

    member=member.replace('%20',' ')

    query = parse_qs(real_qs)

    try:
        ind = order.index(member)
    except ValueError:
        print()
        print(f'<h1 style="color: red">no</h1><p>unknown member {member}</p>')
    else:
        correct_hn = urlparse(george[member]).hostname
        
        rf = getenv("HTTP_REFERER",None)
        if rf is not None:
            our_hn = urlparse(rf).hostname
            if our_hn != correct_hn:
                print()
                print('<h1 style="color: red">no</h1><p>bad referer hostname</p>')
                sys.exit(0)

        for q in query.keys():
            if q.startswith('c_'):
                color = query[q][0]
                if color.isalnum() or (color[0] == '#' and color[1:].isalnum()):
                    colors[q[2:]] = color

        l = len(order)
        ni = (ind + 1)%l
        pi = (ind - 1)%l
        n = george[order[ni]]
        p = george[order[pi]]
        ref = getenv("HTTP_REFERER","the")

        print(f"Content-Security-Policy: sandbox allow-top-navigation; frame-ancestors {correct_hn} http://{correct_hn};")
        print()
        print(
f"""<!DOCTYPE html>
<html>
        <head>
                <base target="_parent">
        </head>
        <body>
                <style>
                        body,html {{
                                overflow: hidden;
                                font-family: sans-serif;
                                padding:0;
                                margin:0;
                        }}
                        main {{
                                margin:0;
                                padding-left: 5px;
                                padding-right: 5px;
                                height: 45px;
                                border: 1px solid black;
                                box-shadow: 5px 5px black;
                                background-color: {colors["bg"]};
                                color: {colors["fg"]};
                                
                                display: flex;
                                flex-wrap: nowrap;
                                justify-content: space-between;
                        }}
                        #george {{
                                color: {colors["george"]};
                                text-decoration: underline;
                                text-decoration-color: {colors["underline"]};
                                text-decoration-thickness: 2px;
                                font-style: oblique;
                                animation: 2s infinite alternate george;
                        }}
                        @media (prefers-reduced-motion) {{
                            #george {{ animation: none; }}
                        }}
                        #noble {{
                                font-size: min(3vw, 12pt);
                        }}
                        p {{
                                white-space: nowrap;
                                align-self: center;
                        }}
                        @keyframes george {{
                                from {{
                                        letter-spacing: 1px;
                                }}
                                to {{
                                        letter-spacing: 6px;
                                }}
                        }}
                        a {{
                                color: {colors["links"]};
                        }}
                </style>
                <main>
                        <p><a href="{p}">&lt; PREV</a></p>
                        <p id="noble">
                                The <a href="https://george.gh0.pw" id="george">GEORGE</a> is a noble animal.
                        </p>
                        <p><a href="{n}">NEXT &gt;</a></p>
                </main>
        </body>
</html>""")