server

package
v1.0.19 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 49 Imported by: 0

Documentation

Index

Constants

View Source
const SessionIdentifier = "wgPortalSession"

Variables

View Source
var DatabaseVersion = "1.0.9"
View Source
var ErrInvalidSpecification = errors.New("specification must be a struct pointer")
View Source
var Version = "testbuild"

Functions

func DestroySessionData added in v1.0.3

func DestroySessionData(c *gin.Context) error

func SetFlashMessage added in v1.0.3

func SetFlashMessage(c *gin.Context, message, typ string)

func SetupApiRoutes added in v1.0.8

func SetupApiRoutes(s *Server)

func SetupRoutes

func SetupRoutes(s *Server)

func UpdateSessionData added in v1.0.3

func UpdateSessionData(c *gin.Context, data SessionData) error

Types

type ApiError added in v1.0.8

type ApiError struct {
	Message string
}

type ApiServer added in v1.0.8

type ApiServer struct {
	// contains filtered or unexported fields
}

ApiServer is a simple wrapper struct so that we can have fresh member function names.

func (*ApiServer) DeletePeer added in v1.0.8

func (s *ApiServer) DeletePeer(c *gin.Context)

DeletePeer godoc @Tags Peers @Summary Updates the given peer based on the given partial peer model @ID DeletePeer @Produce json @Param PublicKey query string true "Public Key" @Success 204 "No Content" @Failure 400 {object} ApiError @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Failure 500 {object} ApiError @Router /backend/peer [delete] @Security ApiBasicAuth

func (*ApiServer) DeleteUser added in v1.0.8

func (s *ApiServer) DeleteUser(c *gin.Context)

DeleteUser godoc @Tags Users @Summary Deletes the specified user @ID DeleteUser @Produce json @Param Email query string true "User Email" @Success 204 "No content" @Failure 400 {object} ApiError @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Failure 500 {object} ApiError @Router /backend/user [delete] @Security ApiBasicAuth

func (*ApiServer) GetDevice added in v1.0.8

func (s *ApiServer) GetDevice(c *gin.Context)

GetDevice godoc @Tags Interface @Summary Get the given device @ID GetDevice @Produce json @Param DeviceName query string true "Device Name" @Success 200 {object} wireguard.Device @Failure 400 {object} ApiError @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Router /backend/device [get] @Security ApiBasicAuth

func (*ApiServer) GetDevices added in v1.0.8

func (s *ApiServer) GetDevices(c *gin.Context)

GetDevices godoc @Tags Interface @Summary Get all devices @ID GetDevices @Produce json @Success 200 {object} []wireguard.Device @Failure 400 {object} ApiError @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Router /backend/devices [get] @Security ApiBasicAuth

func (*ApiServer) GetPeer added in v1.0.8

func (s *ApiServer) GetPeer(c *gin.Context)

GetPeer godoc @Tags Peers @Summary Retrieves the peer for the given public key @ID GetPeer @Produce json @Param PublicKey query string true "Public Key (Base 64)" @Success 200 {object} wireguard.Peer @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Router /backend/peer [get] @Security ApiBasicAuth

func (*ApiServer) GetPeerDeploymentConfig added in v1.0.8

func (s *ApiServer) GetPeerDeploymentConfig(c *gin.Context)

GetPeerDeploymentConfig godoc @Tags Provisioning @Summary Retrieves the peer config for the given public key @ID GetPeerDeploymentConfig @Produce plain @Param PublicKey query string true "Public Key (Base 64)" @Success 200 {object} string "The WireGuard configuration file" @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Router /provisioning/peer [get] @Security GeneralBasicAuth

func (*ApiServer) GetPeerDeploymentInformation added in v1.0.8

func (s *ApiServer) GetPeerDeploymentInformation(c *gin.Context)

GetPeerDeploymentInformation godoc @Tags Provisioning @Summary Retrieves all active peers for the given email address @ID GetPeerDeploymentInformation @Produce json @Param Email query string true "Email Address" @Success 200 {object} []PeerDeploymentInformation "All active WireGuard peers" @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Router /provisioning/peers [get] @Security GeneralBasicAuth

func (*ApiServer) GetPeers added in v1.0.8

func (s *ApiServer) GetPeers(c *gin.Context)

GetPeers godoc @Tags Peers @Summary Retrieves all peers for the given interface @ID GetPeers @Produce json @Param DeviceName query string true "Device Name" @Success 200 {object} []wireguard.Peer @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Router /backend/peers [get] @Security ApiBasicAuth

func (*ApiServer) GetUser added in v1.0.8

func (s *ApiServer) GetUser(c *gin.Context)

GetUser godoc @Tags Users @Summary Retrieves user based on given Email @ID GetUser @Produce json @Param Email query string true "User Email" @Success 200 {object} users.User @Failure 400 {object} ApiError @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Router /backend/user [get] @Security ApiBasicAuth

func (*ApiServer) GetUsers added in v1.0.8

func (s *ApiServer) GetUsers(c *gin.Context)

GetUsers godoc @Tags Users @Summary Retrieves all users @ID GetUsers @Produce json @Success 200 {object} []users.User @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Router /backend/users [get] @Security ApiBasicAuth

func (*ApiServer) PatchDevice added in v1.0.8

func (s *ApiServer) PatchDevice(c *gin.Context)

PatchDevice godoc @Tags Interface @Summary Updates the given device based on the given partial device model (UNIMPLEMENTED) @ID PatchDevice @Accept json @Produce json @Param DeviceName query string true "Device Name" @Param Device body wireguard.Device true "Device Model" @Success 200 {object} wireguard.Device @Failure 400 {object} ApiError @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Failure 500 {object} ApiError @Router /backend/device [patch] @Security ApiBasicAuth

func (*ApiServer) PatchPeer added in v1.0.8

func (s *ApiServer) PatchPeer(c *gin.Context)

PatchPeer godoc @Tags Peers @Summary Updates the given peer based on the given partial peer model @ID PatchPeer @Accept json @Produce json @Param PublicKey query string true "Public Key" @Param Peer body wireguard.Peer true "Peer Model" @Success 200 {object} wireguard.Peer @Failure 400 {object} ApiError @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Failure 500 {object} ApiError @Router /backend/peer [patch] @Security ApiBasicAuth

func (*ApiServer) PatchUser added in v1.0.8

func (s *ApiServer) PatchUser(c *gin.Context)

PatchUser godoc @Tags Users @Summary Updates a user based on the given partial user model @ID PatchUser @Accept json @Produce json @Param Email query string true "User Email" @Param User body users.User true "User Model" @Success 200 {object} users.User @Failure 400 {object} ApiError @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Failure 500 {object} ApiError @Router /backend/user [patch] @Security ApiBasicAuth

func (*ApiServer) PostPeer added in v1.0.8

func (s *ApiServer) PostPeer(c *gin.Context)

PostPeer godoc @Tags Peers @Summary Creates a new peer based on the given peer model @ID PostPeer @Accept json @Produce json @Param DeviceName query string true "Device Name" @Param Peer body wireguard.Peer true "Peer Model" @Success 200 {object} wireguard.Peer @Failure 400 {object} ApiError @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Failure 500 {object} ApiError @Router /backend/peers [post] @Security ApiBasicAuth

func (*ApiServer) PostPeerDeploymentConfig added in v1.0.8

func (s *ApiServer) PostPeerDeploymentConfig(c *gin.Context)

PostPeerDeploymentConfig godoc @Tags Provisioning @Summary Creates the requested peer config and returns the config file @ID PostPeerDeploymentConfig @Accept json @Produce plain @Param ProvisioningRequest body ProvisioningRequest true "Provisioning Request Model" @Success 200 {object} string "The WireGuard configuration file" @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Router /provisioning/peers [post] @Security GeneralBasicAuth

func (*ApiServer) PostUser added in v1.0.8

func (s *ApiServer) PostUser(c *gin.Context)

PostUser godoc @Tags Users @Summary Creates a new user based on the given user model @ID PostUser @Accept json @Produce json @Param User body users.User true "User Model" @Success 200 {object} users.User @Failure 400 {object} ApiError @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Failure 500 {object} ApiError @Router /backend/users [post] @Security ApiBasicAuth

func (*ApiServer) PutDevice added in v1.0.8

func (s *ApiServer) PutDevice(c *gin.Context)

PutDevice godoc @Tags Interface @Summary Updates the given device based on the given device model (UNIMPLEMENTED) @ID PutDevice @Accept json @Produce json @Param DeviceName query string true "Device Name" @Param Device body wireguard.Device true "Device Model" @Success 200 {object} wireguard.Device @Failure 400 {object} ApiError @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Failure 500 {object} ApiError @Router /backend/device [put] @Security ApiBasicAuth

func (*ApiServer) PutPeer added in v1.0.8

func (s *ApiServer) PutPeer(c *gin.Context)

PutPeer godoc @Tags Peers @Summary Updates the given peer based on the given peer model @ID PutPeer @Accept json @Produce json @Param PublicKey query string true "Public Key" @Param Peer body wireguard.Peer true "Peer Model" @Success 200 {object} wireguard.Peer @Failure 400 {object} ApiError @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Failure 500 {object} ApiError @Router /backend/peer [put] @Security ApiBasicAuth

func (*ApiServer) PutUser added in v1.0.8

func (s *ApiServer) PutUser(c *gin.Context)

PutUser godoc @Tags Users @Summary Updates a user based on the given user model @ID PutUser @Accept json @Produce json @Param Email query string true "User Email" @Param User body users.User true "User Model" @Success 200 {object} users.User @Failure 400 {object} ApiError @Failure 401 {object} ApiError @Failure 403 {object} ApiError @Failure 404 {object} ApiError @Failure 500 {object} ApiError @Router /backend/user [put] @Security ApiBasicAuth

type AuthManager added in v1.0.3

type AuthManager struct {
	Server *Server
	Group  *gin.RouterGroup // basic group for all providers (/auth)

	UserManager *users.Manager
	// contains filtered or unexported fields
}

AuthManager keeps track of available authentication providers.

func NewAuthManager added in v1.0.3

func NewAuthManager(server *Server) *AuthManager

func (*AuthManager) GetProvider added in v1.0.3

func (auth *AuthManager) GetProvider(name string) authentication.AuthProvider

GetProvider get provider by name

func (*AuthManager) GetProviders added in v1.0.3

func (auth *AuthManager) GetProviders() (providers []authentication.AuthProvider)

GetProviders return registered providers. Returned providers are ordered by provider priority.

func (*AuthManager) GetProvidersForType added in v1.0.3

func (auth *AuthManager) GetProvidersForType(typ authentication.AuthProviderType) (providers []authentication.AuthProvider)

GetProvidersForType return registered providers for the given type. Returned providers are ordered by provider priority.

func (*AuthManager) RegisterProvider added in v1.0.3

func (auth *AuthManager) RegisterProvider(provider authentication.AuthProvider)

RegisterProvider register auth provider

func (*AuthManager) RegisterProviderWithoutError added in v1.0.3

func (auth *AuthManager) RegisterProviderWithoutError(provider authentication.AuthProvider, err error)

RegisterProviderWithoutError register auth provider if err is nil

type Config added in v1.0.4

type Config struct {
	Core struct {
		ListeningAddress        string `yaml:"listeningAddress" envconfig:"LISTENING_ADDRESS"`
		ExternalUrl             string `yaml:"externalUrl" envconfig:"EXTERNAL_URL"`
		Title                   string `yaml:"title" envconfig:"WEBSITE_TITLE"`
		CompanyName             string `yaml:"company" envconfig:"COMPANY_NAME"`
		MailFrom                string `yaml:"mailFrom" envconfig:"MAIL_FROM"`
		AdminUser               string `yaml:"adminUser" envconfig:"ADMIN_USER"` // must be an email address
		AdminPassword           string `yaml:"adminPass" envconfig:"ADMIN_PASS"`
		EditableKeys            bool   `yaml:"editableKeys" envconfig:"EDITABLE_KEYS"`
		CreateDefaultPeer       bool   `yaml:"createDefaultPeer" envconfig:"CREATE_DEFAULT_PEER"`
		SelfProvisioningAllowed bool   `yaml:"selfProvisioning" envconfig:"SELF_PROVISIONING"`
		WGExporterFriendlyNames bool   `yaml:"wgExporterFriendlyNames" envconfig:"WG_EXPORTER_FRIENDLY_NAMES"`
		LdapEnabled             bool   `yaml:"ldapEnabled" envconfig:"LDAP_ENABLED"`
		SessionSecret           string `yaml:"sessionSecret" envconfig:"SESSION_SECRET"`
		LogoUrl                 string `yaml:"logoUrl" envconfig:"LOGO_URL"`
		BackgroundTaskInterval  int    `yaml:"backgroundTaskInterval" envconfig:"BACKGROUND_TASK_INTERVAL"` // in seconds
		ExpiryReEnable          bool   `yaml:"expiryReEnable" envconfig:"EXPIRY_REENABLE"`
	} `yaml:"core"`
	Database common.DatabaseConfig `yaml:"database"`
	Email    common.MailConfig     `yaml:"email"`
	LDAP     ldap.Config           `yaml:"ldap"`
	WG       wireguard.Config      `yaml:"wg"`
}

func NewConfig added in v1.0.4

func NewConfig() *Config

type FlashData

type FlashData struct {
	HasAlert bool
	Message  string
	Type     string
}

