The UI for New Configuration is done

This commit is contained in:
Donald Zou
2024-01-31 12:06:44 -05:00
parent 5f4a364095
commit 6b6ad05e3a
13 changed files with 654 additions and 189 deletions
+52 -19
View File
@@ -99,27 +99,31 @@ class WireguardConfiguration:
def __str__(self):
return self.message
def __init__(self, name):
self.Name = name
self.__parser.read(os.path.join(WG_CONF_PATH, f'{self.Name}.conf'))
sections = self.__parser.sections()
if "Interface" not in sections:
raise self.InvalidConfigurationFileException(
"[Interface] section not found in " + os.path.join(WG_CONF_PATH, f'{self.Name}.conf'))
interfaceConfig = dict(self.__parser.items("Interface", True))
for i in dir(self):
if str(i) in interfaceConfig.keys():
if isinstance(getattr(self, i), bool):
setattr(self, i, _strToBool(interfaceConfig[i]))
else:
setattr(self, i, interfaceConfig[i])
def __init__(self, name: str = None):
if name is not None:
self.Name = name
self.__parser.read(os.path.join(WG_CONF_PATH, f'{self.Name}.conf'))
sections = self.__parser.sections()
if "Interface" not in sections:
raise self.InvalidConfigurationFileException(
"[Interface] section not found in " + os.path.join(WG_CONF_PATH, f'{self.Name}.conf'))
interfaceConfig = dict(self.__parser.items("Interface", True))
for i in dir(self):
if str(i) in interfaceConfig.keys():
if isinstance(getattr(self, i), bool):
setattr(self, i, _strToBool(interfaceConfig[i]))
else:
setattr(self, i, interfaceConfig[i])
if self.PrivateKey:
self.PublicKey = self.__getPublicKey()
if self.PrivateKey:
self.PublicKey = self.__getPublicKey()
self.Status = self.__getStatus()
self.Status = self.__getStatus()
# Create tables in database
# Create tables in database
self.__createDatabase()
def __createDatabase(self):
inspector = inspect(engine)
existingTable = inspector.get_table_names()
if self.Name not in existingTable:
@@ -139,6 +143,9 @@ class WireguardConfiguration:
self.Status = self.__getStatus()
return self.__dict__
def newConfiguration(self):
pass
def iPv46RegexCheck(ip):
return re.match(
@@ -447,7 +454,11 @@ def API_AuthenticateLogin():
resp.set_cookie("authToken", authToken)
session.permanent = True
return resp
return ResponseObject(False, "Username, password or OTP is incorrect.")
if totpEnabled:
return ResponseObject(False, "Sorry, your username, password or OTP is incorrect.")
else:
return ResponseObject(False, "Sorry, your username or password is incorrect.")
@app.route('/api/signout')
@@ -463,6 +474,28 @@ def API_getWireguardConfigurations():
return ResponseObject(data=[wc.toJSON() for wc in WireguardConfigurations])
@app.route('/api/addWireguardConfiguration', methods=["POST"])
def API_addWireguardConfiguration():
data = request.get_json()
keys = [
"ConfigurationName",
"Address",
"ListenPort",
"PrivateKey",
"PublicKey",
"PresharedKey",
"PreUp",
"PreDown",
"PostUp",
"PostDown",
"UsePreSharedKey"
]
requiredKeys = [
"ConfigurationName", "Address", "ListenPort", "PrivateKey"
]
@app.route('/api/getDashboardConfiguration', methods=["GET"])
def API_getDashboardConfiguration():
return ResponseObject(data=DashboardConfig.toJSON())