openvpn

package module
v0.0.0-...-4b07208 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2017 License: MIT Imports: 17 Imported by: 4

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, ")")
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone(a, b interface{})

Types

type Client

type Client struct {
	CommonName   string
	PublicIP     string
	PrivateIP    string
	BytesRecived string
	BytesSent    string
	LastRef      string

	Env map[string]string
	// contains filtered or unexported fields
}

type Config

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

func NewConfig

func NewConfig() *Config

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) IpConfig

func (c *Config) IpConfig(local, remote string)

func (*Config) IpPool

func (c *Config) IpPool(pool string)

func (*Config) KeepAlive

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

func (*Config) LoadFile

func (c *Config) LoadFile(filename string) error

* Loads configuration from the given file, A configuration is only valid if: 1. It is a string- In this case, append a # symbol at the end to ignore 2. Array of flags-- In this case, append # symbol at the end of the flag to ignore it 3. Array of push params-- Append # as above to ignore a push

func (*Config) PersistKey

func (c *Config) PersistKey()

func (*Config) PersistTun

func (c *Config) PersistTun()

func (*Config) PingTimerRemote

func (c *Config) PingTimerRemote()

func (*Config) Protocol

func (c *Config) Protocol(p string)

func (*Config) Refresh

func (c *Config) Refresh()

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)

* If called for a second time replace the key

func (*Config) Validate

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

type Event

type Event struct {
	Name string
	Args []string
}

type Management

type Management struct {
	Conn            *Process
	ManagementRead  chan string `json:"-"`
	ManagementWrite chan string `json:"-"`

	Path string
	// contains filtered or unexported fields
}

func NewManagement

func NewManagement(conn *Process) *Management

func (*Management) Shutdown

func (m *Management) Shutdown()

func (*Management) Start

func (m *Management) Start() (path string, err error)

type Process

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

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

func NewProcess

func NewProcess() *Process

func NewSslClient

func NewSslClient(remote string, ca *openssl.CA, cert *openssl.Cert, dh *openssl.DH, ta *openssl.TA, configFile string) *Process

func NewSslServer

func NewSslServer(ca *openssl.CA, cert *openssl.Cert, dh *openssl.DH, ta *openssl.TA, configFile string) *Process

func NewStaticKeyClient

func NewStaticKeyClient(remote, key string, configFile string) *Process

func NewStaticKeyServer

func NewStaticKeyServer(key string, configFile string) *Process

func (*Process) Fire

func (p *Process) Fire(name string, args ...string)

func (*Process) ProcessMonitor

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

func (*Process) Restart

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

func (*Process) SetConfig

func (p *Process) SetConfig(c *Config)

func (*Process) Shutdown

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

func (*Process) Start

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

func (*Process) Stop

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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