mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-14 10:50:45 +01:00
Rename GUI menu options and route selection with new network concept (#3035)
* rename route with network for new concept * rename file
This commit is contained in:
parent
6bd9352da8
commit
86352f00fc
@ -58,7 +58,7 @@ func main() {
|
|||||||
var showSettings bool
|
var showSettings bool
|
||||||
flag.BoolVar(&showSettings, "settings", false, "run settings windows")
|
flag.BoolVar(&showSettings, "settings", false, "run settings windows")
|
||||||
var showRoutes bool
|
var showRoutes bool
|
||||||
flag.BoolVar(&showRoutes, "routes", false, "run routes windows")
|
flag.BoolVar(&showRoutes, "networks", false, "run networks windows")
|
||||||
var errorMSG string
|
var errorMSG string
|
||||||
flag.StringVar(&errorMSG, "error-msg", "", "displays a error message window")
|
flag.StringVar(&errorMSG, "error-msg", "", "displays a error message window")
|
||||||
|
|
||||||
@ -233,7 +233,7 @@ func newServiceClient(addr string, a fyne.App, showSettings bool, showRoutes boo
|
|||||||
s.showSettingsUI()
|
s.showSettingsUI()
|
||||||
return s
|
return s
|
||||||
} else if showRoutes {
|
} else if showRoutes {
|
||||||
s.showRoutesUI()
|
s.showNetworksUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
return s
|
return s
|
||||||
@ -549,7 +549,7 @@ func (s *serviceClient) onTrayReady() {
|
|||||||
s.mAdvancedSettings = s.mSettings.AddSubMenuItem("Advanced Settings", "Advanced settings of the application")
|
s.mAdvancedSettings = s.mSettings.AddSubMenuItem("Advanced Settings", "Advanced settings of the application")
|
||||||
s.loadSettings()
|
s.loadSettings()
|
||||||
|
|
||||||
s.mRoutes = systray.AddMenuItem("Network Routes", "Open the routes management window")
|
s.mRoutes = systray.AddMenuItem("Networks", "Open the networks management window")
|
||||||
s.mRoutes.Disable()
|
s.mRoutes.Disable()
|
||||||
systray.AddSeparator()
|
systray.AddSeparator()
|
||||||
|
|
||||||
@ -656,7 +656,7 @@ func (s *serviceClient) onTrayReady() {
|
|||||||
s.mRoutes.Disable()
|
s.mRoutes.Disable()
|
||||||
go func() {
|
go func() {
|
||||||
defer s.mRoutes.Enable()
|
defer s.mRoutes.Enable()
|
||||||
s.runSelfCommand("routes", "true")
|
s.runSelfCommand("networks", "true")
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -19,32 +19,32 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
allRoutesText = "All routes"
|
allNetworksText = "All networks"
|
||||||
overlappingRoutesText = "Overlapping routes"
|
overlappingNetworksText = "Overlapping networks"
|
||||||
exitNodeRoutesText = "Exit-node routes"
|
exitNodeNetworksText = "Exit-node networks"
|
||||||
allRoutes filter = "all"
|
allNetworks filter = "all"
|
||||||
overlappingRoutes filter = "overlapping"
|
overlappingNetworks filter = "overlapping"
|
||||||
exitNodeRoutes filter = "exit-node"
|
exitNodeNetworks filter = "exit-node"
|
||||||
getClientFMT = "get client: %v"
|
getClientFMT = "get client: %v"
|
||||||
)
|
)
|
||||||
|
|
||||||
type filter string
|
type filter string
|
||||||
|
|
||||||
func (s *serviceClient) showRoutesUI() {
|
func (s *serviceClient) showNetworksUI() {
|
||||||
s.wRoutes = s.app.NewWindow("NetBird Routes")
|
s.wRoutes = s.app.NewWindow("Networks")
|
||||||
|
|
||||||
allGrid := container.New(layout.NewGridLayout(3))
|
allGrid := container.New(layout.NewGridLayout(3))
|
||||||
go s.updateRoutes(allGrid, allRoutes)
|
go s.updateNetworks(allGrid, allNetworks)
|
||||||
overlappingGrid := container.New(layout.NewGridLayout(3))
|
overlappingGrid := container.New(layout.NewGridLayout(3))
|
||||||
exitNodeGrid := container.New(layout.NewGridLayout(3))
|
exitNodeGrid := container.New(layout.NewGridLayout(3))
|
||||||
routeCheckContainer := container.NewVBox()
|
routeCheckContainer := container.NewVBox()
|
||||||
tabs := container.NewAppTabs(
|
tabs := container.NewAppTabs(
|
||||||
container.NewTabItem(allRoutesText, allGrid),
|
container.NewTabItem(allNetworksText, allGrid),
|
||||||
container.NewTabItem(overlappingRoutesText, overlappingGrid),
|
container.NewTabItem(overlappingNetworksText, overlappingGrid),
|
||||||
container.NewTabItem(exitNodeRoutesText, exitNodeGrid),
|
container.NewTabItem(exitNodeNetworksText, exitNodeGrid),
|
||||||
)
|
)
|
||||||
tabs.OnSelected = func(item *container.TabItem) {
|
tabs.OnSelected = func(item *container.TabItem) {
|
||||||
s.updateRoutesBasedOnDisplayTab(tabs, allGrid, overlappingGrid, exitNodeGrid)
|
s.updateNetworksBasedOnDisplayTab(tabs, allGrid, overlappingGrid, exitNodeGrid)
|
||||||
}
|
}
|
||||||
tabs.OnUnselected = func(item *container.TabItem) {
|
tabs.OnUnselected = func(item *container.TabItem) {
|
||||||
grid, _ := getGridAndFilterFromTab(tabs, allGrid, overlappingGrid, exitNodeGrid)
|
grid, _ := getGridAndFilterFromTab(tabs, allGrid, overlappingGrid, exitNodeGrid)
|
||||||
@ -58,17 +58,17 @@ func (s *serviceClient) showRoutesUI() {
|
|||||||
buttonBox := container.NewHBox(
|
buttonBox := container.NewHBox(
|
||||||
layout.NewSpacer(),
|
layout.NewSpacer(),
|
||||||
widget.NewButton("Refresh", func() {
|
widget.NewButton("Refresh", func() {
|
||||||
s.updateRoutesBasedOnDisplayTab(tabs, allGrid, overlappingGrid, exitNodeGrid)
|
s.updateNetworksBasedOnDisplayTab(tabs, allGrid, overlappingGrid, exitNodeGrid)
|
||||||
}),
|
}),
|
||||||
widget.NewButton("Select all", func() {
|
widget.NewButton("Select all", func() {
|
||||||
_, f := getGridAndFilterFromTab(tabs, allGrid, overlappingGrid, exitNodeGrid)
|
_, f := getGridAndFilterFromTab(tabs, allGrid, overlappingGrid, exitNodeGrid)
|
||||||
s.selectAllFilteredRoutes(f)
|
s.selectAllFilteredNetworks(f)
|
||||||
s.updateRoutesBasedOnDisplayTab(tabs, allGrid, overlappingGrid, exitNodeGrid)
|
s.updateNetworksBasedOnDisplayTab(tabs, allGrid, overlappingGrid, exitNodeGrid)
|
||||||
}),
|
}),
|
||||||
widget.NewButton("Deselect All", func() {
|
widget.NewButton("Deselect All", func() {
|
||||||
_, f := getGridAndFilterFromTab(tabs, allGrid, overlappingGrid, exitNodeGrid)
|
_, f := getGridAndFilterFromTab(tabs, allGrid, overlappingGrid, exitNodeGrid)
|
||||||
s.deselectAllFilteredRoutes(f)
|
s.deselectAllFilteredNetworks(f)
|
||||||
s.updateRoutesBasedOnDisplayTab(tabs, allGrid, overlappingGrid, exitNodeGrid)
|
s.updateNetworksBasedOnDisplayTab(tabs, allGrid, overlappingGrid, exitNodeGrid)
|
||||||
}),
|
}),
|
||||||
layout.NewSpacer(),
|
layout.NewSpacer(),
|
||||||
)
|
)
|
||||||
@ -81,29 +81,29 @@ func (s *serviceClient) showRoutesUI() {
|
|||||||
s.startAutoRefresh(10*time.Second, tabs, allGrid, overlappingGrid, exitNodeGrid)
|
s.startAutoRefresh(10*time.Second, tabs, allGrid, overlappingGrid, exitNodeGrid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *serviceClient) updateRoutes(grid *fyne.Container, f filter) {
|
func (s *serviceClient) updateNetworks(grid *fyne.Container, f filter) {
|
||||||
grid.Objects = nil
|
grid.Objects = nil
|
||||||
grid.Refresh()
|
grid.Refresh()
|
||||||
idHeader := widget.NewLabelWithStyle(" ID", fyne.TextAlignLeading, fyne.TextStyle{Bold: true})
|
idHeader := widget.NewLabelWithStyle(" ID", fyne.TextAlignLeading, fyne.TextStyle{Bold: true})
|
||||||
networkHeader := widget.NewLabelWithStyle("Network/Domains", fyne.TextAlignLeading, fyne.TextStyle{Bold: true})
|
networkHeader := widget.NewLabelWithStyle("Range/Domains", fyne.TextAlignLeading, fyne.TextStyle{Bold: true})
|
||||||
resolvedIPsHeader := widget.NewLabelWithStyle("Resolved IPs", fyne.TextAlignLeading, fyne.TextStyle{Bold: true})
|
resolvedIPsHeader := widget.NewLabelWithStyle("Resolved IPs", fyne.TextAlignLeading, fyne.TextStyle{Bold: true})
|
||||||
|
|
||||||
grid.Add(idHeader)
|
grid.Add(idHeader)
|
||||||
grid.Add(networkHeader)
|
grid.Add(networkHeader)
|
||||||
grid.Add(resolvedIPsHeader)
|
grid.Add(resolvedIPsHeader)
|
||||||
|
|
||||||
filteredRoutes, err := s.getFilteredRoutes(f)
|
filteredRoutes, err := s.getFilteredNetworks(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sortRoutesByIDs(filteredRoutes)
|
sortNetworksByIDs(filteredRoutes)
|
||||||
|
|
||||||
for _, route := range filteredRoutes {
|
for _, route := range filteredRoutes {
|
||||||
r := route
|
r := route
|
||||||
|
|
||||||
checkBox := widget.NewCheck(r.GetID(), func(checked bool) {
|
checkBox := widget.NewCheck(r.GetID(), func(checked bool) {
|
||||||
s.selectRoute(r.ID, checked)
|
s.selectNetwork(r.ID, checked)
|
||||||
})
|
})
|
||||||
checkBox.Checked = route.Selected
|
checkBox.Checked = route.Selected
|
||||||
checkBox.Resize(fyne.NewSize(20, 20))
|
checkBox.Resize(fyne.NewSize(20, 20))
|
||||||
@ -151,24 +151,24 @@ func (s *serviceClient) updateRoutes(grid *fyne.Container, f filter) {
|
|||||||
grid.Refresh()
|
grid.Refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *serviceClient) getFilteredRoutes(f filter) ([]*proto.Network, error) {
|
func (s *serviceClient) getFilteredNetworks(f filter) ([]*proto.Network, error) {
|
||||||
routes, err := s.fetchRoutes()
|
routes, err := s.fetchNetworks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(getClientFMT, err)
|
log.Errorf(getClientFMT, err)
|
||||||
s.showError(fmt.Errorf(getClientFMT, err))
|
s.showError(fmt.Errorf(getClientFMT, err))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
switch f {
|
switch f {
|
||||||
case overlappingRoutes:
|
case overlappingNetworks:
|
||||||
return getOverlappingRoutes(routes), nil
|
return getOverlappingNetworks(routes), nil
|
||||||
case exitNodeRoutes:
|
case exitNodeNetworks:
|
||||||
return getExitNodeRoutes(routes), nil
|
return getExitNodeNetworks(routes), nil
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
return routes, nil
|
return routes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOverlappingRoutes(routes []*proto.Network) []*proto.Network {
|
func getOverlappingNetworks(routes []*proto.Network) []*proto.Network {
|
||||||
var filteredRoutes []*proto.Network
|
var filteredRoutes []*proto.Network
|
||||||
existingRange := make(map[string][]*proto.Network)
|
existingRange := make(map[string][]*proto.Network)
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
@ -190,7 +190,7 @@ func getOverlappingRoutes(routes []*proto.Network) []*proto.Network {
|
|||||||
return filteredRoutes
|
return filteredRoutes
|
||||||
}
|
}
|
||||||
|
|
||||||
func getExitNodeRoutes(routes []*proto.Network) []*proto.Network {
|
func getExitNodeNetworks(routes []*proto.Network) []*proto.Network {
|
||||||
var filteredRoutes []*proto.Network
|
var filteredRoutes []*proto.Network
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
if route.Range == "0.0.0.0/0" {
|
if route.Range == "0.0.0.0/0" {
|
||||||
@ -200,13 +200,13 @@ func getExitNodeRoutes(routes []*proto.Network) []*proto.Network {
|
|||||||
return filteredRoutes
|
return filteredRoutes
|
||||||
}
|
}
|
||||||
|
|
||||||
func sortRoutesByIDs(routes []*proto.Network) {
|
func sortNetworksByIDs(routes []*proto.Network) {
|
||||||
sort.Slice(routes, func(i, j int) bool {
|
sort.Slice(routes, func(i, j int) bool {
|
||||||
return strings.ToLower(routes[i].GetID()) < strings.ToLower(routes[j].GetID())
|
return strings.ToLower(routes[i].GetID()) < strings.ToLower(routes[j].GetID())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *serviceClient) fetchRoutes() ([]*proto.Network, error) {
|
func (s *serviceClient) fetchNetworks() ([]*proto.Network, error) {
|
||||||
conn, err := s.getSrvClient(defaultFailTimeout)
|
conn, err := s.getSrvClient(defaultFailTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(getClientFMT, err)
|
return nil, fmt.Errorf(getClientFMT, err)
|
||||||
@ -220,7 +220,7 @@ func (s *serviceClient) fetchRoutes() ([]*proto.Network, error) {
|
|||||||
return resp.Routes, nil
|
return resp.Routes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *serviceClient) selectRoute(id string, checked bool) {
|
func (s *serviceClient) selectNetwork(id string, checked bool) {
|
||||||
conn, err := s.getSrvClient(defaultFailTimeout)
|
conn, err := s.getSrvClient(defaultFailTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(getClientFMT, err)
|
log.Errorf(getClientFMT, err)
|
||||||
@ -235,61 +235,61 @@ func (s *serviceClient) selectRoute(id string, checked bool) {
|
|||||||
|
|
||||||
if checked {
|
if checked {
|
||||||
if _, err := conn.SelectNetworks(s.ctx, req); err != nil {
|
if _, err := conn.SelectNetworks(s.ctx, req); err != nil {
|
||||||
log.Errorf("failed to select route: %v", err)
|
log.Errorf("failed to select network: %v", err)
|
||||||
s.showError(fmt.Errorf("failed to select route: %v", err))
|
s.showError(fmt.Errorf("failed to select network: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("Route %s selected", id)
|
log.Infof("Route %s selected", id)
|
||||||
} else {
|
} else {
|
||||||
if _, err := conn.DeselectNetworks(s.ctx, req); err != nil {
|
if _, err := conn.DeselectNetworks(s.ctx, req); err != nil {
|
||||||
log.Errorf("failed to deselect route: %v", err)
|
log.Errorf("failed to deselect network: %v", err)
|
||||||
s.showError(fmt.Errorf("failed to deselect route: %v", err))
|
s.showError(fmt.Errorf("failed to deselect network: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("Route %s deselected", id)
|
log.Infof("Network %s deselected", id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *serviceClient) selectAllFilteredRoutes(f filter) {
|
func (s *serviceClient) selectAllFilteredNetworks(f filter) {
|
||||||
conn, err := s.getSrvClient(defaultFailTimeout)
|
conn, err := s.getSrvClient(defaultFailTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(getClientFMT, err)
|
log.Errorf(getClientFMT, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
req := s.getRoutesRequest(f, true)
|
req := s.getNetworksRequest(f, true)
|
||||||
if _, err := conn.SelectNetworks(s.ctx, req); err != nil {
|
if _, err := conn.SelectNetworks(s.ctx, req); err != nil {
|
||||||
log.Errorf("failed to select all routes: %v", err)
|
log.Errorf("failed to select all networks: %v", err)
|
||||||
s.showError(fmt.Errorf("failed to select all routes: %v", err))
|
s.showError(fmt.Errorf("failed to select all networks: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("All routes selected")
|
log.Debug("All networks selected")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *serviceClient) deselectAllFilteredRoutes(f filter) {
|
func (s *serviceClient) deselectAllFilteredNetworks(f filter) {
|
||||||
conn, err := s.getSrvClient(defaultFailTimeout)
|
conn, err := s.getSrvClient(defaultFailTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(getClientFMT, err)
|
log.Errorf(getClientFMT, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
req := s.getRoutesRequest(f, false)
|
req := s.getNetworksRequest(f, false)
|
||||||
if _, err := conn.DeselectNetworks(s.ctx, req); err != nil {
|
if _, err := conn.DeselectNetworks(s.ctx, req); err != nil {
|
||||||
log.Errorf("failed to deselect all routes: %v", err)
|
log.Errorf("failed to deselect all networks: %v", err)
|
||||||
s.showError(fmt.Errorf("failed to deselect all routes: %v", err))
|
s.showError(fmt.Errorf("failed to deselect all networks: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("All routes deselected")
|
log.Debug("All networks deselected")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *serviceClient) getRoutesRequest(f filter, appendRoute bool) *proto.SelectNetworksRequest {
|
func (s *serviceClient) getNetworksRequest(f filter, appendRoute bool) *proto.SelectNetworksRequest {
|
||||||
req := &proto.SelectNetworksRequest{}
|
req := &proto.SelectNetworksRequest{}
|
||||||
if f == allRoutes {
|
if f == allNetworks {
|
||||||
req.All = true
|
req.All = true
|
||||||
} else {
|
} else {
|
||||||
routes, err := s.getFilteredRoutes(f)
|
routes, err := s.getFilteredNetworks(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -311,7 +311,7 @@ func (s *serviceClient) startAutoRefresh(interval time.Duration, tabs *container
|
|||||||
ticker := time.NewTicker(interval)
|
ticker := time.NewTicker(interval)
|
||||||
go func() {
|
go func() {
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
s.updateRoutesBasedOnDisplayTab(tabs, allGrid, overlappingGrid, exitNodesGrid)
|
s.updateNetworksBasedOnDisplayTab(tabs, allGrid, overlappingGrid, exitNodesGrid)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -320,20 +320,20 @@ func (s *serviceClient) startAutoRefresh(interval time.Duration, tabs *container
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *serviceClient) updateRoutesBasedOnDisplayTab(tabs *container.AppTabs, allGrid, overlappingGrid, exitNodesGrid *fyne.Container) {
|
func (s *serviceClient) updateNetworksBasedOnDisplayTab(tabs *container.AppTabs, allGrid, overlappingGrid, exitNodesGrid *fyne.Container) {
|
||||||
grid, f := getGridAndFilterFromTab(tabs, allGrid, overlappingGrid, exitNodesGrid)
|
grid, f := getGridAndFilterFromTab(tabs, allGrid, overlappingGrid, exitNodesGrid)
|
||||||
s.wRoutes.Content().Refresh()
|
s.wRoutes.Content().Refresh()
|
||||||
s.updateRoutes(grid, f)
|
s.updateNetworks(grid, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGridAndFilterFromTab(tabs *container.AppTabs, allGrid, overlappingGrid, exitNodesGrid *fyne.Container) (*fyne.Container, filter) {
|
func getGridAndFilterFromTab(tabs *container.AppTabs, allGrid, overlappingGrid, exitNodesGrid *fyne.Container) (*fyne.Container, filter) {
|
||||||
switch tabs.Selected().Text {
|
switch tabs.Selected().Text {
|
||||||
case overlappingRoutesText:
|
case overlappingNetworksText:
|
||||||
return overlappingGrid, overlappingRoutes
|
return overlappingGrid, overlappingNetworks
|
||||||
case exitNodeRoutesText:
|
case exitNodeNetworksText:
|
||||||
return exitNodesGrid, exitNodeRoutes
|
return exitNodesGrid, exitNodeNetworks
|
||||||
default:
|
default:
|
||||||
return allGrid, allRoutes
|
return allGrid, allNetworks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user