Merge pull request #871 from donaldzou/v4.3-dev

Handle backup folder error
This commit is contained in:
Donald Zou
2025-09-11 10:39:13 +08:00
committed by GitHub
5 changed files with 31 additions and 30 deletions

View File

@@ -2,7 +2,7 @@
> 🎉 I'm excited to announce that WGDashboard is officially listed on DigitalOcean's Marketplace! For more information, please visit [Host WGDashboard & WireGuard with DigitalOcean](https://docs.wgdashboard.dev/host-wgdashboard-wireguard-with-digitalocean.html) for more information! > 🎉 I'm excited to announce that WGDashboard is officially listed on DigitalOcean's Marketplace! For more information, please visit [Host WGDashboard & WireGuard with DigitalOcean](https://docs.wgdashboard.dev/host-wgdashboard-wireguard-with-digitalocean.html) for more information!
> [!NOTE] > [!NOTE]
> **Help Wanted 🎉**: Localizing WGDashboard to other languages! If you're willing to help, please visit https://github.com/donaldzou/WGDashboard/issues/397. Many thanks! > **Help Wanted 🎉**: Localizing WGDashboard to other languages! If you're willing to help, please visit https://github.com/WGDashboard/WGDashboard/issues/397. Many thanks!

View File

@@ -122,7 +122,7 @@ Examples:
To build from source: To build from source:
```bash ```bash
git clone https://github.com/donaldzou/WGDashboard.git git clone https://github.com/WGDashboard/WGDashboard.git
cd WGDashboard cd WGDashboard
docker build . -f docker/Dockerfile -t yourname/wgdashboard:latest docker build . -f docker/Dockerfile -t yourname/wgdashboard:latest
``` ```

View File

@@ -433,29 +433,30 @@ def API_getAllWireguardConfigurationBackup():
for protocol in ProtocolsEnabled(): for protocol in ProtocolsEnabled():
directory = os.path.join(DashboardConfig.GetConfig("Server", f"{protocol}_conf_path")[1], 'WGDashboard_Backup') directory = os.path.join(DashboardConfig.GetConfig("Server", f"{protocol}_conf_path")[1], 'WGDashboard_Backup')
files = [(file, os.path.getctime(os.path.join(directory, file))) if os.path.exists(directory):
for file in os.listdir(directory) if os.path.isfile(os.path.join(directory, file))] files = [(file, os.path.getctime(os.path.join(directory, file)))
files.sort(key=lambda x: x[1], reverse=True) for file in os.listdir(directory) if os.path.isfile(os.path.join(directory, file))]
files.sort(key=lambda x: x[1], reverse=True)
for f, ct in files: for f, ct in files:
if RegexMatch(r"^(.*)_(.*)\.(conf)$", f): if RegexMatch(r"^(.*)_(.*)\.(conf)$", f):
s = re.search(r"^(.*)_(.*)\.(conf)$", f) s = re.search(r"^(.*)_(.*)\.(conf)$", f)
name = s.group(1) name = s.group(1)
if name not in existingConfiguration: if name not in existingConfiguration:
if name not in data['NonExistingConfigurations'].keys(): if name not in data['NonExistingConfigurations'].keys():
data['NonExistingConfigurations'][name] = [] data['NonExistingConfigurations'][name] = []
date = s.group(2) date = s.group(2)
d = { d = {
"protocol": protocol, "protocol": protocol,
"filename": f, "filename": f,
"backupDate": date, "backupDate": date,
"content": open(os.path.join(DashboardConfig.GetConfig("Server", f"{protocol}_conf_path")[1], 'WGDashboard_Backup', f), 'r').read() "content": open(os.path.join(DashboardConfig.GetConfig("Server", f"{protocol}_conf_path")[1], 'WGDashboard_Backup', f), 'r').read()
} }
if f.replace(".conf", ".sql") in list(os.listdir(directory)): if f.replace(".conf", ".sql") in list(os.listdir(directory)):
d['database'] = True d['database'] = True
d['databaseContent'] = open(os.path.join(DashboardConfig.GetConfig("Server", f"{protocol}_conf_path")[1], 'WGDashboard_Backup', f.replace(".conf", ".sql")), 'r').read() d['databaseContent'] = open(os.path.join(DashboardConfig.GetConfig("Server", f"{protocol}_conf_path")[1], 'WGDashboard_Backup', f.replace(".conf", ".sql")), 'r').read()
data['NonExistingConfigurations'][name].append(d) data['NonExistingConfigurations'][name].append(d)
return ResponseObject(data=data) return ResponseObject(data=data)
@app.get(f'{APP_PREFIX}/api/createWireguardConfigurationBackup') @app.get(f'{APP_PREFIX}/api/createWireguardConfigurationBackup')
@@ -1192,7 +1193,7 @@ def API_traceroute_execute():
def API_getDashboardUpdate(): def API_getDashboardUpdate():
import urllib.request as req import urllib.request as req
try: try:
r = req.urlopen("https://api.github.com/repos/donaldzou/WGDashboard/releases/latest", timeout=5).read() r = req.urlopen("https://api.github.com/repos/WGDashboard/WGDashboard/releases/latest", timeout=5).read()
data = dict(json.loads(r)) data = dict(json.loads(r))
tagName = data.get('tag_name') tagName = data.get('tag_name')
htmlUrl = data.get('html_url') htmlUrl = data.get('html_url')

View File

@@ -903,7 +903,7 @@ class WireguardConfiguration:
"backupDate": datetime.now().strftime("%Y%m%d%H%M%S") "backupDate": datetime.now().strftime("%Y%m%d%H%M%S")
} }
def getBackups(self, databaseContent: bool = False) -> list[dict[str: str, str: str, str: str]]: def getBackups(self, databaseContent: bool = False) -> list[dict[str, str]]:
backups = [] backups = []
directory = os.path.join(self.__getProtocolPath(), 'WGDashboard_Backup') directory = os.path.join(self.__getProtocolPath(), 'WGDashboard_Backup')

