mirror of
https://github.com/h44z/wg-portal
synced 2025-02-26 05:49:14 +00:00
automatically append listening port to endpoint address (#352)
This commit is contained in:
parent
d35889de73
commit
1b8cdc3417
@ -354,7 +354,7 @@
|
|||||||
"endpoint": {
|
"endpoint": {
|
||||||
"label": "Endpoint Address",
|
"label": "Endpoint Address",
|
||||||
"placeholder": "Endpoint Address",
|
"placeholder": "Endpoint Address",
|
||||||
"description": "The endpoint address that peers will connect to."
|
"description": "The endpoint address that peers will connect to. (e.g. wg.example.com or wg.example.com:51820)"
|
||||||
},
|
},
|
||||||
"networks": {
|
"networks": {
|
||||||
"label": "IP Networks",
|
"label": "IP Networks",
|
||||||
|
@ -355,7 +355,7 @@
|
|||||||
"endpoint": {
|
"endpoint": {
|
||||||
"label": "Endpoint Address",
|
"label": "Endpoint Address",
|
||||||
"placeholder": "Endpoint Address",
|
"placeholder": "Endpoint Address",
|
||||||
"description": "The endpoint address that peers will connect to."
|
"description": "The endpoint address that peers will connect to. (e.g. wg.example.com or wg.example.com:51820)"
|
||||||
},
|
},
|
||||||
"networks": {
|
"networks": {
|
||||||
"label": "IP Networks",
|
"label": "IP Networks",
|
||||||
|
@ -456,6 +456,10 @@ func (m Manager) saveInterface(ctx context.Context, iface *domain.Interface) (
|
|||||||
*domain.Interface,
|
*domain.Interface,
|
||||||
error,
|
error,
|
||||||
) {
|
) {
|
||||||
|
if err := iface.Validate(); err != nil {
|
||||||
|
return nil, fmt.Errorf("interface validation failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
stateChanged := m.hasInterfaceStateChanged(ctx, iface)
|
stateChanged := m.hasInterfaceStateChanged(ctx, iface)
|
||||||
|
|
||||||
if err := m.handleInterfacePreSaveHooks(stateChanged, iface); err != nil {
|
if err := m.handleInterfacePreSaveHooks(stateChanged, iface); err != nil {
|
||||||
|
@ -3,6 +3,7 @@ package domain
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -71,8 +72,24 @@ type Interface struct {
|
|||||||
PeerDefPostDown string // default action that is executed after the device is down
|
PeerDefPostDown string // default action that is executed after the device is down
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Interface) IsValid() bool {
|
// Validate performs checks to ensure that the interface is valid.
|
||||||
return true // TODO: implement check
|
func (i *Interface) Validate() error {
|
||||||
|
// validate peer default endpoint, add port if needed
|
||||||
|
if i.PeerDefEndpoint != "" {
|
||||||
|
host, port, err := net.SplitHostPort(i.PeerDefEndpoint)
|
||||||
|
switch {
|
||||||
|
case err != nil && !strings.Contains(err.Error(), "missing port in address"):
|
||||||
|
return fmt.Errorf("invalid default endpoint: %w", err)
|
||||||
|
case err != nil && strings.Contains(err.Error(), "missing port in address"):
|
||||||
|
// In this case, the entire string is the host, and there's no port.
|
||||||
|
host = i.PeerDefEndpoint
|
||||||
|
port = strconv.Itoa(i.ListenPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
i.PeerDefEndpoint = net.JoinHostPort(host, port)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Interface) IsDisabled() bool {
|
func (i *Interface) IsDisabled() bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user