1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-29 00:26:09 +03:00
ProxySU/ProxySU_Core/ViewModels/XraySettingsViewModel.cs

400 lines
10 KiB
C#
Raw Normal View History

2021-03-16 12:22:00 +03:00
using Newtonsoft.Json;
using ProxySU_Core.Common;
using ProxySU_Core.Models;
2021-03-04 11:25:36 +03:00
using System;
using System.Collections.Generic;
2021-03-26 13:13:32 +03:00
using System.Collections.ObjectModel;
2021-03-04 11:25:36 +03:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2021-03-15 12:58:20 +03:00
using System.Web;
2021-03-04 11:25:36 +03:00
using System.Windows;
2021-03-26 13:13:32 +03:00
using System.Windows.Controls;
2021-04-17 06:50:31 +03:00
using System.Windows.Input;
2021-03-04 11:25:36 +03:00
namespace ProxySU_Core.ViewModels
{
2021-03-26 13:13:32 +03:00
public partial class XraySettingsViewModel : BaseViewModel
2021-03-04 11:25:36 +03:00
{
2021-03-04 13:25:52 +03:00
public XraySettings settings;
2021-04-17 06:50:31 +03:00
private readonly ICommand _randomUuid;
2021-03-04 11:25:36 +03:00
public XraySettingsViewModel(XraySettings parameters)
{
2021-04-17 06:50:31 +03:00
_randomUuid = new BaseCommand((obj) => GetUuid());
2021-03-04 13:25:52 +03:00
this.settings = parameters;
2021-03-26 13:13:32 +03:00
Notify("VMESS_KCP_Type");
2021-03-04 11:25:36 +03:00
}
2021-04-17 06:50:31 +03:00
public ICommand RandomUuid
{
get
{
return _randomUuid;
}
}
2021-04-05 05:22:43 +03:00
public int Port
{
get => settings.Port;
set
{
settings.Port = value;
Notify("Port");
}
}
2021-04-17 06:50:31 +03:00
public int VLESS_KCP_Port
2021-04-05 05:22:43 +03:00
{
2021-04-17 06:50:31 +03:00
get => settings.VLESS_KCP_Port;
2021-04-05 05:22:43 +03:00
set
{
2021-04-17 06:50:31 +03:00
settings.VLESS_KCP_Port = value;
Notify("VLESS_KCP_Port");
}
}
public int VMESS_KCP_Port
{
get => settings.VMESS_KCP_Port;
set
{
settings.VMESS_KCP_Port = value;
Notify("VMESS_KCP_Port");
2021-04-05 05:22:43 +03:00
}
}
public int ShadowSocksPort
{
get => settings.ShadowSocksPort;
set
{
2021-04-17 06:50:31 +03:00
settings.VMESS_KCP_Port = value;
2021-04-05 05:22:43 +03:00
Notify("ShadowSocksPort");
}
}
2021-03-04 11:25:36 +03:00
public string UUID
{
2021-03-04 13:25:52 +03:00
get => settings.UUID;
2021-03-26 06:28:41 +03:00
set
{
settings.UUID = value;
Notify("UUID");
}
2021-03-04 11:25:36 +03:00
}
public string Domain
{
2021-03-04 13:25:52 +03:00
get => settings.Domain;
2021-04-18 13:11:35 +03:00
set
{
settings.Domain = value;
Notify("Domain");
}
2021-03-04 11:25:36 +03:00
}
public string MaskDomain
{
2021-03-04 13:25:52 +03:00
get => settings.MaskDomain;
2021-04-18 13:11:35 +03:00
set
{
settings.MaskDomain = value;
Notify("MaskDomain");
}
2021-03-04 11:25:36 +03:00
}
public string TrojanPassword
{
2021-03-04 13:25:52 +03:00
get => settings.TrojanPassword;
set => settings.TrojanPassword = value;
2021-03-04 11:25:36 +03:00
}
2021-03-26 13:13:32 +03:00
public bool Checked_Trojan_TCP
2021-03-04 11:25:36 +03:00
{
get
{
2021-03-26 13:13:32 +03:00
return settings.Types.Contains(XrayType.Trojan_TCP);
2021-03-04 11:25:36 +03:00
}
set
{
if (value == true)
{
2021-03-26 13:13:32 +03:00
if (!settings.Types.Contains(XrayType.Trojan_TCP))
settings.Types.Add(XrayType.Trojan_TCP);
2021-03-04 11:25:36 +03:00
}
else
{
2021-03-26 13:13:32 +03:00
settings.Types.Remove(XrayType.Trojan_TCP);
2021-03-04 11:25:36 +03:00
}
2021-03-26 13:13:32 +03:00
Notify("Checked_Trojan_TCP");
2021-03-04 11:25:36 +03:00
}
}
2021-03-26 13:13:32 +03:00
public string Trojan_TCP_ShareLink
{
get => ShareLink.Build(XrayType.Trojan_TCP, settings);
}
2021-03-04 11:25:36 +03:00
2021-03-26 13:13:32 +03:00
private List<string> _ssMethods = new List<string> { "aes-256-gcm", "aes-128-gcm", "chacha20-poly1305", "chacha20-ietf-poly1305" };
public List<string> ShadowSocksMethods => _ssMethods;
public bool CheckedShadowSocks
2021-03-04 11:25:36 +03:00
{
2021-03-26 13:13:32 +03:00
get => settings.Types.Contains(XrayType.ShadowsocksAEAD);
2021-03-04 11:25:36 +03:00
set
{
2021-03-26 13:13:32 +03:00
CheckBoxChanged(value, XrayType.ShadowsocksAEAD);
Notify("CheckedShadowSocks");
2021-03-04 11:25:36 +03:00
}
}
2021-03-26 13:13:32 +03:00
public string ShadowSocksPassword
2021-03-04 11:25:36 +03:00
{
2021-03-26 13:13:32 +03:00
get => settings.ShadowsocksPassword;
set => settings.ShadowsocksPassword = value;
}
public string ShadowSocksMethod
{
get => settings.ShadowsocksMethod;
2021-03-04 11:25:36 +03:00
set
{
2021-03-26 13:13:32 +03:00
var namespaceStr = typeof(ComboBoxItem).FullName + ":";
var trimValue = value.Replace(namespaceStr, "");
trimValue = trimValue.Trim();
settings.ShadowsocksMethod = trimValue;
Notify("ShadowSocksMethod");
2021-03-04 11:25:36 +03:00
}
}
2021-03-26 13:13:32 +03:00
public string ShadowSocksShareLink
{
get => ShareLink.Build(XrayType.ShadowsocksAEAD, settings);
}
2021-03-04 11:25:36 +03:00
2021-03-26 13:13:32 +03:00
private void CheckBoxChanged(bool value, XrayType type)
2021-03-18 10:17:07 +03:00
{
2021-03-26 13:13:32 +03:00
if (value == true)
2021-03-18 10:17:07 +03:00
{
2021-03-26 13:13:32 +03:00
if (!settings.Types.Contains(type))
2021-03-18 10:17:07 +03:00
{
2021-03-26 13:13:32 +03:00
settings.Types.Add(type);
2021-03-18 10:17:07 +03:00
}
2021-03-26 13:13:32 +03:00
}
else
{
settings.Types.RemoveAll(x => x == type);
2021-03-18 10:17:07 +03:00
}
}
2021-04-17 06:50:31 +03:00
private void GetUuid()
{
UUID = Guid.NewGuid().ToString();
Notify("UUID");
}
2021-03-26 13:13:32 +03:00
}
2021-04-17 15:58:15 +03:00
/// <summary>
/// VMESS
/// </summary>
2021-03-26 13:13:32 +03:00
public partial class XraySettingsViewModel
{
// vmess tcp
2021-03-04 11:25:36 +03:00
public bool Checked_VMESS_TCP
{
2021-03-26 13:13:32 +03:00
get => settings.Types.Contains(XrayType.VMESS_TCP);
2021-03-04 11:25:36 +03:00
set
{
2021-03-26 13:13:32 +03:00
CheckBoxChanged(value, XrayType.VMESS_TCP);
2021-03-04 11:25:36 +03:00
Notify("Checked_VMESS_TCP");
}
}
2021-03-26 13:13:32 +03:00
public string VMESS_TCP_Path
2021-03-04 11:25:36 +03:00
{
2021-03-26 13:13:32 +03:00
get => settings.VMESS_TCP_Path;
set => settings.VMESS_TCP_Path = value;
2021-03-04 11:25:36 +03:00
}
2021-03-26 13:13:32 +03:00
public string VMESS_TCP_ShareLink
2021-03-18 10:17:07 +03:00
{
2021-03-26 13:13:32 +03:00
get => ShareLink.Build(XrayType.VMESS_TCP, settings);
2021-03-18 10:17:07 +03:00
}
2021-03-26 13:13:32 +03:00
// vmess ws
public bool Checked_VMESS_WS
2021-03-04 11:25:36 +03:00
{
2021-03-26 13:13:32 +03:00
get => settings.Types.Contains(XrayType.VMESS_WS);
2021-03-04 11:25:36 +03:00
set
{
2021-03-26 13:13:32 +03:00
CheckBoxChanged(value, XrayType.VMESS_WS);
Notify("Checked_VMESS_WS");
2021-03-04 11:25:36 +03:00
}
}
2021-03-26 13:13:32 +03:00
public string VMESS_WS_Path
2021-03-04 11:25:36 +03:00
{
2021-03-26 13:13:32 +03:00
get => settings.VMESS_WS_Path;
set => settings.VMESS_WS_Path = value;
2021-03-04 11:25:36 +03:00
}
2021-03-27 06:47:02 +03:00
public string VMESS_WS_ShareLink
2021-03-04 11:25:36 +03:00
{
2021-03-26 13:13:32 +03:00
get => ShareLink.Build(XrayType.VMESS_WS, settings);
2021-03-04 11:25:36 +03:00
}
2021-04-05 05:22:43 +03:00
2021-03-26 13:13:32 +03:00
// vmess kcp
public string VMESS_KCP_Seed
2021-03-18 10:17:07 +03:00
{
2021-03-26 13:13:32 +03:00
get => settings.VMESS_KCP_Seed;
set => settings.VMESS_KCP_Seed = value;
2021-03-18 10:17:07 +03:00
}
2021-03-26 13:13:32 +03:00
public string VMESS_KCP_Type
2021-03-04 11:25:36 +03:00
{
2021-03-26 13:13:32 +03:00
get => settings.VMESS_KCP_Type;
set
2021-03-04 11:25:36 +03:00
{
2021-03-26 13:13:32 +03:00
var namespaceStr = typeof(ComboBoxItem).FullName + ":";
var trimValue = value.Replace(namespaceStr, "");
trimValue = trimValue.Trim();
settings.VMESS_KCP_Type = trimValue;
Notify("VMESS_KCP_Type");
2021-03-04 11:25:36 +03:00
}
}
2021-03-26 13:13:32 +03:00
public bool Checked_VMESS_KCP
2021-03-04 11:25:36 +03:00
{
2021-03-26 13:13:32 +03:00
get => settings.Types.Contains(XrayType.VMESS_KCP);
set
2021-03-04 11:25:36 +03:00
{
2021-03-26 13:13:32 +03:00
CheckBoxChanged(value, XrayType.VMESS_KCP);
Notify("Checked_VMESS_KCP");
2021-03-04 11:25:36 +03:00
}
}
2021-03-26 13:13:32 +03:00
public string VMESS_KCP_ShareLink
2021-03-18 10:17:07 +03:00
{
2021-03-26 13:13:32 +03:00
get => ShareLink.Build(XrayType.VMESS_KCP, settings);
2021-03-18 10:17:07 +03:00
}
2021-03-26 13:13:32 +03:00
private List<string> _kcpTypes = new List<string> { "none", "srtp", "utp", "wechat-video", "dtls", "wireguard", };
public List<string> KcpTypes => _kcpTypes;
}
2021-04-17 15:58:15 +03:00
/// <summary>
/// VLESS
/// </summary>
2021-03-26 13:13:32 +03:00
public partial class XraySettingsViewModel
{
// vless xtls
public bool Checked_VLESS_TCP_XTLS
2021-03-04 11:25:36 +03:00
{
2021-03-26 13:13:32 +03:00
get => settings.Types.Contains(XrayType.VLESS_TCP_XTLS);
set
2021-03-04 11:25:36 +03:00
{
2021-03-26 13:13:32 +03:00
CheckBoxChanged(value, XrayType.VLESS_TCP_XTLS);
2021-04-18 13:11:35 +03:00
Notify("Checked_VLESS_TCP_XTLS");
2021-03-04 11:25:36 +03:00
}
}
2021-03-15 12:58:20 +03:00
public string VLESS_TCP_XTLS_ShareLink
{
2021-03-17 06:58:56 +03:00
get => ShareLink.Build(XrayType.VLESS_TCP_XTLS, settings);
2021-03-15 12:58:20 +03:00
}
2021-03-26 13:13:32 +03:00
// vless tcp
public bool Checked_VLESS_TCP
2021-03-18 10:17:07 +03:00
{
2021-03-26 13:13:32 +03:00
get => settings.Types.Contains(XrayType.VLESS_TCP);
set
{
CheckBoxChanged(value, XrayType.VLESS_TCP);
Notify("Checked_VLESS_TCP");
}
2021-03-18 10:17:07 +03:00
}
2021-03-26 13:13:32 +03:00
public string VLESS_TCP_ShareLink
2021-03-15 12:58:20 +03:00
{
2021-03-26 13:13:32 +03:00
get => ShareLink.Build(XrayType.VLESS_TCP, settings);
2021-03-15 12:58:20 +03:00
}
2021-03-26 13:13:32 +03:00
// vless ws
public string VLESS_WS_Path
2021-03-15 12:58:20 +03:00
{
2021-03-26 13:13:32 +03:00
get => settings.VLESS_WS_Path;
set => settings.VLESS_WS_Path = value;
2021-03-15 12:58:20 +03:00
}
2021-03-26 13:13:32 +03:00
public bool Checked_VLESS_WS
2021-03-18 10:17:07 +03:00
{
2021-03-26 13:13:32 +03:00
get
{
return settings.Types.Contains(XrayType.VLESS_WS);
}
set
{
CheckBoxChanged(value, XrayType.VLESS_WS);
Notify("Checked_VLESS_WS");
}
2021-03-18 10:17:07 +03:00
}
2021-03-26 13:13:32 +03:00
public string VLESS_WS_ShareLink
2021-03-15 12:58:20 +03:00
{
2021-03-26 13:13:32 +03:00
get => ShareLink.Build(XrayType.VLESS_WS, settings);
2021-03-15 12:58:20 +03:00
}
2021-04-17 06:50:31 +03:00
// vless kcp
public string VLESS_KCP_Seed
{
get => settings.VLESS_KCP_Seed;
set => settings.VLESS_KCP_Seed = value;
}
public string VLESS_KCP_Type
{
get => settings.VLESS_KCP_Type;
set
{
var namespaceStr = typeof(ComboBoxItem).FullName + ":";
var trimValue = value.Replace(namespaceStr, "");
trimValue = trimValue.Trim();
settings.VLESS_KCP_Type = trimValue;
Notify("VLESS_KCP_Type");
}
}
public bool Checked_VLESS_KCP
{
2021-04-17 15:58:15 +03:00
get => settings.Types.Contains(XrayType.VLESS_KCP);
2021-04-17 06:50:31 +03:00
set
{
2021-04-17 15:58:15 +03:00
CheckBoxChanged(value, XrayType.VLESS_KCP);
2021-04-17 06:50:31 +03:00
Notify("Checked_VLESS_KCP");
}
}
public string VLESS_KCP_ShareLink
{
get => ShareLink.Build(XrayType.VLESS_KCP, settings);
}
2021-04-17 15:58:15 +03:00
// vless grpc
public string VLESS_gRPC_ServiceName
{
get => settings.VLESS_gRPC_ServiceName;
set => settings.VLESS_gRPC_ServiceName = value;
}
public int VLESS_gRPC_Port
{
get => settings.VLESS_gRPC_Port;
set => settings.VLESS_gRPC_Port = value;
}
public bool Checked_VLESS_gRPC
{
get => settings.Types.Contains(XrayType.VLESS_gRPC);
set
{
CheckBoxChanged(value, XrayType.VLESS_gRPC);
Notify("Checked_VLESS_gRPC");
}
}
public string VLESS_gRPC_ShareLink
{
get => ShareLink.Build(XrayType.VLESS_gRPC, settings);
}
2021-03-04 11:25:36 +03:00
}
2021-03-16 12:22:00 +03:00
2021-03-04 11:25:36 +03:00
}