service

package
v2.8.8 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: GPL-3.0 Imports: 59 Imported by: 0

Documentation

Overview

Package service provides business logic services for the 3x-ui web panel, including inbound/outbound management, user administration, settings, and Xray integration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RemoveIndex

func RemoveIndex(s []any, index int) []any

RemoveIndex removes an element at the specified index from a slice. Returns a new slice with the element removed.

func StopBot added in v2.8.6

func StopBot()

StopBot safely stops the Telegram bot's Long Polling operation by cancelling its context. This is the global function called from main.go's signal handler and t.Stop().

Types

type CPUSample

type CPUSample struct {
	T   int64   `json:"t"`   // unix seconds
	Cpu float64 `json:"cpu"` // percent 0..100
}

CPUSample single CPU utilization sample

type InboundService

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

InboundService provides business logic for managing Xray inbound configurations. It handles CRUD operations for inbounds, client management, traffic monitoring, and integration with the Xray API for real-time updates.

func (*InboundService) AddClientStat

func (s *InboundService) AddClientStat(tx *gorm.DB, inboundId int, client *model.Client) error

func (*InboundService) AddInbound

func (s *InboundService) AddInbound(inbound *model.Inbound) (*model.Inbound, bool, error)

AddInbound creates a new inbound configuration. It validates port uniqueness, client email uniqueness, and required fields, then saves the inbound to the database and optionally adds it to the running Xray instance. Returns the created inbound, whether Xray needs restart, and any error.

func (*InboundService) AddInboundClient

func (s *InboundService) AddInboundClient(data *model.Inbound) (bool, error)

func (*InboundService) AddTraffic

func (s *InboundService) AddTraffic(inboundTraffics []*xray.Traffic, clientTraffics []*xray.ClientTraffic) (error, bool)

func (*InboundService) ClearClientIps

func (s *InboundService) ClearClientIps(clientEmail string) error

func (*InboundService) DelClientIPs

func (s *InboundService) DelClientIPs(tx *gorm.DB, email string) error

func (*InboundService) DelClientStat

func (s *InboundService) DelClientStat(tx *gorm.DB, email string) error

func (*InboundService) DelDepletedClients

func (s *InboundService) DelDepletedClients(id int) (err error)

func (*InboundService) DelInbound

func (s *InboundService) DelInbound(id int) (bool, error)

DelInbound deletes an inbound configuration by ID. It removes the inbound from the database and the running Xray instance if active. Returns whether Xray needs restart and any error.

func (*InboundService) DelInboundClient

func (s *InboundService) DelInboundClient(inboundId int, clientId string) (bool, error)

func (*InboundService) DelInboundClientByEmail

func (s *InboundService) DelInboundClientByEmail(inboundId int, email string) (bool, error)

func (*InboundService) FilterAndSortClientEmails

func (s *InboundService) FilterAndSortClientEmails(emails []string) ([]string, []string, error)

func (*InboundService) GetAllInbounds

func (s *InboundService) GetAllInbounds() ([]*model.Inbound, error)

GetAllInbounds retrieves all inbounds from the database. Returns a slice of all inbound models with their associated client statistics.

func (*InboundService) GetClientByEmail

func (s *InboundService) GetClientByEmail(clientEmail string) (*xray.ClientTraffic, *model.Client, error)

func (*InboundService) GetClientInboundByEmail

func (s *InboundService) GetClientInboundByEmail(email string) (traffic *xray.ClientTraffic, inbound *model.Inbound, err error)

func (*InboundService) GetClientInboundByTrafficID

func (s *InboundService) GetClientInboundByTrafficID(trafficId int) (traffic *xray.ClientTraffic, inbound *model.Inbound, err error)

func (*InboundService) GetClientTrafficByEmail

func (s *InboundService) GetClientTrafficByEmail(email string) (traffic *xray.ClientTraffic, err error)

func (*InboundService) GetClientTrafficByID

func (s *InboundService) GetClientTrafficByID(id string) ([]xray.ClientTraffic, error)

func (*InboundService) GetClientTrafficTgBot

func (s *InboundService) GetClientTrafficTgBot(tgId int64) ([]*xray.ClientTraffic, error)

func (*InboundService) GetClients

func (s *InboundService) GetClients(inbound *model.Inbound) ([]model.Client, error)

func (*InboundService) GetClientsLastOnline

func (s *InboundService) GetClientsLastOnline() (map[string]int64, error)

func (*InboundService) GetInbound

func (s *InboundService) GetInbound(id int) (*model.Inbound, error)

func (*InboundService) GetInboundClientIps

func (s *InboundService) GetInboundClientIps(clientEmail string) (string, error)

func (*InboundService) GetInboundTags

func (s *InboundService) GetInboundTags() (string, error)

func (*InboundService) GetInbounds

func (s *InboundService) GetInbounds(userId int) ([]*model.Inbound, error)

GetInbounds retrieves all inbounds for a specific user. Returns a slice of inbound models with their associated client statistics.

func (*InboundService) GetInboundsByTrafficReset

func (s *InboundService) GetInboundsByTrafficReset(period string) ([]*model.Inbound, error)

func (*InboundService) GetOnlineClients

func (s *InboundService) GetOnlineClients() []string

func (*InboundService) MigrateDB

func (s *InboundService) MigrateDB()

func (*InboundService) MigrationRemoveOrphanedTraffics

func (s *InboundService) MigrationRemoveOrphanedTraffics()

func (*InboundService) MigrationRequirements

func (s *InboundService) MigrationRequirements()

func (*InboundService) ResetAllClientTraffics

func (s *InboundService) ResetAllClientTraffics(id int) error

func (*InboundService) ResetAllTraffics

func (s *InboundService) ResetAllTraffics() error

func (*InboundService) ResetClientExpiryTimeByEmail

func (s *InboundService) ResetClientExpiryTimeByEmail(clientEmail string, expiry_time int64) (bool, error)

func (*InboundService) ResetClientIpLimitByEmail

func (s *InboundService) ResetClientIpLimitByEmail(clientEmail string, count int) (bool, error)

func (*InboundService) ResetClientTraffic

func (s *InboundService) ResetClientTraffic(id int, clientEmail string) (bool, error)

func (*InboundService) ResetClientTrafficByEmail

func (s *InboundService) ResetClientTrafficByEmail(clientEmail string) error

func (*InboundService) ResetClientTrafficLimitByEmail

func (s *InboundService) ResetClientTrafficLimitByEmail(clientEmail string, totalGB int) (bool, error)

func (*InboundService) SearchClientTraffic

func (s *InboundService) SearchClientTraffic(query string) (traffic *xray.ClientTraffic, err error)

func (*InboundService) SearchInbounds

func (s *InboundService) SearchInbounds(query string) ([]*model.Inbound, error)

func (*InboundService) SetClientEnableByEmail added in v2.8.5

func (s *InboundService) SetClientEnableByEmail(clientEmail string, enable bool) (bool, bool, error)

SetClientEnableByEmail sets client enable state to desired value; returns (changed, needRestart, error)

func (*InboundService) SetClientTelegramUserID

func (s *InboundService) SetClientTelegramUserID(trafficId int, tgId int64) (bool, error)

func (*InboundService) ToggleClientEnableByEmail

func (s *InboundService) ToggleClientEnableByEmail(clientEmail string) (bool, bool, error)

func (*InboundService) UpdateClientIPs

func (s *InboundService) UpdateClientIPs(tx *gorm.DB, oldEmail string, newEmail string) error

func (*InboundService) UpdateClientStat

func (s *InboundService) UpdateClientStat(tx *gorm.DB, email string, client *model.Client) error

func (*InboundService) UpdateClientTrafficByEmail

func (s *InboundService) UpdateClientTrafficByEmail(email string, upload int64, download int64) error

func (*InboundService) UpdateInbound

func (s *InboundService) UpdateInbound(inbound *model.Inbound) (*model.Inbound, bool, error)

UpdateInbound modifies an existing inbound configuration. It validates changes, updates the database, and syncs with the running Xray instance. Returns the updated inbound, whether Xray needs restart, and any error.

func (*InboundService) UpdateInboundClient

func (s *InboundService) UpdateInboundClient(data *model.Inbound, clientId string) (bool, error)

type LogEntry

type LogEntry struct {
	DateTime    time.Time
	FromAddress string
	ToAddress   string
	Inbound     string
	Outbound    string
	Email       string
	Event       int
}

type LoginStatus

type LoginStatus byte

LoginStatus represents the result of a login attempt.

const (
	LoginSuccess        LoginStatus = 1        // Login was successful
	LoginFail           LoginStatus = 0        // Login failed
	EmptyTelegramUserID             = int64(0) // Default value for empty Telegram user ID
)

Login status constants

type OutboundService

type OutboundService struct{}

OutboundService provides business logic for managing Xray outbound configurations. It handles outbound traffic monitoring and statistics.

func (*OutboundService) AddTraffic

func (s *OutboundService) AddTraffic(traffics []*xray.Traffic, clientTraffics []*xray.ClientTraffic) (error, bool)

func (*OutboundService) GetOutboundsTraffic

func (s *OutboundService) GetOutboundsTraffic() ([]*model.OutboundTraffics, error)

func (*OutboundService) ResetOutboundTraffic

func (s *OutboundService) ResetOutboundTraffic(tag string) error

type PanelService

type PanelService struct{}

PanelService provides business logic for panel management operations. It handles panel restart, updates, and system-level panel controls.

func (*PanelService) RestartPanel

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

type ProcessState

type ProcessState string

ProcessState represents the current state of a system process.

const (
	Running ProcessState = "running" // Process is running normally
	Stop    ProcessState = "stop"    // Process is stopped
	Error   ProcessState = "error"   // Process is in error state
)

Process state constants

type Release

type Release struct {
	TagName string `json:"tag_name"` // The tag name of the release
}

Release represents information about a software release from GitHub.

type ServerService

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

ServerService provides business logic for server monitoring and management. It handles system status collection, IP detection, and application statistics.

func (*ServerService) AggregateCpuHistory

func (s *ServerService) AggregateCpuHistory(bucketSeconds int, maxPoints int) []map[string]any

AggregateCpuHistory returns up to maxPoints averaged buckets of size bucketSeconds over recent data.

func (*ServerService) AppendCpuSample

func (s *ServerService) AppendCpuSample(t time.Time, v float64)

func (*ServerService) GetConfigJson

func (s *ServerService) GetConfigJson() (any, error)

func (*ServerService) GetDb

func (s *ServerService) GetDb() ([]byte, error)

func (*ServerService) GetLogs

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

func (*ServerService) GetNewEchCert

func (s *ServerService) GetNewEchCert(sni string) (any, error)

func (*ServerService) GetNewUUID

func (s *ServerService) GetNewUUID() (map[string]string, error)

func (*ServerService) GetNewVlessEnc

func (s *ServerService) GetNewVlessEnc() (any, error)

func (*ServerService) GetNewX25519Cert

func (s *ServerService) GetNewX25519Cert() (any, error)

func (*ServerService) GetNewmldsa65

func (s *ServerService) GetNewmldsa65() (any, error)

func (*ServerService) GetNewmlkem768

func (s *ServerService) GetNewmlkem768() (any, error)

func (*ServerService) GetStatus

func (s *ServerService) GetStatus(lastStatus *Status) *Status

func (*ServerService) GetXrayLogs

func (s *ServerService) GetXrayLogs(
	count string,
	filter string,
	showDirect string,
	showBlocked string,
	showProxy string,
	freedoms []string,
	blackholes []string) []LogEntry

func (*ServerService) GetXrayVersions

func (s *ServerService) GetXrayVersions() ([]string, error)

func (*ServerService) ImportDB

func (s *ServerService) ImportDB(file multipart.File) error

func (*ServerService) IsValidGeofileName added in v2.8.3

func (s *ServerService) IsValidGeofileName(filename string) bool

IsValidGeofileName validates that the filename is safe for geofile operations. It checks for path traversal attempts and ensures the filename contains only safe characters.

func (*ServerService) RestartXrayService

func (s *ServerService) RestartXrayService() error

func (*ServerService) StopXrayService

func (s *ServerService) StopXrayService() error

func (*ServerService) UpdateGeofile

func (s *ServerService) UpdateGeofile(fileName string) error

func (*ServerService) UpdateXray

func (s *ServerService) UpdateXray(version string) error

type SettingService

type SettingService struct{}

SettingService provides business logic for application settings management. It handles configuration storage, retrieval, and validation for all system settings.

func (*SettingService) GetAllSetting

func (s *SettingService) GetAllSetting() (*entity.AllSetting, error)

func (*SettingService) GetBasePath

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

func (*SettingService) GetCertFile

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

func (*SettingService) GetDatepicker

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

func (*SettingService) GetDefaultJsonConfig

func (s *SettingService) GetDefaultJsonConfig() (any, error)

func (*SettingService) GetDefaultSettings

func (s *SettingService) GetDefaultSettings(host string) (any, error)

func (*SettingService) GetDefaultXrayConfig

func (s *SettingService) GetDefaultXrayConfig() (any, error)

func (*SettingService) GetExpireDiff

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

func (*SettingService) GetExternalTrafficInformEnable

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

func (*SettingService) GetExternalTrafficInformURI

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

func (*SettingService) GetIpLimitEnable

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

func (*SettingService) GetKeyFile

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

func (*SettingService) GetLdapAutoCreate added in v2.8.5

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

func (*SettingService) GetLdapAutoDelete added in v2.8.5

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

func (*SettingService) GetLdapBaseDN added in v2.8.5

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

func (*SettingService) GetLdapBindDN added in v2.8.5

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

func (*SettingService) GetLdapDefaultExpiryDays added in v2.8.5

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

func (*SettingService) GetLdapDefaultLimitIP added in v2.8.5

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

func (*SettingService) GetLdapDefaultTotalGB added in v2.8.5

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

func (*SettingService) GetLdapEnable added in v2.8.5

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

LDAP exported getters

func (*SettingService) GetLdapFlagField added in v2.8.5

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

func (*SettingService) GetLdapHost added in v2.8.5

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

func (*SettingService) GetLdapInboundTags added in v2.8.5

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

func (*SettingService) GetLdapInvertFlag added in v2.8.5

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

func (*SettingService) GetLdapPassword added in v2.8.5

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

func (*SettingService) GetLdapPort added in v2.8.5

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

func (*SettingService) GetLdapSyncCron added in v2.8.5

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

func (*SettingService) GetLdapTruthyValues added in v2.8.5

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

func (*SettingService) GetLdapUseTLS added in v2.8.5

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

func (*SettingService) GetLdapUserAttr added in v2.8.5

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

func (*SettingService) GetLdapUserFilter added in v2.8.5

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

func (*SettingService) GetLdapVlessField added in v2.8.5

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

func (*SettingService) GetListen

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

func (*SettingService) GetPageSize

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

func (*SettingService) GetPort

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

func (*SettingService) GetRemarkModel

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

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

func (*SettingService) GetSubEnable

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

func (*SettingService) GetSubEncrypt

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

func (*SettingService) GetSubJsonEnable

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

func (*SettingService) GetSubJsonFragment

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

func (*SettingService) GetSubJsonMux

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

func (*SettingService) GetSubJsonNoises

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

func (*SettingService) GetSubJsonPath

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

func (*SettingService) GetSubJsonRules

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

func (*SettingService) GetSubJsonURI

func (s *SettingService) GetSubJsonURI() (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) GetSubTitle

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

func (*SettingService) GetSubURI

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

func (*SettingService) GetSubUpdates

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

func (*SettingService) GetTgBotAPIServer

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

func (*SettingService) GetTgBotBackup

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

func (*SettingService) GetTgBotChatId

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

func (*SettingService) GetTgBotLoginNotify

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

func (*SettingService) GetTgBotProxy

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

func (*SettingService) GetTgBotToken

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

func (*SettingService) GetTgCpu

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

func (*SettingService) GetTgLang

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

func (*SettingService) GetTgbotEnabled

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

func (*SettingService) GetTgbotRuntime

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

func (*SettingService) GetTimeLocation

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

func (*SettingService) GetTrafficDiff

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

func (*SettingService) GetTwoFactorEnable

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

func (*SettingService) GetTwoFactorToken

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

func (*SettingService) GetWarp

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

func (*SettingService) GetWebDomain

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

func (*SettingService) GetXrayConfigTemplate

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

func (*SettingService) ResetSettings

func (s *SettingService) ResetSettings() error

func (*SettingService) SetBasePath

func (s *SettingService) SetBasePath(basePath string) error

func (*SettingService) SetCertFile

func (s *SettingService) SetCertFile(webCertFile string) error

func (*SettingService) SetExternalTrafficInformEnable

func (s *SettingService) SetExternalTrafficInformEnable(value bool) error

func (*SettingService) SetExternalTrafficInformURI

func (s *SettingService) SetExternalTrafficInformURI(InformURI string) error

func (*SettingService) SetKeyFile

func (s *SettingService) SetKeyFile(webKeyFile string) error

func (*SettingService) SetListen

func (s *SettingService) SetListen(ip string) error

func (*SettingService) SetPort

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

func (*SettingService) SetSubCertFile added in v2.8.6

func (s *SettingService) SetSubCertFile(subCertFile string) error

func (*SettingService) SetSubKeyFile added in v2.8.6

func (s *SettingService) SetSubKeyFile(subKeyFile string) error

func (*SettingService) SetTgBotAPIServer

func (s *SettingService) SetTgBotAPIServer(token string) error

func (*SettingService) SetTgBotChatId

func (s *SettingService) SetTgBotChatId(chatIds string) error

func (*SettingService) SetTgBotProxy

func (s *SettingService) SetTgBotProxy(token string) error

func (*SettingService) SetTgBotToken

func (s *SettingService) SetTgBotToken(token string) error

func (*SettingService) SetTgbotEnabled

func (s *SettingService) SetTgbotEnabled(value bool) error

func (*SettingService) SetTgbotRuntime

func (s *SettingService) SetTgbotRuntime(time string) error

func (*SettingService) SetTwoFactorEnable

func (s *SettingService) SetTwoFactorEnable(value bool) error

func (*SettingService) SetTwoFactorToken

func (s *SettingService) SetTwoFactorToken(value string) error

func (*SettingService) SetWarp

func (s *SettingService) SetWarp(data string) error

func (*SettingService) UpdateAllSetting

func (s *SettingService) UpdateAllSetting(allSetting *entity.AllSetting) error

type Status

type Status struct {
	T           time.Time `json:"-"`
	Cpu         float64   `json:"cpu"`
	CpuCores    int       `json:"cpuCores"`
	LogicalPro  int       `json:"logicalPro"`
	CpuSpeedMhz float64   `json:"cpuSpeedMhz"`
	Mem         struct {
		Current uint64 `json:"current"`
		Total   uint64 `json:"total"`
	} `json:"mem"`
	Swap struct {
		Current uint64 `json:"current"`
		Total   uint64 `json:"total"`
	} `json:"swap"`
	Disk struct {
		Current uint64 `json:"current"`
		Total   uint64 `json:"total"`
	} `json:"disk"`
	Xray struct {
		State    ProcessState `json:"state"`
		ErrorMsg string       `json:"errorMsg"`
		Version  string       `json:"version"`
	} `json:"xray"`
	Uptime   uint64    `json:"uptime"`
	Loads    []float64 `json:"loads"`
	TcpCount int       `json:"tcpCount"`
	UdpCount int       `json:"udpCount"`
	NetIO    struct {
		Up   uint64 `json:"up"`
		Down uint64 `json:"down"`
	} `json:"netIO"`
	NetTraffic struct {
		Sent uint64 `json:"sent"`
		Recv uint64 `json:"recv"`
	} `json:"netTraffic"`
	PublicIP struct {
		IPv4 string `json:"ipv4"`
		IPv6 string `json:"ipv6"`
	} `json:"publicIP"`
	AppStats struct {
		Threads uint32 `json:"threads"`
		Mem     uint64 `json:"mem"`
		Uptime  uint64 `json:"uptime"`
	} `json:"appStats"`
}

