mirror of
https://github.com/h44z/wg-portal
synced 2025-02-26 05:49:14 +00:00
support AllowIPs for peers in server config (#24)
This commit is contained in:
parent
e1db939a18
commit
e0968b3239
@ -82,6 +82,12 @@
|
|||||||
<input type="text" name="allowedip" class="form-control" id="server_AllowedIP" value="{{.Peer.AllowedIPsStr}}">
|
<input type="text" name="allowedip" class="form-control" id="server_AllowedIP" value="{{.Peer.AllowedIPsStr}}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group col-md-12">
|
||||||
|
<label for="server_AllowedIPSrv">Extra Allowed IPs (Server sided)</label>
|
||||||
|
<input type="text" name="allowedipSrv" class="form-control" id="server_AllowedIPSrv" value="{{.Peer.AllowedIPsSrvStr}}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-group col-md-12 global-config">
|
<div class="form-group col-md-12 global-config">
|
||||||
<label for="server_DNS">Client DNS Servers</label>
|
<label for="server_DNS">Client DNS Servers</label>
|
||||||
|
@ -29,6 +29,13 @@ func init() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
migrations = append(migrations, Migration{
|
||||||
|
version: "1.0.8",
|
||||||
|
migrateFn: func(db *gorm.DB) error {
|
||||||
|
logrus.Infof("upgraded database format to version 1.0.8")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type SupportedDatabase string
|
type SupportedDatabase string
|
||||||
|
@ -64,6 +64,7 @@ func (s *Server) PostAdminEditPeer(c *gin.Context) {
|
|||||||
// Clean list input
|
// Clean list input
|
||||||
formPeer.IPsStr = common.ListToString(common.ParseStringList(formPeer.IPsStr))
|
formPeer.IPsStr = common.ListToString(common.ParseStringList(formPeer.IPsStr))
|
||||||
formPeer.AllowedIPsStr = common.ListToString(common.ParseStringList(formPeer.AllowedIPsStr))
|
formPeer.AllowedIPsStr = common.ListToString(common.ParseStringList(formPeer.AllowedIPsStr))
|
||||||
|
formPeer.AllowedIPsSrvStr = common.ListToString(common.ParseStringList(formPeer.AllowedIPsSrvStr))
|
||||||
|
|
||||||
disabled := c.PostForm("isdisabled") != ""
|
disabled := c.PostForm("isdisabled") != ""
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
@ -121,6 +122,7 @@ func (s *Server) PostAdminCreatePeer(c *gin.Context) {
|
|||||||
// Clean list input
|
// Clean list input
|
||||||
formPeer.IPsStr = common.ListToString(common.ParseStringList(formPeer.IPsStr))
|
formPeer.IPsStr = common.ListToString(common.ParseStringList(formPeer.IPsStr))
|
||||||
formPeer.AllowedIPsStr = common.ListToString(common.ParseStringList(formPeer.AllowedIPsStr))
|
formPeer.AllowedIPsStr = common.ListToString(common.ParseStringList(formPeer.AllowedIPsStr))
|
||||||
|
formPeer.AllowedIPsSrvStr = common.ListToString(common.ParseStringList(formPeer.AllowedIPsSrvStr))
|
||||||
|
|
||||||
disabled := c.PostForm("isdisabled") != ""
|
disabled := c.PostForm("isdisabled") != ""
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
var Version = "testbuild"
|
var Version = "testbuild"
|
||||||
var DatabaseVersion = "1.0.7"
|
var DatabaseVersion = "1.0.8"
|
||||||
|
@ -81,7 +81,8 @@ type Peer struct {
|
|||||||
// Core WireGuard Settings
|
// Core WireGuard Settings
|
||||||
PublicKey string `gorm:"primaryKey" form:"pubkey" binding:"required,base64"` // the public key of the peer itself
|
PublicKey string `gorm:"primaryKey" form:"pubkey" binding:"required,base64"` // the public key of the peer itself
|
||||||
PresharedKey string `form:"presharedkey" binding:"omitempty,base64"`
|
PresharedKey string `form:"presharedkey" binding:"omitempty,base64"`
|
||||||
AllowedIPsStr string `form:"allowedip" binding:"cidrlist"` // a comma separated list of IPs that are used in the client config file
|
AllowedIPsStr string `form:"allowedip" binding:"cidrlist"` // a comma separated list of IPs that are used in the client config file
|
||||||
|
AllowedIPsSrvStr string `form:"allowedipSrv" binding:"cidrlist"` // a comma separated list of IPs that are used in the server config file
|
||||||
Endpoint string `form:"endpoint" binding:"omitempty,hostname_port"`
|
Endpoint string `form:"endpoint" binding:"omitempty,hostname_port"`
|
||||||
PersistentKeepalive int `form:"keepalive" binding:"gte=0"`
|
PersistentKeepalive int `form:"keepalive" binding:"gte=0"`
|
||||||
|
|
||||||
@ -123,6 +124,10 @@ func (p Peer) GetAllowedIPs() []string {
|
|||||||
return common.ParseStringList(p.AllowedIPsStr)
|
return common.ParseStringList(p.AllowedIPsStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p Peer) GetAllowedIPsSrv() []string {
|
||||||
|
return common.ParseStringList(p.AllowedIPsSrvStr)
|
||||||
|
}
|
||||||
|
|
||||||
func (p Peer) GetConfig(dev *Device) wgtypes.PeerConfig {
|
func (p Peer) GetConfig(dev *Device) wgtypes.PeerConfig {
|
||||||
publicKey, _ := wgtypes.ParseKey(p.PublicKey)
|
publicKey, _ := wgtypes.ParseKey(p.PublicKey)
|
||||||
|
|
||||||
@ -153,6 +158,7 @@ func (p Peer) GetConfig(dev *Device) wgtypes.PeerConfig {
|
|||||||
peerAllowedIPs = p.GetAllowedIPs()
|
peerAllowedIPs = p.GetAllowedIPs()
|
||||||
case DeviceTypeServer:
|
case DeviceTypeServer:
|
||||||
peerAllowedIPs = p.GetIPAddresses()
|
peerAllowedIPs = p.GetIPAddresses()
|
||||||
|
peerAllowedIPs = append(peerAllowedIPs, p.GetAllowedIPsSrv()...)
|
||||||
}
|
}
|
||||||
for _, ip := range peerAllowedIPs {
|
for _, ip := range peerAllowedIPs {
|
||||||
_, ipNet, err := net.ParseCIDR(ip)
|
_, ipNet, err := net.ParseCIDR(ip)
|
||||||
|
@ -61,7 +61,7 @@ PublicKey = {{ .PublicKey }}
|
|||||||
PresharedKey = {{ .PresharedKey }}
|
PresharedKey = {{ .PresharedKey }}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{- if eq $.Interface.Type "server"}}
|
{{- if eq $.Interface.Type "server"}}
|
||||||
AllowedIPs = {{ .IPsStr }}
|
AllowedIPs = {{ .IPsStr }}{{if ne .AllowedIPsSrvStr ""}}, {{ .AllowedIPsSrvStr }}{{end}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{- if eq $.Interface.Type "client"}}
|
{{- if eq $.Interface.Type "client"}}
|
||||||
{{- if .AllowedIPsStr}}
|
{{- if .AllowedIPsStr}}
|
||||||
|
Loading…
Reference in New Issue
Block a user