Skip to content

MyBlackJay/go3xui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go3xui

go3xui is a Go client library for interacting with the 3x-ui panel via its API. The project is currently under active development and does not yet cover the full functionality of the panel.

At this stage, the library supports client-related operations, including the following methods.

📌 Supported Features

  1. GetTrafficsByEmail — retrieve detailed information about a client by email (includes traffic statistics and related data)
  2. GetTrafficsByID — retrieve detailed information about a client by UUID
  3. GetIpsByEmail — fetch the IP history associated with a client by email
  4. Add — add a new client to a specific inbound by its ID
  5. Update — update an existing client identified by UUID within a specific inbound
  6. Delete — delete a client by UUID and inbound ID
  7. Online — get IDs of currently online users
  8. ResetStats — reset the IP history associated with a client by email

The goal of the project is to provide a clean, safe, and convenient interface for automating the management of 3x-ui.

🚧 Project Status

⚠️ In development — interfaces and internal structure may change. Use at your own risk.

Pull requests and feedback are welcome!

Example:

package main

import (
	"context"
	"fmt"
	"go3xui/pkg/api"
	"go3xui/pkg/model"
	"go3xui/pkg/utils"
	"time"
)

var cfg = api.ConnectionConfig{
	Host:     "http://127.0.0.1:2053/admin",
	Username: "test",
	Password: "test",
}

func Login() error {

	a, err := api.NewBaseApi(cfg)
	if err != nil {
		return err
	}

	return a.Login(context.Background(), "")
}

func GetTrafficsByEmail() error {
	a, err := api.NewBaseApi(cfg)
	if err != nil {
		return err
	}

	err = a.Login(context.Background(), "")
	if err != nil {
		return err
	}

	client := api.NewClientApi(a)

	if traffic, err := client.GetTrafficsByEmail(context.Background(), "test"); err != nil {
		return err
	} else {
		fmt.Println(traffic)
	}

	return nil
}

func GetTrafficsByID() error {
	a, err := api.NewBaseApi(cfg)
	if err != nil {
		return err
	}

	err = a.Login(context.Background(), "")
	if err != nil {
		return err
	}

	client := api.NewClientApi(a)

	if traffic, err := client.GetTrafficsByID(context.Background(), "bbfad557-28f2-47e5-9f3d-e3c7f532fbda"); err != nil {
		return err
	} else {
		fmt.Println(traffic)
	}

	return nil
}

func Add() error {
	a, err := api.NewBaseApi(cfg)
	if err != nil {
		return err
	}

	err = a.Login(context.Background(), "")
	if err != nil {
		return err
	}

	client := api.NewClientApi(a)

	cl := []*model.Client{{
		Flow:       utils.FlowVision,
		Email:      "dp1plmlt89",
		Id:         "bbfad557-28f2-47e5-9f3d-e3c7f532fbda",
		Enable:     false,
		SubId:      "2rv0gb458kbfl532",
		ExpiryTime: time.Now().Add(time.Hour * 24 * 5).UnixMilli(),
	}}

	return client.Add(context.Background(), 1, cl)
}

func Update() error {
	a, err := api.NewBaseApi(cfg)
	if err != nil {
		return err
	}

	err = a.Login(context.Background(), "")
	if err != nil {
		return err
	}

	client := api.NewClientApi(a)

	cl := model.Client{
		Flow:       utils.FlowVision,
		Email:      "dp1plmlt89",
		Id:         "bbfad557-28f2-47e5-9f3d-e3c7f532fbda",
		Enable:     true,
		SubId:      "2rv0gb458kbfl532",
		ExpiryTime: time.Now().Add(time.Hour * 24 * 5).UnixMilli(),
	}

	return client.Update(context.Background(), 1, &cl)
}

func Delete() error {
	a, err := api.NewBaseApi(cfg)
	if err != nil {
		return err
	}

	err = a.Login(context.Background(), "")
	if err != nil {
		return err
	}

	client := api.NewClientApi(a)

	return client.Delete(context.Background(), 1, "bbfad557-28f2-47e5-9f3d-e3c7f532fbda")
}

func Online() error {
	a, err := api.NewBaseApi(cfg)
	if err != nil {
		return err
	}

	err = a.Login(context.Background(), "")
	if err != nil {
		return err
	}

	client := api.NewClientApi(a)

	_, err = client.Online(context.Background())

	return err
}

func ResetIps() error {
	a, err := api.NewBaseApi(cfg)
	if err != nil {
		return err
	}

	err = a.Login(context.Background(), "")
	if err != nil {
		return err
	}

	client := api.NewClientApi(a)

	return client.ResetIps(context.Background(), "test")
}

func ResetStats() error {
	a, err := api.NewBaseApi(cfg)
	if err != nil {
		return err
	}

	err = a.Login(context.Background(), "")
	if err != nil {
		return err
	}

	client := api.NewClientApi(a)

	return client.ResetIps(context.Background(), "test")
}


func main() {
	_ = Login()
	_ = GetTrafficsByEmail()
	_ = Delete()
	_ = Add()
	_ = Update()
	_ = Online()
	_ = ResetIps()
	_ = ResetStats()
}

🧭 Roadmap

  • Full API coverage for 3x-ui
  • High-level wrappers for common operations

💸 Donations

If you find this project useful and want to support its development:

  1. TON (Toncoin): UQBaeaCSvLpG2xKdzQQem8j1oqTU-Zimrn8z9p1Lw-wsraU2
  2. USDT (TRC20): TCEHVwRweaEyy9kGTYR5g6Rgy66CxiP6Uj
  3. Bitcoin (BTC): 1CCyT6HKvK8P3Dwjb8i59nzyBbf3GpjVyx

Thank you for your support 🙏

About

Go client library for interacting with the 3x-ui panel via its API.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages