from pydantic import BaseModel, Field from typing import List, Optional, Literal from datetime import datetime # --- PKI Settings Schemas --- class PKISettingBase(BaseModel): fqdn_ca: str = "ovpn-ca" fqdn_server: str = "ovpn-srv" easyrsa_dn: str = "cn_only" easyrsa_req_country: str = "RU" easyrsa_req_province: str = "Moscow" easyrsa_req_city: str = "Moscow" easyrsa_req_org: str = "SomeORG" easyrsa_req_email: str = "info@someorg.local" easyrsa_req_ou: str = "IT" easyrsa_key_size: int = 2048 easyrsa_ca_expire: int = 3650 easyrsa_cert_expire: int = 3649 easyrsa_cert_renew: int = 30 easyrsa_crl_days: int = 3649 easyrsa_batch: bool = True class PKISettingUpdate(PKISettingBase): pass class PKISetting(PKISettingBase): id: int class Config: from_attributes = True # --- System Settings Schemas --- class SystemSettingsBase(BaseModel): protocol: Literal['tcp', 'udp'] = "udp" port: int = 1194 vpn_network: str = "172.20.1.0" vpn_netmask: str = "255.255.255.0" tunnel_type: Literal['FULL', 'SPLIT'] = "FULL" split_routes: List[str] = Field(default_factory=list) duplicate_cn: bool = False crl_verify: bool = False client_to_client: bool = False user_defined_dns: bool = False dns_servers: List[str] = Field(default_factory=list) user_defined_cdscripts: bool = False connect_script: str = "" disconnect_script: str = "" management_interface: bool = False management_interface_address: str = "127.0.0.1" management_interface_address: str = "127.0.0.1" management_port: int = 7505 public_ip: Optional[str] = None tun_mtu: Optional[int] = None mssfix: Optional[int] = None class SystemSettingsUpdate(SystemSettingsBase): pass class SystemSettings(SystemSettingsBase): id: int class Config: from_attributes = True class ConfigResponse(BaseModel): server: Optional[SystemSettings] = None pki: Optional[PKISetting] = None # --- User Profile Schemas --- class UserProfileBase(BaseModel): username: str class UserProfileCreate(UserProfileBase): pass class UserProfile(UserProfileBase): id: int status: str created_at: datetime revoked_at: Optional[datetime] = None expiration_date: Optional[datetime] = None days_remaining: Optional[int] = None is_revoked: bool = False is_expired: bool = False file_path: Optional[str] = None class Config: from_attributes = True