mirror of
https://github.com/speatzle/nfsense.git
synced 2025-09-13 15:19:08 +00:00
Add name validation
This commit is contained in:
parent
7d0b9c5c3b
commit
fca86ca590
11 changed files with 60 additions and 0 deletions
|
@ -17,6 +17,7 @@ use super::vpn;
|
|||
use crate::macro_db;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||
#[garde(context(Config))]
|
||||
pub struct Config {
|
||||
#[garde(skip)]
|
||||
pub config_version: u64,
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
use super::config::Config;
|
||||
use garde::Validate;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||
#[garde(context(Config))]
|
||||
pub struct Firewall {
|
||||
#[garde(dive)]
|
||||
pub forward_rules: Vec<ForwardRule>,
|
||||
|
@ -12,6 +14,7 @@ pub struct Firewall {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||
#[garde(context(Config))]
|
||||
#[garde(allow_unvalidated)]
|
||||
pub struct ForwardRule {
|
||||
pub name: String,
|
||||
|
@ -24,6 +27,7 @@ pub struct ForwardRule {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||
#[garde(context(Config))]
|
||||
#[garde(allow_unvalidated)]
|
||||
pub struct DestinationNATRule {
|
||||
pub name: String,
|
||||
|
@ -37,6 +41,7 @@ pub struct DestinationNATRule {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||
#[garde(context(Config))]
|
||||
#[garde(allow_unvalidated)]
|
||||
pub struct SourceNATRule {
|
||||
pub name: String,
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
use super::config::Config;
|
||||
use crate::validation;
|
||||
use garde::Validate;
|
||||
use ipnet::IpNet;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||
#[garde(context(Config))]
|
||||
pub struct Network {
|
||||
#[garde(dive)]
|
||||
pub interfaces: Vec<NetworkInterface>,
|
||||
|
@ -11,8 +14,10 @@ pub struct Network {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||
#[garde(context(Config))]
|
||||
#[garde(allow_unvalidated)]
|
||||
pub struct NetworkInterface {
|
||||
#[garde(custom(validation::validate_name))]
|
||||
pub name: String,
|
||||
pub alias: String,
|
||||
pub comment: String,
|
||||
|
@ -42,8 +47,10 @@ pub enum AddressingMode {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||
#[garde(context(Config))]
|
||||
#[garde(allow_unvalidated)]
|
||||
pub struct StaticRoute {
|
||||
#[garde(custom(validation::validate_name))]
|
||||
pub name: String,
|
||||
pub interface: String,
|
||||
pub gateway: String,
|
||||
|
@ -53,6 +60,7 @@ pub struct StaticRoute {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||
#[garde(context(Config))]
|
||||
#[garde(allow_unvalidated)]
|
||||
pub struct Link {
|
||||
pub name: String,
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
use super::config::Config;
|
||||
use crate::validation;
|
||||
use garde::Validate;
|
||||
use ipnet::IpNet;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::net::IpAddr;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||
#[garde(context(Config))]
|
||||
pub struct Object {
|
||||
#[garde(dive)]
|
||||
pub addresses: Vec<Address>,
|
||||
|
@ -12,8 +15,10 @@ pub struct Object {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||
#[garde(context(Config))]
|
||||
#[garde(allow_unvalidated)]
|
||||
pub struct Address {
|
||||
#[garde(custom(validation::validate_name))]
|
||||
pub name: String,
|
||||
pub address_type: AddressType,
|
||||
pub comment: String,
|
||||
|
@ -29,8 +34,10 @@ pub enum AddressType {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||
#[garde(context(Config))]
|
||||
#[garde(allow_unvalidated)]
|
||||
pub struct Service {
|
||||
#[garde(custom(validation::validate_name))]
|
||||
pub name: String,
|
||||
pub service_type: ServiceType,
|
||||
pub comment: String,
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
use super::config::Config;
|
||||
use garde::Validate;
|
||||
use macaddr::MacAddr8;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||
#[garde(context(Config))]
|
||||
pub struct Service {
|
||||
#[garde(dive)]
|
||||
pub dhcp_servers: Vec<DHCPServer>,
|
||||
|
@ -13,6 +15,7 @@ pub struct Service {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||
#[garde(context(Config))]
|
||||
#[garde(allow_unvalidated)]
|
||||
pub struct DHCPServer {
|
||||
pub name: String,
|
||||
|
@ -27,6 +30,7 @@ pub struct DHCPServer {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||
#[garde(context(Config))]
|
||||
#[garde(allow_unvalidated)]
|
||||
pub struct DNSServer {
|
||||
pub name: String,
|
||||
|
@ -35,6 +39,7 @@ pub struct DNSServer {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||
#[garde(context(Config))]
|
||||
#[garde(allow_unvalidated)]
|
||||
pub struct NTPServer {
|
||||
pub name: String,
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
use super::config::Config;
|
||||
use crate::validation;
|
||||
use garde::Validate;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||
#[garde(context(Config))]
|
||||
pub struct System {
|
||||
#[garde(dive)]
|
||||
pub users: Vec<User>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||
#[garde(context(Config))]
|
||||
#[garde(allow_unvalidated)]
|
||||
pub struct User {
|
||||
#[garde(custom(validation::validate_name))]
|
||||
pub name: String,
|
||||
pub comment: String,
|
||||
pub hash: String,
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
use super::config::Config;
|
||||
use crate::validation;
|
||||
use garde::Validate;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||
#[garde(context(Config))]
|
||||
pub struct VPN {
|
||||
#[garde(dive)]
|
||||
pub wireguard: Wireguard,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||
#[garde(context(Config))]
|
||||
pub struct Wireguard {
|
||||
#[garde(dive)]
|
||||
pub interfaces: Vec<WireguardInterface>,
|
||||
|
@ -16,8 +20,10 @@ pub struct Wireguard {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||
#[garde(context(Config))]
|
||||
#[garde(allow_unvalidated)]
|
||||
pub struct WireguardInterface {
|
||||
#[garde(custom(validation::validate_name))]
|
||||
pub name: String,
|
||||
pub public_key: String,
|
||||
pub private_key: String,
|
||||
|
@ -27,8 +33,10 @@ pub struct WireguardInterface {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||
#[garde(context(Config))]
|
||||
#[garde(allow_unvalidated)]
|
||||
pub struct WireguardPeer {
|
||||
#[garde(custom(validation::validate_name))]
|
||||
pub name: String,
|
||||
pub public_key: String,
|
||||
pub preshared_key: Option<String>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue