feat: VLESS support

This commit is contained in:
ChsBuffer
2020-10-12 21:44:58 +08:00
parent 477c6e3fc1
commit 3f1b21c4e5
4 changed files with 181 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
using System.Collections.Generic;
using Netch.Models;
using Netch.Servers.VMess;
namespace Netch.Servers.VLESS
{
public class VLESS : VMess.VMess
{
public VLESS()
{
Type = "VLESS";
}
/// <summary>
/// 加密方式
/// </summary>
public new string EncryptMethod { get; set; } = "none";
/// <summary>
/// 传输协议
/// </summary>
public new string TransferProtocol { get; set; } = VLESSGlobal.TransferProtocols[0];
/// <summary>
/// 伪装类型
/// </summary>
public new string FakeType { get; set; } = VLESSGlobal.FakeTypes[0];
/// <summary>
///
/// </summary>
public string Flow { get; set; }
}
public class VLESSGlobal
{
public static List<string> TransferProtocols => VMessGlobal.TransferProtocols;
public static readonly List<string> FakeTypes = new List<string>
{
"none",
"http"
};
}
}

View File

@@ -0,0 +1,36 @@
using System.IO;
using Netch.Controllers;
using Netch.Models;
namespace Netch.Servers.VLESS
{
public class VLESSController : Guard, IServerController
{
public override string Name { get; protected set; } = "VLESS";
public override string MainFile { get; protected set; } = "v2ray.exe";
public int? Socks5LocalPort { get; set; }
public string LocalAddress { get; set; }
public bool Start(Server s, Mode mode)
{
var server = (VLESS) s;
File.WriteAllText("data\\last.json", VMess.Utils.V2rayConfigUtils.GenerateClientConfig(server, mode));
if (StartInstanceAuto("-config ..\\data\\last.json"))
{
if (File.Exists("data\\last.json")) File.Delete("data\\last.json");
return true;
}
return false;
}
public override void Stop()
{
StopInstance();
}
}
}

View File

@@ -0,0 +1,46 @@
using Netch.Forms;
namespace Netch.Servers.VLESS.VLESSForm
{
class VLESSForm : ServerForm
{
protected override string TypeName { get; } = "VLESS";
public VLESSForm(VLESS server = default)
{
server ??= new VLESS();
Server = server;
CreateTextBox("UUID", "UUID",
s => true,
s => server.UserID = s,
server.UserID);
CreateTextBox("EncryptMethod", "Encrypt Method",
s => true,
s => server.EncryptMethod = !string.IsNullOrWhiteSpace(s) ? s : "none",
server.EncryptMethod);
CreateTextBox("Flow", "Flow",
s => true,
s => server.Flow = s,
server.Flow);
CreateComboBox("TransferProtocol", "Transfer Protocol",
VLESSGlobal.TransferProtocols,
s => server.TransferProtocol = s,
server.TransferProtocol);
CreateComboBox("FakeType", "Fake Type",
VLESSGlobal.FakeTypes,
s => server.FakeType = s,
server.FakeType);
CreateTextBox("Host", "Host",
s => true,
s => server.Host = s,
server.Host);
CreateTextBox("Path", "Path",
s => true,
s => server.Path = s,
server.Path);
CreateCheckBox("TLSSecure", "TLS Secure",
b => server.TLSSecure = b,
server.TLSSecure);
}
}
}

View File

@@ -0,0 +1,53 @@
using System.Collections.Generic;
using Netch.Controllers;
using Netch.Models;
using Newtonsoft.Json.Linq;
namespace Netch.Servers.VLESS
{
public class VLESSUtil : IServerUtil
{
public ushort Priority { get; } = 2;
public string TypeName { get; } = "VLESS";
public string FullName { get; } = "VLESS";
public string ShortName { get; } = "VL";
public string[] UriScheme { get; } = { };
public Server ParseJObject(JObject j)
{
return j.ToObject<VLESS>();
}
public void Edit(Server s)
{
new VLESSForm.VLESSForm((VLESS) s).ShowDialog();
}
public void Create()
{
new VLESSForm.VLESSForm().ShowDialog();
}
public string GetShareLink(Server server)
{
// TODO
return "";
}
public IServerController GetController()
{
return new VLESSController();
}
public IEnumerable<Server> ParseUri(string text)
{
throw new System.NotImplementedException();
}
public bool CheckServer(Server s)
{
// TODO
return true;
}
}
}