platform

package
v1.144.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

internal/platform/browser.go

internal/platform/clipboard.go

internal/platform/machineid.go

internal/platform/util.go

Index

Constants

View Source
const DefaultVNCPort = 5900

DefaultVNCPort is the standard VNC port.

Variables

This section is empty.

Functions

func ChownR

func ChownR(path, owner string) error

ChownR changes ownership of a file or directory recursively On Windows, this is a no-op as Windows uses ACLs instead of Unix permissions

func ConfigDir

func ConfigDir() string

ConfigDir returns the appropriate config directory for the OS. Uses system-wide paths when running as root, user-local paths otherwise. On Windows, always uses a user-local path (%LOCALAPPDATA%\Citadel) to match the install location and avoid requiring admin privileges.

func CopyToClipboard

func CopyToClipboard(text string) error

CopyToClipboard copies the given text to the system clipboard. Returns nil on success, or an error if clipboard access failed.

func DefaultNodeDir

func DefaultNodeDir(username string) (string, error)

DefaultNodeDir returns the default directory for node configuration

func EnsureHomebrew

func EnsureHomebrew() error

EnsureHomebrew checks if Homebrew is installed and installs it if not

func FormatGPUInfo

func FormatGPUInfo(gpus []GPUInfo) string

FormatGPUInfo returns a human-readable string representation of GPU info

func GenerateMachineID added in v1.12.0

func GenerateMachineID() (string, error)

GenerateMachineID returns a stable SHA-256 hash of hardware identifiers. The hash is computed from: machineUUID + ":" + macAddress + ":" + hostname This provides a stable fingerprint for device re-registration support.

func GenerateVNCPassword added in v1.144.0

func GenerateVNCPassword() (string, error)

GenerateVNCPassword generates a random alphanumeric password. VNC passwords are capped at 8 characters by the DES encryption scheme.

func GetGID

func GetGID(username string) (string, error)

GetGID returns the GID for the given username On Windows, this is not applicable and returns empty string

func GetGPUCountSimple

func GetGPUCountSimple() int

GetGPUCountSimple is a helper function that returns the number of GPUs or 0 if detection fails

func GetGPUMemoryMB

func GetGPUMemoryMB() int

GetGPUMemoryMB returns the total GPU memory in MB (best effort)

func GetSudoUser

func GetSudoUser() string

GetSudoUser returns the original username when running with sudo

func GetUID

func GetUID(username string) (string, error)

GetUID returns the UID for the given username On Windows, this is not applicable and returns empty string

func HomeDir

func HomeDir(username string) (string, error)

HomeDir returns the home directory for the given username. If username is empty, returns the current user's home directory.

func IsDarwin

func IsDarwin() bool

IsDarwin returns true if running on macOS

func IsLinux

func IsLinux() bool

IsLinux returns true if running on Linux

func IsRoot

func IsRoot() bool

IsRoot checks if the current user has root/admin privileges

func IsWindows

func IsWindows() bool

IsWindows returns true if running on Windows

func OS

func OS() string

OS returns the current operating system (linux or darwin)

func OpenURL

func OpenURL(url string) error

OpenURL opens a URL in the default browser Works on Linux and macOS

func ValidatePathWithinDir added in v1.7.1

func ValidatePathWithinDir(baseDir, relativePath string) (string, error)

ValidatePathWithinDir validates that a relative path, when joined with baseDir, stays within the baseDir. This prevents path traversal attacks where a malicious relative path like "../../../etc/passwd" could escape the intended directory.

Returns the validated absolute path if safe, or an error if path traversal is detected.

func ValidateVNCPort added in v1.144.0

func ValidateVNCPort(port int) error

ValidateVNCPort checks whether a port number is valid for VNC.

Types

type AptPackageManager

type AptPackageManager struct{}

AptPackageManager implements PackageManager for Debian/Ubuntu systems

func (*AptPackageManager) Install

func (a *AptPackageManager) Install(packages ...string) error

func (*AptPackageManager) IsInstalled

func (a *AptPackageManager) IsInstalled(pkg string) bool

func (*AptPackageManager) Name

func (a *AptPackageManager) Name() string

func (*AptPackageManager) Update

func (a *AptPackageManager) Update() error

type BrewPackageManager

