diff --git a/docker/Dockerfile-Debian-Slim b/docker/Dockerfile-Debian-Slim deleted file mode 100644 index e36868e3..00000000 --- a/docker/Dockerfile-Debian-Slim +++ /dev/null @@ -1,3 +0,0 @@ -FROM ubuntu:24.04 - -RUN apt-get update && apt-get full-upgrade -y \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index f5f41f84..a6da4bf9 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -57,7 +57,7 @@ stop_service() { } echo "------------------------- START ----------------------------" -echo "Starting the WireGuard Dashboard Docker container." +echo "Starting the WGDashboard Docker container." ensure_installation() { echo "Quick-installing..." @@ -139,7 +139,7 @@ set_envvars() { set_ini Server app_port "${wgd_port}" # Account settings - process all parameters - echo "Configuring user account:" + [[ -n "$username" ]] && echo "Configuring user account:" # Basic account variables [[ -n "$username" ]] && set_ini Account username "${username}" diff --git a/src/modules/AmneziaWireguardConfiguration.py b/src/modules/AmneziaWireguardConfiguration.py index 8223d01f..1f03ced8 100644 --- a/src/modules/AmneziaWireguardConfiguration.py +++ b/src/modules/AmneziaWireguardConfiguration.py @@ -174,12 +174,18 @@ class AmneziaWireguardConfiguration(WireguardConfiguration): def getPeers(self): self.Peers.clear() + current_app.logger.info(f"Refreshing {self.Name} peer list") + if self.configurationFileChanged(): with open(self.configPath, 'r') as configFile: p = [] pCounter = -1 content = configFile.read().split('\n') try: + if "[Peer]" not in content: + current_app.logger.info(f"{self.Name} config has no [Peer] section") + return + peerStarts = content.index("[Peer]") content = content[peerStarts:] for i in content: diff --git a/src/modules/WireguardConfiguration.py b/src/modules/WireguardConfiguration.py index a58829ed..81cacb94 100644 --- a/src/modules/WireguardConfiguration.py +++ b/src/modules/WireguardConfiguration.py @@ -399,80 +399,82 @@ class WireguardConfiguration: def getPeers(self): tmpList = [] current_app.logger.info(f"Refreshing {self.Name} peer list") + if self.configurationFileChanged(): with open(self.configPath, 'r') as configFile: p = [] pCounter = -1 content = configFile.read().split('\n') try: - if "[Peer]" in content: - peerStarts = content.index("[Peer]") - content = content[peerStarts:] - for i in content: - if not RegexMatch("#(.*)", i) and not RegexMatch(";(.*)", i): - if i == "[Peer]": - pCounter += 1 - p.append({}) - p[pCounter]["name"] = "" - else: - if len(i) > 0: - split = re.split(r'\s*=\s*', i, 1) - if len(split) == 2: - p[pCounter][split[0]] = split[1] - - if RegexMatch("#Name# = (.*)", i): - split = re.split(r'\s*=\s*', i, 1) - if len(split) == 2: - p[pCounter]["name"] = split[1] - - for i in p: - if "PublicKey" in i.keys(): - with self.engine.connect() as conn: - tempPeer = conn.execute( - self.peersTable.select().where( + if "[Peer]" not in content: + current_app.logger.info(f"{self.Name} config has no [Peer] section") + return + + peerStarts = content.index("[Peer]") + content = content[peerStarts:] + for i in content: + if not RegexMatch("#(.*)", i) and not RegexMatch(";(.*)", i): + if i == "[Peer]": + pCounter += 1 + p.append({}) + p[pCounter]["name"] = "" + else: + if len(i) > 0: + split = re.split(r'\s*=\s*', i, 1) + if len(split) == 2: + p[pCounter][split[0]] = split[1] + + if RegexMatch("#Name# = (.*)", i): + split = re.split(r'\s*=\s*', i, 1) + if len(split) == 2: + p[pCounter]["name"] = split[1] + + for i in p: + if "PublicKey" in i.keys(): + with self.engine.connect() as conn: + tempPeer = conn.execute( + self.peersTable.select().where( + self.peersTable.columns.id == i['PublicKey'] + ) + ).mappings().fetchone() + + if tempPeer is None: + tempPeer = { + "id": i['PublicKey'], + "private_key": "", + "DNS": self.DashboardConfig.GetConfig("Peers", "peer_global_DNS")[1], + "endpoint_allowed_ip": self.DashboardConfig.GetConfig("Peers", "peer_endpoint_allowed_ip")[ + 1], + "name": i.get("name"), + "total_receive": 0, + "total_sent": 0, + "total_data": 0, + "endpoint": "N/A", + "status": "stopped", + "latest_handshake": "N/A", + "allowed_ip": i.get("AllowedIPs", "N/A"), + "cumu_receive": 0, + "cumu_sent": 0, + "cumu_data": 0, + "mtu": self.DashboardConfig.GetConfig("Peers", "peer_mtu")[1] if len(self.DashboardConfig.GetConfig("Peers", "peer_mtu")[1]) > 0 else None, + "keepalive": self.DashboardConfig.GetConfig("Peers", "peer_keep_alive")[1] if len(self.DashboardConfig.GetConfig("Peers", "peer_keep_alive")[1]) > 0 else None, + "remote_endpoint": self.DashboardConfig.GetConfig("Peers", "remote_endpoint")[1], + "preshared_key": i["PresharedKey"] if "PresharedKey" in i.keys() else "" + } + with self.engine.begin() as conn: + conn.execute( + self.peersTable.insert().values(tempPeer) + ) + else: + with self.engine.begin() as conn: + conn.execute( + self.peersTable.update().values({ + "allowed_ip": i.get("AllowedIPs", "N/A") + }).where( self.peersTable.columns.id == i['PublicKey'] ) - ).mappings().fetchone() - - if tempPeer is None: - tempPeer = { - "id": i['PublicKey'], - "private_key": "", - "DNS": self.DashboardConfig.GetConfig("Peers", "peer_global_DNS")[1], - "endpoint_allowed_ip": self.DashboardConfig.GetConfig("Peers", "peer_endpoint_allowed_ip")[ - 1], - "name": i.get("name"), - "total_receive": 0, - "total_sent": 0, - "total_data": 0, - "endpoint": "N/A", - "status": "stopped", - "latest_handshake": "N/A", - "allowed_ip": i.get("AllowedIPs", "N/A"), - "cumu_receive": 0, - "cumu_sent": 0, - "cumu_data": 0, - "mtu": self.DashboardConfig.GetConfig("Peers", "peer_mtu")[1] if len(self.DashboardConfig.GetConfig("Peers", "peer_mtu")[1]) > 0 else None, - "keepalive": self.DashboardConfig.GetConfig("Peers", "peer_keep_alive")[1] if len(self.DashboardConfig.GetConfig("Peers", "peer_keep_alive")[1]) > 0 else None, - "remote_endpoint": self.DashboardConfig.GetConfig("Peers", "remote_endpoint")[1], - "preshared_key": i["PresharedKey"] if "PresharedKey" in i.keys() else "" - } - with self.engine.begin() as conn: - conn.execute( - self.peersTable.insert().values(tempPeer) - ) - else: - with self.engine.begin() as conn: - conn.execute( - self.peersTable.update().values({ - "allowed_ip": i.get("AllowedIPs", "N/A") - }).where( - self.peersTable.columns.id == i['PublicKey'] - ) - ) - tmpList.append(Peer(tempPeer, self)) - else: - current_app.logger.warning(f"{self.Name} is an empty configuration") + ) + tmpList.append(Peer(tempPeer, self)) except Exception as e: current_app.logger.error(f"{self.Name} getPeers() Error", e) else: