2020-01-30 07:45:49 +01:00
# Wg Gen Web
2020-02-03 08:19:24 +01:00
< h1 align = "center" > < img height = "420" src = "./wg-gen-web_cover.png" alt = "Simple Web based configuration generator for WireGuard" > < / h1 >
2020-01-30 07:45:49 +01:00
2020-02-03 08:19:24 +01:00
Simple Web based configuration generator for [WireGuard ](https://wireguard.com ).
2020-01-30 08:12:26 +01:00
2020-01-31 03:27:30 +01:00
[![pipeline status ](https://gitlab.127-0-0-1.fr/vx3r/wg-gen-web/badges/master/pipeline.svg )](https://gitlab.127-0-0-1.fr/vx3r/wg-gen-web/commits/master)
[![Go Report Card ](https://goreportcard.com/badge/github.com/vx3r/wg-gen-web )](https://goreportcard.com/report/github.com/vx3r/wg-gen-web)
![Gitlab pipeline status (self-hosted) ](https://img.shields.io/gitlab/pipeline/vx3r/wg-gen-web?gitlab_url=https%3A%2F%2Fgitlab.127-0-0-1.fr%2F )
[![License: WTFPL ](https://img.shields.io/badge/License-WTFPL-brightgreen.svg )](http://www.wtfpl.net/about/)
2020-02-25 04:42:37 +01:00
![Discord ](https://img.shields.io/discord/681699554189377567 )
2020-02-07 07:15:39 +01:00
![Build multi-arch Docker Images via buildx ](https://github.com/vx3r/wg-gen-web/workflows/Build%20multi-arch%20Docker%20Images%20via%20buildx/badge.svg )
2020-01-31 03:27:30 +01:00
![GitHub last commit ](https://img.shields.io/github/last-commit/vx3r/wg-gen-web )
![Docker Pulls ](https://img.shields.io/docker/pulls/vx3r/wg-gen-web )
![GitHub go.mod Go version ](https://img.shields.io/github/go-mod/go-version/vx3r/wg-gen-web )
![GitHub code size in bytes ](https://img.shields.io/github/languages/code-size/vx3r/wg-gen-web )
2020-01-30 08:12:26 +01:00
2020-01-31 05:06:39 +01:00
## Why another one ?
2020-01-30 07:45:49 +01:00
2020-01-30 09:34:54 +01:00
All WireGuard UI implementations are trying to manage the service by applying configurations and creating network rules.
2020-01-31 05:06:39 +01:00
This implementation only generates configuration and its up to you to create network rules and apply configuration to WireGuard.
For example by monitoring generated directory with [inotifywait ](https://github.com/inotify-tools/inotify-tools/wiki ).
2020-01-30 07:45:49 +01:00
The goal is to run Wg Gen Web in a container and WireGuard on host system.
## Features
2020-01-31 05:06:39 +01:00
* Self-hosted and web based
* Automatically select IP from the netowrk pool assigned to client
2020-01-30 07:45:49 +01:00
* QR-Code for convenient mobile client configuration
2020-02-19 08:19:16 +01:00
* Sent email to client with QR-code and client config
2020-01-30 07:45:49 +01:00
* Enable / Disable client
* Generation of `wg0.conf` after any modification
2020-05-11 08:59:28 +02:00
* IPv6 ready
* User authentication (Oauth2 OIDC)
2020-01-30 07:45:49 +01:00
* Dockerized
* Pretty cool look
2020-02-05 02:53:53 +01:00
2020-02-03 08:19:24 +01:00
![Screenshot ](wg-gen-web_screenshot.png )
2020-01-30 07:45:49 +01:00
## Running
2020-02-03 08:19:24 +01:00
### Docker
2020-01-30 09:34:54 +01:00
The easiest way to run Wg Gen Web is using the container image
2020-01-30 07:45:49 +01:00
```
docker run --rm -it -v /tmp/wireguard:/data -p 8080:8080 -e "WG_CONF_DIR=/data" vx3r/wg-gen-web:latest
```
2020-05-11 08:59:28 +02:00
Docker compose snippet, used for demo server
2020-01-30 07:45:49 +01:00
```
version: '3.6'
2020-05-11 08:59:28 +02:00
wg-gen-web-demo:
2020-01-30 07:45:49 +01:00
image: vx3r/wg-gen-web:latest
2020-05-11 08:59:28 +02:00
container_name: wg-gen-web-demo
2020-01-30 07:45:49 +01:00
restart: unless-stopped
2020-05-11 08:59:28 +02:00
expose:
- "8080/tcp"
2020-01-30 07:45:49 +01:00
environment:
- WG_CONF_DIR=/data
- WG_INTERFACE_NAME=wg0.conf
2020-02-03 08:19:24 +01:00
- SMTP_HOST=smtp.gmail.com
- SMTP_PORT=587
2020-05-11 08:59:28 +02:00
- SMTP_USERNAME=no-reply@gmail.com
- SMTP_PASSWORD=******************
- SMTP_FROM=Wg Gen Web < no-reply @ gmail . com >
- OAUTH2_PROVIDER_NAME=github
- OAUTH2_PROVIDER=https://github.com
- OAUTH2_CLIENT_ID=******************
- OAUTH2_CLIENT_SECRET=******************
- OAUTH2_REDIRECT_URL=https://wg-gen-web-demo.127-0-0-1.fr
2020-01-30 07:45:49 +01:00
volumes:
2020-01-31 05:06:39 +01:00
- /etc/wireguard:/data
2020-01-30 07:45:49 +01:00
```
2020-01-31 05:06:39 +01:00
Please note that mapping ```/etc/wireguard``` to ```/data``` inside the docker, will erase your host's current configuration.
If needed, please make sure to backup your files from ```/etc/wireguard```.
2020-01-30 09:16:10 +01:00
2020-01-31 05:06:39 +01:00
A workaround would be to change the ```WG_INTERFACE_NAME``` to something different, as it will create a new interface (```wg-auto.conf``` for example), note that if you do so, you will have to adapt your daemon accordingly.
2020-02-03 08:19:24 +01:00
### Directly without docker
2020-04-01 01:03:16 +02:00
Fill free to download latest artifacts from my GitLab server:
* [Backend ](https://gitlab.127-0-0-1.fr/vx3r/wg-gen-web/-/jobs/artifacts/master/download?job=build-back )
* [Frontend ](https://gitlab.127-0-0-1.fr/vx3r/wg-gen-web/-/jobs/artifacts/master/download?job=build-front )
2020-02-03 08:19:24 +01:00
Put everything in one directory, create `.env` file with all configurations and run the backend.
## Automatically apply changes to WireGuard
### Using ```systemd```
2020-01-30 09:16:10 +01:00
Using `systemd.path` monitor for directory changes see [systemd doc ](https://www.freedesktop.org/software/systemd/man/systemd.path.html )
```
# /etc/systemd/system/wg-gen-web.path
[Unit]
Description=Watch /etc/wireguard for changes
[Path]
PathModified=/etc/wireguard
[Install]
WantedBy=multi-user.target
```
This `.path` will activate unit file with the same name
```
# /etc/systemd/system/wg-gen-web.service
[Unit]
Description=Restart WireGuard
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl restart wg-quick@wg0.service
[Install]
WantedBy=multi-user.target
```
Which will restart WireGuard service
2020-02-03 08:19:24 +01:00
### Using ```inotifywait```
2020-01-31 05:06:39 +01:00
For any other init system, create a daemon running this script
2020-01-30 09:16:10 +01:00
```
#!/bin/sh
while inotifywait -e modify -e create /etc/wireguard; do
wg-quick down wg0
wg-quick up wg0
done
```
2020-01-30 07:45:49 +01:00
2020-01-31 03:27:30 +01:00
## How to use with existing WireGuard configuration
2020-01-31 05:06:39 +01:00
After first run Wg Gen Web will create `server.json` in data directory with all server informations.
2020-01-31 03:27:30 +01:00
2020-01-31 05:06:39 +01:00
Feel free to modify this file in order to use your existing keys
2020-01-31 03:27:30 +01:00
2020-01-30 07:45:49 +01:00
## What is out of scope
* Generation or application of any `iptables` or `nftables` rules
2020-02-01 08:08:37 +01:00
* Application of configuration to WireGuard by Wg Gen Web itself
2020-01-30 07:45:49 +01:00
2020-05-11 08:59:28 +02:00
## Authentication
2020-01-30 07:45:49 +01:00
2020-05-11 08:59:28 +02:00
Wg Gen Web can use Oauth2 OpenID Connect provider to authenticate users.
Currently there are 4 implementations:
- `fake` not a real implementation, use this if you don't want to authenticate your clients.
Add the environment variable:
```
OAUTH2_PROVIDER_NAME=fake
```
- `github` in order to use GitHub as Oauth2 provider.
Add the environment variable:
```
OAUTH2_PROVIDER_NAME=github
OAUTH2_PROVIDER=https://github.com
OAUTH2_CLIENT_ID=********************
OAUTH2_CLIENT_SECRET=********************
OAUTH2_REDIRECT_URL=https://wg-gen-web-demo.127-0-0-1.fr
```
- `google` in order to use Google as Oauth2 provider. Not yet implemented
```
help wanted
```
- `oauth2oidc` in order to use RFC compliant Oauth2 OpenId Connect provider.
Add the environment variable:
```
OAUTH2_PROVIDER_NAME=oauth2oidc
OAUTH2_PROVIDER=https://gitlab.com
OAUTH2_CLIENT_ID=********************
OAUTH2_CLIENT_SECRET=********************
OAUTH2_REDIRECT_URL=https://wg-gen-web-demo.127-0-0-1.fr
```
Please fell free to test and report any bugs.
Wg Gen Web will only access your profile to get email address and your name, no other unnecessary scopes will be requested.
2020-02-03 08:19:24 +01:00
2020-02-25 04:42:37 +01:00
## Need Help
* Join us on [Discord ](https://discord.gg/fjx7gGJ )
* Create an issue
2020-03-31 11:31:32 +02:00
## Development
### Backend
From the top level directory run
```
$ go run main.go
```
### Frontend
Inside another terminal session navigate into the `ui` folder
```
$ cd ui
```
Install required dependencies
```
$ npm install
```
Set the base url for the api
```
$ export VUE_APP_API_BASE_URL=http://localhost:8080/api/v1.0
```
Start the development server. It will rebuild and reload the site once you make a change to the source code.
```
$ npm run serve
```
Now you can access the site from a webbrowser with the url `http://localhost:8081` .
2020-02-25 04:42:37 +01:00
## Application stack
* [Gin, HTTP web framework written in Go ](https://github.com/gin-gonic/gin )
* [go-template, data-driven templates for generating textual output ](https://golang.org/pkg/text/template/ )
* [Vue.js, progressive javaScript framework ](https://github.com/vuejs/vue )
* [Vuetify, material design component framework ](https://github.com/vuetifyjs/vuetify )
2020-01-30 07:45:49 +01:00
## License
2020-02-25 04:42:37 +01:00
* Do What the Fuck You Want to Public License. [LICENSE-WTFPL ](LICENSE-WTFPL ) or http://www.wtfpl.net