mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-10-03 15:56:17 +00:00
@@ -140,6 +140,9 @@ class WireguardConfiguration:
|
|||||||
else:
|
else:
|
||||||
self.configurationInfo = WireguardConfigurationInfo.model_validate_json(configurationInfoJson.get("Info"))
|
self.configurationInfo = WireguardConfigurationInfo.model_validate_json(configurationInfoJson.get("Info"))
|
||||||
|
|
||||||
|
if self.Status:
|
||||||
|
self.addAutostart()
|
||||||
|
|
||||||
|
|
||||||
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" \
|
||||||
@@ -367,6 +370,18 @@ class WireguardConfiguration:
|
|||||||
s, d = self.DashboardConfig.GetConfig("WireGuardConfiguration", "autostart")
|
s, d = self.DashboardConfig.GetConfig("WireGuardConfiguration", "autostart")
|
||||||
return self.Name in d
|
return self.Name in d
|
||||||
|
|
||||||
|
def addAutostart(self):
|
||||||
|
s, d = self.DashboardConfig.GetConfig("WireGuardConfiguration", "autostart")
|
||||||
|
if self.Name not in d:
|
||||||
|
d.append(self.Name)
|
||||||
|
self.DashboardConfig.SetConfig("WireGuardConfiguration", "autostart", d)
|
||||||
|
|
||||||
|
def removeAutostart(self):
|
||||||
|
s, d = self.DashboardConfig.GetConfig("WireGuardConfiguration", "autostart")
|
||||||
|
if self.Name in d:
|
||||||
|
d.remove(self.Name)
|
||||||
|
self.DashboardConfig.SetConfig("WireGuardConfiguration", "autostart", d)
|
||||||
|
|
||||||
def getRestrictedPeers(self):
|
def getRestrictedPeers(self):
|
||||||
self.RestrictedPeers = []
|
self.RestrictedPeers = []
|
||||||
with self.engine.connect() as conn:
|
with self.engine.connect() as conn:
|
||||||
@@ -825,11 +840,13 @@ class WireguardConfiguration:
|
|||||||
try:
|
try:
|
||||||
check = subprocess.check_output(f"{self.Protocol}-quick down {self.Name}",
|
check = subprocess.check_output(f"{self.Protocol}-quick down {self.Name}",
|
||||||
shell=True, stderr=subprocess.STDOUT)
|
shell=True, stderr=subprocess.STDOUT)
|
||||||
|
self.removeAutostart()
|
||||||
except subprocess.CalledProcessError as exc:
|
except subprocess.CalledProcessError as exc:
|
||||||
return False, str(exc.output.strip().decode("utf-8"))
|
return False, str(exc.output.strip().decode("utf-8"))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
check = subprocess.check_output(f"{self.Protocol}-quick up {self.Name}", shell=True, stderr=subprocess.STDOUT)
|
check = subprocess.check_output(f"{self.Protocol}-quick up {self.Name}", shell=True, stderr=subprocess.STDOUT)
|
||||||
|
self.addAutostart()
|
||||||
except subprocess.CalledProcessError as exc:
|
except subprocess.CalledProcessError as exc:
|
||||||
return False, str(exc.output.strip().decode("utf-8"))
|
return False, str(exc.output.strip().decode("utf-8"))
|
||||||
self.__parseConfigurationFile()
|
self.__parseConfigurationFile()
|
||||||
|
Reference in New Issue
Block a user