mirror of
https://github.com/h44z/wg-portal
synced 2025-02-26 05:49:14 +00:00
only remove private key if a custom public key was specified (#112)
This commit is contained in:
parent
352c689623
commit
ab7f19bb55
@ -420,10 +420,10 @@ func (s *Server) PostUserCreatePeer(c *gin.Context) {
|
||||
formPeer = currentSession.FormData.(wireguard.Peer)
|
||||
}
|
||||
|
||||
formPeer.Email = currentSession.Email;
|
||||
formPeer.Identifier = currentSession.Email;
|
||||
formPeer.DeviceType = wireguard.DeviceTypeServer;
|
||||
|
||||
formPeer.Email = currentSession.Email
|
||||
formPeer.Identifier = currentSession.Email
|
||||
formPeer.DeviceType = wireguard.DeviceTypeServer
|
||||
|
||||
if err := c.ShouldBind(&formPeer); err != nil {
|
||||
_ = s.updateFormInSession(c, formPeer)
|
||||
SetFlashMessage(c, "failed to bind form data: "+err.Error(), "danger")
|
||||
@ -431,6 +431,11 @@ func (s *Server) PostUserCreatePeer(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// if public key was manually set, remove the incorrect private key
|
||||
if formPeer.PublicKey != currentSession.FormData.(wireguard.Peer).PublicKey {
|
||||
formPeer.PrivateKey = ""
|
||||
}
|
||||
|
||||
disabled := c.PostForm("isdisabled") != ""
|
||||
now := time.Now()
|
||||
if disabled {
|
||||
@ -451,7 +456,6 @@ func (s *Server) PostUserCreatePeer(c *gin.Context) {
|
||||
func (s *Server) GetUserEditPeer(c *gin.Context) {
|
||||
peer := s.peers.GetPeerByKey(c.Query("pkey"))
|
||||
|
||||
|
||||
currentSession, err := s.setFormInSession(c, peer)
|
||||
if err != nil {
|
||||
s.GetHandleError(c, http.StatusInternalServerError, "Session error", err.Error())
|
||||
@ -460,7 +464,7 @@ func (s *Server) GetUserEditPeer(c *gin.Context) {
|
||||
|
||||
if peer.Email != currentSession.Email {
|
||||
s.GetHandleError(c, http.StatusUnauthorized, "No permissions", "You don't have permissions to view this resource!")
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "user_edit_client.html", gin.H{
|
||||
@ -485,7 +489,7 @@ func (s *Server) PostUserEditPeer(c *gin.Context) {
|
||||
|
||||
if currentPeer.Email != currentSession.Email {
|
||||
s.GetHandleError(c, http.StatusUnauthorized, "No permissions", "You don't have permissions to view this resource!")
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
disabled := c.PostForm("isdisabled") != ""
|
||||
@ -493,7 +497,7 @@ func (s *Server) PostUserEditPeer(c *gin.Context) {
|
||||
if disabled && currentPeer.DeactivatedAt == nil {
|
||||
currentPeer.DeactivatedAt = &now
|
||||
}
|
||||
|
||||
|
||||
// Update in database
|
||||
if err := s.UpdatePeer(currentPeer, now); err != nil {
|
||||
_ = s.updateFormInSession(c, currentPeer)
|
||||
|
Loading…
Reference in New Issue
Block a user