mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-10-03 07:46:18 +00:00
Added WireguardConfigurationInfo
This commit is contained in:
@@ -125,6 +125,13 @@ class WireguardConfiguration:
|
|||||||
print(f"[WGDashboard] Autostart Configuration: {name}")
|
print(f"[WGDashboard] Autostart Configuration: {name}")
|
||||||
|
|
||||||
self.configurationInfo: WireguardConfigurationInfo | None = None
|
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):
|
def __getProtocolPath(self):
|
||||||
return self.DashboardConfig.GetConfig("Server", "wg_conf_path")[1] if self.Protocol == "wg" \
|
return self.DashboardConfig.GetConfig("Server", "wg_conf_path")[1] if self.Protocol == "wg" \
|
||||||
@@ -794,6 +801,7 @@ class WireguardConfiguration:
|
|||||||
"TotalPeers": len(self.Peers),
|
"TotalPeers": len(self.Peers),
|
||||||
"Protocol": self.Protocol,
|
"Protocol": self.Protocol,
|
||||||
"Table": self.Table,
|
"Table": self.Table,
|
||||||
|
"Info": self.configurationInfo.model_dump()
|
||||||
}
|
}
|
||||||
|
|
||||||
def backupConfigurationFile(self) -> tuple[bool, dict[str, str]]:
|
def backupConfigurationFile(self) -> tuple[bool, dict[str, str]]:
|
||||||
@@ -1059,6 +1067,10 @@ class WireguardConfiguration:
|
|||||||
else:
|
else:
|
||||||
return { "sent": 0, "recv": 0 }
|
return { "sent": 0, "recv": 0 }
|
||||||
|
|
||||||
|
'''
|
||||||
|
Manager WireGuard Configuration Information
|
||||||
|
'''
|
||||||
|
|
||||||
def readConfigurationInfo(self):
|
def readConfigurationInfo(self):
|
||||||
with self.engine.connect() as conn:
|
with self.engine.connect() as conn:
|
||||||
result = conn.execute(
|
result = conn.execute(
|
||||||
@@ -1066,4 +1078,36 @@ class WireguardConfiguration:
|
|||||||
self.infoTable.c.ID == self.Name
|
self.infoTable.c.ID == self.Name
|
||||||
)
|
)
|
||||||
).mappings().fetchone()
|
).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
|
||||||
|
|
||||||
|
|
@@ -9,6 +9,7 @@ class OverridePeerSettingsClass(BaseModel):
|
|||||||
ListenPort: int | str = ''
|
ListenPort: int | str = ''
|
||||||
|
|
||||||
class PeerGroupsClass(BaseModel):
|
class PeerGroupsClass(BaseModel):
|
||||||
|
GroupName: str = ''
|
||||||
Description: str = ''
|
Description: str = ''
|
||||||
BackgroundColor: str = ''
|
BackgroundColor: str = ''
|
||||||
Peers: list[str] = []
|
Peers: list[str] = []
|
||||||
@@ -20,5 +21,5 @@ class WireguardConfigurationInfo(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
d = WireguardConfigurationInfo.model_validate_json("{\"Description\": \"Hi!\"}")
|
d = WireguardConfigurationInfo.model_validate_json("")
|
||||||
print(d.model_dump())
|
print(d.model_dump())
|
@@ -204,7 +204,7 @@ watch(() => route.query.id, (newValue) => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="container-fluid" >
|
<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>
|
||||||
<div class="text-muted d-flex align-items-center gap-2">
|
<div class="text-muted d-flex align-items-center gap-2">
|
||||||
<h5 class="mb-0">
|
<h5 class="mb-0">
|
||||||
@@ -215,6 +215,7 @@ watch(() => route.query.id, (newValue) => {
|
|||||||
<h1 class="mb-0 display-4"><samp>{{configurationInfo.Name}}</samp></h1>
|
<h1 class="mb-0 display-4"><samp>{{configurationInfo.Name}}</samp></h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="ms-sm-auto d-flex gap-2 flex-column">
|
<div class="ms-sm-auto d-flex gap-2 flex-column">
|
||||||
<div class="card rounded-3 bg-transparent ">
|
<div class="card rounded-3 bg-transparent ">
|
||||||
<div class="card-body py-2 d-flex align-items-center">
|
<div class="card-body py-2 d-flex align-items-center">
|
||||||
@@ -258,6 +259,9 @@ watch(() => route.query.id, (newValue) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<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="row mt-3 gy-2 gx-2 mb-2">
|
||||||
<div class="col-12 col-lg-3">
|
<div class="col-12 col-lg-3">
|
||||||
<div class="card rounded-3 bg-transparent h-100">
|
<div class="card rounded-3 bg-transparent h-100">
|
||||||
|
Reference in New Issue
Block a user