vpn

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TCP = protocol(true)
	UDP = protocol(false)
)

Protocol Type Constants

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	CA     *pki.Authority `json:"ca"`
	Config struct {
		Override struct {
			Client string `json:"client,omitempty"`
			Server string `json:"server,omitempty"`
		} `json:"override"`
		Notify  []notification `json:"notify,omitempty"`
		Options []option       `json:"options,omitempty"`
		Limits  struct {
			Max       uint16 `json:"max_clients"`
			KeepAlive struct {
				Timeout  uint16 `json:"timeout"`
				Interval uint16 `json:"interval"`
			} `json:"keep_alive"`
		} `json:"limits"`
		Auto bool `json:"autostart"`
	} `json:"config"`
	Service struct {
		Clients  map[string][]string `json:"client_config,omitempty"`
		Hostname string              `json:"hostname"`
		Auth     struct {
			File string `json:"file,omitempty"`
			Data []byte `json:"data,omitempty"`
		} `json:"auth"`
		Port     uint16   `json:"port"`
		Protocol protocol `json:"protocol"`
	} `json:"server"`
	DH struct {
		File string `json:"file,omitempty"`
		Data []byte `json:"data,omitempty"`
		Size uint16 `json:"size"`
	} `json:"dh"`
	ID string `json:"id"`

	Network struct {
		Range struct {
			End   string `json:"end,omitempty"`
			Mask  string `json:"mask"`
			Base  string `json:"base"`
			Start string `json:"start,omitempty"`
		} `json:"range"`
		Saved     []string `json:"saved,omitempty"`
		Crosstalk bool     `json:"crosstalk"`
	} `json:"network"`
	// contains filtered or unexported fields
}

Server is a struct that contains the configuration information for a OpenVPN server. This can be used to control a running server or start a new one.

func Load

func Load(b []byte, m manager) (*Server, error)

Load will create and set up the initial properties of a Server struct from the provided arguments and the data contained in the JSON byte array. This function returns any errors made during reading/parsing.

func (*Server) ActionConnect

func (s *Server) ActionConnect(n, l, r string)

ActionConnect is a function that will send out the connect notification email.

func (*Server) ActionDisconnect

func (s *Server) ActionDisconnect(n, l string, d time.Duration)

ActionDisconnect is a function that will send out the disconnect notification email.

func (*Server) AddClientOption

func (s *Server) AddClientOption(client, value string) error

AddClientOption will add the specified value into a client specific config for the server.

The changes will be effective immediately and do NOT require a server restart.

func (*Server) AddNotify

func (s *Server) AddNotify(email, events string) error

AddNotify will add the email address to the server to be notified on the supplied events. This function returns an error if the event names are not valid.

Empty events are considered to be "all".

func (*Server) AddOption

func (s *Server) AddOption(value string, push, config bool)

AddOption will add the server option value to appear in the generated configuration files and profiles. The push option will add the option as a "push" value and config will add the value to each newly generated client profile.

The changes will be applied on a server restart.

func (*Server) CRL

func (s *Server) CRL() error

CRL will attempt to generate the CRL file for this Server. This will also send any emails for notifications that are configured.

func (*Server) ChangeName

func (s *Server) ChangeName(n string) error

ChangeName will attempt to renew the Server's certificate with a new hostname.

func (*Server) Init

func (s *Server) Init(m manager) *Server

Init is a function only to called on a newly created server instance. This sets up the un-exported properties of the struct. This function returns the server instance.

func (*Server) NewClient

func (s *Server) NewClient(name, email string, days int) ([]byte, *pki.Certificate, []byte, error)

NewClient will generate the client key material based on the server TLS data and will return the VPN profile as a byte array

func (*Server) Pid

func (s *Server) Pid() uint64

Pid returns the Server process ID. If the server is not running, this function returns zero.

func (*Server) Print

func (s *Server) Print(w writer)

Print will write the server details to the specified writer.

func (*Server) Reload

func (s *Server) Reload(b []byte) error

Reload will update the Server's info with the new data supplied. This function will trigger a certificate renew if the hostname changes.

func (*Server) RemoveClientOption

func (s *Server) RemoveClientOption(client, value string) error

RemoveClientOption will remove the specified value from a client specific config for the server.

The changes will be effective immediately and do NOT require a server restart.

func (*Server) RemoveNotify

func (s *Server) RemoveNotify(email string)

RemoveNotify will remove the email address associated with any notification events, if it exists.

func (*Server) RemoveOption

func (s *Server) RemoveOption(value string, push, config bool)

RemoveOption will attempt to remove the specified option value from the server. This function will need to match the original push and config values in order to remove the correct option.

func (*Server) Renew

func (s *Server) Renew() error

Renew will attempt to renew the Server's certificate.

func (*Server) Restart

func (s *Server) Restart() error

Restart will gracefully stop the server and save any stored IP options in the struct. Once complete, this function will regenerate the server configuration files and will start up the server.

func (*Server) Running

func (s *Server) Running() bool

Running returns true if the server is currently active.

func (*Server) Start

func (s *Server) Start() error

Start will begin the process of creating the server directory, generating the server config and starting the primary server process.

func (*Server) Status

func (s *Server) Status() ([]Status, error)

Status will return an array of connected clients and some basic info, such as how long connected and local/remote IP addresses.

func (*Server) Stop

func (s *Server) Stop() error

Stop will gracefully stop the server and save any stored IP options in the struct. This will also remove the server runtime directory.

type Status

type Status struct {
	Name   string    `json:"name"`
	Start  time.Time `json:"start"`
	Local  string    `json:"local"`
	Remote string    `json:"remote"`
	Cipher string    `json:"cipher"`
}

Status is a struct that contains the data from an OpenVPN status entry.

Jump to

Keyboard shortcuts

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