client

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateShortIDs

func GenerateShortIDs() []string

GenerateShortIDs generates short IDs based on a predefined sequence and lengths

func GenerateVLESSLink(inbound Inbound, email string) (string, error)

GenerateVLESSLink generates a VLESS link for the given inbound and email It was rewritten from 3xui JS script https://github.com/MHSanaei/3x-ui/blob/2ce9c3cc81799b954441e665e9661a20bc69f8c3/web/assets/js/model/inbound.js#L1364

Types

type APIResponse

type APIResponse[T any] struct {
	Success bool   `json:"success"`
	Msg     string `json:"msg"`
	Obj     T      `json:"obj"`
}

type AddInboundClientConfig

type AddInboundClientConfig struct {
	Clients []InboundClient `json:"clients"`
}

AddInboundClientConfig represents the settings field in the addClient payload

type AddInboundClientPayload

type AddInboundClientPayload struct {
	ID       int                    `json:"id"`
	Settings AddInboundClientConfig `json:"settings"`
}

AddInboundClientPayload represents the payload for the addClient API

type AddInboundPayload

type AddInboundPayload struct {
	Up             int64  `json:"up"`
	Down           int64  `json:"down"`
	Total          int64  `json:"total"`
	Remark         string `json:"remark"`
	Enable         bool   `json:"enable"`
	ExpiryTime     int64  `json:"expiryTime"`
	Listen         string `json:"listen"`
	Port           int    `json:"port"`
	Protocol       string `json:"protocol"`
	Settings       string `json:"settings"`       // JSON string
	StreamSettings string `json:"streamSettings"` // JSON string
	Sniffing       string `json:"sniffing"`       // JSON string
	Allocate       string `json:"allocate"`       // JSON string
}

AddInboundPayload represents the payload for the Add Inbound API

type AddInboundRealitySettings

type AddInboundRealitySettings struct {
	Show        bool     `json:"show"`
	Xver        int      `json:"xver"`
	Dest        string   `json:"dest"`
	ServerNames []string `json:"serverNames"`
	PrivateKey  string   `json:"privateKey"`
	ShortIDs    []string `json:"shortIds"`
	Settings    struct {
		PublicKey   string `json:"publicKey"`
		Fingerprint string `json:"fingerprint"`
		ServerName  string `json:"serverName"`
		SpiderX     string `json:"spiderX"`
	} `json:"settings"`
}

AddInboundRealitySettings represents reality-specific stream settings

type AddInboundSettings

type AddInboundSettings struct {
	Clients    []Client `json:"clients"`
	Decryption string   `json:"decryption"`
	Fallbacks  []string `json:"fallbacks"`
}

AddInboundSettings represents the parsed settings for an inbound

type AddInboundStreamSettings

type AddInboundStreamSettings struct {
	Network         string                    `json:"network"`
	Security        string                    `json:"security"`
	ExternalProxy   []string                  `json:"externalProxy"`
	RealitySettings AddInboundRealitySettings `json:"realitySettings"`
	TCPSettings     AddInboundTCPSettings     `json:"tcpSettings"`
}

AddInboundStreamSettings represents the stream settings for an inbound

type AddInboundTCPSettings

type AddInboundTCPSettings struct {
	AcceptProxyProtocol bool `json:"acceptProxyProtocol"`
	Header              struct {
		Type string `json:"type"`
	} `json:"header"`
}

AddInboundTCPSettings represents TCP-specific settings

type CertificateResponse

type CertificateResponse struct {
	PrivateKey string `json:"privateKey"`
	PublicKey  string `json:"publicKey"`
}

CertificateResponse represents the response from /server/getNewX25519Cert

type Client

type Client struct {
	BaseURL       string
	Logger        *slog.Logger
	Resty         *resty.Client
	Username      string
	Password      string
	LastLoginTime time.Time
	// contains filtered or unexported fields
}

func NewClient

func NewClient(baseURL, username, password string, insecure bool, logger *slog.Logger) *Client

func (*Client) AddInbound

func (c *Client) AddInbound(payload AddInboundPayload) (*Inbound, error)

func (*Client) AddInboundClient

func (c *Client) AddInboundClient(inboundID int, clientConfig InboundClient) error

AddInboundClient adds a new client to the specified inbound

func (*Client) GenerateDefaultInboundClient

func (c *Client) GenerateDefaultInboundClient(email string, tgID int64) InboundClient

GenerateDefaultInboundClient creates a default client configuration for adding a client

func (*Client) GenerateDefaultInboundConfig

func (c *Client) GenerateDefaultInboundConfig(remark, realityCover, listenIP string, port int) (AddInboundPayload, error)

func (*Client) GetNewCertificate

func (c *Client) GetNewCertificate() (CertificateResponse, error)

GetNewCertificate fetches a new X25519 certificate from the server

func (*Client) GetOnlineClients

func (c *Client) GetOnlineClients() (OnlinesResponse, error)

GetOnlineClients fetches the list of online clients.

func (*Client) ListInbounds

func (c *Client) ListInbounds() ([]Inbound, error)

ListInbounds fetches the list of inbounds.

func (*Client) Login

func (c *Client) Login() error

type ClientStats

type ClientStats struct {
	ID         int    `json:"id"`
	InboundID  int    `json:"inboundId"`
	Enable     bool   `json:"enable"`
	Email      string `json:"email"`
	Up         int64  `json:"up"`
	Down       int64  `json:"down"`
	ExpiryTime int64  `json:"expiryTime"`
	Total      int64  `json:"total"`
	Reset      int64  `json:"reset"`
}

ClientStats represents individual client statistics within an inbound.

type FetchCertificateResponse

type FetchCertificateResponse struct {
	Success bool                `json:"success"`
	Msg     string              `json:"msg"`
	Obj     CertificateResponse `json:"obj"`
}

FetchCertificateResponse wraps the API response

type FlexibleInt64 added in v0.0.3

type FlexibleInt64 struct {
	Value *int64
}

FlexibleInt64 handles fields that could be either a string or an int64 It's not a great way, but this is what chatGPT created for me. It's 5 in the morning, I'm sorry.

func (*FlexibleInt64) UnmarshalJSON added in v0.0.3

func (f *FlexibleInt64) UnmarshalJSON(data []byte) error

UnmarshalJSON custom unmarshaler for FlexibleInt64

type Inbound

type Inbound struct {
	ID             int           `json:"id"`
	Up             int64         `json:"up"`
	Down           int64         `json:"down"`
	Total          int64         `json:"total"`
	Remark         string        `json:"remark"`
	Enable         bool          `json:"enable"`
	ExpiryTime     int64         `json:"expiryTime"`
	ClientStats    []ClientStats `json:"clientStats"`
	Listen         string        `json:"listen"`
	Port           int           `json:"port"`
	Protocol       string        `json:"protocol"`
	Settings       string        `json:"settings"`
	StreamSettings string        `json:"streamSettings"`
	Tag            string        `json:"tag"`
	Sniffing       string        `json:"sniffing"`
	Allocate       string        `json:"allocate"`
}

Inbound represents a single inbound entry.

type InboundClient

type InboundClient struct {
	ID         string        `json:"id"`
	Flow       string        `json:"flow"`
	Email      string        `json:"email"`
	LimitIP    int           `json:"limitIp"`
	TotalGB    int           `json:"totalGB"`
	ExpiryTime int64         `json:"expiryTime"`
	Enable     bool          `json:"enable"`
	TgID       FlexibleInt64 `json:"tgId"`
	SubID      string        `json:"subId"`
	Reset      int           `json:"reset"`
}

InboundClient represents a single client to be added to an inbound

type InboundSettings

type InboundSettings struct {
	Clients    []InboundClient `json:"clients"`
	Decryption string          `json:"decryption"`
	Fallbacks  []string        `json:"fallbacks"`
}

InboundSettings represents the parsed settings for an inbound

type OnlinesResponse

type OnlinesResponse []string

OnlinesResponse represents the `inbound/onlines` response object.

Jump to

Keyboard shortcuts

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