type BrewPackageManager struct{}

BrewPackageManager implements PackageManager for macOS Homebrew

func (*BrewPackageManager) Install

func (b *BrewPackageManager) Install(packages ...string) error

func (*BrewPackageManager) IsInstalled

func (b *BrewPackageManager) IsInstalled(pkg string) bool

func (*BrewPackageManager) Name

func (b *BrewPackageManager) Name() string

func (*BrewPackageManager) Update

func (b *BrewPackageManager) Update() error

type DarwinDockerManager

type DarwinDockerManager struct{}

DarwinDockerManager implements DockerManager for macOS Docker Desktop

func (*DarwinDockerManager) ConfigureRuntime

func (d *DarwinDockerManager) ConfigureRuntime() error

func (*DarwinDockerManager) EnsureUserInDockerGroup

func (d *DarwinDockerManager) EnsureUserInDockerGroup(username string) error

func (*DarwinDockerManager) Install

func (d *DarwinDockerManager) Install() error

func (*DarwinDockerManager) IsInstalled

func (d *DarwinDockerManager) IsInstalled() bool

func (*DarwinDockerManager) Start

func (d *DarwinDockerManager) Start() error

type DarwinGPUDetector

type DarwinGPUDetector struct{}

DarwinGPUDetector implements GPUDetector for macOS systems

func (*DarwinGPUDetector) GetGPUCount

func (d *DarwinGPUDetector) GetGPUCount() int

func (*DarwinGPUDetector) GetGPUInfo

func (d *DarwinGPUDetector) GetGPUInfo() ([]GPUInfo, error)

func (*DarwinGPUDetector) HasGPU

func (d *DarwinGPUDetector) HasGPU() bool

type DarwinUserManager

type DarwinUserManager struct{}

DarwinUserManager implements UserManager for macOS systems

func (*DarwinUserManager) AddUserToGroup

func (d *DarwinUserManager) AddUserToGroup(username, groupname string) error

func (*DarwinUserManager) CreateGroup

func (d *DarwinUserManager) CreateGroup(groupname string, system bool) error

func (*DarwinUserManager) CreateUser

func (d *DarwinUserManager) CreateUser(username string, system bool) error

func (*DarwinUserManager) GroupExists

func (d *DarwinUserManager) GroupExists(groupname string) bool

func (*DarwinUserManager) IsUserInGroup

func (d *DarwinUserManager) IsUserInGroup(username, groupname string) bool

func (*DarwinUserManager) UserExists

func (d *DarwinUserManager) UserExists(username string) bool

type DarwinVNCManager added in v1.144.0

type DarwinVNCManager struct{}

DarwinVNCManager is a stub VNC manager for macOS. macOS has built-in Screen Sharing that can be enabled via system preferences.

func (*DarwinVNCManager) Configure added in v1.144.0

func (d *DarwinVNCManager) Configure(password string, port int) error

func (*DarwinVNCManager) Install added in v1.144.0

func (d *DarwinVNCManager) Install() error

func (*DarwinVNCManager) IsInstalled added in v1.144.0

func (d *DarwinVNCManager) IsInstalled() bool

func (*DarwinVNCManager) IsRunning added in v1.144.0

func (d *DarwinVNCManager) IsRunning() bool

func (*DarwinVNCManager) Port added in v1.144.0

func (d *DarwinVNCManager) Port() int

func (*DarwinVNCManager) Start added in v1.144.0

func (d *DarwinVNCManager) Start() error

func (*DarwinVNCManager) Stop added in v1.144.0

func (d *DarwinVNCManager) Stop() error

func (*DarwinVNCManager) Uninstall added in v1.144.0

func (d *DarwinVNCManager) Uninstall() error

type DockerManager

type DockerManager interface {
	IsInstalled() bool
	Install() error
	Start() error
	EnsureUserInDockerGroup(username string) error
	ConfigureRuntime() error
}

DockerManager interface defines operations for Docker installation and management

func GetDockerManager

func GetDockerManager() (DockerManager, error)

GetDockerManager returns the appropriate Docker manager for the current OS

type GPUDetector

type GPUDetector interface {
	HasGPU() bool
	GetGPUInfo() ([]GPUInfo, error)
	GetGPUCount() int
}

