# WireGuard Config REST API
This is a small REST API that can spin up new WireGuard (WG) interfaces on a server as well as adding peers to that interface. Multiple interfaces can be added to each server.

## Setup
- Install WireGuard
- The port for the REST API is 53865, or `WIREGUARD_SERVICE_PORT`, which needs to be open.
- The available range of ports that is to be used by the program will need to be open for UDP traffic.
- To feed the program with the available range the following enviromental variables need to be set. Otherwise, the range 40 000 - 50 000 will be used.
    - `WIREGUARD_PORT_START_RANGE`
    - `WIREGUARD_PORT_END_RANGE`

## Build

Prerequisites
- Linux distribution with WireGuard installed
- libclang-dev
- Rust (https://www.rust-lang.org/)
 
To build:

`cargo build --release`

## Run the program
Just run the binary. 

IMPORTANT: Must run as `root` otherwise it cannot interact with WireGuard.

## Docker

```
docker build . -t oden-wg-config

docker run \
  --name=oden-wg-config \
  --cap-add=NET_ADMIN \
  --cap-add=SYS_MODULE \
  -e WIREGUARD_SERVICE_PORT=53865 \
  -e WIREGUARD_START_RANGE=40000 \
  -e WIREGUARD_END_RANGE=50000 \
  --sysctl net.ipv4.conf.all.src_valid_mark=1 \
  --sysctl net.ipv4.ip_forward=1 \
    oden-wg-config

```