View File

@@ -29,7 +29,7 @@ fi
dashes='---------------------------------------------------------------------------------' dashes='---------------------------------------------------------------------------------'
equals='============================================================' equals='============================================================'
helpMsg="[WGDashboard] Please check ./log/install.txt for more details. For further assistance, please open a ticket on https://github.com/donaldzou/WGDashboard/issues/new/choose, I'm more than happy to help :)" helpMsg="[WGDashboard] Please check ./log/install.txt for more details. For further assistance, please open a ticket on https://github.com/WGDashboard/WGDashboard/issues/new/choose, I'm more than happy to help :)"
print_header(){ print_header(){
printf "=================================================================================\n" printf "=================================================================================\n"
printf "+ <WGDashboard> by Donald Zou - https://github.com/donaldzou +\n" printf "+ <WGDashboard> by Donald Zou - https://github.com/donaldzou +\n"
@@ -525,7 +525,7 @@ update_wgd() {
_installPythonVenv _installPythonVenv
_installPythonPip _installPythonPip
new_ver=$($venv_python -c "import json; import urllib.request; data = urllib.request.urlopen('https://api.github.com/repos/donaldzou/WGDashboard/releases/latest').read(); output = json.loads(data);print(output['tag_name'])") new_ver=$($venv_python -c "import json; import urllib.request; data = urllib.request.urlopen('https://api.github.com/repos/WGDashboard/WGDashboard/releases/latest').read(); output = json.loads(data);print(output['tag_name'])")
if [ "$commandConfirmed" = "true" ]; then if [ "$commandConfirmed" = "true" ]; then
printf "[WGDashboard] Confirmation granted.\n" printf "[WGDashboard] Confirmation granted.\n"
@@ -544,7 +544,7 @@ update_wgd() {
mv wgd.sh wgd.sh.old mv wgd.sh wgd.sh.old
printf "[WGDashboard] Downloading %s from GitHub..." "$new_ver" printf "[WGDashboard] Downloading %s from GitHub..." "$new_ver"
{ date; git stash; git pull https://github.com/donaldzou/WGDashboard.git $new_ver --force; } >> ./log/update.txt { date; git stash; git pull https://github.com/WGDashboard/WGDashboard.git $new_ver --force; } >> ./log/update.txt
chmod +x ./wgd.sh chmod +x ./wgd.sh
sudo ./wgd.sh install sudo ./wgd.sh install
printf "[WGDashboard] Update completed!\n" printf "[WGDashboard] Update completed!\n"