Add sudo password verification success message prompt

pull/7656/head
2dust 2025-07-26 20:55:55 +08:00
parent 191a7a6574
commit e8cdc29bb5
9 changed files with 44 additions and 18 deletions

View File

@ -9,6 +9,7 @@ public class CoreAdminHandler
private static readonly Lazy<CoreAdminHandler> _instance = new(() => new()); private static readonly Lazy<CoreAdminHandler> _instance = new(() => new());
public static CoreAdminHandler Instance => _instance.Value; public static CoreAdminHandler Instance => _instance.Value;
private Config _config; private Config _config;
private readonly string _sudoAccessText = "SUDO_ACCESS_VERIFIED";
private Action<bool, string>? _updateFunc; private Action<bool, string>? _updateFunc;
private int _linuxSudoPid = -1; private int _linuxSudoPid = -1;
@ -50,27 +51,30 @@ public class CoreAdminHandler
} }
}; };
proc.OutputDataReceived += (sender, e) => var sudoVerified = false;
{ DataReceivedEventHandler dataHandler = (sender, e) =>
if (e.Data.IsNotEmpty())
{
UpdateFunc(false, e.Data + Environment.NewLine);
}
};
proc.ErrorDataReceived += (sender, e) =>
{ {
if (e.Data.IsNotEmpty()) 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); UpdateFunc(false, e.Data + Environment.NewLine);
} }
}; };
proc.OutputDataReceived += dataHandler;
proc.ErrorDataReceived += dataHandler;
proc.Start(); proc.Start();
proc.BeginOutputReadLine(); proc.BeginOutputReadLine();
proc.BeginErrorReadLine(); proc.BeginErrorReadLine();
await Task.Delay(10); await Task.Delay(10);
await proc.StandardInput.WriteLineAsync(); await proc.StandardInput.WriteLineAsync(AppHandler.Instance.LinuxSudoPwd);
await Task.Delay(10); await Task.Delay(10);
await proc.StandardInput.WriteLineAsync(AppHandler.Instance.LinuxSudoPwd); await proc.StandardInput.WriteLineAsync(AppHandler.Instance.LinuxSudoPwd);
@ -115,7 +119,7 @@ public class CoreAdminHandler
} }
else else
{ {
sb.AppendLine($"sudo -S {cmdLine}"); sb.AppendLine($"sudo -S echo \"{_sudoAccessText}\" && sudo -S {cmdLine}");
} }
await File.WriteAllTextAsync(shFilePath, sb.ToString()); await File.WriteAllTextAsync(shFilePath, sb.ToString());

View File

@ -280,20 +280,15 @@ public class CoreHandler
if (displayLog) if (displayLog)
{ {
proc.OutputDataReceived += (sender, e) => DataReceivedEventHandler dataHandler = (sender, e) =>
{
if (e.Data.IsNotEmpty())
{
UpdateFunc(false, e.Data + Environment.NewLine);
}
};
proc.ErrorDataReceived += (sender, e) =>
{ {
if (e.Data.IsNotEmpty()) if (e.Data.IsNotEmpty())
{ {
UpdateFunc(false, e.Data + Environment.NewLine); UpdateFunc(false, e.Data + Environment.NewLine);
} }
}; };
proc.OutputDataReceived += dataHandler;
proc.ErrorDataReceived += dataHandler;
} }
proc.Start(); proc.Start();

View File

@ -2202,6 +2202,15 @@ namespace ServiceLib.Resx {
} }
} }
/// <summary>
/// 查找类似 Sudo password has been verified successfully, please ignore the incorrect password prompts! 的本地化字符串。
/// </summary>
public static string SudoPwdVerfiedSuccessTip {
get {
return ResourceManager.GetString("SudoPwdVerfiedSuccessTip", resourceCulture);
}
}
/// <summary> /// <summary>
/// 查找类似 Address 的本地化字符串。 /// 查找类似 Address 的本地化字符串。
/// </summary> /// </summary>

View File

@ -1395,4 +1395,7 @@
<data name="TbRuleOutboundTagTip" xml:space="preserve"> <data name="TbRuleOutboundTagTip" xml:space="preserve">
<value>Can fill in the configuration remarks, please make sure it exist and are unique</value> <value>Can fill in the configuration remarks, please make sure it exist and are unique</value>
</data> </data>
<data name="SudoPwdVerfiedSuccessTip" xml:space="preserve">
<value>Sudo password has been verified successfully, please ignore the incorrect password prompts!</value>
</data>
</root> </root>

View File

@ -1395,4 +1395,7 @@
<data name="TbRuleOutboundTagTip" xml:space="preserve"> <data name="TbRuleOutboundTagTip" xml:space="preserve">
<value>Can fill in the configuration remarks, please make sure it exist and are unique</value> <value>Can fill in the configuration remarks, please make sure it exist and are unique</value>
</data> </data>
<data name="SudoPwdVerfiedSuccessTip" xml:space="preserve">
<value>Sudo password has been verified successfully, please ignore the incorrect password prompts!</value>
</data>
</root> </root>

View File

@ -1395,4 +1395,7 @@
<data name="TbRuleOutboundTagTip" xml:space="preserve"> <data name="TbRuleOutboundTagTip" xml:space="preserve">
<value>Can fill in the configuration remarks, please make sure it exist and are unique</value> <value>Can fill in the configuration remarks, please make sure it exist and are unique</value>
</data> </data>
<data name="SudoPwdVerfiedSuccessTip" xml:space="preserve">
<value>Sudo password has been verified successfully, please ignore the incorrect password prompts!</value>
</data>
</root> </root>

View File

@ -1395,4 +1395,7 @@
<data name="TbRuleOutboundTagTip" xml:space="preserve"> <data name="TbRuleOutboundTagTip" xml:space="preserve">
<value>Can fill in the configuration remarks, please make sure it exist and are unique</value> <value>Can fill in the configuration remarks, please make sure it exist and are unique</value>
</data> </data>
<data name="SudoPwdVerfiedSuccessTip" xml:space="preserve">
<value>Sudo password has been verified successfully, please ignore the incorrect password prompts!</value>
</data>
</root> </root>

View File

@ -1392,4 +1392,7 @@
<data name="TbRuleOutboundTagTip" xml:space="preserve"> <data name="TbRuleOutboundTagTip" xml:space="preserve">
<value>可以填写配置文件别名,请确保存在并唯一</value> <value>可以填写配置文件别名,请确保存在并唯一</value>
</data> </data>
<data name="SudoPwdVerfiedSuccessTip" xml:space="preserve">
<value>sudo 密码已经验证成功,请忽略错误密码提示!</value>
</data>
</root> </root>

View File

@ -1392,4 +1392,7 @@
<data name="TbRuleOutboundTagTip" xml:space="preserve"> <data name="TbRuleOutboundTagTip" xml:space="preserve">
<value>可以填寫設定檔別名,請確保存在並唯一</value> <value>可以填寫設定檔別名,請確保存在並唯一</value>
</data> </data>
<data name="SudoPwdVerfiedSuccessTip" xml:space="preserve">
<value>sudo 密碼已經驗證成功,請忽略錯誤密碼提示!</value>
</data>
</root> </root>