cli

package
v0.0.0-...-c9180d9 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const Confirm bool = true

Variables

This section is empty.

Functions

func Add

func Add(hostname, owner, description string, confirm bool) (string, error)

Add prompts for the required information and creates a new peer

func BytesToSI

func BytesToSI(b uint64) string

func ConfirmOrAbort

func ConfirmOrAbort(format string, a ...interface{})

func ExitFail

func ExitFail(format string, a ...interface{})

func GenerateReport

func GenerateReport() (string, error)

func GetServer

func GetServer(config *DsnetConfig) *lib.Server

func Init

func Init() (string, error)

func MustPromptString

func MustPromptString(prompt string, required bool) (string, error)

func Regenerate

func Regenerate(hostname string, confirm bool) (string, error)

func Remove

func Remove(hostname string) error

func Sync

func Sync()

Types

type DsnetConfig

type DsnetConfig struct {
	// When generating configs, the ExternalHostname has precendence for the
	// server Endpoint, followed by ExternalIP (IPv4) and ExternalIP6 (IPv6)
	// The IPs are discovered automatically on init. Define an ExternalHostname
	// if you're using dynamic DNS, want to change IPs without updating
	// configs, or want wireguard to be able to choose between IPv4/IPv6. It is
	// only possible to specify one Endpoint per peer entry in wireguard.
	ExternalHostname string
	ExternalIP       net.IP
	ExternalIP6      net.IP
	ListenPort       int `validate:"gte=1,lte=65535"`
	// domain to append to hostnames. Relies on separate DNS server for
	// resolution. Informational only.
	Domain        string `validate:"required,gte=1,lte=255"`
	InterfaceName string `validate:"required,gte=1,lte=255"`
	// IP network from which to allocate automatic sequential addresses
	// Network is chosen randomly when not specified
	Network  lib.JSONIPNet `validate:"required"`
	Network6 lib.JSONIPNet `validate:"required"`
	IP       net.IP
	IP6      net.IP
	DNS      net.IP
	// extra networks available, will be added to AllowedIPs
	Networks []lib.JSONIPNet `validate:"required"`
	// TODO Default subnets to route via VPN
	PrivateKey lib.JSONKey `validate:"required,len=44"`
	PostUp     string
	PostDown   string
	Peers      []PeerConfig `validate:"dive"`
	// used for server and client
	PersistentKeepalive int `validate:"gte=0,lte=255"`
}

func LoadConfigFile

func LoadConfigFile() (*DsnetConfig, error)

LoadConfigFile parses the json config file, validates and stuffs it in to a struct

func MustLoadConfigFile

func MustLoadConfigFile() (*DsnetConfig, error)

func (*DsnetConfig) AddPeer

func (conf *DsnetConfig) AddPeer(peer lib.Peer) error

AddPeer adds a provided peer to the Peers list in the conf

func (DsnetConfig) GetWgPeerConfigs

func (conf DsnetConfig) GetWgPeerConfigs() []wgtypes.PeerConfig

func (*DsnetConfig) MustAddPeer

func (conf *DsnetConfig) MustAddPeer(peer lib.Peer)

MustAddPeer is like AddPeer, except it exist on error

func (*DsnetConfig) MustRemovePeer

func (conf *DsnetConfig) MustRemovePeer(hostname string)

MustRemovePeer is like RemovePeer, except it exits on error

func (*DsnetConfig) MustSave

func (conf *DsnetConfig) MustSave() error

MustSave is like Save except it exits on error

func (*DsnetConfig) RemovePeer

func (conf *DsnetConfig) RemovePeer(hostname string) error

RemovePeer removes a peer from the peer list based on hostname

func (*DsnetConfig) Save

func (conf *DsnetConfig) Save() error

Save writes the configuration to disk

type DsnetReport

type DsnetReport struct {
	ExternalIP       net.IP
	ExternalIP6      net.IP
	ExternalHostname string
	InterfaceName    string
	ListenPort       int
	// domain to append to hostnames. Relies on separate DNS server for
	// resolution. Informational only.
	Domain string
	IP     net.IP
	IP6    net.IP
	// IP network from which to allocate automatic sequential addresses
	// Network is chosen randomly when not specified
	Network         lib.JSONIPNet
	Network6        lib.JSONIPNet
	DNS             net.IP
	PeersOnline     int
	PeersTotal      int
	Peers           []PeerReport
	ReceiveBytes    uint64
	TransmitBytes   uint64
	ReceiveBytesSI  string
	TransmitBytesSI string
	// when the report was made
	Timestamp time.Time
}

func GetReport

func GetReport(dev *wgtypes.Device, conf *DsnetConfig) DsnetReport

func (*DsnetReport) Print

func (report *DsnetReport) Print()

func (*DsnetReport) String

func (report *DsnetReport) String() (string, error)

type JSONKey

type JSONKey struct {
	Key wgtypes.Key
}

func GenerateJSONKey

func GenerateJSONKey() JSONKey

func GenerateJSONPrivateKey

func GenerateJSONPrivateKey() JSONKey

func (JSONKey) MarshalJSON

func (k JSONKey) MarshalJSON() ([]byte, error)

func (JSONKey) PublicKey

func (k JSONKey) PublicKey() JSONKey

func (*JSONKey) UnmarshalJSON

func (k *JSONKey) UnmarshalJSON(b []byte) error

type PeerConfig

type PeerConfig struct {
	// Used to update DNS
	Hostname string `validate:"required,gte=1,lte=255"`
	// username of person running this host/router
	Owner string `validate:"required,gte=1,lte=255"`
	// Description of what the host is and/or does
	Description string `validate:"required,gte=1,lte=255"`
	// Internal VPN IP address. Added to AllowedIPs in server config as a /32
	IP    net.IP
	IP6   net.IP
	Added time.Time `validate:"required"`
	// TODO ExternalIP support (Endpoint)
	//ExternalIP     net.UDPAddr `validate:"required,udp4_addr"`
	// TODO support routing additional networks (AllowedIPs)
	Networks     []lib.JSONIPNet `validate:"required"`
	PublicKey    lib.JSONKey     `validate:"required,len=44"`
	PrivateKey   lib.JSONKey     `json:"-"` // omitted from config!
	PresharedKey lib.JSONKey     `validate:"required,len=44"`
}

see https://github.com/WireGuard/wgctrl-go/blob/master/wgtypes/types.go for definitions

type PeerReport

type PeerReport struct {
	// Used to update DNS
	Hostname string
	// username of person running this host/router
	Owner string
	// Description of what the host is and/or does
	Description string
	// Has a handshake occurred in the last 3 mins?
	Online bool
	// No handshake for 28 days
	Dormant bool
	// date peer was added to dsnet config
	Added time.Time
	// Internal VPN IP address. Added to AllowedIPs in server config as a /32
	IP  net.IP
	IP6 net.IP
	// Last known external IP
	ExternalIP net.IP
	// TODO ExternalIP support (Endpoint)
	//ExternalIP     net.UDPAddr `validate:"required,udp4_addr"`
	// TODO support routing additional networks (AllowedIPs)
	Networks          []lib.JSONIPNet
	LastHandshakeTime time.Time
	ReceiveBytes      uint64
	TransmitBytes     uint64
	ReceiveBytesSI    string
	TransmitBytesSI   string
}

Jump to

Keyboard shortcuts

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