biz

package
v3.3.13 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: BSD-3-Clause Imports: 58 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlertTypeCPU           = "cpu"            // CPU 使用率 %
	AlertTypeMemory        = "memory"         // 内存使用率 %
	AlertTypeSwap          = "swap"           // Swap 使用率 %
	AlertTypeLoad1         = "load1"          // 1 分钟平均负载
	AlertTypeLoad5         = "load5"          // 5 分钟平均负载
	AlertTypeLoad15        = "load15"         // 15 分钟平均负载
	AlertTypeDisk          = "disk"           // 磁盘使用率 %,目标为挂载点
	AlertTypeDiskInode     = "disk_inode"     // 磁盘 inode 使用率 %,目标为挂载点
	AlertTypeDiskRead      = "disk_read"      // 磁盘读取速率 MB/s,目标为设备名
	AlertTypeDiskWrite     = "disk_write"     // 磁盘写入速率 MB/s,目标为设备名
	AlertTypeNetIn         = "net_in"         // 网卡下行速率 MB/s,目标为网卡名
	AlertTypeNetOut        = "net_out"        // 网卡上行速率 MB/s,目标为网卡名
	AlertTypeWebsite5xx    = "website_5xx"    // 网站本小时 5xx 次数,目标为网站名
	AlertTypeWebsiteError  = "website_error"  // 网站本小时错误率 %,目标为网站名
	AlertTypeService       = "service"        // 服务未运行,目标为服务名
	AlertTypeProject       = "project"        // 项目未运行,目标为项目名
	AlertTypeContainer     = "container"      // 容器未运行,目标为容器名
	AlertTypeApp           = "app"            // 应用未运行,目标为应用标识
	AlertTypeDatabase      = "database"       // 数据库服务器不可达,目标为服务器名
	AlertTypeCertExpire    = "cert_expire"    // 证书剩余天数,目标为域名
	AlertTypeWebsiteExpire = "website_expire" // 网站剩余天数,目标为网站名
)

告警指标类型

View Source
const (
	AlertOperatorGT  = "gt"
	AlertOperatorGTE = "gte"
	AlertOperatorLT  = "lt"
	AlertOperatorLTE = "lte"
)

告警比较运算符

View Source
const (
	OperationTypePanel          = "panel"
	OperationTypeWebsite        = "website"
	OperationTypeDatabase       = "database"
	OperationTypeDatabaseUser   = "database_user"
	OperationTypeDatabaseServer = "database_server"
	OperationTypeProject        = "project"
	OperationTypeCert           = "cert"
	OperationTypeFile           = "file"
	OperationTypeApp            = "app"
	OperationTypeCron           = "cron"
	OperationTypeBackup         = "backup"
	OperationTypeContainer      = "container"
	OperationTypeFirewall       = "firewall"
	OperationTypeSafe           = "safe"
	OperationTypeSSH            = "ssh"
	OperationTypeSetting        = "setting"
	OperationTypeMonitor        = "monitor"
	OperationTypeWebhook        = "webhook"
	OperationTypeUser           = "user"
	OperationTypeEnvironment    = "environment"
	OperationTypeToolbox        = "toolbox"
	OperationTypeSystem         = "system"
)

操作日志类型常量

View Source
const LogTypeApp = "app"

Variables

This section is empty.

Functions

func ContainerSock added in v3.3.13

func ContainerSock(setting SettingRepo) string

ContainerSock 从设置读取容器 socket 路径,未配置或失败时返回默认值

func CustomCompileApp added in v3.3.0

func CustomCompileApp(slug string) bool

CustomCompileApp 判断应用是否支持自定义编译参数

func CustomCompileEnv added in v3.3.0

func CustomCompileEnv(typ string) bool

CustomCompileEnv 判断环境类型是否支持自定义编译参数

func MigrationItemKey added in v3.3.2

func MigrationItemKey(typ, id string) string

MigrationItemKey 生成前端选择用的资源标识

func NotifyBody added in v3.3.1

func NotifyBody(summary string, rows [][2]string) string

NotifyBody 构建通知正文,rows 为「名称,值」明细

func OperatorID added in v3.3.12

func OperatorID(ctx context.Context) uint64

OperatorID 从 context 获取操作员 ID,无法获取时返回 0(系统操作),供各层记操作日志用

func RegisterCertHook added in v3.3.12

func RegisterCertHook(hook CertHook)

RegisterCertHook 注册证书更新钩子,子应用在构造时调用

Types

type Alert added in v3.3.1

type Alert struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	RuleID    uint      `gorm:"not null;default:0;index" json:"rule_id"`
	RuleName  string    `gorm:"not null;default:''" json:"rule_name"`
	Type      string    `gorm:"not null;default:''" json:"type"`
	Target    string    `gorm:"not null;default:''" json:"target"`
	Value     float64   `gorm:"not null;default:0" json:"value"`
	Message   string    `gorm:"not null;default:''" json:"message"`
	Notified  bool      `gorm:"not null;default:false" json:"notified"`
	CreatedAt time.Time `gorm:"index" json:"created_at"`
}

Alert 告警记录

type AlertMetric added in v3.3.1

type AlertMetric struct {
	Target string
	Value  float64
}

AlertMetric 单个目标的取值

type AlertRepo added in v3.3.1

type AlertRepo interface {
	ListRules(page, limit uint) ([]*AlertRule, int64, error)
	AllRules() ([]*AlertRule, error)
	GetRule(id uint) (*AlertRule, error)
	CreateRule(rule *AlertRule) error
	UpdateRule(rule *AlertRule) error
	DeleteRule(id uint) error
	AddAlert(alert *Alert) error
	ListAlerts(page, limit uint) ([]*Alert, int64, error)
	ClearAlerts() error
	ClearAlertsBefore(t time.Time) error
	CertExpiry() ([]*AlertMetric, error)
	WebsiteExpiry() ([]*AlertMetric, error)
	ProjectNames() ([]string, error)
	DatabaseServers() ([]*DatabaseServer, error)
	WebsiteHourStats() ([]*WebsiteHourStat, error)
}

type AlertRule added in v3.3.1

type AlertRule struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Name      string    `gorm:"not null;default:''" json:"name"`
	Type      string    `gorm:"not null;default:''" json:"type"`
	Target    string    `gorm:"not null;default:''" json:"target"`     // 挂载点/网卡/磁盘/服务名/域名,空表示全部
	Operator  string    `gorm:"not null;default:'gt'" json:"operator"` // gt/gte/lt/lte
	Threshold float64   `gorm:"not null;default:0" json:"threshold"`
	Duration  uint      `gorm:"not null;default:1" json:"duration"` // 连续满足次数
	Silence   uint      `gorm:"not null;default:30" json:"silence"` // 静默期(分钟)
	Channels  []uint    `gorm:"serializer:json" json:"channels"`    // 通知渠道 ID
	Enabled   bool      `gorm:"not null;default:true" json:"enabled"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

AlertRule 告警规则

type AlertUsecase added in v3.3.1

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

func NewAlertUsecase added in v3.3.1

func NewAlertUsecase(
	notifyUsecase *NotifyUsecase,
	loader *apploader.Loader,
	t *gotext.Locale,
	log *slog.Logger,
	alertRepo AlertRepo,
	appRepo AppRepo,
	containerRepo ContainerRepo,
	databaseServerRepo DatabaseServerRepo,
	settingRepo SettingRepo,
) *AlertUsecase

func (*AlertUsecase) ClearAlerts added in v3.3.1

func (uc *AlertUsecase) ClearAlerts(ctx context.Context) error

func (*AlertUsecase) CreateRule added in v3.3.1

func (uc *AlertUsecase) CreateRule(ctx context.Context, req *request.AlertRuleCreate) (*AlertRule, error)

func (*AlertUsecase) DeleteRule added in v3.3.1

func (uc *AlertUsecase) DeleteRule(ctx context.Context, id uint) error

func (*AlertUsecase) Evaluate added in v3.3.1

func (uc *AlertUsecase) Evaluate(ctx context.Context) error

Evaluate 评估全部启用的规则,命中则记录并通知

func (*AlertUsecase) GetRule added in v3.3.1

func (uc *AlertUsecase) GetRule(ctx context.Context, id uint) (*AlertRule, error)

func (*AlertUsecase) ListAlerts added in v3.3.1

func (uc *AlertUsecase) ListAlerts(ctx context.Context, page, limit uint) ([]*Alert, int64, error)

func (*AlertUsecase) ListRules added in v3.3.1

func (uc *AlertUsecase) ListRules(ctx context.Context, page, limit uint) ([]*AlertRule, int64, error)

func (*AlertUsecase) UpdateRule added in v3.3.1

func (uc *AlertUsecase) UpdateRule(ctx context.Context, req *request.AlertRuleUpdate) error

type App

type App struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Slug      string    `gorm:"not null;default:'';unique" json:"slug"`
	Channel   string    `gorm:"not null;default:''" json:"channel"`
	Version   string    `gorm:"not null;default:''" json:"version"`
	Show      bool      `gorm:"not null;default:false" json:"show"`
	ShowOrder int       `gorm:"not null;default:0" json:"show_order"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type AppCustom added in v3.3.0

type AppCustom struct {
	PreScript string `json:"pre_script"`
	Args      string `json:"args"`
}

AppCustom 自定义编译参数(前置脚本在 configure 前执行,参数追加到 configure 末尾)

type AppRepo

type AppRepo interface {
	Installed() ([]*App, error)
	GetInstalled(slug string) (*App, error)
	ListHomeShow() ([]*App, error)
	IsInstalled(query string, cond ...any) (bool, error)
	UpdateShow(slug string, show bool) error
	UpdateOrder(slugs []string) error
	DownloadCallback(slug string)
	CheckPanelVersion() error
	ResolveScript(item *api.App, matchChannel, action, execVersion string) (string, error)
	ExecScript(ctx context.Context, script string) error
	PreCheck(item *api.App, catalog api.Apps) error
	GetCustom(slug string) (*AppCustom, error)
	SaveCustom(ctx context.Context, slug string, custom *AppCustom) error
}

type AppUsecase added in v3.3.0

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

func NewAppUsecase added in v3.3.0

func NewAppUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	appRepo AppRepo,
	cacheRepo CacheRepo,
	taskRepo TaskRepo,
) *AppUsecase

func (*AppUsecase) All added in v3.3.0

func (uc *AppUsecase) All() api.Apps

func (*AppUsecase) Categories added in v3.3.0

func (uc *AppUsecase) Categories() []types.LV

func (*AppUsecase) Get added in v3.3.0

func (uc *AppUsecase) Get(slug string) (*api.App, error)

func (*AppUsecase) GetCustom added in v3.3.0

func (uc *AppUsecase) GetCustom(slug string) (*AppCustom, error)

func (*AppUsecase) GetHomeShow added in v3.3.0

func (uc *AppUsecase) GetHomeShow() ([]map[string]string, error)

func (*AppUsecase) GetInstalled added in v3.3.0

func (uc *AppUsecase) GetInstalled(slug string) (*App, error)

func (*AppUsecase) Install added in v3.3.0

func (uc *AppUsecase) Install(ctx context.Context, channel, slug string) error

func (*AppUsecase) Installed added in v3.3.0

func (uc *AppUsecase) Installed() ([]*App, error)

func (*AppUsecase) IsInstalled added in v3.3.0

func (uc *AppUsecase) IsInstalled(query string, cond ...any) (bool, error)

func (*AppUsecase) SaveCustom added in v3.3.0

func (uc *AppUsecase) SaveCustom(ctx context.Context, slug string, custom *AppCustom) error

func (*AppUsecase) UnInstall added in v3.3.0

func (uc *AppUsecase) UnInstall(ctx context.Context, slug string) error

func (*AppUsecase) Update added in v3.3.0

func (uc *AppUsecase) Update(ctx context.Context, slug string) error

func (*AppUsecase) UpdateOrder added in v3.3.0

func (uc *AppUsecase) UpdateOrder(slugs []string) error

func (*AppUsecase) UpdateShow added in v3.3.0

func (uc *AppUsecase) UpdateShow(ctx context.Context, slug string, show bool) error

type BackupAccountRepo

type BackupAccountRepo interface {
	ListPaged(page, limit uint) ([]*BackupStorage, int64, error)
	GetByID(id uint) (*BackupStorage, error)
	Create(account *BackupStorage) error
	Update(account *BackupStorage) error
	Delete(id uint) error
	Check(ctx context.Context, account *BackupStorage) error
}

type BackupAccountUsecase added in v3.3.0

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

func NewBackupAccountUsecase added in v3.3.0

func NewBackupAccountUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	backupAccountRepo BackupAccountRepo,
	settingRepo SettingRepo,
) *BackupAccountUsecase

func (*BackupAccountUsecase) Create added in v3.3.0

func (*BackupAccountUsecase) Delete added in v3.3.0

func (uc *BackupAccountUsecase) Delete(ctx context.Context, id uint) error

func (*BackupAccountUsecase) Get added in v3.3.0

func (uc *BackupAccountUsecase) Get(id uint) (*BackupStorage, error)

func (*BackupAccountUsecase) List added in v3.3.0

func (uc *BackupAccountUsecase) List(page, limit uint) ([]*BackupStorage, int64, error)

func (*BackupAccountUsecase) Update added in v3.3.0

type BackupRepo

type BackupRepo interface {
	List(typ BackupType) ([]*types.BackupFile, error)
	Create(ctx context.Context, typ BackupType, target string, account uint) error
	CreatePanel(ctx context.Context) error
	Delete(ctx context.Context, typ BackupType, name string) error
	Restore(ctx context.Context, typ BackupType, backup, target string) error
	ClearExpired(path, prefix string, save uint) error
	ClearStorageExpired(ctx context.Context, account uint, dir, prefix string, save uint) error
	CutoffLog(ctx context.Context, path, target string) (string, error)
	CutoffUpload(ctx context.Context, account uint, typ BackupType, name string, files []string) error
	GetDefaultPath(typ BackupType) string
	FixPanel(ctx context.Context) error
	UpdatePanel(ctx context.Context, version, url, checksum string, progress func(string)) error
}

type BackupStorage

type BackupStorage struct {
	ID        uint                    `gorm:"primaryKey" json:"id"`
	Type      BackupStorageType       `gorm:"not null;default:''" json:"type"`
	Name      string                  `gorm:"not null;default:''" json:"name"`
	Info      types.BackupStorageInfo `gorm:"not null;default:'{}';serializer:json" json:"info"`
	CreatedAt time.Time               `json:"created_at"`
	UpdatedAt time.Time               `json:"updated_at"`
}

func (*BackupStorage) AfterFind

func (r *BackupStorage) AfterFind(tx *gorm.DB) error

func (*BackupStorage) BeforeSave

func (r *BackupStorage) BeforeSave(tx *gorm.DB) error

type BackupStorageType

type BackupStorageType string
const (
	BackupStorageTypeLocal  BackupStorageType = "local"
	BackupStorageTypeS3     BackupStorageType = "s3"
	BackupStorageTypeSFTP   BackupStorageType = "sftp"
	BackupStorageTypeWebDAV BackupStorageType = "webdav"
)

type BackupType

type BackupType string
const (
	BackupTypePath       BackupType = "path"
	BackupTypeWebsite    BackupType = "website"
	BackupTypeMySQL      BackupType = "mysql"
	BackupTypePostgres   BackupType = "postgresql"
	BackupTypeClickHouse BackupType = "clickhouse"
	BackupTypeRedis      BackupType = "redis"
	BackupTypeValkey     BackupType = "valkey"
	BackupTypePanel      BackupType = "panel"
)

type BackupUsecase added in v3.3.0

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

func NewBackupUsecase added in v3.3.0

func NewBackupUsecase(
	notifyUsecase *NotifyUsecase,
	conf *config.Config,
	t *gotext.Locale,
	log *slog.Logger,
	backupRepo BackupRepo,
	cacheRepo CacheRepo,
	settingRepo SettingRepo,
) *BackupUsecase

func (*BackupUsecase) ClearExpired added in v3.3.0

func (uc *BackupUsecase) ClearExpired(path, prefix string, save uint) error

func (*BackupUsecase) ClearStorageExpired added in v3.3.0

func (uc *BackupUsecase) ClearStorageExpired(ctx context.Context, account uint, dir, prefix string, save uint) error

func (*BackupUsecase) Create added in v3.3.0

func (uc *BackupUsecase) Create(ctx context.Context, typ BackupType, target string, account uint) error

func (*BackupUsecase) CreatePanel added in v3.3.0

func (uc *BackupUsecase) CreatePanel(ctx context.Context) error

func (*BackupUsecase) CutoffLog added in v3.3.0

func (uc *BackupUsecase) CutoffLog(ctx context.Context, path, target string) (string, error)

func (*BackupUsecase) CutoffUpload added in v3.3.0

func (uc *BackupUsecase) CutoffUpload(
	ctx context.Context,
	account uint,
	typ BackupType,
	name string,
	files []string,
) error

func (*BackupUsecase) Delete added in v3.3.0

func (uc *BackupUsecase) Delete(ctx context.Context, typ BackupType, name string) error

func (*BackupUsecase) FixPanel added in v3.3.0

func (uc *BackupUsecase) FixPanel(ctx context.Context) error

func (*BackupUsecase) GetDefaultPath added in v3.3.0

func (uc *BackupUsecase) GetDefaultPath(typ BackupType) string

func (*BackupUsecase) LatestPanel added in v3.3.13

func (uc *BackupUsecase) LatestPanel() (*PanelRelease, error)

LatestPanel 取更新渠道内最新的面板版本及其安装包地址

func (*BackupUsecase) List added in v3.3.0

func (uc *BackupUsecase) List(typ BackupType) ([]*types.BackupFile, error)

func (*BackupUsecase) ListGroup added in v3.3.7

func (uc *BackupUsecase) ListGroup(typ BackupType) ([]*types.BackupGroup, error)

ListGroup 时间点取文件名中的时间,上传或拷贝来的旧备份修改时间不可信

func (*BackupUsecase) PanelChangelog added in v3.3.13

func (uc *BackupUsecase) PanelChangelog() (*api.Versions, error)

PanelChangelog 取运行中的版本之后更新渠道内发布的全部版本

func (*BackupUsecase) Restore added in v3.3.0

func (uc *BackupUsecase) Restore(ctx context.Context, typ BackupType, backup, target string) error

func (*BackupUsecase) UpdatePanel added in v3.3.0

func (uc *BackupUsecase) UpdatePanel(ctx context.Context, release *PanelRelease, progress func(string)) error

type Cache

type Cache struct {
	Key       CacheKey  `gorm:"primaryKey" json:"key"`
	Value     string    `gorm:"not null;default:''" json:"value"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type CacheKey

type CacheKey string
const (
	CacheKeyCategories  CacheKey = "categories"
	CacheKeyApps        CacheKey = "apps"
	CacheKeyEnvironment CacheKey = "environment"
	CacheKeyTemplates   CacheKey = "templates"
)

type CacheRepo

type CacheRepo interface {
	Get(key CacheKey, defaultValue ...string) (string, error)
	Set(key CacheKey, value string) error
	FetchCategories() (*api.Categories, error)
	FetchApps() (*api.Apps, error)
	FetchEnvironments() (*api.Environments, error)
	FetchTemplates() (*api.Templates, error)
	FetchLatestVersion(channel string) (*api.Version, error)
	FetchIntermediateVersions(channel string) (*api.Versions, error)
}

type CacheUpdate added in v3.3.13

type CacheUpdate struct {
	Key CacheKey
	Run func() error
}

CacheUpdate 一项云端数据缓存的刷新动作

type CacheUsecase added in v3.3.0

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

func NewCacheUsecase added in v3.3.0

func NewCacheUsecase(repo CacheRepo) *CacheUsecase

func (*CacheUsecase) UpdateAll added in v3.3.13

func (uc *CacheUsecase) UpdateAll() (CacheKey, error)

UpdateAll 依次刷新全部云端数据缓存,出错即停并返回出错的那一项

func (*CacheUsecase) Updates added in v3.3.13

func (uc *CacheUsecase) Updates() []CacheUpdate

Updates 按刷新顺序列出全部云端数据缓存

type Cert

type Cert struct {
	ID          uint                  `gorm:"primaryKey" json:"id"`
	AccountID   uint                  `gorm:"not null;default:0" json:"account_id"`                      // 关联的 ACME 账户 ID
	DNSID       uint                  `gorm:"not null;default:0" json:"dns_id"`                          // 关联的 DNS ID
	Type        string                `gorm:"not null;default:''" json:"type"`                           // 证书类型 (P256, P384, 2048, 3072, 4096)
	Domains     []string              `gorm:"not null;default:'[]';serializer:json" json:"domains"`      // 域名
	Alias       map[string]string     `gorm:"not null;default:'{}';serializer:json" json:"alias"`        // DNS 验证别名
	AutoRenewal bool                  `gorm:"not null;default:false" json:"auto_renewal"`                // 自动续签
	RenewalInfo mholtacme.RenewalInfo `gorm:"not null;default:'{}';serializer:json" json:"renewal_info"` // 续签信息
	CertURL     string                `gorm:"not null;default:''" json:"cert_url"`                       // 证书 URL (续签时使用)
	Cert        string                `gorm:"not null;default:''" json:"cert"`                           // 证书内容
	Key         string                `gorm:"not null;default:''" json:"key"`                            // 私钥内容
	CertPath    string                `gorm:"not null;default:''" json:"cert_path"`                      // 证书文件路径 (从路径导入时使用)
	KeyPath     string                `gorm:"not null;default:''" json:"key_path"`                       // 私钥文件路径 (从路径导入时使用)
	Script      string                `gorm:"not null;default:''" json:"script"`                         // 部署脚本
	CreatedAt   time.Time             `json:"created_at"`
	UpdatedAt   time.Time             `json:"updated_at"`

	Websites []*Website   `gorm:"foreignKey:CertID" json:"websites"` // 部署的网站
	Account  *CertAccount `gorm:"foreignKey:AccountID" json:"account"`
	DNS      *CertDNS     `gorm:"foreignKey:DNSID" json:"dns"`
}

func (*Cert) WebsiteIDs added in v3.3.2

func (r *Cert) WebsiteIDs() []uint

WebsiteIDs 取证书关联的网站 ID 列表

type CertAccount

type CertAccount struct {
	ID          uint      `gorm:"primaryKey" json:"id"`
	Email       string    `gorm:"not null;default:''" json:"email"`
	CA          string    `gorm:"not null;default:'letsencrypt'" json:"ca"` // CA 提供商 (letsencrypt, zerossl, sslcom, google)
	Kid         string    `gorm:"not null;default:''" json:"kid"`
	HmacEncoded string    `gorm:"not null;default:''" json:"hmac_encoded"`
	PrivateKey  string    `gorm:"not null;default:''" json:"private_key"`
	KeyType     string    `gorm:"not null;default:'P256'" json:"key_type"` // 密钥类型 (P256, P384, 2048, 3072, 4096)
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`

	Certs []*Cert `gorm:"foreignKey:AccountID" json:"-"`
}

func (*CertAccount) Directory added in v3.3.13

func (r *CertAccount) Directory() string

Directory 取账户所属 CA 的 ACME 目录地址,CA 不受支持时为空

func (*CertAccount) EAB added in v3.3.13

func (r *CertAccount) EAB() *acme.EAB

EAB 取回已注册账户时要带的 EAB 凭据,不需要时为 nil

type CertAccountRepo

type CertAccountRepo interface {
	List(page, limit uint) ([]*CertAccount, int64, error)
	Get(id uint) (*CertAccount, error)
	GetByCAEmail(ca, email string) (*CertAccount, error)
	Create(account *CertAccount) error
	Save(account *CertAccount) error
	Delete(id uint) error
	GetGoogleEAB() (*acme.EAB, error)
	GetZeroSSLEAB(email string) (*acme.EAB, error)
	RegisterAccount(ctx context.Context, email, ca string, eab *acme.EAB, keyType acme.KeyType) (*acme.Client, error)
}

type CertAccountUsecase added in v3.3.0

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

func NewCertAccountUsecase added in v3.3.0

func NewCertAccountUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	certAccountRepo CertAccountRepo,
	userRepo UserRepo,
) *CertAccountUsecase

func (*CertAccountUsecase) Create added in v3.3.0

func (*CertAccountUsecase) Delete added in v3.3.0

func (uc *CertAccountUsecase) Delete(ctx context.Context, id uint) error

func (*CertAccountUsecase) Get added in v3.3.0

func (uc *CertAccountUsecase) Get(id uint) (*CertAccount, error)

func (*CertAccountUsecase) GetDefault added in v3.3.0

func (uc *CertAccountUsecase) GetDefault(ctx context.Context, userID uint) (*CertAccount, error)

func (*CertAccountUsecase) List added in v3.3.0

func (uc *CertAccountUsecase) List(page, limit uint) ([]*CertAccount, int64, error)

func (*CertAccountUsecase) Update added in v3.3.0

type CertDNS

type CertDNS struct {
	ID        uint          `gorm:"primaryKey" json:"id"`
	Name      string        `gorm:"not null;default:''" json:"name"`       // 备注名称
	Type      acme.DnsType  `gorm:"not null;default:'aliyun'" json:"type"` // DNS 提供商
	Data      acme.DNSParam `gorm:"not null;default:'{}';serializer:json" json:"dns_param"`
	CreatedAt time.Time     `json:"created_at"`
	UpdatedAt time.Time     `json:"updated_at"`

	Certs []*Cert `gorm:"foreignKey:DNSID" json:"-"`
}

type CertDNSRepo

type CertDNSRepo interface {
	List(page, limit uint) ([]*CertDNS, int64, error)
	Get(id uint) (*CertDNS, error)
	Create(req *request.CertDNSCreate) (*CertDNS, error)
	Update(req *request.CertDNSUpdate) error
	Delete(id uint) error
}

type CertDNSUsecase added in v3.3.0

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

func NewCertDNSUsecase added in v3.3.0

func NewCertDNSUsecase(t *gotext.Locale, log *slog.Logger, repo CertDNSRepo) *CertDNSUsecase

func (*CertDNSUsecase) Create added in v3.3.0

func (uc *CertDNSUsecase) Create(ctx context.Context, req *request.CertDNSCreate) (*CertDNS, error)

func (*CertDNSUsecase) Delete added in v3.3.0

func (uc *CertDNSUsecase) Delete(ctx context.Context, id uint) error

func (*CertDNSUsecase) Get added in v3.3.0

func (uc *CertDNSUsecase) Get(id uint) (*CertDNS, error)

func (*CertDNSUsecase) List added in v3.3.0

func (uc *CertDNSUsecase) List(page, limit uint) ([]*CertDNS, int64, error)

func (*CertDNSUsecase) Update added in v3.3.0

func (uc *CertDNSUsecase) Update(ctx context.Context, req *request.CertDNSUpdate) error

type CertHook added in v3.3.12

type CertHook func(ctx context.Context, cert *Cert) error

CertHook 在证书签发、续签或重新生成后被调用,供面板外的服务(如邮件服务)同步最新证书

type CertRepo

type CertRepo interface {
	List(page, limit uint) ([]*types.CertList, int64, error)
	Get(id uint) (*Cert, error)
	GetByWebsite(WebsiteID uint) (*Cert, error)
	Create(req *request.CertCreate) (*Cert, error)
	CreateUploaded(cert *Cert) error
	Update(req *request.CertUpdate) error
	Delete(id uint) error
	Save(cert *Cert) error
	GetClient(ctx context.Context, cert *Cert) (*acme.Client, error)
	GenerateSelfSigned(domains []string) ([]byte, []byte, error)
	RunScript(ctx context.Context, cert *Cert) error
	ObtainPanel(ctx context.Context, account *CertAccount, names []string, webServer string) ([]byte, []byte, error)
	LoadWebsites(websiteIDs []uint) ([]*Website, error)
	BindWebsites(certID uint, websiteIDs []uint) error
	HTTPConfs(cert *Cert, webServer string) (map[string]string, []string)
	ReadCertFiles(certPath, keyPath string) (string, string, error)
	WriteCertFiles(cert *Cert, certPath, keyPath string) error
	EnableWebsiteSSL(website *Website, certPath, keyPath, webServer string, tlsVersions []string, listenIPv6 bool) error
	ReloadWebserver(ctx context.Context, webServer string) error
}

type CertUsecase added in v3.3.0

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

func NewCertUsecase added in v3.3.0

func NewCertUsecase(t *gotext.Locale, log *slog.Logger, certRepo CertRepo, settingRepo SettingRepo) *CertUsecase

func (*CertUsecase) Create added in v3.3.0

func (uc *CertUsecase) Create(ctx context.Context, req *request.CertCreate) (*Cert, error)

func (*CertUsecase) Delete added in v3.3.0

func (uc *CertUsecase) Delete(ctx context.Context, id uint) error

func (*CertUsecase) Deploy added in v3.3.0

func (uc *CertUsecase) Deploy(ctx context.Context, id uint, websiteIDs []uint, enableHTTPS bool) error

func (*CertUsecase) Get added in v3.3.0

func (uc *CertUsecase) Get(id uint) (*Cert, error)

func (*CertUsecase) GetByWebsite added in v3.3.0

func (uc *CertUsecase) GetByWebsite(websiteID uint) (*Cert, error)

func (*CertUsecase) List added in v3.3.0

func (uc *CertUsecase) List(page, limit uint) ([]*types.CertList, int64, error)

func (*CertUsecase) ObtainAutoWithProgressCallback added in v3.3.0

func (uc *CertUsecase) ObtainAutoWithProgressCallback(
	ctx context.Context,
	id uint,
	progressCallback func(string),
) (*acme.Certificate, error)

func (*CertUsecase) ObtainPanel added in v3.3.0

func (uc *CertUsecase) ObtainPanel(
	ctx context.Context,
	account *CertAccount,
	domains []string,
) ([]byte, []byte, error)

func (*CertUsecase) ObtainSelfSigned added in v3.3.0

func (uc *CertUsecase) ObtainSelfSigned(ctx context.Context, id uint) error

func (*CertUsecase) RefreshRenewalInfo added in v3.3.0

func (uc *CertUsecase) RefreshRenewalInfo(ctx context.Context, id uint) (mholtacme.RenewalInfo, error)

func (*CertUsecase) RenewWithProgressCallback added in v3.3.0

func (uc *CertUsecase) RenewWithProgressCallback(
	ctx context.Context,
	id uint,
	progressCallback func(string),
) (*acme.Certificate, error)

func (*CertUsecase) Save added in v3.3.0

func (uc *CertUsecase) Save(cert *Cert) error

func (*CertUsecase) Update added in v3.3.0

func (uc *CertUsecase) Update(ctx context.Context, req *request.CertUpdate) error

func (*CertUsecase) Upload added in v3.3.0

func (uc *CertUsecase) Upload(ctx context.Context, req *request.CertUpload) (*Cert, error)

type ContainerComposeRepo

type ContainerComposeRepo interface {
	List(ctx context.Context) ([]types.ContainerCompose, error)
	Get(name string) (string, []types.KV, error)
	Create(name, compose string, envs []types.KV) error
	Update(name, compose string, envs []types.KV) error
	Up(ctx context.Context, name string, force bool) error
	Down(ctx context.Context, name string) error
	RemoveDir(name string) error
}

type ContainerComposeUsecase added in v3.3.0

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

func NewContainerComposeUsecase added in v3.3.0

func NewContainerComposeUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	repo ContainerComposeRepo,
) *ContainerComposeUsecase

func (*ContainerComposeUsecase) Create added in v3.3.0

func (uc *ContainerComposeUsecase) Create(ctx context.Context, name, compose string, envs []types.KV) error

func (*ContainerComposeUsecase) Down added in v3.3.0

func (uc *ContainerComposeUsecase) Down(ctx context.Context, name string) error

func (*ContainerComposeUsecase) Get added in v3.3.0

func (uc *ContainerComposeUsecase) Get(ctx context.Context, name string) (string, []types.KV, error)

func (*ContainerComposeUsecase) List added in v3.3.0

func (*ContainerComposeUsecase) Remove added in v3.3.0

func (uc *ContainerComposeUsecase) Remove(ctx context.Context, name string) error

func (*ContainerComposeUsecase) Up added in v3.3.0

func (uc *ContainerComposeUsecase) Up(ctx context.Context, name string, force bool) error

func (*ContainerComposeUsecase) Update added in v3.3.0

func (uc *ContainerComposeUsecase) Update(ctx context.Context, name, compose string, envs []types.KV) error

type ContainerImageRepo

type ContainerImageRepo interface {
	List(ctx context.Context) ([]types.ContainerImage, error)
	Exist(ctx context.Context, name string) (bool, error)
	Pull(ctx context.Context, req *request.ContainerImagePull) error
	// PullStream 发起镜像拉取并返回进度流,发起失败直接返回错误,开始后的失败在流里给出
	PullStream(ctx context.Context, req *request.ContainerImagePull) (iter.Seq2[ImagePullProgress, error], error)
	// PullShell 生成后台拉取镜像的命令,需要认证时一并返回清理凭据的命令
	PullShell(req *request.ContainerImagePull) (shell, cancelShell string, err error)
	Remove(ctx context.Context, id string) error
	Prune(ctx context.Context) error
}

type ContainerImageUsecase added in v3.3.0

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

func NewContainerImageUsecase added in v3.3.0

func NewContainerImageUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	containerImageRepo ContainerImageRepo,
	taskRepo TaskRepo,
) *ContainerImageUsecase

func (*ContainerImageUsecase) Exist added in v3.3.0

func (uc *ContainerImageUsecase) Exist(ctx context.Context, name string) (bool, error)

func (*ContainerImageUsecase) List added in v3.3.0

func (*ContainerImageUsecase) Prune added in v3.3.0

func (uc *ContainerImageUsecase) Prune(ctx context.Context) error

func (*ContainerImageUsecase) Pull added in v3.3.0

func (*ContainerImageUsecase) PullBackground added in v3.3.2

func (uc *ContainerImageUsecase) PullBackground(ctx context.Context, req *request.ContainerImagePull) error

func (*ContainerImageUsecase) PullStream added in v3.3.13

func (*ContainerImageUsecase) Remove added in v3.3.0

