Skip to content

Commit ad6b86a

Browse files
committed
fix: fix some bugs
1 parent a957219 commit ad6b86a

File tree

5 files changed

+30
-54
lines changed

5 files changed

+30
-54
lines changed

Ui/Model/GlobalEventHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace _1RM.Model
1111
{
1212
public static class GlobalEventHelper
1313
{
14-
public delegate void OnRequestServerConnectDelegate(in ProtocolBase? server, in string fromView, in string assignTabToken = "", in string assignRunnerName = "", in string assignCredentialName = "");
14+
public delegate void OnRequestServerConnectDelegate(in ProtocolBase server, in string fromView, in string assignTabToken = "", in string assignRunnerName = "", in string assignCredentialName = "");
1515
public static OnRequestServerConnectDelegate? OnRequestQuickConnect { get; set; } = null;
1616
/// <summary>
1717
/// Invoke notify to open a new remote session to Tab with assignTabToken (if assignTabToken != null).

Ui/Model/Protocol/Base/ProtocolBaseWithAddressPortUserPwd.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public virtual bool ShowPrivateKeyInput()
107107
/// <returns></returns>
108108
public override string BuildConnectionId()
109109
{
110-
return $"{Id}_{Address}:{Port}({UserName})";
110+
return $"{Id}_{Address}:{Port}({MD5Helper.GetMd5Hash16BitString(Password)}@{UserName})";
111111
}
112112
}
113113
}

Ui/Model/ProtocolRunner/ExternalRunnerForSSH.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ public string ArgumentsForPrivateKey
2424
if (Params.ContainsKey(nameof(ArgumentsForPrivateKey)) == false)
2525
{
2626
Params.Add(nameof(ArgumentsForPrivateKey), value);
27-
RaisePropertyChanged();
2827

2928
}
3029
else if (Params.ContainsKey(nameof(ArgumentsForPrivateKey)) && Params[nameof(ArgumentsForPrivateKey)] != value)
3130
{
3231
Params[nameof(ArgumentsForPrivateKey)] = value;
33-
RaisePropertyChanged();
3432
}
33+
RaisePropertyChanged();
3534
}
3635
}
3736
}

Ui/Service/SessionControlService.cs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,9 @@ public int TabWindowCount
7474
public ConcurrentDictionary<string, HostBase> ConnectionId2Hosts => _connectionId2Hosts;
7575

7676

77-
private void OnRequestOpenConnection(in ProtocolBase? serverOrg, in string fromView, in string assignTabToken = "", in string assignRunnerName = "", in string assignCredentialName = "")
77+
private void OnRequestOpenConnection(in ProtocolBase serverOrg, in string fromView, in string assignTabToken = "", in string assignRunnerName = "", in string assignCredentialName = "")
7878
{
7979
CleanupProtocolsAndWindows();
80-
#region START MULTIPLE SESSION
81-
// if server == null, then start multiple sessions
82-
if (serverOrg == null)
83-
{
84-
var list = _appData.VmItemList
85-
.Where(x => x.IsSelected)
86-
.Select(x => x.Server)
87-
.ToArray();
88-
OnRequestOpenConnection(list, in fromView, in assignTabToken, in assignRunnerName, in assignCredentialName);
89-
MsAppCenterHelper.TraceSessionOpen($"multiple sessions ({((list.Length >= 5) ? ">=5" : list.Length.ToString())})", fromView);
90-
return;
91-
}
92-
#endregion
9380

9481
var org = serverOrg;
9582
var view = fromView;
@@ -137,33 +124,22 @@ private void OnRequestCloseConnection(string connectionId)
137124
}
138125

139126

140-
private bool ActivateOrReConnIfServerSessionIsOpened(in ProtocolBase server, Credential? assignCredential)
127+
private bool ActivateOrReConnIfServerSessionIsOpened(in ProtocolBase server)
141128
{
142129
if (!server.IsOnlyOneInstance()) return false;
143130
var connectionId = server.BuildConnectionId();
144131
// if is OnlyOneInstance Protocol and it is connected now, activate it and return.
145132
if (!_connectionId2Hosts.ContainsKey(connectionId))
146133
return false;
147134

148-
// FOR RDP with alternative account
149-
if (assignCredential != null)
150-
{
151-
if (_connectionId2Hosts[connectionId].ProtocolServer is ProtocolBaseWithAddressPort p
152-
&& assignCredential.Address != p.Address)
153-
return false;
154-
if (_connectionId2Hosts[connectionId].ProtocolServer is ProtocolBaseWithAddressPortUserPwd p2
155-
&& assignCredential.UserName != p2.UserName)
156-
return false;
157-
}
158-
159135
SimpleLogHelper.Debug($"_connectionId2Hosts ContainsKey {connectionId}");
160136
// Activate
161137
if (_connectionId2Hosts[connectionId].ParentWindow is { } win)
162138
{
163139
if (win is TabWindowView tab)
164140
{
165141
var serverId = server.Id;
166-
var s = tab.GetViewModel().Items.FirstOrDefault(x => x.Content?.ProtocolServer?.Id == serverId);
142+
var s = tab.GetViewModel().Items.FirstOrDefault(x => x.Content?.ProtocolServer?.BuildConnectionId() == connectionId);
167143
if (s != null)
168144
tab.GetViewModel().SelectedItem = s;
169145
}

Ui/Service/SessionControlService_OpenConnection.cs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,6 @@ private async Task<string> Connect(ProtocolBase protocol, string fromView, strin
179179
{
180180
string tabToken = "";
181181

182-
// if is OnlyOneInstance server and it is connected now, activate it and return.
183-
{
184-
Credential? assignCredential = null;
185-
if (!string.IsNullOrEmpty(assignCredentialName) && protocol is ProtocolBaseWithAddressPort p)
186-
assignCredential = p.AlternateCredentials.FirstOrDefault(x => x.Name == assignCredentialName);
187-
if (this.ActivateOrReConnIfServerSessionIsOpened(protocol, assignCredential))
188-
return tabToken;
189-
}
190-
191182
#region prepare
192183

193184
// trace source view
@@ -210,6 +201,26 @@ private async Task<string> Connect(ProtocolBase protocol, string fromView, strin
210201
// clone and decrypt!
211202
var protocolClone = protocol.Clone();
212203
protocolClone.ConnectPreprocess();
204+
205+
// apply alternate credential
206+
{
207+
if (protocolClone is ProtocolBaseWithAddressPort p)
208+
{
209+
var c = await GetCredential(p, assignCredentialName);
210+
if (c == null)
211+
{
212+
return tabToken;
213+
}
214+
215+
p.SetCredential(c);
216+
if (string.IsNullOrEmpty(assignCredentialName) == false)
217+
p.DisplayName += $" ({c.Name})";
218+
}
219+
}
220+
221+
222+
223+
// check if need to input password
213224
if (protocolClone is ProtocolBaseWithAddressPortUserPwd pb)
214225
{
215226
if (protocolClone is RDP || (protocolClone is SSH ssh && string.IsNullOrEmpty(ssh.PrivateKey)) || protocolClone is VNC || protocolClone is SFTP)
@@ -240,21 +251,11 @@ private async Task<string> Connect(ProtocolBase protocol, string fromView, strin
240251

241252
#endregion
242253

243-
// apply alternate credential
244-
{
245-
if (protocolClone is ProtocolBaseWithAddressPort p)
246-
{
247-
var c = await GetCredential(p, assignCredentialName);
248-
if (c == null)
249-
{
250-
return tabToken;
251-
}
252254

253-
p.SetCredential(c);
254-
if (string.IsNullOrEmpty(assignCredentialName) == false)
255-
p.DisplayName += $" ({c.Name})";
256-
}
257-
}
255+
// if is OnlyOneInstance server and it is connected now, activate it and return.
256+
if (this.ActivateOrReConnIfServerSessionIsOpened(protocolClone))
257+
return tabToken;
258+
258259

259260
// run script before connected
260261
{

0 commit comments

Comments
 (0)