feature_v0.5_uiint

This commit is contained in:
afeiszli
2021-05-31 18:05:48 -04:00
parent b3655d2fdf
commit cd49cff809
2 changed files with 43 additions and 21 deletions

View File

@@ -565,17 +565,28 @@ func CreateEgressGateway(gateway models.EgressGatewayRequest) (models.Node, erro
var nodechange models.Node var nodechange models.Node
nodechange.IsEgressGateway = true nodechange.IsEgressGateway = true
nodechange.EgressGatewayRange = gateway.RangeString nodechange.EgressGatewayRange = gateway.RangeString
if gateway.PostUp == "" {
nodechange.PostUp = "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + gateway.Interface + " -j MASQUERADE" nodechange.PostUp = "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + gateway.Interface + " -j MASQUERADE"
} else { nodechange.PostDown = "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + gateway.Interface + " -j MASQUERADE"
if gateway.PostUp != "" {
nodechange.PostUp = gateway.PostUp nodechange.PostUp = gateway.PostUp
} }
if gateway.PostDown == "" { if gateway.PostDown != "" {
nodechange.PostDown = "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + gateway.Interface + " -j MASQUERADE"
} else {
nodechange.PostDown = gateway.PostDown nodechange.PostDown = gateway.PostDown
} }
if node.PostUp != "" {
if !strings.Contains(node.PostUp, nodechange.PostUp) {
nodechange.PostUp = node.PostUp + "; " + nodechange.PostUp
} else {
nodechange.PostUp = node.PostUp
}
}
if node.PostDown != "" {
if !strings.Contains(node.PostDown, nodechange.PostDown) {
nodechange.PostDown = node.PostDown + "; " + nodechange.PostDown
} else {
nodechange.PostDown = node.PostDown
}
}
collection := mongoconn.Client.Database("netmaker").Collection("nodes") collection := mongoconn.Client.Database("netmaker").Collection("nodes")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
// Create filter // Create filter
@@ -705,15 +716,25 @@ func CreateIngressGateway(netid string, macaddress string) (models.Node, error)
log.Println("Could not find network.") log.Println("Could not find network.")
return models.Node{}, err return models.Node{}, err
} }
var nodechange models.Node
if node.IsEgressGateway { nodechange.IngressGatewayRange = network.AddressRange
errors.New("Node cannot be both Ingress and Egress Gateway in same network.") nodechange.PostUp = "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + node.Interface + " -j MASQUERADE"
return models.Node{}, err nodechange.PostDown = "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + node.Interface + " -j MASQUERADE"
if node.PostUp != "" {
if !strings.Contains(node.PostUp, nodechange.PostUp) {
nodechange.PostUp = node.PostUp + "; " + nodechange.PostUp
} else {
nodechange.PostUp = node.PostUp
}
}
if node.PostDown != "" {
if !strings.Contains(node.PostDown, nodechange.PostDown) {
nodechange.PostDown = node.PostDown + "; " + nodechange.PostDown
} else {
nodechange.PostDown = node.PostDown
}
} }
node.IngressGatewayRange = network.AddressRange
node.PostUp = "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + node.Interface + " -j MASQUERADE"
node.PostDown = "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + node.Interface + " -j MASQUERADE"
collection := mongoconn.Client.Database("netmaker").Collection("nodes") collection := mongoconn.Client.Database("netmaker").Collection("nodes")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
// Create filter // Create filter
@@ -722,10 +743,10 @@ func CreateIngressGateway(netid string, macaddress string) (models.Node, error)
// prepare update model. // prepare update model.
update := bson.D{ update := bson.D{
{"$set", bson.D{ {"$set", bson.D{
{"postup", node.PostUp}, {"postup", nodechange.PostUp},
{"postdown", node.PostDown}, {"postdown", nodechange.PostDown},
{"isingressgateway", true}, {"isingressgateway", true},
{"ingressgatewayrange", node.IngressGatewayRange}, {"ingressgatewayrange", nodechange.IngressGatewayRange},
{"lastmodified", node.LastModified}, {"lastmodified", node.LastModified},
}}, }},
} }

View File

@@ -3,7 +3,8 @@ set -e
[ -z "$KEY" ] && KEY=nokey; [ -z "$KEY" ] && KEY=nokey;
wget -O netclient https://github.com/gravitl/netmaker/releases/download/latest/netclient wget -O netclient https://github.com/gravitl/netmaker/releases/download/v0.5/netclient
chmod +x netclient chmod +x netclient
sudo ./netclient -c install -t $KEY sudo ./netclient register -t $KEY
sudo ./netclient join -t $KEY
rm -f netclient rm -f netclient