aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan <me@jordan.im>2020-10-25 20:03:23 -0700
committerJordan <me@jordan.im>2020-10-25 20:03:23 -0700
commitf0c466afa5b1cc7a5e42e2f097f266d137cece10 (patch)
tree4648ae2deaaf8f73a73115f529dbaf90d7f3be80
parent421bd0bc206fa9326ffb8acee547f7b7ea49a2dd (diff)
downloadallium-f0c466afa5b1cc7a5e42e2f097f266d137cece10.tar.gz
allium-f0c466afa5b1cc7a5e42e2f097f266d137cece10.zip
include contact hash in listings, related to #1
-rw-r--r--allium/relays.py30
-rw-r--r--allium/templates/contact.html3
-rw-r--r--allium/templates/misc-families.html2
-rw-r--r--allium/templates/relay-info.html4
-rw-r--r--allium/templates/relay-list.html12
5 files changed, 20 insertions, 31 deletions
diff --git a/allium/relays.py b/allium/relays.py
index 97e1514..74c091f 100644
--- a/allium/relays.py
+++ b/allium/relays.py
@@ -20,27 +20,6 @@ ABS_PATH = os.path.dirname(os.path.abspath(__file__))
ENV = Environment(loader=FileSystemLoader(os.path.join(ABS_PATH, 'templates')),
trim_blocks=True, lstrip_blocks=True)
-def hash_filter(value, hash_type='md5'):
- '''
- Custom hash filter for jinja; defaults to "md5" if no type specified
-
- :param value: value to be hashed
- :param hash_type: valid hash type
- :return: computed hash as a hexadecimal string
- '''
- hash_func = getattr(hashlib, hash_type, None)
-
- if hash_func:
- computed_hash = hash_func(value.encode('utf-8')).hexdigest()
- else:
- raise AttributeError(
- 'No hashing function named {hname}'.format(hname=hash_type)
- )
-
- return computed_hash
-
-ENV.filters['hash'] = hash_filter
-
class Relays:
'''
Relay class consisting of relays (list of dict) and onionoo fetch timestamp
@@ -58,6 +37,7 @@ class Relays:
self._fix_missing_observed_bandwidth()
self._sort_by_bandwidth()
self._trim_platform()
+ self._add_hashed_contact()
self._categorize()
def _fetch_onionoo_details(self):
@@ -104,6 +84,14 @@ class Relays:
if not relay.get('observed_bandwidth'):
self.json['relays'][idx]['observed_bandwidth'] = 0
+ def _add_hashed_contact(self):
+ '''
+ Adds a hashed contact key/value for every relay
+ '''
+ for idx, relay in enumerate(self.json['relays']):
+ c = relay.get('contact', '').encode('utf-8')
+ self.json['relays'][idx]['contact_md5'] = hashlib.md5(c).hexdigest()
+
def _sort_by_bandwidth(self):
'''
Sort full JSON list by highest observed_bandwidth, retain this order
diff --git a/allium/templates/contact.html b/allium/templates/contact.html
index ed10631..d060a2d 100644
--- a/allium/templates/contact.html
+++ b/allium/templates/contact.html
@@ -1,10 +1,9 @@
{% extends "relay-list.html" %}
+{% set contact_hash = relays.json['relay_subset'][0]['contact_md5'] %}
{% if relays.json['relay_subset'][0]['contact'] %}
{% set contact = relays.json['relay_subset'][0]['contact']|escape %}
- {% set contact_hash = relays.json['relay_subset'][0]['contact']|hash %}
{% else %}
{% set contact = 'none' %}
- {% set contact_hash = ''|hash %}
{% endif %}
{% block title %}Tor Relays :: Contact {{ contact_hash }}{% endblock %}
{% block header %}<a href="../../">Home</a> :: Contact {{ contact_hash }}{%
diff --git a/allium/templates/misc-families.html b/allium/templates/misc-families.html
index dea08e3..12773c8 100644
--- a/allium/templates/misc-families.html
+++ b/allium/templates/misc-families.html
@@ -56,7 +56,7 @@ reverse=True) -%}
{% if v['contact'] -%}
<td class="visible-md visible-lg"><code><a href="{{ path_prefix }}contact/{{
-v['contact']|hash }}/" title="{{ v['contact']|escape }}">{{
+v['contact_md5'] }}/" title="{{ v['contact']|escape }}">{{
v['contact']|truncate(50)|escape }}<a></td></code>
{% else -%}
<td class="visible-md visible-lg">none</td>
diff --git a/allium/templates/relay-info.html b/allium/templates/relay-info.html
index d26dab3..f2aabe7 100644
--- a/allium/templates/relay-info.html
+++ b/allium/templates/relay-info.html
@@ -17,10 +17,10 @@
<dt>Contact</dt>
{% if relay['contact'] -%}
-<dd><a href="{{ path_prefix }}contact/{{ relay['contact']|hash }}">{{
+<dd><a href="{{ path_prefix }}contact/{{ relay['contact_md5'] }}">{{
relay['contact']|escape }}</a></dd>
{% else -%}
-<dd><a href="{{ path_prefix }}contact/{{ ''|hash }}">none</a></dd>
+<dd><a href="{{ path_prefix }}contact/{{ relay['contact_md5'] }}">none</a></dd>
{% endif -%}
<dt>Dir Address</dt>
diff --git a/allium/templates/relay-list.html b/allium/templates/relay-list.html
index 8283c04..6698755 100644
--- a/allium/templates/relay-list.html
+++ b/allium/templates/relay-list.html
@@ -7,7 +7,7 @@
<tr>
<th></th>
<th>Nickname</th>
-<th></th>
+<th>Contact</th>
<th>Bandwidth</th>
<th class="visible-md visible-lg">IP Address</th>
<th>AS Number</th>
@@ -49,13 +49,15 @@ relay['fingerprint']|escape }}.html">{{ relay['nickname']|truncate(15)|escape
{% if key != 'contact' -%}
{% if relay['contact'] -%}
-<td><a href="{{ path_prefix }}contact/{{ relay['contact']|hash }}/" title="{{
-relay['contact']|escape }}">&#9993;</a></td>
+<td><code><a href="{{ path_prefix }}contact/{{ relay['contact_md5'] }}/"
+title="{{ relay['contact']|escape }}">{{ relay['contact_md5'][0:8]
+}}</a></code></td>
{% else -%}
-<td title="none">&#9993;</td>
+<td title="none"><code>none</code></td>
{% endif -%}
{% else -%}
-<td title="{{ relay['contact']|escape }}">&#9993;</td>
+<td title="{{ relay['contact']|escape }}"><code>{{ relay['contact_md5'][0:8]
+}}</code></td>
{% endif -%}
<td>{{ obs_bandwidth }}</td>