From bdba6db42d6e286089c211eefb1d74dc43f954fe Mon Sep 17 00:00:00 2001 From: Andrea Mistrali Date: Tue, 10 Sep 2024 11:51:53 +0200 Subject: [PATCH] Add support for backfillips --- app/static/main.js | 28 ++++++++++++++++++++++++++-- app/templates/nodes.html | 11 ++++++++++- app/views/rest.py | 8 ++++++++ poetry.lock | 6 +++--- pyproject.toml | 2 +- 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/app/static/main.js b/app/static/main.js index e227ecc..5edb71a 100644 --- a/app/static/main.js +++ b/app/static/main.js @@ -14,12 +14,10 @@ function renameNode(nodeId) { } function createPKA(username) { - console.log(username); var url = `${username}/pakcreate`; var ephemereal = $("#ephemereal").is(":checked"); var reusable = $("#reusable").is(":checked"); var expiration = $("#expiration").val(); - console.log(expiration); $.ajax({ url: url, method: "POST", @@ -65,3 +63,29 @@ function toggleExpired(obj) { $(".pka-expired").addClass("pka-hide"); } } + +function backfillips(obj) { + var url = "backfillips"; + var button = $(obj); + var original = button.html(); + $.ajax({ + url: url, + method: "POST", + dataType: "json", + contentType: "application/json; charset=utf-8", + xhrFields: { + withCredentials: true, + }, + data: {}, + success: function (data) { + if (data.length) { + button.html("Updated"); + } else { + button.html("Done"); + } + setTimeout(function () { + button.html(original); + }, 500); + }, + }); +} diff --git a/app/templates/nodes.html b/app/templates/nodes.html index 3dce487..11840a5 100644 --- a/app/templates/nodes.html +++ b/app/templates/nodes.html @@ -1,7 +1,16 @@ {% extends "base.html" %} {% block content %} -

nodes

+
+
+

nodes

+
+
+ + + +
+

diff --git a/app/views/rest.py b/app/views/rest.py index 181ca7d..9eaea5d 100644 --- a/app/views/rest.py +++ b/app/views/rest.py @@ -9,6 +9,7 @@ from flask import jsonify from hsapi_client import Node, User, Route, PreAuthKey from hsapi_client.preauthkeys import (v1CreatePreAuthKeyRequest, v1ExpirePreAuthKeyRequest) +from hsapi_client.nodes import v1BackfillNodeIPsResponse log = logging.getLogger() @@ -104,3 +105,10 @@ def expirePKA(userName: str, key: str): PreAuthKey().expire(req) return redirect(url_for('main.user', userName=userName)) + + +@rest_blueprint.route('/backfillips', methods=['POST']) +@auth.authorize_admins('default') +def backfillips(): + response = Node().backfillips() + return jsonify(response.changes) diff --git a/poetry.lock b/poetry.lock index 8895be0..0e8e538 100644 --- a/poetry.lock +++ b/poetry.lock @@ -452,13 +452,13 @@ files = [ [[package]] name = "hsapi-client" -version = "0.9.6" +version = "0.9.7" description = "Headscale API client" optional = false python-versions = "<4.0,>=3.11" files = [ - {file = "hsapi_client-0.9.6-py3-none-any.whl", hash = "sha256:441cd219a2384f66511b8cca21224171b4e6753d16d364d984eb9887aa686a6c"}, - {file = "hsapi_client-0.9.6.tar.gz", hash = "sha256:b6a4183fb9cdf95b0e864eec5b79ea18843e25379f928c4770b68e4f1ce8334b"}, + {file = "hsapi_client-0.9.7-py3-none-any.whl", hash = "sha256:6cd8ac2a787112a02d7d5d3e029ceba0749844806b20b3c27247393cccd53def"}, + {file = "hsapi_client-0.9.7.tar.gz", hash = "sha256:7a6bf7cb533a4f0431c322bc292f09559eb27b37177ea2101a6ea559dc0c9e47"}, ] [package.dependencies] diff --git a/pyproject.toml b/pyproject.toml index 7c3a8cb..1608ce6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "hsman" -version = "0.9.15" +version = "0.9.16" description = "Flask Admin webui for Headscale" authors = ["Andrea Mistrali "] license = "BSD"