func (uc *ContainerImageUsecase) Remove(ctx context.Context, id string) error

type ContainerNetworkRepo

type ContainerNetworkRepo interface {
	List(ctx context.Context) ([]types.ContainerNetwork, error)
	Create(ctx context.Context, req *request.ContainerNetworkCreate) (string, error)
	Remove(ctx context.Context, id string) error
	Prune(ctx context.Context) error
}

type ContainerNetworkUsecase added in v3.3.0

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

func NewContainerNetworkUsecase added in v3.3.0

func NewContainerNetworkUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	repo ContainerNetworkRepo,
) *ContainerNetworkUsecase

func (*ContainerNetworkUsecase) Create added in v3.3.0

func (*ContainerNetworkUsecase) List added in v3.3.0

func (*ContainerNetworkUsecase) Prune added in v3.3.0

func (*ContainerNetworkUsecase) Remove added in v3.3.0

func (uc *ContainerNetworkUsecase) Remove(ctx context.Context, id string) error

type ContainerRepo

type ContainerRepo interface {
	ListAll(ctx context.Context) ([]types.Container, error)
	Inspect(ctx context.Context, id string) (any, error)
	Create(ctx context.Context, req *request.ContainerCreate) (string, error)
	// CreateShell 生成后台创建容器的命令
	CreateShell(req *request.ContainerCreate) (string, error)
	// UpdateShell 生成后台重建容器的命令:删除旧容器后按新配置创建,本地没有镜像时先拉取
	UpdateShell(id string, req *request.ContainerCreate) (string, error)
	Remove(ctx context.Context, id string) error
	Start(ctx context.Context, id string) error
	Stop(ctx context.Context, id string) error
	Restart(ctx context.Context, id string) error
	Pause(ctx context.Context, id string) error
	Unpause(ctx context.Context, id string) error
	Kill(ctx context.Context, id string) error
	Rename(ctx context.Context, id string, newName string) error
	Logs(ctx context.Context, id string, tail int) (string, error)
	// FollowLogs 把容器新增的日志持续写入 w,直到日志流结束或 ctx 取消,只在无法开始跟随时返回错误
	FollowLogs(ctx context.Context, id string, w io.Writer) error
	Prune(ctx context.Context) error
}

type ContainerUsecase added in v3.3.0

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

func NewContainerUsecase added in v3.3.0

func NewContainerUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	containerRepo ContainerRepo,
	taskRepo TaskRepo,
) *ContainerUsecase

func (*ContainerUsecase) Create added in v3.3.0

Create 创建并启动容器

func (*ContainerUsecase) CreateBackground added in v3.3.2

func (uc *ContainerUsecase) CreateBackground(ctx context.Context, req *request.ContainerCreate) error

func (*ContainerUsecase) FollowLogs added in v3.3.13

func (uc *ContainerUsecase) FollowLogs(ctx context.Context, id string, w io.Writer) error

func (*ContainerUsecase) Inspect added in v3.3.0

func (uc *ContainerUsecase) Inspect(ctx context.Context, id string) (any, error)

func (*ContainerUsecase) Kill added in v3.3.0

func (uc *ContainerUsecase) Kill(ctx context.Context, id string) error

func (*ContainerUsecase) List added in v3.3.6

func (uc *ContainerUsecase) List(ctx context.Context, keyword string) ([]types.Container, error)

List 按名称或镜像关键字筛选容器,关键字为空时返回全部

func (*ContainerUsecase) ListAll added in v3.3.0

func (uc *ContainerUsecase) ListAll(ctx context.Context) ([]types.Container, error)

func (*ContainerUsecase) Logs added in v3.3.0

func (uc *ContainerUsecase) Logs(ctx context.Context, id string, tail int) (string, error)

func (*ContainerUsecase) Pause added in v3.3.0

func (uc *ContainerUsecase) Pause(ctx context.Context, id string) error

func (*ContainerUsecase) Prune added in v3.3.0

func (uc *ContainerUsecase) Prune(ctx context.Context) error

func (*ContainerUsecase) Remove added in v3.3.0

func (uc *ContainerUsecase) Remove(ctx context.Context, id string) error

func (*ContainerUsecase) Rename added in v3.3.0

func (uc *ContainerUsecase) Rename(ctx context.Context, id string, newName string) error

func (*ContainerUsecase) Restart added in v3.3.0

func (uc *ContainerUsecase) Restart(ctx context.Context, id string) error

func (*ContainerUsecase) Start added in v3.3.0

func (uc *ContainerUsecase) Start(ctx context.Context, id string) error

func (*ContainerUsecase) Stop added in v3.3.0

func (uc *ContainerUsecase) Stop(ctx context.Context, id string) error

func (*ContainerUsecase) Unpause added in v3.3.0

func (uc *ContainerUsecase) Unpause(ctx context.Context, id string) error

func (*ContainerUsecase) Update added in v3.3.0

Update 删除旧容器后按新配置重建同名容器

func (*ContainerUsecase) UpdateBackground added in v3.3.2

func (uc *ContainerUsecase) UpdateBackground(ctx context.Context, id string, req *request.ContainerCreate) error

type ContainerVolumeRepo

type ContainerVolumeRepo interface {
	List(ctx context.Context) ([]types.ContainerVolume, error)
	Create(ctx context.Context, req *request.ContainerVolumeCreate) (string, error)
	Remove(ctx context.Context, id string) error
	Prune(ctx context.Context) error
}

type ContainerVolumeUsecase added in v3.3.0

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

func NewContainerVolumeUsecase added in v3.3.0

func NewContainerVolumeUsecase(t *gotext.Locale, log *slog.Logger, repo ContainerVolumeRepo) *ContainerVolumeUsecase

func (*ContainerVolumeUsecase) Create added in v3.3.0

func (*ContainerVolumeUsecase) List added in v3.3.0

func (*ContainerVolumeUsecase) Prune added in v3.3.0

func (*ContainerVolumeUsecase) Remove added in v3.3.0

func (uc *ContainerVolumeUsecase) Remove(ctx context.Context, id string) error

type Cron

type Cron struct {
	ID        uint             `gorm:"primaryKey" json:"id"`
	Name      string           `gorm:"not null;default:'';unique" json:"name"`
	Status    bool             `gorm:"not null;default:false" json:"status"`
	Type      string           `gorm:"not null;default:''" json:"type"`
	Time      string           `gorm:"not null;default:''" json:"time"`
	Config    types.CronConfig `gorm:"serializer:json;not null;default:'{}'" json:"config"`
	Shell     string           `gorm:"not null;default:''" json:"shell"`
	Log       string           `gorm:"not null;default:''" json:"log"`
	CreatedAt time.Time        `json:"created_at"`
	UpdatedAt time.Time        `json:"updated_at"`
}

type CronRepo

type CronRepo interface {
	Count() (int64, error)
	List(page, limit uint) ([]*Cron, int64, error)
	Get(id uint) (*Cron, error)
	Create(cron *Cron) error
	Save(cron *Cron) error
	Delete(cron *Cron) error
	GenerateScript(typ string, config types.CronConfig, rawScript string) string
	WriteNewScript(ctx context.Context, script string) (string, string, error)
	WriteScript(path, script string) error
	Dos2Unix(ctx context.Context, path string) error
	AddToSystem(ctx context.Context, cron *Cron) error
	DeleteFromSystem(ctx context.Context, cron *Cron) error
	RemoveFiles(ctx context.Context, cron *Cron) error
}

type CronUsecase added in v3.3.0

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

CronUsecase 计划任务业务逻辑

func NewCronUsecase added in v3.3.0

func NewCronUsecase(repo CronRepo, t *gotext.Locale, log *slog.Logger) *CronUsecase

func (*CronUsecase) Count added in v3.3.0

func (uc *CronUsecase) Count() (int64, error)

func (*CronUsecase) Create added in v3.3.0

func (uc *CronUsecase) Create(ctx context.Context, req *request.CronCreate) error

func (*CronUsecase) Delete added in v3.3.0

func (uc *CronUsecase) Delete(ctx context.Context, id uint) error

func (*CronUsecase) Get added in v3.3.0

func (uc *CronUsecase) Get(id uint) (*Cron, error)

func (*CronUsecase) List added in v3.3.0

func (uc *CronUsecase) List(page, limit uint) ([]*Cron, int64, error)

func (*CronUsecase) Status added in v3.3.0

func (uc *CronUsecase) Status(ctx context.Context, id uint, status bool) error

func (*CronUsecase) Update added in v3.3.0

func (uc *CronUsecase) Update(ctx context.Context, req *request.CronUpdate) error

type Database

type Database struct {
	Type     DatabaseType `json:"type"`
	Name     string       `json:"name"`
	Server   string       `json:"server"`
	ServerID uint         `json:"server_id"`
	Encoding string       `json:"encoding"`
	Comment  string       `json:"comment"`
}

type DatabaseElasticsearchRepo added in v3.2.0

type DatabaseElasticsearchRepo interface {
	Indices(ctx context.Context, req *request.DatabaseESIndices) ([]db.ESIndex, error)
	IndexCreate(ctx context.Context, req *request.DatabaseESIndexCreate) error
	IndexDelete(ctx context.Context, req *request.DatabaseESIndexDelete) error
	Data(ctx context.Context, req *request.DatabaseESData) ([]db.ESDocument, int64, error)
	DocumentGet(ctx context.Context, req *request.DatabaseESDocumentGet) (*db.ESDocument, error)
	DocumentSet(ctx context.Context, req *request.DatabaseESDocumentSet) error
	DocumentDelete(ctx context.Context, req *request.DatabaseESDocumentDelete) error
}

type DatabaseElasticsearchUsecase added in v3.3.0

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

DatabaseElasticsearchUsecase Elasticsearch 业务用例

func NewDatabaseElasticsearchUsecase added in v3.3.0

func NewDatabaseElasticsearchUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	repo DatabaseElasticsearchRepo,
) *DatabaseElasticsearchUsecase

func (*DatabaseElasticsearchUsecase) Data added in v3.3.0

func (*DatabaseElasticsearchUsecase) DocumentDelete added in v3.3.0

func (*DatabaseElasticsearchUsecase) DocumentGet added in v3.3.0

func (*DatabaseElasticsearchUsecase) DocumentSet added in v3.3.0

func (*DatabaseElasticsearchUsecase) IndexCreate added in v3.3.0

func (*DatabaseElasticsearchUsecase) IndexDelete added in v3.3.0

func (*DatabaseElasticsearchUsecase) Indices added in v3.3.0

type DatabaseRedisUsecase added in v3.3.0

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

DatabaseRedisUsecase Redis 业务用例

func NewDatabaseRedisUsecase added in v3.3.0

func NewDatabaseRedisUsecase(t *gotext.Locale, log *slog.Logger, repo DatabaseRedisRepo) *DatabaseRedisUsecase

func (*DatabaseRedisUsecase) Clear added in v3.3.0

func (*DatabaseRedisUsecase) Data added in v3.3.0

func (*DatabaseRedisUsecase) Databases added in v3.3.0

func (*DatabaseRedisUsecase) KeyDelete added in v3.3.0

func (*DatabaseRedisUsecase) KeyGet added in v3.3.0

func (*DatabaseRedisUsecase) KeyRename added in v3.3.0

func (*DatabaseRedisUsecase) KeySet added in v3.3.0

func (*DatabaseRedisUsecase) KeyTTL added in v3.3.0

type DatabaseRepo

type DatabaseRepo interface {
	ListServers(typ string) ([]*DatabaseServer, error)
	DatabasesOf(ctx context.Context, server *DatabaseServer) ([]*Database, error)
	Operator(ctx context.Context, server *DatabaseServer) (db.Operator, error)
	Mongo(ctx context.Context, server *DatabaseServer) (*db.MongoDB, error)
}

type DatabaseServer

type DatabaseServer struct {
	ID        uint                 `gorm:"primaryKey" json:"id"`
	Name      string               `gorm:"not null;default:'';unique" json:"name"`
	Type      DatabaseType         `gorm:"not null;default:''" json:"type"`
	Host      string               `gorm:"not null;default:''" json:"host"`
	Port      uint                 `gorm:"not null;default:0" json:"port"`
	Username  string               `gorm:"not null;default:''" json:"username"`
	Password  string               `gorm:"not null;default:''" json:"password"`
	Status    DatabaseServerStatus `gorm:"-:all" json:"status"`
	Remark    string               `gorm:"not null;default:''" json:"remark"`
	CreatedAt time.Time            `json:"created_at"`
	UpdatedAt time.Time            `json:"updated_at"`
}

func (*DatabaseServer) AfterFind

func (r *DatabaseServer) AfterFind(tx *gorm.DB) error

func (*DatabaseServer) BeforeSave

func (r *DatabaseServer) BeforeSave(tx *gorm.DB) error

type DatabaseServerRepo

type DatabaseServerRepo interface {
	List(ctx context.Context, page, limit uint, typ string) ([]*DatabaseServer, int64, error)
	Get(ctx context.Context, id uint) (*DatabaseServer, error)
	Find(id uint) (*DatabaseServer, error)
	FindByName(name string) (*DatabaseServer, error)
	Create(server *DatabaseServer) error
	Save(server *DatabaseServer) error
	UpdateRemark(req *request.DatabaseServerUpdateRemark) error
	UpdatePassword(name string, password string) error
	UpdatePort(name string, port uint) error
	Delete(id uint) error
	ListUsers(serverID uint) ([]*DatabaseUser, error)
	CreateUser(user *DatabaseUser) error
	Operator(ctx context.Context, server *DatabaseServer) (db.Operator, error)
	CheckServer(ctx context.Context, server *DatabaseServer) bool
}

type DatabaseServerStatus

type DatabaseServerStatus string
const (
	DatabaseServerStatusValid   DatabaseServerStatus = "valid"
	DatabaseServerStatusInvalid DatabaseServerStatus = "invalid"
)

type DatabaseServerUsecase added in v3.3.0

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

DatabaseServerUsecase 数据库服务器业务用例

func NewDatabaseServerUsecase added in v3.3.0

func NewDatabaseServerUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	databaseServerRepo DatabaseServerRepo,
) *DatabaseServerUsecase

func (*DatabaseServerUsecase) Create added in v3.3.0

func (*DatabaseServerUsecase) Delete added in v3.3.0

func (uc *DatabaseServerUsecase) Delete(ctx context.Context, id uint) error

func (*DatabaseServerUsecase) FindByName added in v3.3.13

func (uc *DatabaseServerUsecase) FindByName(name string) (*DatabaseServer, error)

FindByName 只读记录不探测连通性,Status 为空

func (*DatabaseServerUsecase) Get added in v3.3.0

func (*DatabaseServerUsecase) List added in v3.3.0

func (uc *DatabaseServerUsecase) List(
	ctx context.Context,
	page, limit uint,
	typ string,
) ([]*DatabaseServer, int64, error)

func (*DatabaseServerUsecase) Sync added in v3.3.0

func (uc *DatabaseServerUsecase) Sync(ctx context.Context, id uint) error

func (*DatabaseServerUsecase) Update added in v3.3.0

func (*DatabaseServerUsecase) UpdateRemark added in v3.3.0

type DatabaseType

type DatabaseType string
const (
	DatabaseTypeMysql         DatabaseType = "mysql"
	DatabaseTypePostgresql    DatabaseType = "postgresql"
	DatabaseTypeMongoDB       DatabaseType = "mongodb"
	DatabaseTypeClickHouse    DatabaseType = "clickhouse"
	DatabaseTypeSQLite        DatabaseType = "sqlite"
	DatabaseTypeRedis         DatabaseType = "redis"
	DatabaseTypeElasticsearch DatabaseType = "elasticsearch"
)

type DatabaseUsecase added in v3.3.0

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

DatabaseUsecase 数据库业务用例

func NewDatabaseUsecase added in v3.3.0

func NewDatabaseUsecase(
	databaseUserUsecase *DatabaseUserUsecase,
	t *gotext.Locale,
	log *slog.Logger,
	databaseRepo DatabaseRepo,
	databaseServerRepo DatabaseServerRepo,
) *DatabaseUsecase

func (*DatabaseUsecase) Comment added in v3.3.0

func (*DatabaseUsecase) Create added in v3.3.0

func (*DatabaseUsecase) Delete added in v3.3.0

func (uc *DatabaseUsecase) Delete(ctx context.Context, serverID uint, name string) error

func (*DatabaseUsecase) List added in v3.3.0

func (uc *DatabaseUsecase) List(
	ctx context.Context,
	page, limit uint,
	typ, keyword string,
) ([]*Database, int64, error)

List 按名称或备注关键字筛选数据库,关键字为空时返回全部

type DatabaseUser

type DatabaseUser struct {
	ID         uint               `gorm:"primaryKey" json:"id"`
	ServerID   uint               `gorm:"not null;default:0" json:"server_id"`
	Username   string             `gorm:"not null;default:''" json:"username"`
	Password   string             `gorm:"not null;default:''" json:"password"`
	Host       string             `gorm:"not null;default:''" json:"host"` // 仅 mysql
	Status     DatabaseUserStatus `gorm:"-:all" json:"status"`             // 仅显示
	Privileges []string           `gorm:"-:all" json:"privileges"`         // 仅显示
	Remark     string             `gorm:"not null;default:''" json:"remark"`
	CreatedAt  time.Time          `json:"created_at"`
	UpdatedAt  time.Time          `json:"updated_at"`

	Server *DatabaseServer `gorm:"foreignKey:ServerID;references:ID" json:"server"`
}

