Skip to content

Commit

Permalink
Code clean
Browse files Browse the repository at this point in the history
Add allowInsecure to Share
  • Loading branch information
2dust committed Jul 11, 2024
1 parent 39faccf commit 9f4718a
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 145 deletions.
9 changes: 2 additions & 7 deletions v2rayN/v2rayN/Common/YamlUtils.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

namespace v2rayN.Common
Expand Down Expand Up @@ -60,4 +55,4 @@ public static string ToYaml(Object obj)

#endregion YAML
}
}
}
4 changes: 4 additions & 0 deletions v2rayN/v2rayN/Handler/Fmt/BaseFmt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ protected static int GetStdTransport(ProfileItem item, string? securityDef, ref
{
dicQuery.Add("spx", Utils.UrlEncode(item.spiderX));
}
if (item.allowInsecure.Equals("true"))
{
dicQuery.Add("allowInsecure", "1");
}

dicQuery.Add("type", !Utils.IsNullOrEmpty(item.network) ? item.network : nameof(ETransport.tcp));

Expand Down
125 changes: 11 additions & 114 deletions v2rayN/v2rayN/Handler/Fmt/VmessFmt.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
using System.Text.RegularExpressions;
using v2rayN.Enums;
using v2rayN.Enums;
using v2rayN.Models;
using v2rayN.Resx;

namespace v2rayN.Handler.Fmt
{
internal class VmessFmt : BaseFmt
{
private static readonly Regex StdVmessUserInfo = new(
@"^(?<network>[a-z]+)(\+(?<streamSecurity>[a-z]+))?:(?<id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$", RegexOptions.Compiled);

public static ProfileItem? Resolve(string str, out string msg)
{
msg = ResUI.ConfigurationFormatIncorrect;
ProfileItem? item;
int indexSplit = str.IndexOf("?");
if (indexSplit > 0)
if (str.IndexOf('?') > 0 && str.IndexOf('&') > 0)
{
item = ResolveStdVmess(str) ?? ResolveVmess4Kitsunebi(str);
item = ResolveStdVmess(str);
}
else
{
Expand Down Expand Up @@ -107,121 +102,23 @@ internal class VmessFmt : BaseFmt
return item;
}

private static ProfileItem? ResolveStdVmess(string result)
public static ProfileItem? ResolveStdVmess(string str)
{
ProfileItem item = new()
{
configType = EConfigType.VMess,
security = "auto"
};

Uri u = new(result);

item.address = u.IdnHost;
item.port = u.Port;
item.remarks = u.GetComponents(UriComponents.Fragment, UriFormat.Unescaped);
var query = Utils.ParseQueryString(u.Query);

var m = StdVmessUserInfo.Match(u.UserInfo);
if (!m.Success) return null;

item.id = m.Groups["id"].Value;

if (m.Groups["streamSecurity"].Success)
{
item.streamSecurity = m.Groups["streamSecurity"].Value;
}
switch (item.streamSecurity)
{
case Global.StreamSecurity:
break;

default:
if (!Utils.IsNullOrEmpty(item.streamSecurity))
return null;
break;
}
Uri url = new(str);

item.network = m.Groups["network"].Value;
switch (item.network)
{
case nameof(ETransport.tcp):
string t1 = query["type"] ?? Global.None;
item.headerType = t1;
break;

case nameof(ETransport.kcp):
item.headerType = query["type"] ?? Global.None;
break;

case nameof(ETransport.ws):
case nameof(ETransport.httpupgrade):
case nameof(ETransport.splithttp):
string p1 = query["path"] ?? "/";
string h1 = query["host"] ?? "";
item.requestHost = Utils.UrlDecode(h1);
item.path = p1;
break;

case nameof(ETransport.http):
case nameof(ETransport.h2):
item.network = nameof(ETransport.h2);
string p2 = query["path"] ?? "/";
string h2 = query["host"] ?? "";
item.requestHost = Utils.UrlDecode(h2);
item.path = p2;
break;

case nameof(ETransport.quic):
string s = query["security"] ?? Global.None;
string k = query["key"] ?? "";
string t3 = query["type"] ?? Global.None;
item.headerType = t3;
item.requestHost = Utils.UrlDecode(s);
item.path = k;
break;

default:
return null;
}
item.address = url.IdnHost;
item.port = url.Port;
item.remarks = url.GetComponents(UriComponents.Fragment, UriFormat.Unescaped);
item.id = Utils.UrlDecode(url.UserInfo);

return item;
}

private static ProfileItem? ResolveVmess4Kitsunebi(string result)
{
ProfileItem item = new()
{
configType = EConfigType.VMess
};
result = result[Global.ProtocolShares[EConfigType.VMess].Length..];
int indexSplit = result.IndexOf("?");
if (indexSplit > 0)
{
result = result[..indexSplit];
}
result = Utils.Base64Decode(result);

string[] arr1 = result.Split('@');
if (arr1.Length != 2)
{
return null;
}
string[] arr21 = arr1[0].Split(':');
string[] arr22 = arr1[1].Split(':');
if (arr21.Length != 2 || arr22.Length != 2)
{
return null;
}

item.address = arr22[0];
item.port = Utils.ToInt(arr22[1]);
item.security = arr21[0];
item.id = arr21[1];

item.network = Global.DefaultNetwork;
item.headerType = Global.None;
item.remarks = "Alien";
var query = Utils.ParseQueryString(url.Query);
ResolveStdTransport(query, ref item);

return item;
}
Expand Down
4 changes: 1 addition & 3 deletions v2rayN/v2rayN/Models/ClashProviders.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@


using static v2rayN.Models.ClashProxies;
using static v2rayN.Models.ClashProxies;

namespace v2rayN.Models
{
Expand Down
6 changes: 3 additions & 3 deletions v2rayN/v2rayN/ViewModels/ClashProxiesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void ProxiesClear()
public void ProxiesDelayTest()
{
ProxiesDelayTest(true);
}
}

#region proxy function

Expand Down Expand Up @@ -337,7 +337,7 @@ private void RefreshProxyDetails(bool c)

private ProxiesItem? TryGetProxy(string name)
{
if(proxies is null)
if (proxies is null)
return null;
proxies.TryGetValue(name, out ProxiesItem proxy2);
if (proxy2 != null)
Expand Down Expand Up @@ -479,7 +479,7 @@ public void DelayTestTask()
}
Thread.Sleep(1000);
}
});
});
}

#endregion task
Expand Down
5 changes: 3 additions & 2 deletions v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public class MainWindowViewModel : ReactiveObject

//CheckUpdate
public ReactiveCommand<Unit, Unit> CheckUpdateNCmd { get; }

public ReactiveCommand<Unit, Unit> CheckUpdateXrayCoreCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateClashMetaCoreCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateSingBoxCoreCmd { get; }
Expand Down Expand Up @@ -1519,11 +1520,11 @@ public void Reload()
{
BlReloadEnabled = true;
ShowCalshUI = (_config.runningCoreType is ECoreType.clash or ECoreType.clash_meta or ECoreType.mihomo);
if (ShowCalshUI) {
if (ShowCalshUI)
{
Locator.Current.GetService<ClashProxiesViewModel>()?.ProxiesReload();
}
}));

});
}

Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Views/ClashConnectionsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using v2rayN.ViewModels;
using ReactiveUI;
using System.Reactive.Disposables;
using v2rayN.ViewModels;

namespace v2rayN.Views
{
Expand Down
9 changes: 4 additions & 5 deletions v2rayN/v2rayN/Views/ClashProxiesView.xaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<reactiveui:ReactiveUserControl
x:Class="v2rayN.Views.ClashProxiesView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:v2rayN.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:v2rayN.Views"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:reactiveui="http://reactiveui.net"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:converters="clr-namespace:v2rayN.Converters"
xmlns:resx="clr-namespace:v2rayN.Resx"
xmlns:vms="clr-namespace:v2rayN.ViewModels"
d:DesignHeight="450"
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Views/ClashProxiesView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using v2rayN.ViewModels;
using ReactiveUI;
using Splat;
using System.Reactive.Disposables;
using System.Windows.Input;
using v2rayN.ViewModels;

namespace v2rayN.Views
{
Expand Down
1 change: 0 additions & 1 deletion v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public DNSSettingWindow()
{
cmbdomainStrategy4Out.Items.Add(it);
});


this.WhenActivated(disposables =>
{
Expand Down
8 changes: 4 additions & 4 deletions v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<reactiveui:ReactiveWindow
x:Class="v2rayN.Views.RoutingRuleDetailsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:conv="clr-namespace:v2rayN.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:reactiveui="http://reactiveui.net"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:conv="clr-namespace:v2rayN.Converters"
xmlns:resx="clr-namespace:v2rayN.Resx"
xmlns:vms="clr-namespace:v2rayN.ViewModels"
Title="{x:Static resx:ResUI.menuRoutingRuleDetailsSetting}"
Expand Down
8 changes: 4 additions & 4 deletions v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<reactiveui:ReactiveWindow
x:Class="v2rayN.Views.RoutingRuleSettingWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:conv="clr-namespace:v2rayN.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:reactiveui="http://reactiveui.net"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:conv="clr-namespace:v2rayN.Converters"
xmlns:resx="clr-namespace:v2rayN.Resx"
xmlns:vms="clr-namespace:v2rayN.ViewModels"
Title="{x:Static resx:ResUI.menuRoutingRuleSetting}"
Expand Down

0 comments on commit 9f4718a

Please sign in to comment.