Compare commits

..

No commits in common. "0032a3d27af7d91010233bed494105120f0cff5b" and "3f19958c75566493b61234a948b3e0770ac71cbc" have entirely different histories.

19 changed files with 95 additions and 241 deletions

View file

@ -5,83 +5,21 @@ internal static class Program
[STAThread]
private static void Main(string[] args)
{
try
if (args.Length == 0)
{
// If no arguments are provided, display usage guidelines and exit
if (args.Length == 0)
{
ShowHelp();
return;
}
// Log all arguments for debugging purposes
foreach (var arg in args)
{
Console.WriteLine(arg);
}
// Parse command based on first argument
switch (args[0].ToLowerInvariant())
{
case "rebootas":
// Handle application restart
HandleRebootAsync();
break;
case "help":
case "--help":
case "-h":
case "/?":
// Display help information
ShowHelp();
break;
default:
// Default behavior: handle as upgrade data
// Maintain backward compatibility with existing usage pattern
var argData = Uri.UnescapeDataString(string.Join(" ", args));
HandleUpgrade(argData);
break;
}
Console.WriteLine(Resx.Resource.Guidelines);
Thread.Sleep(5000);
return;
}
catch (Exception ex)
var argData = Uri.UnescapeDataString(string.Join(" ", args));
if (argData.Equals("rebootas"))
{
// Global exception handling
Console.WriteLine($"An error occurred: {ex.Message}");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
Thread.Sleep(1000);
Utils.StartV2RayN();
return;
}
}
/// <summary>
/// Display help information and usage guidelines
/// </summary>
private static void ShowHelp()
{
Console.WriteLine(Resx.Resource.Guidelines);
Console.WriteLine("Available commands:");
Console.WriteLine(" rebootas - Restart the application");
Console.WriteLine(" help - Display this help information");
Thread.Sleep(5000);
}
/// <summary>
/// Handle application restart
/// </summary>
private static void HandleRebootAsync()
{
Console.WriteLine("Restarting application...");
Thread.Sleep(1000);
Utils.StartV2RayN();
}
/// <summary>
/// Handle application upgrade with the provided data
/// </summary>
/// <param name="upgradeData">Data for the upgrade process</param>
private static void HandleUpgrade(string upgradeData)
{
Console.WriteLine("Upgrading application...");
UpgradeApp.Upgrade(upgradeData);
UpgradeApp.Upgrade(argData);
}
}

View file

@ -20,7 +20,6 @@ public enum EViewAction
BrowseServer,
ImportRulesFromFile,
InitSettingFont,
PasswordInput,
SubEditWindow,
RoutingRuleSettingWindow,
RoutingRuleDetailsWindow,

View file

@ -40,8 +40,6 @@ public sealed class AppHandler
}
}
public string LinuxSudoPwd { get; set; }
#endregion Property
#region Init

View file

