admin

package
v0.0.0-...-69cc41d Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdminHandlers

type AdminHandlers struct {
	UserManagement *UserManagementHandlers
	Security       *SecurityHandlers
	Config         *ConfigHandlers
	Database       *DatabaseHandlers
	Templates      *TemplateHandlers
}

AdminHandlers aggregates all admin API handlers

func NewAdminHandlers

func NewAdminHandlers(db *sql.DB, configPath string) *AdminHandlers

NewAdminHandlers creates a new admin handlers instance

func (*AdminHandlers) RegisterRoutes

func (h *AdminHandlers) RegisterRoutes(router *mux.Router)

RegisterRoutes registers all admin API routes

type AuditLogEntry

type AuditLogEntry struct {
	ID        int                    `json:"id"`
	UserID    int                    `json:"user_id"`
	Username  string                 `json:"username"`
	Action    string                 `json:"action"`
	Resource  string                 `json:"resource"`
	Details   map[string]interface{} `json:"details"`
	IP        string                 `json:"ip"`
	UserAgent string                 `json:"user_agent"`
	Success   bool                   `json:"success"`
	CreatedAt time.Time              `json:"created_at"`
}

type ColumnInfo

type ColumnInfo struct {
	Name         string      `json:"name"`
	Type         string      `json:"type"`
	Nullable     bool        `json:"nullable"`
	DefaultValue interface{} `json:"default_value"`
	IsPrimaryKey bool        `json:"is_primary_key"`
}

type ConfigBackup

type ConfigBackup struct {
	ID          int          `json:"id"`
	Config      SystemConfig `json:"config"`
	CreatedAt   time.Time    `json:"created_at"`
	CreatedBy   string       `json:"created_by"`
	Description string       `json:"description"`
}

type ConfigHandlers

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

func NewConfigHandlers

func NewConfigHandlers(configPath string) *ConfigHandlers

func (*ConfigHandlers) CreateBackup

func (h *ConfigHandlers) CreateBackup(w http.ResponseWriter, r *http.Request)

POST /api/admin/config/backup - Create configuration backup

func (*ConfigHandlers) GetConfig

func (h *ConfigHandlers) GetConfig(w http.ResponseWriter, r *http.Request)

GET /api/admin/config - Get current system configuration

func (*ConfigHandlers) ListBackups

func (h *ConfigHandlers) ListBackups(w http.ResponseWriter, r *http.Request)

GET /api/admin/config/backups - List configuration backups

func (*ConfigHandlers) RestoreBackup

func (h *ConfigHandlers) RestoreBackup(w http.ResponseWriter, r *http.Request)

POST /api/admin/config/restore/{id} - Restore configuration from backup

func (*ConfigHandlers) UpdateConfig

func (h *ConfigHandlers) UpdateConfig(w http.ResponseWriter, r *http.Request)

PUT /api/admin/config - Update system configuration

func (*ConfigHandlers) ValidateConfig

func (h *ConfigHandlers) ValidateConfig(w http.ResponseWriter, r *http.Request)

GET /api/admin/config/validate - Validate configuration without applying

type CreateTemplateRequest

type CreateTemplateRequest struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	OS          string                 `json:"os"`
	OSVersion   string                 `json:"os_version"`
	CPUCores    int                    `json:"cpu_cores"`
	MemoryMB    int                    `json:"memory_mb"`
	DiskGB      int                    `json:"disk_gb"`
	ImagePath   string                 `json:"image_path"`
	IsPublic    bool                   `json:"is_public"`
	Tags        []string               `json:"tags,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

type CreateUserRequest

type CreateUserRequest struct {
	Username string `json:"username"`
	Email    string `json:"email"`
	Password string `json:"password"`
	Role     string `json:"role"`
}

type DatabaseConfig

type DatabaseConfig struct {
	Host            string `json:"host"`
	Port            int    `json:"port"`
	Name            string `json:"name"`
	Username        string `json:"username"`
	MaxConnections  int    `json:"max_connections"`
	MaxIdleConns    int    `json:"max_idle_connections"`
	ConnMaxLifetime int    `json:"connection_max_lifetime_minutes"`
	SSLMode         string `json:"ssl_mode"`
}

type DatabaseHandlers

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

func NewDatabaseHandlers

func NewDatabaseHandlers(db *sql.DB) *DatabaseHandlers

func (*DatabaseHandlers) ExecuteQuery

func (h *DatabaseHandlers) ExecuteQuery(w http.ResponseWriter, r *http.Request)

POST /api/admin/database/query - Execute read query

func (*DatabaseHandlers) ExecuteStatement

func (h *DatabaseHandlers) ExecuteStatement(w http.ResponseWriter, r *http.Request)

POST /api/admin/database/execute - Execute write query (admin only)

func (*DatabaseHandlers) GetTableDetails

func (h *DatabaseHandlers) GetTableDetails(w http.ResponseWriter, r *http.Request)

GET /api/admin/database/tables/{table} - Get table details

func (*DatabaseHandlers) ListTables

func (h *DatabaseHandlers) ListTables(w http.ResponseWriter, r *http.Request)

GET /api/admin/database/tables - List all tables

type IPStatistic

type IPStatistic struct {
	IP      string `json:"ip"`
	Count   int    `json:"count"`
	Country string `json:"country,omitempty"`
}

type IndexInfo

type IndexInfo struct {
	Name    string   `json:"name"`
	Columns []string `json:"columns"`
	Unique  bool     `json:"unique"`
}

type MonitoringConfig

type MonitoringConfig struct {
	Enabled            bool   `json:"enabled"`
	MetricsInterval    int    `json:"metrics_interval_seconds"`
	RetentionDays      int    `json:"retention_days"`
	PrometheusEnabled  bool   `json:"prometheus_enabled"`
	GrafanaEnabled     bool   `json:"grafana_enabled"`
	AlertingEnabled    bool   `json:"alerting_enabled"`
	WebhookURL         string `json:"webhook_url,omitempty"`
	SlackWebhook       string `json:"slack_webhook,omitempty"`
	EmailNotifications bool   `json:"email_notifications"`
}

type NetworkConfig

type NetworkConfig struct {
	DefaultSubnet     string `json:"default_subnet"`
	DHCPEnabled       bool   `json:"dhcp_enabled"`
	VLANSupport       bool   `json:"vlan_support"`
	SDNEnabled        bool   `json:"sdn_enabled"`
	BandwidthLimiting bool   `json:"bandwidth_limiting"`
	QoSEnabled        bool   `json:"qos_enabled"`
	FirewallEnabled   bool   `json:"firewall_enabled"`
	DNSServers        string `json:"dns_servers"`
}

type QueryRequest

type QueryRequest struct {
	SQL string `json:"sql"`
}

type QueryResult

type QueryResult struct {
	Columns  []string        `json:"columns"`
	Rows     [][]interface{} `json:"rows"`
	Affected int64           `json:"affected"`
	Duration string          `json:"duration"`
}

type ResourceLimits

type ResourceLimits struct {
	MaxCPUCores    int `json:"max_cpu_cores"`
	MaxMemoryGB    int `json:"max_memory_gb"`
	MaxDiskGB      int `json:"max_disk_gb"`
	MaxNetworkMbps int `json:"max_network_mbps"`
}

type SecureUserManagementHandlers

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

func NewSecureUserManagementHandlers

func NewSecureUserManagementHandlers(db *sql.DB) *SecureUserManagementHandlers

func (*SecureUserManagementHandlers) AssignRoles

POST /api/admin/users/{id}/roles - Assign roles to user (SQL injection safe)

func (*SecureUserManagementHandlers) CreateUser

POST /api/admin/users - Create user (SQL injection safe)

func (*SecureUserManagementHandlers) DeleteUser

DELETE /api/admin/users/{id} - Delete user (SQL injection safe)

func (*SecureUserManagementHandlers) ListUsers

GET /api/admin/users - List users with pagination (SQL injection safe)

func (*SecureUserManagementHandlers) UpdateUser

PUT /api/admin/users/{id} - Update user (SQL injection safe)

type SecurityAlert

type SecurityAlert struct {
	ID          int       `json:"id"`
	Type        string    `json:"type"`
	Severity    string    `json:"severity"`
	Title       string    `json:"title"`
	Description string    `json:"description"`
	Source      string    `json:"source"`
	IP          string    `json:"ip,omitempty"`
	UserAgent   string    `json:"user_agent,omitempty"`
	Status      string    `json:"status"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

type SecurityConfig

type SecurityConfig struct {
	JWTSecret           string `json:"-"` // Hidden from JSON
	JWTExpiryHours      int    `json:"jwt_expiry_hours"`
	PasswordMinLength   int    `json:"password_min_length"`
	RequireSpecialChars bool   `json:"require_special_chars"`
	MaxLoginAttempts    int    `json:"max_login_attempts"`
	LockoutDuration     int    `json:"lockout_duration_minutes"`
	SessionTimeout      int    `json:"session_timeout_minutes"`
	RequireMFA          bool   `json:"require_mfa"`
	AllowedOrigins      string `json:"allowed_origins"`
	RateLimitEnabled    bool   `json:"rate_limit_enabled"`
	RateLimitRPM        int    `json:"rate_limit_rpm"`
}

type SecurityHandlers

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

func NewSecurityHandlers

func NewSecurityHandlers(db *sql.DB) *SecurityHandlers

func (*SecurityHandlers) CreateSecurityAlert

func (h *SecurityHandlers) CreateSecurityAlert(alertType, severity, title, description, source, ip, userAgent string) error

Helper function to create a security alert

func (*SecurityHandlers) GetAuditLogs

func (h *SecurityHandlers) GetAuditLogs(w http.ResponseWriter, r *http.Request)

GET /api/admin/security/audit - Get audit logs

func (*SecurityHandlers) GetSecurityAlerts

func (h *SecurityHandlers) GetSecurityAlerts(w http.ResponseWriter, r *http.Request)

GET /api/admin/security/alerts - Get security alerts

func (*SecurityHandlers) GetSecurityMetrics

func (h *SecurityHandlers) GetSecurityMetrics(w http.ResponseWriter, r *http.Request)

GET /api/admin/security/metrics - Get security metrics overview

func (*SecurityHandlers) GetSecurityPolicies

func (h *SecurityHandlers) GetSecurityPolicies(w http.ResponseWriter, r *http.Request)

GET /api/admin/security/policies - Get security policies

func (*SecurityHandlers) LogAuditEntry

func (h *SecurityHandlers) LogAuditEntry(userID int, action, resource string, details map[string]interface{}, ip, userAgent string, success bool) error

Helper function to log audit entry

func (*SecurityHandlers) UpdateSecurityPolicy

func (h *SecurityHandlers) UpdateSecurityPolicy(w http.ResponseWriter, r *http.Request)

PUT /api/admin/security/policies/{id} - Update security policy

type SecurityMetrics

type SecurityMetrics struct {
	TotalAlerts      int             `json:"total_alerts"`
	CriticalAlerts   int             `json:"critical_alerts"`
	FailedLogins     int             `json:"failed_logins_24h"`
	ActiveSessions   int             `json:"active_sessions"`
	LastBreach       *time.Time      `json:"last_breach,omitempty"`
	AlertsByType     map[string]int  `json:"alerts_by_type"`
	AlertsBySeverity map[string]int  `json:"alerts_by_severity"`
	RecentActivities []AuditLogEntry `json:"recent_activities"`
	TopIPs           []IPStatistic   `json:"top_ips"`
}

type SecurityPolicy

type SecurityPolicy struct {
	ID                  int    `json:"id"`
	Name                string `json:"name"`
	Description         string `json:"description"`
	Enabled             bool   `json:"enabled"`
	MaxLoginAttempts    int    `json:"max_login_attempts"`
	LockoutDuration     int    `json:"lockout_duration_minutes"`
	SessionTimeout      int    `json:"session_timeout_minutes"`
	PasswordMinLength   int    `json:"password_min_length"`
	PasswordRequireSpec bool   `json:"password_require_special"`
	RequireMFA          bool   `json:"require_mfa"`
	AllowedIPs          string `json:"allowed_ips,omitempty"`
	BlockedIPs          string `json:"blocked_ips,omitempty"`
}

type ServerConfig

type ServerConfig struct {
	APIPort        int    `json:"api_port"`
	WSPort         int    `json:"ws_port"`
	LogLevel       string `json:"log_level"`
	LogFormat      string `json:"log_format"`
	Environment    string `json:"environment"`
	MaxConnections int    `json:"max_connections"`
	RequestTimeout int    `json:"request_timeout_seconds"`
	EnableCORS     bool   `json:"enable_cors"`
	TLSEnabled     bool   `json:"tls_enabled"`
	TLSCertPath    string `json:"tls_cert_path,omitempty"`
	TLSKeyPath     string `json:"tls_key_path,omitempty"`
}

type StorageConfig

type StorageConfig struct {
	DefaultPath         string `json:"default_path"`
	MaxDiskUsage        int    `json:"max_disk_usage_gb"`
	CompressionEnabled  bool   `json:"compression_enabled"`
	EncryptionEnabled   bool   `json:"encryption_enabled"`
	BackupEnabled       bool   `json:"backup_enabled"`
	BackupRetentionDays int    `json:"backup_retention_days"`
	TieredStorage       bool   `json:"tiered_storage_enabled"`
}

type SystemConfig

type SystemConfig struct {
	Server      ServerConfig     `json:"server"`
	Database    DatabaseConfig   `json:"database"`
	Security    SecurityConfig   `json:"security"`
	Storage     StorageConfig    `json:"storage"`
	VM          VMConfig         `json:"vm"`
	Monitoring  MonitoringConfig `json:"monitoring"`
	Network     NetworkConfig    `json:"network"`
	LastUpdated time.Time        `json:"last_updated"`
	UpdatedBy   string           `json:"updated_by,omitempty"`
}

type TableDetailsResponse

type TableDetailsResponse struct {
	Table   TableInfo    `json:"table"`
	Columns []ColumnInfo `json:"columns"`
	Indexes []IndexInfo  `json:"indexes"`
}

type TableInfo

type TableInfo struct {
	Name        string `json:"name"`
	Schema      string `json:"schema"`
	RowCount    int64  `json:"row_count"`
	Size        string `json:"size"`
	Description string `json:"description"`
}

type TemplateHandlers

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

func NewTemplateHandlers

func NewTemplateHandlers(db *sql.DB) *TemplateHandlers

func (*TemplateHandlers) CreateTemplate

func (h *TemplateHandlers) CreateTemplate(w http.ResponseWriter, r *http.Request)

POST /api/admin/templates - Create a new VM template

func (*TemplateHandlers) DeleteTemplate

func (h *TemplateHandlers) DeleteTemplate(w http.ResponseWriter, r *http.Request)

DELETE /api/admin/templates/{id} - Delete template

func (*TemplateHandlers) GetTemplate

func (h *TemplateHandlers) GetTemplate(w http.ResponseWriter, r *http.Request)

GET /api/admin/templates/{id} - Get template by ID

func (*TemplateHandlers) ListTemplates

func (h *TemplateHandlers) ListTemplates(w http.ResponseWriter, r *http.Request)

GET /api/admin/templates - List VM templates

func (*TemplateHandlers) UpdateTemplate

func (h *TemplateHandlers) UpdateTemplate(w http.ResponseWriter, r *http.Request)

PUT /api/admin/templates/{id} - Update template

type TemplateListResponse

type TemplateListResponse struct {
	Templates  []VMTemplate `json:"templates"`
	Total      int          `json:"total"`
	Page       int          `json:"page"`
	PageSize   int          `json:"page_size"`
	TotalPages int          `json:"total_pages"`
}

type UpdateTemplateRequest

type UpdateTemplateRequest struct {
	Name        *string                `json:"name,omitempty"`
	Description *string                `json:"description,omitempty"`
	OS          *string                `json:"os,omitempty"`
	OSVersion   *string                `json:"os_version,omitempty"`
	CPUCores    *int                   `json:"cpu_cores,omitempty"`
	MemoryMB    *int                   `json:"memory_mb,omitempty"`
	DiskGB      *int                   `json:"disk_gb,omitempty"`
	ImagePath   *string                `json:"image_path,omitempty"`
	IsPublic    *bool                  `json:"is_public,omitempty"`
	Tags        []string               `json:"tags,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

type UpdateUserRequest

type UpdateUserRequest struct {
	Username string `json:"username,omitempty"`
	Email    string `json:"email,omitempty"`
	Role     string `json:"role,omitempty"`
	Active   *bool  `json:"active,omitempty"`
}

type User

type User struct {
	ID        int       `json:"id"`
	Username  string    `json:"username"`
	Email     string    `json:"email"`
	Role      string    `json:"role"`
	Active    bool      `json:"active"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type UserListResponse

type UserListResponse struct {
	Users      []User `json:"users"`
	Total      int    `json:"total"`
	Page       int    `json:"page"`
	PageSize   int    `json:"page_size"`
	TotalPages int    `json:"total_pages"`
}

type UserManagementHandlers

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

func NewUserManagementHandlers

func NewUserManagementHandlers(db *sql.DB) *UserManagementHandlers

func (*UserManagementHandlers) AssignRoles

func (h *UserManagementHandlers) AssignRoles(w http.ResponseWriter, r *http.Request)

POST /api/admin/users/{id}/roles - Assign roles to user

func (*UserManagementHandlers) CreateUser

func (h *UserManagementHandlers) CreateUser(w http.ResponseWriter, r *http.Request)

POST /api/admin/users - Create user

func (*UserManagementHandlers) DeleteUser

func (h *UserManagementHandlers) DeleteUser(w http.ResponseWriter, r *http.Request)

DELETE /api/admin/users/{id} - Delete user

func (*UserManagementHandlers) ListUsers

GET /api/admin/users - List users with pagination

func (*UserManagementHandlers) UpdateUser

func (h *UserManagementHandlers) UpdateUser(w http.ResponseWriter, r *http.Request)

PUT /api/admin/users/{id} - Update user

type VMConfig

type VMConfig struct {
	DefaultDriver    string         `json:"default_driver"`
	MaxVMsPerNode    int            `json:"max_vms_per_node"`
	DefaultCPU       int            `json:"default_cpu_cores"`
	DefaultMemory    int            `json:"default_memory_mb"`
	DefaultDisk      int            `json:"default_disk_gb"`
	MigrationEnabled bool           `json:"migration_enabled"`
	LiveMigration    bool           `json:"live_migration_enabled"`
	CompressionLevel int            `json:"compression_level"`
	NetworkOptimized bool           `json:"network_optimized"`
	ResourceLimits   ResourceLimits `json:"resource_limits"`
	SupportedDrivers []string       `json:"supported_drivers"`
}

type VMTemplate

type VMTemplate struct {
	ID          string                 `json:"id"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	OS          string                 `json:"os"`
	OSVersion   string                 `json:"os_version"`
	CPUCores    int                    `json:"cpu_cores"`
	MemoryMB    int                    `json:"memory_mb"`
	DiskGB      int                    `json:"disk_gb"`
	ImagePath   string                 `json:"image_path"`
	IsPublic    bool                   `json:"is_public"`
	UsageCount  int                    `json:"usage_count"`
	Tags        []string               `json:"tags,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
	CreatedBy   string                 `json:"created_by"`
	CreatedAt   time.Time              `json:"created_at"`
	UpdatedAt   time.Time              `json:"updated_at"`
}

Jump to

Keyboard shortcuts

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