Skip to content

Loupeznik/better-wapi

Repository files navigation

Better WAPI

This project is inteded to serve as a more standardized wrapper around the Wedos API (WAPI).

GitHub GitHub go.mod Go version

It currently offers following functionality:

  • Add DNS record for a specific domain
  • Update DNS record for specific domain
  • Remove DNS record for specific domain
  • List all DNS records for specific domain
  • List a particular DNS record for specific domain
  • Commit changes to DNS records for specific domain

The BetterWAPI project uses RESTful API style and tries to take a more standardized approach, something that the original WAPI is missing entirely. The core functionality remains similar.

The API now supports all record types supported by WEDOS.

Installation

For the API to work, it is first important to whitelist the IP address of the host machine in the WEDOS management dashboard. It is best to have a server with a static IP address assigned and have this address whitelisted (for production environments).

To run the project locally:

git clone https://github.com/Loupeznik/better-wapi.git
cd better-wapi
go get .
cp .env.example .env

Fill the .env file with your credentials.

  • The BW_WAPI_ variables are your WAPI credentials from the WEDOS management dashboard
  • The BW_USER_ variables are credentials to use within your API
  • The BW_JSON_WEB_KEY is a key used for JWT signing (always fill this to secure your API)

Alternatively, it is possible to use environment variables without using the .env file.

Example in Powershell:

$Env:BW_USER_LOGIN = "admin"
$Env:BW_USER_SECRET = "admin"
$Env:BW_WAPI_LOGIN = "admin@example.com"
$Env:BW_WAPI_PASSWORD = "yourpassword"
$Env:BW_JSON_WEB_KEY = "yourkey"

Finally, to run the API.

go run .

For production workloads, a web server like NGINX is needed, the .env file also needs to be present.

Running in Docker

Docker Image Version (latest by date) Docker Image Size (latest semver) Docker Pulls

An option to run the API in Docker is available as well.

Building the image:

docker build -t better-wapi:latest .
docker run -d -p 8083:8000 --env-file .\.env better-wapi:latest

Alternatively, get the image from Dockerhub

docker pull loupeznik/better-wapi
docker run -d -p 8083:8000 --env-file .\.env loupeznik/better-wapi:latest

Documentation

Example usage

The API uses JWT auth with the BW_USER credentials set in the .env file.

Get the access token

curl --location --request GET 'http://127.0.0.1:8000/token' \
--header 'Content-Type: application/json' \
--data '{
    "login": "BW_USER_LOGIN",
    "secret": "BW_USER_SECRET"
}'

List all subdomains

curl --location --request GET 'http://127.0.0.1:8000/api/domain/yourdomain.xyz/info' \
--header 'Authorization: Bearer <token>'

Create a record

In the following case, an A record would be created with the default TTL of 3600 and the other data specified in the request, it will not be automatically commited.

curl --location --request POST 'http://127.0.0.1:8000/api/domain/yourdomain.xyz/record' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "subdomain": "*",
    "data": "123.123.123.123"
}'

The following is the complete request with all possible parameters.

curl --location --request POST 'http://127.0.0.1:8000/api/domain/yourdomain.xyz/record' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "subdomain": "exampletextrecord",
    "data": "TEXT",
    "ttl": 3600,
    "type": "TXT",
    "autocommit": true
}'

Update a record

curl --location --request PUT 'http://127.0.0.1:8000/api/domain/yourdomain.xyz/record' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "subdomain": "*",
    "data": "123.123.123.123"
}'

License

This project is GPL-3.0 licensed.

Created by Dominik Zarsky.