func (*DatabaseUser) AfterFind

func (r *DatabaseUser) AfterFind(tx *gorm.DB) error

func (*DatabaseUser) BeforeSave

func (r *DatabaseUser) BeforeSave(tx *gorm.DB) error

type DatabaseUserRepo

type DatabaseUserRepo interface {
	List(ctx context.Context, page, limit uint, typ string) ([]*DatabaseUser, int64, error)
	Get(ctx context.Context, id uint) (*DatabaseUser, error)
	Find(id uint) (*DatabaseUser, error)
	ListByNames(serverID uint, names []string) ([]*DatabaseUser, error)
	Upsert(user *DatabaseUser) error
	Save(user *DatabaseUser) error
	UpdateRemark(req *request.DatabaseUserUpdateRemark) error
	DeleteByID(id uint) error
	DeleteByServerNames(serverID uint, names []string) error
	Operator(ctx context.Context, server *DatabaseServer) (db.Operator, error)
}

type DatabaseUserStatus

type DatabaseUserStatus string
const (
	DatabaseUserStatusValid   DatabaseUserStatus = "valid"
	DatabaseUserStatusInvalid DatabaseUserStatus = "invalid"
)

type DatabaseUserUsecase added in v3.3.0

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

DatabaseUserUsecase 数据库用户业务用例

func NewDatabaseUserUsecase added in v3.3.0

func NewDatabaseUserUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	databaseServerRepo DatabaseServerRepo,
	databaseUserRepo DatabaseUserRepo,
) *DatabaseUserUsecase

func (*DatabaseUserUsecase) Create added in v3.3.0

func (*DatabaseUserUsecase) Delete added in v3.3.0

func (uc *DatabaseUserUsecase) Delete(ctx context.Context, id uint) error

func (*DatabaseUserUsecase) DeleteByNames added in v3.3.0

func (uc *DatabaseUserUsecase) DeleteByNames(ctx context.Context, serverID uint, names []string) error

func (*DatabaseUserUsecase) Exists added in v3.3.13

func (uc *DatabaseUserUsecase) Exists(serverID uint, username string) (bool, error)

Exists 面板里是否已有该服务器下的同名用户记录

func (*DatabaseUserUsecase) Get added in v3.3.0

func (*DatabaseUserUsecase) List added in v3.3.0

func (uc *DatabaseUserUsecase) List(ctx context.Context, page, limit uint, typ string) ([]*DatabaseUser, int64, error)

func (*DatabaseUserUsecase) Update added in v3.3.0

func (*DatabaseUserUsecase) UpdateRemark added in v3.3.0

type EnvironmentRepo

type EnvironmentRepo interface {
	IsInstalled(typ, slug string) bool
	InstalledVersion(ctx context.Context, typ, slug string) string
	ScriptCommand(typ, action, slug, version string) string
	ExecScript(ctx context.Context, cmd string) error
}

type EnvironmentUsecase added in v3.3.0

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

func NewEnvironmentUsecase added in v3.3.0

func NewEnvironmentUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	cacheRepo CacheRepo,
	environmentRepo EnvironmentRepo,
	taskRepo TaskRepo,
) *EnvironmentUsecase

func (*EnvironmentUsecase) All added in v3.3.0

func (uc *EnvironmentUsecase) All(typ ...string) api.Environments

func (*EnvironmentUsecase) Install added in v3.3.0

func (uc *EnvironmentUsecase) Install(ctx context.Context, typ, slug string) error

func (*EnvironmentUsecase) InstalledSlugs added in v3.3.0

func (uc *EnvironmentUsecase) InstalledSlugs(typ string) []string

func (*EnvironmentUsecase) InstalledVersion added in v3.3.0

func (uc *EnvironmentUsecase) InstalledVersion(ctx context.Context, typ, slug string) string

func (*EnvironmentUsecase) IsInstalled added in v3.3.0

func (uc *EnvironmentUsecase) IsInstalled(typ, slug string) bool

func (*EnvironmentUsecase) Types added in v3.3.0

func (uc *EnvironmentUsecase) Types() []types.LV

func (*EnvironmentUsecase) Uninstall added in v3.3.0

func (uc *EnvironmentUsecase) Uninstall(ctx context.Context, typ, slug string) error

func (*EnvironmentUsecase) Update added in v3.3.0

func (uc *EnvironmentUsecase) Update(ctx context.Context, typ, slug string) error

type FileFavorite added in v3.3.12

type FileFavorite struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Path      string    `gorm:"not null;unique" json:"path"`
	Remark    string    `gorm:"not null;default:''" json:"remark"`
	Sort      int       `gorm:"not null;default:0" json:"sort"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type FileFavoriteRepo added in v3.3.12

type FileFavoriteRepo interface {
	List() ([]*FileFavorite, error)
	Get(id uint) (*FileFavorite, error)
	Create(path, remark string) (*FileFavorite, error)
	UpdateRemark(id uint, remark string) error
	Delete(id uint) error
	UpdateOrder(ids []uint) error
}

type FileFavoriteUsecase added in v3.3.12

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

func NewFileFavoriteUsecase added in v3.3.12

func NewFileFavoriteUsecase(t *gotext.Locale, log *slog.Logger, repo FileFavoriteRepo) *FileFavoriteUsecase

func (*FileFavoriteUsecase) Create added in v3.3.12

func (uc *FileFavoriteUsecase) Create(ctx context.Context, path, remark string) (*FileFavorite, error)

func (*FileFavoriteUsecase) Delete added in v3.3.12

func (uc *FileFavoriteUsecase) Delete(ctx context.Context, id uint) error

func (*FileFavoriteUsecase) List added in v3.3.12

func (uc *FileFavoriteUsecase) List() ([]*FileFavorite, error)

func (*FileFavoriteUsecase) UpdateOrder added in v3.3.12

func (uc *FileFavoriteUsecase) UpdateOrder(ids []uint) error

func (*FileFavoriteUsecase) UpdateRemark added in v3.3.12

func (uc *FileFavoriteUsecase) UpdateRemark(ctx context.Context, id uint, remark string) error

type FileShare added in v3.3.0

type FileShare struct {
	ID           uint      `gorm:"primaryKey" json:"id"`
	Token        string    `gorm:"not null;uniqueIndex" json:"token"`       // 唯一标识(用于下载 URL)
	Path         string    `gorm:"not null;index" json:"path"`              // 文件路径(同一文件可有多条分享)
	Downloads    uint      `gorm:"not null;default:0" json:"downloads"`     // 已下载次数
	MaxDownloads uint      `gorm:"not null;default:0" json:"max_downloads"` // 最大下载次数(0 不限)
	ExpiredAt    time.Time `gorm:"not null;index" json:"expired_at"`        // 过期时间
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

type FileShareRepo added in v3.3.0

type FileShareRepo interface {
	List() ([]*FileShare, error)
	Get(id uint) (*FileShare, error)
	Create(path string, maxDownloads uint, expiredAt time.Time) (*FileShare, error)
	Delete(id uint) error
	Consume(token string, count bool) (*FileShare, error)
	ClearExpired() (int64, error)
}

type FileShareUsecase added in v3.3.0

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

func NewFileShareUsecase added in v3.3.0

func NewFileShareUsecase(t *gotext.Locale, log *slog.Logger, fileShareRepo FileShareRepo) *FileShareUsecase

func (*FileShareUsecase) ClearExpired added in v3.3.0

func (uc *FileShareUsecase) ClearExpired() (int64, error)

func (*FileShareUsecase) Consume added in v3.3.0

func (uc *FileShareUsecase) Consume(token string, count bool) (*FileShare, error)

Consume 校验分享有效性,count 为真时原子计数一次下载

func (*FileShareUsecase) Create added in v3.3.0

Create 创建分享,同一路径可重复分享为多条独立记录

func (*FileShareUsecase) Delete added in v3.3.0

func (uc *FileShareUsecase) Delete(ctx context.Context, id uint) error

func (*FileShareUsecase) List added in v3.3.0

func (uc *FileShareUsecase) List() ([]*FileShare, error)

type ImagePullProgress added in v3.3.13

type ImagePullProgress = jsonstream.Message

ImagePullProgress 拉取镜像时 Docker 推送的一条进度

type LogEntry

type LogEntry struct {
	Time         time.Time      `json:"time"`
	Level        string         `json:"level"`
	Msg          string         `json:"msg"`
	Type         string         `json:"type,omitempty"`
	OperatorID   uint           `json:"operator_id,omitempty"`
	OperatorName string         `json:"operator_name,omitempty"`
	Extra        map[string]any `json:"extra,omitempty"`
}

LogEntry 日志条目

type LogRepo

type LogRepo interface {
	// List 获取日志列表
	// date 格式为 YYYY-MM-DD,空字符串表示当天日志
	// level 为日志级别(DEBUG/INFO/WARN/ERROR),空字符串表示不过滤
	// keyword 不区分大小写匹配整条日志,空字符串表示不过滤
	List(logType string, limit int, date, level, keyword string) ([]LogEntry, error)
	// ListDates 获取可用的日志日期列表
	ListDates(logType string) ([]string, error)
	// Clean 清理指定日期及之前的日志
	Clean(logType string, date string) error
}

LogRepo 日志仓库接口

type LogUsecase added in v3.3.0

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

func NewLogUsecase added in v3.3.0

func NewLogUsecase(t *gotext.Locale, log *slog.Logger, repo LogRepo) *LogUsecase

func (*LogUsecase) Clean added in v3.3.7

func (uc *LogUsecase) Clean(ctx context.Context, logType, date string) error

func (*LogUsecase) List added in v3.3.0

func (uc *LogUsecase) List(logType string, limit int, date, level, keyword string) ([]LogEntry, error)

func (*LogUsecase) ListDates added in v3.3.0

func (uc *LogUsecase) ListDates(logType string) ([]string, error)

type MigrationArchiveRepo added in v3.3.2

type MigrationArchiveRepo interface {
	// TempDir 创建迁移临时目录
	TempDir() (string, error)
	// Extract 解包归档到目标目录,返回真实内容根目录
	Extract(ctx context.Context, archive, target string) (string, error)
	// Compress 打包目录为 tar.gz
	Compress(ctx context.Context, source, archive string) error
	// CopyTree 复制目录内容(保留属性)
	CopyTree(ctx context.Context, source, target string) error
	// IsEmpty 判断目录为空或不存在
	IsEmpty(path string) bool
}

MigrationArchiveRepo 本地归档与目录操作

type MigrationRemoteRepo added in v3.3.2

type MigrationRemoteRepo interface {
	// Request 调用目标面板 API
	Request(ctx context.Context, conn *request.ToolboxMigrationConnection, method, path string, body any) ([]byte, error)
	// Upload 分片上传文件到目标面板,progress 可为 nil
	Upload(ctx context.Context, conn *request.ToolboxMigrationConnection, local, remote string, progress types.MigrationProgress) error
	// Exec 在目标面板执行命令
	Exec(ctx context.Context, conn *request.ToolboxMigrationConnection, command string) error
}

MigrationRemoteRepo 访问目标 AcePanel 面板(AcePanel 之间迁移使用)

type MigrationSourceRepo added in v3.3.2

type MigrationSourceRepo interface {
	// Probe 探测来源面板类型与版本,同时校验凭据
	Probe(ctx context.Context, conn *request.ToolboxMigrationConnection) (*types.MigrationSource, error)
	// Items 列出来源面板上所有可迁移资源
	Items(ctx context.Context, conn *request.ToolboxMigrationConnection) ([]types.MigrationItem, error)
	// Detail 迁移前重新读取资源详情
	Detail(ctx context.Context, conn *request.ToolboxMigrationConnection, item types.MigrationItem) (*types.MigrationDetail, error)
	// SetRunning 启停来源资源
	SetRunning(ctx context.Context, conn *request.ToolboxMigrationConnection, item types.MigrationItem, running bool) error
	// Backup 在来源侧生成备份,返回来源上的文件路径
	Backup(ctx context.Context, conn *request.ToolboxMigrationConnection, detail *types.MigrationDetail) (string, error)
	// Download 下载来源备份到本地,progress 可为 nil
	Download(ctx context.Context, conn *request.ToolboxMigrationConnection, remote, local string, progress types.MigrationProgress) error
}

MigrationSourceRepo 读取来源面板(宝塔 / 1Panel)的资源并生成备份

type Monitor

type Monitor struct {
	ID        uint              `gorm:"primaryKey" json:"id"`
	Info      types.CurrentInfo `gorm:"not null;default:'{}';serializer:zstd" json:"info"`
	CreatedAt time.Time         `gorm:"index:idx_monitors_created_at" json:"created_at"`
	UpdatedAt time.Time         `json:"updated_at"`
}

type MonitorRepo

type MonitorRepo interface {
	Create(monitor *Monitor) error
	ClearBefore(t time.Time) error
	Clear() error
	List(start, end time.Time) ([]*Monitor, error)
	VacuumDB() error
}

type MonitorUsecase added in v3.3.0

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

func NewMonitorUsecase added in v3.3.0

func NewMonitorUsecase(t *gotext.Locale, log *slog.Logger, repo MonitorRepo, setting SettingRepo) *MonitorUsecase

func (*MonitorUsecase) Clear added in v3.3.0

func (uc *MonitorUsecase) Clear(ctx context.Context) error

func (*MonitorUsecase) ClearBefore added in v3.3.2

func (uc *MonitorUsecase) ClearBefore(t time.Time) error

func (*MonitorUsecase) Create added in v3.3.2

func (uc *MonitorUsecase) Create(monitor *Monitor) error

func (*MonitorUsecase) Detail added in v3.3.13

func (uc *MonitorUsecase) Detail(start, end time.Time) (types.MonitorDetail, error)

func (*MonitorUsecase) GetSetting added in v3.3.0

func (uc *MonitorUsecase) GetSetting(ctx context.Context) (*request.MonitorSetting, error)

func (*MonitorUsecase) UpdateSetting added in v3.3.0

func (uc *MonitorUsecase) UpdateSetting(ctx context.Context, setting *request.MonitorSetting) error

func (*MonitorUsecase) VacuumDB added in v3.3.2

func (uc *MonitorUsecase) VacuumDB() error

type NotifyChannel added in v3.3.1

type NotifyChannel struct {
	ID        uint            `gorm:"primaryKey" json:"id"`
	Name      string          `gorm:"not null;default:''" json:"name"`
	Type      string          `gorm:"not null;default:''" json:"type"`   // smtp
	Config    json.RawMessage `gorm:"not null;default:''" json:"config"` // 渠道配置,含凭据,落库前整体加密
	Enabled   bool            `gorm:"not null;default:true" json:"enabled"`
	CreatedAt time.Time       `json:"created_at"`
	UpdatedAt time.Time       `json:"updated_at"`
}

NotifyChannel 通知渠道

func (*NotifyChannel) AfterFind added in v3.3.1

func (r *NotifyChannel) AfterFind(tx *gorm.DB) error

func (*NotifyChannel) BeforeSave added in v3.3.1

func (r *NotifyChannel) BeforeSave(tx *gorm.DB) error

type NotifyChannelRepo added in v3.3.1

type NotifyChannelRepo interface {
	List(page, limit uint) ([]*NotifyChannel, int64, error)
	All() ([]*NotifyChannel, error)
	Get(id uint) (*NotifyChannel, error)
	GetByIDs(ids []uint) ([]*NotifyChannel, error)
	Create(channel *NotifyChannel) error
	Update(channel *NotifyChannel) error
	Delete(id uint) error
}

type NotifyEvent added in v3.3.1

type NotifyEvent string

NotifyEvent 系统事件类型

const (
	NotifyEventCertRenew     NotifyEvent = "cert_renew"     // 证书续签失败
	NotifyEventBackup        NotifyEvent = "backup"         // 备份失败
	NotifyEventTaskFailed    NotifyEvent = "task_failed"    // 后台任务失败
	NotifyEventCronFailed    NotifyEvent = "cron_failed"    // 计划任务执行失败
	NotifyEventWebsiteExpire NotifyEvent = "website_expire" // 网站到期关停
	NotifyEventTamper        NotifyEvent = "tamper"         // 防篡改拦截
	NotifyEventHealth        NotifyEvent = "health"         // 面板健康问题
	NotifyEventLogin         NotifyEvent = "login"          // 面板登录
	NotifyEventLoginFailed   NotifyEvent = "login_failed"   // 面板登录失败过多
	NotifyEventSSHLogin      NotifyEvent = "ssh_login"      // SSH 登录
	NotifyEventSSHBruteforce NotifyEvent = "ssh_bruteforce" // SSH 爆破
)

type NotifyUsecase added in v3.3.1

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

func NewNotifyUsecase added in v3.3.1

func NewNotifyUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	notifyChannelRepo NotifyChannelRepo,
	settingRepo SettingRepo,
) *NotifyUsecase

func (*NotifyUsecase) All added in v3.3.1

func (uc *NotifyUsecase) All() ([]*NotifyChannel, error)

func (*NotifyUsecase) Create added in v3.3.1

func (*NotifyUsecase) Delete added in v3.3.1

func (uc *NotifyUsecase) Delete(ctx context.Context, id uint) error

func (*NotifyUsecase) EventEnabled added in v3.3.2

func (uc *NotifyUsecase) EventEnabled(events ...NotifyEvent) bool

EventEnabled 判断给定事件中是否有已订阅且配好渠道的 供调用方在采集前提前跳过,避免为没人接收的通知付出采集开销

func (*NotifyUsecase) Get added in v3.3.1

func (uc *NotifyUsecase) Get(ctx context.Context, id uint) (*NotifyChannel, error)

func (*NotifyUsecase) GetSetting added in v3.3.1

func (uc *NotifyUsecase) GetSetting(ctx context.Context) (*request.NotifySetting, error)

func (*NotifyUsecase) List added in v3.3.1

func (uc *NotifyUsecase) List(ctx context.Context, page, limit uint) ([]*NotifyChannel, int64, error)

func (*NotifyUsecase) Send added in v3.3.1

func (uc *NotifyUsecase) Send(ctx context.Context, channelIDs []uint, subject, body string) (int, error)

Send 向指定渠道列表发送通知,返回成功发送的渠道数,部分渠道失败不影响其他渠道

func (*NotifyUsecase) SendEvent added in v3.3.1

func (uc *NotifyUsecase) SendEvent(event NotifyEvent, subject, body string)

SendEvent 发送系统事件通知,不阻塞业务流程 待发送数超过上限时丢弃并告知,避免慢渠道拖垮调用方

func (*NotifyUsecase) SendEventSync added in v3.3.1

func (uc *NotifyUsecase) SendEventSync(ctx context.Context, event NotifyEvent, subject, body string) error

SendEventSync 同步发送系统事件通知,未订阅该事件或未配置渠道时静默跳过 供 CLI 等短生命周期进程使用,异步发送会随进程退出丢失

func (*NotifyUsecase) Test added in v3.3.1

func (uc *NotifyUsecase) Test(ctx context.Context, id uint) error

Test 向指定渠道发送一条测试消息

func (*NotifyUsecase) Update added in v3.3.1

func (*NotifyUsecase) UpdateSetting added in v3.3.1

func (uc *NotifyUsecase) UpdateSetting(ctx context.Context, setting *request.NotifySetting) error

type PanelRelease added in v3.3.13

type PanelRelease struct {
	Version  string
	URL      string
	Checksum string
}

PanelRelease 更新渠道内最新的面板版本,本机架构没有安装包时 URL 与 Checksum 为空

func (*PanelRelease) Newer added in v3.3.13

func (r *PanelRelease) Newer() (bool, error)

Newer 报告该版本是否比运行中的面板新

type Project

type Project struct {
	ID        uint              `gorm:"primaryKey" json:"id"`
	Name      string            `gorm:"not null;unique" json:"name"`                  // 项目名称
	Type      types.ProjectType `gorm:"not null;index;default:'general'" json:"type"` // 项目类型
	Path      string            `gorm:"not null;default:''" json:"path"`              // 项目路径
	CreatedAt time.Time         `json:"created_at"`
	UpdatedAt time.Time         `json:"updated_at"`
}

type ProjectRepo

type ProjectRepo interface {
	Count() (int64, error)
	List(typ types.ProjectType, keyword string, page, limit uint) ([]*Project, int64, error)
	GetEntity(id uint) (*Project, error)
	ParseDetail(ctx context.Context, project *Project) (*types.ProjectDetail, error)
	NameExists(name string) (bool, error)
	Create(ctx context.Context, project *Project, req *request.ProjectCreate) error
	Save(project *Project) error
	Delete(project *Project) error
	RenameUnitFile(oldName, newName string) error
	RemoveUnitFile(name string) error
	UpdateUnitFile(ctx context.Context, name string, req *request.ProjectUpdate) error
}

type ProjectUsecase added in v3.3.0

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

func NewProjectUsecase added in v3.3.0

func NewProjectUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	projectRepo ProjectRepo,
	websiteUsecase *WebsiteUsecase,
) *ProjectUsecase

func (*ProjectUsecase) Count added in v3.3.0

func (uc *ProjectUsecase) Count() (int64, error)

func (*ProjectUsecase) Create added in v3.3.0

func (*ProjectUsecase) Delete added in v3.3.0

func (uc *ProjectUsecase) Delete(ctx context.Context, id uint, websites bool) error

func (*ProjectUsecase) Get added in v3.3.0

func (*ProjectUsecase) List added in v3.3.0

func (uc *ProjectUsecase) List(
	ctx context.Context,
	typ types.ProjectType,
	keyword string,
	page, limit uint,
) ([]*types.ProjectDetail, int64, error)

func (*ProjectUsecase) Update added in v3.3.0

func (uc *ProjectUsecase) Update(ctx context.Context, req *request.ProjectUpdate) error

type SSH

type SSH struct {
	ID        uint             `gorm:"primaryKey" json:"id"`
	Name      string           `gorm:"not null;default:''" json:"name"`
	Host      string           `gorm:"not null;default:''" json:"host"`
	Port      uint             `gorm:"not null;default:0" json:"port"`
	Config    ssh.ClientConfig `gorm:"not null;default:'{}';serializer:json" json:"config"`
	Remark    string           `gorm:"not null;default:''" json:"remark"`
	CreatedAt time.Time        `json:"created_at"`
	UpdatedAt time.Time        `json:"updated_at"`
}

func (*SSH) AfterFind

func (r *SSH) AfterFind(tx *gorm.DB) error

func (*SSH) BeforeSave

func (r *SSH) BeforeSave(tx *gorm.DB) error

type SSHFileInfo added in v3.3.0

type SSHFileInfo struct {
	Name    string `json:"name"`
	Size    int64  `json:"size"`
	Mode    string `json:"mode"`
	ModTime int64  `json:"mod_time"`
	IsDir   bool   `json:"is_dir"`
	IsLink  bool   `json:"is_link"`
}

SSHFileInfo SFTP 文件信息

type SSHRepo

type SSHRepo interface {
	List(page, limit uint) ([]*SSH, int64, error)
	Get(id uint) (*SSH, error)
	Create(req *request.SSHCreate) error
	Update(req *request.SSHUpdate) error
	Delete(id uint) error
	// 文件互传相关,hostID 为 0 表示面板本机
	ListFiles(hostID uint, path string) ([]*SSHFileInfo, error)
	Mkdir(hostID uint, path string) error
	TransferFile(ctx context.Context, srcID uint, srcPath string, dstID uint, dstPath string, progress func(transferred, total int64)) error
}

type SSHUsecase added in v3.3.0

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

SSHUsecase SSH 业务逻辑

func NewSSHUsecase added in v3.3.0

func NewSSHUsecase(t *gotext.Locale, log *slog.Logger, repo SSHRepo) *SSHUsecase

func (*SSHUsecase) Create added in v3.3.0

func (uc *SSHUsecase) Create(ctx context.Context, req *request.SSHCreate) error

func (*SSHUsecase) Delete added in v3.3.0

func (uc *SSHUsecase) Delete(ctx context.Context, id uint) error

func (*SSHUsecase) Get added in v3.3.0

func (uc *SSHUsecase) Get(id uint) (*SSH, error)

func (*SSHUsecase) List added in v3.3.0

func (uc *SSHUsecase) List(page, limit uint) ([]*SSH, int64, error)

func (*SSHUsecase) ListFiles added in v3.3.0

func (uc *SSHUsecase) ListFiles(hostID uint, path string) ([]*SSHFileInfo, error)

func (*SSHUsecase) Mkdir added in v3.3.0

func (uc *SSHUsecase) Mkdir(ctx context.Context, hostID uint, path string) error

func (*SSHUsecase) TransferFile added in v3.3.0

func (uc *SSHUsecase) TransferFile(
	ctx context.Context,
	srcID uint,
	srcPath string,
	dstID uint,
	dstPath string,
	progress func(transferred, total int64),
) error

func (*SSHUsecase) Update added in v3.3.0

func (uc *SSHUsecase) Update(ctx context.Context, req *request.SSHUpdate) error

type SafeRepo

type SafeRepo interface {
	GetPingStatus(ctx context.Context) (bool, error)
	FirewallRunning(ctx context.Context) (bool, error)
	SetPingStatus(ctx context.Context, status bool) error
}

type SafeUsecase added in v3.3.0

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

func NewSafeUsecase added in v3.3.0

func NewSafeUsecase(repo SafeRepo, t *gotext.Locale, log *slog.Logger) *SafeUsecase

func (*SafeUsecase) GetPingStatus added in v3.3.0

func (uc *SafeUsecase) GetPingStatus(ctx context.Context) (bool, error)

func (*SafeUsecase) UpdatePingStatus added in v3.3.0

func (uc *SafeUsecase) UpdatePingStatus(ctx context.Context, status bool) error

type ScanBlock added in v3.3.13

type ScanBlock struct {
	IP        string    `gorm:"primaryKey" json:"ip"`
	ExpiresAt int64     `gorm:"not null;default:0;index" json:"expires_at"` // Unix 秒,0 为永久
	Outbound  bool      `gorm:"not null;default:false" json:"outbound"`     // 出站是否一并屏蔽,解封时据此删规则
	CreatedAt time.Time `json:"created_at"`
}

ScanBlock 扫描感知自动屏蔽的 IP

type ScanDayTrend

type ScanDayTrend struct {
	Date       string `json:"date"`
	TotalCount uint   `json:"total_count"`
	UniqueIPs  uint   `json:"unique_ips"`
}

ScanDayTrend 每日趋势

type ScanEvent

type ScanEvent struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	SourceID  uint      `gorm:"not null;uniqueIndex:idx_scan_unique,priority:2" json:"-"`
	Port      uint      `gorm:"not null;uniqueIndex:idx_scan_unique,priority:3" json:"port"`
	Protocol  string    `gorm:"not null;default:'tcp';uniqueIndex:idx_scan_unique,priority:4" json:"protocol"`
	Date      string    `gorm:"not null;uniqueIndex:idx_scan_unique,priority:1" json:"date"` // YYYY-MM-DD
	Count     uint      `gorm:"not null;default:1" json:"count"`
	FirstSeen time.Time `gorm:"not null" json:"first_seen"`
	LastSeen  time.Time `gorm:"not null" json:"last_seen"`
	SourceIP  string    `gorm:"->;-:migration" json:"source_ip"`
	Country   string    `gorm:"->;-:migration" json:"country"`
	Region    string    `gorm:"->;-:migration" json:"region"`
	City      string    `gorm:"->;-:migration" json:"city"`
	ISP       string    `gorm:"->;-:migration" json:"isp"`
}

ScanEvent 扫描事件模型

type ScanEventRepo

type ScanEventRepo interface {
	Upsert(events []*ScanEvent) error
	List(start, end, sourceIP string, port uint, location string, page, limit uint) ([]*ScanEvent, uint, error)
	Summary(start, end string) (*ScanSummary, error)
	Trend(start, end string) ([]*ScanDayTrend, error)
	TopSourceIPs(start, end string, limit uint) ([]*ScanSourceRank, error)
	TopPorts(start, end string, limit uint) ([]*ScanPortRank, error)
	ClearBefore(date string) error
	Clear() error
	VacuumDB() error
	// AddBlocks 记录屏蔽的 IP,已有记录的保持原样
	AddBlocks(blocks []*ScanBlock) error
	// BlockedIPs 返回给定 IP 中已有屏蔽记录的
	BlockedIPs(ips []string) ([]string, error)
	// ExpiredBlocks 返回到期的限时屏蔽
	ExpiredBlocks(now time.Time) ([]*ScanBlock, error)
	DeleteBlocks(ips []string) error
}

ScanEventRepo 扫描事件数据访问接口

type ScanEventUsecase added in v3.3.0

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

ScanEventUsecase 扫描事件业务逻辑

func NewScanEventUsecase added in v3.3.0

func NewScanEventUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	repo ScanEventRepo,
	setting SettingRepo,
) *ScanEventUsecase

func (*ScanEventUsecase) AddBlocks added in v3.3.13

func (uc *ScanEventUsecase) AddBlocks(blocks []*ScanBlock) error

func (*ScanEventUsecase) BlockedIPs added in v3.3.13

func (uc *ScanEventUsecase) BlockedIPs(ips []string) ([]string, error)

func (*ScanEventUsecase) Clear added in v3.3.0

func (uc *ScanEventUsecase) Clear(ctx context.Context) error

func (*ScanEventUsecase) ClearBefore added in v3.3.0

func (uc *ScanEventUsecase) ClearBefore(date string) error

func (*ScanEventUsecase) DeleteBlocks added in v3.3.13

func (uc *ScanEventUsecase) DeleteBlocks(ips []string) error

func (*ScanEventUsecase) ExpiredBlocks added in v3.3.13

func (uc *ScanEventUsecase) ExpiredBlocks(now time.Time) ([]*ScanBlock, error)

func (*ScanEventUsecase) GetSetting added in v3.3.0

func (uc *ScanEventUsecase) GetSetting() (*ScanSetting, error)

func (*ScanEventUsecase) List added in v3.3.0

func (uc *ScanEventUsecase) List(
	start, end, sourceIP string,
	port uint,
	location string,
	page, limit uint,
) ([]*ScanEvent, uint, error)

func (*ScanEventUsecase) Summary added in v3.3.0

func (uc *ScanEventUsecase) Summary(start, end string) (*ScanSummary, error)

func (*ScanEventUsecase) TopPorts added in v3.3.0

func (uc *ScanEventUsecase) TopPorts(start, end string, limit uint) ([]*ScanPortRank, error)

func (*ScanEventUsecase) TopSourceIPs added in v3.3.0

func (uc *ScanEventUsecase) TopSourceIPs(start, end string, limit uint) ([]*ScanSourceRank, error)

func (*ScanEventUsecase) Trend added in v3.3.0

func (uc *ScanEventUsecase) Trend(start, end string) ([]*ScanDayTrend, error)

func (*ScanEventUsecase) UpdateSetting added in v3.3.0

func (uc *ScanEventUsecase) UpdateSetting(ctx context.Context, setting *ScanSetting) error

func (*ScanEventUsecase) Upsert added in v3.3.0

func (uc *ScanEventUsecase) Upsert(events []*ScanEvent) error

func (*ScanEventUsecase) VacuumDB added in v3.3.0

func (uc *ScanEventUsecase) VacuumDB() error

type ScanPortRank

type ScanPortRank struct {
	Port       uint   `json:"port"`
	Protocol   string `json:"protocol"`
	TotalCount uint   `json:"total_count"`
	IPCount    uint   `json:"ip_count"`
}

ScanPortRank 被扫描端口排行

type ScanSetting

type ScanSetting struct {
	Enabled        bool     `json:"enabled"`
	Days           uint     `json:"days"`
	Interfaces     []string `json:"interfaces"`
	AutoBlock      bool     `json:"auto_block"`
	BlockThreshold uint     `json:"block_threshold"` // 扫描次数阈值
	BlockWindow    uint     `json:"block_window"`    // 检测窗口(分钟)
	BlockDuration  uint     `json:"block_duration"`  // 屏蔽时长(小时),0=永久
	BlockOutbound  bool     `json:"block_outbound"`  // 屏蔽时连出站一并屏蔽
	Whitelist      []string `json:"whitelist"`       // IP/CIDR 白名单
}

ScanSetting 扫描感知设置

type ScanSource added in v3.3.2

type ScanSource struct {
	ID       uint   `gorm:"primaryKey"`
	SourceIP string `gorm:"not null;uniqueIndex:idx_scan_sources_ip"`
	Country  string `gorm:"not null;default:''"`
	Region   string `gorm:"not null;default:''"`
	City     string `gorm:"not null;default:''"`
	ISP      string `gorm:"not null;default:''"`
}

ScanSource 扫描来源模型

type ScanSourceRank

type ScanSourceRank struct {
	SourceIP   string `json:"source_ip"`
	TotalCount uint   `json:"total_count"`
	PortCount  uint   `json:"port_count"`
	LastSeen   string `json:"last_seen"`
	Country    string `json:"country"`
	Region     string `json:"region"`
	City       string `json:"city"`
	ISP        string `json:"isp"`
}

ScanSourceRank 扫描源 IP 排行

type ScanSummary

type ScanSummary struct {
	TotalCount  uint `json:"total_count"`
	UniqueIPs   uint `json:"unique_ips"`
	UniquePorts uint `json:"unique_ports"`
}

ScanSummary 扫描汇总

type Setting

type Setting struct {
	ID        uint       `gorm:"primaryKey" json:"id"`
	Key       SettingKey `gorm:"not null;default:'';unique" json:"key"`
	Value     string     `gorm:"not null;default:''" json:"value"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
}

type SettingKey

