1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-22 21:26:09 +03:00
ProxySU/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs

610 lines
17 KiB
C#
Raw Normal View History

2021-07-08 13:37:32 +03:00
using MvvmCross.Commands;
2021-05-16 04:12:47 +03:00
using MvvmCross.Navigation;
2021-05-15 11:45:36 +03:00
using MvvmCross.ViewModels;
2021-05-14 14:07:19 +03:00
using ProxySuper.Core.Models;
using ProxySuper.Core.Models.Hosts;
using ProxySuper.Core.Models.Projects;
2021-05-15 11:45:36 +03:00
using ProxySuper.Core.Services;
2021-05-14 14:07:19 +03:00
using System;
using System.Collections.Generic;
using System.Linq;
2021-05-15 11:45:36 +03:00
using System.Windows.Controls;
2021-05-14 14:07:19 +03:00
namespace ProxySuper.Core.ViewModels
{
2021-05-16 04:12:47 +03:00
public partial class XrayEditorViewModel : MvxViewModel<Record, Record>
2021-05-14 14:07:19 +03:00
{
2021-05-16 11:29:37 +03:00
public XrayEditorViewModel(IMvxNavigationService navigationService)
2021-05-15 11:45:36 +03:00
{
2021-05-16 11:29:37 +03:00
NavigationService = navigationService;
2021-05-15 11:45:36 +03:00
}
2021-05-16 04:12:47 +03:00
public string Id { get; set; }
2021-05-14 14:07:19 +03:00
public Host Host { get; set; }
public XraySettings Settings { get; set; }
2021-08-18 12:34:32 +03:00
public IMvxCommand SaveCommand => new MvxCommand(Save);
public IMvxCommand SaveAndInstallCommand => new MvxCommand(SaveAndInstall);
2021-05-16 11:29:37 +03:00
public IMvxNavigationService NavigationService { get; }
2021-05-16 04:12:47 +03:00
2021-05-14 14:07:19 +03:00
public override void Prepare(Record parameter)
{
2021-05-16 04:12:47 +03:00
var record = Utils.DeepClone(parameter);
Id = record.Id;
Host = record.Host;
Settings = record.XraySettings;
}
public void Save()
{
2021-05-16 11:29:37 +03:00
NavigationService.Close(this, new Record()
2021-05-16 04:12:47 +03:00
{
Id = Id,
Host = Host,
XraySettings = Settings,
2021-05-16 11:29:37 +03:00
});
2021-05-15 11:45:36 +03:00
}
2021-08-18 12:34:32 +03:00
public void SaveAndInstall()
{
var record = new Record()
{
Id = Id,
Host = Host,
XraySettings = Settings,
};
NavigationService.Close(this, record);
NavigationService.Navigate<XrayInstallViewModel, Record>(record);
}
2021-05-15 11:45:36 +03:00
}
public partial class XrayEditorViewModel
{
2022-11-23 17:06:09 +03:00
public List<string> UTLSList { get => XraySettings.UTLSList; }
public List<string> KcpTypes => V2raySettings.DisguiseTypes;
public List<string> QuicTypes => V2raySettings.DisguiseTypes;
public List<string> QuicSecurities => new List<string>
{
"none",
"aes-128-gcm",
"chacha20-poly1305"
};
public List<string> ShadowSocksMethods => new List<string>
{
"2022-blake3-aes-128-gcm",
"2022-blake3-aes-256-gcm",
"2022-blake3-chacha20-poly1305",
"aes-256-gcm",
"aes-128-gcm",
"chacha20-poly1305",
"none"
};
2021-05-16 11:29:37 +03:00
public IMvxCommand RandomUuid => new MvxCommand(() => GetUuid());
2021-05-15 11:45:36 +03:00
2021-08-19 12:54:23 +03:00
public bool WithTLS
{
get => Settings.WithTLS;
set
{
Settings.WithTLS = value;
RaisePropertyChanged("Port");
}
}
2021-05-15 11:45:36 +03:00
public int Port
{
get => Settings.Port;
set
{
Settings.Port = value;
RaisePropertyChanged("Port");
}
}
2022-11-21 11:42:47 +03:00
public string UTLS
{
get => Settings.UTLS;
set
{
Settings.UTLS = value;
RaisePropertyChanged(nameof(UTLS));
}
}
2021-05-15 11:45:36 +03:00
public int VLESS_KCP_Port
{
get => Settings.VLESS_KCP_Port;
set
{
Settings.VLESS_KCP_Port = value;
RaisePropertyChanged("VLESS_KCP_Port");
}
}
public int VMESS_KCP_Port
{
get => Settings.VMESS_KCP_Port;
set
{
Settings.VMESS_KCP_Port = value;
RaisePropertyChanged("VMESS_KCP_Port");
}
}
public string UUID
{
get => Settings.UUID;
set
{
Settings.UUID = value;
RaisePropertyChanged("UUID");
}
}
2021-06-30 13:36:27 +03:00
public string MultiUUID
{
get => string.Join(",", Settings.MulitUUID);
set
{
var input = value.Replace('', ',');
2022-02-28 05:07:34 +03:00
var arr = input.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
arr.RemoveAll(x => x == this.UUID);
2021-06-30 13:36:27 +03:00
Settings.MulitUUID = arr;
RaisePropertyChanged("MultiUUID");
}
}
2021-05-15 11:45:36 +03:00
public string Domain
{
get => Settings.Domain;
set
{
Settings.Domain = value;
RaisePropertyChanged("Domain");
}
}
public string MaskDomain
{
get => Settings.MaskDomain;
set
{
Settings.MaskDomain = value;
RaisePropertyChanged("MaskDomain");
}
}
2022-11-23 17:06:09 +03:00
#region Trojan
2021-05-15 11:45:36 +03:00
public string TrojanPassword
{
get => Settings.TrojanPassword;
set => Settings.TrojanPassword = value;
}
2021-07-13 05:12:15 +03:00
2021-05-15 11:45:36 +03:00
public bool Checked_Trojan_TCP
{
get
{
2021-08-20 06:52:45 +03:00
return Settings.Types.Contains(RayType.Trojan_TCP);
2021-05-15 11:45:36 +03:00
}
set
{
if (value == true)
{
2021-08-20 06:52:45 +03:00
if (!Settings.Types.Contains(RayType.Trojan_TCP))
Settings.Types.Add(RayType.Trojan_TCP);
2021-05-15 11:45:36 +03:00
}
else
{
2021-08-20 06:52:45 +03:00
Settings.Types.Remove(RayType.Trojan_TCP);
2021-05-15 11:45:36 +03:00
}
RaisePropertyChanged("Checked_Trojan_TCP");
}
}
public string Trojan_TCP_ShareLink
{
2021-08-20 06:52:45 +03:00
get => ShareLink.Build(RayType.Trojan_TCP, Settings);
2021-05-15 11:45:36 +03:00
}
2022-11-23 17:06:09 +03:00
#endregion
2021-05-15 11:45:36 +03:00
2022-11-23 17:06:09 +03:00
#region ShadowSocks
public int ShadowSocksPort
{
get => Settings.ShadowSocksPort;
set
{
Settings.ShadowSocksPort = value;
RaisePropertyChanged("ShadowSocksPort");
}
}
2021-05-15 11:45:36 +03:00
public bool CheckedShadowSocks
{
2021-08-20 06:52:45 +03:00
get => Settings.Types.Contains(RayType.ShadowsocksAEAD);
2021-05-15 11:45:36 +03:00
set
{
2021-08-20 06:52:45 +03:00
CheckBoxChanged(value, RayType.ShadowsocksAEAD);
2021-05-15 11:45:36 +03:00
RaisePropertyChanged("CheckedShadowSocks");
}
}
public string ShadowSocksPassword
{
2021-05-22 12:14:27 +03:00
get => Settings.ShadowSocksPassword;
set => Settings.ShadowSocksPassword = value;
2021-05-15 11:45:36 +03:00
}
public string ShadowSocksMethod
{
2021-05-22 12:14:27 +03:00
get => Settings.ShadowSocksMethod;
2021-05-15 11:45:36 +03:00
set
{
var namespaceStr = typeof(ComboBoxItem).FullName + ":";
var trimValue = value.Replace(namespaceStr, "");
trimValue = trimValue.Trim();
2021-05-22 12:14:27 +03:00
Settings.ShadowSocksMethod = trimValue;
2021-05-15 11:45:36 +03:00
RaisePropertyChanged("ShadowSocksMethod");
}
2021-05-14 14:07:19 +03:00
}
2021-05-15 11:45:36 +03:00
public string ShadowSocksShareLink
{
2021-08-20 06:52:45 +03:00
get => ShareLink.Build(RayType.ShadowsocksAEAD, Settings);
2021-05-15 11:45:36 +03:00
}
2022-11-23 17:06:09 +03:00
#endregion
2021-05-15 11:45:36 +03:00
2021-08-20 06:52:45 +03:00
private void CheckBoxChanged(bool value, RayType type)
2021-05-15 11:45:36 +03:00
{
if (value == true)
{
if (!Settings.Types.Contains(type))
{
Settings.Types.Add(type);
}
}
else
{
Settings.Types.RemoveAll(x => x == type);
}
}
private void GetUuid()
{
UUID = Guid.NewGuid().ToString();
RaisePropertyChanged("UUID");
}
2021-05-14 14:07:19 +03:00
}
2021-05-15 11:45:36 +03:00
/// <summary>
/// VMESS
/// </summary>
public partial class XrayEditorViewModel
{
2022-11-23 17:06:09 +03:00
#region VMESS TCP
2021-05-15 11:45:36 +03:00
public bool Checked_VMESS_TCP
{
2021-08-20 06:52:45 +03:00
get => Settings.Types.Contains(RayType.VMESS_TCP);
2021-05-15 11:45:36 +03:00
set
{
2021-08-20 06:52:45 +03:00
CheckBoxChanged(value, RayType.VMESS_TCP);
2021-05-15 11:45:36 +03:00
RaisePropertyChanged("Checked_VMESS_TCP");
}
}
public string VMESS_TCP_Path
{
get => Settings.VMESS_TCP_Path;
set => Settings.VMESS_TCP_Path = value;
}
public string VMESS_TCP_ShareLink
{
2021-08-20 06:52:45 +03:00
get => ShareLink.Build(RayType.VMESS_TCP, Settings);
2021-05-15 11:45:36 +03:00
}
2022-11-23 17:06:09 +03:00
#endregion
2021-05-15 11:45:36 +03:00
2022-11-23 17:06:09 +03:00
#region VMESS WS
2021-05-15 11:45:36 +03:00
public bool Checked_VMESS_WS
{
2021-08-20 06:52:45 +03:00
get => Settings.Types.Contains(RayType.VMESS_WS);
2021-05-15 11:45:36 +03:00
set
{
2021-08-20 06:52:45 +03:00
CheckBoxChanged(value, RayType.VMESS_WS);
2021-05-15 11:45:36 +03:00
RaisePropertyChanged("Checked_VMESS_WS");
}
}
public string VMESS_WS_Path
{
get => Settings.VMESS_WS_Path;
set => Settings.VMESS_WS_Path = value;
}
public string VMESS_WS_ShareLink
{
2021-08-20 06:52:45 +03:00
get => ShareLink.Build(RayType.VMESS_WS, Settings);
2021-05-15 11:45:36 +03:00
}
2022-11-23 17:06:09 +03:00
#endregion
2021-05-15 11:45:36 +03:00
2022-11-23 17:06:09 +03:00
#region VMESS KCP
2021-05-15 11:45:36 +03:00
public string VMESS_KCP_Seed
{
get => Settings.VMESS_KCP_Seed;
set => Settings.VMESS_KCP_Seed = value;
}
public string VMESS_KCP_Type
{
get => Settings.VMESS_KCP_Type;
set
{
var namespaceStr = typeof(ComboBoxItem).FullName + ":";
var trimValue = value.Replace(namespaceStr, "");
trimValue = trimValue.Trim();
Settings.VMESS_KCP_Type = trimValue;
RaisePropertyChanged("VMESS_KCP_Type");
}
}
public bool Checked_VMESS_KCP
{
2021-08-20 06:52:45 +03:00
get => Settings.Types.Contains(RayType.VMESS_KCP);
2021-05-15 11:45:36 +03:00
set
{
2021-08-20 06:52:45 +03:00
CheckBoxChanged(value, RayType.VMESS_KCP);
2021-05-15 11:45:36 +03:00
RaisePropertyChanged("Checked_VMESS_KCP");
}
}
public string VMESS_KCP_ShareLink
{
2021-08-20 06:52:45 +03:00
get => ShareLink.Build(RayType.VMESS_KCP, Settings);
2021-05-15 11:45:36 +03:00
}
2022-11-23 17:06:09 +03:00
#endregion
2021-05-15 11:45:36 +03:00
2022-11-23 17:06:09 +03:00
#region VMESS QUIC
public bool Checked_VMESS_QUIC
{
get => Settings.Types.Contains(RayType.VMESS_QUIC);
set
{
CheckBoxChanged(value, RayType.VMESS_QUIC);
RaisePropertyChanged(nameof(Checked_VMESS_QUIC));
}
}
public string VMESS_QUIC_Key
{
get => Settings.VMESS_QUIC_Key;
set
{
Settings.VMESS_QUIC_Key = value;
RaisePropertyChanged(nameof(VMESS_QUIC_Key));
}
}
public string VMESS_QUIC_Security
{
get => Settings.VMESS_QUIC_Security;
set
{
Settings.VMESS_QUIC_Security = value;
RaisePropertyChanged(nameof(VMESS_QUIC_Security));
}
}
public string VMESS_QUIC_Type
{
get => Settings.VMESS_QUIC_Type;
set
{
Settings.VMESS_QUIC_Type = value;
RaisePropertyChanged(nameof(VMESS_QUIC_Type));
}
}
public int VMESS_QUIC_Port
{
get => Settings.VMESS_QUIC_Port;
set
{
Settings.VMESS_QUIC_Port = value;
RaisePropertyChanged(nameof(VMESS_QUIC_Port));
}
}
public string VMESS_QUIC_ShareLink
{
get => ShareLink.Build(RayType.VMESS_QUIC, Settings);
}
#endregion
2021-05-15 11:45:36 +03:00
}
/// <summary>
/// VLESS
/// </summary>
public partial class XrayEditorViewModel
{
2022-11-23 17:06:09 +03:00
#region VLESS XTLS
public List<string> FlowList { get => XraySettings.FlowList; }
2021-05-15 11:45:36 +03:00
2022-11-23 17:06:09 +03:00
public string Flow
{
get => Settings.Flow;
set
{
Settings.Flow = value;
RaisePropertyChanged(nameof(Flow));
}
}
2021-05-15 11:45:36 +03:00
public bool Checked_VLESS_TCP_XTLS
{
2021-08-20 06:52:45 +03:00
get => Settings.Types.Contains(RayType.VLESS_TCP_XTLS);
2021-05-15 11:45:36 +03:00
set
{
2021-08-20 06:52:45 +03:00
CheckBoxChanged(value, RayType.VLESS_TCP_XTLS);
2021-05-15 11:45:36 +03:00
RaisePropertyChanged("Checked_VLESS_TCP_XTLS");
}
}
public string VLESS_TCP_XTLS_ShareLink
{
2021-08-20 06:52:45 +03:00
get => ShareLink.Build(RayType.VLESS_TCP_XTLS, Settings);
2021-05-15 11:45:36 +03:00
}
2022-11-23 17:06:09 +03:00
#endregion
2021-05-15 11:45:36 +03:00
2022-11-23 17:06:09 +03:00
#region VLESS TCP
2021-05-15 11:45:36 +03:00
public bool Checked_VLESS_TCP
{
2021-08-20 06:52:45 +03:00
get => Settings.Types.Contains(RayType.VLESS_TCP);
2021-05-15 11:45:36 +03:00
set
{
2021-08-20 06:52:45 +03:00
CheckBoxChanged(value, RayType.VLESS_TCP);
2021-05-15 11:45:36 +03:00
RaisePropertyChanged("Checked_VLESS_TCP");
}
}
public string VLESS_TCP_ShareLink
{
2021-08-20 06:52:45 +03:00
get => ShareLink.Build(RayType.VLESS_TCP, Settings);
2021-05-15 11:45:36 +03:00
}
2022-11-23 17:06:09 +03:00
#endregion
2021-05-15 11:45:36 +03:00
2022-11-23 17:06:09 +03:00
#region VLESS WS
2021-05-15 11:45:36 +03:00
public string VLESS_WS_Path
{
get => Settings.VLESS_WS_Path;
set => Settings.VLESS_WS_Path = value;
}
public bool Checked_VLESS_WS
{
get
{
2021-08-20 06:52:45 +03:00
return Settings.Types.Contains(RayType.VLESS_WS);
2021-05-15 11:45:36 +03:00
}
set
{
2021-08-20 06:52:45 +03:00
CheckBoxChanged(value, RayType.VLESS_WS);
2021-05-15 11:45:36 +03:00
RaisePropertyChanged("Checked_VLESS_WS");
}
}
public string VLESS_WS_ShareLink
{
2021-08-20 06:52:45 +03:00
get => ShareLink.Build(RayType.VLESS_WS, Settings);
2021-05-15 11:45:36 +03:00
}
2022-11-23 17:06:09 +03:00
#endregion
#region VLESS QUIC
public string VLESS_QUIC_Key
{
get => Settings.VLESS_QUIC_Key; set
{
Settings.VLESS_QUIC_Key = value;
RaisePropertyChanged(nameof(VLESS_QUIC_Key));
}
}
public bool Checked_VLESS_QUIC
{
get => Settings.Types.Contains(RayType.VLESS_QUIC);
set
{
CheckBoxChanged(value, RayType.VLESS_QUIC);
RaisePropertyChanged(nameof(Checked_VLESS_QUIC));
}
}
public string VLESS_QUIC_Security
{
get => Settings.VLESS_QUIC_Security;
set
{
Settings.VLESS_QUIC_Security = value;
RaisePropertyChanged(nameof(VLESS_QUIC_Security));
}
}
public string VLESS_QUIC_Type
{
get => Settings.VLESS_QUIC_Type;
set
{
Settings.VLESS_QUIC_Type = value;
RaisePropertyChanged(nameof(VLESS_QUIC_Type));
}
}
public int VLESS_QUIC_Port
{
get => Settings.VLESS_QUIC_Port;
set
{
Settings.VLESS_QUIC_Port = value;
RaisePropertyChanged(nameof(VLESS_QUIC_Port));
}
}
public string VLESS_QUIC_ShareLink
{
get => ShareLink.Build(RayType.VLESS_QUIC, Settings);
}
#endregion
2021-05-15 11:45:36 +03:00
2022-11-23 17:06:09 +03:00
#region VLESS KCP
2021-05-15 11:45:36 +03:00
public string VLESS_KCP_Seed
{
get => Settings.VLESS_KCP_Seed;
2022-11-23 17:06:09 +03:00
set
{
Settings.VLESS_KCP_Seed = value;
RaisePropertyChanged(nameof(VLESS_KCP_Seed));
}
2021-05-15 11:45:36 +03:00
}
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;
RaisePropertyChanged("VLESS_KCP_Type");
}
}
public bool Checked_VLESS_KCP
{
2021-08-20 06:52:45 +03:00
get => Settings.Types.Contains(RayType.VLESS_KCP);
2021-05-15 11:45:36 +03:00
set
{
2021-08-20 06:52:45 +03:00
CheckBoxChanged(value, RayType.VLESS_KCP);
2021-05-15 11:45:36 +03:00
RaisePropertyChanged("Checked_VLESS_KCP");
}
}
public string VLESS_KCP_ShareLink
{
2021-08-20 06:52:45 +03:00
get => ShareLink.Build(RayType.VLESS_KCP, Settings);
2021-05-15 11:45:36 +03:00
}
2022-11-23 17:06:09 +03:00
#endregion
2021-05-15 11:45:36 +03:00
2022-11-23 17:06:09 +03:00
#region VLESS gRPC
2021-05-15 11:45:36 +03:00
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
{
2021-08-20 06:52:45 +03:00
get => Settings.Types.Contains(RayType.VLESS_gRPC);
2021-05-15 11:45:36 +03:00
set
{
2021-08-20 06:52:45 +03:00
CheckBoxChanged(value, RayType.VLESS_gRPC);
2021-05-15 11:45:36 +03:00
RaisePropertyChanged("Checked_VLESS_gRPC");
}
}
public string VLESS_gRPC_ShareLink
{
2021-08-20 06:52:45 +03:00
get => ShareLink.Build(RayType.VLESS_gRPC, Settings);
2021-05-15 11:45:36 +03:00
}
2022-11-23 17:06:09 +03:00
#endregion
2021-05-15 11:45:36 +03:00
}
2021-05-14 14:07:19 +03:00
}