service

package
v1.5.7 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: GPL-3.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LastUpdate int64
)

Functions

This section is empty.

Types

type AcmeService added in v1.4.7

type AcmeService struct{}

AcmeService 是无状态工具,不嵌入 SettingService(避免与 ApiService 已嵌入的 SettingService 产生方法集二义性)。所有入参由调用方传入,不直接读写数据库。

func (*AcmeService) DetectNginx added in v1.4.7

func (a *AcmeService) DetectNginx() NginxStatus

DetectNginx 检测 nginx 是否安装并运行。Windows 直接返回未安装。

func (*AcmeService) IssueWeb added in v1.4.7

func (a *AcmeService) IssueWeb(domain, email string, useNginx, force bool) (*IssueResult, error)

IssueWeb 为面板申请证书并安装到 /root/cert/{域名}/。

  • useNginx=false:standalone 模式占用 80 端口申请(需 socat)。
  • useNginx=true :nginx 模式申请,不抢 80 端口,证书供 nginx 使用。
  • force=true :域名已有未到期证书时 acme.sh 默认跳过签发,force 时加 --force 强制续期。

func (*AcmeService) ListCerts added in v1.4.7

func (a *AcmeService) ListCerts() (string, error)

ListCerts 返回 acme.sh 已管理的证书列表,供前端展示、避免重复申请触发 LE 限速。

type ClientService

type ClientService struct{}

func (*ClientService) DepleteClients

func (s *ClientService) DepleteClients() ([]uint, error)

func (*ClientService) Get

func (s *ClientService) Get(id string) (*[]model.Client, error)

func (*ClientService) GetAll

func (s *ClientService) GetAll() (*[]model.Client, error)

func (*ClientService) ResetAllClientsTraffic added in v1.5.4

func (s *ClientService) ResetAllClientsTraffic() error

ResetAllClientsTraffic zeroes up/down for every client (accumulating into the total counters) and re-enables all of them, in a single bulk update. Used by the global periodic traffic reset; the caller restarts the core afterwards so re-enabled clients take effect.

func (*ClientService) ResetClients

func (s *ClientService) ResetClients(tx *gorm.DB, dt int64) ([]uint, error)

func (*ClientService) Save

func (s *ClientService) Save(tx *gorm.DB, act string, data json.RawMessage, hostname string) ([]uint, error)

func (*ClientService) UpdateClientsOnInboundAdd

func (s *ClientService) UpdateClientsOnInboundAdd(tx *gorm.DB, initIds string, inboundId uint, hostname string) error

func (*ClientService) UpdateClientsOnInboundDelete

func (s *ClientService) UpdateClientsOnInboundDelete(tx *gorm.DB, id uint, tag string) error

func (*ClientService) UpdateLinksByInboundChange

func (s *ClientService) UpdateLinksByInboundChange(tx *gorm.DB, inbounds *[]model.Inbound, hostname string, oldTag string) error

type ConfigService

func NewConfigService

func NewConfigService(core *core.Core) *ConfigService

func (*ConfigService) CheckChanges

func (s *ConfigService) CheckChanges(lu string) (bool, error)

func (*ConfigService) CheckOutbound

func (s *ConfigService) CheckOutbound(tag string, link string) core.CheckOutboundResult

func (*ConfigService) GetChanges

func (s *ConfigService) GetChanges(actor string, chngKey string, count string) []model.Changes

func (*ConfigService) GetConfig

func (s *ConfigService) GetConfig(data string) (*[]byte, error)

func (*ConfigService) RestartCore

func (s *ConfigService) RestartCore() error

func (*ConfigService) Save

func (s *ConfigService) Save(obj string, act string, data json.RawMessage, initUsers string, loginUser string, hostname string) ([]string, error)

func (*ConfigService) StartCore

func (s *ConfigService) StartCore() error

func (*ConfigService) StopCore

func (s *ConfigService) StopCore() error

func (*ConfigService) TestAcme

func (s *ConfigService) TestAcme(domain, email string) error

TestAcme attempts to obtain a certificate for the domain right now, so the UI can verify ACME actually works (domain resolves, port 80 reachable, etc.) BEFORE the user commits the setting. On success the certificate is cached, so the subsequent panel restart serves HTTPS without another challenge.

type EndpointService

type EndpointService struct {
	WarpService
}

func (*EndpointService) GetAll

func (o *EndpointService) GetAll() (*[]map[string]interface{}, error)

func (*EndpointService) GetAllConfig

func (o *EndpointService) GetAllConfig(db *gorm.DB) ([]json.RawMessage, error)

func (*EndpointService) Save

func (s *EndpointService) Save(tx *gorm.DB, act string, data json.RawMessage) error

type InboundService

type InboundService struct {
	ClientService
}

func (*InboundService) FromIds

func (s *InboundService) FromIds(ids []uint) ([]*model.Inbound, error)

func (*InboundService) Get

func (s *InboundService) Get(ids string) (*[]map[string]interface{}, error)

func (*InboundService) GetAll

func (s *InboundService) GetAll() (*[]map[string]interface{}, error)

func (*InboundService) GetAllConfig

func (s *InboundService) GetAllConfig(db *gorm.DB) ([]json.RawMessage, error)

func (*InboundService) RestartInbounds

func (s *InboundService) RestartInbounds(tx *gorm.DB, ids []uint) error

func (*InboundService) Save

func (s *InboundService) Save(tx *gorm.DB, act string, data json.RawMessage, initUserIds string, hostname string) error

func (*InboundService) UpdateOutJsons

func (s *InboundService) UpdateOutJsons(tx *gorm.DB, inboundIds []uint, hostname string) error

type IssueResult added in v1.4.7

type IssueResult struct {
	CertFile  string `json:"certFile"`
	KeyFile   string `json:"keyFile"`
	NginxMode bool   `json:"nginxMode"`
}

type NginxStatus added in v1.4.7

type NginxStatus struct {
	Installed bool `json:"installed"`
	Active    bool `json:"active"`
}

type OutboundService

type OutboundService struct{}

func (*OutboundService) GetAll

func (o *OutboundService) GetAll() (*[]map[string]interface{}, error)

func (*OutboundService) GetAllConfig

func (o *OutboundService) GetAllConfig(db *gorm.DB) ([]json.RawMessage, error)

func (*OutboundService) Save

func (s *OutboundService) Save(tx *gorm.DB, act string, data json.RawMessage) error

type PanelService

type PanelService struct {
}

func (*PanelService) RestartPanel

func (s *PanelService) RestartPanel(delay time.Duration) error

type ServerService

type ServerService struct{}

func (*ServerService) GenKeypair

func (s *ServerService) GenKeypair(keyType string, options string) []string

func (*ServerService) GetCpuPercent

func (s *ServerService) GetCpuPercent() float64

func (*ServerService) GetDatabaseInfo

func (s *ServerService) GetDatabaseInfo() map[string]int64

func (*ServerService) GetDiskIO

func (s *ServerService) GetDiskIO() map[string]interface{}

func (*ServerService) GetDiskInfo

func (s *ServerService) GetDiskInfo() map[string]interface{}

func (*ServerService) GetLogs

func (s *ServerService) GetLogs(count string, level string) []string

func (*ServerService) GetMemInfo

func (s *ServerService) GetMemInfo() map[string]interface{}

func (*ServerService) GetNetInfo

func (s *ServerService) GetNetInfo() map[string]interface{}

func (*ServerService) GetSingboxInfo

func (s *ServerService) GetSingboxInfo() map[string]interface{}

func (*ServerService) GetStatus

func (s *ServerService) GetStatus(request string) *map[string]interface{}

func (*ServerService) GetSwapInfo

func (s *ServerService) GetSwapInfo() map[string]interface{}

func (*ServerService) GetSystemInfo

func (s *ServerService) GetSystemInfo() map[string]interface{}

type ServicesService

type ServicesService struct{}

func (*ServicesService) GetAll

func (s *ServicesService) GetAll() (*[]map[string]interface{}, error)

func (*ServicesService) GetAllConfig

func (s *ServicesService) GetAllConfig(db *gorm.DB) ([]json.RawMessage, error)

func (*ServicesService) RestartServices

func (s *ServicesService) RestartServices(tx *gorm.DB, ids []uint) error

func (*ServicesService) Save

func (s *ServicesService) Save(tx *gorm.DB, act string, data json.RawMessage) error

type SettingService

type SettingService struct {
}

func (*SettingService) GetAllSetting

func (s *SettingService) GetAllSetting() (*map[string]string, error)

func (*SettingService) GetCertFile

func (s *SettingService) GetCertFile() (string, error)

func (*SettingService) GetConfig

func (s *SettingService) GetConfig() (string, error)

func (*SettingService) GetFinalSubURI

func (s *SettingService) GetFinalSubURI(host string) (string, error)

func (*SettingService) GetGlobalReset added in v1.5.4

func (s *SettingService) GetGlobalReset() (string, error)

GetGlobalReset returns the configured period for resetting all clients' traffic: "off", "weekly", "monthly" or "yearly".

func (*SettingService) GetGlobalResetLast added in v1.5.4

func (s *SettingService) GetGlobalResetLast() (int64, error)

