feature: Add option to disable echo for Ssh Client Sessions

This commit is contained in:
Trevor Payne
2023-04-28 17:25:30 -05:00
parent 6797db101a
commit dc8d1b3286
2 changed files with 53 additions and 21 deletions

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
@@ -34,6 +35,8 @@ namespace PepperDash.Core
/// </summary> /// </summary>
public event EventHandler<GenericSocketStatusChageEventArgs> ConnectionChange; public event EventHandler<GenericSocketStatusChageEventArgs> ConnectionChange;
private Dictionary<TerminalModes, uint> _terminalModes = new Dictionary<TerminalModes, uint>();
///// <summary> ///// <summary>
///// /////
///// </summary> ///// </summary>
@@ -152,6 +155,30 @@ namespace PepperDash.Core
Password = password; Password = password;
AutoReconnectIntervalMs = 5000; AutoReconnectIntervalMs = 5000;
ReconnectTimer = new CTimer(o =>
{
if (ConnectEnabled)
{
Connect();
}
}, Timeout.Infinite);
}
/// <summary>
/// Constructor With Terminal Option \"Echo Off\".
/// </summary>
public GenericSshClient(string key, string hostname, int port, string username, string password, bool disableEcho) :
base(key)
{
StreamDebugging = new CommunicationStreamDebugging(key);
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
Key = key;
Hostname = hostname;
Port = port;
Username = username;
Password = password;
AutoReconnectIntervalMs = 5000;
if(disableEcho) _terminalModes.Add(TerminalModes.ECHO, 0);
ReconnectTimer = new CTimer(o => ReconnectTimer = new CTimer(o =>
{ {
if (ConnectEnabled) if (ConnectEnabled)
@@ -258,7 +285,7 @@ namespace PepperDash.Core
try try
{ {
Client.Connect(); Client.Connect();
TheStream = Client.CreateShellStream("PDTShell", 100, 80, 100, 200, 65534); TheStream = Client.CreateShellStream("PDTShell", 100, 80, 100, 200, 65534, _terminalModes);
TheStream.DataReceived += Stream_DataReceived; TheStream.DataReceived += Stream_DataReceived;
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Connected"); Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Connected");
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECTED; ClientStatus = SocketStatus.SOCKET_STATUS_CONNECTED;

View File

@@ -549,6 +549,11 @@ namespace PepperDash.Core
/// </summary> /// </summary>
public int AutoReconnectIntervalMs { get; set; } public int AutoReconnectIntervalMs { get; set; }
/// <summary>
/// Used to set TerminalMode.Echo to 0
/// </summary>
public bool DisableEcho { get; set; }
/// <summary> /// <summary>
/// Default constructor /// Default constructor
/// </summary> /// </summary>