mirror of https://github.com/2dust/v2rayN
Improved enhanced tun mode
parent
5e2e45c673
commit
6e366bf55a
|
@ -88,9 +88,10 @@ namespace v2rayN.Handler
|
|||
{
|
||||
if (config.logEnabled)
|
||||
{
|
||||
var dtNow = DateTime.Now;
|
||||
v2rayConfig.log.loglevel = config.loglevel;
|
||||
v2rayConfig.log.access = Utils.GetLogPath(v2rayConfig.log.access);
|
||||
v2rayConfig.log.error = Utils.GetLogPath(v2rayConfig.log.error);
|
||||
v2rayConfig.log.access = Utils.GetLogPath($"Vaccess_{dtNow.ToString("yyyy-MM-dd")}.txt");
|
||||
v2rayConfig.log.error = Utils.GetLogPath($"Verror_{dtNow.ToString("yyyy-MM-dd")}.txt");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -100,6 +100,17 @@ namespace v2rayN.Base
|
|||
configStr = configStr.Replace("$strict_route$", $"{_config.tunModeItem.strictRoute.ToString().ToLower()}");
|
||||
configStr = configStr.Replace("$stack$", $"{_config.tunModeItem.stack}");
|
||||
|
||||
//logs
|
||||
if (_config.tunModeItem.showWindow)
|
||||
{
|
||||
configStr = configStr.Replace("$log_output$", $"");
|
||||
}
|
||||
else
|
||||
{
|
||||
var dtNow = DateTime.Now;
|
||||
var log_output = $"\"output\": \"{Utils.GetLogPath($"singbox_{dtNow.ToString("yyyy-MM-dd")}.txt")}\", ";
|
||||
configStr = configStr.Replace("$log_output$", $"{log_output.Replace(@"\", @"\\")}");
|
||||
}
|
||||
|
||||
//port
|
||||
configStr = configStr.Replace("$socksPort$", $"{_socksPort}");
|
||||
|
@ -118,13 +129,13 @@ namespace v2rayN.Base
|
|||
{
|
||||
if (!lstDnsExe.Contains(it2) && it.coreType != ECoreType.sing_box)
|
||||
{
|
||||
lstDnsExe.Add(it2);
|
||||
//lstDnsExe.Add(it2);
|
||||
lstDnsExe.Add($"{it2}.exe");
|
||||
}
|
||||
|
||||
if (!lstDirectExe.Contains(it2))
|
||||
{
|
||||
lstDirectExe.Add(it2);
|
||||
//lstDirectExe.Add(it2);
|
||||
lstDirectExe.Add($"{it2}.exe");
|
||||
}
|
||||
}
|
||||
|
@ -135,32 +146,50 @@ namespace v2rayN.Base
|
|||
string strDirect = string.Join("\",\"", lstDirectExe.ToArray());
|
||||
configStr = configStr.Replace("$directProcessName$", $"\"{strDirect}\"");
|
||||
|
||||
if (_config.tunModeItem.bypassMode)
|
||||
{
|
||||
//direct ips
|
||||
if (_config.tunModeItem.directIP != null && _config.tunModeItem.directIP.Count > 0)
|
||||
{
|
||||
var ips = new { outbound = "direct", ip_cidr = _config.tunModeItem.directIP };
|
||||
configStr = configStr.Replace("$ruleDirectIPs$", "," + Utils.ToJson(ips));
|
||||
}
|
||||
//direct process
|
||||
if (_config.tunModeItem.directProcess != null && _config.tunModeItem.directProcess.Count > 0)
|
||||
{
|
||||
var process = new { outbound = "direct", process_name = _config.tunModeItem.directProcess };
|
||||
configStr = configStr.Replace("$ruleDirectProcess$", "," + Utils.ToJson(process));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//proxy ips
|
||||
if (_config.tunModeItem.proxyIP != null && _config.tunModeItem.proxyIP.Count > 0)
|
||||
{
|
||||
var ips = new { outbound = "proxy", ip_cidr = _config.tunModeItem.proxyIP };
|
||||
configStr = configStr.Replace("$ruleProxyIPs$", "," + Utils.ToJson(ips));
|
||||
}
|
||||
//proxy process
|
||||
if (_config.tunModeItem.proxyProcess != null && _config.tunModeItem.proxyProcess.Count > 0)
|
||||
{
|
||||
var process = new { outbound = "proxy", process_name = _config.tunModeItem.proxyProcess };
|
||||
configStr = configStr.Replace("$ruleProxyProcess$", "," + Utils.ToJson(process));
|
||||
}
|
||||
|
||||
//ips
|
||||
if (_config.tunModeItem.directIP != null && _config.tunModeItem.directIP.Count > 0)
|
||||
{
|
||||
var ips = new { outbound = "direct", ip_cidr = _config.tunModeItem.directIP };
|
||||
configStr = configStr.Replace("$ruleDirectIPs$", "," + Utils.ToJson(ips));
|
||||
}
|
||||
else
|
||||
{
|
||||
configStr = configStr.Replace("$ruleDirectIPs$", "");
|
||||
}
|
||||
//process
|
||||
if (_config.tunModeItem.directProcess != null && _config.tunModeItem.directProcess.Count > 0)
|
||||
{
|
||||
var process = new { outbound = "direct", process_name = _config.tunModeItem.directProcess };
|
||||
configStr = configStr.Replace("$ruleDirectProcess$", "," + Utils.ToJson(process));
|
||||
}
|
||||
else
|
||||
{
|
||||
configStr = configStr.Replace("$ruleDirectProcess$", "");
|
||||
var final = new { outbound = "direct", inbound = "tun-in" };
|
||||
configStr = configStr.Replace("$ruleFinally$", "," + Utils.ToJson(final));
|
||||
}
|
||||
configStr = configStr.Replace("$ruleDirectIPs$", "");
|
||||
configStr = configStr.Replace("$ruleDirectProcess$", "");
|
||||
configStr = configStr.Replace("$ruleProxyIPs$", "");
|
||||
configStr = configStr.Replace("$ruleProxyProcess$", "");
|
||||
configStr = configStr.Replace("$ruleFinally$", "");
|
||||
|
||||
|
||||
File.WriteAllText(Utils.GetConfigPath(_tunConfigName), configStr);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void CoreStop()
|
||||
{
|
||||
|
@ -172,6 +201,7 @@ namespace v2rayN.Base
|
|||
KillProcess(_process);
|
||||
_process.Dispose();
|
||||
_process = null;
|
||||
_needRestart = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
@ -110,8 +110,11 @@ namespace v2rayN.Mode
|
|||
public string stack { get; set; }
|
||||
public int mtu { get; set; }
|
||||
public string customTemplate { get; set; }
|
||||
public bool bypassMode { get; set; } = true;
|
||||
public List<string> directIP { get; set; }
|
||||
public List<string> directProcess { get; set; }
|
||||
public List<string> proxyIP { get; set; }
|
||||
public List<string> proxyProcess { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2770,6 +2770,24 @@ namespace v2rayN.Resx {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Bypass Mode 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string TbSettingsTunModeBypassMode {
|
||||
get {
|
||||
return ResourceManager.GetString("TbSettingsTunModeBypassMode", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Enable: If no route matches, the final proxy 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string TbSettingsTunModeBypassModeTip {
|
||||
get {
|
||||
return ResourceManager.GetString("TbSettingsTunModeBypassModeTip", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Custom Template 的本地化字符串。
|
||||
/// </summary>
|
||||
|
@ -2797,6 +2815,24 @@ namespace v2rayN.Resx {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Proxy IP CIDR, separated by commas (,) 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string TbSettingsTunModeProxyIP {
|
||||
get {
|
||||
return ResourceManager.GetString("TbSettingsTunModeProxyIP", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Proxy Process name, separated by commas (,) 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string TbSettingsTunModeProxyProcess {
|
||||
get {
|
||||
return ResourceManager.GetString("TbSettingsTunModeProxyProcess", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Show console 的本地化字符串。
|
||||
/// </summary>
|
||||
|
|
|
@ -1108,4 +1108,16 @@
|
|||
<data name="TbSettingsFontSize" xml:space="preserve">
|
||||
<value>FontSize</value>
|
||||
</data>
|
||||
<data name="TbSettingsTunModeProxyIP" xml:space="preserve">
|
||||
<value>Proxy IP CIDR, separated by commas (,)</value>
|
||||
</data>
|
||||
<data name="TbSettingsTunModeProxyProcess" xml:space="preserve">
|
||||
<value>Proxy Process name, separated by commas (,)</value>
|
||||
</data>
|
||||
<data name="TbSettingsTunModeBypassMode" xml:space="preserve">
|
||||
<value>Bypass Mode</value>
|
||||
</data>
|
||||
<data name="TbSettingsTunModeBypassModeTip" xml:space="preserve">
|
||||
<value>Enable: If no route matches, the final proxy</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1108,4 +1108,16 @@
|
|||
<data name="TbSettingsFontSize" xml:space="preserve">
|
||||
<value>字体大小</value>
|
||||
</data>
|
||||
<data name="TbSettingsTunModeProxyIP" xml:space="preserve">
|
||||
<value>代理的IP CIDR,用逗号(,)分隔</value>
|
||||
</data>
|
||||
<data name="TbSettingsTunModeProxyProcess" xml:space="preserve">
|
||||
<value>代理的进程名,用逗号(,)分隔</value>
|
||||
</data>
|
||||
<data name="TbSettingsTunModeBypassMode" xml:space="preserve">
|
||||
<value>绕行模式</value>
|
||||
</data>
|
||||
<data name="TbSettingsTunModeBypassModeTip" xml:space="preserve">
|
||||
<value>启用:路由无匹配则最终代理</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1,4 +1,10 @@
|
|||
{
|
||||
"log": {
|
||||
"disabled": false,
|
||||
"level": "info",
|
||||
$log_output$
|
||||
"timestamp": true
|
||||
},
|
||||
"dns": {
|
||||
"servers": [
|
||||
{
|
||||
|
@ -23,6 +29,7 @@
|
|||
"inbounds": [
|
||||
{
|
||||
"type": "tun",
|
||||
"tag": "tun-in",
|
||||
"interface_name": "singbox_tun",
|
||||
"inet4_address": "172.19.0.1/30",
|
||||
|
||||
|
@ -102,6 +109,9 @@
|
|||
}
|
||||
$ruleDirectIPs$
|
||||
$ruleDirectProcess$
|
||||
$ruleProxyIPs$
|
||||
$ruleProxyProcess$
|
||||
$ruleFinally$
|
||||
]
|
||||
}
|
||||
}
|
|
@ -77,8 +77,12 @@ namespace v2rayN.ViewModels
|
|||
[Reactive] public string TunStack { get; set; }
|
||||
[Reactive] public int TunMtu { get; set; }
|
||||
[Reactive] public string TunCustomTemplate { get; set; }
|
||||
[Reactive] public bool TunBypassMode { get; set; }
|
||||
[Reactive] public bool TunBypassMode2 { get; set; }
|
||||
[Reactive] public string TunDirectIP { get; set; }
|
||||
[Reactive] public string TunDirectProcess { get; set; }
|
||||
[Reactive] public string TunProxyIP { get; set; }
|
||||
[Reactive] public string TunProxyProcess { get; set; }
|
||||
#endregion
|
||||
|
||||
#region CoreType
|
||||
|
@ -164,8 +168,14 @@ namespace v2rayN.ViewModels
|
|||
TunStack = _config.tunModeItem.stack;
|
||||
TunMtu = _config.tunModeItem.mtu;
|
||||
TunCustomTemplate = _config.tunModeItem.customTemplate;
|
||||
TunBypassMode = _config.tunModeItem.bypassMode;
|
||||
TunDirectIP = Utils.List2String(_config.tunModeItem.directIP, true);
|
||||
TunDirectProcess = Utils.List2String(_config.tunModeItem.directProcess, true);
|
||||
TunProxyIP = Utils.List2String(_config.tunModeItem.proxyIP, true);
|
||||
TunProxyProcess = Utils.List2String(_config.tunModeItem.proxyProcess, true);
|
||||
this.WhenAnyValue(
|
||||
x => x.TunBypassMode)
|
||||
.Subscribe(c => TunBypassMode2 = !TunBypassMode);
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -328,8 +338,11 @@ namespace v2rayN.ViewModels
|
|||
_config.tunModeItem.stack = TunStack;
|
||||
_config.tunModeItem.mtu = TunMtu;
|
||||
_config.tunModeItem.customTemplate = TunCustomTemplate;
|
||||
_config.tunModeItem.bypassMode = TunBypassMode;
|
||||
_config.tunModeItem.directIP = Utils.String2List(TunDirectIP);
|
||||
_config.tunModeItem.directProcess = Utils.String2List(TunDirectProcess);
|
||||
_config.tunModeItem.proxyIP = Utils.String2List(TunProxyIP);
|
||||
_config.tunModeItem.proxyProcess = Utils.String2List(TunProxyProcess);
|
||||
|
||||
//coreType
|
||||
SaveCoreType();
|
||||
|
|
|
@ -771,6 +771,7 @@
|
|||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
|
@ -849,7 +850,7 @@
|
|||
x:Name="txtCustomTemplate"
|
||||
Grid.Row="5"
|
||||
Grid.Column="1"
|
||||
Width="600"
|
||||
Width="400"
|
||||
Margin="{StaticResource SettingItemMargin}"
|
||||
VerticalAlignment="Top"
|
||||
AcceptsReturn="True"
|
||||
|
@ -864,9 +865,35 @@
|
|||
Click="btnBrowse_Click"
|
||||
Content="{x:Static resx:ResUI.TbBrowse}"
|
||||
Style="{StaticResource DefButton}" />
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="6"
|
||||
Grid.Column="0"
|
||||
Margin="{StaticResource SettingItemMargin}"
|
||||
VerticalAlignment="Center"
|
||||
Style="{StaticResource ToolbarTextBlock}"
|
||||
Text="{x:Static resx:ResUI.TbSettingsTunModeBypassMode}" />
|
||||
<ToggleButton
|
||||
x:Name="togBypassMode"
|
||||
Grid.Row="6"
|
||||
Grid.Column="1"
|
||||
Margin="{StaticResource SettingItemMargin}"
|
||||
HorizontalAlignment="Left" />
|
||||
<TextBlock
|
||||
Grid.Row="6"
|
||||
Grid.Column="2"
|
||||
Margin="{StaticResource ServerItemMargin}"
|
||||
VerticalAlignment="Center"
|
||||
Style="{StaticResource ToolbarTextBlock}"
|
||||
Text="{x:Static resx:ResUI.TbSettingsTunModeBypassModeTip}" />
|
||||
</Grid>
|
||||
|
||||
<Grid Margin="{StaticResource SettingItemMargin}">
|
||||
|
||||
<Grid
|
||||
x:Name="gridTunModeDirect"
|
||||
Width="600"
|
||||
Margin="{StaticResource SettingItemMargin}"
|
||||
HorizontalAlignment="Left">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="10" />
|
||||
|
@ -896,6 +923,42 @@
|
|||
VerticalScrollBarVisibility="Auto" />
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
|
||||
<Grid
|
||||
x:Name="gridTunModeProxy"
|
||||
Width="600"
|
||||
Margin="{StaticResource SettingItemMargin}"
|
||||
HorizontalAlignment="Left">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="10" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<GroupBox
|
||||
Grid.Column="0"
|
||||
Header="{x:Static resx:ResUI.TbSettingsTunModeProxyIP}"
|
||||
Style="{StaticResource MyGroupBox}">
|
||||
<TextBox
|
||||
Name="txtProxyIP"
|
||||
AcceptsReturn="True"
|
||||
Style="{StaticResource DefTextBox}"
|
||||
TextWrapping="Wrap"
|
||||
VerticalScrollBarVisibility="Auto" />
|
||||
</GroupBox>
|
||||
<GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" />
|
||||
<GroupBox
|
||||
Grid.Column="2"
|
||||
Header="{x:Static resx:ResUI.TbSettingsTunModeProxyProcess}"
|
||||
Style="{StaticResource MyGroupBox}">
|
||||
<TextBox
|
||||
Name="txtProxyProcess"
|
||||
AcceptsReturn="True"
|
||||
Style="{StaticResource DefTextBox}"
|
||||
TextWrapping="Wrap"
|
||||
VerticalScrollBarVisibility="Auto" />
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
|
||||
</DockPanel>
|
||||
</TabItem>
|
||||
|
||||
|
|
|
@ -164,8 +164,13 @@ namespace v2rayN.Views
|
|||
this.Bind(ViewModel, vm => vm.TunStack, v => v.cmbStack.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.TunMtu, v => v.cmbMtu.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.TunCustomTemplate, v => v.txtCustomTemplate.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.TunBypassMode, v => v.togBypassMode.IsChecked).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.TunBypassMode, v => v.gridTunModeDirect.Visibility, vmToViewConverterOverride: new BooleanToVisibilityTypeConverter()).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.TunBypassMode2, v => v.gridTunModeProxy.Visibility, vmToViewConverterOverride: new BooleanToVisibilityTypeConverter()).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.TunDirectIP, v => v.txtDirectIP.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.TunDirectProcess, v => v.txtDirectProcess.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.TunProxyIP, v => v.txtProxyIP.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.TunProxyProcess, v => v.txtProxyProcess.Text).DisposeWith(disposables);
|
||||
|
||||
|
||||
this.Bind(ViewModel, vm => vm.CoreType1, v => v.cmbCoreType1.Text).DisposeWith(disposables);
|
||||
|
|
Loading…
Reference in New Issue