diff options
author | Jordan <me@jordan.im> | 2020-09-16 01:58:06 -0700 |
---|---|---|
committer | Jordan <me@jordan.im> | 2020-09-16 01:58:06 -0700 |
commit | 83ee11ebae9d0900ab98bd6583396ce0ff5f8b40 (patch) | |
tree | 9990e592d6117557f8918b240535c67cdb2edf29 /tor-metrics | |
parent | 3401a3efba57b7948632b9fc96ace5db89e6b040 (diff) | |
download | allium-83ee11ebae9d0900ab98bd6583396ce0ff5f8b40.tar.gz allium-83ee11ebae9d0900ab98bd6583396ce0ff5f8b40.zip |
template cleanup, make First Seen clickable, closes #3
Diffstat (limited to 'tor-metrics')
-rwxr-xr-x | tor-metrics/generate.py | 1 | ||||
-rw-r--r-- | tor-metrics/relays.py | 7 | ||||
-rw-r--r-- | tor-metrics/templates/first_seen.html | 4 | ||||
-rw-r--r-- | tor-metrics/templates/relay-info.html | 2 | ||||
-rw-r--r-- | tor-metrics/templates/relay-list.html | 44 |
5 files changed, 40 insertions, 18 deletions
diff --git a/tor-metrics/generate.py b/tor-metrics/generate.py index 26af5b2..4315e7d 100755 --- a/tor-metrics/generate.py +++ b/tor-metrics/generate.py @@ -78,6 +78,7 @@ if __name__ == '__main__': RELAY_SET.write_pages_by_key('family') RELAY_SET.write_pages_by_key('flag') RELAY_SET.write_pages_by_key('platform') + RELAY_SET.write_pages_by_key('first_seen') RELAY_SET.write_relay_info() # copy static directory and its contents diff --git a/tor-metrics/relays.py b/tor-metrics/relays.py index 60014c0..97e1514 100644 --- a/tor-metrics/relays.py +++ b/tor-metrics/relays.py @@ -8,6 +8,7 @@ timestamp import hashlib import json import os +import re import time import urllib.request from shutil import rmtree @@ -134,7 +135,7 @@ class Relays: :k: the name of the key to use in self.sorted :v: the name of the subkey to use in self.sorted[k] ''' - if not v or not v.isalnum(): + if not v or not re.match(r'^[A-Za-z0-9_-]+$', v): return if not k in self.json['sorted']: self.json['sorted'][k] = dict() @@ -187,6 +188,8 @@ class Relays: continue self._sort(relay, idx, 'family', member) + self._sort(relay, idx, 'first_seen', relay['first_seen'].split(' ')[0]) + c_str = relay.get('contact', '').encode('utf-8') c_hash = hashlib.md5(c_str).hexdigest() self._sort(relay, idx, 'contact', c_hash) @@ -249,7 +252,7 @@ class Relays: middle_count = i['middle_count'], is_index = False, path_prefix = '../../', - deactivate = k, + key = k, value = v, sp_countries = countries.THE_PREFIXED ) diff --git a/tor-metrics/templates/first_seen.html b/tor-metrics/templates/first_seen.html new file mode 100644 index 0000000..9b40362 --- /dev/null +++ b/tor-metrics/templates/first_seen.html @@ -0,0 +1,4 @@ +{% extends "relay-list.html" %} +{% block title %}Tor Relays :: {{ value }}{% endblock %} +{% block header %}<a href="../../">Home</a> :: {{ value }}{% endblock %} +{% block description %}Relays started on {{ value }} are responsible for ~{{ bandwidth }} MB/s of traffic, with {% if middle_count > 0 %}{{ middle_count }} middle relay{% if middle_count > 1 %}s{% endif %}{% if exit_count > 0 %} and {% endif %}{% endif %}{% if exit_count > 0 %}{{ exit_count }} exit relay{% if exit_count > 1 %}s{% endif %}{% endif %}.{% endblock %} diff --git a/tor-metrics/templates/relay-info.html b/tor-metrics/templates/relay-info.html index 666be11..9dc3f1c 100644 --- a/tor-metrics/templates/relay-info.html +++ b/tor-metrics/templates/relay-info.html @@ -153,7 +153,7 @@ {% endif -%} <dt>First Seen</dt> - <dd>{{ relay['first_seen']|escape }}</dd> + <dd><a href="{{ path_prefix }}first_seen/{{ relay['first_seen'].split(' ', 1)[0]|escape }}">{{ relay['first_seen']|escape }}</a></dd> <dt>Last Restarted</dt> <dd>{{ relay['last_restarted']|escape }}</dd> diff --git a/tor-metrics/templates/relay-list.html b/tor-metrics/templates/relay-list.html index 1275de1..4ecadd6 100644 --- a/tor-metrics/templates/relay-list.html +++ b/tor-metrics/templates/relay-list.html @@ -27,55 +27,69 @@ {% else %} {% set obs_bandwidth = '%s %s'|format((relay['observed_bandwidth'] / 1000)|round(2, 'common'), 'KB/s') %}{% endif %} - {% if deactivate != 'family' and relay['effective_family']|length > 1 %} + {% if key != 'family' and relay['effective_family']|length > 1 %} <td title="{{ relay['nickname']|escape }}"><a href="{{ path_prefix }}relay/{{ relay['fingerprint']|escape }}.html">{{ relay['nickname']|truncate(10)|escape }}</a> (<a href="{{ path_prefix }}family/{{ relay['effective_family'][0]|escape }}/">{{ relay['effective_family']|length }}</a>)</td> {% else %} - <td title="{{ relay['nickname']|escape }}"><a href="{{ path_prefix}}relay/{{ relay['fingerprint']|escape }}.html">{{ relay['nickname']|truncate(15)|escape }}</a></td>{% endif %} + <td title="{{ relay['nickname']|escape }}"><a href="{{ path_prefix}}relay/{{ relay['fingerprint']|escape }}.html">{{ relay['nickname']|truncate(15)|escape }}</a></td> + {% endif %} - {% if deactivate != 'contact' %} + {% if key != 'contact' %} {% if relay['contact'] %} <td><a href="{{ path_prefix }}contact/{{ relay['contact']|hash }}/" title="{{ relay['contact']|escape }}">✉</a></td> {% else %} - <td title="none">✉</td>{% endif %} + <td title="none">✉</td> + {% endif %} {% else %} - <td title="{{ relay['contact']|escape }}">✉</td>{% endif %} + <td title="{{ relay['contact']|escape }}">✉</td> + {% endif %} <td>{{ obs_bandwidth }}</td> <td class="visible-md visible-lg"><a href="https://bgp.he.net/ip/{{ relay['or_addresses'][0].split(':', 1)[0]|escape }}">{{ relay['or_addresses'][0].split(':', 1)[0]|escape }}</a></td> - {% if relay['as'] %}{% if deactivate != 'as' %} + {% if relay['as'] %}{% if key != 'as' %} <td><a href="{{ path_prefix }}as/{{ relay['as']|escape }}/">{{ relay['as']|escape }}</a></td> {% else %} - <td>{{ relay['as']|escape }}</td>{% endif %} + <td>{{ relay['as']|escape }}</td> + {% endif %} {% else %} - <td>Unknown</td>{% endif %} + <td>Unknown</td> + {% endif %} {% if relay['as_name'] %} <td><a href="https://bgp.he.net/{{ relay['as']|escape }}" title="{{ relay['as_name']|escape }}">{{ relay['as_name']|escape|truncate(length=20) }}</a></td> {% else %} - <td>Unknown</td>{% endif %} + <td>Unknown</td> + {% endif %} - {% if relay['country'] %}{% if deactivate != 'country' %} + {% if relay['country'] %}{% if key != 'country' %} <td><a href="{{ path_prefix }}country/{{ relay['country']|escape }}/"><img src="{{ path_prefix }}static/images/cc/{{ relay['country']|escape }}.png" title="{{ relay['country_name']|escape }}" alt="{{ relay['country_name']|escape }}"></a></td> {% else %} - <td><img src="{{ path_prefix }}static/images/cc/{{ relay['country']|escape }}.png" title="{{ relay['country_name']|escape }}" alt="{{ relay['country_name']|escape }}"></td>{% endif %} + <td><img src="{{ path_prefix }}static/images/cc/{{ relay['country']|escape }}.png" title="{{ relay['country_name']|escape }}" alt="{{ relay['country_name']|escape }}"></td> + {% endif %} {% else %} - <td>X</td>{% endif %} + <td>X</td> + {% endif %} - {% if deactivate != 'platform' %} + {% if key != 'platform' %} <td><a href="{{ path_prefix }}platform/{{ relay['platform']|escape }}/">{{ relay['platform']|truncate(length=10)|escape }}</a></td> {% else %} - <td>{{ relay['platform']|truncate(length=10)|escape }}</td>{% endif %} + <td>{{ relay['platform']|truncate(length=10)|escape }}</td> + {% endif %} <td>{% for flag in relay['flags'] %}{% if flag != 'StaleDesc' %}<a href="{{ path_prefix }}flag/{{ flag.lower()|escape }}"><img src="{{ path_prefix}}static/images/flags/{{ flag.lower()|escape }}.png" title="{{ flag|escape }}" alt="{{ flag|escape }}"></a> {% endif %}{% endfor %}</td> {% if relay['running'] %} <td class="visible-md visible-lg"><font color="green">True</font></td> {% else %} - <td class="visible-md visible-lg"><font color="red">False</font></td>{% endif %} + <td class="visible-md visible-lg"><font color="red">False</font></td> + {% endif %} + {% if key != 'first_seen' %} + <td class="visible-md visible-lg"><a href="{{ path_prefix }}first_seen/{{ relay['first_seen'].split(' ', 1)[0]|escape }}">{{ relay['first_seen'].split(' ', 1)[0]|escape }}</a></td> + {% else %} <td class="visible-md visible-lg">{{ relay['first_seen'].split(' ', 1)[0]|escape }}</td> + {% endif %} </tr> {% endfor %} </tbody> |