Skip to content

Commit 6e61ef1

Browse files
committed
MTProxy -> MTProto | 修复ssh私钥带密码登陆
1 parent be9ae4a commit 6e61ef1

33 files changed

+198
-131
lines changed

ProxySuper.Core/Models/Hosts/Host.cs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.Win32;
22
using MvvmCross.Commands;
3+
using Newtonsoft.Json;
34
using System.ComponentModel;
45
using System.Threading.Tasks;
56
using System.Windows;

ProxySuper.Core/Models/Projects/MTProxyGoSettings.cs renamed to ProxySuper.Core/Models/Projects/MTProtoGoSettings.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
namespace ProxySuper.Core.Models.Projects
88
{
9-
public class MTProxyGoSettings : IProjectSettings
9+
public class MTProtoGoSettings : IProjectSettings
1010
{
11-
public MTProxyGoSettings()
11+
public MTProtoGoSettings()
1212
{
1313
Port = 443;
1414

ProxySuper.Core/Models/Projects/ProjectType.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ public enum ProjectType
77
NaiveProxy = 2,
88
Brook = 3,
99
V2ray = 4,
10-
MTProxyGo = 5,
10+
MTProtoGo = 5,
1111
}
1212
}

ProxySuper.Core/Models/Record.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ public Host Host
4242
[JsonProperty("trojanGoSettings")]
4343
public TrojanGoSettings TrojanGoSettings { get; set; }
4444

45-
[JsonProperty("naiveProxySettings")]
45+
[JsonProperty("naiveProtoSettings")]
4646
public NaiveProxySettings NaiveProxySettings { get; set; }
4747

4848
[JsonProperty("brook")]
4949
public BrookSettings BrookSettings { get; set; }
5050

51-
[JsonProperty("mtProxyGoSettings")]
52-
public MTProxyGoSettings MTProxyGoSettings { get; set; }
51+
[JsonProperty("mtProtoGoSettings")]
52+
public MTProtoGoSettings MTProtoGoSettings { get; set; }
5353

5454

5555
[JsonIgnore]
@@ -65,7 +65,7 @@ public ProjectType Type
6565

6666
if (NaiveProxySettings != null) return ProjectType.NaiveProxy;
6767

68-
if (MTProxyGoSettings != null) return ProjectType.MTProxyGo;
68+
if (MTProtoGoSettings != null) return ProjectType.MTProtoGo;
6969

7070
return ProjectType.Brook;
7171
}

ProxySuper.Core/ProxySuper.Core.csproj

+5-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<Compile Include="Models\Projects\BrookType.cs" />
7676
<Compile Include="Models\Projects\IProjectSettings.cs" />
7777
<Compile Include="Models\Hosts\LocalProxy.cs" />
78-
<Compile Include="Models\Projects\MTProxyGoSettings.cs" />
78+
<Compile Include="Models\Projects\MTProtoGoSettings.cs" />
7979
<Compile Include="Models\Projects\NaiveProxySettings.cs" />
8080
<Compile Include="Models\Projects\ProjectType.cs" />
8181
<Compile Include="Models\Projects\TrojanGoSettings.cs" />
@@ -90,7 +90,7 @@
9090
<Compile Include="Properties\AssemblyInfo.cs" />
9191
<Compile Include="Helpers\Utils.cs" />
9292
<Compile Include="Services\BrookService.cs" />
93-
<Compile Include="Services\MTProxyGoService.cs" />
93+
<Compile Include="Services\MTProtoGoService.cs" />
9494
<Compile Include="Services\NaiveProxyService.cs" />
9595
<Compile Include="Services\ServiceBase.cs" />
9696
<Compile Include="Services\ShareLink.cs" />
@@ -105,9 +105,9 @@
105105
<Compile Include="ViewModels\BrookInstallViewModel.cs" />
106106
<Compile Include="ViewModels\EnableRootViewModel.cs" />
107107
<Compile Include="ViewModels\HomeViewModel.cs" />
108-
<Compile Include="ViewModels\MTProxyGoConfigViewModel.cs" />
109-
<Compile Include="ViewModels\MTProxyGoEditorViewModel.cs" />
110-
<Compile Include="ViewModels\MTProxyGoInstallViewModel.cs" />
108+
<Compile Include="ViewModels\MTProtoGoConfigViewModel.cs" />
109+
<Compile Include="ViewModels\MTProtoGoEditorViewModel.cs" />
110+
<Compile Include="ViewModels\MTProtoGoInstallViewModel.cs" />
111111
<Compile Include="ViewModels\NaiveProxyConfigViewModel.cs" />
112112
<Compile Include="ViewModels\NaiveProxyEditorViewModel.cs" />
113113
<Compile Include="ViewModels\NaiveProxyInstallViewModel.cs" />

ProxySuper.Core/Services/BrookService.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using ProxySuper.Core.Models.Hosts;
22
using ProxySuper.Core.Models.Projects;
3+
using ProxySuper.Core.ViewModels;
34
using System;
45
using System.Collections.Generic;
56
using System.Linq;
@@ -72,6 +73,8 @@ public void Install()
7273

7374
AppendCommand("分享连接:");
7475
AppendCommand(ShareLink.BuildBrook(Settings));
76+
77+
NavigationService.Navigate<BrookConfigViewModel, BrookSettings>(Settings);
7578
}
7679
catch (Exception ex)
7780
{

ProxySuper.Core/Services/MTProxyGoService.cs renamed to ProxySuper.Core/Services/MTProtoGoService.cs

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using ProxySuper.Core.Models.Hosts;
22
using ProxySuper.Core.Models.Projects;
3+
using ProxySuper.Core.ViewModels;
34
using System;
45
using System.Collections.Generic;
56
using System.Linq;
@@ -9,9 +10,9 @@
910

1011
namespace ProxySuper.Core.Services
1112
{
12-
public class MTProxyGoService : ServiceBase<MTProxyGoSettings>
13+
public class MTProtoGoService : ServiceBase<MTProtoGoSettings>
1314
{
14-
public MTProxyGoService(Host host, MTProxyGoSettings settings) : base(host, settings)
15+
public MTProtoGoService(Host host, MTProtoGoSettings settings) : base(host, settings)
1516
{
1617
}
1718

@@ -53,9 +54,9 @@ public void Install()
5354
RunCmd($"echo \"bind-to=\\\"0.0.0.0:{Settings.Port}\\\"\" >> /etc/mtg.toml");
5455
Progress.Percentage = 80;
5556

56-
Progress.Step = "7. 启动MTProxy服务";
57+
Progress.Step = "7. 启动MTProto服务";
5758
RunCmd($"docker run -d -v /etc/mtg.toml:/config.toml --name=mtg --restart=always -p {Settings.Port + ":" + Settings.Port} nineseconds/mtg");
58-
Progress.Desc = "设置自启动MTProxy服务";
59+
Progress.Desc = "设置自启动MTProto服务";
5960

6061
Progress.Step = "安装完成";
6162
Progress.Percentage = 100;
@@ -64,6 +65,7 @@ public void Install()
6465
AppendCommand("Port: " + Settings.Port);
6566
AppendCommand("Secret: " + Settings.SecretText);
6667

68+
NavigationService.Navigate<MTProtoGoConfigViewModel, MTProtoGoSettings>(Settings);
6769
}
6870
catch (Exception ex)
6971
{
@@ -79,7 +81,7 @@ public void Uninstall()
7981
try
8082
{
8183
Progress.Percentage = 0;
82-
Progress.Step = "卸载MTProxy";
84+
Progress.Step = "卸载MTProto";
8385

8486
Progress.Desc = "检测系统环境";
8587
EnsureRootUser();
@@ -106,9 +108,9 @@ public void UpdateSettings()
106108
try
107109
{
108110
Progress.Percentage = 0;
109-
Progress.Step = "更新MTProxy配置";
111+
Progress.Step = "更新MTProto配置";
110112

111-
Progress.Desc = "暂停MTProxy服务";
113+
Progress.Desc = "暂停MTProto服务";
112114
var cid = RunCmd("docker ps -q --filter name=mtg");
113115
RunCmd($"docker stop {cid}");
114116
Progress.Percentage = 50;
@@ -122,7 +124,7 @@ public void UpdateSettings()
122124
RunCmd($"echo \"bind-to=\\\"0.0.0.0:{Settings.Port}\\\"\" >> /etc/mtg.toml");
123125
Progress.Percentage = 80;
124126

125-
Progress.Desc = "重启MTProxy服务";
127+
Progress.Desc = "重启MTProto服务";
126128
RunCmd($"docker restart {cid}");
127129

128130
Progress.Percentage = 100;

ProxySuper.Core/Services/NaiveProxyService.cs

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using ProxySuper.Core.Models;
44
using ProxySuper.Core.Models.Hosts;
55
using ProxySuper.Core.Models.Projects;
6+
using ProxySuper.Core.ViewModels;
67
using System;
78
using System.Collections.Generic;
89
using System.ComponentModel;
@@ -69,6 +70,8 @@ public void Install()
6970

7071
AppendCommand("分享连接:");
7172
AppendCommand(ShareLink.BuildNaiveProxy(Settings));
73+
74+
NavigationService.Navigate<NaiveProxyConfigViewModel, NaiveProxySettings>(Settings);
7275
}
7376
catch (Exception ex)
7477
{

ProxySuper.Core/Services/ServiceBase.cs

+59-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using ProxySuper.Core.Helpers;
1+
using MvvmCross;
2+
using MvvmCross.Navigation;
3+
using ProxySuper.Core.Helpers;
24
using ProxySuper.Core.Models;
35
using ProxySuper.Core.Models.Hosts;
46
using ProxySuper.Core.Models.Projects;
@@ -9,6 +11,8 @@
911
using System.Linq;
1012
using System.Text;
1113
using System.Threading.Tasks;
14+
using System.Windows;
15+
using System.Windows.Navigation;
1216

1317
namespace ProxySuper.Core.Services
1418
{
@@ -30,7 +34,6 @@ public abstract class ServiceBase<TSettings> where TSettings : IProjectSettings
3034
{
3135
private Host _host;
3236

33-
3437
private SshClient _sshClient;
3538

3639
private ProjectProgress _progress;
@@ -41,7 +44,11 @@ public ServiceBase(Host host, TSettings settings)
4144

4245
Settings = settings;
4346

44-
_sshClient = new SshClient(CreateConnectionInfo());
47+
var connection = CreateConnectionInfo();
48+
if (connection != null)
49+
{
50+
_sshClient = new SshClient(connection);
51+
}
4552

4653
_progress = new ProjectProgress();
4754

@@ -54,6 +61,8 @@ public ServiceBase(Host host, TSettings settings)
5461
IPv6 = string.Empty;
5562

5663
IsOnlyIPv6 = false;
64+
65+
NavigationService = Mvx.IoCProvider.Resolve<IMvxNavigationService>();
5766
}
5867

5968
public string RunCmd(string command)
@@ -89,12 +98,20 @@ public string RunCmd(string command)
8998

9099
public bool IsOnlyIPv6 { get; set; }
91100

101+
public IMvxNavigationService NavigationService { get; set; }
102+
92103

93104
#region 公用方法
94105
public void Connect()
95106
{
96107
Task.Run(() =>
97108
{
109+
if (_sshClient == null)
110+
{
111+
MessageBox.Show("无法建立连接,连接参数有误!");
112+
return;
113+
}
114+
98115
if (_sshClient.IsConnected == false)
99116
{
100117
Progress.Desc = ("正在与服务器建立连接");
@@ -115,7 +132,7 @@ public void Disconnect()
115132
{
116133
Task.Run(() =>
117134
{
118-
_sshClient.Disconnect();
135+
_sshClient?.Disconnect();
119136
});
120137
}
121138

@@ -314,7 +331,6 @@ public void EnsureRootUser()
314331
}
315332
}
316333

317-
318334
public void UninstallCaddy()
319335
{
320336
Progress.Desc = "关闭Caddy服务";
@@ -751,35 +767,52 @@ private string GetInstallCmd(string soft)
751767

752768
private ConnectionInfo CreateConnectionInfo()
753769
{
754-
var authMethods = new List<AuthenticationMethod>();
755-
756-
if (!string.IsNullOrEmpty(_host.Password))
770+
try
757771
{
758-
authMethods.Add(new PasswordAuthenticationMethod(_host.UserName, _host.Password));
759-
}
772+
var authMethods = new List<AuthenticationMethod>();
760773

761-
if (_host.SecretType == LoginSecretType.PrivateKey)
762-
{
763-
authMethods.Add(new PrivateKeyAuthenticationMethod(_host.UserName, new PrivateKeyFile(_host.PrivateKeyPath)));
764-
}
774+
if (_host.SecretType == LoginSecretType.Password)
775+
{
776+
authMethods.Add(new PasswordAuthenticationMethod(_host.UserName, _host.Password));
777+
}
778+
779+
if (_host.SecretType == LoginSecretType.PrivateKey)
780+
{
781+
PrivateKeyFile keyFile;
782+
if (string.IsNullOrEmpty(_host.Password))
783+
{
784+
keyFile = new PrivateKeyFile(_host.PrivateKeyPath);
785+
}
786+
else
787+
{
788+
keyFile = new PrivateKeyFile(_host.PrivateKeyPath, _host.Password);
789+
}
790+
authMethods.Add(new PrivateKeyAuthenticationMethod(_host.UserName, keyFile));
791+
}
792+
793+
if (_host.Proxy.Type == ProxyTypes.None)
794+
{
795+
return new ConnectionInfo(
796+
host: _host.Address,
797+
username: _host.UserName,
798+
authenticationMethods: authMethods.ToArray());
799+
}
765800

766-
if (_host.Proxy.Type == ProxyTypes.None)
767-
{
768801
return new ConnectionInfo(
769802
host: _host.Address,
803+
port: _host.Port,
770804
username: _host.UserName,
805+
proxyType: _host.Proxy.Type,
806+
proxyHost: _host.Proxy.Address,
807+
proxyPort: _host.Proxy.Port,
808+
proxyUsername: _host.Proxy.UserName, proxyPassword: _host.Proxy.Password,
771809
authenticationMethods: authMethods.ToArray());
772810
}
773-
774-
return new ConnectionInfo(
775-
host: _host.Address,
776-
port: _host.Port,
777-
username: _host.UserName,
778-
proxyType: _host.Proxy.Type,
779-
proxyHost: _host.Proxy.Address,
780-
proxyPort: _host.Proxy.Port,
781-
proxyUsername: _host.Proxy.UserName, proxyPassword: _host.Proxy.Password,
782-
authenticationMethods: authMethods.ToArray());
811+
catch (Exception ex)
812+
{
813+
MessageBox.Show(ex.Message);
814+
return null;
815+
}
783816
}
784817
#endregion
785818
}

ProxySuper.Core/Services/TrojanGoService.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.Win32;
22
using ProxySuper.Core.Models.Hosts;
33
using ProxySuper.Core.Models.Projects;
4+
using ProxySuper.Core.ViewModels;
45
using System;
56
using System.Collections.Generic;
67
using System.ComponentModel;
@@ -93,6 +94,10 @@ public void Install()
9394
{
9495
Progress.Step = "安装成功,请上传您的 TLS 证书。";
9596
}
97+
else
98+
{
99+
NavigationService.Navigate<TrojanGoConfigViewModel, TrojanGoSettings>(Settings);
100+
}
96101
}
97102
catch (Exception ex)
98103
{
@@ -202,12 +207,12 @@ public void ApplyForCert()
202207
{
203208
try
204209
{
205-
EnsureRootUser();
206210

207211
Progress.Step = "续签证书";
208212
Progress.Percentage = 0;
209213

210214
Progress.Desc = "检测系统环境";
215+
EnsureRootUser();
211216
EnsureSystemEnv();
212217
Progress.Percentage = 20;
213218

0 commit comments

Comments
 (0)