mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 21:42:24 +00:00
socks5 proxy option added to telegram bot settings (#1500)
* socks5 option added to telegram bot settings * update socks5 proxy settings translations
This commit is contained in:
parent
c76199514a
commit
5e3478f1c1
13 changed files with 54 additions and 3 deletions
2
go.mod
2
go.mod
|
@ -13,6 +13,7 @@ require (
|
||||||
github.com/pelletier/go-toml/v2 v2.1.1
|
github.com/pelletier/go-toml/v2 v2.1.1
|
||||||
github.com/robfig/cron/v3 v3.0.1
|
github.com/robfig/cron/v3 v3.0.1
|
||||||
github.com/shirou/gopsutil/v3 v3.23.12
|
github.com/shirou/gopsutil/v3 v3.23.12
|
||||||
|
github.com/valyala/fasthttp v1.51.0
|
||||||
github.com/xtls/xray-core v1.8.6
|
github.com/xtls/xray-core v1.8.6
|
||||||
go.uber.org/atomic v1.11.0
|
go.uber.org/atomic v1.11.0
|
||||||
golang.org/x/text v0.14.0
|
golang.org/x/text v0.14.0
|
||||||
|
@ -75,7 +76,6 @@ require (
|
||||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||||
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e // indirect
|
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e // indirect
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
github.com/valyala/fasthttp v1.51.0 // indirect
|
|
||||||
github.com/vishvananda/netlink v1.2.1-beta.2.0.20230316163032-ced5aaba43e3 // indirect
|
github.com/vishvananda/netlink v1.2.1-beta.2.0.20230316163032-ced5aaba43e3 // indirect
|
||||||
github.com/vishvananda/netns v0.0.4 // indirect
|
github.com/vishvananda/netns v0.0.4 // indirect
|
||||||
github.com/xtls/reality v0.0.0-20231112171332-de1173cf2b19 // indirect
|
github.com/xtls/reality v0.0.0-20231112171332-de1173cf2b19 // indirect
|
||||||
|
|
|
@ -15,6 +15,7 @@ class AllSetting {
|
||||||
this.datepicker = "gregorian";
|
this.datepicker = "gregorian";
|
||||||
this.tgBotEnable = false;
|
this.tgBotEnable = false;
|
||||||
this.tgBotToken = "";
|
this.tgBotToken = "";
|
||||||
|
this.tgBotProxy = "";
|
||||||
this.tgBotChatId = "";
|
this.tgBotChatId = "";
|
||||||
this.tgRunTime = "@daily";
|
this.tgRunTime = "@daily";
|
||||||
this.tgBotBackup = false;
|
this.tgBotBackup = false;
|
||||||
|
|
|
@ -28,6 +28,7 @@ type AllSetting struct {
|
||||||
RemarkModel string `json:"remarkModel" form:"remarkModel"`
|
RemarkModel string `json:"remarkModel" form:"remarkModel"`
|
||||||
TgBotEnable bool `json:"tgBotEnable" form:"tgBotEnable"`
|
TgBotEnable bool `json:"tgBotEnable" form:"tgBotEnable"`
|
||||||
TgBotToken string `json:"tgBotToken" form:"tgBotToken"`
|
TgBotToken string `json:"tgBotToken" form:"tgBotToken"`
|
||||||
|
TgBotProxy string `json:"tgBotProxy" form:"tgBotProxy"`
|
||||||
TgBotChatId string `json:"tgBotChatId" form:"tgBotChatId"`
|
TgBotChatId string `json:"tgBotChatId" form:"tgBotChatId"`
|
||||||
TgRunTime string `json:"tgRunTime" form:"tgRunTime"`
|
TgRunTime string `json:"tgRunTime" form:"tgRunTime"`
|
||||||
TgBotBackup bool `json:"tgBotBackup" form:"tgBotBackup"`
|
TgBotBackup bool `json:"tgBotBackup" form:"tgBotBackup"`
|
||||||
|
|
|
@ -264,6 +264,7 @@
|
||||||
<setting-list-item type="switch" title='{{ i18n "pages.settings.tgNotifyBackup" }}' desc='{{ i18n "pages.settings.tgNotifyBackupDesc" }}' v-model="allSetting.tgBotBackup"></setting-list-item>
|
<setting-list-item type="switch" title='{{ i18n "pages.settings.tgNotifyBackup" }}' desc='{{ i18n "pages.settings.tgNotifyBackupDesc" }}' v-model="allSetting.tgBotBackup"></setting-list-item>
|
||||||
<setting-list-item type="switch" title='{{ i18n "pages.settings.tgNotifyLogin" }}' desc='{{ i18n "pages.settings.tgNotifyLoginDesc" }}' v-model="allSetting.tgBotLoginNotify"></setting-list-item>
|
<setting-list-item type="switch" title='{{ i18n "pages.settings.tgNotifyLogin" }}' desc='{{ i18n "pages.settings.tgNotifyLoginDesc" }}' v-model="allSetting.tgBotLoginNotify"></setting-list-item>
|
||||||
<setting-list-item type="number" title='{{ i18n "pages.settings.tgNotifyCpu" }}' desc='{{ i18n "pages.settings.tgNotifyCpuDesc" }}' v-model="allSetting.tgCpu" :min="0" :max="100"></setting-list-item>
|
<setting-list-item type="number" title='{{ i18n "pages.settings.tgNotifyCpu" }}' desc='{{ i18n "pages.settings.tgNotifyCpuDesc" }}' v-model="allSetting.tgCpu" :min="0" :max="100"></setting-list-item>
|
||||||
|
<setting-list-item type="text" title='{{ i18n "pages.settings.telegramProxy"}}' desc='{{ i18n "pages.settings.telegramProxyDesc"}}' v-model="allSetting.tgBotProxy" placeholder="socks5://[user:pass@]host:port"></setting-list-item>
|
||||||
<a-list-item>
|
<a-list-item>
|
||||||
<a-row style="padding: 20px">
|
<a-row style="padding: 20px">
|
||||||
<a-col :lg="24" :xl="12">
|
<a-col :lg="24" :xl="12">
|
||||||
|
|
|
@ -38,6 +38,7 @@ var defaultValueMap = map[string]string{
|
||||||
"timeLocation": "Asia/Tehran",
|
"timeLocation": "Asia/Tehran",
|
||||||
"tgBotEnable": "false",
|
"tgBotEnable": "false",
|
||||||
"tgBotToken": "",
|
"tgBotToken": "",
|
||||||
|
"tgBotProxy": "",
|
||||||
"tgBotChatId": "",
|
"tgBotChatId": "",
|
||||||
"tgRunTime": "@daily",
|
"tgRunTime": "@daily",
|
||||||
"tgBotBackup": "false",
|
"tgBotBackup": "false",
|
||||||
|
@ -245,6 +246,14 @@ func (s *SettingService) SetTgBotToken(token string) error {
|
||||||
return s.setString("tgBotToken", token)
|
return s.setString("tgBotToken", token)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SettingService) GetTgBotProxy() (string, error) {
|
||||||
|
return s.getString("tgBotProxy")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SettingService) SetTgBotProxy(token string) error {
|
||||||
|
return s.setString("tgBotProxy", token)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SettingService) GetTgBotChatId() (string, error) {
|
func (s *SettingService) GetTgBotChatId() (string, error) {
|
||||||
return s.getString("tgBotChatId")
|
return s.getString("tgBotChatId")
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -21,6 +22,8 @@ import (
|
||||||
"github.com/mymmrac/telego"
|
"github.com/mymmrac/telego"
|
||||||
th "github.com/mymmrac/telego/telegohandler"
|
th "github.com/mymmrac/telego/telegohandler"
|
||||||
tu "github.com/mymmrac/telego/telegoutil"
|
tu "github.com/mymmrac/telego/telegoutil"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
"github.com/valyala/fasthttp/fasthttpproxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
var bot *telego.Bot
|
var bot *telego.Bot
|
||||||
|
@ -90,7 +93,12 @@ func (t *Tgbot) Start(i18nFS embed.FS) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bot, err = telego.NewBot(tgBottoken)
|
tgBotProxy, err := t.settingService.GetTgBotProxy()
|
||||||
|
if err != nil {
|
||||||
|
logger.Warning("Failed to get ProxyUrl:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
bot, err = t.NewBot(tgBottoken, tgBotProxy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Get tgbot's api error:", err)
|
fmt.Println("Get tgbot's api error:", err)
|
||||||
return err
|
return err
|
||||||
|
@ -106,6 +114,23 @@ func (t *Tgbot) Start(i18nFS embed.FS) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tgbot) NewBot(token string, proxyUrl string) (*telego.Bot, error) {
|
||||||
|
if proxyUrl == "" || !strings.HasPrefix(proxyUrl, "socks5://") {
|
||||||
|
logger.Warning("invalid socks5 url, start with default")
|
||||||
|
return telego.NewBot(token)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := url.Parse(proxyUrl)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warning("cant parse proxy url, use default instance for tgbot:", err)
|
||||||
|
return telego.NewBot(token)
|
||||||
|
}
|
||||||
|
|
||||||
|
return telego.NewBot(token, telego.WithFastHTTPClient(&fasthttp.Client{
|
||||||
|
Dial: fasthttpproxy.FasthttpSocksDialer(proxyUrl),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Tgbot) IsRunning() bool {
|
func (t *Tgbot) IsRunning() bool {
|
||||||
return isRunning
|
return isRunning
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,6 +257,8 @@
|
||||||
"telegramBotEnableDesc" = "Connect to the features of this panel through the Telegram bot."
|
"telegramBotEnableDesc" = "Connect to the features of this panel through the Telegram bot."
|
||||||
"telegramToken" = "Telegram Token"
|
"telegramToken" = "Telegram Token"
|
||||||
"telegramTokenDesc" = "The token you have got from @BotFather."
|
"telegramTokenDesc" = "The token you have got from @BotFather."
|
||||||
|
"telegramProxy" = "Socks5 Proxy"
|
||||||
|
"telegramProxyDesc" = "If you need the Socks5 proxy to connect to Telegram. Adjust its settings as per the guide."
|
||||||
"telegramChatId" = "Telegram Admin Chat IDs"
|
"telegramChatId" = "Telegram Admin Chat IDs"
|
||||||
"telegramChatIdDesc" = "Multiple chat IDs separated by comma. use @userinfobot or use '/id' command in bot to get your Chat IDs."
|
"telegramChatIdDesc" = "Multiple chat IDs separated by comma. use @userinfobot or use '/id' command in bot to get your Chat IDs."
|
||||||
"telegramNotifyTime" = "Telegram bot notification time"
|
"telegramNotifyTime" = "Telegram bot notification time"
|
||||||
|
|
|
@ -257,6 +257,8 @@
|
||||||
"telegramBotEnableDesc" = "Conéctese a las funciones de este panel a través del bot de Telegram."
|
"telegramBotEnableDesc" = "Conéctese a las funciones de este panel a través del bot de Telegram."
|
||||||
"telegramToken" = "Token de Telegram"
|
"telegramToken" = "Token de Telegram"
|
||||||
"telegramTokenDesc" = "Debe obtener el token del administrador de bots de Telegram @botfather."
|
"telegramTokenDesc" = "Debe obtener el token del administrador de bots de Telegram @botfather."
|
||||||
|
"telegramProxy" = "Socks5 Proxy"
|
||||||
|
"telegramProxyDesc" = "Si necesita el proxy Socks5 para conectarse a Telegram. Ajuste su configuración según la guía."
|
||||||
"telegramChatId" = "IDs de Chat de Telegram para Administradores"
|
"telegramChatId" = "IDs de Chat de Telegram para Administradores"
|
||||||
"telegramChatIdDesc" = "IDs de Chat múltiples separados por comas. Use @userinfobot o use el comando '/id' en el bot para obtener sus IDs de Chat."
|
"telegramChatIdDesc" = "IDs de Chat múltiples separados por comas. Use @userinfobot o use el comando '/id' en el bot para obtener sus IDs de Chat."
|
||||||
"telegramNotifyTime" = "Hora de Notificación del Bot de Telegram"
|
"telegramNotifyTime" = "Hora de Notificación del Bot de Telegram"
|
||||||
|
|
|
@ -257,6 +257,8 @@
|
||||||
"telegramBotEnableDesc" = "از طریق بات تلگرام به امکانات این پنل متصل شوید"
|
"telegramBotEnableDesc" = "از طریق بات تلگرام به امکانات این پنل متصل شوید"
|
||||||
"telegramToken" = "توکن تلگرام"
|
"telegramToken" = "توکن تلگرام"
|
||||||
"telegramTokenDesc" = "توکن را باید از مدیر بات های تلگرام دریافت کنید @botfather"
|
"telegramTokenDesc" = "توکن را باید از مدیر بات های تلگرام دریافت کنید @botfather"
|
||||||
|
"telegramProxy" = "پروکسی Socks5"
|
||||||
|
"telegramProxyDesc" = "اگر برای اتصال به تلگرام به پروکسی Socks5 نیاز دارید. تنظیمات خود را طبق راهنما تنظیم کنید."
|
||||||
"telegramChatId" = "آی دی تلگرام مدیریت"
|
"telegramChatId" = "آی دی تلگرام مدیریت"
|
||||||
"telegramChatIdDesc" = "از @userinfobot یا دستور '/id' در ربات برای دریافت شناسه های چت خود استفاده کنید. با استفاده از کاما میتونید چند آی دی را از هم جدا کنید. "
|
"telegramChatIdDesc" = "از @userinfobot یا دستور '/id' در ربات برای دریافت شناسه های چت خود استفاده کنید. با استفاده از کاما میتونید چند آی دی را از هم جدا کنید. "
|
||||||
"telegramNotifyTime" = "مدت زمان نوتیفیکیشن ربات تلگرام"
|
"telegramNotifyTime" = "مدت زمان نوتیفیکیشن ربات تلگرام"
|
||||||
|
|
|
@ -257,6 +257,8 @@
|
||||||
"telegramBotEnableDesc" = "Подключайтесь к функциям этой панели через Telegram бота"
|
"telegramBotEnableDesc" = "Подключайтесь к функциям этой панели через Telegram бота"
|
||||||
"telegramToken" = "Токен Telegram бота"
|
"telegramToken" = "Токен Telegram бота"
|
||||||
"telegramTokenDesc" = "Необходимо получить токен у менеджера ботов Telegram @botfather"
|
"telegramTokenDesc" = "Необходимо получить токен у менеджера ботов Telegram @botfather"
|
||||||
|
"telegramProxy" = "Прокси Socks5"
|
||||||
|
"telegramProxyDesc" = "Если для подключения к Telegram вам нужен прокси Socks5. Настройте его параметры согласно руководству."
|
||||||
"telegramChatId" = "Telegram ID админа бота"
|
"telegramChatId" = "Telegram ID админа бота"
|
||||||
"telegramChatIdDesc" = "Множественные идентификаторы чата, разделенные запятыми. Чтобы получить свои идентификаторы чатов, используйте @userinfobot или команду '/id' в боте."
|
"telegramChatIdDesc" = "Множественные идентификаторы чата, разделенные запятыми. Чтобы получить свои идентификаторы чатов, используйте @userinfobot или команду '/id' в боте."
|
||||||
"telegramNotifyTime" = "Частота уведомлений бота Telegram"
|
"telegramNotifyTime" = "Частота уведомлений бота Telegram"
|
||||||
|
|
|
@ -257,6 +257,8 @@
|
||||||
"telegramBotEnableDesc" = "Kết nối với các tính năng của bảng điều khiển này thông qua bot Telegram"
|
"telegramBotEnableDesc" = "Kết nối với các tính năng của bảng điều khiển này thông qua bot Telegram"
|
||||||
"telegramToken" = "Token Telegram"
|
"telegramToken" = "Token Telegram"
|
||||||
"telegramTokenDesc" = "Bạn phải nhận token từ quản lý bot Telegram @botfather"
|
"telegramTokenDesc" = "Bạn phải nhận token từ quản lý bot Telegram @botfather"
|
||||||
|
"telegramProxy" = "Socks5 Proxy"
|
||||||
|
"telegramProxyDesc" = "Nếu bạn cần socks5 proxy để kết nối với Telegram. Điều chỉnh cài đặt của nó theo hướng dẫn."
|
||||||
"telegramChatId" = "Chat ID Telegram của quản trị viên"
|
"telegramChatId" = "Chat ID Telegram của quản trị viên"
|
||||||
"telegramChatIdDesc" = "Nhiều Chat ID phân tách bằng dấu phẩy. Sử dụng @userinfobot hoặc sử dụng lệnh '/id' trong bot để lấy Chat ID của bạn."
|
"telegramChatIdDesc" = "Nhiều Chat ID phân tách bằng dấu phẩy. Sử dụng @userinfobot hoặc sử dụng lệnh '/id' trong bot để lấy Chat ID của bạn."
|
||||||
"telegramNotifyTime" = "Thời gian thông báo của bot Telegram"
|
"telegramNotifyTime" = "Thời gian thông báo của bot Telegram"
|
||||||
|
|
|
@ -257,6 +257,8 @@
|
||||||
"telegramBotEnableDesc" = "重启面板生效"
|
"telegramBotEnableDesc" = "重启面板生效"
|
||||||
"telegramToken" = "电报机器人TOKEN"
|
"telegramToken" = "电报机器人TOKEN"
|
||||||
"telegramTokenDesc" = "重启面板生效"
|
"telegramTokenDesc" = "重启面板生效"
|
||||||
|
"telegramProxy" = "Socks5 代理"
|
||||||
|
"telegramProxyDesc" = "如果您需要 Socks5 代理来连接 Telegram。 根据指南调整其设置。"
|
||||||
"telegramChatId" = "以逗号分隔的多个 chatID 重启面板生效"
|
"telegramChatId" = "以逗号分隔的多个 chatID 重启面板生效"
|
||||||
"telegramChatIdDesc" = "多个聊天 ID 用逗号分隔。使用 @userinfobot 或在机器人中使用'/id'命令获取您的聊天 ID。"
|
"telegramChatIdDesc" = "多个聊天 ID 用逗号分隔。使用 @userinfobot 或在机器人中使用'/id'命令获取您的聊天 ID。"
|
||||||
"telegramNotifyTime" = "电报机器人通知时间"
|
"telegramNotifyTime" = "电报机器人通知时间"
|
||||||
|
|
|
@ -50,7 +50,9 @@ func (x *XrayAPI) Init(apiPort int) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *XrayAPI) Close() {
|
func (x *XrayAPI) Close() {
|
||||||
|
if x.grpcClient != nil {
|
||||||
x.grpcClient.Close()
|
x.grpcClient.Close()
|
||||||
|
}
|
||||||
x.HandlerServiceClient = nil
|
x.HandlerServiceClient = nil
|
||||||
x.StatsServiceClient = nil
|
x.StatsServiceClient = nil
|
||||||
x.isConnected = false
|
x.isConnected = false
|
||||||
|
|
Loading…
Reference in a new issue