Browse Source

switch legacy url generation by hidden flag in config

tags/4.2.0.0
Student Main 4 years ago
parent
commit
f3c4dfb106
No known key found for this signature in database GPG Key ID: 53D9E1FEC1BE3A1B
5 changed files with 44 additions and 35 deletions
  1. +1
    -1
      shadowsocks-csharp/Controller/ShadowsocksController.cs
  2. +6
    -0
      shadowsocks-csharp/Model/Configuration.cs
  3. +32
    -29
      shadowsocks-csharp/Model/Server.cs
  4. +4
    -4
      shadowsocks-csharp/View/QRCodeForm.cs
  5. +1
    -1
      test/UrlTest.cs

+ 1
- 1
shadowsocks-csharp/Controller/ShadowsocksController.cs View File

@@ -371,7 +371,7 @@ namespace Shadowsocks.Controller
public string GetServerURLForCurrentServer()
{
return GetCurrentServer().URL;
return GetCurrentServer().GetURL(_config.generateLegacyUrl);
}
public void UpdatePACFromGeosite()


+ 6
- 0
shadowsocks-csharp/Model/Configuration.cs View File

@@ -24,11 +24,13 @@ namespace Shadowsocks.Model
public bool enabled;
public bool shareOverLan;
public bool isDefault;
// hidden
public bool isIPv6Enabled = false;
public int localPort;
public bool portableMode = true;
public bool showPluginOutput;
public string pacUrl;
// geosite config is hidden
public string geositeUrl;
public string geositeGroup = "geolocation-!cn";
public bool geositeBlacklistMode = true;
@@ -39,6 +41,10 @@ namespace Shadowsocks.Model
public bool autoCheckUpdate;
public bool checkPreRelease;
public bool isVerboseLogging;
// hidden config
public bool generateLegacyUrl = false;
//public NLogConfig.LogLevel logLevel;
public LogViewerConfig logViewer;
public ProxyConfig proxy;


+ 32
- 29
shadowsocks-csharp/Model/Server.cs View File

@@ -56,47 +56,50 @@ namespace Shadowsocks.Model
: $"{remarks} ({serverStr})";
}
public string URL
public string GetURL(bool legacyUrl = false)
{
get
{
string tag = string.Empty;
string url = string.Empty;
string tag = string.Empty;
string url = string.Empty;
if (string.IsNullOrWhiteSpace(plugin))
{
// For backwards compatiblity, if no plugin, use old url format
string parts = $"{method}:{password}@{server}:{server_port}";
string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(parts));
url = base64;
}
else
if (legacyUrl && string.IsNullOrWhiteSpace(plugin))
{
// For backwards compatiblity, if no plugin, use old url format
string parts = $"{method}:{password}@{server}:{server_port}";
string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(parts));
url = base64;
}
else
{
// SIP002
string parts = $"{method}:{password}";
string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(parts));
string websafeBase64 = base64.Replace('+', '-').Replace('/', '_').TrimEnd('=');
url = string.Format(
"{0}@{1}:{2}/",
websafeBase64,
FormalHostName,
server_port
);
if (!plugin.IsNullOrWhiteSpace())
{
// SIP002
string parts = $"{method}:{password}";
string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(parts));
string websafeBase64 = base64.Replace('+', '-').Replace('/', '_').TrimEnd('=');
string pluginPart = plugin;
if (!string.IsNullOrWhiteSpace(plugin_opts))
{
pluginPart += ";" + plugin_opts;
}
url = string.Format(
"{0}@{1}:{2}/?plugin={3}",
websafeBase64,
FormalHostName,
server_port,
HttpUtility.UrlEncode(pluginPart, Encoding.UTF8));
string pluginQuery = "?plugin=" + HttpUtility.UrlEncode(pluginPart, Encoding.UTF8);
url += pluginQuery;
}
}
if (!remarks.IsNullOrEmpty())
{
tag = $"#{HttpUtility.UrlEncode(remarks, Encoding.UTF8)}";
}
return $"ss://{url}{tag}";
if (!remarks.IsNullOrEmpty())
{
tag = $"#{HttpUtility.UrlEncode(remarks, Encoding.UTF8)}";
}
return $"ss://{url}{tag}";
}
public string FormalHostName


+ 4
- 4
shadowsocks-csharp/View/QRCodeForm.cs View File

@@ -64,14 +64,14 @@ namespace Shadowsocks.View
private void QRCodeForm_Load(object sender, EventArgs e)
{
var servers = Configuration.Load();
var serverDatas = servers.configs.Select(
Configuration config = Configuration.Load();
List<KeyValuePair<string, string>> serverDatas = config.configs.Select(
server =>
new KeyValuePair<string, string>(server.URL, server.ToString())
new KeyValuePair<string, string>(server.GetURL(config.generateLegacyUrl), server.ToString())
).ToList();
listBox1.DataSource = serverDatas;
var selectIndex = serverDatas.FindIndex(serverData => serverData.Key.StartsWith(code));
int selectIndex = serverDatas.FindIndex(serverData => serverData.Key.StartsWith(code));
if (selectIndex >= 0) listBox1.SetSelected(selectIndex, true);
}


+ 1
- 1
test/UrlTest.cs View File

@@ -243,7 +243,7 @@ namespace Shadowsocks.Test
string expected = testCase.Key;
Server config = testCase.Value;
var actual = config.URL;
var actual = config.GetURL(true);
Assert.AreEqual(expected, actual);
}
}


Loading…
Cancel
Save