Documentation
¶
Index ¶
- func CheckTorConnection(socksAddr string) bool
- func DropPrivileges(userName string) error
- func FindAvailableSystemID() (int, error)
- func GetServiceGroup(serviceName string) string
- func GetServiceStatus() string
- func GetServiceUser(serviceName string) string
- func IsRunningAsRoot() bool
- func UserExists(name string) bool
- func VerifyPrivilegesDropped() error
- type GracefulDegradation
- func (g *GracefulDegradation) Execute(feature string, fn func() (interface{}, error)) (interface{}, error)
- func (g *GracefulDegradation) GetDegradedFeatures() []string
- func (g *GracefulDegradation) GetFallback(feature string) interface{}
- func (g *GracefulDegradation) IsDegraded(feature string) bool
- func (g *GracefulDegradation) MarkDegraded(feature string)
- func (g *GracefulDegradation) MarkHealthy(feature string)
- func (g *GracefulDegradation) RegisterFallback(feature string, fallback func() interface{})
- type HealthStatus
- type MaintenanceMode
- type MaintenanceService
- func (m *MaintenanceService) BackupDatabase(dbPath, backupDir string) (string, error)
- func (m *MaintenanceService) CheckDatabaseIntegrity(db *sql.DB) error
- func (m *MaintenanceService) DisableMaintenance()
- func (m *MaintenanceService) EnableMaintenance(message string, duration time.Duration)
- func (m *MaintenanceService) GetHealthStatus() map[string]*HealthStatus
- func (m *MaintenanceService) GetMessage() string
- func (m *MaintenanceService) GetMode() MaintenanceMode
- func (m *MaintenanceService) GetScheduledEnd() time.Time
- func (m *MaintenanceService) GetStatus() map[string]interface{}
- func (m *MaintenanceService) IsDegraded() bool
- func (m *MaintenanceService) IsInMaintenance() bool
- func (m *MaintenanceService) IsNormal() bool
- func (m *MaintenanceService) RegisterCallback(cb func(MaintenanceMode))
- func (m *MaintenanceService) RegisterRecoveryFunc(component string, fn func(ctx context.Context) error)
- func (m *MaintenanceService) RepairDatabase(dbPath string) error
- func (m *MaintenanceService) RestoreDatabase(backupPath, dbPath string) error
- func (m *MaintenanceService) SetDatabaseChecks(serverCheck, usersCheck func(ctx context.Context) error)
- func (m *MaintenanceService) SetMode(mode MaintenanceMode, message string)
- func (m *MaintenanceService) Start() error
- func (m *MaintenanceService) Stop()
- type PrivilegeEscalator
- type ServiceManager
- func (sm *ServiceManager) Disable() error
- func (sm *ServiceManager) Enable() error
- func (sm *ServiceManager) Install() error
- func (sm *ServiceManager) Reload() error
- func (sm *ServiceManager) Restart() error
- func (sm *ServiceManager) Start() error
- func (sm *ServiceManager) Status() (string, error)
- func (sm *ServiceManager) Stop() error
- func (sm *ServiceManager) Uninstall() error
- type SystemUser
- type TorService
- func (t *TorService) ApplyVanityAddress() (string, error)
- func (t *TorService) CancelVanity()
- func (t *TorService) ExportKeys() ([]byte, error)
- func (t *TorService) GenerateVanity(prefix string) error
- func (t *TorService) GetHTTPClient(useTor bool) *http.Client
- func (t *TorService) GetOnionAddress() string
- func (t *TorService) GetTorStatus() map[string]interface{}
- func (t *TorService) GetVanityProgress() *VanityProgress
- func (t *TorService) ImportKeys(privateKey []byte) (string, error)
- func (t *TorService) IsRunning() bool
- func (t *TorService) OutboundEnabled() bool
- func (t *TorService) RegenerateAddress() (string, error)
- func (t *TorService) Restart() error
- func (t *TorService) SetEnabled(enabled bool) error
- func (t *TorService) Shutdown()
- func (t *TorService) Start() error
- func (t *TorService) Stop() error
- type VanityProgress
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckTorConnection ¶
CheckTorConnection tests if Tor is accessible
func DropPrivileges ¶
DropPrivileges drops from root to the specified user Per AI.md PART 8: Step 8g - DROP PRIVILEGES to search user This uses syscall.Setgid and syscall.Setuid to drop privileges
func FindAvailableSystemID ¶
FindAvailableSystemID finds an available UID/GID in the system range Per AI.md PART 24: UID/GID 100-999 for system accounts
func GetServiceGroup ¶
GetServiceGroup returns the appropriate service group name for the current OS
func GetServiceStatus ¶
func GetServiceStatus() string
GetServiceStatus returns formatted service status information
func GetServiceUser ¶
GetServiceUser returns the appropriate service user name for the current OS Per AI.md PART 24: OS-specific user naming
func IsRunningAsRoot ¶
func IsRunningAsRoot() bool
IsRunningAsRoot returns true if the process is running as root
func VerifyPrivilegesDropped ¶
func VerifyPrivilegesDropped() error
VerifyPrivilegesDropped verifies that privileges have been dropped Per AI.md PART 8: Step 8h - Verify privilege drop succeeded
Types ¶
type GracefulDegradation ¶
type GracefulDegradation struct {
// contains filtered or unexported fields
}
GracefulDegradation provides fallback behavior when services are unavailable Per AI.md PART 6: Graceful degradation
func NewGracefulDegradation ¶
func NewGracefulDegradation() *GracefulDegradation
NewGracefulDegradation creates a new graceful degradation handler
func (*GracefulDegradation) Execute ¶
func (g *GracefulDegradation) Execute(feature string, fn func() (interface{}, error)) (interface{}, error)
Execute executes a function with graceful degradation
func (*GracefulDegradation) GetDegradedFeatures ¶
func (g *GracefulDegradation) GetDegradedFeatures() []string
GetDegradedFeatures returns a list of currently degraded features
func (*GracefulDegradation) GetFallback ¶
func (g *GracefulDegradation) GetFallback(feature string) interface{}
GetFallback returns the fallback value for a degraded feature
func (*GracefulDegradation) IsDegraded ¶
func (g *GracefulDegradation) IsDegraded(feature string) bool
IsDegraded checks if a feature is degraded
func (*GracefulDegradation) MarkDegraded ¶
func (g *GracefulDegradation) MarkDegraded(feature string)
MarkDegraded marks a feature as degraded
func (*GracefulDegradation) MarkHealthy ¶
func (g *GracefulDegradation) MarkHealthy(feature string)
MarkHealthy marks a feature as healthy
func (*GracefulDegradation) RegisterFallback ¶
func (g *GracefulDegradation) RegisterFallback(feature string, fallback func() interface{})
RegisterFallback registers a fallback function for a feature
type HealthStatus ¶
type HealthStatus struct {
Component string `json:"component"`
Healthy bool `json:"healthy"`
Message string `json:"message,omitempty"`
LastCheck time.Time `json:"last_check"`
LastHealthy time.Time `json:"last_healthy,omitempty"`
ErrorCount int `json:"error_count"`
}
HealthStatus represents the health of a system component
type MaintenanceMode ¶
type MaintenanceMode int
MaintenanceMode represents the current maintenance state Per AI.md PART 6: Maintenance Mode (NON-NEGOTIABLE)
const ( // ModeNormal is normal operation ModeNormal MaintenanceMode = iota // ModeDegraded is reduced functionality (some services unavailable) ModeDegraded // ModeMaintenance is full maintenance mode (read-only, limited access) ModeMaintenance // ModeRecovery is recovery mode (attempting to repair) ModeRecovery // ModeEmergency is emergency mode (critical failure, minimal functionality) ModeEmergency )
func (MaintenanceMode) String ¶
func (m MaintenanceMode) String() string
String returns the string representation of the maintenance mode
type MaintenanceService ¶
type MaintenanceService struct {
// contains filtered or unexported fields
}
MaintenanceService manages maintenance mode and self-healing Per AI.md PART 6: Maintenance Mode (NON-NEGOTIABLE)
func NewMaintenanceService ¶
func NewMaintenanceService(cfg *config.Config) *MaintenanceService
NewMaintenanceService creates a new maintenance service
func (*MaintenanceService) BackupDatabase ¶
func (m *MaintenanceService) BackupDatabase(dbPath, backupDir string) (string, error)
BackupDatabase creates a backup of the database
func (*MaintenanceService) CheckDatabaseIntegrity ¶
func (m *MaintenanceService) CheckDatabaseIntegrity(db *sql.DB) error
CheckDatabaseIntegrity checks database integrity and attempts repair if needed Per AI.md PART 6: Database corruption handling
func (*MaintenanceService) DisableMaintenance ¶
func (m *MaintenanceService) DisableMaintenance()
DisableMaintenance disables maintenance mode
func (*MaintenanceService) EnableMaintenance ¶
func (m *MaintenanceService) EnableMaintenance(message string, duration time.Duration)
EnableMaintenance enables maintenance mode
func (*MaintenanceService) GetHealthStatus ¶
func (m *MaintenanceService) GetHealthStatus() map[string]*HealthStatus
GetHealthStatus returns the health status of all components
func (*MaintenanceService) GetMessage ¶
func (m *MaintenanceService) GetMessage() string
GetMessage returns the current maintenance message
func (*MaintenanceService) GetMode ¶
func (m *MaintenanceService) GetMode() MaintenanceMode
GetMode returns the current maintenance mode
func (*MaintenanceService) GetScheduledEnd ¶
func (m *MaintenanceService) GetScheduledEnd() time.Time
GetScheduledEnd returns when maintenance is scheduled to end
func (*MaintenanceService) GetStatus ¶
func (m *MaintenanceService) GetStatus() map[string]interface{}
GetStatus returns the full maintenance status
func (*MaintenanceService) IsDegraded ¶
func (m *MaintenanceService) IsDegraded() bool
IsDegraded returns true if system is in degraded mode
func (*MaintenanceService) IsInMaintenance ¶
func (m *MaintenanceService) IsInMaintenance() bool
IsInMaintenance returns true if system is in maintenance mode
func (*MaintenanceService) IsNormal ¶
func (m *MaintenanceService) IsNormal() bool
IsNormal returns true if system is in normal mode
func (*MaintenanceService) RegisterCallback ¶
func (m *MaintenanceService) RegisterCallback(cb func(MaintenanceMode))
RegisterCallback registers a callback for mode changes
func (*MaintenanceService) RegisterRecoveryFunc ¶
func (m *MaintenanceService) RegisterRecoveryFunc(component string, fn func(ctx context.Context) error)
RegisterRecoveryFunc registers a recovery function for a component
func (*MaintenanceService) RepairDatabase ¶
func (m *MaintenanceService) RepairDatabase(dbPath string) error
RepairDatabase attempts to repair a corrupted database Per AI.md PART 6: Database corruption handling
func (*MaintenanceService) RestoreDatabase ¶
func (m *MaintenanceService) RestoreDatabase(backupPath, dbPath string) error
RestoreDatabase restores a database from backup
func (*MaintenanceService) SetDatabaseChecks ¶
func (m *MaintenanceService) SetDatabaseChecks(serverCheck, usersCheck func(ctx context.Context) error)
SetDatabaseChecks sets the database check functions
func (*MaintenanceService) SetMode ¶
func (m *MaintenanceService) SetMode(mode MaintenanceMode, message string)
SetMode sets the maintenance mode
func (*MaintenanceService) Start ¶
func (m *MaintenanceService) Start() error
Start starts the maintenance service monitoring
func (*MaintenanceService) Stop ¶
func (m *MaintenanceService) Stop()
Stop stops the maintenance service
type PrivilegeEscalator ¶
type PrivilegeEscalator struct {
// contains filtered or unexported fields
}
PrivilegeEscalator handles privilege escalation for service installation Per AI.md PART 24: Privilege Escalation (NON-NEGOTIABLE)
func NewPrivilegeEscalator ¶
func NewPrivilegeEscalator() *PrivilegeEscalator
NewPrivilegeEscalator creates a new privilege escalator Per AI.md PART 24: Auto-detect available privilege escalation method
func (*PrivilegeEscalator) EscalateCommand ¶
func (p *PrivilegeEscalator) EscalateCommand(cmd string, args ...string) *exec.Cmd
EscalateCommand wraps a command with privilege escalation Per AI.md PART 24: Wrap commands appropriately for each method
func (*PrivilegeEscalator) IsAvailable ¶
func (p *PrivilegeEscalator) IsAvailable() bool
IsAvailable returns true if privilege escalation is available
func (*PrivilegeEscalator) Method ¶
func (p *PrivilegeEscalator) Method() string
Method returns the detected privilege escalation method
type ServiceManager ¶
type ServiceManager struct {
// contains filtered or unexported fields
}
ServiceManager handles system service installation
func NewServiceManager ¶
func NewServiceManager(cfg *config.Config) *ServiceManager
NewServiceManager creates a new service manager
func (*ServiceManager) Disable ¶
func (sm *ServiceManager) Disable() error
Disable disables the service from starting on boot
func (*ServiceManager) Enable ¶
func (sm *ServiceManager) Enable() error
Enable enables the service to start on boot
func (*ServiceManager) Install ¶
func (sm *ServiceManager) Install() error
Install installs the system service
func (*ServiceManager) Reload ¶
func (sm *ServiceManager) Reload() error
Reload reloads the service configuration (sends SIGHUP)
func (*ServiceManager) Restart ¶
func (sm *ServiceManager) Restart() error
Restart restarts the service
func (*ServiceManager) Status ¶
func (sm *ServiceManager) Status() (string, error)
Status returns the service status
func (*ServiceManager) Uninstall ¶
func (sm *ServiceManager) Uninstall() error
Uninstall removes the system service
type SystemUser ¶
SystemUser represents a system service user Per AI.md PART 24: System user creation logic
func CreateSystemUser ¶
func CreateSystemUser(name string) (*SystemUser, error)
CreateSystemUser creates a system user for the service Per AI.md PART 24: System user creation logic
type TorService ¶
type TorService struct {
// contains filtered or unexported fields
}
TorService manages Tor hidden service using github.com/cretz/bine per AI.md PART 32: TOR HIDDEN SERVICE (NON-NEGOTIABLE) Server binary fully owns and controls the Tor process lifecycle.
func NewTorService ¶
func NewTorService(cfg *config.Config) *TorService
NewTorService creates a new Tor service manager
func (*TorService) ApplyVanityAddress ¶
func (t *TorService) ApplyVanityAddress() (string, error)
ApplyVanityAddress applies a generated vanity address
func (*TorService) CancelVanity ¶
func (t *TorService) CancelVanity()
CancelVanity cancels any running vanity generation
func (*TorService) ExportKeys ¶
func (t *TorService) ExportKeys() ([]byte, error)
ExportKeys exports the current Tor hidden service keys Per AI.md PART 32: Key import/export for external vanity addresses
func (*TorService) GenerateVanity ¶
func (t *TorService) GenerateVanity(prefix string) error
GenerateVanity starts background vanity address generation Per AI.md PART 32: Built-in generation supports max 6 character prefixes
func (*TorService) GetHTTPClient ¶
func (t *TorService) GetHTTPClient(useTor bool) *http.Client
GetHTTPClient returns an HTTP client, optionally routed through Tor Per AI.md PART 32: useTor: true = route through Tor, false = direct
func (*TorService) GetOnionAddress ¶
func (t *TorService) GetOnionAddress() string
GetOnionAddress returns the .onion address
func (*TorService) GetTorStatus ¶
func (t *TorService) GetTorStatus() map[string]interface{}
GetTorStatus returns detailed Tor status information
func (*TorService) GetVanityProgress ¶
func (t *TorService) GetVanityProgress() *VanityProgress
GetVanityProgress returns the current vanity generation progress
func (*TorService) ImportKeys ¶
func (t *TorService) ImportKeys(privateKey []byte) (string, error)
ImportKeys imports external Tor hidden service keys Per AI.md PART 32: Key import/export for external vanity addresses
func (*TorService) IsRunning ¶
func (t *TorService) IsRunning() bool
IsRunning returns whether Tor is running
func (*TorService) OutboundEnabled ¶
func (t *TorService) OutboundEnabled() bool
OutboundEnabled returns true if Tor outbound connections are available
func (*TorService) RegenerateAddress ¶
func (t *TorService) RegenerateAddress() (string, error)
RegenerateAddress creates a new random .onion address
func (*TorService) Restart ¶
func (t *TorService) Restart() error
Restart stops and starts Tor (used for config changes, recovery)
func (*TorService) SetEnabled ¶
func (t *TorService) SetEnabled(enabled bool) error
SetEnabled enables or disables Tor
func (*TorService) Shutdown ¶
func (t *TorService) Shutdown()
Shutdown gracefully shuts down the Tor service
func (*TorService) Start ¶
func (t *TorService) Start() error
Start starts the Tor hidden service using bine Per AI.md PART 32: "Auto-enabled if tor binary is installed - no enable flag needed"