From 4fa98f91e723917a85164c1b0a0921a853386a75 Mon Sep 17 00:00:00 2001 From: Mohammed Date: Wed, 30 Oct 2024 17:31:25 +0330 Subject: [PATCH 1/3] fix mac survey improve windows survey --- pkg/visor/visorconfig/values_darwin.go | 37 ++++++++++++++++++------ pkg/visor/visorconfig/values_linux.go | 11 ++----- pkg/visor/visorconfig/values_windows.go | 38 +++++++++++-------------- 3 files changed, 47 insertions(+), 39 deletions(-) diff --git a/pkg/visor/visorconfig/values_darwin.go b/pkg/visor/visorconfig/values_darwin.go index c9210d6add..639a275e4b 100644 --- a/pkg/visor/visorconfig/values_darwin.go +++ b/pkg/visor/visorconfig/values_darwin.go @@ -4,11 +4,14 @@ package visorconfig import ( + "net" "os/user" "runtime" + "time" "github.com/google/uuid" "github.com/jaypipes/ghw" + "github.com/zcalusic/sysinfo" "github.com/skycoin/skywire-utilities/pkg/cipher" "github.com/skycoin/skywire/pkg/skyenv" @@ -29,10 +32,12 @@ func UserConfig() skyenv.PkgConfig { // Survey system hardware survey struct type Survey struct { + Timestamp time.Time `json:"timestamp"` PubKey cipher.PubKey `json:"public_key,omitempty"` SkycoinAddress string `json:"skycoin_address,omitempty"` GOOS string `json:"go_os,omitempty"` GOARCH string `json:"go_arch,omitempty"` + SYSINFO customSysinfo `json:"zcalusic_sysinfo,omitempty"` IPAddr string `json:"ip_address,omitempty"` Disks *ghw.BlockInfo `json:"ghw_blockinfo,omitempty"` UUID uuid.UUID `json:"uuid,omitempty"` @@ -47,17 +52,11 @@ func SystemSurvey() (Survey, error) { if err != nil { return Survey{}, err } - // var ipAddr string - // for { - // ipAddr, err = FetchIP(dmsgDisc) - // if err == nil { - // break - // } - // } s := Survey{ - // IPAddr: ipAddr, + Timestamp: time.Now(), GOOS: runtime.GOOS, GOARCH: runtime.GOARCH, + SYSINFO: getMacAddr(), UUID: uuid.New(), Disks: disks, SkywireVersion: Version(), @@ -70,3 +69,25 @@ func IsRoot() bool { userLvl, _ := user.Current() //nolint return userLvl.Username == "root" } + +type customSysinfo struct { + Network []sysinfo.NetworkDevice `json:"network,omitempty"` +} + +func getMacAddr() customSysinfo { + var sysInfo customSysinfo + si := make([]sysinfo.NetworkDevice, 1) + interfaces, err := net.Interfaces() + if err != nil { + return sysInfo + } + + for _, ifa := range interfaces { + si[0].MACAddress = ifa.HardwareAddr.String() + if si[0].MACAddress != "" { + sysInfo.Network = si + return sysInfo + } + } + return sysInfo +} diff --git a/pkg/visor/visorconfig/values_linux.go b/pkg/visor/visorconfig/values_linux.go index fa28c69964..7d24bbb942 100644 --- a/pkg/visor/visorconfig/values_linux.go +++ b/pkg/visor/visorconfig/values_linux.go @@ -64,16 +64,9 @@ func SystemSurvey() (Survey, error) { if err != nil && !strings.Contains(err.Error(), "Could not determine total usable bytes of memory") { return Survey{}, err } - // var ipAddr string - // for { - // ipAddr, err = FetchIP(dmsgDisc) - // if err == nil { - // break - // } - // } + s := Survey{ - Timestamp: time.Now(), - // IPAddr: ipAddr, + Timestamp: time.Now(), GOOS: runtime.GOOS, GOARCH: runtime.GOARCH, SYSINFO: si, diff --git a/pkg/visor/visorconfig/values_windows.go b/pkg/visor/visorconfig/values_windows.go index 29b5cbf053..6f3e6f31a5 100644 --- a/pkg/visor/visorconfig/values_windows.go +++ b/pkg/visor/visorconfig/values_windows.go @@ -7,11 +7,13 @@ import ( "log" "net" "runtime" + "time" "golang.org/x/sys/windows" "github.com/google/uuid" "github.com/jaypipes/ghw" + "github.com/zcalusic/sysinfo" "github.com/skycoin/skywire-utilities/pkg/cipher" "github.com/skycoin/skywire/pkg/skyenv" @@ -32,11 +34,12 @@ func UserConfig() skyenv.PkgConfig { // Survey system hardware survey struct type Survey struct { + Timestamp time.Time `json:"timestamp"` PubKey cipher.PubKey `json:"public_key,omitempty"` SkycoinAddress string `json:"skycoin_address,omitempty"` GOOS string `json:"go_os,omitempty"` GOARCH string `json:"go_arch,omitempty"` - SYSINFO []NetworkDevice `json:"zcalusic_sysinfo,omitempty"` + SYSINFO customSysinfo `json:"zcalusic_sysinfo,omitempty"` IPAddr string `json:"ip_address,omitempty"` Disks *ghw.BlockInfo `json:"ghw_blockinfo,omitempty"` Product *ghw.ProductInfo `json:"ghw_productinfo,omitempty"` @@ -61,16 +64,9 @@ func SystemSurvey() (Survey, error) { if err != nil { return Survey{}, err } - // var ipAddr string - // for { - // ipAddr, err = FetchIP(dmsgDisc) - // if err == nil { - // break - // } - // } s := Survey{ - // IPAddr: ipAddr, + Timestamp: time.Now(), GOOS: runtime.GOOS, GOARCH: runtime.GOARCH, SYSINFO: getMacAddr(), @@ -83,28 +79,26 @@ func SystemSurvey() (Survey, error) { return s, nil } -type NetworkDevice struct { - Name string `json:"name,omitempty"` - Driver string `json:"driver,omitempty"` - MACAddress string `json:"macaddress,omitempty"` - Port string `json:"port,omitempty"` - Speed uint `json:"speed,omitempty"` // device max supported speed in Mbps +type customSysinfo struct { + Network []sysinfo.NetworkDevice `json:"network,omitempty"` } -func getMacAddr() []NetworkDevice { - si := make([]NetworkDevice, 1) - ifas, err := net.Interfaces() +func getMacAddr() customSysinfo { + var sysInfo customSysinfo + si := make([]sysinfo.NetworkDevice, 1) + interfaces, err := net.Interfaces() if err != nil { - return nil + return sysInfo } - for _, ifa := range ifas { + for _, ifa := range interfaces { si[0].MACAddress = ifa.HardwareAddr.String() if si[0].MACAddress != "" { - return si + sysInfo.Network = si + return sysInfo } } - return nil + return sysInfo } // IsRoot checks for root permissions From 1fa6c1c3fc656ee8faecf3b7e69da346cd58c0fd Mon Sep 17 00:00:00 2001 From: Mohammed Date: Wed, 30 Oct 2024 17:42:56 +0330 Subject: [PATCH 2/3] fix windows zcalusic unknown lib --- pkg/visor/visorconfig/values_windows.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/visor/visorconfig/values_windows.go b/pkg/visor/visorconfig/values_windows.go index 6f3e6f31a5..3d478050f3 100644 --- a/pkg/visor/visorconfig/values_windows.go +++ b/pkg/visor/visorconfig/values_windows.go @@ -13,7 +13,6 @@ import ( "github.com/google/uuid" "github.com/jaypipes/ghw" - "github.com/zcalusic/sysinfo" "github.com/skycoin/skywire-utilities/pkg/cipher" "github.com/skycoin/skywire/pkg/skyenv" @@ -80,12 +79,19 @@ func SystemSurvey() (Survey, error) { } type customSysinfo struct { - Network []sysinfo.NetworkDevice `json:"network,omitempty"` + Network []networkDevice `json:"network,omitempty"` +} +type networkDevice struct { + Name string `json:"name,omitempty"` + Driver string `json:"driver,omitempty"` + MACAddress string `json:"macaddress,omitempty"` + Port string `json:"port,omitempty"` + Speed uint `json:"speed,omitempty"` // device max supported speed in Mbps } func getMacAddr() customSysinfo { var sysInfo customSysinfo - si := make([]sysinfo.NetworkDevice, 1) + si := make([]networkDevice, 1) interfaces, err := net.Interfaces() if err != nil { return sysInfo From f50db9d8e0e7061861252ac0d1bd89d5d9e98ffd Mon Sep 17 00:00:00 2001 From: Mohammed Date: Wed, 30 Oct 2024 17:45:36 +0330 Subject: [PATCH 3/3] remove useless element in struct --- pkg/visor/visorconfig/values_windows.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/visor/visorconfig/values_windows.go b/pkg/visor/visorconfig/values_windows.go index 3d478050f3..ecdfacc601 100644 --- a/pkg/visor/visorconfig/values_windows.go +++ b/pkg/visor/visorconfig/values_windows.go @@ -82,11 +82,7 @@ type customSysinfo struct { Network []networkDevice `json:"network,omitempty"` } type networkDevice struct { - Name string `json:"name,omitempty"` - Driver string `json:"driver,omitempty"` MACAddress string `json:"macaddress,omitempty"` - Port string `json:"port,omitempty"` - Speed uint `json:"speed,omitempty"` // device max supported speed in Mbps } func getMacAddr() customSysinfo {