diff --git a/BUILD.md b/BUILD.md new file mode 100644 index 00000000..b8cd7318 --- /dev/null +++ b/BUILD.md @@ -0,0 +1,10 @@ +# How to build +## Requirements +- Go +- MinGW-w64 +- Visual Studio 2019 + +## Build +```powershell +.\build.ps1 +``` diff --git a/Netch/Controllers/Mode/LSPController.cs b/Netch/Controllers/Mode/LSPController.cs index f71b265a..ada6865f 100644 --- a/Netch/Controllers/Mode/LSPController.cs +++ b/Netch/Controllers/Mode/LSPController.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Netch.Controllers.Mode { diff --git a/Netch/Controllers/Mode/RedirectorController.cs b/Netch/Controllers/Mode/RedirectorController.cs index 837bd40d..faf6d85d 100644 --- a/Netch/Controllers/Mode/RedirectorController.cs +++ b/Netch/Controllers/Mode/RedirectorController.cs @@ -56,6 +56,8 @@ namespace Netch.Controllers.Mode public bool Create(Models.Server.Server s, Models.Mode.Mode m) { + Global.Logger.Info(String.Format("{0:x} Redirector.bin", Utils.FileHelper.Checksum("Bin\\Redirector.bin"))); + var mode = m as Models.Mode.ProcessMode.ProcessMode; Methods.aio_dial(NameList.TYPE_FILTERLOOPBACK, mode.Loopback ? "true" : "false"); Methods.aio_dial(NameList.TYPE_FILTERTCP, mode.TCP ? "true" : "false"); diff --git a/Netch/Controllers/Mode/TapController.cs b/Netch/Controllers/Mode/TapController.cs index 297b2f6f..96809b62 100644 --- a/Netch/Controllers/Mode/TapController.cs +++ b/Netch/Controllers/Mode/TapController.cs @@ -133,8 +133,12 @@ namespace Netch.Controllers.Mode public bool Create(Models.Server.Server s, Models.Mode.Mode m) { + Global.Logger.Info(String.Format("{0:x} tap2socks.bin", Utils.FileHelper.Checksum("Bin\\tap2socks.bin"))); + if (!this.Outbound.Get()) { + Global.Logger.Error(String.Format("Failed to fetch outbound")); + return false; } diff --git a/Netch/Controllers/Mode/TunController.cs b/Netch/Controllers/Mode/TunController.cs index 80262d02..191bd31d 100644 --- a/Netch/Controllers/Mode/TunController.cs +++ b/Netch/Controllers/Mode/TunController.cs @@ -133,8 +133,12 @@ namespace Netch.Controllers.Mode public bool Create(Models.Server.Server s, Models.Mode.Mode m) { + Global.Logger.Info(String.Format("{0:x} tun2socks.bin", Utils.FileHelper.Checksum("Bin\\tun2socks.bin")); + if (!this.Outbound.Get()) { + Global.Logger.Error(String.Format("Failed to fetch outbound")); + return false; } diff --git a/Netch/Controllers/Mode/WinDivertController.cs b/Netch/Controllers/Mode/WinDivertController.cs index bd5d84d6..a7d8bfc1 100644 --- a/Netch/Controllers/Mode/WinDivertController.cs +++ b/Netch/Controllers/Mode/WinDivertController.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Netch.Controllers.Mode { diff --git a/Netch/Controllers/Other/DNS/AioDNSController.cs b/Netch/Controllers/Other/DNS/AioDNSController.cs index 3490723e..b5831226 100644 --- a/Netch/Controllers/Other/DNS/AioDNSController.cs +++ b/Netch/Controllers/Other/DNS/AioDNSController.cs @@ -1,4 +1,5 @@ -using System.Runtime.InteropServices; +using System; +using System.Runtime.InteropServices; namespace Netch.Controllers.Other.DNS { @@ -27,6 +28,8 @@ namespace Netch.Controllers.Other.DNS public bool Create(Models.Server.Server s, Models.Mode.Mode m) { + Global.Logger.Info(String.Format("{0:x} aiodns.bin", Utils.FileHelper.Checksum("Bin\\aiodns.bin"))); + Methods.aiodns_dial(NameList.TYPE_REST, ""); Methods.aiodns_dial(NameList.TYPE_ADDR, ":53"); Methods.aiodns_dial(NameList.TYPE_LIST, "Bin\\aiodns.conf"); diff --git a/Netch/Controllers/Other/DNS/CoreDNSController.cs b/Netch/Controllers/Other/DNS/CoreDNSController.cs index 4c7cff0f..403e450a 100644 --- a/Netch/Controllers/Other/DNS/CoreDNSController.cs +++ b/Netch/Controllers/Other/DNS/CoreDNSController.cs @@ -2,9 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Netch.Controllers.Other.DNS { diff --git a/Netch/Controllers/Other/DNS/DNSController.cs b/Netch/Controllers/Other/DNS/DNSController.cs index 21bce414..cb52ccc9 100644 --- a/Netch/Controllers/Other/DNS/DNSController.cs +++ b/Netch/Controllers/Other/DNS/DNSController.cs @@ -2,9 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Netch.Controllers.Other.DNS { diff --git a/Netch/Controllers/Other/DNS/UnboundController.cs b/Netch/Controllers/Other/DNS/UnboundController.cs index c86d5464..f378b4c4 100644 --- a/Netch/Controllers/Other/DNS/UnboundController.cs +++ b/Netch/Controllers/Other/DNS/UnboundController.cs @@ -2,9 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Netch.Controllers.Other.DNS { diff --git a/Netch/Controllers/Other/Web/PrivoxyController.cs b/Netch/Controllers/Other/Web/PrivoxyController.cs new file mode 100644 index 00000000..4c00e9be --- /dev/null +++ b/Netch/Controllers/Other/Web/PrivoxyController.cs @@ -0,0 +1,17 @@ +using System; + +namespace Netch.Controllers.Other.Web +{ + public class PrivoxyController : Interface.IController + { + public bool Create(Models.Server.Server s, Models.Mode.Mode m) + { + throw new NotImplementedException(); + } + + public bool Delete() + { + throw new NotImplementedException(); + } + } +} diff --git a/Netch/Controllers/Server/ClashController.cs b/Netch/Controllers/Server/ClashController.cs new file mode 100644 index 00000000..d2d71fec --- /dev/null +++ b/Netch/Controllers/Server/ClashController.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Netch.Controllers.Server +{ + public class ClashController : Interface.IController + { + public bool Create(Models.Server.Server s, Models.Mode.Mode m) + { + throw new NotImplementedException(); + } + + public bool Delete() + { + throw new NotImplementedException(); + } + } +} diff --git a/Netch/Controllers/Server/HTTPController.cs b/Netch/Controllers/Server/HTTPController.cs index 9cb46a09..02dadc06 100644 --- a/Netch/Controllers/Server/HTTPController.cs +++ b/Netch/Controllers/Server/HTTPController.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Netch.Controllers.Server { diff --git a/Netch/Global.cs b/Netch/Global.cs index 081e2ad6..8ecac567 100644 --- a/Netch/Global.cs +++ b/Netch/Global.cs @@ -14,7 +14,7 @@ namespace Netch /// /// 日志记录 /// - public static Tools.Logger Logger = new Tools.Logger() { SavePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs\\Netch.log") }; + public static Tools.Logger Logger = new() { SavePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs\\Netch.log") }; /// /// 配置文件 diff --git a/Netch/Models/Server/Clash/Clash.cs b/Netch/Models/Server/Clash/Clash.cs new file mode 100644 index 00000000..2bc05562 --- /dev/null +++ b/Netch/Models/Server/Clash/Clash.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Netch.Models.Server.Clash +{ + public class Clash : Server + { + public Clash() + { + this.Type = ServerType.Clash; + } + + /// + /// 自定义配置 + /// + [Newtonsoft.Json.JsonProperty("custom")] + public bool Custom = true; + + /// + /// 自定义配置文件路径 + /// + [Newtonsoft.Json.JsonProperty("filepath")] + public string FilePath; + + /// + /// 解析链接 + /// + /// 链接 + /// 是否成功 + public bool ParseLink(string link) + { + return false; + } + } +} diff --git a/Netch/Models/Server/ServerType.cs b/Netch/Models/Server/ServerType.cs index e5bfde2e..0ab552bb 100644 --- a/Netch/Models/Server/ServerType.cs +++ b/Netch/Models/Server/ServerType.cs @@ -2,6 +2,16 @@ { public enum ServerType : int { + /// + /// HTTP + /// + HTTP, + + /// + /// Clash + /// + Clash, + /// /// Socks5 /// diff --git a/Netch/Models/Server/Trojan/Trojan.cs b/Netch/Models/Server/Trojan/Trojan.cs index 16293a47..8f0f7b0a 100644 --- a/Netch/Models/Server/Trojan/Trojan.cs +++ b/Netch/Models/Server/Trojan/Trojan.cs @@ -10,27 +10,32 @@ /// /// 密码 /// - public string Passwd; + [Newtonsoft.Json.JsonProperty("password")] + public string Password; /// /// 伪装 SNI 标头 /// + [Newtonsoft.Json.JsonProperty("sni")] public string SNI; /// /// 复用会话 /// + [Newtonsoft.Json.JsonProperty("reuse")] public bool Reuse = true; /// /// Session Ticket /// + [Newtonsoft.Json.JsonProperty("ticket")] public bool Ticket = false; /// /// 不安全模式(跳过证书验证、跳过主机名验证) /// - public bool Insecure = true; + [Newtonsoft.Json.JsonProperty("insecure")] + public bool Insecure = false; /// /// 解析链接 diff --git a/Netch/Models/Server/VLess/VLess.cs b/Netch/Models/Server/VLess/VLess.cs index 3304e080..0673978d 100644 --- a/Netch/Models/Server/VLess/VLess.cs +++ b/Netch/Models/Server/VLess/VLess.cs @@ -10,11 +10,13 @@ /// /// 自定义配置 /// + [Newtonsoft.Json.JsonProperty("custom")] public bool Custom = true; /// /// 自定义配置文件路径 /// + [Newtonsoft.Json.JsonProperty("filepath")] public string FilePath; /// diff --git a/Netch/Models/Server/VMess/VMess.cs b/Netch/Models/Server/VMess/VMess.cs index bd5936ca..06f25c2e 100644 --- a/Netch/Models/Server/VMess/VMess.cs +++ b/Netch/Models/Server/VMess/VMess.cs @@ -10,11 +10,13 @@ /// /// 自定义配置 /// + [Newtonsoft.Json.JsonProperty("custom")] public bool Custom = true; /// /// 自定义配置文件路径 /// + [Newtonsoft.Json.JsonProperty("filepath")] public string FilePath; /// diff --git a/Other/.gitignore b/Other/.gitignore new file mode 100644 index 00000000..1db33ebd --- /dev/null +++ b/Other/.gitignore @@ -0,0 +1 @@ +/release diff --git a/Other/aiodns/README.md b/Other/aiodns/README.md deleted file mode 100644 index bc32d9df..00000000 --- a/Other/aiodns/README.md +++ /dev/null @@ -1 +0,0 @@ -# aiodns diff --git a/Other/aiodns/build.ps1 b/Other/aiodns/build.ps1 new file mode 100644 index 00000000..b24aecd5 --- /dev/null +++ b/Other/aiodns/build.ps1 @@ -0,0 +1,14 @@ +$exec=(Split-Path $MyInvocation.MyCommand.Path -Parent) +$last=(Get-Location).Path + +Set-Location $exec + +$Env:CGO_ENABLED="0" +$Env:GOROOT_FINAL="/usr" + +$Env:GOOS="windows" +$Env:GOARCH="amd64" +go build -a -trimpath -asmflags "-s -w" -ldflags "-s -w" -o "..\release\aiodns.exe" + +Set-Location $last +exit $lastExitCode diff --git a/Other/aiodns/deps.ps1 b/Other/aiodns/deps.ps1 new file mode 100644 index 00000000..800eeefb --- /dev/null +++ b/Other/aiodns/deps.ps1 @@ -0,0 +1,11 @@ +$exec=(Split-Path $MyInvocation.MyCommand.Path -Parent) +$last=(Get-Location).Path + +Set-Location $exec + +rm -Force go.* +go mod init aiodns +go mod tidy + +Set-Location $last +exit $lastExitCode diff --git a/Other/aiodns/go.mod b/Other/aiodns/go.mod index 7391149d..d17e1cc4 100644 --- a/Other/aiodns/go.mod +++ b/Other/aiodns/go.mod @@ -1,4 +1,4 @@ -module github.com/netchx/netch/other/aiodns +module aiodns go 1.16 diff --git a/Other/build.ps1 b/Other/build.ps1 new file mode 100644 index 00000000..494a7d74 --- /dev/null +++ b/Other/build.ps1 @@ -0,0 +1,17 @@ +Set-Location (Split-Path $MyInvocation.MyCommand.Path -Parent) + +.\clean.ps1 + +Get-ChildItem -Path . -Directory | ForEach-Object { + $name=$_.Name + + Write-Host "Building $name" + & ".\$name\build.ps1" + + if ( -Not $? ) { + Write-Host "Build $name failed" + exit $lastExitCode + } +} + +exit 0 diff --git a/Other/clean.ps1 b/Other/clean.ps1 new file mode 100644 index 00000000..7e41210a --- /dev/null +++ b/Other/clean.ps1 @@ -0,0 +1,7 @@ +Set-Location (Split-Path $MyInvocation.MyCommand.Path -Parent) + +if (Test-Path release) { + Remove-Item -Recurse -Force release +} + +exit 0 diff --git a/Other/deps.ps1 b/Other/deps.ps1 new file mode 100644 index 00000000..6421a8a8 --- /dev/null +++ b/Other/deps.ps1 @@ -0,0 +1,14 @@ +Set-Location (Split-Path $MyInvocation.MyCommand.Path -Parent) + +.\clean.ps1 + +Get-ChildItem -Path . -Directory | ForEach-Object { + $name=$_.Name + & ".\$name\deps.ps1" + + if (-Not $?) { + exit $lastExitCode + } +} + +exit 0 diff --git a/Other/tap2socks/build.ps1 b/Other/tap2socks/build.ps1 new file mode 100644 index 00000000..04077fa5 --- /dev/null +++ b/Other/tap2socks/build.ps1 @@ -0,0 +1,14 @@ +$exec=(Split-Path $MyInvocation.MyCommand.Path -Parent) +$last=(Get-Location).Path + +Set-Location $exec + +$Env:CGO_ENABLED="0" +$Env:GOROOT_FINAL="/usr" + +$Env:GOOS="windows" +$Env:GOARCH="amd64" +go build -a -trimpath -asmflags "-s -w" -ldflags "-s -w" -o "..\release\tap2socks.exe" + +Set-Location $last +exit $lastExitCode diff --git a/Other/tap2socks/deps.ps1 b/Other/tap2socks/deps.ps1 new file mode 100644 index 00000000..4063a6cb --- /dev/null +++ b/Other/tap2socks/deps.ps1 @@ -0,0 +1,11 @@ +$exec=(Split-Path $MyInvocation.MyCommand.Path -Parent) +$last=(Get-Location).Path + +Set-Location $exec + +rm -Force go.* +go mod init tap2socks +go mod tidy + +Set-Location $last +exit $lastExitCode diff --git a/Other/tap2socks/go.mod b/Other/tap2socks/go.mod new file mode 100644 index 00000000..675c669f --- /dev/null +++ b/Other/tap2socks/go.mod @@ -0,0 +1,3 @@ +module tap2socks + +go 1.16 diff --git a/Other/tap2socks/main.go b/Other/tap2socks/main.go new file mode 100644 index 00000000..fbdbe4a2 --- /dev/null +++ b/Other/tap2socks/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + +} diff --git a/Other/tun2socks/build.ps1 b/Other/tun2socks/build.ps1 new file mode 100644 index 00000000..157172aa --- /dev/null +++ b/Other/tun2socks/build.ps1 @@ -0,0 +1,14 @@ +$exec=(Split-Path $MyInvocation.MyCommand.Path -Parent) +$last=(Get-Location).Path + +Set-Location $exec + +$Env:CGO_ENABLED="0" +$Env:GOROOT_FINAL="/usr" + +$Env:GOOS="windows" +$Env:GOARCH="amd64" +go build -a -trimpath -asmflags "-s -w" -ldflags "-s -w" -o "..\release\tun2socks.exe" + +Set-Location $last +exit $lastExitCode diff --git a/Other/tun2socks/deps.ps1 b/Other/tun2socks/deps.ps1 new file mode 100644 index 00000000..a533d0b6 --- /dev/null +++ b/Other/tun2socks/deps.ps1 @@ -0,0 +1,11 @@ +$exec=(Split-Path $MyInvocation.MyCommand.Path -Parent) +$last=(Get-Location).Path + +Set-Location $exec + +rm -Force go.* +go mod init tun2socks +go mod tidy + +Set-Location $last +exit $lastExitCode diff --git a/Other/tun2socks/go.mod b/Other/tun2socks/go.mod new file mode 100644 index 00000000..966edfcd --- /dev/null +++ b/Other/tun2socks/go.mod @@ -0,0 +1,3 @@ +module tun2socks + +go 1.16 diff --git a/Other/tun2socks/main.go b/Other/tun2socks/main.go new file mode 100644 index 00000000..fbdbe4a2 --- /dev/null +++ b/Other/tun2socks/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + +} diff --git a/build.ps1 b/build.ps1 index 72ada54c..e888324a 100644 --- a/build.ps1 +++ b/build.ps1 @@ -22,8 +22,11 @@ param ( $PublishSingleFile = $True ) +.\Other\build.ps1 +if ( -Not $? ) { exit $lastExitCode } + .\scripts\download.ps1 $OutputPath -if ( -Not $? ) { exit 1 } +if ( -Not $? ) { exit $lastExitCode } Write-Host "Building $Configuration to $OutputPath" dotnet publish ` @@ -37,4 +40,4 @@ dotnet publish ` -o $OutputPath ` Netch\Netch.csproj -exit $lastExitCode \ No newline at end of file +exit $lastExitCode diff --git a/clean.ps1 b/clean.ps1 index 068b7399..be7e36e5 100644 --- a/clean.ps1 +++ b/clean.ps1 @@ -1,3 +1,5 @@ +Set-Location (Split-Path $MyInvocation.MyCommand.Path -Parent) + function Delete { param([string]$Path) @@ -12,4 +14,6 @@ Delete "Netch\obj" Delete "Tests\bin" Delete "Tests\obj" Delete "TestResults" -exit 0 + +.\Other\clean.ps1 +exit $lastExitCode diff --git a/scripts/download.ps1 b/scripts/download.ps1 index 91368654..733a6444 100644 --- a/scripts/download.ps1 +++ b/scripts/download.ps1 @@ -1,10 +1,10 @@ param([string]$OutputPath) -$NetchDataURL="https://github.com/NetchX/NetchData/archive/refs/heads/master.zip" -$NetchModeURL="https://github.com/NetchX/NetchMode/archive/refs/heads/master.zip" -$NetchI18NURL="https://github.com/NetchX/NetchI18N/archive/refs/heads/master.zip" +$NetchDataURL="https://github.com/netchx/netch-data/archive/refs/heads/main.zip" +$NetchModeURL="https://github.com/netchx/netch-mode/archive/refs/heads/main.zip" +$NetchI18NURL="https://github.com/netchx/netch-i18n/archive/refs/heads/main.zip" -$last=$(Get-Location) +$last=(Get-Location).Path New-Item -ItemType Directory -Name $OutputPath | Out-Null Set-Location $OutputPath @@ -16,24 +16,24 @@ Expand-Archive -Force -Path data.zip -DestinationPath . Expand-Archive -Force -Path mode.zip -DestinationPath . Expand-Archive -Force -Path i18n.zip -DestinationPath . -New-Item -ItemType Directory -Name bin | Out-Null -New-Item -ItemType Directory -Name mode | Out-Null -New-Item -ItemType Directory -Name i18n | Out-Null +New-Item -ItemType Directory -Name Bin | Out-Null +New-Item -ItemType Directory -Name Mode | Out-Null +New-Item -ItemType Directory -Name I18N | Out-Null -Copy-Item -Recurse -Force .\NetchData-master\* .\bin -Copy-Item -Recurse -Force .\NetchMode-master\mode\* .\mode -Copy-Item -Recurse -Force .\NetchI18N-master\i18n\* .\i18n +Copy-Item -Recurse -Force .\netch-data-main\* .\Bin +Copy-Item -Recurse -Force .\netch-mode-main\mode\* .\Mode +Copy-Item -Recurse -Force .\netch-i18n-main\i18n\* .\I18N -Remove-Item -Recurse -Force NetchData-master -Remove-Item -Recurse -Force NetchMode-master -Remove-Item -Recurse -Force NetchI18N-master +Remove-Item -Recurse -Force netch-data-main +Remove-Item -Recurse -Force netch-mode-main +Remove-Item -Recurse -Force netch-i18n-main Remove-Item -Force data.zip Remove-Item -Force mode.zip Remove-Item -Force i18n.zip -..\scripts\download\cloak.ps1 -OutputPath bin -..\scripts\download\xray-core.ps1 -OutputPath bin +..\scripts\download\cloak.ps1 -OutputPath Bin +..\scripts\download\xray-core.ps1 -OutputPath Bin Get-Item * Set-Location $last -exit 0 \ No newline at end of file +exit 0