mirror of
https://github.com/netchx/netch.git
synced 2026-05-11 23:45:06 +08:00
[Netch] Updated
This commit is contained in:
@@ -21,31 +21,23 @@ namespace Netch.Controllers
|
||||
case Models.Server.ServerType.Socks:
|
||||
break;
|
||||
case Models.Server.ServerType.Shadowsocks:
|
||||
{
|
||||
if (m.Type == Models.Mode.ModeType.ProcessMode)
|
||||
{
|
||||
var node = s as Models.Server.Shadowsocks.Shadowsocks;
|
||||
if (String.IsNullOrEmpty(node.OBFS))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.NodeController = new Server.ShadowsocksController();
|
||||
}
|
||||
this.NodeController = new Server.ShadowsocksController();
|
||||
break;
|
||||
case Models.Server.ServerType.ShadowsocksR:
|
||||
this.NodeController = new Server.ShadowsocksRController();
|
||||
break;
|
||||
case Models.Server.ServerType.WireGuard:
|
||||
this.NodeController = new Server.WireGuardController();
|
||||
break;
|
||||
case Models.Server.ServerType.Trojan:
|
||||
this.NodeController = new Server.TrojanController();
|
||||
break;
|
||||
case Models.Server.ServerType.VLess:
|
||||
this.NodeController = new Server.VLessController();
|
||||
break;
|
||||
case Models.Server.ServerType.VMess:
|
||||
this.NodeController = new Server.VMessController();
|
||||
break;
|
||||
case Models.Server.ServerType.VLess:
|
||||
this.NodeController = new Server.VLessController();
|
||||
break;
|
||||
default:
|
||||
Global.Logger.Error($"未知的节点类型:{s.Type}");
|
||||
|
||||
@@ -63,23 +55,17 @@ namespace Netch.Controllers
|
||||
switch (m.Type)
|
||||
{
|
||||
case Models.Mode.ModeType.ProcessMode:
|
||||
this.ModeController = new Mode.RedirectorController();
|
||||
this.ModeController = new Mode.ProcessController();
|
||||
break;
|
||||
case Models.Mode.ModeType.ShareMode:
|
||||
this.ModeController = new Mode.ShareController();
|
||||
break;
|
||||
case Models.Mode.ModeType.TapMode:
|
||||
this.ModeController = new Mode.TapController();
|
||||
break;
|
||||
case Models.Mode.ModeType.TunMode:
|
||||
this.ModeController = new Mode.TunController();
|
||||
break;
|
||||
case Models.Mode.ModeType.WebMode:
|
||||
this.ModeController = new Mode.WebController();
|
||||
break;
|
||||
case Models.Mode.ModeType.WmpMode:
|
||||
this.ModeController = new Mode.WmpController();
|
||||
break;
|
||||
default:
|
||||
Global.Logger.Error($"未知的模式类型:{s.Type}");
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Netch.Controllers.Mode
|
||||
{
|
||||
public class LSPController : Interface.IController
|
||||
{
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
96
Netch/Controllers/Mode/ProcessController.cs
Normal file
96
Netch/Controllers/Mode/ProcessController.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Netch.Controllers.Mode
|
||||
{
|
||||
public class ProcessController : Interface.IController
|
||||
{
|
||||
private enum NameList : int
|
||||
{
|
||||
AIO_FILTERLOOPBACK,
|
||||
AIO_FILTERINTRANET,
|
||||
AIO_FILTERICMP,
|
||||
AIO_FILTERTCP,
|
||||
AIO_FILTERUDP,
|
||||
|
||||
AIO_TGTHOST,
|
||||
AIO_TGTPORT,
|
||||
AIO_TGTUSER,
|
||||
AIO_TGTPASS,
|
||||
|
||||
AIO_CLRNAME,
|
||||
AIO_ADDNAME,
|
||||
AIO_BYPNAME
|
||||
}
|
||||
|
||||
private static class Methods
|
||||
{
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aio_dial(NameList name, [MarshalAs(UnmanagedType.LPWStr)] string value);
|
||||
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aio_init();
|
||||
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void aio_free();
|
||||
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong aio_getUP();
|
||||
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong aio_getDL();
|
||||
}
|
||||
|
||||
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.AIO_FILTERLOOPBACK, mode.Loopback ? "true" : "false");
|
||||
Methods.aio_dial(NameList.AIO_FILTERINTRANET, mode.Intranet ? "true" : "false");
|
||||
Methods.aio_dial(NameList.AIO_FILTERTCP, mode.TCP ? "true" : "false");
|
||||
Methods.aio_dial(NameList.AIO_FILTERUDP, mode.UDP ? "true" : "false");
|
||||
|
||||
Methods.aio_dial(NameList.AIO_CLRNAME, "");
|
||||
Methods.aio_dial(NameList.AIO_BYPNAME, AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "\\\\"));
|
||||
for (int i = 0; i < mode.BypassList.Count; i++) if (!Methods.aio_dial(NameList.AIO_BYPNAME, mode.BypassList[i])) return false;
|
||||
for (int i = 0; i < mode.HandleList.Count; i++) if (!Methods.aio_dial(NameList.AIO_ADDNAME, mode.HandleList[i])) return false;
|
||||
|
||||
switch (s.Type)
|
||||
{
|
||||
case Models.Server.ServerType.Socks:
|
||||
{
|
||||
var node = s as Models.Server.Socks.Socks;
|
||||
Methods.aio_dial(NameList.AIO_TGTHOST, node.Resolve());
|
||||
Methods.aio_dial(NameList.AIO_TGTPORT, node.Port.ToString());
|
||||
|
||||
if (!String.IsNullOrEmpty(node.Username))
|
||||
{
|
||||
Methods.aio_dial(NameList.AIO_TGTUSER, node.Username);
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(node.Password))
|
||||
{
|
||||
Methods.aio_dial(NameList.AIO_TGTPASS, node.Password);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
Methods.aio_dial(NameList.AIO_TGTHOST, "127.0.0.1");
|
||||
Methods.aio_dial(NameList.AIO_TGTPORT, Global.Config.Ports.Socks.ToString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return Methods.aio_init();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
Methods.aio_free();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Netch.Controllers.Mode
|
||||
{
|
||||
public class RedirectorController : Interface.IController
|
||||
{
|
||||
private enum NameList : int
|
||||
{
|
||||
TYPE_FILTERLOOPBACK,
|
||||
TYPE_FILTERTCP,
|
||||
TYPE_FILTERUDP,
|
||||
TYPE_CLRNAME,
|
||||
TYPE_ADDNAME,
|
||||
TYPE_BYPNAME,
|
||||
TYPE_DNSHOST,
|
||||
TYPE_TCPLISN,
|
||||
TYPE_TCPTYPE,
|
||||
TYPE_TCPHOST,
|
||||
TYPE_TCPUSER,
|
||||
TYPE_TCPPASS,
|
||||
TYPE_TCPMETH,
|
||||
TYPE_TCPPROT,
|
||||
TYPE_TCPPRPA,
|
||||
TYPE_TCPOBFS,
|
||||
TYPE_TCPOBPA,
|
||||
TYPE_UDPLISN,
|
||||
TYPE_UDPTYPE,
|
||||
TYPE_UDPHOST,
|
||||
TYPE_UDPUSER,
|
||||
TYPE_UDPPASS,
|
||||
TYPE_UDPMETH,
|
||||
TYPE_UDPPROT,
|
||||
TYPE_UDPPRPA,
|
||||
TYPE_UDPOBFS,
|
||||
TYPE_UDPOBPA
|
||||
}
|
||||
|
||||
private static class Methods
|
||||
{
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aio_dial(NameList name, [MarshalAs(UnmanagedType.LPWStr)] string value);
|
||||
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aio_init();
|
||||
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aio_free();
|
||||
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong aio_getUP();
|
||||
|
||||
[DllImport("Redirector.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong aio_getDL();
|
||||
}
|
||||
|
||||
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");
|
||||
Methods.aio_dial(NameList.TYPE_FILTERUDP, mode.UDP ? "true" : "false");
|
||||
|
||||
Methods.aio_dial(NameList.TYPE_CLRNAME, "");
|
||||
Methods.aio_dial(NameList.TYPE_BYPNAME, AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "\\\\"));
|
||||
for (int i = 0; i < mode.HandleList.Count; i++) if (!Methods.aio_dial(NameList.TYPE_ADDNAME, mode.HandleList[i])) return false;
|
||||
for (int i = 0; i < mode.BypassList.Count; i++) if (!Methods.aio_dial(NameList.TYPE_BYPNAME, mode.BypassList[i])) return false;
|
||||
|
||||
Methods.aio_dial(NameList.TYPE_TCPLISN, Global.Config.Ports.Redir.ToString());
|
||||
Methods.aio_dial(NameList.TYPE_UDPLISN, Global.Config.Ports.Redir.ToString());
|
||||
|
||||
switch (s.Type)
|
||||
{
|
||||
case Models.Server.ServerType.Socks:
|
||||
{
|
||||
var node = s as Models.Server.Socks.Socks;
|
||||
Methods.aio_dial(NameList.TYPE_TCPTYPE, "Socks");
|
||||
Methods.aio_dial(NameList.TYPE_UDPTYPE, "Socks");
|
||||
Methods.aio_dial(NameList.TYPE_TCPHOST, $"{node.Resolve()}:{node.Port}");
|
||||
Methods.aio_dial(NameList.TYPE_UDPHOST, $"{node.Resolve()}:{node.Port}");
|
||||
|
||||
if (!String.IsNullOrEmpty(node.Username))
|
||||
{
|
||||
Methods.aio_dial(NameList.TYPE_TCPUSER, node.Username);
|
||||
Methods.aio_dial(NameList.TYPE_UDPUSER, node.Username);
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(node.Password))
|
||||
{
|
||||
Methods.aio_dial(NameList.TYPE_TCPPASS, node.Password);
|
||||
Methods.aio_dial(NameList.TYPE_UDPPASS, node.Password);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Models.Server.ServerType.Shadowsocks:
|
||||
{
|
||||
var node = s as Models.Server.Shadowsocks.Shadowsocks;
|
||||
if (String.IsNullOrEmpty(node.OBFS))
|
||||
{
|
||||
Methods.aio_dial(NameList.TYPE_TCPTYPE, "Shadowsocks");
|
||||
Methods.aio_dial(NameList.TYPE_UDPTYPE, "Shadowsocks");
|
||||
Methods.aio_dial(NameList.TYPE_TCPHOST, $"{node.Resolve()}:{node.Port}");
|
||||
Methods.aio_dial(NameList.TYPE_UDPHOST, $"{node.Resolve()}:{node.Port}");
|
||||
Methods.aio_dial(NameList.TYPE_TCPPASS, node.Passwd);
|
||||
Methods.aio_dial(NameList.TYPE_UDPPASS, node.Passwd);
|
||||
Methods.aio_dial(NameList.TYPE_TCPMETH, node.Method);
|
||||
Methods.aio_dial(NameList.TYPE_UDPMETH, node.Method);
|
||||
}
|
||||
else
|
||||
{
|
||||
Methods.aio_dial(NameList.TYPE_TCPTYPE, "Socks");
|
||||
Methods.aio_dial(NameList.TYPE_UDPTYPE, "Socks");
|
||||
Methods.aio_dial(NameList.TYPE_TCPHOST, $"127.0.0.1:{Global.Config.Ports.Socks}");
|
||||
Methods.aio_dial(NameList.TYPE_UDPHOST, $"127.0.0.1:{Global.Config.Ports.Socks}");
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
Methods.aio_dial(NameList.TYPE_TCPTYPE, "Socks");
|
||||
Methods.aio_dial(NameList.TYPE_UDPTYPE, "Socks");
|
||||
Methods.aio_dial(NameList.TYPE_TCPHOST, $"127.0.0.1:{Global.Config.Ports.Socks}");
|
||||
Methods.aio_dial(NameList.TYPE_UDPHOST, $"127.0.0.1:{Global.Config.Ports.Socks}");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return Methods.aio_init();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
return Methods.aio_free();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,239 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Management;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Netch.Controllers.Mode
|
||||
{
|
||||
public class TapController : Interface.IController
|
||||
{
|
||||
private enum NameList : int
|
||||
{
|
||||
TYPE_BYPBIND,
|
||||
TYPE_BYPLIST,
|
||||
TYPE_DNSADDR,
|
||||
TYPE_ADAPMTU,
|
||||
TYPE_TCPREST,
|
||||
TYPE_TCPTYPE,
|
||||
TYPE_TCPHOST,
|
||||
TYPE_TCPUSER,
|
||||
TYPE_TCPPASS,
|
||||
TYPE_TCPMETH,
|
||||
TYPE_TCPPROT,
|
||||
TYPE_TCPPRPA,
|
||||
TYPE_TCPOBFS,
|
||||
TYPE_TCPOBPA,
|
||||
TYPE_UDPREST,
|
||||
TYPE_UDPTYPE,
|
||||
TYPE_UDPHOST,
|
||||
TYPE_UDPUSER,
|
||||
TYPE_UDPPASS,
|
||||
TYPE_UDPMETH,
|
||||
TYPE_UDPPROT,
|
||||
TYPE_UDPPRPA,
|
||||
TYPE_UDPOBFS,
|
||||
TYPE_UDPOBPA
|
||||
}
|
||||
|
||||
private static class Methods
|
||||
{
|
||||
[DllImport("tap2socks.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool tap_dial(NameList name, string value);
|
||||
|
||||
[DllImport("tap2socks.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool tap_init();
|
||||
|
||||
[DllImport("tap2socks.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool tap_free();
|
||||
|
||||
[DllImport("tap2socks.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern string tap_name();
|
||||
|
||||
[DllImport("tap2socks.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong tap_getUP();
|
||||
|
||||
[DllImport("tap2socks.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong tap_getDL();
|
||||
}
|
||||
|
||||
private Tools.TunTap.Outbound Outbound = new();
|
||||
private Interface.IController DNSController;
|
||||
|
||||
private bool AssignInterface()
|
||||
{
|
||||
var index = Utils.RouteHelper.GetInterfaceIndexByDescription(Methods.tap_name());
|
||||
|
||||
var address = Global.Config.TunMode.Network.Split('/')[0];
|
||||
var netmask = byte.Parse(Global.Config.TunMode.Network.Split('/')[1]);
|
||||
if (!Utils.RouteHelper.CreateUnicastIP(AddressFamily.InterNetwork, address, netmask, index))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
NetworkInterface adapter = Utils.RouteHelper.GetInterfaceByIndex(index);
|
||||
if (adapter == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using (var wmi = new ManagementClass("Win32_NetworkAdapterConfiguration"))
|
||||
{
|
||||
using var ins = wmi.GetInstances();
|
||||
var ada = ins.Cast<ManagementObject>().First(m => m["Description"].ToString() == adapter.Description);
|
||||
|
||||
var dns = new[] { "127.0.0.1" };
|
||||
if (Global.Config.TunMode.DNS != "aiodns")
|
||||
{
|
||||
dns[0] = Global.Config.TunMode.DNS;
|
||||
}
|
||||
|
||||
using var ord = wmi.GetMethodParameters("SetDNSServerSearchOrder");
|
||||
ord["DNSServerSearchOrder"] = dns;
|
||||
|
||||
ada.InvokeMethod("SetDNSServerSearchOrder", ord, null);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool CreateServerRoute(Models.Server.Server s)
|
||||
{
|
||||
var addr = Utils.DNS.Fetch(s.Host);
|
||||
if (addr == IPAddress.Any)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (addr.AddressFamily == AddressFamily.InterNetworkV6)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return Utils.RouteHelper.CreateRoute(AddressFamily.InterNetwork, addr.ToString(), 32, this.Outbound.Gateway.ToString(), this.Outbound.Index);
|
||||
}
|
||||
|
||||
private bool CreateHandleRoute(Models.Mode.TunMode.TunMode mode)
|
||||
{
|
||||
var index = Utils.RouteHelper.GetInterfaceIndexByDescription(Methods.tap_name());
|
||||
|
||||
for (int i = 0; i < mode.HandleList.Count; i++)
|
||||
{
|
||||
var address = mode.HandleList[i].Split('/')[0];
|
||||
var netmask = byte.Parse(mode.HandleList[i].Split('/')[1]);
|
||||
|
||||
Utils.RouteHelper.CreateRoute(AddressFamily.InterNetwork, address, netmask, Global.Config.TunMode.Gateway, index);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Methods.tap_dial(NameList.TYPE_BYPBIND, this.Outbound.Address.ToString());
|
||||
|
||||
var mode = m as Models.Mode.TunMode.TunMode;
|
||||
if (mode.BypassList.Count > 0)
|
||||
{
|
||||
if (File.Exists("ipcidr.txt"))
|
||||
{
|
||||
File.Delete("ipcidr.txt");
|
||||
}
|
||||
File.WriteAllLines("ipcidr.txt", mode.BypassList);
|
||||
|
||||
Methods.tap_dial(NameList.TYPE_BYPLIST, "ipcidr.txt");
|
||||
}
|
||||
else
|
||||
{
|
||||
Methods.tap_dial(NameList.TYPE_BYPLIST, "disabled");
|
||||
}
|
||||
|
||||
Methods.tap_dial(NameList.TYPE_DNSADDR, (Global.Config.TunMode.DNS == "aiodns") ? "127.0.0.1" : Global.Config.TunMode.DNS);
|
||||
Methods.tap_dial(NameList.TYPE_TCPREST, "");
|
||||
Methods.tap_dial(NameList.TYPE_UDPREST, "");
|
||||
|
||||
switch (s.Type)
|
||||
{
|
||||
case Models.Server.ServerType.Socks:
|
||||
{
|
||||
var node = s as Models.Server.Socks.Socks;
|
||||
|
||||
Methods.tap_dial(NameList.TYPE_TCPTYPE, "Socks");
|
||||
Methods.tap_dial(NameList.TYPE_UDPTYPE, "Socks");
|
||||
Methods.tap_dial(NameList.TYPE_TCPHOST, $"{node.Resolve()}:{node.Port}");
|
||||
Methods.tap_dial(NameList.TYPE_UDPHOST, $"{node.Resolve()}:{node.Port}");
|
||||
|
||||
if (!String.IsNullOrEmpty(node.Username))
|
||||
{
|
||||
Methods.tap_dial(NameList.TYPE_TCPUSER, node.Username);
|
||||
Methods.tap_dial(NameList.TYPE_UDPUSER, node.Username);
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(node.Password))
|
||||
{
|
||||
Methods.tap_dial(NameList.TYPE_TCPPASS, node.Password);
|
||||
Methods.tap_dial(NameList.TYPE_UDPPASS, node.Password);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Methods.tap_dial(NameList.TYPE_TCPTYPE, "Socks");
|
||||
Methods.tap_dial(NameList.TYPE_TCPHOST, $"127.0.0.1:{Global.Config.Ports.Socks}");
|
||||
Methods.tap_dial(NameList.TYPE_UDPTYPE, "Socks");
|
||||
Methods.tap_dial(NameList.TYPE_UDPHOST, $"127.0.0.1:{Global.Config.Ports.Socks}");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!Methods.tap_init())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.DNSController = new Other.DNS.AioDNSController();
|
||||
if (!this.DNSController.Create(s, m))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.AssignInterface())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.CreateServerRoute(s))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.CreateHandleRoute(mode))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (File.Exists("ipcidr.txt"))
|
||||
{
|
||||
File.Delete("ipcidr.txt");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
this.DNSController?.Delete();
|
||||
|
||||
return Methods.tap_free();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ namespace Netch.Controllers.Mode
|
||||
|
||||
if (!this.Outbound.Get())
|
||||
{
|
||||
Global.Logger.Error(String.Format("Failed to fetch outbound"));
|
||||
Global.Logger.Error("Fetch outbound adapter failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -201,7 +201,15 @@ namespace Netch.Controllers.Mode
|
||||
return false;
|
||||
}
|
||||
|
||||
this.DNSController = new Other.DNS.AioDNSController();
|
||||
if (Global.Config.Generic.AioDNS)
|
||||
{
|
||||
this.DNSController = new Other.DNS.AioDNSController();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.DNSController = new Other.DNS.DNSProxyController();
|
||||
}
|
||||
|
||||
if (!this.DNSController.Create(s, m))
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Netch.Controllers.Mode
|
||||
{
|
||||
public class WinDivertController : Interface.IController
|
||||
{
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
namespace Netch.Controllers.Mode
|
||||
{
|
||||
public class WmpController : Interface.IController
|
||||
{
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,43 +2,49 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Netch.Controllers.Other.DNS
|
||||
{
|
||||
public class AioDNSController : Interface.IController
|
||||
{
|
||||
private Tools.Guard Guard = new()
|
||||
private enum NameList : int
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin\\aiodns.exe"),
|
||||
WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"),
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
WindowStyle = ProcessWindowStyle.Hidden
|
||||
},
|
||||
JudgmentStarted = new List<string>()
|
||||
{
|
||||
"Started"
|
||||
},
|
||||
JudgmentStopped = new List<string>()
|
||||
{
|
||||
"[aiodns][main]"
|
||||
},
|
||||
AutoRestart = true
|
||||
};
|
||||
TYPE_REST,
|
||||
TYPE_LIST,
|
||||
TYPE_LISN,
|
||||
TYPE_CDNS,
|
||||
TYPE_ODNS
|
||||
}
|
||||
|
||||
private static class Methods
|
||||
{
|
||||
[DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aiodns_dial(NameList name, string value);
|
||||
|
||||
[DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool aiodns_init();
|
||||
|
||||
[DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void aiodns_free();
|
||||
}
|
||||
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
Global.Logger.Info(String.Format("{0:x} aiodns.exe", Utils.FileHelper.Checksum("bin\\aiodns.exe")));
|
||||
Global.Logger.Info(String.Format("{0:x} aiodns.bin", Utils.FileHelper.Checksum("bin\\aiodns.bin")));
|
||||
|
||||
this.Guard.StartInfo.Arguments = String.Format("-c {} -l {} -cdns {} -odns {}", ".\\aiodns.conf", ":53", Global.Config.AioDNS.ChinaDNS, Global.Config.AioDNS.OtherDNS);
|
||||
return this.Guard.Create();
|
||||
Methods.aiodns_dial(NameList.TYPE_REST, "");
|
||||
Methods.aiodns_dial(NameList.TYPE_LIST, "chnsite.txt");
|
||||
Methods.aiodns_dial(NameList.TYPE_LISN, Global.Config.AioDNS.ListenPort.ToString());
|
||||
Methods.aiodns_dial(NameList.TYPE_CDNS, Global.Config.AioDNS.ChinaDNS);
|
||||
Methods.aiodns_dial(NameList.TYPE_ODNS, Global.Config.AioDNS.OtherDNS);
|
||||
|
||||
return Methods.aiodns_init();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
this.Guard.Delete();
|
||||
Methods.aiodns_free();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Netch.Controllers.Other.DNS
|
||||
{
|
||||
public class CoreDNSController : Interface.IController
|
||||
{
|
||||
private Tools.Guard Guard = new()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin\\CoreDNS.exe"),
|
||||
WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"),
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
WindowStyle = ProcessWindowStyle.Hidden
|
||||
},
|
||||
JudgmentStarted = new List<string>()
|
||||
{
|
||||
},
|
||||
JudgmentStopped = new List<string>()
|
||||
{
|
||||
},
|
||||
AutoRestart = true
|
||||
};
|
||||
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using System.IO;
|
||||
|
||||
namespace Netch.Controllers.Other.DNS
|
||||
{
|
||||
public class DNSController : Interface.IController
|
||||
public class DNSProxyController : Interface.IController
|
||||
{
|
||||
private Tools.Guard Guard = new()
|
||||
{
|
||||
@@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Netch.Controllers.Other.DNS
|
||||
{
|
||||
public class UnboundController : Interface.IController
|
||||
{
|
||||
private Tools.Guard Guard = new()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin\\Unbound.exe"),
|
||||
WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"),
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
WindowStyle = ProcessWindowStyle.Hidden
|
||||
},
|
||||
JudgmentStarted = new List<string>()
|
||||
{
|
||||
},
|
||||
JudgmentStopped = new List<string>()
|
||||
{
|
||||
},
|
||||
AutoRestart = true
|
||||
};
|
||||
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Netch.Controllers.Server
|
||||
{
|
||||
public class HTTPController : Interface.IController
|
||||
public class WireGuardController : Interface.IController
|
||||
{
|
||||
public bool Create(Models.Server.Server s, Models.Mode.Mode m)
|
||||
{
|
||||
Reference in New Issue
Block a user