131 lines
3.8 KiB
Python
131 lines
3.8 KiB
Python
import flask
|
|
from flask import render_template
|
|
import sys
|
|
import time
|
|
import json
|
|
from datetime import datetime
|
|
import subprocess
|
|
import requests
|
|
import markupsafe, random
|
|
|
|
app = flask.Flask(__name__)
|
|
|
|
SITE_DATA = "/stats" if len(sys.argv)==1 else sys.argv[1]
|
|
|
|
global text
|
|
text = "Hello, World!"
|
|
|
|
def un_fuck(text):
|
|
in_tag = False
|
|
tag = ""
|
|
ret = ""
|
|
for i in text:
|
|
if i == "<":
|
|
in_tag = True
|
|
tag = ""
|
|
elif i == ">":
|
|
in_tag = False
|
|
print(tag, tag.split(" ")[0], "aaa")
|
|
if tag.split(" ")[0] in ["h1", "h2", "h3", "h4", "h5", "h6", "style", "p", "b", "i", "strong", "div", "input", "table", "blockquote", "ul", "li", "div"]:
|
|
ret += "<" + tag + ">"
|
|
else:
|
|
ret += "<" + tag + ">"
|
|
tag = ""
|
|
else:
|
|
if not in_tag:
|
|
ret += i
|
|
else:
|
|
tag += i
|
|
return ret
|
|
|
|
def fortune():
|
|
return subprocess.check_output(["fortune"]).decode()
|
|
|
|
def get_ip():
|
|
return flask.request.headers.get("Cf-Connecting-Ip", flask.request.headers.get("X-Forwarded-For", "uhhhhhhhh"))
|
|
|
|
def view():
|
|
with open(SITE_DATA + "/visits", "r+") as f:
|
|
txt = f.read().split("\n")
|
|
r = str(int(txt[0])+1)
|
|
txt[0] = r
|
|
txt.append(time.ctime() + " " + get_ip() + " " + flask.request.path)
|
|
f.seek(0)
|
|
f.write("\n".join(txt))
|
|
return r
|
|
|
|
#@app.route("/style.css")
|
|
#def style_cause_we_cool_like_that_trust_colon3_i_wish_i_could_have_colons_in_function_definitions_in_python_so_i_can_be_a_femboy_hai():
|
|
|
|
colors = [[
|
|
"\x1b[48;5;45m\x1b[30m",
|
|
"\x1b[48;5;219m\x1b[30m",
|
|
"\x1b[48;5;255m\x1b[30m",
|
|
"\x1b[48;5;219m\x1b[30m",
|
|
],
|
|
[
|
|
"\x1b[48;5;196m\x1b[30m",
|
|
"\x1b[48;5;208m\x1b[30m",
|
|
"\x1b[48;5;226m\x1b[30m",
|
|
"\x1b[48;5;82m\x1b[30m",
|
|
"\x1b[48;5;33m\x1b[30m",
|
|
"\x1b[48;5;165m\x1b[30m",
|
|
],
|
|
[
|
|
"\x1b[48;5;213m\x1b[30m",
|
|
"\x1b[48;5;226m\x1b[30m",
|
|
"\x1b[48;5;117m\x1b[30m",
|
|
],
|
|
[
|
|
"\x1b[48;5;162m\x1b[30m",
|
|
"\x1b[48;5;162m\x1b[30m",
|
|
"\x1b[48;5;171m\x1b[30m",
|
|
"\x1b[48;5;33m\x1b[30m",
|
|
"\x1b[48;5;33m\x1b[30m",
|
|
],
|
|
[
|
|
"\x1b[48;5;196m\x1b[30m",
|
|
"\x1b[48;5;255m\x1b[30m",
|
|
"\x1b[48;5;33m\x1b[30m",
|
|
]]
|
|
|
|
def trans(string):
|
|
color = random.choice(colors)
|
|
out = ""
|
|
string = string.split("\n")
|
|
i = 0
|
|
for idx, line in enumerate(string):
|
|
out += color[i] + "\x1b[K" + line + "\x1b[0m\n"
|
|
i = (i+1)%len(color)
|
|
while i != 1:
|
|
out += color[i] + "\x1b[K\x1b[0m\n"
|
|
i = (i+1)%len(color)
|
|
return out
|
|
|
|
@app.route("/", methods=["GET", "POST"])
|
|
def messsage_endpoint():
|
|
global text
|
|
if flask.request.method == "POST":
|
|
form_data = markupsafe.Markup(flask.request.form.get("message")).unescape()
|
|
if (get_ip().startswith("192.168.")):
|
|
text = form_data
|
|
else:
|
|
text = un_fuck(form_data)
|
|
print(text)
|
|
sys.stdout.flush()
|
|
|
|
with open(SITE_DATA + "/visits", "r+") as f:
|
|
txt = f.read().split("\n")
|
|
txt.append(time.ctime() + " " + get_ip() + " " + text)
|
|
f.seek(0)
|
|
f.write("\n".join(txt))
|
|
else:
|
|
view()
|
|
if "curl" in flask.request.headers.get('User-Agent'):
|
|
return trans(render_template("curl.txt", message=text, fortune=fortune(), reset="\x1b[0m", title="\x1b[1m", ansi_fortune="\x1b[3m"))
|
|
|
|
return render_template("index.html", message=text, fortune=str(markupsafe.Markup.escape(fortune().replace("\n", "<br>"))).replace("<br>", "<br>"), catgirl="")
|
|
#return render_template("index.html", message=text, fortune=str(markupsafe.Markup.escape(fortune().replace("\n", "<br>"))).replace("<br>", "<br>"), catgirl=requests.get("https://nekos.best/api/v2/neko").json()["results"][0]["url"])
|
|
|
|
if __name__ == "__main__":
|
|
app.run("0.0.0.0", 6969, "--debug" in sys.argv)
|