UI improvements
This commit is contained in:
@@ -32,7 +32,6 @@ import (
|
||||
"nhooyr.io/websocket"
|
||||
)
|
||||
|
||||
|
||||
func runClient(cfg config.Config) {
|
||||
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
|
||||
baseBackoff := computeBaseBackoff()
|
||||
@@ -294,7 +293,6 @@ func refreshServerURLsFromRaw(cfg *config.Config) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
func createHTTPTransport(cfg config.Config) *http.Transport {
|
||||
tlsConfig := &tls.Config{
|
||||
InsecureSkipVerify: cfg.TLSInsecureSkipVerify,
|
||||
@@ -608,6 +606,9 @@ func runSession(ctx context.Context, cancel context.CancelFunc, conn *websocket.
|
||||
if osVal == "" {
|
||||
osVal = runtime.GOOS
|
||||
}
|
||||
if prettyOS := strings.TrimSpace(sysinfo.OSName()); prettyOS != "" {
|
||||
osVal = prettyOS
|
||||
}
|
||||
|
||||
archVal := strings.TrimSpace(cfg.Arch)
|
||||
if archVal == "" {
|
||||
@@ -636,6 +637,8 @@ func runSession(ctx context.Context, cancel context.CancelFunc, conn *websocket.
|
||||
hello.CPU = hw.CPU
|
||||
hello.GPU = hw.GPU
|
||||
hello.RAM = hw.RAM
|
||||
hello.BatteryPercent = hw.BatteryPercent
|
||||
hello.BatteryCharging = hw.BatteryCharging
|
||||
hello.IsAdmin = sysinfo.IsAdmin()
|
||||
hello.Elevation = sysinfo.Elevation()
|
||||
hello.Permissions = sysinfo.DarwinPermissions()
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package sysinfo
|
||||
|
||||
type Info struct {
|
||||
CPU string `json:"cpu,omitempty"`
|
||||
GPU string `json:"gpu,omitempty"`
|
||||
RAM string `json:"ram,omitempty"`
|
||||
CPU string `json:"cpu,omitempty"`
|
||||
GPU string `json:"gpu,omitempty"`
|
||||
RAM string `json:"ram,omitempty"`
|
||||
BatteryPercent *int `json:"batteryPercent,omitempty"`
|
||||
BatteryCharging bool `json:"batteryCharging,omitempty"`
|
||||
}
|
||||
|
||||
func Collect() Info {
|
||||
|
||||
@@ -4,6 +4,7 @@ package sysinfo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"unsafe"
|
||||
@@ -12,13 +13,54 @@ import (
|
||||
)
|
||||
|
||||
func collectPlatform() Info {
|
||||
percent, charging := batteryStatus()
|
||||
return Info{
|
||||
CPU: cpuName(),
|
||||
GPU: gpuName(),
|
||||
RAM: totalRAM(),
|
||||
CPU: cpuName(),
|
||||
GPU: gpuName(),
|
||||
RAM: totalRAM(),
|
||||
BatteryPercent: percent,
|
||||
BatteryCharging: charging,
|
||||
}
|
||||
}
|
||||
|
||||
func OSName() string {
|
||||
out, err := exec.Command("sw_vers", "-productVersion").Output()
|
||||
if err != nil {
|
||||
return "macOS"
|
||||
}
|
||||
version := strings.TrimSpace(string(out))
|
||||
if version == "" {
|
||||
return "macOS"
|
||||
}
|
||||
return "macOS " + version
|
||||
}
|
||||
|
||||
func batteryStatus() (*int, bool) {
|
||||
out, err := exec.Command("pmset", "-g", "batt").Output()
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
text := string(out)
|
||||
idx := strings.Index(text, "%")
|
||||
if idx <= 0 {
|
||||
return nil, false
|
||||
}
|
||||
start := idx - 1
|
||||
for start >= 0 && text[start] >= '0' && text[start] <= '9' {
|
||||
start--
|
||||
}
|
||||
var percent int
|
||||
if _, err := fmt.Sscanf(text[start+1:idx], "%d", &percent); err != nil {
|
||||
return nil, false
|
||||
}
|
||||
if percent < 0 || percent > 100 {
|
||||
return nil, false
|
||||
}
|
||||
lower := strings.ToLower(text)
|
||||
charging := strings.Contains(lower, "charging") || strings.Contains(lower, "charged")
|
||||
return &percent, charging
|
||||
}
|
||||
|
||||
func cpuName() string {
|
||||
name, err := unix.Sysctl("machdep.cpu.brand_string")
|
||||
if err != nil || name == "" {
|
||||
|
||||
@@ -11,13 +11,74 @@ import (
|
||||
)
|
||||
|
||||
func collectPlatform() Info {
|
||||
percent, charging := batteryStatus()
|
||||
return Info{
|
||||
CPU: cpuName(),
|
||||
GPU: gpuName(),
|
||||
RAM: totalRAM(),
|
||||
CPU: cpuName(),
|
||||
GPU: gpuName(),
|
||||
RAM: totalRAM(),
|
||||
BatteryPercent: percent,
|
||||
BatteryCharging: charging,
|
||||
}
|
||||
}
|
||||
|
||||
func OSName() string {
|
||||
data, err := os.ReadFile("/etc/os-release")
|
||||
if err != nil {
|
||||
return "Linux"
|
||||
}
|
||||
values := map[string]string{}
|
||||
for _, line := range strings.Split(string(data), "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" || strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
parts := strings.SplitN(line, "=", 2)
|
||||
if len(parts) != 2 {
|
||||
continue
|
||||
}
|
||||
values[parts[0]] = strings.Trim(strings.TrimSpace(parts[1]), `"`)
|
||||
}
|
||||
if pretty := strings.TrimSpace(values["PRETTY_NAME"]); pretty != "" {
|
||||
return pretty
|
||||
}
|
||||
if name := strings.TrimSpace(values["NAME"]); name != "" {
|
||||
if version := strings.TrimSpace(values["VERSION_ID"]); version != "" {
|
||||
return name + " " + version
|
||||
}
|
||||
return name
|
||||
}
|
||||
return "Linux"
|
||||
}
|
||||
|
||||
func batteryStatus() (*int, bool) {
|
||||
entries, err := os.ReadDir("/sys/class/power_supply")
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
for _, entry := range entries {
|
||||
if !strings.HasPrefix(entry.Name(), "BAT") {
|
||||
continue
|
||||
}
|
||||
base := "/sys/class/power_supply/" + entry.Name()
|
||||
capacityRaw, err := os.ReadFile(base + "/capacity")
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
var percent int
|
||||
if _, err := fmt.Sscanf(strings.TrimSpace(string(capacityRaw)), "%d", &percent); err != nil {
|
||||
continue
|
||||
}
|
||||
if percent < 0 || percent > 100 {
|
||||
continue
|
||||
}
|
||||
statusRaw, _ := os.ReadFile(base + "/status")
|
||||
status := strings.ToLower(strings.TrimSpace(string(statusRaw)))
|
||||
charging := status == "charging" || status == "full"
|
||||
return &percent, charging
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func cpuName() string {
|
||||
data, err := os.ReadFile("/proc/cpuinfo")
|
||||
if err != nil {
|
||||
|
||||
@@ -14,13 +14,70 @@ import (
|
||||
)
|
||||
|
||||
func collectPlatform() Info {
|
||||
percent, charging := batteryStatus()
|
||||
return Info{
|
||||
CPU: cpuName(),
|
||||
GPU: gpuName(),
|
||||
RAM: totalRAM(),
|
||||
CPU: cpuName(),
|
||||
GPU: gpuName(),
|
||||
RAM: totalRAM(),
|
||||
BatteryPercent: percent,
|
||||
BatteryCharging: charging,
|
||||
}
|
||||
}
|
||||
|
||||
func OSName() string {
|
||||
k, err := registry.OpenKey(registry.LOCAL_MACHINE,
|
||||
`SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
|
||||
if err != nil {
|
||||
return "Windows"
|
||||
}
|
||||
defer k.Close()
|
||||
|
||||
product, _, _ := k.GetStringValue("ProductName")
|
||||
display, _, _ := k.GetStringValue("DisplayVersion")
|
||||
build, _, _ := k.GetStringValue("CurrentBuildNumber")
|
||||
|
||||
name := strings.TrimSpace(product)
|
||||
if name == "" {
|
||||
name = "Windows"
|
||||
}
|
||||
var buildNumber int
|
||||
_, _ = fmt.Sscanf(strings.TrimSpace(build), "%d", &buildNumber)
|
||||
if buildNumber >= 22000 && !strings.Contains(name, "11") {
|
||||
name = strings.Replace(name, "Windows 10", "Windows 11", 1)
|
||||
if !strings.Contains(name, "11") {
|
||||
name = "Windows 11"
|
||||
}
|
||||
}
|
||||
if display = strings.TrimSpace(display); display != "" {
|
||||
name += " " + display
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func batteryStatus() (*int, bool) {
|
||||
type systemPowerStatus struct {
|
||||
ACLineStatus byte
|
||||
BatteryFlag byte
|
||||
BatteryLifePercent byte
|
||||
SystemStatusFlag byte
|
||||
BatteryLifeTime uint32
|
||||
BatteryFullLifeTime uint32
|
||||
}
|
||||
|
||||
kernel32 := windows.NewLazySystemDLL("kernel32.dll")
|
||||
getSystemPowerStatus := kernel32.NewProc("GetSystemPowerStatus")
|
||||
var status systemPowerStatus
|
||||
ret, _, _ := getSystemPowerStatus.Call(uintptr(unsafe.Pointer(&status)))
|
||||
if ret == 0 || status.BatteryLifePercent == 255 || status.BatteryFlag == 128 {
|
||||
return nil, false
|
||||
}
|
||||
percent := int(status.BatteryLifePercent)
|
||||
if percent < 0 || percent > 100 {
|
||||
return nil, false
|
||||
}
|
||||
return &percent, status.ACLineStatus == 1
|
||||
}
|
||||
|
||||
func cpuName() string {
|
||||
k, err := registry.OpenKey(registry.LOCAL_MACHINE,
|
||||
`HARDWARE\DESCRIPTION\System\CentralProcessor\0`, registry.QUERY_VALUE)
|
||||
|
||||
@@ -1,29 +1,31 @@
|
||||
package wire
|
||||
|
||||
type Hello struct {
|
||||
Type string `msgpack:"type"`
|
||||
ID string `msgpack:"id"`
|
||||
HWID string `msgpack:"hwid"`
|
||||
Host string `msgpack:"host"`
|
||||
OS string `msgpack:"os"`
|
||||
Arch string `msgpack:"arch"`
|
||||
HostArch string `msgpack:"hostArch,omitempty"`
|
||||
Version string `msgpack:"version"`
|
||||
User string `msgpack:"user"`
|
||||
Monitors int `msgpack:"monitors"`
|
||||
MonitorInfo []MonitorInfo `msgpack:"monitorInfo,omitempty"`
|
||||
Country string `msgpack:"country,omitempty"`
|
||||
BuildTag string `msgpack:"buildTag,omitempty"`
|
||||
PublicKey string `msgpack:"publicKey,omitempty"`
|
||||
Signature string `msgpack:"signature,omitempty"`
|
||||
InMemory bool `msgpack:"inMemory,omitempty"`
|
||||
CPU string `msgpack:"cpu,omitempty"`
|
||||
GPU string `msgpack:"gpu,omitempty"`
|
||||
RAM string `msgpack:"ram,omitempty"`
|
||||
IsAdmin bool `msgpack:"isAdmin,omitempty"`
|
||||
Elevation string `msgpack:"elevation,omitempty"`
|
||||
Permissions map[string]bool `msgpack:"permissions,omitempty"`
|
||||
PublicIP string `msgpack:"publicIP,omitempty"`
|
||||
Type string `msgpack:"type"`
|
||||
ID string `msgpack:"id"`
|
||||
HWID string `msgpack:"hwid"`
|
||||
Host string `msgpack:"host"`
|
||||
OS string `msgpack:"os"`
|
||||
Arch string `msgpack:"arch"`
|
||||
HostArch string `msgpack:"hostArch,omitempty"`
|
||||
Version string `msgpack:"version"`
|
||||
User string `msgpack:"user"`
|
||||
Monitors int `msgpack:"monitors"`
|
||||
MonitorInfo []MonitorInfo `msgpack:"monitorInfo,omitempty"`
|
||||
Country string `msgpack:"country,omitempty"`
|
||||
BuildTag string `msgpack:"buildTag,omitempty"`
|
||||
PublicKey string `msgpack:"publicKey,omitempty"`
|
||||
Signature string `msgpack:"signature,omitempty"`
|
||||
InMemory bool `msgpack:"inMemory,omitempty"`
|
||||
CPU string `msgpack:"cpu,omitempty"`
|
||||
GPU string `msgpack:"gpu,omitempty"`
|
||||
RAM string `msgpack:"ram,omitempty"`
|
||||
BatteryPercent *int `msgpack:"batteryPercent,omitempty"`
|
||||
BatteryCharging bool `msgpack:"batteryCharging,omitempty"`
|
||||
IsAdmin bool `msgpack:"isAdmin,omitempty"`
|
||||
Elevation string `msgpack:"elevation,omitempty"`
|
||||
Permissions map[string]bool `msgpack:"permissions,omitempty"`
|
||||
PublicIP string `msgpack:"publicIP,omitempty"`
|
||||
}
|
||||
|
||||
type EnrollmentChallenge struct {
|
||||
|
||||
Reference in New Issue
Block a user