|
|
@@ -58,13 +58,10 @@ var (
|
|
|
|
client_ShPassword string
|
|
|
|
client_ShPassword string
|
|
|
|
client_TrPassword string
|
|
|
|
client_TrPassword string
|
|
|
|
client_Method string
|
|
|
|
client_Method string
|
|
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var userStates = make(map[int64]string)
|
|
|
|
var userStates = make(map[int64]string)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type LoginStatus byte
|
|
|
|
type LoginStatus byte
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
const (
|
|
|
@@ -73,8 +70,6 @@ const (
|
|
|
|
EmptyTelegramUserID = int64(0)
|
|
|
|
EmptyTelegramUserID = int64(0)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type Tgbot struct {
|
|
|
|
type Tgbot struct {
|
|
|
|
inboundService InboundService
|
|
|
|
inboundService InboundService
|
|
|
|
settingService SettingService
|
|
|
|
settingService SettingService
|
|
|
@@ -83,7 +78,6 @@ type Tgbot struct {
|
|
|
|
lastStatus *Status
|
|
|
|
lastStatus *Status
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (t *Tgbot) NewTgbot() *Tgbot {
|
|
|
|
func (t *Tgbot) NewTgbot() *Tgbot {
|
|
|
|
return new(Tgbot)
|
|
|
|
return new(Tgbot)
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -499,7 +493,6 @@ func (t *Tgbot) sendResponse(chatId int64, msg string, onlyMessage, isAdmin bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (t *Tgbot) randomLowerAndNum(length int) string {
|
|
|
|
func (t *Tgbot) randomLowerAndNum(length int) string {
|
|
|
|
charset := "abcdefghijklmnopqrstuvwxyz0123456789"
|
|
|
|
charset := "abcdefghijklmnopqrstuvwxyz0123456789"
|
|
|
|
bytes := make([]byte, length)
|
|
|
|
bytes := make([]byte, length)
|
|
|
@@ -510,7 +503,6 @@ func (t *Tgbot) randomLowerAndNum(length int) string {
|
|
|
|
return string(bytes)
|
|
|
|
return string(bytes)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (t *Tgbot) randomShadowSocksPassword() string {
|
|
|
|
func (t *Tgbot) randomShadowSocksPassword() string {
|
|
|
|
array := make([]byte, 32)
|
|
|
|
array := make([]byte, 32)
|
|
|
|
_, err := rand.Read(array)
|
|
|
|
_, err := rand.Read(array)
|
|
|
@@ -520,7 +512,6 @@ func (t *Tgbot) randomShadowSocksPassword() string {
|
|
|
|
return base64.StdEncoding.EncodeToString(array)
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
@@ -1425,7 +1416,6 @@ 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
|
|
|
|
var message string
|
|
|
|
|
|
|
|
|
|
|
@@ -1468,7 +1458,6 @@ func (t *Tgbot) BuildInboundClientDataMessage(inbound_remark string ,protocol mo
|
|
|
|
return message, nil
|
|
|
|
return message, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (t *Tgbot) BuildJSONForProtocol(protocol model.Protocol) (string, error) {
|
|
|
|
func (t *Tgbot) BuildJSONForProtocol(protocol model.Protocol) (string, error) {
|
|
|
|
var jsonString string
|
|
|
|
var jsonString string
|
|
|
|
|
|
|
|
|
|
|
@@ -1547,18 +1536,14 @@ func (t *Tgbot) BuildJSONForProtocol(protocol model.Protocol) (string, error) {
|
|
|
|
return jsonString, nil
|
|
|
|
return jsonString, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (t *Tgbot) SubmitAddClient() (bool, error) {
|
|
|
|
func (t *Tgbot) SubmitAddClient() (bool, error) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inbound, err := t.inboundService.GetInbound(receiver_inbound_ID)
|
|
|
|
inbound, err := t.inboundService.GetInbound(receiver_inbound_ID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
logger.Warning("getIboundClients run failed:", err)
|
|
|
|
logger.Warning("getIboundClients run failed:", err)
|
|
|
|
return false, errors.New(t.I18nBot("tgbot.answers.getInboundsFailed"))
|
|
|
|
return false, errors.New(t.I18nBot("tgbot.answers.getInboundsFailed"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jsonString, err := t.BuildJSONForProtocol(inbound.Protocol)
|
|
|
|
jsonString, err := t.BuildJSONForProtocol(inbound.Protocol)
|
|
|
|
|
|
|
|
|
|
|
|
newInbound := &model.Inbound{
|
|
|
|
newInbound := &model.Inbound{
|
|
|
@@ -1566,7 +1551,6 @@ func (t *Tgbot) SubmitAddClient() (bool, error) {
|
|
|
|
Settings: jsonString,
|
|
|
|
Settings: jsonString,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return t.inboundService.AddInboundClient(newInbound)
|
|
|
|
return t.inboundService.AddInboundClient(newInbound)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@@ -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) {
|
|
|
|
func (t *Tgbot) SendMsgToTgbotDeleteAfter(chatId int64, msg string, delayInSeconds int, replyMarkup ...telego.ReplyMarkup) {
|
|
|
|
// Determine if replyMarkup was passed; otherwise, set it to nil
|
|
|
|
// Determine if replyMarkup was passed; otherwise, set it to nil
|
|
|
|
var replyMarkupParam telego.ReplyMarkup
|
|
|
|
var replyMarkupParam telego.ReplyMarkup
|
|
|
@@ -2706,4 +2689,3 @@ func (t *Tgbot) isSingleWord(text string) bool {
|
|
|
|
re := regexp.MustCompile(`\s+`)
|
|
|
|
re := regexp.MustCompile(`\s+`)
|
|
|
|
return re.MatchString(text)
|
|
|
|
return re.MatchString(text)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|