2024-06-13 13:24:24 +02:00
|
|
|
//go:build !(linux && 386) && !freebsd
|
2022-07-01 10:42:38 +02:00
|
|
|
|
2022-03-20 17:36:35 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-03-15 07:54:51 +01:00
|
|
|
_ "embed"
|
2024-06-19 10:09:35 +02:00
|
|
|
"errors"
|
2022-03-20 17:36:35 +01:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
2022-03-23 18:24:25 +01:00
|
|
|
"os"
|
2022-04-15 17:30:12 +02:00
|
|
|
"os/exec"
|
2022-03-23 18:24:25 +01:00
|
|
|
"path"
|
2022-03-20 17:36:35 +01:00
|
|
|
"runtime"
|
2022-03-23 18:24:25 +01:00
|
|
|
"strconv"
|
2022-03-20 17:36:35 +01:00
|
|
|
"strings"
|
2023-10-30 10:32:48 +01:00
|
|
|
"sync"
|
2022-03-20 17:36:35 +01:00
|
|
|
"time"
|
2023-10-30 10:32:48 +01:00
|
|
|
"unicode"
|
2022-03-20 17:36:35 +01:00
|
|
|
|
2023-03-15 07:54:51 +01:00
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
"fyne.io/fyne/v2/app"
|
|
|
|
"fyne.io/fyne/v2/dialog"
|
|
|
|
"fyne.io/fyne/v2/widget"
|
2024-08-07 14:40:43 +02:00
|
|
|
"fyne.io/systray"
|
2022-05-25 23:25:02 +02:00
|
|
|
"github.com/cenkalti/backoff/v4"
|
2022-03-20 17:36:35 +01:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/skratchdot/open-golang/open"
|
2022-04-15 17:30:12 +02:00
|
|
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
2022-03-20 17:36:35 +01:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/credentials/insecure"
|
2022-04-15 17:30:12 +02:00
|
|
|
|
2023-03-15 07:54:51 +01:00
|
|
|
"github.com/netbirdio/netbird/client/internal"
|
|
|
|
"github.com/netbirdio/netbird/client/proto"
|
|
|
|
"github.com/netbirdio/netbird/client/system"
|
2024-07-15 14:53:52 +02:00
|
|
|
"github.com/netbirdio/netbird/util"
|
2023-03-15 07:54:51 +01:00
|
|
|
"github.com/netbirdio/netbird/version"
|
2022-04-15 17:30:12 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2022-04-18 09:43:37 +02:00
|
|
|
defaultFailTimeout = 3 * time.Second
|
|
|
|
failFastTimeout = time.Second
|
2022-03-20 17:36:35 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var daemonAddr string
|
|
|
|
|
2022-05-22 18:53:47 +02:00
|
|
|
defaultDaemonAddr := "unix:///var/run/netbird.sock"
|
2022-03-20 17:36:35 +01:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
defaultDaemonAddr = "tcp://127.0.0.1:41731"
|
|
|
|
}
|
|
|
|
|
|
|
|
flag.StringVar(
|
|
|
|
&daemonAddr, "daemon-addr",
|
|
|
|
defaultDaemonAddr,
|
|
|
|
"Daemon service address to serve CLI requests [unix|tcp]://[path|host:port]")
|
|
|
|
|
2022-04-15 17:30:12 +02:00
|
|
|
var showSettings bool
|
|
|
|
flag.BoolVar(&showSettings, "settings", false, "run settings windows")
|
2024-04-23 14:42:53 +02:00
|
|
|
var showRoutes bool
|
|
|
|
flag.BoolVar(&showRoutes, "routes", false, "run routes windows")
|
2024-04-22 11:57:38 +02:00
|
|
|
var errorMSG string
|
|
|
|
flag.StringVar(&errorMSG, "error-msg", "", "displays a error message window")
|
2022-04-15 17:30:12 +02:00
|
|
|
|
2024-07-15 14:53:52 +02:00
|
|
|
tmpDir := "/tmp"
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
tmpDir = os.TempDir()
|
|
|
|
}
|
|
|
|
|
|
|
|
var saveLogsInFile bool
|
|
|
|
flag.BoolVar(&saveLogsInFile, "use-log-file", false, fmt.Sprintf("save logs in a file: %s/netbird-ui-PID.log", tmpDir))
|
|
|
|
|
2022-03-20 17:36:35 +01:00
|
|
|
flag.Parse()
|
|
|
|
|
2024-07-15 14:53:52 +02:00
|
|
|
if saveLogsInFile {
|
|
|
|
logFile := path.Join(tmpDir, fmt.Sprintf("netbird-ui-%d.log", os.Getpid()))
|
|
|
|
err := util.InitLog("trace", logFile)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("error while initializing log: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-01 17:57:17 +01:00
|
|
|
a := app.NewWithID("NetBird")
|
2022-11-01 00:34:30 +01:00
|
|
|
a.SetIcon(fyne.NewStaticResource("netbird", iconDisconnectedPNG))
|
2022-10-26 14:34:30 +02:00
|
|
|
|
2024-04-22 11:57:38 +02:00
|
|
|
if errorMSG != "" {
|
|
|
|
showErrorMSG(errorMSG)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-04-23 14:42:53 +02:00
|
|
|
client := newServiceClient(daemonAddr, a, showSettings, showRoutes)
|
|
|
|
if showSettings || showRoutes {
|
2022-04-15 17:30:12 +02:00
|
|
|
a.Run()
|
|
|
|
} else {
|
2024-07-15 14:53:52 +02:00
|
|
|
running, err := isAnotherProcessRunning()
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("error while checking process: %v", err)
|
|
|
|
}
|
|
|
|
if running {
|
|
|
|
log.Warn("another process is running")
|
2022-04-15 17:30:12 +02:00
|
|
|
return
|
|
|
|
}
|
2024-07-02 11:47:26 +02:00
|
|
|
client.setDefaultFonts()
|
2022-04-15 17:30:12 +02:00
|
|
|
systray.Run(client.onTrayReady, client.onTrayExit)
|
|
|
|
}
|
2022-03-20 17:36:35 +01:00
|
|
|
}
|
|
|
|
|
2023-10-30 10:32:48 +01:00
|
|
|
//go:embed netbird-systemtray-connected.ico
|
2022-04-15 17:30:12 +02:00
|
|
|
var iconConnectedICO []byte
|
|
|
|
|
2023-10-30 10:32:48 +01:00
|
|
|
//go:embed netbird-systemtray-connected.png
|
2022-04-15 17:30:12 +02:00
|
|
|
var iconConnectedPNG []byte
|
2022-03-20 17:36:35 +01:00
|
|
|
|
2024-02-26 23:28:33 +01:00
|
|
|
//go:embed netbird-systemtray-disconnected.ico
|
2022-04-15 17:30:12 +02:00
|
|
|
var iconDisconnectedICO []byte
|
|
|
|
|
2024-02-26 23:28:33 +01:00
|
|
|
//go:embed netbird-systemtray-disconnected.png
|
2022-04-15 17:30:12 +02:00
|
|
|
var iconDisconnectedPNG []byte
|
2022-03-20 17:36:35 +01:00
|
|
|
|
2024-02-26 23:28:33 +01:00
|
|
|
//go:embed netbird-systemtray-update-disconnected.ico
|
|
|
|
var iconUpdateDisconnectedICO []byte
|
2023-10-30 10:32:48 +01:00
|
|
|
|
2024-02-26 23:28:33 +01:00
|
|
|
//go:embed netbird-systemtray-update-disconnected.png
|
|
|
|
var iconUpdateDisconnectedPNG []byte
|
|
|
|
|
|
|
|
//go:embed netbird-systemtray-update-connected.ico
|
|
|
|
var iconUpdateConnectedICO []byte
|
|
|
|
|
|
|
|
//go:embed netbird-systemtray-update-connected.png
|
|
|
|
var iconUpdateConnectedPNG []byte
|
2023-10-30 10:32:48 +01:00
|
|
|
|
|
|
|
//go:embed netbird-systemtray-update-cloud.ico
|
|
|
|
var iconUpdateCloudICO []byte
|
|
|
|
|
|
|
|
//go:embed netbird-systemtray-update-cloud.png
|
|
|
|
var iconUpdateCloudPNG []byte
|
|
|
|
|
2022-03-20 17:36:35 +01:00
|
|
|
type serviceClient struct {
|
2022-04-15 17:30:12 +02:00
|
|
|
ctx context.Context
|
|
|
|
addr string
|
|
|
|
conn proto.DaemonServiceClient
|
|
|
|
|
2024-02-26 23:28:33 +01:00
|
|
|
icConnected []byte
|
|
|
|
icDisconnected []byte
|
|
|
|
icUpdateConnected []byte
|
|
|
|
icUpdateDisconnected []byte
|
|
|
|
icUpdateCloud []byte
|
2022-04-15 17:30:12 +02:00
|
|
|
|
2022-05-27 13:56:12 +02:00
|
|
|
// systray menu items
|
2024-06-19 10:09:35 +02:00
|
|
|
mStatus *systray.MenuItem
|
|
|
|
mUp *systray.MenuItem
|
|
|
|
mDown *systray.MenuItem
|
|
|
|
mAdminPanel *systray.MenuItem
|
|
|
|
mSettings *systray.MenuItem
|
|
|
|
mAbout *systray.MenuItem
|
|
|
|
mVersionUI *systray.MenuItem
|
|
|
|
mVersionDaemon *systray.MenuItem
|
|
|
|
mUpdate *systray.MenuItem
|
|
|
|
mQuit *systray.MenuItem
|
|
|
|
mRoutes *systray.MenuItem
|
|
|
|
mAllowSSH *systray.MenuItem
|
|
|
|
mAutoConnect *systray.MenuItem
|
|
|
|
mEnableRosenpass *systray.MenuItem
|
|
|
|
mAdvancedSettings *systray.MenuItem
|
2022-04-15 17:30:12 +02:00
|
|
|
|
|
|
|
// application with main windows.
|
2024-06-19 10:09:35 +02:00
|
|
|
app fyne.App
|
|
|
|
wSettings fyne.Window
|
|
|
|
showAdvancedSettings bool
|
|
|
|
sendNotification bool
|
2022-04-15 17:30:12 +02:00
|
|
|
|
|
|
|
// input elements for settings form
|
2024-06-19 10:09:35 +02:00
|
|
|
iMngURL *widget.Entry
|
|
|
|
iAdminURL *widget.Entry
|
|
|
|
iConfigFile *widget.Entry
|
|
|
|
iLogFile *widget.Entry
|
|
|
|
iPreSharedKey *widget.Entry
|
|
|
|
iInterfaceName *widget.Entry
|
|
|
|
iInterfacePort *widget.Entry
|
|
|
|
|
|
|
|
// switch elements for settings form
|
|
|
|
sRosenpassPermissive *widget.Check
|
2022-04-15 17:30:12 +02:00
|
|
|
|
2022-10-26 14:34:30 +02:00
|
|
|
// observable settings over corresponding iMngURL and iPreSharedKey values.
|
2024-06-19 10:09:35 +02:00
|
|
|
managementURL string
|
|
|
|
preSharedKey string
|
|
|
|
adminURL string
|
|
|
|
RosenpassPermissive bool
|
|
|
|
interfaceName string
|
|
|
|
interfacePort int
|
2023-10-30 10:32:48 +01:00
|
|
|
|
2024-02-26 23:28:33 +01:00
|
|
|
connected bool
|
2023-10-30 10:32:48 +01:00
|
|
|
update *version.Update
|
|
|
|
daemonVersion string
|
|
|
|
updateIndicationLock sync.Mutex
|
|
|
|
isUpdateIconActive bool
|
2024-06-19 10:09:35 +02:00
|
|
|
showRoutes bool
|
|
|
|
wRoutes fyne.Window
|
2022-03-20 17:36:35 +01:00
|
|
|
}
|
|
|
|
|
2022-04-15 17:30:12 +02:00
|
|
|
// newServiceClient instance constructor
|
|
|
|
//
|
2022-10-26 14:34:30 +02:00
|
|
|
// This constructor also builds the UI elements for the settings window.
|
2024-04-23 14:42:53 +02:00
|
|
|
func newServiceClient(addr string, a fyne.App, showSettings bool, showRoutes bool) *serviceClient {
|
2022-03-20 17:36:35 +01:00
|
|
|
s := &serviceClient{
|
2024-03-01 17:57:17 +01:00
|
|
|
ctx: context.Background(),
|
|
|
|
addr: addr,
|
|
|
|
app: a,
|
|
|
|
sendNotification: false,
|
2022-04-15 17:30:12 +02:00
|
|
|
|
2024-06-19 10:09:35 +02:00
|
|
|
showAdvancedSettings: showSettings,
|
|
|
|
showRoutes: showRoutes,
|
|
|
|
update: version.NewUpdate(),
|
2022-03-20 17:36:35 +01:00
|
|
|
}
|
2022-04-15 17:30:12 +02:00
|
|
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
s.icConnected = iconConnectedICO
|
|
|
|
s.icDisconnected = iconDisconnectedICO
|
2024-02-26 23:28:33 +01:00
|
|
|
s.icUpdateConnected = iconUpdateConnectedICO
|
|
|
|
s.icUpdateDisconnected = iconUpdateDisconnectedICO
|
2023-10-30 10:32:48 +01:00
|
|
|
s.icUpdateCloud = iconUpdateCloudICO
|
|
|
|
|
2022-04-15 17:30:12 +02:00
|
|
|
} else {
|
|
|
|
s.icConnected = iconConnectedPNG
|
|
|
|
s.icDisconnected = iconDisconnectedPNG
|
2024-02-26 23:28:33 +01:00
|
|
|
s.icUpdateConnected = iconUpdateConnectedPNG
|
|
|
|
s.icUpdateDisconnected = iconUpdateDisconnectedPNG
|
2023-10-30 10:32:48 +01:00
|
|
|
s.icUpdateCloud = iconUpdateCloudPNG
|
2022-04-15 17:30:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if showSettings {
|
2024-04-23 14:42:53 +02:00
|
|
|
s.showSettingsUI()
|
2022-04-15 17:30:12 +02:00
|
|
|
return s
|
2024-04-23 14:42:53 +02:00
|
|
|
} else if showRoutes {
|
|
|
|
s.showRoutesUI()
|
2022-04-15 17:30:12 +02:00
|
|
|
}
|
|
|
|
|
2022-03-20 17:36:35 +01:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2024-04-23 14:42:53 +02:00
|
|
|
func (s *serviceClient) showSettingsUI() {
|
2022-04-15 17:30:12 +02:00
|
|
|
// add settings window UI elements.
|
2022-10-26 14:34:30 +02:00
|
|
|
s.wSettings = s.app.NewWindow("NetBird Settings")
|
2022-04-15 17:30:12 +02:00
|
|
|
s.iMngURL = widget.NewEntry()
|
|
|
|
s.iAdminURL = widget.NewEntry()
|
|
|
|
s.iConfigFile = widget.NewEntry()
|
|
|
|
s.iConfigFile.Disable()
|
|
|
|
s.iLogFile = widget.NewEntry()
|
|
|
|
s.iLogFile.Disable()
|
|
|
|
s.iPreSharedKey = widget.NewPasswordEntry()
|
2024-06-19 10:09:35 +02:00
|
|
|
s.iInterfaceName = widget.NewEntry()
|
|
|
|
s.iInterfacePort = widget.NewEntry()
|
|
|
|
s.sRosenpassPermissive = widget.NewCheck("Enable Rosenpass permissive mode", nil)
|
|
|
|
|
2022-04-15 17:30:12 +02:00
|
|
|
s.wSettings.SetContent(s.getSettingsForm())
|
2024-06-19 10:09:35 +02:00
|
|
|
s.wSettings.Resize(fyne.NewSize(600, 400))
|
|
|
|
s.wSettings.SetFixedSize(true)
|
2022-04-15 17:30:12 +02:00
|
|
|
|
|
|
|
s.getSrvConfig()
|
|
|
|
|
|
|
|
s.wSettings.Show()
|
|
|
|
}
|
|
|
|
|
2024-04-22 11:57:38 +02:00
|
|
|
// showErrorMSG opens a fyne app window to display the supplied message
|
|
|
|
func showErrorMSG(msg string) {
|
|
|
|
app := app.New()
|
|
|
|
w := app.NewWindow("NetBird Error")
|
|
|
|
content := widget.NewLabel(msg)
|
|
|
|
content.Wrapping = fyne.TextWrapWord
|
|
|
|
w.SetContent(content)
|
|
|
|
w.Resize(fyne.NewSize(400, 100))
|
|
|
|
w.Show()
|
|
|
|
app.Run()
|
|
|
|
}
|
|
|
|
|
2022-04-15 17:30:12 +02:00
|
|
|
// getSettingsForm to embed it into settings window.
|
|
|
|
func (s *serviceClient) getSettingsForm() *widget.Form {
|
|
|
|
return &widget.Form{
|
|
|
|
Items: []*widget.FormItem{
|
2024-06-19 10:09:35 +02:00
|
|
|
{Text: "Quantum-Resistance", Widget: s.sRosenpassPermissive},
|
|
|
|
{Text: "Interface Name", Widget: s.iInterfaceName},
|
|
|
|
{Text: "Interface Port", Widget: s.iInterfacePort},
|
2022-04-15 17:30:12 +02:00
|
|
|
{Text: "Management URL", Widget: s.iMngURL},
|
|
|
|
{Text: "Admin URL", Widget: s.iAdminURL},
|
|
|
|
{Text: "Pre-shared Key", Widget: s.iPreSharedKey},
|
|
|
|
{Text: "Config File", Widget: s.iConfigFile},
|
|
|
|
{Text: "Log File", Widget: s.iLogFile},
|
|
|
|
},
|
|
|
|
SubmitText: "Save",
|
|
|
|
OnSubmit: func() {
|
|
|
|
if s.iPreSharedKey.Text != "" && s.iPreSharedKey.Text != "**********" {
|
|
|
|
// validate preSharedKey if it added
|
|
|
|
if _, err := wgtypes.ParseKey(s.iPreSharedKey.Text); err != nil {
|
|
|
|
dialog.ShowError(fmt.Errorf("Invalid Pre-shared Key Value"), s.wSettings)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-19 10:09:35 +02:00
|
|
|
port, err := strconv.ParseInt(s.iInterfacePort.Text, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
dialog.ShowError(errors.New("Invalid interface port"), s.wSettings)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-19 12:27:37 +02:00
|
|
|
iAdminURL := strings.TrimSpace(s.iAdminURL.Text)
|
|
|
|
iMngURL := strings.TrimSpace(s.iMngURL.Text)
|
|
|
|
|
2022-04-15 17:30:12 +02:00
|
|
|
defer s.wSettings.Close()
|
2024-06-19 10:09:35 +02:00
|
|
|
|
|
|
|
// If the management URL, pre-shared key, admin URL, Rosenpass permissive mode,
|
|
|
|
// interface name, or interface port have changed, we attempt to re-login with the new settings.
|
2024-06-19 12:27:37 +02:00
|
|
|
if s.managementURL != iMngURL || s.preSharedKey != s.iPreSharedKey.Text ||
|
|
|
|
s.adminURL != iAdminURL || s.RosenpassPermissive != s.sRosenpassPermissive.Checked ||
|
2024-06-19 10:09:35 +02:00
|
|
|
s.interfaceName != s.iInterfaceName.Text || s.interfacePort != int(port) {
|
2022-04-15 17:30:12 +02:00
|
|
|
|
2024-06-19 12:27:37 +02:00
|
|
|
s.managementURL = iMngURL
|
2022-04-15 17:30:12 +02:00
|
|
|
s.preSharedKey = s.iPreSharedKey.Text
|
2024-06-19 12:27:37 +02:00
|
|
|
s.adminURL = iAdminURL
|
2022-04-15 17:30:12 +02:00
|
|
|
|
2024-01-19 10:30:41 +01:00
|
|
|
loginRequest := proto.LoginRequest{
|
2024-06-19 12:27:37 +02:00
|
|
|
ManagementUrl: iMngURL,
|
|
|
|
AdminURL: iAdminURL,
|
2023-10-06 17:03:17 +02:00
|
|
|
IsLinuxDesktopClient: runtime.GOOS == "linux",
|
2024-06-19 10:09:35 +02:00
|
|
|
RosenpassPermissive: &s.sRosenpassPermissive.Checked,
|
|
|
|
InterfaceName: &s.iInterfaceName.Text,
|
|
|
|
WireguardPort: &port,
|
2024-01-19 10:30:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if s.iPreSharedKey.Text != "**********" {
|
|
|
|
loginRequest.OptionalPreSharedKey = &s.iPreSharedKey.Text
|
|
|
|
}
|
|
|
|
|
2024-06-19 10:09:35 +02:00
|
|
|
if err := s.restartClient(&loginRequest); err != nil {
|
|
|
|
log.Errorf("restarting client connection: %v", err)
|
2022-04-15 17:30:12 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
OnCancel: func() {
|
|
|
|
s.wSettings.Close()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-12 11:17:24 +02:00
|
|
|
func (s *serviceClient) login() error {
|
|
|
|
conn, err := s.getSrvClient(defaultFailTimeout)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("get client: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-10-06 18:28:46 +02:00
|
|
|
loginResp, err := conn.Login(s.ctx, &proto.LoginRequest{
|
|
|
|
IsLinuxDesktopClient: runtime.GOOS == "linux",
|
|
|
|
})
|
2022-05-12 11:17:24 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("login to management URL with: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if loginResp.NeedsSSOLogin {
|
|
|
|
err = open.Run(loginResp.VerificationURIComplete)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("opening the verification uri in the browser failed: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = conn.WaitSSOLogin(s.ctx, &proto.WaitSSOLoginRequest{UserCode: loginResp.UserCode})
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("waiting sso login failed with: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-15 17:30:12 +02:00
|
|
|
func (s *serviceClient) menuUpClick() error {
|
2022-04-18 09:43:37 +02:00
|
|
|
conn, err := s.getSrvClient(defaultFailTimeout)
|
2022-03-20 17:36:35 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("get client: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-27 19:16:58 +02:00
|
|
|
err = s.login()
|
2022-03-20 17:36:35 +01:00
|
|
|
if err != nil {
|
2022-05-28 18:37:08 +02:00
|
|
|
log.Errorf("login failed with: %v", err)
|
2022-03-20 17:36:35 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-27 19:16:58 +02:00
|
|
|
status, err := conn.Status(s.ctx, &proto.StatusRequest{})
|
2022-05-18 00:22:47 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("get service status: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-28 18:37:08 +02:00
|
|
|
if status.Status == string(internal.StatusConnected) {
|
2022-03-20 17:36:35 +01:00
|
|
|
log.Warnf("already connected")
|
2022-05-28 18:37:08 +02:00
|
|
|
return err
|
2022-03-20 17:36:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := s.conn.Up(s.ctx, &proto.UpRequest{}); err != nil {
|
|
|
|
log.Errorf("up service: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-15 17:30:12 +02:00
|
|
|
func (s *serviceClient) menuDownClick() error {
|
2022-04-18 09:43:37 +02:00
|
|
|
conn, err := s.getSrvClient(defaultFailTimeout)
|
2022-03-20 17:36:35 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("get client: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := conn.Status(s.ctx, &proto.StatusRequest{})
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("get service status: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if status.Status != string(internal.StatusConnected) {
|
|
|
|
log.Warnf("already down")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := s.conn.Down(s.ctx, &proto.DownRequest{}); err != nil {
|
|
|
|
log.Errorf("down service: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-18 09:43:37 +02:00
|
|
|
func (s *serviceClient) updateStatus() error {
|
|
|
|
conn, err := s.getSrvClient(defaultFailTimeout)
|
2022-03-20 17:36:35 +01:00
|
|
|
if err != nil {
|
2022-04-18 09:43:37 +02:00
|
|
|
return err
|
2022-03-20 17:36:35 +01:00
|
|
|
}
|
2022-04-18 09:43:37 +02:00
|
|
|
err = backoff.Retry(func() error {
|
|
|
|
status, err := conn.Status(s.ctx, &proto.StatusRequest{})
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("get service status: %v", err)
|
2024-05-21 15:45:49 +02:00
|
|
|
s.setDisconnectedStatus()
|
2022-04-18 09:43:37 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-10-30 10:32:48 +01:00
|
|
|
s.updateIndicationLock.Lock()
|
|
|
|
defer s.updateIndicationLock.Unlock()
|
|
|
|
|
2024-03-01 17:57:17 +01:00
|
|
|
// notify the user when the session has expired
|
|
|
|
if status.Status == string(internal.StatusNeedsLogin) {
|
|
|
|
s.onSessionExpire()
|
|
|
|
}
|
|
|
|
|
2023-10-30 10:32:48 +01:00
|
|
|
var systrayIconState bool
|
2022-10-12 12:25:06 +02:00
|
|
|
if status.Status == string(internal.StatusConnected) && !s.mUp.Disabled() {
|
2024-02-26 23:28:33 +01:00
|
|
|
s.connected = true
|
2024-03-01 17:57:17 +01:00
|
|
|
s.sendNotification = true
|
2024-02-26 23:28:33 +01:00
|
|
|
if s.isUpdateIconActive {
|
|
|
|
systray.SetIcon(s.icUpdateConnected)
|
|
|
|
} else {
|
2023-10-30 10:32:48 +01:00
|
|
|
systray.SetIcon(s.icConnected)
|
|
|
|
}
|
2022-10-26 14:34:30 +02:00
|
|
|
systray.SetTooltip("NetBird (Connected)")
|
2022-04-18 09:43:37 +02:00
|
|
|
s.mStatus.SetTitle("Connected")
|
|
|
|
s.mUp.Disable()
|
|
|
|
s.mDown.Enable()
|
2024-04-23 14:42:53 +02:00
|
|
|
s.mRoutes.Enable()
|
2023-10-30 10:32:48 +01:00
|
|
|
systrayIconState = true
|
2022-10-12 12:25:06 +02:00
|
|
|
} else if status.Status != string(internal.StatusConnected) && s.mUp.Disabled() {
|
2024-05-21 15:45:49 +02:00
|
|
|
s.setDisconnectedStatus()
|
2023-10-30 10:32:48 +01:00
|
|
|
systrayIconState = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// the updater struct notify by the upgrades available only, but if meanwhile the daemon has successfully
|
|
|
|
// updated must reset the mUpdate visibility state
|
|
|
|
if s.daemonVersion != status.DaemonVersion {
|
|
|
|
s.mUpdate.Hide()
|
|
|
|
s.daemonVersion = status.DaemonVersion
|
|
|
|
|
|
|
|
s.isUpdateIconActive = s.update.SetDaemonVersion(status.DaemonVersion)
|
|
|
|
if !s.isUpdateIconActive {
|
|
|
|
if systrayIconState {
|
|
|
|
systray.SetIcon(s.icConnected)
|
|
|
|
s.mAbout.SetIcon(s.icConnected)
|
|
|
|
} else {
|
|
|
|
systray.SetIcon(s.icDisconnected)
|
|
|
|
s.mAbout.SetIcon(s.icDisconnected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
daemonVersionTitle := normalizedVersion(s.daemonVersion)
|
|
|
|
s.mVersionDaemon.SetTitle(fmt.Sprintf("Daemon: %s", daemonVersionTitle))
|
|
|
|
s.mVersionDaemon.SetTooltip(fmt.Sprintf("Daemon version: %s", daemonVersionTitle))
|
|
|
|
s.mVersionDaemon.Show()
|
2022-04-18 09:43:37 +02:00
|
|
|
}
|
2023-10-30 10:32:48 +01:00
|
|
|
|
2022-04-18 09:43:37 +02:00
|
|
|
return nil
|
|
|
|
}, &backoff.ExponentialBackOff{
|
|
|
|
InitialInterval: time.Second,
|
|
|
|
RandomizationFactor: backoff.DefaultRandomizationFactor,
|
|
|
|
Multiplier: backoff.DefaultMultiplier,
|
|
|
|
MaxInterval: 300 * time.Millisecond,
|
|
|
|
MaxElapsedTime: 2 * time.Second,
|
|
|
|
Stop: backoff.Stop,
|
|
|
|
Clock: backoff.SystemClock,
|
|
|
|
})
|
2022-03-20 17:36:35 +01:00
|
|
|
|
|
|
|
if err != nil {
|
2022-04-18 09:43:37 +02:00
|
|
|
return err
|
2022-03-20 17:36:35 +01:00
|
|
|
}
|
|
|
|
|
2022-04-18 09:43:37 +02:00
|
|
|
return nil
|
2022-03-20 17:36:35 +01:00
|
|
|
}
|
|
|
|
|
2024-05-21 15:45:49 +02:00
|
|
|
func (s *serviceClient) setDisconnectedStatus() {
|
|
|
|
s.connected = false
|
|
|
|
if s.isUpdateIconActive {
|
|
|
|
systray.SetIcon(s.icUpdateDisconnected)
|
|
|
|
} else {
|
|
|
|
systray.SetIcon(s.icDisconnected)
|
|
|
|
}
|
|
|
|
systray.SetTooltip("NetBird (Disconnected)")
|
|
|
|
s.mStatus.SetTitle("Disconnected")
|
|
|
|
s.mDown.Disable()
|
|
|
|
s.mUp.Enable()
|
|
|
|
s.mRoutes.Disable()
|
|
|
|
}
|
|
|
|
|
2022-03-20 17:36:35 +01:00
|
|
|
func (s *serviceClient) onTrayReady() {
|
2022-04-15 17:30:12 +02:00
|
|
|
systray.SetIcon(s.icDisconnected)
|
2022-10-26 14:34:30 +02:00
|
|
|
systray.SetTooltip("NetBird")
|
2022-03-20 17:36:35 +01:00
|
|
|
|
2022-04-15 17:30:12 +02:00
|
|
|
// setup systray menu items
|
2022-03-25 13:21:04 +01:00
|
|
|
s.mStatus = systray.AddMenuItem("Disconnected", "Disconnected")
|
|
|
|
s.mStatus.Disable()
|
|
|
|
systray.AddSeparator()
|
2022-03-25 15:28:51 +01:00
|
|
|
s.mUp = systray.AddMenuItem("Connect", "Connect")
|
|
|
|
s.mDown = systray.AddMenuItem("Disconnect", "Disconnect")
|
2022-03-25 13:21:04 +01:00
|
|
|
s.mDown.Disable()
|
2024-04-23 14:42:53 +02:00
|
|
|
s.mAdminPanel = systray.AddMenuItem("Admin Panel", "Netbird Admin Panel")
|
2022-03-25 13:21:04 +01:00
|
|
|
systray.AddSeparator()
|
2024-06-19 10:09:35 +02:00
|
|
|
|
2022-04-15 17:30:12 +02:00
|
|
|
s.mSettings = systray.AddMenuItem("Settings", "Settings of the application")
|
2024-06-19 10:09:35 +02:00
|
|
|
s.mAllowSSH = s.mSettings.AddSubMenuItemCheckbox("Allow SSH", "Allow SSH connections", false)
|
|
|
|
s.mAutoConnect = s.mSettings.AddSubMenuItemCheckbox("Connect on Startup", "Connect automatically when the service starts", false)
|
|
|
|
s.mEnableRosenpass = s.mSettings.AddSubMenuItemCheckbox("Enable Quantum-Resistance", "Enable post-quantum security via Rosenpass", false)
|
|
|
|
s.mAdvancedSettings = s.mSettings.AddSubMenuItem("Advanced Settings", "Advanced settings of the application")
|
|
|
|
s.loadSettings()
|
|
|
|
|
2024-04-23 14:42:53 +02:00
|
|
|
s.mRoutes = systray.AddMenuItem("Network Routes", "Open the routes management window")
|
|
|
|
s.mRoutes.Disable()
|
2022-04-15 17:30:12 +02:00
|
|
|
systray.AddSeparator()
|
2023-10-30 10:32:48 +01:00
|
|
|
|
|
|
|
s.mAbout = systray.AddMenuItem("About", "About")
|
|
|
|
s.mAbout.SetIcon(s.icDisconnected)
|
|
|
|
versionString := normalizedVersion(version.NetbirdVersion())
|
|
|
|
s.mVersionUI = s.mAbout.AddSubMenuItem(fmt.Sprintf("GUI: %s", versionString), fmt.Sprintf("GUI Version: %s", versionString))
|
|
|
|
s.mVersionUI.Disable()
|
|
|
|
|
|
|
|
s.mVersionDaemon = s.mAbout.AddSubMenuItem("", "")
|
|
|
|
s.mVersionDaemon.Disable()
|
|
|
|
s.mVersionDaemon.Hide()
|
|
|
|
|
|
|
|
s.mUpdate = s.mAbout.AddSubMenuItem("Download latest version", "Download latest version")
|
|
|
|
s.mUpdate.Hide()
|
|
|
|
|
2022-05-27 13:56:12 +02:00
|
|
|
systray.AddSeparator()
|
2022-04-15 17:30:12 +02:00
|
|
|
s.mQuit = systray.AddMenuItem("Quit", "Quit the client app")
|
2022-03-20 17:36:35 +01:00
|
|
|
|
2023-10-30 10:32:48 +01:00
|
|
|
s.update.SetOnUpdateListener(s.onUpdateAvailable)
|
2022-03-25 13:21:04 +01:00
|
|
|
go func() {
|
2022-04-15 17:30:12 +02:00
|
|
|
s.getSrvConfig()
|
2022-03-25 13:21:04 +01:00
|
|
|
for {
|
2022-04-18 09:43:37 +02:00
|
|
|
err := s.updateStatus()
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("error while updating status: %v", err)
|
|
|
|
}
|
|
|
|
time.Sleep(2 * time.Second)
|
2022-03-25 13:21:04 +01:00
|
|
|
}
|
|
|
|
}()
|
2022-03-20 17:36:35 +01:00
|
|
|
|
2022-03-25 13:21:04 +01:00
|
|
|
go func() {
|
2022-03-20 17:36:35 +01:00
|
|
|
var err error
|
|
|
|
for {
|
|
|
|
select {
|
2022-04-15 17:30:12 +02:00
|
|
|
case <-s.mAdminPanel.ClickedCh:
|
|
|
|
err = open.Run(s.adminURL)
|
2022-03-20 17:36:35 +01:00
|
|
|
case <-s.mUp.ClickedCh:
|
2024-06-19 10:09:35 +02:00
|
|
|
s.mUp.Disable()
|
2022-05-28 18:37:08 +02:00
|
|
|
go func() {
|
2024-04-22 11:57:38 +02:00
|
|
|
defer s.mUp.Enable()
|
2022-05-28 18:37:08 +02:00
|
|
|
err := s.menuUpClick()
|
|
|
|
if err != nil {
|
2024-04-22 11:57:38 +02:00
|
|
|
s.runSelfCommand("error-msg", err.Error())
|
2022-05-28 18:37:08 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
2022-03-20 17:36:35 +01:00
|
|
|
case <-s.mDown.ClickedCh:
|
2024-04-22 11:57:38 +02:00
|
|
|
s.mDown.Disable()
|
2022-05-28 18:37:08 +02:00
|
|
|
go func() {
|
2024-04-22 11:57:38 +02:00
|
|
|
defer s.mDown.Enable()
|
2022-05-28 18:37:08 +02:00
|
|
|
err := s.menuDownClick()
|
|
|
|
if err != nil {
|
2024-04-22 11:57:38 +02:00
|
|
|
s.runSelfCommand("error-msg", err.Error())
|
2022-05-28 18:37:08 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
2024-06-19 10:09:35 +02:00
|
|
|
case <-s.mAllowSSH.ClickedCh:
|
|
|
|
if s.mAllowSSH.Checked() {
|
|
|
|
s.mAllowSSH.Uncheck()
|
|
|
|
} else {
|
|
|
|
s.mAllowSSH.Check()
|
|
|
|
}
|
|
|
|
if err := s.updateConfig(); err != nil {
|
|
|
|
log.Errorf("failed to update config: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
case <-s.mAutoConnect.ClickedCh:
|
|
|
|
if s.mAutoConnect.Checked() {
|
|
|
|
s.mAutoConnect.Uncheck()
|
|
|
|
} else {
|
|
|
|
s.mAutoConnect.Check()
|
|
|
|
}
|
|
|
|
if err := s.updateConfig(); err != nil {
|
|
|
|
log.Errorf("failed to update config: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
case <-s.mEnableRosenpass.ClickedCh:
|
|
|
|
if s.mEnableRosenpass.Checked() {
|
|
|
|
s.mEnableRosenpass.Uncheck()
|
|
|
|
} else {
|
|
|
|
s.mEnableRosenpass.Check()
|
|
|
|
}
|
|
|
|
if err := s.updateConfig(); err != nil {
|
|
|
|
log.Errorf("failed to update config: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
case <-s.mAdvancedSettings.ClickedCh:
|
|
|
|
s.mAdvancedSettings.Disable()
|
2022-04-15 17:30:12 +02:00
|
|
|
go func() {
|
2024-06-19 10:09:35 +02:00
|
|
|
defer s.mAdvancedSettings.Enable()
|
2024-04-22 11:57:38 +02:00
|
|
|
defer s.getSrvConfig()
|
|
|
|
s.runSelfCommand("settings", "true")
|
2022-04-15 17:30:12 +02:00
|
|
|
}()
|
|
|
|
case <-s.mQuit.ClickedCh:
|
2022-03-20 17:36:35 +01:00
|
|
|
systray.Quit()
|
|
|
|
return
|
2023-10-30 10:32:48 +01:00
|
|
|
case <-s.mUpdate.ClickedCh:
|
|
|
|
err := openURL(version.DownloadUrl())
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("%s", err)
|
|
|
|
}
|
2024-04-23 14:42:53 +02:00
|
|
|
case <-s.mRoutes.ClickedCh:
|
|
|
|
s.mRoutes.Disable()
|
|
|
|
go func() {
|
|
|
|
defer s.mRoutes.Enable()
|
|
|
|
s.runSelfCommand("routes", "true")
|
|
|
|
}()
|
2022-03-20 17:36:35 +01:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("process connection: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2024-04-22 11:57:38 +02:00
|
|
|
func (s *serviceClient) runSelfCommand(command, arg string) {
|
|
|
|
proc, err := os.Executable()
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("show %s failed with error: %v", command, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := exec.Command(proc, fmt.Sprintf("--%s=%s", command, arg))
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if exitErr, ok := err.(*exec.ExitError); ok && exitErr.ExitCode() == 1 {
|
|
|
|
log.Errorf("start %s UI: %v, %s", command, err, string(out))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(out) != 0 {
|
|
|
|
log.Infof("command %s executed: %s", command, string(out))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-30 10:32:48 +01:00
|
|
|
func normalizedVersion(version string) string {
|
|
|
|
versionString := version
|
|
|
|
if unicode.IsDigit(rune(versionString[0])) {
|
|
|
|
versionString = fmt.Sprintf("v%s", versionString)
|
|
|
|
}
|
|
|
|
return versionString
|
|
|
|
}
|
|
|
|
|
2022-03-20 17:36:35 +01:00
|
|
|
func (s *serviceClient) onTrayExit() {}
|
|
|
|
|
2022-04-15 17:30:12 +02:00
|
|
|
// getSrvClient connection to the service.
|
|
|
|
func (s *serviceClient) getSrvClient(timeout time.Duration) (proto.DaemonServiceClient, error) {
|
2022-03-20 17:36:35 +01:00
|
|
|
if s.conn != nil {
|
|
|
|
return s.conn, nil
|
|
|
|
}
|
|
|
|
|
2022-04-15 17:30:12 +02:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
2022-03-20 17:36:35 +01:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
conn, err := grpc.DialContext(
|
|
|
|
ctx,
|
|
|
|
strings.TrimPrefix(s.addr, "tcp://"),
|
|
|
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
|
|
|
grpc.WithBlock(),
|
2022-05-25 23:25:02 +02:00
|
|
|
grpc.WithUserAgent(system.GetDesktopUIUserAgent()),
|
2022-03-20 17:36:35 +01:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("dial service: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.conn = proto.NewDaemonServiceClient(conn)
|
|
|
|
return s.conn, nil
|
|
|
|
}
|
2022-03-23 18:24:25 +01:00
|
|
|
|
2022-04-15 17:30:12 +02:00
|
|
|
// getSrvConfig from the service to show it in the settings window.
|
|
|
|
func (s *serviceClient) getSrvConfig() {
|
2023-12-27 20:56:04 +01:00
|
|
|
s.managementURL = internal.DefaultManagementURL
|
|
|
|
s.adminURL = internal.DefaultAdminURL
|
2022-04-15 17:30:12 +02:00
|
|
|
|
2022-04-18 09:43:37 +02:00
|
|
|
conn, err := s.getSrvClient(failFastTimeout)
|
2022-04-15 17:30:12 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("get client: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg, err := conn.GetConfig(s.ctx, &proto.GetConfigRequest{})
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("get config settings from server: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.ManagementUrl != "" {
|
|
|
|
s.managementURL = cfg.ManagementUrl
|
|
|
|
}
|
|
|
|
if cfg.AdminURL != "" {
|
|
|
|
s.adminURL = cfg.AdminURL
|
|
|
|
}
|
|
|
|
s.preSharedKey = cfg.PreSharedKey
|
2024-06-19 10:09:35 +02:00
|
|
|
s.RosenpassPermissive = cfg.RosenpassPermissive
|
|
|
|
s.interfaceName = cfg.InterfaceName
|
|
|
|
s.interfacePort = int(cfg.WireguardPort)
|
2022-04-15 17:30:12 +02:00
|
|
|
|
2024-06-19 10:09:35 +02:00
|
|
|
if s.showAdvancedSettings {
|
2022-04-15 17:30:12 +02:00
|
|
|
s.iMngURL.SetText(s.managementURL)
|
|
|
|
s.iAdminURL.SetText(s.adminURL)
|
|
|
|
s.iConfigFile.SetText(cfg.ConfigFile)
|
|
|
|
s.iLogFile.SetText(cfg.LogFile)
|
|
|
|
s.iPreSharedKey.SetText(cfg.PreSharedKey)
|
2024-06-19 10:09:35 +02:00
|
|
|
s.iInterfaceName.SetText(cfg.InterfaceName)
|
|
|
|
s.iInterfacePort.SetText(strconv.Itoa(int(cfg.WireguardPort)))
|
|
|
|
s.sRosenpassPermissive.SetChecked(cfg.RosenpassPermissive)
|
|
|
|
if !cfg.RosenpassEnabled {
|
|
|
|
s.sRosenpassPermissive.Disable()
|
|
|
|
}
|
|
|
|
|
2022-04-15 17:30:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-30 10:32:48 +01:00
|
|
|
func (s *serviceClient) onUpdateAvailable() {
|
|
|
|
s.updateIndicationLock.Lock()
|
|
|
|
defer s.updateIndicationLock.Unlock()
|
|
|
|
|
|
|
|
s.mUpdate.Show()
|
|
|
|
s.isUpdateIconActive = true
|
2024-02-26 23:28:33 +01:00
|
|
|
|
|
|
|
if s.connected {
|
|
|
|
systray.SetIcon(s.icUpdateConnected)
|
|
|
|
} else {
|
|
|
|
systray.SetIcon(s.icUpdateDisconnected)
|
|
|
|
}
|
2023-10-30 10:32:48 +01:00
|
|
|
}
|
|
|
|
|
2024-03-01 17:57:17 +01:00
|
|
|
// onSessionExpire sends a notification to the user when the session expires.
|
|
|
|
func (s *serviceClient) onSessionExpire() {
|
|
|
|
if s.sendNotification {
|
|
|
|
title := "Connection session expired"
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
title = "NetBird connection session expired"
|
|
|
|
}
|
|
|
|
s.app.SendNotification(
|
|
|
|
fyne.NewNotification(
|
|
|
|
title,
|
|
|
|
"Please re-authenticate to connect to the network",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
s.sendNotification = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-19 10:09:35 +02:00
|
|
|
// loadSettings loads the settings from the config file and updates the UI elements accordingly.
|
|
|
|
func (s *serviceClient) loadSettings() {
|
|
|
|
conn, err := s.getSrvClient(failFastTimeout)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("get client: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg, err := conn.GetConfig(s.ctx, &proto.GetConfigRequest{})
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("get config settings from server: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.ServerSSHAllowed {
|
|
|
|
s.mAllowSSH.Check()
|
|
|
|
} else {
|
|
|
|
s.mAllowSSH.Uncheck()
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.DisableAutoConnect {
|
|
|
|
s.mAutoConnect.Uncheck()
|
|
|
|
} else {
|
|
|
|
s.mAutoConnect.Check()
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.RosenpassEnabled {
|
|
|
|
s.mEnableRosenpass.Check()
|
|
|
|
} else {
|
|
|
|
s.mEnableRosenpass.Uncheck()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// updateConfig updates the configuration parameters
|
|
|
|
// based on the values selected in the settings window.
|
|
|
|
func (s *serviceClient) updateConfig() error {
|
|
|
|
disableAutoStart := !s.mAutoConnect.Checked()
|
|
|
|
sshAllowed := s.mAllowSSH.Checked()
|
|
|
|
rosenpassEnabled := s.mEnableRosenpass.Checked()
|
|
|
|
|
|
|
|
loginRequest := proto.LoginRequest{
|
|
|
|
IsLinuxDesktopClient: runtime.GOOS == "linux",
|
|
|
|
ServerSSHAllowed: &sshAllowed,
|
|
|
|
RosenpassEnabled: &rosenpassEnabled,
|
|
|
|
DisableAutoConnect: &disableAutoStart,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.restartClient(&loginRequest); err != nil {
|
|
|
|
log.Errorf("restarting client connection: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// restartClient restarts the client connection.
|
|
|
|
func (s *serviceClient) restartClient(loginRequest *proto.LoginRequest) error {
|
|
|
|
client, err := s.getSrvClient(failFastTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = client.Login(s.ctx, loginRequest)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = client.Up(s.ctx, &proto.UpRequest{})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-30 10:32:48 +01:00
|
|
|
func openURL(url string) error {
|
|
|
|
var err error
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "windows":
|
|
|
|
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
|
|
|
|
case "darwin":
|
|
|
|
err = exec.Command("open", url).Start()
|
|
|
|
case "linux":
|
|
|
|
err = exec.Command("xdg-open", url).Start()
|
|
|
|
default:
|
|
|
|
err = fmt.Errorf("unsupported platform")
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|