mirror of
https://github.com/snltty/linker.git
synced 2025-12-20 10:26:45 +08:00
提交
This commit is contained in:
48
README.md
48
README.md
@@ -34,11 +34,11 @@
|
||||
|
||||
## 功能
|
||||
###### 系统
|
||||
- [x] 桌面捕获,捕获鼠标,**screen**
|
||||
- [x] 桌面捕获,捕获鼠标,**plugins.screen**
|
||||
- [x] 登录界面捕获和登录页面键盘输入
|
||||
- [x] 双指画面缩放
|
||||
- [ ] 区域热更新
|
||||
- [x] 功能禁用,禁用各种系统功能 **system**
|
||||
- [x] 功能禁用,禁用各种系统功能 ***plugins.system**
|
||||
- 任务栏锁定,任务栏设置,任务栏菜单
|
||||
- 任务管理器
|
||||
- 注册表编辑,组策略编辑
|
||||
@@ -49,36 +49,34 @@
|
||||
- 关机按钮,注销按钮,锁定按钮,修改密码,切换用户
|
||||
- 安全SAS
|
||||
- 禁用U盘
|
||||
- [x] 系统信息,展示CPU,内存利用率,硬盘使用率,发呆时间 **system**
|
||||
- [x] 音量控制,音量和静音 **volume**
|
||||
- [x] 音频峰值,展示音频峰值,是否在播放音视频,及激昂程度 **volume**
|
||||
- [x] 系统亮度,暂不支持外界显示器 **light**
|
||||
- [x] 模拟键盘,键盘操作,模拟ctrl+alt+delete,模拟win+l,等等 **keyboard**
|
||||
- [ ] 模拟鼠标,鼠标操作 **volume**
|
||||
- [x] 系统信息,展示CPU,内存利用率,硬盘使用率,发呆时间 ***plugins.system**
|
||||
- [x] 音量控制,音量和静音 ***plugins.volume**
|
||||
- [x] 音频峰值,展示音频峰值,是否在播放音视频,及激昂程度 ***plugins.volume**
|
||||
- [x] 系统亮度,暂不支持外界显示器 ***plugins.light**
|
||||
- [x] 模拟键盘,键盘操作,模拟ctrl+alt+delete,模拟win+l,等等 ***plugins.keyboard**
|
||||
- [ ] 模拟鼠标,鼠标操作 ***plugins.keyboard**
|
||||
###### 程序
|
||||
- [x] 程序限制,分为禁止打开程序,和自定检测关闭程序 **active**
|
||||
- [x] 前景窗口,当前焦点程序捕获,手动关闭之 **active**
|
||||
- [x] 时间统计,查看程序使用时间记录 **active**
|
||||
- [x] 程序限制,分为禁止打开程序,和自定检测关闭程序 ***plugins.active**
|
||||
- [x] 前景窗口,当前焦点程序捕获,手动关闭之 ***plugins.active**
|
||||
- [x] 时间统计,查看程序使用时间记录 ***plugins.active**
|
||||
###### 网络
|
||||
- [x] 网络限制,程序,域名,IP 黑白名单 **hijack**
|
||||
- [x] 网速显示,由网络限制组件提供 **hijack**
|
||||
- [x] 自动连接wifi **wlan**
|
||||
- [x] 网络限制,程序,域名,IP 黑白名单 ***plugins.hijack**
|
||||
- [x] 网速显示,由网络限制组件提供 ***plugins.hijack**
|
||||
- [x] 自动连接wifi ***plugins.wlan**
|
||||
###### 消息
|
||||
- [x] 消息提醒,向设备发送消息提醒 **message**
|
||||
- [x] 全局广播,向所有设备发送广播 **notify**
|
||||
- [x] 语音消息,向设备发送语音消息 **message**
|
||||
- [x] 消息提醒,向设备发送消息提醒 ***plugins.message**
|
||||
- [x] 全局广播,向所有设备发送广播 ***plugins.notify**
|
||||
- [x] 语音消息,向设备发送语音消息 ***plugins.message**
|
||||
###### 命令
|
||||
- [x] 发送命令,执行cmd命令,等等 **command**
|
||||
- [x] 发送命令,执行cmd命令,等等 ***plugins.command**
|
||||
###### 互动
|
||||
- [x] 互动答题 **snatch**
|
||||
- [x] 屏幕共享,以某一设备为主机,向其它设备共享屏幕,用于演示 **viewer**第一次成功连接服务端后自动恢复**
|
||||
- [x] 互动答题 ***plugins.snatch**
|
||||
- [x] 屏幕共享,以某一设备为主机,向其它设备共享屏幕,用于演示 **plugins.viewer**
|
||||
###### 壁纸
|
||||
- [x] 壁纸程序,为所有设备设置统一壁纸,以程序的方式 **wallpaper**
|
||||
- [x] 键盘按键,显示键盘按键(当前键盘按键由壁纸程序提供) **wallpaper**
|
||||
- [x] 壁纸程序,为所有设备设置统一壁纸,以程序的方式 ***plugins.wallpaper**
|
||||
- [x] 键盘按键,显示键盘按键(当前键盘按键由壁纸程序提供) ***plugins.wallpaper**
|
||||
###### 锁屏
|
||||
- [x] 锁屏程序,打开锁屏程序,禁用键盘 **llock**
|
||||
###### 其它
|
||||
- [x] 设备用户,显示当前使用设备用户姓名 **devices**
|
||||
- [x] 锁屏程序,打开锁屏程序,禁用键盘 ***plugins.llock**
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -135,6 +135,7 @@ export default {
|
||||
|
||||
const windows = globalData.value.usernames[globalData.value.username].Windows || [];
|
||||
const group = windows.filter(c => c.Name == state.group)[0];
|
||||
if(!group) return;
|
||||
const items = group.List;
|
||||
const names = items.map(c => c.Name);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using cmonitor.client.args;
|
||||
using cmonitor.config;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.server;
|
||||
using common.libs;
|
||||
using common.libs.extends;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using common.libs;
|
||||
using common.libs.extends;
|
||||
using System.Net;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace cmonitor.config
|
||||
@@ -51,7 +50,7 @@ namespace cmonitor.config
|
||||
{
|
||||
slim.Release();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Save()
|
||||
@@ -74,7 +73,7 @@ namespace cmonitor.config
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public sealed partial class ConfigInfo
|
||||
@@ -96,7 +95,17 @@ namespace cmonitor.config
|
||||
{
|
||||
get => plugins; set
|
||||
{
|
||||
PluginNames = value.Select(c => $"plugins.{c}.").ToArray();
|
||||
plugins = value;
|
||||
|
||||
if (value.Length > 0)
|
||||
{
|
||||
PluginNames = value.ToList().Concat(new List<string>
|
||||
{
|
||||
"client","server","api","web","plugins.signin",
|
||||
"plugins.watch","plugins.devices","plugins.report",
|
||||
"plugins.share","plugins.rule","plugins.modes",
|
||||
}).Select(c => $".{c}.").ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
[JsonIgnore]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.plugins.active.messenger;
|
||||
using cmonitor.plugins.active.report;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.server;
|
||||
using cmonitor.server.ruleConfig;
|
||||
using common.libs;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.plugins.command.messenger;
|
||||
using cmonitor.plugins.command.report;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.server;
|
||||
using common.libs.extends;
|
||||
using MemoryPack;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.plugins.display.messenger;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.server;
|
||||
using common.libs.extends;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.plugins.hijack.messenger;
|
||||
using cmonitor.plugins.hijack.report;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.server;
|
||||
using cmonitor.server.ruleConfig;
|
||||
using common.libs.extends;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.plugins.keyboard.messenger;
|
||||
using cmonitor.plugins.keyboard.report;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.server;
|
||||
using common.libs.extends;
|
||||
using MemoryPack;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.plugins.light.messenger;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.server;
|
||||
using common.libs.extends;
|
||||
using MemoryPack;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.plugins.llock.messenger;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.server;
|
||||
using common.libs.extends;
|
||||
using MemoryPack;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.plugins.notify.messenger;
|
||||
using cmonitor.plugins.notify.report;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.server;
|
||||
using common.libs.extends;
|
||||
using MemoryPack;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using cmonitor.client.report;
|
||||
using cmonitor.config;
|
||||
using cmonitor.plugins.report.messenger;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.server;
|
||||
using common.libs;
|
||||
using common.libs.extends;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using cmonitor.config;
|
||||
using cmonitor.plugins.screen.messenger;
|
||||
using cmonitor.plugins.screen.report;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.server;
|
||||
using common.libs.extends;
|
||||
using MemoryPack;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.config;
|
||||
using cmonitor.plugins.screen.report;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.server;
|
||||
using MemoryPack;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.plugins.share.messenger;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.server;
|
||||
using common.libs.extends;
|
||||
using MemoryPack;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.config;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
|
||||
namespace cmonitor.plugins.signIn
|
||||
namespace cmonitor.plugins.signin
|
||||
{
|
||||
public sealed class SignInApiController : IApiController
|
||||
{
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using cmonitor.config;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.startup;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Reflection;
|
||||
|
||||
namespace cmonitor.plugins.signIn
|
||||
namespace cmonitor.plugins.signin
|
||||
{
|
||||
public sealed class SignInStartup : IStartup
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Collections.Concurrent;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace cmonitor.plugins.signIn.messenger
|
||||
namespace cmonitor.plugins.signin.messenger
|
||||
{
|
||||
public sealed class SignCaching
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ using cmonitor.server;
|
||||
using common.libs;
|
||||
using MemoryPack;
|
||||
|
||||
namespace cmonitor.plugins.signIn.messenger
|
||||
namespace cmonitor.plugins.signin.messenger
|
||||
{
|
||||
public sealed class SignInMessenger : IMessenger
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace cmonitor.plugins.signIn.messenger
|
||||
namespace cmonitor.plugins.signin.messenger
|
||||
{
|
||||
public enum SignInMessengerIds : ushort
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.plugins.snatch.messenger;
|
||||
using cmonitor.plugins.snatch.report;
|
||||
using cmonitor.server;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.plugins.snatch.report;
|
||||
using cmonitor.server;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.plugins.system.messenger;
|
||||
using cmonitor.plugins.system.report;
|
||||
using cmonitor.server;
|
||||
|
||||
38
cmonitor/plugins/tunnel/TunnelStartup.cs
Normal file
38
cmonitor/plugins/tunnel/TunnelStartup.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using cmonitor.config;
|
||||
using cmonitor.plugins.tunnel.compact;
|
||||
using cmonitor.plugins.tunnel.server;
|
||||
using cmonitor.startup;
|
||||
using common.libs;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Reflection;
|
||||
|
||||
namespace cmonitor.plugins.tunnel
|
||||
{
|
||||
public sealed class TunnelStartup : IStartup
|
||||
{
|
||||
public void AddClient(ServiceCollection serviceCollection, Config config, Assembly[] assemblies)
|
||||
{
|
||||
serviceCollection.AddSingleton<CompactTransfer>();
|
||||
serviceCollection.AddSingleton<CompactSelfHost>();
|
||||
}
|
||||
|
||||
public void AddServer(ServiceCollection serviceCollection, Config config, Assembly[] assemblies)
|
||||
{
|
||||
serviceCollection.AddSingleton<TunnelServer>();
|
||||
}
|
||||
|
||||
public void UseClient(ServiceProvider serviceProvider, Config config, Assembly[] assemblies)
|
||||
{
|
||||
CompactTransfer transfer = serviceProvider.GetService<CompactTransfer>();
|
||||
transfer.Load(assemblies);
|
||||
}
|
||||
|
||||
public void UseServer(ServiceProvider serviceProvider, Config config, Assembly[] assemblies)
|
||||
{
|
||||
Logger.Instance.Info($"use tunnel server in server mode.");
|
||||
TunnelServer tunnelServer = serviceProvider.GetService<TunnelServer>();
|
||||
tunnelServer.Start(config.Data.Server.Tunnel.ListenPort);
|
||||
Logger.Instance.Info($"start tunnel server, port : {config.Data.Server.Tunnel.ListenPort}");
|
||||
}
|
||||
}
|
||||
}
|
||||
63
cmonitor/plugins/tunnel/compact/CompactSelfHost.cs
Normal file
63
cmonitor/plugins/tunnel/compact/CompactSelfHost.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using common.libs.extends;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace cmonitor.plugins.tunnel.compact
|
||||
{
|
||||
public sealed class CompactSelfHost : ICompact
|
||||
{
|
||||
public string Type => "self";
|
||||
|
||||
public async Task<CompactIPEndPoint> GetTcpExternalIPAsync(IPEndPoint server)
|
||||
{
|
||||
Socket socket = new Socket(server.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||
socket.Reuse(true);
|
||||
socket.IPv6Only(server.AddressFamily, false);
|
||||
await socket.ConnectAsync(server).WaitAsync(TimeSpan.FromSeconds(5));
|
||||
|
||||
byte[] bytes = new byte[20];
|
||||
int length = await socket.ReceiveAsync(bytes.AsMemory(), SocketFlags.None);
|
||||
if (length == 0) return null;
|
||||
|
||||
return new CompactIPEndPoint { Local = socket.LocalEndPoint as IPEndPoint, Remote = ReadData(bytes) };
|
||||
}
|
||||
|
||||
public async Task<CompactIPEndPoint> GetUdpExternalIPAsync(IPEndPoint server)
|
||||
{
|
||||
|
||||
using UdpClient udpClient = new UdpClient();
|
||||
udpClient.Client.Reuse(true);
|
||||
await udpClient.SendAsync(new byte[1] { 0 }, server);
|
||||
var result = await udpClient.ReceiveAsync().WaitAsync(TimeSpan.FromSeconds(5));
|
||||
if (result.Buffer.Length == 0) return null;
|
||||
|
||||
return new CompactIPEndPoint { Local = udpClient.Client.LocalEndPoint as IPEndPoint, Remote = ReadData(result.Buffer) };
|
||||
}
|
||||
|
||||
private IPEndPoint ReadData(byte[] bytes)
|
||||
{
|
||||
int index = 0;
|
||||
AddressFamily family = (AddressFamily)bytes[index];
|
||||
index++;
|
||||
|
||||
int ipLength = family switch
|
||||
{
|
||||
AddressFamily.InterNetwork => 4,
|
||||
AddressFamily.InterNetworkV6 => 16,
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
if (ipLength > 0)
|
||||
{
|
||||
IPAddress ip = new IPAddress(bytes.AsSpan(0, ipLength));
|
||||
index += ipLength;
|
||||
|
||||
ushort port = bytes.AsSpan(index).ToUInt16();
|
||||
IPEndPoint iPEndPoint = new IPEndPoint(ip, port);
|
||||
return iPEndPoint;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
67
cmonitor/plugins/tunnel/compact/CompactTransfer.cs
Normal file
67
cmonitor/plugins/tunnel/compact/CompactTransfer.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using cmonitor.config;
|
||||
using common.libs;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Reflection;
|
||||
|
||||
namespace cmonitor.plugins.tunnel.compact
|
||||
{
|
||||
public sealed class CompactTransfer
|
||||
{
|
||||
private List<ICompact> compacts;
|
||||
|
||||
private readonly Config config;
|
||||
private readonly ServiceProvider serviceProvider;
|
||||
public CompactTransfer(Config config, ServiceProvider serviceProvider)
|
||||
{
|
||||
this.config = config;
|
||||
this.serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public void Load(Assembly[] assembs)
|
||||
{
|
||||
IEnumerable<Type> types = ReflectionHelper.GetInterfaceSchieves(assembs, typeof(ICompact));
|
||||
if (config.Data.Common.PluginNames.Length > 0)
|
||||
{
|
||||
types = types.Where(c => config.Data.Common.PluginNames.Any(d => c.FullName.Contains(d)));
|
||||
}
|
||||
compacts = types.Select(c => (ICompact)serviceProvider.GetService(c)).Where(c => c != null).Where(c => string.IsNullOrWhiteSpace(c.Type) == false).ToList();
|
||||
|
||||
Logger.Instance.Warning($"load tunnel compacts:{string.Join(",", compacts.Select(c => c.Type))}");
|
||||
}
|
||||
|
||||
public async Task<CompactIPEndPoint[]> GetExternalIPAsync(ProtocolType protocolType)
|
||||
{
|
||||
CompactIPEndPoint[] endpoints = new CompactIPEndPoint[config.Data.Client.Tunnel.Servers.Length];
|
||||
|
||||
for (int i = 0; i < config.Data.Client.Tunnel.Servers.Length; i++)
|
||||
{
|
||||
TunnelCompactInfo item = config.Data.Client.Tunnel.Servers[i];
|
||||
ICompact compact = compacts.FirstOrDefault(c => c.Type == item.Type);
|
||||
if (compact == null) continue;
|
||||
|
||||
try
|
||||
{
|
||||
IPEndPoint server = NetworkHelper.GetEndPoint(item.Host, 3478);
|
||||
if (protocolType == ProtocolType.Tcp)
|
||||
{
|
||||
CompactIPEndPoint externalIP = await compact.GetTcpExternalIPAsync(server);
|
||||
endpoints[i] = externalIP;
|
||||
}
|
||||
else if (protocolType == ProtocolType.Udp)
|
||||
{
|
||||
CompactIPEndPoint externalIP = await compact.GetUdpExternalIPAsync(server);
|
||||
endpoints[i] = externalIP;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Instance.Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
return endpoints.Where(c => c != null && c.Remote != null).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
17
cmonitor/plugins/tunnel/compact/ICompact.cs
Normal file
17
cmonitor/plugins/tunnel/compact/ICompact.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Net;
|
||||
|
||||
namespace cmonitor.plugins.tunnel.compact
|
||||
{
|
||||
public interface ICompact
|
||||
{
|
||||
public string Type { get; }
|
||||
public Task<CompactIPEndPoint> GetTcpExternalIPAsync(IPEndPoint server);
|
||||
public Task<CompactIPEndPoint> GetUdpExternalIPAsync(IPEndPoint server);
|
||||
}
|
||||
|
||||
public sealed class CompactIPEndPoint
|
||||
{
|
||||
public IPEndPoint Local { get; set; }
|
||||
public IPEndPoint Remote { get; set; }
|
||||
}
|
||||
}
|
||||
30
cmonitor/plugins/tunnel/config/Config.cs
Normal file
30
cmonitor/plugins/tunnel/config/Config.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
namespace cmonitor.config
|
||||
{
|
||||
public partial class ConfigClientInfo
|
||||
{
|
||||
public TunnelConfigClientInfo Tunnel { get; set; } = new TunnelConfigClientInfo();
|
||||
}
|
||||
public partial class ConfigServerInfo
|
||||
{
|
||||
public TunnelConfigServerInfo Tunnel { get; set; } = new TunnelConfigServerInfo();
|
||||
}
|
||||
|
||||
public sealed class TunnelConfigClientInfo
|
||||
{
|
||||
public TunnelCompactInfo[] Servers { get; set; } = new TunnelCompactInfo[]
|
||||
{
|
||||
new TunnelCompactInfo { Type="self", Host="127.0.0.1:1804" }
|
||||
};
|
||||
}
|
||||
|
||||
public sealed class TunnelConfigServerInfo
|
||||
{
|
||||
public int ListenPort { get; set; } = 1804;
|
||||
}
|
||||
|
||||
public sealed class TunnelCompactInfo
|
||||
{
|
||||
public string Type { get; set; }
|
||||
public string Host { get; set; }
|
||||
}
|
||||
}
|
||||
12
cmonitor/plugins/tunnel/messenger/TunnelMessenger.cs
Normal file
12
cmonitor/plugins/tunnel/messenger/TunnelMessenger.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using cmonitor.server;
|
||||
|
||||
namespace cmonitor.plugins.tunnel.messenger
|
||||
{
|
||||
public sealed class TunnelMessenger : IMessenger
|
||||
{
|
||||
public TunnelMessenger()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
9
cmonitor/plugins/tunnel/messenger/TunnelMessengerIds.cs
Normal file
9
cmonitor/plugins/tunnel/messenger/TunnelMessengerIds.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace cmonitor.plugins.tunnel.messenger
|
||||
{
|
||||
public enum TunnelMessengerIds : ushort
|
||||
{
|
||||
Update = 2000,
|
||||
|
||||
None = 2001
|
||||
}
|
||||
}
|
||||
165
cmonitor/plugins/tunnel/server/TunnelServer.cs
Normal file
165
cmonitor/plugins/tunnel/server/TunnelServer.cs
Normal file
@@ -0,0 +1,165 @@
|
||||
using common.libs;
|
||||
using common.libs.extends;
|
||||
using System.Buffers;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace cmonitor.plugins.tunnel.server
|
||||
{
|
||||
public sealed class TunnelServer
|
||||
{
|
||||
private SocketAsyncEventArgs acceptEventArg;
|
||||
private Socket socket;
|
||||
private UdpClient socketUdp;
|
||||
|
||||
public void Start(int port)
|
||||
{
|
||||
try
|
||||
{
|
||||
Stop();
|
||||
|
||||
IPEndPoint localEndPoint = new IPEndPoint(NetworkHelper.IPv6Support ? IPAddress.IPv6Any : IPAddress.Any, port);
|
||||
socket = new Socket(localEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||
socket.IPv6Only(localEndPoint.AddressFamily, false);
|
||||
socket.ReuseBind(localEndPoint);
|
||||
socket.Listen(int.MaxValue);
|
||||
|
||||
acceptEventArg = new SocketAsyncEventArgs
|
||||
{
|
||||
UserToken = new AsyncUserToken
|
||||
{
|
||||
SourceSocket = socket
|
||||
},
|
||||
SocketFlags = SocketFlags.None,
|
||||
};
|
||||
|
||||
acceptEventArg.Completed += IO_Completed;
|
||||
StartAccept(acceptEventArg);
|
||||
|
||||
|
||||
socketUdp = new UdpClient(new IPEndPoint(IPAddress.Any, port));
|
||||
socketUdp.Client.EnableBroadcast = true;
|
||||
socketUdp.Client.WindowsUdpBug();
|
||||
IAsyncResult result = socketUdp.BeginReceive(ReceiveCallbackUdp, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Instance.Error(ex);
|
||||
}
|
||||
}
|
||||
private void StartAccept(SocketAsyncEventArgs acceptEventArg)
|
||||
{
|
||||
acceptEventArg.AcceptSocket = null;
|
||||
AsyncUserToken token = (AsyncUserToken)acceptEventArg.UserToken;
|
||||
try
|
||||
{
|
||||
if (token.SourceSocket.AcceptAsync(acceptEventArg) == false)
|
||||
{
|
||||
ProcessAccept(acceptEventArg);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
token.Clear();
|
||||
}
|
||||
}
|
||||
private void IO_Completed(object sender, SocketAsyncEventArgs e)
|
||||
{
|
||||
switch (e.LastOperation)
|
||||
{
|
||||
case SocketAsyncOperation.Accept:
|
||||
ProcessAccept(e);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void ProcessAccept(SocketAsyncEventArgs e)
|
||||
{
|
||||
if (e.AcceptSocket != null)
|
||||
{
|
||||
WriteExternalIP(e);
|
||||
StartAccept(e);
|
||||
}
|
||||
}
|
||||
private async void WriteExternalIP(SocketAsyncEventArgs e)
|
||||
{
|
||||
AsyncUserToken token = e.UserToken as AsyncUserToken;
|
||||
if (token.SourceSocket != null)
|
||||
{
|
||||
IPEndPoint ep = token.SourceSocket.RemoteEndPoint as IPEndPoint;
|
||||
|
||||
byte[] bytes = ArrayPool<byte>.Shared.Rent(20);
|
||||
|
||||
int index = 0;
|
||||
bytes[index] = (byte)ep.Address.AddressFamily;
|
||||
index++;
|
||||
ep.Address.TryWriteBytes(bytes.AsSpan(index), out int bytesWritten);
|
||||
index += bytesWritten;
|
||||
((ushort)ep.Port).ToBytes(bytes.AsMemory(index));
|
||||
index += 2;
|
||||
|
||||
await token.SourceSocket.SendAsync(bytes.AsMemory(0, index));
|
||||
|
||||
ArrayPool<byte>.Shared.Return(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
private async void ReceiveCallbackUdp(IAsyncResult result)
|
||||
{
|
||||
try
|
||||
{
|
||||
IPEndPoint ep = new IPEndPoint(IPAddress.Any, IPEndPoint.MinPort);
|
||||
byte[] _ = socketUdp.EndReceive(result, ref ep);
|
||||
|
||||
|
||||
byte[] bytes = ArrayPool<byte>.Shared.Rent(20);
|
||||
|
||||
int index = 0;
|
||||
bytes[index] = (byte)ep.Address.AddressFamily;
|
||||
index++;
|
||||
ep.Address.TryWriteBytes(bytes.AsSpan(index), out int bytesWritten);
|
||||
index += bytesWritten;
|
||||
((ushort)ep.Port).ToBytes(bytes.AsMemory(index));
|
||||
index += 2;
|
||||
|
||||
await socketUdp.SendAsync(bytes.AsMemory(0, index), ep);
|
||||
|
||||
ArrayPool<byte>.Shared.Return(bytes);
|
||||
|
||||
result = socketUdp.BeginReceive(ReceiveCallbackUdp, null);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseClientSocket(SocketAsyncEventArgs e)
|
||||
{
|
||||
if (e == null) return;
|
||||
AsyncUserToken token = e.UserToken as AsyncUserToken;
|
||||
if (token.SourceSocket != null)
|
||||
{
|
||||
token.Clear();
|
||||
e.Dispose();
|
||||
}
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
CloseClientSocket(acceptEventArg);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AsyncUserToken
|
||||
{
|
||||
public Socket SourceSocket { get; set; }
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
SourceSocket?.SafeClose();
|
||||
SourceSocket = null;
|
||||
|
||||
GC.Collect();
|
||||
}
|
||||
}
|
||||
}
|
||||
10
cmonitor/plugins/tunnel/transport/ITransport.cs
Normal file
10
cmonitor/plugins/tunnel/transport/ITransport.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace cmonitor.plugins.tunnel.transport
|
||||
{
|
||||
public interface ITransport
|
||||
{
|
||||
public Task<Socket> ConnectAsync(IPEndPoint local, IPEndPoint remote);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.plugins.viewer.messenger;
|
||||
using cmonitor.plugins.viewer.proxy;
|
||||
using cmonitor.plugins.viewer.report;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using cmonitor.client;
|
||||
using cmonitor.client.running;
|
||||
using cmonitor.config;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.plugins.viewer.proxy;
|
||||
using cmonitor.plugins.viewer.report;
|
||||
using cmonitor.server;
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace cmonitor.plugins.viewer.proxy
|
||||
private NumberSpaceUInt32 ns = new NumberSpaceUInt32();
|
||||
private SocketAsyncEventArgs acceptEventArg;
|
||||
|
||||
Socket socket;
|
||||
private Socket socket;
|
||||
|
||||
public IPEndPoint LocalEndpoint => socket?.LocalEndPoint as IPEndPoint ?? new IPEndPoint(IPAddress.Any, 0);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.server;
|
||||
using common.libs.extends;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
@@ -3,6 +3,7 @@ using cmonitor.client.running;
|
||||
using cmonitor.config;
|
||||
using cmonitor.plugins.viewer.messenger;
|
||||
using cmonitor.server;
|
||||
using common.libs;
|
||||
using MemoryPack;
|
||||
|
||||
namespace cmonitor.plugins.viewer.proxy
|
||||
@@ -22,6 +23,7 @@ namespace cmonitor.plugins.viewer.proxy
|
||||
this.runningConfig = runningConfig;
|
||||
|
||||
Start(0);
|
||||
Logger.Instance.Info($"start viewer proxy, port : {LocalEndpoint.Port}");
|
||||
}
|
||||
|
||||
public override async Task Connect(string name, uint connectId)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using cmonitor.config;
|
||||
using cmonitor.plugins.viewer.messenger;
|
||||
using cmonitor.server;
|
||||
using common.libs;
|
||||
using MemoryPack;
|
||||
|
||||
namespace cmonitor.plugins.viewer.proxy
|
||||
@@ -16,7 +17,7 @@ namespace cmonitor.plugins.viewer.proxy
|
||||
this.viewerProxyCaching = viewerProxyCaching;
|
||||
|
||||
Start(config.Data.Server.Viewer.ProxyPort);
|
||||
|
||||
Logger.Instance.Info($"start viewer proxy, port : {LocalEndpoint.Port}");
|
||||
}
|
||||
|
||||
public override async Task Connect(string name, uint connectId)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.plugins.volume.messenger;
|
||||
using cmonitor.server;
|
||||
using common.libs.extends;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.plugins.wallpaper.messenger;
|
||||
using cmonitor.plugins.wallpaper.report;
|
||||
using cmonitor.server;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using cmonitor.api;
|
||||
using cmonitor.plugins.signIn.messenger;
|
||||
using cmonitor.plugins.signin.messenger;
|
||||
using cmonitor.plugins.wlan.messenger;
|
||||
using cmonitor.plugins.wlan.report;
|
||||
using cmonitor.server;
|
||||
|
||||
@@ -33,6 +33,19 @@ namespace common.libs
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IPEndPoint GetEndPoint(string host, int defaultPort)
|
||||
{
|
||||
string[] hostArr = host.Split(':');
|
||||
int port = defaultPort;
|
||||
if (hostArr.Length == 2)
|
||||
{
|
||||
port = int.Parse(hostArr[1]);
|
||||
}
|
||||
IPAddress ip = GetDomainIp(hostArr[0]);
|
||||
|
||||
return new IPEndPoint(ip, port);
|
||||
}
|
||||
|
||||
|
||||
#if DISABLE_IPV6 || (!UNITY_EDITOR && ENABLE_IL2CPP && !UNITY_2018_3_OR_NEWER)
|
||||
public static bool IPv6Support = false;
|
||||
|
||||
Reference in New Issue
Block a user