config

package
v0.0.0-...-64126c4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Copyright 2023 Sebastian Bünger SPDX-License-Identifier: AGPL-3.0-only OR MIT

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCannotReadFile = errors.New("cannot read file")

	// Matches any XML open tag
	// <tag>
	XMLOpenTag = regexp.MustCompile("<([a-zA-Z0-9-_]+)>")
	// Matches any XML close tag
	// </tag>
	XMLCloseTag = regexp.MustCompile("</([a-zA-Z0-9-_]+)>")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Options []ConfigOption
	Auth    *auth.AuthOption
	// contains filtered or unexported fields
}

Config is a representation of a OpenVPN configuration.

func FromFile

func FromFile(filePath string) (*Config, error)

FromFile parses a OpenVPN configuration file and returns a Config object.

func FromString

func FromString(config string) (*Config, error)

FromString parses a OpenVPN configuration string and returns a Config object.

func NewConfig

func NewConfig() *Config

NewConfig creates a new Config object.

func (*Config) AddFile

func (c *Config) AddFile(name string, content string)

func (*Config) AddFlag

func (c *Config) AddFlag(name string)

SetFlag sets a flag.

func (*Config) AddOptions

func (c *Config) AddOptions(options ...ConfigOption)

AddOptions adds one or more ConfigOption to the Config object.

func (*Config) AddParam

func (c *Config) AddParam(name string, values ...string)

SetParam sets the value of a parameter.

func (*Config) Dir

func (c *Config) Dir() string

Dir returns the directory of the file the Config object has been loaded from or written to.

func (*Config) GetOption

func (c *Config) GetOption(name string) ConfigOption

func (*Config) GetProto

func (c *Config) GetProto() NetProtocol

func (*Config) GetRemote

func (c *Config) GetRemote() (string, int)

func (*Config) Path

func (c *Config) Path() string

func (*Config) RemoveOption

func (c *Config) RemoveOption(name string) bool

func (*Config) Save

func (c *Config) Save(filePath string) error

Save serializes the Config object and writes it to a file in the OpenVPN configuration format at the given path. It also sets the path of the Config object to the given path.

func (*Config) SetAuth

func (c *Config) SetAuth(username, password string, allowFile bool)

SetAuth sets username and password for authentication. allowFile controls whether the password can be written to a file or must be send via the management interface.

func (*Config) SetDevice

func (c *Config) SetDevice(device string)

SetDevice sets the device of the OpenVPN server.

func (*Config) SetManagementAddress

func (c *Config) SetManagementAddress(ip string, port int)

SetManagementAddress sets the IP address and port of the management interface.

func (*Config) SetPort

func (c *Config) SetPort(port int)

SetPort sets the port of the OpenVPN server.

func (*Config) SetProto

func (c *Config) SetProto(proto NetProtocol)

func (*Config) SetTLSCaCert

func (c *Config) SetTLSCaCert(caFile string) error

SetTLSCaCert sets the CA certificate for TLS authentication.

func (*Config) SetTLSClientCert

func (c *Config) SetTLSClientCert(certFile string) error

SetTLSClientCert sets the client certificate for TLS authentication.

func (*Config) SetTLSCrypt

func (c *Config) SetTLSCrypt(cryptFile string) error

SetTLSCrypt sets the tls-crypt key for TLS authentication.

func (*Config) SetTLSPrivateKey

func (c *Config) SetTLSPrivateKey(keyFile string) error

SetTLSPrivateKey sets the client private key for TLS authentication.

func (*Config) ToCli

func (c *Config) ToCli() ([]string, error)

ToCli writes the Config to a file and returns the arguments to pass to OpenVPN. If no file path is set, the Config is written to a temporary file and must be deleted manually.

func (*Config) ToString

func (c *Config) ToString() (string, error)

ToString serializes the Config object and returns it as a string in the OpenVPN configuration format.

type ConfigOption

type ConfigOption interface {
	Name() string
	Value() string
	ToLines() (string, error)
}

ConfigOption is an interface for all configuration options.

type NetProtocol

type NetProtocol string
const (
	TCP NetProtocol = "tcp"
	UDP NetProtocol = "udp"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL