wireguard-ui/README.md

230 lines
12 KiB
Markdown
Raw Normal View History

2020-05-21 18:33:10 +02:00
![](https://github.com/ngoduykhanh/wireguard-ui/workflows/wireguard-ui%20build%20release/badge.svg)
2020-05-21 18:33:46 +02:00
# wireguard-ui
2020-04-25 06:13:29 +02:00
A web user interface to manage your WireGuard setup.
## Features
2022-12-13 22:44:11 +01:00
2020-04-25 06:13:29 +02:00
- Friendly UI
- Authentication
2022-12-13 21:31:19 +01:00
- Manage extra client information (name, email, etc)
2022-12-13 22:44:11 +01:00
- Retrieve client config using QR code / file / email
![wireguard-ui 0.3.7](https://user-images.githubusercontent.com/37958026/177041280-e3e7ca16-d4cf-4e95-9920-68af15e780dd.png)
2020-04-25 06:13:29 +02:00
## Run WireGuard-UI
2022-12-13 22:44:11 +01:00
> The default username and password are `admin`. Please change it to secure your setup.
2022-04-26 21:04:22 +02:00
### Using binary file
2022-12-13 22:44:11 +01:00
Download the binary file from the release page and run it directly on the host machine
2022-04-26 21:04:22 +02:00
```
./wireguard-ui
```
### Using docker compose
2023-03-15 21:35:57 +01:00
The [examples/docker-compose](examples/docker-compose) folder contains example docker-compose files.
Choose the example which fits you the most, adjust the configuration for your needs, then run it like below:
2020-04-25 06:13:29 +02:00
```
docker-compose up
```
2022-04-26 21:04:22 +02:00
## Environment Variables
2022-12-13 22:44:11 +01:00
| Variable | Description | Default |
|-----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|
| `BASE_PATH` | Set this variable if you run wireguard-ui under a subpath of your reverse proxy virtual host (e.g. /wireguard)) | N/A |
2022-12-21 21:52:00 +01:00
| `SESSION_SECRET` | The secret key used to encrypt the session cookies. Set this to a random value | N/A |
| `WGUI_USERNAME` | The username for the login page. Used for db initialization only | `admin` |
| `WGUI_PASSWORD` | The password for the user on the login page. Will be hashed automatically. Used for db initialization only | `admin` |
| `WGUI_PASSWORD_HASH` | The password hash for the user on the login page. (alternative to `WGUI_PASSWORD`). Used for db initialization only | N/A |
2023-02-16 17:09:24 +01:00
| `WGUI_FAVICON_FILE_PATH` | The file path used as website favicon | Embedded WireGuard logo |
2022-12-13 22:44:11 +01:00
| `WGUI_ENDPOINT_ADDRESS` | The default endpoint address used in global settings | Resolved to your public ip address |
| `WGUI_DNS` | The default DNS servers (comma-separated-list) used in the global settings | `1.1.1.1` |
| `WGUI_MTU` | The default MTU used in global settings | `1450` |
| `WGUI_PERSISTENT_KEEPALIVE` | The default persistent keepalive for WireGuard in global settings | `15` |
2023-03-15 21:37:39 +01:00
| `WGUI_FIREWALL_MARK` | The default WireGuard firewall mark | `0xca6c` (51820) |
2022-12-13 22:44:11 +01:00
| `WGUI_CONFIG_FILE_PATH` | The default WireGuard config file path used in global settings | `/etc/wireguard/wg0.conf` |
2023-03-15 21:29:08 +01:00
| `WGUI_LOG_LEVEL` | The default log level. Possible values: `DEBUG`, `INFO`, `WARN`, `ERROR`, `OFF` | `INFO` | |
2022-12-13 22:44:11 +01:00
| `WG_CONF_TEMPLATE` | The custom `wg.conf` config file template. Please refer to our [default template](https://github.com/ngoduykhanh/wireguard-ui/blob/master/templates/wg.conf) | N/A |
| `EMAIL_FROM_ADDRESS` | The sender email address | N/A |
| `EMAIL_FROM_NAME` | The sender name | `WireGuard UI` |
| `SENDGRID_API_KEY` | The SendGrid api key | N/A |
| `SMTP_HOSTNAME` | The SMTP IP address or hostname | `127.0.0.1` |
| `SMTP_PORT` | The SMTP port | `25` |
| `SMTP_USERNAME` | The SMTP username | N/A |
| `SMTP_PASSWORD` | The SMTP user password | N/A |
| `SMTP_AUTH_TYPE` | The SMTP authentication type. Possible values: `PLAIN`, `LOGIN`, `NONE` | `NONE` |
| `SMTP_ENCRYPTION` | the encryption method. Possible values: `NONE`, `SSL`, `SSLTLS`, `TLS`, `STARTTLS` | `STARTTLS` |
2022-04-26 21:04:22 +02:00
### Defaults for server configuration
These environment variables are used to control the default server settings used when initializing the database.
2022-12-13 22:44:11 +01:00
| Variable | Description | Default |
|-----------------------------------|-----------------------------------------------------------------------------------------------|-----------------|
| `WGUI_SERVER_INTERFACE_ADDRESSES` | The default interface addresses (comma-separated-list) for the WireGuard server configuration | `10.252.1.0/24` |
| `WGUI_SERVER_LISTEN_PORT` | The default server listen port | `51820` |
| `WGUI_SERVER_POST_UP_SCRIPT` | The default server post-up script | N/A |
| `WGUI_SERVER_POST_DOWN_SCRIPT` | The default server post-down script | N/A |
2022-04-26 21:04:22 +02:00
### Defaults for new clients
These environment variables are used to set the defaults used in `New Client` dialog.
2022-12-13 22:44:11 +01:00
| Variable | Description | Default |
|---------------------------------------------|-------------------------------------------------------------------------------------------------|-------------|
| `WGUI_DEFAULT_CLIENT_ALLOWED_IPS` | Comma-separated-list of CIDRs for the `Allowed IPs` field. (default ) | `0.0.0.0/0` |
| `WGUI_DEFAULT_CLIENT_EXTRA_ALLOWED_IPS` | Comma-separated-list of CIDRs for the `Extra Allowed IPs` field. (default empty) | N/A |
| `WGUI_DEFAULT_CLIENT_USE_SERVER_DNS` | Boolean value [`0`, `f`, `F`, `false`, `False`, `FALSE`, `1`, `t`, `T`, `true`, `True`, `TRUE`] | `true` |
| `WGUI_DEFAULT_CLIENT_ENABLE_AFTER_CREATION` | Boolean value [`0`, `f`, `F`, `false`, `False`, `FALSE`, `1`, `t`, `T`, `true`, `True`, `TRUE`] | `true` |
### Docker only
These environment variables only apply to the docker container.
2022-12-13 22:48:00 +01:00
| Variable | Description | Default |
|-----------------------|---------------------------------------------------------------|---------|
2022-12-26 10:12:09 +01:00
| `WGUI_MANAGE_START` | Start/stop WireGuard when the container is started/stopped | `false` |
2022-12-13 22:48:00 +01:00
| `WGUI_MANAGE_RESTART` | Auto restart WireGuard when we Apply Config changes in the UI | `false` |
2020-04-25 06:13:29 +02:00
## Auto restart WireGuard daemon
2022-12-13 22:44:11 +01:00
WireGuard-UI only takes care of configuration generation. You can use systemd to watch for the changes and restart the
service. Following is an example:
### Using systemd
2022-12-13 21:31:19 +01:00
Create `/etc/systemd/system/wgui.service`
2020-04-25 06:13:29 +02:00
2022-12-13 21:31:19 +01:00
```bash
cd /etc/systemd/system/
cat << EOF > wgui.service
2020-04-25 06:13:29 +02:00
[Unit]
Description=Restart WireGuard
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl restart wg-quick@wg0.service
2021-08-05 19:46:11 +02:00
[Install]
RequiredBy=wgui.path
2022-12-13 21:31:19 +01:00
EOF
2020-04-25 06:13:29 +02:00
```
2022-12-13 21:31:19 +01:00
Create `/etc/systemd/system/wgui.path`
2020-04-25 06:13:29 +02:00
2022-12-13 21:31:19 +01:00
```bash
cd /etc/systemd/system/
cat << EOF > wgui.path
2020-04-25 06:13:29 +02:00
[Unit]
Description=Watch /etc/wireguard/wg0.conf for changes
[Path]
PathModified=/etc/wireguard/wg0.conf
[Install]
WantedBy=multi-user.target
2022-12-13 21:31:19 +01:00
EOF
2020-04-25 06:13:29 +02:00
```
Apply it
2022-12-13 21:31:19 +01:00
```sh
2020-04-25 06:13:29 +02:00
systemctl enable wgui.{path,service}
systemctl start wgui.{path,service}
```
2022-12-13 22:44:11 +01:00
### Using openrc
2022-12-13 22:48:00 +01:00
Create `/usr/local/bin/wgui` file and make it executable
2022-12-13 22:44:11 +01:00
2022-12-13 21:31:19 +01:00
```sh
cd /usr/local/bin/
cat << EOF > wgui
#!/bin/sh
wg-quick down wg0
wg-quick up wg0
2022-12-13 21:31:19 +01:00
EOF
chmod +x wgui
```
2022-12-13 22:48:00 +01:00
Create `/etc/init.d/wgui` file and make it executable
2022-12-13 22:44:11 +01:00
2022-12-13 21:31:19 +01:00
```sh
cd /etc/init.d/
cat << EOF > wgui
#!/sbin/openrc-run
command=/sbin/inotifyd
command_args="/usr/local/bin/wgui /etc/wireguard/wg0.conf:w"
pidfile=/run/${RC_SVCNAME}.pid
command_background=yes
2022-12-13 21:31:19 +01:00
EOF
chmod +x wgui
```
Apply it
2022-12-13 21:31:19 +01:00
```sh
rc-service wgui start
rc-update add wgui default
```
2022-12-13 22:44:11 +01:00
### Using Docker
Set `WGUI_MANAGE_RESTART=true` to manage Wireguard interface restarts.
2022-12-13 22:44:11 +01:00
Using `WGUI_MANAGE_START=true` can also replace the function of `wg-quick@wg0` service, to start Wireguard at boot, by
running the container with `restart: unless-stopped`. These settings can also pick up changes to Wireguard Config File
2022-12-13 22:48:00 +01:00
Path, after restarting the container. Please make sure you have `--cap-add=NET_ADMIN` in your container config to make
this
2022-12-13 22:44:11 +01:00
feature work.
## Build
### Build docker image
Go to the project root directory and run the following command:
2022-12-13 21:31:19 +01:00
```sh
docker build -t wireguard-ui .
```
### Build binary file
Prepare the assets directory
2022-12-13 21:31:19 +01:00
```sh
./prepare_assets.sh
```
Then you can embed resources by generating Go source code
2022-12-13 21:31:19 +01:00
```sh
rice embed-go
go build -o wireguard-ui
```
Or, append resources to executable as zip file
2022-12-13 21:31:19 +01:00
```sh
go build -o wireguard-ui
rice append --exec wireguard-ui
```
2020-04-25 06:13:29 +02:00
## License
2022-12-13 22:44:11 +01:00
2020-04-25 06:13:29 +02:00
MIT. See [LICENSE](https://github.com/ngoduykhanh/wireguard-ui/blob/master/LICENSE).
2020-05-17 09:38:26 +02:00
## Support
2022-12-13 22:44:11 +01:00
2020-05-17 09:38:26 +02:00
If you like the project and want to support it, you can *buy me a coffee*
<a href="https://www.buymeacoffee.com/khanhngo" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>