mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-13 11:38:21 +00:00
Compare commits
No commits in common. "cfb3d0a3b0d029a0ac16ac6395221bf91645230a" and "2c050ae61d9ff31280cc094318514c01c89f3c2c" have entirely different histories.
cfb3d0a3b0
...
2c050ae61d
13 changed files with 520 additions and 952 deletions
1247
Cargo.lock
generated
1247
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -22,9 +22,7 @@ tower-http = "0.4.4"
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-subscriber = "0.3.17"
|
tracing-subscriber = "0.3.17"
|
||||||
uuid = { version = "1.5.0", features = ["v4"] }
|
uuid = { version = "1.5.0", features = ["v4"] }
|
||||||
|
validator = { version = "0.15", features = ["derive"] }
|
||||||
tera = "1"
|
tera = "1"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
garde = { version = "0.20.0", features = ["full"] }
|
|
||||||
once_cell = "1.19.0"
|
|
||||||
regex = "1.10.5"
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { apiCall } from "../../api";
|
import { apiCall } from '../../api';
|
||||||
import getPlugins from "../../plugins";
|
import getPlugins from '../../plugins';
|
||||||
const p = getPlugins();
|
const p = getPlugins();
|
||||||
|
|
||||||
let peers = $ref({});
|
let peers = $ref({});
|
||||||
|
@ -8,81 +8,65 @@ let loading = $ref(false);
|
||||||
let selection = $ref([] as number[]);
|
let selection = $ref([] as number[]);
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{ heading: "Name", path: "name" },
|
{heading: 'Name', path: 'name'},
|
||||||
{ heading: "Allowed IPs", path: "allowed_ips" },
|
{heading: 'Allowed IPs', path: 'allowed_ips'},
|
||||||
{ heading: "Endpoint", path: "endpoint" },
|
{heading: 'Endpoint', path: 'endpoint'},
|
||||||
{ heading: "Persistent Keepalive", path: "persistent_keepalive" },
|
{heading: 'Persistent Keepalive', path: 'persistent_keepalive'},
|
||||||
{ heading: "Comment", path: "comment" },
|
{heading: 'Comment', path: 'comment'},
|
||||||
];
|
];
|
||||||
|
|
||||||
const displayData = $computed(() => {
|
const displayData = $computed(() => {
|
||||||
let data: any;
|
let data: any;
|
||||||
data = [];
|
data = [];
|
||||||
for (const index in peers) {
|
for (const name in peers) {
|
||||||
data.push({
|
data.push({
|
||||||
name: peers[index].name,
|
name,
|
||||||
allowed_ips: peers[index].allowed_ips,
|
allowed_ips: peers[name].allowed_ips,
|
||||||
endpoint: peers[index].endpoint,
|
endpoint: peers[name].endpoint,
|
||||||
persistent_keepalive: peers[index].persistent_keepalive,
|
persistent_keepalive: peers[name].persistent_keepalive,
|
||||||
comment: peers[index].comment,
|
comment: peers[name].comment,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
|
|
||||||
async function load() {
|
async function load(){
|
||||||
loading = true;
|
loading = true;
|
||||||
let res = await apiCall("vpn.wireguard.peers.list", {});
|
let res = await apiCall('vpn.wireguard.peers.list', {});
|
||||||
if (res.Error === null) {
|
if (res.Error === null) {
|
||||||
console.debug("peers", res.Data);
|
console.debug('peers', res.Data);
|
||||||
peers = res.Data;
|
peers = res.Data;
|
||||||
} else {
|
} else {
|
||||||
console.debug("error", res);
|
console.debug('error', res);
|
||||||
}
|
}
|
||||||
loading = false;
|
loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deletePeer() {
|
async function deletePeer(){
|
||||||
let res = await apiCall("vpn.wireguard.peers.delete", {
|
let res = await apiCall('vpn.wireguard.peers.delete', {name: displayData[selection[0]].name});
|
||||||
name: displayData[selection[0]].name,
|
if (res.Error === null) {
|
||||||
});
|
console.debug('deleted peer');
|
||||||
if (res.Error === null) {
|
} else {
|
||||||
console.debug("deleted peer");
|
console.debug('error', res);
|
||||||
} else {
|
}
|
||||||
console.debug("error", res);
|
load();
|
||||||
}
|
|
||||||
load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function editPeer() {
|
async function editPeer() {
|
||||||
p.router.push(
|
p.router.push(`/vpn/wireguard.peers/edit/${ displayData[selection[0]].name}`);
|
||||||
`/vpn/wireguard.peers/edit/${displayData[selection[0]].name}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async() => {
|
||||||
load();
|
load();
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<TableView
|
<TableView v-model:selection="selection" v-model:data="displayData" title="Peers" :columns="columns" :loading="loading" :table-props="{sort:true, sortSelf: true}">
|
||||||
v-model:selection="selection"
|
<button @click="load">Refresh</button>
|
||||||
v-model:data="displayData"
|
<router-link class="button" to="/vpn/wireguard.peers/edit">Create</router-link>
|
||||||
title="Peers"
|
<button :disabled="selection.length != 1" @click="editPeer">Edit</button>
|
||||||
:columns="columns"
|
<button :disabled="selection.length != 1" @click="deletePeer">Delete</button>
|
||||||
:loading="loading"
|
</TableView>
|
||||||
:table-props="{ sort: true, sortSelf: true }"
|
|
||||||
>
|
|
||||||
<button @click="load">Refresh</button>
|
|
||||||
<router-link class="button" to="/vpn/wireguard.peers/edit"
|
|
||||||
>Create</router-link
|
|
||||||
>
|
|
||||||
<button :disabled="selection.length != 1" @click="editPeer">
|
|
||||||
Edit
|
|
||||||
</button>
|
|
||||||
<button :disabled="selection.length != 1" @click="deletePeer">
|
|
||||||
Delete
|
|
||||||
</button>
|
|
||||||
</TableView>
|
|
||||||
</template>
|
</template>
|
|
@ -1,11 +1,11 @@
|
||||||
use super::definitions::config::Config;
|
use super::definitions::config::Config;
|
||||||
use garde::Validate;
|
|
||||||
use pwhash::sha512_crypt;
|
use pwhash::sha512_crypt;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::sync::{Arc, Mutex, MutexGuard};
|
use std::sync::{Arc, Mutex, MutexGuard};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum ConfigError {
|
pub enum ConfigError {
|
||||||
|
@ -13,7 +13,7 @@ pub enum ConfigError {
|
||||||
SerdeError(#[from] serde_json::Error),
|
SerdeError(#[from] serde_json::Error),
|
||||||
|
|
||||||
#[error("Validation Error")]
|
#[error("Validation Error")]
|
||||||
ValidatonError(#[from] garde::Report),
|
ValidatonError(#[from] validator::ValidationErrors),
|
||||||
|
|
||||||
#[error("Hash Error")]
|
#[error("Hash Error")]
|
||||||
HashError(#[from] pwhash::error::Error),
|
HashError(#[from] pwhash::error::Error),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use garde::Validate;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
use super::firewall;
|
use super::firewall;
|
||||||
use super::firewall::SNATType;
|
use super::firewall::SNATType;
|
||||||
|
@ -17,21 +17,13 @@ use super::vpn;
|
||||||
use crate::macro_db;
|
use crate::macro_db;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
#[garde(skip)]
|
|
||||||
pub config_version: u64,
|
pub config_version: u64,
|
||||||
#[garde(dive)]
|
|
||||||
pub network: network::Network,
|
pub network: network::Network,
|
||||||
#[garde(dive)]
|
|
||||||
pub object: object::Object,
|
pub object: object::Object,
|
||||||
#[garde(dive)]
|
|
||||||
pub system: system::System,
|
pub system: system::System,
|
||||||
#[garde(dive)]
|
|
||||||
pub service: service::Service,
|
pub service: service::Service,
|
||||||
#[garde(dive)]
|
|
||||||
pub vpn: vpn::VPN,
|
pub vpn: vpn::VPN,
|
||||||
#[garde(dive)]
|
|
||||||
pub firewall: firewall::Firewall,
|
pub firewall: firewall::Firewall,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,14 @@
|
||||||
use super::config::Config;
|
|
||||||
use garde::Validate;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
pub struct Firewall {
|
pub struct Firewall {
|
||||||
#[garde(dive)]
|
|
||||||
pub forward_rules: Vec<ForwardRule>,
|
pub forward_rules: Vec<ForwardRule>,
|
||||||
#[garde(dive)]
|
|
||||||
pub destination_nat_rules: Vec<DestinationNATRule>,
|
pub destination_nat_rules: Vec<DestinationNATRule>,
|
||||||
#[garde(dive)]
|
|
||||||
pub source_nat_rules: Vec<SourceNATRule>,
|
pub source_nat_rules: Vec<SourceNATRule>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
#[garde(allow_unvalidated)]
|
|
||||||
pub struct ForwardRule {
|
pub struct ForwardRule {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub services: Vec<String>,
|
pub services: Vec<String>,
|
||||||
|
@ -27,8 +20,6 @@ pub struct ForwardRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
#[garde(allow_unvalidated)]
|
|
||||||
pub struct DestinationNATRule {
|
pub struct DestinationNATRule {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub services: Vec<String>,
|
pub services: Vec<String>,
|
||||||
|
@ -41,8 +32,6 @@ pub struct DestinationNATRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
#[garde(allow_unvalidated)]
|
|
||||||
pub struct SourceNATRule {
|
pub struct SourceNATRule {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub services: Vec<String>,
|
pub services: Vec<String>,
|
||||||
|
|
|
@ -1,23 +1,15 @@
|
||||||
use super::config::Config;
|
|
||||||
use crate::validation;
|
|
||||||
use garde::Validate;
|
|
||||||
use ipnet::IpNet;
|
use ipnet::IpNet;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
pub struct Network {
|
pub struct Network {
|
||||||
#[garde(dive)]
|
|
||||||
pub interfaces: Vec<NetworkInterface>,
|
pub interfaces: Vec<NetworkInterface>,
|
||||||
#[garde(dive)]
|
|
||||||
pub static_routes: Vec<StaticRoute>,
|
pub static_routes: Vec<StaticRoute>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
#[garde(allow_unvalidated)]
|
|
||||||
pub struct NetworkInterface {
|
pub struct NetworkInterface {
|
||||||
#[garde(custom(validation::validate_name))]
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub alias: String,
|
pub alias: String,
|
||||||
pub comment: String,
|
pub comment: String,
|
||||||
|
@ -47,10 +39,7 @@ pub enum AddressingMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
#[garde(allow_unvalidated)]
|
|
||||||
pub struct StaticRoute {
|
pub struct StaticRoute {
|
||||||
#[garde(custom(validation::validate_name))]
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub interface: String,
|
pub interface: String,
|
||||||
pub gateway: String,
|
pub gateway: String,
|
||||||
|
@ -60,8 +49,6 @@ pub struct StaticRoute {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
#[garde(allow_unvalidated)]
|
|
||||||
pub struct Link {
|
pub struct Link {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,16 @@
|
||||||
use super::config::Config;
|
|
||||||
use crate::validation;
|
|
||||||
use garde::Validate;
|
|
||||||
use ipnet::IpNet;
|
use ipnet::IpNet;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
pub struct Object {
|
pub struct Object {
|
||||||
#[garde(dive)]
|
|
||||||
pub addresses: Vec<Address>,
|
pub addresses: Vec<Address>,
|
||||||
#[garde(dive)]
|
|
||||||
pub services: Vec<Service>,
|
pub services: Vec<Service>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
#[garde(allow_unvalidated)]
|
|
||||||
pub struct Address {
|
pub struct Address {
|
||||||
#[garde(custom(validation::validate_name))]
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub address_type: AddressType,
|
pub address_type: AddressType,
|
||||||
pub comment: String,
|
pub comment: String,
|
||||||
|
@ -34,10 +26,7 @@ pub enum AddressType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
#[garde(allow_unvalidated)]
|
|
||||||
pub struct Service {
|
pub struct Service {
|
||||||
#[garde(custom(validation::validate_name))]
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub service_type: ServiceType,
|
pub service_type: ServiceType,
|
||||||
pub comment: String,
|
pub comment: String,
|
||||||
|
|
|
@ -1,22 +1,15 @@
|
||||||
use super::config::Config;
|
|
||||||
use garde::Validate;
|
|
||||||
use macaddr::MacAddr8;
|
use macaddr::MacAddr8;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
pub struct Service {
|
pub struct Service {
|
||||||
#[garde(dive)]
|
|
||||||
pub dhcp_servers: Vec<DHCPServer>,
|
pub dhcp_servers: Vec<DHCPServer>,
|
||||||
#[garde(dive)]
|
|
||||||
pub dns_servers: Vec<DNSServer>,
|
pub dns_servers: Vec<DNSServer>,
|
||||||
#[garde(dive)]
|
|
||||||
pub ntp_servers: Vec<NTPServer>,
|
pub ntp_servers: Vec<NTPServer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
#[garde(allow_unvalidated)]
|
|
||||||
pub struct DHCPServer {
|
pub struct DHCPServer {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub interface: String,
|
pub interface: String,
|
||||||
|
@ -30,8 +23,6 @@ pub struct DHCPServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
#[garde(allow_unvalidated)]
|
|
||||||
pub struct DNSServer {
|
pub struct DNSServer {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub interface: String,
|
pub interface: String,
|
||||||
|
@ -39,8 +30,6 @@ pub struct DNSServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
#[garde(allow_unvalidated)]
|
|
||||||
pub struct NTPServer {
|
pub struct NTPServer {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub interface: String,
|
pub interface: String,
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
use super::config::Config;
|
|
||||||
use crate::validation;
|
|
||||||
use garde::Validate;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
pub struct System {
|
pub struct System {
|
||||||
#[garde(dive)]
|
|
||||||
pub users: Vec<User>,
|
pub users: Vec<User>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
#[garde(allow_unvalidated)]
|
|
||||||
pub struct User {
|
pub struct User {
|
||||||
#[garde(custom(validation::validate_name))]
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub comment: String,
|
pub comment: String,
|
||||||
pub hash: String,
|
pub hash: String,
|
||||||
|
|
|
@ -1,29 +1,19 @@
|
||||||
use super::config::Config;
|
|
||||||
use crate::validation;
|
|
||||||
use garde::Validate;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
pub struct VPN {
|
pub struct VPN {
|
||||||
#[garde(dive)]
|
|
||||||
pub wireguard: Wireguard,
|
pub wireguard: Wireguard,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
pub struct Wireguard {
|
pub struct Wireguard {
|
||||||
#[garde(dive)]
|
|
||||||
pub interfaces: Vec<WireguardInterface>,
|
pub interfaces: Vec<WireguardInterface>,
|
||||||
#[garde(dive)]
|
|
||||||
pub peers: Vec<WireguardPeer>,
|
pub peers: Vec<WireguardPeer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
#[garde(allow_unvalidated)]
|
|
||||||
pub struct WireguardInterface {
|
pub struct WireguardInterface {
|
||||||
#[garde(custom(validation::validate_name))]
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub public_key: String,
|
pub public_key: String,
|
||||||
pub private_key: String,
|
pub private_key: String,
|
||||||
|
@ -33,10 +23,7 @@ pub struct WireguardInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
#[garde(context(Config))]
|
|
||||||
#[garde(allow_unvalidated)]
|
|
||||||
pub struct WireguardPeer {
|
pub struct WireguardPeer {
|
||||||
#[garde(custom(validation::validate_name))]
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub public_key: String,
|
pub public_key: String,
|
||||||
pub preshared_key: Option<String>,
|
pub preshared_key: Option<String>,
|
||||||
|
|
|
@ -25,7 +25,6 @@ mod config_manager;
|
||||||
mod definitions;
|
mod definitions;
|
||||||
mod state;
|
mod state;
|
||||||
mod templates;
|
mod templates;
|
||||||
mod validation;
|
|
||||||
mod web;
|
mod web;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
use {
|
|
||||||
crate::definitions::config::Config, garde::rules::pattern::Matcher, once_cell::sync::Lazy,
|
|
||||||
regex::Regex,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn validate_name(value: &str, _: &Config) -> garde::Result {
|
|
||||||
if value.len() > 32 {
|
|
||||||
return Err(garde::Error::new("name is longer than 32"));
|
|
||||||
}
|
|
||||||
|
|
||||||
static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"/^[0-9A-Za-z_-]*$/g").unwrap());
|
|
||||||
if !RE.is_match(value) {
|
|
||||||
return Err(garde::Error::new("name must only contain 0-9A-Za-z_-"));
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue