From b833ed799237fee9b6ba0b74675b5d340025279b Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Sat, 17 Jun 2023 19:11:16 +0330 Subject: [PATCH] new - tg Login Notification #584 --- web/assets/js/model/models.js | 1 + web/entity/entity.go | 1 + web/html/xui/settings.html | 1 + web/service/setting.go | 5 +++++ web/service/tgbot.go | 5 +++++ web/translation/translate.en_US.toml | 2 ++ web/translation/translate.fa_IR.toml | 2 ++ web/translation/translate.ru_RU.toml | 2 ++ web/translation/translate.zh_Hans.toml | 2 ++ 9 files changed, 21 insertions(+) diff --git a/web/assets/js/model/models.js b/web/assets/js/model/models.js index e1a766dc..2c992a1a 100644 --- a/web/assets/js/model/models.js +++ b/web/assets/js/model/models.js @@ -181,6 +181,7 @@ class AllSetting { this.tgBotChatId = ""; this.tgRunTime = "@daily"; this.tgBotBackup = false; + this.tgBotLoginNotify = false; this.tgCpu = ""; this.tgLang = "en-US"; this.xrayTemplateConfig = ""; diff --git a/web/entity/entity.go b/web/entity/entity.go index d5e90108..328af7b6 100644 --- a/web/entity/entity.go +++ b/web/entity/entity.go @@ -41,6 +41,7 @@ type AllSetting struct { TgBotChatId string `json:"tgBotChatId" form:"tgBotChatId"` TgRunTime string `json:"tgRunTime" form:"tgRunTime"` TgBotBackup bool `json:"tgBotBackup" form:"tgBotBackup"` + TgBotLoginNotify bool `json:"tgBotLoginNotify" form:"tgBotLoginNotify"` TgCpu int `json:"tgCpu" form:"tgCpu"` TgLang string `json:"tgLang" form:"tgLang"` XrayTemplateConfig string `json:"xrayTemplateConfig" form:"xrayTemplateConfig"` diff --git a/web/html/xui/settings.html b/web/html/xui/settings.html index abcacada..76ca8aa1 100644 --- a/web/html/xui/settings.html +++ b/web/html/xui/settings.html @@ -370,6 +370,7 @@ + diff --git a/web/service/setting.go b/web/service/setting.go index 677ccbb2..9bf74641 100644 --- a/web/service/setting.go +++ b/web/service/setting.go @@ -39,6 +39,7 @@ var defaultValueMap = map[string]string{ "tgBotChatId": "", "tgRunTime": "@daily", "tgBotBackup": "false", + "tgBotLoginNotify": "false", "tgCpu": "0", "tgLang": "en-US", "secretEnable": "false", @@ -266,6 +267,10 @@ func (s *SettingService) GetTgBotBackup() (bool, error) { return s.getBool("tgBotBackup") } +func (s *SettingService) GetTgBotLoginNotify() (bool, error) { + return s.getBool("tgBotLoginNotify") +} + func (s *SettingService) GetTgCpu() (int, error) { return s.getInt("tgCpu") } diff --git a/web/service/tgbot.go b/web/service/tgbot.go index 751de41b..39e7771a 100644 --- a/web/service/tgbot.go +++ b/web/service/tgbot.go @@ -643,6 +643,11 @@ func (t *Tgbot) UserLoginNotify(username string, ip string, time string, status return } + loginNotifyEnabled, err := t.settingService.GetTgBotLoginNotify() + if err != nil || !loginNotifyEnabled { + return + } + msg := "" if status == LoginSuccess { msg += t.I18nBot("tgbot.messages.loginSuccess") diff --git a/web/translation/translate.en_US.toml b/web/translation/translate.en_US.toml index 15c8416a..4e2f7c4a 100644 --- a/web/translation/translate.en_US.toml +++ b/web/translation/translate.en_US.toml @@ -245,6 +245,8 @@ "telegramNotifyTimeDesc" = "Use Crontab timing format." "tgNotifyBackup" = "Database Backup" "tgNotifyBackupDesc" = "Include database backup file with report notification." +"tgNotifyLogin" = "Login Notification" +"tgNotifyLoginDesc" = "Displays the username, IP address, and time when someone tries to log into your panel." "sessionMaxAge" = "Session maximum age" "sessionMaxAgeDesc" = "The duration of a login session (unit: minute)" "expireTimeDiff" = "Expiration threshold for notification" diff --git a/web/translation/translate.fa_IR.toml b/web/translation/translate.fa_IR.toml index 16635d35..06cbc23c 100644 --- a/web/translation/translate.fa_IR.toml +++ b/web/translation/translate.fa_IR.toml @@ -245,6 +245,8 @@ "telegramNotifyTimeDesc" = "از فرمت زمان بندی لینوکس استفاده کنید " "tgNotifyBackup" = "پشتیبان گیری از پایگاه داده" "tgNotifyBackupDesc" = "ارسال کپی فایل پایگاه داده به همراه گزارش دوره ای" +"tgNotifyLogin" = "اعلان ورود" +"tgNotifyLoginDesc" = "نام کاربری، آدرس ای پی، و زمان وقتی که فردی سعی می‌کند به پنل شما وارد شود نمایش میدهد" "sessionMaxAge" = "بیشینه زمان جلسه وب" "sessionMaxAgeDesc" = "بیشینه زمانی که میتوانید لاگین بمانید (واحد: دقیقه)" "expireTimeDiff" = "آستانه زمان باقی مانده" diff --git a/web/translation/translate.ru_RU.toml b/web/translation/translate.ru_RU.toml index 800f42a4..faaf3c6b 100644 --- a/web/translation/translate.ru_RU.toml +++ b/web/translation/translate.ru_RU.toml @@ -245,6 +245,8 @@ "telegramNotifyTimeDesc" = "Используйте формат времени Crontab" "tgNotifyBackup" = "Резервное копирование базы данных" "tgNotifyBackupDesc" = "Включать файл резервной копии базы данных с уведомлением об отчете" +"tgNotifyLogin" = "Уведомление о входе" +"tgNotifyLoginDesc" = "Отображает имя пользователя, IP-адрес и время, когда кто-то пытается войти в вашу панель." "sessionMaxAge" = "Продолжительность сессии" "sessionMaxAgeDesc" = "Продолжительность сессии в системе (значение: минута)" "expireTimeDiff" = "Порог истечения срока сессии для уведомления" diff --git a/web/translation/translate.zh_Hans.toml b/web/translation/translate.zh_Hans.toml index 18fc2ad5..1aa704e0 100644 --- a/web/translation/translate.zh_Hans.toml +++ b/web/translation/translate.zh_Hans.toml @@ -245,6 +245,8 @@ "telegramNotifyTimeDesc" = "采用Crontab定时格式,重启面板生效" "tgNotifyBackup" = "数据库备份" "tgNotifyBackupDesc" = "正在发送数据库备份文件和报告通知" +"tgNotifyLogin" = "登录通知" +"tgNotifyLoginDesc" = "当有人试图登录您的面板时显示用户名、IP 地址和时间" "sessionMaxAge" = "会话最大年龄" "sessionMaxAgeDesc" = "您可以保持登录状态的时间(单位:分钟)" "expireTimeDiff" = "耗尽时间阈值"