changed stuff to make it work

This commit is contained in:
worker-9 2021-08-10 12:15:30 -04:00
parent 19d0c3c5e9
commit 9b37940c1a
2 changed files with 30 additions and 9 deletions

View file

@ -57,7 +57,7 @@ type Node struct {
IsIngressGateway string `json:"isingressgateway" bson:"isingressgateway" yaml:"isingressgateway"`
EgressGatewayRanges []string `json:"egressgatewayranges" bson:"egressgatewayranges" yaml:"egressgatewayranges"`
IngressGatewayRange string `json:"ingressgatewayrange" bson:"ingressgatewayrange" yaml:"ingressgatewayrange"`
IsStatic string `json:"isstatic" bson:"isstatic" yaml:"isstatic" validate:"checkyesorno"`
IsStatic string `json:"isstatic" bson:"isstatic" yaml:"isstatic" validate:"checkyesorno"`
UDPHolePunch string `json:"udpholepunch" bson:"udpholepunch" yaml:"udpholepunch" validate:"checkyesorno"`
PullChanges string `json:"pullchanges" bson:"pullchanges" yaml:"pullchanges" validate:"checkyesorno"`
DNSOn string `json:"dnson" bson:"dnson" yaml:"dnson" validate:"checkyesorno"`
@ -70,6 +70,24 @@ type Node struct {
IPForwarding string `json:"ipforwarding" bson:"ipforwarding" yaml:"ipforwarding" validate:"checkyesorno"`
}
func (node *Node) SetDefaulIsPending() {
if node.IsPending == "" {
node.IsPending = "no"
}
}
func (node *Node) SetDefaultEgressGateway() {
if node.IsEgressGateway == "" {
node.IsEgressGateway = "no"
}
}
func (node *Node) SetDefaultIngressGateway() {
if node.IsIngressGateway == "" {
node.IsIngressGateway = "no"
}
}
func (node *Node) SetDefaultAction() {
if node.Action == "" {
node.Action = NODE_NOOP
@ -235,6 +253,9 @@ func (node *Node) SetDefaults() {
node.SetID()
node.SetIsServerDefault()
node.SetIsStaticDefault()
node.SetDefaultEgressGateway()
node.SetDefaultIngressGateway()
node.SetDefaulIsPending()
node.KeyUpdateTimeStamp = time.Now().Unix()
}
@ -242,10 +263,10 @@ func (newNode *Node) Fill(currentNode *Node) {
if newNode.ID == "" {
newNode.ID = currentNode.ID
}
if newNode.Address == "" && newNode.IsStatic != "yes"{
if newNode.Address == "" && newNode.IsStatic != "yes" {
newNode.Address = currentNode.Address
}
if newNode.Address6 == "" && newNode.IsStatic != "yes"{
if newNode.Address6 == "" && newNode.IsStatic != "yes" {
newNode.Address6 = currentNode.Address6
}
if newNode.LocalAddress == "" {
@ -254,7 +275,7 @@ func (newNode *Node) Fill(currentNode *Node) {
if newNode.Name == "" {
newNode.Name = currentNode.Name
}
if newNode.ListenPort == 0 && newNode.IsStatic != "yes"{
if newNode.ListenPort == 0 && newNode.IsStatic != "yes" {
newNode.ListenPort = currentNode.ListenPort
}
if newNode.PublicKey == "" && newNode.IsStatic != "yes" {
@ -262,7 +283,7 @@ func (newNode *Node) Fill(currentNode *Node) {
} else {
newNode.KeyUpdateTimeStamp = time.Now().Unix()
}
if newNode.Endpoint == "" && newNode.IsStatic != "yes"{
if newNode.Endpoint == "" && newNode.IsStatic != "yes" {
newNode.Endpoint = currentNode.Endpoint
}
if newNode.PostUp == "" {

View file

@ -80,10 +80,10 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
nodeport = int(node.ListenPort)
conf := wgtypes.Config{}
if nodecfg.UDPHolePunch == "yes" &&
nodecfg.IsServer == "no" &&
nodecfg.IsIngressGateway == "no" &&
nodecfg.IsStatic != "yes" {
if nodecfg.UDPHolePunch == "yes" &&
nodecfg.IsServer == "no" &&
nodecfg.IsIngressGateway != "yes" &&
nodecfg.IsStatic != "yes" {
conf = wgtypes.Config{
PrivateKey: &key,
ReplacePeers: true,