util

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultUsername                        = "admin"
	DefaultPassword                        = "admin"
	DefaultIsAdmin                         = true
	DefaultServerAddress                   = "10.252.1.0/24"
	DefaultServerPort                      = 51820
	DefaultDNS                             = "1.1.1.1"
	DefaultMTU                             = 1450
	DefaultPersistentKeepalive             = 15
	DefaultFirewallMark                    = "0xca6c" // i.e. 51820
	DefaultTable                           = "auto"
	DefaultConfigFilePath                  = "/etc/wireguard/wg0.conf"
	UsernameEnvVar                         = "WGUI_USERNAME"
	PasswordEnvVar                         = "WGUI_PASSWORD"
	PasswordFileEnvVar                     = "WGUI_PASSWORD_FILE"
	PasswordHashEnvVar                     = "WGUI_PASSWORD_HASH"
	PasswordHashFileEnvVar                 = "WGUI_PASSWORD_HASH_FILE"
	FaviconFilePathEnvVar                  = "WGUI_FAVICON_FILE_PATH"
	EndpointAddressEnvVar                  = "WGUI_ENDPOINT_ADDRESS"
	DNSEnvVar                              = "WGUI_DNS"
	MTUEnvVar                              = "WGUI_MTU"
	PersistentKeepaliveEnvVar              = "WGUI_PERSISTENT_KEEPALIVE"
	FirewallMarkEnvVar                     = "WGUI_FIREWALL_MARK"
	TableEnvVar                            = "WGUI_TABLE"
	ConfigFilePathEnvVar                   = "WGUI_CONFIG_FILE_PATH"
	LogLevel                               = "WGUI_LOG_LEVEL"
	ServerAddressesEnvVar                  = "WGUI_SERVER_INTERFACE_ADDRESSES"
	ServerListenPortEnvVar                 = "WGUI_SERVER_LISTEN_PORT"
	ServerPostUpScriptEnvVar               = "WGUI_SERVER_POST_UP_SCRIPT"
	ServerPostDownScriptEnvVar             = "WGUI_SERVER_POST_DOWN_SCRIPT"
	DefaultClientAllowedIpsEnvVar          = "WGUI_DEFAULT_CLIENT_ALLOWED_IPS"
	DefaultClientExtraAllowedIpsEnvVar     = "WGUI_DEFAULT_CLIENT_EXTRA_ALLOWED_IPS"
	DefaultClientUseServerDNSEnvVar        = "WGUI_DEFAULT_CLIENT_USE_SERVER_DNS"
	DefaultClientEnableAfterCreationEnvVar = "WGUI_DEFAULT_CLIENT_ENABLE_AFTER_CREATION"
)

Variables

View Source
var (
	DisableLogin       bool
	BindAddress        string
	SmtpHostname       string
	SmtpPort           int
	SmtpUsername       string
	SmtpPassword       string
	SmtpNoTLSCheck     bool
	SmtpEncryption     string
	SmtpAuthType       string
	SmtpHelo           string
	SendgridApiKey     string
	EmailFrom          string
	EmailFromName      string
	SessionSecret      [64]byte
	SessionMaxDuration int64
	WgConfTemplate     string
	BasePath           string
	SubnetRanges       map[string]([]*net.IPNet)
	SubnetRangesOrder  []string
)

Runtime config

View Source
var DBUsersToCRC32 = map[string]uint32{}
View Source
var IPToSubnetRange = map[string]uint16{}
View Source
var TgUseridToClientID = map[int64][]string{}
View Source
var TgUseridToClientIDMutex sync.RWMutex

Functions

func AddTgToClientID added in v0.6.0

func AddTgToClientID(userid int64, clientID string)

func BuildClientConfig

func BuildClientConfig(client model.Client, server model.Server, setting model.GlobalSetting) string

BuildClientConfig to create wireguard client config string

func ClientDefaultsFromEnv added in v0.4.0

func ClientDefaultsFromEnv() model.ClientDefaults

ClientDefaultsFromEnv to read the default values for creating a new client from the environment or use sane defaults

func ConcatMultipleSlices added in v0.6.0

func ConcatMultipleSlices(slices ...[]byte) []byte

func ContainsCIDR added in v0.6.0

func ContainsCIDR(ipnet1, ipnet2 *net.IPNet) bool

ContainsCIDR to check if ipnet1 contains ipnet2 https://stackoverflow.com/a/40406619/6111641 https://go.dev/play/p/Q4J-JEN3sF

func FillClientSubnetRange added in v0.6.0

func FillClientSubnetRange(client model.ClientData) model.ClientData

FillClientSubnetRange to fill subnet ranges client belongs to, does nothing if SRs are not found

func GetAllocatedIPs

func GetAllocatedIPs(ignoreClientID string) ([]string, error)

GetAllocatedIPs to get all ip addresses allocated to clients and server

func GetAvailableIP

func GetAvailableIP(cidr string, allocatedList, interfaceAddresses []string) (string, error)

GetAvailableIP get the ip address that can be allocated from an CIDR We need interfaceAddresses to find real broadcast and network addresses

func GetBroadcastAndNetworkAddrsLookup added in v0.6.0

func GetBroadcastAndNetworkAddrsLookup(interfaceAddresses []string) map[string]bool

GetBroadcastAndNetworkAddrsLookup get the ip address that can't be used with current server interfaces

func GetBroadcastIP

func GetBroadcastIP(n *net.IPNet) net.IP

GetBroadcastIP func to get the broadcast ip address of a network

func GetCookiePath added in v0.6.0

func GetCookiePath() string

func GetCurrentHash added in v0.5.0

func GetCurrentHash(db store.IStore) (string, string)

GetCurrentHash returns current hashes

func GetDBUserCRC32 added in v0.6.0

func GetDBUserCRC32(dbuser model.User) uint32

func GetIPFromCIDR

func GetIPFromCIDR(cidr string) (string, error)

GetIPFromCIDR get ip from CIDR

func GetInterfaceIPs

func GetInterfaceIPs() ([]model.Interface, error)

GetInterfaceIPs to get local machine's interface ip addresses

func GetPublicIP

func GetPublicIP() (model.Interface, error)

GetPublicIP to get machine's public ip address

func GetSubnetRangesString added in v0.6.0

func GetSubnetRangesString() string

GetSubnetRangesString to get a formatted string, representing active subnet ranges

func HashPassword added in v0.4.0

func HashPassword(plaintext string) (string, error)

func HashesChanged added in v0.5.0

func HashesChanged(db store.IStore) bool

func LookupEnvOrBool added in v0.3.3

func LookupEnvOrBool(key string, defaultVal bool) bool

func LookupEnvOrFile added in v0.6.0

func LookupEnvOrFile(key string, defaultVal string) string

func LookupEnvOrInt added in v0.3.3

func LookupEnvOrInt(key string, defaultVal int) int

func LookupEnvOrString added in v0.3.3

func LookupEnvOrString(key string, defaultVal string) string

func LookupEnvOrStrings added in v0.4.0

func LookupEnvOrStrings(key string, defaultVal []string) []string

func ManagePerms added in v0.6.0

func ManagePerms(path string) error

func ParseBasePath added in v0.4.0

func ParseBasePath(basePath string) string

func ParseLogLevel added in v0.5.0

func ParseLogLevel(lvl string) (log.Lvl, error)

func ParseSubnetRanges added in v0.6.0

func ParseSubnetRanges(subnetRangesStr string) map[string]([]*net.IPNet)

func RandomString added in v0.6.0

func RandomString(length int) string

func RemoveTgToClientID added in v0.6.0

func RemoveTgToClientID(clientID string)

func SendRequestedConfigsToTelegram added in v0.6.0

func SendRequestedConfigsToTelegram(db store.IStore, userid int64) []string

SendRequestedConfigsToTelegram to send client all their configs. Returns failed configs list.

func StringFromEmbedFile added in v0.5.0

func StringFromEmbedFile(embed fs.FS, filename string) (string, error)

func UpdateHashes added in v0.5.0

func UpdateHashes(db store.IStore) error

func UpdateTgToClientID added in v0.6.0

func UpdateTgToClientID(userid int64, clientID string)

func ValidateAllowedIPs

func ValidateAllowedIPs(cidrs []string) bool

ValidateAllowedIPs to validate allowed ip addresses in CIDR format

func ValidateAndFixSubnetRanges added in v0.6.0

func ValidateAndFixSubnetRanges(db store.IStore) error

ValidateAndFixSubnetRanges to check if subnet ranges are valid for the server configuration Removes all non-valid CIDRs

func ValidateCIDR

func ValidateCIDR(cidr string) bool

ValidateCIDR to validate a network CIDR

func ValidateCIDRList

func ValidateCIDRList(cidrs []string, allowEmpty bool) bool

ValidateCIDRList to validate a list of network CIDR

func ValidateExtraAllowedIPs added in v0.3.6

func ValidateExtraAllowedIPs(cidrs []string) bool

ValidateExtraAllowedIPs to validate extra Allowed ip addresses, allowing empty strings

func ValidateIPAddress

func ValidateIPAddress(ip string) bool

ValidateIPAddress to validate the IPv4 and IPv6 address

func ValidateIPAddressList

func ValidateIPAddressList(ips []string) bool

ValidateIPAddressList to validate a list of IPv4 and IPv6 addresses

func ValidateIPAllocation

func ValidateIPAllocation(serverAddresses []string, ipAllocatedList []string, ipAllocationList []string) (bool, error)

ValidateIPAllocation to validate the list of client's ip allocation They must have a correct format and available in serverAddresses space

func ValidateServerAddresses

func ValidateServerAddresses(cidrs []string) bool

ValidateServerAddresses to validate allowed ip addresses in CIDR format

func VerifyHash added in v0.4.0

func VerifyHash(base64Hash string, plaintext string) (bool, error)

func WriteWireGuardServerConfig

func WriteWireGuardServerConfig(tmplDir fs.FS, serverConfig model.Server, clientDataList []model.ClientData, usersList []model.User, globalSettings model.GlobalSetting) error

WriteWireGuardServerConfig to write Wireguard server config. e.g. wg0.conf

Types

This section is empty.

Jump to

Keyboard shortcuts

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