openvpn

package module
v0.0.0-...-8a9afe1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2021 License: MIT Imports: 14 Imported by: 0

README

go-openvpn

A go library to start and interface with openvpn processes.

Basic static key example

First use the following command to create a PSK (pre shared key)

openvpn --genkey --secret pre-shared.key
Server
// Create an instance of the openvpn struct
p := openvpn.NewStaticKeyServer("pre-shared.key")

// Start the openvpn process. Note that this method do not block so the program will continue at once.
p.Start()

// Listen for events
for {
	select {
	case event := <-p.Events:
		log.Println("Event: ", event.Name, "(", event.Args, ")")
	}
}
Client
// Create an instance of the openvpn struct
p := openvpn.NewStaticKeyClient("localhost", "pre-shared.key")

// Start the openvpn process. Note that this method do not block so the program will continue at once.
p.Start()

// Listen for events
for {
	select {
	case event := <-p.Events:
		log.Println("Event: ", event.Name, "(", event.Args, ")")
	}
}

References

Documentation

Index

Constants

View Source
const (
	TcpSocket  = 0
	UnixSocket = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(socket string) *Config

func (*Config) Address

func (c *Config) Address(address string, port int)

func (*Config) ClientMode

func (c *Config) ClientMode(ca *openssl.CA, cert *openssl.Cert, dh *openssl.DH, ta *openssl.TA)

func (*Config) ClientToClient

func (c *Config) ClientToClient()

func (*Config) Compression

func (c *Config) Compression()

func (*Config) Device

func (c *Config) Device(t string)

func (*Config) Flag

func (c *Config) Flag(key string)

func (*Config) InterfaceAddress

func (c *Config) InterfaceAddress() string

func (*Config) IpPool

func (c *Config) IpPool(pool string)

func (*Config) KeepAlive

func (c *Config) KeepAlive(interval, timeout int)

func (*Config) PersistKey

func (c *Config) PersistKey()

func (*Config) PersistTun

func (c *Config) PersistTun()

func (*Config) PingTimerRemote

func (c *Config) PingTimerRemote()

func (*Config) Port

func (c *Config) Port() int

func (*Config) Protocol

func (c *Config) Protocol(p string)

func (*Config) Remote

func (c *Config) Remote(r string, port int)

func (*Config) Secret

func (c *Config) Secret(key string)

func (*Config) ServerMode

func (c *Config) ServerMode(port int, ca *openssl.CA, cert *openssl.Cert, dh *openssl.DH, ta *openssl.TA)

func (*Config) Set

func (c *Config) Set(key, val string)

func (*Config) Validate

func (c *Config) Validate() (config []string, err error)

type Management

type Management struct {
	Conn *Process

	Mode          int
	Events        chan utils.Event `json:"-"`
	OpenVpnEvents chan string
	// contains filtered or unexported fields
}

func NewManagement

func NewManagement(conn *Process, connector core.OpenVpnConnector) *Management

func (*Management) Fire

func (m *Management) Fire(name string, args ...string)

func (*Management) Shutdown

func (m *Management) Shutdown()

func (*Management) Start

func (m *Management) Start() error

type OpenVpnManagement

type OpenVpnManagement struct {
	Events chan core.EventData
	// contains filtered or unexported fields
}

func NewVpnManagement

func NewVpnManagement(ip string, socket string, port int, password string, mode int) OpenVpnManagement

func (*OpenVpnManagement) Exec

func (vm *OpenVpnManagement) Exec(cmd string)

func (OpenVpnManagement) GetClients

func (vm OpenVpnManagement) GetClients(data core.EventData) ([]utils.Client, error)

func (OpenVpnManagement) Shutdown

func (vm OpenVpnManagement) Shutdown()

func (*OpenVpnManagement) StartClient

func (vm *OpenVpnManagement) StartClient() error

Starts OpenVPN management interface in client mode Events are sent by OpenVPN

func (*OpenVpnManagement) StartServer

func (vm *OpenVpnManagement) StartServer() error

Starts OpenVPN management interface in server mode Events are poled from the server

func (OpenVpnManagement) Status

func (vm OpenVpnManagement) Status() (string, error)

type Process

type Process struct {
	StdOut  chan string `json:"-"`
	StdErr  chan string `json:"-"`
	Stopped chan bool   `json:"-"`

	Env     map[string]string
	Clients map[string]*utils.Client
	// contains filtered or unexported fields
}

func NewProcess

func NewProcess(socket string, config *Config) *Process

func (*Process) ProcessMonitor

func (p *Process) ProcessMonitor(cmd *exec.Cmd, release chan bool)

func (*Process) Restart

func (p *Process) Restart() (err error)

func (*Process) Shutdown

func (p *Process) Shutdown() error

func (*Process) Start

func (p *Process) Start() (err error)

func (*Process) Stop

func (p *Process) Stop() (err error)

Directories

Path Synopsis
ssl

Jump to

Keyboard shortcuts

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