diff --git a/controllers/dns.go b/controllers/dns.go index cc1d70abf..524d2b4c6 100644 --- a/controllers/dns.go +++ b/controllers/dns.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net/http" + "strings" "github.com/gorilla/mux" "github.com/gravitl/netmaker/database" @@ -49,7 +50,7 @@ func getNodeDNS(w http.ResponseWriter, r *http.Request) { var dns []models.DNSEntry var params = mux.Vars(r) network := params["network"] - dns, err := logic.GetNodeDNS(network) + dns, err := logic.GetNodeDNS(models.NetworkID(network)) if err != nil { logger.Log(0, r.Header.Get("user"), fmt.Sprintf("failed to get node DNS entries for network [%s]: %v", network, err)) @@ -125,7 +126,7 @@ func getDNS(w http.ResponseWriter, r *http.Request) { var dns []models.DNSEntry var params = mux.Vars(r) network := params["network"] - dns, err := logic.GetDNS(network) + dns, err := logic.GetDNS(models.NetworkID(network)) if err != nil { logger.Log(0, r.Header.Get("user"), fmt.Sprintf("failed to get all DNS entries for network [%s]: %v", network, err.Error())) @@ -162,7 +163,10 @@ func createDNS(w http.ResponseWriter, r *http.Request) { logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest")) return } - + // check if default domain is appended if not append + if !strings.HasSuffix(entry.Name, servercfg.GetDefaultDomain()) { + entry.Name += "." + servercfg.GetDefaultDomain() + } entry, err = logic.CreateDNS(entry) if err != nil { logger.Log(0, r.Header.Get("user"), @@ -298,7 +302,7 @@ func syncDNS(w http.ResponseWriter, r *http.Request) { } var params = mux.Vars(r) netID := params["network"] - k, err := logic.GetDNS(netID) + k, err := logic.GetDNS(models.NetworkID(netID)) if err == nil && len(k) > 0 { err = mq.PushSyncDNS(k) } diff --git a/controllers/dns_test.go b/controllers/dns_test.go index 4682f5258..d6fc5cf1c 100644 --- a/controllers/dns_test.go +++ b/controllers/dns_test.go @@ -1,6 +1,7 @@ package controller import ( + "fmt" "net" "os" "testing" @@ -440,6 +441,7 @@ func createHost() { func deleteAllDNS(t *testing.T) { dns, err := logic.GetAllDNS() assert.Nil(t, err) + fmt.Println("=====> DNS RECORDS ", dns) for _, record := range dns { err := logic.DeleteDNS(record.Name, record.Network) assert.Nil(t, err) diff --git a/controllers/network.go b/controllers/network.go index 86a6e3403..c65ea2648 100644 --- a/controllers/network.go +++ b/controllers/network.go @@ -488,14 +488,6 @@ func createNetwork(w http.ResponseWriter, r *http.Request) { return } - if len(network.NetID) > 32 { - err := errors.New("network name shouldn't exceed 32 characters") - logger.Log(0, r.Header.Get("user"), "failed to create network: ", - err.Error()) - logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest")) - return - } - if network.AddressRange == "" && network.AddressRange6 == "" { err := errors.New("IPv4 or IPv6 CIDR required") logger.Log(0, r.Header.Get("user"), "failed to create network: ", @@ -614,15 +606,19 @@ func updateNetwork(w http.ResponseWriter, r *http.Request) { logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest")) return } - // partial update - netOld2 := netOld1 - _, _, _, err = logic.UpdateNetwork(&netOld1, &netOld2) + + _, _, _, err = logic.UpdateNetwork(&netOld1, &payload) if err != nil { slog.Info("failed to update network", "user", r.Header.Get("user"), "err", err) logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest")) return } - + if payload.Name != netOld1.Name { + if servercfg.GetManageDNS() { + mq.SendDNSSyncByNetwork(payload.NetID) + } + logic.CreateDefaultNetworkRolesAndGroups(models.NetworkID(payload.NetID)) + } slog.Info("updated network", "network", payload.NetID, "user", r.Header.Get("user")) w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(payload) diff --git a/controllers/network_test.go b/controllers/network_test.go index 4320b6e39..6d1a11360 100644 --- a/controllers/network_test.go +++ b/controllers/network_test.go @@ -46,10 +46,8 @@ func TestCreateNetwork(t *testing.T) { deleteAllNetworks() var network models.Network - network.NetID = "skynet1" + network.Name = "skynet1" network.AddressRange = "10.10.0.1/24" - // if tests break - check here (removed displayname) - //network.DisplayName = "mynetwork" _, err := logic.CreateNetwork(network) assert.Nil(t, err) @@ -115,7 +113,7 @@ func TestValidateNetwork(t *testing.T) { { testname: "InvalidAddress", network: models.Network{ - NetID: "skynet", + Name: "skynet", AddressRange: "10.0.0.256", }, errMessage: "Field validation for 'AddressRange' failed on the 'cidrv4' tag", @@ -123,29 +121,15 @@ func TestValidateNetwork(t *testing.T) { { testname: "InvalidAddress6", network: models.Network{ - NetID: "skynet1", + Name: "skynet1", AddressRange6: "2607::ffff/130", }, errMessage: "Field validation for 'AddressRange6' failed on the 'cidrv6' tag", }, - { - testname: "InvalidNetID", - network: models.Network{ - NetID: "with spaces", - }, - errMessage: "Field validation for 'NetID' failed on the 'netid_valid' tag", - }, - { - testname: "NetIDTooLong", - network: models.Network{ - NetID: "LongNetIDNameForMaxCharactersTest", - }, - errMessage: "Field validation for 'NetID' failed on the 'max' tag", - }, { testname: "ListenPortTooLow", network: models.Network{ - NetID: "skynet", + Name: "skynet", DefaultListenPort: 1023, }, errMessage: "Field validation for 'DefaultListenPort' failed on the 'min' tag", @@ -153,7 +137,7 @@ func TestValidateNetwork(t *testing.T) { { testname: "ListenPortTooHigh", network: models.Network{ - NetID: "skynet", + Name: "skynet", DefaultListenPort: 65536, }, errMessage: "Field validation for 'DefaultListenPort' failed on the 'max' tag", @@ -161,7 +145,7 @@ func TestValidateNetwork(t *testing.T) { { testname: "KeepAliveTooBig", network: models.Network{ - NetID: "skynet", + Name: "skynet", DefaultKeepalive: 1010, }, errMessage: "Field validation for 'DefaultKeepalive' failed on the 'max' tag", @@ -207,9 +191,9 @@ func deleteAllNetworks() { func createNet() { var network models.Network - network.NetID = "skynet" + network.Name = "skynet" network.AddressRange = "10.0.0.1/24" - _, err := logic.GetNetwork("skynet") + _, err := logic.GetNetworkByName("skynet") if err != nil { logic.CreateNetwork(network) } diff --git a/controllers/node.go b/controllers/node.go index 904f6375b..11d439e28 100644 --- a/controllers/node.go +++ b/controllers/node.go @@ -430,6 +430,8 @@ func getNode(w http.ResponseWriter, r *http.Request) { logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal")) return } + net, _ := logic.GetNetwork(node.Network) + node.NetworkName = net.Name server := servercfg.GetServerInfo() response := models.NodeGet{ Node: node, diff --git a/logic/dns.go b/logic/dns.go index dd3450a21..05c33904e 100644 --- a/logic/dns.go +++ b/logic/dns.go @@ -2,6 +2,7 @@ package logic import ( "encoding/json" + "errors" "fmt" "os" "regexp" @@ -11,6 +12,7 @@ import ( "github.com/gravitl/netmaker/database" "github.com/gravitl/netmaker/logger" "github.com/gravitl/netmaker/models" + "github.com/gravitl/netmaker/servercfg" "github.com/txn2/txeh" ) @@ -28,7 +30,7 @@ func SetDNS() error { for _, net := range networks { corefilestring = corefilestring + net.NetID + " " - dns, err := GetDNS(net.NetID) + dns, err := GetDNS(models.NetworkID(net.NetID)) if err != nil && !database.IsEmptyRecord(err) { return err } @@ -58,13 +60,13 @@ func SetDNS() error { } // GetDNS - gets the DNS of a current network -func GetDNS(network string) ([]models.DNSEntry, error) { +func GetDNS(networkID models.NetworkID) ([]models.DNSEntry, error) { - dns, err := GetNodeDNS(network) + dns, err := GetNodeDNS(networkID) if err != nil && !database.IsEmptyRecord(err) { return dns, err } - customdns, err := GetCustomDNS(network) + customdns, err := GetCustomDNS(networkID.String()) if err != nil && !database.IsEmptyRecord(err) { return dns, err } @@ -96,17 +98,20 @@ func GetExtclientDNS() []models.DNSEntry { } // GetNodeDNS - gets the DNS of a network node -func GetNodeDNS(network string) ([]models.DNSEntry, error) { +func GetNodeDNS(networkID models.NetworkID) ([]models.DNSEntry, error) { var dns []models.DNSEntry - - nodes, err := GetNetworkNodes(network) + net, err := GetNetwork(networkID.String()) + if err != nil { + return []models.DNSEntry{}, err + } + nodes, err := GetNetworkNodes(networkID.String()) if err != nil { return dns, err } - + defaultDomain := servercfg.GetDefaultDomain() for _, node := range nodes { - if node.Network != network { + if node.Network != networkID.String() { continue } host, err := GetHost(node.HostID.String()) @@ -114,8 +119,8 @@ func GetNodeDNS(network string) ([]models.DNSEntry, error) { continue } var entry = models.DNSEntry{} - entry.Name = fmt.Sprintf("%s.%s", host.Name, network) - entry.Network = network + entry.Name = fmt.Sprintf("%s.%s.%s", host.Name, net.Name, defaultDomain) + entry.Network = net.NetID if node.Address.IP != nil { entry.Address = node.Address.IP.String() } @@ -188,7 +193,7 @@ func GetAllDNS() ([]models.DNSEntry, error) { return []models.DNSEntry{}, err } for _, net := range networks { - netdns, err := GetDNS(net.NetID) + netdns, err := GetDNS(models.NetworkID(net.NetID)) if err != nil { return []models.DNSEntry{}, nil } @@ -202,7 +207,7 @@ func GetDNSEntryNum(domain string, network string) (int, error) { num := 0 - entries, err := GetDNS(network) + entries, err := GetDNS(models.NetworkID(network)) if err != nil { return 0, err } @@ -224,9 +229,17 @@ func SortDNSEntrys(unsortedDNSEntrys []models.DNSEntry) { }) } +// IsNetworkNameValid - checks if a netid of a network uses valid characters +func IsDNSEntryValid(d string) bool { + re := regexp.MustCompile(`^[A-Za-z0-9-.]+$`) + return re.MatchString(d) +} + // ValidateDNSCreate - checks if an entry is valid func ValidateDNSCreate(entry models.DNSEntry) error { - + if !IsDNSEntryValid(entry.Name) { + return errors.New("invalid input. Only uppercase letters (A-Z), lowercase letters (a-z), numbers (0-9), minus sign (-) and dots (.) are allowed") + } v := validator.New() _ = v.RegisterValidation("whitespace", func(f1 validator.FieldLevel) bool { diff --git a/logic/networks.go b/logic/networks.go index 1617889d5..17c6cd355 100644 --- a/logic/networks.go +++ b/logic/networks.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net" + "regexp" "sort" "strings" "sync" @@ -23,6 +24,7 @@ import ( ) var ( + networkMutex = &sync.RWMutex{} networkCacheMutex = &sync.RWMutex{} networkCacheMap = make(map[string]models.Network) allocatedIpMap = make(map[string]map[string]net.IP) @@ -205,7 +207,9 @@ func DeleteNetwork(network string) error { // CreateNetwork - creates a network in database func CreateNetwork(network models.Network) (models.Network, error) { - + networkMutex.Lock() + defer networkMutex.Unlock() + network.NetID = fmt.Sprintf("%d", time.Now().Unix()) if network.AddressRange != "" { normalizedRange, err := NormalizeCIDR(network.AddressRange) if err != nil { @@ -227,7 +231,7 @@ func CreateNetwork(network models.Network) (models.Network, error) { network.SetDefaults() network.SetNodesLastModified() network.SetNetworkLastModified() - + network.Name = strings.ReplaceAll(network.Name, " ", "-") err := ValidateNetwork(&network, false) if err != nil { //logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest")) @@ -250,7 +254,7 @@ func CreateNetwork(network models.Network) (models.Network, error) { 0, time.Time{}, []string{network.NetID}, - []string{network.NetID}, + []string{network.Name}, []models.TagID{}, true, uuid.Nil, @@ -470,7 +474,7 @@ func IsNetworkNameUnique(network *models.Network) (bool, error) { for i := 0; i < len(dbs); i++ { - if network.NetID == dbs[i].NetID { + if network.Name == dbs[i].Name { isunique = false } } @@ -480,6 +484,7 @@ func IsNetworkNameUnique(network *models.Network) (bool, error) { // UpdateNetwork - updates a network with another network's fields func UpdateNetwork(currentNetwork *models.Network, newNetwork *models.Network) (bool, bool, bool, error) { + newNetwork.Name = strings.ReplaceAll(newNetwork.Name, " ", "-") if err := ValidateNetwork(newNetwork, true); err != nil { return false, false, false, err } @@ -487,11 +492,12 @@ func UpdateNetwork(currentNetwork *models.Network, newNetwork *models.Network) ( hasrangeupdate4 := newNetwork.AddressRange != currentNetwork.AddressRange hasrangeupdate6 := newNetwork.AddressRange6 != currentNetwork.AddressRange6 hasholepunchupdate := newNetwork.DefaultUDPHolePunch != currentNetwork.DefaultUDPHolePunch + newNetwork.SetNetworkLastModified() data, err := json.Marshal(newNetwork) if err != nil { return false, false, false, err } - newNetwork.SetNetworkLastModified() + err = database.Insert(newNetwork.NetID, string(data), database.NETWORKS_TABLE_NAME) if err == nil { if servercfg.CacheEnabled() { @@ -504,16 +510,50 @@ func UpdateNetwork(currentNetwork *models.Network, newNetwork *models.Network) ( return false, false, false, errors.New("failed to update network " + newNetwork.NetID + ", cannot change netid.") } +func UpsertNetwork(net *models.Network) error { + net.SetNetworkLastModified() + data, err := json.Marshal(net) + if err != nil { + return err + } + + err = database.Insert(net.NetID, string(data), database.NETWORKS_TABLE_NAME) + if err == nil { + if servercfg.CacheEnabled() { + storeNetworkInCache(net.NetID, *net) + } + } + return nil +} + +func GetNetworkByName(name string) (network models.Network, err error) { + networksData, err := database.FetchRecords(database.NETWORKS_TABLE_NAME) + if err != nil { + return network, err + } + for _, networkData := range networksData { + + if err = json.Unmarshal([]byte(networkData), &network); err != nil { + return models.Network{}, err + } + if network.Name == name { + return network, nil + } + + } + return network, errors.New("network not found") +} + // GetNetwork - gets a network from database -func GetNetwork(networkname string) (models.Network, error) { +func GetNetwork(networkID string) (models.Network, error) { var network models.Network if servercfg.CacheEnabled() { - if network, ok := getNetworkFromCache(networkname); ok { + if network, ok := getNetworkFromCache(networkID); ok { return network, nil } } - networkData, err := database.FetchRecord(database.NETWORKS_TABLE_NAME, networkname) + networkData, err := database.FetchRecord(database.NETWORKS_TABLE_NAME, networkID) if err != nil { return network, err } @@ -523,31 +563,22 @@ func GetNetwork(networkname string) (models.Network, error) { return network, nil } -// NetIDInNetworkCharSet - checks if a netid of a network uses valid characters -func NetIDInNetworkCharSet(network *models.Network) bool { - - charset := "abcdefghijklmnopqrstuvwxyz1234567890-_" - - for _, char := range network.NetID { - if !strings.Contains(charset, string(char)) { - return false - } - } - return true +// IsNetworkNameValid - checks if a netid of a network uses valid characters +func IsNetworkNameValid(network *models.Network) bool { + re := regexp.MustCompile(`^[A-Za-z0-9-]+$`) + return re.MatchString(network.Name) } // Validate - validates fields of an network struct func ValidateNetwork(network *models.Network, isUpdate bool) error { v := validator.New() - _ = v.RegisterValidation("netid_valid", func(fl validator.FieldLevel) bool { - inCharSet := NetIDInNetworkCharSet(network) - if isUpdate { - return inCharSet - } - isFieldUnique, _ := IsNetworkNameUnique(network) - return isFieldUnique && inCharSet - }) - // + isFieldUnique, _ := IsNetworkNameUnique(network) + if !isFieldUnique { + return errors.New("duplicate network name") + } + if !IsNetworkNameValid(network) { + return errors.New("invalid input. Only uppercase letters (A-Z), lowercase letters (a-z), numbers (0-9), and the minus sign (-) are allowed") + } _ = v.RegisterValidation("checkyesorno", func(fl validator.FieldLevel) bool { return validation.CheckYesOrNo(fl) }) @@ -561,13 +592,6 @@ func ValidateNetwork(network *models.Network, isUpdate bool) error { return err } -// ParseNetwork - parses a network into a model -func ParseNetwork(value string) (models.Network, error) { - var network models.Network - err := json.Unmarshal([]byte(value), &network) - return network, err -} - // SaveNetwork - save network struct to database func SaveNetwork(network *models.Network) error { data, err := json.Marshal(network) diff --git a/logic/tags.go b/logic/tags.go index 0c2aa095e..8ab4af3e1 100644 --- a/logic/tags.go +++ b/logic/tags.go @@ -85,9 +85,14 @@ func ListTagsWithNodes(netID models.NetworkID) ([]models.TagListResp, error) { if err != nil { return []models.TagListResp{}, err } + network, err := GetNetwork(netID.String()) + if err != nil { + return []models.TagListResp{}, err + } tagsNodeMap := GetTagMapWithNodesByNetwork(netID, true) resp := []models.TagListResp{} for _, tagI := range tags { + tagI.NetworkName = network.Name tagRespI := models.TagListResp{ Tag: tagI, UsedByCnt: len(tagsNodeMap[tagI.ID]), diff --git a/migrate/migrate.go b/migrate/migrate.go index 824deecae..6005621e9 100644 --- a/migrate/migrate.go +++ b/migrate/migrate.go @@ -20,6 +20,7 @@ import ( // Run - runs all migrations func Run() { + updateNetworks() updateEnrollmentKeys() assignSuperAdmin() createDefaultTagsAndPolicies() @@ -138,14 +139,14 @@ func updateEnrollmentKeys() { } networks, _ := logic.GetNetworks() for _, network := range networks { - if _, ok := existingTags[network.NetID]; ok { + if _, ok := existingTags[network.Name]; ok { continue } _, _ = logic.CreateEnrollmentKey( 0, time.Time{}, []string{network.NetID}, - []string{network.NetID}, + []string{network.Name}, []models.TagID{}, true, uuid.Nil, @@ -155,6 +156,20 @@ func updateEnrollmentKeys() { } } +func updateNetworks() { + nets, err := logic.GetNetworks() + if err != nil { + return + } + for _, netI := range nets { + netI := netI + if netI.Name == "" { + netI.Name = netI.NetID + logic.UpsertNetwork(&netI) + } + } +} + func removeOldUserGrps() { rows, err := database.FetchRecords(database.USER_GROUPS_TABLE_NAME) if err != nil { diff --git a/models/network.go b/models/network.go index dbb2fc4a4..904474329 100644 --- a/models/network.go +++ b/models/network.go @@ -8,9 +8,10 @@ import ( // Network Struct - contains info for a given unique network // At some point, need to replace all instances of Name with something else like Identifier type Network struct { + Name string `json:"name"` AddressRange string `json:"addressrange" bson:"addressrange" validate:"omitempty,cidrv4"` AddressRange6 string `json:"addressrange6" bson:"addressrange6" validate:"omitempty,cidrv6"` - NetID string `json:"netid" bson:"netid" validate:"required,min=1,max=32,netid_valid"` + NetID string `json:"netid"` NodesLastModified int64 `json:"nodeslastmodified" bson:"nodeslastmodified" swaggertype:"primitive,integer" format:"int64"` NetworkLastModified int64 `json:"networklastmodified" bson:"networklastmodified" swaggertype:"primitive,integer" format:"int64"` DefaultInterface string `json:"defaultinterface" bson:"defaultinterface" validate:"min=1,max=35"` @@ -24,6 +25,8 @@ type Network struct { DefaultUDPHolePunch string `json:"defaultudpholepunch" bson:"defaultudpholepunch" validate:"checkyesorno"` DefaultMTU int32 `json:"defaultmtu" bson:"defaultmtu"` DefaultACL string `json:"defaultacl" bson:"defaultacl" yaml:"defaultacl" validate:"checkyesorno"` + CreatedBy string `json:"created_by"` + CreatedAt string `json:"created_at"` } // SaveData - sensitive fields of a network that should be kept the same @@ -81,6 +84,7 @@ func (network *Network) SetDefaults() { if network.DefaultACL == "" { network.DefaultACL = "yes" } + network.CreatedAt = time.Now().UTC().String() } func (network *Network) GetNetworkNetworkCIDR4() *net.IPNet { diff --git a/models/node.go b/models/node.go index c9e55e5d5..c48155964 100644 --- a/models/node.go +++ b/models/node.go @@ -68,6 +68,7 @@ type CommonNode struct { ID uuid.UUID `json:"id" yaml:"id"` HostID uuid.UUID `json:"hostid" yaml:"hostid"` Network string `json:"network" yaml:"network"` + NetworkName string `json:"network_name" yaml:"network_name"` NetworkRange net.IPNet `json:"networkrange" yaml:"networkrange" swaggertype:"primitive,integer"` NetworkRange6 net.IPNet `json:"networkrange6" yaml:"networkrange6" swaggertype:"primitive,number"` Server string `json:"server" yaml:"server"` diff --git a/models/tags.go b/models/tags.go index 9fcb449da..9be767321 100644 --- a/models/tags.go +++ b/models/tags.go @@ -20,11 +20,12 @@ func (t Tag) GetIDFromName() string { } type Tag struct { - ID TagID `json:"id"` - TagName string `json:"tag_name"` - Network NetworkID `json:"network"` - CreatedBy string `json:"created_by"` - CreatedAt time.Time `json:"created_at"` + ID TagID `json:"id"` + TagName string `json:"tag_name"` + Network NetworkID `json:"network"` + NetworkName string `json:"network_name"` + CreatedBy string `json:"created_by"` + CreatedAt time.Time `json:"created_at"` } type CreateTagReq struct { diff --git a/mq/publishers.go b/mq/publishers.go index 28ef1935d..bbeb9dea1 100644 --- a/mq/publishers.go +++ b/mq/publishers.go @@ -240,7 +240,7 @@ func sendPeers() { func SendDNSSyncByNetwork(network string) error { - k, err := logic.GetDNS(network) + k, err := logic.GetDNS(models.NetworkID(network)) if err == nil && len(k) > 0 { err = PushSyncDNS(k) if err != nil { @@ -256,7 +256,7 @@ func sendDNSSync() error { networks, err := logic.GetNetworks() if err == nil && len(networks) > 0 { for _, v := range networks { - k, err := logic.GetDNS(v.NetID) + k, err := logic.GetDNS(models.NetworkID(v.NetID)) if err == nil && len(k) > 0 { err = PushSyncDNS(k) if err != nil { diff --git a/pro/logic/user_mgmt.go b/pro/logic/user_mgmt.go index 2a21a8bdb..e0df0296f 100644 --- a/pro/logic/user_mgmt.go +++ b/pro/logic/user_mgmt.go @@ -143,10 +143,14 @@ func CreateDefaultNetworkRolesAndGroups(netID models.NetworkID) { if netID.String() == "" { return } + network, err := logic.GetNetwork(netID.String()) + if err != nil { + return + } var NetworkAdminPermissionTemplate = models.UserRolePermissionTemplate{ ID: models.UserRoleID(fmt.Sprintf("%s-%s", netID, models.NetworkAdmin)), - Name: fmt.Sprintf("%s Admin", netID), - MetaData: fmt.Sprintf("can manage your network `%s` configuration.", netID), + Name: fmt.Sprintf("%s Admin", network.Name), + MetaData: fmt.Sprintf("can manage your network `%s` configuration.", network.Name), Default: true, NetworkID: netID, FullAccess: true, @@ -155,8 +159,8 @@ func CreateDefaultNetworkRolesAndGroups(netID models.NetworkID) { var NetworkUserPermissionTemplate = models.UserRolePermissionTemplate{ ID: models.UserRoleID(fmt.Sprintf("%s-%s", netID, models.NetworkUser)), - Name: fmt.Sprintf("%s User", netID), - MetaData: fmt.Sprintf("cannot access the admin console, but can connect to nodes in your network `%s` via Remote Access Client.", netID), + Name: fmt.Sprintf("%s User", network.Name), + MetaData: fmt.Sprintf("cannot access the admin console, but can connect to nodes in your network `%s` via Remote Access Client.", network.Name), Default: true, FullAccess: false, NetworkID: netID, @@ -217,23 +221,23 @@ func CreateDefaultNetworkRolesAndGroups(netID models.NetworkID) { // create default network groups var NetworkAdminGroup = models.UserGroup{ ID: models.UserGroupID(fmt.Sprintf("%s-%s-grp", netID, models.NetworkAdmin)), - Name: fmt.Sprintf("%s Admin Group", netID), + Name: fmt.Sprintf("%s Admin Group", network.Name), NetworkRoles: map[models.NetworkID]map[models.UserRoleID]struct{}{ netID: { models.UserRoleID(fmt.Sprintf("%s-%s", netID, models.NetworkAdmin)): {}, }, }, - MetaData: fmt.Sprintf("can manage your network `%s` configuration including adding and removing devices.", netID), + MetaData: fmt.Sprintf("can manage your network `%s` configuration including adding and removing devices.", network.Name), } var NetworkUserGroup = models.UserGroup{ ID: models.UserGroupID(fmt.Sprintf("%s-%s-grp", netID, models.NetworkUser)), - Name: fmt.Sprintf("%s User Group", netID), + Name: fmt.Sprintf("%s User Group", network.Name), NetworkRoles: map[models.NetworkID]map[models.UserRoleID]struct{}{ netID: { models.UserRoleID(fmt.Sprintf("%s-%s", netID, models.NetworkUser)): {}, }, }, - MetaData: fmt.Sprintf("cannot access the admin console, but can connect to nodes in your network `%s` via Remote Access Client.", netID), + MetaData: fmt.Sprintf("cannot access the admin console, but can connect to nodes in your network `%s` via Remote Access Client.", network.Name), } d, _ = json.Marshal(NetworkAdminGroup) database.Insert(NetworkAdminGroup.ID.String(), string(d), database.USER_GROUPS_TABLE_NAME)