From bd8007340207510870ea7610f07a38ec22972225 Mon Sep 17 00:00:00 2001 From: "Shishkevich D." <135337715+shishkevichd@users.noreply.github.com> Date: Thu, 22 May 2025 05:51:29 +0000 Subject: [PATCH 1/3] chore: add `resetTwoFactor` argument for main.go fixes #3025 --- main.go | 17 +++++++++++++++-- web/service/setting.go | 8 ++++++++ x-ui.sh | 11 ++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index dcbd3c9e..9986ede1 100644 --- a/main.go +++ b/main.go @@ -232,7 +232,7 @@ func updateTgbotSetting(tgBotToken string, tgBotChatid string, tgBotRuntime stri } } -func updateSetting(port int, username string, password string, webBasePath string, listenIP string) { +func updateSetting(port int, username string, password string, webBasePath string, listenIP string, resetTwoFactor bool) { err := database.InitDB(config.GetDBPath()) if err != nil { fmt.Println("Database initialization failed:", err) @@ -269,6 +269,17 @@ func updateSetting(port int, username string, password string, webBasePath strin } } + if resetTwoFactor { + err := settingService.SetTwoFactorEnable(false) + + if err != nil { + fmt.Println("Failed to reset two-factor authentication:", err) + } else { + settingService.SetTwoFactorToken("") + fmt.Println("Two-factor authentication reset successfully") + } + } + if listenIP != "" { err := settingService.SetListen(listenIP) if err != nil { @@ -376,6 +387,7 @@ func main() { var reset bool var show bool var getCert bool + var resetTwoFactor bool settingCmd.BoolVar(&reset, "reset", false, "Reset all settings") settingCmd.BoolVar(&show, "show", false, "Display current settings") settingCmd.IntVar(&port, "port", 0, "Set panel port number") @@ -383,6 +395,7 @@ func main() { settingCmd.StringVar(&password, "password", "", "Set login password") settingCmd.StringVar(&webBasePath, "webBasePath", "", "Set base path for Panel") settingCmd.StringVar(&listenIP, "listenIP", "", "set panel listenIP IP") + settingCmd.BoolVar(&resetTwoFactor, "resetTwoFactor", false, "Reset two-factor authentication settings") settingCmd.BoolVar(&getListen, "getListen", false, "Display current panel listenIP IP") settingCmd.BoolVar(&getCert, "getCert", false, "Display current certificate settings") settingCmd.StringVar(&webCertFile, "webCert", "", "Set path to public key file for panel") @@ -427,7 +440,7 @@ func main() { if reset { resetSetting() } else { - updateSetting(port, username, password, webBasePath, listenIP) + updateSetting(port, username, password, webBasePath, listenIP, resetTwoFactor) } if show { showSetting(show) diff --git a/web/service/setting.go b/web/service/setting.go index 62d66c11..868d55bc 100644 --- a/web/service/setting.go +++ b/web/service/setting.go @@ -322,10 +322,18 @@ func (s *SettingService) GetTwoFactorEnable() (bool, error) { return s.getBool("twoFactorEnable") } +func (s *SettingService) SetTwoFactorEnable(value bool) error { + return s.setBool("twoFactorEnable", value) +} + func (s *SettingService) GetTwoFactorToken() (string, error) { return s.getString("twoFactorToken") } +func (s *SettingService) SetTwoFactorToken(value string) error { + return s.setString("twoFactorToken", value) +} + func (s *SettingService) GetPort() (int, error) { return s.getInt("webPort") } diff --git a/x-ui.sh b/x-ui.sh index 88e5a7bb..641db3a0 100644 --- a/x-ui.sh +++ b/x-ui.sh @@ -179,11 +179,20 @@ reset_user() { fi return 0 fi + read -rp "Please set the login username [default is a random username]: " config_account [[ -z $config_account ]] && config_account=$(date +%s%N | md5sum | cut -c 1-8) read -rp "Please set the login password [default is a random password]: " config_password [[ -z $config_password ]] && config_password=$(date +%s%N | md5sum | cut -c 1-8) - /usr/local/x-ui/x-ui setting -username ${config_account} -password ${config_password} >/dev/null 2>&1 + + read -rp "Are you sure you want to reset the two factor? (y/n): " twoFactorConfirm + if [[ $twoFactorConfirm != "y" && $twoFactorConfirm != "Y" ]]; then + /usr/local/x-ui/x-ui setting -username ${config_account} -password ${config_password} -resetTwoFactor false >/dev/null 2>&1 + else + /usr/local/x-ui/x-ui setting -username ${config_account} -password ${config_password} -resetTwoFactor true >/dev/null 2>&1 + echo -e "Two factor authentication has been disabled." + fi + echo -e "Panel login username has been reset to: ${green} ${config_account} ${plain}" echo -e "Panel login password has been reset to: ${green} ${config_password} ${plain}" echo -e "${green} Please use the new login username and password to access the X-UI panel. Also remember them! ${plain}" From 5546c27feac1aa4b3ce99ed194519301d61f97ef Mon Sep 17 00:00:00 2001 From: "Shishkevich D." <135337715+shishkevichd@users.noreply.github.com> Date: Thu, 22 May 2025 06:08:42 +0000 Subject: [PATCH 2/3] chore: reset two-factor authentication after changing admin credentials --- web/html/modals/two_factor_modal.html | 18 ++++--------- web/html/settings.html | 37 ++++++++++++++++++++++----- web/service/user.go | 10 ++++++++ web/translation/translate.ar_EG.toml | 2 ++ web/translation/translate.en_US.toml | 2 ++ web/translation/translate.es_ES.toml | 2 ++ web/translation/translate.fa_IR.toml | 2 ++ web/translation/translate.id_ID.toml | 2 ++ web/translation/translate.ja_JP.toml | 2 ++ web/translation/translate.pt_BR.toml | 2 ++ web/translation/translate.ru_RU.toml | 2 ++ web/translation/translate.tr_TR.toml | 2 ++ web/translation/translate.uk_UA.toml | 2 ++ web/translation/translate.vi_VN.toml | 2 ++ web/translation/translate.zh_CN.toml | 2 ++ web/translation/translate.zh_TW.toml | 2 ++ 16 files changed, 71 insertions(+), 20 deletions(-) diff --git a/web/html/modals/two_factor_modal.html b/web/html/modals/two_factor_modal.html index 7823485f..13d22a5e 100644 --- a/web/html/modals/two_factor_modal.html +++ b/web/html/modals/two_factor_modal.html @@ -15,8 +15,8 @@
{{ i18n "pages.settings.security.twoFactorModalSecondStep" }}
{{ i18n "pages.settings.security.twoFactorModalRemoveStep" }}
+ +[[ twoFactorModal.description ]]