donaldzou / WGDashboard

Simple dashboard for WireGuard VPN written in Python & Vue.js
https://donaldzou.github.io/WGDashboard-Documentation/
Apache License 2.0
1.63k stars 248 forks source link

Edge Case Bug #472

Closed NOXCIS closed 5 days ago

NOXCIS commented 1 week ago

Describe The Problem A clear and concise description of what the bug is.

https://github.com/user-attachments/assets/79a14f27-32ba-442a-8194-99a885377cc4

Expected Error / Traceback

Please provide the error traceback here

Sample of your .conf file

[Interface]
Address = 10.0.0.1/24, fe80::638b:df05:dd54:65d1/64, fe80::3060:9c6d:41e7:13e4/64, fe80::b004:ebe5:df7:86a5/64, fe80::fdc4:33c4:dbe2:3437/64, fe80::1dcd:6d91:349:6b77/64
SaveConfig = true
PostUp = /opt/wireguarddashboard/src/iptable-rules/Admins/tor-postup.sh
PreDown = /opt/wireguarddashboard/src/iptable-rules/Admins/tor-postdown.sh
ListenPort = 4430
PrivateKey = EOeVZ+333333333333333333333333333=
Jc = 5
Jmin = 500
Jmax = 550
S1 = 30
S2 = 40
H1 = 123456
H2 = 67543
H3 = 32345
H4 = 123123

[Peer]
PublicKey = 33333333333333333333333333332HXgnxuVFWQ=
PresharedKey =sssssssssssssssssssssssssssssssssssssssnDTPc=
AllowedIPs = 10.0.0.254/32

[Peer]
PublicKey = bbjwbejhbdwbdbwO11gggggfsbsbxxibbbbixbebxibTAU=
AllowedIPs = 10.0.0.2/32
Endpoint = 10.2.0.1:60547
donaldzou commented 1 week ago

Ohhhhh.. I think there's another user with a similar issue..

What if you wg-quick up ADMIN and wg-quick down ADMIN manually through console?

I found this interesting cuz WGDashboard does not edit the configuration file only when you use the Edit Configuration feature through the UI, other than that is through wg or wg-quick.. maybe this is a bug with WireGuard itself?

NOXCIS commented 1 week ago

@donaldzou Nope, Wireguard works fine and doesnt cause this issue turns out. The AmneziaWG-go is based off of wireguard-go, which doesnt natively handle ipv6 causing a new one to be generated upon interface startup. Youll run into this and other issues trying to intigrate AmneziaWG-go, im still working on the kernel module image, which wouldnt need patching. The only issue sould now be IPV6 Allowed Ip Assignment.

Also there is a typo called "ListenPost" in the dashboard along with some syntax issues with a missing "/" these too... dashboard.py:712: DeprecationWarning: 'maxsplit' is passed as positional argument dashboard.py:707: DeprecationWarning: 'maxsplit' is passed as positional argument

def toggleConfiguration(self) -> [bool, str]:
        self.getStatus()
        interface_address = self.get_awg_iface_address()

        config_file_path = os.path.join(DashboardConfig.GetConfig("Server", "wg_conf_path")[1], f"{self.Name}.conf")

        if self.Status:
            try:
                check = subprocess.check_output(f"wg-quick down {self.Name}",
                                                shell=True, stderr=subprocess.STDOUT)
            except subprocess.CalledProcessError as exc:
                return False, str(exc.output.strip().decode("utf-8"))

            # Write the interface address after bringing it down
            write_error = self.patch_awg_iface_address(interface_address)
            if write_error:
                return write_error
        else:
            try:
                # Extract IPv6 address from the WireGuard configuration file
                with open(config_file_path, 'r') as f:
                    config_data = f.read()

                # Extract the IPv6 address from the Address line
                ipv6_address = None
                for line in config_data.splitlines():
                    if line.strip().startswith("Address"):
                        parts = line.split("=")[1].strip().split(", ")
                        for part in parts:
                            if ":" in part:  # Check if the part looks like an IPv6 address
                                ipv6_address = part.strip()
                                break
                        if ipv6_address:
                            break

                # Modify the logic to continue without IPv6 if not found
                if ipv6_address:
                    # Bring the WireGuard interface up
                    check = subprocess.check_output(f"wg-quick up {self.Name}",
                                                    shell=True, stderr=subprocess.STDOUT)

                    try:
                        # Remove any existing IPv6 addresses for the interface
                        remove_ipv6_cmd = f"ip -6 addr flush dev {self.Name}"
                        subprocess.check_output(remove_ipv6_cmd, shell=True, stderr=subprocess.STDOUT)

                        # Add the new IPv6 address with the desired parameters
                        add_ipv6_cmd = f"ip -6 addr add {ipv6_address} dev {self.Name}"
                        subprocess.check_output(add_ipv6_cmd, shell=True, stderr=subprocess.STDOUT)
                    except subprocess.CalledProcessError as exc:
                        return False, str(exc.output.strip().decode("utf-8"))
                else:
                    # No IPv6 address found, just bring the interface up without modifying IPv6
                    check = subprocess.check_output(f"wg-quick up {self.Name}",
                                                    shell=True, stderr=subprocess.STDOUT)
            except subprocess.CalledProcessError as exc:
                return False, str(exc.output.strip().decode("utf-8"))

        self.getStatus()
        return True, None

WireGate using Static WGDashboard Binary with AmneziaWG Support

https://github.com/user-attachments/assets/921afd53-39c5-4d08-ae44-340d499e9292