-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
83 lines (66 loc) · 2.18 KB
/
app.py
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
import os
import json
from flask import (
abort,
Flask,
jsonify,
redirect,
render_template,
request,
url_for,
)
from esnicheck.check import ESNICheck
app = Flask(__name__)
def most_visited():
sites = {}
file_path = os.path.join("mostvisited", "esni.txt")
with app.open_resource(file_path, "r") as f:
sites = json.load(f)
return sites
def has_esni(hostname):
esni = ESNICheck(hostname)
(tls13, tls13_output) = esni.has_tls13()
(dns, error, dns_output) = esni.has_dns()
(host_ip, is_host_cf) = esni.is_cloudflare()
result = dict()
result["tls13"] = {}
result["tls13"]["enabled"] = True if tls13 else False
result["tls13"]["output"] = tls13_output
result["dns"] = {}
result["dns"]["enabled"] = True if dns else False
result["dns"]["output"] = dns_output
result["dns"]["error"] = error
result["hostname"] = hostname
result["has_esni"] = esni.has_esni()
result["host_ip"] = host_ip
result["is_host_cf"] = is_host_cf
return result
@app.route('/', methods=["GET", "POST"])
def landing():
esni_sites = most_visited()
len_esni_sites_cf = len([site for site in esni_sites.keys()
if esni_sites[site]['is_cf']])
len_esni_sites = len(esni_sites)
data = {"websites": esni_sites,
"cf_percentage": (len_esni_sites_cf / len_esni_sites) * 100,
"percentage": (len_esni_sites / 250) * 100}
if request.method == "POST":
if not request.form['hostname']:
return redirect(url_for('landing'))
return redirect(url_for('check', q=request.form['hostname']))
return render_template("index.html", data=data)
@app.route('/check', methods=["GET", "POST"])
def check():
if request.method == "POST":
data = request.get_json()
try:
result = has_esni(data["q"])
except KeyError:
return abort(404)
return jsonify({"has_esni": result["has_esni"]}), 200
hostname = request.args.get("q")
result = has_esni(hostname)
return render_template("result.html", result=result)
@app.route('/faq', methods=["GET"])
def faq():
return render_template("faq.html")