1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-25 06:36:08 +03:00
This commit is contained in:
nuxt-autumn 2021-05-16 09:12:47 +08:00
parent 5e1e9e90cf
commit 3b79a7ca44
17 changed files with 300 additions and 183 deletions

View File

@ -1,23 +1,32 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
namespace ProxySuper.Core.Services
{
public class Base64
public class Utils
{
public static string Encode(string plainText)
public static string Base64Encode(string plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}
public static string Decode(string base64EncodedData)
public static string Base64Decode(string base64EncodedData)
{
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}
public static T DeepClone<T>(T obj) where T : class
{
var serialized = JsonConvert.SerializeObject(obj);
return JsonConvert.DeserializeObject<T>(serialized);
}
}
}

View File

@ -6,8 +6,6 @@ using System.Threading.Tasks;
namespace ProxySuper.Core.Models.Hosts
{
public class Host
{

View File

@ -6,26 +6,26 @@ using System.Threading.Tasks;
namespace ProxySuper.Core.Models.Projects
{
public interface IProjectSettings
public class IProjectSettings
{
/// <summary>
/// 端口
/// </summary>
int Port { get; set; }
public virtual int Port { get; set; }
/// <summary>
/// 域名
/// </summary>
string Domain { get; set; }
public virtual string Domain { get; set; }
/// <summary>
/// 额外需要开放的端口
/// </summary>
List<int> FreePorts { get; }
public virtual List<int> FreePorts { get; }
/// <summary>
/// 类型
/// </summary>
ProjectType Type { get; set; }
public virtual ProjectType Type { get; set; }
}
}

View File

@ -8,7 +8,7 @@ namespace ProxySuper.Core.Models.Projects
{
public class TrojanGoSettings : IProjectSettings
{
public List<int> FreePorts
public override List<int> FreePorts
{
get
{
@ -16,17 +16,17 @@ namespace ProxySuper.Core.Models.Projects
}
}
public ProjectType Type { get; set; } = ProjectType.TrojanGo;
public override ProjectType Type { get; set; } = ProjectType.TrojanGo;
/// <summary>
/// 域名
/// </summary>
public string Domain { get; set; }
public override string Domain { get; set; }
/// <summary>
/// 端口
/// </summary>
public int Port { get; set; }
public override int Port { get; set; }
/// <summary>
/// 密码

View File

@ -8,7 +8,7 @@ namespace ProxySuper.Core.Models.Projects
{
public partial class XraySettings : IProjectSettings
{
public List<int> FreePorts
public override List<int> FreePorts
{
get
{
@ -21,23 +21,23 @@ namespace ProxySuper.Core.Models.Projects
}
}
public ProjectType Type { get; set; } = ProjectType.Xray;
public override ProjectType Type { get; set; } = ProjectType.Xray;
/// <summary>
/// 端口
/// </summary>
public override int Port { get; set; }
/// <summary>
/// 域名
/// </summary>
public override string Domain { get; set; }
/// <summary>
/// UUID
/// </summary>
public string UUID { get; set; }
/// <summary>
/// 端口
/// </summary>
public int Port { get; set; }
/// <summary>
/// 域名
/// </summary>
public string Domain { get; set; }
/// <summary>
/// 伪装域名
/// </summary>
@ -46,7 +46,7 @@ namespace ProxySuper.Core.Models.Projects
/// <summary>
/// 安装类型
/// </summary>
public List<XrayType> Types { get; set; }
public List<XrayType> Types { get; set; } = new List<XrayType>();
/// <summary>
/// 根据xray类型获取路径

View File

@ -1,7 +1,12 @@
using Newtonsoft.Json;
using MvvmCross;
using MvvmCross.Commands;
using MvvmCross.Navigation;
using MvvmCross.ViewModels;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using ProxySuper.Core.Models.Hosts;
using ProxySuper.Core.Models.Projects;
using ProxySuper.Core.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
@ -10,19 +15,46 @@ using System.Threading.Tasks;
namespace ProxySuper.Core.Models
{
public class Record
public class Record : MvxViewModel
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("host")]
public Host Host { get; set; }
[JsonProperty("settings")]
public dynamic Settings { get; set; }
public XraySettings XraySettings { get; set; }
[JsonProperty("trojanGoSettings")]
public TrojanGoSettings TrojanGoSettings { get; set; }
public string Type
[JsonIgnore]
public ProjectType Type
{
get
{
return Settings.type ?? "Xray";
if (XraySettings != null) return ProjectType.Xray;
return ProjectType.TrojanGo;
}
}
public IMvxCommand NavToEditorCommand => new MvxAsyncCommand(NavigateToEditor);
public async Task NavigateToEditor()
{
var nav = Mvx.IoCProvider.Resolve<IMvxNavigationService>();
if (Type == ProjectType.Xray)
{
var result = await nav.Navigate<XrayEditorViewModel, Record, Record>(this);
if (result == null) return;
this.Host = result.Host;
this.XraySettings = result.XraySettings;
await RaisePropertyChanged("Host");
}
}
}

View File

@ -77,7 +77,7 @@
<Compile Include="Models\Projects\XrayType.cs" />
<Compile Include="Models\Record.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\Base64.cs" />
<Compile Include="Helpers\Utils.cs" />
<Compile Include="Services\ProjectBase.cs" />
<Compile Include="Services\ShareLink.cs" />
<Compile Include="Services\TrojanGoConfigBuilder.cs" />

View File

@ -41,7 +41,7 @@ namespace ProxySuper.Core.Services
var _server = settings.Domain;
var _port = settings.ShadowSocksPort;
var base64URL = Base64.Encode($"{_method}:{_password}@{_server}:{_port}");
var base64URL = Utils.Base64Encode($"{_method}:{_password}@{_server}:{_port}");
return "ss://" + base64URL + "#ShadowSocks";
}
@ -88,7 +88,7 @@ namespace ProxySuper.Core.Services
return string.Empty;
}
var base64Url = Base64.Encode(JsonConvert.SerializeObject(vmess));
var base64Url = Utils.Base64Encode(JsonConvert.SerializeObject(vmess));
return $"vmess://" + base64Url;
}

View File

@ -1,7 +1,10 @@
using MvvmCross.Navigation;
using MvvmCross.Commands;
using MvvmCross.Navigation;
using MvvmCross.ViewModels;
using Newtonsoft.Json;
using ProxySuper.Core.Models;
using ProxySuper.Core.Models.Hosts;
using ProxySuper.Core.Models.Projects;
using System;
using System.Collections.Generic;
using System.IO;
@ -26,14 +29,32 @@ namespace ProxySuper.Core.ViewModels
var json = File.ReadAllText("Data/Record.json");
var records = JsonConvert.DeserializeObject<List<Record>>(json);
this.Records = new MvxObservableCollection<Record>();
records.ForEach(item =>
{
if (string.IsNullOrEmpty(item.Id))
{
item.Id = Guid.NewGuid().ToString();
}
this.Records.Add(item);
});
}
public MvxObservableCollection<Record> Records { get; set; }
public IMvxCommand AddXrayCommand => new MvxAsyncCommand(AddXrayRecord);
public async Task AddXrayRecord()
{
Record record = new Record();
record.Id = Guid.NewGuid().ToString();
record.Host = new Host();
record.XraySettings = new XraySettings();
var result = await _navigationService.Navigate<XrayEditorViewModel, Record, Record>(record);
if (result == null) return;
Records.Add(result);
}
}
}

View File

@ -1,4 +1,6 @@
using MvvmCross.Commands;
using MvvmCross;
using MvvmCross.Commands;
using MvvmCross.Navigation;
using MvvmCross.ViewModels;
using Newtonsoft.Json;
using ProxySuper.Core.Models;
@ -15,21 +17,42 @@ using System.Windows.Input;
namespace ProxySuper.Core.ViewModels
{
public partial class XrayEditorViewModel : MvxViewModel<Record>
public partial class XrayEditorViewModel : MvxViewModel<Record, Record>
{
public XrayEditorViewModel()
private IMvxNavigationService _navigationService;
public XrayEditorViewModel(IMvxNavigationService mvxNavigationService)
{
_navigationService = mvxNavigationService;
_randomUuid = new MvxCommand(() => GetUuid());
SaveCommand = new MvxCommand(() => Save());
}
public string Id { get; set; }
public Host Host { get; set; }
public XraySettings Settings { get; set; }
public IMvxCommand SaveCommand { get; }
public override void Prepare(Record parameter)
{
Host = parameter.Host;
Settings = JsonConvert.DeserializeObject<XraySettings>(JsonConvert.SerializeObject(parameter.Settings));
var record = Utils.DeepClone(parameter);
Id = record.Id;
Host = record.Host;
Settings = record.XraySettings;
}
public void Save()
{
var result = new Record()
{
Id = Id,
Host = Host,
XraySettings = Settings,
};
_navigationService.Close(this, result);
}
}

View File

@ -45,26 +45,26 @@
<Label Content="{DynamicResource HostTag}" Grid.Row="0" Grid.Column="0" />
<TextBox Grid.Row="0" Grid.Column="1"
Width="180"
Width="170"
Text="{Binding Host.Tag}"
VerticalContentAlignment="Center" />
<Label Content="{DynamicResource HostAddress}" Grid.Row="1" Grid.Column="0" />
<TextBox Grid.Row="1" Grid.Column="1"
Width="180"
Width="170"
Text="{Binding Host.Address}"
VerticalContentAlignment="Center" />
<Label Content="{DynamicResource HostUserName}" Grid.Row="2" Grid.Column="0" />
<TextBox Grid.Row="2" Grid.Column="1"
Width="180"
Width="170"
Text="{Binding Host.UserName}"
VerticalContentAlignment="Center" />
<Label Content="{DynamicResource HostPassword}" Grid.Row="3" Grid.Column="0" />
<TextBox Grid.Row="3" Grid.Column="1"
Width="180"
Width="170"
Text="{Binding Host.Password}"
VerticalContentAlignment="Center" />

View File

@ -10,6 +10,7 @@
<UserControl.Resources>
<convert:VisibleConverter x:Key="VisibleConverter" />
</UserControl.Resources>
<StackPanel Orientation="Horizontal">
<StackPanel Width="220">
<!--XTLS-->
@ -88,24 +89,24 @@
<!--************************** 参数 **************************-->
<StackPanel Width="auto">
<StackPanel>
<!--Domain-->
<StackPanel Margin="40,15,0,0"
<StackPanel Margin="30,15,0,0"
Orientation="Horizontal">
<Label Content="{DynamicResource XrayDomain}" Width="120" />
<TextBox Text="{Binding Path=Domain}" Width="200" />
</StackPanel>
<!--Mask Domain-->
<StackPanel Margin="40,15,0,0"
<StackPanel Margin="30,15,0,0"
Orientation="Horizontal">
<Label Content="{DynamicResource XrayMarkDomain}" Width="120" />
<TextBox Text="{Binding Path=MaskDomain}" Width="200" />
</StackPanel>
<!--UUID-->
<StackPanel Margin="40,10,0,0"
<StackPanel Margin="30,10,0,0"
Orientation="Horizontal">
<Label Content="{DynamicResource XrayUUID}" Width="120" />
@ -119,7 +120,7 @@
</StackPanel>
<!--WebSocket Path-->
<StackPanel Margin="40,15,0,0"
<StackPanel Margin="30,15,0,0"
Orientation="Horizontal"
Visibility="{
Binding Path=Checked_VLESS_WS,
@ -131,7 +132,7 @@
</StackPanel>
<!--seed-->
<StackPanel Margin="40,15,0,0"
<StackPanel Margin="30,15,0,0"
Orientation="Horizontal"
Visibility="{
Binding Path=Checked_VLESS_KCP,
@ -142,7 +143,7 @@
</StackPanel>
<!--kcp type-->
<StackPanel Margin="40,15,0,0"
<StackPanel Margin="30,15,0,0"
Visibility="{
Binding Path=Checked_VLESS_KCP,
Converter={StaticResource VisibleConverter}
@ -156,7 +157,7 @@
</StackPanel>
<!--kcp port-->
<StackPanel Margin="40,15,0,0"
<StackPanel Margin="30,15,0,0"
Visibility="{
Binding Path=Checked_VLESS_KCP,
Converter={StaticResource VisibleConverter}
@ -167,7 +168,7 @@
</StackPanel>
<!--gRPC Port-->
<!--<StackPanel Margin="40,15,0,0"
<!--<StackPanel Margin="30,15,0,0"
Orientation="Horizontal"
Visibility="{
Binding Path=Checked_VLESS_gRPC,
@ -181,7 +182,7 @@
</StackPanel>-->
<!--Tcp Path-->
<!--<StackPanel Margin="40,15,0,0"
<!--<StackPanel Margin="30,15,0,0"
Orientation="Horizontal"
Visibility="{
Binding Path=Checked_VMESS_TCP,
@ -194,7 +195,7 @@
</StackPanel>-->
<!--WebSocket Path-->
<StackPanel Margin="40,15,0,0"
<StackPanel Margin="30,15,0,0"
Orientation="Horizontal"
Visibility="{
Binding Path=Checked_VMESS_WS,
@ -207,7 +208,7 @@
</StackPanel>
<!--seed-->
<StackPanel Margin="40,15,0,0"
<StackPanel Margin="30,15,0,0"
Orientation="Horizontal"
Visibility="{
Binding Path=Checked_VMESS_KCP,
@ -218,7 +219,7 @@
</StackPanel>
<!--kcp type-->
<StackPanel Margin="40,15,0,0"
<StackPanel Margin="30,15,0,0"
Orientation="Horizontal"
Visibility="{
Binding Path=Checked_VMESS_KCP,
@ -233,7 +234,7 @@
</StackPanel>
<!--kcp port-->
<StackPanel Margin="40,15,0,0"
<StackPanel Margin="30,15,0,0"
Orientation="Horizontal"
Visibility="{
Binding Path=Checked_VMESS_KCP,
@ -244,7 +245,7 @@
</StackPanel>
<!--ss密码-->
<StackPanel Margin="40,15,0,0"
<StackPanel Margin="30,15,0,0"
Orientation="Horizontal"
Visibility="{
Binding Path=CheckedShadowSocks,
@ -256,7 +257,7 @@
</StackPanel>
<!--ss加密方式-->
<StackPanel Margin="40,15,0,0"
<StackPanel Margin="30,15,0,0"
Orientation="Horizontal"
Visibility="{
Binding Path=CheckedShadowSocks,
@ -270,7 +271,7 @@
</StackPanel>
<!--Trojan密码-->
<StackPanel Margin="40,15,0,0"
<StackPanel Margin="30,15,0,0"
Orientation="Horizontal"
Visibility="{
Binding Path=Checked_Trojan_TCP,
@ -282,7 +283,7 @@
</StackPanel>
<!--xray prot-->
<StackPanel Margin="40,15,0,0"
<StackPanel Margin="30,15,0,0"
Orientation="Horizontal">
<Label Content="{DynamicResource XrayPort}" Foreground="Gray" Width="120" />
<TextBox Text="{Binding Path=Port}" Width="120" />
@ -290,4 +291,5 @@
</StackPanel>
</StackPanel>
</StackPanel>
</UserControl>

View File

@ -2,6 +2,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<!--common-->
<sys:String x:Key="Random">Random</sys:String>
<sys:String x:Key="Save">Save</sys:String>
<!--Main Menu-->
<sys:String x:Key="MainMenuAddHost">Add Host</sys:String>
<sys:String x:Key="MainMenuActions">Actions</sys:String>
@ -49,7 +53,6 @@
<!--Xray-->
<sys:String x:Key="Random">Random</sys:String>
<sys:String x:Key="VlessXtlsDesc" xml:space="preserve">VLESS over TCP With XTLS&#x0a;Preferred</sys:String>
<sys:String x:Key="VlessTcpDesc" xml:space="preserve">VLESS over TCP with TLS&#x0a;XTLS is Preferred</sys:String>
<sys:String x:Key="VlessWsDesc" xml:space="preserve">VLESS over WS with TLS&#x0a;Support CDN</sys:String>

View File

@ -2,6 +2,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<!--common-->
<sys:String x:Key="Random">随机</sys:String>
<sys:String x:Key="Save">保存</sys:String>
<!--Main Menu-->
<sys:String x:Key="MainMenuAddHost">添加主机</sys:String>
<sys:String x:Key="MainMenuActions">操作</sys:String>
@ -48,7 +52,6 @@
<sys:String x:Key="ProxyTypeSocks5">Socks5</sys:String>
<!--Xray-->
<sys:String x:Key="Random">随机</sys:String>
<sys:String x:Key="VlessXtlsDesc" xml:space="preserve">VLESS Over TCP With XTLS&#x0a;性能数倍,首选方式。</sys:String>
<sys:String x:Key="VlessTcpDesc" xml:space="preserve">VLESS over TCP with TLS&#x0a;仍推荐XTLS。</sys:String>
<sys:String x:Key="VlessWsDesc" xml:space="preserve">VLESS over WS with TLS&#x0a;推荐支持CDN。</sys:String>

View File

@ -15,7 +15,7 @@
<Menu Background="White" Grid.Row="0" BorderThickness="0,0,0,2" BorderBrush="#eee">
<MenuItem Header="{DynamicResource MainMenuAddHost}" Padding="10,3">
<MenuItem Padding="0,5" Header="Xray"></MenuItem>
<MenuItem Padding="0,5" Header="Xray" Command="{Binding AddXrayCommand}"></MenuItem>
<MenuItem Padding="0,5" Header="Trojan-Go"></MenuItem>
<MenuItem Padding="0,5" Header="NaiveProxy"></MenuItem>
</MenuItem>
@ -65,14 +65,14 @@
<DataGridTemplateColumn Header="{DynamicResource MainDataGridColumnAction}" Width="400">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ItemContainerTemplate>
<StackPanel Orientation="Horizontal">
<Button Click="NavToEditor"
Margin="5,0"
Padding="12,3"
Content="{DynamicResource MainDataGridColumnActionInstall}" />
<Button Click="NavToEditor"
<Button Command="{Binding NavToEditorCommand}"
Margin="5,0"
Padding="12,3"
Content="{DynamicResource MainDataGridColumnActionEdit}" />
@ -82,7 +82,7 @@
Padding="12,3"
Content="{DynamicResource MainDataGridColumnActionDelete}" />
</StackPanel>
</DataTemplate>
</ItemContainerTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>

View File

@ -28,7 +28,7 @@ namespace ProxySuper.WPF.Views
var navSrv = Mvx.IoCProvider.Resolve<IMvxNavigationService>();
var vm = ViewModel as HomeViewModel;
navSrv.Navigate<XrayEditorViewModel, Record>(vm.Records[0]);
navSrv.Navigate<XrayEditorViewModel, Record, Record>(vm.Records[0]);
}
}
}

View File

@ -11,13 +11,13 @@
Icon="/Resources/ProxySU.ico"
BorderThickness="0,1,0,0"
BorderBrush="#EEE"
Title="XrayEditorView" Height="600" Width="1000">
Title="XrayEditorView" Height="610" Width="1015">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="320" />
<ColumnDefinition Width="310" />
<ColumnDefinition Width="1" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Margin="10">
@ -27,7 +27,33 @@
<StackPanel Grid.Column="1" Background="#EEE"></StackPanel>
<StackPanel Grid.Column="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="500" />
<RowDefinition Height="80" />
</Grid.RowDefinitions>
<ScrollViewer Name="scroll"
Padding="10"
Height="500"
Grid.Row="0"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto" >
<ctrl:XraySettingsControl />
</ScrollViewer>
<Border Grid.Row="1"
BorderBrush="#eee"
BorderThickness="0,1,0,0">
<Button Content="{DynamicResource Save}"
Command="{Binding SaveCommand}"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Height="30"
Width="100"
Margin="40,0" />
</Border>
</Grid>
</StackPanel>
</Grid>
</views:MvxWindow>