diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2022-11-28 08:53:45 +0100 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2022-11-28 08:53:45 +0100 |
commit | 428308f07c77b6a374b7f0f9cef8a163c5e52dd2 (patch) | |
tree | 36c439efa29bf1b724ecaab6180e30edffd3b47f | |
parent | workflows/ci: set-output is deprecated (diff) | |
download | wg-api-web-0.1.0.tar.gz wg-api-web-0.1.0.zip |
support peer aliasesv0.1.0
-rw-r--r-- | data/README | 3 | ||||
-rw-r--r-- | data/aliases | 2 | ||||
-rw-r--r-- | docker-compose.yml | 2 | ||||
-rw-r--r-- | etc/nginx/conf.d/default.conf | 8 | ||||
-rw-r--r-- | html/index.html | 27 |
5 files changed, 40 insertions, 2 deletions
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/(?<rpc_method>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"] { <table> <thead> <tr> - <th>Public key</th> + <th>Peer</th> <th>Last handshake</th> <th>Endpoint</th> <th>Rx</th> @@ -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; |