Code Monkey home page Code Monkey logo

wg-api's Introduction

logo

wg-api is an API endpoint for a Wireguard® VPN server. It allows you to make HTTP GET requests with JSON responses, enabling you to create & revoke peers (eg. clients), access QR/plaintext/JSON config files and receive realtime server info.

It also currently includes an installer script to configure your Wireguard® interface correctly as per wg-api's construction.

It's still a baby project but I plan on building it out into a full-featured RESTful API for this amazing VPN software. I would NOT use this in production for awhile. It is a very insecure endpoint that could and most likely will give an attacker access to your user's keys and full control over your system. The only thing securing it currently is an IP-based whitelist in config.json. Seriously, don't even think about exposing this as a public IP and/or port.

Installation

Use a fresh Ubuntu 18.* install with up-to-date apt dependencies, with Node and NPM installed and Wireguard uninstalled.

apt-get install nodejs npm -y
git clone https://github.com/alectrocute/wg-api
cd wg-api
npm install fastify fastify-static chalk ini
cd ./scripts/bash
./installer.sh

Take time to configure the options in /wg-api/scripts/data/wg.def and /wg-api/config.json.

Then get your Wireguard® server up and running:

cd ./wg-api/scripts/bash
./wg.sh -i

Running the server

node server.js

API endpoints

GET /interface/info

Will return a JSON object of all Wireguard® interface stats:

{
  "wg0": {
    "privateKey": "[hidden]",
    "publicKey": "dutH7c8K2VX4OcQ1c/rvIAAFJBRcf2a9ieVmq2GI4UA=",
    "listenPort": 27953,
    "peers": {
      "EobS6jP7+b4jqI1o97PAjp8rhLBpmD9hSbcnhLRqcTQ=": {
        "endpoint": "12.34.45.545:21807",
        "latestHandshake": "Nov 5, 2019 3:23:3 UTC",
        "transferRx": "3.034 MB",
        "transferTx": "21.65 MB",
        "allowedIps": [
          "10.9.0.6/32"
        ]
      }
    }
  }
}

GET /peer/create/[nickname]

Will generate a new peer, assign IP, etc. based on customized template and return JSON of their details:

{
  "code": 200,
  "profile": {
    "Interface": {
      "Address": "10.9.0.7/24",
      "PrivateKey": "eOksCc/sE+MYmHBlXc9t4ZPpIdBcB94Bgbip12gbEVI=",
      "DNS": "1.1.1.1, 1.0.0.1"
    },
    "Peer": {
      "PublicKey": "dutH7c8K2VX4OcQ1c/rvIAAFJBRcf2a9ieVmq2GI4UA=",
      "AllowedIPs": "0.0.0.0/0, ::/0",
      "Endpoint": "45.76.174.177:27953",
      "PersistentKeepalive": "25"
    },
    "qr": "/peer/qr/alec2"
  }
}

GET /peer/remove/[nickname]

Will revoke a peer, remove all associated files, reload the interface and return a basic message:

{
  "code": 200,
  "profile": "Revoked"
}

GET /peer/qr/[nickname]

Will return a PNG image of a Wireguard® peer's QR code.

GET /peer/info/[nickname]

Will return a JSON object of a Wireguard® peer's stats:

 {
  "code": 200,
  "profile": {
    "Interface": {
      "Address": "10.9.0.6/24",
      "PrivateKey": "8PZh0lf2lZ0CB8i585ei2ZYcCBruZGKubiRgt+b3NGA=",
      "DNS": "1.1.1.1, 1.0.0.1"
    },
    "Peer": {
      "PublicKey": "dutH7c8K2VX4OcQ1c/rvIAAFJBRcf2a9ieVmq2GI4UA=",
      "AllowedIPs": "0.0.0.0/0, ::/0",
      "Endpoint": "12.34.56.343:27953",
      "PersistentKeepalive": "25"
    },
    "qr": "/peer/qr/alec"
  }
}

GET /peer/plaintext/[nickname]

Will return a INI-formatted plaintext document of a Wireguard® peer's configuration file:

[Interface]
Address = 10.9.0.6/24
PrivateKey = PZh0lf2lZ0CB8i585ei2ZYcCBruZGKubiRgt+b3NGA=
DNS = 1.1.1.1, 1.0.0.1

