mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2026-05-03 09:56:20 +00:00
A patch to support a wide range of AmneziaWG versions. (#1210)
Support for all keys ever used in AmneziaWG has been added. Setting an empty value to a key will prevent it from being used or rendered in the configuration. This ensures flexible support for all versions and specific configurations.
This commit is contained in:
@@ -32,11 +32,15 @@ class AmneziaConfiguration(WireguardConfiguration):
|
|||||||
self.H2 = 2
|
self.H2 = 2
|
||||||
self.H3 = 3
|
self.H3 = 3
|
||||||
self.H4 = 4
|
self.H4 = 4
|
||||||
self.I1 = "0"
|
self.I1 = ""
|
||||||
self.I2 = "0"
|
self.I2 = ""
|
||||||
self.I3 = "0"
|
self.I3 = ""
|
||||||
self.I4 = "0"
|
self.I4 = ""
|
||||||
self.I5 = "0"
|
self.I5 = ""
|
||||||
|
self.J1 = ""
|
||||||
|
self.J2 = ""
|
||||||
|
self.J3 = ""
|
||||||
|
self.Itime = ""
|
||||||
|
|
||||||
super().__init__(DashboardConfig, AllPeerJobs, AllPeerShareLinks, DashboardWebHooks, name, data, backup, startup, wg=False)
|
super().__init__(DashboardConfig, AllPeerJobs, AllPeerShareLinks, DashboardWebHooks, name, data, backup, startup, wg=False)
|
||||||
|
|
||||||
@@ -79,7 +83,11 @@ class AmneziaConfiguration(WireguardConfiguration):
|
|||||||
"I2": self.I2,
|
"I2": self.I2,
|
||||||
"I3": self.I3,
|
"I3": self.I3,
|
||||||
"I4": self.I4,
|
"I4": self.I4,
|
||||||
"I5": self.I5
|
"I5": self.I5,
|
||||||
|
"J1": self.J1,
|
||||||
|
"J2": self.J2,
|
||||||
|
"J3": self.J3,
|
||||||
|
"Itime": self.Itime
|
||||||
}
|
}
|
||||||
|
|
||||||
def createDatabase(self, dbName = None):
|
def createDatabase(self, dbName = None):
|
||||||
|
|||||||
@@ -206,7 +206,11 @@ class Peer:
|
|||||||
"I2": self.configuration.I2,
|
"I2": self.configuration.I2,
|
||||||
"I3": self.configuration.I3,
|
"I3": self.configuration.I3,
|
||||||
"I4": self.configuration.I4,
|
"I4": self.configuration.I4,
|
||||||
"I5": self.configuration.I5
|
"I5": self.configuration.I5,
|
||||||
|
"J1": self.configuration.J1,
|
||||||
|
"J2": self.configuration.J2,
|
||||||
|
"J3": self.configuration.J3,
|
||||||
|
"Itime": self.configuration.Itime
|
||||||
})
|
})
|
||||||
|
|
||||||
peerSection = {
|
peerSection = {
|
||||||
|
|||||||
@@ -109,23 +109,31 @@ class WireguardConfiguration:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.Protocol == 'awg':
|
if self.Protocol == 'awg':
|
||||||
self.__parser["Interface"]["Jc"] = self.Jc
|
values = {
|
||||||
self.__parser["Interface"]["Jc"] = self.Jc
|
"Jc": self.Jc,
|
||||||
self.__parser["Interface"]["Jmin"] = self.Jmin
|
"Jmin": self.Jmin,
|
||||||
self.__parser["Interface"]["Jmax"] = self.Jmax
|
"Jmax": self.Jmax,
|
||||||
self.__parser["Interface"]["S1"] = self.S1
|
"S1": self.S1,
|
||||||
self.__parser["Interface"]["S2"] = self.S2
|
"S2": self.S2,
|
||||||
self.__parser["Interface"]["S3"] = self.S3
|
"S3": self.S3,
|
||||||
self.__parser["Interface"]["S4"] = self.S4
|
"S4": self.S4,
|
||||||
self.__parser["Interface"]["H1"] = self.H1
|
"H1": self.H1,
|
||||||
self.__parser["Interface"]["H2"] = self.H2
|
"H2": self.H2,
|
||||||
self.__parser["Interface"]["H3"] = self.H3
|
"H3": self.H3,
|
||||||
self.__parser["Interface"]["H4"] = self.H4
|
"H4": self.H4,
|
||||||
self.__parser["Interface"]["I1"] = self.I1
|
"I1": self.I1,
|
||||||
self.__parser["Interface"]["I2"] = self.I2
|
"I2": self.I2,
|
||||||
self.__parser["Interface"]["I3"] = self.I3
|
"I3": self.I3,
|
||||||
self.__parser["Interface"]["I4"] = self.I4
|
"I4": self.I4,
|
||||||
self.__parser["Interface"]["I5"] = self.I5
|
"I5": self.I5,
|
||||||
|
"J1": self.J1,
|
||||||
|
"J2": self.J2,
|
||||||
|
"J3": self.J3,
|
||||||
|
"Itime": self.Itime
|
||||||
|
}
|
||||||
|
for key, value in values.items():
|
||||||
|
if value != None and str(value).strip():
|
||||||
|
self.__parser["Interface"][key] = str(value)
|
||||||
|
|
||||||
if "Backup" not in data.keys():
|
if "Backup" not in data.keys():
|
||||||
self.createDatabase()
|
self.createDatabase()
|
||||||
@@ -1007,8 +1015,10 @@ class WireguardConfiguration:
|
|||||||
with open(self.configPath, 'r') as f:
|
with open(self.configPath, 'r') as f:
|
||||||
original = [l.rstrip("\n") for l in f.readlines()]
|
original = [l.rstrip("\n") for l in f.readlines()]
|
||||||
allowEdit = ["Address", "PreUp", "PostUp", "PreDown", "PostDown", "ListenPort", "Table"]
|
allowEdit = ["Address", "PreUp", "PostUp", "PreDown", "PostDown", "ListenPort", "Table"]
|
||||||
|
awgKeys = []
|
||||||
if self.Protocol == 'awg':
|
if self.Protocol == 'awg':
|
||||||
allowEdit += ["Jc", "Jmin", "Jmax", "S1", "S2", "S3", "S4", "H1", "H2", "H3", "H4", "I1", "I2", "I3", "I4", "I5"]
|
awgKeys = ["Jc", "Jmin", "Jmax", "S1", "S2", "S3", "S4", "H1", "H2", "H3", "H4", "I1", "I2", "I3", "I4", "I5", "J1", "J2", "J3", "Itime"]
|
||||||
|
allowEdit += awgKeys
|
||||||
start = original.index("[Interface]")
|
start = original.index("[Interface]")
|
||||||
try:
|
try:
|
||||||
end = original.index("[Peer]")
|
end = original.index("[Peer]")
|
||||||
@@ -1022,7 +1032,10 @@ class WireguardConfiguration:
|
|||||||
if split[0] not in allowEdit:
|
if split[0] not in allowEdit:
|
||||||
new.append(original[line])
|
new.append(original[line])
|
||||||
for key in allowEdit:
|
for key in allowEdit:
|
||||||
new.insert(1, f"{key} = {str(newData[key]).strip()}")
|
val = str(newData.get(key, "")).strip()
|
||||||
|
if key in awgKeys and val == "":
|
||||||
|
continue
|
||||||
|
new.insert(1, f"{key} = {val}")
|
||||||
new.append("")
|
new.append("")
|
||||||
for line in range(end, len(original)):
|
for line in range(end, len(original)):
|
||||||
new.append(original[line])
|
new.append(original[line])
|
||||||
|
|||||||
Reference in New Issue
Block a user