1
0
mirror of https://github.com/Ylianst/MeshCentralRouter synced 2025-12-06 00:13:33 +00:00

Added mcrouter:// installation.

This commit is contained in:
Ylian Saint-Hilaire
2020-05-30 13:54:14 -07:00
parent c313f692c2
commit 944fbe7e9a
11 changed files with 2095 additions and 19 deletions

128
InstallForm.Designer.cs generated Normal file
View File

@@ -0,0 +1,128 @@
namespace MeshCentralRouter
{
partial class InstallForm
{
/// <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(InstallForm));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.cancelButton = new System.Windows.Forms.Button();
this.okButton = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Image = global::MeshCentralRouter.Properties.Resources.install;
this.pictureBox1.Location = new System.Drawing.Point(6, 29);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(250, 184);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// 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(200, 300);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 23);
this.cancelButton.TabIndex = 1;
this.cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true;
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
//
// 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(119, 300);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(75, 23);
this.okButton.TabIndex = 2;
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.label1);
this.groupBox1.Controls.Add(this.pictureBox1);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(263, 282);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "MeshCentral Router Installation";
//
// label1
//
this.label1.Location = new System.Drawing.Point(6, 219);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(250, 59);
this.label1.TabIndex = 1;
this.label1.Text = "Click ok to register MeshCentral Router on your system as the handler for the \"mc" +
"router://\" protocol. This will allow the MeshCentral web site to launch this app" +
"lication when needed.";
//
// InstallForm
//
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(287, 335);
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.Name = "InstallForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Installation";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
}
}

30
InstallForm.cs Normal file
View File

@@ -0,0 +1,30 @@
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 InstallForm : Form
{
public InstallForm()
{
InitializeComponent();
}
private void okButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
}
private void cancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
}
}

1815
InstallForm.resx Normal file

File diff suppressed because it is too large Load Diff

21
MainForm.Designer.cs generated
View File

@@ -35,6 +35,7 @@
this.mainTabControl = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.panel1 = new System.Windows.Forms.Panel();
this.installButton = new System.Windows.Forms.Button();
this.stateLabel = new System.Windows.Forms.Label();
this.label28 = new System.Windows.Forms.Label();
this.label27 = new System.Windows.Forms.Label();
@@ -103,6 +104,7 @@
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.installTimer = new System.Windows.Forms.Timer(this.components);
this.panel5.SuspendLayout();
this.mainPanel.SuspendLayout();
this.mainTabControl.SuspendLayout();
@@ -180,6 +182,7 @@
//
// panel1
//
this.panel1.Controls.Add(this.installButton);
this.panel1.Controls.Add(this.stateLabel);
this.panel1.Controls.Add(this.label28);
this.panel1.Controls.Add(this.label27);
@@ -199,6 +202,18 @@
this.panel1.Size = new System.Drawing.Size(478, 316);
this.panel1.TabIndex = 6;
//
// installButton
//
this.installButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.installButton.Location = new System.Drawing.Point(6, 285);
this.installButton.Name = "installButton";
this.installButton.Size = new System.Drawing.Size(75, 23);
this.installButton.TabIndex = 20;
this.installButton.Text = "Install...";
this.installButton.UseVisualStyleBackColor = true;
this.installButton.Visible = false;
this.installButton.Click += new System.EventHandler(this.installButton_Click);
//
// stateLabel
//
this.stateLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
@@ -950,6 +965,10 @@
this.exitToolStripMenuItem.Text = "E&xit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click_1);
//
// installTimer
//
this.installTimer.Tick += new System.EventHandler(this.installTimer_Tick);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -1073,6 +1092,8 @@
private System.Windows.Forms.ToolStripMenuItem sortByNameToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem sortByGroupToolStripMenuItem;
private System.Windows.Forms.Button smsTokenButton;
private System.Windows.Forms.Button installButton;
private System.Windows.Forms.Timer installTimer;
}
}

View File

@@ -18,7 +18,9 @@ using System;
using System.Net;
using System.Reflection;
using System.Collections;
using System.Diagnostics;
using System.Windows.Forms;
using System.Security.Principal;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Win32;
@@ -41,6 +43,7 @@ namespace MeshCentralRouter
public bool sendEmailToken = false;
public bool sendSMSToken = false;
public Uri authLoginUrl = null;
public Process installProcess = null;
public void setRegValue(string name, string value) {
try { Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router", name, value); } catch (Exception) { }
@@ -49,6 +52,19 @@ namespace MeshCentralRouter
try { return Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router", name, value).ToString(); } catch (Exception) { return value; }
}
public bool isRouterHooked()
{
try
{
return (
((string)Registry.GetValue(@"HKEY_CLASSES_ROOT\mcrouter", "", null) == "MeshCentral Router") &&
((string)Registry.GetValue(@"HKEY_CLASSES_ROOT\mcrouter\shell\open\command", "", null) == "\"" + Assembly.GetEntryAssembly().Location + "\" \"%1\"")
);
}
catch (Exception) { }
return false;
}
public void hookRouter()
{
try
@@ -64,7 +80,40 @@ namespace MeshCentralRouter
try { Registry.ClassesRoot.DeleteSubKeyTree("mcrouter"); } catch (Exception) { }
}
public static void DeleteSubKeyTree(RegistryKey key, string subkey) { if (key.OpenSubKey(subkey) == null) { return; } DeleteSubKeyTree(key, subkey); }
private void hookRouterEx()
{
if (IsAdministrator() == false)
{
// Restart program and run as admin
var exeName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
ProcessStartInfo startInfo = new ProcessStartInfo(exeName, "-install");
startInfo.Verb = "runas";
try { installProcess = System.Diagnostics.Process.Start(startInfo); } catch (Exception) { return; }
installTimer.Enabled = true;
installButton.Visible = false;
} else {
hookRouter();
installButton.Visible = !isRouterHooked();
}
}
private void installTimer_Tick(object sender, EventArgs e)
{
if ((installProcess == null) || (installProcess.HasExited == true))
{
installTimer.Enabled = false;
installButton.Visible = !isRouterHooked();
}
}
private bool IsAdministrator()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
public void DeleteSubKeyTree(RegistryKey key, string subkey) { if (key.OpenSubKey(subkey) == null) { return; } DeleteSubKeyTree(key, subkey); }
public class DeviceComparer : IComparer
{
@@ -116,6 +165,8 @@ namespace MeshCentralRouter
int argflags = 0;
foreach (string arg in this.args) {
if (arg.ToLower() == "-install") { hookRouter(); forceExit = true; return; }
if (arg.ToLower() == "-uninstall") { unHookRouter(); forceExit = true; return; }
if (arg.ToLower() == "-debug") { debug = true; }
if (arg.ToLower() == "-ignorecert") { ignoreCert = true; }
if (arg.ToLower() == "-all") { inaddrany = true; }
@@ -129,8 +180,8 @@ namespace MeshCentralRouter
}
autoLogin = (argflags == 7);
unHookRouter();
//hookRouter();
// Check MeshCentral .mcrouter hook
installButton.Visible = !isRouterHooked();
}
private void setPanel(int newPanel)
@@ -1023,6 +1074,12 @@ namespace MeshCentralRouter
updateDeviceList();
}
private void installButton_Click(object sender, EventArgs e)
{
InstallForm form = new InstallForm();
if (form.ShowDialog(this) == DialogResult.OK) { hookRouterEx(); }
}
/*
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)

View File

@@ -117,12 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="mainContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>613, 17</value>
</metadata>
<data name="label5.Text" xml:space="preserve">
<value>This server presented a un-trusted certificate. This may indicate that this is not the correct server or that the server does not have a valid certificate. It is not recommanded, but you can press the ignore button to continue connection to this server.</value>
</data>
<metadata name="mainContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>613, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="settingsPictureBox.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
@@ -1863,6 +1863,9 @@
AADAPwAAwD8AAMA/AADAPwAA
</value>
</data>
<metadata name="installTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>791, 17</value>
</metadata>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAA0AMDAQAAEABABoBgAA1gAAACAgEAABAAQA6AIAAD4HAAAYGBAAAQAEAOgBAAAmCgAAEBAQAAEA

View File

@@ -98,6 +98,12 @@
<Compile Include="AppLaunchForm.Designer.cs">
<DependentUpon>AppLaunchForm.cs</DependentUpon>
</Compile>
<Compile Include="InstallForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="InstallForm.Designer.cs">
<DependentUpon>InstallForm.cs</DependentUpon>
</Compile>
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
@@ -167,6 +173,9 @@
<EmbeddedResource Include="AppLaunchForm.resx">
<DependentUpon>AppLaunchForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="InstallForm.resx">
<DependentUpon>InstallForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
<SubType>Designer</SubType>
@@ -214,6 +223,7 @@
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\install.png" />
<None Include="HelpImages\HelpRelayMap.png" />
<Content Include="MeshServer.ico" />
</ItemGroup>
@@ -234,9 +244,7 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -31,7 +31,8 @@ namespace MeshCentralRouter
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Properties.Settings.Default.Upgrade();
Application.Run(new MainForm(args));
MainForm main = new MainForm(args);
if (main.forceExit == false) { Application.Run(main); }
}
}

View File

@@ -128,6 +128,16 @@ namespace MeshCentralRouter.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap install {
get {
object obj = ResourceManager.GetObject("install", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>

View File

@@ -118,6 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="MeshIcon50T" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>../Resources/MeshIcon50T.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Empty-Banner" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>../Resources/Empty-Banner.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
@@ -130,12 +133,12 @@
<data name="MC2-Logo" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>../Resources/MC2-Logo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Help20" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>../Resources/Help20.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="CertMgrForm_Del" xml:space="preserve">
<value>Confirm Delete</value>
</data>
<data name="MC2-Banner" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>../Resources/MC2-Banner.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="MsgBox_Import_Error" xml:space="preserve">
<value>Incorrect file or password</value>
</data>
@@ -148,16 +151,16 @@
<data name="MeshServerLogo" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>../Resources/MeshServerLogo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Help20" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>../Resources/Help20.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="HelpRelayMap" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>../Resources/HelpRelayMap.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="MsgBox_Import_Cert" xml:space="preserve">
<value>Cert Import</value>
</data>
<data name="MeshIcon50T" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>../Resources/MeshIcon50T.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="MC2-Banner" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>../Resources/MC2-Banner.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="HelpRelayMap" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>../Resources/HelpRelayMap.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="install" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\install.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

BIN
Resources/install.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB