diff --git a/v2rayN/ServiceLib/Enums/EViewAction.cs b/v2rayN/ServiceLib/Enums/EViewAction.cs index 75142925..a72e8765 100644 --- a/v2rayN/ServiceLib/Enums/EViewAction.cs +++ b/v2rayN/ServiceLib/Enums/EViewAction.cs @@ -20,6 +20,7 @@ public enum EViewAction BrowseServer, ImportRulesFromFile, InitSettingFont, + PasswordInput, SubEditWindow, RoutingRuleSettingWindow, RoutingRuleDetailsWindow, diff --git a/v2rayN/ServiceLib/Handler/AppHandler.cs b/v2rayN/ServiceLib/Handler/AppHandler.cs index 0b8054f1..3f9fdf74 100644 --- a/v2rayN/ServiceLib/Handler/AppHandler.cs +++ b/v2rayN/ServiceLib/Handler/AppHandler.cs @@ -40,6 +40,8 @@ public sealed class AppHandler } } + public string LinuxSudoPwd { get; set; } + #endregion Property #region Init diff --git a/v2rayN/ServiceLib/Handler/CoreHandler.cs b/v2rayN/ServiceLib/Handler/CoreHandler.cs index 41ea866d..499d8999 100644 --- a/v2rayN/ServiceLib/Handler/CoreHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreHandler.cs @@ -229,9 +229,7 @@ public class CoreHandler { return _config.TunModeItem.EnableTun && eCoreType == ECoreType.sing_box - && (Utils.IsNonWindows()) - //&& _config.TunModeItem.LinuxSudoPwd.IsNotEmpty() - ; + && Utils.IsNonWindows(); } #endregion Private @@ -288,13 +286,11 @@ public class CoreHandler } proc.Start(); - if (isNeedSudo && _config.TunModeItem.LinuxSudoPwd.IsNotEmpty()) + if (isNeedSudo && AppHandler.Instance.LinuxSudoPwd.IsNotEmpty()) { - var pwd = DesUtils.Decrypt(_config.TunModeItem.LinuxSudoPwd); + await proc.StandardInput.WriteLineAsync(); await Task.Delay(10); - await proc.StandardInput.WriteLineAsync(pwd); - await Task.Delay(10); - await proc.StandardInput.WriteLineAsync(pwd); + await proc.StandardInput.WriteLineAsync(AppHandler.Instance.LinuxSudoPwd); } if (isNeedSudo) _linuxSudoPid = proc.Id; @@ -333,7 +329,7 @@ public class CoreHandler proc.StartInfo.FileName = shFilePath; proc.StartInfo.Arguments = ""; proc.StartInfo.WorkingDirectory = ""; - if (_config.TunModeItem.LinuxSudoPwd.IsNotEmpty()) + if (AppHandler.Instance.LinuxSudoPwd.IsNotEmpty()) { proc.StartInfo.StandardInputEncoding = Encoding.UTF8; proc.StartInfo.RedirectStandardInput = true; @@ -342,7 +338,7 @@ public class CoreHandler private async Task KillProcessAsLinuxSudo() { - var cmdLine = $"kill {_linuxSudoPid}"; + var cmdLine = $"pkill -P {_linuxSudoPid} ; kill {_linuxSudoPid}"; var shFilePath = await CreateLinuxShellFile(cmdLine, "kill_as_sudo.sh"); Process proc = new() { @@ -357,15 +353,13 @@ public class CoreHandler }; proc.Start(); - if (_config.TunModeItem.LinuxSudoPwd.IsNotEmpty()) + if (AppHandler.Instance.LinuxSudoPwd.IsNotEmpty()) { try { - var pwd = DesUtils.Decrypt(_config.TunModeItem.LinuxSudoPwd); + await proc.StandardInput.WriteLineAsync(); await Task.Delay(10); - await proc.StandardInput.WriteLineAsync(pwd); - await Task.Delay(10); - await proc.StandardInput.WriteLineAsync(pwd); + await proc.StandardInput.WriteLineAsync(AppHandler.Instance.LinuxSudoPwd); } catch (Exception) { @@ -375,7 +369,7 @@ public class CoreHandler var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(10)); await proc.WaitForExitAsync(timeout.Token); - await Task.Delay(3000); + await Task.Delay(1000); } private async Task CreateLinuxShellFile(string cmdLine, string fileName) @@ -389,10 +383,6 @@ public class CoreHandler { sb.AppendLine($"{cmdLine}"); } - else if (_config.TunModeItem.LinuxSudoPwd.IsNullOrEmpty()) - { - sb.AppendLine($"pkexec {cmdLine}"); - } else { sb.AppendLine($"sudo -S {cmdLine}"); diff --git a/v2rayN/ServiceLib/Models/ConfigItems.cs b/v2rayN/ServiceLib/Models/ConfigItems.cs index b3fa1b98..47c96a3f 100644 --- a/v2rayN/ServiceLib/Models/ConfigItems.cs +++ b/v2rayN/ServiceLib/Models/ConfigItems.cs @@ -147,7 +147,6 @@ public class TunModeItem public int Mtu { get; set; } public bool EnableExInbound { get; set; } public bool EnableIPv6Address { get; set; } - public string? LinuxSudoPwd { get; set; } } [Serializable] diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index 0b9cc936..ac507c45 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -3247,7 +3247,7 @@ namespace ServiceLib.Resx { } /// - /// 查找类似 The password is encrypted and stored only in local files 的本地化字符串。 + /// 查找类似 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. 的本地化字符串。 /// public static string TbSettingsLinuxSudoPasswordTip { get { diff --git a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx index a937a262..adf4eb0e 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx @@ -1339,7 +1339,7 @@ رمز عبور sudo سیستم - رمز عبور رمزگذاری شده و فقط در فایل های محلی ذخیره می شود. + 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. لطفاً ابتدا رمز عبور sudo را در تنظیمات حالت Tun تنظیم کنید @@ -1416,4 +1416,4 @@ صادر کردن سرور - + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.hu.resx b/v2rayN/ServiceLib/Resx/ResUI.hu.resx index 05a12c10..130c3579 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.hu.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.hu.resx @@ -1339,7 +1339,7 @@ Rendszer sudo jelszó - A jelszó titkosítva és csak a helyi fájlokban tárolva. + 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. Kérlek, először állítsd be a sudo jelszót a Tun módban diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index 1fb3d23b..7ec5d653 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1339,7 +1339,7 @@ System sudo password - The password is encrypted and stored only in local files + 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. Please set the sudo password in Tun mode settings first diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx index 824ea29a..9103641b 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx @@ -1339,7 +1339,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. Please set the sudo password in Tun mode settings first diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index a5f07957..150a9353 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -1071,13 +1071,13 @@ 拥塞控制算法 - + 前置代理配置文件别名 - + 落地代理配置文件別名 - + 请确保配置文件别名存在并唯一 @@ -1336,7 +1336,7 @@ 系统的 sudo 密码 - 密码已加密且只存储在本地文件中,无密码则每次都要输入 + 输入的密码无法校验,所以请确保输入正确。如果因为输入错误导致无法正常运行时,请重启本应用。 密码不会存储,每次重启后都需要再次输入。 请先在 Tun 模式设置中设置 sudo 密码 @@ -1413,4 +1413,4 @@ 导出配置文件 - + \ 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 b8a5011a..e827d0ea 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -1071,13 +1071,13 @@ 擁塞控制算法 - + 前置代理設定檔別名 - + 落地代理設定檔別名 - + 請確保設定檔別名存在並且唯一 @@ -1336,7 +1336,7 @@ 系統的 sudo 密碼 - 密碼已加密且只儲存在本機檔案中,無密碼則每次都要輸入 + 輸入的密碼無法校驗,所以請確保輸入正確。如果因為輸入錯誤導致無法正常運作時,請重新啟動本應用。 密碼不會存儲,每次重啟後都需要再次輸入。 請先在 Tun 模式設定中設定 sudo 密碼 @@ -1413,4 +1413,4 @@ 匯出設定檔 - + \ No newline at end of file diff --git a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs index b99339d6..fd26eb32 100644 --- a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs @@ -88,7 +88,6 @@ public class OptionSettingViewModel : MyReactiveObject [Reactive] public int TunMtu { get; set; } [Reactive] public bool TunEnableExInbound { get; set; } [Reactive] public bool TunEnableIPv6Address { get; set; } - [Reactive] public string TunLinuxSudoPassword { get; set; } #endregion Tun mode @@ -205,7 +204,6 @@ public class OptionSettingViewModel : MyReactiveObject TunMtu = _config.TunModeItem.Mtu; TunEnableExInbound = _config.TunModeItem.EnableExInbound; TunEnableIPv6Address = _config.TunModeItem.EnableIPv6Address; - TunLinuxSudoPassword = _config.TunModeItem.LinuxSudoPwd; #endregion Tun mode @@ -358,11 +356,7 @@ public class OptionSettingViewModel : MyReactiveObject _config.TunModeItem.Mtu = TunMtu; _config.TunModeItem.EnableExInbound = TunEnableExInbound; _config.TunModeItem.EnableIPv6Address = TunEnableIPv6Address; - if (TunLinuxSudoPassword != _config.TunModeItem.LinuxSudoPwd) - { - _config.TunModeItem.LinuxSudoPwd = DesUtils.Encrypt(TunLinuxSudoPassword); - } - + //coreType await SaveCoreType(); diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index 00cc391a..ec6ec39e 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -436,11 +436,13 @@ public class StatusBarViewModel : MyReactiveObject Locator.Current.GetService()?.RebootAsAdmin(); return; } - else if (Utils.IsOSX()) + else { - _config.TunModeItem.EnableTun = false; - NoticeHandler.Instance.SendMessageAndEnqueue(ResUI.TbSettingsLinuxSudoPasswordIsEmpty); - return; + if (await _updateView?.Invoke(EViewAction.PasswordInput, null) == false) + { + _config.TunModeItem.EnableTun = false; + return; + } } } await ConfigHandler.SaveConfig(_config); @@ -456,11 +458,11 @@ public class StatusBarViewModel : MyReactiveObject } else if (Utils.IsLinux()) { - return _config.TunModeItem.LinuxSudoPwd.IsNotEmpty(); + return AppHandler.Instance.LinuxSudoPwd.IsNotEmpty(); } else if (Utils.IsOSX()) { - return _config.TunModeItem.LinuxSudoPwd.IsNotEmpty(); + return AppHandler.Instance.LinuxSudoPwd.IsNotEmpty(); } return false; } diff --git a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml index 8c9351d7..3ad9b178 100644 --- a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml @@ -784,28 +784,6 @@ Margin="{StaticResource Margin4}" HorizontalAlignment="Left" /> - - - diff --git a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs index 58aceaf1..4faa0c27 100644 --- a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs @@ -153,7 +153,6 @@ public partial class OptionSettingWindow : ReactiveWindow vm.TunMtu, v => v.cmbMtu.SelectedValue).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.TunEnableExInbound, v => v.togEnableExInbound.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.TunEnableIPv6Address, v => v.togEnableIPv6Address.IsChecked).DisposeWith(disposables); - this.Bind(ViewModel, vm => vm.TunLinuxSudoPassword, v => v.txtLinuxSudoPassword.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.CoreType1, v => v.cmbCoreType1.SelectedValue).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.CoreType2, v => v.cmbCoreType2.SelectedValue).DisposeWith(disposables); @@ -170,10 +169,6 @@ public partial class OptionSettingWindow : ReactiveWindow return false; await AvaUtils.SetClipboardData(this, (string)obj); break; + + case EViewAction.PasswordInput: + return await PasswordInputAsync(); + break; } return await Task.FromResult(true); } @@ -96,6 +102,20 @@ public partial class StatusBarView : ReactiveUserControl } } + private async Task PasswordInputAsync() + { + var dialog = new SudoPasswordInputView(); + var obj = await DialogHost.Show(dialog); + if (obj == null) + { + togEnableTun.IsChecked = false; + return false; + } + + AppHandler.Instance.LinuxSudoPwd = obj.ToString() ?? string.Empty; + return true; + } + private void TxtRunningServerDisplay_Tapped(object? sender, Avalonia.Input.TappedEventArgs e) { ViewModel?.TestServerAvailability(); diff --git a/v2rayN/v2rayN.Desktop/Views/SudoPasswordInputView.axaml b/v2rayN/v2rayN.Desktop/Views/SudoPasswordInputView.axaml new file mode 100644 index 00000000..507cbb49 --- /dev/null +++ b/v2rayN/v2rayN.Desktop/Views/SudoPasswordInputView.axaml @@ -0,0 +1,70 @@ + + + + + + +