type SettingKey string
const (
	SettingKeyName                      SettingKey = "name"
	SettingKeyVersion                   SettingKey = "version"
	SettingKeyChannel                   SettingKey = "channel"
	SettingKeyMonitor                   SettingKey = "monitor"
	SettingKeyMonitorDays               SettingKey = "monitor_days"
	SettingKeyMonitorInterval           SettingKey = "monitor_interval"
	SettingKeyBackupPath                SettingKey = "backup_path"
	SettingKeyBackupFormat              SettingKey = "backup_format" // tar.xz / tar.gz / tar.zst / zip / 7z
	SettingKeyWebsitePath               SettingKey = "website_path"
	SettingKeyProjectPath               SettingKey = "project_path"
	SettingKeyContainerSock             SettingKey = "container_sock"
	SettingKeyWebsiteTLSVersions        SettingKey = "website_tls_versions"
	SettingKeyWebsiteListenIPv6         SettingKey = "website_listen_ipv6"
	SettingKeyMySQLRootPassword         SettingKey = "mysql_root_password"
	SettingKeyPostgresPassword          SettingKey = "postgres_password"
	SettingKeyMongoDBAdminPassword      SettingKey = "mongodb_admin_password"
	SettingKeyClickHouseDefaultPassword SettingKey = "clickhouse_default_password"
	SettingKeyStalwartAdminUser         SettingKey = "stalwart_admin_user"
	SettingKeyStalwartAdminPassword     SettingKey = "stalwart_admin_password"
	SettingKeyStalwartCertID            SettingKey = "stalwart_cert_id"       // 绑定到邮件服务的面板证书 ID
	SettingKeyStalwartCertObject        SettingKey = "stalwart_cert_object"   // Stalwart 侧对应的证书对象 ID
	SettingKeyStalwartProxyWebsite      SettingKey = "stalwart_proxy_website" // 一键创建的反代网站 ID
	SettingKeyOfflineMode               SettingKey = "offline_mode"
	SettingKeyAutoUpdate                SettingKey = "auto_update"
	SettingKeyWebserver                 SettingKey = "webserver"
	SettingKeyPublicIPs                 SettingKey = "public_ips"
	SettingHiddenMenu                   SettingKey = "hidden_menu"
	SettingKeyMemo                      SettingKey = "memo"
	SettingKeyScanAware                 SettingKey = "scan_aware"
	SettingKeyScanAwareDays             SettingKey = "scan_aware_days"
	SettingKeyScanAwareInterfaces       SettingKey = "scan_aware_interfaces"
	SettingKeyScanAwareAutoBlock        SettingKey = "scan_aware_auto_block"
	SettingKeyScanAwareBlockThreshold   SettingKey = "scan_aware_block_threshold"
	SettingKeyScanAwareBlockWindow      SettingKey = "scan_aware_block_window"
	SettingKeyScanAwareBlockOutbound    SettingKey = "scan_aware_block_outbound"
	SettingKeyScanAwareBlockDuration    SettingKey = "scan_aware_block_duration" // 小时,0=永久
	SettingKeyScanAwareWhitelist        SettingKey = "scan_aware_whitelist"      // JSON 数组
	SettingKeyWebsiteStatDays           SettingKey = "website_stat_days"
	SettingKeyWebsiteStatErrBufMax      SettingKey = "website_stat_err_buf_max"
	SettingKeyWebsiteStatUVMaxKeys      SettingKey = "website_stat_uv_max_keys"
	SettingKeyWebsiteStatIPMaxKeys      SettingKey = "website_stat_ip_max_keys"
	SettingKeyWebsiteStatDetailMaxKeys  SettingKey = "website_stat_detail_max_keys"
	SettingKeyWebsiteStatBodyEnabled    SettingKey = "website_stat_body_enabled"
	SettingKeyIPDBType                  SettingKey = "ipdb_type" // "" / "custom" / "subscribe"
	SettingKeyIPDBURL                   SettingKey = "ipdb_url"  // 订阅链接
	SettingKeyIPDBPath                  SettingKey = "ipdb_path"
	SettingKeyInfoRan                   SettingKey = "info_ran"            // info 命令是否已运行过
	SettingKeyServiceLogCleared         SettingKey = "service_log_cleared" // 后接 :服务名,值为清空运行日志的时刻(Unix 微秒)
	SettingKeyTamperEnabled             SettingKey = "tamper_enabled"
	SettingKeyTamperMode                SettingKey = "tamper_mode"           // chattr / ebpf
	SettingKeyTamperBlockNew            SettingKey = "tamper_block_new"      // 新建受保护类型文件时删除拦截
	SettingKeyTamperLogDays             SettingKey = "tamper_log_days"       // 拦截日志保留天数
	SettingKeyNotifyEvents              SettingKey = "notify_event_types"    // 订阅的系统事件类型,JSON 数组
	SettingKeyNotifyEventChannels       SettingKey = "notify_event_channels" // 接收系统事件的渠道 ID,JSON 数组
	SettingKeyAlertLogDays              SettingKey = "alert_log_days"        // 告警记录保留天数
)

type SettingRepo

type SettingRepo interface {
	Get(key SettingKey, defaultValue ...string) (string, error)
	GetBool(key SettingKey, defaultValue ...bool) (bool, error)
	GetInt(key SettingKey, defaultValue ...int) (int, error)
	GetSlice(key SettingKey, defaultValue ...[]string) ([]string, error)
	Set(key SettingKey, value string) error
	SetSlice(key SettingKey, value []string) error
	Delete(key SettingKey) error
	GetPanel() (*request.SettingPanel, error)
}

type SettingUsecase added in v3.3.0

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

func NewSettingUsecase added in v3.3.0

func NewSettingUsecase(t *gotext.Locale, log *slog.Logger, settingRepo SettingRepo, taskRepo TaskRepo) *SettingUsecase

func (*SettingUsecase) Delete added in v3.3.0

func (uc *SettingUsecase) Delete(key SettingKey) error

func (*SettingUsecase) Get added in v3.3.0

func (uc *SettingUsecase) Get(key SettingKey, defaultValue ...string) (string, error)

func (*SettingUsecase) GetBool added in v3.3.0

func (uc *SettingUsecase) GetBool(key SettingKey, defaultValue ...bool) (bool, error)

func (*SettingUsecase) GetInt added in v3.3.0

func (uc *SettingUsecase) GetInt(key SettingKey, defaultValue ...int) (int, error)

func (*SettingUsecase) GetPanel added in v3.3.0

func (uc *SettingUsecase) GetPanel() (*request.SettingPanel, error)

func (*SettingUsecase) GetSlice added in v3.3.0

func (uc *SettingUsecase) GetSlice(key SettingKey, defaultValue ...[]string) ([]string, error)

func (*SettingUsecase) Set added in v3.3.0

func (uc *SettingUsecase) Set(key SettingKey, value string) error

func (*SettingUsecase) SetSlice added in v3.3.0

func (uc *SettingUsecase) SetSlice(key SettingKey, value []string) error

func (*SettingUsecase) UpdateCert added in v3.3.0

func (uc *SettingUsecase) UpdateCert(req *request.SettingCert) error

func (*SettingUsecase) UpdatePanel added in v3.3.0

func (uc *SettingUsecase) UpdatePanel(ctx context.Context, req *request.SettingPanel) (bool, error)

type TamperLog added in v3.3.0

type TamperLog struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Path      string    `gorm:"not null;default:'';serializer:zstd" json:"path"`
	Op        string    `gorm:"not null;default:''" json:"op"` // write/unlink/rename/setattr/create
	PID       uint      `gorm:"not null;default:0" json:"pid"`
	Comm      string    `gorm:"not null;default:''" json:"comm"`
	CreatedAt time.Time `gorm:"index" json:"created_at"`
}

TamperLog 篡改拦截/告警日志

type TamperRepo added in v3.3.0

type TamperRepo interface {
	ListRules() ([]*TamperRule, error)
	GetRule(id uint) (*TamperRule, error)
	CreateRule(rule *TamperRule) error
	UpdateRule(rule *TamperRule) error
	DeleteRule(id uint) error
	AddLogs(logs []*TamperLog) error
	ListLogs(page, limit uint) ([]*TamperLog, int64, error)
	ClearLogs() error
	ClearLogsBefore(t time.Time) error
	VacuumDB() error
}

TamperRepo 防篡改数据访问接口

type TamperRule added in v3.3.0

type TamperRule struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Name      string    `gorm:"not null;default:'';unique" json:"name"` // 标识
	Path      string    `gorm:"not null;default:''" json:"path"`        // 受保护目录
	Exts      []string  `gorm:"serializer:json" json:"exts"`            // 受保护后缀,空=全部
	Excludes  []string  `gorm:"serializer:json" json:"excludes"`        // 排除子路径
	Enabled   bool      `gorm:"not null;default:true" json:"enabled"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

TamperRule 防篡改保护规则(通常对应一个网站目录)

type TamperSetting added in v3.3.0

type TamperSetting struct {
	Enabled       bool   `json:"enabled"`
	Mode          string `json:"mode"`            // chattr / ebpf
	BlockNewFiles bool   `json:"block_new_files"` // 新建受保护类型文件时删除拦截
	LogDays       uint   `json:"log_days"`        // 日志保留天数
}

TamperSetting 防篡改全局设置

type TamperUsecase added in v3.3.0

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

TamperUsecase 防篡改业务逻辑,持有运行时 Manager

func NewTamperUsecase added in v3.3.0

func NewTamperUsecase(
	notifyUsecase *NotifyUsecase,
	settingUsecase *SettingUsecase,
	t *gotext.Locale,
	log *slog.Logger,
	tamperRepo TamperRepo,
) *TamperUsecase

func (*TamperUsecase) CheckPaths added in v3.3.0

func (uc *TamperUsecase) CheckPaths(paths []string) (map[string]bool, error)

CheckPaths 批量查询路径是否处于保护范围(防篡改未运行时全为 false)

func (*TamperUsecase) CleanupLogs added in v3.3.0

func (uc *TamperUsecase) CleanupLogs()

CleanupLogs 清理过期日志 调用方每分钟触发,但日志按天过期,故限流到 6 小时一次

func (*TamperUsecase) ClearLogs added in v3.3.0

func (uc *TamperUsecase) ClearLogs(ctx context.Context) error

func (*TamperUsecase) CreateRule added in v3.3.0

func (uc *TamperUsecase) CreateRule(ctx context.Context, rule *TamperRule) error

func (*TamperUsecase) DeleteRule added in v3.3.0

func (uc *TamperUsecase) DeleteRule(ctx context.Context, id uint) error

func (*TamperUsecase) DetectEBPF added in v3.3.0

func (uc *TamperUsecase) DetectEBPF() tamper.EBPFStatus

DetectEBPF 检测 eBPF 模式可用性

func (*TamperUsecase) EnableBPFLSMGrub added in v3.3.0

func (uc *TamperUsecase) EnableBPFLSMGrub(ctx context.Context) error

EnableBPFLSMGrub 修改 grub 激活 bpf LSM(需重启系统生效)

func (*TamperUsecase) FlushLogs added in v3.3.0

func (uc *TamperUsecase) FlushLogs()

FlushLogs 将缓冲的拦截日志落库,由定时任务调用

func (*TamperUsecase) GetRule added in v3.3.0

func (uc *TamperUsecase) GetRule(id uint) (*TamperRule, error)

func (*TamperUsecase) GetSetting added in v3.3.0

func (uc *TamperUsecase) GetSetting() (*TamperSetting, error)

GetSetting 读取全局设置

func (*TamperUsecase) ListLogs added in v3.3.0

func (uc *TamperUsecase) ListLogs(page, limit uint) ([]*TamperLog, int64, error)

ListLogs 日志

func (*TamperUsecase) ListRules added in v3.3.0

func (uc *TamperUsecase) ListRules() ([]*TamperRule, error)

Rules 规则管理

func (*TamperUsecase) Reconcile added in v3.3.0

func (uc *TamperUsecase) Reconcile() error

Reconcile 依据设置启停并同步 Manager,应由设置/规则变更后调用

func (*TamperUsecase) Relock added in v3.3.0

func (uc *TamperUsecase) Relock(paths ...string)

Relock 恢复指定路径保护

func (*TamperUsecase) Running added in v3.3.0

func (uc *TamperUsecase) Running() bool

Running 当前是否有 Manager 在运行

func (*TamperUsecase) SaveSetting added in v3.3.0

func (uc *TamperUsecase) SaveSetting(ctx context.Context, s *TamperSetting) error

SaveSetting 保存全局设置并立即生效

func (*TamperUsecase) SetProtect added in v3.3.0

func (uc *TamperUsecase) SetProtect(ctx context.Context, path string, protect bool) error

SetProtect 切换单个路径的保护状态,经由规则/排除联动实现: 保护:命中排除则移除排除项,无覆盖规则则对目录新建整树规则 解除:路径即规则根则删除规则,否则加入排除项

func (*TamperUsecase) Stats added in v3.3.0

func (uc *TamperUsecase) Stats() tamper.Stats

Stats 运行统计

func (*TamperUsecase) Supported added in v3.3.0

func (uc *TamperUsecase) Supported() bool

Supported 当前平台是否支持防篡改

func (*TamperUsecase) Unlock added in v3.3.0

func (uc *TamperUsecase) Unlock(paths ...string) bool

Unlock 临时解除指定路径保护(供面板合法写入前调用),返回是否处于保护中

func (*TamperUsecase) UpdateRule added in v3.3.0

func (uc *TamperUsecase) UpdateRule(ctx context.Context, rule *TamperRule) error

func (*TamperUsecase) VacuumDB added in v3.3.0

func (uc *TamperUsecase) VacuumDB() error

type Task

type Task struct {
	ID          uint       `gorm:"primaryKey" json:"id"`
	Key         string     `gorm:"not null;default:'';index" json:"-"` // 任务标识(域:动作:标的),用于防重
	Name        string     `gorm:"not null;default:'';index" json:"name"`
	Status      TaskStatus `gorm:"not null;default:'waiting'" json:"status"`
	Shell       string     `gorm:"not null;default:''" json:"-"`
	CancelShell string     `gorm:"not null;default:''" json:"-"` // 运行中被取消后执行的清理命令(可选)
	Log         string     `gorm:"not null;default:''" json:"log"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
}

type TaskRepo

type TaskRepo interface {
	HasRunningTask() bool
	List(page, limit uint) ([]*Task, int64, error)
	ListActive() ([]*Task, error)
	Get(id uint) (*Task, error)
	GetByIDs(ids []uint) ([]*Task, error)
	Delete(id uint) error
	Cancel(id uint) error
	Push(task *Task) error
}

type TaskStatus

type TaskStatus string
const (
	TaskStatusWaiting  TaskStatus = "waiting"
	TaskStatusRunning  TaskStatus = "running"
	TaskStatusSuccess  TaskStatus = "finished"
	TaskStatusFailed   TaskStatus = "failed"
	TaskStatusCanceled TaskStatus = "canceled"
)

type TaskUsecase added in v3.3.0

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

func NewTaskUsecase added in v3.3.0

func NewTaskUsecase(t *gotext.Locale, log *slog.Logger, repo TaskRepo) *TaskUsecase

func (*TaskUsecase) Cancel added in v3.3.0

func (uc *TaskUsecase) Cancel(ctx context.Context, id uint) error

func (*TaskUsecase) Delete added in v3.3.0

func (uc *TaskUsecase) Delete(ctx context.Context, id uint) error

func (*TaskUsecase) Get added in v3.3.0

func (uc *TaskUsecase) Get(ctx context.Context, id uint) (*Task, error)

func (*TaskUsecase) GetByIDs added in v3.3.7

func (uc *TaskUsecase) GetByIDs(ids []uint) ([]*Task, error)

func (*TaskUsecase) HasRunningTask added in v3.3.0

func (uc *TaskUsecase) HasRunningTask() bool

func (*TaskUsecase) List added in v3.3.0

func (uc *TaskUsecase) List(ctx context.Context, page, limit uint) ([]*Task, int64, error)

func (*TaskUsecase) ListActive added in v3.3.7

func (uc *TaskUsecase) ListActive() ([]*Task, error)

func (*TaskUsecase) Push added in v3.3.0

func (uc *TaskUsecase) Push(task *Task) error

type TemplateRepo

type TemplateRepo interface {
	LoadLocalTemplates() api.Templates
	Callback(slug string) error
	WriteCompose(name, compose string, envs []types.KV) (string, error)
}

type TemplateUsecase added in v3.3.0

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

func NewTemplateUsecase added in v3.3.0

func NewTemplateUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	cacheRepo CacheRepo,
	templateRepo TemplateRepo,
) *TemplateUsecase

func (*TemplateUsecase) Callback added in v3.3.0

func (uc *TemplateUsecase) Callback(slug string) error

Callback 模版下载回调

func (*TemplateUsecase) CreateCompose added in v3.3.0

func (uc *TemplateUsecase) CreateCompose(
	ctx context.Context,
	slug, name, compose string,
	envs []types.KV,
) (string, error)

CreateCompose 创建编排

func (*TemplateUsecase) Get added in v3.3.0

func (uc *TemplateUsecase) Get(slug string) (*api.Template, error)

Get 获取模版详情

func (*TemplateUsecase) List added in v3.3.0

func (uc *TemplateUsecase) List() api.Templates

List 获取所有模版,包括本地模板

type ToolboxMigrationUsecase added in v3.3.2

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

ToolboxMigrationUsecase 迁移编排,同一时间只允许一个迁移任务

func NewToolboxMigrationUsecase added in v3.3.2

func NewToolboxMigrationUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	source MigrationSourceRepo,
	remote MigrationRemoteRepo,
	archive MigrationArchiveRepo,
	setting *SettingUsecase,
	website *WebsiteUsecase,
	database *DatabaseUsecase,
	databaseServer *DatabaseServerUsecase,
	databaseUser *DatabaseUserUsecase,
	backup *BackupUsecase,
	project *ProjectUsecase,
	app *AppUsecase,
	environment *EnvironmentUsecase,
) *ToolboxMigrationUsecase

func (*ToolboxMigrationUsecase) Connect added in v3.3.2

Connect 校验来源连接并保存,返回来源面板信息

func (*ToolboxMigrationUsecase) Items added in v3.3.2

Items 列出可迁移资源,并标注目标侧冲突

func (*ToolboxMigrationUsecase) Logs added in v3.3.2

func (uc *ToolboxMigrationUsecase) Logs() []string

Logs 返回完整迁移日志

func (*ToolboxMigrationUsecase) Reset added in v3.3.2

Reset 重置迁移状态

func (*ToolboxMigrationUsecase) Start added in v3.3.2

Start 异步开始迁移

func (*ToolboxMigrationUsecase) Status added in v3.3.2

Status 返回当前迁移状态,since 为已获取的日志条数

type User

type User struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Username  string    `gorm:"not null;default:'';unique" json:"username"`
	Password  string    `gorm:"not null;default:''" json:"password"`
	Email     string    `gorm:"not null;default:''" json:"email"`
	TwoFA     string    `gorm:"not null;default:''" json:"two_fa"` // 2FA secret,为空表示未开启
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type UserPasskey added in v3.1.2

type UserPasskey struct {
	ID             uint       `gorm:"primaryKey" json:"id"`
	UserID         uint       `gorm:"index;not null" json:"user_id"`
	Name           string     `gorm:"not null;default:''" json:"name"`
	CredentialID   []byte     `gorm:"uniqueIndex;not null" json:"-"`
	PublicKey      []byte     `gorm:"not null" json:"-"`
	AAGUID         []byte     `json:"-"`
	SignCount      uint32     `gorm:"not null;default:0" json:"-"`
	Transports     string     `gorm:"not null;default:''" json:"transports"` // JSON: ["internal","hybrid"]
	BackupEligible bool       `gorm:"not null;default:false" json:"-"`
	BackupState    bool       `gorm:"not null;default:false" json:"-"`
	LastUsedAt     *time.Time `json:"last_used_at"`
	CreatedAt      time.Time  `json:"created_at"`
	UpdatedAt      time.Time  `json:"updated_at"`
}

type UserPasskeyRepo added in v3.1.2

type UserPasskeyRepo interface {
	List(userID uint) ([]*UserPasskey, error)
	Get(userID, id uint) (*UserPasskey, error)
	Create(passkey *UserPasskey) error
	UpdateSignCount(credentialID []byte, signCount uint32) error
	UpdateLastUsed(credentialID []byte) error
	Delete(userID, id uint) error
	HasAny() (bool, error)
	DeleteAllByUserID(userID uint) error
}

type UserPasskeyUsecase added in v3.3.0

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

func NewUserPasskeyUsecase added in v3.3.0

func NewUserPasskeyUsecase(t *gotext.Locale, log *slog.Logger, repo UserPasskeyRepo) *UserPasskeyUsecase

func (*UserPasskeyUsecase) Create added in v3.3.0

func (uc *UserPasskeyUsecase) Create(ctx context.Context, passkey *UserPasskey) error

func (*UserPasskeyUsecase) Delete added in v3.3.0

func (uc *UserPasskeyUsecase) Delete(ctx context.Context, userID, id uint) error

func (*UserPasskeyUsecase) DeleteAllByUserID added in v3.3.0

func (uc *UserPasskeyUsecase) DeleteAllByUserID(userID uint) error

func (*UserPasskeyUsecase) HasAny added in v3.3.0

func (uc *UserPasskeyUsecase) HasAny() (bool, error)

func (*UserPasskeyUsecase) List added in v3.3.0

func (uc *UserPasskeyUsecase) List(userID uint) ([]*UserPasskey, error)

func (*UserPasskeyUsecase) UpdateLastUsed added in v3.3.0

func (uc *UserPasskeyUsecase) UpdateLastUsed(credentialID []byte) error

func (*UserPasskeyUsecase) UpdateSignCount added in v3.3.0

func (uc *UserPasskeyUsecase) UpdateSignCount(credentialID []byte, signCount uint32) error

type UserRepo

type UserRepo interface {
	List(page, limit uint) ([]*User, int64, error)
	Get(id uint) (*User, error)
	GetByUsername(username string) (*User, error)
	First() (*User, error)
	Count() (int64, error)
	Create(username, password, email string) (*User, error)
	UpdateUsername(id uint, username string) error
	UpdatePassword(id uint, password string) error
	UpdateEmail(id uint, email string) error
	Delete(id uint) (string, error)
	CheckPassword(username, password string) (*User, error)
	IsTwoFA(username string) (bool, error)
	GenerateTwoFA(id uint) (image.Image, string, string, error)
	UpdateTwoFA(id uint, code, secret string) error
}

type UserToken

type UserToken struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	UserID    uint      `gorm:"index" json:"user_id"`
	Token     string    `gorm:"not null;default:'';unique" json:"-"`
	IPs       []string  `gorm:"not null;default:'[]';serializer:json" json:"ips"`
	ExpiredAt time.Time `json:"expired_at"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func (*UserToken) AfterFind

func (r *UserToken) AfterFind(tx *gorm.DB) error

func (*UserToken) BeforeSave

func (r *UserToken) BeforeSave(tx *gorm.DB) error

type UserTokenRepo

type UserTokenRepo interface {
	List(userID, page, limit uint) ([]*UserToken, int64, error)
	Get(id uint) (*UserToken, error)
	Create(userID uint, ips []string, expired time.Time) (*UserToken, error)
	Update(id uint, ips []string, expired time.Time) (*UserToken, error)
	Delete(id uint) error
	ValidateReq(req *http.Request) (uint, error)
}

type UserTokenUsecase added in v3.3.0

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

func NewUserTokenUsecase added in v3.3.0

func NewUserTokenUsecase(t *gotext.Locale, log *slog.Logger, repo UserTokenRepo) *UserTokenUsecase

func (*UserTokenUsecase) Create added in v3.3.0

func (uc *UserTokenUsecase) Create(
	ctx context.Context,
	userID uint,
	ips []string,
	expired time.Time,
) (*UserToken, error)

func (*UserTokenUsecase) Delete added in v3.3.0

func (uc *UserTokenUsecase) Delete(ctx context.Context, id uint) error

func (*UserTokenUsecase) List added in v3.3.0

func (uc *UserTokenUsecase) List(ctx context.Context, userID, page, limit uint) ([]*UserToken, int64, error)

func (*UserTokenUsecase) Update added in v3.3.0

func (uc *UserTokenUsecase) Update(ctx context.Context, id uint, ips []string, expired time.Time) (*UserToken, error)

type UserUsecase added in v3.3.0

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

func NewUserUsecase added in v3.3.0

func NewUserUsecase(t *gotext.Locale, log *slog.Logger, userRepo UserRepo) *UserUsecase

func (*UserUsecase) CheckPassword added in v3.3.0

func (uc *UserUsecase) CheckPassword(username, password string) (*User, error)

func (*UserUsecase) Create added in v3.3.0

func (uc *UserUsecase) Create(ctx context.Context, username, password, email string) (*User, error)

func (*UserUsecase) Delete added in v3.3.0

func (uc *UserUsecase) Delete(ctx context.Context, id uint) error

func (*UserUsecase) First added in v3.3.13

func (uc *UserUsecase) First() (*User, error)

First 取 ID 最小的用户,没有登录态的面板级操作用它代表管理员

func (*UserUsecase) GenerateTwoFA added in v3.3.0

func (uc *UserUsecase) GenerateTwoFA(id uint) (image.Image, string, string, error)

func (*UserUsecase) Get added in v3.3.0

func (uc *UserUsecase) Get(id uint) (*User, error)

func (*UserUsecase) GetByUsername added in v3.3.13

func (uc *UserUsecase) GetByUsername(username string) (*User, error)

func (*UserUsecase) IsTwoFA added in v3.3.0

func (uc *UserUsecase) IsTwoFA(username string) (bool, error)

func (*UserUsecase) List added in v3.3.0

func (uc *UserUsecase) List(ctx context.Context, page, limit uint) ([]*User, int64, error)

func (*UserUsecase) UpdateEmail added in v3.3.0

func (uc *UserUsecase) UpdateEmail(ctx context.Context, id uint, email string) error

func (*UserUsecase) UpdatePassword added in v3.3.0

func (uc *UserUsecase) UpdatePassword(ctx context.Context, id uint, password string) error

func (*UserUsecase) UpdateTwoFA added in v3.3.0

func (uc *UserUsecase) UpdateTwoFA(ctx context.Context, id uint, code, secret string) error

func (*UserUsecase) UpdateUsername added in v3.3.0

func (uc *UserUsecase) UpdateUsername(ctx context.Context, id uint, username string) error

type WebHook

type WebHook struct {
	ID         uint      `gorm:"primaryKey" json:"id"`
	Name       string    `gorm:"not null;default:''" json:"name"`      // 钩子名称
	Key        string    `gorm:"not null;uniqueIndex" json:"key"`      // 唯一标识(用于 URL)
	Script     string    `gorm:"not null;default:''" json:"script"`    // 脚本内容
	Raw        bool      `gorm:"not null;default:false" json:"raw"`    // 是否以原始格式返回输出
	User       string    `gorm:"not null;default:''" json:"user"`      // 以哪个用户身份执行脚本
	Status     bool      `gorm:"not null;default:true" json:"status"`  // 启用状态
	CallCount  uint      `gorm:"not null;default:0" json:"call_count"` // 调用次数
	LastCallAt time.Time `json:"last_call_at"`                         // 上次调用时间
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

type WebHookRepo

type WebHookRepo interface {
	List(page, limit uint) ([]*WebHook, int64, error)
	Get(id uint) (*WebHook, error)
	GetByKey(key string) (*WebHook, error)
	CreateWithScript(webhook *WebHook, script string) error
	UpdateWithScript(webhook *WebHook, req *request.WebHookUpdate) error
	RemoveScript(key string)
	Delete(id uint) error
	Call(key string) (string, error)
}

type WebHookUsecase added in v3.3.0

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

func NewWebHookUsecase added in v3.3.0

func NewWebHookUsecase(t *gotext.Locale, log *slog.Logger, webHookRepo WebHookRepo) *WebHookUsecase

func (*WebHookUsecase) Call added in v3.3.0

func (uc *WebHookUsecase) Call(ctx context.Context, webhook *WebHook, ip string) (string, error)

func (*WebHookUsecase) Create added in v3.3.0

func (uc *WebHookUsecase) Create(ctx context.Context, req *request.WebHookCreate) (*WebHook, error)

func (*WebHookUsecase) Delete added in v3.3.0

func (uc *WebHookUsecase) Delete(ctx context.Context, id uint) error

func (*WebHookUsecase) Get added in v3.3.0

func (uc *WebHookUsecase) Get(ctx context.Context, id uint) (*WebHook, error)

func (*WebHookUsecase) GetByKey added in v3.3.0

func (uc *WebHookUsecase) GetByKey(key string) (*WebHook, error)

func (*WebHookUsecase) List added in v3.3.0

func (uc *WebHookUsecase) List(ctx context.Context, page, limit uint) ([]*WebHook, int64, error)

func (*WebHookUsecase) Update added in v3.3.0

func (uc *WebHookUsecase) Update(ctx context.Context, req *request.WebHookUpdate) error

type Website

type Website struct {
	ID        uint        `gorm:"primaryKey" json:"id"`
	Name      string      `gorm:"not null;default:'';unique" json:"name"`
	Type      WebsiteType `gorm:"not null;index;default:'static'" json:"type"`
	Status    bool        `gorm:"not null;default:true" json:"status"`
	Path      string      `gorm:"not null;default:''" json:"path"`
	SSL       bool        `gorm:"not null;default:false" json:"ssl"`
	CertID    uint        `gorm:"not null;index;default:0" json:"cert_id"`    // 部署的证书 ID
	ProjectID uint        `gorm:"not null;index;default:0" json:"project_id"` // 绑定的项目 ID,0 表示未绑定
	Remark    string      `gorm:"not null;default:''" json:"remark"`
	ExpireAt  *time.Time  `json:"expire_at"` // 到期时间,nil 表示不限时
	CreatedAt time.Time   `json:"created_at"`
	UpdatedAt time.Time   `json:"updated_at"`

	CertExpire string   `gorm:"-:all" json:"cert_expire"` // 仅显示
	PHP        uint     `gorm:"-:all" json:"php"`         // 仅显示
	Domains    []string `gorm:"-:all" json:"domains"`     // 仅显示

	Cert *Cert `gorm:"foreignKey:CertID" json:"cert"`
}

type WebsiteErrorLog

type WebsiteErrorLog struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Site      string    `gorm:"not null;index:idx_werr_site_time" json:"site"`
	URI       string    `gorm:"not null;serializer:zstd" json:"uri"`
	Method    string    `gorm:"not null" json:"method"`
	Status    int       `gorm:"not null;index" json:"status"`
	IP        string    `gorm:"not null" json:"ip"`
	UA        string    `gorm:"not null;serializer:zstd" json:"ua"`
	Body      string    `gorm:"type:text;serializer:zstd" json:"body"`
	CreatedAt time.Time `gorm:"index:idx_werr_site_time" json:"created_at"`
}

WebsiteErrorLog 网站错误日志(400-599 状态码详情)

type WebsiteHourStat added in v3.3.1

type WebsiteHourStat struct {
	Site      string
	Requests  uint64
	Errors    uint64
	Status5xx uint64
}

WebsiteHourStat 网站当前小时的请求统计

type WebsiteRepo

type WebsiteRepo interface {
	GetRewrites() (map[string]string, error)
	UpdateDefaultConfig(ctx context.Context, req *request.WebsiteDefaultConfig) error
	Count() (int64, error)
	Get(id uint) (*types.WebsiteSetting, error)
	GetByName(name string) (*types.WebsiteSetting, error)
	List(typ, keyword string, projectID, page, limit uint) ([]*Website, int64, error)
	// All 只查库,不读证书和 vhost 配置
	All() ([]*Website, error)
	Create(ctx context.Context, req *request.WebsiteCreate) (*Website, error)
	Update(ctx context.Context, req *request.WebsiteUpdate) (*Website, error)
	SwitchType(ctx context.Context, req *request.WebsiteSwitchType) (*Website, error)
	GetForDelete(id uint) (*Website, error)
	RemoveFiles(ctx context.Context, name string, removePath bool) error
	Delete(website *Website) error
	ReloadWebServer(ctx context.Context) error
	UpdateRemark(id uint, remark string) error
	ResetConfig(ctx context.Context, id uint) error
	Rebuild(ctx context.Context, website *Website) (bool, []string, error)
	UpdateStatus(ctx context.Context, id uint, status bool) error
	UpdateExpireAt(id uint, expireAt *time.Time) error
	UpdateCert(ctx context.Context, req *request.WebsiteUpdateCert) error
	UpdateProject(id, projectID uint) error
	UnbindProject(projectID uint) error
}

type WebsiteStat

type WebsiteStat struct {
	ID               uint      `gorm:"primaryKey" json:"id"`
	Site             string    `gorm:"not null;uniqueIndex:idx_wstat_unique" json:"site"`
	Date             string    `gorm:"not null;uniqueIndex:idx_wstat_unique;index" json:"date"`
	Hour             int       `gorm:"not null;uniqueIndex:idx_wstat_unique;default:-1" json:"hour"` // -1=每日汇总, 0-23=小时
	PV               uint64    `gorm:"not null;default:0" json:"pv"`
	UV               uint64    `gorm:"not null;default:0" json:"uv"`
	IP               uint64    `gorm:"not null;default:0" json:"ip"`
	Bandwidth        uint64    `gorm:"not null;default:0" json:"bandwidth"`
	BandwidthIn      uint64    `gorm:"not null;default:0" json:"bandwidth_in"`
	Requests         uint64    `gorm:"not null;default:0" json:"requests"`
	Errors           uint64    `gorm:"not null;default:0" json:"errors"`
	Spiders          uint64    `gorm:"not null;default:0" json:"spiders"`
	RequestTimeSum   uint64    `gorm:"not null;default:0" json:"request_time_sum"`
	RequestTimeCount uint64    `gorm:"not null;default:0" json:"request_time_count"`
	Status2xx        uint64    `gorm:"not null;default:0" json:"status_2xx"`
	Status3xx        uint64    `gorm:"not null;default:0" json:"status_3xx"`
	Status4xx        uint64    `gorm:"not null;default:0" json:"status_4xx"`
	Status5xx        uint64    `gorm:"not null;default:0" json:"status_5xx"`
	CreatedAt        time.Time `json:"created_at"`
	UpdatedAt        time.Time `json:"updated_at"`
}

WebsiteStat 网站统计(每站每天一行或每小时一行)

type WebsiteStatClient

type WebsiteStatClient struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Site      string    `gorm:"not null;uniqueIndex:idx_wclient_unique" json:"site"`
	Date      string    `gorm:"not null;uniqueIndex:idx_wclient_unique;index" json:"date"`
	Browser   string    `gorm:"not null;uniqueIndex:idx_wclient_unique" json:"browser"`
	OS        string    `gorm:"not null;uniqueIndex:idx_wclient_unique" json:"os"`
	Requests  uint64    `gorm:"not null;default:0" json:"requests"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