[Peer]
PublicKey = dutH7c8K2VX4OcQ1c/rvIAAFJBRcf2a9ieVmq2GI4UA=
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = 12.34.56.343:27953
PersistentKeepalive = 25

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

wg-api's People

Contributors

alectrocute avatar herukrayz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wg-api's Issues

Addition of Unbound for DNS provider

Currently, you only have options for Cloudflare, Google DNS, and OpenDNS, but with a full tunnel, which is the default setup, and an external DNS, the VPN end-user is leaking traffic every time a DNS request/lookup comes from a client device.

I propose to add a fourth option to install/configure unbound and iptables so that the wireguard server will act as the VPN DNS.

This guide has an excellent example of a similar setup.

Call /peer/remove/username doesn't work

Hello!

I have found a small bug. I am able to create a peer, but I can't remove them afterwards. This is what I get;

root@server:~# curl http://x.x.x.x:3000/peer/create/removetest
{
  "code": 200,
  "profile": {
    "Interface": {
      "Address": "10.9.0.5/24",
      "PrivateKey": "<hidden>",
      "DNS": "1.1.1.1, 1.0.0.1"
    },
    "Peer": {
      "PublicKey": "07G4gg98uYm0LNO+Xwon01zVnzWwFRFGTjxMJgP88AI=",
      "AllowedIPs": "0.0.0.0/0, ::/0",
      "Endpoint": "x.x.x.x:2000",
      "PersistentKeepalive": "25"
    },
    "qr": "/peer/qr/removetest"
  }
}root@server:~#
root@server:~# curl http://x.x.x.x:3000/peer/remove/removetest
{"message":"Route GET:/peer/remove/removetest not found","error":"Not Found","statusCode":404}root@server:~#

Further, very enthousiastic about this API, comes in useful!

Is this WireGuad Interface/Peer Configuration persistant ?

Hi
Is this script WireGuad Interface/Peer Configuration persistan on service restart ?
and another question is if i have thousand users and i make config for each of them on the fly may this cause interruption of other users ? (since creating and inserting each peer should restart the service to make user be able to connect successfully with that newly created config)

"etc/wireguard/wg0.conf" file gets corrupted after reboot

The QR code given in the first installation works just fine. But, let's use (create or remove) functions as get after making the necessary config settings. When we reboot after use, none of them work anymore. Because after reboot "/etc/wireguard/wg0.conf" file gets corrupted. More precisely, it gets corrupted after create and remove, but is noticed after reboot. "/wg-api/scripts/data/wg.def" does not get the necessary information from here and update itself, PublicKey and AllowedIPs remain empty. In addition, when we use the remove process, the user can still continue to use it even though they delete it from the profiles folder. "wg set $interface peer $key remove" instantly destroys this command when we run it manually in the terminal. When we use a command with "wg.sh" it breaks. It also crashes after reboot when we do create and remove with GET or use "wg.sh -a xxxx & wg.sh -d xxxx" directly. Corrupts the "wg.conf" file. Can you tell me where exactly is the problem?

Peer Public Key missing

Hello! First of all thanks for this software!

But i have a small problem.
When i generate new user:

:3000/peer/create/newclient

the response is empty public key and qr code not correct reading by phone device without public key.

{
  "code": 200,
  "profile": {
    "Interface": {
      "Address": "10.9.0.2/24",
      "PrivateKey": "somekey",
      "DNS": "1.1.1.1, 1.0.0.1"
    },
    "Peer": {
      "PublicKey": "",
      "AllowedIPs": "0.0.0.0/0, ::/0",
      "Endpoint": "myip:2000",
      "PersistentKeepalive": "25"
    },
    "qr": "/peer/qr/newclient"
  }
}

as you can see, the PublicKey is empty.

Any way of get peer names in a clear way?

Exist any way to get peer names using api given data?

"oAe6pZFvW5qyn3zL1ANyj+px4jzCoudydJSR2lsJ+mw=": {
"endpoint": "152.206.192.229:7192",
"latestHandshake": "Oct 1, 2021 16:18:52 UTC",
"transferRx": "4.82 MB",
"transferTx": "24.626 MB",
"allowedIps": [
"10.9.0.5/32"
]
},
That is an example, how can I know the client name that is using this

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.