diff --git a/assets/css/signin.css b/assets/css/signin.css index e69de29..8479bf2 100644 --- a/assets/css/signin.css +++ b/assets/css/signin.css @@ -0,0 +1,3 @@ +.navbar { + padding: 0.5rem 1rem; +} \ No newline at end of file diff --git a/assets/tpl/admin_edit_client.html b/assets/tpl/admin_edit_client.html index 4cf61bd..1cb0bfd 100644 --- a/assets/tpl/admin_edit_client.html +++ b/assets/tpl/admin_edit_client.html @@ -137,36 +137,9 @@ - {{if .EditableKeys}} -
-
- - -
-
-
-
- - -
-
-
-
- - -
-
- {{else}} - -
-
- - -
-
- {{end}} -
+ +
@@ -184,6 +157,12 @@
+
+
+ + +
+
diff --git a/assets/tpl/admin_index.html b/assets/tpl/admin_index.html index 8077b7f..026665a 100644 --- a/assets/tpl/admin_index.html +++ b/assets/tpl/admin_index.html @@ -163,7 +163,7 @@ {{$p.Identifier}} - {{$p.PublicKey}} + {{if eq $.Device.Type "server"}}{{$p.PublicKey}}{{end}}{{if eq $.Device.Type "client"}}{{$p.EndpointPublicKey}}{{end}} {{$p.Email}} {{$p.IPsStr}} {{$p.LastHandshake}} diff --git a/assets/tpl/login.html b/assets/tpl/login.html index a6b6287..e3e89b4 100644 --- a/assets/tpl/login.html +++ b/assets/tpl/login.html @@ -13,8 +13,17 @@ - -
+ + +
Please sign in
@@ -28,15 +37,16 @@
- + {{ if eq .error true }} -
- {{.message}} + {{end}} -
+
diff --git a/assets/tpl/prt_nav.html b/assets/tpl/prt_nav.html index 994f540..e997a44 100644 --- a/assets/tpl/prt_nav.html +++ b/assets/tpl/prt_nav.html @@ -27,8 +27,8 @@
diff --git a/internal/server/handlers_common.go b/internal/server/handlers_common.go index 2fa1087..476474b 100644 --- a/internal/server/handlers_common.go +++ b/internal/server/handlers_common.go @@ -23,7 +23,7 @@ func (s *Server) GetHandleError(c *gin.Context, code int, message, details strin "Session": GetSessionData(c), "Static": s.getStaticData(), "Device": s.peers.GetDevice(currentSession.DeviceName), - "DeviceNames": s.wg.Cfg.DeviceNames, + "DeviceNames": s.GetDeviceNames(), }) } @@ -36,7 +36,7 @@ func (s *Server) GetIndex(c *gin.Context) { "Session": currentSession, "Static": s.getStaticData(), "Device": s.peers.GetDevice(currentSession.DeviceName), - "DeviceNames": s.wg.Cfg.DeviceNames, + "DeviceNames": s.GetDeviceNames(), }) } @@ -104,7 +104,7 @@ func (s *Server) GetAdminIndex(c *gin.Context) { "TotalPeers": len(s.peers.GetAllPeers(currentSession.DeviceName)), "Users": s.users.GetUsers(), "Device": device, - "DeviceNames": s.wg.Cfg.DeviceNames, + "DeviceNames": s.GetDeviceNames(), }) } @@ -143,7 +143,7 @@ func (s *Server) GetUserIndex(c *gin.Context) { "TotalPeers": len(peers), "Users": []users.User{*s.users.GetUser(currentSession.Email)}, "Device": s.peers.GetDevice(currentSession.DeviceName), - "DeviceNames": s.wg.Cfg.DeviceNames, + "DeviceNames": s.GetDeviceNames(), }) } diff --git a/internal/server/handlers_interface.go b/internal/server/handlers_interface.go index 96f477e..457ac3f 100644 --- a/internal/server/handlers_interface.go +++ b/internal/server/handlers_interface.go @@ -27,7 +27,7 @@ func (s *Server) GetAdminEditInterface(c *gin.Context) { "Static": s.getStaticData(), "Device": currentSession.FormData.(wireguard.Device), "EditableKeys": s.config.Core.EditableKeys, - "DeviceNames": s.wg.Cfg.DeviceNames, + "DeviceNames": s.GetDeviceNames(), "Csrf": csrf.GetToken(c), }) } diff --git a/internal/server/handlers_peer.go b/internal/server/handlers_peer.go index 7e12e35..3933519 100644 --- a/internal/server/handlers_peer.go +++ b/internal/server/handlers_peer.go @@ -39,7 +39,7 @@ func (s *Server) GetAdminEditPeer(c *gin.Context) { "Peer": currentSession.FormData.(wireguard.Peer), "EditableKeys": s.config.Core.EditableKeys, "Device": s.peers.GetDevice(currentSession.DeviceName), - "DeviceNames": s.wg.Cfg.DeviceNames, + "DeviceNames": s.GetDeviceNames(), "AdminEmail": s.config.Core.AdminUser, "Csrf": csrf.GetToken(c), }) @@ -99,7 +99,7 @@ func (s *Server) GetAdminCreatePeer(c *gin.Context) { "Peer": currentSession.FormData.(wireguard.Peer), "EditableKeys": s.config.Core.EditableKeys, "Device": s.peers.GetDevice(currentSession.DeviceName), - "DeviceNames": s.wg.Cfg.DeviceNames, + "DeviceNames": s.GetDeviceNames(), "AdminEmail": s.config.Core.AdminUser, "Csrf": csrf.GetToken(c), }) @@ -154,7 +154,7 @@ func (s *Server) GetAdminCreateLdapPeers(c *gin.Context) { "Users": s.users.GetFilteredAndSortedUsers("lastname", "asc", ""), "FormData": currentSession.FormData.(LdapCreateForm), "Device": s.peers.GetDevice(currentSession.DeviceName), - "DeviceNames": s.wg.Cfg.DeviceNames, + "DeviceNames": s.GetDeviceNames(), "Csrf": csrf.GetToken(c), }) } diff --git a/internal/server/handlers_user.go b/internal/server/handlers_user.go index 17e9ff4..643e56f 100644 --- a/internal/server/handlers_user.go +++ b/internal/server/handlers_user.go @@ -58,7 +58,7 @@ func (s *Server) GetAdminUsersIndex(c *gin.Context) { "Users": dbUsers, "TotalUsers": len(s.users.GetUsers()), "Device": s.peers.GetDevice(currentSession.DeviceName), - "DeviceNames": s.wg.Cfg.DeviceNames, + "DeviceNames": s.GetDeviceNames(), }) } @@ -78,7 +78,7 @@ func (s *Server) GetAdminUsersEdit(c *gin.Context) { "Static": s.getStaticData(), "User": currentSession.FormData.(users.User), "Device": s.peers.GetDevice(currentSession.DeviceName), - "DeviceNames": s.wg.Cfg.DeviceNames, + "DeviceNames": s.GetDeviceNames(), "Epoch": time.Time{}, "Csrf": csrf.GetToken(c), }) @@ -156,7 +156,7 @@ func (s *Server) GetAdminUsersCreate(c *gin.Context) { "Static": s.getStaticData(), "User": currentSession.FormData.(users.User), "Device": s.peers.GetDevice(currentSession.DeviceName), - "DeviceNames": s.wg.Cfg.DeviceNames, + "DeviceNames": s.GetDeviceNames(), "Epoch": time.Time{}, "Csrf": csrf.GetToken(c), }) diff --git a/internal/server/server_helper.go b/internal/server/server_helper.go index 5eec6b3..b0d8863 100644 --- a/internal/server/server_helper.go +++ b/internal/server/server_helper.go @@ -140,8 +140,13 @@ func (s *Server) UpdatePeer(peer wireguard.Peer, updateTime time.Time) error { // Update WireGuard device var err error switch { - case peer.DeactivatedAt == &updateTime: - err = s.wg.RemovePeer(peer.DeviceName, peer.PublicKey) + case peer.DeactivatedAt != nil && *peer.DeactivatedAt == updateTime: + switch dev.Type { + case wireguard.DeviceTypeServer: + err = s.wg.RemovePeer(peer.DeviceName, peer.PublicKey) + case wireguard.DeviceTypeClient: + err = s.wg.RemovePeer(peer.DeviceName, peer.EndpointPublicKey) + } case peer.DeactivatedAt == nil && currentPeer.Peer != nil: err = s.wg.UpdatePeer(peer.DeviceName, peer.GetConfig(&dev)) case peer.DeactivatedAt == nil && currentPeer.Peer == nil: @@ -161,8 +166,18 @@ func (s *Server) UpdatePeer(peer wireguard.Peer, updateTime time.Time) error { // DeletePeer removes the peer from the physical WireGuard interface and the database. func (s *Server) DeletePeer(peer wireguard.Peer) error { + dev := s.peers.GetDevice(peer.DeviceName) + + var publicKey string + switch dev.Type { + case wireguard.DeviceTypeServer: + publicKey = peer.PublicKey + case wireguard.DeviceTypeClient: + publicKey = peer.EndpointPublicKey + } + // Delete WireGuard peer - if err := s.wg.RemovePeer(peer.DeviceName, peer.PublicKey); err != nil { + if err := s.wg.RemovePeer(peer.DeviceName, publicKey); err != nil { return errors.WithMessage(err, "failed to remove WireGuard peer") } @@ -308,3 +323,14 @@ func (s *Server) CreateUserDefaultPeer(email, device string) error { return nil } + +func (s *Server) GetDeviceNames() map[string]string { + devNames := make(map[string]string, len(s.wg.Cfg.DeviceNames)) + + for _, devName := range s.wg.Cfg.DeviceNames { + dev := s.peers.GetDevice(devName) + devNames[devName] = dev.DisplayName + } + + return devNames +} diff --git a/internal/wireguard/tpl/peer.tpl b/internal/wireguard/tpl/peer.tpl index 5899308..78c7fca 100644 --- a/internal/wireguard/tpl/peer.tpl +++ b/internal/wireguard/tpl/peer.tpl @@ -19,7 +19,9 @@ MTU = {{.Peer.Mtu}} [Peer] PublicKey = {{ .Peer.EndpointPublicKey }} Endpoint = {{ .Peer.Endpoint }} +{{- if .Peer.AllowedIPsStr}} AllowedIPs = {{ .Peer.AllowedIPsStr }} +{{- end}} {{- if .Peer.PresharedKey}} PresharedKey = {{ .Peer.PresharedKey }} {{- end}}