Compare commits

...

2 commits

Author SHA1 Message Date
Donald Zou e0d6f35cea Update dashboard.py 2024-08-21 16:15:48 +08:00
Donald Zou 9312e168cb Update dashboard.py 2024-08-21 11:35:10 +08:00

View file

@ -592,7 +592,8 @@ class WireguardConfiguration:
def __getPeers(self): def __getPeers(self):
mt = os.path.getmtime(os.path.join(WG_CONF_PATH, f'{self.Name}.conf')) mt = os.path.getmtime(os.path.join(WG_CONF_PATH, f'{self.Name}.conf'))
# if self.__configFileModifiedTime is None or self.__configFileModifiedTime != mt: if self.__configFileModifiedTime is None or self.__configFileModifiedTime != mt:
print(f"[WGDashboard] WireGuard configuration file modified. Reading {self.Name}.conf now")
self.Peers = [] self.Peers = []
with open(os.path.join(WG_CONF_PATH, f'{self.Name}.conf'), 'r') as configFile: with open(os.path.join(WG_CONF_PATH, f'{self.Name}.conf'), 'r') as configFile:
p = [] p = []
@ -1074,7 +1075,7 @@ def regex_match(regex, text):
def iPv46RegexCheck(ip): def iPv46RegexCheck(ip):
return re.match( return re.match(
'((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))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|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))',
ip) ip)
class DashboardAPIKey: class DashboardAPIKey:
@ -1368,7 +1369,10 @@ def _getWireguardConfigurationAvailableIP(configName: str) -> tuple[bool, list[s
add = p.allowed_ip.split(',') add = p.allowed_ip.split(',')
for i in add: for i in add:
a, c = i.split('/') a, c = i.split('/')
try:
existedAddress.append(ipaddress.ip_address(a.replace(" ", ""))) existedAddress.append(ipaddress.ip_address(a.replace(" ", "")))
except ValueError as e:
print("[WGDashboard] Error: " + str(e))
for p in configuration.getRestrictedPeersList(): for p in configuration.getRestrictedPeersList():
if len(p.allowed_ip) > 0: if len(p.allowed_ip) > 0:
@ -2127,8 +2131,6 @@ def API_Welcome_Finish():
"repeatNewPassword": data["repeatNewPassword"], "repeatNewPassword": data["repeatNewPassword"],
"currentPassword": "admin" "currentPassword": "admin"
}) })
# updateEnableTotp, updateEnableTotpErr = DashboardConfig.SetConfig("Account", "enable_totp", data["enable_totp"])
if not updateUsername or not updatePassword: if not updateUsername or not updatePassword:
return ResponseObject(False, f"{updateUsernameErr},{updatePasswordErr}".strip(",")) return ResponseObject(False, f"{updateUsernameErr},{updatePasswordErr}".strip(","))