From 6856fcc8ae46d7dfeb9bcdd8f75b02504e9d6a48 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Tue, 4 May 2021 23:41:45 -0700 Subject: [PATCH] fetch and display onion addresses for nodes --- app/library/cache.py | 18 ++++++++++++++++++ app/models.py | 4 ++++ app/templates/index.html | 6 +++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/library/cache.py b/app/library/cache.py index ea130af..a576f45 100644 --- a/app/library/cache.py +++ b/app/library/cache.py @@ -22,6 +22,24 @@ class Cache(object): value=data ) + def get_tor_url(self, codename): + key_name = f'node_{codename}_tor_url' + data = self.redis.get(key_name) + if data: + current_app.logger.info(f'HIT - {key_name}') + return data + else: + current_app.logger.info(f'MISS - {key_name}') + try: + dns = f'{codename}.node.{config.DO_DOMAIN}' + url = f'https://{dns}/tor/' + r = r_get(url, timeout=6) + data = r.text.strip() + self.store_data(key_name, 86400, data) + return data + except: + return {'error': 'true'} + def get_info(self, codename): key_name = f'node_{codename}_info' data = self.redis.get(key_name) diff --git a/app/models.py b/app/models.py index 8e033bc..24a4d12 100644 --- a/app/models.py +++ b/app/models.py @@ -29,6 +29,10 @@ class Operation(db.Model): record_v4_id = db.Column(db.Integer, unique=True, nullable=True) record_v6_id = db.Column(db.Integer, unique=True, nullable=True) + def get_node_tor_url(self): + u = cache.get_tor_url(self.codename) + return u.decode() + def get_node_url(self): return f'{self.codename}.node.{config.DO_DOMAIN}' diff --git a/app/templates/index.html b/app/templates/index.html index 4a7b4bb..45db43f 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -37,7 +37,11 @@ {{ op.codename }} {{ op.create_date }} {{ op.region }} - {{ op.get_node_url() }} + + {{ op.get_node_url() }} +
+ {{ op.get_node_tor_url() }} + Checking View Stats