func GetFlashes added in v1.0.3

func GetFlashes(c *gin.Context) []FlashData

type LdapCreateForm

type LdapCreateForm struct {
	Emails     string `form:"email" binding:"required"`
	Identifier string `form:"identifier" binding:"required,lte=20"`
}

type PeerDeploymentInformation added in v1.0.8

type PeerDeploymentInformation struct {
	PublicKey        string
	Identifier       string
	Device           string
	DeviceIdentifier string
}

type ProvisioningRequest added in v1.0.8

type ProvisioningRequest struct {
	// DeviceName is optional, if not specified, the configured default device will be used.
	DeviceName string `json:",omitempty"`
	Identifier string `binding:"required"`
	Email      string `binding:"required"`

	AllowedIPsStr       string `binding:"cidrlist" json:",omitempty"`
	PersistentKeepalive int    `binding:"gte=0" json:",omitempty"`
	DNSStr              string `binding:"iplist" json:",omitempty"`
	Mtu                 int    `binding:"gte=0,lte=1500" json:",omitempty"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func (*Server) CreatePeer added in v1.0.3

func (s *Server) CreatePeer(device string, peer wireguard.Peer) error

CreatePeer creates the new peer in the database. If the peer has no assigned ip addresses, a new one will be assigned automatically. Also, if the private key is empty, a new key-pair will be generated. This function also configures the new peer on the physical WireGuard interface if the peer is not deactivated.

func (*Server) CreatePeerByEmail added in v1.0.3

func (s *Server) CreatePeerByEmail(device, email, identifierSuffix string) error

CreatePeerByEmail creates a new peer for the given email.

func (*Server) CreateUser

func (s *Server) CreateUser(user users.User, device string) error

CreateUser creates the user in the database and optionally adds a default WireGuard peer for the user.

func (*Server) CreateUserDefaultPeer added in v1.0.3

func (s *Server) CreateUserDefaultPeer(email, device string) error

func (*Server) DeletePeer added in v1.0.3

func (s *Server) DeletePeer(peer wireguard.Peer) error

DeletePeer removes the peer from the physical WireGuard interface and the database.

func (*Server) DeleteUser

func (s *Server) DeleteUser(user users.User) error

DeleteUser soft-deletes the user from the database (disable the user). Also, if the user has linked WireGuard peers, they will be deactivated.

func (*Server) GetAdminCreateLdapPeers

func (s *Server) GetAdminCreateLdapPeers(c *gin.Context)

func (*Server) GetAdminCreatePeer

func (s *Server) GetAdminCreatePeer(c *gin.Context)

func (*Server) GetAdminDeletePeer

func (s *Server) GetAdminDeletePeer(c *gin.Context)

func (*Server) GetAdminEditInterface

func (s *Server) GetAdminEditInterface(c *gin.Context)

func (*Server) GetAdminEditPeer

func (s *Server) GetAdminEditPeer(c *gin.Context)

func (*Server) GetAdminIndex

func (s *Server) GetAdminIndex(c *gin.Context)

func (*Server) GetAdminSendEmails added in v1.0.11

func (s *Server) GetAdminSendEmails(c *gin.Context)

func (*Server) GetAdminUsersCreate added in v1.0.3

func (s *Server) GetAdminUsersCreate(c *gin.Context)

func (*Server) GetAdminUsersDelete added in v1.0.14

func (s *Server) GetAdminUsersDelete(c *gin.Context)

func (*Server) GetAdminUsersEdit added in v1.0.3

func (s *Server) GetAdminUsersEdit(c *gin.Context)

func (*Server) GetAdminUsersIndex added in v1.0.3

func (s *Server) GetAdminUsersIndex(c *gin.Context)

func (*Server) GetApplyGlobalConfig

func (s *Server) GetApplyGlobalConfig(c *gin.Context)

func (*Server) GetDeviceNames added in v1.0.5

func (s *Server) GetDeviceNames() map[string]string

func (*Server) GetHandleError

func (s *Server) GetHandleError(c *gin.Context, code int, message, details string)

func (*Server) GetIndex

func (s *Server) GetIndex(c *gin.Context)

func (*Server) GetInterfaceConfig

func (s *Server) GetInterfaceConfig(c *gin.Context)

func (*Server) GetLogin

func (s *Server) GetLogin(c *gin.Context)

func (*Server) GetLogout

func (s *Server) GetLogout(c *gin.Context)

func (*Server) GetPeerConfig

func (s *Server) GetPeerConfig(c *gin.Context)

func (*Server) GetPeerConfigMail

func (s *Server) GetPeerConfigMail(c *gin.Context)

func (*Server) GetPeerQRCode

func (s *Server) GetPeerQRCode(c *gin.Context)

func (*Server) GetPeerStatus

func (s *Server) GetPeerStatus(c *gin.Context)

func (*Server) GetSaveConfig added in v1.0.5

func (s *Server) GetSaveConfig(c *gin.Context)

func (*Server) GetUserCreatePeer added in v1.0.15

func (s *Server) GetUserCreatePeer(c *gin.Context)

func (*Server) GetUserEditPeer added in v1.0.15

func (s *Server) GetUserEditPeer(c *gin.Context)

func (*Server) GetUserIndex

func (s *Server) GetUserIndex(c *gin.Context)

func (*Server) HardDeleteUser added in v1.0.14

func (s *Server) HardDeleteUser(user users.User) error

HardDeleteUser removes the user from the database. Also, if the user has linked WireGuard peers, they will be deleted.

func (*Server) PostAdminCreateLdapPeers

func (s *Server) PostAdminCreateLdapPeers(c *gin.Context)

func (*Server) PostAdminCreatePeer

func (s *Server) PostAdminCreatePeer(c *gin.Context)

func (*Server) PostAdminEditInterface

func (s *Server) PostAdminEditInterface(c *gin.Context)

func (*Server) PostAdminEditPeer

func (s *Server) PostAdminEditPeer(c *gin.Context)

func (*Server) PostAdminUsersCreate added in v1.0.3

func (s *Server) PostAdminUsersCreate(c *gin.Context)

func (*Server) PostAdminUsersEdit added in v1.0.3

func (s *Server) PostAdminUsersEdit(c *gin.Context)

func (*Server) PostLogin

func (s *Server) PostLogin(c *gin.Context)

func (*Server) PostUserCreatePeer added in v1.0.15

func (s *Server) PostUserCreatePeer(c *gin.Context)

func (*Server) PostUserEditPeer added in v1.0.15

func (s *Server) PostUserEditPeer(c *gin.Context)

func (*Server) PrepareNewPeer added in v1.0.3

func (s *Server) PrepareNewPeer(device string) (wireguard.Peer, error)

PrepareNewPeer initiates a new peer for the given WireGuard device.

func (*Server) RequireApiAuthentication added in v1.0.8

func (s *Server) RequireApiAuthentication(scope string) gin.HandlerFunc

func (*Server) RequireAuthentication

func (s *Server) RequireAuthentication(scope string) gin.HandlerFunc

func (*Server) RestoreWireGuardInterface

func (s *Server) RestoreWireGuardInterface(device string) error

RestoreWireGuardInterface restores the state of the physical WireGuard interface from the database.

func (*Server) Run

func (s *Server) Run()

func (*Server) RunBackgroundTasks added in v1.0.16

func (s *Server) RunBackgroundTasks(ctx context.Context)

func (*Server) Setup

func (s *Server) Setup(ctx context.Context) error

func (*Server) SyncLdapWithUserDatabase added in v1.0.3

func (s *Server) SyncLdapWithUserDatabase()

func (*Server) UpdatePeer added in v1.0.3

func (s *Server) UpdatePeer(peer wireguard.Peer, updateTime time.Time) error

UpdatePeer updates the physical WireGuard interface and the database.

func (*Server) UpdateUser

func (s *Server) UpdateUser(user users.User) error

UpdateUser updates the user in the database. If the user is marked as deleted, it will get remove from the database. Also, if the user is re-enabled, all it's linked WireGuard peers will be activated again.

func (*Server) WriteWireGuardConfigFile

func (s *Server) WriteWireGuardConfigFile(device string) error

WriteWireGuardConfigFile writes the configuration file for the physical WireGuard interface.

type SessionData

type SessionData struct {
	LoggedIn   bool
	IsAdmin    bool
	Firstname  string
	Lastname   string
	Email      string
	DeviceName string

	SortedBy      map[string]string
	SortDirection map[string]string
	Search        map[string]string

	AlertData string
	AlertType string
	FormData  interface{}
}

func GetSessionData added in v1.0.3

func GetSessionData(c *gin.Context) SessionData

func (SessionData) GetSortIcon

func (s SessionData) GetSortIcon(table, field string) string

type StaticData

type StaticData struct {
	WebsiteTitle string
	CompanyName  string
	Year         int
	Version      string
}

Directories

Path Synopsis
Code generated by swaggo/swag.
Code generated by swaggo/swag.

Jump to

Keyboard shortcuts

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