mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 05:22:25 +00:00
minor changes
This commit is contained in:
parent
bea19a263d
commit
3ded4ee658
4 changed files with 157 additions and 171 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -6,8 +6,6 @@
|
|||
|
||||
# Ignore log files
|
||||
*.log
|
||||
access.log
|
||||
error.log
|
||||
|
||||
# Ignore temporary files
|
||||
tmp/
|
||||
|
|
|
@ -56,6 +56,9 @@
|
|||
.dark .ant-input-password-icon {
|
||||
color: var(--dark-color-text-primary);
|
||||
}
|
||||
.ant-collapse-content-box .ant-alert {
|
||||
margin-block-end: 12px;
|
||||
}
|
||||
</style>
|
||||
<body>
|
||||
<a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
|
||||
|
|
|
@ -42,6 +42,9 @@
|
|||
.ant-list-item>li {
|
||||
padding: 10px 20px !important;
|
||||
}
|
||||
.ant-collapse-content-box .ant-alert {
|
||||
margin-block-end: 12px;
|
||||
}
|
||||
</style>
|
||||
<body>
|
||||
<a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
|
||||
|
|
|
@ -58,13 +58,10 @@ var (
|
|||
client_ShPassword string
|
||||
client_TrPassword string
|
||||
client_Method string
|
||||
|
||||
)
|
||||
|
||||
|
||||
var userStates = make(map[int64]string)
|
||||
|
||||
|
||||
type LoginStatus byte
|
||||
|
||||
const (
|
||||
|
@ -73,8 +70,6 @@ const (
|
|||
EmptyTelegramUserID = int64(0)
|
||||
)
|
||||
|
||||
|
||||
|
||||
type Tgbot struct {
|
||||
inboundService InboundService
|
||||
settingService SettingService
|
||||
|
@ -83,7 +78,6 @@ type Tgbot struct {
|
|||
lastStatus *Status
|
||||
}
|
||||
|
||||
|
||||
func (t *Tgbot) NewTgbot() *Tgbot {
|
||||
return new(Tgbot)
|
||||
}
|
||||
|
@ -263,7 +257,7 @@ func (t *Tgbot) OnReceive() {
|
|||
}, th.AnyCommand())
|
||||
|
||||
botHandler.HandleCallbackQuery(func(_ *telego.Bot, query telego.CallbackQuery) {
|
||||
delete(userStates,query.Message.GetChat().ID)
|
||||
delete(userStates, query.Message.GetChat().ID)
|
||||
t.answerCallback(&query, checkAdmin(query.From.ID))
|
||||
}, th.AnyCallbackQueryWithMessage())
|
||||
|
||||
|
@ -499,7 +493,6 @@ func (t *Tgbot) sendResponse(chatId int64, msg string, onlyMessage, isAdmin bool
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func (t *Tgbot) randomLowerAndNum(length int) string {
|
||||
charset := "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||
bytes := make([]byte, length)
|
||||
|
@ -510,7 +503,6 @@ func (t *Tgbot) randomLowerAndNum(length int) string {
|
|||
return string(bytes)
|
||||
}
|
||||
|
||||
|
||||
func (t *Tgbot) randomShadowSocksPassword() string {
|
||||
array := make([]byte, 32)
|
||||
_, err := rand.Read(array)
|
||||
|
@ -520,7 +512,6 @@ func (t *Tgbot) randomShadowSocksPassword() string {
|
|||
return base64.StdEncoding.EncodeToString(array)
|
||||
}
|
||||
|
||||
|
||||
func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool) {
|
||||
chatId := callbackQuery.Message.GetChat().ID
|
||||
|
||||
|
@ -695,7 +686,7 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
|||
}
|
||||
message_text, err := t.BuildInboundClientDataMessage(inbound.Remark, inbound.Protocol)
|
||||
|
||||
t.addClient(chatId,message_text,messageId)
|
||||
t.addClient(chatId, message_text, messageId)
|
||||
t.sendCallbackAnswerTgBot(callbackQuery.ID, t.I18nBot("tgbot.answers.successfulOperation"))
|
||||
case "add_client_limit_traffic_in":
|
||||
if len(dataArray) >= 2 {
|
||||
|
@ -910,7 +901,7 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
|||
}
|
||||
message_text, err := t.BuildInboundClientDataMessage(inbound.Remark, inbound.Protocol)
|
||||
|
||||
t.addClient(chatId,message_text,messageId)
|
||||
t.addClient(chatId, message_text, messageId)
|
||||
t.sendCallbackAnswerTgBot(callbackQuery.ID, t.I18nBot("tgbot.answers.successfulOperation"))
|
||||
case "add_client_reset_exp_in":
|
||||
if len(dataArray) >= 2 {
|
||||
|
@ -1184,10 +1175,10 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
|||
client_SubID = t.randomLowerAndNum(16)
|
||||
client_Comment = ""
|
||||
client_Reset = 0
|
||||
client_Security="auto"
|
||||
client_ShPassword=t.randomShadowSocksPassword()
|
||||
client_TrPassword=t.randomLowerAndNum(10)
|
||||
client_Method=""
|
||||
client_Security = "auto"
|
||||
client_ShPassword = t.randomShadowSocksPassword()
|
||||
client_TrPassword = t.randomLowerAndNum(10)
|
||||
client_Method = ""
|
||||
|
||||
inboundId := dataArray[1]
|
||||
inboundIdInt, err := strconv.Atoi(inboundId)
|
||||
|
@ -1271,10 +1262,10 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
|||
client_SubID = t.randomLowerAndNum(16)
|
||||
client_Comment = ""
|
||||
client_Reset = 0
|
||||
client_Security="auto"
|
||||
client_ShPassword=t.randomShadowSocksPassword()
|
||||
client_TrPassword=t.randomLowerAndNum(10)
|
||||
client_Method=""
|
||||
client_Security = "auto"
|
||||
client_ShPassword = t.randomShadowSocksPassword()
|
||||
client_TrPassword = t.randomLowerAndNum(10)
|
||||
client_Method = ""
|
||||
|
||||
inbounds, err := t.getInboundsAddClient()
|
||||
if err != nil {
|
||||
|
@ -1410,7 +1401,7 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
|||
return
|
||||
}
|
||||
message_text, err := t.BuildInboundClientDataMessage(inbound.Remark, inbound.Protocol)
|
||||
t.addClient(chatId,message_text,messageId)
|
||||
t.addClient(chatId, message_text, messageId)
|
||||
t.sendCallbackAnswerTgBot(callbackQuery.ID, t.I18nBot("tgbot.answers.canceled", "Email=="+client_Email))
|
||||
case "add_client_submit_disable":
|
||||
client_Enable = false
|
||||
|
@ -1425,8 +1416,7 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func (t *Tgbot) BuildInboundClientDataMessage(inbound_remark string ,protocol model.Protocol) (string, error) {
|
||||
func (t *Tgbot) BuildInboundClientDataMessage(inbound_remark string, protocol model.Protocol) (string, error) {
|
||||
var message string
|
||||
|
||||
currentTime := time.Now()
|
||||
|
@ -1447,19 +1437,19 @@ func (t *Tgbot) BuildInboundClientDataMessage(inbound_remark string ,protocol mo
|
|||
traffic_value := ""
|
||||
if client_TotalGB == 0 {
|
||||
traffic_value = "♾️ Unlimited(Reset)"
|
||||
}else {
|
||||
} else {
|
||||
traffic_value = common.FormatTraffic(client_TotalGB)
|
||||
}
|
||||
|
||||
switch protocol {
|
||||
case model.VMESS, model.VLESS:
|
||||
message = t.I18nBot("tgbot.messages.inbound_client_data_id", "InboundRemark=="+inbound_remark,"ClientId=="+client_Id,"ClientEmail=="+client_Email,"ClientTraffic=="+traffic_value,"ClientExp=="+expiryTime,"ClientComment=="+client_Comment)
|
||||
message = t.I18nBot("tgbot.messages.inbound_client_data_id", "InboundRemark=="+inbound_remark, "ClientId=="+client_Id, "ClientEmail=="+client_Email, "ClientTraffic=="+traffic_value, "ClientExp=="+expiryTime, "ClientComment=="+client_Comment)
|
||||
|
||||
case model.Trojan:
|
||||
message = t.I18nBot("tgbot.messages.inbound_client_data_pass", "InboundRemark=="+inbound_remark,"ClientPass=="+client_TrPassword,"ClientEmail=="+client_Email,"ClientTraffic=="+traffic_value,"ClientExp=="+expiryTime,"ClientComment=="+client_Comment)
|
||||
message = t.I18nBot("tgbot.messages.inbound_client_data_pass", "InboundRemark=="+inbound_remark, "ClientPass=="+client_TrPassword, "ClientEmail=="+client_Email, "ClientTraffic=="+traffic_value, "ClientExp=="+expiryTime, "ClientComment=="+client_Comment)
|
||||
|
||||
case model.Shadowsocks:
|
||||
message = t.I18nBot("tgbot.messages.inbound_client_data_pass", "InboundRemark=="+inbound_remark,"ClientPass=="+client_ShPassword,"ClientEmail=="+client_Email,"ClientTraffic=="+traffic_value,"ClientExp=="+expiryTime,"ClientComment=="+client_Comment)
|
||||
message = t.I18nBot("tgbot.messages.inbound_client_data_pass", "InboundRemark=="+inbound_remark, "ClientPass=="+client_ShPassword, "ClientEmail=="+client_Email, "ClientTraffic=="+traffic_value, "ClientExp=="+expiryTime, "ClientComment=="+client_Comment)
|
||||
|
||||
default:
|
||||
return "", errors.New("unknown protocol")
|
||||
|
@ -1468,7 +1458,6 @@ func (t *Tgbot) BuildInboundClientDataMessage(inbound_remark string ,protocol mo
|
|||
return message, nil
|
||||
}
|
||||
|
||||
|
||||
func (t *Tgbot) BuildJSONForProtocol(protocol model.Protocol) (string, error) {
|
||||
var jsonString string
|
||||
|
||||
|
@ -1547,18 +1536,14 @@ func (t *Tgbot) BuildJSONForProtocol(protocol model.Protocol) (string, error) {
|
|||
return jsonString, nil
|
||||
}
|
||||
|
||||
|
||||
func (t *Tgbot) SubmitAddClient() (bool, error) {
|
||||
|
||||
|
||||
inbound, err := t.inboundService.GetInbound(receiver_inbound_ID)
|
||||
if err != nil {
|
||||
logger.Warning("getIboundClients run failed:", err)
|
||||
return false, errors.New(t.I18nBot("tgbot.answers.getInboundsFailed"))
|
||||
}
|
||||
|
||||
|
||||
|
||||
jsonString, err := t.BuildJSONForProtocol(inbound.Protocol)
|
||||
|
||||
newInbound := &model.Inbound{
|
||||
|
@ -1566,7 +1551,6 @@ func (t *Tgbot) SubmitAddClient() (bool, error) {
|
|||
Settings: jsonString,
|
||||
}
|
||||
|
||||
|
||||
return t.inboundService.AddInboundClient(newInbound)
|
||||
}
|
||||
|
||||
|
@ -1862,7 +1846,7 @@ func (t *Tgbot) getInbounds() (*telego.InlineKeyboardMarkup, error) {
|
|||
if inbound.Enable {
|
||||
status = "✅"
|
||||
}
|
||||
callbackData := t.encodeQuery(fmt.Sprintf("%s %d","get_clients", 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))
|
||||
}
|
||||
|
||||
|
@ -1904,7 +1888,7 @@ func (t *Tgbot) getInboundsAddClient() (*telego.InlineKeyboardMarkup, error) {
|
|||
if inbound.Enable {
|
||||
status = "✅"
|
||||
}
|
||||
callbackData := t.encodeQuery(fmt.Sprintf("%s %d","add_client_to", inbound.Id))
|
||||
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))
|
||||
}
|
||||
|
||||
|
@ -2662,7 +2646,6 @@ func (t *Tgbot) editMessageTgBot(chatId int64, messageID int, text string, inlin
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func (t *Tgbot) SendMsgToTgbotDeleteAfter(chatId int64, msg string, delayInSeconds int, replyMarkup ...telego.ReplyMarkup) {
|
||||
// Determine if replyMarkup was passed; otherwise, set it to nil
|
||||
var replyMarkupParam telego.ReplyMarkup
|
||||
|
@ -2706,4 +2689,3 @@ func (t *Tgbot) isSingleWord(text string) bool {
|
|||
re := regexp.MustCompile(`\s+`)
|
||||
return re.MatchString(text)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue