mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Compare commits
5 Commits
2022.06.13
...
v1.77.2-de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15149f9e2c | ||
|
|
ab3d85b089 | ||
|
|
2f3a03eab7 | ||
|
|
629515b81a | ||
|
|
05c8da3ee4 |
@@ -28,6 +28,7 @@ namespace mRemoteNG.App.Info
|
||||
|
||||
//public static string ReportingFilePath = "";
|
||||
public static readonly string PuttyPath = HomePath + "\\PuTTYNG.exe";
|
||||
public static readonly string WinboxPath = HomePath + "\\winbox.exe";
|
||||
|
||||
public static string UserAgent
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using WeifenLuo.WinFormsUI.Docking;
|
||||
@@ -11,7 +11,7 @@ using mRemoteNG.Messages;
|
||||
using mRemoteNG.Tools;
|
||||
using mRemoteNG.UI.Controls;
|
||||
using mRemoteNG.UI.Forms;
|
||||
|
||||
using mRemoteNG.Connection.Protocol.Winbox;
|
||||
|
||||
namespace mRemoteNG.Config.Settings
|
||||
{
|
||||
@@ -69,6 +69,7 @@ namespace mRemoteNG.Config.Settings
|
||||
SetKioskMode();
|
||||
|
||||
SetPuttyPath();
|
||||
SetWinboxPath();
|
||||
SetShowSystemTrayIcon();
|
||||
SetAutoSave();
|
||||
LoadExternalAppsFromXml();
|
||||
@@ -169,6 +170,11 @@ namespace mRemoteNG.Config.Settings
|
||||
: GeneralAppInfo.PuttyPath;
|
||||
}
|
||||
|
||||
private static void SetWinboxPath()
|
||||
{
|
||||
ProtocolWinbox.WinboxPath = GeneralAppInfo.WinboxPath;
|
||||
}
|
||||
|
||||
private void EnsureSettingsAreSavedInNewestVersion()
|
||||
{
|
||||
if (Properties.Settings.Default.DoUpgrade)
|
||||
|
||||
@@ -18,6 +18,7 @@ using mRemoteNG.Properties;
|
||||
using mRemoteNG.Tree;
|
||||
using mRemoteNG.Resources.Language;
|
||||
using mRemoteNG.Tree.Root;
|
||||
using mRemoteNG.Connection.Protocol.Winbox;
|
||||
|
||||
|
||||
namespace mRemoteNG.Connection
|
||||
@@ -274,6 +275,8 @@ namespace mRemoteNG.Connection
|
||||
return (int)ProtocolPowerShell.Defaults.Port;
|
||||
case ProtocolType.IntApp:
|
||||
return (int)IntegratedProgram.Defaults.Port;
|
||||
case ProtocolType.Winbox:
|
||||
return (int)ProtocolWinbox.Defaults.Port;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -9,6 +9,7 @@ using System;
|
||||
using mRemoteNG.Connection.Protocol.PowerShell;
|
||||
using mRemoteNG.Properties;
|
||||
using mRemoteNG.Resources.Language;
|
||||
using mRemoteNG.Connection.Protocol.Winbox;
|
||||
|
||||
namespace mRemoteNG.Connection.Protocol
|
||||
{
|
||||
@@ -49,6 +50,8 @@ namespace mRemoteNG.Connection.Protocol
|
||||
throw (new Exception(Language.NoExtAppDefined));
|
||||
}
|
||||
return new IntegratedProgram();
|
||||
case ProtocolType.Winbox:
|
||||
return new ProtocolWinbox();
|
||||
}
|
||||
|
||||
return default(ProtocolBase);
|
||||
|
||||
@@ -36,6 +36,9 @@ namespace mRemoteNG.Connection.Protocol
|
||||
PowerShell = 10,
|
||||
|
||||
[LocalizedAttributes.LocalizedDescription(nameof(Language.ExternalTool))]
|
||||
IntApp = 20
|
||||
IntApp = 20,
|
||||
|
||||
[LocalizedAttributes.LocalizedDescription(nameof(Language.Winbox))]
|
||||
Winbox = 11
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using mRemoteNG.App;
|
||||
using mRemoteNG.Messages;
|
||||
using mRemoteNG.Security.SymmetricEncryption;
|
||||
using mRemoteNG.Tools.Cmdline;
|
||||
using mRemoteNG.UI;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using mRemoteNG.Resources.Language;
|
||||
using mRemoteNG.Properties;
|
||||
|
||||
namespace mRemoteNG.Connection.Protocol.Winbox
|
||||
{
|
||||
public class ProtocolWinbox : ProtocolBase
|
||||
{
|
||||
public ProtocolWinbox() { }
|
||||
|
||||
public enum Defaults
|
||||
{
|
||||
Port = 8291
|
||||
}
|
||||
|
||||
private const int IDM_RECONF = 0x50; // PuTTY Settings Menu ID
|
||||
private readonly DisplayProperties _display = new DisplayProperties();
|
||||
|
||||
#region Public Properties
|
||||
|
||||
|
||||
public IntPtr WinboxHandle { get; set; }
|
||||
|
||||
private Process WinboxProcess { get; set; }
|
||||
|
||||
public static string WinboxPath { get; set; }
|
||||
|
||||
public bool Focused
|
||||
{
|
||||
get { return NativeMethods.GetForegroundWindow() == WinboxHandle; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Events & Handlers
|
||||
|
||||
private void ProcessExited(object sender, EventArgs e)
|
||||
{
|
||||
Event_Closed(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public override bool Connect()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
WinboxProcess = new Process
|
||||
{
|
||||
StartInfo =
|
||||
{
|
||||
UseShellExecute = false,
|
||||
FileName = WinboxPath,
|
||||
RedirectStandardOutput = true
|
||||
}
|
||||
};
|
||||
|
||||
var arguments = new CommandLineArguments { EscapeForShell = false };
|
||||
|
||||
var username = "";
|
||||
var password = "";
|
||||
var host = InterfaceControl.Info.Hostname;
|
||||
|
||||
if (!string.IsNullOrEmpty(InterfaceControl.Info?.Username))
|
||||
{
|
||||
username = InterfaceControl.Info.Username;
|
||||
}
|
||||
else
|
||||
{
|
||||
// ReSharper disable once SwitchStatementMissingSomeCases
|
||||
switch (Settings.Default.EmptyCredentials)
|
||||
{
|
||||
case "windows":
|
||||
username = Environment.UserName;
|
||||
break;
|
||||
case "custom":
|
||||
username = Settings.Default.DefaultUsername;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(InterfaceControl.Info?.Password))
|
||||
{
|
||||
password = InterfaceControl.Info.Password;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Settings.Default.EmptyCredentials == "custom")
|
||||
{
|
||||
var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
|
||||
password = cryptographyProvider.Decrypt(Settings.Default.DefaultPassword,
|
||||
Runtime.EncryptionKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!InterfaceControl.Info.Port.Equals(Defaults.Port))
|
||||
{
|
||||
host += ":" + InterfaceControl.Info.Port.ToString();
|
||||
}
|
||||
arguments.Add(host, username, password);
|
||||
|
||||
WinboxProcess.StartInfo.Arguments = arguments.ToString();
|
||||
|
||||
WinboxProcess.EnableRaisingEvents = true;
|
||||
WinboxProcess.Exited += ProcessExited;
|
||||
|
||||
WinboxProcess.Start();
|
||||
WinboxProcess.WaitForInputIdle(Settings.Default.MaxPuttyWaitTime * 1000);
|
||||
while (!WinboxProcess.StandardOutput.EndOfStream)
|
||||
{
|
||||
var line = WinboxProcess.StandardOutput.ReadLine();
|
||||
Console.WriteLine(line);
|
||||
if (line.Contains("startServices done"))
|
||||
{
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.DebugMsg, "Winbox - Find connection done");
|
||||
break;
|
||||
}
|
||||
else if (line.Contains("disconnect"))
|
||||
{
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.DebugMsg, "Winbox - Cannot Connect");
|
||||
break;
|
||||
}
|
||||
}
|
||||
var startTicks = Environment.TickCount;
|
||||
while (WinboxHandle.ToInt32() == 0 &
|
||||
Environment.TickCount < startTicks + Settings.Default.MaxPuttyWaitTime * 1000)
|
||||
{
|
||||
WinboxHandle = NativeMethods.FindWindowEx(InterfaceControl.Handle, new IntPtr(0), null, null);
|
||||
WinboxProcess.Refresh();
|
||||
WinboxHandle = WinboxProcess.MainWindowHandle;
|
||||
if (WinboxHandle.ToInt32() == 0)
|
||||
{
|
||||
Thread.Sleep(0);
|
||||
}
|
||||
}
|
||||
|
||||
NativeMethods.SetParent(WinboxHandle, InterfaceControl.Handle);
|
||||
|
||||
Resize(this, new EventArgs());
|
||||
base.Connect();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.ConnectionFailed + Environment.NewLine + ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Focus()
|
||||
{
|
||||
try
|
||||
{
|
||||
NativeMethods.SetForegroundWindow(WinboxHandle);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.PuttyFocusFailed + Environment.NewLine + ex.Message, true);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Resize(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (InterfaceControl.Size == Size.Empty)
|
||||
return;
|
||||
|
||||
//NativeMethods.MoveWindow(WinboxHandle, 0, 0, InterfaceControl.Width, InterfaceControl.Height, true);
|
||||
var scaledFrameBorderHeight = _display.ScaleHeight(SystemInformation.FrameBorderSize.Height);
|
||||
var scaledFrameBorderWidth = _display.ScaleWidth(SystemInformation.FrameBorderSize.Width);
|
||||
|
||||
NativeMethods.MoveWindow(WinboxHandle, -scaledFrameBorderWidth,
|
||||
-(SystemInformation.CaptionHeight + scaledFrameBorderHeight),
|
||||
InterfaceControl.Width + scaledFrameBorderWidth * 2,
|
||||
InterfaceControl.Height + SystemInformation.CaptionHeight +
|
||||
scaledFrameBorderHeight * 2,
|
||||
true);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.PuttyResizeFailed + Environment.NewLine + ex.Message, true);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (WinboxProcess.HasExited == false)
|
||||
{
|
||||
WinboxProcess.Kill();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, "Winbox - Kill process failed" + Environment.NewLine + ex.Message, true);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
WinboxProcess.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.PuttyDisposeFailed + Environment.NewLine + ex.Message, true);
|
||||
}
|
||||
|
||||
base.Close();
|
||||
}
|
||||
|
||||
public void ShowSettingsDialog()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Enums
|
||||
|
||||
protected enum Winbox_Protocol
|
||||
{
|
||||
winbox = 0,
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
13
mRemoteNG/Language/Language.Designer.cs
generated
13
mRemoteNG/Language/Language.Designer.cs
generated
@@ -6353,7 +6353,18 @@ namespace mRemoteNG.Resources.Language {
|
||||
return ResourceManager.GetString("Windows", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Windows.
|
||||
/// </summary>
|
||||
internal static string Winbox
|
||||
{
|
||||
get
|
||||
{
|
||||
return ResourceManager.GetString("Winbox", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Working directory.
|
||||
/// </summary>
|
||||
|
||||
@@ -2223,4 +2223,7 @@ Nightly Channel includes Alphas, Betas & Release Candidates.</value>
|
||||
<data name="PropertyDescriptionEC2Region" xml:space="preserve">
|
||||
<value>fetch aws instance info from this region</value>
|
||||
</data>
|
||||
<data name="Winbox" xml:space="preserve">
|
||||
<value>Winbox</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -48,8 +48,9 @@ namespace mRemoteNG.UI.Tabs
|
||||
set
|
||||
{
|
||||
currentPanel = value;
|
||||
Runtime.MessageCollector.AddMessage(Messages.MessageClass.DebugMsg,
|
||||
"Panel got focused: " + currentPanel.TabText);
|
||||
//Disabled due to interaction with popups that would show this information and cause a softlock
|
||||
//Runtime.MessageCollector.AddMessage(Messages.MessageClass.DebugMsg,
|
||||
// "Panel got focused: " + currentPanel.TabText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace mRemoteNG.UI.Window
|
||||
new RootNodeExpander()
|
||||
};
|
||||
|
||||
if (Settings.Default.OpenConsFromLastSession && !Settings.Default.NoReconnect)
|
||||
if (Settings.Default.OpenConsFromLastSession && !Settings.Default.NoReconnect && !Settings.Default.AlwaysShowPanelSelectionDlg)
|
||||
actions.Add(new PreviousSessionOpener(Runtime.ConnectionInitiator));
|
||||
|
||||
ConnectionTree.PostSetupActions = actions;
|
||||
|
||||
BIN
mRemoteNG/winbox.exe
Normal file
BIN
mRemoteNG/winbox.exe
Normal file
Binary file not shown.
Reference in New Issue
Block a user