Browse Source

Merge pull request #2598 from studentmain/pac-structure

Init JS variable in more reliable and quick way, reduce redundant code
tags/4.1.9.0
Allen Zhu GitHub 4 years ago
parent
commit
ad36bf6d4d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 7338 additions and 8128 deletions
  1. +5
    -4
      shadowsocks-csharp/Controller/Service/GfwListUpdater.cs
  2. +2
    -2
      shadowsocks-csharp/Controller/Service/PACDaemon.cs
  3. +7
    -7
      shadowsocks-csharp/Controller/Service/PACServer.cs
  4. +4
    -3
      shadowsocks-csharp/Data/abp.js
  5. +7250
    -0
      shadowsocks-csharp/Data/default-abp-rule.js
  6. +0
    -8040
      shadowsocks-csharp/Data/proxy.pac.txt
  7. +66
    -68
      shadowsocks-csharp/Properties/Resources.Designer.cs
  8. +3
    -3
      shadowsocks-csharp/Properties/Resources.resx
  9. +1
    -1
      shadowsocks-csharp/shadowsocks-csharp.csproj

+ 5
- 4
shadowsocks-csharp/Controller/Service/GfwListUpdater.cs View File

@@ -81,9 +81,10 @@ namespace Shadowsocks.Controller
List<string> gfwLines = new List<string>();
gfwLines = ParseBase64ToValidList(gfwListResult);
abpContent = abpContent.Replace("__USERRULES__", JsonConvert.SerializeObject(userruleLines, Formatting.Indented))
.Replace("__RULES__", JsonConvert.SerializeObject(gfwLines, Formatting.Indented));
abpContent =
$@"var __USERRULES__ = {JsonConvert.SerializeObject(userruleLines, Formatting.Indented)};
var __RULES__ = {JsonConvert.SerializeObject(gfwLines, Formatting.Indented)};
{abpContent}";
return abpContent;
}
@@ -94,7 +95,7 @@ namespace Shadowsocks.Controller
if (config.enabled)
{
http.Proxy = new WebProxy(
config.isIPv6Enabled ? IPAddress.IPv6Loopback.ToString() : IPAddress.Loopback.ToString(),
config.isIPv6Enabled ? IPAddress.IPv6Loopback.ToString() : IPAddress.Loopback.ToString(),
config.localPort);
}
http.DownloadStringCompleted += http_DownloadStringCompleted;


+ 2
- 2
shadowsocks-csharp/Controller/Service/PACDaemon.cs View File

@@ -39,7 +39,7 @@ namespace Shadowsocks.Controller
{
if (!File.Exists(PAC_FILE))
{
File.WriteAllText(PAC_FILE, Resources.proxy_pac_txt);
File.WriteAllText(PAC_FILE, Resources.default_abp_rule + Resources.abp_js);
}
return PAC_FILE;
}
@@ -61,7 +61,7 @@ namespace Shadowsocks.Controller
}
else
{
return Resources.proxy_pac_txt;
return Resources.default_abp_rule + Resources.abp_js;
}
}


+ 7
- 7
shadowsocks-csharp/Controller/Service/PACServer.cs View File

@@ -70,7 +70,7 @@ namespace Shadowsocks.Controller
Host: www.example.com
Accept-Language: en, mi
*/
string request = Encoding.UTF8.GetString(firstPacket, 0, length);
string[] lines = request.Split('\r', '\n');
bool hostMatch = false, pathMatch = false, useSocks = false;
@@ -164,15 +164,15 @@ namespace Shadowsocks.Controller
string proxy = GetPACAddress(localEndPoint, useSocks);
string pacContent = _pacDaemon.GetPACContent().Replace("__PROXY__", proxy);
string responseHead = String.Format(@"HTTP/1.1 200 OK
Server: Shadowsocks
string pacContent = $"var __PROXY__ = '{proxy}';\n" + _pacDaemon.GetPACContent();
string responseHead =
$@"HTTP/1.1 200 OK
Server: ShadowsocksWindows/{UpdateChecker.Version}
Content-Type: application/x-ns-proxy-autoconfig
Content-Length: {0}
Content-Length: { Encoding.UTF8.GetBytes(pacContent).Length}
Connection: Close
", Encoding.UTF8.GetBytes(pacContent).Length);
";
byte[] response = Encoding.UTF8.GetBytes(responseHead + pacContent);
socket.BeginSend(response, 0, response.Length, 0, new AsyncCallback(SendCallback), socket);
Utils.ReleaseMemory(true);


+ 4
- 3
shadowsocks-csharp/Data/abp.js View File

@@ -1,10 +1,11 @@
// Generated by gfwlist2pac in precise mode
/* eslint-disable */
// Was generated by gfwlist2pac in precise mode
// https://github.com/clowwindy/gfwlist2pac
// 2019-10-06: More 'javascript' way to interaction with main program
// 2019-02-08: Updated to support shadowsocks-windows user rules.
var proxy = "__PROXY__";
var proxy = __PROXY__;
var userrules = __USERRULES__;
var rules = __RULES__;


+ 7250
- 0
shadowsocks-csharp/Data/default-abp-rule.js
File diff suppressed because it is too large
View File


+ 0
- 8040
shadowsocks-csharp/Data/proxy.pac.txt
File diff suppressed because it is too large
View File


+ 66
- 68
shadowsocks-csharp/Properties/Resources.Designer.cs View File

@@ -1,10 +1,10 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
@@ -13,12 +13,12 @@ namespace Shadowsocks.Properties {
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
@@ -33,7 +33,7 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// 返回此类使用的缓存的 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
@@ -47,8 +47,8 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// 重写当前线程的 CurrentUICulture 属性
/// 重写当前线程的 CurrentUICulture 属性。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
@@ -61,13 +61,14 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Looks up a localized string similar to // Generated by gfwlist2pac in precise mode
/// 查找类似 /* eslint-disable */
///// Was generated by gfwlist2pac in precise mode
///// https://github.com/clowwindy/gfwlist2pac
///
///// 2019-10-06: More &apos;javascript&apos; way to interaction with main program
///// 2019-02-08: Updated to support shadowsocks-windows user rules.
///
///var proxy = &quot;__PROXY__&quot;;
///
///var proxy = __PROXY__;
///var userrules = __USERRULES__;
///var rules = __RULES__;
///
@@ -75,9 +76,7 @@ namespace Shadowsocks.Properties {
///* This file is part of Adblock Plus &lt;http://adblockplus.org/&gt;,
///* Copyright (C) 2006-2014 Eyeo GmbH
///*
///* Adblock Plus is free software: you can redistribute it and/or modify
///* it under the terms of the GNU General Public License version 3 as
///* published by t [rest of string was truncated]&quot;;.
///* Adblock Plus is free software: you can redistribute it and/or [字符串的其余部分被截断]&quot;; 的本地化字符串。
/// </summary>
internal static string abp_js {
get {
@@ -86,7 +85,37 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Looks up a localized string similar to # translation for Japanese
/// 查找类似 var __USERRULES__ = [];
///var __RULES__ = [
/// &quot;|http://85.17.73.31/&quot;,
/// &quot;||agnesb.fr&quot;,
/// &quot;||akiba-web.com&quot;,
/// &quot;||altrec.com&quot;,
/// &quot;||angela-merkel.de&quot;,
/// &quot;||angola.org&quot;,
/// &quot;||apartmentratings.com&quot;,
/// &quot;||apartments.com&quot;,
/// &quot;||arena.taipei&quot;,
/// &quot;||asianspiss.com&quot;,
/// &quot;||assimp.org&quot;,
/// &quot;||athenaeizou.com&quot;,
/// &quot;||azubu.tv&quot;,
/// &quot;||bankmobilevibe.com&quot;,
/// &quot;||banorte.com&quot;,
/// &quot;||bash-hackers.org&quot;,
/// &quot;||beeg.com&quot;,
/// &quot;||global.bing.com&quot;,
/// &quot;||bloombergview.com&quot;,
/// &quot; [字符串的其余部分被截断]&quot;; 的本地化字符串。
/// </summary>
internal static string default_abp_rule {
get {
return ResourceManager.GetString("default_abp_rule", resourceCulture);
}
}
/// <summary>
/// 查找类似 # translation for Japanese
///
///Shadowsocks=Shadowsocks
///
@@ -107,7 +136,7 @@ namespace Shadowsocks.Properties {
///Edit Local PAC File...=ローカル PAC ファイルの編集...
///Update Local PAC from GFWList=GFWList からローカル PAC を更新
///Edit User Rule for GFWList...=ユーザールールの編集...
///Secure Local PA [rest of string was truncated]&quot;;.
///Secure Local PA [字符串的其余部分被截断]&quot;; 的本地化字符串。
/// </summary>
internal static string ja {
get {
@@ -116,7 +145,7 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] libsscrypto_dll {
get {
@@ -126,7 +155,7 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Looks up a localized string similar to listen-address __PRIVOXY_BIND_IP__:__PRIVOXY_BIND_PORT__
/// 查找类似 listen-address __PRIVOXY_BIND_IP__:__PRIVOXY_BIND_PORT__
///toggle 0
///logfile ss_privoxy.log
///show-on-task-bar 0
@@ -134,7 +163,7 @@ namespace Shadowsocks.Properties {
///forward-socks5 / __SOCKS_HOST__:__SOCKS_PORT__ .
///max-client-connections 2048
///hide-console
///.
/// 的本地化字符串。
/// </summary>
internal static string privoxy_conf {
get {
@@ -143,7 +172,7 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] privoxy_exe {
get {
@@ -153,38 +182,7 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Looks up a localized string similar to // Generated by gfwlist2pac in precise mode
///// https://github.com/clowwindy/gfwlist2pac
///
///// 2019-02-08: Updated to support shadowsocks-windows user rules.
///
///var proxy = &quot;__PROXY__&quot;;
///
///var userrules = [];
///var rules = [
/// &quot;|http://85.17.73.31/&quot;,
/// &quot;||agnesb.fr&quot;,
/// &quot;||akiba-web.com&quot;,
/// &quot;||altrec.com&quot;,
/// &quot;||angela-merkel.de&quot;,
/// &quot;||angola.org&quot;,
/// &quot;||apartmentratings.com&quot;,
/// &quot;||apartments.com&quot;,
/// &quot;||arena.taipei&quot;,
/// &quot;||asianspiss.com&quot;,
/// &quot;||assimp.org&quot;,
/// &quot;||athenaeizou.com&quot;,
/// &quot;||azubu.tv&quot;,
/// [rest of string was truncated]&quot;;.
/// </summary>
internal static string proxy_pac_txt {
get {
return ResourceManager.GetString("proxy_pac_txt", resourceCulture);
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap ss32Fill {
get {
@@ -194,7 +192,7 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap ss32In {
get {
@@ -204,7 +202,7 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap ss32Out {
get {
@@ -214,7 +212,7 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap ss32Outline {
get {
@@ -224,7 +222,7 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap ssw128 {
get {
@@ -234,7 +232,7 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] sysproxy_exe {
get {
@@ -244,7 +242,7 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] sysproxy64_exe {
get {
@@ -254,9 +252,9 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Looks up a localized string similar to ! Put user rules line by line in this file.
/// 查找类似 ! Put user rules line by line in this file.
///! See https://adblockplus.org/en/filter-cheatsheet
///.
/// 的本地化字符串。
/// </summary>
internal static string user_rule {
get {
@@ -265,7 +263,7 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Looks up a localized string similar to # translation for Simplified Chinese
/// 查找类似 # translation for Simplified Chinese
///
///Shadowsocks=Shadowsocks
///
@@ -287,7 +285,7 @@ namespace Shadowsocks.Properties {
///Update Local PAC from GFWList=从 GFWList 更新本地 PAC
///Edit User Rule for GFWList...=编辑 GFWList 的用户规则...
///Secure Local PAC=保护本地 PAC
///Copy Lo [rest of string was truncated]&quot;;.
///Copy Lo [字符串的其余部分被截断]&quot;; 的本地化字符串。
/// </summary>
internal static string zh_CN {
get {
@@ -296,7 +294,7 @@ namespace Shadowsocks.Properties {
}
/// <summary>
/// Looks up a localized string similar to # translation for Traditional Chinese
/// 查找类似 # translation for Traditional Chinese
///
///Shadowsocks=Shadowsocks
///
@@ -317,7 +315,7 @@ namespace Shadowsocks.Properties {
///Edit Local PAC File...=編輯本機 PAC 檔案...
///Update Local PAC from GFWList=從 GFWList 更新本機 PAC
///Edit User Rule for GFWList...=編輯 GFWList 的使用者規則...
///Secure Local PAC=安全本機 PAC /// [rest of string was truncated]&quot;;.
///Secure Local PAC=安全本機 PAC /// [字符串的其余部分被截断]&quot;; 的本地化字符串。
/// </summary>
internal static string zh_TW {
get {


+ 3
- 3
shadowsocks-csharp/Properties/Resources.resx View File

@@ -121,6 +121,9 @@
<data name="abp_js" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Data\abp.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312</value>
</data>
<data name="default_abp_rule" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Data\default-abp-rule.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="ja" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Data\ja.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
@@ -133,9 +136,6 @@
<data name="privoxy_exe" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\data\privoxy.exe.gz;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="proxy_pac_txt" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Data\proxy.pac.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="ss32Fill" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ss32Fill.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>


+ 1
- 1
shadowsocks-csharp/shadowsocks-csharp.csproj View File

@@ -269,7 +269,7 @@
</None>
<None Include="Resources\ssw128.png" />
<Content Include="Data\abp.js" />
<Content Include="Data\proxy.pac.txt" />
<Content Include="Data\default-abp-rule.js" />
<Content Include="Data\zh_CN.txt" />
<Content Include="Data\zh_TW.txt" />
<Content Include="Data\ja.txt" />


Loading…
Cancel
Save