mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 16:26:38 +00:00
updated
This commit is contained in:
@@ -1,5 +1,12 @@
|
|||||||
package dns
|
package dns
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
type iosHostManager struct {
|
type iosHostManager struct {
|
||||||
dnsManager IosDnsManager
|
dnsManager IosDnsManager
|
||||||
config HostDNSConfig
|
config HostDNSConfig
|
||||||
@@ -12,7 +19,23 @@ func newHostManager(wgInterface WGIface, dnsManager IosDnsManager) (hostManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a iosHostManager) applyDNSConfig(config HostDNSConfig) error {
|
func (a iosHostManager) applyDNSConfig(config HostDNSConfig) error {
|
||||||
a.dnsManager.applyDns("bla")
|
var configAsString []string
|
||||||
|
configAsString = append(configAsString, config.serverIP)
|
||||||
|
configAsString = append(configAsString, strconv.Itoa(config.serverPort))
|
||||||
|
configAsString = append(configAsString, strconv.FormatBool(config.routeAll))
|
||||||
|
var domainConfigAsString []string
|
||||||
|
for _, domain := range config.domains {
|
||||||
|
var domainAsString []string
|
||||||
|
domainAsString = append(domainAsString, strconv.FormatBool(domain.disabled))
|
||||||
|
domainAsString = append(domainAsString, domain.domain)
|
||||||
|
domainAsString = append(domainAsString, strconv.FormatBool(domain.matchOnly))
|
||||||
|
domainConfigAsString = append(domainConfigAsString, strings.Join(domainAsString, "|"))
|
||||||
|
}
|
||||||
|
domainConfig := strings.Join(domainConfigAsString, ";")
|
||||||
|
configAsString = append(configAsString, domainConfig)
|
||||||
|
outputString := strings.Join(configAsString, ",")
|
||||||
|
log.Debug("applyDNSConfig: " + outputString)
|
||||||
|
a.dnsManager.ApplyDns(outputString)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ type ReadyListener interface {
|
|||||||
|
|
||||||
// IosDnsManager is a dns manager interface for iosß
|
// IosDnsManager is a dns manager interface for iosß
|
||||||
type IosDnsManager interface {
|
type IosDnsManager interface {
|
||||||
applyDns(string)
|
ApplyDns(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server is a dns server interface
|
// Server is a dns server interface
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ func (e *Engine) Start() error {
|
|||||||
log.Debugf("Initial routes contain %d routes", len(routes))
|
log.Debugf("Initial routes contain %d routes", len(routes))
|
||||||
e.routeManager = routemanager.NewManager(e.ctx, e.config.WgPrivateKey.PublicKey().String(), e.wgInterface, e.statusRecorder, routes)
|
e.routeManager = routemanager.NewManager(e.ctx, e.config.WgPrivateKey.PublicKey().String(), e.wgInterface, e.statusRecorder, routes)
|
||||||
e.mobileDep.RouteListener.SetInterfaceIP(wgAddr)
|
e.mobileDep.RouteListener.SetInterfaceIP(wgAddr)
|
||||||
|
|
||||||
e.routeManager.SetRouteChangeListener(e.mobileDep.RouteListener)
|
e.routeManager.SetRouteChangeListener(e.mobileDep.RouteListener)
|
||||||
|
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
package netbird
|
package NetBirdSDK
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/internal"
|
"github.com/netbirdio/netbird/client/internal"
|
||||||
|
"github.com/netbirdio/netbird/client/internal/auth"
|
||||||
"github.com/netbirdio/netbird/client/internal/dns"
|
"github.com/netbirdio/netbird/client/internal/dns"
|
||||||
"github.com/netbirdio/netbird/client/internal/peer"
|
"github.com/netbirdio/netbird/client/internal/peer"
|
||||||
"github.com/netbirdio/netbird/client/internal/routemanager"
|
"github.com/netbirdio/netbird/client/internal/routemanager"
|
||||||
@@ -14,11 +16,6 @@ import (
|
|||||||
"github.com/netbirdio/netbird/formatter"
|
"github.com/netbirdio/netbird/formatter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConnectionListener export internal Listener for mobile
|
|
||||||
type ConnectionListener interface {
|
|
||||||
peer.Listener
|
|
||||||
}
|
|
||||||
|
|
||||||
// RouteListener export internal RouteListener for mobile
|
// RouteListener export internal RouteListener for mobile
|
||||||
type RouteListener interface {
|
type RouteListener interface {
|
||||||
routemanager.RouteListener
|
routemanager.RouteListener
|
||||||
@@ -47,16 +44,21 @@ type Client struct {
|
|||||||
ctxCancel context.CancelFunc
|
ctxCancel context.CancelFunc
|
||||||
ctxCancelLock *sync.Mutex
|
ctxCancelLock *sync.Mutex
|
||||||
deviceName string
|
deviceName string
|
||||||
|
osName string
|
||||||
|
osVersion string
|
||||||
routeListener routemanager.RouteListener
|
routeListener routemanager.RouteListener
|
||||||
onHostDnsFn func([]string)
|
onHostDnsFn func([]string)
|
||||||
dnsManager dns.IosDnsManager
|
dnsManager dns.IosDnsManager
|
||||||
|
loginComplete bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient instantiate a new Client
|
// NewClient instantiate a new Client
|
||||||
func NewClient(cfgFile, deviceName string, routeListener RouteListener, dnsManager DnsManager) *Client {
|
func NewClient(cfgFile, deviceName string, osVersion string, osName string, routeListener RouteListener, dnsManager DnsManager) *Client {
|
||||||
return &Client{
|
return &Client{
|
||||||
cfgFile: cfgFile,
|
cfgFile: cfgFile,
|
||||||
deviceName: deviceName,
|
deviceName: deviceName,
|
||||||
|
osName: osName,
|
||||||
|
osVersion: osVersion,
|
||||||
recorder: peer.NewRecorder(""),
|
recorder: peer.NewRecorder(""),
|
||||||
ctxCancelLock: &sync.Mutex{},
|
ctxCancelLock: &sync.Mutex{},
|
||||||
routeListener: routeListener,
|
routeListener: routeListener,
|
||||||
@@ -78,14 +80,15 @@ func (c *Client) Run(fd int32) error {
|
|||||||
var ctx context.Context
|
var ctx context.Context
|
||||||
//nolint
|
//nolint
|
||||||
ctxWithValues := context.WithValue(context.Background(), system.DeviceNameCtxKey, c.deviceName)
|
ctxWithValues := context.WithValue(context.Background(), system.DeviceNameCtxKey, c.deviceName)
|
||||||
|
ctxWithValues = context.WithValue(ctxWithValues, system.OsNameCtxKey, c.osName)
|
||||||
|
ctxWithValues = context.WithValue(ctxWithValues, system.OsVersionCtxKey, c.osVersion)
|
||||||
c.ctxCancelLock.Lock()
|
c.ctxCancelLock.Lock()
|
||||||
ctx, c.ctxCancel = context.WithCancel(ctxWithValues)
|
ctx, c.ctxCancel = context.WithCancel(ctxWithValues)
|
||||||
defer c.ctxCancel()
|
defer c.ctxCancel()
|
||||||
c.ctxCancelLock.Unlock()
|
c.ctxCancelLock.Unlock()
|
||||||
|
|
||||||
auth := NewAuthWithConfig(ctx, cfg)
|
auth := NewAuthWithConfig(ctx, cfg)
|
||||||
// err = auth.login(urlOpener)
|
err = auth.Login()
|
||||||
auth.loginWithSetupKeyAndSaveConfig("C3803F45-435B-4333-96EB-50F9EC723355", "iPhone")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -97,32 +100,6 @@ func (c *Client) Run(fd int32) error {
|
|||||||
return internal.RunClientiOS(ctx, cfg, c.recorder, fd, c.routeListener, c.dnsManager)
|
return internal.RunClientiOS(ctx, cfg, c.recorder, fd, c.routeListener, c.dnsManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Auth(urlOpener URLOpener) error {
|
|
||||||
cfg, err := internal.UpdateOrCreateConfig(internal.ConfigInput{
|
|
||||||
ConfigPath: c.cfgFile,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.recorder.UpdateManagementAddress(cfg.ManagementURL.String())
|
|
||||||
|
|
||||||
var ctx context.Context
|
|
||||||
//nolint
|
|
||||||
ctxWithValues := context.WithValue(context.Background(), system.DeviceNameCtxKey, c.deviceName)
|
|
||||||
c.ctxCancelLock.Lock()
|
|
||||||
ctx, c.ctxCancel = context.WithCancel(ctxWithValues)
|
|
||||||
defer c.ctxCancel()
|
|
||||||
c.ctxCancelLock.Unlock()
|
|
||||||
|
|
||||||
auth := NewAuthWithConfig(ctx, cfg)
|
|
||||||
err = auth.login(urlOpener)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop the internal client and free the resources
|
// Stop the internal client and free the resources
|
||||||
func (c *Client) Stop() {
|
func (c *Client) Stop() {
|
||||||
c.ctxCancelLock.Lock()
|
c.ctxCancelLock.Lock()
|
||||||
@@ -139,8 +116,8 @@ func (c *Client) SetTraceLogLevel() {
|
|||||||
log.SetLevel(log.TraceLevel)
|
log.SetLevel(log.TraceLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PeersList return with the list of the PeerInfos
|
// getStatusDetails return with the list of the PeerInfos
|
||||||
func (c *Client) PeersList() *PeerInfoArray {
|
func (c *Client) GetStatusDetails() *StatusDetails {
|
||||||
|
|
||||||
fullStatus := c.recorder.GetFullStatus()
|
fullStatus := c.recorder.GetFullStatus()
|
||||||
|
|
||||||
@@ -153,26 +130,70 @@ func (c *Client) PeersList() *PeerInfoArray {
|
|||||||
}
|
}
|
||||||
peerInfos[n] = pi
|
peerInfos[n] = pi
|
||||||
}
|
}
|
||||||
return &PeerInfoArray{items: peerInfos}
|
return &StatusDetails{items: peerInfos, fqdn: fullStatus.LocalPeerState.FQDN, ip: fullStatus.LocalPeerState.IP}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnUpdatedHostDNS update the DNS servers addresses for root zones
|
func (c *Client) GetManagementStatus() bool {
|
||||||
func (c *Client) OnUpdatedHostDNS(list *DNSList) error {
|
return c.recorder.GetFullStatus().ManagementState.Connected
|
||||||
dnsServer, err := dns.GetServerDns()
|
}
|
||||||
|
|
||||||
|
func (c *Client) IsLoginRequired() bool {
|
||||||
|
var ctx context.Context
|
||||||
|
ctxWithValues := context.WithValue(context.Background(), system.DeviceNameCtxKey, c.deviceName)
|
||||||
|
c.ctxCancelLock.Lock()
|
||||||
|
defer c.ctxCancelLock.Unlock()
|
||||||
|
ctx, c.ctxCancel = context.WithCancel(ctxWithValues)
|
||||||
|
|
||||||
|
cfg, _ := internal.UpdateOrCreateConfig(internal.ConfigInput{
|
||||||
|
ConfigPath: c.cfgFile,
|
||||||
|
})
|
||||||
|
|
||||||
|
needsLogin, _ := internal.IsLoginRequired(ctx, cfg.PrivateKey, cfg.ManagementURL, cfg.SSHKey)
|
||||||
|
return needsLogin
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) LoginForMobile() string {
|
||||||
|
var ctx context.Context
|
||||||
|
ctxWithValues := context.WithValue(context.Background(), system.DeviceNameCtxKey, c.deviceName)
|
||||||
|
c.ctxCancelLock.Lock()
|
||||||
|
defer c.ctxCancelLock.Unlock()
|
||||||
|
ctx, c.ctxCancel = context.WithCancel(ctxWithValues)
|
||||||
|
|
||||||
|
cfg, _ := internal.UpdateOrCreateConfig(internal.ConfigInput{
|
||||||
|
ConfigPath: c.cfgFile,
|
||||||
|
})
|
||||||
|
|
||||||
|
oAuthFlow, err := auth.NewOAuthFlow(ctx, cfg, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
dnsServer.OnUpdatedHostDNSServer(list.items)
|
flowInfo, err := oAuthFlow.RequestAuthInfo(context.TODO())
|
||||||
return nil
|
if err != nil {
|
||||||
|
return err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
// This could cause a potential race condition with loading the extension which need to be handled on swift side
|
||||||
|
go func() {
|
||||||
|
waitTimeout := time.Duration(flowInfo.ExpiresIn)
|
||||||
|
waitCTX, cancel := context.WithTimeout(ctx, waitTimeout*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
tokenInfo, err := oAuthFlow.WaitToken(waitCTX, flowInfo)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
jwtToken := tokenInfo.GetTokenToUse()
|
||||||
|
_ = internal.Login(ctx, cfg, "", jwtToken)
|
||||||
|
c.loginComplete = true
|
||||||
|
}()
|
||||||
|
|
||||||
|
return flowInfo.VerificationURIComplete
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetConnectionListener set the network connection listener
|
func (c *Client) IsLoginComplete() bool {
|
||||||
func (c *Client) SetConnectionListener(listener ConnectionListener) {
|
return c.loginComplete
|
||||||
c.recorder.SetConnectionListener(listener)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveConnectionListener remove connection listener
|
func (c *Client) ClearLoginComplete() {
|
||||||
func (c *Client) RemoveConnectionListener() {
|
c.loginComplete = false
|
||||||
c.recorder.RemoveConnectionListener()
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package netbird
|
package NetBirdSDK
|
||||||
|
|
||||||
import _ "golang.org/x/mobile/bind"
|
import _ "golang.org/x/mobile/bind"
|
||||||
|
|
||||||
16
client/ios/NetBirdSDK/logger.go
Normal file
16
client/ios/NetBirdSDK/logger.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package NetBirdSDK
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/netbirdio/netbird/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
var logFile *os.File
|
||||||
|
|
||||||
|
// InitializeLog initializes the log file.
|
||||||
|
func InitializeLog(logLevel string, filePath string) error {
|
||||||
|
var err error
|
||||||
|
err = util.InitLog(logLevel, filePath)
|
||||||
|
return err
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package netbird
|
package NetBirdSDK
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -70,18 +70,7 @@ func NewAuthWithConfig(ctx context.Context, config *internal.Config) *Auth {
|
|||||||
// SaveConfigIfSSOSupported test the connectivity with the management server by retrieving the server device flow info.
|
// SaveConfigIfSSOSupported test the connectivity with the management server by retrieving the server device flow info.
|
||||||
// If it returns a flow info than save the configuration and return true. If it gets a codes.NotFound, it means that SSO
|
// If it returns a flow info than save the configuration and return true. If it gets a codes.NotFound, it means that SSO
|
||||||
// is not supported and returns false without saving the configuration. For other errors return false.
|
// is not supported and returns false without saving the configuration. For other errors return false.
|
||||||
func (a *Auth) SaveConfigIfSSOSupported(listener SSOListener) {
|
func (a *Auth) SaveConfigIfSSOSupported() (bool, error) {
|
||||||
go func() {
|
|
||||||
sso, err := a.saveConfigIfSSOSupported()
|
|
||||||
if err != nil {
|
|
||||||
listener.OnError(err)
|
|
||||||
} else {
|
|
||||||
listener.OnSuccess(sso)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Auth) saveConfigIfSSOSupported() (bool, error) {
|
|
||||||
supportsSSO := true
|
supportsSSO := true
|
||||||
err := a.withBackOff(a.ctx, func() (err error) {
|
err := a.withBackOff(a.ctx, func() (err error) {
|
||||||
_, err = internal.GetDeviceAuthorizationFlowInfo(a.ctx, a.config.PrivateKey, a.config.ManagementURL)
|
_, err = internal.GetDeviceAuthorizationFlowInfo(a.ctx, a.config.PrivateKey, a.config.ManagementURL)
|
||||||
@@ -111,18 +100,7 @@ func (a *Auth) saveConfigIfSSOSupported() (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LoginWithSetupKeyAndSaveConfig test the connectivity with the management server with the setup key.
|
// LoginWithSetupKeyAndSaveConfig test the connectivity with the management server with the setup key.
|
||||||
func (a *Auth) LoginWithSetupKeyAndSaveConfig(resultListener ErrListener, setupKey string, deviceName string) {
|
func (a *Auth) LoginWithSetupKeyAndSaveConfig(setupKey string, deviceName string) error {
|
||||||
go func() {
|
|
||||||
err := a.loginWithSetupKeyAndSaveConfig(setupKey, deviceName)
|
|
||||||
if err != nil {
|
|
||||||
resultListener.OnError(err)
|
|
||||||
} else {
|
|
||||||
resultListener.OnSuccess()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Auth) loginWithSetupKeyAndSaveConfig(setupKey string, deviceName string) error {
|
|
||||||
//nolint
|
//nolint
|
||||||
ctxWithValues := context.WithValue(a.ctx, system.DeviceNameCtxKey, deviceName)
|
ctxWithValues := context.WithValue(a.ctx, system.DeviceNameCtxKey, deviceName)
|
||||||
|
|
||||||
@@ -141,19 +119,7 @@ func (a *Auth) loginWithSetupKeyAndSaveConfig(setupKey string, deviceName string
|
|||||||
return internal.WriteOutConfig(a.cfgPath, a.config)
|
return internal.WriteOutConfig(a.cfgPath, a.config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Login try register the client on the server
|
func (a *Auth) Login() error {
|
||||||
func (a *Auth) Login(resultListener ErrListener, urlOpener URLOpener) {
|
|
||||||
go func() {
|
|
||||||
err := a.login(urlOpener)
|
|
||||||
if err != nil {
|
|
||||||
resultListener.OnError(err)
|
|
||||||
} else {
|
|
||||||
resultListener.OnSuccess()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Auth) login(urlOpener URLOpener) error {
|
|
||||||
var needsLogin bool
|
var needsLogin bool
|
||||||
|
|
||||||
// check if we need to generate JWT token
|
// check if we need to generate JWT token
|
||||||
@@ -167,11 +133,7 @@ func (a *Auth) login(urlOpener URLOpener) error {
|
|||||||
|
|
||||||
jwtToken := ""
|
jwtToken := ""
|
||||||
if needsLogin {
|
if needsLogin {
|
||||||
tokenInfo, err := a.foregroundGetTokenInfo(urlOpener)
|
return fmt.Errorf("Not authenticated")
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("interactive sso login failed: %v", err)
|
|
||||||
}
|
|
||||||
jwtToken = tokenInfo.GetTokenToUse()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = a.withBackOff(a.ctx, func() error {
|
err = a.withBackOff(a.ctx, func() error {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package netbird
|
package NetBirdSDK
|
||||||
|
|
||||||
// PeerInfo describe information about the peers. It designed for the UI usage
|
// PeerInfo describe information about the peers. It designed for the UI usage
|
||||||
type PeerInfo struct {
|
type PeerInfo struct {
|
||||||
@@ -12,25 +12,39 @@ type PeerInfoCollection interface {
|
|||||||
Add(s string) PeerInfoCollection
|
Add(s string) PeerInfoCollection
|
||||||
Get(i int) string
|
Get(i int) string
|
||||||
Size() int
|
Size() int
|
||||||
|
GetFQDN() string
|
||||||
|
GetIP() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// PeerInfoArray is the implementation of the PeerInfoCollection
|
// StatusDetails is the implementation of the PeerInfoCollection
|
||||||
type PeerInfoArray struct {
|
type StatusDetails struct {
|
||||||
items []PeerInfo
|
items []PeerInfo
|
||||||
|
fqdn string
|
||||||
|
ip string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add new PeerInfo to the collection
|
// Add new PeerInfo to the collection
|
||||||
func (array PeerInfoArray) Add(s PeerInfo) PeerInfoArray {
|
func (array StatusDetails) Add(s PeerInfo) StatusDetails {
|
||||||
array.items = append(array.items, s)
|
array.items = append(array.items, s)
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get return an element of the collection
|
// Get return an element of the collection
|
||||||
func (array PeerInfoArray) Get(i int) *PeerInfo {
|
func (array StatusDetails) Get(i int) *PeerInfo {
|
||||||
return &array.items[i]
|
return &array.items[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Size return with the size of the collection
|
// Size return with the size of the collection
|
||||||
func (array PeerInfoArray) Size() int {
|
func (array StatusDetails) Size() int {
|
||||||
return len(array.items)
|
return len(array.items)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetFQDN return with the FQDN of the local peer
|
||||||
|
func (array StatusDetails) GetFQDN() string {
|
||||||
|
return array.fqdn
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetIP return with the IP of the local peer
|
||||||
|
func (array StatusDetails) GetIP() string {
|
||||||
|
return array.ip
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package netbird
|
package NetBirdSDK
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/netbirdio/netbird/client/internal"
|
"github.com/netbirdio/netbird/client/internal"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package netbird
|
package NetBirdSDK
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package netbird
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
// DNSList is a wrapper of []string
|
|
||||||
type DNSList struct {
|
|
||||||
items []string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add new DNS address to the collection
|
|
||||||
func (array *DNSList) Add(s string) {
|
|
||||||
array.items = append(array.items, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get return an element of the collection
|
|
||||||
func (array *DNSList) Get(i int) (string, error) {
|
|
||||||
if i >= len(array.items) || i < 0 {
|
|
||||||
return "", fmt.Errorf("out of range")
|
|
||||||
}
|
|
||||||
return array.items[i], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Size return with the size of the collection
|
|
||||||
func (array *DNSList) Size() int {
|
|
||||||
return len(array.items)
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package netbird
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
func TestDNSList_Get(t *testing.T) {
|
|
||||||
l := DNSList{
|
|
||||||
items: make([]string, 1),
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := l.Get(0)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("invalid error: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = l.Get(-1)
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("expected error but got nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = l.Get(1)
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("expected error but got nil")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package netbird
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
var logFile *os.File
|
|
||||||
|
|
||||||
// InitializeLog initializes the log file.
|
|
||||||
func InitializeLog(logLevel string, filePath string) error {
|
|
||||||
var err error
|
|
||||||
err = util.InitLog(logLevel, filePath)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// // CloseLog closes the log file.
|
|
||||||
// func CloseLog() {
|
|
||||||
// if logFile != nil {
|
|
||||||
// logFile.Close()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // Log writes a message to the log file.
|
|
||||||
// func Log(message string) {
|
|
||||||
// if logFile != nil {
|
|
||||||
// ts := time.Now().Format(time.RFC3339)
|
|
||||||
// fmt.Fprintf(logFile, "%s: %s\n", ts, message)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
@@ -12,6 +12,12 @@ import (
|
|||||||
// DeviceNameCtxKey context key for device name
|
// DeviceNameCtxKey context key for device name
|
||||||
const DeviceNameCtxKey = "deviceName"
|
const DeviceNameCtxKey = "deviceName"
|
||||||
|
|
||||||
|
// OsVersionCtxKey context key for operating system version
|
||||||
|
const OsVersionCtxKey = "OsVersion"
|
||||||
|
|
||||||
|
// OsNameCtxKey context key for operating system name
|
||||||
|
const OsNameCtxKey = "OsName"
|
||||||
|
|
||||||
// Info is an object that contains machine information
|
// Info is an object that contains machine information
|
||||||
// Most of the code is taken from https://github.com/matishsiao/goInfo
|
// Most of the code is taken from https://github.com/matishsiao/goInfo
|
||||||
type Info struct {
|
type Info struct {
|
||||||
@@ -52,6 +58,24 @@ func extractDeviceName(ctx context.Context, defaultName string) string {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// extractOsVersion extracts operating system version from context or returns the default
|
||||||
|
func extractOsVersion(ctx context.Context, defaultName string) string {
|
||||||
|
v, ok := ctx.Value(OsVersionCtxKey).(string)
|
||||||
|
if !ok {
|
||||||
|
return defaultName
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// extractOsName extracts operating system name from context or returns the default
|
||||||
|
func extractOsName(ctx context.Context, defaultName string) string {
|
||||||
|
v, ok := ctx.Value(OsNameCtxKey).(string)
|
||||||
|
if !ok {
|
||||||
|
return defaultName
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
// GetDesktopUIUserAgent returns the Desktop ui user agent
|
// GetDesktopUIUserAgent returns the Desktop ui user agent
|
||||||
func GetDesktopUIUserAgent() string {
|
func GetDesktopUIUserAgent() string {
|
||||||
return "netbird-desktop-ui/" + version.NetbirdVersion()
|
return "netbird-desktop-ui/" + version.NetbirdVersion()
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ package system
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/version"
|
"github.com/netbirdio/netbird/version"
|
||||||
@@ -15,14 +14,12 @@ import (
|
|||||||
func GetInfo(ctx context.Context) *Info {
|
func GetInfo(ctx context.Context) *Info {
|
||||||
|
|
||||||
// Convert fixed-size byte arrays to Go strings
|
// Convert fixed-size byte arrays to Go strings
|
||||||
sysName := "iOS"
|
sysName := extractOsName(ctx, "sysName")
|
||||||
machine := "machine"
|
swVersion := extractOsVersion(ctx, "swVersion")
|
||||||
release := "release"
|
|
||||||
swversion := "swversion"
|
|
||||||
|
|
||||||
gio := &Info{Kernel: sysName, OSVersion: swversion, Core: release, Platform: machine, OS: sysName, GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
|
gio := &Info{Kernel: sysName, OSVersion: swVersion, Core: swVersion, Platform: "unknown", OS: sysName, GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
|
||||||
systemHostname, _ := os.Hostname()
|
// systemHostname, _ := os.Hostname()
|
||||||
gio.Hostname = extractDeviceName(ctx, systemHostname)
|
gio.Hostname = extractDeviceName(ctx, "hostname")
|
||||||
gio.WiretrusteeVersion = version.NetbirdVersion()
|
gio.WiretrusteeVersion = version.NetbirdVersion()
|
||||||
gio.UIVersion = extractUserAgent(ctx)
|
gio.UIVersion = extractUserAgent(ctx)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user