file

package
v0.34.8 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: GPL-3.0 Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	AclOff       = 0
	AclWhitelist = 1
	AclBlacklist = 2
)

ACLMode: 0=off, 1=whitelist(deny-by-default), 2=blacklist(allow-by-default)

Variables

View Source
var (
	Db *DbUtils

	HostIndex         = index.NewDomainIndex()
	Blake2bVkeyIndex  = index.NewStringIDIndex()
	TaskPasswordIndex = index.NewStringIDIndex()
)

Functions

func ConfigTaskPorts added in v0.34.8

func ConfigTaskPorts(t *Tunnel) (ports, targets []int, ok bool)

ConfigTaskPorts expands a task delivered by a client configuration into the server ports it is opened on and, for multi-port tcp/udp tasks, the matching target ports. The server reports one add status per returned port, or a single failure status when ok is false, so both sides use this to stay in step on the configuration connection.

func GetAccountMap added in v0.26.47

func GetAccountMap(multiAccount *MultiAccount) map[string]string

func GetMapKeys

func GetMapKeys(m *sync.Map, isSort bool, sortKey, order string) (keys []int)

Types

type Client

type Client struct {
	Cnf             *Config
	Id              int        // id
	VerifyKey       string     // verify key
	Mode            string     // bridge mode
	Addr            string     // client ip
	LocalAddr       string     // client local ip
	Remark          string     // remark
	Status          bool       // allowed to connect
	IsConnect       bool       // connected now
	RateLimit       int        // rate limit (KB/s)
	Flow            *Flow      // flow
	ExportFlow      int64      // outbound flow
	InletFlow       int64      // inbound flow
	Rate            *rate.Rate // rate limiter
	NoStore         bool       // do not store to file
	NoDisplay       bool       // do not display on web
	MaxConn         int        // max concurrent connections
	NowConn         int32      // current connections
	WebUserName     string     // web username
	WebPassword     string     // web password
	WebTotpSecret   string     // web totp secret
	ConfigConnAllow bool       // allowed by config file
	MaxTunnelNum    int
	Version         string
	BlackIpList     []string
	CreateTime      string
	LastOnlineTime  string
	sync.RWMutex
}

func NewClient

func NewClient(vKey string, noStore bool, noDisplay bool) *Client

func (*Client) AddConn

func (s *Client) AddConn()

func (*Client) CutConn

func (s *Client) CutConn()

CutConn releases a connection taken by GetConn or AddConn; the count never drops below zero.

func (*Client) EnsureWebPassword added in v0.29.30

func (s *Client) EnsureWebPassword()

func (*Client) GetConn

func (s *Client) GetConn() bool

GetConn takes a connection slot, reporting false when MaxConn is reached.

func (*Client) GetTunnelNum

func (s *Client) GetTunnelNum() (num int)

func (*Client) HasHost

func (s *Client) HasHost(h *Host) (hh *Host, exist bool)

func (*Client) HasTunnel

func (s *Client) HasTunnel(t *Tunnel) (tt *Tunnel, exist bool)

type Config

type Config struct {
	U        string // username
	P        string // password
	Compress bool
	Crypt    bool
}

type DbUtils

type DbUtils struct {
	JsonDb *JsonDb
}

func GetDb

func GetDb() *DbUtils

GetDb init data from file

func (*DbUtils) DelClient

func (s *DbUtils) DelClient(id int) error

func (*DbUtils) DelHost

func (s *DbUtils) DelHost(id int) error

func (*DbUtils) DelTask

func (s *DbUtils) DelTask(id int) error

func (*DbUtils) FindCertByHost

func (s *DbUtils) FindCertByHost(host string) (*Host, error)

FindCertByHost returns the host entry that terminates TLS for the server name host. An entry for the exact name beats a wildcard one, and a longer wildcard suffix a shorter one; among entries for the same name, one with TLS configured (a certificate or AutoSSL) wins, then the one with the shortest location, then the lowest id, so the choice never depends on map order. Names compare case-insensitively, ignoring a trailing dot.

func (*DbUtils) GetClient

func (s *DbUtils) GetClient(id int) (c *Client, err error)

func (*DbUtils) GetClientIdByBlake2bVkey added in v0.29.9

func (s *DbUtils) GetClientIdByBlake2bVkey(vkey string) (id int, err error)

func (*DbUtils) GetClientIdByMd5Vkey added in v0.27.0

func (s *DbUtils) GetClientIdByMd5Vkey(vkey string) (id int, err error)

func (*DbUtils) GetClientList

func (s *DbUtils) GetClientList(start, length int, search, sort, order string, clientId int) ([]*Client, int)

func (*DbUtils) GetGlobal

func (s *DbUtils) GetGlobal() (c *Glob)

func (*DbUtils) GetHost

func (s *DbUtils) GetHost(start, length int, id int, search string) ([]*Host, int)

func (*DbUtils) GetHostById

func (s *DbUtils) GetHostById(id int) (h *Host, err error)

func (*DbUtils) GetIdByVerifyKey

func (s *DbUtils) GetIdByVerifyKey(vKey, addr, localAddr string, hashFunc func(string) string) (id int, err error)

func (*DbUtils) GetInfoByHost

func (s *DbUtils) GetInfoByHost(host string, r *http.Request) (h *Host, err error)

GetInfoByHost get key by host from x

func (*DbUtils) GetTask

func (s *DbUtils) GetTask(id int) (t *Tunnel, err error)

func (*DbUtils) GetTaskByMd5Password

func (s *DbUtils) GetTaskByMd5Password(p string) (t *Tunnel)

GetTaskByMd5Password md5 password

func (*DbUtils) GetTaskByMd5PasswordOld added in v0.29.9

func (s *DbUtils) GetTaskByMd5PasswordOld(p string) (t *Tunnel)

func (*DbUtils) IsHostExist

func (s *DbUtils) IsHostExist(h *Host) bool

func (*DbUtils) IsHostModify

func (s *DbUtils) IsHostModify(h *Host) bool

func (*DbUtils) IsPubClient

func (s *DbUtils) IsPubClient(id int) bool

func (*DbUtils) NewClient

func (s *DbUtils) NewClient(c *Client) error

func (*DbUtils) NewHost

func (s *DbUtils) NewHost(t *Host) error

func (*DbUtils) NewTask

func (s *DbUtils) NewTask(t *Tunnel) error

NewTask adds t. A password explicitly set on a task created through the web or API that is already used by another task is rejected; for tasks delivered by a client configuration (NoStore) it is replaced by a random one, see reserveTaskPassword.

func (*DbUtils) RangeClientCertHosts added in v0.34.8

func (s *DbUtils) RangeClientCertHosts(clientID int, fn func(*Host) bool)

RangeClientCertHosts calls fn, until it returns false, for each host entry of the client clientID with a certificate configured.

func (*DbUtils) ReserveTaskPassword added in v0.34.8

func (s *DbUtils) ReserveTaskPassword(t *Tunnel) error

ReserveTaskPassword claims t.Password for t.Id under the same rules as NewTask and UpdateTask. It is used before an existing task is updated in place from t.

func (*DbUtils) SaveGlobal

func (s *DbUtils) SaveGlobal(t *Glob) error

func (*DbUtils) UpdateClient

func (s *DbUtils) UpdateClient(t *Client) error

func (*DbUtils) UpdateTask

func (s *DbUtils) UpdateTask(t *Tunnel) error

UpdateTask stores t in place of the task with the same id. t may be the stored object itself or an edited copy; the password the task held before is tracked separately and released when it changes. A rejected password leaves the stored task and the password index unchanged.

func (*DbUtils) VerifyUserName

func (s *DbUtils) VerifyUserName(username string, id int) (res bool)

func (*DbUtils) VerifyVkey

func (s *DbUtils) VerifyVkey(vkey string, id int) (res bool)

type Flow

type Flow struct {
	ExportFlow int64     // outbound traffic
	InletFlow  int64     // inbound traffic
	FlowLimit  int64     // traffic limit
	TimeLimit  time.Time // expire time
	sync.RWMutex
}

func (*Flow) Add

func (s *Flow) Add(in, out int64)

func (*Flow) AddOver added in v0.34.8

func (s *Flow) AddOver(in, out int64) (traffic, expired bool)

AddOver adds like Add and reports, under the same lock, whether the flow is then over its traffic limit or past its time limit.

func (*Flow) Over added in v0.34.8

func (s *Flow) Over() (traffic, expired bool)

Over reports whether the flow is over its traffic limit (FlowLimit MiB of inbound and outbound traffic together) or past its time limit. The fields are read under the lock, so that a 64-bit counter is never seen half written on 32-bit platforms.

func (*Flow) ResetTraffic added in v0.34.8

func (s *Flow) ResetTraffic()

ResetTraffic zeroes the inbound and outbound traffic.

func (*Flow) SetFlowLimit added in v0.34.8

func (s *Flow) SetFlowLimit(limit int64)

SetFlowLimit sets the traffic limit in MiB, 0 for none.

func (*Flow) SetLimits added in v0.34.8

func (s *Flow) SetLimits(flowLimit int64, timeLimit time.Time)

SetLimits sets the traffic limit in MiB and the time limit together.

func (*Flow) SetTimeLimit added in v0.34.8

func (s *Flow) SetTimeLimit(limit time.Time)

SetTimeLimit sets the time limit, the zero time for none.

func (*Flow) Sub added in v0.26.41

func (s *Flow) Sub(in, out int64)

type Glob

type Glob struct {
	BlackIpList []string
	sync.RWMutex
}

type Health

type Health struct {
	HealthCheckTimeout  int
	HealthMaxFail       int
	HealthCheckInterval int
	HealthNextTime      time.Time
	HealthMap           map[string]int
	HttpHealthUrl       string
	HealthRemoveArr     []string
	HealthCheckType     string
	HealthCheckTarget   string
	sync.RWMutex
}

type Host

type Host struct {
	Id               int
	Host             string // host
	HeaderChange     string // request header change
	RespHeaderChange string // response header change
	HostChange       string // host change
	Location         string // url router
	PathRewrite      string // url rewrite
	Remark           string // remark
	Scheme           string // http/https/all
	RedirectURL      string // 307
	HttpsJustProxy   bool
	TlsOffload       bool
	AutoSSL          bool
	CertType         string
	CertHash         string
	CertFile         string
	KeyFile          string
	NoStore          bool
	IsClose          bool
	AutoHttps        bool
	AutoCORS         bool
	CompatMode       bool
	Flow             *Flow
	NowConn          int32
	Client           *Client
	TargetIsHttps    bool
	Target           *Target
	UserAuth         *MultiAccount
	MultiAccount     *MultiAccount
	Health           `json:"-"`
	sync.RWMutex
}

func (*Host) AddConn added in v0.29.17

func (s *Host) AddConn()

func (*Host) CutConn added in v0.29.17

func (s *Host) CutConn()

func (*Host) HasCert added in v0.34.8

func (s *Host) HasCert() bool

HasCert reports whether the entry has a certificate configured.

func (*Host) Update added in v0.32.8

func (s *Host) Update(h *Host)

type JsonDb

type JsonDb struct {
	Tasks            sync.Map
	Hosts            sync.Map
	HostsTmp         sync.Map
	Clients          sync.Map
	Global           *Glob
	RunPath          string
	ClientIncreaseId int32  //client increased id
	TaskIncreaseId   int32  //task increased id
	HostIncreaseId   int32  //host increased id
	TaskFilePath     string //task file path
	HostFilePath     string //host file path
	ClientFilePath   string //client file path
	GlobalFilePath   string //global file path
}

func NewJsonDb

func NewJsonDb(runPath string) *JsonDb

func (*JsonDb) GetClient

func (s *JsonDb) GetClient(id int) (c *Client, err error)

func (*JsonDb) GetClientId

func (s *JsonDb) GetClientId() int32

func (*JsonDb) GetHostId

func (s *JsonDb) GetHostId() int32

func (*JsonDb) GetTaskId

func (s *JsonDb) GetTaskId() int32

func (*JsonDb) LoadClientFromJsonFile

func (s *JsonDb) LoadClientFromJsonFile()

func (*JsonDb) LoadGlobalFromJsonFile

func (s *JsonDb) LoadGlobalFromJsonFile()

func (*JsonDb) LoadHostFromJsonFile

func (s *JsonDb) LoadHostFromJsonFile()

func (*JsonDb) LoadTaskFromJsonFile

func (s *JsonDb) LoadTaskFromJsonFile()

func (*JsonDb) StoreClientsToJsonFile

func (s *JsonDb) StoreClientsToJsonFile() error

func (*JsonDb) StoreGlobalToJsonFile

func (s *JsonDb) StoreGlobalToJsonFile() error

func (*JsonDb) StoreHostToJsonFile

func (s *JsonDb) StoreHostToJsonFile() error

func (*JsonDb) StoreTasksToJsonFile

func (s *JsonDb) StoreTasksToJsonFile() error

type MultiAccount

type MultiAccount struct {
	Content    string
	AccountMap map[string]string // multi account and pwd
}

type Pair

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

Pair A data structure to hold a key/value pair.

type PairList

type PairList []*Pair

PairList A slice of Pairs that implements sort.Interface to sort by Value.

func (PairList) Len

func (p PairList) Len() int

func (PairList) Less

func (p PairList) Less(i, j int) bool

func (PairList) Swap

func (p PairList) Swap(i, j int)

type Target

type Target struct {
	TargetStr     string
	LocalProxy    bool
	ProxyProtocol int // 0=off, 1=v1, 2=v2

	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Target) GetRandomTarget

func (s *Target) GetRandomTarget() (string, error)

func (*Target) HasTarget added in v0.34.8

func (s *Target) HasTarget(addr string) bool

HasTarget reports whether addr is one of the configured targets.

func (*Target) RemoveTarget added in v0.34.8

func (s *Target) RemoveTarget(addr string) bool

RemoveTarget takes addr out of the rotation and reports whether it was present.

func (*Target) RestoreTarget added in v0.34.8

func (s *Target) RestoreTarget(addr string) bool

RestoreTarget puts addr back into the rotation if it is a configured target that is currently out of it, and reports whether it was restored.

type Tunnel

type Tunnel struct {
	Id           int
	Port         int
	ServerIp     string
	Mode         string
	Status       bool
	RunStatus    bool
	Client       *Client
	Ports        string
	Flow         *Flow
	NowConn      int32
	Password     string
	Remark       string
	TargetAddr   string
	TargetType   string
	DestAclMode  int              // 0=off, 1=whitelist, 2=blacklist
	DestAclRules string           // raw rules text
	DestAclSet   *common.ProxyACL `json:"-"`
	NoStore      bool
	IsHttp       bool
	HttpProxy    bool
	Socks5Proxy  bool
	LocalPath    string
	StripPre     string
	ReadOnly     bool
	Target       *Target
	UserAuth     *MultiAccount
	MultiAccount *MultiAccount
	Health
	sync.RWMutex
}

func NewTunnelByHost added in v0.33.9

func NewTunnelByHost(host *Host, port int) *Tunnel

func (*Tunnel) AddConn added in v0.29.17

func (t *Tunnel) AddConn()

func (*Tunnel) AllowsDestination added in v0.34.0

func (t *Tunnel) AllowsDestination(addr string) bool

func (*Tunnel) Clone added in v0.34.8

func (t *Tunnel) Clone() *Tunnel

Clone returns a copy of t that can be edited and then stored with UpdateTask without touching t until the update is accepted. Flow and the health state are copied; Client, Target and the account settings are shared and are expected to be replaced rather than modified.

func (*Tunnel) CompileDestACL added in v0.34.0

func (t *Tunnel) CompileDestACL()

func (*Tunnel) CutConn added in v0.29.17

func (t *Tunnel) CutConn()

func (*Tunnel) Update added in v0.32.8

func (t *Tunnel) Update(other *Tunnel)

Jump to

Keyboard shortcuts

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