summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-06-07 19:53:36 +0000
committerMax Magorsch <arzano@gentoo.org>2020-06-07 19:53:36 +0000
commitdfbd3fa53c78c389bf99940c6726a417e2d52cfb (patch)
treea1d65cb604cca59b62bcd9a83222e416a98df946
parentAdd an option to show all entries in the datatable (diff)
downloadgentoo-mirrorstats-dfbd3fa53c78c389bf99940c6726a417e2d52cfb.tar.gz
gentoo-mirrorstats-dfbd3fa53c78c389bf99940c6726a417e2d52cfb.tar.bz2
gentoo-mirrorstats-dfbd3fa53c78c389bf99940c6726a417e2d52cfb.zip
Check TLS version and display it in the table
Signed-off-by: Max Magorsch <arzano@gentoo.org>
-rwxr-xr-xhtml/generate.py31
-rw-r--r--html/stats.jinja229
2 files changed, 55 insertions, 5 deletions
diff --git a/html/generate.py b/html/generate.py
index d88e030..a4b75e8 100755
--- a/html/generate.py
+++ b/html/generate.py
@@ -15,6 +15,7 @@
import datetime
import socket
+import ssl
import os
import tempfile
import urllib.request, json
@@ -64,6 +65,19 @@ def getIp(hostname):
ip = ""
return ip
+#
+# Get TLS version of the given host
+#
+def getTLSVersion(hostname):
+ socket.setdefaulttimeout(2)
+ try:
+ with socket.create_connection((hostname, 443)) as sock:
+ with ssl.create_default_context().wrap_socket(sock, server_hostname=hostname) as ssock:
+ return ssock.version().replace("TLSv", "", 1)
+ except:
+ print("err")
+ return ''
+
#
# Render the stats template for a given page, i.e. all, rsync, distfiles...
@@ -87,6 +101,12 @@ if os.path.exists(cache_path):
with open(cache_path, mode='rt') as json_file:
try:
cache_data = json.load(json_file)
+ if 'ips' not in cache_data:
+ cache_data['ips'] = {}
+ if 'hosts' not in cache_data:
+ cache_data['hosts'] = {}
+ if 'tls_version' not in cache_data:
+ cache_data['tls_version'] = {}
except:
pass
@@ -150,6 +170,17 @@ def getHostList(mirrorstatsList):
# populate cache with new value
cache_data['ips'][ip] = mirrorGeoData['loc']
+ for host in hosts:
+ if 'https' not in hosts[host]['Protocols']:
+ hosts[host]['TLSVersion'] = ''
+ continue
+ if host in cache_data['tls_version']:
+ hosts[host]['TLSVersion'] = cache_data['tls_version'][host]
+ else:
+ tlsVersion = getTLSVersion(host)
+ hosts[host]['TLSVersion'] = tlsVersion
+ cache_data['tls_version'][host] = tlsVersion
+
return lastUpdate, hosts
diff --git a/html/stats.jinja2 b/html/stats.jinja2
index 22fb50d..02b50ff 100644
--- a/html/stats.jinja2
+++ b/html/stats.jinja2
@@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://assets.gentoo.org/tyrian/v2/tyrian.min.css" rel="stylesheet" media="screen">
<link href="https://www.gentoo.org/assets/css/leaflet.css" rel="stylesheet" media="screen">
- <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/dt-1.10.20/datatables.min.css"/>
+ <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/dt-1.10.21/b-1.6.2/b-colvis-1.6.2/b-print-1.6.2/rg-1.1.2/datatables.min.css"/>
<link rel="icon" href="https://www.gentoo.org/favicon.ico" type="image/x-icon">
</head>
@@ -100,6 +100,7 @@
<th>Protocol</th>
<th class="statusHistory">Daily Stats</th>
<th class="statusHistory">Probe Stats</th>
+ <th class="hide">TLS</th>
<th style="text-align: right;">Last State</th>
</tr>
</thead>
@@ -113,6 +114,7 @@
<td>{{ stat['Protocol'] }}</td>
<td>{{ stat['StateHistory'] }}</td>
<td>{{ stat['ProbeHistory'] }}</td>
+ <td>{{ mirrors[mirror]['TLSVersion'] }}</td>
<td style="text-align: right;">
{% if stat['StatusLastProbe'] == "ok" %}
<span class="badge badge-success">OK</span>
@@ -194,7 +196,7 @@
<script src="https://www.gentoo.org/assets/js/leaflet.js"></script>
- <script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.10.20/rg-1.1.1/datatables.min.js"></script>
+ <script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.10.21/b-1.6.2/b-colvis-1.6.2/b-print-1.6.2/rg-1.1.2/datatables.min.js"></script>
<script>
@@ -302,9 +304,9 @@
</script>
<script>
-
+ var table;
$(document).ready( function () {
- $('#table_id').DataTable({
+ table = $('#table_id').DataTable({
"autoWidth": true,
"iDisplayLength": 25,
"lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
@@ -330,7 +332,24 @@
},
"targets": "statusHistory"
},
- ]
+ {
+ "targets": 'hide',
+ "visible": false
+ }
+ ],
+ buttons: [
+ {
+ extend: 'colvis',
+ columns: ':not(.noVis)'
+ }
+ ],
+ "initComplete": function( settings, json ) {
+ setTimeout(function(){
+ table.buttons().container().prependTo($('#table_id_length'));
+ $('#table_id_length').prepend("<span class='mr-1'> Show </span>");
+ document.getElementsByClassName("buttons-colvis")[0].classList = "custom-select custom-select-sm form-control form-control-sm mr-4";
+ }, 200);
+ }
});
} );