Skip to content

Commit 82e5b77

Browse files
authored
Issue 278 putty log (BornToBeRoot#280)
* PuTTY logging added * Update
1 parent c861d72 commit 82e5b77

26 files changed

Lines changed: 370 additions & 66 deletions

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

Lines changed: 27 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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,4 +2851,13 @@ URL: https://github.com/BornToBeRoot/NETworkManager/tree/master/Documentation</v
28512851
<data name="SettingsViewName_Window" xml:space="preserve">
28522852
<value>Window</value>
28532853
</data>
2854+
<data name="EnableSessionLog" xml:space="preserve">
2855+
<value>Enable session log</value>
2856+
</data>
2857+
<data name="SessionLogFileName" xml:space="preserve">
2858+
<value>Session log file name</value>
2859+
</data>
2860+
<data name="SessionLogPath" xml:space="preserve">
2861+
<value>Session log path</value>
2862+
</data>
28542863
</root>

Source/NETworkManager.Models/PuTTY/PuTTY.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public static string BuildCommandLine(PuTTYSessionInfo profileInfo)
3434
if (!string.IsNullOrEmpty(profileInfo.Username))
3535
command += $" -l {profileInfo.Username}";
3636

37+
// Session log
38+
if (profileInfo.EnableSessionLog)
39+
command += $" -sessionlog {'"'}{ profileInfo.SessionLogFullName}{'"'}";
40+
3741
// Additional commands
3842
if (!string.IsNullOrEmpty(profileInfo.AdditionalCommandLine))
3943
command += $" {profileInfo.AdditionalCommandLine}";

Source/NETworkManager.Models/PuTTY/PuTTYSessionInfo.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,59 @@
22

33
namespace NETworkManager.Models.PuTTY
44
{
5+
/// <summary>
6+
/// Stores informations about a putty session.
7+
/// </summary>
58
public class PuTTYSessionInfo
69
{
10+
/// <summary>
11+
/// Full path to the PuTTY.exe on the filesystem.
12+
/// </summary>
713
public string ApplicationFilePath { get; set; }
14+
15+
/// <summary>
16+
/// Mode (SSH, Telnet, etc.), which is used to establish the connection.
17+
/// </summary>
818
public ConnectionMode Mode { get; set; }
19+
20+
/// <summary>
21+
/// Hostname or SerialLine. Depends on the <see cref="ConnectionMode"/>.
22+
/// </summary>
923
public string HostOrSerialLine { get; set; }
24+
25+
/// <summary>
26+
/// Port or Baud. Depends on the <see cref="ConnectionMode"/>.
27+
/// </summary>
1028
public int PortOrBaud { get; set; }
11-
public string Profile { get; set; }
29+
30+
/// <summary>
31+
/// Username for login.
32+
/// </summary>
1233
public string Username { get; set; }
34+
35+
/// <summary>
36+
/// PuTTY profile to use.
37+
/// </summary>
38+
public string Profile { get; set; }
39+
40+
/// <summary>
41+
/// Enables session log.
42+
/// </summary>
43+
public bool EnableSessionLog { get; set; }
44+
45+
/// <summary>
46+
/// Path and filename of the session log file (e.g. "C:\..\PuTTY.log").
47+
/// </summary>
48+
public string SessionLogFullName { get; set; }
49+
50+
/// <summary>
51+
/// Additional command line argument. Everything putty can handle.
52+
/// </summary>
1353
public string AdditionalCommandLine { get; set; }
1454

55+
/// <summary>
56+
/// Initializes a new instance of the <see cref="PuTTYSessionInfo"/> class.
57+
/// </summary>
1558
public PuTTYSessionInfo()
1659
{
1760

Source/NETworkManager.Profiles/Application/PuTTY.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using NETworkManager.Models.PuTTY;
22
using NETworkManager.Settings;
3+
using System.IO;
4+
using System;
35

46
namespace NETworkManager.Profiles.Application
57
{
@@ -14,6 +16,8 @@ public static PuTTYSessionInfo CreateSessionInfo(ProfileInfo profileInfo)
1416
PortOrBaud = profileInfo.PuTTY_OverridePortOrBaud ? profileInfo.PuTTY_PortOrBaud : Settings.Application.PuTTY.GetPortOrBaudByConnectionMode(profileInfo.PuTTY_ConnectionMode),
1517
Username = profileInfo.PuTTY_OverrideUsername ? profileInfo.PuTTY_Username : SettingsManager.Current.PuTTY_Username,
1618
Profile = profileInfo.PuTTY_OverrideProfile ? profileInfo.PuTTY_Profile : SettingsManager.Current.PuTTY_Profile,
19+
EnableSessionLog = profileInfo.PuTTY_OverrideEnableSessionLog ? profileInfo.PuTTY_EnableSessionLog : SettingsManager.Current.PuTTY_EnableSessionLog,
20+
SessionLogFullName = Environment.ExpandEnvironmentVariables(Path.Combine(SettingsManager.Current.PuTTY_SessionLogPath, profileInfo.PuTTY_OverrideSessionLogFileName ? profileInfo.PuTTY_SessionLogFileName : SettingsManager.Current.PuTTY_SessionLogFileName)),
1721
AdditionalCommandLine = profileInfo.PuTTY_OverrideAdditionalCommandLine ? profileInfo.PuTTY_AdditionalCommandLine : SettingsManager.Current.PuTTY_AdditionalCommandLine
1822
};
1923

Source/NETworkManager.Profiles/NETworkManager.Profiles.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<DefineConstants>DEBUG;TRACE</DefineConstants>
2222
<ErrorReport>prompt</ErrorReport>
2323
<WarningLevel>4</WarningLevel>
24+
<DocumentationFile>bin\Debug\NETworkManager.Profiles.xml</DocumentationFile>
2425
</PropertyGroup>
2526
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2627
<DebugType>pdbonly</DebugType>

Source/NETworkManager.Profiles/ProfileInfo.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,13 @@ public class ProfileInfo
124124
public string PuTTY_Username { get; set; }
125125
public bool PuTTY_OverrideProfile { get; set; }
126126
public string PuTTY_Profile { get; set; }
127+
public bool PuTTY_OverrideEnableSessionLog { get; set; }
128+
public bool PuTTY_EnableSessionLog { get; set; }
129+
public bool PuTTY_OverrideSessionLogFileName { get; set; }
130+
public string PuTTY_SessionLogFileName { get; set; } = GlobalStaticConfiguration.PuTTY_SessionLogFileName;
127131
public bool PuTTY_OverrideAdditionalCommandLine { get; set; }
128132
public string PuTTY_AdditionalCommandLine { get; set; }
133+
129134

130135
public bool TigerVNC_Enabled { get; set; }
131136
public bool TigerVNC_InheritHost { get; set; } = true;
@@ -149,6 +154,9 @@ public class ProfileInfo
149154
public bool Whois_InheritHost { get; set; } = true;
150155
public string Whois_Domain { get; set; }
151156

157+
/// <summary>
158+
/// Initializes a new instance of the<see cref="ProfileInfo"/> class.
159+
/// </summary>
152160
public ProfileInfo()
153161
{
154162

Source/NETworkManager.Profiles/ProfileManager.cs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
namespace NETworkManager.Profiles
1212
{
13-
/// <summary>
14-
///
15-
/// </summary>
1613
public static class ProfileManager
1714
{
1815
#region Variables
@@ -36,24 +33,12 @@ public static class ProfileManager
3633
/// </summary>
3734
public static string ProfilesEncryptionIdentifier => ".encrypted";
3835

39-
/// <summary>
40-
///
41-
/// </summary>
4236
public static string TagIdentifier => "tag=";
4337

44-
/// <summary>
45-
///
46-
/// </summary>
4738
public static ObservableCollection<ProfileFileInfo> ProfileFiles { get; set; } = new ObservableCollection<ProfileFileInfo>();
4839

49-
/// <summary>
50-
///
51-
/// </summary>
5240
private static ProfileFileInfo _profileFileInfo;
5341

54-
/// <summary>
55-
///
56-
/// </summary>
5742
public static ProfileFileInfo LoadedProfileFile
5843
{
5944
get => _profileFileInfo;
@@ -66,25 +51,12 @@ public static ProfileFileInfo LoadedProfileFile
6651
}
6752
}
6853

69-
/// <summary>
70-
///
71-
/// </summary>
7254
public static ObservableCollection<ProfileInfo> Profiles { get; set; } = new ObservableCollection<ProfileInfo>();
73-
74-
/// <summary>
75-
///
76-
/// </summary>
55+
7756
public static bool ProfilesChanged { get; set; }
7857

79-
/// <summary>
80-
///
81-
/// </summary>
8258
public static event EventHandler<ProfileFileInfoArgs> OnProfileFileChangedEvent;
8359

84-
/// <summary>
85-
///
86-
/// </summary>
87-
/// <param name="profileFileInfo"></param>
8860
private static void ProfileFileChanged(ProfileFileInfo profileFileInfo)
8961
{
9062
OnProfileFileChangedEvent?.Invoke(null, new ProfileFileInfoArgs(profileFileInfo));
@@ -118,10 +90,6 @@ public static string GetPortableProfilesLocation()
11890
return Path.Combine(Path.GetDirectoryName(AssemblyManager.Current.Location) ?? throw new InvalidOperationException(), ProfilesFolderName);
11991
}
12092

121-
/// <summary>
122-
///
123-
/// </summary>
124-
/// <returns></returns>
12593
public static string GetProfilesLocation()
12694
{
12795
return ConfigurationManager.Current.IsPortable ? GetPortableProfilesLocation() : GetProfilesLocationNotPortable();

Source/NETworkManager.Settings/GlobalStaticConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ public static class GlobalStaticConfiguration
118118

119119
// Application: PuTTY
120120
public static PuTTY.ConnectionMode PuTTY_DefaultConnectionMode => PuTTY.ConnectionMode.SSH;
121+
public static string PuTTY_SessionLogPath => Path.Combine("%LocalAppData%", AssemblyManager.Current.Name, "PuTTY_LogFiles");
122+
public static string PuTTY_SessionLogFileName => "&H_&Y-&M-&D_&T.log";
121123
public static int PuTTY_SSHPort => 22;
122124
public static string PuTTY_SerialLine => "COM1";
123125
public static int PuTTY_TelnetPort => 23;

Source/NETworkManager.Settings/SettingsInfo.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,6 +2589,51 @@ public string PuTTY_Profile
25892589
}
25902590
}
25912591

2592+
private bool _puTTY_EnableSessionLog;
2593+
public bool PuTTY_EnableSessionLog
2594+
{
2595+
get => _puTTY_EnableSessionLog;
2596+
set
2597+
{
2598+
if (value == _puTTY_EnableSessionLog)
2599+
return;
2600+
2601+
_puTTY_EnableSessionLog = value;
2602+
OnPropertyChanged();
2603+
SettingsChanged = true;
2604+
}
2605+
}
2606+
2607+
private string _puTTY_SessionLogPath = GlobalStaticConfiguration.PuTTY_SessionLogPath;
2608+
public string PuTTY_SessionLogPath
2609+
{
2610+
get => _puTTY_SessionLogPath;
2611+
set
2612+
{
2613+
if (value == _puTTY_SessionLogPath)
2614+
return;
2615+
2616+
_puTTY_SessionLogPath = value;
2617+
OnPropertyChanged();
2618+
SettingsChanged = true;
2619+
}
2620+
}
2621+
2622+
private string _puTTY_SessionLogFileName = GlobalStaticConfiguration.PuTTY_SessionLogFileName;
2623+
public string PuTTY_SessionLogFileName
2624+
{
2625+
get => _puTTY_SessionLogFileName;
2626+
set
2627+
{
2628+
if (value == _puTTY_SessionLogFileName)
2629+
return;
2630+
2631+
_puTTY_SessionLogFileName = value;
2632+
OnPropertyChanged();
2633+
SettingsChanged = true;
2634+
}
2635+
}
2636+
25922637
private string _puTTY_AdditionalCommandLine;
25932638
public string PuTTY_AdditionalCommandLine
25942639
{

0 commit comments

Comments
 (0)