Documentation
¶
Index ¶
- Constants
- Variables
- func AddPeerToInterface(client model.Client, server model.Server, settings model.GlobalSetting, ...) error
- func AddTgToClientID(userid int64, clientID string)
- func ApplyPeerDiffs(interfaceName string, diffs []PeerDiff, settings model.GlobalSetting) error
- func BuildClientConfig(client model.Client, server model.Server, setting model.GlobalSetting) string
- func BuildPeerConfig(cl *model.Client, settings model.GlobalSetting) (wgtypes.PeerConfig, error)
- func ClientDefaultsFromEnv() model.ClientDefaults
- func ConcatMultipleSlices(slices ...[]byte) []byte
- func ContainsCIDR(ipnet1, ipnet2 *net.IPNet) bool
- func FillClientSubnetRange(client model.ClientData) model.ClientData
- func GetAllocatedIPs(ignoreClientID string) ([]string, error)
- func GetAvailableIP(cidr string, allocatedList, interfaceAddresses []string) (string, error)
- func GetBroadcastAndNetworkAddrsLookup(interfaceAddresses []string) map[string]bool
- func GetBroadcastIP(n *net.IPNet) net.IP
- func GetCookiePath() string
- func GetCurrentHash(db store.IStore) (string, string)
- func GetDBUserCRC32(dbuser model.User) uint32
- func GetDefaultInterfaceName() string
- func GetIPFromCIDR(cidr string) (string, error)
- func GetInterfaceIPs() ([]model.Interface, error)
- func GetInterfaceNameFromConfig(configFilePath string) string
- func GetPublicIP() (model.Interface, error)
- func GetSubnetRangesString() string
- func GetWireGuardConfigTemplate() ([]byte, error)
- func HashPassword(plaintext string) (string, error)
- func HashesChanged(db store.IStore) bool
- func IsClientValid(client model.Client) bool
- func LookupEnvOrBool(key string, defaultVal bool) bool
- func LookupEnvOrFile(key string, defaultVal string) string
- func LookupEnvOrInt(key string, defaultVal int) int
- func LookupEnvOrString(key string, defaultVal string) string
- func LookupEnvOrStrings(key string, defaultVal []string) []string
- func ManagePerms(path string) error
- func ParseBasePath(basePath string) string
- func ParseLogLevel(lvl string) (log.Lvl, error)
- func ParseSubnetRanges(subnetRangesStr string) map[string]([]*net.IPNet)
- func RandomString(length int) string
- func RemovePeerFromInterface(publicKey string, interfaceName string) error
- func RemoveTgToClientID(clientID string)
- func SendRequestedConfigsToTelegram(db store.IStore, userid int64) []string
- func StringFromEmbedFile(embed fs.FS, filename string) (string, error)
- func UpdateHashes(db store.IStore) error
- func UpdatePeerOnInterface(client model.Client, server model.Server, settings model.GlobalSetting, ...) error
- func UpdateTgToClientID(userid int64, clientID string)
- func ValidateAllowedIPs(cidrs []string) bool
- func ValidateAndFixSubnetRanges(db store.IStore) error
- func ValidateCIDR(cidr string) bool
- func ValidateCIDRList(cidrs []string, allowEmpty bool) bool
- func ValidateExtraAllowedIPs(cidrs []string) bool
- func ValidateIPAddress(ip string) bool
- func ValidateIPAddressList(ips []string) bool
- func ValidateIPAllocation(serverAddresses []string, ipAllocatedList []string, ipAllocationList []string) (bool, error)
- func ValidateServerAddresses(cidrs []string) bool
- func VerifyHash(base64Hash string, plaintext string) (bool, error)
- func WriteWireGuardServerConfig(tmplDir fs.FS, serverConfig model.Server, clientDataList []model.ClientData, ...) error
- type PeerDiff
- type PeerState
Constants ¶
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" TimezoneEnvVar = "WGUI_TIMEZONE" LanguageEnvVar = "WGUI_LANGUAGE" 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" SessionMaxAgeEnvVar = "SESSION_MAX_AGE" )
Variables ¶
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 SessionMaxAge int WgConfTemplate string BasePath string SubnetRanges map[string]([]*net.IPNet) SubnetRangesOrder []string )
Runtime config
var DBUsersToCRC32 = map[string]uint32{}
var IPToSubnetRange = map[string]uint16{}
var TgUseridToClientID = map[int64][]string{}
var TgUseridToClientIDMutex sync.RWMutex
Functions ¶
func AddPeerToInterface ¶
func AddPeerToInterface(client model.Client, server model.Server, settings model.GlobalSetting, interfaceName string) error
AddPeerToInterface adds or updates a peer on the WireGuard interface using wgctrl This is a hot-reload operation that doesn't restart the service
func AddTgToClientID ¶
func ApplyPeerDiffs ¶
func ApplyPeerDiffs(interfaceName string, diffs []PeerDiff, settings model.GlobalSetting) error
ApplyPeerDiffs applies the given diffs using wgctrl
func BuildClientConfig ¶
func BuildClientConfig(client model.Client, server model.Server, setting model.GlobalSetting) string
BuildClientConfig to create wireguard client config string
func BuildPeerConfig ¶
func BuildPeerConfig(cl *model.Client, settings model.GlobalSetting) (wgtypes.PeerConfig, error)
BuildPeerConfig converts a client entry into a wgtypes.PeerConfig for runtime updates
func ClientDefaultsFromEnv ¶
func ClientDefaultsFromEnv() model.ClientDefaults
ClientDefaultsFromEnv to read the default values for creating a new client from the environment or use sane defaults
func ConcatMultipleSlices ¶
func ContainsCIDR ¶
ContainsCIDR to check if ipnet1 contains ipnet2 https://stackoverflow.com/a/40406619/6111641 https://go.dev/play/p/Q4J-JEN3sF
func FillClientSubnetRange ¶
func FillClientSubnetRange(client model.ClientData) model.ClientData
func GetAllocatedIPs ¶
GetAllocatedIPs to get all ip addresses allocated to clients and server
func GetAvailableIP ¶
GetAvailableIP get the ip address that can be allocated from an CIDR We need interfaceAddresses to find real broadcast and network addresses
func GetBroadcastAndNetworkAddrsLookup ¶
GetBroadcastAndNetworkAddrsLookup get the ip address that can't be used with current server interfaces
func GetBroadcastIP ¶
GetBroadcastIP func to get the broadcast ip address of a network
func GetCookiePath ¶
func GetCookiePath() string
func GetCurrentHash ¶
GetCurrentHash returns current hashes
func GetDBUserCRC32 ¶
func GetDefaultInterfaceName ¶
func GetDefaultInterfaceName() string
GetDefaultInterfaceName detects the default network interface name Returns the interface name that has the default route, or "eth0" as fallback
func GetInterfaceIPs ¶
GetInterfaceIPs to get local machine's interface ip addresses
func GetInterfaceNameFromConfig ¶
GetInterfaceNameFromConfig extracts the interface name from the config file path Defaults to "wg0" if not found
func GetPublicIP ¶
GetPublicIP to get machine's public ip address
func GetSubnetRangesString ¶
func GetSubnetRangesString() string
GetSubnetRangesString to get a formatted string, representing active subnet ranges
func GetWireGuardConfigTemplate ¶
GetWireGuardConfigTemplate returns the embedded WireGuard config template file
func HashPassword ¶
func HashesChanged ¶
func IsClientValid ¶
FillClientSubnetRange to fill subnet ranges client belongs to, does nothing if SRs are not found IsClientValid checks if a client is valid (not expired and not over quota) Returns true if client can be enabled, false otherwise
func LookupEnvOrBool ¶
func LookupEnvOrFile ¶
func LookupEnvOrInt ¶
func LookupEnvOrString ¶
func LookupEnvOrStrings ¶
func ManagePerms ¶
func ParseBasePath ¶
func RandomString ¶
func RemovePeerFromInterface ¶
RemovePeerFromInterface removes a peer from the WireGuard interface using wgctrl This instantly disconnects the user without restarting the service Returns nil if peer was removed successfully or if peer doesn't exist (idempotent)
func RemoveTgToClientID ¶
func RemoveTgToClientID(clientID string)
func SendRequestedConfigsToTelegram ¶
SendRequestedConfigsToTelegram to send client all their configs. Returns failed configs list.
func UpdateHashes ¶
func UpdatePeerOnInterface ¶
func UpdatePeerOnInterface(client model.Client, server model.Server, settings model.GlobalSetting, interfaceName string) error
UpdatePeerOnInterface updates a peer on the WireGuard interface If client is disabled, expired, or over quota, it removes the peer Otherwise, it adds/updates the peer
func UpdateTgToClientID ¶
func ValidateAllowedIPs ¶
ValidateAllowedIPs to validate allowed ip addresses in CIDR format
func ValidateAndFixSubnetRanges ¶
ValidateAndFixSubnetRanges to check if subnet ranges are valid for the server configuration Removes all non-valid CIDRs
func ValidateCIDRList ¶
ValidateCIDRList to validate a list of network CIDR
func ValidateExtraAllowedIPs ¶
ValidateExtraAllowedIPs to validate extra Allowed ip addresses, allowing empty strings
func ValidateIPAddress ¶
ValidateIPAddress to validate the IPv4 and IPv6 address
func ValidateIPAddressList ¶
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 ¶
ValidateServerAddresses to validate allowed ip addresses in CIDR format
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 ¶
type PeerDiff ¶
PeerDiff represents an action required to sync peer state
func ComputePeerDiffs ¶
func ComputePeerDiffs(interfaceName string, clients []model.ClientData, settings model.GlobalSetting) ([]PeerDiff, error)
ComputePeerDiffs compares current interface state with target client list