From e94f0057bfe6dd1cca5fbdd618829d676698d83d Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 23 May 2022 00:52:09 -0700 Subject: [PATCH] add checks for web compatible rpc nodes --- xmrnodes/app.py | 19 ++++++++++-- xmrnodes/helpers.py | 3 +- xmrnodes/models.py | 1 + xmrnodes/static/css/style.css | 8 +++++ xmrnodes/static/images/error.svg | 44 ++++++++++++++++++++++++++++ xmrnodes/static/images/success.svg | 47 ++++++++++++++++++++++++++++++ xmrnodes/templates/index.html | 9 ++++++ 7 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 xmrnodes/static/images/error.svg create mode 100644 xmrnodes/static/images/success.svg diff --git a/xmrnodes/app.py b/xmrnodes/app.py index 26454a3..13eb300 100644 --- a/xmrnodes/app.py +++ b/xmrnodes/app.py @@ -37,12 +37,17 @@ def index(): crypto = request.args.get("crypto", "monero") onion = request.args.get("onion", False) show_all = "true" == request.args.get("all", "false") + web_compatible = request.args.get("web_compatible", False) + nodes = Node.select().where( Node.validated == True, Node.nettype == nettype, Node.crypto == crypto ) + if web_compatible: + nodes = nodes.where(Node.web_compatible == True) + nodes_all = nodes.count() nodes_unhealthy = nodes.where(Node.available == False).count() @@ -53,7 +58,7 @@ def index(): Node.datetime_entered.desc() ) if onion: - nodes = nodes.where(Node.is_tor==True) + nodes = nodes.where(Node.is_tor == True) nodes = [n for n in nodes] shuffle(nodes) @@ -65,7 +70,8 @@ def index(): nodes_unhealthy=nodes_unhealthy, nettype=nettype, crypto=crypto, - form=form + form=form, + web_compatible=web_compatible ) @app.route("/nodes.json") @@ -80,7 +86,8 @@ def nodes_json(): return jsonify({ "monero": { "clear": [n.url for n in xmr_nodes if n.is_tor == False], - "onion": [n.url for n in xmr_nodes if n.is_tor == True] + "onion": [n.url for n in xmr_nodes if n.is_tor == True], + "web_compatible": [n.url for n in xmr_nodes if n.web_compatible == True], }, "wownero": { "clear": [n.url for n in wow_nodes if n.is_tor == False], @@ -161,9 +168,12 @@ def check(): assert "status" in r.json() assert "offline" in r.json() assert "height" in r.json() + has_cors = 'Access-Control-Allow-Origin' in r.headers + is_ssl = node.url.startswith('https://') if r.json()["status"] == "OK": logging.info("success") node.available = True + node.web_compatible = has_cors and is_ssl node.last_height = r.json()["height"] hc.health = True else: @@ -253,6 +263,8 @@ def validate(): r = make_request(node.url) assert "height" in r.json() assert "nettype" in r.json() + has_cors = 'Access-Control-Allow-Origin' in r.headers + is_ssl = node.url.startswith('https://') nettype = r.json()["nettype"] crypto = determine_crypto(node.url) logging.info("success") @@ -260,6 +272,7 @@ def validate(): node.nettype = nettype node.available = True node.validated = True + node.web_compatible = has_cors and is_ssl node.last_height = r.json()["height"] node.datetime_checked = now node.crypto = crypto diff --git a/xmrnodes/helpers.py b/xmrnodes/helpers.py index 3a087e6..3449bfe 100644 --- a/xmrnodes/helpers.py +++ b/xmrnodes/helpers.py @@ -13,13 +13,14 @@ from xmrnodes import config def make_request(url: str, path="/get_info", data=None): + headers = {"Origin": "https://monero.fail"} if is_onion(url): proxies = {"http": f"socks5h://{config.TOR_HOST}:{config.TOR_PORT}"} timeout = 18 else: proxies = None timeout = 6 - r = r_get(url + path, timeout=timeout, proxies=proxies, json=data) + r = r_get(url + path, timeout=timeout, proxies=proxies, json=data, headers=headers) r.raise_for_status() return r diff --git a/xmrnodes/models.py b/xmrnodes/models.py index cabcd74..8cb5ca7 100644 --- a/xmrnodes/models.py +++ b/xmrnodes/models.py @@ -14,6 +14,7 @@ class Node(Model): is_tor = BooleanField(default=False) available = BooleanField(default=False) validated = BooleanField(default=False) + web_compatible = BooleanField(default=False) nettype = CharField(null=True) last_height = IntegerField(null=True) crypto = CharField(null=True) diff --git a/xmrnodes/static/css/style.css b/xmrnodes/static/css/style.css index d965ce5..605969f 100644 --- a/xmrnodes/static/css/style.css +++ b/xmrnodes/static/css/style.css @@ -79,3 +79,11 @@ input[type="text"] { #nodes { padding-top: 1em; } + +.filter-green { + filter: invert(58%) sepia(20%) saturate(5505%) hue-rotate(67deg) brightness(101%) contrast(90%); +} + +.filter-red { + filter: invert(16%) sepia(59%) saturate(5380%) hue-rotate(333deg) brightness(79%) contrast(101%); +} diff --git a/xmrnodes/static/images/error.svg b/xmrnodes/static/images/error.svg new file mode 100644 index 0000000..efaaa32 --- /dev/null +++ b/xmrnodes/static/images/error.svg @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xmrnodes/static/images/success.svg b/xmrnodes/static/images/success.svg new file mode 100644 index 0000000..b32fb14 --- /dev/null +++ b/xmrnodes/static/images/success.svg @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xmrnodes/templates/index.html b/xmrnodes/templates/index.html index a8b0ae8..39cf6cd 100644 --- a/xmrnodes/templates/index.html +++ b/xmrnodes/templates/index.html @@ -33,6 +33,7 @@ + {% if 'onion' not in request.args %}{% endif %} @@ -56,6 +57,7 @@ URL Available + Web
Compatible Network Date Added Height @@ -74,6 +76,13 @@ {% endif %} + + {% if node.web_compatible %} + + {% else %} + + {% endif %} + {{ node.nettype }} {{ node.datetime_entered.strftime('%Y-%m-%d %H:%M') }} UTC
({{ node.datetime_entered | humanize }}) {{ node.last_height }}