MapGuy11 / homeassistant-openvpn-client-addon

A Home Assistant OpenVPN client for anything you want to use it for!
MIT License
1 stars 2 forks source link

Pull Request: Add Optional Username and Password Fields for OpenVPN Authentication #2

Closed Izakun closed 2 months ago

Izakun commented 2 months ago

Description:

This PR introduces the ability to optionally provide username and password for OpenVPN connections that require user authentication. If these fields are not provided, OpenVPN will still run without the --auth-user-pass option, ensuring compatibility with configurations that do not require user credentials.

Changes:

  1. config.json Updates:

    • Added username and password fields to the configuration schema, allowing users to optionally input their VPN credentials via the Home Assistant UI.
    "options": {
       "ovpnfile": "client.ovpn",
       "username": "",
       "password": ""
    },
    "schema": {
       "ovpnfile": "str",
       "username": "str",
       "password": "str"
    }
  2. run.sh Updates:

    • Modified the run.sh script to:
      • Check if the username and password are provided.
      • Create an auth.txt file containing the credentials only if both username and password are provided.
      • Add the --auth-user-pass option to the OpenVPN command when credentials are provided.
      • Run OpenVPN without the --auth-user-pass option if credentials are not supplied, allowing it to function with configurations that don’t require authentication.
        
        if [[ -n "$USERNAME" ]] && [[ -n "$PASSWORD" ]]; then
        echo "$USERNAME" > $AUTH_FILE
        echo "$PASSWORD" >> $AUTH_FILE
        AUTH_OPTION="--auth-user-pass $AUTH_FILE"
        else
        AUTH_OPTION=""
        fi

    openvpn --config ${OPENVPN_CONFIG} $AUTH_OPTION

Impact:

MapGuy11 commented 2 months ago

I am going to look through this. I like your thing with the auth.txt. I am going to try to make that more secure before I push this!