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

Default .ini file #424

Closed DaanSelen closed 1 month ago

DaanSelen commented 1 month ago

Hi @donaldzou,

I wanted to ask if there is a way to modify the wg-dashboard.ini that is being generated. For my current WGDashboard docker container I just copy a template and it works well. But the way the current Docker container in the main repo works is through:

  1. start the WGDashboard so the wg-dashboard.ini is generated.
  2. modify the wg-dashboard.ini and apply environment variables.
  3. restart WGDashboard to apply changes.

I would like to shorten that.

regarding: https://github.com/donaldzou/WGDashboard/pull/420

What is your opinion?

NOXCIS commented 1 month ago

👀

donaldzou commented 1 month ago

Oops, totally forgot about this..

Yes, one way is to CURL the API and change the settings. Or, use a bash script to create wg-dashboard.ini after Docker started.

DaanSelen commented 1 month ago

Oops, totally forgot about this..

Yes, one way is to CURL the API and change the settings. Or, use a bash script to create wg-dashboard.ini after Docker started.

Modifying is what it does now, but this causes the docker container to perform:

  1. Start
  2. Wait for generation of wg-dashboard.ini
  3. Stop
  4. Modify wg-dashboard.ini
  5. Start again.

Which takes unnecessary long. How would I change this with the API? Specifically the DNS and external IP.

donaldzou commented 1 month ago

Ahh.. I see.. then I don't think API is suitable for this. What we can do is to use bash to create a minimal version of wg-dashboard.ini:

$ touch wg-dashboard.ini
$ echo [Peers] >> wg-dashboard.ini
$ echo "remote_endpoint = $(ip addr show "$(route | grep '^default' | grep -o '[^ ]*$')" | grep 'inet ' | awk '{print $2}' | cut -d/ -f1)" >> wg-dashboard.ini
$ echo "peer_global_dns = 1.1.1.1" >> wg-dashboard.ini

Then the wg-dashboard.ini should something like this:

[Peers]
remote_endpoint = 10.0.3.6
peer_global_dns = 1.1.1.1
DaanSelen commented 1 month ago

Does WGDashboard expand on this file? Or overwrite it?

donaldzou commented 1 month ago

Yes, WGDashboard will expand on it. Basically, it will loop through every section and see if a key exists or not. If not, it will write to it with the default value specified in dashboard.py where the DashboardConfig class is :)

DaanSelen commented 1 month ago

Okay will update on next PR!