mirror of
https://github.com/Ylianst/MeshCentralRouter
synced 2025-12-06 00:13:33 +00:00
Merge branch 'master' into develop
This commit is contained in:
3
AddPortMapForm.Designer.cs
generated
3
AddPortMapForm.Designer.cs
generated
@@ -88,6 +88,7 @@
|
||||
this.nodeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.nodeComboBox.FormattingEnabled = true;
|
||||
this.nodeComboBox.Name = "nodeComboBox";
|
||||
this.nodeComboBox.Sorted = true;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
@@ -137,6 +138,7 @@
|
||||
resources.GetString("appComboBox.Items4"),
|
||||
resources.GetString("appComboBox.Items5")});
|
||||
this.appComboBox.Name = "appComboBox";
|
||||
this.appComboBox.Sorted = true;
|
||||
this.appComboBox.SelectedIndexChanged += new System.EventHandler(this.appComboBox_SelectedIndexChanged);
|
||||
//
|
||||
// label5
|
||||
@@ -150,6 +152,7 @@
|
||||
this.groupComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.groupComboBox.FormattingEnabled = true;
|
||||
this.groupComboBox.Name = "groupComboBox";
|
||||
this.groupComboBox.Sorted = true;
|
||||
this.groupComboBox.SelectedIndexChanged += new System.EventHandler(this.groupComboBox_SelectedIndexChanged);
|
||||
//
|
||||
// label6
|
||||
|
||||
@@ -105,8 +105,8 @@ namespace MeshCentralRouter
|
||||
{
|
||||
if (appComboBox.SelectedIndex == 1) { remoteNumericUpDown.Value = 80; }
|
||||
if (appComboBox.SelectedIndex == 2) { remoteNumericUpDown.Value = 443; }
|
||||
if (appComboBox.SelectedIndex == 3) { remoteNumericUpDown.Value = 3389; }
|
||||
if (appComboBox.SelectedIndex == 4) { remoteNumericUpDown.Value = 22; }
|
||||
if (appComboBox.SelectedIndex == 3) { remoteNumericUpDown.Value = 22; }
|
||||
if (appComboBox.SelectedIndex == 4) { remoteNumericUpDown.Value = 3389; }
|
||||
if (appComboBox.SelectedIndex == 5) { remoteNumericUpDown.Value = 22; }
|
||||
}
|
||||
|
||||
|
||||
@@ -373,10 +373,10 @@
|
||||
<value>HTTPS</value>
|
||||
</data>
|
||||
<data name="appComboBox.Items3" xml:space="preserve">
|
||||
<value>RDP</value>
|
||||
<value>PuTTY</value>
|
||||
</data>
|
||||
<data name="appComboBox.Items4" xml:space="preserve">
|
||||
<value>PuTTY</value>
|
||||
<value>RDP</value>
|
||||
</data>
|
||||
<data name="appComboBox.Items5" xml:space="preserve">
|
||||
<value>WinSCP</value>
|
||||
@@ -534,6 +534,9 @@
|
||||
<data name=">>udpRadioButton.ZOrder" xml:space="preserve">
|
||||
<value>2</value>
|
||||
</data>
|
||||
<metadata name="mainToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<data name="nameTextBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
|
||||
<value>Top, Left, Right</value>
|
||||
</data>
|
||||
@@ -546,9 +549,6 @@
|
||||
<data name="nameTextBox.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>20</value>
|
||||
</data>
|
||||
<metadata name="mainToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<data name="nameTextBox.ToolTip" xml:space="preserve">
|
||||
<value>Optional mapping name</value>
|
||||
</data>
|
||||
@@ -564,9 +564,6 @@
|
||||
<data name=">>nameTextBox.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<metadata name="mainToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<data name="label8.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
</data>
|
||||
@@ -600,6 +597,9 @@
|
||||
<data name=">>label8.ZOrder" xml:space="preserve">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<metadata name="mainToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
|
||||
3
AddRelayMapForm.Designer.cs
generated
3
AddRelayMapForm.Designer.cs
generated
@@ -90,6 +90,7 @@
|
||||
this.nodeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.nodeComboBox.FormattingEnabled = true;
|
||||
this.nodeComboBox.Name = "nodeComboBox";
|
||||
this.nodeComboBox.Sorted = true;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
@@ -139,6 +140,7 @@
|
||||
resources.GetString("appComboBox.Items4"),
|
||||
resources.GetString("appComboBox.Items5")});
|
||||
this.appComboBox.Name = "appComboBox";
|
||||
this.appComboBox.Sorted = true;
|
||||
this.appComboBox.SelectedIndexChanged += new System.EventHandler(this.appComboBox_SelectedIndexChanged);
|
||||
//
|
||||
// label5
|
||||
@@ -163,6 +165,7 @@
|
||||
this.groupComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.groupComboBox.FormattingEnabled = true;
|
||||
this.groupComboBox.Name = "groupComboBox";
|
||||
this.groupComboBox.Sorted = true;
|
||||
this.groupComboBox.SelectedIndexChanged += new System.EventHandler(this.groupComboBox_SelectedIndexChanged);
|
||||
//
|
||||
// udpRadioButton
|
||||
|
||||
@@ -107,8 +107,8 @@ namespace MeshCentralRouter
|
||||
{
|
||||
if (appComboBox.SelectedIndex == 1) { remoteNumericUpDown.Value = 80; }
|
||||
if (appComboBox.SelectedIndex == 2) { remoteNumericUpDown.Value = 443; }
|
||||
if (appComboBox.SelectedIndex == 3) { remoteNumericUpDown.Value = 3389; }
|
||||
if (appComboBox.SelectedIndex == 4) { remoteNumericUpDown.Value = 22; }
|
||||
if (appComboBox.SelectedIndex == 3) { remoteNumericUpDown.Value = 22; }
|
||||
if (appComboBox.SelectedIndex == 4) { remoteNumericUpDown.Value = 3389; }
|
||||
if (appComboBox.SelectedIndex == 5) { remoteNumericUpDown.Value = 22; }
|
||||
}
|
||||
|
||||
|
||||
@@ -373,10 +373,10 @@
|
||||
<value>HTTPS</value>
|
||||
</data>
|
||||
<data name="appComboBox.Items3" xml:space="preserve">
|
||||
<value>RDP</value>
|
||||
<value>PuTTY</value>
|
||||
</data>
|
||||
<data name="appComboBox.Items4" xml:space="preserve">
|
||||
<value>PuTTY</value>
|
||||
<value>RDP</value>
|
||||
</data>
|
||||
<data name="appComboBox.Items5" xml:space="preserve">
|
||||
<value>WinSCP</value>
|
||||
@@ -591,6 +591,9 @@
|
||||
<data name=">>label7.ZOrder" xml:space="preserve">
|
||||
<value>4</value>
|
||||
</data>
|
||||
<metadata name="mainToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<data name="nameTextBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
|
||||
<value>Top, Left, Right</value>
|
||||
</data>
|
||||
@@ -603,9 +606,6 @@
|
||||
<data name="nameTextBox.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>18</value>
|
||||
</data>
|
||||
<metadata name="mainToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<data name="nameTextBox.ToolTip" xml:space="preserve">
|
||||
<value>Optional mapping name</value>
|
||||
</data>
|
||||
@@ -654,6 +654,9 @@
|
||||
<data name=">>label8.ZOrder" xml:space="preserve">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<metadata name="mainToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
|
||||
149
DeviceSettingsForm.Designer.cs
generated
Normal file
149
DeviceSettingsForm.Designer.cs
generated
Normal file
@@ -0,0 +1,149 @@
|
||||
namespace MeshCentralRouter
|
||||
{
|
||||
partial class DeviceSettingsForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DeviceSettingsForm));
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.doubleClickComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.okButton = new System.Windows.Forms.Button();
|
||||
this.cancelButton = new System.Windows.Forms.Button();
|
||||
this.systemTrayCheckBox = new System.Windows.Forms.CheckBox();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.groupBox1.Controls.Add(this.systemTrayCheckBox);
|
||||
this.groupBox1.Controls.Add(this.doubleClickComboBox);
|
||||
this.groupBox1.Controls.Add(this.label1);
|
||||
this.groupBox1.Location = new System.Drawing.Point(12, 12);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(294, 99);
|
||||
this.groupBox1.TabIndex = 5;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Settings";
|
||||
//
|
||||
// doubleClickComboBox
|
||||
//
|
||||
this.doubleClickComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.doubleClickComboBox.FormattingEnabled = true;
|
||||
this.doubleClickComboBox.Items.AddRange(new object[] {
|
||||
"Add Map...",
|
||||
"Add Relay Map...",
|
||||
"Remote Desktop...",
|
||||
"Remote Files...",
|
||||
"HTTP",
|
||||
"HTTPS",
|
||||
"SSH",
|
||||
"SCP"});
|
||||
this.doubleClickComboBox.Location = new System.Drawing.Point(14, 43);
|
||||
this.doubleClickComboBox.Name = "doubleClickComboBox";
|
||||
this.doubleClickComboBox.Size = new System.Drawing.Size(267, 21);
|
||||
this.doubleClickComboBox.TabIndex = 1;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(12, 24);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(100, 13);
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "Double Click Action";
|
||||
//
|
||||
// okButton
|
||||
//
|
||||
this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.okButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||
this.okButton.Location = new System.Drawing.Point(150, 117);
|
||||
this.okButton.Name = "okButton";
|
||||
this.okButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.okButton.TabIndex = 4;
|
||||
this.okButton.Text = "OK";
|
||||
this.okButton.UseVisualStyleBackColor = true;
|
||||
this.okButton.Click += new System.EventHandler(this.okButton_Click);
|
||||
//
|
||||
// cancelButton
|
||||
//
|
||||
this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
this.cancelButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||
this.cancelButton.Location = new System.Drawing.Point(231, 117);
|
||||
this.cancelButton.Name = "cancelButton";
|
||||
this.cancelButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.cancelButton.TabIndex = 3;
|
||||
this.cancelButton.Text = "Cancel";
|
||||
this.cancelButton.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// systemTrayCheckBox
|
||||
//
|
||||
this.systemTrayCheckBox.AutoSize = true;
|
||||
this.systemTrayCheckBox.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||
this.systemTrayCheckBox.Location = new System.Drawing.Point(14, 70);
|
||||
this.systemTrayCheckBox.Name = "systemTrayCheckBox";
|
||||
this.systemTrayCheckBox.Size = new System.Drawing.Size(123, 17);
|
||||
this.systemTrayCheckBox.TabIndex = 2;
|
||||
this.systemTrayCheckBox.Text = "Show on system tray";
|
||||
this.systemTrayCheckBox.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// DeviceSettingsForm
|
||||
//
|
||||
this.AcceptButton = this.okButton;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.CancelButton = this.cancelButton;
|
||||
this.ClientSize = new System.Drawing.Size(318, 152);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Controls.Add(this.okButton);
|
||||
this.Controls.Add(this.cancelButton);
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "DeviceSettingsForm";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
this.Text = "Device Settings";
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.Button okButton;
|
||||
private System.Windows.Forms.Button cancelButton;
|
||||
private System.Windows.Forms.ComboBox doubleClickComboBox;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.CheckBox systemTrayCheckBox;
|
||||
}
|
||||
}
|
||||
38
DeviceSettingsForm.cs
Normal file
38
DeviceSettingsForm.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace MeshCentralRouter
|
||||
{
|
||||
public partial class DeviceSettingsForm : Form
|
||||
{
|
||||
public DeviceSettingsForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
doubleClickComboBox.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
public int deviceDoubleClickAction
|
||||
{
|
||||
get { return doubleClickComboBox.SelectedIndex; }
|
||||
set { doubleClickComboBox.SelectedIndex = value; }
|
||||
}
|
||||
|
||||
public bool ShowSystemTray
|
||||
{
|
||||
get { return systemTrayCheckBox.Checked; }
|
||||
set { systemTrayCheckBox.Checked = value; }
|
||||
}
|
||||
|
||||
private void okButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
1815
DeviceSettingsForm.resx
Normal file
1815
DeviceSettingsForm.resx
Normal file
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Collections;
|
||||
using System.Windows.Forms;
|
||||
using System.Collections.Generic;
|
||||
@@ -243,6 +244,30 @@ namespace MeshCentralRouter
|
||||
private void MainForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
updateLocalFileView();
|
||||
|
||||
// Restore Window Location
|
||||
string locationStr = getRegValue("filelocation", "");
|
||||
if (locationStr != null)
|
||||
{
|
||||
string[] locationSplit = locationStr.Split(',');
|
||||
if (locationSplit.Length == 4)
|
||||
{
|
||||
try
|
||||
{
|
||||
var x = int.Parse(locationSplit[0]);
|
||||
var y = int.Parse(locationSplit[1]);
|
||||
var w = int.Parse(locationSplit[2]);
|
||||
var h = int.Parse(locationSplit[3]);
|
||||
Point p = new Point(x, y);
|
||||
if (isPointVisibleOnAScreen(p))
|
||||
{
|
||||
Location = p;
|
||||
if ((w > 50) && (h > 50)) { Size = new Size(w, h); }
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MenuItemExit_Click(object sender, EventArgs e)
|
||||
@@ -588,6 +613,9 @@ namespace MeshCentralRouter
|
||||
UpdateStatus();
|
||||
}
|
||||
node.fileViewer = null;
|
||||
|
||||
// Save window location
|
||||
setRegValue("filelocation", Location.X + "," + Location.Y + "," + Size.Width + "," + Size.Height);
|
||||
}
|
||||
|
||||
public delegate void displayMessageHandler(string msg);
|
||||
@@ -1187,5 +1215,21 @@ namespace MeshCentralRouter
|
||||
return Convert.ToBase64String(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRegValue(string name, string value)
|
||||
{
|
||||
try { Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router", name, value); } catch (Exception) { }
|
||||
}
|
||||
public string getRegValue(string name, string value)
|
||||
{
|
||||
try { return Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router", name, value).ToString(); } catch (Exception) { return value; }
|
||||
}
|
||||
|
||||
bool isPointVisibleOnAScreen(Point p)
|
||||
{
|
||||
foreach (Screen s in Screen.AllScreens) { if ((p.X < s.Bounds.Right) && (p.X > s.Bounds.Left) && (p.Y > s.Bounds.Top) && (p.Y < s.Bounds.Bottom)) return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace MeshCentralRouter
|
||||
private int scalinglevel = 1024; // 100% scale
|
||||
private int frameRate = 100; // Medium frame rate
|
||||
private bool swamMouseButtons = false;
|
||||
private bool remoteKeybaordMap = false;
|
||||
private double scalefactor = 1;
|
||||
public List<string> displays = new List<string>();
|
||||
public ushort currentDisp = 0;
|
||||
@@ -52,6 +53,7 @@ namespace MeshCentralRouter
|
||||
private bool isHookWanted;
|
||||
private bool isHookPriority;
|
||||
private bool keyboardIsAttached;
|
||||
private long killNextKeyPress = 0;
|
||||
|
||||
|
||||
private enum KvmCommands
|
||||
@@ -76,6 +78,7 @@ namespace MeshCentralRouter
|
||||
Jumbo = 27,
|
||||
Disconnect = 59,
|
||||
Alert = 65,
|
||||
KeyUnicode = 85,
|
||||
MouseCursor = 88
|
||||
}
|
||||
|
||||
@@ -108,6 +111,7 @@ namespace MeshCentralRouter
|
||||
public int ScalingLevel { get { return scalinglevel; } set { scalinglevel = value; SendCompressionLevel(); } }
|
||||
public int FrameRate { get { return frameRate; } set { frameRate = value; SendCompressionLevel(); } }
|
||||
public bool SwamMouseButtons { get { return swamMouseButtons; } set { swamMouseButtons = value; } }
|
||||
public bool RemoteKeybaordMap { get { return remoteKeybaordMap; } set { remoteKeybaordMap = value; } }
|
||||
|
||||
public double ScaleFactor { get { return scalefactor; } set { scalefactor = value; } }
|
||||
|
||||
@@ -395,18 +399,53 @@ namespace MeshCentralRouter
|
||||
Send(bw);
|
||||
}
|
||||
|
||||
private void SendKey(KeyEventArgs e, byte action)
|
||||
public void SendUnicodeKey(ushort key, byte action)
|
||||
{
|
||||
//if (state != ConnectState.Connected) return;
|
||||
|
||||
BinaryWriter bw = GetBinaryWriter();
|
||||
bw.Write(IPAddress.HostToNetworkOrder((short)KvmCommands.Key));
|
||||
bw.Write(IPAddress.HostToNetworkOrder((short)6));
|
||||
bw.Write(IPAddress.HostToNetworkOrder((short)KvmCommands.KeyUnicode));
|
||||
bw.Write(IPAddress.HostToNetworkOrder((short)7));
|
||||
bw.Write((byte)action);
|
||||
bw.Write((byte)e.KeyCode);
|
||||
bw.Write((byte)(key >> 8));
|
||||
bw.Write((byte)(key & 0xFF));
|
||||
Send(bw);
|
||||
}
|
||||
|
||||
private void SendPress(KeyPressEventArgs e, byte action)
|
||||
{
|
||||
//if (state != ConnectState.Connected) return;
|
||||
|
||||
if (remoteKeybaordMap == true) return;
|
||||
|
||||
if (killNextKeyPress > 0) {
|
||||
long t = DateTime.Now.Ticks;
|
||||
if ((t - killNextKeyPress) < 10) { killNextKeyPress = 0; return; }
|
||||
}
|
||||
|
||||
ushort c = (ushort)e.KeyChar;
|
||||
if (c < 32)
|
||||
{
|
||||
SendKey((byte)c, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
SendUnicodeKey(c, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void SendKey(KeyEventArgs e, byte action)
|
||||
{
|
||||
//if (state != ConnectState.Connected) return;
|
||||
|
||||
if (remoteKeybaordMap == true) { SendKey((byte)e.KeyCode, action); return; } // Use old key system that uses the remote keyboard mapping.
|
||||
string keycode = e.KeyCode.ToString();
|
||||
if ((action == 0) && (e.Control == false) && (e.Alt == false) && (((e.KeyValue >= 48) && (e.KeyValue <= 57)) || (keycode.Length == 1) || (keycode.StartsWith("Oem") == true))) return;
|
||||
if ((e.Control == true) || (e.Alt == true)) { killNextKeyPress = DateTime.Now.Ticks; }
|
||||
SendKey((byte)e.KeyCode, action);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private short LastX = 0;
|
||||
private short LastY = 0;
|
||||
private void SendMouse(MouseEventArgs e, byte action)
|
||||
@@ -681,6 +720,7 @@ namespace MeshCentralRouter
|
||||
{
|
||||
if (!isHookPriority)
|
||||
{
|
||||
SendPress(e, 0);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
19
KVMSettingsForm.Designer.cs
generated
19
KVMSettingsForm.Designer.cs
generated
@@ -32,6 +32,7 @@
|
||||
this.cancelButton = new System.Windows.Forms.Button();
|
||||
this.okButton = new System.Windows.Forms.Button();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.swapMouseButtonsCheckBox = new System.Windows.Forms.CheckBox();
|
||||
this.frameRateComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.scalingComboBox = new System.Windows.Forms.ComboBox();
|
||||
@@ -40,7 +41,7 @@
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.swapMouseButtonsCheckBox = new System.Windows.Forms.CheckBox();
|
||||
this.remoteKeyboardMapCheckBox = new System.Windows.Forms.CheckBox();
|
||||
this.groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@@ -63,6 +64,7 @@
|
||||
// groupBox1
|
||||
//
|
||||
resources.ApplyResources(this.groupBox1, "groupBox1");
|
||||
this.groupBox1.Controls.Add(this.remoteKeyboardMapCheckBox);
|
||||
this.groupBox1.Controls.Add(this.swapMouseButtonsCheckBox);
|
||||
this.groupBox1.Controls.Add(this.frameRateComboBox);
|
||||
this.groupBox1.Controls.Add(this.label2);
|
||||
@@ -73,6 +75,12 @@
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.TabStop = false;
|
||||
//
|
||||
// swapMouseButtonsCheckBox
|
||||
//
|
||||
resources.ApplyResources(this.swapMouseButtonsCheckBox, "swapMouseButtonsCheckBox");
|
||||
this.swapMouseButtonsCheckBox.Name = "swapMouseButtonsCheckBox";
|
||||
this.swapMouseButtonsCheckBox.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// frameRateComboBox
|
||||
//
|
||||
resources.ApplyResources(this.frameRateComboBox, "frameRateComboBox");
|
||||
@@ -121,11 +129,11 @@
|
||||
resources.ApplyResources(this.label4, "label4");
|
||||
this.label4.Name = "label4";
|
||||
//
|
||||
// swapMouseButtonsCheckBox
|
||||
// remoteKeyboardMapCheckBox
|
||||
//
|
||||
resources.ApplyResources(this.swapMouseButtonsCheckBox, "swapMouseButtonsCheckBox");
|
||||
this.swapMouseButtonsCheckBox.Name = "swapMouseButtonsCheckBox";
|
||||
this.swapMouseButtonsCheckBox.UseVisualStyleBackColor = true;
|
||||
resources.ApplyResources(this.remoteKeyboardMapCheckBox, "remoteKeyboardMapCheckBox");
|
||||
this.remoteKeyboardMapCheckBox.Name = "remoteKeyboardMapCheckBox";
|
||||
this.remoteKeyboardMapCheckBox.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// KVMSettingsForm
|
||||
//
|
||||
@@ -164,5 +172,6 @@
|
||||
private System.Windows.Forms.ComboBox qualityComboBox;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.CheckBox swapMouseButtonsCheckBox;
|
||||
private System.Windows.Forms.CheckBox remoteKeyboardMapCheckBox;
|
||||
}
|
||||
}
|
||||
@@ -124,6 +124,12 @@ namespace MeshCentralRouter
|
||||
set { swapMouseButtonsCheckBox.Checked = value; }
|
||||
}
|
||||
|
||||
public bool RemoteKeybaordMap
|
||||
{
|
||||
get { return remoteKeyboardMapCheckBox.Checked; }
|
||||
set { remoteKeyboardMapCheckBox.Checked = value; }
|
||||
}
|
||||
|
||||
private void okButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = System.Windows.Forms.DialogResult.OK;
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
</data>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="cancelButton.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>312, 207</value>
|
||||
<value>312, 236</value>
|
||||
</data>
|
||||
<data name="cancelButton.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>75, 23</value>
|
||||
@@ -151,7 +151,7 @@
|
||||
<value>Bottom, Right</value>
|
||||
</data>
|
||||
<data name="okButton.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>231, 207</value>
|
||||
<value>231, 236</value>
|
||||
</data>
|
||||
<data name="okButton.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>75, 23</value>
|
||||
@@ -177,6 +177,36 @@
|
||||
<data name="groupBox1.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
|
||||
<value>Top, Bottom, Left, Right</value>
|
||||
</data>
|
||||
<data name="remoteKeyboardMapCheckBox.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
</data>
|
||||
<data name="remoteKeyboardMapCheckBox.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
|
||||
<value>NoControl</value>
|
||||
</data>
|
||||
<data name="remoteKeyboardMapCheckBox.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>128, 128</value>
|
||||
</data>
|
||||
<data name="remoteKeyboardMapCheckBox.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>157, 17</value>
|
||||
</data>
|
||||
<data name="remoteKeyboardMapCheckBox.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>11</value>
|
||||
</data>
|
||||
<data name="remoteKeyboardMapCheckBox.Text" xml:space="preserve">
|
||||
<value>Use Remote Keyboard Map</value>
|
||||
</data>
|
||||
<data name=">>remoteKeyboardMapCheckBox.Name" xml:space="preserve">
|
||||
<value>remoteKeyboardMapCheckBox</value>
|
||||
</data>
|
||||
<data name=">>remoteKeyboardMapCheckBox.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>remoteKeyboardMapCheckBox.Parent" xml:space="preserve">
|
||||
<value>groupBox1</value>
|
||||
</data>
|
||||
<data name=">>remoteKeyboardMapCheckBox.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name="swapMouseButtonsCheckBox.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
</data>
|
||||
@@ -202,7 +232,7 @@
|
||||
<value>groupBox1</value>
|
||||
</data>
|
||||
<data name=">>swapMouseButtonsCheckBox.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name="frameRateComboBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
|
||||
<value>Top, Left, Right</value>
|
||||
@@ -226,7 +256,7 @@
|
||||
<value>groupBox1</value>
|
||||
</data>
|
||||
<data name=">>frameRateComboBox.ZOrder" xml:space="preserve">
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
</data>
|
||||
<data name="label2.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
@@ -253,7 +283,7 @@
|
||||
<value>groupBox1</value>
|
||||
</data>
|
||||
<data name=">>label2.ZOrder" xml:space="preserve">
|
||||
<value>2</value>
|
||||
<value>3</value>
|
||||
</data>
|
||||
<data name="scalingComboBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
|
||||
<value>Top, Left, Right</value>
|
||||
@@ -277,7 +307,7 @@
|
||||
<value>groupBox1</value>
|
||||
</data>
|
||||
<data name=">>scalingComboBox.ZOrder" xml:space="preserve">
|
||||
<value>3</value>
|
||||
<value>4</value>
|
||||
</data>
|
||||
<data name="label1.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
@@ -304,7 +334,7 @@
|
||||
<value>groupBox1</value>
|
||||
</data>
|
||||
<data name=">>label1.ZOrder" xml:space="preserve">
|
||||
<value>4</value>
|
||||
<value>5</value>
|
||||
</data>
|
||||
<data name="qualityComboBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
|
||||
<value>Top, Left, Right</value>
|
||||
@@ -328,7 +358,7 @@
|
||||
<value>groupBox1</value>
|
||||
</data>
|
||||
<data name=">>qualityComboBox.ZOrder" xml:space="preserve">
|
||||
<value>5</value>
|
||||
<value>6</value>
|
||||
</data>
|
||||
<data name="label3.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
@@ -355,13 +385,13 @@
|
||||
<value>groupBox1</value>
|
||||
</data>
|
||||
<data name=">>label3.ZOrder" xml:space="preserve">
|
||||
<value>6</value>
|
||||
<value>7</value>
|
||||
</data>
|
||||
<data name="groupBox1.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>12, 68</value>
|
||||
</data>
|
||||
<data name="groupBox1.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>375, 133</value>
|
||||
<value>375, 162</value>
|
||||
</data>
|
||||
<data name="groupBox1.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>2</value>
|
||||
@@ -439,7 +469,7 @@
|
||||
<value>6, 13</value>
|
||||
</data>
|
||||
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
|
||||
<value>399, 242</value>
|
||||
<value>399, 271</value>
|
||||
</data>
|
||||
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
|
||||
45
KVMViewer.cs
45
KVMViewer.cs
@@ -78,6 +78,30 @@ namespace MeshCentralRouter
|
||||
this.Size = new Size(820, 480);
|
||||
resizeKvmControl.CenterKvmControl(false);
|
||||
topPanel.Visible = true;
|
||||
|
||||
// Restore Window Location
|
||||
string locationStr = getRegValue("kvmlocation", "");
|
||||
if (locationStr != null)
|
||||
{
|
||||
string[] locationSplit = locationStr.Split(',');
|
||||
if (locationSplit.Length == 4)
|
||||
{
|
||||
try
|
||||
{
|
||||
var x = int.Parse(locationSplit[0]);
|
||||
var y = int.Parse(locationSplit[1]);
|
||||
var w = int.Parse(locationSplit[2]);
|
||||
var h = int.Parse(locationSplit[3]);
|
||||
Point p = new Point(x, y);
|
||||
if (isPointVisibleOnAScreen(p))
|
||||
{
|
||||
Location = p;
|
||||
if ((w > 50) && (h > 50)) { Size = new Size(w, h); }
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnScreenChanged()
|
||||
@@ -293,6 +317,9 @@ namespace MeshCentralRouter
|
||||
}
|
||||
node.desktopViewer = null;
|
||||
closeKvmStats();
|
||||
|
||||
// Save window location
|
||||
setRegValue("kvmlocation", Location.X + "," + Location.Y + "," + Size.Width + "," + Size.Height);
|
||||
}
|
||||
|
||||
private void toolStripMenuItem2_DropDownOpening(object sender, EventArgs e)
|
||||
@@ -317,10 +344,12 @@ namespace MeshCentralRouter
|
||||
form.Scaling = kvmControl.ScalingLevel;
|
||||
form.FrameRate = kvmControl.FrameRate;
|
||||
form.SwamMouseButtons = kvmControl.SwamMouseButtons;
|
||||
form.RemoteKeybaordMap = kvmControl.RemoteKeybaordMap;
|
||||
if (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
kvmControl.SetCompressionParams(form.Compression, form.Scaling, form.FrameRate);
|
||||
kvmControl.SwamMouseButtons = form.SwamMouseButtons;
|
||||
kvmControl.RemoteKeybaordMap = form.RemoteKeybaordMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -504,5 +533,21 @@ namespace MeshCentralRouter
|
||||
{
|
||||
kvmControl.AttachKeyboard();
|
||||
}
|
||||
|
||||
public void setRegValue(string name, string value)
|
||||
{
|
||||
try { Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router", name, value); } catch (Exception) { }
|
||||
}
|
||||
public string getRegValue(string name, string value)
|
||||
{
|
||||
try { return Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router", name, value).ToString(); } catch (Exception) { return value; }
|
||||
}
|
||||
|
||||
bool isPointVisibleOnAScreen(Point p)
|
||||
{
|
||||
foreach (Screen s in Screen.AllScreens) { if ((p.X < s.Bounds.Right) && (p.X > s.Bounds.Left) && (p.Y > s.Bounds.Top) && (p.Y < s.Bounds.Bottom)) return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
95
MainForm.Designer.cs
generated
95
MainForm.Designer.cs
generated
@@ -81,10 +81,13 @@
|
||||
this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.sortByNameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.sortByGroupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.searchTextBox = new System.Windows.Forms.TextBox();
|
||||
this.devicesTabControl = new System.Windows.Forms.TabControl();
|
||||
this.devicesTabPage = new System.Windows.Forms.TabPage();
|
||||
this.devicesPanel = new System.Windows.Forms.Panel();
|
||||
this.cancelAutoCloseButton1 = new System.Windows.Forms.Button();
|
||||
this.devicesListView = new System.Windows.Forms.ListView();
|
||||
this.nameColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.stateColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
@@ -103,9 +106,9 @@
|
||||
this.noSearchResultsLabel = new System.Windows.Forms.Label();
|
||||
this.noDevicesLabel = new System.Windows.Forms.Label();
|
||||
this.portMapTabPage = new System.Windows.Forms.TabPage();
|
||||
this.cancelAutoCloseButton2 = new System.Windows.Forms.Button();
|
||||
this.mapPanel = new System.Windows.Forms.Panel();
|
||||
this.noMapLabel = new System.Windows.Forms.Label();
|
||||
this.settingsPictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.helpPictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.addButton = new System.Windows.Forms.Button();
|
||||
this.addRelayButton = new System.Windows.Forms.Button();
|
||||
@@ -127,6 +130,9 @@
|
||||
this.saveMappingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.openMapFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.saveMapFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
this.toolStripMenuItem5 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.settingsToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.settingsPictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.panel5.SuspendLayout();
|
||||
this.mainPanel.SuspendLayout();
|
||||
this.mainTabControl.SuspendLayout();
|
||||
@@ -150,12 +156,12 @@
|
||||
this.devicesContextMenuStrip.SuspendLayout();
|
||||
this.portMapTabPage.SuspendLayout();
|
||||
this.mapPanel.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.settingsPictureBox)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.helpPictureBox)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.trayIconContextMenuStrip.SuspendLayout();
|
||||
this.mappingsContextMenuStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.settingsPictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// panel5
|
||||
@@ -180,6 +186,7 @@
|
||||
this.mainTabControl.Controls.Add(this.tabPage5);
|
||||
this.mainTabControl.Name = "mainTabControl";
|
||||
this.mainTabControl.SelectedIndex = 0;
|
||||
this.mainTabControl.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress);
|
||||
//
|
||||
// tabPage1
|
||||
//
|
||||
@@ -502,7 +509,9 @@
|
||||
this.showOfflineDevicesToolStripMenuItem,
|
||||
this.toolStripMenuItem2,
|
||||
this.sortByNameToolStripMenuItem,
|
||||
this.sortByGroupToolStripMenuItem});
|
||||
this.sortByGroupToolStripMenuItem,
|
||||
this.toolStripMenuItem4,
|
||||
this.settingsToolStripMenuItem});
|
||||
this.mainContextMenuStrip.Name = "mainContextMenuStrip";
|
||||
resources.ApplyResources(this.mainContextMenuStrip, "mainContextMenuStrip");
|
||||
//
|
||||
@@ -539,6 +548,17 @@
|
||||
resources.ApplyResources(this.sortByGroupToolStripMenuItem, "sortByGroupToolStripMenuItem");
|
||||
this.sortByGroupToolStripMenuItem.Click += new System.EventHandler(this.sortByGroupToolStripMenuItem_Click);
|
||||
//
|
||||
// toolStripMenuItem4
|
||||
//
|
||||
this.toolStripMenuItem4.Name = "toolStripMenuItem4";
|
||||
resources.ApplyResources(this.toolStripMenuItem4, "toolStripMenuItem4");
|
||||
//
|
||||
// settingsToolStripMenuItem
|
||||
//
|
||||
this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem";
|
||||
resources.ApplyResources(this.settingsToolStripMenuItem, "settingsToolStripMenuItem");
|
||||
this.settingsToolStripMenuItem.Click += new System.EventHandler(this.settingsToolStripMenuItem_Click);
|
||||
//
|
||||
// searchTextBox
|
||||
//
|
||||
resources.ApplyResources(this.searchTextBox, "searchTextBox");
|
||||
@@ -554,6 +574,7 @@
|
||||
this.devicesTabControl.Name = "devicesTabControl";
|
||||
this.devicesTabControl.SelectedIndex = 0;
|
||||
this.devicesTabControl.SelectedIndexChanged += new System.EventHandler(this.devicesTabControl_SelectedIndexChanged);
|
||||
this.devicesTabControl.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress);
|
||||
//
|
||||
// devicesTabPage
|
||||
//
|
||||
@@ -567,11 +588,20 @@
|
||||
resources.ApplyResources(this.devicesPanel, "devicesPanel");
|
||||
this.devicesPanel.BackColor = System.Drawing.SystemColors.ControlLightLight;
|
||||
this.devicesPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
||||
this.devicesPanel.Controls.Add(this.cancelAutoCloseButton1);
|
||||
this.devicesPanel.Controls.Add(this.devicesListView);
|
||||
this.devicesPanel.Controls.Add(this.noSearchResultsLabel);
|
||||
this.devicesPanel.Controls.Add(this.noDevicesLabel);
|
||||
this.devicesPanel.Name = "devicesPanel";
|
||||
//
|
||||
// cancelAutoCloseButton1
|
||||
//
|
||||
resources.ApplyResources(this.cancelAutoCloseButton1, "cancelAutoCloseButton1");
|
||||
this.cancelAutoCloseButton1.Name = "cancelAutoCloseButton1";
|
||||
this.cancelAutoCloseButton1.UseVisualStyleBackColor = true;
|
||||
this.cancelAutoCloseButton1.Click += new System.EventHandler(this.cancelAutoCloseButton_Click);
|
||||
this.cancelAutoCloseButton1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress);
|
||||
//
|
||||
// devicesListView
|
||||
//
|
||||
this.devicesListView.BackColor = System.Drawing.SystemColors.Window;
|
||||
@@ -591,7 +621,9 @@
|
||||
this.devicesListView.Sorting = System.Windows.Forms.SortOrder.Ascending;
|
||||
this.devicesListView.UseCompatibleStateImageBehavior = false;
|
||||
this.devicesListView.View = System.Windows.Forms.View.Details;
|
||||
this.devicesListView.Click += new System.EventHandler(this.devicesListView_Click);
|
||||
this.devicesListView.DoubleClick += new System.EventHandler(this.devicesListView_DoubleClick);
|
||||
this.devicesListView.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress);
|
||||
//
|
||||
// nameColumnHeader
|
||||
//
|
||||
@@ -711,6 +743,7 @@
|
||||
// portMapTabPage
|
||||
//
|
||||
this.portMapTabPage.BackColor = System.Drawing.SystemColors.Control;
|
||||
this.portMapTabPage.Controls.Add(this.cancelAutoCloseButton2);
|
||||
this.portMapTabPage.Controls.Add(this.mapPanel);
|
||||
this.portMapTabPage.Controls.Add(this.settingsPictureBox);
|
||||
this.portMapTabPage.Controls.Add(this.helpPictureBox);
|
||||
@@ -719,6 +752,13 @@
|
||||
resources.ApplyResources(this.portMapTabPage, "portMapTabPage");
|
||||
this.portMapTabPage.Name = "portMapTabPage";
|
||||
//
|
||||
// cancelAutoCloseButton2
|
||||
//
|
||||
resources.ApplyResources(this.cancelAutoCloseButton2, "cancelAutoCloseButton2");
|
||||
this.cancelAutoCloseButton2.Name = "cancelAutoCloseButton2";
|
||||
this.cancelAutoCloseButton2.UseVisualStyleBackColor = true;
|
||||
this.cancelAutoCloseButton2.Click += new System.EventHandler(this.cancelAutoCloseButton_Click);
|
||||
//
|
||||
// mapPanel
|
||||
//
|
||||
this.mapPanel.AllowDrop = true;
|
||||
@@ -735,15 +775,6 @@
|
||||
resources.ApplyResources(this.noMapLabel, "noMapLabel");
|
||||
this.noMapLabel.Name = "noMapLabel";
|
||||
//
|
||||
// settingsPictureBox
|
||||
//
|
||||
resources.ApplyResources(this.settingsPictureBox, "settingsPictureBox");
|
||||
this.settingsPictureBox.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.settingsPictureBox.Image = global::MeshCentralRouter.Properties.Resources.Gear20;
|
||||
this.settingsPictureBox.Name = "settingsPictureBox";
|
||||
this.settingsPictureBox.TabStop = false;
|
||||
this.settingsPictureBox.Click += new System.EventHandler(this.settingsPictureBox_Click);
|
||||
//
|
||||
// helpPictureBox
|
||||
//
|
||||
resources.ApplyResources(this.helpPictureBox, "helpPictureBox");
|
||||
@@ -759,6 +790,7 @@
|
||||
this.addButton.Name = "addButton";
|
||||
this.addButton.UseVisualStyleBackColor = true;
|
||||
this.addButton.Click += new System.EventHandler(this.addButton_Click);
|
||||
this.addButton.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress);
|
||||
//
|
||||
// addRelayButton
|
||||
//
|
||||
@@ -766,6 +798,7 @@
|
||||
this.addRelayButton.Name = "addRelayButton";
|
||||
this.addRelayButton.UseVisualStyleBackColor = true;
|
||||
this.addRelayButton.Click += new System.EventHandler(this.addRelayMapButton_Click);
|
||||
this.addRelayButton.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress);
|
||||
//
|
||||
// openWebSiteButton
|
||||
//
|
||||
@@ -773,6 +806,7 @@
|
||||
this.openWebSiteButton.Name = "openWebSiteButton";
|
||||
this.openWebSiteButton.UseVisualStyleBackColor = true;
|
||||
this.openWebSiteButton.Click += new System.EventHandler(this.openWebSiteButton_Click);
|
||||
this.openWebSiteButton.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress);
|
||||
//
|
||||
// backButton5
|
||||
//
|
||||
@@ -780,6 +814,7 @@
|
||||
this.backButton5.Name = "backButton5";
|
||||
this.backButton5.UseVisualStyleBackColor = true;
|
||||
this.backButton5.Click += new System.EventHandler(this.backButton5_Click);
|
||||
this.backButton5.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress);
|
||||
//
|
||||
// nextButton5
|
||||
//
|
||||
@@ -787,6 +822,7 @@
|
||||
this.nextButton5.Name = "nextButton5";
|
||||
this.nextButton5.UseVisualStyleBackColor = true;
|
||||
this.nextButton5.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
|
||||
this.nextButton5.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress);
|
||||
//
|
||||
// pictureBox7
|
||||
//
|
||||
@@ -852,7 +888,9 @@
|
||||
//
|
||||
this.mappingsContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.openMappingsToolStripMenuItem,
|
||||
this.saveMappingsToolStripMenuItem});
|
||||
this.saveMappingsToolStripMenuItem,
|
||||
this.toolStripMenuItem5,
|
||||
this.settingsToolStripMenuItem1});
|
||||
this.mappingsContextMenuStrip.Name = "mappingsContextMenuStrip";
|
||||
resources.ApplyResources(this.mappingsContextMenuStrip, "mappingsContextMenuStrip");
|
||||
//
|
||||
@@ -878,6 +916,26 @@
|
||||
this.saveMapFileDialog.DefaultExt = "mcrouter";
|
||||
resources.ApplyResources(this.saveMapFileDialog, "saveMapFileDialog");
|
||||
//
|
||||
// toolStripMenuItem5
|
||||
//
|
||||
this.toolStripMenuItem5.Name = "toolStripMenuItem5";
|
||||
resources.ApplyResources(this.toolStripMenuItem5, "toolStripMenuItem5");
|
||||
//
|
||||
// ToolStripMenuItem1
|
||||
//
|
||||
this.settingsToolStripMenuItem1.Name = "settingsToolStripMenuItem1";
|
||||
resources.ApplyResources(this.settingsToolStripMenuItem1, "settingsToolStripMenuItem1");
|
||||
this.settingsToolStripMenuItem1.Click += new System.EventHandler(this.settingsPictureBox_Click);
|
||||
//
|
||||
// settingsPictureBox
|
||||
//
|
||||
resources.ApplyResources(this.settingsPictureBox, "settingsPictureBox");
|
||||
this.settingsPictureBox.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.settingsPictureBox.Image = global::MeshCentralRouter.Properties.Resources.Gear20;
|
||||
this.settingsPictureBox.Name = "settingsPictureBox";
|
||||
this.settingsPictureBox.TabStop = false;
|
||||
this.settingsPictureBox.Click += new System.EventHandler(this.settingsPictureBox_Click);
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
resources.ApplyResources(this, "$this");
|
||||
@@ -889,6 +947,7 @@
|
||||
this.Name = "MainForm";
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);
|
||||
this.Load += new System.EventHandler(this.MainForm_Load);
|
||||
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress);
|
||||
this.panel5.ResumeLayout(false);
|
||||
this.mainPanel.ResumeLayout(false);
|
||||
this.mainTabControl.ResumeLayout(false);
|
||||
@@ -916,12 +975,12 @@
|
||||
this.devicesContextMenuStrip.ResumeLayout(false);
|
||||
this.portMapTabPage.ResumeLayout(false);
|
||||
this.mapPanel.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.settingsPictureBox)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.helpPictureBox)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
this.trayIconContextMenuStrip.ResumeLayout(false);
|
||||
this.mappingsContextMenuStrip.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.settingsPictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
@@ -982,7 +1041,6 @@
|
||||
private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;
|
||||
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
|
||||
private System.Windows.Forms.PictureBox settingsPictureBox;
|
||||
private System.Windows.Forms.TabControl devicesTabControl;
|
||||
private System.Windows.Forms.TabPage devicesTabPage;
|
||||
private System.Windows.Forms.TabPage portMapTabPage;
|
||||
@@ -1024,6 +1082,13 @@
|
||||
private System.Windows.Forms.CheckBox rememberCertCheckBox;
|
||||
private System.Windows.Forms.CheckBox tokenRememberCheckBox;
|
||||
private System.Windows.Forms.ToolStripMenuItem remoteFilesToolStripMenuItem;
|
||||
private System.Windows.Forms.Button cancelAutoCloseButton1;
|
||||
private System.Windows.Forms.Button cancelAutoCloseButton2;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem4;
|
||||
private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem5;
|
||||
private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem1;
|
||||
private System.Windows.Forms.PictureBox settingsPictureBox;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
267
MainForm.cs
267
MainForm.cs
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2009-2017 Intel Corporation
|
||||
Copyright 2009-2020 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -27,6 +27,7 @@ using System.Runtime.InteropServices;
|
||||
using System.Web.Script.Serialization;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Microsoft.Win32;
|
||||
using System.Drawing;
|
||||
|
||||
namespace MeshCentralRouter
|
||||
{
|
||||
@@ -51,6 +52,8 @@ namespace MeshCentralRouter
|
||||
public string acceptableCertHash = null;
|
||||
public ArrayList mappingsToSetup = null;
|
||||
public bool deviceListViewMode = true;
|
||||
public Process autoExitProc = null;
|
||||
public int deviceDoubleClickAction = 0;
|
||||
|
||||
public bool isRouterHooked()
|
||||
{
|
||||
@@ -142,6 +145,9 @@ namespace MeshCentralRouter
|
||||
|
||||
public MainForm(string[] args)
|
||||
{
|
||||
// Set TLS 1.2
|
||||
ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
|
||||
|
||||
this.args = args;
|
||||
InitializeComponent();
|
||||
mainPanel.Controls.Add(panel1);
|
||||
@@ -157,6 +163,8 @@ namespace MeshCentralRouter
|
||||
title = this.Text;
|
||||
|
||||
int argflags = 0;
|
||||
string update = null;
|
||||
string delete = null;
|
||||
foreach (string arg in this.args) {
|
||||
if (arg.ToLower() == "-oldstyle") { deviceListViewMode = false; }
|
||||
if (arg.ToLower() == "-install") { hookRouter(); forceExit = true; return; }
|
||||
@@ -171,14 +179,82 @@ namespace MeshCentralRouter
|
||||
if (arg.Length > 6 && arg.Substring(0, 6).ToLower() == "-user:") { userNameTextBox.Text = arg.Substring(6); argflags |= 2; }
|
||||
if (arg.Length > 6 && arg.Substring(0, 6).ToLower() == "-pass:") { passwordTextBox.Text = arg.Substring(6); argflags |= 4; }
|
||||
if (arg.Length > 8 && arg.Substring(0, 8).ToLower() == "-search:") { searchTextBox.Text = arg.Substring(8); }
|
||||
if (arg.Length > 8 && arg.Substring(0, 8).ToLower() == "-update:") { update = arg.Substring(8); }
|
||||
if (arg.Length > 8 && arg.Substring(0, 8).ToLower() == "-delete:") { delete = arg.Substring(8); }
|
||||
if (arg.Length > 11 && arg.Substring(0, 11).ToLower() == "mcrouter://") { authLoginUrl = new Uri(arg); }
|
||||
if ((arg.Length > 1) && (arg[0] != '-') && (arg.ToLower().EndsWith(".mcrouter"))) { try { argflags |= loadMappingFile(File.ReadAllText(arg), 1); } catch (Exception) { } }
|
||||
if (arg.ToLower() == "-localfiles") { FileViewer fileViewer = new FileViewer(meshcentral, null); fileViewer.Show(); }
|
||||
}
|
||||
autoLogin = (argflags == 7);
|
||||
|
||||
if (update != null) {
|
||||
// New args
|
||||
ArrayList args2 = new ArrayList();
|
||||
foreach (string a in args) { if (a.StartsWith("-update:") == false) { args2.Add(a); } }
|
||||
|
||||
// Remove ".update.exe" and copy
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
File.Copy(Assembly.GetEntryAssembly().Location, update, true);
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
Process.Start(update, string.Join(" ", (string[])args2.ToArray(typeof(string))) + " -delete:" + Assembly.GetEntryAssembly().Location);
|
||||
this.forceExit = true;
|
||||
Application.Exit();
|
||||
return;
|
||||
}
|
||||
|
||||
if (delete != null) { try { System.Threading.Thread.Sleep(1000); File.Delete(delete); } catch (Exception) { } }
|
||||
|
||||
// Set automatic port map values
|
||||
if (authLoginUrl != null) {
|
||||
string autoNodeId = null;
|
||||
int autoRemotePort = 0;
|
||||
int autoProtocol = 0;
|
||||
int autoAppId = 0;
|
||||
bool autoExit = false;
|
||||
try
|
||||
{
|
||||
// Automatic mappings
|
||||
autoNodeId = getValueFromQueryString(authLoginUrl.Query, "nodeid");
|
||||
autoRemotePort = int.Parse(getValueFromQueryString(authLoginUrl.Query, "remoteport"));
|
||||
autoProtocol = int.Parse(getValueFromQueryString(authLoginUrl.Query, "protocol"));
|
||||
autoAppId = int.Parse(getValueFromQueryString(authLoginUrl.Query, "appid"));
|
||||
autoExit = (getValueFromQueryString(authLoginUrl.Query, "autoexit") == "1");
|
||||
}
|
||||
catch (Exception) { }
|
||||
if ((autoRemotePort != 0) && (autoProtocol != 0) && (autoNodeId != null)) {
|
||||
Dictionary<string, object> map = new Dictionary<string, object>();
|
||||
map.Add("nodeId", autoNodeId);
|
||||
map.Add("remotePort", autoRemotePort);
|
||||
map.Add("localPort", 0);
|
||||
map.Add("protocol", autoProtocol);
|
||||
map.Add("appId", autoAppId);
|
||||
map.Add("autoExit", autoExit);
|
||||
map.Add("launch", 1);
|
||||
mappingsToSetup = new ArrayList();
|
||||
mappingsToSetup.Add(map);
|
||||
devicesTabControl.SelectedIndex = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Check MeshCentral .mcrouter hook
|
||||
installButton.Visible = !isRouterHooked();
|
||||
|
||||
// Right click action
|
||||
deviceDoubleClickAction = int.Parse(getRegValue("DevDoubleClickClickAction", "0"));
|
||||
setDoubleClickDeviceAction();
|
||||
}
|
||||
|
||||
private void setDoubleClickDeviceAction()
|
||||
{
|
||||
addMapToolStripMenuItem.Font = new Font("Segoe UI", 9, (deviceDoubleClickAction == 0) ? FontStyle.Bold : FontStyle.Regular);
|
||||
addRelayMapToolStripMenuItem.Font = new Font("Segoe UI", 9, (deviceDoubleClickAction == 1) ? FontStyle.Bold : FontStyle.Regular);
|
||||
remoteDesktopToolStripMenuItem.Font = new Font("Segoe UI", 9, (deviceDoubleClickAction == 2) ? FontStyle.Bold : FontStyle.Regular);
|
||||
remoteFilesToolStripMenuItem.Font = new Font("Segoe UI", 9, (deviceDoubleClickAction == 3) ? FontStyle.Bold : FontStyle.Regular);
|
||||
httpToolStripMenuItem.Font = new Font("Segoe UI", 9, (deviceDoubleClickAction == 4) ? FontStyle.Bold : FontStyle.Regular);
|
||||
httpsToolStripMenuItem.Font = new Font("Segoe UI", 9, (deviceDoubleClickAction == 5) ? FontStyle.Bold : FontStyle.Regular);
|
||||
rdpToolStripMenuItem.Font = new Font("Segoe UI", 9, (deviceDoubleClickAction == 6) ? FontStyle.Bold : FontStyle.Regular);
|
||||
sshToolStripMenuItem.Font = new Font("Segoe UI", 9, (deviceDoubleClickAction == 7) ? FontStyle.Bold : FontStyle.Regular);
|
||||
scpToolStripMenuItem.Font = new Font("Segoe UI", 9, (deviceDoubleClickAction == 8) ? FontStyle.Bold : FontStyle.Regular);
|
||||
}
|
||||
|
||||
private void setPanel(int newPanel)
|
||||
@@ -194,6 +270,7 @@ namespace MeshCentralRouter
|
||||
// Setup stuff
|
||||
if (newPanel == 1) { tokenRememberCheckBox.Checked = false; }
|
||||
nextButton2.Enabled = (tokenTextBox.Text.Replace(" ", "") != "");
|
||||
if (currentPanel == 4) { devicesTabControl.Focus(); }
|
||||
}
|
||||
|
||||
private void MainForm_Load(object sender, EventArgs e)
|
||||
@@ -237,6 +314,30 @@ namespace MeshCentralRouter
|
||||
sortByNameToolStripMenuItem.Visible = false;
|
||||
sortByGroupToolStripMenuItem.Visible = false;
|
||||
}
|
||||
|
||||
// Restore Window Location
|
||||
string locationStr = getRegValue("location", "");
|
||||
if (locationStr != null)
|
||||
{
|
||||
string[] locationSplit = locationStr.Split(',');
|
||||
if (locationSplit.Length == 2)
|
||||
{
|
||||
try
|
||||
{
|
||||
var x = int.Parse(locationSplit[0]);
|
||||
var y = int.Parse(locationSplit[1]);
|
||||
Point p = new Point(x, y);
|
||||
if (isPointVisibleOnAScreen(p)) { Location = p; }
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isPointVisibleOnAScreen(Point p)
|
||||
{
|
||||
foreach (Screen s in Screen.AllScreens) { if ((p.X < s.Bounds.Right) && (p.X > s.Bounds.Left) && (p.Y > s.Bounds.Top) && (p.Y < s.Bounds.Bottom)) return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updatePanel1(object sender, EventArgs e)
|
||||
@@ -271,14 +372,16 @@ namespace MeshCentralRouter
|
||||
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
if ((notifyIcon.Visible == true) && (forceExit == false)) { e.Cancel = true; Visible = false; }
|
||||
setRegValue("Location", Location.X + "," + Location.Y);
|
||||
}
|
||||
|
||||
private void backButton5_Click(object sender, EventArgs e)
|
||||
{
|
||||
cancelAutoClose();
|
||||
meshcentral.disconnect();
|
||||
}
|
||||
|
||||
private string getValueFromQueryString(string query, string name)
|
||||
private static string getValueFromQueryString(string query, string name)
|
||||
{
|
||||
if ((query == null) || (name == null)) return null;
|
||||
int i = query.IndexOf("?" + name + "=");
|
||||
@@ -306,6 +409,7 @@ namespace MeshCentralRouter
|
||||
meshcentral.onLoginTokenChanged += Meshcentral_onLoginTokenChanged;
|
||||
meshcentral.onClipboardData += Meshcentral_onClipboardData;
|
||||
meshcentral.onTwoFactorCookie += Meshcentral_onTwoFactorCookie;
|
||||
//meshcentral.onToolUpdate += Meshcentral_onToolUpdate;
|
||||
if (lastBadConnectCert != null)
|
||||
{
|
||||
meshcentral.okCertHash = lastBadConnectCert.GetCertHashString();
|
||||
@@ -377,22 +481,44 @@ namespace MeshCentralRouter
|
||||
meshcentral.onLoginTokenChanged += Meshcentral_onLoginTokenChanged;
|
||||
meshcentral.onClipboardData += Meshcentral_onClipboardData;
|
||||
meshcentral.onTwoFactorCookie += Meshcentral_onTwoFactorCookie;
|
||||
meshcentral.onToolUpdate += Meshcentral_onToolUpdate;
|
||||
meshcentral.okCertHash = lastBadConnectCert.GetCertHashString();
|
||||
|
||||
Uri serverurl = null;
|
||||
if (authLoginUrl != null) {
|
||||
meshcentral.okCertHash2 = getValueFromQueryString(authLoginUrl.Query, "t");
|
||||
serverurl = new Uri("wss://" + authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443) + authLoginUrl.LocalPath + "?auth=" + getValueFromQueryString(authLoginUrl.Query, "c"));
|
||||
string loginkey = getValueFromQueryString(authLoginUrl.Query, "key");
|
||||
string urlstring = "wss://" + authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443) + authLoginUrl.LocalPath + "?auth=" + getValueFromQueryString(authLoginUrl.Query, "c");
|
||||
if (loginkey != null) { urlstring += ("&key=" + loginkey); }
|
||||
serverurl = new Uri(urlstring);
|
||||
meshcentral.connect(serverurl, null, null, null);
|
||||
} else {
|
||||
// Load two factor cookie if present
|
||||
string twoFactorCookie = Settings.GetRegValue("TwoFactorCookie", null);
|
||||
if ((twoFactorCookie != null) && (twoFactorCookie != "")) { twoFactorCookie = "cookie=" + twoFactorCookie; } else { twoFactorCookie = null; }
|
||||
serverurl = new Uri("wss://" + serverNameComboBox.Text + "/control.ashx");
|
||||
meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, twoFactorCookie);
|
||||
int keyIndex = serverNameComboBox.Text.IndexOf("?key=");
|
||||
if (keyIndex >= 0)
|
||||
{
|
||||
string hostname = serverNameComboBox.Text.Substring(0, keyIndex);
|
||||
string loginkey = serverNameComboBox.Text.Substring(keyIndex + 5);
|
||||
try { serverurl = new Uri("wss://" + hostname + "/control.ashx?key=" + loginkey); } catch (Exception) { }
|
||||
meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, twoFactorCookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
try { serverurl = new Uri("wss://" + serverNameComboBox.Text + "/control.ashx"); } catch (Exception) { }
|
||||
meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, twoFactorCookie);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Meshcentral_onToolUpdate(string url, string hash, int size, string serverhash)
|
||||
{
|
||||
if (this.InvokeRequired) { this.Invoke(new MeshCentralServer.toolUpdateHandler(Meshcentral_onToolUpdate), url, hash, size, serverhash); return; }
|
||||
UpdateForm f = new UpdateForm(url, hash, size, args, serverhash);
|
||||
if (f.ShowDialog(this) == DialogResult.OK) { }
|
||||
}
|
||||
|
||||
private void Meshcentral_onLoginTokenChanged()
|
||||
{
|
||||
if (this.InvokeRequired) { this.Invoke(new MeshCentralServer.onLoginTokenChangedHandler(Meshcentral_onLoginTokenChanged)); return; }
|
||||
@@ -851,6 +977,7 @@ namespace MeshCentralRouter
|
||||
|
||||
private void addButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
cancelAutoClose();
|
||||
AddPortMapForm form = new AddPortMapForm(meshcentral);
|
||||
|
||||
if (sender == null)
|
||||
@@ -908,9 +1035,22 @@ namespace MeshCentralRouter
|
||||
|
||||
Uri serverurl = null;
|
||||
if (authLoginUrl != null) {
|
||||
serverurl = new Uri("wss://" + authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443) + authLoginUrl.LocalPath + "?auth=" + getValueFromQueryString(authLoginUrl.Query, "c"));
|
||||
string loginkey = getValueFromQueryString(authLoginUrl.Query, "key");
|
||||
string urlstring = "wss://" + authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443) + authLoginUrl.LocalPath + "?auth=" + getValueFromQueryString(authLoginUrl.Query, "c");
|
||||
if (loginkey != null) { urlstring += ("&key=" + loginkey); }
|
||||
serverurl = new Uri(urlstring);
|
||||
} else {
|
||||
serverurl = new Uri("wss://" + serverNameComboBox.Text + "/control.ashx");
|
||||
int keyIndex = serverNameComboBox.Text.IndexOf("?key=");
|
||||
if (keyIndex >= 0)
|
||||
{
|
||||
string hostname = serverNameComboBox.Text.Substring(0, keyIndex);
|
||||
string loginkey = serverNameComboBox.Text.Substring(keyIndex + 5);
|
||||
serverurl = new Uri("wss://" + hostname + "/control.ashx?key=" + loginkey);
|
||||
}
|
||||
else
|
||||
{
|
||||
serverurl = new Uri("wss://" + serverNameComboBox.Text + "/control.ashx");
|
||||
}
|
||||
}
|
||||
|
||||
meshcentral = new MeshCentralServer();
|
||||
@@ -928,6 +1068,7 @@ namespace MeshCentralRouter
|
||||
meshcentral.onLoginTokenChanged += Meshcentral_onLoginTokenChanged;
|
||||
meshcentral.onClipboardData += Meshcentral_onClipboardData;
|
||||
meshcentral.onTwoFactorCookie += Meshcentral_onTwoFactorCookie;
|
||||
meshcentral.onToolUpdate += Meshcentral_onToolUpdate;
|
||||
if (sendEmailToken == true)
|
||||
{
|
||||
sendEmailToken = false;
|
||||
@@ -985,8 +1126,16 @@ namespace MeshCentralRouter
|
||||
X509Certificate2UI.DisplayCertificate(lastBadConnectCert);
|
||||
}
|
||||
|
||||
private void cancelAutoClose()
|
||||
{
|
||||
autoExitProc = null;
|
||||
cancelAutoCloseButton1.Visible = false;
|
||||
cancelAutoCloseButton2.Visible = false;
|
||||
}
|
||||
|
||||
private void addRelayMapButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
cancelAutoClose();
|
||||
AddRelayMapForm form = new AddRelayMapForm(meshcentral);
|
||||
|
||||
if (sender == null)
|
||||
@@ -1025,11 +1174,13 @@ namespace MeshCentralRouter
|
||||
|
||||
private void helpPictureBox_Click(object sender, EventArgs e)
|
||||
{
|
||||
cancelAutoClose();
|
||||
new MappingHelpForm().ShowDialog(this);
|
||||
}
|
||||
|
||||
private void openWebSiteButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
cancelAutoClose();
|
||||
if (meshcentral.loginCookie != null) {
|
||||
Uri serverurl = null;
|
||||
if (authLoginUrl != null) {
|
||||
@@ -1066,6 +1217,7 @@ namespace MeshCentralRouter
|
||||
|
||||
private void settingsPictureBox_Click(object sender, EventArgs e)
|
||||
{
|
||||
cancelAutoClose();
|
||||
SettingsForm f = new SettingsForm();
|
||||
f.BindAllInterfaces = inaddrany;
|
||||
f.ShowSystemTray = (notifyIcon.Visible == true);
|
||||
@@ -1126,6 +1278,7 @@ namespace MeshCentralRouter
|
||||
|
||||
private void devicesTabControl_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
cancelAutoClose();
|
||||
searchTextBox.Visible = (devicesTabControl.SelectedIndex == 0);
|
||||
if (devicesTabControl.SelectedIndex == 0) {
|
||||
menuLabel.ContextMenuStrip = mainContextMenuStrip;
|
||||
@@ -1136,6 +1289,7 @@ namespace MeshCentralRouter
|
||||
|
||||
private void searchTextBox_KeyPress(object sender, KeyPressEventArgs e)
|
||||
{
|
||||
cancelAutoClose();
|
||||
if (e.KeyChar == 27) { searchTextBox.Text = ""; e.Handled = true; }
|
||||
}
|
||||
|
||||
@@ -1208,6 +1362,7 @@ namespace MeshCentralRouter
|
||||
|
||||
private void menuLabel_Click(object sender, EventArgs e)
|
||||
{
|
||||
cancelAutoClose();
|
||||
if (devicesTabControl.SelectedIndex == 0)
|
||||
{
|
||||
mainContextMenuStrip.Show(menuLabel, menuLabel.PointToClient(Cursor.Position));
|
||||
@@ -1316,6 +1471,7 @@ namespace MeshCentralRouter
|
||||
if (x.ContainsKey("remoteIP")) { map.remoteIP = (string)x["remoteIP"]; }
|
||||
map.remotePort = (int)x["remotePort"];
|
||||
map.appId = (int)x["appId"];
|
||||
if (x.ContainsKey("autoExit")) { map.autoexit = (bool)x["autoExit"]; }
|
||||
map.node = node;
|
||||
if (authLoginUrl != null) { map.host = authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443); } else { map.host = serverNameComboBox.Text; }
|
||||
map.authCookie = meshcentral.authCookie;
|
||||
@@ -1329,11 +1485,17 @@ namespace MeshCentralRouter
|
||||
|
||||
// Launch any executable
|
||||
if (x.ContainsKey("launch")) {
|
||||
try {
|
||||
string lanuchString = (string)x["launch"];
|
||||
lanuchString = lanuchString.Replace("{port}", x["localPort"].ToString());
|
||||
System.Diagnostics.Process.Start(lanuchString);
|
||||
} catch (Exception) { }
|
||||
if (x["launch"].GetType() == typeof(int)) { map.appButton_Click(this, null); }
|
||||
if (x["launch"].GetType() == typeof(string))
|
||||
{
|
||||
try
|
||||
{
|
||||
string lanuchString = (string)x["launch"];
|
||||
lanuchString = lanuchString.Replace("{port}", x["localPort"].ToString());
|
||||
System.Diagnostics.Process.Start(lanuchString);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
mappingsToSetup = null;
|
||||
@@ -1370,6 +1532,7 @@ namespace MeshCentralRouter
|
||||
|
||||
private void mapPanel_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
cancelAutoClose();
|
||||
if (e.Data.GetDataPresent(DataFormats.FileDrop) == false) return;
|
||||
string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
|
||||
if ((s.Length != 1) || (s[0].ToLower().EndsWith(".mcrouter") == false)) return;
|
||||
@@ -1378,6 +1541,7 @@ namespace MeshCentralRouter
|
||||
|
||||
private void mapPanel_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
cancelAutoClose();
|
||||
if (e.Data.GetDataPresent(DataFormats.FileDrop) == false) return;
|
||||
string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
|
||||
if ((s.Length != 1) || (s[0].ToLower().EndsWith(".mcrouter") == false)) return;
|
||||
@@ -1474,11 +1638,21 @@ namespace MeshCentralRouter
|
||||
|
||||
private void devicesListView_DoubleClick(object sender, EventArgs e)
|
||||
{
|
||||
cancelAutoClose();
|
||||
if (devicesListView.SelectedItems.Count != 1) { return; }
|
||||
ListViewItem selecteditem = devicesListView.SelectedItems[0];
|
||||
NodeClass node = (NodeClass)selecteditem.Tag;
|
||||
if ((node.conn & 1) == 0) { return; } // Agent not connected on this device
|
||||
addButton_Click(null, null);
|
||||
|
||||
if (deviceDoubleClickAction == 0) { addMapToolStripMenuItem_Click(null, null); }
|
||||
if (deviceDoubleClickAction == 1) { addRelayMapToolStripMenuItem_Click(null, null); }
|
||||
if (deviceDoubleClickAction == 2) { remoteDesktopToolStripMenuItem_Click(null, null); }
|
||||
if (deviceDoubleClickAction == 3) { remoteFilesToolStripMenuItem_Click(null, null); }
|
||||
if (deviceDoubleClickAction == 4) { httpToolStripMenuItem_Click(null, null); }
|
||||
if (deviceDoubleClickAction == 5) { httpsToolStripMenuItem_Click(null, null); }
|
||||
if (deviceDoubleClickAction == 6) { rdpToolStripMenuItem_Click(null, null); }
|
||||
if (deviceDoubleClickAction == 7) { sshToolStripMenuItem_Click(null, null); }
|
||||
if (deviceDoubleClickAction == 8) { scpToolStripMenuItem_Click(null, null); }
|
||||
}
|
||||
|
||||
private void remoteDesktopToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
@@ -1515,6 +1689,73 @@ namespace MeshCentralRouter
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelAutoCloseButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
cancelAutoClose();
|
||||
}
|
||||
|
||||
public delegate void SetAutoCloseHandler();
|
||||
public void SetAutoClose()
|
||||
{
|
||||
if (this.InvokeRequired) { this.Invoke(new SetAutoCloseHandler(SetAutoClose)); return; }
|
||||
cancelAutoCloseButton1.Visible = true;
|
||||
cancelAutoCloseButton2.Visible = true;
|
||||
}
|
||||
|
||||
private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
DeviceSettingsForm f = new DeviceSettingsForm();
|
||||
f.deviceDoubleClickAction = deviceDoubleClickAction;
|
||||
f.ShowSystemTray = (notifyIcon.Visible == true);
|
||||
if (f.ShowDialog(this) == DialogResult.OK)
|
||||
{
|
||||
deviceDoubleClickAction = f.deviceDoubleClickAction;
|
||||
setRegValue("DevDoubleClickClickAction", deviceDoubleClickAction.ToString());
|
||||
setDoubleClickDeviceAction();
|
||||
if (f.ShowSystemTray)
|
||||
{
|
||||
notifyIcon.Visible = true;
|
||||
this.ShowInTaskbar = false;
|
||||
this.MinimizeBox = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
notifyIcon.Visible = false;
|
||||
this.ShowInTaskbar = true;
|
||||
this.MinimizeBox = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MainForm_KeyPress(object sender, KeyPressEventArgs e)
|
||||
{
|
||||
cancelAutoClose();
|
||||
if ((currentPanel == 4) && (devicesTabControl.SelectedIndex == 0))
|
||||
{
|
||||
if (e.KeyChar == 27)
|
||||
{
|
||||
searchTextBox.Text = "";
|
||||
}
|
||||
else if (e.KeyChar == 8)
|
||||
{
|
||||
if (searchTextBox.Text.Length > 0)
|
||||
{
|
||||
searchTextBox.Text = searchTextBox.Text.Substring(0, searchTextBox.Text.Length - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
searchTextBox.Text += e.KeyChar;
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void devicesListView_Click(object sender, EventArgs e)
|
||||
{
|
||||
cancelAutoClose();
|
||||
}
|
||||
|
||||
/*
|
||||
private delegate void displayMessageHandler(string msg, int buttons, string extra, int progress);
|
||||
private void displayMessage(string msg, int buttons = 0, string extra = "", int progress = 0)
|
||||
|
||||
1793
MainForm.resx
1793
MainForm.resx
File diff suppressed because it is too large
Load Diff
7
MapUserControl.Designer.cs
generated
7
MapUserControl.Designer.cs
generated
@@ -38,6 +38,7 @@
|
||||
this.deviceImageList = new System.Windows.Forms.ImageList(this.components);
|
||||
this.mainContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.statsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.autoExitTimer = new System.Windows.Forms.Timer(this.components);
|
||||
((System.ComponentModel.ISupportInitialize)(this.devicePictureBox)).BeginInit();
|
||||
this.mainContextMenuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@@ -99,6 +100,11 @@
|
||||
resources.ApplyResources(this.statsToolStripMenuItem, "statsToolStripMenuItem");
|
||||
this.statsToolStripMenuItem.Click += new System.EventHandler(this.statsToolStripMenuItem_Click);
|
||||
//
|
||||
// autoExitTimer
|
||||
//
|
||||
this.autoExitTimer.Interval = 1000;
|
||||
this.autoExitTimer.Tick += new System.EventHandler(this.autoExitTimer_Tick);
|
||||
//
|
||||
// MapUserControl
|
||||
//
|
||||
resources.ApplyResources(this, "$this");
|
||||
@@ -128,5 +134,6 @@
|
||||
private System.Windows.Forms.ImageList deviceImageList;
|
||||
private System.Windows.Forms.ContextMenuStrip mainContextMenuStrip;
|
||||
private System.Windows.Forms.ToolStripMenuItem statsToolStripMenuItem;
|
||||
private System.Windows.Forms.Timer autoExitTimer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace MeshCentralRouter
|
||||
public bool xdebug = false;
|
||||
public bool inaddrany = false;
|
||||
public MappingStats stats = null;
|
||||
public bool autoexit = false;
|
||||
|
||||
public static void saveToRegistry(string name, string value)
|
||||
{
|
||||
@@ -104,6 +105,9 @@ namespace MeshCentralRouter
|
||||
|
||||
public void appButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
bool shift = false;
|
||||
if (Control.ModifierKeys == Keys.Shift) { shift = true; }
|
||||
|
||||
if (appId == 1) { System.Diagnostics.Process.Start("http://localhost:" + mapper.localport); }
|
||||
if (appId == 2) { System.Diagnostics.Process.Start("https://localhost:" + mapper.localport); }
|
||||
if (appId == 3)
|
||||
@@ -129,40 +133,81 @@ namespace MeshCentralRouter
|
||||
// Launch the process
|
||||
try { proc = System.Diagnostics.Process.Start(cmd, args); }
|
||||
catch (System.ComponentModel.Win32Exception) { }
|
||||
|
||||
// Setup auto-exit
|
||||
if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; }
|
||||
}
|
||||
if (appId == 4)
|
||||
{
|
||||
using (AppLaunchForm f = new AppLaunchForm())
|
||||
string puttyPath = loadFromRegistry("PuttyPath");
|
||||
if ((shift == false) && (File.Exists(puttyPath)))
|
||||
{
|
||||
// Launch the process
|
||||
System.Diagnostics.Process proc = null;
|
||||
f.SetAppName(Properties.Resources.PuttyAppName);
|
||||
f.SetAppLink("http://www.chiark.greenend.org.uk/~sgtatham/putty/");
|
||||
f.SetAppPath(loadFromRegistry("PuttyPath"));
|
||||
if (f.ShowDialog(this) == DialogResult.OK)
|
||||
string args = "-ssh 127.0.0.1 -P " + mapper.localport;
|
||||
try { proc = System.Diagnostics.Process.Start(puttyPath, args); }
|
||||
catch (System.ComponentModel.Win32Exception) { }
|
||||
|
||||
// Setup auto-exit
|
||||
if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; }
|
||||
}
|
||||
else
|
||||
{
|
||||
using (AppLaunchForm f = new AppLaunchForm())
|
||||
{
|
||||
saveToRegistry("PuttyPath", f.GetAppPath());
|
||||
string args = "-ssh 127.0.0.1 -P " + mapper.localport;
|
||||
// Launch the process
|
||||
try { proc = System.Diagnostics.Process.Start(f.GetAppPath(), args); }
|
||||
catch (System.ComponentModel.Win32Exception) { }
|
||||
System.Diagnostics.Process proc = null;
|
||||
f.SetAppName(Properties.Resources.PuttyAppName);
|
||||
f.SetAppLink("http://www.chiark.greenend.org.uk/~sgtatham/putty/");
|
||||
f.SetAppPath(puttyPath);
|
||||
if (f.ShowDialog(this) == DialogResult.OK)
|
||||
{
|
||||
saveToRegistry("PuttyPath", f.GetAppPath());
|
||||
string args = "-ssh 127.0.0.1 -P " + mapper.localport;
|
||||
|
||||
// Launch the process
|
||||
try { proc = System.Diagnostics.Process.Start(f.GetAppPath(), args); }
|
||||
catch (System.ComponentModel.Win32Exception) { }
|
||||
|
||||
// Setup auto-exit
|
||||
if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (appId == 5)
|
||||
{
|
||||
using (AppLaunchForm f = new AppLaunchForm())
|
||||
string winScpPath = loadFromRegistry("WinSCPPath");
|
||||
if ((shift == false) && (File.Exists(winScpPath)))
|
||||
{
|
||||
// Launch the process
|
||||
System.Diagnostics.Process proc = null;
|
||||
f.SetAppName(Properties.Resources.WinscpAppName);
|
||||
f.SetAppLink("http://winscp.net/");
|
||||
f.SetAppPath(loadFromRegistry("WinSCPPath"));
|
||||
if (f.ShowDialog(this) == DialogResult.OK)
|
||||
string args = "scp://127.0.0.1:" + mapper.localport;
|
||||
try { proc = System.Diagnostics.Process.Start(winScpPath, args); }
|
||||
catch (System.ComponentModel.Win32Exception) { }
|
||||
|
||||
// Setup auto-exit
|
||||
if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; }
|
||||
}
|
||||
else
|
||||
{
|
||||
using (AppLaunchForm f = new AppLaunchForm())
|
||||
{
|
||||
saveToRegistry("WinSCPPath", f.GetAppPath());
|
||||
string args = "scp://127.0.0.1:" + mapper.localport;
|
||||
// Launch the process
|
||||
try { proc = System.Diagnostics.Process.Start(f.GetAppPath(), args); }
|
||||
catch (System.ComponentModel.Win32Exception) { }
|
||||
System.Diagnostics.Process proc = null;
|
||||
f.SetAppName(Properties.Resources.WinscpAppName);
|
||||
f.SetAppLink("http://winscp.net/");
|
||||
f.SetAppPath(winScpPath);
|
||||
if (f.ShowDialog(this) == DialogResult.OK)
|
||||
{
|
||||
saveToRegistry("WinSCPPath", f.GetAppPath());
|
||||
string args = "scp://127.0.0.1:" + mapper.localport;
|
||||
|
||||
// Launch the process
|
||||
try { proc = System.Diagnostics.Process.Start(f.GetAppPath(), args); }
|
||||
catch (System.ComponentModel.Win32Exception) { }
|
||||
|
||||
// Setup auto-exit
|
||||
if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,5 +236,11 @@ namespace MeshCentralRouter
|
||||
stats.Close();
|
||||
stats = null;
|
||||
}
|
||||
|
||||
private void autoExitTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if (parent.autoExitProc == null) return;
|
||||
if (parent.autoExitProc.HasExited == true) { Application.Exit(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
|
||||
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
|
||||
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAy
|
||||
mgAAAk1TRnQBSQFMAgEBCAEAAVABAAFQAQABMgEAATIBAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAHI
|
||||
mgAAAk1TRnQBSQFMAgEBCAEAAVgBAAFYAQABMgEAATIBAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAHI
|
||||
AwABlgMAAQEBAAEQBQABYAHq/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A
|
||||
/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A
|
||||
/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A
|
||||
@@ -929,6 +929,12 @@
|
||||
<metadata name="mainContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>156, 17</value>
|
||||
</metadata>
|
||||
<data name="statsToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>108, 22</value>
|
||||
</data>
|
||||
<data name="statsToolStripMenuItem.Text" xml:space="preserve">
|
||||
<value>Stats...</value>
|
||||
</data>
|
||||
<data name="mainContextMenuStrip.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>109, 26</value>
|
||||
</data>
|
||||
@@ -938,12 +944,9 @@
|
||||
<data name=">>mainContextMenuStrip.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="statsToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>108, 22</value>
|
||||
</data>
|
||||
<data name="statsToolStripMenuItem.Text" xml:space="preserve">
|
||||
<value>Stats...</value>
|
||||
</data>
|
||||
<metadata name="autoExitTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>334, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
@@ -951,7 +954,7 @@
|
||||
<value>6, 13</value>
|
||||
</data>
|
||||
<data name="$this.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>425, 58</value>
|
||||
<value>421, 54</value>
|
||||
</data>
|
||||
<data name=">>deviceImageList.Name" xml:space="preserve">
|
||||
<value>deviceImageList</value>
|
||||
@@ -965,6 +968,12 @@
|
||||
<data name=">>statsToolStripMenuItem.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>autoExitTimer.Name" xml:space="preserve">
|
||||
<value>autoExitTimer</value>
|
||||
</data>
|
||||
<data name=">>autoExitTimer.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.Timer, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>$this.Name" xml:space="preserve">
|
||||
<value>MapUserControl</value>
|
||||
</data>
|
||||
|
||||
@@ -100,6 +100,12 @@
|
||||
<Compile Include="AppLaunchForm.Designer.cs">
|
||||
<DependentUpon>AppLaunchForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="DeviceSettingsForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="DeviceSettingsForm.Designer.cs">
|
||||
<DependentUpon>DeviceSettingsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FileDeletePromptForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@@ -229,6 +235,12 @@
|
||||
<Compile Include="SettingsForm.Designer.cs">
|
||||
<DependentUpon>SettingsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UpdateForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="UpdateForm.Designer.cs">
|
||||
<DependentUpon>UpdateForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="WebSocketClient.cs" />
|
||||
<Compile Include="Win32Api.cs" />
|
||||
<EmbeddedResource Include="AddPortMapForm.cs.resx">
|
||||
@@ -384,6 +396,9 @@
|
||||
<EmbeddedResource Include="AppLaunchForm.zh-chs.resx">
|
||||
<DependentUpon>AppLaunchForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="DeviceSettingsForm.resx">
|
||||
<DependentUpon>DeviceSettingsForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="DeviceUserControl.cs.resx">
|
||||
<DependentUpon>DeviceUserControl.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
@@ -744,6 +759,9 @@
|
||||
<EmbeddedResource Include="SettingsForm.zh-chs.resx">
|
||||
<DependentUpon>SettingsForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="UpdateForm.resx">
|
||||
<DependentUpon>UpdateForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<None Include="app.manifest">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2009-2018 Intel Corporation
|
||||
Copyright 2009-2020 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -218,6 +218,7 @@ namespace MeshCentralRouter
|
||||
wc.WriteStringWebSocket("{\"action\":\"nodes\"}");
|
||||
wc.WriteStringWebSocket("{\"action\":\"authcookie\"}");
|
||||
wc.WriteStringWebSocket("{\"action\":\"logincookie\"}");
|
||||
wc.WriteStringWebSocket("{\"action\":\"meshToolInfo\",\"name\":\"MeshCentralRouter\"}");
|
||||
break;
|
||||
}
|
||||
case "authcookie":
|
||||
@@ -582,6 +583,33 @@ namespace MeshCentralRouter
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "meshToolInfo":
|
||||
{
|
||||
if (onToolUpdate == null) return;
|
||||
if (jsonAction.ContainsKey("hash") && jsonAction.ContainsKey("url"))
|
||||
{
|
||||
// MeshCentral Router hash on the server
|
||||
string hash = (string)jsonAction["hash"];
|
||||
|
||||
// Hash our own executable
|
||||
byte[] selfHash;
|
||||
using (var sha384 = SHA384Managed.Create()) { using (var stream = File.OpenRead(System.Reflection.Assembly.GetEntryAssembly().Location)) { selfHash = sha384.ComputeHash(stream); } }
|
||||
string selfExecutableHashHex = BitConverter.ToString(selfHash).Replace("-", string.Empty).ToLower();
|
||||
|
||||
// Get login key
|
||||
string url = jsonAction["url"] + "&auth=" + authCookie;
|
||||
string loginkey = getValueFromQueryString(wsurl.Query, "key");
|
||||
if (loginkey != null) { url += ("&key=" + loginkey); }
|
||||
|
||||
// Server TLS certificate hash
|
||||
string serverhash = null;
|
||||
if (jsonAction.ContainsKey("serverhash")) { serverhash = jsonAction["serverhash"].ToString(); }
|
||||
|
||||
// If the hashes don't match, event the tool update with URL
|
||||
if (selfExecutableHashHex != hash) { onToolUpdate((string)url, (string)jsonAction["hash"], (int)jsonAction["size"], serverhash); }
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
@@ -589,6 +617,18 @@ namespace MeshCentralRouter
|
||||
}
|
||||
}
|
||||
|
||||
private static string getValueFromQueryString(string query, string name)
|
||||
{
|
||||
if ((query == null) || (name == null)) return null;
|
||||
int i = query.IndexOf("?" + name + "=");
|
||||
if (i == -1) { i = query.IndexOf("&" + name + "="); }
|
||||
if (i == -1) return null;
|
||||
string r = query.Substring(i + name.Length + 2);
|
||||
i = r.IndexOf("&");
|
||||
if (i >= 0) { r = r.Substring(0, i); }
|
||||
return r;
|
||||
}
|
||||
|
||||
public delegate void onStateChangedHandler(int state);
|
||||
public event onStateChangedHandler onStateChanged;
|
||||
public void changeState(int newState) { if (constate != newState) { constate = newState; if (onStateChanged != null) { onStateChanged(constate); } } }
|
||||
@@ -601,6 +641,8 @@ namespace MeshCentralRouter
|
||||
public event onClipboardDataHandler onClipboardData;
|
||||
public delegate void twoFactorCookieHandler(string cookie);
|
||||
public event twoFactorCookieHandler onTwoFactorCookie;
|
||||
public delegate void toolUpdateHandler(string url, string hash, int size, string serverhash);
|
||||
public event toolUpdateHandler onToolUpdate;
|
||||
|
||||
public class xwebclient : IDisposable
|
||||
{
|
||||
|
||||
@@ -31,6 +31,6 @@ using System.Runtime.InteropServices;
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.*")]
|
||||
//[assembly: AssemblyVersion("1.0.0.0")]
|
||||
//[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
||||
@@ -2059,7 +2059,7 @@ This will allow special keys</value>
|
||||
<value>CenterParent</value>
|
||||
</data>
|
||||
<data name="$this.Text" xml:space="preserve">
|
||||
<value>Settings</value>
|
||||
<value>Mapping Settings</value>
|
||||
</data>
|
||||
<data name=">>$this.Name" xml:space="preserve">
|
||||
<value>SettingsForm</value>
|
||||
|
||||
146
UpdateForm.Designer.cs
generated
Normal file
146
UpdateForm.Designer.cs
generated
Normal file
@@ -0,0 +1,146 @@
|
||||
namespace MeshCentralRouter
|
||||
{
|
||||
partial class UpdateForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UpdateForm));
|
||||
this.cancelButton = new System.Windows.Forms.Button();
|
||||
this.okButton = new System.Windows.Forms.Button();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.mainLabel = new System.Windows.Forms.Label();
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.updateProgressBar = new System.Windows.Forms.ProgressBar();
|
||||
this.groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// cancelButton
|
||||
//
|
||||
this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
this.cancelButton.Location = new System.Drawing.Point(294, 155);
|
||||
this.cancelButton.Name = "cancelButton";
|
||||
this.cancelButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.cancelButton.TabIndex = 0;
|
||||
this.cancelButton.Text = "Cancel";
|
||||
this.cancelButton.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// okButton
|
||||
//
|
||||
this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.okButton.Location = new System.Drawing.Point(213, 155);
|
||||
this.okButton.Name = "okButton";
|
||||
this.okButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.okButton.TabIndex = 1;
|
||||
this.okButton.Text = "OK";
|
||||
this.okButton.UseVisualStyleBackColor = true;
|
||||
this.okButton.Click += new System.EventHandler(this.okButton_Click);
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.groupBox1.Controls.Add(this.updateProgressBar);
|
||||
this.groupBox1.Controls.Add(this.pictureBox1);
|
||||
this.groupBox1.Controls.Add(this.mainLabel);
|
||||
this.groupBox1.Location = new System.Drawing.Point(12, 12);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(357, 137);
|
||||
this.groupBox1.TabIndex = 2;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "MeshCentral Router Update";
|
||||
//
|
||||
// mainLabel
|
||||
//
|
||||
this.mainLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.mainLabel.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.mainLabel.Location = new System.Drawing.Point(131, 19);
|
||||
this.mainLabel.Name = "mainLabel";
|
||||
this.mainLabel.Size = new System.Drawing.Size(220, 115);
|
||||
this.mainLabel.TabIndex = 0;
|
||||
this.mainLabel.Text = "This MeshCentral Server uses a different version of this tool. Click ok to downlo" +
|
||||
"ad and update.";
|
||||
//
|
||||
// pictureBox1
|
||||
//
|
||||
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.pictureBox1.Image = global::MeshCentralRouter.Properties.Resources.MeshCentral;
|
||||
this.pictureBox1.Location = new System.Drawing.Point(6, 19);
|
||||
this.pictureBox1.Name = "pictureBox1";
|
||||
this.pictureBox1.Size = new System.Drawing.Size(119, 112);
|
||||
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
|
||||
this.pictureBox1.TabIndex = 1;
|
||||
this.pictureBox1.TabStop = false;
|
||||
//
|
||||
// updateProgressBar
|
||||
//
|
||||
this.updateProgressBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.updateProgressBar.Location = new System.Drawing.Point(134, 110);
|
||||
this.updateProgressBar.Name = "updateProgressBar";
|
||||
this.updateProgressBar.Size = new System.Drawing.Size(217, 20);
|
||||
this.updateProgressBar.TabIndex = 2;
|
||||
this.updateProgressBar.Visible = false;
|
||||
//
|
||||
// UpdateForm
|
||||
//
|
||||
this.AcceptButton = this.okButton;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.CancelButton = this.cancelButton;
|
||||
this.ClientSize = new System.Drawing.Size(381, 190);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Controls.Add(this.okButton);
|
||||
this.Controls.Add(this.cancelButton);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "UpdateForm";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
this.Text = "Update";
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Button cancelButton;
|
||||
private System.Windows.Forms.Button okButton;
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.Label mainLabel;
|
||||
private System.Windows.Forms.PictureBox pictureBox1;
|
||||
private System.Windows.Forms.ProgressBar updateProgressBar;
|
||||
}
|
||||
}
|
||||
142
UpdateForm.cs
Normal file
142
UpdateForm.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Security;
|
||||
using System.Windows.Forms;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
|
||||
namespace MeshCentralRouter
|
||||
{
|
||||
public partial class UpdateForm : Form
|
||||
{
|
||||
private string url = null;
|
||||
private string hash = null;
|
||||
private int size = 0;
|
||||
private string[] args = null;
|
||||
private string serverTlsCertHash = null;
|
||||
|
||||
public UpdateForm(string url, string hash, int size, string[] args, string serverhash)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.url = url;
|
||||
this.hash = hash;
|
||||
this.size = size;
|
||||
this.args = args;
|
||||
this.serverTlsCertHash = serverhash;
|
||||
}
|
||||
|
||||
private void okButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
DownloadUpdate();
|
||||
}
|
||||
|
||||
private void Client_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
|
||||
{
|
||||
updateProgressBar.Value = e.ProgressPercentage;
|
||||
}
|
||||
|
||||
private void DownloadUpdate()
|
||||
{
|
||||
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
|
||||
Uri x = webRequest.RequestUri;
|
||||
webRequest.Method = "GET";
|
||||
webRequest.Timeout = 10000;
|
||||
webRequest.BeginGetResponse(new AsyncCallback(DownloadUpdateRespone), webRequest);
|
||||
webRequest.ServerCertificateValidationCallback += RemoteCertificateValidationCallback;
|
||||
updateProgressBar.Visible = true;
|
||||
}
|
||||
|
||||
public bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
{
|
||||
// Check MeshCentral server's TLS certificate. This is our first security layer.
|
||||
if ((serverTlsCertHash != null) && (serverTlsCertHash != certificate.GetCertHashString().ToLower()) && (serverTlsCertHash != GetMeshKeyHash(certificate).ToLower()) && (serverTlsCertHash != GetMeshCertHash(certificate).ToLower())) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public delegate void updateProgressHandler(int ptr, int total);
|
||||
public void updateProgress(int ptr, int total)
|
||||
{
|
||||
if (this.InvokeRequired) { this.Invoke(new updateProgressHandler(updateProgress), ptr, total); return; }
|
||||
updateProgressBar.Visible = true;
|
||||
updateProgressBar.Maximum = total;
|
||||
if (ptr <= total) { updateProgressBar.Value = ptr; } else { updateProgressBar.Value = total; }
|
||||
}
|
||||
|
||||
public delegate void updateMessageHandler(string msg, int buttons);
|
||||
public void updateMessage(string msg, int buttons)
|
||||
{
|
||||
if (this.InvokeRequired) { this.Invoke(new updateMessageHandler(updateMessage), msg, buttons); return; }
|
||||
mainLabel.Text = msg;
|
||||
okButton.Enabled = ((buttons & 1) != 0);
|
||||
cancelButton.Enabled = ((buttons & 2) != 0);
|
||||
updateProgressBar.Visible = ((buttons & 4) != 0);
|
||||
}
|
||||
|
||||
private void DownloadUpdateRespone(IAsyncResult asyncResult)
|
||||
{
|
||||
long received = 0;
|
||||
HttpWebRequest webRequest = (HttpWebRequest)asyncResult.AsyncState;
|
||||
try
|
||||
{
|
||||
// Hash our own executable
|
||||
using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.EndGetResponse(asyncResult))
|
||||
{
|
||||
byte[] buffer = new byte[4096];
|
||||
FileStream fileStream = File.OpenWrite(System.Reflection.Assembly.GetEntryAssembly().Location + ".update.exe");
|
||||
using (Stream input = webResponse.GetResponseStream())
|
||||
{
|
||||
int size = input.Read(buffer, 0, buffer.Length);
|
||||
while (size > 0)
|
||||
{
|
||||
fileStream.Write(buffer, 0, size);
|
||||
received += size;
|
||||
updateProgress((int)received, (int)size);
|
||||
size = input.Read(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
fileStream.Flush();
|
||||
fileStream.Close();
|
||||
|
||||
// Hash the resulting file
|
||||
byte[] downloadHash;
|
||||
using (var sha384 = SHA384Managed.Create()) { using (var stream = File.OpenRead(System.Reflection.Assembly.GetEntryAssembly().Location + ".update.exe")) { downloadHash = sha384.ComputeHash(stream); } }
|
||||
string downloadHashHex = BitConverter.ToString(downloadHash).Replace("-", string.Empty).ToLower();
|
||||
if (downloadHashHex != hash) {
|
||||
updateMessage("Invalid download.", 2);
|
||||
File.Delete(System.Reflection.Assembly.GetEntryAssembly().Location + ".update.exe");
|
||||
} else {
|
||||
updateMessage("Updating...", 0);
|
||||
Process.Start(System.Reflection.Assembly.GetEntryAssembly().Location + ".update.exe", "-update:" + System.Reflection.Assembly.GetEntryAssembly().Location + " " + string.Join(" ", args));
|
||||
Application.Exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { updateMessage("Error: " + ex.ToString(), 2); }
|
||||
}
|
||||
|
||||
|
||||
// Return a modified base64 SHA384 hash string of the certificate public key
|
||||
public static string GetMeshKeyHash(X509Certificate cert)
|
||||
{
|
||||
return ByteArrayToHexString(new SHA384Managed().ComputeHash(cert.GetPublicKey()));
|
||||
}
|
||||
|
||||
// Return a modified base64 SHA384 hash string of the certificate
|
||||
public static string GetMeshCertHash(X509Certificate cert)
|
||||
{
|
||||
return ByteArrayToHexString(new SHA384Managed().ComputeHash(cert.GetRawCertData()));
|
||||
}
|
||||
|
||||
public static string ByteArrayToHexString(byte[] Bytes)
|
||||
{
|
||||
StringBuilder Result = new StringBuilder(Bytes.Length * 2);
|
||||
string HexAlphabet = "0123456789ABCDEF";
|
||||
foreach (byte B in Bytes) { Result.Append(HexAlphabet[(int)(B >> 4)]); Result.Append(HexAlphabet[(int)(B & 0xF)]); }
|
||||
return Result.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
1815
UpdateForm.resx
Normal file
1815
UpdateForm.resx
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user