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 252 forks source link

API: addPeers error (500 Internal Server Error) #454

Closed NovianPutera closed 2 weeks ago

NovianPutera commented 2 weeks ago

500 Internal Server Error after test addPeers

Method Post, URL:

http://{server}:10086/api/addPeers/wg2

wg2 = our name configuration wg-dashboard-apikey = included in header

Error Log

ERROR in app: Exception on /api/addPeers/wg2 [POST]
Traceback (most recent call last):
  File "/home/folder/WGDashboard/src/venv/lib/python3.11/site-packages/flask/app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/folder/WGDashboard/src/venv/lib/python3.11/site-packages/flask/app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/folder/WGDashboard/src/venv/lib/python3.11/site-packages/flask_cors/extension.py", line 194, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
                                                ^^^^^^^^^^^^^^^^^^
  File "/home/folder/WGDashboard/src/venv/lib/python3.11/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/folder/WGDashboard/src/venv/lib/python3.11/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/folder/WGDashboard/src/dashboard.py", line 1811, in API_addPeers
    bulkAdd = data['bulkAdd']
              ~~~~^^^^^^^^^^^
KeyError: 'bulkAdd'

Version Information:

Body Params

{
    "name": "testing",
    "allowed_ips": [
        "{pick avalaible IP from api/getAvailableIPs}"
    ],
    "private_key": "{manual wg genkey on server}",
    "public_key": "{pubkey from manual wg genkey on server}",
    "preshared_key": "{manual wg genpsk on server}",
    "DNS": "1.1.1.1",
    "endpoint_allowed_ip": "0.0.0.0/0",
    "keepalive": 21,
    "mtu": 1420
}

Screenshot 2024-11-05 at 15 42 22

donaldzou commented 2 weeks ago

Uh oh.. this is my bad.. you can add this line into your JSON body to prevent this issue:

{
        "bulkAdd": false, // This line
    "name": "testing",
    "allowed_ips": [
        "{pick avalaible IP from api/getAvailableIPs}"
    ],
    "private_key": "{manual wg genkey on server}",
    "public_key": "{pubkey from manual wg genkey on server}",
    "preshared_key": "{manual wg genpsk on server}",
    "DNS": "1.1.1.1",
    "endpoint_allowed_ip": "0.0.0.0/0",
    "keepalive": 21,
    "mtu": 1420
}

This won't need in the next release :)

NovianPutera commented 2 weeks ago

Thanks, I tried that. But it still doesn't seem to work. The current error requires 'bulkAddAmount' in error.log

Error Log

ERROR in app: Exception on /api/addPeers/wg2 [POST]
Traceback (most recent call last):
  File "/home/folder/WGDashboard/src/venv/lib/python3.11/site-packages/flask/app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/folder/WGDashboard/src/venv/lib/python3.11/site-packages/flask/app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/folder/WGDashboard/src/venv/lib/python3.11/site-packages/flask_cors/extension.py", line 194, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
                                                ^^^^^^^^^^^^^^^^^^
  File "/home/folder/WGDashboard/src/venv/lib/python3.11/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/folder/WGDashboard/src/venv/lib/python3.11/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/folder/WGDashboard/src/dashboard.py", line 1812, in API_addPeers
    bulkAddAmount = data['bulkAddAmount']
                    ~~~~^^^^^^^^^^^^^^^^^
KeyError: 'bulkAddAmount'

Screenshot 2024-11-06 at 11 27 55

NovianPutera commented 2 weeks ago

Success when adding value to 'bulkAddAmount'. But Profile name is not as expected.

Screenshot 2024-11-06 at 11 30 59 Screenshot 2024-11-06 at 12 37 13

donaldzou commented 2 weeks ago

Sorry my bad, please use the following JSON body

{
  "bulkAdd": false,
  "bulkAddAmount": 0,
  "name": "Peer name",
  "allowed_ips": [
    "10.24.4.3/32"
  ],
  "private_key": "yJ/VvhOhlyBG6D4nvCpLGCIPBAK4IiEhB9CdnWtIB0o=",
  "public_key": "1qiiC1agXcjbldt//eLrJ//d1L7bxNHD5CGkiOQ7yWY=",
  "DNS": "1.1.1.1",
  "endpoint_allowed_ip": "0.0.0.0/0",
  "keepalive": 21,
  "mtu": 1420,
  "preshared_key": "",
  "preshared_key_bulkAdd": false
}
NovianPutera commented 2 weeks ago

Sorry my bad, please use the following JSON body

{
  "bulkAdd": false,
  "bulkAddAmount": 0,
  "name": "Peer name",
  "allowed_ips": [
    "10.24.4.3/32"
  ],
  "private_key": "yJ/VvhOhlyBG6D4nvCpLGCIPBAK4IiEhB9CdnWtIB0o=",
  "public_key": "1qiiC1agXcjbldt//eLrJ//d1L7bxNHD5CGkiOQ7yWY=",
  "DNS": "1.1.1.1",
  "endpoint_allowed_ip": "0.0.0.0/0",
  "keepalive": 21,
  "mtu": 1420,
  "preshared_key": "",
  "preshared_key_bulkAdd": false
}

Ahh, great solution. Thank you very much 🎊