PHP code example of dimkinthepro / wireguard-bundle
1. Go to this page and download the library: Download dimkinthepro/wireguard-bundle library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dimkinthepro / wireguard-bundle example snippets
# config/bundles.php
return [
#...
Dimkinthepro\Wireguard\DimkintheproWireguardBundle::class => ['all' => true],
];
# src/Infrastructure/Service/VpnService.php
declare(strict_types=1);
namespace App\Infrastructure\Service;
use Dimkinthepro\Wireguard\Application\PeerManager;
use Dimkinthepro\Wireguard\Application\QrCodeGenerator;
use Dimkinthepro\Wireguard\Application\VpnConfigMaker;
use Dimkinthepro\Wireguard\Application\VpnManager;
use Dimkinthepro\Wireguard\Domain\Entity\Peer;
class VpnService
{
public function __construct(
private readonly VpnManager $vpnManager,
private readonly PeerManager $peerManager,
private readonly VpnConfigMaker $vpnConfigMaker,
private readonly QrCodeGenerator $qrCodeGenerator,
) {
}
public function createPeer(): Peer
{
$peer = new Peer();
$peer->setId(1);
$this->peerManager->setupKeyPairs($peer);
$this->peerManager->setupIp($peer);
return $peer;
}
public function upServer(Peer $peer): void
{
$config = $this->vpnConfigMaker->makeServerConfig($peer);
$this->vpnManager->applyConfig($config);
$this->vpnManager->up();
}
public function getQrCode(Peer $peer): string
{
$peerConfig = $this->vpnConfigMaker->makePeerConfig($peer);
return $this->qrCodeGenerator->getQrCodeImage($peerConfig);
}
}
bash
echo 'www-data ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers