Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Openvpn Bundle Laravel Package

amf/openvpn-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require amf/openvpn-bundle
    

    Enable the bundle in config/bundles.php:

    return [
        // ...
        AMF\OpenVpnBundle\AMFOpenVpnBundle::class => ['all' => true],
    ];
    
  2. Configuration Define OpenVPN servers in config/packages/amf_openvpn.yaml:

    amf_openvpn:
        servers:
            my_vpn:
                host: '192.168.1.1'
                port: 1194
                username: 'admin'
                password: 'securepass'
                timeout: 30
    
  3. First Use Case List connected clients for a server via CLI:

    php bin/console amf:openvpn:list my_vpn
    

Implementation Patterns

Core Workflows

  1. Server Management

    • List Clients: Fetch connected clients for a server.
      $clientManager = $this->get('amf_openvpn.server_manager');
      $clients = $clientManager->listClients('my_vpn');
      
    • Kill Client: Terminate a specific client connection.
      $clientManager->killClient('my_vpn', 'client_id');
      
  2. Logging & Monitoring

    • Retrieve logs for a server:
      $logManager = $this->get('amf_openvpn.log_manager');
      $logs = $logManager->getLogs('my_vpn', 100); // Last 100 lines
      
    • Check server version:
      $version = $clientManager->getVersion('my_vpn');
      
  3. Integration with Symfony

    • Controller Example:
      use AMF\OpenVpnBundle\Manager\ServerManagerInterface;
      
      class VpnController extends AbstractController {
          public function listClients(ServerManagerInterface $serverManager) {
              $clients = $serverManager->listClients('my_vpn');
              return $this->render('vpn/list.html.twig', ['clients' => $clients]);
          }
      }
      
    • Event Listeners: Extend functionality (e.g., log client disconnections to a database).
  4. CLI Automation

    • Schedule periodic checks (e.g., via cron or Symfony Messenger):
      php bin/console amf:openvpn:check my_vpn
      

Gotchas and Tips

Common Pitfalls

  1. Authentication Failures

    • Ensure username/password in config match the OpenVPN server’s management interface credentials.
    • Debug with:
      php bin/console debug:config amf_openvpn
      
  2. Connection Timeouts

    • Adjust timeout in config if servers are slow to respond.
    • Handle exceptions gracefully:
      try {
          $clients = $serverManager->listClients('my_vpn');
      } catch (\AMF\OpenVpnBundle\Exception\ConnectionException $e) {
          $this->addFlash('error', 'VPN connection failed: ' . $e->getMessage());
      }
      
  3. Telnet Dependency

    • The bundle relies on PHP’s telnet stream functions. Ensure your server has:
      allow_url_fopen = On
      
  4. Rate Limiting

    • Avoid rapid CLI calls (e.g., listClients) to prevent overwhelming the OpenVPN server.

Debugging Tips

  • Enable Verbose Output:
    php bin/console amf:openvpn:list my_vpn --verbose
    
  • Check Raw Commands: The bundle uses OpenVPN’s management interface commands (e.g., status, kill). Verify these work manually via telnet.

Extension Points

  1. Custom Commands Extend the bundle by adding new management commands:

    # config/packages/amf_openvpn.yaml
    amf_openvpn:
        commands:
            custom_command: 'custom_command_arg'
    

    Then implement a custom service to handle it.

  2. Event Dispatching Listen for client connection/disconnection events:

    // src/EventListener/VpnListener.php
    class VpnListener implements EventSubscriberInterface {
        public static function getSubscribedEvents() {
            return [
                AMFOpenVpnEvents::CLIENT_CONNECTED => 'onClientConnected',
            ];
        }
    }
    
  3. Database Integration Store logs/clients in Doctrine:

    // After fetching clients:
    foreach ($clients as $client) {
        $entityManager->persist(new VpnClient($client));
    }
    $entityManager->flush();
    

Configuration Quirks

  • Multiple Servers: Use the servers array to manage multiple OpenVPN instances with unique configs.
  • SSL/TLS: If using encrypted management interfaces, extend the Connection class to handle SSL handshakes.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
headercat/phpstan-extension-ide-helper
yosymfony/parser-utils
innmind/black-box
babenkoivan/elastic-migrations
babenkoivan/elastic-adapter
sandermuller/package-boost-php
sandermuller/boost-core
depa/sulu-google-reviews-bundle
croct/plug-symfony
develia/commons
dmstr/symfony-system-resources-bundle
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
renatomarinho/laravel-page-speed
develia/geo-bundle
austinheap/laravel-database-encryption
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard