From 428308f07c77b6a374b7f0f9cef8a163c5e52dd2 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 28 Nov 2022 08:53:45 +0100 Subject: support peer aliases --- data/README | 3 +++ data/aliases | 2 ++ docker-compose.yml | 2 ++ etc/nginx/conf.d/default.conf | 8 ++++++++ html/index.html | 27 +++++++++++++++++++++++++-- 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 data/README create mode 100644 data/aliases diff --git a/data/README b/data/README new file mode 100644 index 0000000..526ba86 --- /dev/null +++ b/data/README @@ -0,0 +1,3 @@ +The aliases file has the following format: each line represents a peer. It +must start with a public key; the key is separated from its readable alias by +whitespace. The rest of the line (after the whitespace) is the key's alias. diff --git a/data/aliases b/data/aliases new file mode 100644 index 0000000..388279e --- /dev/null +++ b/data/aliases @@ -0,0 +1,2 @@ +0ey2pXRG/WXIs5NyMITq0qyCIMERxPoO89wisK7LTAY= peer1 +egaZeGPGlOLkVVunaxBav73gGzbwghY17ClWzTD8QXQ= peer2 diff --git a/docker-compose.yml b/docker-compose.yml index 717c23c..7eaa2a2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,8 @@ services: image: egortensin/wg-api-web:latest ports: - '8080:80' + volumes: + - './data:/data:ro' api: << : *default-settings image: james/wg-api:latest diff --git a/etc/nginx/conf.d/default.conf b/etc/nginx/conf.d/default.conf index 176010f..88dcc0f 100644 --- a/etc/nginx/conf.d/default.conf +++ b/etc/nginx/conf.d/default.conf @@ -12,6 +12,14 @@ server { index index.html; } + location = /api/aliases { + alias /data/aliases; + default_type text/plain; + # Disable caching? + add_header Cache-Control no-store; + add_header Last-Modified $date_gmt; + } + location ~ ^/api/(?ListPeers|GetDeviceInfo)$ { proxy_set_header Content-Type application/json; proxy_set_header Referer ""; diff --git a/html/index.html b/html/index.html index d1cf373..92a865f 100644 --- a/html/index.html +++ b/html/index.html @@ -65,7 +65,7 @@ td, th[scope="row"] { - + @@ -191,6 +191,8 @@ PublicKey.prototype = Object.create(Field.prototype); PublicKey.prototype.constructor = PublicKey; PublicKey.prototype.cell_contents = function(value) { + if (value in aliases) + value = aliases[value]; return [in_code(value)]; } @@ -349,6 +351,20 @@ function peers_show() { }); } +var aliases = {}; + +function aliases_parse(data) { + aliases = {}; + data.split(/\r?\n/).forEach(function(line) { + let delim = line.match(/\s+/); + if (!delim) + return; + let key = line.slice(0, delim.index); + let alias = line.slice(delim.index + delim[0].length); + aliases[key] = alias; + }); +} + function device_update() { send_request('GetDeviceInfo', device_show); } @@ -357,9 +373,16 @@ function peers_update() { send_request('ListPeers', peers_show); } +function aliases_update() { + send_request('aliases', function() { + aliases_parse(this.responseText); + peers_update(); + }); +} + function update() { device_update(); - peers_update(); + aliases_update(); } var update_interval_seconds = 30; -- cgit v1.2.3
Public keyPeer Last handshake Endpoint Rx