GetGlobalResetLast returns the unix time of the last global traffic reset.

func (*SettingService) GetKeyFile

func (s *SettingService) GetKeyFile() (string, error)

func (*SettingService) GetListen

func (s *SettingService) GetListen() (string, error)

func (*SettingService) GetPort

func (s *SettingService) GetPort() (int, error)

func (*SettingService) GetSecret

func (s *SettingService) GetSecret() ([]byte, error)

func (*SettingService) GetSessionMaxAge

func (s *SettingService) GetSessionMaxAge() (int, error)

func (*SettingService) GetStatsBucketSeconds added in v1.5.4

func (s *SettingService) GetStatsBucketSeconds() (int64, error)

GetStatsBucketSeconds returns the bucket size (in seconds) that traffic samples are rounded down to before being stored. Larger buckets mean fewer rows at the cost of chart resolution. Falls back to the default on a missing or non-positive value.

func (*SettingService) GetSubAcmeEmail

func (s *SettingService) GetSubAcmeEmail() (string, error)

func (*SettingService) GetSubCertFile

func (s *SettingService) GetSubCertFile() (string, error)

func (*SettingService) GetSubCertMode

func (s *SettingService) GetSubCertMode() (string, error)

func (*SettingService) GetSubClashExt

func (s *SettingService) GetSubClashExt() (string, error)

func (*SettingService) GetSubClashNoDefGrp added in v1.5.5

func (s *SettingService) GetSubClashNoDefGrp() (bool, error)

GetSubClashNoDefGrp reports whether the default "Proxy"/"Auto" proxy-groups should never be injected into a Clash subscription. When true, the config is left with exactly the groups the user defined.

func (*SettingService) GetSubClashSprtAll added in v1.5.5

func (s *SettingService) GetSubClashSprtAll() (bool, error)

GetSubClashSprtAll reports whether a case-insensitive "all" entry inside a custom proxy-group's "proxies" list should be expanded into every generated proxy tag.

func (*SettingService) GetSubDomain

func (s *SettingService) GetSubDomain() (string, error)

func (*SettingService) GetSubEncode

func (s *SettingService) GetSubEncode() (bool, error)

func (*SettingService) GetSubJsonExt

func (s *SettingService) GetSubJsonExt() (string, error)

func (*SettingService) GetSubKeyFile

func (s *SettingService) GetSubKeyFile() (string, error)

func (*SettingService) GetSubListen

func (s *SettingService) GetSubListen() (string, error)

func (*SettingService) GetSubPath

func (s *SettingService) GetSubPath() (string, error)

func (*SettingService) GetSubPort

func (s *SettingService) GetSubPort() (int, error)

func (*SettingService) GetSubShowInfo

func (s *SettingService) GetSubShowInfo() (bool, error)

func (*SettingService) GetSubURI

func (s *SettingService) GetSubURI() (string, error)

func (*SettingService) GetSubUpdates

func (s *SettingService) GetSubUpdates() (int, error)

func (*SettingService) GetTimeLocation

func (s *SettingService) GetTimeLocation() (*time.Location, error)

func (*SettingService) GetTrafficAge

func (s *SettingService) GetTrafficAge() (int, error)

func (*SettingService) GetWebAcmeEmail

func (s *SettingService) GetWebAcmeEmail() (string, error)

func (*SettingService) GetWebCertMode

func (s *SettingService) GetWebCertMode() (string, error)

func (*SettingService) GetWebDomain

func (s *SettingService) GetWebDomain() (string, error)

func (*SettingService) GetWebNginx added in v1.4.7

func (s *SettingService) GetWebNginx() (bool, error)

func (*SettingService) GetWebPath

func (s *SettingService) GetWebPath() (string, error)

func (*SettingService) ResetSettings

func (s *SettingService) ResetSettings() error

func (*SettingService) Save

func (s *SettingService) Save(tx *gorm.DB, data json.RawMessage) error

func (*SettingService) SaveConfig

func (s *SettingService) SaveConfig(tx *gorm.DB, config json.RawMessage) error

func (*SettingService) SetConfig

func (s *SettingService) SetConfig(config string) error

func (*SettingService) SetGlobalResetLast added in v1.5.4

func (s *SettingService) SetGlobalResetLast(value int64) error

func (*SettingService) SetPort

func (s *SettingService) SetPort(port int) error

func (*SettingService) SetSubPath

func (s *SettingService) SetSubPath(subPath string) error

func (*SettingService) SetSubPort

func (s *SettingService) SetSubPort(subPort int) error

func (*SettingService) SetWebPath

func (s *SettingService) SetWebPath(webPath string) error

