Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mRemoteNG/mRemoteNG.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitrij <kvarkas@gmail.com>2022-01-18 14:31:23 +0300
committerDimitrij <kvarkas@gmail.com>2022-01-18 14:31:23 +0300
commit05c8da3ee48b781093fd4dfe5a8015471aa14848 (patch)
tree75da14214be33e92ee90dfc976b50790e6c9e614
parent859d12b450f74405d950f3c07c01ede6b9ef6033 (diff)
manual merge from Filippo125:add_winbox - save only
-rw-r--r--mRemoteNG/Config/Settings/SettingsLoader.cs14
-rw-r--r--mRemoteNG/Connection/ConnectionInfo.cs3
-rw-r--r--mRemoteNG/Connection/Protocol/ProtocolFactory.cs3
-rw-r--r--mRemoteNG/Connection/Protocol/ProtocolType.cs5
-rw-r--r--mRemoteNG/Connection/Protocol/Winbox/Connection.Protocol.Winbox.cs246
-rw-r--r--mRemoteNG/Language/Language.Designer.cs13
-rw-r--r--mRemoteNG/Language/Language.resx3
-rw-r--r--mRemoteNG/winbox.exebin0 -> 1660472 bytes
8 files changed, 283 insertions, 4 deletions
diff --git a/mRemoteNG/Config/Settings/SettingsLoader.cs b/mRemoteNG/Config/Settings/SettingsLoader.cs
index 180e9948..de84a1da 100644
--- a/mRemoteNG/Config/Settings/SettingsLoader.cs
+++ b/mRemoteNG/Config/Settings/SettingsLoader.cs
@@ -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,15 @@ namespace mRemoteNG.Config.Settings
: GeneralAppInfo.PuttyPath;
}
+ private static void SetWinboxPath()
+ {
+ ProtocolWinbox.WinboxPath = "C:\\Program Files (x86)\\winbox.exe";
+
+ // mRemoteNG.Settings.Default.UseCustomPuttyPath
+ // ? mRemoteNG.Settings.Default.CustomPuttyPath
+ // : GeneralAppInfo.PuttyPath;
+ }
+
private void EnsureSettingsAreSavedInNewestVersion()
{
if (Properties.Settings.Default.DoUpgrade)
diff --git a/mRemoteNG/Connection/ConnectionInfo.cs b/mRemoteNG/Connection/ConnectionInfo.cs
index 0fee759d..76c29b86 100644
--- a/mRemoteNG/Connection/ConnectionInfo.cs
+++ b/mRemoteNG/Connection/ConnectionInfo.cs
@@ -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;
diff --git a/mRemoteNG/Connection/Protocol/ProtocolFactory.cs b/mRemoteNG/Connection/Protocol/ProtocolFactory.cs
index 8f20464a..d7f692f7 100644
--- a/mRemoteNG/Connection/Protocol/ProtocolFactory.cs
+++ b/mRemoteNG/Connection/Protocol/ProtocolFactory.cs
@@ -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);
diff --git a/mRemoteNG/Connection/Protocol/ProtocolType.cs b/mRemoteNG/Connection/Protocol/ProtocolType.cs
index 6f4016fd..e7ad0162 100644
--- a/mRemoteNG/Connection/Protocol/ProtocolType.cs
+++ b/mRemoteNG/Connection/Protocol/ProtocolType.cs
@@ -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
}
} \ No newline at end of file
diff --git a/mRemoteNG/Connection/Protocol/Winbox/Connection.Protocol.Winbox.cs b/mRemoteNG/Connection/Protocol/Winbox/Connection.Protocol.Winbox.cs
new file mode 100644
index 00000000..8483fdc8
--- /dev/null
+++ b/mRemoteNG/Connection/Protocol/Winbox/Connection.Protocol.Winbox.cs
@@ -0,0 +1,246 @@
+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 = true,
+ FileName = WinboxPath
+ }
+ };
+
+ 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);
+
+ 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);
+
+ Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.PuttyStuff, true);
+ Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.PuttyHandle, WinboxHandle), true);
+ Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.PuttyTitle, WinboxProcess.MainWindowTitle), true);
+ //::TODO not found putty parent handle
+ //Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.PuttyParentHandle, InterfaceControl.Parent.Handle), true);
+
+ 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, Language.PuttyKillFailed + 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()
+ {
+ try
+ {
+ NativeMethods.PostMessage(WinboxHandle, NativeMethods.WM_SYSCOMMAND, (IntPtr)IDM_RECONF, (IntPtr)0);
+ NativeMethods.SetForegroundWindow(WinboxHandle);
+ }
+ catch (Exception ex)
+ {
+ Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.PuttyShowSettingsDialogFailed + Environment.NewLine + ex.Message, true);
+ }
+ }
+
+ #endregion
+
+ #region Enums
+
+ protected enum Winbox_Protocol
+ {
+ winbox = 0,
+ }
+
+
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/mRemoteNG/Language/Language.Designer.cs b/mRemoteNG/Language/Language.Designer.cs
index 8919ee23..47163e33 100644
--- a/mRemoteNG/Language/Language.Designer.cs
+++ b/mRemoteNG/Language/Language.Designer.cs
@@ -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>
diff --git a/mRemoteNG/Language/Language.resx b/mRemoteNG/Language/Language.resx
index 80427b75..8f968581 100644
--- a/mRemoteNG/Language/Language.resx
+++ b/mRemoteNG/Language/Language.resx
@@ -2223,4 +2223,7 @@ Nightly Channel includes Alphas, Betas &amp; 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> \ No newline at end of file
diff --git a/mRemoteNG/winbox.exe b/mRemoteNG/winbox.exe
new file mode 100644
index 00000000..e62079cc
--- /dev/null
+++ b/mRemoteNG/winbox.exe
Binary files differ