From 6a67a3e68566790f5b655aa53f33f8d9bcafb698 Mon Sep 17 00:00:00 2001 From: test Date: Sat, 1 Apr 2023 11:29:01 +0800 Subject: [PATCH] merge hysteria --- .../Models/Projects/HysteriaSettings.cs | 2 +- ProxySuper.Core/ProxySuper.Core.csproj | 1 + ProxySuper.Core/Services/HysteriaService.cs | 68 ++++++++++--------- ProxySuper.Core/ViewModels/HomeViewModel.cs | 16 +++++ .../ViewModels/HysteriaConfigViewModel.cs | 45 ++++++++++++ ProxySuper.WPF/ProxySuper.WPF.csproj | 14 ++++ .../Views/Hysteria/HysteriaConfigView.xaml | 14 ++++ .../Views/Hysteria/HysteriaConfigView.xaml.cs | 30 ++++++++ .../Views/Hysteria/HysteriaEditorView.xaml.cs | 2 + .../Views/Hysteria/HysteriaInstallView.xaml | 34 ++++++++++ .../Hysteria/HysteriaInstallView.xaml.cs | 30 ++++++++ 11 files changed, 223 insertions(+), 33 deletions(-) create mode 100644 ProxySuper.Core/ViewModels/HysteriaConfigViewModel.cs create mode 100644 ProxySuper.WPF/Views/Hysteria/HysteriaConfigView.xaml create mode 100644 ProxySuper.WPF/Views/Hysteria/HysteriaConfigView.xaml.cs create mode 100644 ProxySuper.WPF/Views/Hysteria/HysteriaInstallView.xaml create mode 100644 ProxySuper.WPF/Views/Hysteria/HysteriaInstallView.xaml.cs diff --git a/ProxySuper.Core/Models/Projects/HysteriaSettings.cs b/ProxySuper.Core/Models/Projects/HysteriaSettings.cs index 4f7f9ed..8bc57c6 100644 --- a/ProxySuper.Core/Models/Projects/HysteriaSettings.cs +++ b/ProxySuper.Core/Models/Projects/HysteriaSettings.cs @@ -26,7 +26,7 @@ namespace ProxySuper.Core.Models.Projects { get { - return new List { Port }; + return new List { Port, 80 }; } } } diff --git a/ProxySuper.Core/ProxySuper.Core.csproj b/ProxySuper.Core/ProxySuper.Core.csproj index 5f54766..2debdf5 100644 --- a/ProxySuper.Core/ProxySuper.Core.csproj +++ b/ProxySuper.Core/ProxySuper.Core.csproj @@ -124,6 +124,7 @@ + diff --git a/ProxySuper.Core/Services/HysteriaService.cs b/ProxySuper.Core/Services/HysteriaService.cs index 3c5b48b..c5f2883 100644 --- a/ProxySuper.Core/Services/HysteriaService.cs +++ b/ProxySuper.Core/Services/HysteriaService.cs @@ -24,40 +24,43 @@ namespace ProxySuper.Core.Services { try { - Progress.Step = "安装Hysteria"; - Progress.Percentage = 0; + Task.Factory.StartNew(() => + { + Progress.Step = "安装Hysteria"; + Progress.Percentage = 0; - Progress.Desc = "检测系统环境"; - EnsureRootUser(); - EnsureSystemEnv(); - Progress.Percentage = 20; + Progress.Desc = "检测系统环境"; + EnsureRootUser(); + EnsureSystemEnv(); + Progress.Percentage = 20; - Progress.Desc = "安装必要的系统工具"; - InstallSystemTools(); - Progress.Percentage = 40; + Progress.Desc = "安装必要的系统工具"; + InstallSystemTools(); + Progress.Percentage = 40; - Progress.Desc = "配置防火墙"; - ConfigFirewalld(); - Progress.Percentage = 50; + Progress.Desc = "配置防火墙"; + ConfigFirewalld(); + Progress.Percentage = 50; - Progress.Step = "检测网络环境"; - EnsureNetwork(); - Progress.Percentage = 60; + Progress.Step = "检测网络环境"; + EnsureNetwork(); + Progress.Percentage = 60; - Progress.Desc = "检测域名是否绑定本机IP"; - ValidateDomain(); - Progress.Percentage = 80; + Progress.Desc = "检测域名是否绑定本机IP"; + ValidateDomain(); + Progress.Percentage = 80; - Progress.Step = "上传Hysteria配置文件"; - UploadConfigFile(); - Progress.Step = "安装Hysteria服务"; - InstallHysteria(); + Progress.Step = "上传Hysteria配置文件"; + UploadConfigFile(); + Progress.Step = "安装Hysteria服务"; + InstallHysteria(); - Progress.Percentage = 100; - Progress.Step = "安装Hysteria成功"; - Progress.Desc = "安装Hysteria成功"; + Progress.Percentage = 100; + Progress.Step = "安装Hysteria成功"; + Progress.Desc = "安装Hysteria成功"; + }); } catch (Exception ex) { @@ -113,8 +116,8 @@ namespace ProxySuper.Core.Services private void InstallHysteria() { Progress.Desc = "执行Hysteria安装文件"; - string url = "https://github.com/apernet/hysteria/releases/download/v1.3.3/hysteria-linux-386"; - string targetPath = "/user/bin/hysteria/hysteria-linux-386"; + string url = "https://github.com/apernet/hysteria/releases/download/v1.3.4/hysteria-linux-386"; + string targetPath = "/usr/bin/hysteria/hysteria-linux-386"; if (ArchType == ArchType.arm) { @@ -122,11 +125,11 @@ namespace ProxySuper.Core.Services targetPath = targetPath.Replace("hysteria-linux-386", "hysteria-linux-arm"); } - RunCmd($"curl -L {url} -o /usr/bin/hysteria"); - RunCmd("chmod +x /usr/bin/hysteria"); + RunCmd($"curl -L {url} -o {targetPath}"); + RunCmd($"chmod +x {targetPath}"); Progress.Desc = "设置Hysteria服务"; - var cmd = targetPath + " server"; + var cmd = targetPath + " -c /usr/bin/hysteria/config.json server"; var hysteriaService = HysteriaServiceTemp.Replace("##run_cmd##", cmd); RunCmd("rm -rf /etc/systemd/system/hysteria.service"); @@ -149,7 +152,7 @@ namespace ProxySuper.Core.Services var obj = JToken.FromObject(json) as dynamic; - obj["listen"] = Settings.Port; + obj["listen"] = $":{Settings.Port}"; obj["acme"]["domains"][0] = Settings.Domain; obj["email"] = Settings.Email; obj["obfs"] = Settings.Obfs; @@ -162,7 +165,8 @@ namespace ProxySuper.Core.Services NullValueHandling = NullValueHandling.Ignore }); - WriteToFile(configJson, "/user/bin/hysteria/config.json"); + RunCmd("mkdir /usr/bin/hysteria"); + WriteToFile(configJson, "/usr/bin/hysteria/config.json"); } } } diff --git a/ProxySuper.Core/ViewModels/HomeViewModel.cs b/ProxySuper.Core/ViewModels/HomeViewModel.cs index 5c5c1ec..2fd1d16 100644 --- a/ProxySuper.Core/ViewModels/HomeViewModel.cs +++ b/ProxySuper.Core/ViewModels/HomeViewModel.cs @@ -276,6 +276,14 @@ namespace ProxySuper.Core.ViewModels record.Host = result.Host; record.MTProtoGoSettings = result.MTProtoGoSettings; } + if (record.Type == ProjectType.Hysteria) + { + result = await _navigationService.Navigate(record); + if (result == null) return; + + record.Host = result.Host; + record.HysteriaSettings = result.HysteriaSettings; + } SaveToJson(); } @@ -324,6 +332,10 @@ namespace ProxySuper.Core.ViewModels { await _navigationService.Navigate(record.MTProtoGoSettings); } + if (record.Type == ProjectType.Hysteria) + { + await _navigationService.Navigate(record.HysteriaSettings); + } } public async Task GoToInstall(string id) @@ -356,6 +368,10 @@ namespace ProxySuper.Core.ViewModels { await _navigationService.Navigate(record); } + if (record.Type == ProjectType.Hysteria) + { + await _navigationService.Navigate(record); + } SaveToJson(); } diff --git a/ProxySuper.Core/ViewModels/HysteriaConfigViewModel.cs b/ProxySuper.Core/ViewModels/HysteriaConfigViewModel.cs new file mode 100644 index 0000000..bad7d44 --- /dev/null +++ b/ProxySuper.Core/ViewModels/HysteriaConfigViewModel.cs @@ -0,0 +1,45 @@ +using MvvmCross.ViewModels; +using Newtonsoft.Json; +using ProxySuper.Core.Models.Projects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class HysteriaConfigViewModel : MvxViewModel + { + public HysteriaSettings Settings { get; set; } + + public override void Prepare(HysteriaSettings parameter) + { + Settings = parameter; + } + + public string ClientJson { + + get + { + var jsonData = new + { + server = $"{Settings.Domain}:{Settings.Port}", + obfs = Settings.Obfs, + up_mbps = 10, + down_mbps = 50, + socks5 = new + { + listen = "127.0.0.1:1080" + }, + http = new + { + listen = "127.0.0.1:1081" + } + }; + + return JsonConvert.SerializeObject(jsonData, Formatting.Indented); + } + } + } +} diff --git a/ProxySuper.WPF/ProxySuper.WPF.csproj b/ProxySuper.WPF/ProxySuper.WPF.csproj index aab901b..b1f09a2 100644 --- a/ProxySuper.WPF/ProxySuper.WPF.csproj +++ b/ProxySuper.WPF/ProxySuper.WPF.csproj @@ -158,9 +158,15 @@ HomeView.xaml + + HysteriaConfigView.xaml + HysteriaEditorView.xaml + + HysteriaInstallView.xaml + MTProxyGoConfigView.xaml @@ -321,10 +327,18 @@ MSBuild:Compile PreserveNewest + + Designer + MSBuild:Compile + Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/ProxySuper.WPF/Views/Hysteria/HysteriaConfigView.xaml b/ProxySuper.WPF/Views/Hysteria/HysteriaConfigView.xaml new file mode 100644 index 0000000..6606fcf --- /dev/null +++ b/ProxySuper.WPF/Views/Hysteria/HysteriaConfigView.xaml @@ -0,0 +1,14 @@ + + + + + diff --git a/ProxySuper.WPF/Views/Hysteria/HysteriaConfigView.xaml.cs b/ProxySuper.WPF/Views/Hysteria/HysteriaConfigView.xaml.cs new file mode 100644 index 0000000..8e22992 --- /dev/null +++ b/ProxySuper.WPF/Views/Hysteria/HysteriaConfigView.xaml.cs @@ -0,0 +1,30 @@ +using MvvmCross.Platforms.Wpf.Presenters.Attributes; +using MvvmCross.Platforms.Wpf.Views; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace ProxySuper.WPF.Views.Hysteria +{ + /// + /// HysteriaConfigView.xaml 的交互逻辑 + /// + [MvxWindowPresentation] + public partial class HysteriaConfigView : MvxWindow + { + public HysteriaConfigView() + { + InitializeComponent(); + } + } +} diff --git a/ProxySuper.WPF/Views/Hysteria/HysteriaEditorView.xaml.cs b/ProxySuper.WPF/Views/Hysteria/HysteriaEditorView.xaml.cs index d790ec3..ee96efb 100644 --- a/ProxySuper.WPF/Views/Hysteria/HysteriaEditorView.xaml.cs +++ b/ProxySuper.WPF/Views/Hysteria/HysteriaEditorView.xaml.cs @@ -23,5 +23,7 @@ namespace ProxySuper.WPF.Views.Hysteria { InitializeComponent(); } + + } } diff --git a/ProxySuper.WPF/Views/Hysteria/HysteriaInstallView.xaml b/ProxySuper.WPF/Views/Hysteria/HysteriaInstallView.xaml new file mode 100644 index 0000000..1ec8777 --- /dev/null +++ b/ProxySuper.WPF/Views/Hysteria/HysteriaInstallView.xaml @@ -0,0 +1,34 @@ + + + + + +