mirror of https://github.com/2dust/v2rayN
Enhanced share link
parent
f84e538b6a
commit
b5b5eb25a1
|
@ -69,7 +69,7 @@ namespace v2rayN.Handler
|
||||||
add = item.address,
|
add = item.address,
|
||||||
port = item.port.ToString(),
|
port = item.port.ToString(),
|
||||||
id = item.id,
|
id = item.id,
|
||||||
aid = item.alterId.ToString(),
|
aid = "0",
|
||||||
scy = item.security,
|
scy = item.security,
|
||||||
net = item.network,
|
net = item.network,
|
||||||
type = item.headerType,
|
type = item.headerType,
|
||||||
|
@ -96,15 +96,15 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
remark = "#" + Utils.UrlEncode(item.remarks);
|
remark = "#" + Utils.UrlEncode(item.remarks);
|
||||||
}
|
}
|
||||||
url = string.Format("{0}:{1}@{2}:{3}",
|
//url = string.Format("{0}:{1}@{2}:{3}",
|
||||||
item.security,
|
// item.security,
|
||||||
item.id,
|
// item.id,
|
||||||
item.address,
|
// item.address,
|
||||||
item.port);
|
// item.port);
|
||||||
url = Utils.Base64Encode(url);
|
//url = Utils.Base64Encode(url);
|
||||||
//new
|
//new Sip002
|
||||||
//var pw = Utils.Base64Encode($"{item.security}:{item.id}");
|
var pw = Utils.Base64Encode($"{item.security}:{item.id}");
|
||||||
//url = $"{pw}@{item.address}:{ item.port}";
|
url = $"{pw}@{GetIpv6(item.address)}:{ item.port}";
|
||||||
url = string.Format("{0}{1}{2}", Global.ssProtocol, url, remark);
|
url = string.Format("{0}{1}{2}", Global.ssProtocol, url, remark);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
@ -117,12 +117,15 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
remark = "#" + Utils.UrlEncode(item.remarks);
|
remark = "#" + Utils.UrlEncode(item.remarks);
|
||||||
}
|
}
|
||||||
url = string.Format("{0}:{1}@{2}:{3}",
|
//url = string.Format("{0}:{1}@{2}:{3}",
|
||||||
item.security,
|
// item.security,
|
||||||
item.id,
|
// item.id,
|
||||||
item.address,
|
// item.address,
|
||||||
item.port);
|
// item.port);
|
||||||
url = Utils.Base64Encode(url);
|
//url = Utils.Base64Encode(url);
|
||||||
|
//new
|
||||||
|
var pw = Utils.Base64Encode($"{item.security}:{item.id}");
|
||||||
|
url = $"{pw}@{GetIpv6(item.address)}:{ item.port}";
|
||||||
url = string.Format("{0}{1}{2}", Global.socksProtocol, url, remark);
|
url = string.Format("{0}{1}{2}", Global.socksProtocol, url, remark);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
@ -135,15 +138,14 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
remark = "#" + Utils.UrlEncode(item.remarks);
|
remark = "#" + Utils.UrlEncode(item.remarks);
|
||||||
}
|
}
|
||||||
string query = string.Empty;
|
var dicQuery = new Dictionary<string, string>();
|
||||||
if (!Utils.IsNullOrEmpty(item.sni))
|
GetStdTransport(item, null, ref dicQuery);
|
||||||
{
|
string query = "?" + string.Join("&", dicQuery.Select(x => x.Key + "=" + x.Value).ToArray());
|
||||||
query = string.Format("?sni={0}", Utils.UrlEncode(item.sni));
|
|
||||||
}
|
|
||||||
url = string.Format("{0}@{1}:{2}",
|
url = string.Format("{0}@{1}:{2}",
|
||||||
item.id,
|
item.id,
|
||||||
GetIpv6(item.address),
|
GetIpv6(item.address),
|
||||||
item.port);
|
item.port);
|
||||||
url = string.Format("{0}{1}{2}{3}", Global.trojanProtocol, url, query, remark);
|
url = string.Format("{0}{1}{2}{3}", Global.trojanProtocol, url, query, remark);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
@ -157,10 +159,6 @@ namespace v2rayN.Handler
|
||||||
remark = "#" + Utils.UrlEncode(item.remarks);
|
remark = "#" + Utils.UrlEncode(item.remarks);
|
||||||
}
|
}
|
||||||
var dicQuery = new Dictionary<string, string>();
|
var dicQuery = new Dictionary<string, string>();
|
||||||
if (!Utils.IsNullOrEmpty(item.flow))
|
|
||||||
{
|
|
||||||
dicQuery.Add("flow", item.flow);
|
|
||||||
}
|
|
||||||
if (!Utils.IsNullOrEmpty(item.security))
|
if (!Utils.IsNullOrEmpty(item.security))
|
||||||
{
|
{
|
||||||
dicQuery.Add("encryption", item.security);
|
dicQuery.Add("encryption", item.security);
|
||||||
|
@ -169,13 +167,38 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
dicQuery.Add("encryption", "none");
|
dicQuery.Add("encryption", "none");
|
||||||
}
|
}
|
||||||
|
GetStdTransport(item, "none", ref dicQuery);
|
||||||
|
string query = "?" + string.Join("&", dicQuery.Select(x => x.Key + "=" + x.Value).ToArray());
|
||||||
|
|
||||||
|
url = string.Format("{0}@{1}:{2}",
|
||||||
|
item.id,
|
||||||
|
GetIpv6(item.address),
|
||||||
|
item.port);
|
||||||
|
url = string.Format("{0}{1}{2}{3}", Global.vlessProtocol, url, query, remark);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
private static string GetIpv6(string address)
|
||||||
|
{
|
||||||
|
return Utils.IsIpv6(address) ? $"[{address}]" : address;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int GetStdTransport(VmessItem item, string securityDef, ref Dictionary<string, string> dicQuery)
|
||||||
|
{
|
||||||
|
if (!Utils.IsNullOrEmpty(item.flow))
|
||||||
|
{
|
||||||
|
dicQuery.Add("flow", item.flow);
|
||||||
|
}
|
||||||
|
|
||||||
if (!Utils.IsNullOrEmpty(item.streamSecurity))
|
if (!Utils.IsNullOrEmpty(item.streamSecurity))
|
||||||
{
|
{
|
||||||
dicQuery.Add("security", item.streamSecurity);
|
dicQuery.Add("security", item.streamSecurity);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dicQuery.Add("security", "none");
|
if (securityDef != null)
|
||||||
|
{
|
||||||
|
dicQuery.Add("security", securityDef);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!Utils.IsNullOrEmpty(item.sni))
|
if (!Utils.IsNullOrEmpty(item.sni))
|
||||||
{
|
{
|
||||||
|
@ -272,19 +295,9 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
string query = "?" + string.Join("&", dicQuery.Select(x => x.Key + "=" + x.Value).ToArray());
|
return 0;
|
||||||
|
|
||||||
url = string.Format("{0}@{1}:{2}",
|
|
||||||
item.id,
|
|
||||||
GetIpv6(item.address),
|
|
||||||
item.port);
|
|
||||||
url = string.Format("{0}{1}{2}{3}", Global.vlessProtocol, url, query, remark);
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
private static string GetIpv6(string address)
|
|
||||||
{
|
|
||||||
return Utils.IsIpv6(address) ? $"[{address}]" : address;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ImportShareUrl
|
#region ImportShareUrl
|
||||||
|
@ -349,7 +362,21 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
msg = UIRes.I18N("ConfigurationFormatIncorrect");
|
msg = UIRes.I18N("ConfigurationFormatIncorrect");
|
||||||
|
|
||||||
vmessItem = ResolveSocks(result);
|
vmessItem = ResolveSocksNew(result);
|
||||||
|
if (vmessItem == null)
|
||||||
|
{
|
||||||
|
vmessItem = ResolveSocks(result);
|
||||||
|
}
|
||||||
|
if (vmessItem == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (vmessItem.address.Length == 0 || vmessItem.port == 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
vmessItem.configType = (int)EConfigType.Socks;
|
||||||
}
|
}
|
||||||
else if (result.StartsWith(Global.trojanProtocol))
|
else if (result.StartsWith(Global.trojanProtocol))
|
||||||
{
|
{
|
||||||
|
@ -403,7 +430,6 @@ namespace v2rayN.Handler
|
||||||
vmessItem.address = Utils.ToString(vmessQRCode.add);
|
vmessItem.address = Utils.ToString(vmessQRCode.add);
|
||||||
vmessItem.port = Utils.ToInt(vmessQRCode.port);
|
vmessItem.port = Utils.ToInt(vmessQRCode.port);
|
||||||
vmessItem.id = Utils.ToString(vmessQRCode.id);
|
vmessItem.id = Utils.ToString(vmessQRCode.id);
|
||||||
vmessItem.alterId = Utils.ToInt(vmessQRCode.aid);
|
|
||||||
vmessItem.security = Utils.ToString(vmessQRCode.scy);
|
vmessItem.security = Utils.ToString(vmessQRCode.scy);
|
||||||
|
|
||||||
if (!Utils.IsNullOrEmpty(vmessQRCode.scy))
|
if (!Utils.IsNullOrEmpty(vmessQRCode.scy))
|
||||||
|
@ -429,7 +455,7 @@ namespace v2rayN.Handler
|
||||||
vmessItem.sni = Utils.ToString(vmessQRCode.sni);
|
vmessItem.sni = Utils.ToString(vmessQRCode.sni);
|
||||||
vmessItem.alpn = Utils.String2List(vmessQRCode.alpn);
|
vmessItem.alpn = Utils.String2List(vmessQRCode.alpn);
|
||||||
|
|
||||||
return vmessItem;
|
return vmessItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static VmessItem ResolveVmess4Kitsunebi(string result)
|
private static VmessItem ResolveVmess4Kitsunebi(string result)
|
||||||
|
@ -466,7 +492,6 @@ namespace v2rayN.Handler
|
||||||
vmessItem.network = Global.DefaultNetwork;
|
vmessItem.network = Global.DefaultNetwork;
|
||||||
vmessItem.headerType = Global.None;
|
vmessItem.headerType = Global.None;
|
||||||
vmessItem.remarks = "Alien";
|
vmessItem.remarks = "Alien";
|
||||||
vmessItem.alterId = 0;
|
|
||||||
|
|
||||||
return vmessItem;
|
return vmessItem;
|
||||||
}
|
}
|
||||||
|
@ -490,11 +515,6 @@ namespace v2rayN.Handler
|
||||||
if (!m.Success) return null;
|
if (!m.Success) return null;
|
||||||
|
|
||||||
i.id = m.Groups["id"].Value;
|
i.id = m.Groups["id"].Value;
|
||||||
if (!int.TryParse(m.Groups["alterId"].Value, out int aid))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
i.alterId = aid;
|
|
||||||
|
|
||||||
if (m.Groups["streamSecurity"].Success)
|
if (m.Groups["streamSecurity"].Success)
|
||||||
{
|
{
|
||||||
|
@ -577,17 +597,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
// parse base64 UserInfo
|
// parse base64 UserInfo
|
||||||
string rawUserInfo = parsedUrl.GetComponents(UriComponents.UserInfo, UriFormat.Unescaped);
|
string rawUserInfo = parsedUrl.GetComponents(UriComponents.UserInfo, UriFormat.Unescaped);
|
||||||
string base64 = rawUserInfo.Replace('-', '+').Replace('_', '/'); // Web-safe base64 to normal base64
|
string userInfo = Utils.Base64Decode(rawUserInfo);
|
||||||
string userInfo;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
userInfo = Encoding.UTF8.GetString(Convert.FromBase64String(
|
|
||||||
base64.PadRight(base64.Length + (4 - base64.Length % 4) % 4, '=')));
|
|
||||||
}
|
|
||||||
catch (FormatException)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
string[] userInfoParts = userInfo.Split(new char[] { ':' }, 2);
|
string[] userInfoParts = userInfo.Split(new char[] { ':' }, 2);
|
||||||
if (userInfoParts.Length != 2)
|
if (userInfoParts.Length != 2)
|
||||||
{
|
{
|
||||||
|
@ -624,8 +634,7 @@ namespace v2rayN.Handler
|
||||||
Match details;
|
Match details;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
details = DetailsParser.Match(Encoding.UTF8.GetString(Convert.FromBase64String(
|
details = DetailsParser.Match(Utils.Base64Decode(base64));
|
||||||
base64.PadRight(base64.Length + (4 - base64.Length % 4) % 4, '='))));
|
|
||||||
}
|
}
|
||||||
catch (FormatException)
|
catch (FormatException)
|
||||||
{
|
{
|
||||||
|
@ -642,7 +651,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
|
|
||||||
private static readonly Regex StdVmessUserInfo = new Regex(
|
private static readonly Regex StdVmessUserInfo = new Regex(
|
||||||
@"^(?<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})-(?<alterId>[0-9]+)$");
|
@"^(?<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})$");
|
||||||
|
|
||||||
private static VmessItem ResolveSocks(string result)
|
private static VmessItem ResolveSocks(string result)
|
||||||
{
|
{
|
||||||
|
@ -690,30 +699,55 @@ namespace v2rayN.Handler
|
||||||
return vmessItem;
|
return vmessItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static VmessItem ResolveSocksNew(string result)
|
||||||
|
{
|
||||||
|
Uri parsedUrl;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
parsedUrl = new Uri(result);
|
||||||
|
}
|
||||||
|
catch (UriFormatException)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
VmessItem server = new VmessItem
|
||||||
|
{
|
||||||
|
remarks = Utils.UrlDecode(parsedUrl.GetComponents(UriComponents.Fragment, UriFormat.Unescaped)),
|
||||||
|
address = parsedUrl.IdnHost,
|
||||||
|
port = parsedUrl.Port,
|
||||||
|
};
|
||||||
|
|
||||||
|
// parse base64 UserInfo
|
||||||
|
string rawUserInfo = parsedUrl.GetComponents(UriComponents.UserInfo, UriFormat.Unescaped);
|
||||||
|
string userInfo = Utils.Base64Decode(rawUserInfo);
|
||||||
|
string[] userInfoParts = userInfo.Split(new char[] { ':' }, 2);
|
||||||
|
if (userInfoParts.Length == 2)
|
||||||
|
{
|
||||||
|
server.security = userInfoParts[0];
|
||||||
|
server.id = userInfoParts[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
private static VmessItem ResolveTrojan(string result)
|
private static VmessItem ResolveTrojan(string result)
|
||||||
{
|
{
|
||||||
VmessItem vmessItem = new VmessItem();
|
VmessItem item = new VmessItem
|
||||||
|
|
||||||
vmessItem.configType = (int)EConfigType.Trojan;
|
|
||||||
|
|
||||||
Uri uri = new Uri(result);
|
|
||||||
vmessItem.address = uri.IdnHost;
|
|
||||||
vmessItem.port = uri.Port;
|
|
||||||
vmessItem.id = uri.UserInfo;
|
|
||||||
|
|
||||||
var qurery = HttpUtility.ParseQueryString(uri.Query);
|
|
||||||
vmessItem.sni = qurery["sni"] ?? "";
|
|
||||||
|
|
||||||
var remarks = uri.Fragment.Replace("#", "");
|
|
||||||
if (Utils.IsNullOrEmpty(remarks))
|
|
||||||
{
|
{
|
||||||
vmessItem.remarks = "NONE";
|
configType = (int)EConfigType.Trojan
|
||||||
}
|
};
|
||||||
else
|
|
||||||
{
|
Uri url = new Uri(result);
|
||||||
vmessItem.remarks = Utils.UrlDecode(remarks);
|
|
||||||
}
|
item.address = url.IdnHost;
|
||||||
return vmessItem;
|
item.port = url.Port;
|
||||||
|
item.remarks = Utils.UrlDecode(url.GetComponents(UriComponents.Fragment, UriFormat.Unescaped));
|
||||||
|
item.id = url.UserInfo;
|
||||||
|
|
||||||
|
var query = HttpUtility.ParseQueryString(url.Query);
|
||||||
|
ResolveStdTransport(query, ref item);
|
||||||
|
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
private static VmessItem ResolveStdVLESS(string result)
|
private static VmessItem ResolveStdVLESS(string result)
|
||||||
{
|
{
|
||||||
|
@ -731,10 +765,17 @@ namespace v2rayN.Handler
|
||||||
item.id = url.UserInfo;
|
item.id = url.UserInfo;
|
||||||
|
|
||||||
var query = HttpUtility.ParseQueryString(url.Query);
|
var query = HttpUtility.ParseQueryString(url.Query);
|
||||||
|
|
||||||
item.flow = query["flow"] ?? "";
|
|
||||||
item.security = query["encryption"] ?? "none";
|
item.security = query["encryption"] ?? "none";
|
||||||
item.streamSecurity = query["security"] ?? "";
|
item.streamSecurity = query["security"] ?? "";
|
||||||
|
ResolveStdTransport(query, ref item);
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int ResolveStdTransport(NameValueCollection query, ref VmessItem item)
|
||||||
|
{
|
||||||
|
item.flow = query["flow"] ?? "";
|
||||||
|
item.streamSecurity = query["security"] ?? "";
|
||||||
item.sni = query["sni"] ?? "";
|
item.sni = query["sni"] ?? "";
|
||||||
item.alpn = Utils.String2List(Utils.UrlDecode(query["alpn"] ?? ""));
|
item.alpn = Utils.String2List(Utils.UrlDecode(query["alpn"] ?? ""));
|
||||||
item.network = query["type"] ?? "tcp";
|
item.network = query["type"] ?? "tcp";
|
||||||
|
@ -772,10 +813,9 @@ namespace v2rayN.Handler
|
||||||
item.headerType = Utils.UrlDecode(query["mode"] ?? Global.GrpcgunMode);
|
item.headerType = Utils.UrlDecode(query["mode"] ?? Global.GrpcgunMode);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return null;
|
break;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
return item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Reference in New Issue