Signed-off-by: Syrone Wong <wong.syrone@gmail.com>tags/3.3.6
@@ -5,6 +5,7 @@ using System.Net; | |||||
using System.Net.Sockets; | using System.Net.Sockets; | ||||
using System.Text; | using System.Text; | ||||
using System.Threading; | using System.Threading; | ||||
using System.Web; | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using Shadowsocks.Controller.Strategy; | using Shadowsocks.Controller.Strategy; | ||||
@@ -299,11 +300,15 @@ namespace Shadowsocks.Controller | |||||
public static string GetQRCode(Server server) | public static string GetQRCode(Server server) | ||||
{ | { | ||||
string parts = server.method; | |||||
if (server.auth) parts += "-auth"; | |||||
parts += ":" + server.password + "@" + server.server + ":" + server.server_port; | |||||
string tag = string.Empty; | |||||
string auth = server.auth ? "-auth" : string.Empty; | |||||
string parts = $"{server.method}{auth}:{server.password}@{server.server}:{server.server_port}"; | |||||
string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(parts)); | string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(parts)); | ||||
return "ss://" + base64; | |||||
if(!server.remarks.IsNullOrEmpty()) | |||||
{ | |||||
tag = $"#{HttpUtility.UrlEncode(server.remarks, Encoding.UTF8)}"; | |||||
} | |||||
return $"ss://{base64}{tag}"; | |||||
} | } | ||||
public void UpdatePACFromGFWList() | public void UpdatePACFromGFWList() | ||||
@@ -1,7 +1,7 @@ | |||||
using System; | using System; | ||||
using System.Text; | using System.Text; | ||||
using System.Text.RegularExpressions; | using System.Text.RegularExpressions; | ||||
using System.Web; | |||||
using Shadowsocks.Controller; | using Shadowsocks.Controller; | ||||
namespace Shadowsocks.Model | namespace Shadowsocks.Model | ||||
@@ -10,7 +10,7 @@ namespace Shadowsocks.Model | |||||
public class Server | public class Server | ||||
{ | { | ||||
public static readonly Regex | public static readonly Regex | ||||
UrlFinder = new Regex("^(?i)ss://([A-Za-z0-9+-/=_]+)(#.+)?$", | |||||
UrlFinder = new Regex("^(?i)ss://([A-Za-z0-9+-/=_]+)(#(.+))?$", | |||||
RegexOptions.IgnoreCase | RegexOptions.Compiled), | RegexOptions.IgnoreCase | RegexOptions.Compiled), | ||||
DetailsParser = new Regex("^((?<method>.+?)(?<auth>-auth)??:(?<password>.*)@(?<hostname>.+?)" + | DetailsParser = new Regex("^((?<method>.+?)(?<auth>-auth)??:(?<password>.*)@(?<hostname>.+?)" + | ||||
":(?<port>\\d+?))$", RegexOptions.Compiled | RegexOptions.IgnoreCase); | ":(?<port>\\d+?))$", RegexOptions.Compiled | RegexOptions.IgnoreCase); | ||||
@@ -79,9 +79,9 @@ namespace Shadowsocks.Model | |||||
var match = UrlFinder.Match(ssURL); | var match = UrlFinder.Match(ssURL); | ||||
if (!match.Success) throw new FormatException(); | if (!match.Success) throw new FormatException(); | ||||
var base64 = match.Groups[1].Value; | var base64 = match.Groups[1].Value; | ||||
var tag = match.Groups[2].Value; | |||||
var tag = match.Groups[3].Value; | |||||
if (!tag.IsNullOrEmpty()) | if (!tag.IsNullOrEmpty()) | ||||
remarks = tag.Substring(1).Trim(); | |||||
remarks = HttpUtility.UrlDecode(tag, Encoding.UTF8); | |||||
match = DetailsParser.Match(Encoding.UTF8.GetString(Convert.FromBase64String( | match = DetailsParser.Match(Encoding.UTF8.GetString(Convert.FromBase64String( | ||||
base64.PadRight(base64.Length + (4 - base64.Length % 4) % 4, '=')))); | base64.PadRight(base64.Length + (4 - base64.Length % 4) % 4, '=')))); | ||||
method = match.Groups["method"].Value; | method = match.Groups["method"].Value; | ||||
@@ -81,6 +81,7 @@ | |||||
<Reference Include="System.Drawing" /> | <Reference Include="System.Drawing" /> | ||||
<Reference Include="System.Management" /> | <Reference Include="System.Management" /> | ||||
<Reference Include="System.Net" /> | <Reference Include="System.Net" /> | ||||
<Reference Include="System.Web" /> | |||||
<Reference Include="System.Windows.Forms" /> | <Reference Include="System.Windows.Forms" /> | ||||
<Reference Include="System.Windows.Forms.DataVisualization" /> | <Reference Include="System.Windows.Forms.DataVisualization" /> | ||||
<Reference Include="System.XML" /> | <Reference Include="System.XML" /> | ||||