GPUDetector interface defines operations for GPU detection

func GetGPUDetector

func GetGPUDetector() (GPUDetector, error)

GetGPUDetector returns the appropriate GPU detector for the current OS

type GPUInfo

type GPUInfo struct {
	Name        string
	Memory      string
	MemoryUsed  string
	Temperature string
	Utilization string
	Driver      string
}

GPUInfo represents information about a detected GPU

type LinuxDockerManager

type LinuxDockerManager struct{}

LinuxDockerManager implements DockerManager for Linux systems

func (*LinuxDockerManager) ConfigureRuntime

func (l *LinuxDockerManager) ConfigureRuntime() error

func (*LinuxDockerManager) EnsureUserInDockerGroup

func (l *LinuxDockerManager) EnsureUserInDockerGroup(username string) error

func (*LinuxDockerManager) Install

func (l *LinuxDockerManager) Install() error

func (*LinuxDockerManager) IsInstalled

func (l *LinuxDockerManager) IsInstalled() bool

func (*LinuxDockerManager) Start

func (l *LinuxDockerManager) Start() error

type LinuxGPUDetector

type LinuxGPUDetector struct{}

LinuxGPUDetector implements GPUDetector for Linux systems (NVIDIA)

func (*LinuxGPUDetector) GetGPUCount

func (l *LinuxGPUDetector) GetGPUCount() int

func (*LinuxGPUDetector) GetGPUInfo

func (l *LinuxGPUDetector) GetGPUInfo() ([]GPUInfo, error)

func (*LinuxGPUDetector) HasGPU

func (l *LinuxGPUDetector) HasGPU() bool

type LinuxUserManager

type LinuxUserManager struct{}

LinuxUserManager implements UserManager for Linux systems

func (*LinuxUserManager) AddUserToGroup

func (l *LinuxUserManager) AddUserToGroup(username, groupname string) error

func (*LinuxUserManager) CreateGroup

func (l *LinuxUserManager) CreateGroup(groupname string, system bool) error

func (*LinuxUserManager) CreateUser

func (l *LinuxUserManager) CreateUser(username string, system bool) error

func (*LinuxUserManager) GroupExists

func (l *LinuxUserManager) GroupExists(groupname string) bool

func (*LinuxUserManager) IsUserInGroup

func (l *LinuxUserManager) IsUserInGroup(username, groupname string) bool

func (*LinuxUserManager) UserExists

func (l *LinuxUserManager) UserExists(username string) bool

type LinuxVNCManager added in v1.144.0

type LinuxVNCManager struct {
	// contains filtered or unexported fields
}

LinuxVNCManager manages x11vnc on Linux.

func (*LinuxVNCManager) Configure added in v1.144.0

func (l *LinuxVNCManager) Configure(password string, port int) error

func (*LinuxVNCManager) Install added in v1.144.0

func (l *LinuxVNCManager) Install() error

func (*LinuxVNCManager) IsInstalled added in v1.144.0

func (l *LinuxVNCManager) IsInstalled() bool

func (*LinuxVNCManager) IsRunning added in v1.144.0

func (l *LinuxVNCManager) IsRunning() bool

func (*LinuxVNCManager) Port added in v1.144.0

func (l *LinuxVNCManager) Port() int

func (*LinuxVNCManager) Start added in v1.144.0

func (l *LinuxVNCManager) Start() error

func (*LinuxVNCManager) Stop added in v1.144.0

func (l *LinuxVNCManager) Stop() error

func (*LinuxVNCManager) Uninstall added in v1.144.0

func (l *LinuxVNCManager) Uninstall() error

type PackageManager

type PackageManager interface {
	Update() error
	Install(packages ...string) error
	IsInstalled(pkg string) bool
	Name() string
}

PackageManager interface defines operations for system package management

func GetPackageManager

func GetPackageManager() (PackageManager, error)

GetPackageManager returns the appropriate package manager for the current OS

type UserManager

type UserManager interface {
	CreateUser(username string, system bool) error
	UserExists(username string) bool
	CreateGroup(groupname string, system bool) error
	GroupExists(groupname string) bool
	AddUserToGroup(username, groupname string) error
	IsUserInGroup(username, groupname string) bool
}

UserManager interface defines operations for system user management