Status represents comprehensive system and application status information. It includes CPU, memory, disk, network statistics, and Xray process status.

type Tgbot

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

Tgbot provides business logic for Telegram bot integration. It handles bot commands, user interactions, and status reporting via Telegram.

func (*Tgbot) BuildInboundClientDataMessage

func (t *Tgbot) BuildInboundClientDataMessage(inbound_remark string, protocol model.Protocol) (string, error)

BuildInboundClientDataMessage builds a message with client data for the given inbound and protocol.

func (*Tgbot) BuildJSONForProtocol

func (t *Tgbot) BuildJSONForProtocol(protocol model.Protocol) (string, error)

BuildJSONForProtocol builds a JSON string for the given protocol with client data.

func (*Tgbot) GetHashStorage

func (t *Tgbot) GetHashStorage() *global.HashStorage

GetHashStorage returns the hash storage instance for callback queries.

func (*Tgbot) I18nBot

func (t *Tgbot) I18nBot(name string, params ...string) string

I18nBot retrieves a localized message for the bot interface.

func (*Tgbot) IsRunning

func (t *Tgbot) IsRunning() bool

IsRunning checks if the Telegram bot is currently running.

func (*Tgbot) NewBot

func (t *Tgbot) NewBot(token string, proxyUrl string, apiServerUrl string) (*telego.Bot, error)

NewBot creates a new Telegram bot instance with optional proxy and API server settings.

func (*Tgbot) NewTgbot

func (t *Tgbot) NewTgbot() *Tgbot

NewTgbot creates a new Tgbot instance.

func (*Tgbot) OnReceive

func (t *Tgbot) OnReceive()

OnReceive starts the message receiving loop for the Telegram bot.

func (*Tgbot) SendAnswer

func (t *Tgbot) SendAnswer(chatId int64, msg string, isAdmin bool)

SendAnswer sends a response message with an inline keyboard to the specified chat.

func (*Tgbot) SendBackupToAdmins

func (t *Tgbot) SendBackupToAdmins()

SendBackupToAdmins sends a database backup to admin chats.

func (*Tgbot) SendMsgToTgbot

func (t *Tgbot) SendMsgToTgbot(chatId int64, msg string, replyMarkup ...telego.ReplyMarkup)

SendMsgToTgbot sends a message to the Telegram bot with optional reply markup.

func (*Tgbot) SendMsgToTgbotAdmins

func (t *Tgbot) SendMsgToTgbotAdmins(msg string, replyMarkup ...telego.ReplyMarkup)

SendMsgToTgbotAdmins sends a message to all admin Telegram chats.

func (*Tgbot) SendMsgToTgbotDeleteAfter

func (t *Tgbot) SendMsgToTgbotDeleteAfter(chatId int64, msg string, delayInSeconds int, replyMarkup ...telego.ReplyMarkup)

SendMsgToTgbotDeleteAfter sends a message and deletes it after a specified delay.

func (*Tgbot) SendReport

func (t *Tgbot) SendReport()

SendReport sends a periodic report to admin chats.

func (*Tgbot) SetHostname

func (t *Tgbot) SetHostname()

SetHostname sets the hostname for the bot.

func (*Tgbot) Start

func (t *Tgbot) Start(i18nFS embed.FS) error

Start initializes and starts the Telegram bot with the provided translation files.

func (*Tgbot) Stop

func (t *Tgbot) Stop()

Stop safely stops the Telegram bot's Long Polling operation. This method now calls the global StopBot function and cleans up other resources.

func (*Tgbot) SubmitAddClient

func (t *Tgbot) SubmitAddClient() (bool, error)

SubmitAddClient submits the client addition request to the inbound service.

func (*Tgbot) UserLoginNotify

func (t *Tgbot) UserLoginNotify(username string, password string, ip string, time string, status LoginStatus)

UserLoginNotify sends a notification about user login attempts to admins.

type UserService

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

UserService provides business logic for user management and authentication. It handles user creation, login, password management, and 2FA operations.

func (*UserService) CheckUser

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

func (*UserService) GetFirstUser

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

GetFirstUser retrieves the first user from the database. This is typically used for initial setup or when there's only one admin user.

func (*UserService) UpdateFirstUser

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

func (*UserService) UpdateUser

func (s *UserService) UpdateUser(id int, username string, password string) error

type WarpService

type WarpService struct {
	SettingService
}

WarpService provides business logic for Cloudflare WARP integration. It manages WARP configuration and connectivity settings.

func (*WarpService) DelWarpData

func (s *WarpService) DelWarpData() error

func (*WarpService) GetWarpConfig

func (s *WarpService) GetWarpConfig() (string, error)

func (*WarpService) GetWarpData

func (s *WarpService) GetWarpData() (string, error)

func (*WarpService) RegWarp

func (s *WarpService) RegWarp(secretKey string, publicKey string) (string, error)

func (*WarpService) SetWarpLicense

func (s *WarpService) SetWarpLicense(license string) (string, error)

type XrayService

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

XrayService provides business logic for Xray process management. It handles starting, stopping, restarting Xray, and managing its configuration.

func (*XrayService) DidXrayCrash

func (s *XrayService) DidXrayCrash() bool

DidXrayCrash checks if Xray crashed by verifying it's not running and wasn't manually stopped.

func (*XrayService) GetXrayConfig

func (s *XrayService) GetXrayConfig() (*xray.Config, error)

GetXrayConfig retrieves and builds the Xray configuration from settings and inbounds.

func (*XrayService) GetXrayErr

func (s *XrayService) GetXrayErr() error

GetXrayErr returns the error from the Xray process, if any.

func (*XrayService) GetXrayResult

func (s *XrayService) GetXrayResult() string

GetXrayResult returns the result string from the Xray process.

func (*XrayService) GetXrayTraffic

func (s *XrayService) GetXrayTraffic() ([]*xray.Traffic, []*xray.ClientTraffic, error)

GetXrayTraffic fetches the current traffic statistics from the running Xray process.

func (*XrayService) GetXrayVersion

func (s *XrayService) GetXrayVersion() string

GetXrayVersion returns the version of the running Xray process.

func (*XrayService) IsNeedRestartAndSetFalse

func (s *XrayService) IsNeedRestartAndSetFalse() bool

IsNeedRestartAndSetFalse checks if restart is needed and resets the flag to false.

func (*XrayService) IsXrayRunning

func (s *XrayService) IsXrayRunning() bool

IsXrayRunning checks if the Xray process is currently running.

func (*XrayService) RestartXray

func (s *XrayService) RestartXray(isForce bool) error

RestartXray restarts the Xray process, optionally forcing a restart even if config unchanged.

func (*XrayService) SetToNeedRestart

func (s *XrayService) SetToNeedRestart()

SetToNeedRestart marks that Xray needs to be restarted.

func (*XrayService) StopXray

func (s *XrayService) StopXray() error

StopXray stops the running Xray process.

type XraySettingService

type XraySettingService struct {
	SettingService
}

XraySettingService provides business logic for Xray configuration management. It handles validation and storage of Xray template configurations.

func (*XraySettingService) CheckXrayConfig

func (s *XraySettingService) CheckXrayConfig(XrayTemplateConfig string) error

func (*XraySettingService) SaveXraySetting

func (s *XraySettingService) SaveXraySetting(newXraySettings string) error

Jump to

Keyboard shortcuts

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