Skip to content

Commit

Permalink
优化添加防火墙规则
Browse files Browse the repository at this point in the history
  • Loading branch information
snltty committed Sep 13, 2024
1 parent 0769e1b commit 5d0dbcd
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 73 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.ACTIONS_TOKEN }}
with:
tag_name: v1.3.2
release_name: v1.3.2.${{ steps.date.outputs.today }}
tag_name: v1.3.3
release_name: v1.3.3.${{ steps.date.outputs.today }}
draft: false
prerelease: false
body: "1. 优化网卡(设备下线后路由指向错误)\r\n2. 管理页面配置权限\r\n3. 导出配置及指定节点配置权限\r\n4. 实时配置客户端管理权限\r\n5. 重复连接,同设备挤压,不同设备禁止连接\r\n6. 自定义背景图片"
body: 1. 优化添加防火墙规则,不使用文件
- name: upload-win-x86-oss
id: upload-win-x86-oss
uses: tvrcgo/[email protected]
Expand All @@ -47,7 +47,7 @@ jobs:
key-secret: ${{ secrets.ALIYUN_OSS_SECRET }}
bucket: ide-qbcode
asset-path: ./public/publish-zip/linker-win-x86.zip
target-path: /downloads/linker/v1.3.2/linker-win-x86.zip
target-path: /downloads/linker/v1.3.3/linker-win-x86.zip
- name: upload-win-x86
id: upload-win-x86
uses: actions/upload-release-asset@master
Expand All @@ -67,7 +67,7 @@ jobs:
key-secret: ${{ secrets.ALIYUN_OSS_SECRET }}
bucket: ide-qbcode
asset-path: ./public/publish-zip/linker-win-x64.zip
target-path: /downloads/linker/v1.3.2/linker-win-x64.zip
target-path: /downloads/linker/v1.3.3/linker-win-x64.zip
- name: upload-win-x64
id: upload-win-x64
uses: actions/upload-release-asset@master
Expand All @@ -87,7 +87,7 @@ jobs:
key-secret: ${{ secrets.ALIYUN_OSS_SECRET }}
bucket: ide-qbcode
asset-path: ./public/publish-zip/linker-win-arm64.zip
target-path: /downloads/linker/v1.3.2/linker-win-arm64.zip
target-path: /downloads/linker/v1.3.3/linker-win-arm64.zip
- name: upload-win-arm64
id: upload-win-arm64
uses: actions/upload-release-asset@master
Expand All @@ -107,7 +107,7 @@ jobs:
key-secret: ${{ secrets.ALIYUN_OSS_SECRET }}
bucket: ide-qbcode
asset-path: ./public/publish-zip/linker-linux-x64.zip
target-path: /downloads/linker/v1.3.2/linker-linux-x64.zip
target-path: /downloads/linker/v1.3.3/linker-linux-x64.zip
- name: upload-linux-x64
id: upload-linux-x64
uses: actions/upload-release-asset@master
Expand All @@ -127,7 +127,7 @@ jobs:
key-secret: ${{ secrets.ALIYUN_OSS_SECRET }}
bucket: ide-qbcode
asset-path: ./public/publish-zip/linker-linux-arm.zip
target-path: /downloads/linker/v1.3.2/linker-linux-arm.zip
target-path: /downloads/linker/v1.3.3/linker-linux-arm.zip
- name: upload-linux-arm
id: upload-linux-arm
uses: actions/upload-release-asset@master
Expand All @@ -147,7 +147,7 @@ jobs:
key-secret: ${{ secrets.ALIYUN_OSS_SECRET }}
bucket: ide-qbcode
asset-path: ./public/publish-zip/linker-linux-arm64.zip
target-path: /downloads/linker/v1.3.2/linker-linux-arm64.zip
target-path: /downloads/linker/v1.3.3/linker-linux-arm64.zip
- name: upload-linux-arm64
id: upload-linux-arm64
uses: actions/upload-release-asset@master
Expand All @@ -167,7 +167,7 @@ jobs:
key-secret: ${{ secrets.ALIYUN_OSS_SECRET }}
bucket: ide-qbcode
asset-path: ./public/publish-zip/linker-linux-musl-x64.zip
target-path: /downloads/linker/v1.3.2/linker-linux-musl-x64.zip
target-path: /downloads/linker/v1.3.3/linker-linux-musl-x64.zip
- name: upload-linux-musl-x64
id: upload-linux-musl-x64
uses: actions/upload-release-asset@master
Expand All @@ -187,7 +187,7 @@ jobs:
key-secret: ${{ secrets.ALIYUN_OSS_SECRET }}
bucket: ide-qbcode
asset-path: ./public/publish-zip/linker-linux-musl-arm.zip
target-path: /downloads/linker/v1.3.2/linker-linux-musl-arm.zip
target-path: /downloads/linker/v1.3.3/linker-linux-musl-arm.zip
- name: upload-linux-musl-arm
id: upload-linux-musl-arm
uses: actions/upload-release-asset@master
Expand All @@ -207,7 +207,7 @@ jobs:
key-secret: ${{ secrets.ALIYUN_OSS_SECRET }}
bucket: ide-qbcode
asset-path: ./public/publish-zip/linker-linux-musl-arm64.zip
target-path: /downloads/linker/v1.3.2/linker-linux-musl-arm64.zip
target-path: /downloads/linker/v1.3.3/linker-linux-musl-arm64.zip
- name: upload-linux-musl-arm64
id: upload-linux-musl-arm64
uses: actions/upload-release-asset@master
Expand All @@ -227,7 +227,7 @@ jobs:
key-secret: ${{ secrets.ALIYUN_OSS_SECRET }}
bucket: ide-qbcode
asset-path: ./public/publish-zip/linker-osx-x64.zip
target-path: /downloads/linker/v1.3.2/linker-osx-x64.zip
target-path: /downloads/linker/v1.3.3/linker-osx-x64.zip
- name: upload-osx-x64
id: upload-osx-x64
uses: actions/upload-release-asset@master
Expand All @@ -247,7 +247,7 @@ jobs:
key-secret: ${{ secrets.ALIYUN_OSS_SECRET }}
bucket: ide-qbcode
asset-path: ./public/publish-zip/linker-osx-arm64.zip
target-path: /downloads/linker/v1.3.2/linker-osx-arm64.zip
target-path: /downloads/linker/v1.3.3/linker-osx-arm64.zip
- name: upload-osx-arm64
id: upload-osx-arm64
uses: actions/upload-release-asset@master
Expand Down Expand Up @@ -277,7 +277,7 @@ jobs:
key-secret: ${{ secrets.ALIYUN_OSS_SECRET }}
bucket: ide-qbcode
asset-path: ./public/publish-zip/linker-windows-route.zip
target-path: /downloads/linker/v1.3.2/linker-windows-route.zip
target-path: /downloads/linker/v1.3.3/linker-windows-route.zip
- name: upload-windows-route
id: upload-windows-route
uses: actions/upload-release-asset@master
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ jobs:

- name: Push
run: |
nuget push ./linker.tunnel/bin/release/linker.tunnel.1.3.2.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NUGET_KEY }} -NoSymbol
nuget push ./linker.libs/bin/release/linker.libs.1.3.2.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NUGET_KEY }} -NoSymbol
nuget push ./linker.tun/bin/release/linker.tun.1.3.2.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NUGET_KEY }} -NoSymbol
nuget push ./linker.tunnel/bin/release/linker.tunnel.1.3.3.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NUGET_KEY }} -NoSymbol
nuget push ./linker.libs/bin/release/linker.libs.1.3.3.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NUGET_KEY }} -NoSymbol
nuget push ./linker.tun/bin/release/linker.tun.1.3.3.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NUGET_KEY }} -NoSymbol
38 changes: 11 additions & 27 deletions linker.libs/FireWallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace linker.libs
{
public static class FireWallHelper
{
public static void Write(string fileName, string distPatt)
public static void Write(string fileName)
{
if (OperatingSystem.IsWindows())
{
Windows(fileName, distPatt);
Windows(fileName);
}
else if (OperatingSystem.IsLinux())
{
Expand All @@ -19,6 +19,7 @@ public static void Write(string fileName, string distPatt)

private static void Linux(string fileName)
{
fileName = Path.GetFileNameWithoutExtension(fileName);
CommandHelper.Linux(string.Empty, new string[] {
$"firewall-cmd --permanent --new-service={fileName}",
$"firewall-cmd --permanent --service={fileName} --set-short=\"My Application {fileName}\"",
Expand All @@ -31,34 +32,17 @@ private static void Linux(string fileName)
});
}

private static void Windows(string fileName, string distPath)
private static void Windows(string fileName)
{
try
{
string content = $@"@echo off
cd ""%CD%""
for /f ""tokens=4,5 delims=. "" %%a in ('ver') do if %%a%%b geq 60 goto new
:old
cmd /c netsh firewall delete allowedprogram program=""%CD%\{fileName}.exe"" profile=ALL
cmd /c netsh firewall add allowedprogram program=""%CD%\{fileName}.exe"" name=""{fileName}"" ENABLE
cmd /c netsh firewall add allowedprogram program=""%CD%\{fileName}.exe"" name=""{fileName}"" ENABLE profile=ALL
goto end
:new
cmd /c netsh advfirewall firewall delete rule name=""{fileName}""
cmd /c netsh advfirewall firewall add rule name=""{fileName}"" dir=in action=allow program=""%CD%\{fileName}.exe"" protocol=tcp enable=yes
cmd /c netsh advfirewall firewall add rule name=""{fileName}"" dir=in action=allow program=""%CD%\{fileName}.exe"" protocol=udp enable=yes
cmd /c netsh advfirewall firewall add rule name=""{fileName}"" dir=in action=allow program=""%CD%\{fileName}.exe"" protocol=icmpv4 enable=yes
:end";
if (Directory.Exists(distPath) == false)
{
Directory.CreateDirectory(distPath);
}
string firewall = Path.Join(distPath, "firewall.bat");

File.WriteAllText(firewall, content);
CommandHelper.Execute(firewall, string.Empty, new string[0],out string error);
File.Delete(firewall);
string name = Path.GetFileNameWithoutExtension(fileName);
CommandHelper.Windows(string.Empty, new string[] {
$"netsh advfirewall firewall delete rule name=\"{name}\"",
$"netsh advfirewall firewall add rule name=\"{name}\" dir=in action=allow program=\"{fileName}\" protocol=tcp enable=yes",
$"netsh advfirewall firewall add rule name=\"{name}\" dir=in action=allow program=\"{fileName}\" protocol=udp enable=yes",
$"netsh advfirewall firewall add rule name=\"{name}\" dir=in action=allow program=\"{fileName}\" protocol=icmpv4 enable=yes",
});
}
catch (Exception)
{
Expand Down
6 changes: 3 additions & 3 deletions linker.libs/linker.libs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<Copyright>snltty</Copyright>
<PackageProjectUrl>https://github.com/snltty/linker</PackageProjectUrl>
<RepositoryUrl>https://github.com/snltty/linker</RepositoryUrl>
<Version>1.3.2</Version>
<AssemblyVersion>1.3.2</AssemblyVersion>
<FileVersion>1.3.2</FileVersion>
<Version>1.3.3</Version>
<AssemblyVersion>1.3.3</AssemblyVersion>
<FileVersion>1.3.3</FileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>full</DebugType>
Expand Down
2 changes: 1 addition & 1 deletion linker.tray.win/default.aproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<project ver="10" name="linker.tray.win" libEmbed="true" icon="..\linker\favicon.ico" ui="win" output="linker.tray.win.exe" CompanyName="snltty" FileDescription="linker.tray.win" LegalCopyright="Copyright (C) snltty 2024" ProductName="linker.tray.win" InternalName="linker.install.win" FileVersion="0.0.0.100" ProductVersion="0.0.0.100" publishDir="/dist/" dstrip="false" local="false" ignored="false">
<project ver="10" name="linker.tray.win" libEmbed="true" icon="..\linker\favicon.ico" ui="win" output="linker.tray.win.exe" CompanyName="snltty" FileDescription="linker.tray.win" LegalCopyright="Copyright (C) snltty 2024" ProductName="linker.tray.win" InternalName="linker.install.win" FileVersion="0.0.0.102" ProductVersion="0.0.0.102" publishDir="/dist/" dstrip="false" local="false" ignored="false">
<file name="main.aardio" path="main.aardio" comment="main.aardio"/>
<folder name="资源文件" path="res" embed="true" local="false" ignored="false">
<file name="favicon.ico" path="res\favicon.ico" comment="res\favicon.ico"/>
Expand Down
6 changes: 3 additions & 3 deletions linker.tun/linker.tun.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<Title>linker tun</Title>
<Version>1.3.2</Version>
<Version>1.3.3</Version>
<Authors>snltty</Authors>
<Company>snltty</Company>
<Description>linker tun</Description>
<Copyright>snltty</Copyright>
<PackageProjectUrl>https://github.com/snltty/linker</PackageProjectUrl>
<RepositoryUrl>https://github.com/snltty/linker</RepositoryUrl>
<PackageReleaseNotes>linker tun</PackageReleaseNotes>
<AssemblyVersion>1.3.2</AssemblyVersion>
<FileVersion>1.3.2</FileVersion>
<AssemblyVersion>1.3.3</AssemblyVersion>
<FileVersion>1.3.3</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
6 changes: 3 additions & 3 deletions linker.tunnel/linker.tunnel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<Title>linker tunnel</Title>
<Version>1.3.2</Version>
<Version>1.3.3</Version>
<Authors>snltty</Authors>
<Company>snltty</Company>
<Description>linker tunnel</Description>
<Copyright>snltty</Copyright>
<PackageProjectUrl>https://github.com/snltty/linker</PackageProjectUrl>
<RepositoryUrl>https://github.com/snltty/linker</RepositoryUrl>
<PackageReleaseNotes>linker tunnel</PackageReleaseNotes>
<AssemblyVersion>1.3.2</AssemblyVersion>
<FileVersion>1.3.2</FileVersion>
<AssemblyVersion>1.3.3</AssemblyVersion>
<FileVersion>1.3.3</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
13 changes: 4 additions & 9 deletions linker/linker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,16 @@
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<ServerGarbageCollection>false</ServerGarbageCollection>
<Title>linker</Title>
<Version>1.3.2</Version>
<Version>1.3.3</Version>
<Authors>snltty</Authors>
<Company>snltty</Company>
<Description>1. 优化网卡(设备下线后路由指向错误)
2. 管理页面配置权限
3. 导出配置及指定节点配置权限
4. 实时配置客户端管理权限
5. 重复连接,同设备挤压,不同设备禁止连接
6. 自定义背景图片</Description>
<Description>1. 优化添加防火墙规则,不使用文件</Description>
<Copyright>snltty</Copyright>
<PackageProjectUrl>https://github.com/snltty/linker</PackageProjectUrl>
<RepositoryUrl>https://github.com/snltty/linker</RepositoryUrl>
<PackageReleaseNotes>linker</PackageReleaseNotes>
<AssemblyVersion>1.3.2</AssemblyVersion>
<FileVersion>1.3.2</FileVersion>
<AssemblyVersion>1.3.3</AssemblyVersion>
<FileVersion>1.3.3</FileVersion>
</PropertyGroup>


Expand Down
3 changes: 2 additions & 1 deletion linker/plugins/firewall/FireWallStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ public sealed class FireWallStartup : IStartup

public void AddClient(ServiceCollection serviceCollection, FileConfig config, Assembly[] assemblies)
{
//linker.libs.FireWallHelper.Write(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
#if DEBUG
#else
linker.libs.FireWallHelper.Write(Path.GetFileNameWithoutExtension(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName), "./");
linker.libs.FireWallHelper.Write(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
#endif
}

Expand Down
11 changes: 3 additions & 8 deletions version.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
v1.3.2
2024-09-13 00:24:28
1. 优化网卡(设备下线后路由指向错误)
2. 管理页面配置权限
3. 导出配置及指定节点配置权限
4. 实时配置客户端管理权限
5. 重复连接,同设备挤压,不同设备禁止连接
6. 自定义背景图片
v1.3.3
2024-09-13 09:40:55
1. 优化添加防火墙规则,不使用文件

0 comments on commit 5d0dbcd

Please sign in to comment.