service

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: GPL-3.0 Imports: 50 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxTokenExpiryDays       int64 = 3650
	MaxTokenDescriptionRunes       = 128
)

Variables

View Source
var (
	LastUpdate atomic.Int64
)

Functions

func AttachConnectionSourceFromCandidates

func AttachConnectionSourceFromCandidates(item *ConnectionEntry, candidates []ConnectionEntry)

func AttachConnectionSources

func AttachConnectionSources(items []ConnectionEntry)

func EnrichConnectionEntriesOwners added in v1.0.13

func EnrichConnectionEntriesOwners(entries []*ConnectionEntry, limit int)

EnrichConnectionEntriesOwners resolves and describes only the requested page. Lookups are deduplicated and share one deadline so log APIs remain responsive.

func EnrichConnectionEntryOwners

func EnrichConnectionEntryOwners(entry *ConnectionEntry)

func EnrichConnectionEntryOwnersWithBudget

func EnrichConnectionEntryOwnersWithBudget(entry *ConnectionEntry, budget *ConnectionOwnerLookupBudget)

func GenerateWireGuardPresharedKey

func GenerateWireGuardPresharedKey() (string, error)

func ValidateTokenOptions added in v1.0.12

func ValidateTokenOptions(expiryDays int64, description string) error

Types

type AuthService

type AuthService struct {
	SettingService
	UserService
}

func (*AuthService) BeginOIDC

func (s *AuthService) BeginOIDC(ctx context.Context) (*OIDCStart, error)

func (*AuthService) BeginPasskeyLogin

func (s *AuthService) BeginPasskeyLogin(username string, request *http.Request) (interface{}, string, error)

func (*AuthService) BeginPasskeyRegistration

func (s *AuthService) BeginPasskeyRegistration(username string, request *http.Request) (interface{}, string, error)

func (*AuthService) DeletePasskey

func (s *AuthService) DeletePasskey(username, id string) error

func (*AuthService) FinishOIDC

func (s *AuthService) FinishOIDC(ctx context.Context, state, code string) (string, error)

func (*AuthService) FinishPasskeyLogin

func (s *AuthService) FinishPasskeyLogin(sessionID string, request *http.Request) (string, error)

func (*AuthService) FinishPasskeyRegistration

func (s *AuthService) FinishPasskeyRegistration(username, sessionID, requestedName string, request *http.Request) (string, error)

func (*AuthService) ListPasskeys

func (s *AuthService) ListPasskeys(username string) ([]model.PasskeyCredential, error)

func (*AuthService) PublicAuthMethods

func (s *AuthService) PublicAuthMethods() map[string]interface{}

func (*AuthService) RenamePasskey

func (s *AuthService) RenamePasskey(username, id, name string) error

func (*AuthService) SecuritySummary

func (s *AuthService) SecuritySummary(username string) (map[string]interface{}, error)

type ChangesFilter

type ChangesFilter struct {
	Actor  string
	Key    string
	Search string
	Start  int64
	End    int64
	Offset int
	Limit  int
}

type ChangesQueryResult

type ChangesQueryResult struct {
	Items  []model.Changes `json:"items"`
	Total  int64           `json:"total"`
	Offset int             `json:"offset"`
	Limit  int             `json:"limit"`
}

type ClientService

type ClientService struct{}

func (*ClientService) DepleteClients

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

func (*ClientService) EnsureClientSubIds

func (s *ClientService) EnsureClientSubIds(db *gorm.DB) 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) GetEnabledBySubscriptionKey added in v1.0.9

func (s *ClientService) GetEnabledBySubscriptionKey(db *gorm.DB, key string) (*model.Client, error)

func (*ClientService) ResetClients

func (s *ClientService) ResetClients(tx *gorm.DB, dt int64) ([]uint, bool, 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) QueryChanges

func (s *ConfigService) QueryChanges(filter ChangesFilter) (*ChangesQueryResult, 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) SaveWithApply

func (s *ConfigService) SaveWithApply(obj string, act string, data json.RawMessage, initUsers string, loginUser string, hostname string, apply bool) (objs []string, err error)

func (*ConfigService) StartCore

func (s *ConfigService) StartCore() error

func (*ConfigService) StopCore

func (s *ConfigService) StopCore() error

type ConnectionEntry

type ConnectionEntry struct {
	Timestamp       int64             `json:"timestamp"`
	Time            string            `json:"time"`
	Resource        string            `json:"resource"`
	Protocol        string            `json:"protocol"`
	Tag             string            `json:"tag"`
	User            string            `json:"user,omitempty"`
	Event           string            `json:"event"`
	Remote          string            `json:"remote,omitempty"`
	RemoteInfo      *ConnectionIPInfo `json:"remoteInfo,omitempty"`
	Destination     string            `json:"destination,omitempty"`
	DestinationInfo *ConnectionIPInfo `json:"destinationInfo,omitempty"`
	Source          string            `json:"source,omitempty"`
	SourceInfo      *ConnectionIPInfo `json:"sourceInfo,omitempty"`
	Message         string            `json:"message"`
}

func ParseConnectionLog

func ParseConnectionLog(entry logger.LogEntry) (ConnectionEntry, bool)

type ConnectionFilter

type ConnectionFilter struct {
	Resource string
	Tag      string
	User     string
	Search   string
	Start    int64
	End      int64
	Offset   int
	Limit    int
}

type ConnectionIPInfo

type ConnectionIPInfo struct {
	Address     string `json:"address,omitempty"`
	Host        string `json:"host,omitempty"`
	Port        string `json:"port,omitempty"`
	IP          string `json:"ip,omitempty"`
	Scope       string `json:"scope,omitempty"`
	Attribution string `json:"attribution,omitempty"`
	ISP         string `json:"isp,omitempty"`
	ASN         string `json:"asn,omitempty"`
	Country     string `json:"country,omitempty"`
	Region      string `json:"region,omitempty"`
	City        string `json:"city,omitempty"`
	Network     string `json:"network,omitempty"`
}

func ResolveConnectionAddress added in v1.0.13

func ResolveConnectionAddress(ctx context.Context, value string) (*ConnectionIPInfo, error)

type ConnectionOwnerLookupBudget

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

func NewConnectionOwnerLookupBudget

func NewConnectionOwnerLookupBudget(limit int) *ConnectionOwnerLookupBudget

type ConnectionQueryResult

type ConnectionQueryResult struct {
	Items   []ConnectionEntry              `json:"items"`
	Total   int                            `json:"total"`
	Offset  int                            `json:"offset"`
	Limit   int                            `json:"limit"`
	Summary map[string][]ConnectionSummary `json:"summary"`
	Parsed  int                            `json:"parsed"`
	Scanned int                            `json:"scanned"`
}

type ConnectionSummary

type ConnectionSummary struct {
	Resource string   `json:"resource"`
	Tag      string   `json:"tag"`
	Count    int      `json:"count"`
	LastSeen int64    `json:"lastSeen"`
	Users    []string `json:"users,omitempty"`
}

type EndpointService

type EndpointService struct {
	WarpService
}

func (*EndpointService) ExportWireGuardPeer

func (s *EndpointService) ExportWireGuardPeer(tag string, peerIndex int) (*WireGuardExport, error)

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 OIDCStart

type OIDCStart struct {
	URL string `json:"url"`
}

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) GetAuthSetting

func (s *SettingService) GetAuthSetting(key 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) GetKeyFile

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

func (*SettingService) GetListen

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

func (*SettingService) GetOIDCEnabled

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

func (*SettingService) GetPasskeyEnabled

func (s *SettingService) GetPasskeyEnabled() (bool, 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) GetSubCertFile

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

func (*SettingService) GetSubClashExt

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

func (*SettingService) GetSubDomain

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

func (*SettingService) GetSubEncode

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

func (*SettingService) GetSubInfoOptions

func (s *SettingService) GetSubInfoOptions() SubInfoOptions

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) GetWebDomain

