From b92149a77d4d1662e4ef279f6267d5a4de2698f3 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 27 Jan 2025 22:57:09 +0100 Subject: [PATCH] Can create read only clients --- src/server/web_ui.rs | 6 +++++- src/user.rs | 4 ++++ templates/index.html | 25 ++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/server/web_ui.rs b/src/server/web_ui.rs index 237d171..ac6793e 100644 --- a/src/server/web_ui.rs +++ b/src/server/web_ui.rs @@ -51,6 +51,9 @@ pub struct FormRequest { /// Restrict new client to a given network ip_network: Option, + /// Grant read only access to client + readonly_client: Option, + /// Delete a specified client id delete_client_id: Option, } @@ -111,7 +114,8 @@ pub async fn home(session: Session, form_req: Option>) -> }; if error_message.is_none() { - let token = APIClient::generate(new_token_desc, ip_net); + let mut token = APIClient::generate(new_token_desc, ip_net); + token.readonly_client = form_req.0.readonly_client.is_some(); success_message = Some(format!("The secret of your new token is '{}'. Be sure to write it somewhere as you will not be able to recover it later!", token.secret)); config.clients.push(token); config.save().await?; diff --git a/src/user.rs b/src/user.rs index 5fc3cac..56f60dd 100644 --- a/src/user.rs +++ b/src/user.rs @@ -49,6 +49,9 @@ pub struct APIClient { /// Client last usage time pub used: u64, + + /// Read only access + pub readonly_client: bool, } impl APIClient { @@ -71,6 +74,7 @@ impl APIClient { secret: rand_str(TOKEN_LEN), created: curr_time().unwrap(), used: curr_time().unwrap(), + readonly_client: true, } } } diff --git a/templates/index.html b/templates/index.html index 93dd0ca..7857fcc 100644 --- a/templates/index.html +++ b/templates/index.html @@ -57,6 +57,7 @@ ID Description + Read only Network Created Used @@ -68,6 +69,13 @@ {{ client.id }} {{ client.description }} + + {% if client.readonly_client %} + YES + {% else %} + NO + {% endif %} + {% if let Some(net) = client.network %} {{ net }} @@ -78,7 +86,9 @@ {{ client.fmt_created() }} {{ client.fmt_used() }} - + {% endfor %} @@ -111,6 +121,19 @@ Restrict the networks this IP address can be used from. +
+ +
+ + +
+ +
+ +