Skip to content

Commit

Permalink
1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
i3ladik committed Jul 19, 2023
1 parent 6d1dca4 commit 6b15f35
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 4 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@

### First initialization

* First initialization
* First initialization

# 1.0.2 (2023-07-19)

### Added

* getRelease() - Getting the release version
* getSession() - Getting a session
* getQRCode(clientId) - Getting wg-easy client qr-code
* updateAddress(clientId, address) - Update wg-easy client address

### Fix
* rename(clientId, newName) - now it is not possible to take an existing name
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ const WGEasyWrapper = require('wg-easy-wrapper');
const WGEW = new WGEasyWrapper('https://website.com', 'password_example');
```

### Getting the release version
```
const response = await WGEW.getRelease();
console.log(response);
```

```
7
```

### Getting a session
```
const response = await WGEW.getSession();
console.log(response);
```

```
{
requiresPassword: true,
authenticated: true
}
```

### Creating a wg-easy client
```
const response = await WGEW.create('newClient');
Expand Down Expand Up @@ -106,6 +129,20 @@ PersistentKeepalive = 0
Endpoint = website.com:51820
```

### Getting wg-easy client qr-code

```
const response = await WGEW.getQRCode('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
console.log(response);
```

```
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 77 77" shape-rendering="crispEdges">
<path fill="#ffffff" d="M0 0h77v77H0z"/>
<path stroke="#000000" d="M4 ... 0h2m2 0h1"/>
</svg>
```

### Enable wg-easy client
```
const response = await WGEW.enable('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
Expand Down Expand Up @@ -134,6 +171,24 @@ console.log(response);
```

```
The name newName is already taken
Or
true
```

### Update wg-easy client address
```
const response = await WGEW.updateAddress('f2t3bdbh-b340-4e7d-62f7-651a0122bc62', '10.8.0.1');
console.log(response);
```

```
Address is already occupied
Or
true
```

Expand Down
52 changes: 50 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ class WGEasyWrapper {
this.api = api;
}

/**
* Getting the release version
* @returns {Promise<Number>}
* @async
*/
async getRelease() {
const { data } = await this.api.get('/api/release');
return data;
}

/**
* Getting a session
* @returns {Promise<Object>}
* @async
*/
async getSession() {
const { data } = await this.api.get('/api/session');
return data;
}

/**
* Getting wg-easy clients
* @returns {Promise<Array>}
Expand All @@ -74,6 +94,17 @@ class WGEasyWrapper {
return data;
}

/**
* Getting wg-easy client qr-code
* @param {string} clientId - client id. It may look like f2t3bdbh-b340-4e7d-62f7-651a0122bc62
* @returns {Promise<String>}
* @async
*/
async getQRCode(clientId) {
const { data } = await this.api.get(`/api/wireguard/client/${clientId}/qrcode.svg`);
return data;
}

/**
* Enable wg-easy client
* @param {string} clientId - client id. It may look like f2t3bdbh-b340-4e7d-62f7-651a0122bc62
Expand All @@ -100,11 +131,28 @@ class WGEasyWrapper {
* Rename wg-easy client
* @param {string} clientId - client id. It may look like f2t3bdbh-b340-4e7d-62f7-651a0122bc62
* @param {string} newName - new name
* @returns {Promise<Boolean>}
* @returns {Promise<Boolean|String>}
* @async
*/
async rename(clientId, newName) {
await this.api.put(`/api/wireguard/client/${clientId}/name`, { name: newName.toString() });
const check = this.find(newName);
if (check) return `The name ${newName} is already taken`;
await this.api.put(`/api/wireguard/client/${clientId}/name`, { name: newName });
return true;
}

/**
* Update wg-easy client address
* @param {string} clientId - client id. It may look like f2t3bdbh-b340-4e7d-62f7-651a0122bc62
* @param {string} address - new address
* @returns {Promise<Boolean|String>}
* @async
*/
async updateAddress(clientId, address) {
const clients = await this.getClients();
const check = clients.find(c => c.address === address);
if (check) return 'Address is already occupied';
await this.api.put(`/api/wireguard/client/${clientId}/address`, { address });
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wg-easy-wrapper",
"version": "1.0.0",
"version": "1.0.2",
"description": "Convenient Node module for interacting with the wg-easy API",
"main": "index.js",
"keywords": [
Expand Down

0 comments on commit 6b15f35

Please sign in to comment.