diff --git a/shadowsocks-csharp/Controller/Service/PACServer.cs b/shadowsocks-csharp/Controller/Service/PACServer.cs index 616a153..207ee62 100644 --- a/shadowsocks-csharp/Controller/Service/PACServer.cs +++ b/shadowsocks-csharp/Controller/Service/PACServer.cs @@ -18,7 +18,9 @@ namespace Shadowsocks.Controller public const string USER_RULE_FILE = "user-rule.txt"; public const string USER_ABP_FILE = "abp.txt"; - public string PacSecret { get; private set; } = ""; + private string PacSecret { get; set; } = ""; + + public string PacUrl { get; private set; } = ""; FileSystemWatcher PACFileWatcher; FileSystemWatcher UserRuleFileWatcher; @@ -47,6 +49,14 @@ namespace Shadowsocks.Controller { PacSecret = ""; } + + PacUrl = $"http://127.0.0.1:{config.localPort}/pac?t={GetTimestamp(DateTime.Now)}{PacSecret}"; + } + + + private static string GetTimestamp(DateTime value) + { + return value.ToString("yyyyMMddHHmmssfff"); } public override bool Handle(byte[] firstPacket, int length, Socket socket, object state) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 9243b92..3e12bdd 100644 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -6,6 +6,7 @@ using System.Net.Sockets; using System.Text; using System.Threading; using System.Web; +using System.Windows.Forms; using Newtonsoft.Json; using Shadowsocks.Controller.Service; using Shadowsocks.Controller.Strategy; @@ -575,6 +576,11 @@ namespace Shadowsocks.Controller File.WriteAllText(PACServer.PAC_FILE, abpContent, Encoding.UTF8); } + public void CopyPacUrl() + { + Clipboard.SetDataObject(_pacServer.PacUrl); + } + #region Memory Management private void StartReleasingMemory() diff --git a/shadowsocks-csharp/Controller/System/SystemProxy.cs b/shadowsocks-csharp/Controller/System/SystemProxy.cs index 6b7aab8..63e2a8b 100644 --- a/shadowsocks-csharp/Controller/System/SystemProxy.cs +++ b/shadowsocks-csharp/Controller/System/SystemProxy.cs @@ -38,8 +38,7 @@ namespace Shadowsocks.Controller } else { - pacUrl = - $"http://127.0.0.1:{config.localPort}/pac?t={GetTimestamp(DateTime.Now)}{pacSrv.PacSecret}"; + pacUrl = pacSrv.PacUrl; } Sysproxy.SetIEProxy(true, false, "", pacUrl); } diff --git a/shadowsocks-csharp/Data/cn.txt b/shadowsocks-csharp/Data/cn.txt index 2e90f3f..98cc98e 100644 --- a/shadowsocks-csharp/Data/cn.txt +++ b/shadowsocks-csharp/Data/cn.txt @@ -20,6 +20,7 @@ Edit Local PAC File...=编辑本地 PAC 文件... Update Local PAC from GFWList=从 GFWList 更新本地 PAC Edit User Rule for GFWList...=编辑 GFWList 的用户规则... Secure Local PAC=保护本地 PAC +Copy Local PAC URL=复制本地 PAC 网址 Show QRCode...=显示二维码... Scan QRCode from Screen...=扫描屏幕上的二维码... Availability Statistics=统计可用性 diff --git a/shadowsocks-csharp/Data/zh_tw.txt b/shadowsocks-csharp/Data/zh_tw.txt index d0c4b07..17a1351 100644 --- a/shadowsocks-csharp/Data/zh_tw.txt +++ b/shadowsocks-csharp/Data/zh_tw.txt @@ -20,6 +20,7 @@ Edit Local PAC File...=編輯本地 PAC 文件... Update Local PAC from GFWList=從 GFWList 更新本地 PAC Edit User Rule for GFWList...=編輯 GFWList 的用戶規則... Secure Local PAC=保護本地 PAC +Copy Local PAC URL=複製本地 PAC 網址 Show QRCode...=顯示 QR 碼... Scan QRCode from Screen...=掃描螢幕上的 QR 碼... Availability Statistics=統計可用性 diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index fa73ff5..3aba64d 100644 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -271,8 +271,9 @@ namespace Shadowsocks.View this.editLocalPACItem = CreateMenuItem("Edit Local PAC File...", new EventHandler(this.EditPACFileItem_Click)), this.updateFromGFWListItem = CreateMenuItem("Update Local PAC from GFWList", new EventHandler(this.UpdatePACFromGFWListItem_Click)), this.editGFWUserRuleItem = CreateMenuItem("Edit User Rule for GFWList...", new EventHandler(this.EditUserRuleFileForGFWListItem_Click)), - this.editOnlinePACItem = CreateMenuItem("Edit Online PAC URL...", new EventHandler(this.UpdateOnlinePACURLItem_Click)), this.secureLocalPacUrlToggleItem = CreateMenuItem("Secure Local PAC", new EventHandler(this.SecureLocalPacUrlToggleItem_Click)), + CreateMenuItem("Copy Local PAC URL", new EventHandler(this.CopyLocalPacUrlItem_Click)), + this.editOnlinePACItem = CreateMenuItem("Edit Online PAC URL...", new EventHandler(this.UpdateOnlinePACURLItem_Click)), }), this.proxyItem = CreateMenuItem("Forward Proxy...", new EventHandler(this.proxyItem_Click)), new MenuItem("-"), @@ -805,6 +806,11 @@ namespace Shadowsocks.View controller.ToggleSecureLocalPac(!configuration.secureLocalPac); } + private void CopyLocalPacUrlItem_Click(object sender, EventArgs e) + { + controller.CopyPacUrl(); + } + private void UpdatePACItemsEnabledStatus() { if (this.localPACItem.Checked)