mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-14 19:00:50 +01:00
94fbfcdb85
Send Desktop UI client version as user-agent to daemon This is sent on every login request to the management Parse the GRPC context on the system package and retrieves the user-agent Management receives the new UIVersion field and store in the Peer's system meta
45 lines
1005 B
Go
45 lines
1005 B
Go
package system
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"runtime"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// GetInfo retrieves and parses the system information
|
|
func GetInfo(ctx context.Context) *Info {
|
|
out := _getInfo()
|
|
for strings.Contains(out, "broken pipe") {
|
|
out = _getInfo()
|
|
time.Sleep(500 * time.Millisecond)
|
|
}
|
|
osStr := strings.Replace(out, "\n", "", -1)
|
|
osStr = strings.Replace(osStr, "\r\n", "", -1)
|
|
osInfo := strings.Split(osStr, " ")
|
|
gio := &Info{Kernel: osInfo[0], Core: osInfo[1], Platform: runtime.GOARCH, OS: osInfo[2], GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
|
|
gio.Hostname, _ = os.Hostname()
|
|
gio.WiretrusteeVersion = NetbirdVersion()
|
|
gio.UIVersion = extractUserAgent(ctx)
|
|
|
|
return gio
|
|
}
|
|
|
|
func _getInfo() string {
|
|
cmd := exec.Command("uname", "-sri")
|
|
cmd.Stdin = strings.NewReader("some input")
|
|
var out bytes.Buffer
|
|
var stderr bytes.Buffer
|
|
cmd.Stdout = &out
|
|
cmd.Stderr = &stderr
|
|
err := cmd.Run()
|
|
if err != nil {
|
|
fmt.Println("getInfo:", err)
|
|
}
|
|
return out.String()
|
|
}
|