mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 21:42:24 +00:00
- Add client variables: client_method, client_sh_password, client_tr_password
- Exclude specific inbound protocols (HTTP, WireGuard, Socks, DOKODEMO) from addclient inline button
This commit is contained in:
parent
698c1be3bb
commit
27fca74d10
1 changed files with 67 additions and 9 deletions
|
@ -3,6 +3,7 @@ package service
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"embed"
|
"embed"
|
||||||
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
@ -52,6 +53,11 @@ var (
|
||||||
client_SubID string
|
client_SubID string
|
||||||
client_Comment string
|
client_Comment string
|
||||||
client_Reset int
|
client_Reset int
|
||||||
|
client_security string
|
||||||
|
client_ShPassword string
|
||||||
|
client_TrPassword string
|
||||||
|
client_method string
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -424,6 +430,17 @@ func (t *Tgbot) randomLowerAndNum(length int) string {
|
||||||
return string(bytes)
|
return string(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (t *Tgbot) randomShadowSocksPassword() string {
|
||||||
|
array := make([]byte, 32)
|
||||||
|
_, err := rand.Read(array)
|
||||||
|
if err != nil {
|
||||||
|
return t.randomLowerAndNum(32)
|
||||||
|
}
|
||||||
|
return base64.StdEncoding.EncodeToString(array)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool) {
|
func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool) {
|
||||||
chatId := callbackQuery.Message.GetChat().ID
|
chatId := callbackQuery.Message.GetChat().ID
|
||||||
|
|
||||||
|
@ -931,6 +948,10 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
||||||
client_SubID = t.randomLowerAndNum(16)
|
client_SubID = t.randomLowerAndNum(16)
|
||||||
client_Comment = ""
|
client_Comment = ""
|
||||||
client_Reset = 0
|
client_Reset = 0
|
||||||
|
client_security="auto"
|
||||||
|
client_ShPassword=t.randomShadowSocksPassword()
|
||||||
|
client_TrPassword=t.randomLowerAndNum(10)
|
||||||
|
client_method=""
|
||||||
|
|
||||||
inboundId := dataArray[1]
|
inboundId := dataArray[1]
|
||||||
inboundIdInt, err := strconv.Atoi(inboundId)
|
inboundIdInt, err := strconv.Atoi(inboundId)
|
||||||
|
@ -1014,6 +1035,9 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
||||||
client_SubID = t.randomLowerAndNum(16)
|
client_SubID = t.randomLowerAndNum(16)
|
||||||
client_Comment = ""
|
client_Comment = ""
|
||||||
client_Reset = 0
|
client_Reset = 0
|
||||||
|
client_ShPassword=t.randomShadowSocksPassword()
|
||||||
|
client_TrPassword=t.randomLowerAndNum(10)
|
||||||
|
client_method=""
|
||||||
|
|
||||||
inbounds, err := t.getInboundsAddClient()
|
inbounds, err := t.getInboundsAddClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1389,7 +1413,7 @@ func (t *Tgbot) getInboundUsages() string {
|
||||||
}
|
}
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
func (t *Tgbot) getInboundsKeyboard(action string) (*telego.InlineKeyboardMarkup, error) {
|
func (t *Tgbot) getInbounds() (*telego.InlineKeyboardMarkup, error) {
|
||||||
inbounds, err := t.inboundService.GetAllInbounds()
|
inbounds, err := t.inboundService.GetAllInbounds()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warning("GetAllInbounds run failed:", err)
|
logger.Warning("GetAllInbounds run failed:", err)
|
||||||
|
@ -1407,11 +1431,11 @@ func (t *Tgbot) getInboundsKeyboard(action string) (*telego.InlineKeyboardMarkup
|
||||||
if inbound.Enable {
|
if inbound.Enable {
|
||||||
status = "✅"
|
status = "✅"
|
||||||
}
|
}
|
||||||
callbackData := t.encodeQuery(fmt.Sprintf("%s %d", action, inbound.Id))
|
callbackData := t.encodeQuery(fmt.Sprintf("%s %d","get_clients", inbound.Id))
|
||||||
buttons = append(buttons, tu.InlineKeyboardButton(fmt.Sprintf("%v - %v", inbound.Remark, status)).WithCallbackData(callbackData))
|
buttons = append(buttons, tu.InlineKeyboardButton(fmt.Sprintf("%v - %v", inbound.Remark, status)).WithCallbackData(callbackData))
|
||||||
}
|
}
|
||||||
|
|
||||||
cols := 3
|
cols := 1
|
||||||
if len(buttons) >= 6 {
|
if len(buttons) >= 6 {
|
||||||
cols = 2
|
cols = 2
|
||||||
}
|
}
|
||||||
|
@ -1420,12 +1444,46 @@ func (t *Tgbot) getInboundsKeyboard(action string) (*telego.InlineKeyboardMarkup
|
||||||
return keyboard, nil
|
return keyboard, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tgbot) getInbounds() (*telego.InlineKeyboardMarkup, error) {
|
func (t *Tgbot) getInboundsAddClient() (*telego.InlineKeyboardMarkup, error) {
|
||||||
return t.getInboundsKeyboard("get_clients")
|
inbounds, err := t.inboundService.GetAllInbounds()
|
||||||
|
if err != nil {
|
||||||
|
logger.Warning("GetAllInbounds run failed:", err)
|
||||||
|
return nil, errors.New(t.I18nBot("tgbot.answers.getInboundsFailed"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tgbot) getInboundsAddClient() (*telego.InlineKeyboardMarkup, error) {
|
if len(inbounds) == 0 {
|
||||||
return t.getInboundsKeyboard("add_client_to")
|
logger.Warning("No inbounds found")
|
||||||
|
return nil, errors.New(t.I18nBot("tgbot.answers.getInboundsFailed"))
|
||||||
|
}
|
||||||
|
|
||||||
|
excludedProtocols := map[model.Protocol]bool{
|
||||||
|
model.DOKODEMO: true,
|
||||||
|
model.Socks: true,
|
||||||
|
model.WireGuard: true,
|
||||||
|
model.HTTP: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
var buttons []telego.InlineKeyboardButton
|
||||||
|
for _, inbound := range inbounds {
|
||||||
|
if excludedProtocols[inbound.Protocol] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
status := "❌"
|
||||||
|
if inbound.Enable {
|
||||||
|
status = "✅"
|
||||||
|
}
|
||||||
|
callbackData := t.encodeQuery(fmt.Sprintf("%s %d","add_client_to", inbound.Id))
|
||||||
|
buttons = append(buttons, tu.InlineKeyboardButton(fmt.Sprintf("%v - %v", inbound.Remark, status)).WithCallbackData(callbackData))
|
||||||
|
}
|
||||||
|
|
||||||
|
cols := 1
|
||||||
|
if len(buttons) >= 6 {
|
||||||
|
cols = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
keyboard := tu.InlineKeyboardGrid(tu.InlineKeyboardCols(cols, buttons...))
|
||||||
|
return keyboard, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tgbot) getInboundClients(id int) (*telego.InlineKeyboardMarkup, error) {
|
func (t *Tgbot) getInboundClients(id int) (*telego.InlineKeyboardMarkup, error) {
|
||||||
|
|
Loading…
Reference in a new issue