This implements PHP library to use wgrest API:
https://github.com/suquant/wgrest
- PHP 100%
| src | ||
| .gitignore | ||
| composer.json | ||
| README.md | ||
cURL
Description
Class to use wgrest API and automate Wireguard.
Install
Install with composer:
composer require iwalkalone/wgrest-api
Or a specific version:
composer require iwalkalone/wgrest-api ^1.0
What supports now
For now it just implements adding and deleting peers.
How to use it
$wgrest = new \iwalkalone\WgRestApi([
'bearer_token' => 'you-token',
'base_uri' => 'http://127.0.0.1:8000',
]);
// To add a peer, we just have to pass interface, endpoint and a list of allowed ips
$data = $wgrest->addPeer('wg0', '1.2.3.4:12345', ['10.10.0.0/32']);
// $data contains the response in array format
// you should save url_safe_public_key to delete the peer in the future
// To delete a peer, we just have to pass interface and the public key we just saved
$url_safe_public_key = $data['url_safe_public_key'];
$data = $wgrest->deletePeer('wg0', $url_safe_public_key);