func GetUserManager

func GetUserManager() (UserManager, error)

GetUserManager returns the appropriate user manager for the current OS

type VNCManager added in v1.144.0

type VNCManager interface {
	IsInstalled() bool
	Install() error
	Uninstall() error
	Configure(password string, port int) error
	Start() error
	Stop() error
	IsRunning() bool
	Port() int
}

VNCManager interface defines operations for VNC server management.

func GetVNCManager added in v1.144.0

func GetVNCManager() VNCManager

GetVNCManager returns the appropriate VNC manager for the current OS.

type WindowsDockerManager

type WindowsDockerManager struct{}

WindowsDockerManager implements DockerManager for Windows systems with Docker Desktop

func (*WindowsDockerManager) ConfigureRuntime

func (w *WindowsDockerManager) ConfigureRuntime() error

func (*WindowsDockerManager) EnsureUserInDockerGroup

func (w *WindowsDockerManager) EnsureUserInDockerGroup(username string) error

func (*WindowsDockerManager) Install

func (w *WindowsDockerManager) Install() error

func (*WindowsDockerManager) IsInstalled

func (w *WindowsDockerManager) IsInstalled() bool

func (*WindowsDockerManager) Start

func (w *WindowsDockerManager) Start() error

type WindowsGPUDetector

type WindowsGPUDetector struct{}

WindowsGPUDetector implements GPUDetector for Windows systems (NVIDIA)

func (*WindowsGPUDetector) GetGPUCount

func (w *WindowsGPUDetector) GetGPUCount() int

func (*WindowsGPUDetector) GetGPUInfo

func (w *WindowsGPUDetector) GetGPUInfo() ([]GPUInfo, error)

func (*WindowsGPUDetector) HasGPU

func (w *WindowsGPUDetector) HasGPU() bool

type WindowsUserManager

type WindowsUserManager struct{}

WindowsUserManager implements UserManager for Windows systems

func (*WindowsUserManager) AddUserToGroup

func (w *WindowsUserManager) AddUserToGroup(username, groupname string) error

func (*WindowsUserManager) CreateGroup

func (w *WindowsUserManager) CreateGroup(groupname string, system bool) error

func (*WindowsUserManager) CreateUser

func (w *WindowsUserManager) CreateUser(username string, system bool) error

func (*WindowsUserManager) GroupExists

func (w *WindowsUserManager) GroupExists(groupname string) bool

func (*WindowsUserManager) IsUserInGroup

func (w *WindowsUserManager) IsUserInGroup(username, groupname string) bool

func (*WindowsUserManager) UserExists

func (w *WindowsUserManager) UserExists(username string) bool

type WindowsVNCManager added in v1.144.0

type WindowsVNCManager struct{}

WindowsVNCManager manages TightVNC on Windows.

func (*WindowsVNCManager) Configure added in v1.144.0

func (w *WindowsVNCManager) Configure(password string, port int) error

func (*WindowsVNCManager) Install added in v1.144.0

func (w *WindowsVNCManager) Install() error

func (*WindowsVNCManager) IsInstalled added in v1.144.0

func (w *WindowsVNCManager) IsInstalled() bool

func (*WindowsVNCManager) IsRunning added in v1.144.0

func (w *WindowsVNCManager) IsRunning() bool

func (*WindowsVNCManager) Port added in v1.144.0

func (w *WindowsVNCManager) Port() int

func (*WindowsVNCManager) Start added in v1.144.0

func (w *WindowsVNCManager) Start() error

func (*WindowsVNCManager) Stop added in v1.144.0

func (w *WindowsVNCManager) Stop() error

func (*WindowsVNCManager) Uninstall added in v1.144.0

func (w *WindowsVNCManager) Uninstall() error

type WingetPackageManager

type WingetPackageManager struct{}

WingetPackageManager implements PackageManager for Windows Package Manager (winget)

func (*WingetPackageManager) Install

func (w *WingetPackageManager) Install(packages ...string) error

func (*WingetPackageManager) IsInstalled

func (w *WingetPackageManager) IsInstalled(pkg string) bool

func (*WingetPackageManager) Name

func (w *WingetPackageManager) Name() string

func (*WingetPackageManager) Update

func (w *WingetPackageManager) Update() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL