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:
freetushkan
2026-04-30 17:23:26 +03:00
committed by GitHub
parent 90614a6360
commit 930c4169c5
3 changed files with 51 additions and 26 deletions

View File

@@ -32,11 +32,15 @@ class AmneziaConfiguration(WireguardConfiguration):
self.H2 = 2
self.H3 = 3
self.H4 = 4
self.I1 = "0"
self.I2 = "0"
self.I3 = "0"
self.I4 = "0"
self.I5 = "0"
self.I1 = ""
self.I2 = ""
self.I3 = ""
self.I4 = ""
self.I5 = ""
self.J1 = ""
self.J2 = ""
self.J3 = ""
self.Itime = ""
super().__init__(DashboardConfig, AllPeerJobs, AllPeerShareLinks, DashboardWebHooks, name, data, backup, startup, wg=False)
@@ -79,7 +83,11 @@ class AmneziaConfiguration(WireguardConfiguration):
"I2": self.I2,
"I3": self.I3,
"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):

View File

@@ -206,7 +206,11 @@ class Peer:
"I2": self.configuration.I2,
"I3": self.configuration.I3,
"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 = {

View File

@@ -109,23 +109,31 @@ class WireguardConfiguration:
}
if self.Protocol == 'awg':
self.__parser["Interface"]["Jc"] = self.Jc
self.__parser["Interface"]["Jc"] = self.Jc
self.__parser["Interface"]["Jmin"] = self.Jmin
self.__parser["Interface"]["Jmax"] = self.Jmax
self.__parser["Interface"]["S1"] = self.S1
self.__parser["Interface"]["S2"] = self.S2
self.__parser["Interface"]["S3"] = self.S3
self.__parser["Interface"]["S4"] = self.S4
self.__parser["Interface"]["H1"] = self.H1
self.__parser["Interface"]["H2"] = self.H2
self.__parser["Interface"]["H3"] = self.H3
self.__parser["Interface"]["H4"] = self.H4
self.__parser["Interface"]["I1"] = self.I1
self.__parser["Interface"]["I2"] = self.I2
self.__parser["Interface"]["I3"] = self.I3
self.__parser["Interface"]["I4"] = self.I4
self.__parser["Interface"]["I5"] = self.I5
values = {
"Jc": self.Jc,
"Jmin": self.Jmin,
"Jmax": self.Jmax,
"S1": self.S1,
"S2": self.S2,
"S3": self.S3,
"S4": self.S4,
"H1": self.H1,
"H2": self.H2,
"H3": self.H3,
"H4": self.H4,
"I1": self.I1,
"I2": self.I2,
"I3": self.I3,
"I4": self.I4,
"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():
self.createDatabase()
@@ -1007,8 +1015,10 @@ class WireguardConfiguration:
with open(self.configPath, 'r') as f:
original = [l.rstrip("\n") for l in f.readlines()]
allowEdit = ["Address", "PreUp", "PostUp", "PreDown", "PostDown", "ListenPort", "Table"]
awgKeys = []
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]")
try:
end = original.index("[Peer]")
@@ -1022,7 +1032,10 @@ class WireguardConfiguration:
if split[0] not in allowEdit:
new.append(original[line])
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("")
for line in range(end, len(original)):
new.append(original[line])