From e8cdc29bb598c8fc545e07bd77eebd135d8edc78 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 26 Jul 2025 20:55:55 +0800 Subject: [PATCH] Add sudo password verification success message prompt --- v2rayN/ServiceLib/Handler/CoreAdminHandler.cs | 24 +++++++++++-------- v2rayN/ServiceLib/Handler/CoreHandler.cs | 11 +++------ v2rayN/ServiceLib/Resx/ResUI.Designer.cs | 9 +++++++ v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx | 3 +++ v2rayN/ServiceLib/Resx/ResUI.hu.resx | 3 +++ v2rayN/ServiceLib/Resx/ResUI.resx | 3 +++ v2rayN/ServiceLib/Resx/ResUI.ru.resx | 3 +++ v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx | 3 +++ v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx | 3 +++ 9 files changed, 44 insertions(+), 18 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/CoreAdminHandler.cs b/v2rayN/ServiceLib/Handler/CoreAdminHandler.cs index 7fd07262..df633b24 100644 --- a/v2rayN/ServiceLib/Handler/CoreAdminHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreAdminHandler.cs @@ -9,6 +9,7 @@ public class CoreAdminHandler private static readonly Lazy _instance = new(() => new()); public static CoreAdminHandler Instance => _instance.Value; private Config _config; + private readonly string _sudoAccessText = "SUDO_ACCESS_VERIFIED"; private Action? _updateFunc; private int _linuxSudoPid = -1; @@ -50,27 +51,30 @@ public class CoreAdminHandler } }; - proc.OutputDataReceived += (sender, e) => - { - if (e.Data.IsNotEmpty()) - { - UpdateFunc(false, e.Data + Environment.NewLine); - } - }; - proc.ErrorDataReceived += (sender, e) => + var sudoVerified = false; + DataReceivedEventHandler dataHandler = (sender, e) => { if (e.Data.IsNotEmpty()) { + if (!sudoVerified && e.Data.Contains(_sudoAccessText)) + { + sudoVerified = true; + UpdateFunc(false, ResUI.SudoPwdVerfiedSuccessTip + Environment.NewLine); + return; + } UpdateFunc(false, e.Data + Environment.NewLine); } }; + proc.OutputDataReceived += dataHandler; + proc.ErrorDataReceived += dataHandler; + proc.Start(); proc.BeginOutputReadLine(); proc.BeginErrorReadLine(); await Task.Delay(10); - await proc.StandardInput.WriteLineAsync(); + await proc.StandardInput.WriteLineAsync(AppHandler.Instance.LinuxSudoPwd); await Task.Delay(10); await proc.StandardInput.WriteLineAsync(AppHandler.Instance.LinuxSudoPwd); @@ -115,7 +119,7 @@ public class CoreAdminHandler } else { - sb.AppendLine($"sudo -S {cmdLine}"); + sb.AppendLine($"sudo -S echo \"{_sudoAccessText}\" && sudo -S {cmdLine}"); } await File.WriteAllTextAsync(shFilePath, sb.ToString()); diff --git a/v2rayN/ServiceLib/Handler/CoreHandler.cs b/v2rayN/ServiceLib/Handler/CoreHandler.cs index 92c30171..d1cf43f0 100644 --- a/v2rayN/ServiceLib/Handler/CoreHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreHandler.cs @@ -280,20 +280,15 @@ public class CoreHandler if (displayLog) { - proc.OutputDataReceived += (sender, e) => - { - if (e.Data.IsNotEmpty()) - { - UpdateFunc(false, e.Data + Environment.NewLine); - } - }; - proc.ErrorDataReceived += (sender, e) => + DataReceivedEventHandler dataHandler = (sender, e) => { if (e.Data.IsNotEmpty()) { UpdateFunc(false, e.Data + Environment.NewLine); } }; + proc.OutputDataReceived += dataHandler; + proc.ErrorDataReceived += dataHandler; } proc.Start(); diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index 6167fd75..5f4732d4 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -2202,6 +2202,15 @@ namespace ServiceLib.Resx { } } + /// + /// 查找类似 Sudo password has been verified successfully, please ignore the incorrect password prompts! 的本地化字符串。 + /// + public static string SudoPwdVerfiedSuccessTip { + get { + return ResourceManager.GetString("SudoPwdVerfiedSuccessTip", resourceCulture); + } + } + /// /// 查找类似 Address 的本地化字符串。 /// diff --git a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx index 3bc07d9f..8ac49ba3 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx @@ -1395,4 +1395,7 @@ Can fill in the configuration remarks, please make sure it exist and are unique + + Sudo password has been verified successfully, please ignore the incorrect password prompts! + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.hu.resx b/v2rayN/ServiceLib/Resx/ResUI.hu.resx index 114e1a21..c5028b11 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.hu.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.hu.resx @@ -1395,4 +1395,7 @@ Can fill in the configuration remarks, please make sure it exist and are unique + + Sudo password has been verified successfully, please ignore the incorrect password prompts! + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index 4be88f75..a83ad30f 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1395,4 +1395,7 @@ Can fill in the configuration remarks, please make sure it exist and are unique + + Sudo password has been verified successfully, please ignore the incorrect password prompts! + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx index b987c364..da763973 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx @@ -1395,4 +1395,7 @@ Can fill in the configuration remarks, please make sure it exist and are unique + + Sudo password has been verified successfully, please ignore the incorrect password prompts! + \ 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 27240b80..9d3216e0 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -1392,4 +1392,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 4ea33211..4f8420a3 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -1392,4 +1392,7 @@ 可以填寫設定檔別名,請確保存在並唯一 + + sudo 密碼已經驗證成功,請忽略錯誤密碼提示! + \ No newline at end of file