Skip to content

Commit e0968b3

Browse files
committed
support AllowIPs for peers in server config (h44z#24)
1 parent e1db939 commit e0968b3

File tree

6 files changed

+24
-3
lines changed

6 files changed

+24
-3
lines changed

assets/tpl/admin_edit_client.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ <h1>Edit client: <strong>{{.Peer.Identifier}}</strong></h1>
8282
<input type="text" name="allowedip" class="form-control" id="server_AllowedIP" value="{{.Peer.AllowedIPsStr}}">
8383
</div>
8484
</div>
85+
<div class="form-row">
86+
<div class="form-group col-md-12">
87+
<label for="server_AllowedIPSrv">Extra Allowed IPs (Server sided)</label>
88+
<input type="text" name="allowedipSrv" class="form-control" id="server_AllowedIPSrv" value="{{.Peer.AllowedIPsSrvStr}}">
89+
</div>
90+
</div>
8591
<div class="form-row">
8692
<div class="form-group col-md-12 global-config">
8793
<label for="server_DNS">Client DNS Servers</label>

internal/common/db.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ func init() {
2929
return nil
3030
},
3131
})
32+
migrations = append(migrations, Migration{
33+
version: "1.0.8",
34+
migrateFn: func(db *gorm.DB) error {
35+
logrus.Infof("upgraded database format to version 1.0.8")
36+
return nil
37+
},
38+
})
3239
}
3340

3441
type SupportedDatabase string

internal/server/handlers_peer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (s *Server) PostAdminEditPeer(c *gin.Context) {
6464
// Clean list input
6565
formPeer.IPsStr = common.ListToString(common.ParseStringList(formPeer.IPsStr))
6666
formPeer.AllowedIPsStr = common.ListToString(common.ParseStringList(formPeer.AllowedIPsStr))
67+
formPeer.AllowedIPsSrvStr = common.ListToString(common.ParseStringList(formPeer.AllowedIPsSrvStr))
6768

6869
disabled := c.PostForm("isdisabled") != ""
6970
now := time.Now()
@@ -121,6 +122,7 @@ func (s *Server) PostAdminCreatePeer(c *gin.Context) {
121122
// Clean list input
122123
formPeer.IPsStr = common.ListToString(common.ParseStringList(formPeer.IPsStr))
123124
formPeer.AllowedIPsStr = common.ListToString(common.ParseStringList(formPeer.AllowedIPsStr))
125+
formPeer.AllowedIPsSrvStr = common.ListToString(common.ParseStringList(formPeer.AllowedIPsSrvStr))
124126

125127
disabled := c.PostForm("isdisabled") != ""
126128
now := time.Now()

internal/server/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package server
22

33
var Version = "testbuild"
4-
var DatabaseVersion = "1.0.7"
4+
var DatabaseVersion = "1.0.8"

internal/wireguard/peermanager.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ type Peer struct {
8181
// Core WireGuard Settings
8282
PublicKey string `gorm:"primaryKey" form:"pubkey" binding:"required,base64"` // the public key of the peer itself
8383
PresharedKey string `form:"presharedkey" binding:"omitempty,base64"`
84-
AllowedIPsStr string `form:"allowedip" binding:"cidrlist"` // a comma separated list of IPs that are used in the client config file
84+
AllowedIPsStr string `form:"allowedip" binding:"cidrlist"` // a comma separated list of IPs that are used in the client config file
85+
AllowedIPsSrvStr string `form:"allowedipSrv" binding:"cidrlist"` // a comma separated list of IPs that are used in the server config file
8586
Endpoint string `form:"endpoint" binding:"omitempty,hostname_port"`
8687
PersistentKeepalive int `form:"keepalive" binding:"gte=0"`
8788

@@ -123,6 +124,10 @@ func (p Peer) GetAllowedIPs() []string {
123124
return common.ParseStringList(p.AllowedIPsStr)
124125
}
125126

127+
func (p Peer) GetAllowedIPsSrv() []string {
128+
return common.ParseStringList(p.AllowedIPsSrvStr)
129+
}
130+
126131
func (p Peer) GetConfig(dev *Device) wgtypes.PeerConfig {
127132
publicKey, _ := wgtypes.ParseKey(p.PublicKey)
128133

@@ -153,6 +158,7 @@ func (p Peer) GetConfig(dev *Device) wgtypes.PeerConfig {
153158
peerAllowedIPs = p.GetAllowedIPs()
154159
case DeviceTypeServer:
155160
peerAllowedIPs = p.GetIPAddresses()
161+
peerAllowedIPs = append(peerAllowedIPs, p.GetAllowedIPsSrv()...)
156162
}
157163
for _, ip := range peerAllowedIPs {
158164
_, ipNet, err := net.ParseCIDR(ip)

internal/wireguard/tpl/interface.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ PublicKey = {{ .PublicKey }}
6161
PresharedKey = {{ .PresharedKey }}
6262
{{- end}}
6363
{{- if eq $.Interface.Type "server"}}
64-
AllowedIPs = {{ .IPsStr }}
64+
AllowedIPs = {{ .IPsStr }}{{if ne .AllowedIPsSrvStr ""}}, {{ .AllowedIPsSrvStr }}{{end}}
6565
{{- end}}
6666
{{- if eq $.Interface.Type "client"}}
6767
{{- if .AllowedIPsStr}}

0 commit comments

Comments
 (0)