@ -155,12 +155,6 @@ public class CoreHandler
{
try
{
if (_linuxSudoPid > 0)
{
await KillProcessAsLinuxSudo();
_linuxSudoPid = -1;
}
if (_process != null)
{
await ProcUtils.ProcessKill(_process, true);
@ -172,6 +166,12 @@ public class CoreHandler
await ProcUtils.ProcessKill(_processPre, true);
_processPre = null;
}
if (_linuxSudoPid > 0)
{
await KillProcessAsLinuxSudo();
}
_linuxSudoPid = -1;
}
catch (Exception ex)
{
@ -229,7 +229,9 @@ public class CoreHandler
{
return _config.TunModeItem.EnableTun
&& eCoreType == ECoreType.sing_box
&& Utils.IsNonWindows();
&& (Utils.IsNonWindows())
//&& _config.TunModeItem.LinuxSudoPwd.IsNotEmpty()
;
}
#endregion Private
@ -286,11 +288,13 @@ public class CoreHandler
}
proc.Start();
if (isNeedSudo && AppHandler.Instance.LinuxSudoPwd.IsNotEmpty())
if (isNeedSudo && _config.TunModeItem.LinuxSudoPwd.IsNotEmpty())
{
await proc.StandardInput.WriteLineAsync();
var pwd = DesUtils.Decrypt(_config.TunModeItem.LinuxSudoPwd);
await Task.Delay(10);
await proc.StandardInput.WriteLineAsync(AppHandler.Instance.LinuxSudoPwd);
await proc.StandardInput.WriteLineAsync(pwd);
await Task.Delay(10);
await proc.StandardInput.WriteLineAsync(pwd);
}
if (isNeedSudo)
_linuxSudoPid = proc.Id;
@ -329,7 +333,7 @@ public class CoreHandler
proc.StartInfo.FileName = shFilePath;
proc.StartInfo.Arguments = "";
proc.StartInfo.WorkingDirectory = "";
if (AppHandler.Instance.LinuxSudoPwd.IsNotEmpty())
if (_config.TunModeItem.LinuxSudoPwd.IsNotEmpty())
{
proc.StartInfo.StandardInputEncoding = Encoding.UTF8;
proc.StartInfo.RedirectStandardInput = true;
@ -338,7 +342,7 @@ public class CoreHandler
private async Task KillProcessAsLinuxSudo()
{
var cmdLine = $"pkill -P {_linuxSudoPid} ; kill {_linuxSudoPid}";
var cmdLine = $"kill {_linuxSudoPid}";
var shFilePath = await CreateLinuxShellFile(cmdLine, "kill_as_sudo.sh");
Process proc = new()
{
@ -353,13 +357,15 @@ public class CoreHandler
};
proc.Start();
if (AppHandler.Instance.LinuxSudoPwd.IsNotEmpty())
if (_config.TunModeItem.LinuxSudoPwd.IsNotEmpty())
{
try
{
await proc.StandardInput.WriteLineAsync();
var pwd = DesUtils.Decrypt(_config.TunModeItem.LinuxSudoPwd);
await Task.Delay(10);
await proc.StandardInput.WriteLineAsync(AppHandler.Instance.LinuxSudoPwd);
await proc.StandardInput.WriteLineAsync(pwd);
await Task.Delay(10);
await proc.StandardInput.WriteLineAsync(pwd);
}
catch (Exception)
{
@ -369,7 +375,7 @@ public class CoreHandler
var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(10));
await proc.WaitForExitAsync(timeout.Token);
await Task.Delay(1000);
await Task.Delay(3000);
}
private async Task<string> CreateLinuxShellFile(string cmdLine, string fileName)
@ -383,6 +389,10 @@ public class CoreHandler
{
sb.AppendLine($"{cmdLine}");
}
else if (_config.TunModeItem.LinuxSudoPwd.IsNullOrEmpty())
{
sb.AppendLine($"pkexec {cmdLine}");
}
else
{
sb.AppendLine($"sudo -S {cmdLine}");
@ -390,7 +400,7 @@ public class CoreHandler
await File.WriteAllTextAsync(shFilePath, sb.ToString());
await Utils.SetLinuxChmod(shFilePath);
//Logging.SaveLog(shFilePath);
Logging.SaveLog(shFilePath);
return shFilePath;
}

View file

@ -147,6 +147,7 @@ public class TunModeItem
public int Mtu { get; set; }
public bool EnableExInbound { get; set; }
public bool EnableIPv6Address { get; set; }
public string? LinuxSudoPwd { get; set; }
}
[Serializable]

View file

@ -3247,7 +3247,7 @@ namespace ServiceLib.Resx {
}
/// <summary>
/// 查找类似 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 is encrypted and stored only in local files 的本地化字符串。
/// </summary>
public static string TbSettingsLinuxSudoPasswordTip {
get {

View file

@ -1339,7 +1339,7 @@
<value>رمز عبور sudo سیستم</value>
</data>
<data name="TbSettingsLinuxSudoPasswordTip" xml:space="preserve">
<value>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.</value>
<value>رمز عبور رمزگذاری شده و فقط در فایل های محلی ذخیره می شود.</value>
</data>
<data name="TbSettingsLinuxSudoPasswordIsEmpty" xml:space="preserve">
<value>لطفاً ابتدا رمز عبور sudo را در تنظیمات حالت Tun تنظیم کنید</value>
@ -1416,4 +1416,4 @@
<data name="menuExportConfig" xml:space="preserve">
<value>صادر کردن سرور</value>
</data>
</root>
</root>

View file

@ -1339,7 +1339,7 @@
<value>Rendszer sudo jelszó</value>
</data>
<data name="TbSettingsLinuxSudoPasswordTip" xml:space="preserve">
<value>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.</value>
<value>A jelszó titkosítva és csak a helyi fájlokban tárolva.</value>
</data>
<data name="TbSettingsLinuxSudoPasswordIsEmpty" xml:space="preserve">
<value>Kérlek, először állítsd be a sudo jelszót a Tun módban</value>

View file

@ -1339,7 +1339,7 @@
<value>System sudo password</value>
</data>
<data name="TbSettingsLinuxSudoPasswordTip" xml:space="preserve">
<value>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.</value>
<value>The password is encrypted and stored only in local files</value>
</data>
<data name="TbSettingsLinuxSudoPasswordIsEmpty" xml:space="preserve">
<value>Please set the sudo password in Tun mode settings first</value>

View file

@ -1339,7 +1339,7 @@
<value>System sudo password</value>
</data>
<data name="TbSettingsLinuxSudoPasswordTip" xml:space="preserve">
<value>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.</value>
<value>Пароль зашифрован и хранится только в локальных файлах..</value>
</data>
<data name="TbSettingsLinuxSudoPasswordIsEmpty" xml:space="preserve">
<value>Please set the sudo password in Tun mode settings first</value>

View file

@ -1071,13 +1071,13 @@
<data name="TbHeaderType8" xml:space="preserve">
<value>拥塞控制算法</value>
</data>
<data name="LvPrevProfile" xml:space="preserve">
<data name="LvPrevProfile" xml:space="preserve">
<value>前置代理配置文件别名</value>
</data>
<data name="LvNextProfile" xml:space="preserve">
<data name="LvNextProfile" xml:space="preserve">
<value>落地代理配置文件別名</value>
</data>
<data name="LvPrevProfileTip" xml:space="preserve">
<data name="LvPrevProfileTip" xml:space="preserve">
<value>请确保配置文件别名存在并唯一</value>
</data>
<data name="TbSettingsEnableExInbound" xml:space="preserve">
@ -1336,7 +1336,7 @@
<value>系统的 sudo 密码</value>
</data>
<data name="TbSettingsLinuxSudoPasswordTip" xml:space="preserve">
<value>输入的密码无法校验,所以请确保输入正确。如果因为输入错误导致无法正常运行时,请重启本应用。 密码不会存储,每次重启后都需要再次输入。</value>
<value>密码已加密且只存储在本地文件中,无密码则每次都要输入</value>
</data>
<data name="TbSettingsLinuxSudoPasswordIsEmpty" xml:space="preserve">
<value>请先在 Tun 模式设置中设置 sudo 密码</value>
@ -1413,4 +1413,4 @@
<data name="menuExportConfig" xml:space="preserve">
<value>导出配置文件</value>
</data>
</root>
</root>

View file

@ -1071,13 +1071,13 @@
<data name="TbHeaderType8" xml:space="preserve">
<value>擁塞控制算法</value>
</data>
<data name="LvPrevProfile" xml:space="preserve">
<data name="LvPrevProfile" xml:space="preserve">
<value>前置代理設定檔別名</value>
</data>
<data name="LvNextProfile" xml:space="preserve">
<data name="LvNextProfile" xml:space="preserve">
<value>落地代理設定檔別名</value>
</data>
<data name="LvPrevProfileTip" xml:space="preserve">
<data name="LvPrevProfileTip" xml:space="preserve">
<value>請確保設定檔別名存在並且唯一</value>
</data>
<data name="TbSettingsEnableExInbound" xml:space="preserve">
@ -1336,7 +1336,7 @@
<value>系統的 sudo 密碼</value>
</data>
<data name="TbSettingsLinuxSudoPasswordTip" xml:space="preserve">
<value>輸入的密碼無法校驗,所以請確保輸入正確。如果因為輸入錯誤導致無法正常運作時,請重新啟動本應用。 密碼不會存儲,每次重啟後都需要再次輸入。</value>
<value>密碼已加密且只儲存在本機檔案中,無密碼則每次都要輸入</value>
</data>
<data name="TbSettingsLinuxSudoPasswordIsEmpty" xml:space="preserve">
<value>請先在 Tun 模式設定中設定 sudo 密碼</value>
@ -1413,4 +1413,4 @@
<data name="menuExportConfig" xml:space="preserve">
<value>匯出設定檔</value>
</data>
</root>
</root>

View file

@ -88,6 +88,7 @@ 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
@ -204,6 +205,7 @@ public class OptionSettingViewModel : MyReactiveObject
TunMtu = _config.TunModeItem.Mtu;
TunEnableExInbound = _config.TunModeItem.EnableExInbound;
TunEnableIPv6Address = _config.TunModeItem.EnableIPv6Address;
TunLinuxSudoPassword = _config.TunModeItem.LinuxSudoPwd;
#endregion Tun mode
@ -356,7 +358,11 @@ 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();

View file

@ -436,13 +436,11 @@ public class StatusBarViewModel : MyReactiveObject
Locator.Current.GetService<MainWindowViewModel>()?.RebootAsAdmin();
return;
}
else
else if (Utils.IsOSX())
{
if (await _updateView?.Invoke(EViewAction.PasswordInput, null) == false)
{
_config.TunModeItem.EnableTun = false;
return;
}
_config.TunModeItem.EnableTun = false;
NoticeHandler.Instance.SendMessageAndEnqueue(ResUI.TbSettingsLinuxSudoPasswordIsEmpty);
return;
}
}
await ConfigHandler.SaveConfig(_config);
@ -458,11 +456,11 @@ public class StatusBarViewModel : MyReactiveObject
}
else if (Utils.IsLinux())
{
return AppHandler.Instance.LinuxSudoPwd.IsNotEmpty();
return _config.TunModeItem.LinuxSudoPwd.IsNotEmpty();
}
else if (Utils.IsOSX())
{
return AppHandler.Instance.LinuxSudoPwd.IsNotEmpty();
return _config.TunModeItem.LinuxSudoPwd.IsNotEmpty();
}
return false;
}

View file

@ -784,6 +784,28 @@
Margin="{StaticResource Margin4}"
HorizontalAlignment="Left" />
<TextBlock
x:Name="labLinuxSudoPassword"
Grid.Row="7"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbSettingsLinuxSudoPassword}" />
<TextBox
x:Name="txtLinuxSudoPassword"
Grid.Row="7"
Grid.Column="1"
Width="200"
Margin="{StaticResource Margin4}"
HorizontalAlignment="Left" />
<TextBlock
x:Name="labLinuxSudoPasswordTip"
Grid.Row="7"
Grid.Column="2"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbSettingsLinuxSudoPasswordTip}"
TextWrapping="Wrap" />
</Grid>
</TabItem>

View file

@ -153,6 +153,7 @@ public partial class OptionSettingWindow : ReactiveWindow<OptionSettingViewModel
this.Bind(ViewModel, vm => 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);
@ -169,6 +170,10 @@ public partial class OptionSettingWindow : ReactiveWindow<OptionSettingViewModel
{
txbSettingsExceptionTip2.IsVisible = false;
txtLinuxSudoPassword.IsVisible = false;
labLinuxSudoPassword.IsVisible = false;
labLinuxSudoPasswordTip.IsVisible = false;
labHide2TrayWhenClose.IsVisible = false;
togHide2TrayWhenClose.IsVisible = false;
}

View file

@ -4,11 +4,9 @@ using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.ReactiveUI;
using Avalonia.Threading;
using DialogHostAvalonia;
using ReactiveUI;
using Splat;
using v2rayN.Desktop.Common;
using static QRCoder.PayloadGenerator;
namespace v2rayN.Desktop.Views;
@ -83,10 +81,6 @@ public partial class StatusBarView : ReactiveUserControl<StatusBarViewModel>
return false;
await AvaUtils.SetClipboardData(this, (string)obj);
break;
case EViewAction.PasswordInput:
return await PasswordInputAsync();
break;
}
return await Task.FromResult(true);
}
@ -102,20 +96,6 @@ public partial class StatusBarView : ReactiveUserControl<StatusBarViewModel>
}
}
private async Task<bool> 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();

View file

@ -1,70 +0,0 @@
<UserControl
x:Class="v2rayN.Desktop.Views.SudoPasswordInputView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:resx="clr-namespace:ServiceLib.Resx;assembly=ServiceLib"
d:DesignHeight="200"
d:DesignWidth="400"
mc:Ignorable="d">
<DockPanel Margin="{StaticResource Margin8}">
<Border
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
DockPanel.Dock="Bottom"
Theme="{DynamicResource CardBorder}">
<StackPanel
Margin="{StaticResource Margin4}"
HorizontalAlignment="Center"
Orientation="Horizontal">
<Button
x:Name="btnSave"
Width="100"
Content="{x:Static resx:ResUI.TbConfirm}"
Cursor="Hand"
IsDefault="True" />
<Button
x:Name="btnCancel"
Width="100"
Margin="{StaticResource MarginLr8}"
Content="{x:Static resx:ResUI.TbCancel}"
Cursor="Hand"
IsCancel="True" />
</StackPanel>
</Border>
<Border
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Theme="{DynamicResource CardBorder}">
<Grid ColumnDefinitions="Auto,400" RowDefinitions="Auto,Auto,Auto">
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbSettingsLinuxSudoPassword}" />
<TextBox
x:Name="txtPassword"
Grid.Row="1"
Grid.Column="1"
Margin="{StaticResource Margin4}"
Classes="revealPasswordButton"
Focusable="True" />
<TextBlock
Grid.Row="2"
Grid.Column="1"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbSettingsLinuxSudoPasswordTip}"
TextWrapping="Wrap" />
</Grid>
</Border>
</DockPanel>
</UserControl>

View file

@ -1,33 +0,0 @@
using Avalonia.Controls;
using Avalonia.Threading;
using DialogHostAvalonia;
namespace v2rayN.Desktop.Views;
public partial class SudoPasswordInputView : UserControl
{
public SudoPasswordInputView()
{
InitializeComponent();
this.Loaded += (s, e) => txtPassword.Focus();
btnSave.Click += (_, _) =>
{
if (string.IsNullOrEmpty(txtPassword.Text))
{
txtPassword.Focus();
return;
}
Dispatcher.UIThread.Post(() =>
{
DialogHost.Close(null, txtPassword.Text);
});
};
btnCancel.Click += (_, _) =>
{
DialogHost.Close(null);
};
}
}