diff --git a/xmrnodes/app.py b/xmrnodes/app.py index 4869bde..5c1c519 100644 --- a/xmrnodes/app.py +++ b/xmrnodes/app.py @@ -11,7 +11,7 @@ from flask import render_template, flash, url_for from urllib.parse import urlparse from xmrnodes.helpers import determine_crypto, is_onion, make_request from xmrnodes.forms import SubmitNode -from xmrnodes.models import Node +from xmrnodes.models import Node, HealthCheck from xmrnodes import config @@ -50,7 +50,7 @@ def index(): ) if onion: nodes = nodes.where(Node.is_tor==True) - + paginated = nodes.paginate(page, itp) total_pages = nodes.count() / itp return render_template( @@ -93,6 +93,7 @@ def check(): nodes = Node.select().where(Node.validated == True) for node in nodes: now = datetime.utcnow() + hc = HealthCheck(node=node) logging.info(f"Attempting to check {node.url}") try: r = make_request(node.url) @@ -103,15 +104,18 @@ def check(): logging.info("success") node.available = True node.last_height = r.json()["height"] + hc.health = True else: raise except: logging.info("fail") node.datetime_failed = now node.available = False + hc.health = False finally: node.datetime_checked = now node.save() + hc.save() @app.cli.command("validate") def validate(): @@ -171,11 +175,14 @@ def import_(): export_dir = f"{config.DATA_DIR}/export.txt" with open(export_dir, 'r') as f: for url in f.readlines(): - n = url.rstrip() - all_nodes.append(n) - logging.info(f"Adding {n}") - node = Node(url=n) - node.save() + try: + n = url.rstrip() + logging.info(f"Adding {n}") + node = Node(url=n) + node.save() + all_nodes.append(n) + except: + pass logging.info(f"{len(all_nodes)} node urls imported and ready to be validated") @app.template_filter("humanize") diff --git a/xmrnodes/models.py b/xmrnodes/models.py index 59c31e8..1c527ea 100644 --- a/xmrnodes/models.py +++ b/xmrnodes/models.py @@ -7,7 +7,7 @@ db = SqliteDatabase(f"{config.DATA_DIR}/sqlite.db") class Node(Model): id = AutoField() - url = CharField() + url = CharField(unique=True) is_tor = BooleanField(default=False) available = BooleanField(default=False) validated = BooleanField(default=False) @@ -22,4 +22,13 @@ class Node(Model): class Meta: database = db -db.create_tables([Node]) +class HealthCheck(Model): + id = AutoField() + node = ForeignKeyField(Node, backref='healthchecks') + datetime = DateTimeField(default=datetime.utcnow) + health = BooleanField() + + class Meta: + database = db + +db.create_tables([Node, HealthCheck]) diff --git a/xmrnodes/static/css/style.css b/xmrnodes/static/css/style.css index 377aeb2..b92f67c 100644 --- a/xmrnodes/static/css/style.css +++ b/xmrnodes/static/css/style.css @@ -33,3 +33,18 @@ input[type="text"] { .wownero { background-color: rgb(235, 74, 206); } + +.dot { + height: 10px; + width: 10px; + border-radius: 50%; + display: inline-block; +} + +.glowing-green { + background-color: #00cd00; +} + +.glowing-red { + background-color: #cd0000; +} diff --git a/xmrnodes/templates/index.html b/xmrnodes/templates/index.html index 808df70..6e94660 100644 --- a/xmrnodes/templates/index.html +++ b/xmrnodes/templates/index.html @@ -38,6 +38,7 @@ Network Height Last Checked + History @@ -54,6 +55,12 @@ {{ node.nettype }} {{ node.last_height }} {{ node.datetime_checked | humanize }} + {% for hc in node.healthchecks %} + {% if loop.index > loop.length - 11 %} + + {% endif %} + {% endfor %} + {% endfor %}