Skip to content

Commit dd9eedb

Browse files
authored
Feature: PuTTY parameter -hostkey added (BornToBeRoot#1977)
* Chore: Fix strings * Feature: PuTTY hostkey * Docs: Add BornToBeRoot#1977
1 parent c57b8d9 commit dd9eedb

14 files changed

Lines changed: 129 additions & 29 deletions

File tree

Source/NETworkManager.Localization/Resources/StaticStrings.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/NETworkManager.Localization/Resources/StaticStrings.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,10 @@
318318
<data name="ExampleTigerVNCPath" xml:space="preserve">
319319
<value>C:\Tools\TigerVNC\vncviewer64-1.12.0.exe</value>
320320
</data>
321+
<data name="ExampleHostkey" xml:space="preserve">
322+
<value>71:b8:f2:6e..., 13:59:a7...</value>
323+
</data>
324+
<data name="ExamplePuTTYProfile" xml:space="preserve">
325+
<value>NETworkManager</value>
326+
</data>
321327
</root>

Source/NETworkManager.Localization/Resources/Strings.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/NETworkManager.Localization/Resources/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,4 +3326,7 @@ If the option is disabled again, the values are no longer modified. However, the
33263326
<data name="PortState_TimedOut" xml:space="preserve">
33273327
<value>Timed out</value>
33283328
</data>
3329+
<data name="Hostkey" xml:space="preserve">
3330+
<value>Hostkey</value>
3331+
</data>
33293332
</root>

Source/NETworkManager.Models/PuTTY/PuTTY.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.Win32;
2+
using NETworkManager.Utilities;
23
using System;
34
using System.Collections.Generic;
45
using System.IO;
@@ -158,11 +159,20 @@ public static string BuildCommandLine(PuTTYSessionInfo sessionInfo)
158159

159160
// Private key
160161
if (!string.IsNullOrEmpty(sessionInfo.PrivateKey))
161-
command += $" -i {'"'}{sessionInfo.PrivateKey}{'"'}";
162+
command += $" -i \"{sessionInfo.PrivateKey}\"";
162163

163164
// Profile
164165
if (!string.IsNullOrEmpty(sessionInfo.Profile))
165-
command += $" -load {'"'}{sessionInfo.Profile}{'"'}";
166+
command += $" -load \"{sessionInfo.Profile}\"";
167+
168+
// Hostkey(s)
169+
if (!string.IsNullOrEmpty(sessionInfo.Hostkey))
170+
{
171+
var hostkeys = StringHelper.RemoveWhitespace(sessionInfo.Hostkey).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
172+
173+
foreach (var hostkey in hostkeys)
174+
command += $" -hostkey \"{hostkey}\"";
175+
}
166176

167177
// Log
168178
if (sessionInfo.EnableLog)

Source/NETworkManager.Models/PuTTY/PuTTYSessionInfo.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public class PuTTYSessionInfo
4040
/// </summary>
4141
public string Profile { get; set; }
4242

43+
/// <summary>
44+
/// PuTTY host key. Multiple keys are separated by a comma.
45+
/// </summary>
46+
public string Hostkey { get; set; }
47+
4348
/// <summary>
4449
/// Enables session log.
4550
/// </summary>

Source/NETworkManager.Profiles/Application/PuTTY.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public static PuTTYSessionInfo CreateSessionInfo(ProfileInfo profile)
2020
Username = profile.PuTTY_OverrideUsername ? profile.PuTTY_Username : (group.PuTTY_OverrideUsername ? group.PuTTY_Username : SettingsManager.Current.PuTTY_Username),
2121
PrivateKey = profile.PuTTY_OverridePrivateKeyFile ? profile.PuTTY_PrivateKeyFile : (group.PuTTY_OverridePrivateKeyFile ? group.PuTTY_PrivateKeyFile : SettingsManager.Current.PuTTY_PrivateKeyFile),
2222
Profile = profile.PuTTY_OverrideProfile ? profile.PuTTY_Profile : (group.PuTTY_OverrideProfile ? group.PuTTY_Profile : SettingsManager.Current.PuTTY_Profile),
23+
Hostkey = profile.PuTTY_OverrideHostkey ? profile.PuTTY_Hostkey : "",
2324
EnableLog = profile.PuTTY_OverrideEnableLog ? profile.PuTTY_EnableLog : (group.PuTTY_OverrideEnableLog ? group.PuTTY_EnableLog : SettingsManager.Current.PuTTY_EnableSessionLog),
2425
LogMode = profile.PuTTY_OverrideLogMode ? profile.PuTTY_LogMode : (group.PuTTY_OverrideLogMode ? group.PuTTY_LogMode : SettingsManager.Current.PuTTY_LogMode),
2526
LogPath = profile.PuTTY_OverrideLogPath ? profile.PuTTY_LogPath : (group.PuTTY_OverrideLogPath ? group.PuTTY_LogPath : Settings.Application.PuTTY.LogPath),

Source/NETworkManager.Profiles/ProfileInfo.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ public class ProfileInfo
154154
public string PuTTY_PrivateKeyFile { get; set; }
155155
public bool PuTTY_OverrideProfile { get; set; }
156156
public string PuTTY_Profile { get; set; }
157+
public bool PuTTY_OverrideHostkey { get; set; }
158+
public string PuTTY_Hostkey { get; set; }
157159
public bool PuTTY_OverrideEnableLog { get; set; }
158160
public bool PuTTY_EnableLog { get; set; }
159161
public bool PuTTY_OverrideLogMode { get; set; }
@@ -307,7 +309,7 @@ public ProfileInfo(ProfileInfo profile)
307309
RemoteDesktop_MenuAndWindowAnimation = profile.RemoteDesktop_MenuAndWindowAnimation;
308310
RemoteDesktop_OverrideVisualStyles = profile.RemoteDesktop_OverrideVisualStyles;
309311
RemoteDesktop_VisualStyles = profile.RemoteDesktop_VisualStyles;
310-
312+
311313
// PowerShell
312314
PowerShell_Enabled = profile.PowerShell_Enabled;
313315
PowerShell_EnableRemoteConsole = profile.PowerShell_EnableRemoteConsole;
@@ -333,6 +335,8 @@ public ProfileInfo(ProfileInfo profile)
333335
PuTTY_PrivateKeyFile = profile.PuTTY_PrivateKeyFile;
334336
PuTTY_OverrideProfile = profile.PuTTY_OverrideProfile;
335337
PuTTY_Profile = profile.PuTTY_Profile;
338+
PuTTY_OverrideHostkey = profile.PuTTY_OverrideHostkey;
339+
PuTTY_Hostkey = profile.PuTTY_Hostkey;
336340
PuTTY_OverrideEnableLog = profile.PuTTY_OverrideEnableLog;
337341
PuTTY_EnableLog = profile.PuTTY_EnableLog;
338342
PuTTY_OverrideLogMode = profile.PuTTY_OverrideLogMode;
@@ -374,6 +378,6 @@ public ProfileInfo(ProfileInfo profile)
374378
Whois_Enabled = profile.Whois_Enabled;
375379
Whois_InheritHost = profile.Whois_InheritHost;
376380
Whois_Domain = profile.Whois_Domain;
377-
}
381+
}
378382
}
379383
}

Source/NETworkManager.Settings/SettingsManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,19 +266,19 @@ public static void Upgrade(Version fromVersion, Version toVersion)
266266

267267
if (portProfileFound == null)
268268
{
269-
_log.Info($"Add PortScanner_PortProfiles \"{portProfile.Name}\"...");
269+
_log.Info($"Add \"{portProfile.Name}\" to \"PortScanner_PortProfiles\"...");
270270
Current.PortScanner_PortProfiles.Add(portProfile);
271271
}
272272
else if (!portProfile.Ports.Equals(portProfileFound.Ports))
273273
{
274-
_log.Info($"Update PortScanner_PortProfiles \"{portProfile.Name}\"...");
274+
_log.Info($"Update \"{portProfile.Name}\" in \"PortScanner_PortProfiles\"...");
275275
Current.PortScanner_PortProfiles.Remove(portProfileFound);
276276
Current.PortScanner_PortProfiles.Add(portProfile);
277277
}
278278
}
279279

280280
// Add new DNS lookup profiles
281-
_log.Info("Set \"DNSLookup_DNSServers_v2\" to default...");
281+
_log.Info("Init \"DNSLookup_DNSServers_v2\" with default DNS servers...");
282282
Current.DNSLookup_DNSServers_v2 = new ObservableCollection<DNSServerConnectionInfoProfile>(DNSServer.GetDefaultList());
283283
}
284284

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Text.RegularExpressions;
2+
3+
namespace NETworkManager.Utilities
4+
{
5+
public static class StringHelper
6+
{
7+
/// <summary>
8+
/// Method to remove whitespaces from a string.
9+
/// </summary>
10+
/// <param name="input">Text with whitespaces.</param>
11+
/// <returns>Text without whitespaces.</returns>
12+
public static string RemoveWhitespace(string input)
13+
{
14+
return Regex.Replace(input, @"\s+", "");
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)