type SingBoxConfig

type SingBoxConfig struct {
	Log          json.RawMessage   `json:"log"`
	Dns          json.RawMessage   `json:"dns"`
	Ntp          json.RawMessage   `json:"ntp"`
	Inbounds     []json.RawMessage `json:"inbounds"`
	Outbounds    []json.RawMessage `json:"outbounds"`
	Services     []json.RawMessage `json:"services"`
	Endpoints    []json.RawMessage `json:"endpoints"`
	Route        json.RawMessage   `json:"route"`
	Experimental json.RawMessage   `json:"experimental"`
}

type StatsService

type StatsService struct {
}

func (*StatsService) DelOldStats

func (s *StatsService) DelOldStats(days int) error

func (*StatsService) GetOnlines

func (s *StatsService) GetOnlines() (onlines, error)

func (*StatsService) GetStats

func (s *StatsService) GetStats(resource string, tag string, period string) ([]model.Stats, error)

func (*StatsService) SaveStats

func (s *StatsService) SaveStats(enableTraffic bool, bucketSeconds int64) error

type TlsService

type TlsService struct {
	InboundService
	ServicesService
}

func (*TlsService) GetAll

func (s *TlsService) GetAll() ([]model.Tls, error)

func (*TlsService) Save

func (s *TlsService) Save(tx *gorm.DB, action string, data json.RawMessage, hostname string) error

type UpdatePhase added in v1.5.6

type UpdatePhase string
const (
	UpdateIdle        UpdatePhase = "idle"
	UpdateChecking    UpdatePhase = "checking"
	UpdateDownloading UpdatePhase = "downloading"
	UpdateVerifying   UpdatePhase = "verifying"
	UpdateExtracting  UpdatePhase = "extracting"
	UpdateSwapping    UpdatePhase = "swapping"
	UpdateRestarting  UpdatePhase = "restarting"
	UpdateDone        UpdatePhase = "done"
	UpdateFailed      UpdatePhase = "failed"
)

type UpdateService added in v1.5.6

type UpdateService struct{}

func (*UpdateService) CanSelfUpdate added in v1.5.6

func (s *UpdateService) CanSelfUpdate() (bool, string)

CanSelfUpdate reports whether an in-panel update can run here, and if not, a short human-readable reason for the UI.

func (*UpdateService) GetStatus added in v1.5.6

func (s *UpdateService) GetStatus() UpdateStatus

func (*UpdateService) InDocker added in v1.5.6

func (s *UpdateService) InDocker() bool

InDocker is exposed so the API layer can tell the UI to warn that a container-layer update reverts when the container is recreated.

func (*UpdateService) LatestRelease added in v1.5.6

func (s *UpdateService) LatestRelease() (string, error)

LatestRelease returns the tag name of the newest GitHub release.

func (*UpdateService) StartUpdate added in v1.5.6

func (s *UpdateService) StartUpdate() error

StartUpdate validates the environment, then kicks off the update in the background. It returns immediately; callers poll GetStatus.

type UpdateStatus added in v1.5.6

type UpdateStatus struct {
	Phase   UpdatePhase `json:"phase"`
	Target  string      `json:"target"`
	Message string      `json:"message"`
	Error   string      `json:"error"`
}

type UserService

type UserService struct {
}

func (*UserService) AddToken

func (s *UserService) AddToken(username string, expiry int64, desc string) (string, error)

func (*UserService) ChangePass

func (s *UserService) ChangePass(id string, oldPass string, newUser string, newPass string) error

func (*UserService) CheckUser

func (s *UserService) CheckUser(username string, password string, remoteIP string) *model.User

func (*UserService) DeleteToken

func (s *UserService) DeleteToken(id string) error

func (*UserService) GetFirstUser

func (s *UserService) GetFirstUser() (*model.User, error)

func (*UserService) GetUserTokens

func (s *UserService) GetUserTokens(username string) (*[]model.Tokens, error)

func (*UserService) GetUsers

func (s *UserService) GetUsers() (*[]model.User, error)

func (*UserService) LoadTokens

func (s *UserService) LoadTokens() ([]byte, error)

func (*UserService) Login

func (s *UserService) Login(username string, password string, remoteIP string) (string, error)

func (*UserService) UpdateFirstUser

func (s *UserService) UpdateFirstUser(username string, password string) error

type WarpService

type WarpService struct{}

func (*WarpService) RegisterWarp

func (s *WarpService) RegisterWarp(ep *model.Endpoint) error

func (*WarpService) SetWarpLicense

func (s *WarpService) SetWarpLicense(old_license string, ep *model.Endpoint) error

Jump to

Keyboard shortcuts

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