diff --git a/client/system/info_android.go b/client/system/info_android.go index 7718da913..dd861c224 100644 --- a/client/system/info_android.go +++ b/client/system/info_android.go @@ -16,7 +16,7 @@ import ( ) // GetInfo retrieves and parses the system information -func GetInfo(ctx context.Context) *Info { +func GetInfo(ctx context.Context, _ *StaticInfo) *Info { kernel := "android" osInfo := uname() if len(osInfo) == 2 { @@ -44,6 +44,10 @@ func GetInfo(ctx context.Context) *Info { return gio } +func getStaticInfo(ctx context.Context) *StaticInfo { + return nil +} + // checkFileAndProcess checks if the file path exists and if a process is running at that path. func checkFileAndProcess(paths []string) ([]File, error) { return []File{}, nil diff --git a/client/system/info_freebsd.go b/client/system/info_freebsd.go index 454e58a0b..a457d165f 100644 --- a/client/system/info_freebsd.go +++ b/client/system/info_freebsd.go @@ -19,7 +19,7 @@ import ( ) // GetInfo retrieves and parses the system information -func GetInfo(ctx context.Context) *Info { +func GetInfo(ctx context.Context, staticInfo *StaticInfo) *Info { out := _getInfo() for strings.Contains(out, "broken pipe") { out = _getInfo() @@ -29,16 +29,11 @@ func GetInfo(ctx context.Context) *Info { osStr = strings.ReplaceAll(osStr, "\r\n", "") osInfo := strings.Split(osStr, " ") - env := Environment{ - Cloud: detect_cloud.Detect(ctx), - Platform: detect_platform.Detect(ctx), - } - osName, osVersion := readOsReleaseFile() systemHostname, _ := os.Hostname() - return &Info{ + info := &Info{ GoOS: runtime.GOOS, Kernel: osInfo[0], Platform: runtime.GOARCH, @@ -49,7 +44,25 @@ func GetInfo(ctx context.Context) *Info { WiretrusteeVersion: version.NetbirdVersion(), UIVersion: extractUserAgent(ctx), KernelVersion: osInfo[1], - Environment: env, + } + if staticInfo != nil { + info.SystemSerialNumber = staticInfo.SystemSerialNumber + info.SystemProductName = staticInfo.SystemProductName + info.SystemManufacturer = staticInfo.SystemManufacturer + info.Environment = staticInfo.Environment + } + + return info +} + +func getStaticInfo(ctx context.Context) *StaticInfo { + env := Environment{ + Cloud: detect_cloud.Detect(ctx), + Platform: detect_platform.Detect(ctx), + } + + return &StaticInfo{ + Environment: env, } } diff --git a/client/system/info_ios.go b/client/system/info_ios.go index 3dbf50e1e..28a3e66c4 100644 --- a/client/system/info_ios.go +++ b/client/system/info_ios.go @@ -11,7 +11,7 @@ import ( ) // GetInfo retrieves and parses the system information -func GetInfo(ctx context.Context) *Info { +func GetInfo(ctx context.Context, _ *StaticInfo) *Info { // Convert fixed-size byte arrays to Go strings sysName := extractOsName(ctx, "sysName") @@ -25,6 +25,10 @@ func GetInfo(ctx context.Context) *Info { return gio } +func getStaticInfo(ctx context.Context) *StaticInfo { + return nil +} + // checkFileAndProcess checks if the file path exists and if a process is running at that path. func checkFileAndProcess(paths []string) ([]File, error) { return []File{}, nil diff --git a/client/system/info_linux.go b/client/system/info_linux.go index b6a142bce..934437f18 100644 --- a/client/system/info_linux.go +++ b/client/system/info_linux.go @@ -42,7 +42,7 @@ func (s SysInfoWrapper) GetSysInfo() SysInfo { } // GetInfo retrieves and parses the system information -func GetInfo(ctx context.Context) *Info { +func GetInfo(ctx context.Context, staticInfo *StaticInfo) *Info { info := _getInfo() for strings.Contains(info, "broken pipe") { info = _getInfo() @@ -65,14 +65,6 @@ func GetInfo(ctx context.Context) *Info { log.Warnf("failed to discover network addresses: %s", err) } - si := SysInfoWrapper{} - serialNum, prodName, manufacturer := sysInfo(si.GetSysInfo()) - - env := Environment{ - Cloud: detect_cloud.Detect(ctx), - Platform: detect_platform.Detect(ctx), - } - gio := &Info{ Kernel: osInfo[0], Platform: osInfo[2], @@ -85,13 +77,32 @@ func GetInfo(ctx context.Context) *Info { UIVersion: extractUserAgent(ctx), KernelVersion: osInfo[1], NetworkAddresses: addrs, + } + + if staticInfo != nil { + gio.SystemSerialNumber = staticInfo.SystemSerialNumber + gio.SystemProductName = staticInfo.SystemProductName + gio.SystemManufacturer = staticInfo.SystemManufacturer + gio.Environment = staticInfo.Environment + } + + return gio +} + +func getStaticInfo(ctx context.Context) *StaticInfo { + si := SysInfoWrapper{} + serialNum, prodName, manufacturer := sysInfo(si.GetSysInfo()) + env := Environment{ + Cloud: detect_cloud.Detect(ctx), + Platform: detect_platform.Detect(ctx), + } + + return &StaticInfo{ SystemSerialNumber: serialNum, SystemProductName: prodName, SystemManufacturer: manufacturer, Environment: env, } - - return gio } func _getInfo() string { diff --git a/client/system/info_windows.go b/client/system/info_windows.go index 68631fe16..2e331d806 100644 --- a/client/system/info_windows.go +++ b/client/system/info_windows.go @@ -8,7 +8,6 @@ import ( "strings" log "github.com/sirupsen/logrus" - "github.com/yusufpapurcu/wmi" "golang.org/x/sys/windows/registry" "github.com/netbirdio/netbird/client/system/detect_cloud" @@ -33,7 +32,7 @@ type Win32_BIOS struct { } // GetInfo retrieves and parses the system information -func GetInfo(ctx context.Context) *Info { +func GetInfo(ctx context.Context, staticInfo *StaticInfo) *Info { osName, osVersion := getOSNameAndVersion() buildVersion := getBuildVersion() @@ -42,39 +41,22 @@ func GetInfo(ctx context.Context) *Info { log.Warnf("failed to discover network addresses: %s", err) } - serialNum, err := sysNumber() - if err != nil { - log.Warnf("failed to get system serial number: %s", err) - } - - prodName, err := sysProductName() - if err != nil { - log.Warnf("failed to get system product name: %s", err) - } - - manufacturer, err := sysManufacturer() - if err != nil { - log.Warnf("failed to get system manufacturer: %s", err) - } - - env := Environment{ - Cloud: detect_cloud.Detect(ctx), - Platform: detect_platform.Detect(ctx), - } - gio := &Info{ - Kernel: "windows", - OSVersion: osVersion, - Platform: "unknown", - OS: osName, - GoOS: runtime.GOOS, - CPUs: runtime.NumCPU(), - KernelVersion: buildVersion, - NetworkAddresses: addrs, - SystemSerialNumber: serialNum, - SystemProductName: prodName, - SystemManufacturer: manufacturer, - Environment: env, + Kernel: "windows", + OSVersion: osVersion, + Platform: "unknown", + OS: osName, + GoOS: runtime.GOOS, + CPUs: runtime.NumCPU(), + KernelVersion: buildVersion, + NetworkAddresses: addrs, + } + + if staticInfo != nil { + gio.SystemSerialNumber = staticInfo.SystemSerialNumber + gio.SystemProductName = staticInfo.SystemProductName + gio.SystemManufacturer = staticInfo.SystemManufacturer + gio.Environment = staticInfo.Environment } systemHostname, _ := os.Hostname() @@ -85,6 +67,41 @@ func GetInfo(ctx context.Context) *Info { return gio } +func getStaticInfo(ctx context.Context) *StaticInfo { + serialNum, prodName, manufacturer := sysInfo() + env := Environment{ + Cloud: detect_cloud.Detect(ctx), + Platform: detect_platform.Detect(ctx), + } + + return &StaticInfo{ + SystemSerialNumber: serialNum, + SystemProductName: prodName, + SystemManufacturer: manufacturer, + Environment: env, + } +} + +func sysInfo() (serialNumber string, productName string, manufacturer string) { + var err error + serialNumber, err = sysNumber() + if err != nil { + log.Warnf("failed to get system serial number: %s", err) + } + + productName, err = sysProductName() + if err != nil { + log.Warnf("failed to get system product name: %s", err) + } + + manufacturer, err = sysManufacturer() + if err != nil { + log.Warnf("failed to get system manufacturer: %s", err) + } + + return serialNumber, productName, manufacturer +} + func getOSNameAndVersion() (string, string) { var dst []Win32_OperatingSystem query := wmi.CreateQuery(&dst, "")