pac proxy toggle
This commit is contained in:
@@ -10,6 +10,7 @@ namespace shadowsocks_csharp
|
||||
[Serializable]
|
||||
public class Config
|
||||
{
|
||||
public bool enabled;
|
||||
public string server;
|
||||
public int server_port;
|
||||
public int local_port;
|
||||
@@ -51,6 +52,7 @@ namespace shadowsocks_csharp
|
||||
local_port = 1080,
|
||||
password = "barfoo!",
|
||||
method = "table",
|
||||
enabled = true,
|
||||
isDefault = true
|
||||
};
|
||||
}
|
||||
@@ -68,7 +70,8 @@ namespace shadowsocks_csharp
|
||||
server_port = config.server_port,
|
||||
local_port = config.local_port,
|
||||
password = config.password,
|
||||
method = config.method
|
||||
method = config.method,
|
||||
enabled = config.enabled
|
||||
});
|
||||
sw.Write(jsonString);
|
||||
sw.Flush();
|
||||
|
||||
Generated
+48
-60
@@ -42,18 +42,17 @@
|
||||
this.textBox3 = new System.Windows.Forms.TextBox();
|
||||
this.textBox4 = new System.Windows.Forms.TextBox();
|
||||
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
|
||||
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.ConfigItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.QuitItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.panel2 = new System.Windows.Forms.Panel();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.EnableItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
|
||||
this.enableItem = new System.Windows.Forms.MenuItem();
|
||||
this.aboutItem = new System.Windows.Forms.MenuItem();
|
||||
this.menuItem3 = new System.Windows.Forms.MenuItem();
|
||||
this.quitItem = new System.Windows.Forms.MenuItem();
|
||||
this.configItem = new System.Windows.Forms.MenuItem();
|
||||
this.tableLayoutPanel1.SuspendLayout();
|
||||
this.contextMenuStrip1.SuspendLayout();
|
||||
this.panel1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@@ -192,50 +191,11 @@
|
||||
//
|
||||
// notifyIcon1
|
||||
//
|
||||
this.notifyIcon1.ContextMenuStrip = this.contextMenuStrip1;
|
||||
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
|
||||
this.notifyIcon1.Text = "shadowsocks";
|
||||
this.notifyIcon1.Visible = true;
|
||||
this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
|
||||
//
|
||||
// contextMenuStrip1
|
||||
//
|
||||
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.EnableItem,
|
||||
this.ConfigItem,
|
||||
this.aboutToolStripMenuItem,
|
||||
this.toolStripSeparator2,
|
||||
this.QuitItem});
|
||||
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
||||
this.contextMenuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
|
||||
this.contextMenuStrip1.Size = new System.Drawing.Size(153, 120);
|
||||
//
|
||||
// ConfigItem
|
||||
//
|
||||
this.ConfigItem.Name = "ConfigItem";
|
||||
this.ConfigItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.ConfigItem.Text = "Config";
|
||||
this.ConfigItem.Click += new System.EventHandler(this.Config_Click);
|
||||
//
|
||||
// aboutToolStripMenuItem
|
||||
//
|
||||
this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
|
||||
this.aboutToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.aboutToolStripMenuItem.Text = "About";
|
||||
this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click);
|
||||
//
|
||||
// toolStripSeparator2
|
||||
//
|
||||
this.toolStripSeparator2.Name = "toolStripSeparator2";
|
||||
this.toolStripSeparator2.Size = new System.Drawing.Size(149, 6);
|
||||
//
|
||||
// QuitItem
|
||||
//
|
||||
this.QuitItem.Name = "QuitItem";
|
||||
this.QuitItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.QuitItem.Text = "Quit";
|
||||
this.QuitItem.Click += new System.EventHandler(this.Quit_Click);
|
||||
//
|
||||
// panel2
|
||||
//
|
||||
this.panel2.Anchor = System.Windows.Forms.AnchorStyles.Top;
|
||||
@@ -280,14 +240,43 @@
|
||||
this.panel1.Size = new System.Drawing.Size(164, 30);
|
||||
this.panel1.TabIndex = 1;
|
||||
//
|
||||
// EnableItem
|
||||
// contextMenu1
|
||||
//
|
||||
this.EnableItem.Checked = true;
|
||||
this.EnableItem.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||
this.EnableItem.Name = "EnableItem";
|
||||
this.EnableItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.EnableItem.Text = "Enable";
|
||||
this.EnableItem.Click += new System.EventHandler(this.EnableItem_Click);
|
||||
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
||||
this.enableItem,
|
||||
this.configItem,
|
||||
this.aboutItem,
|
||||
this.menuItem3,
|
||||
this.quitItem});
|
||||
//
|
||||
// enableItem
|
||||
//
|
||||
this.enableItem.Index = 0;
|
||||
this.enableItem.Text = "Enable";
|
||||
this.enableItem.Click += new System.EventHandler(this.EnableItem_Click);
|
||||
//
|
||||
// aboutItem
|
||||
//
|
||||
this.aboutItem.Index = 2;
|
||||
this.aboutItem.Text = "About";
|
||||
this.aboutItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click);
|
||||
//
|
||||
// menuItem3
|
||||
//
|
||||
this.menuItem3.Index = 3;
|
||||
this.menuItem3.Text = "-";
|
||||
//
|
||||
// quitItem
|
||||
//
|
||||
this.quitItem.Index = 4;
|
||||
this.quitItem.Text = "Quit";
|
||||
this.quitItem.Click += new System.EventHandler(this.Quit_Click);
|
||||
//
|
||||
// configItem
|
||||
//
|
||||
this.configItem.Index = 1;
|
||||
this.configItem.Text = "Options...";
|
||||
this.configItem.Click += new System.EventHandler(this.Config_Click);
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
@@ -309,7 +298,6 @@
|
||||
this.Load += new System.EventHandler(this.Form1_Load);
|
||||
this.tableLayoutPanel1.ResumeLayout(false);
|
||||
this.tableLayoutPanel1.PerformLayout();
|
||||
this.contextMenuStrip1.ResumeLayout(false);
|
||||
this.panel1.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
@@ -328,18 +316,18 @@
|
||||
private System.Windows.Forms.TextBox textBox3;
|
||||
private System.Windows.Forms.TextBox textBox4;
|
||||
private System.Windows.Forms.NotifyIcon notifyIcon1;
|
||||
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
|
||||
private System.Windows.Forms.ToolStripMenuItem ConfigItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem QuitItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private System.Windows.Forms.ComboBox comboBox1;
|
||||
private System.Windows.Forms.Panel panel2;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.Button button2;
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
private System.Windows.Forms.ToolStripMenuItem EnableItem;
|
||||
private System.Windows.Forms.ContextMenu contextMenu1;
|
||||
private System.Windows.Forms.MenuItem enableItem;
|
||||
private System.Windows.Forms.MenuItem aboutItem;
|
||||
private System.Windows.Forms.MenuItem menuItem3;
|
||||
private System.Windows.Forms.MenuItem quitItem;
|
||||
private System.Windows.Forms.MenuItem configItem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,11 @@ namespace shadowsocks_csharp
|
||||
{
|
||||
config = Config.Load();
|
||||
InitializeComponent();
|
||||
notifyIcon1.ContextMenu = contextMenu1;
|
||||
enableItem.Checked = config.enabled;
|
||||
configToTextBox();
|
||||
}
|
||||
|
||||
|
||||
private void showWindow()
|
||||
{
|
||||
this.Opacity = 1;
|
||||
@@ -49,6 +51,7 @@ namespace shadowsocks_csharp
|
||||
}
|
||||
pacServer = new PACServer();
|
||||
pacServer.Start();
|
||||
updateSystemProxy();
|
||||
}
|
||||
|
||||
private void reload(Config config)
|
||||
@@ -120,6 +123,10 @@ namespace shadowsocks_csharp
|
||||
{
|
||||
if (local != null) local.Stop();
|
||||
if (polipoRunner != null) polipoRunner.Stop();
|
||||
if (config.enabled)
|
||||
{
|
||||
SystemProxy.Disable();
|
||||
}
|
||||
}
|
||||
|
||||
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
@@ -132,10 +139,9 @@ namespace shadowsocks_csharp
|
||||
showWindow();
|
||||
}
|
||||
|
||||
private void EnableItem_Click(object sender, EventArgs e)
|
||||
private void updateSystemProxy()
|
||||
{
|
||||
EnableItem.Checked = !EnableItem.Checked;
|
||||
if (EnableItem.Checked)
|
||||
if (config.enabled)
|
||||
{
|
||||
SystemProxy.Enable();
|
||||
}
|
||||
@@ -145,5 +151,13 @@ namespace shadowsocks_csharp
|
||||
}
|
||||
}
|
||||
|
||||
private void EnableItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
enableItem.Checked = !enableItem.Checked;
|
||||
config.enabled = enableItem.Checked;
|
||||
Config.Save(config);
|
||||
updateSystemProxy();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,9 +120,6 @@
|
||||
<metadata name="notifyIcon1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>130, 17</value>
|
||||
</metadata>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="notifyIcon1.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
@@ -148,6 +145,9 @@
|
||||
//8AAP//AAD//w==
|
||||
</value>
|
||||
</data>
|
||||
<metadata name="contextMenu1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>146, 19</value>
|
||||
</metadata>
|
||||
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
AAABAAUAEBAAAAAAIABoBAAAVgAAACAgAAAAACAAqBAAAL4EAAAwMAAAAAAgAKglAABmFQAAQEAAAAAA
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using shadowsocks_csharp.Properties;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
@@ -46,6 +48,26 @@ namespace shadowsocks_csharp
|
||||
}
|
||||
}
|
||||
|
||||
private string getPACContent()
|
||||
{
|
||||
// TODO try pac.txt in current directory
|
||||
byte[] pacGZ = Resources.proxy_pac_txt;
|
||||
|
||||
byte[] buffer = new byte[1024 * 1024]; // builtin pac gzip size: maximum 1M
|
||||
int n;
|
||||
|
||||
using (GZipStream input = new GZipStream(new MemoryStream(pacGZ),
|
||||
CompressionMode.Decompress, false))
|
||||
{
|
||||
n = input.Read(buffer, 0, buffer.Length);
|
||||
if (n == 0)
|
||||
{
|
||||
throw new IOException("can not decompress pac");
|
||||
}
|
||||
return System.Text.Encoding.UTF8.GetString(buffer, 0, n);
|
||||
}
|
||||
}
|
||||
|
||||
private void receiveCallback(IAsyncResult ar)
|
||||
{
|
||||
Socket conn = (Socket)ar.AsyncState;
|
||||
@@ -53,7 +75,7 @@ namespace shadowsocks_csharp
|
||||
{
|
||||
int bytesRead = conn.EndReceive(ar);
|
||||
|
||||
string pac = Resources.proxy_pac;
|
||||
string pac = getPACContent();
|
||||
|
||||
string proxy = "PROXY 127.0.0.1:8123; DIRECT;";
|
||||
|
||||
|
||||
+4
-25
@@ -96,33 +96,12 @@ namespace shadowsocks_csharp.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to // Generated by gfwlist2pac
|
||||
///// https://github.com/clowwindy/gfwlist2pac
|
||||
///
|
||||
///var domains = {
|
||||
/// "gimpshop.com": 1,
|
||||
/// "directcreative.com": 1,
|
||||
/// "speedpluss.org": 1,
|
||||
/// "mingpaovan.com": 1,
|
||||
/// "wikinews.org": 1,
|
||||
/// "joachims.org": 1,
|
||||
/// "maiio.net": 1,
|
||||
/// "idv.tw": 1,
|
||||
/// "mail-archive.com": 1,
|
||||
/// "surfeasy.com.au": 1,
|
||||
/// "hihistory.net": 1,
|
||||
/// "alexlur.org": 1,
|
||||
/// "finalion.jp": 1,
|
||||
/// "nrk.no": 1,
|
||||
/// "nyt.com": 1,
|
||||
/// "cmule.com": 1,
|
||||
/// "gappp.org": 1,
|
||||
/// "givemesomethingtoread.com": 1,
|
||||
/// [rest of string was truncated]";.
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
internal static string proxy_pac {
|
||||
internal static byte[] proxy_pac_txt {
|
||||
get {
|
||||
return ResourceManager.GetString("proxy_pac", resourceCulture);
|
||||
object obj = ResourceManager.GetObject("proxy_pac_txt", resourceCulture);
|
||||
return ((byte[])(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@
|
||||
<data name="polipo_exe" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\polipo.exe.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="proxy_pac" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\proxy.pac.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312</value>
|
||||
<data name="proxy_pac_txt" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\proxy.pac.txt.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
</root>
|
||||
File diff suppressed because it is too large
Load Diff
Executable
BIN
Binary file not shown.
@@ -126,6 +126,7 @@
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="simple-json\src\SimpleJson\SimpleJson.cs" />
|
||||
<None Include="proxy.pac.txt.gz" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="config.txt" />
|
||||
|
||||
Reference in New Issue
Block a user