Use openvpn3 API via Python wrapper

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • piotr1221
    Junior Member
    • Apr 2024
    • 1

    Use openvpn3 API via Python wrapper

    Hello, my goal is to be able to connect to a VPN via an .ovpn file using the OpenVPN API itself. My use case is executing some Python code in a serverless cloud environment to connect to a database behind this VPN. Since the environment is serverless, I can't install the client and execute it via shell, so I was trying to sort of use the code behind the client.

    I build the source code from https://github.com/OpenVPN/openvpn3 and found out there is a Python wrapper at core/build/client/ovpncli.py. I tried to copy a CLI example in C++ from this repo, but I can't get it to work.

    [
    Code:
    from ovpncli import ClientAPI_OpenVPNClientHelper as OpenVPNClientHelper, ClientAPI_OpenVPNClient as OpenVPNClient, ClientAPI_Config as Config
    import threading
    
    class Client(OpenVPNClient):
        pass
    
    def execute(client):
        status = client.connect()
    
        print(status.error)
        print(status.message)
    
        return status
    
    helper = OpenVPNClientHelper()
    merged_config = helper.merge_config('path_to_ovpn_file', True)
    
    config = Config()
    config.content = merged_config.profileContent
    
    client = Client()
    eval_config = client.eval_config(config)
    
    thread = threading.Thread(target=execute, args=(client,))
    thread.start()
    thread.join()
    When i execute it, I get the error
    Code:
    SWIG director method error. Error detected when calling 'ClientAPI_OpenVPNClient.event'
    . Why does this happen? How can I fix it? Is there any other more straightforward way to achieve this? (Btw, I have almost zero knowledge on networking)

    Thanks
    Last edited by piotr1221; 2024-04-19, 01:52 PM.
Working...
😀
😂
🥰
😘
🤢
😎
😞
😡
👍
👎