mirror of
https://github.com/DJSundog/wg-portal.git
synced 2024-11-23 07:03:50 -05:00
fix some bugs in client mode, improve login ui
This commit is contained in:
parent
94ca177884
commit
39166250ea
@ -0,0 +1,3 @@
|
|||||||
|
.navbar {
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
}
|
@ -137,36 +137,9 @@
|
|||||||
<input type="hidden" name="mail" value="{{.AdminEmail}}">
|
<input type="hidden" name="mail" value="{{.AdminEmail}}">
|
||||||
<input type="hidden" name="devicetype" value="{{.Device.Type}}">
|
<input type="hidden" name="devicetype" value="{{.Device.Type}}">
|
||||||
<input type="hidden" name="device" value="{{.Device.DeviceName}}">
|
<input type="hidden" name="device" value="{{.Device.DeviceName}}">
|
||||||
{{if .EditableKeys}}
|
|
||||||
<div class="form-row">
|
|
||||||
<div class="form-group col-md-12">
|
|
||||||
<label for="client_PrivateKey">Private Key</label>
|
|
||||||
<input type="text" name="privkey" class="form-control" id="client_PrivateKey" value="{{.Peer.PrivateKey}}">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
|
||||||
<div class="form-group required col-md-12">
|
|
||||||
<label for="client_PublicKey">Peer Public Key</label>
|
|
||||||
<input type="text" name="pubkey" class="form-control" id="client_PublicKey" value="{{.Peer.PublicKey}}" required>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
|
||||||
<div class="form-group col-md-12">
|
|
||||||
<label for="client_PresharedKey">Preshared Key</label>
|
|
||||||
<input type="text" name="presharedkey" class="form-control" id="client_PresharedKey" value="{{.Peer.PresharedKey}}">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{else}}
|
|
||||||
<input type="hidden" name="privkey" value="{{.Peer.PrivateKey}}">
|
<input type="hidden" name="privkey" value="{{.Peer.PrivateKey}}">
|
||||||
<input type="hidden" name="presharedkey" value="{{.Peer.PresharedKey}}">
|
<input type="hidden" name="pubkey" value="{{.Peer.PublicKey}}">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-group col-md-12">
|
|
||||||
<label for="client_ro_PublicKey">Public Key</label>
|
|
||||||
<input type="text" name="pubkey" readonly class="form-control" id="client_ro_PublicKey" value="{{.Peer.PublicKey}}">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
<div class="form-row">
|
|
||||||
<div class="form-group required col-md-12">
|
<div class="form-group required col-md-12">
|
||||||
<label for="client_Identifier">Endpoint Friendly Name</label>
|
<label for="client_Identifier">Endpoint Friendly Name</label>
|
||||||
<input type="text" name="identifier" class="form-control" id="client_Identifier" value="{{.Peer.Identifier}}" required>
|
<input type="text" name="identifier" class="form-control" id="client_Identifier" value="{{.Peer.Identifier}}" required>
|
||||||
@ -184,6 +157,12 @@
|
|||||||
<input type="text" name="endpointpubkey" class="form-control" id="client_EndpointPublicKey" value="{{.Peer.EndpointPublicKey}}" required>
|
<input type="text" name="endpointpubkey" class="form-control" id="client_EndpointPublicKey" value="{{.Peer.EndpointPublicKey}}" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group col-md-12">
|
||||||
|
<label for="client_PresharedKey">Preshared Key</label>
|
||||||
|
<input type="text" name="presharedkey" class="form-control" id="client_PresharedKey" value="{{.Peer.PresharedKey}}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-group col-md-12">
|
<div class="form-group col-md-12">
|
||||||
<label for="client_AllowedIP">Allowed IPs</label>
|
<label for="client_AllowedIP">Allowed IPs</label>
|
||||||
|
@ -163,7 +163,7 @@
|
|||||||
<span title="Online status" class="online-status" id="online-{{$p.UID}}" data-pkey="{{$p.PublicKey}}"><i class="fas fa-unlink"></i></span>
|
<span title="Online status" class="online-status" id="online-{{$p.UID}}" data-pkey="{{$p.PublicKey}}"><i class="fas fa-unlink"></i></span>
|
||||||
</th>
|
</th>
|
||||||
<td>{{$p.Identifier}}</td>
|
<td>{{$p.Identifier}}</td>
|
||||||
<td>{{$p.PublicKey}}</td>
|
<td>{{if eq $.Device.Type "server"}}{{$p.PublicKey}}{{end}}{{if eq $.Device.Type "client"}}{{$p.EndpointPublicKey}}{{end}}</td>
|
||||||
<td>{{$p.Email}}</td>
|
<td>{{$p.Email}}</td>
|
||||||
<td>{{$p.IPsStr}}</td>
|
<td>{{$p.IPsStr}}</td>
|
||||||
<td><span data-toggle="tooltip" data-placement="left" title="" data-original-title="{{$p.LastHandshakeTime}}">{{$p.LastHandshake}}</span></td>
|
<td><span data-toggle="tooltip" data-placement="left" title="" data-original-title="{{$p.LastHandshakeTime}}">{{$p.LastHandshake}}</span></td>
|
||||||
|
@ -13,8 +13,17 @@
|
|||||||
<link rel="stylesheet" href="/css/signin.css">
|
<link rel="stylesheet" href="/css/signin.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="bg-gradient-primary">
|
<body id="page-top" class="d-flex flex-column min-vh-100">
|
||||||
<div class="container">
|
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
||||||
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#topNavbar" aria-controls="topNavbar" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<a class="navbar-brand" href="/"><img src="{{$.static.WebsiteLogo}}" alt="{{$.static.CompanyName}}"/></a>
|
||||||
|
<div id="topNavbar" class="navbar-collapse collapse">
|
||||||
|
</div><!--/.navbar-collapse -->
|
||||||
|
</nav>
|
||||||
|
<div class="container mt-1">
|
||||||
<div class="card mt-5">
|
<div class="card mt-5">
|
||||||
<div class="card-header">Please sign in</div>
|
<div class="card-header">Please sign in</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@ -28,15 +37,16 @@
|
|||||||
<label for="inputPassword">Password</label>
|
<label for="inputPassword">Password</label>
|
||||||
<input type="password" name="password" class="form-control" id="inputPassword" placeholder="Password">
|
<input type="password" name="password" class="form-control" id="inputPassword" placeholder="Password">
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
|
<button class="btn btn-lg btn-primary btn-block mt-5" type="submit">Sign in</button>
|
||||||
|
|
||||||
{{ if eq .error true }}
|
{{ if eq .error true }}
|
||||||
<hr>
|
<div class="alert alert-danger" role="alert">
|
||||||
<span class="text-danger">{{.message}}</span>
|
{{.message}}
|
||||||
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div class="card shadow-lg o-hidden border-0 my-5">
|
<div class="card o-hidden border-0 my-5">
|
||||||
<div class="card-body p-0">
|
<div class="card-body p-0">
|
||||||
<a href="/" class="btn btn-white btn-block text-primary btn-user">Go Home</a>
|
<a href="/" class="btn btn-white btn-block text-primary btn-user">Go Home</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -27,8 +27,8 @@
|
|||||||
<form class="form-inline my-2 my-lg-0" method="get">
|
<form class="form-inline my-2 my-lg-0" method="get">
|
||||||
<div class="form-group mr-sm-2">
|
<div class="form-group mr-sm-2">
|
||||||
<select name="device" id="inputDevice" class="form-control device-selector">
|
<select name="device" id="inputDevice" class="form-control device-selector">
|
||||||
{{range $i, $d :=$.DeviceNames}}
|
{{range $d, $dn := $.DeviceNames}}
|
||||||
<option value="{{$d}}" {{if eq $d $.Session.DeviceName}}selected{{end}}>{{$d}}</option>
|
<option value="{{$d}}" {{if eq $d $.Session.DeviceName}}selected{{end}}>{{$d}} {{if and (ne $dn "") (ne $d $dn)}}({{$dn}}){{end}}</option>
|
||||||
{{end}}
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
@ -23,7 +23,7 @@ func (s *Server) GetHandleError(c *gin.Context, code int, message, details strin
|
|||||||
"Session": GetSessionData(c),
|
"Session": GetSessionData(c),
|
||||||
"Static": s.getStaticData(),
|
"Static": s.getStaticData(),
|
||||||
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
"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,
|
"Session": currentSession,
|
||||||
"Static": s.getStaticData(),
|
"Static": s.getStaticData(),
|
||||||
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
"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)),
|
"TotalPeers": len(s.peers.GetAllPeers(currentSession.DeviceName)),
|
||||||
"Users": s.users.GetUsers(),
|
"Users": s.users.GetUsers(),
|
||||||
"Device": device,
|
"Device": device,
|
||||||
"DeviceNames": s.wg.Cfg.DeviceNames,
|
"DeviceNames": s.GetDeviceNames(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ func (s *Server) GetUserIndex(c *gin.Context) {
|
|||||||
"TotalPeers": len(peers),
|
"TotalPeers": len(peers),
|
||||||
"Users": []users.User{*s.users.GetUser(currentSession.Email)},
|
"Users": []users.User{*s.users.GetUser(currentSession.Email)},
|
||||||
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
||||||
"DeviceNames": s.wg.Cfg.DeviceNames,
|
"DeviceNames": s.GetDeviceNames(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ func (s *Server) GetAdminEditInterface(c *gin.Context) {
|
|||||||
"Static": s.getStaticData(),
|
"Static": s.getStaticData(),
|
||||||
"Device": currentSession.FormData.(wireguard.Device),
|
"Device": currentSession.FormData.(wireguard.Device),
|
||||||
"EditableKeys": s.config.Core.EditableKeys,
|
"EditableKeys": s.config.Core.EditableKeys,
|
||||||
"DeviceNames": s.wg.Cfg.DeviceNames,
|
"DeviceNames": s.GetDeviceNames(),
|
||||||
"Csrf": csrf.GetToken(c),
|
"Csrf": csrf.GetToken(c),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ func (s *Server) GetAdminEditPeer(c *gin.Context) {
|
|||||||
"Peer": currentSession.FormData.(wireguard.Peer),
|
"Peer": currentSession.FormData.(wireguard.Peer),
|
||||||
"EditableKeys": s.config.Core.EditableKeys,
|
"EditableKeys": s.config.Core.EditableKeys,
|
||||||
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
||||||
"DeviceNames": s.wg.Cfg.DeviceNames,
|
"DeviceNames": s.GetDeviceNames(),
|
||||||
"AdminEmail": s.config.Core.AdminUser,
|
"AdminEmail": s.config.Core.AdminUser,
|
||||||
"Csrf": csrf.GetToken(c),
|
"Csrf": csrf.GetToken(c),
|
||||||
})
|
})
|
||||||
@ -99,7 +99,7 @@ func (s *Server) GetAdminCreatePeer(c *gin.Context) {
|
|||||||
"Peer": currentSession.FormData.(wireguard.Peer),
|
"Peer": currentSession.FormData.(wireguard.Peer),
|
||||||
"EditableKeys": s.config.Core.EditableKeys,
|
"EditableKeys": s.config.Core.EditableKeys,
|
||||||
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
||||||
"DeviceNames": s.wg.Cfg.DeviceNames,
|
"DeviceNames": s.GetDeviceNames(),
|
||||||
"AdminEmail": s.config.Core.AdminUser,
|
"AdminEmail": s.config.Core.AdminUser,
|
||||||
"Csrf": csrf.GetToken(c),
|
"Csrf": csrf.GetToken(c),
|
||||||
})
|
})
|
||||||
@ -154,7 +154,7 @@ func (s *Server) GetAdminCreateLdapPeers(c *gin.Context) {
|
|||||||
"Users": s.users.GetFilteredAndSortedUsers("lastname", "asc", ""),
|
"Users": s.users.GetFilteredAndSortedUsers("lastname", "asc", ""),
|
||||||
"FormData": currentSession.FormData.(LdapCreateForm),
|
"FormData": currentSession.FormData.(LdapCreateForm),
|
||||||
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
||||||
"DeviceNames": s.wg.Cfg.DeviceNames,
|
"DeviceNames": s.GetDeviceNames(),
|
||||||
"Csrf": csrf.GetToken(c),
|
"Csrf": csrf.GetToken(c),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ func (s *Server) GetAdminUsersIndex(c *gin.Context) {
|
|||||||
"Users": dbUsers,
|
"Users": dbUsers,
|
||||||
"TotalUsers": len(s.users.GetUsers()),
|
"TotalUsers": len(s.users.GetUsers()),
|
||||||
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
"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(),
|
"Static": s.getStaticData(),
|
||||||
"User": currentSession.FormData.(users.User),
|
"User": currentSession.FormData.(users.User),
|
||||||
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
||||||
"DeviceNames": s.wg.Cfg.DeviceNames,
|
"DeviceNames": s.GetDeviceNames(),
|
||||||
"Epoch": time.Time{},
|
"Epoch": time.Time{},
|
||||||
"Csrf": csrf.GetToken(c),
|
"Csrf": csrf.GetToken(c),
|
||||||
})
|
})
|
||||||
@ -156,7 +156,7 @@ func (s *Server) GetAdminUsersCreate(c *gin.Context) {
|
|||||||
"Static": s.getStaticData(),
|
"Static": s.getStaticData(),
|
||||||
"User": currentSession.FormData.(users.User),
|
"User": currentSession.FormData.(users.User),
|
||||||
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
||||||
"DeviceNames": s.wg.Cfg.DeviceNames,
|
"DeviceNames": s.GetDeviceNames(),
|
||||||
"Epoch": time.Time{},
|
"Epoch": time.Time{},
|
||||||
"Csrf": csrf.GetToken(c),
|
"Csrf": csrf.GetToken(c),
|
||||||
})
|
})
|
||||||
|
@ -140,8 +140,13 @@ func (s *Server) UpdatePeer(peer wireguard.Peer, updateTime time.Time) error {
|
|||||||
// Update WireGuard device
|
// Update WireGuard device
|
||||||
var err error
|
var err error
|
||||||
switch {
|
switch {
|
||||||
case peer.DeactivatedAt == &updateTime:
|
case peer.DeactivatedAt != nil && *peer.DeactivatedAt == updateTime:
|
||||||
err = s.wg.RemovePeer(peer.DeviceName, peer.PublicKey)
|
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:
|
case peer.DeactivatedAt == nil && currentPeer.Peer != nil:
|
||||||
err = s.wg.UpdatePeer(peer.DeviceName, peer.GetConfig(&dev))
|
err = s.wg.UpdatePeer(peer.DeviceName, peer.GetConfig(&dev))
|
||||||
case peer.DeactivatedAt == nil && currentPeer.Peer == nil:
|
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.
|
// DeletePeer removes the peer from the physical WireGuard interface and the database.
|
||||||
func (s *Server) DeletePeer(peer wireguard.Peer) error {
|
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
|
// 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")
|
return errors.WithMessage(err, "failed to remove WireGuard peer")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,3 +323,14 @@ func (s *Server) CreateUserDefaultPeer(email, device string) error {
|
|||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
@ -19,7 +19,9 @@ MTU = {{.Peer.Mtu}}
|
|||||||
[Peer]
|
[Peer]
|
||||||
PublicKey = {{ .Peer.EndpointPublicKey }}
|
PublicKey = {{ .Peer.EndpointPublicKey }}
|
||||||
Endpoint = {{ .Peer.Endpoint }}
|
Endpoint = {{ .Peer.Endpoint }}
|
||||||
|
{{- if .Peer.AllowedIPsStr}}
|
||||||
AllowedIPs = {{ .Peer.AllowedIPsStr }}
|
AllowedIPs = {{ .Peer.AllowedIPsStr }}
|
||||||
|
{{- end}}
|
||||||
{{- if .Peer.PresharedKey}}
|
{{- if .Peer.PresharedKey}}
|
||||||
PresharedKey = {{ .Peer.PresharedKey }}
|
PresharedKey = {{ .Peer.PresharedKey }}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
Loading…
Reference in New Issue
Block a user