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": {
|
||||
"label": "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": {
|
||||
"label": "IP Networks",
|
||||
|
@ -355,7 +355,7 @@
|
||||
"endpoint": {
|
||||
"label": "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": {
|
||||
"label": "IP Networks",
|
||||
|
@ -456,6 +456,10 @@ func (m Manager) saveInterface(ctx context.Context, iface *domain.Interface) (
|
||||
*domain.Interface,
|
||||
error,
|
||||
) {
|
||||
if err := iface.Validate(); err != nil {
|
||||
return nil, fmt.Errorf("interface validation failed: %w", err)
|
||||
}
|
||||
|
||||
stateChanged := m.hasInterfaceStateChanged(ctx, iface)
|
||||
|
||||
if err := m.handleInterfacePreSaveHooks(stateChanged, iface); err != nil {
|
||||
|
@ -3,6 +3,7 @@ package domain
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"net"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -71,8 +72,24 @@ type Interface struct {
|
||||
PeerDefPostDown string // default action that is executed after the device is down
|
||||
}
|
||||
|
||||
func (i *Interface) IsValid() bool {
|
||||
return true // TODO: implement check
|
||||
// Validate performs checks to ensure that the interface is valid.
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user