populate peer device type (#170)

This commit is contained in:
Christoph Haas 2023-10-26 10:20:08 +02:00
parent b3a5f2ac60
commit bdd426a679
4 changed files with 51 additions and 12 deletions

View File

@ -25,6 +25,7 @@ help:
#> codegen: Re-generate autogenerated files (like API docs)
.PHONY: codegen
codegen: $(SUBDIRS)
$(GOCMD) install github.com/swaggo/swag/cmd/swag@v1.8.10
cd internal; swag init --propertyStrategy pascalcase --parseInternal --generalInfo server/api.go --output server/docs/
$(GOCMD) fmt internal/server/docs/docs.go

View File

@ -1,5 +1,4 @@
// Package docs GENERATED BY SWAG; DO NOT EDIT
// This file was generated by swaggo/swag
// Code generated by swaggo/swag. DO NOT EDIT
package docs
import "github.com/swaggo/swag"
@ -1307,13 +1306,28 @@ const docTemplate = `{
"type": "string"
},
"Source": {
"type": "string"
"$ref": "#/definitions/users.UserSource"
},
"UpdatedAt": {
"type": "string"
}
}
},
"users.UserSource": {
"type": "string",
"enum": [
"ldap",
"db"
],
"x-enum-comments": {
"UserSourceDatabase": "sqlite / mysql database",
"UserSourceLdap": "LDAP / ActiveDirectory"
},
"x-enum-varnames": [
"UserSourceLdap",
"UserSourceDatabase"
]
},
"wireguard.Device": {
"type": "object",
"required": [
@ -1400,10 +1414,14 @@ const docTemplate = `{
"type": "boolean"
},
"Type": {
"type": "string",
"enum": [
"client",
"server"
],
"allOf": [
{
"$ref": "#/definitions/wireguard.DeviceType"
}
]
},
"UpdatedAt": {
@ -1411,6 +1429,17 @@ const docTemplate = `{
}
}
},
"wireguard.DeviceType": {
"type": "string",
"enum": [
"server",
"client"
],
"x-enum-varnames": [
"DeviceTypeServer",
"DeviceTypeClient"
]
},
"wireguard.Peer": {
"type": "object",
"required": [
@ -1447,13 +1476,19 @@ const docTemplate = `{
"type": "string"
},
"DeviceName": {
"description": "server interface name",
"type": "string"
},
"DeviceType": {
"type": "string",
"description": "the device type of the server (not the peer device)",
"enum": [
"client",
"server"
],
"allOf": [
{
"$ref": "#/definitions/wireguard.DeviceType"
}
]
},
"Email": {

View File

@ -128,8 +128,8 @@ func (s *Server) GetUserIndex(c *gin.Context) {
s.GetHandleError(c, http.StatusInternalServerError, "sort error", "failed to save session")
return
}
/*c.Redirect(http.StatusSeeOther, "/admin")
return*/
c.Redirect(http.StatusSeeOther, "/user/profile")
return
}
peers := s.peers.GetSortedPeersForEmail(currentSession.SortedBy["userpeers"], currentSession.SortDirection["userpeers"], currentSession.Email)

View File

@ -93,10 +93,10 @@ type Peer struct {
Peer *wgtypes.Peer `gorm:"-" json:"-"` // WireGuard peer
Config string `gorm:"-" json:"-"`
UID string `form:"uid" binding:"required,alphanum"` // uid for html identification
DeviceName string `gorm:"index" form:"device" binding:"required"`
DeviceType DeviceType `gorm:"-" form:"devicetype" binding:"required,oneof=client server"`
Identifier string `form:"identifier" binding:"required,max=64"` // Identifier AND Email make a WireGuard peer unique
UID string `form:"uid" binding:"required,alphanum"` // uid for html identification
DeviceName string `gorm:"index" form:"device" binding:"required"` // server interface name
DeviceType DeviceType `gorm:"-" form:"devicetype" binding:"required,oneof=client server"` // the device type of the server (not the peer device)
Identifier string `form:"identifier" binding:"required,max=64"` // Identifier AND Email make a WireGuard peer unique
Email string `gorm:"index" form:"mail" binding:"required,email"`
IgnoreGlobalSettings bool `form:"ignoreglobalsettings"`
@ -601,9 +601,12 @@ func (m *PeerManager) validateOrCreateDevice(dev wgtypes.Device, ipAddresses []s
// populatePeerData enriches the peer struct with WireGuard live data like last handshake, ...
func (m *PeerManager) populatePeerData(peer *Peer) {
device := m.GetDevice(peer.DeviceName)
// Set config file
tmpCfg, _ := peer.GetConfigFile(m.GetDevice(peer.DeviceName))
tmpCfg, _ := peer.GetConfigFile(device)
peer.Config = string(tmpCfg)
peer.DeviceType = device.Type
// set data from WireGuard interface
peer.Peer, _ = m.wg.GetPeer(peer.DeviceName, peer.PublicKey)