Added WireguardConfigurationInfo

This commit is contained in:
Donald Zou
2025-08-15 11:45:06 +08:00
parent 1e264ca4a1
commit 663c134e60
3 changed files with 52 additions and 3 deletions

View File

@@ -125,6 +125,13 @@ class WireguardConfiguration:
print(f"[WGDashboard] Autostart Configuration: {name}")
self.configurationInfo: WireguardConfigurationInfo | None = None
configurationInfoJson = self.readConfigurationInfo()
if not configurationInfoJson:
self.configurationInfo = WireguardConfigurationInfo(**{})
self.initConfigurationInfo()
else:
self.configurationInfo = WireguardConfigurationInfo.model_validate_json(configurationInfoJson)
def __getProtocolPath(self):
return self.DashboardConfig.GetConfig("Server", "wg_conf_path")[1] if self.Protocol == "wg" \
@@ -794,6 +801,7 @@ class WireguardConfiguration:
"TotalPeers": len(self.Peers),
"Protocol": self.Protocol,
"Table": self.Table,
"Info": self.configurationInfo.model_dump()
}
def backupConfigurationFile(self) -> tuple[bool, dict[str, str]]:
@@ -1059,6 +1067,10 @@ class WireguardConfiguration:
else:
return { "sent": 0, "recv": 0 }
'''
Manager WireGuard Configuration Information
'''
def readConfigurationInfo(self):
with self.engine.connect() as conn:
result = conn.execute(
@@ -1066,4 +1078,36 @@ class WireguardConfiguration:
self.infoTable.c.ID == self.Name
)
).mappings().fetchone()
return result
return result.get('Info')
def initConfigurationInfo(self):
with self.engine.begin() as conn:
conn.execute(
self.infoTable.insert().values(
{
"ID": self.Name,
"Info": self.configurationInfo.model_dump_json()
}
)
)
def storeConfigurationInfo(self):
try:
with self.engine.begin() as conn:
conn.execute(
self.infoTable.update().values(
{
"Info": self.configurationInfo.model_dump_json()
}
).where(
self.infoTable.c.ID == self.Name
)
)
except Exception as e:
return False
def updateConfigurationInfo(self, key: str, value):
if key == "Description":
self.configurationInfo.Description = value

View File

@@ -9,6 +9,7 @@ class OverridePeerSettingsClass(BaseModel):
ListenPort: int | str = ''
class PeerGroupsClass(BaseModel):
GroupName: str = ''
Description: str = ''
BackgroundColor: str = ''
Peers: list[str] = []
@@ -20,5 +21,5 @@ class WireguardConfigurationInfo(BaseModel):
if __name__ == '__main__':
d = WireguardConfigurationInfo.model_validate_json("{\"Description\": \"Hi!\"}")
d = WireguardConfigurationInfo.model_validate_json("")
print(d.model_dump())

View File

@@ -204,7 +204,7 @@ watch(() => route.query.id, (newValue) => {
<template>
<div class="container-fluid" >
<div class="d-flex align-items-sm-center flex-column flex-sm-row gap-3">
<div class="d-flex align-items-sm-start flex-column flex-sm-row gap-3">
<div>
<div class="text-muted d-flex align-items-center gap-2">
<h5 class="mb-0">
@@ -215,6 +215,7 @@ watch(() => route.query.id, (newValue) => {
<h1 class="mb-0 display-4"><samp>{{configurationInfo.Name}}</samp></h1>
</div>
</div>
<div class="ms-sm-auto d-flex gap-2 flex-column">
<div class="card rounded-3 bg-transparent ">
<div class="card-body py-2 d-flex align-items-center">
@@ -258,6 +259,9 @@ watch(() => route.query.id, (newValue) => {
</div>
</div>
<hr>
<input type="text"
placeholder="Want to make some notes? Type it in here :)"
class="form-control rounded-3 bg-transparent form-control-sm text-muted">
<div class="row mt-3 gy-2 gx-2 mb-2">
<div class="col-12 col-lg-3">
<div class="card rounded-3 bg-transparent h-100">