WebsiteStatClient 客户端统计(site, date, browser, os 唯一)

type WebsiteStatClientRank

type WebsiteStatClientRank struct {
	Browser  string `json:"browser"`
	OS       string `json:"os"`
	Requests uint64 `json:"requests"`
}

WebsiteStatClientRank 客户端排名

type WebsiteStatGeoRank

type WebsiteStatGeoRank struct {
	Country   string `json:"country"`
	Region    string `json:"region"`
	City      string `json:"city"`
	Requests  uint64 `json:"requests"`
	Bandwidth uint64 `json:"bandwidth"`
}

WebsiteStatGeoRank 地理位置归类统计

type WebsiteStatIP

type WebsiteStatIP struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Site      string    `gorm:"not null;uniqueIndex:idx_wip_unique" json:"site"`
	Date      string    `gorm:"not null;uniqueIndex:idx_wip_unique;index" json:"date"`
	IP        string    `gorm:"not null;uniqueIndex:idx_wip_unique" json:"ip"`
	Country   string    `gorm:"not null;default:''" json:"country"`
	Region    string    `gorm:"not null;default:''" json:"region"`
	City      string    `gorm:"not null;default:''" json:"city"`
	ISP       string    `gorm:"not null;default:''" json:"isp"`
	Requests  uint64    `gorm:"not null;default:0" json:"requests"`
	Bandwidth uint64    `gorm:"not null;default:0" json:"bandwidth"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

WebsiteStatIP IP 统计(site, date, ip 唯一)

type WebsiteStatIPRank

type WebsiteStatIPRank struct {
	IP        string `json:"ip"`
	Country   string `json:"country"`
	Region    string `json:"region"`
	City      string `json:"city"`
	ISP       string `json:"isp"`
	Requests  uint64 `json:"requests"`
	Bandwidth uint64 `json:"bandwidth"`
}

WebsiteStatIPRank IP 排名

type WebsiteStatOverview added in v3.3.13

type WebsiteStatOverview struct {
	Current        websitestat.Counters
	Previous       websitestat.Counters
	Series         []*WebsiteStatSeries
	PreviousSeries []*WebsiteStatSeries
}

WebsiteStatOverview 概览:所选周期与紧邻其前的等长周期

type WebsiteStatRepo

type WebsiteStatRepo interface {
	// Upsert 批量写入/更新统计数据(含每日汇总和小时数据)
	Upsert(stats []*WebsiteStat) error
	// DailySeries 按日分组的时间序列
	DailySeries(start, end string, sites []string) ([]*WebsiteStatSeries, error)
	// HourlySeries 按小时的时间序列(单天查询)
	HourlySeries(date string, sites []string) ([]*WebsiteStatSeries, error)
	// ClearBefore 清理过期数据
	ClearBefore(date string) error
	// InsertErrors 批量写入错误日志
	InsertErrors(errors []*WebsiteErrorLog) error
	// ClearErrorsBefore 清理过期错误日志
	ClearErrorsBefore(t time.Time) error
	// Clear 清空所有统计数据
	Clear() error
	// DeleteBySite 清空指定站点在六张统计表中的全部数据
	DeleteBySite(site string) error
	VacuumDB() error

	// 蜘蛛统计
	UpsertSpiders(stats []*WebsiteStatSpider) error
	TopSpiders(start, end string, sites []string, limit uint) ([]*WebsiteStatSpiderRank, error)
	ClearSpidersBefore(date string) error

	// 客户端统计
	UpsertClients(stats []*WebsiteStatClient) error
	TopClients(start, end string, sites []string, limit uint) ([]*WebsiteStatClientRank, error)
	ClearClientsBefore(date string) error

	// IP 统计
	UpsertIPs(stats []*WebsiteStatIP) error
	TopIPs(start, end string, sites []string, page, limit uint) ([]*WebsiteStatIPRank, uint, error)
	TopGeos(start, end string, sites []string, groupBy string, country string, limit uint) ([]*WebsiteStatGeoRank, error)
	ClearIPsBefore(date string) error

	// URI 统计
	UpsertURIs(stats []*WebsiteStatURI) error
	TopURIs(start, end string, sites []string, page, limit uint) ([]*WebsiteStatURIRank, uint, error)
	TopSlowURIs(start, end string, sites []string, threshold, page, limit uint) ([]*WebsiteStatURIRank, uint, error)
	ClearURIsBefore(date string) error

	// 错误日志查询
	ListErrors(start, end string, sites []string, status int, page, limit uint) ([]*WebsiteErrorLog, uint, error)

	// 网站维度汇总
	ListSiteStats(start, end string, sites []string) ([]*WebsiteStatSiteItem, error)
}

WebsiteStatRepo 网站统计数据访问接口

type WebsiteStatSeries

type WebsiteStatSeries struct {
	Key string `json:"key"` // 小时 "0"-"23" 或日期 "2026-02-18"
	websitestat.Counters
}

WebsiteStatSeries 时间序列数据点(用于 API 返回)

type WebsiteStatSiteItem

type WebsiteStatSiteItem struct {
	Site string `json:"site"`
	websitestat.Counters
}

WebsiteStatSiteItem 网站维度汇总

type WebsiteStatSpider

type WebsiteStatSpider struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Site      string    `gorm:"not null;uniqueIndex:idx_wspider_unique" json:"site"`
	Date      string    `gorm:"not null;uniqueIndex:idx_wspider_unique;index" json:"date"`
	Spider    string    `gorm:"not null;uniqueIndex:idx_wspider_unique" json:"spider"`
	Requests  uint64    `gorm:"not null;default:0" json:"requests"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

WebsiteStatSpider 蜘蛛统计(site, date, spider 唯一)

type WebsiteStatSpiderRank

type WebsiteStatSpiderRank struct {
	Spider   string  `json:"spider"`
	Requests uint64  `json:"requests"`
	Percent  float64 `json:"percent"`
}

WebsiteStatSpiderRank 蜘蛛排名

type WebsiteStatURI

type WebsiteStatURI struct {
	ID               uint      `gorm:"primaryKey" json:"id"`
	Site             string    `gorm:"not null;uniqueIndex:idx_wuri_unique" json:"site"`
	Date             string    `gorm:"not null;uniqueIndex:idx_wuri_unique;index" json:"date"`
	URI              string    `gorm:"not null;uniqueIndex:idx_wuri_unique" json:"uri"`
	Requests         uint64    `gorm:"not null;default:0" json:"requests"`
	Bandwidth        uint64    `gorm:"not null;default:0" json:"bandwidth"`
	Errors           uint64    `gorm:"not null;default:0" json:"errors"`
	RequestTimeSum   uint64    `gorm:"not null;default:0" json:"request_time_sum"`
	RequestTimeCount uint64    `gorm:"not null;default:0" json:"request_time_count"`
	CreatedAt        time.Time `json:"created_at"`
	UpdatedAt        time.Time `json:"updated_at"`
}

WebsiteStatURI URI 统计(site, date, uri 唯一)

type WebsiteStatURIRank

type WebsiteStatURIRank struct {
	URI              string `json:"uri"`
	Requests         uint64 `json:"requests"`
	Bandwidth        uint64 `json:"bandwidth"`
	Errors           uint64 `json:"errors"`
	RequestTimeSum   uint64 `json:"request_time_sum"`
	RequestTimeCount uint64 `json:"request_time_count"`
}

WebsiteStatURIRank URI 排名

type WebsiteStatUsecase added in v3.3.0

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

func NewWebsiteStatUsecase added in v3.3.0

func NewWebsiteStatUsecase(
	t *gotext.Locale,
	log *slog.Logger,
	repo WebsiteStatRepo,
	aggregator *websitestat.Aggregator,
) *WebsiteStatUsecase

func (*WebsiteStatUsecase) Clear added in v3.3.0

func (uc *WebsiteStatUsecase) Clear(ctx context.Context) error

func (*WebsiteStatUsecase) ClearBefore added in v3.3.0

func (uc *WebsiteStatUsecase) ClearBefore(date string) error

func (*WebsiteStatUsecase) ClearClientsBefore added in v3.3.0

func (uc *WebsiteStatUsecase) ClearClientsBefore(date string) error

func (*WebsiteStatUsecase) ClearErrorsBefore added in v3.3.0

func (uc *WebsiteStatUsecase) ClearErrorsBefore(t time.Time) error

func (*WebsiteStatUsecase) ClearIPsBefore added in v3.3.0

func (uc *WebsiteStatUsecase) ClearIPsBefore(date string) error

func (*WebsiteStatUsecase) ClearSpidersBefore added in v3.3.0

func (uc *WebsiteStatUsecase) ClearSpidersBefore(date string) error

func (*WebsiteStatUsecase) ClearURIsBefore added in v3.3.0

func (uc *WebsiteStatUsecase) ClearURIsBefore(date string) error

func (*WebsiteStatUsecase) DeleteBySite added in v3.3.0

func (uc *WebsiteStatUsecase) DeleteBySite(site string) error

func (*WebsiteStatUsecase) InsertErrors added in v3.3.0

func (uc *WebsiteStatUsecase) InsertErrors(errors []*WebsiteErrorLog) error

func (*WebsiteStatUsecase) ListErrors added in v3.3.0

func (uc *WebsiteStatUsecase) ListErrors(
	start, end string,
	sites []string,
	status int,
	page, limit uint,
) ([]*WebsiteErrorLog, uint, error)

func (*WebsiteStatUsecase) ListSiteStats added in v3.3.0

func (uc *WebsiteStatUsecase) ListSiteStats(start, end string, sites []string) ([]*WebsiteStatSiteItem, error)

ListSiteStats 各站点在日期范围内的汇总,按请求数降序

func (*WebsiteStatUsecase) Overview added in v3.3.13

func (uc *WebsiteStatUsecase) Overview(start, end string, sites []string) (*WebsiteStatOverview, error)

Overview 所选周期与上一周期的汇总和时间序列,单日按小时、多日按天

func (*WebsiteStatUsecase) TopClients added in v3.3.0

func (uc *WebsiteStatUsecase) TopClients(
	start, end string,
	sites []string,
	limit uint,
) ([]*WebsiteStatClientRank, error)

func (*WebsiteStatUsecase) TopGeos added in v3.3.0

func (uc *WebsiteStatUsecase) TopGeos(
	start, end string,
	sites []string,
	groupBy string,
	country string,
	limit uint,
) ([]*WebsiteStatGeoRank, error)

func (*WebsiteStatUsecase) TopIPs added in v3.3.0

func (uc *WebsiteStatUsecase) TopIPs(
	start, end string,
	sites []string,
	page, limit uint,
) ([]*WebsiteStatIPRank, uint, error)

func (*WebsiteStatUsecase) TopSlowURIs added in v3.3.0

func (uc *WebsiteStatUsecase) TopSlowURIs(
	start, end string,
	sites []string,
	threshold, page, limit uint,
) ([]*WebsiteStatURIRank, uint, error)

func (*WebsiteStatUsecase) TopSpiders added in v3.3.0

func (uc *WebsiteStatUsecase) TopSpiders(
	start, end string,
	sites []string,
	limit uint,
) ([]*WebsiteStatSpiderRank, error)

func (*WebsiteStatUsecase) TopURIs added in v3.3.0

func (uc *WebsiteStatUsecase) TopURIs(
	start, end string,
	sites []string,
	page, limit uint,
) ([]*WebsiteStatURIRank, uint, error)

func (*WebsiteStatUsecase) Upsert added in v3.3.0

func (uc *WebsiteStatUsecase) Upsert(stats []*WebsiteStat) error

func (*WebsiteStatUsecase) UpsertClients added in v3.3.0

func (uc *WebsiteStatUsecase) UpsertClients(stats []*WebsiteStatClient) error

func (*WebsiteStatUsecase) UpsertIPs added in v3.3.0

func (uc *WebsiteStatUsecase) UpsertIPs(stats []*WebsiteStatIP) error

func (*WebsiteStatUsecase) UpsertSpiders added in v3.3.0

func (uc *WebsiteStatUsecase) UpsertSpiders(stats []*WebsiteStatSpider) error

func (*WebsiteStatUsecase) UpsertURIs added in v3.3.0

func (uc *WebsiteStatUsecase) UpsertURIs(stats []*WebsiteStatURI) error

func (*WebsiteStatUsecase) VacuumDB added in v3.3.0

func (uc *WebsiteStatUsecase) VacuumDB() error

type WebsiteType

type WebsiteType string
const (
	WebsiteTypeProxy  WebsiteType = "proxy"
	WebsiteTypePHP    WebsiteType = "php"
	WebsiteTypeStatic WebsiteType = "static"
)

type WebsiteUsecase added in v3.3.0

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

func NewWebsiteUsecase added in v3.3.0

func NewWebsiteUsecase(
	certAccountUsecase *CertAccountUsecase,
	certUsecase *CertUsecase,
	databaseUsecase *DatabaseUsecase,
	databaseUserUsecase *DatabaseUserUsecase,
	tamperUsecase *TamperUsecase,
	websiteStatUsecase *WebsiteStatUsecase,
	t *gotext.Locale,
	log *slog.Logger,
	databaseServerRepo DatabaseServerRepo,
	websiteRepo WebsiteRepo,
) *WebsiteUsecase

func (*WebsiteUsecase) All added in v3.3.13

func (uc *WebsiteUsecase) All() ([]*Website, error)

func (*WebsiteUsecase) Count added in v3.3.0

func (uc *WebsiteUsecase) Count() (int64, error)

func (*WebsiteUsecase) Create added in v3.3.0

func (uc *WebsiteUsecase) Create(ctx context.Context, req *request.WebsiteCreate) (*Website, []string, error)

func (*WebsiteUsecase) Delete added in v3.3.0

func (uc *WebsiteUsecase) Delete(ctx context.Context, req *request.WebsiteDelete) error

func (*WebsiteUsecase) Get added in v3.3.0

func (uc *WebsiteUsecase) Get(id uint) (*types.WebsiteSetting, error)

func (*WebsiteUsecase) GetByName added in v3.3.0

func (uc *WebsiteUsecase) GetByName(name string) (*types.WebsiteSetting, error)

func (*WebsiteUsecase) GetRewrites added in v3.3.0

func (uc *WebsiteUsecase) GetRewrites() (map[string]string, error)

func (*WebsiteUsecase) List added in v3.3.0

func (uc *WebsiteUsecase) List(typ, keyword string, projectID, page, limit uint) ([]*Website, int64, error)

func (*WebsiteUsecase) ObtainCert added in v3.3.0

func (uc *WebsiteUsecase) ObtainCert(ctx context.Context, id uint, dnsID uint) error

func (*WebsiteUsecase) Rebuild added in v3.3.6

func (uc *WebsiteUsecase) Rebuild(ctx context.Context, website *Website) (bool, []string, error)

Rebuild 按当前 Web 服务器重建站点配置

func (*WebsiteUsecase) ReleaseProject added in v3.3.11

func (uc *WebsiteUsecase) ReleaseProject(ctx context.Context, projectID uint, remove bool) error

ReleaseProject 处理项目删除后留下的网站:remove 为 true 时一并删除,否则解除绑定成为普通网站

func (*WebsiteUsecase) ResetConfig added in v3.3.0

func (uc *WebsiteUsecase) ResetConfig(ctx context.Context, id uint) error

func (*WebsiteUsecase) SwitchType added in v3.3.2

func (uc *WebsiteUsecase) SwitchType(ctx context.Context, req *request.WebsiteSwitchType) error

func (*WebsiteUsecase) Update added in v3.3.0

func (uc *WebsiteUsecase) Update(ctx context.Context, req *request.WebsiteUpdate) error

func (*WebsiteUsecase) UpdateCert added in v3.3.0

func (uc *WebsiteUsecase) UpdateCert(ctx context.Context, req *request.WebsiteUpdateCert) error

func (*WebsiteUsecase) UpdateDefaultConfig added in v3.3.0

func (uc *WebsiteUsecase) UpdateDefaultConfig(ctx context.Context, req *request.WebsiteDefaultConfig) error

func (*WebsiteUsecase) UpdateExpireAt added in v3.3.0

func (uc *WebsiteUsecase) UpdateExpireAt(ctx context.Context, id uint, expireAt *time.Time) error

func (*WebsiteUsecase) UpdateProject added in v3.3.11

func (uc *WebsiteUsecase) UpdateProject(ctx context.Context, id, projectID uint) error

UpdateProject 绑定到项目,projectID 为 0 时解除绑定

func (*WebsiteUsecase) UpdateRemark added in v3.3.0

func (uc *WebsiteUsecase) UpdateRemark(ctx context.Context, id uint, remark string) error

func (*WebsiteUsecase) UpdateStatus added in v3.3.0

func (uc *WebsiteUsecase) UpdateStatus(ctx context.Context, id uint, status bool) error

Jump to

Keyboard shortcuts

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