replace polipo with privoxy
This commit is contained in:
@@ -8,6 +8,7 @@ using System.IO.Compression;
|
||||
using System.Text;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Shadowsocks.Controller
|
||||
{
|
||||
@@ -22,7 +23,8 @@ namespace Shadowsocks.Controller
|
||||
temppath = Path.GetTempPath();
|
||||
try
|
||||
{
|
||||
FileManager.UncompressFile(temppath + "/ss_polipo.exe", Resources.polipo_exe);
|
||||
FileManager.UncompressFile(temppath + "/ss_privoxy.exe", Resources.privoxy_exe);
|
||||
FileManager.UncompressFile(temppath + "/mgwz.dll", Resources.mgwz_dll);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
@@ -43,7 +45,7 @@ namespace Shadowsocks.Controller
|
||||
Server server = configuration.GetCurrentServer();
|
||||
if (_process == null)
|
||||
{
|
||||
Process[] existingPolipo = Process.GetProcessesByName("ss_polipo");
|
||||
Process[] existingPolipo = Process.GetProcessesByName("ss_privoxy");
|
||||
foreach (Process p in existingPolipo)
|
||||
{
|
||||
try
|
||||
@@ -56,17 +58,17 @@ namespace Shadowsocks.Controller
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
string polipoConfig = Resources.polipo_config;
|
||||
string polipoConfig = Resources.privoxy_conf;
|
||||
_runningPort = this.GetFreePort();
|
||||
polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", configuration.localPort.ToString());
|
||||
polipoConfig = polipoConfig.Replace("__POLIPO_BIND_PORT__", _runningPort.ToString());
|
||||
polipoConfig = polipoConfig.Replace("__POLIPO_BIND_IP__", configuration.shareOverLan ? "0.0.0.0" : "127.0.0.1");
|
||||
FileManager.ByteArrayToFile(temppath + "/polipo.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig));
|
||||
FileManager.ByteArrayToFile(temppath + "/privoxy.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig));
|
||||
|
||||
_process = new Process();
|
||||
// Configure the process using the StartInfo properties.
|
||||
_process.StartInfo.FileName = temppath + "/ss_polipo.exe";
|
||||
_process.StartInfo.Arguments = "-c \"" + temppath + "/polipo.conf\"";
|
||||
_process.StartInfo.FileName = temppath + "/ss_privoxy.exe";
|
||||
_process.StartInfo.Arguments = " \"" + temppath + "/privoxy.conf\"";
|
||||
_process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
_process.StartInfo.UseShellExecute = true;
|
||||
_process.StartInfo.CreateNoWindow = true;
|
||||
@@ -74,6 +76,7 @@ namespace Shadowsocks.Controller
|
||||
//_process.StartInfo.RedirectStandardError = true;
|
||||
_process.Start();
|
||||
}
|
||||
RefreshTrayArea();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
@@ -91,6 +94,7 @@ namespace Shadowsocks.Controller
|
||||
}
|
||||
_process = null;
|
||||
}
|
||||
RefreshTrayArea();
|
||||
}
|
||||
|
||||
private int GetFreePort()
|
||||
@@ -122,5 +126,50 @@ namespace Shadowsocks.Controller
|
||||
}
|
||||
throw new Exception("No free port found.");
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct RECT
|
||||
{
|
||||
public int left;
|
||||
public int top;
|
||||
public int right;
|
||||
public int bottom;
|
||||
}
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
|
||||
|
||||
|
||||
public void RefreshTrayArea()
|
||||
{
|
||||
IntPtr systemTrayContainerHandle = FindWindow("Shell_TrayWnd", null);
|
||||
IntPtr systemTrayHandle = FindWindowEx(systemTrayContainerHandle, IntPtr.Zero, "TrayNotifyWnd", null);
|
||||
IntPtr sysPagerHandle = FindWindowEx(systemTrayHandle, IntPtr.Zero, "SysPager", null);
|
||||
IntPtr notificationAreaHandle = FindWindowEx(sysPagerHandle, IntPtr.Zero, "ToolbarWindow32", "Notification Area");
|
||||
if (notificationAreaHandle == IntPtr.Zero)
|
||||
{
|
||||
notificationAreaHandle = FindWindowEx(sysPagerHandle, IntPtr.Zero, "ToolbarWindow32", "User Promoted Notification Area");
|
||||
IntPtr notifyIconOverflowWindowHandle = FindWindow("NotifyIconOverflowWindow", null);
|
||||
IntPtr overflowNotificationAreaHandle = FindWindowEx(notifyIconOverflowWindowHandle, IntPtr.Zero, "ToolbarWindow32", "Overflow Notification Area");
|
||||
RefreshTrayArea(overflowNotificationAreaHandle);
|
||||
}
|
||||
RefreshTrayArea(notificationAreaHandle);
|
||||
}
|
||||
|
||||
|
||||
private static void RefreshTrayArea(IntPtr windowHandle)
|
||||
{
|
||||
const uint wmMousemove = 0x0200;
|
||||
RECT rect;
|
||||
GetClientRect(windowHandle, out rect);
|
||||
for (var x = 0; x < rect.right; x += 5)
|
||||
for (var y = 0; y < rect.bottom; y += 5)
|
||||
SendMessage(windowHandle, wmMousemove, 0, (y << 16) + x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
listen-address __POLIPO_BIND_IP__:8123
|
||||
show-on-task-bar 0
|
||||
activity-animation 0
|
||||
forward-socks5 / 127.0.0.1:__SOCKS_PORT__ .
|
||||
hide-console
|
||||
+30
@@ -112,6 +112,16 @@ namespace Shadowsocks.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
internal static byte[] mgwz_dll {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("mgwz_dll", resourceCulture);
|
||||
return ((byte[])(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to proxyAddress = "__POLIPO_BIND_IP__"
|
||||
///proxyPort = 8123
|
||||
@@ -140,6 +150,26 @@ namespace Shadowsocks.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to listen-address __POLIPO_BIND_IP__:8123
|
||||
///.
|
||||
/// </summary>
|
||||
internal static string privoxy_conf {
|
||||
get {
|
||||
return ResourceManager.GetString("privoxy_conf", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
internal static byte[] privoxy_exe {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("privoxy_exe", resourceCulture);
|
||||
return ((byte[])(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
|
||||
@@ -112,12 +112,12 @@
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="abp_js" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Data\abp.js.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
@@ -127,12 +127,21 @@
|
||||
<data name="libsscrypto_dll" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\data\libsscrypto.dll.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="mgwz_dll" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\data\mgwz.dll.gz;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="polipo_config" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Data\polipo_config.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312</value>
|
||||
</data>
|
||||
<data name="polipo_exe" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Data\polipo.exe.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="privoxy_conf" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\data\privoxy_conf.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
|
||||
</data>
|
||||
<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.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
|
||||
@@ -205,7 +205,9 @@
|
||||
</None>
|
||||
<None Include="Data\abp.js.gz" />
|
||||
<None Include="Data\libsscrypto.dll.gz" />
|
||||
<None Include="Data\mgwz.dll.gz" />
|
||||
<None Include="Data\polipo.exe.gz" />
|
||||
<None Include="Data\privoxy.exe.gz" />
|
||||
<None Include="Data\proxy.pac.txt.gz" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -214,6 +216,7 @@
|
||||
<None Include="Resources\ss24.png" />
|
||||
<None Include="Resources\ssw128.png" />
|
||||
<Content Include="Data\cn.txt" />
|
||||
<Content Include="Data\privoxy_conf.txt" />
|
||||
<Content Include="Data\user-rule.txt" />
|
||||
<Content Include="shadowsocks.ico" />
|
||||
<None Include="Data\polipo_config.txt" />
|
||||
|
||||
Reference in New Issue
Block a user