xui

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client communicates with the 3x-ui panel API. It manages session-based authentication transparently.

func NewClient

func NewClient(cfg *config.Config, logger *slog.Logger) *Client

NewClient creates a new XUI API client.

func (*Client) AddClient

func (c *Client) AddClient(ctx context.Context, data map[string]any) (*Response, error)

AddClient adds a client to an inbound. data must contain "id" (inbound ID) and "settings" (JSON string with clients array).

func (*Client) ClearClientIPs

func (c *Client) ClearClientIPs(ctx context.Context, email string) (*Response, error)

ClearClientIPs clears recorded IP addresses for a client.

func (*Client) CreateInbound

func (c *Client) CreateInbound(ctx context.Context, data map[string]any) (*Response, error)

CreateInbound creates a new inbound. data should contain all inbound fields.

func (*Client) DeleteClient

func (c *Client) DeleteClient(ctx context.Context, inboundID int, clientID string) (*Response, error)

DeleteClient removes a client from an inbound by inbound ID and client UUID.

func (*Client) DeleteClientByEmail

func (c *Client) DeleteClientByEmail(ctx context.Context, inboundID int, email string) (*Response, error)

DeleteClientByEmail removes a client from an inbound by email.

func (*Client) DeleteDepletedClients

func (c *Client) DeleteDepletedClients(ctx context.Context, inboundID int) (*Response, error)

DeleteDepletedClients removes clients that exhausted their traffic/time.

func (*Client) DeleteInbound

func (c *Client) DeleteInbound(ctx context.Context, id int) (*Response, error)

DeleteInbound removes an inbound by ID.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string) (*Response, error)

Get performs an authenticated GET request.

func (*Client) GetClientIPs

func (c *Client) GetClientIPs(ctx context.Context, email string) (*Response, error)

GetClientIPs returns IP addresses recorded for a client.

func (*Client) GetClientTraffic

func (c *Client) GetClientTraffic(ctx context.Context, email string) (*Response, error)

GetClientTraffic returns traffic stats for a client by email.

func (*Client) GetClientTrafficByID

func (c *Client) GetClientTrafficByID(ctx context.Context, id string) (*Response, error)

GetClientTrafficByID returns traffic stats for a client by UUID.

func (*Client) GetDefaultXrayConfig

func (c *Client) GetDefaultXrayConfig(ctx context.Context) (*Response, error)

GetDefaultXrayConfig returns the default Xray configuration template.

func (*Client) GetInbound

func (c *Client) GetInbound(ctx context.Context, id int) (*Response, error)

GetInbound returns a single inbound by ID.

func (*Client) GetLastOnline

func (c *Client) GetLastOnline(ctx context.Context) (*Response, error)

GetLastOnline returns last online timestamps for all clients.

func (*Client) GetLogs

func (c *Client) GetLogs(ctx context.Context, count int, level, syslog string) (*Response, error)

GetLogs returns application logs.

func (*Client) GetOnlineClients

func (c *Client) GetOnlineClients(ctx context.Context) (*Response, error)

GetOnlineClients returns currently connected clients.

func (*Client) GetOutboundsTraffic

func (c *Client) GetOutboundsTraffic(ctx context.Context) (*Response, error)

GetOutboundsTraffic returns traffic statistics for all outbounds.

func (*Client) GetSettings

func (c *Client) GetSettings(ctx context.Context) (*Response, error)

GetSettings returns all panel settings.

func (*Client) GetXrayConfig

func (c *Client) GetXrayConfig(ctx context.Context) (*Response, error)

GetXrayConfig returns the current Xray JSON configuration.

func (*Client) GetXrayLogs

func (c *Client) GetXrayLogs(ctx context.Context, count int, filter string) (*Response, error)

GetXrayLogs returns Xray proxy logs with optional filtering.

func (*Client) GetXrayResult

func (c *Client) GetXrayResult(ctx context.Context) (*Response, error)

GetXrayResult returns the current Xray service operational status.

func (*Client) GetXrayTemplate

func (c *Client) GetXrayTemplate(ctx context.Context) (*Response, error)

GetXrayTemplate returns the current Xray template config, inbound tags, and test URL. Response obj contains: xraySetting (JSON string), inboundTags ([]string), outboundTestUrl (string).

func (*Client) GetXrayVersions

func (c *Client) GetXrayVersions(ctx context.Context) (*Response, error)

GetXrayVersions returns available Xray versions.

func (*Client) ImportInbound

func (c *Client) ImportInbound(ctx context.Context, jsonData string) (*Response, error)

ImportInbound imports an inbound from JSON data (form field "data").

func (*Client) InstallXray

func (c *Client) InstallXray(ctx context.Context, version string) (*Response, error)

InstallXray installs a specific Xray version.

func (*Client) ListInbounds

func (c *Client) ListInbounds(ctx context.Context) (*Response, error)

ListInbounds returns all inbounds configured on the panel.

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string) (*Response, error)

Post performs an authenticated POST with no body.

func (*Client) PostForm

func (c *Client) PostForm(ctx context.Context, path string, data url.Values) (*Response, error)

PostForm performs an authenticated POST with form-encoded body.

func (*Client) PostJSON

func (c *Client) PostJSON(ctx context.Context, path string, data any) (*Response, error)

PostJSON performs an authenticated POST with a JSON body.

func (*Client) ResetAllClientTraffics

func (c *Client) ResetAllClientTraffics(ctx context.Context, inboundID int) (*Response, error)

ResetAllClientTraffics resets traffic for all clients in an inbound.

func (*Client) ResetAllTraffics

func (c *Client) ResetAllTraffics(ctx context.Context) (*Response, error)

ResetAllTraffics resets all inbound traffic counters.

func (*Client) ResetClientTraffic

func (c *Client) ResetClientTraffic(ctx context.Context, inboundID int, email string) (*Response, error)

ResetClientTraffic resets traffic counters for a client within an inbound.

func (*Client) ResetOutboundTraffic

func (c *Client) ResetOutboundTraffic(ctx context.Context, tag string) (*Response, error)

ResetOutboundTraffic resets traffic counters for a specific outbound tag.

func (*Client) RestartPanel

func (c *Client) RestartPanel(ctx context.Context) (*Response, error)

RestartPanel restarts the 3x-ui panel itself.

func (*Client) RestartXray

func (c *Client) RestartXray(ctx context.Context) (*Response, error)

RestartXray restarts the Xray proxy service.

func (*Client) SearchInbounds

func (c *Client) SearchInbounds(ctx context.Context, query string) (*Response, error)

SearchInbounds searches inbounds (via query, not a standard API — reserved for extension).

func (*Client) ServerStatus

func (c *Client) ServerStatus(ctx context.Context) (*Response, error)

ServerStatus returns current server resource usage (CPU, RAM, disk, etc).

func (*Client) StopXray

func (c *Client) StopXray(ctx context.Context) (*Response, error)

StopXray stops the Xray proxy service.

func (*Client) TestOutbound

func (c *Client) TestOutbound(ctx context.Context, outbound string) (*Response, error)

TestOutbound tests an outbound configuration for connectivity.

func (*Client) UpdateClient

func (c *Client) UpdateClient(ctx context.Context, clientID string, data map[string]any) (*Response, error)

UpdateClient updates a client within an inbound. clientID is the UUID/ID of the client to update.

func (*Client) UpdateClientTraffic

func (c *Client) UpdateClientTraffic(ctx context.Context, email string, upload, download int64) (*Response, error)

UpdateClientTraffic sets specific traffic values for a client.

func (*Client) UpdateInbound

func (c *Client) UpdateInbound(ctx context.Context, id int, data map[string]any) (*Response, error)

UpdateInbound updates an existing inbound by ID.

func (*Client) UpdateSettings

func (c *Client) UpdateSettings(ctx context.Context, data map[string]any) (*Response, error)

UpdateSettings updates panel settings.

func (*Client) UpdateXrayTemplate

func (c *Client) UpdateXrayTemplate(ctx context.Context, xraySetting string, outboundTestUrl string) (*Response, error)

UpdateXrayTemplate saves a new Xray template configuration. xraySetting is the full Xray config as a JSON string.

type ClientConfig

type ClientConfig struct {
	ID         string `json:"id,omitempty"`
	Password   string `json:"password,omitempty"`
	Flow       string `json:"flow,omitempty"`
	Email      string `json:"email"`
	LimitIP    int    `json:"limitIp"`
	TotalGB    int64  `json:"totalGB"`
	ExpiryTime int64  `json:"expiryTime"`
	Enable     bool   `json:"enable"`
	TgID       int64  `json:"tgId"`
	SubID      string `json:"subId"`
	Comment    string `json:"comment,omitempty"`
	Reset      int    `json:"reset"`
}

ClientConfig represents a client within an inbound's settings JSON.

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"`
	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"`
}

Inbound represents a 3x-ui inbound connection.

type InboundSettings

type InboundSettings struct {
	Clients []ClientConfig `json:"clients"`
}

InboundSettings wraps the clients array within inbound settings JSON.

type Response

type Response struct {
	Success bool            `json:"success"`
	Msg     string          `json:"msg"`
	Obj     json.RawMessage `json:"obj"`
}

Response is the standard 3x-ui API response envelope.

Jump to

Keyboard shortcuts

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