Documentation
¶
Index ¶
- Variables
- func ManagedCertDir(domain string) string
- type AcmeService
- func (a *AcmeService) DetectNginx() NginxStatus
- func (a *AcmeService) EnsureVhost(opt VhostOptions) (*VhostResult, error)
- func (a *AcmeService) IssueWeb(domain, email, method string, force, behindProxy bool) (*IssueResult, error)
- func (a *AcmeService) ListCerts() ([]CertInfo, error)
- func (a *AcmeService) RemoveCert(domain string) error
- func (a *AcmeService) SyncVhosts(specs []VhostOptions) ([]*VhostResult, error)
- type CertInfo
- type CertService
- func (c *CertService) ArchiveLegacy()
- func (c *CertService) DeleteManual(domain string) error
- func (c *CertService) FindByDomain(domain string) (CertInfo, bool, error)
- func (c *CertService) HasManual(domain string) bool
- func (c *CertService) List() ([]CertInfo, error)
- func (c *CertService) SaveManual(domain, certFile, keyFile string) error
- type ClientService
- func (s *ClientService) DepleteClients() ([]uint, []string, error)
- func (s *ClientService) Get(id string) (*[]model.Client, error)
- func (s *ClientService) GetAll() (*[]model.Client, error)
- func (s *ClientService) ResetAllClientsTraffic() error
- func (s *ClientService) ResetClients(tx *gorm.DB, dt int64) ([]uint, error)
- func (s *ClientService) Save(tx *gorm.DB, act string, data json.RawMessage, hostname string) ([]uint, error)
- func (s *ClientService) UpdateClientsOnInboundAdd(tx *gorm.DB, initIds string, inboundId uint, hostname string) error
- func (s *ClientService) UpdateClientsOnInboundDelete(tx *gorm.DB, id uint, tag string) error
- func (s *ClientService) UpdateLinksByInboundChange(tx *gorm.DB, inbounds *[]model.Inbound, hostname string, oldTag string) error
- type ConfigService
- func (s *ConfigService) CheckChanges(lu string) (bool, error)
- func (s *ConfigService) CheckOutbound(tag string, link string) core.CheckOutboundResult
- func (s *ConfigService) GetChanges(actor string, chngKey string, count string) []model.Changes
- func (s *ConfigService) GetConfig(data string) (*[]byte, error)
- func (s *ConfigService) RestartCore() error
- func (s *ConfigService) Save(obj string, act string, data json.RawMessage, initUsers string, ...) ([]string, error)
- func (s *ConfigService) StartCore() error
- func (s *ConfigService) StopCore() error
- func (s *ConfigService) TestAcme(domain, email string) error
- type EndpointService
- type InboundService
- func (s *InboundService) FromIds(ids []uint) ([]*model.Inbound, error)
- func (s *InboundService) Get(ids string) (*[]map[string]interface{}, error)
- func (s *InboundService) GetAll() (*[]map[string]interface{}, error)
- func (s *InboundService) GetAllConfig(db *gorm.DB) ([]json.RawMessage, error)
- func (s *InboundService) RestartInbounds(tx *gorm.DB, ids []uint) error
- func (s *InboundService) Save(tx *gorm.DB, act string, data json.RawMessage, initUserIds string, ...) error
- func (s *InboundService) UpdateInboundsUsers(tx *gorm.DB, ids []uint) error
- func (s *InboundService) UpdateOutJsons(tx *gorm.DB, inboundIds []uint, hostname string) error
- type IssueResult
- type NginxStatus
- type NodeMem
- type NodeService
- func (s *NodeService) GetAll() ([]map[string]interface{}, error)
- func (s *NodeService) GetStatuses() map[uint]NodeStatus
- func (s *NodeService) RefreshAll()
- func (s *NodeService) Save(tx *gorm.DB, act string, data json.RawMessage) error
- func (s *NodeService) TestNode(data json.RawMessage) (NodeStatus, error)
- type NodeStatus
- type NodeSyncService
- func (s *NodeSyncService) AdoptInbounds(nodeId uint, tags []string, actor string) error
- func (s *NodeSyncService) CollectTraffic()
- func (s *NodeSyncService) FetchNodeInbounds(nodeId uint) ([]remoteInbound, error)
- func (s *NodeSyncService) MarkAllDirty()
- func (s *NodeSyncService) Reconcile(nodeId uint) error
- func (s *NodeSyncService) ReconcileAllOnline()
- func (s *NodeSyncService) ReconcileDirtyOnline()
- func (s *NodeSyncService) ReconcileNow(nodeId uint) error
- type OutboundService
- type PanelService
- type ProxyEndpoint
- type ServerService
- func (s *ServerService) GenKeypair(keyType string, options string) []string
- func (s *ServerService) GetCpuPercent() float64
- func (s *ServerService) GetDatabaseInfo() map[string]int64
- func (s *ServerService) GetDiskIO() map[string]interface{}
- func (s *ServerService) GetDiskInfo() map[string]interface{}
- func (s *ServerService) GetLogs(count string, level string) []string
- func (s *ServerService) GetMemInfo() map[string]interface{}
- func (s *ServerService) GetNetInfo() map[string]interface{}
- func (s *ServerService) GetSingboxInfo() map[string]interface{}
- func (s *ServerService) GetStatus(request string) *map[string]interface{}
- func (s *ServerService) GetSwapInfo() map[string]interface{}
- func (s *ServerService) GetSystemInfo() map[string]interface{}
- type ServicesService
- func (s *ServicesService) GetAll() (*[]map[string]interface{}, error)
- func (s *ServicesService) GetAllConfig(db *gorm.DB) ([]json.RawMessage, error)
- func (s *ServicesService) RestartServices(tx *gorm.DB, ids []uint) error
- func (s *ServicesService) Save(tx *gorm.DB, act string, data json.RawMessage) error
- type SettingService
- func (s *SettingService) GetAllSetting() (*map[string]string, error)
- func (s *SettingService) GetCertFile() (string, error)
- func (s *SettingService) GetConfig() (string, error)
- func (s *SettingService) GetFinalSubURI(host string) (string, error)
- func (s *SettingService) GetGlobalReset() (string, error)
- func (s *SettingService) GetGlobalResetLast() (int64, error)
- func (s *SettingService) GetKeyFile() (string, error)
- func (s *SettingService) GetListen() (string, error)
- func (s *SettingService) GetPort() (int, error)
- func (s *SettingService) GetSecret() ([]byte, error)
- func (s *SettingService) GetSessionMaxAge() (int, error)
- func (s *SettingService) GetStatsBucketSeconds() (int64, error)
- func (s *SettingService) GetSubAcmeEmail() (string, error)
- func (s *SettingService) GetSubCertFile() (string, error)
- func (s *SettingService) GetSubCertMode() (string, error)
- func (s *SettingService) GetSubClashExt() (string, error)
- func (s *SettingService) GetSubClashNoDefGrp() (bool, error)
- func (s *SettingService) GetSubClashSprtAll() (bool, error)
- func (s *SettingService) GetSubDomain() (string, error)
- func (s *SettingService) GetSubEncode() (bool, error)
- func (s *SettingService) GetSubJsonExt() (string, error)
- func (s *SettingService) GetSubKeyFile() (string, error)
- func (s *SettingService) GetSubListen() (string, error)
- func (s *SettingService) GetSubNginx() (bool, error)
- func (s *SettingService) GetSubPath() (string, error)
- func (s *SettingService) GetSubPort() (int, error)
- func (s *SettingService) GetSubShowInfo() (bool, error)
- func (s *SettingService) GetSubURI() (string, error)
- func (s *SettingService) GetSubUpdates() (int, error)
- func (s *SettingService) GetTimeLocation() (*time.Location, error)
- func (s *SettingService) GetTrafficAge() (int, error)
- func (s *SettingService) GetWebAcmeEmail() (string, error)
- func (s *SettingService) GetWebCertMode() (string, error)
- func (s *SettingService) GetWebDomain() (string, error)
- func (s *SettingService) GetWebNginx() (bool, error)
- func (s *SettingService) GetWebPath() (string, error)
- func (s *SettingService) GetWebURI() (string, error)
- func (s *SettingService) ResetSettings() error
- func (s *SettingService) Save(tx *gorm.DB, data json.RawMessage) error
- func (s *SettingService) SaveConfig(tx *gorm.DB, config json.RawMessage) error
- func (s *SettingService) SetConfig(config string) error
- func (s *SettingService) SetGlobalResetLast(value int64) error
- func (s *SettingService) SetPort(port int) error
- func (s *SettingService) SetSubPath(subPath string) error
- func (s *SettingService) SetSubPort(subPort int) error
- func (s *SettingService) SetWebPath(webPath string) error
- type SingBoxConfig
- type StatsService
- type TlsService
- type UpdatePhase
- type UpdateService
- type UpdateStatus
- type UserService
- func (s *UserService) AddToken(username string, expiry int64, desc string) (string, error)
- func (s *UserService) ChangePass(id string, oldPass string, newUser string, newPass string) error
- func (s *UserService) CheckUser(username string, password string, remoteIP string) *model.User
- func (s *UserService) DeleteToken(id string) error
- func (s *UserService) GetFirstUser() (*model.User, error)
- func (s *UserService) GetUserTokens(username string) (*[]model.Tokens, error)
- func (s *UserService) GetUsers() (*[]model.User, error)
- func (s *UserService) LoadTokens() ([]byte, error)
- func (s *UserService) Login(username string, password string, remoteIP string) (string, error)
- func (s *UserService) UpdateFirstUser(username string, password string) error
- type VhostOptions
- type VhostResult
- type WarpService
Constants ¶
This section is empty.
Variables ¶
var (
LastUpdate int64
)
Functions ¶
func ManagedCertDir ¶ added in v1.6.1
ManagedCertDir 返回面板为该域名安装证书的目录。RemoveCert 会把它整个删掉, 所以「设置里的证书路径落在这个目录下」也算正在使用(删除守卫要靠它兜住 域名与路径分岔的情形)。
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 是否安装并运行,以及 80 端口是否被占用。Windows 直接返回零值。
func (*AcmeService) EnsureVhost ¶ added in v1.6.1
func (a *AcmeService) EnsureVhost(opt VhostOptions) (*VhostResult, error)
EnsureVhost 为一个域名生成 nginx 反向代理配置并确认它真的生效。
全过程「验证通过才算成功」:nginx -t 不过、和用户已有配置撞 server_name、reload 失败、 或者块压根没进入生效配置,都会删掉文件、把 nginx 恢复原状,再带着 nginx 自己的输出报错。 调用方必须在这里成功之后才把面板/订阅切成明文 HTTP —— 顺序反了就会出现 「服务不再终结 TLS,前面又没人接管」的窗口,而关掉开关的入口正在那个打不开的页面里。
func (*AcmeService) IssueWeb ¶ added in v1.4.7
func (a *AcmeService) IssueWeb(domain, email, method string, force, behindProxy bool) (*IssueResult, error)
IssueWeb 为面板/订阅申请证书并安装到 /root/cert/{域名}/。
- method :standalone / nginx / auto(空视同 auto),解析与可行性校验见 resolveMethod。
- force :域名已有未到期证书时 acme.sh 默认跳过签发,force 时加 --force 强制续期。
- behindProxy:webNginx=true,即反向代理终结 TLS、nginx 是证书消费方(决定 reloadcmd)。
func (*AcmeService) ListCerts ¶ added in v1.4.7
func (a *AcmeService) ListCerts() ([]CertInfo, error)
ListCerts 列出 acme.sh 维护的证书。直接读它的家目录,不调 `acme.sh --list`。 找不到 acme.sh 时返回空列表而不是错误:那只是还没申请过证书,页面该显示空态。
func (*AcmeService) RemoveCert ¶ added in v1.6.1
func (a *AcmeService) RemoveCert(domain string) error
RemoveCert 删除一张证书:先让 acme.sh 忘掉它(不再续期),再删掉安装出去的文件副本。
调用方必须先确认没有服务在用这个域名——面板/订阅正用着的证书被删掉,下次重启就起不来。 那个检查放在调用方(它才读得到设置),这里只管删。 入站 TLS 是否手填了这两个路径不做检查:那要遍历所有 TLS 配置解析 JSON、还要处理软链接 和相对路径,代价和收益不成正比,由前端在确认框里提示。
func (*AcmeService) SyncVhosts ¶ added in v1.6.1
func (a *AcmeService) SyncVhosts(specs []VhostOptions) ([]*VhostResult, error)
SyncVhosts 让 nginx 里「我们生成的那些反代配置」与传入的期望状态一致: specs 里的每个域名各生成一份,而以前生成过、现在不在 specs 里的一律删掉。
删除这一步是必须的,漏了会留下两种坏状态:关掉反代后 443 还在把明文请求转给一个 已经改回 TLS 的端口(502),换域名后旧域名的块还赖在 nginx 里。 清理只扫 s-ui-proxy-* 前缀,碰不到 ACME 验证块,更碰不到用户自己写的配置。
type CertInfo ¶ added in v1.6.1
type CertInfo struct {
Domain string `json:"domain"`
CertFile string `json:"certFile"` // 摆出来供复制:建入站 TLS 时要填进 certificate_path
KeyFile string `json:"keyFile"`
CA string `json:"ca"`
KeyType string `json:"keyType"`
NotAfter int64 `json:"notAfter"` // 0 表示证书文件读不到
NextRenew int64 `json:"nextRenew"` // 0 表示不适用(手动登记的证书)
Managed bool `json:"managed"` // true = acme.sh 维护并自动续期
}
CertInfo 是「域名与证书」页面上的一条记录。 时间统一用 unix 秒回给前端,由前端按浏览器时区渲染并算剩余天数——服务器时区不一定 是用户的,后端算好天数反而会差一天。
type CertService ¶ added in v1.6.1
type CertService struct {
// contains filtered or unexported fields
}
CertService 管手动登记的证书,并把它们与 acme.sh 托管的那些合并成「域名与证书」 页面上的那一份清单。
分工:acme.sh 那半边的事实来源是它自己的家目录(AcmeService 扫盘直接读),只有 手动登记的这半边才落库。同一个域名两边都有时以 acme.sh 为准——它在自动续期, 手动记录多半是升级时归档进来的旧路径。
域名一律以小写存储和比对:DNS 不区分大小写,而 uniqueIndex、合并去重、前端匹配 全是精确比对,混着存会让同一个域名分裂成两条互相矛盾的记录。
字段用具名的 settings 而不是嵌入 SettingService:ApiService 已经嵌入了后者, 这里再嵌入会让 CertService 的方法提升到 ApiService 上产生二义性(AcmeService 那个注释说的也是这件事)。
func (*CertService) ArchiveLegacy ¶ added in v1.6.1
func (c *CertService) ArchiveLegacy()
ArchiveLegacy 把升级前手填在设置里的证书路径归档成手动登记记录。
面板启动时调用,幂等:只在「域名非空 + 两个路径都非空且可读 + 该域名还没有任何 证书」时补一条。设置里的 webCertFile/webKeyFile 不动,面板照旧读它启动——这一步 只是让那份证书在新页面上看得见、可管理,不改变任何现有行为。
不放在 cmd/migration 里:那套迁移只在 `sui migrate` 和导入备份时跑,正常启动 根本不经过,挂在那儿等于对绝大多数升级用户没生效。
成本控制:正常启动在 HasManual(索引 COUNT)就短路了;acme.sh 家目录的全量扫描 只在两侧至少有一侧真要归档时才做,而且只做一次。
func (*CertService) DeleteManual ¶ added in v1.6.1
func (c *CertService) DeleteManual(domain string) error
DeleteManual 删掉一条登记记录。只忘掉路径,不碰证书文件本身——那是用户自己的 文件,多半还被别的服务用着。对不存在的域名是 no-op。
func (*CertService) FindByDomain ¶ added in v1.6.1
func (c *CertService) FindByDomain(domain string) (CertInfo, bool, error)
FindByDomain 查某个域名当前可用的证书。
错误必须上抛而不是吞成「没找到」:调用方拿 found/Managed 决定走哪条分支,把一次 数据库故障当成「不存在」会让删除走错路(acme.sh 托管的被当成手动记录,DeleteManual 删了个寂寞还报成功)。
func (*CertService) HasManual ¶ added in v1.6.1
func (c *CertService) HasManual(domain string) bool
HasManual 判断某个域名有没有手动登记记录。唯一索引上的一次 COUNT,零磁盘 I/O, 给 ArchiveLegacy 当每次启动的快速出口。
func (*CertService) List ¶ added in v1.6.1
func (c *CertService) List() ([]CertInfo, error)
List 返回合并后的证书清单,按域名排序。
func (*CertService) SaveManual ¶ added in v1.6.1
func (c *CertService) SaveManual(domain, certFile, keyFile string) error
SaveManual 登记(或改写)一份自带的证书。
type ClientService ¶
type ClientService struct{}
func (*ClientService) DepleteClients ¶
func (s *ClientService) DepleteClients() ([]uint, []string, error)
DepleteClients disables clients over quota or past expiry and returns both the affected local inbound ids (to hot-restart) and the disabled client names (so the caller can fan the disable out to nodes). With cluster totals folded into up/down, the quota check is already a whole-cluster judgement.
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 (*ClientService) Save ¶
func (s *ClientService) Save(tx *gorm.DB, act string, data json.RawMessage, hostname string) ([]uint, error)
func (*ClientService) UpdateClientsOnInboundAdd ¶
func (*ClientService) UpdateClientsOnInboundDelete ¶
func (*ClientService) UpdateLinksByInboundChange ¶
type ConfigService ¶
type ConfigService struct {
ClientService
TlsService
SettingService
InboundService
OutboundService
ServicesService
EndpointService
NodeService
}
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 (*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) UpdateInboundsUsers ¶ added in v1.6.0
func (s *InboundService) UpdateInboundsUsers(tx *gorm.DB, ids []uint) error
func (*InboundService) UpdateOutJsons ¶
type IssueResult ¶ added in v1.4.7
type NginxStatus ¶ added in v1.4.7
type NodeService ¶ added in v1.6.0
type NodeService struct {
}
func (*NodeService) GetAll ¶ added in v1.6.0
func (s *NodeService) GetAll() ([]map[string]interface{}, error)
GetAll returns nodes in panel shape. The token never leaves the server — only a tokenSet flag does.
func (*NodeService) GetStatuses ¶ added in v1.6.0
func (s *NodeService) GetStatuses() map[uint]NodeStatus
GetStatuses returns a copy of the live snapshot for API responses.
func (*NodeService) RefreshAll ¶ added in v1.6.0
func (s *NodeService) RefreshAll()
RefreshAll probes every enabled node with bounded parallelism and atomically swaps in a freshly built snapshot. Called by the @every 5s cron job.
func (*NodeService) Save ¶ added in v1.6.0
func (s *NodeService) Save(tx *gorm.DB, act string, data json.RawMessage) error
func (*NodeService) TestNode ¶ added in v1.6.0
func (s *NodeService) TestNode(data json.RawMessage) (NodeStatus, error)
TestNode probes the node described by the (possibly unsaved) form data with a one-off client, so Test Connection reflects the form, not the DB row. An empty token on an existing node falls back to the stored one.
type NodeStatus ¶ added in v1.6.0
type NodeStatus struct {
State string `json:"state"` // online | offline | core-stopped
Latency int64 `json:"latency"`
Cpu float64 `json:"cpu"`
Mem NodeMem `json:"mem"`
AppVersion string `json:"appVersion"`
CoreVersion string `json:"coreVersion"`
Error string `json:"error,omitempty"`
CheckedAt int64 `json:"checkedAt"`
LastOnline int64 `json:"lastOnline"`
}
type NodeSyncService ¶ added in v1.6.0
type NodeSyncService struct {
NodeService
}
NodeSyncService owns everything that writes TO a node: adopting its inbounds as read-only replicas, and pushing/reconciling the master's clients onto it. Reconcile is the single write channel — first push, offline catch-up, drift repair and the manual button all funnel through it.
func (*NodeSyncService) AdoptInbounds ¶ added in v1.6.0
func (s *NodeSyncService) AdoptInbounds(nodeId uint, tags []string, actor string) error
AdoptInbounds pulls the full panel-shape inbound for each selected tag and stores it as a local replica row (node_id set). tag collisions fail loudly — the tag is the reconciliation key, so we never silently rename.
func (*NodeSyncService) CollectTraffic ¶ added in v1.6.0
func (s *NodeSyncService) CollectTraffic()
CollectTraffic pulls each online node's @cluster client counters and folds the delta since the last collection into the master's per-client totals. The node's clients.up/down are cumulative; a per-(node,client) baseline turns them into deltas, resetting the baseline when the node's counter drops (reset).
func (*NodeSyncService) FetchNodeInbounds ¶ added in v1.6.0
func (s *NodeSyncService) FetchNodeInbounds(nodeId uint) ([]remoteInbound, error)
FetchNodeInbounds lists a node's inbounds, flagging which tags this panel has already adopted as replicas.
func (*NodeSyncService) MarkAllDirty ¶ added in v1.6.0
func (s *NodeSyncService) MarkAllDirty()
func (*NodeSyncService) Reconcile ¶ added in v1.6.0
func (s *NodeSyncService) Reconcile(nodeId uint) error
Reconcile makes a node's @cluster clients match the master's expectation: clients that reference any of this node's replica inbounds. Together with ReconcileNow it is the ONLY path that writes clients to a node.
This is the background entry: single-flight per node plus a 30s backoff so heartbeat/fanout triggers don't stampede. A skip returns nil — the dirty flag stays set and the next heartbeat retries.
func (*NodeSyncService) ReconcileAllOnline ¶ added in v1.6.0
func (s *NodeSyncService) ReconcileAllOnline()
ReconcileAllOnline reconciles all online nodes regardless of dirty flag — the hourly safety net that repairs silent node-side drift.
func (*NodeSyncService) ReconcileDirtyOnline ¶ added in v1.6.0
func (s *NodeSyncService) ReconcileDirtyOnline()
ReconcileDirtyOnline reconciles every enabled node that is online and dirty. Called by the heartbeat so offline-period edits converge once a node returns.
func (*NodeSyncService) ReconcileNow ¶ added in v1.6.0
func (s *NodeSyncService) ReconcileNow(nodeId uint) error
ReconcileNow is the interactive entry (manual sync button, post-adoption push): it skips the backoff — the user asked, so sync — and reports a busy overlap as an error instead of silently doing nothing, so the UI never toasts success for a no-op.
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
RestartPanel 在 delay 之后给自己发 SIGHUP(Windows 上 Kill)触发重启。 delay 是 time.Duration,别传裸数字——那是纳秒,等于立即重启,调用方的 HTTP 响应 会来不及刷出就随 gin server 一起被拆掉。它存在的意义就是留出这段刷响应的时间。
type ProxyEndpoint ¶ added in v1.6.1
type ProxyEndpoint struct {
Name string // 只用于配置里的注释和日志:panel / sub
Path string // 形如 /app/
Listen string // 上游监听地址,空表示 0.0.0.0
Port int
}
ProxyEndpoint 是一个域名下的一条反代规则:把 Path 交给本机的某个端口。 面板和订阅各算一条;两者共用域名时会落进同一个 server 块的两个 location—— 各生成一份 server 块会被 nginx 判 conflicting server name 而忽略掉后一个。
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) GetSubNginx ¶ added in v1.6.1
func (s *SettingService) GetSubNginx() (bool, error)
GetSubNginx 是订阅侧的「由反向代理终结 TLS」,语义与 webNginx 对称: 开着时订阅服务只跑明文 HTTP,TLS 交给前面的 nginx。 空字符串表示尚未设置,按 false 处理(避免 ParseBool("") 报错)。
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) GetWebURI ¶ added in v1.6.0
func (s *SettingService) GetWebURI() (string, error)
GetWebURI 返回面板对外地址的手工覆盖值(空表示未设置,由调用方自行推断)。 反代场景下面板推断不出对外地址,只能靠它,参见 sui uri 与前端 restartApp。
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)
type TlsService ¶
type TlsService struct {
InboundService
ServicesService
}
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) ChangePass ¶
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) LoadTokens ¶
func (s *UserService) LoadTokens() ([]byte, error)
func (*UserService) UpdateFirstUser ¶
func (s *UserService) UpdateFirstUser(username string, password string) error
type VhostOptions ¶ added in v1.6.1
type VhostOptions struct {
Domain string
CertFile string // 设置里手填的证书,仅当 /root/cert/<域名>/ 下那份不存在时才用
KeyFile string
Endpoints []ProxyEndpoint
}
VhostOptions 描述一个域名要生成的整份配置。
type VhostResult ¶ added in v1.6.1
type VhostResult struct {
Domain string `json:"domain"`
ConfFile string `json:"confFile"`
CertFile string `json:"certFile"`
URLs []string `json:"urls"`
}
VhostResult 回给前端展示:生成了哪个文件、每个端点的对外地址是什么。
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