Compare commits

..

2 Commits

Author SHA1 Message Date
DaanSelen
e5e9273889 Merge branch 'main' into docker-quit-update 2025-12-14 17:31:02 +01:00
Daan Selen
c4d037047f feat: add better docker stopping response 2025-12-11 00:06:17 +01:00
3 changed files with 23 additions and 22 deletions

View File

@@ -53,10 +53,13 @@ set_ini() {
stop_service() {
echo "[WGDashboard] Stopping WGDashboard..."
kill $runtime_pid
exit 0
}
local max_rounds="10"
local round="0"
local runtime_pid=""
grab_pid() {
max_rounds="10"
round="0"
while true; do
round=$((round + 1))
@@ -77,8 +80,6 @@ stop_service() {
sleep 0.5s
done
kill $runtime_pid
exit 0
}
echo "------------------------- START ----------------------------"
@@ -217,7 +218,6 @@ start_and_monitor() {
[[ ! -d ${WGDASH}/src/log ]] && mkdir ${WGDASH}/src/log
[[ ! -d ${WGDASH}/src/download ]] && mkdir ${WGDASH}/src/download
${WGDASH}/src/venv/bin/gunicorn --config ${WGDASH}/src/gunicorn.conf.py
/usr/sbin/resolvconf -u
@@ -229,14 +229,13 @@ start_and_monitor() {
# Wait a second before continuing, to give the python program some time to get ready.
echo -e "\nEnsuring container continuation."
local max_rounds="10"
local round="0"
max_rounds="10"
round="0"
# Hang in there for 10s for Gunicorn to get ready
while true; do
round=$((round + 1))
local latest_error=$(ls -t ${WGDASH}/src/log/error_*.log 2> /dev/null | head -n 1)
latest_error=$(ls -t ${WGDASH}/src/log/error_*.log 2> /dev/null | head -n 1)
if [[ $round -eq $max_rounds ]]; then
echo "Reached breaking point!"
@@ -264,8 +263,15 @@ start_and_monitor() {
tail -f "$latest_error" &
tail_pid=$!
echo "Grabbing PID..."
grab_pid &
wait $tail_pid
fi
echo "The blocking command has been broken! Script will exit in 3 minutes... Investigate!"
sleep 180s
exit 1
}
# Main execution flow

View File

@@ -18,18 +18,10 @@ def GetRemoteEndpoint() -> str:
@return:
"""
import socket
try:
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s.connect(("1.1.1.1", 80)) # Connecting to a public IP
wgd_remote_endpoint = s.getsockname()[0]
return str(wgd_remote_endpoint)
except (socket.error, OSError):
pass
try:
return socket.gethostbyname(socket.gethostname())
except (socket.error, OSError):
pass
return "127.0.0.1"
def StringToBoolean(value: str):

View File

@@ -404,7 +404,6 @@ class WireguardConfiguration:
try:
if "[Peer]" not in content:
current_app.logger.info(f"{self.Name} config has no [Peer] section")
self.Peers = []
return
peerStarts = content.index("[Peer]")
@@ -666,8 +665,9 @@ class WireguardConfiguration:
if not self.__wgSave():
return False, "Failed to save configuration through WireGuard"
self.getRestrictedPeers()
self.getPeers()
if numOfRestrictedPeers == len(listOfPublicKeys):
return True, f"Restricted {numOfRestrictedPeers} peer(s)"
return False, f"Restricted {numOfRestrictedPeers} peer(s) successfully. Failed to restrict {numOfFailedToRestrictPeers} peer(s)"
@@ -783,7 +783,9 @@ class WireguardConfiguration:
)
).mappings().fetchone()
if cur_i is not None:
# print(cur_i is None)
total_sent = cur_i['total_sent']
# print(cur_i is None)
total_receive = cur_i['total_receive']
cur_total_sent = float(data_usage[i][2]) / (1024 ** 3)
cur_total_receive = float(data_usage[i][1]) / (1024 ** 3)
@@ -1224,6 +1226,7 @@ class WireguardConfiguration:
def __validateOverridePeerSettings(self, key: str, value: str | int) -> tuple[bool, None] | tuple[bool, str]:
status = True
msg = None
print(value)
if key == "DNS" and value:
status, msg = ValidateDNSAddress(value)
elif key == "EndpointAllowedIPs" and value: