添加自定义ACL及更新ACL功能

This commit is contained in:
Amazing_DM
2020-04-16 18:30:36 +08:00
parent bc0e88ae5e
commit 5f3a300ccc
7 changed files with 138 additions and 26 deletions

View File

@@ -50,8 +50,10 @@ namespace Netch.Forms
this.RestartServiceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.UninstallServiceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.CleanDNSCacheToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.UpdateACLToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.AboutToolStripButton = new System.Windows.Forms.ToolStripButton();
this.VersionLabel = new System.Windows.Forms.ToolStripLabel();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ConfigurationGroupBox = new System.Windows.Forms.GroupBox();
this.configLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
this.ProfileLabel = new System.Windows.Forms.Label();
@@ -108,7 +110,8 @@ namespace Netch.Forms
this.SubscribeToolStripMenuItem,
this.OptionsToolStripMenuItem,
this.AboutToolStripButton,
this.VersionLabel});
this.VersionLabel,
this.exitToolStripMenuItem});
this.MenuStrip.Location = new System.Drawing.Point(0, 0);
this.MenuStrip.Name = "MenuStrip";
this.MenuStrip.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;
@@ -217,7 +220,8 @@ namespace Netch.Forms
this.ReloadModesToolStripMenuItem,
this.RestartServiceToolStripMenuItem,
this.UninstallServiceToolStripMenuItem,
this.CleanDNSCacheToolStripMenuItem});
this.CleanDNSCacheToolStripMenuItem,
this.UpdateACLToolStripMenuItem});
this.OptionsToolStripMenuItem.Margin = new System.Windows.Forms.Padding(0, 0, 0, 1);
this.OptionsToolStripMenuItem.Name = "OptionsToolStripMenuItem";
this.OptionsToolStripMenuItem.Size = new System.Drawing.Size(66, 21);
@@ -226,31 +230,38 @@ namespace Netch.Forms
// ReloadModesToolStripMenuItem
//
this.ReloadModesToolStripMenuItem.Name = "ReloadModesToolStripMenuItem";
this.ReloadModesToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
this.ReloadModesToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.ReloadModesToolStripMenuItem.Text = "Reload Modes";
this.ReloadModesToolStripMenuItem.Click += new System.EventHandler(this.ReloadModesToolStripMenuItem_Click);
//
// RestartServiceToolStripMenuItem
//
this.RestartServiceToolStripMenuItem.Name = "RestartServiceToolStripMenuItem";
this.RestartServiceToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
this.RestartServiceToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.RestartServiceToolStripMenuItem.Text = "Restart Service";
this.RestartServiceToolStripMenuItem.Click += new System.EventHandler(this.RestartServiceToolStripMenuItem_Click);
//
// UninstallServiceToolStripMenuItem
//
this.UninstallServiceToolStripMenuItem.Name = "UninstallServiceToolStripMenuItem";
this.UninstallServiceToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
this.UninstallServiceToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.UninstallServiceToolStripMenuItem.Text = "Uninstall Service";
this.UninstallServiceToolStripMenuItem.Click += new System.EventHandler(this.UninstallServiceToolStripMenuItem_Click);
//
// CleanDNSCacheToolStripMenuItem
//
this.CleanDNSCacheToolStripMenuItem.Name = "CleanDNSCacheToolStripMenuItem";
this.CleanDNSCacheToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
this.CleanDNSCacheToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.CleanDNSCacheToolStripMenuItem.Text = "Clean DNS Cache";
this.CleanDNSCacheToolStripMenuItem.Click += new System.EventHandler(this.CleanDNSCacheToolStripMenuItem_Click);
//
// UpdateACLToolStripMenuItem
//
this.UpdateACLToolStripMenuItem.Name = "UpdateACLToolStripMenuItem";
this.UpdateACLToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.UpdateACLToolStripMenuItem.Text = "Update ACL";
this.UpdateACLToolStripMenuItem.Click += new System.EventHandler(this.updateACLToolStripMenuItem_Click);
//
// AboutToolStripButton
//
this.AboutToolStripButton.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
@@ -273,6 +284,13 @@ namespace Netch.Forms
this.VersionLabel.Text = "x.x.x";
this.VersionLabel.Click += new System.EventHandler(this.VersionLabel_Click);
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(40, 22);
this.exitToolStripMenuItem.Text = "Exit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
//
// ConfigurationGroupBox
//
this.ConfigurationGroupBox.Controls.Add(this.configLayoutPanel);
@@ -698,5 +716,7 @@ namespace Netch.Forms
private System.Windows.Forms.TableLayoutPanel configLayoutPanel;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3;
private System.Windows.Forms.ToolStripMenuItem UpdateACLToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
}
}

View File

@@ -6,6 +6,7 @@ using System.Drawing;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -325,10 +326,12 @@ namespace Netch.Forms
ManageSubscribeLinksToolStripMenuItem.Text = Utils.i18N.Translate(ManageSubscribeLinksToolStripMenuItem.Text);
UpdateServersFromSubscribeLinksToolStripMenuItem.Text = Utils.i18N.Translate(UpdateServersFromSubscribeLinksToolStripMenuItem.Text);
OptionsToolStripMenuItem.Text = Utils.i18N.Translate(OptionsToolStripMenuItem.Text);
exitToolStripMenuItem.Text = Utils.i18N.Translate(exitToolStripMenuItem.Text);
RestartServiceToolStripMenuItem.Text = Utils.i18N.Translate(RestartServiceToolStripMenuItem.Text);
UninstallServiceToolStripMenuItem.Text = Utils.i18N.Translate(UninstallServiceToolStripMenuItem.Text);
ReloadModesToolStripMenuItem.Text = Utils.i18N.Translate(ReloadModesToolStripMenuItem.Text);
CleanDNSCacheToolStripMenuItem.Text = Utils.i18N.Translate(CleanDNSCacheToolStripMenuItem.Text);
UpdateACLToolStripMenuItem.Text = Utils.i18N.Translate(UpdateACLToolStripMenuItem.Text);
AboutToolStripButton.Text = Utils.i18N.Translate(AboutToolStripButton.Text);
ConfigurationGroupBox.Text = Utils.i18N.Translate(ConfigurationGroupBox.Text);
ServerLabel.Text = Utils.i18N.Translate(ServerLabel.Text);
@@ -885,8 +888,8 @@ namespace Netch.Forms
if (State == Models.State.Started)
{
server.Test();
// 重载服务器列表
InitServer();
// 重载服务器列表
InitServer();
Thread.Sleep(Global.Settings.StartedTcping_Interval * 1000);
}
@@ -1284,5 +1287,55 @@ namespace Netch.Forms
NatTypeStatusLabel.Text = "NAT" + Utils.i18N.Translate(": ") + Utils.i18N.Translate("Test failed");
}
}
private void updateACLToolStripMenuItem_Click(object sender, EventArgs e)
{
using var client = new Override.WebClient();
client.DownloadFileTaskAsync(Global.Settings.ACL, "bin\\default.acl");
client.DownloadFileCompleted += ((sender, args) =>
{
if (args.Error == null)
{
MessageBox.Show(Utils.i18N.Translate("ACL updated successfully"));
}
else
{
Utils.Logging.Info("ACL更新失败" + args.Error);
MessageBox.Show(Utils.i18N.Translate("ACL update failed"));
}
});
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
// 当前状态如果不是已停止状态
if (State != Models.State.Waiting && State != Models.State.Stopped)
{
// 如果未勾选退出时停止,要求先点击停止按钮
if (!Global.Settings.StopWhenExited)
{
MessageBox.Show(Utils.i18N.Translate("Please press Stop button first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Visible = true;
ShowInTaskbar = true; // 显示在系统任务栏
WindowState = FormWindowState.Normal; // 还原窗体
NotifyIcon.Visible = true; // 托盘图标隐藏
return;
}
// 否则直接调用停止按钮的方法
ControlButton_Click(sender, e);
}
SaveConfigs();
State = Models.State.Terminating;
NotifyIcon.Visible = false;
Close();
Dispose();
Environment.Exit(Environment.ExitCode);
}
}
}

View File

@@ -30,6 +30,8 @@
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SettingForm));
this.PortGroupBox = new System.Windows.Forms.GroupBox();
this.RedirectorLabel = new System.Windows.Forms.Label();
this.RedirectorTextBox = new System.Windows.Forms.TextBox();
this.AllowDevicesCheckBox = new System.Windows.Forms.CheckBox();
this.HTTPPortLabel = new System.Windows.Forms.Label();
this.HTTPPortTextBox = new System.Windows.Forms.TextBox();
@@ -68,8 +70,8 @@
this.StartWhenOpenedCheckBox = new System.Windows.Forms.CheckBox();
this.StopWhenExitedCheckBox = new System.Windows.Forms.CheckBox();
this.ExitWhenClosedCheckBox = new System.Windows.Forms.CheckBox();
this.RedirectorLabel = new System.Windows.Forms.Label();
this.RedirectorTextBox = new System.Windows.Forms.TextBox();
this.AclAddr = new System.Windows.Forms.TextBox();
this.AclLabel = new System.Windows.Forms.Label();
this.PortGroupBox.SuspendLayout();
this.TUNTAPGroupBox.SuspendLayout();
this.BehaviorGroupBox.SuspendLayout();
@@ -91,6 +93,23 @@
this.PortGroupBox.TabStop = false;
this.PortGroupBox.Text = "Local Port";
//
// RedirectorLabel
//
this.RedirectorLabel.AutoSize = true;
this.RedirectorLabel.Location = new System.Drawing.Point(9, 83);
this.RedirectorLabel.Name = "RedirectorLabel";
this.RedirectorLabel.Size = new System.Drawing.Size(95, 17);
this.RedirectorLabel.TabIndex = 6;
this.RedirectorLabel.Text = "Redirector TCP";
//
// RedirectorTextBox
//
this.RedirectorTextBox.Location = new System.Drawing.Point(120, 80);
this.RedirectorTextBox.Name = "RedirectorTextBox";
this.RedirectorTextBox.Size = new System.Drawing.Size(294, 23);
this.RedirectorTextBox.TabIndex = 7;
this.RedirectorTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// AllowDevicesCheckBox
//
this.AllowDevicesCheckBox.AutoSize = true;
@@ -268,6 +287,8 @@
//
// BehaviorGroupBox
//
this.BehaviorGroupBox.Controls.Add(this.AclAddr);
this.BehaviorGroupBox.Controls.Add(this.AclLabel);
this.BehaviorGroupBox.Controls.Add(this.DetectionInterval_Label);
this.BehaviorGroupBox.Controls.Add(this.DetectionInterval_TextBox);
this.BehaviorGroupBox.Controls.Add(this.EnableStartedTcping_CheckBox);
@@ -333,7 +354,7 @@
// BypassModeCheckBox
//
this.BypassModeCheckBox.AutoSize = true;
this.BypassModeCheckBox.Location = new System.Drawing.Point(276, 236);
this.BypassModeCheckBox.Location = new System.Drawing.Point(276, 307);
this.BypassModeCheckBox.Name = "BypassModeCheckBox";
this.BypassModeCheckBox.Size = new System.Drawing.Size(135, 21);
this.BypassModeCheckBox.TabIndex = 14;
@@ -344,7 +365,7 @@
// Redirector2checkBox
//
this.Redirector2checkBox.AutoSize = true;
this.Redirector2checkBox.Location = new System.Drawing.Point(152, 235);
this.Redirector2checkBox.Location = new System.Drawing.Point(152, 306);
this.Redirector2checkBox.Name = "Redirector2checkBox";
this.Redirector2checkBox.Size = new System.Drawing.Size(118, 21);
this.Redirector2checkBox.TabIndex = 11;
@@ -354,7 +375,7 @@
// ExperimentalFunction_Label
//
this.ExperimentalFunction_Label.AutoSize = true;
this.ExperimentalFunction_Label.Location = new System.Drawing.Point(6, 236);
this.ExperimentalFunction_Label.Location = new System.Drawing.Point(6, 307);
this.ExperimentalFunction_Label.Name = "ExperimentalFunction_Label";
this.ExperimentalFunction_Label.Size = new System.Drawing.Size(133, 17);
this.ExperimentalFunction_Label.TabIndex = 13;
@@ -475,22 +496,22 @@
this.ExitWhenClosedCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.ExitWhenClosedCheckBox.UseVisualStyleBackColor = true;
//
// RedirectorLabel
// AclAddr
//
this.RedirectorLabel.AutoSize = true;
this.RedirectorLabel.Location = new System.Drawing.Point(9, 83);
this.RedirectorLabel.Name = "RedirectorLabel";
this.RedirectorLabel.Size = new System.Drawing.Size(95, 17);
this.RedirectorLabel.TabIndex = 6;
this.RedirectorLabel.Text = "Redirector TCP";
this.AclAddr.Location = new System.Drawing.Point(117, 235);
this.AclAddr.Name = "AclAddr";
this.AclAddr.Size = new System.Drawing.Size(294, 23);
this.AclAddr.TabIndex = 19;
this.AclAddr.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// RedirectorTextBox
// AclLabel
//
this.RedirectorTextBox.Location = new System.Drawing.Point(120, 80);
this.RedirectorTextBox.Name = "RedirectorTextBox";
this.RedirectorTextBox.Size = new System.Drawing.Size(294, 23);
this.RedirectorTextBox.TabIndex = 7;
this.RedirectorTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.AclLabel.AutoSize = true;
this.AclLabel.Location = new System.Drawing.Point(6, 238);
this.AclLabel.Name = "AclLabel";
this.AclLabel.Size = new System.Drawing.Size(78, 17);
this.AclLabel.TabIndex = 20;
this.AclLabel.Text = "Custom ACL";
//
// SettingForm
//
@@ -565,5 +586,7 @@
private System.Windows.Forms.Label DetectionInterval_Label;
private System.Windows.Forms.Label RedirectorLabel;
private System.Windows.Forms.TextBox RedirectorTextBox;
private System.Windows.Forms.TextBox AclAddr;
private System.Windows.Forms.Label AclLabel;
}
}

View File

@@ -96,6 +96,9 @@ namespace Netch.Forms
STUN_ServerTextBox.Text = Global.Settings.STUN_Server.ToString();
STUN_ServerPortTextBox.Text = Global.Settings.STUN_Server_Port.ToString();
AclLabel.Text = Utils.i18N.Translate(AclLabel.Text);
AclAddr.Text = Global.Settings.ACL.ToString();
if (Global.Settings.TUNTAP.DNS.Count > 0)
{
var dns = "";
@@ -367,6 +370,8 @@ namespace Netch.Forms
return;
}
Global.Settings.ACL = AclAddr.Text;
Global.Settings.TUNTAP.Address = TUNTAPAddressTextBox.Text;
Global.Settings.TUNTAP.Netmask = TUNTAPNetmaskTextBox.Text;
Global.Settings.TUNTAP.Gateway = TUNTAPGatewayTextBox.Text;

View File

@@ -173,5 +173,11 @@ namespace Netch.Models
/// 启动后延迟测试间隔/秒
/// </summary>
public int StartedTcping_Interval = 3;
/// <summary>
/// ACL规则
/// </summary>
public string ACL = "https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/banAD.acl";
}
}

View File

@@ -112,4 +112,5 @@
<Target Condition="'$(VisualStudioDir)' != ''" Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="@ECHO OFF&#xD;&#xA;RD /S /Q $(TargetDir)bin &gt; NUL 2&gt;&amp;1&#xD;&#xA;RD /S /Q $(TargetDir)i18n &gt; NUL 2&gt;&amp;1&#xD;&#xA;RD /S /Q $(TargetDir)mode &gt; NUL 2&gt;&amp;1&#xD;&#xA;&#xD;&#xA;MKDIR $(TargetDir)bin &gt; NUL 2&gt;&amp;1&#xD;&#xA;MKDIR $(TargetDir)i18n &gt; NUL 2&gt;&amp;1&#xD;&#xA;MKDIR $(TargetDir)mode &gt; NUL 2&gt;&amp;1&#xD;&#xA;&#xD;&#xA;COPY /Y $(SolutionDir)binaries\$(PlatformName)\* $(TargetDir)bin &gt; NUL 2&gt;&amp;1&#xD;&#xA;COPY /Y $(SolutionDir)binaries\* $(TargetDir)bin &gt; NUL 2&gt;&amp;1&#xD;&#xA;MOVE /Y $(TargetDir)bin\nfapinet.dll $(TargetDir)nfapinet.dll &gt; NUL 2&gt;&amp;1&#xD;&#xA;COPY /Y $(SolutionDir)translations\i18n\* $(TargetDir)i18n &gt; NUL 2&gt;&amp;1&#xD;&#xA;COPY /Y $(SolutionDir)modes\mode\*.txt $(TargetDir)mode &gt; NUL 2&gt;&amp;1&#xD;&#xA;MKDIR $(TargetDir)bin\tap-driver &gt; NUL 2&gt;&amp;1&#xD;&#xA;COPY /Y $(SolutionDir)binaries\$(PlatformName)\tap-driver\* $(TargetDir)bin\tap-driver &gt; NUL 2&gt;&amp;1" />
</Target>
<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions>
</Project>

View File

@@ -88,6 +88,9 @@
"Modes have been reload": "模式已重载",
"Clean DNS Cache": "清理 DNS 缓存",
"DNS cache cleanup succeeded": "DNS 缓存清理成功",
"Update ACL": "更新ACL规则",
"ACL updated successfully": "ACL更新成功",
"ACL update failed": "ACL更新失败",
"About": "关于",
"Telegram Channel": "Telegram 频道",
@@ -158,6 +161,7 @@
"Delay test after startup": "启动后延迟测试",
"Enable": "启用",
"Detection interval(/s)": "检测间隔(/秒)",
"Custom ACL": "自定义ACL规则",
"Profile": "配置名",
"Profiles": "配置",