Can create read only clients
This commit is contained in:
		@@ -51,6 +51,9 @@ pub struct FormRequest {
 | 
			
		||||
    /// Restrict new client to a given network
 | 
			
		||||
    ip_network: Option<String>,
 | 
			
		||||
 | 
			
		||||
    /// Grant read only access to client
 | 
			
		||||
    readonly_client: Option<String>,
 | 
			
		||||
 | 
			
		||||
    /// Delete a specified client id
 | 
			
		||||
    delete_client_id: Option<uuid::Uuid>,
 | 
			
		||||
}
 | 
			
		||||
@@ -111,7 +114,8 @@ pub async fn home(session: Session, form_req: Option<web::Form<FormRequest>>) ->
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            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?;
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -57,6 +57,7 @@
 | 
			
		||||
                <tr>
 | 
			
		||||
                    <th scope="col">ID</th>
 | 
			
		||||
                    <th scope="col">Description</th>
 | 
			
		||||
                    <th scope="col">Read only</th>
 | 
			
		||||
                    <th scope="col">Network</th>
 | 
			
		||||
                    <th scope="col">Created</th>
 | 
			
		||||
                    <th scope="col">Used</th>
 | 
			
		||||
@@ -68,6 +69,13 @@
 | 
			
		||||
                <tr>
 | 
			
		||||
                    <th scope="row">{{ client.id }}</th>
 | 
			
		||||
                    <td>{{ client.description }}</td>
 | 
			
		||||
                    <td>
 | 
			
		||||
                        {% if client.readonly_client %}
 | 
			
		||||
                        <strong>YES</strong>
 | 
			
		||||
                        {% else %}
 | 
			
		||||
                        <i>NO</i>
 | 
			
		||||
                        {% endif %}
 | 
			
		||||
                    </td>
 | 
			
		||||
                    <td>
 | 
			
		||||
                        {% if let Some(net) = client.network %}
 | 
			
		||||
                        {{ net }}
 | 
			
		||||
@@ -78,7 +86,9 @@
 | 
			
		||||
                    <td>{{ client.fmt_created() }}</td>
 | 
			
		||||
                    <td>{{ client.fmt_used() }}</td>
 | 
			
		||||
                    <td>
 | 
			
		||||
                        <button type="button" class="btn btn-danger btn-sm" onclick="deleteClient('{{ client.id }}');">Delete</button>
 | 
			
		||||
                        <button type="button" class="btn btn-danger btn-sm" onclick="deleteClient('{{ client.id }}');">
 | 
			
		||||
                            Delete
 | 
			
		||||
                        </button>
 | 
			
		||||
                    </td>
 | 
			
		||||
                </tr>
 | 
			
		||||
                {% endfor %}
 | 
			
		||||
@@ -111,6 +121,19 @@
 | 
			
		||||
                    <small class="form-text text-muted">Restrict the networks this IP address can be used from.</small>
 | 
			
		||||
                </div>
 | 
			
		||||
 | 
			
		||||
                <br/>
 | 
			
		||||
 | 
			
		||||
                <div class="form-check">
 | 
			
		||||
                    <input class="form-check-input" type="checkbox" value="" checked id="readonly_client"
 | 
			
		||||
                           name="readonly_client"/>
 | 
			
		||||
                    <label class="form-check-label" for="readonly_client">
 | 
			
		||||
                        Readonly client
 | 
			
		||||
                    </label>
 | 
			
		||||
                </div>
 | 
			
		||||
 | 
			
		||||
                <br/>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                <input type="submit" class="btn btn-primary" value="Create client"/>
 | 
			
		||||
            </form>
 | 
			
		||||
        </div>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user