PHP code example of stellarsecurity / stellarsecurity-vpn-laravel

1. Go to this page and download the library: Download stellarsecurity/stellarsecurity-vpn-laravel 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/ */

    

stellarsecurity / stellarsecurity-vpn-laravel example snippets


'providers' => [
    // ...
    StellarSecurity\LaravelVpn\StellarVpnServiceProvider::class,
];

use StellarSecurity\LaravelVpn\Services\VpnServerClient;

class VpnController
{
    public function __construct(private VpnServerClient $client) {}

    public function servers()
    {
        $servers = $client->listServers();

        return response()->json($servers);
    }
}

$servers = $client->listServers();

[
    [
        'id'            => 'eu-1',
        'name'          => 'Switzerland – Zurich',
        'country'       => 'CH',
        'lat'           => 47.3769,
        'lon'           => 8.5417,
        'protocols'     => ['udp', 'tcp'],
        'hostname'      => 'ch-zurich-1.stellarsecurity.com',
        'config_url'    => 'https://cdn.stellarsecurity.com/ovpn/eu-1.ovpn',
        'config_sha256' => '...',
    ],
    // ...
]

$payload = $client->issueCredentials($userId, $deviceId);

[
    'user_id'   => 123,
    'device_id' => 'some-device-id',
]

[
    'response_code'    => 200,
    'response_message' => 'OK',
    'data'             => [
        'username' => 'stvpn_xxx',
        'password' => 'plain_random_password_or_null',
    ],
]

$success = $client->resetDevice($userId, $deviceId);

$success = $client->resetAll($userId);

use StellarSecurity\LaravelVpn\Services\VpnServerClient;

class StellarVpnController
{
    public function __construct(private VpnServerClient $vpnClient) {}

    public function serverList()
    {
        return response()->json($this->vpnClient->listServers());
    }

    public function credentials()
    {
        $userId   = auth()->id();
        $deviceId = request()->input('device_id');

        $response = $this->vpnClient->issueCredentials($userId, $deviceId);

        return response()->json($response);
    }
}
bash
php artisan vendor:publish --tag=stellar-vpn-config