controller

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2025 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Allconfigs

type Allconfigs []*db.Config

func (Allconfigs) Appendconf

func (a Allconfigs) Appendconf(conf *sbox.Userconfig, userid int64)

func (Allconfigs) RemoveAll

func (a Allconfigs) RemoveAll()

type BroadcastSig

type BroadcastSig string //use to send Broadcast signal with broadcast msg

type Controller

type Controller struct {
	Lockval    *atomic.Int32
	Metaconfig *MetadataConf

	*Metadata
	Overview *Overview

	Usermgrsession *sync.Map
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, db *db.Database, logger *zap.Logger, metaconf *MetadataConf, btapi botapi.BotAPI, sboxopt option.Options) (*Controller, error)

func (*Controller) AddEvent

func (c *Controller) AddEvent(userId int64, name string) error

func (*Controller) AddResetUserSbox

func (c *Controller) AddResetUserSbox(conf *sbox.Userconfig) (sbox.Sboxstatus, error)

func (*Controller) Addquemg

func (w *Controller) Addquemg(upxctx context.Context, msg any)

msg should be type controller.UserCount, *botapi.Msgcommon, botapi.UpMessage: remove ctx argument later

func (*Controller) Addsession

func (c *Controller) Addsession(closefunc ForceCloser, UserId int64)

func (*Controller) AdduserSbox

func (c *Controller) AdduserSbox(conf *sbox.Userconfig) (sbox.Sboxstatus, error)

func (*Controller) CancleUpdateContexs

func (c *Controller) CancleUpdateContexs()

canceling all ongoing upx

func (*Controller) CheckLock

func (c *Controller) CheckLock() bool

check is that controller locked by watchman if locked this function wait for it to unlock

func (*Controller) Checksession

func (c *Controller) Checksession(UserId int64) (any, bool)

func (*Controller) ClaimReferVerified

func (c *Controller) ClaimReferVerified(owenerid int64) (int, error)

heavy load on db optimize later

func (*Controller) Close

func (c *Controller) Close() error

func (*Controller) CreateRefrral

func (c *Controller) CreateRefrral(owenerid, userid int64) (*db.Reffral, error)

func (*Controller) CreateSboxConf

func (c *Controller) CreateSboxConf(userId int64, name string) (db.SboxConfigs, error)

func (*Controller) DecCriticalOp

func (c *Controller) DecCriticalOp()

func (*Controller) DeleteConf

func (c *Controller) DeleteConf(confId int64) error

Deletes buildconfig not releted to server configs

func (*Controller) DirectMg

func (c *Controller) DirectMg(text string, UserId int64, ChatID int64) error

func (*Controller) GetBaseContext

func (c *Controller) GetBaseContext() context.Context

func (*Controller) GetHelepCmdInfo

func (c *Controller) GetHelepCmdInfo() bottype.HelpCommandInfo

func (*Controller) GetLastRefreshtime

func (c *Controller) GetLastRefreshtime() time.Time

func (*Controller) GetSboxConfig

func (c *Controller) GetSboxConfig(userID int64) ([]db.SboxConfigs, error)

func (*Controller) GetSpecificConf

func (c *Controller) GetSpecificConf(userId int64, name string) (db.SboxConfigs, error)

func (*Controller) GetUnVerifiedUserList

func (c *Controller) GetUnVerifiedUserList(in *[]int64) error

func (*Controller) GetUser

func (c *Controller) GetUser(user *tgbotapi.User) (*bottype.User, bool, error)

func (*Controller) GetUserById

func (c *Controller) GetUserById(userId int64) (*db.User, error)

func (*Controller) GetUserByUserName

func (c *Controller) GetUserByUserName(userName string) (*db.User, error)

func (*Controller) GetUserConfigs

func (c *Controller) GetUserConfigs(userID int64) ([]db.Config, error)

this give configs according to server not from builder

func (*Controller) GetUserList

func (c *Controller) GetUserList(in *[]int64) error

func (*Controller) GetVerifiedUserList

func (c *Controller) GetVerifiedUserList(in *[]int64) error

func (*Controller) Getadminchat

func (c *Controller) Getadminchat() (map[int64]string, error)

func (*Controller) Getmgque

func (c *Controller) Getmgque() chan any

returning channel can be used many things, user update count, que sending msg to user when buffring usercount update type should be UserCount

func (*Controller) GetstatusUserSbox

func (c *Controller) GetstatusUserSbox(conf *sbox.Userconfig) (sbox.Sboxstatus, error)

func (*Controller) Gift

func (c *Controller) Gift(upx *update.Updatectx, to any, quota C.Bwidth) (*db.User, error)

Only checks reciver can recive the gift if not return err, Caller should check sender is valid input quota should be BYte format

func (*Controller) IncCriticalOp

func (c *Controller) IncCriticalOp()

func (*Controller) IncreaseUserCount

func (c *Controller) IncreaseUserCount(count int)

func (*Controller) Init

func (c *Controller) Init() error

func (*Controller) LoadEvents

func (c *Controller) LoadEvents(userID int64) (map[string]db.Event, error)

func (*Controller) Newuser

func (c *Controller) Newuser(user *tgbotapi.User, chat *tgbotapi.Chat) (*bottype.User, error)

func (*Controller) RecalculateConfigquotas

func (c *Controller) RecalculateConfigquotas(user *db.User) error

user struct should have been preloaded configs this method does not save to db, caller should

func (*Controller) ReffralCount

func (c *Controller) ReffralCount(owenerid int64) (int64, int64, error)

return reffrld, verified, error

func (*Controller) RefreshUrlTest

func (c *Controller) RefreshUrlTest()

func (*Controller) RefreshUser

func (c *Controller) RefreshUser(ctx context.Context, dbuser *db.User) error

func (*Controller) RemoveSesion

func (c *Controller) RemoveSesion(UserId int64)

func (*Controller) RemoveUserSbox

func (c *Controller) RemoveUserSbox(conf *sbox.Userconfig) (sbox.Sboxstatus, error)

func (*Controller) SearchUserByUsername

func (c *Controller) SearchUserByUsername(username string) (*db.User, bool, error)

func (*Controller) SendMsgContext

func (c *Controller) SendMsgContext(ctx context.Context, msg any) (*tgbotapi.Message, error)

func (*Controller) SetIsbotarted

func (c *Controller) SetIsbotarted(userID int64, val bool) error

Do not use this func its slow

func (*Controller) SetLastRefreshtime

func (c *Controller) SetLastRefreshtime()

only use In watchman, Do not use elsewhere

func (*Controller) UpdatePoint

func (c *Controller) UpdatePoint(newpointCount int64, userId int64) error

func (*Controller) UrlTestOut

func (c *Controller) UrlTestOut(tag string) (int16, error)

func (*Controller) WaitCriticalop

func (c *Controller) WaitCriticalop()

func (*Controller) WatchmanLock

func (c *Controller) WatchmanLock()

func (*Controller) WatchmanUnlock

func (c *Controller) WatchmanUnlock()

type CtrlSession

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

Ctrlsession is not theadsafe use in single thread

func NewctrlSession

func NewctrlSession(ctrl *Controller, upx *update.Updatectx, ForceCloseOldSession bool) (*CtrlSession, error)

func (*CtrlSession) ActivateAll

func (c *CtrlSession) ActivateAll() error

func (*CtrlSession) ActivateConfig

func (c *CtrlSession) ActivateConfig(confid int64) (sbox.Sboxstatus, error)

func (*CtrlSession) AddNewConfig

func (c *CtrlSession) AddNewConfig(inboundid int16, outboundid int16, Quota C.Bwidth, login int16, name string) (*sbox.Userconfig, error)

func (*CtrlSession) Banuser

func (c *CtrlSession) Banuser(chat string)

func (*CtrlSession) ChangeIO

func (c *CtrlSession) ChangeIO(ioboundname string, confid, ioid int64) error

func (*CtrlSession) ChangeInbound

func (c *CtrlSession) ChangeInbound(confid, inboundid int64) error

func (*CtrlSession) ChangeLoginLimit

func (c *CtrlSession) ChangeLoginLimit(confid int64, newlimit int32) (sbox.Sboxstatus, error)

func (*CtrlSession) ChangeOutbound

func (c *CtrlSession) ChangeOutbound(confid, inboundid int64) error

func (*CtrlSession) Chatupdate

func (c *CtrlSession) Chatupdate(chat string, val bool)

func (*CtrlSession) Close

func (c *CtrlSession) Close() error

func (*CtrlSession) ConfigCloseConn

func (c *CtrlSession) ConfigCloseConn(confid int64) error

func (*CtrlSession) CreateUsagehistory

func (c *CtrlSession) CreateUsagehistory(status sbox.Sboxstatus, confid int64) error

func (*CtrlSession) DeactivateAll

func (c *CtrlSession) DeactivateAll() error

func (*CtrlSession) DeactivateConfig

func (c *CtrlSession) DeactivateConfig(configID int64) (sbox.Sboxstatus, error)

func (*CtrlSession) DeleteConfig

func (c *CtrlSession) DeleteConfig(configID int64) error

func (*CtrlSession) ForceClose

func (c *CtrlSession) ForceClose() error

func (*CtrlSession) FullUsageHistory

func (c *CtrlSession) FullUsageHistory()

func (*CtrlSession) GetConfig

func (c *CtrlSession) GetConfig(confid int64) (*db.Config, error)

func (*CtrlSession) GetConfigFullUsage

func (c *CtrlSession) GetConfigFullUsage(confid int64) (bottype.FullUsage, sbox.Sboxstatus)

func (*CtrlSession) GetFullUsage

func (c *CtrlSession) GetFullUsage() bottype.FullUsage

func (*CtrlSession) GetUsage

func (c *CtrlSession) GetUsage() (C.Bwidth, C.Bwidth)

return current vpn usage, old usage from db total usage for now = vpn usage + old Every thing in byte format retur today, monthusage

func (*CtrlSession) GetUser

func (c *CtrlSession) GetUser() *db.User

func (*CtrlSession) GetconfigQuota

func (c *CtrlSession) GetconfigQuota(confid int64) C.Bwidth

func (*CtrlSession) GetconfigUsage

func (c *CtrlSession) GetconfigUsage(confid int64) (C.Bwidth, C.Bwidth, error)

returns today, month, usage as byte

func (*CtrlSession) GetconfigUsageTotal

func (c *CtrlSession) GetconfigUsageTotal(confid int64) C.Bwidth

func (*CtrlSession) Getstatus

func (c *CtrlSession) Getstatus(confid int64) (sbox.Sboxstatus, error)

func (*CtrlSession) LeftQuota

func (c *CtrlSession) LeftQuota() C.Bwidth

this returns left quota for user userquota - quota elpsed for configs

func (*CtrlSession) LeftQuotaFromOrigin

func (c *CtrlSession) LeftQuotaFromOrigin() C.Bwidth

this is special for gift command

func (*CtrlSession) LeftUsage

func (c *CtrlSession) LeftUsage() C.Bwidth

func (*CtrlSession) ReActivateConfig

func (c *CtrlSession) ReActivateConfig(confid int64) (sbox.Sboxstatus, error)

func (*CtrlSession) RemoveRestrict

func (c *CtrlSession) RemoveRestrict()

func (*CtrlSession) Restrict

func (c *CtrlSession) Restrict()

used by admin

func (*CtrlSession) Save

func (c *CtrlSession) Save() error

func (*CtrlSession) SaveConfigs

func (c *CtrlSession) SaveConfigs() error

func (*CtrlSession) TotalUsage

func (c *CtrlSession) TotalUsage() C.Bwidth

return total usage for this month

type ForceCloser

type ForceCloser interface {
	ForceClose() error
}

type ForceResetUsage

type ForceResetUsage uint16 //use to send Newrefresh signal wit force reset all usage database checkcount will reset

type Metadata

type Metadata struct {
	ChannelId int64
	GroupID   int64

	//UserQuota		C.Bwidth // Last calculated userquota should use with rwmutext
	CommonQuota *atomic.Int64 // This is commonquota for all user userquota may vary to their settings
	//Channelusercount *atomic.Int32
	//Groupusercount   *atomic.Int32
	VerifiedUserCount *atomic.Int32
	Maxconfigcount    int16

	Dbusercount       *atomic.Int32
	LoginLimit        int32
	BandwidthAvelable C.Bwidth

	Inbounds  []sbox.Inboud
	Outbounds []sbox.Outbound

	CheckCount  *atomic.Int32
	ResetCount  int32 //static value that db should reset when checkcount eqal to this
	RefreshRate int32

	GroupLink  string
	Channelink string
	Botlink    string

	GroupName   string
	ChannelName string
	BotName     string

	DefaultDomain string
	DefaultPubip  string

	MaxRecurtion int

	SudoAdmin    int64
	ConfigFolder string

	HelperInfo bottype.HelpCommandInfo
	// contains filtered or unexported fields
}

func (*Metadata) ConfFolder

func (m *Metadata) ConfFolder() string

func (*Metadata) DefaultInboud

func (m *Metadata) DefaultInboud() (sbox.Inboud, db.Inbound)

func (*Metadata) Defaultoutboud

func (m *Metadata) Defaultoutboud() (sbox.Outbound, db.Outbound)

func (*Metadata) GetInlinePost

func (m *Metadata) GetInlinePost() []string

func (*Metadata) GetdbInbound

func (m *Metadata) GetdbInbound(id int) (db.Inbound, error)

func (*Metadata) GetdbOutbound

func (m *Metadata) GetdbOutbound(id int) (db.Outbound, error)

func (*Metadata) Getinbound

func (m *Metadata) Getinbound(id int) (sbox.Inboud, bool)

func (*Metadata) Getinbounds

func (m *Metadata) Getinbounds() []sbox.Inboud

func (*Metadata) Getoutbound

func (m *Metadata) Getoutbound(id int) (sbox.Outbound, bool)

func (*Metadata) Getoutbounds

func (m *Metadata) Getoutbounds() []sbox.Outbound

func (*Metadata) Init

func (m *Metadata) Init(metaconf MetadataConf) error

func (*Metadata) StorePath

func (m *Metadata) StorePath() string

type MetadataConf

type MetadataConf struct {
	//ForceAdd          bool   `json:"forceAdd,omitempty"`
	ChannelID         int64  `json:"channel_id,omitempty"`
	GroupID           int64  `json:"groupd_id,omitempty"`
	BandwidthAvelable string `json:"bandwidth,omitempty"`
	LoginLimit        int16  `json:"login_limit,omitempty"`
	//Userquota         int32  `json:"userquota,omitempty"`
	//Verifiedcount     int32  `json:"verifiedcount,omitempty"`
	Maxconfigcount int16 `json:"max_config_count,omitempty"`
	//CheckCount        int32  `json:"checkcount,omitempty"`  // database checked count for exting period
	RefreshRate int32 `json:"refresh_rate,omitempty"` //rate of db refresh in hours

	GroupLink  string `json:"group_link,omitempty"`
	Channelink string `json:"channel_link,omitempty"`
	Botlink    string `json:"bot_link,omitempty"`

	GroupName   string `json:"group_name,omitempty"`
	ChannelName string `json:"channel_name,omitempty"`
	BotName     string `json:"bot_name,omitempty"`

	//SudoAdminId int64 `json:"adminId,omitempty"`
	//AllAdmin  []int64 `json:"alladmin,omitempty"`
	SudoAdmin int64 `json:"admin,omitempty"`

	WatchMgbuf int `json:"group_maxmg,omitempty"`

	DefaultDomain   string `json:"default_domain,omitempty"`
	DefaultPublicIp string `json:"default_publicip,omitempty"`

	StorePath    string `json:"store_path,omitempty"`
	ConfigFolder string `json:"config_folder,omitempty"`

	HelperInfo bottype.HelpCommandInfo `json:"help_cmd,omitempty"`

	InlinePost []string `json:"inline_posts,omitempty"`
}

type Overview

type Overview struct {
	Mu *sync.RWMutex

	BandwidthAvailable C.Bwidth
	//DownLoad C.Bwidth
	//Upload C.Bwidth
	MonthTotal C.Bwidth
	AllTime    C.Bwidth

	VerifiedUserCount int64
	TotalUser         int32
	CappedUser        int64
	DistributedUser   int64
	QuotaForEach      C.Bwidth
	Restricted        int64

	LastRefresh time.Time

	Error error
}

type RefreshSignal

type RefreshSignal uint16 //use to send Newrefresh signal

type SboxIO

type SboxIO struct {
	Inbounds []option.Inbound
	// contains filtered or unexported fields
}

type UserCount

type UserCount int //sending usercount updates

Jump to

Keyboard shortcuts

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