1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-23 05:36:08 +03:00
ProxySU/ProxySuper.Core/Models/Projects/XraySettings.cs

161 lines
4.1 KiB
C#
Raw Normal View History

2021-06-17 13:54:07 +03:00
using Newtonsoft.Json;
2021-06-29 12:43:48 +03:00
using ProxySuper.Core.Services;
2021-06-17 13:54:07 +03:00
using System;
2021-05-13 04:58:45 +03:00
using System.Collections.Generic;
2021-07-12 12:58:51 +03:00
using System.Linq;
2021-07-13 06:05:10 +03:00
using System.Net;
2021-05-13 04:58:45 +03:00
2021-05-14 14:07:19 +03:00
namespace ProxySuper.Core.Models.Projects
2021-05-13 04:58:45 +03:00
{
public partial class XraySettings : IProjectSettings
{
2021-05-23 09:24:13 +03:00
public XraySettings()
{
2021-08-19 12:54:23 +03:00
WithTLS = true;
2021-05-23 09:24:13 +03:00
var guid = Guid.NewGuid().ToString();
Port = 443;
VLESS_KCP_Port = 2001;
VLESS_gRPC_Port = 2002;
VMESS_KCP_Port = 3001;
ShadowSocksPort = 4001;
UUID = guid;
Types = new List<XrayType>();
2021-06-29 12:43:48 +03:00
VLESS_WS_Path = "/" + Utils.RandomString(6);
2021-05-23 09:24:13 +03:00
VLESS_KCP_Type = "none";
VLESS_KCP_Seed = guid;
2021-06-29 12:43:48 +03:00
VLESS_gRPC_ServiceName = "/" + Utils.RandomString(7);
2021-05-23 09:24:13 +03:00
2021-06-29 12:43:48 +03:00
VMESS_WS_Path = "/" + Utils.RandomString(8);
VMESS_TCP_Path = "/" + Utils.RandomString(9);
2021-05-23 09:24:13 +03:00
VMESS_KCP_Seed = guid;
VMESS_KCP_Type = "none";
TrojanPassword = guid;
ShadowSocksPassword = guid;
ShadowSocksMethod = "aes-128-gcm";
}
2021-07-12 12:58:51 +03:00
[JsonIgnore]
2021-07-13 06:05:10 +03:00
public bool IsIPAddress
2021-07-12 12:58:51 +03:00
{
get
{
2021-07-13 06:05:10 +03:00
return IPAddress.TryParse(Domain, out _);
2021-07-12 12:58:51 +03:00
}
}
[JsonIgnore]
2021-05-20 13:32:17 +03:00
public List<int> FreePorts
2021-05-13 04:58:45 +03:00
{
get
{
2021-06-30 06:56:13 +03:00
var list = new List<int>();
2021-07-12 12:58:51 +03:00
list.Add(80);
2021-08-02 06:37:16 +03:00
list.Add(Port);
2021-07-12 12:58:51 +03:00
2021-06-30 06:56:13 +03:00
if (Types.Contains(XrayType.VLESS_KCP))
2021-05-13 04:58:45 +03:00
{
2021-06-30 06:56:13 +03:00
list.Add(VLESS_KCP_Port);
}
if (Types.Contains(XrayType.VMESS_KCP))
{
list.Add(VMESS_KCP_Port);
}
if (Types.Contains(XrayType.ShadowsocksAEAD))
{
list.Add(ShadowSocksPort);
}
if (Types.Contains(XrayType.VLESS_gRPC))
{
list.Add(VLESS_gRPC_Port);
}
2021-07-12 12:58:51 +03:00
return list.Distinct().ToList();
2021-05-13 04:58:45 +03:00
}
}
2021-05-20 13:32:17 +03:00
public ProjectType Type { get; set; } = ProjectType.Xray;
2021-05-14 14:07:19 +03:00
2021-08-19 12:54:23 +03:00
/// <summary>
/// 是否安装证书,
/// 上传自有证书时选False则不会自动安装证书。
/// </summary>
public bool WithTLS { get; set; }
2021-05-13 04:58:45 +03:00
/// <summary>
2021-05-16 04:12:47 +03:00
/// 端口
2021-05-13 04:58:45 +03:00
/// </summary>
2021-05-20 13:32:17 +03:00
public int Port { get; set; }
2021-05-13 04:58:45 +03:00
/// <summary>
2021-05-16 04:12:47 +03:00
/// 域名
2021-05-13 04:58:45 +03:00
/// </summary>
2021-05-20 13:32:17 +03:00
public string Domain { get; set; }
2021-05-13 04:58:45 +03:00
/// <summary>
2021-05-16 04:12:47 +03:00
/// UUID
2021-05-13 04:58:45 +03:00
/// </summary>
2021-05-16 04:12:47 +03:00
public string UUID { get; set; }
2021-05-13 04:58:45 +03:00
2021-06-30 13:36:27 +03:00
/// <summary>
/// 多用户
/// </summary>
public List<string> MulitUUID { get; set; } = new List<string>();
2021-05-13 04:58:45 +03:00
/// <summary>
/// 伪装域名
/// </summary>
public string MaskDomain { get; set; }
2021-06-17 13:54:07 +03:00
[JsonIgnore]
public string Email
{
get
{
if (!string.IsNullOrEmpty(Domain))
{
var arr = Domain.Split('.');
if (arr.Length == 3)
{
return $"{arr[0]}@{arr[1]}.{arr[2]}";
}
}
return $"{UUID.Substring(2, 6)}@gmail.com";
}
}
2021-05-13 04:58:45 +03:00
/// <summary>
/// 安装类型
/// </summary>
2021-05-16 04:12:47 +03:00
public List<XrayType> Types { get; set; } = new List<XrayType>();
2021-05-13 04:58:45 +03:00
/// <summary>
/// 根据xray类型获取路径
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public string GetPath(XrayType type)
{
switch (type)
{
case XrayType.VLESS_WS:
return VLESS_WS_Path;
case XrayType.VMESS_TCP:
return VMESS_TCP_Path;
case XrayType.VMESS_WS:
return VMESS_WS_Path;
default:
return string.Empty;
}
}
}
}