func (s *SettingService) GetWebDomain() (string, 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) 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 StatsFilter

type StatsFilter struct {
	Resource string
	Tag      string
	Search   string
	Start    int64
	End      int64
	Offset   int
	Limit    int
}

StatsFilter is shared by the app API's chart and drill-down endpoints. Start and End are Unix seconds. A zero value leaves that boundary open.

type StatsQueryResult

type StatsQueryResult struct {
	Items  []model.Stats `json:"items"`
	Total  int64         `json:"total"`
	Offset int           `json:"offset"`
	Limit  int           `json:"limit"`
}

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, limit int) ([]model.Stats, error)

func (*StatsService) QueryConnections

func (s *StatsService) QueryConnections(filter ConnectionFilter) (*ConnectionQueryResult, error)

func (*StatsService) QueryStats

func (s *StatsService) QueryStats(filter StatsFilter) (*StatsQueryResult, error)

func (*StatsService) QueryUsage

func (s *StatsService) QueryUsage(filter UsageFilter) (*UsageQueryResult, error)

func (*StatsService) SaveStats

func (s *StatsService) SaveStats(enableTraffic bool) error

type SubInfoOptions

type SubInfoOptions struct {
	Upload    bool
	Download  bool
	Total     bool
	Expire    bool
	Remaining bool
}

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 UsageFilter

type UsageFilter struct {
	User   string
	Search string
	Start  int64
	End    int64
	Offset int
	Limit  int
}

type UsageQueryResult

type UsageQueryResult struct {
	Items    []UserUsage `json:"items"`
	Total    int64       `json:"total"`
	Upload   int64       `json:"upload"`
	Download int64       `json:"download"`
	Offset   int         `json:"offset"`
	Limit    int         `json:"limit"`
}

type UserService

type UserService struct{}

func (*UserService) AddToken

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

func (*UserService) BeginTOTP

func (s *UserService) BeginTOTP(username, issuer string) (map[string]string, error)

func (*UserService) ChangePass

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

func (*UserService) CheckPassword

func (s *UserService) CheckPassword(username string, password string, remoteIP string) (*model.User, 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) DeleteTokenValue

func (s *UserService) DeleteTokenValue(username string, token string) error

func (*UserService) DeleteUserToken

func (s *UserService) DeleteUserToken(username string, id string) error

DeleteUserToken prevents one administrator token from deleting another administrator's token by guessing its numeric id.

func (*UserService) DisableTOTP

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

func (*UserService) EnableTOTP

func (s *UserService) EnableTOTP(username, code string) ([]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) RecordLogin

func (s *UserService) RecordLogin(username, remoteIP string)

func (*UserService) UpdateFirstUser

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

func (*UserService) VerifySecondFactor

func (s *UserService) VerifySecondFactor(user *model.User, code string) bool

type UserUsage

type UserUsage struct {
	User       string `json:"user" gorm:"column:user"`
	Upload     int64  `json:"upload" gorm:"column:upload"`
	Download   int64  `json:"download" gorm:"column:download"`
	Total      int64  `json:"total" gorm:"column:total"`
	Enabled    bool   `json:"enabled" gorm:"-"`
	Quota      int64  `json:"quota" gorm:"-"`
	Expiry     int64  `json:"expiry" gorm:"-"`
	Group      string `json:"group,omitempty" gorm:"-"`
	Online     bool   `json:"online" gorm:"-"`
	LifetimeUp int64  `json:"lifetimeUpload" gorm:"-"`
	LifetimeDn int64  `json:"lifetimeDownload" gorm:"-"`
}

type WarpService

type WarpService struct{}

func (*WarpService) RegisterWarp

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

func (*WarpService) SetWarpLicense

func (s *WarpService) SetWarpLicense(oldLicense string, endpoint *model.Endpoint) error

type WireGuardExport

type WireGuardExport struct {
	Name     string `json:"name"`
	Filename string `json:"filename"`
	Config   string `json:"config"`
}

Jump to

Keyboard shortcuts

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