add ui proxy setting

This commit is contained in:
Surbiks 2023-12-13 16:15:00 +03:30
parent 24a0b143ae
commit b6c787f5d7
7 changed files with 24 additions and 1 deletions

View file

@ -14,6 +14,7 @@ class AllSetting {
this.remarkModel = "-ieo";
this.tgBotEnable = false;
this.tgBotToken = "";
this.tgBotProxy = "";
this.tgBotChatId = "";
this.tgRunTime = "@daily";
this.tgBotBackup = false;

View file

@ -28,6 +28,7 @@ type AllSetting struct {
RemarkModel string `json:"remarkModel" form:"remarkModel"`
TgBotEnable bool `json:"tgBotEnable" form:"tgBotEnable"`
TgBotToken string `json:"tgBotToken" form:"tgBotToken"`
TgBotProxy string `json:"tgBotProxy" form:"tgBotProxy"`
TgBotChatId string `json:"tgBotChatId" form:"tgBotChatId"`
TgRunTime string `json:"tgRunTime" form:"tgRunTime"`
TgBotBackup bool `json:"tgBotBackup" form:"tgBotBackup"`

View file

@ -243,6 +243,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.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="text" title='{{ i18n "pages.settings.telegramProxy"}}' desc='{{ i18n "pages.settings.telegramProxyDesc"}}' v-model="allSetting.tgBotProxy"></setting-list-item>
<a-list-item>
<a-row style="padding: 20px">
<a-col :lg="24" :xl="12">

View file

@ -38,6 +38,7 @@ var defaultValueMap = map[string]string{
"timeLocation": "Asia/Tehran",
"tgBotEnable": "false",
"tgBotToken": "",
"tgBotProxy": "",
"tgBotChatId": "",
"tgRunTime": "@daily",
"tgBotBackup": "false",
@ -244,6 +245,14 @@ func (s *SettingService) SetTgBotToken(token string) error {
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) {
return s.getString("tgBotChatId")
}

View file

@ -89,6 +89,13 @@ func (t *Tgbot) Start(i18nFS embed.FS) error {
}
}
tgBotProxy, err := t.settingService.GetTgBotProxy()
if err != nil || tgBotProxy == "" {
logger.Warning("Telegram proxy not valid use direct connection")
} else {
}
bot, err = telego.NewBot(tgBottoken)
if err != nil {
fmt.Println("Get tgbot's api error:", err)

View file

@ -255,6 +255,8 @@
"telegramBotEnableDesc" = "Connect to the features of this panel through the Telegram bot"
"telegramToken" = "Telegram Token"
"telegramTokenDesc" = "You must get the token from the manager of Telegram bots @botfather"
"telegramProxy" = "Telegram Socks5 Proxy"
"telegramProxyDesc" = "If you need Telegram to connect through a socks5 proxy. (socks5://user:pass@host:port)"
"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."
"telegramNotifyTime" = "Telegram bot notification time"

View file

@ -50,7 +50,9 @@ func (x *XrayAPI) Init(apiPort int) (err error) {
}
func (x *XrayAPI) Close() {
x.grpcClient.Close()
if x.grpcClient != nil {
x.grpcClient.Close()
}
x.HandlerServiceClient = nil
x.StatsServiceClient = nil
x.isConnected = false