forked from Support/sp-hydra-veil-gui
Pass through json file writing to core for error handling
This commit is contained in:
parent
817b797701
commit
39925ad546
2 changed files with 14 additions and 19 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
import json
|
from core.utils.basic_operations.write_or_read_from_json import read_entire_json, write_json_to_file
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
def setup_gui_directory(gui_cache_home, gui_config_home, gui_config_file):
|
def setup_gui_directory(gui_cache_home, gui_config_home, gui_config_file) -> bool:
|
||||||
os.makedirs(gui_cache_home, exist_ok=True)
|
os.makedirs(gui_cache_home, exist_ok=True)
|
||||||
os.makedirs(gui_config_home, exist_ok=True)
|
os.makedirs(gui_config_home, exist_ok=True)
|
||||||
|
|
||||||
|
|
@ -14,24 +14,17 @@ def setup_gui_directory(gui_cache_home, gui_config_home, gui_config_file):
|
||||||
"log_level": "INFO"
|
"log_level": "INFO"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
with open(gui_config_file, 'w') as f:
|
return write_json_to_file(data=default_config, filepath=gui_config_file)
|
||||||
json.dump(default_config, f, indent=4)
|
return True
|
||||||
|
|
||||||
|
def load_gui_config(gui_config_file) -> str|None:
|
||||||
|
"""Pass through to core for better error handling, such as UnicodeDecodeError."""
|
||||||
|
return read_entire_json(gui_config_file)
|
||||||
|
|
||||||
|
|
||||||
def load_gui_config(gui_config_file):
|
def save_gui_config(gui_config_file, config) -> bool:
|
||||||
try:
|
"""Pass through to core for better error handling"""
|
||||||
with open(gui_config_file, 'r') as f:
|
return write_json_to_file(data=config, filepath=gui_config_file)
|
||||||
return json.load(f)
|
|
||||||
except FileNotFoundError:
|
|
||||||
return None
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
logging.error("Invalid GUI config file format")
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def save_gui_config(gui_config_file, config):
|
|
||||||
with open(gui_config_file, 'w') as f:
|
|
||||||
json.dump(config, f, indent=4)
|
|
||||||
|
|
||||||
|
|
||||||
def default_gui_config():
|
def default_gui_config():
|
||||||
|
|
|
||||||
|
|
@ -102,8 +102,10 @@ def extract_endpoint_ip(profile):
|
||||||
wg_conf_path = f'{profile_path}/wg.conf.bak'
|
wg_conf_path = f'{profile_path}/wg.conf.bak'
|
||||||
if not os.path.exists(wg_conf_path):
|
if not os.path.exists(wg_conf_path):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
with open(wg_conf_path, 'r') as f:
|
with open(wg_conf_path, 'r') as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
|
||||||
for line in content.split('\n'):
|
for line in content.split('\n'):
|
||||||
if line.strip().startswith('Endpoint = '):
|
if line.strip().startswith('Endpoint = '):
|
||||||
endpoint = line.strip().split(' = ')[1]
|
endpoint = line.strip().split(' = ')[1]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue