diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index 5f4732d4..4732cdd4 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -2202,6 +2202,15 @@ namespace ServiceLib.Resx { } } + /// + /// 查找类似 Incorrect password, please try again. 的本地化字符串。 + /// + public static string SudoIncorrectPasswordTip { + get { + return ResourceManager.GetString("SudoIncorrectPasswordTip", resourceCulture); + } + } + /// /// 查找类似 Sudo password has been verified successfully, please ignore the incorrect password prompts! 的本地化字符串。 /// @@ -3202,7 +3211,7 @@ namespace ServiceLib.Resx { } /// - /// 查找类似 The password you entered cannot be verified, so make sure you enter it correctly. If the application does not work properly due to an incorrect input, please restart the application. The password will not be stored and you will need to enter it again after each restart. 的本地化字符串。 + /// 查找类似 The password will be validated via the command line. If a validation error causes the application to malfunction, please restart the application. The password will not be stored and must be entered again after each restart. 的本地化字符串。 /// public static string TbSettingsLinuxSudoPasswordTip { get { diff --git a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx index 8ac49ba3..f8f8d6fa 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx @@ -1318,7 +1318,7 @@ رمز عبور sudo سیستم - رمز عبوری که وارد کرده اید تایید نمی شود، بنابراین مطمئن شوید که آن را به درستی وارد کرده اید. اگر برنامه به دلیل ورودی نادرست به درستی کار نمی کند، لطفاً برنامه را مجدداً راه اندازی کنید. رمز عبور ذخیره نمی شود و پس از هر بار راه اندازی مجدد باید آن را دوباره وارد کنید. + The password will be validated via the command line. If a validation error causes the application to malfunction, please restart the application. The password will not be stored and must be entered again after each restart. *حالت xhttp @@ -1398,4 +1398,7 @@ Sudo password has been verified successfully, please ignore the incorrect password prompts! + + Incorrect password, please try again. + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.hu.resx b/v2rayN/ServiceLib/Resx/ResUI.hu.resx index c5028b11..85ea3335 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.hu.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.hu.resx @@ -1318,7 +1318,7 @@ Rendszer sudo jelszó - The password you entered cannot be verified, so make sure you enter it correctly. If the application does not work properly due to an incorrect input, please restart the application. The password will not be stored and you will need to enter it again after each restart. + The password will be validated via the command line. If a validation error causes the application to malfunction, please restart the application. The password will not be stored and must be entered again after each restart. *xhttp mód @@ -1398,4 +1398,7 @@ Sudo password has been verified successfully, please ignore the incorrect password prompts! + + Incorrect password, please try again. + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index a83ad30f..8092e2e9 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1318,7 +1318,7 @@ System sudo password - The password you entered cannot be verified, so make sure you enter it correctly. If the application does not work properly due to an incorrect input, please restart the application. The password will not be stored and you will need to enter it again after each restart. + The password will be validated via the command line. If a validation error causes the application to malfunction, please restart the application. The password will not be stored and must be entered again after each restart. *xhttp mode @@ -1398,4 +1398,7 @@ Sudo password has been verified successfully, please ignore the incorrect password prompts! + + Incorrect password, please try again. + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx index da763973..434b2c8f 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx @@ -1318,7 +1318,7 @@ Пароль sudo системы - Введенный вами пароль не может быть подтвержден, поэтому убедитесь, что вы ввели его правильно. Если приложение не работает должным образом из-за неправильного ввода, то перезапустите его. Пароль не будет сохранен, и вам придется вводить его заново после каждого перезапуска + The password will be validated via the command line. If a validation error causes the application to malfunction, please restart the application. The password will not be stored and must be entered again after each restart. *XHTTP-режим @@ -1398,4 +1398,7 @@ Sudo password has been verified successfully, please ignore the incorrect password prompts! + + Incorrect password, please try again. + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index 9d3216e0..fed61bf6 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -1315,7 +1315,7 @@ 系统的 sudo 密码 - 输入的密码无法校验,所以请确保输入正确。如果因为输入错误导致无法正常运行时,请重启本应用。 密码不会存储,每次重启后都需要再次输入。 + 密码将调用命令行校验,如果因为校验错误导致无法正常运行时,请重启本应用。 密码不会存储,每次重启后都需要再次输入。 *XHTTP 模式 @@ -1395,4 +1395,7 @@ sudo 密码已经验证成功,请忽略错误密码提示! + + 密码错误,请重试。 + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx index 4f8420a3..f6676488 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -1315,7 +1315,7 @@ 系統的 sudo 密碼 - 輸入的密碼無法校驗,所以請確保輸入正確。如果因為輸入錯誤導致無法正常運作時,請重新啟動本應用。 密碼不會儲存,每次重啟後都需要再次輸入。 + 密碼將調用命令行校驗,如果因為校驗錯誤導致無法正常運行時,請重啟本應用。密碼不會存儲,每次重啟後都需要再次輸入。 *xhttp 模式 @@ -1395,4 +1395,7 @@ sudo 密碼已經驗證成功,請忽略錯誤密碼提示! + + 密碼錯誤,請重試。 + \ No newline at end of file diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index bbc6c585..5c2acab6 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -436,30 +436,34 @@ public class StatusBarViewModel : MyReactiveObject private async Task DoEnableTun(bool c) { - if (_config.TunModeItem.EnableTun != EnableTun) + if (_config.TunModeItem.EnableTun == EnableTun) + { + return; + } + + _config.TunModeItem.EnableTun = EnableTun; + + if (EnableTun && AllowEnableTun() == false) { - _config.TunModeItem.EnableTun = EnableTun; // When running as a non-administrator, reboot to administrator mode - if (EnableTun && AllowEnableTun() == false) + if (Utils.IsWindows()) { - if (Utils.IsWindows()) + _config.TunModeItem.EnableTun = false; + Locator.Current.GetService()?.RebootAsAdmin(); + return; + } + else + { + bool? passwordResult = await _updateView?.Invoke(EViewAction.PasswordInput, null); + if (passwordResult == false) { _config.TunModeItem.EnableTun = false; - Locator.Current.GetService()?.RebootAsAdmin(); return; } - else - { - if (await _updateView?.Invoke(EViewAction.PasswordInput, null) == false) - { - _config.TunModeItem.EnableTun = false; - return; - } - } } - await ConfigHandler.SaveConfig(_config); - Locator.Current.GetService()?.Reload(); } + await ConfigHandler.SaveConfig(_config); + Locator.Current.GetService()?.Reload(); } private bool AllowEnableTun() diff --git a/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs index 682a3ef2..92472c50 100644 --- a/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs @@ -104,13 +104,15 @@ public partial class StatusBarView : ReactiveUserControl { var dialog = new SudoPasswordInputView(); var obj = await DialogHost.Show(dialog); - if (obj == null) + + var password = obj?.ToString(); + if (password.IsNullOrEmpty()) { togEnableTun.IsChecked = false; return false; } - AppHandler.Instance.LinuxSudoPwd = obj.ToString() ?? string.Empty; + AppHandler.Instance.LinuxSudoPwd = password; return true; } diff --git a/v2rayN/v2rayN.Desktop/Views/SudoPasswordInputView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/SudoPasswordInputView.axaml.cs index 8276faf4..ad1a0211 100644 --- a/v2rayN/v2rayN.Desktop/Views/SudoPasswordInputView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/SudoPasswordInputView.axaml.cs @@ -1,5 +1,6 @@ using Avalonia.Controls; using Avalonia.Threading; +using CliWrap.Buffered; using DialogHostAvalonia; namespace v2rayN.Desktop.Views; @@ -12,22 +13,71 @@ public partial class SudoPasswordInputView : UserControl this.Loaded += (s, e) => txtPassword.Focus(); - btnSave.Click += (_, _) => - { - if (string.IsNullOrEmpty(txtPassword.Text)) - { - txtPassword.Focus(); - return; - } - Dispatcher.UIThread.Post(() => - { - DialogHost.Close(null, txtPassword.Text); - }); - }; + btnSave.Click += async (_, _) => await SavePasswordAsync(); btnCancel.Click += (_, _) => { DialogHost.Close(null); }; } + + private async Task SavePasswordAsync() + { + if (txtPassword.Text.IsNullOrEmpty()) + { + txtPassword.Focus(); + return; + } + + var password = txtPassword.Text; + btnSave.IsEnabled = false; + + try + { + // Verify if the password is correct + if (await CheckSudoPasswordAsync(password)) + { + // Password verification successful, return password and close dialog + await Dispatcher.UIThread.InvokeAsync(() => + { + DialogHost.Close(null, password); + }); + } + else + { + // Password verification failed, display error and let user try again + NoticeHandler.Instance.Enqueue(ResUI.SudoIncorrectPasswordTip); + txtPassword.Focus(); + } + } + catch (Exception ex) + { + Logging.SaveLog("SudoPassword", ex); + } + finally + { + btnSave.IsEnabled = true; + } + } + + private async Task CheckSudoPasswordAsync(string password) + { + try + { + // Use sudo -S echo command to verify password + var arg = new List() { "-c", "sudo -S echo SUDO_CHECK" }; + var result = await CliWrap.Cli + .Wrap(Global.LinuxBash) + .WithArguments(arg) + .WithStandardInputPipe(CliWrap.PipeSource.FromString(password)) + .ExecuteBufferedAsync(); + + return result.ExitCode == 0; + } + catch (Exception ex) + { + Logging.SaveLog("CheckSudoPassword", ex); + return false; + } + } }