wggen

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAllWGConfigFiles

func GetAllWGConfigFiles(dir string) ([]string, error)

func GetGateway

func GetGateway(subnet string) (string, error)

GetGateway takes in a subnet and returns the first IP address after the network address. The function expects the subnet to be in CIDR notation (e.g., "192.168.0.0/24") and returns the IP address immediately following the network address.

Parameters:

subnet (string): The subnet in CIDR notation (e.g., "192.168.0.0/24").

Returns:

    gateway (string): The IP address of the gateway.
	err (error): An error object if the provided subnet is not a valid.

Example usage: subnet := "192.168.0.0/24" gateway := GetGateway(subnet) fmt.Println("Gateway IP:", gateway)

func IsIPv4

func IsIPv4(address string) bool

func IsIPv6

func IsIPv6(address string) bool

func ValidateIP

func ValidateIP(IP string, subnet string) error

ValidateIP takes an IP address and the subnet that the IP address belongs to and performs various checks to validate the IP address.

Parameters: - IP (string): The IP address to validate. - subnet (string): The subnet in CIDR notation to which the IP address belongs.

Returns: - err (error): An error object if the IP address is not valid or does not belong to the specified subnet.

Description: The ValidateIP function checks the validity of the provided IP address within the context of the given subnet. It performs the following checks:

1. Empty IP or Subnet: The function checks if either the IP or subnet is empty. If either value is empty, it returns an error indicating the missing value.

2. Invalid Subnet: The function checks if the provided subnet is valid by parsing it using the netip.ParsePrefix function. If the subnet is invalid, an error is returned.

3. Network Address: The function compares the IP address with the network address of the subnet. If they match, it implies that the IP address is the network address and is considered invalid.

4. Subnet Containment: The function verifies if the IP address falls within the specified subnet by checking if it is contained within the network range. If the IP address is not within the subnet, an error is returned.

Example Usage: err := ValidateIP("192.168.0.10", "192.168.0.0/24")

if err != nil {
    fmt.Println("Invalid IP address:", err)
}

Please note that this function provides basic IP address validation within a subnet and may require additional checks based on specific use cases and requirements.

Types

type Peers

type Peers struct {
	Name                string   `yaml:"name"`
	IPAddress           []string `yaml:"IPAddress"`
	AllowedIPs          []string `yaml:"allowedIPs"`
	PrivateKey          string   `yaml:"privateKey"`
	PublicKey           string   `yaml:"publicKey"`
	PresharedKey        string   `yaml:"presharedKey"`
	PersistentKeepalive int      `yaml:"persistentKeepalive"`
	DNS                 []string `yaml:"dns"`
}

type WGSrv

type WGSrv struct {
	Name       string   `yaml:"name"`
	Endpoint   string   `yaml:"endpoint"`
	ListenPort int      `yaml:"listenPort"`
	IPAddress  []string `yaml:"IPAddress"`
	PrivateKey string   `yaml:"privateKey"`
	PublicKey  string   `yaml:"publicKey"`
	Peers      []Peers  `yaml:"peers"`
}

func GenServerConf

func GenServerConf(Name string, endpoint string, listen int, IPSubnet []string) (serverConf WGSrv, err error)

func GetWGConfig

func GetWGConfig(dir, endpoint string) (*WGSrv, error)

func (*WGSrv) GenPeerConf

func (wg *WGSrv) GenPeerConf(Name string, AllowedIPs []string, DNS []string, PresharedKey bool, PersistentKeepalive bool) (Peers, error)

func (*WGSrv) GeneratePeerConfig

func (wg *WGSrv) GeneratePeerConfig(name string) (wgcfg string, err error)

func (*WGSrv) GenerateSrvConfig

func (wg *WGSrv) GenerateSrvConfig() (wgcfg string, err error)

func (*WGSrv) SaveWGConfig

func (wg *WGSrv) SaveWGConfig(dir string) error

func (*WGSrv) UpdateWGConfig

func (wg *WGSrv) UpdateWGConfig(dir string) error

Jump to

Keyboard shortcuts

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