mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-10-02 23:36:17 +00:00
Added Pydantic for configurations info
This commit is contained in:
@@ -12,6 +12,7 @@ from .Peer import Peer
|
||||
from .PeerJobs import PeerJobs
|
||||
from .PeerShareLinks import PeerShareLinks
|
||||
from .Utilities import StringToBoolean, GenerateWireguardPublicKey, RegexMatch
|
||||
from .WireguardConfigurationInfo import WireguardConfigurationInfo
|
||||
|
||||
|
||||
class WireguardConfiguration:
|
||||
@@ -122,6 +123,8 @@ class WireguardConfiguration:
|
||||
if self.getAutostartStatus() and not self.getStatus() and startup:
|
||||
self.toggleConfiguration()
|
||||
print(f"[WGDashboard] Autostart Configuration: {name}")
|
||||
|
||||
self.configurationInfo: WireguardConfigurationInfo | None = None
|
||||
|
||||
def __getProtocolPath(self):
|
||||
return self.DashboardConfig.GetConfig("Server", "wg_conf_path")[1] if self.Protocol == "wg" \
|
||||
@@ -296,6 +299,12 @@ class WireguardConfiguration:
|
||||
sqlalchemy.Column('preshared_key', sqlalchemy.String(255)),
|
||||
extend_existing=True
|
||||
)
|
||||
self.infoTable = sqlalchemy.Table(
|
||||
'ConfigurationsInfo', self.metadata,
|
||||
sqlalchemy.Column('ID', sqlalchemy.String(255), primary_key=True),
|
||||
sqlalchemy.Column('Info', sqlalchemy.Text),
|
||||
extend_existing=True
|
||||
)
|
||||
|
||||
self.metadata.create_all(self.engine)
|
||||
|
||||
@@ -1048,4 +1057,13 @@ class WireguardConfiguration:
|
||||
else:
|
||||
return { "sent": 0, "recv": 0 }
|
||||
else:
|
||||
return { "sent": 0, "recv": 0 }
|
||||
return { "sent": 0, "recv": 0 }
|
||||
|
||||
def readConfigurationInfo(self):
|
||||
with self.engine.connect() as conn:
|
||||
result = conn.execute(
|
||||
self.infoTable.select().where(
|
||||
self.infoTable.c.ID == self.Name
|
||||
)
|
||||
).mappings().fetchone()
|
||||
return result
|
24
src/modules/WireguardConfigurationInfo.py
Normal file
24
src/modules/WireguardConfigurationInfo.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from pydantic import BaseModel, PositiveInt
|
||||
|
||||
class OverridePeerSettingsClass(BaseModel):
|
||||
DNS: str = ''
|
||||
EndpointAllowedIPs: str = ''
|
||||
MTU: str | int = ''
|
||||
PersistentKeepalive: int | str = ''
|
||||
PeerRemoteEndpoint: str = ''
|
||||
ListenPort: int | str = ''
|
||||
|
||||
class PeerGroupsClass(BaseModel):
|
||||
Description: str = ''
|
||||
BackgroundColor: str = ''
|
||||
Peers: list[str] = []
|
||||
|
||||
class WireguardConfigurationInfo(BaseModel):
|
||||
Description: str = ''
|
||||
OverridePeerSettings: OverridePeerSettingsClass = OverridePeerSettingsClass(**{})
|
||||
PeerGroups: dict[str, PeerGroupsClass] = {}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
d = WireguardConfigurationInfo.model_validate_json("{\"Description\": \"Hi!\"}")
|
||||
print(d.model_dump())
|
@@ -13,4 +13,5 @@ sqlalchemy_utils
|
||||
psycopg
|
||||
mysqlclient
|
||||
tzlocal
|
||||
python-jose
|
||||
python-jose
|
||||
pydantic
|
Reference in New Issue
Block a user