Browse Source

Direct set the system PAC to the online PAC URL

tags/2.4
Gang Zhuo 10 years ago
parent
commit
b762c8046a
2 changed files with 7 additions and 29 deletions
  1. +1
    -28
      shadowsocks-csharp/Controller/PACServer.cs
  2. +6
    -1
      shadowsocks-csharp/Controller/SystemProxy.cs

+ 1
- 28
shadowsocks-csharp/Controller/PACServer.cs View File

@@ -71,10 +71,7 @@ namespace Shadowsocks.Controller
} }
if (hostMatch && pathMatch) if (hostMatch && pathMatch)
{ {
if (_config.useOnlinePac && !string.IsNullOrEmpty(_config.pacUrl))
RedirectToOnlinePAC(firstPacket, length, socket, useSocks);
else
SendResponse(firstPacket, length, socket, useSocks);
SendResponse(firstPacket, length, socket, useSocks);
return true; return true;
} }
return false; return false;
@@ -124,30 +121,6 @@ namespace Shadowsocks.Controller
} }
} }
private void RedirectToOnlinePAC(byte[] firstPacket, int length, Socket socket, bool useSocks)
{
try
{
string friendlyMessage = "Redirect to online pac " + _config.pacUrl;
string text = String.Format(@"HTTP/1.1 302 Found
Server: Shadowsocks
Content-Type: text/html; charset=utf-8
Location: {0}
Content-Length: {1}
Connection: Close
", _config.pacUrl, System.Text.Encoding.UTF8.GetBytes(friendlyMessage).Length) + friendlyMessage;
byte[] response = System.Text.Encoding.UTF8.GetBytes(text);
socket.BeginSend(response, 0, response.Length, 0, new AsyncCallback(SendCallback), socket);
Util.Utils.ReleaseMemory();
}
catch (Exception e)
{
Console.WriteLine(e);
socket.Close();
}
}
public void SendResponse(byte[] firstPacket, int length, Socket socket, bool useSocks) public void SendResponse(byte[] firstPacket, int length, Socket socket, bool useSocks)
{ {
try try


+ 6
- 1
shadowsocks-csharp/Controller/SystemProxy.cs View File

@@ -49,9 +49,14 @@ namespace Shadowsocks.Controller
} }
else else
{ {
string pacUrl;
if (config.useOnlinePac && !string.IsNullOrEmpty(config.pacUrl))
pacUrl = config.pacUrl;
else
pacUrl = "http://127.0.0.1:" + config.localPort.ToString() + "/pac?t=" + GetTimestamp(DateTime.Now);
registry.SetValue("ProxyEnable", 0); registry.SetValue("ProxyEnable", 0);
registry.SetValue("ProxyServer", ""); registry.SetValue("ProxyServer", "");
registry.SetValue("AutoConfigURL", "http://127.0.0.1:" + config.localPort.ToString() + "/pac?t=" + GetTimestamp(DateTime.Now));
registry.SetValue("AutoConfigURL", pacUrl);
} }
} }
else else


Loading…
Cancel
Save