- Retro-compatibility: `OPENVPN_CUSTOM_CONFIG` set implies `VPNSP=custom` - Change: `up` and `down` options are not filtered out - Change: `OPENVPN_INTERFACE` overrides the network interface defined in the configuration file - Change: `PORT` overrides any port found in the configuration file - Feat: config file is read when building the OpenVPN configuration, so it's effectively reloaded on VPN restarts - Feat: extract values from custom file at start to log out valid settings - Maint: `internal/openvpn/extract` package instead of `internal/openvpn/custom` package - Maint: All providers' `BuildConf` method return an error - Maint: rename `CustomConfig` to `ConfFile` in Settings structures
30 lines
714 B
Go
30 lines
714 B
Go
package extract
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
|
)
|
|
|
|
var (
|
|
ErrRead = errors.New("cannot read file")
|
|
ErrExtractConnection = errors.New("cannot extract connection from file")
|
|
)
|
|
|
|
// Data extracts the lines and connection from the OpenVPN configuration file.
|
|
func (e *Extractor) Data(filepath string) (lines []string,
|
|
connection models.Connection, err error) {
|
|
lines, err = readCustomConfigLines(filepath)
|
|
if err != nil {
|
|
return nil, connection, fmt.Errorf("%w: %s", ErrRead, err)
|
|
}
|
|
|
|
connection, err = extractDataFromLines(lines)
|
|
if err != nil {
|
|
return nil, connection, fmt.Errorf("%w: %s", ErrExtractConnection, err)
|
|
}
|
|
|
|
return lines, connection, nil
|
|
}
|