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

Added custom app support.

This commit is contained in:
Ylian Saint-Hilaire
2022-05-12 16:07:33 -07:00
parent 95d1a442be
commit bf668eae23
19 changed files with 6885 additions and 431 deletions

View File

@@ -138,7 +138,6 @@
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

View File

@@ -16,6 +16,7 @@ limitations under the License.
using System;
using System.Windows.Forms;
using System.Collections.Generic;
namespace MeshCentralRouter
{
@@ -43,13 +44,25 @@ namespace MeshCentralRouter
if (x == 3) { return 4; } // PuTTY
if (x == 4) { return 3; } // RDP
if (x == 5) { return 5; } // WinSCP
return x;
return 0;
}
public string getAppIdStr()
{
int x = (int)appComboBox.SelectedIndex;
if (x < 6) { return null; } // Custom or pre-defined
return apps[x - 6][1];
}
public NodeClass getNode() { return (NodeClass)nodeComboBox.SelectedItem; }
public void setNode(NodeClass node) { selectedNode = node; }
private List<String[]> apps = null;
private void AddPortMapForm_Load(object sender, EventArgs e)
{
// Add any custom applications
apps = Settings.GetApplications();
if (apps != null) { foreach (String[] app in apps) { appComboBox.Items.Add(app[0]); } }
if (selectedNode == null)
{
// Fill the groups

View File

@@ -140,7 +140,6 @@
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

View File

@@ -17,6 +17,7 @@ limitations under the License.
using System;
using System.Net;
using System.Windows.Forms;
using System.Collections.Generic;
namespace MeshCentralRouter
{
@@ -46,13 +47,25 @@ namespace MeshCentralRouter
if (x == 3) { return 4; } // PuTTY
if (x == 4) { return 3; } // RDP
if (x == 5) { return 5; } // WinSCP
return x;
return 0;
}
public string getAppIdStr()
{
int x = (int)appComboBox.SelectedIndex;
if (x < 6) { return null; } // Custom or pre-defined
return apps[x - 6][1];
}
public NodeClass getNode() { return (NodeClass)nodeComboBox.SelectedItem; }
public void setNode(NodeClass node) { selectedNode = node; }
private List<String[]> apps = null;
private void AddRelayMapForm_Load(object sender, EventArgs e)
{
// Add any custom applications
apps = Settings.GetApplications();
if (apps != null) { foreach (String[] app in apps) { appComboBox.Items.Add(app[0]); } }
if (selectedNode == null)
{
// Fill the groups

211
CustomAppsAddForm.Designer.cs generated Normal file
View File

@@ -0,0 +1,211 @@
namespace MeshCentralRouter
{
partial class CustomAppsAddForm
{
/// <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(CustomAppsAddForm));
this.okButton = new System.Windows.Forms.Button();
this.cancelButton = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.nameTextBox = new System.Windows.Forms.TextBox();
this.protocolTextBox = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.commandTextBox = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label4 = new System.Windows.Forms.Label();
this.selectFileButton = new System.Windows.Forms.Button();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// 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(244, 160);
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(325, 160);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 23);
this.cancelButton.TabIndex = 5;
this.cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true;
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(6, 22);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 6;
this.label1.Text = "Name";
//
// nameTextBox
//
this.nameTextBox.Location = new System.Drawing.Point(116, 19);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(266, 20);
this.nameTextBox.TabIndex = 7;
this.nameTextBox.TextChanged += new System.EventHandler(this.nameTextBox_TextChanged);
//
// protocolTextBox
//
this.protocolTextBox.Location = new System.Drawing.Point(116, 45);
this.protocolTextBox.Name = "protocolTextBox";
this.protocolTextBox.Size = new System.Drawing.Size(266, 20);
this.protocolTextBox.TabIndex = 9;
this.protocolTextBox.TextChanged += new System.EventHandler(this.nameTextBox_TextChanged);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(6, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(46, 13);
this.label2.TabIndex = 8;
this.label2.Text = "Protocol";
//
// commandTextBox
//
this.commandTextBox.Location = new System.Drawing.Point(116, 71);
this.commandTextBox.Name = "commandTextBox";
this.commandTextBox.Size = new System.Drawing.Size(238, 20);
this.commandTextBox.TabIndex = 11;
this.commandTextBox.TextChanged += new System.EventHandler(this.nameTextBox_TextChanged);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(6, 74);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(54, 13);
this.label3.TabIndex = 10;
this.label3.Text = "Command";
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.selectFileButton);
this.groupBox1.Controls.Add(this.nameTextBox);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.commandTextBox);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.protocolTextBox);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(12, 56);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(388, 98);
this.groupBox1.TabIndex = 12;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Application";
//
// label4
//
this.label4.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.label4.Location = new System.Drawing.Point(12, 9);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(388, 44);
this.label4.TabIndex = 13;
this.label4.Text = "Enter a friendly name, protocol (like HTTP, RDP, VNC) and the command line and ar" +
"guments to run the application. In the command line, use %L for address and %P f" +
"or connection port.";
//
// selectFileButton
//
this.selectFileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.selectFileButton.Location = new System.Drawing.Point(360, 71);
this.selectFileButton.Name = "selectFileButton";
this.selectFileButton.Size = new System.Drawing.Size(21, 20);
this.selectFileButton.TabIndex = 12;
this.selectFileButton.Text = "...";
this.selectFileButton.UseVisualStyleBackColor = true;
this.selectFileButton.Click += new System.EventHandler(this.selectFileButton_Click);
//
// openFileDialog
//
this.openFileDialog.DefaultExt = "exe";
this.openFileDialog.Filter = "Executable|*.exe";
this.openFileDialog.Title = "Select Application Executable";
//
// CustomAppsAddForm
//
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(412, 195);
this.Controls.Add(this.label4);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.okButton);
this.Controls.Add(this.cancelButton);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CustomAppsAddForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Add Custom Application";
this.Load += new System.EventHandler(this.CustomAppsAddForm_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox nameTextBox;
private System.Windows.Forms.TextBox protocolTextBox;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox commandTextBox;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button selectFileButton;
private System.Windows.Forms.OpenFileDialog openFileDialog;
}
}

70
CustomAppsAddForm.cs Normal file
View File

@@ -0,0 +1,70 @@
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 CustomAppsAddForm : Form
{
public string appName
{
get { return nameTextBox.Text; }
set { nameTextBox.Text = value; updateInfo(); }
}
public string appProtocol
{
get { return protocolTextBox.Text; }
set { protocolTextBox.Text = value; updateInfo(); }
}
public string appCommand
{
get { return commandTextBox.Text; }
set { commandTextBox.Text = value; updateInfo(); }
}
public CustomAppsAddForm()
{
InitializeComponent();
}
public void updateInfo()
{
okButton.Enabled = (nameTextBox.Text.Length > 0) && (protocolTextBox.Text.Length > 0) && (commandTextBox.Text.Length > 0) && (nameTextBox.Text.IndexOf(' ') == -1) && (protocolTextBox.Text.IndexOf(' ') == -1);
}
private void CustomAppsAddForm_Load(object sender, EventArgs e)
{
updateInfo();
nameTextBox.Focus();
}
private void nameTextBox_TextChanged(object sender, EventArgs e)
{
updateInfo();
}
private void okButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
}
private void cancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
private void selectFileButton_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
commandTextBox.Text = openFileDialog.FileName;
}
}
}
}

1818
CustomAppsAddForm.resx Normal file

File diff suppressed because it is too large Load Diff

248
CustomAppsForm.Designer.cs generated Normal file
View File

@@ -0,0 +1,248 @@
namespace MeshCentralRouter
{
partial class CustomAppsForm
{
/// <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()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CustomAppsForm));
this.cancelButton = new System.Windows.Forms.Button();
this.okButton = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.removeButton = new System.Windows.Forms.Button();
this.addButton = new System.Windows.Forms.Button();
this.mainListView = new System.Windows.Forms.ListView();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.appContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.runToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.removeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
this.addToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBox1.SuspendLayout();
this.appContextMenuStrip.SuspendLayout();
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(320, 280);
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;
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(239, 280);
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);
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(383, 48);
this.label1.TabIndex = 2;
this.label1.Text = "Setup custom applications that MeshCentral Router can open to use port mappings. " +
"These applications match a protocol and have a command line to open the applicat" +
"ion.";
//
// 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.removeButton);
this.groupBox1.Controls.Add(this.addButton);
this.groupBox1.Controls.Add(this.mainListView);
this.groupBox1.Location = new System.Drawing.Point(15, 60);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(380, 214);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Applications";
//
// removeButton
//
this.removeButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.removeButton.Location = new System.Drawing.Point(299, 185);
this.removeButton.Name = "removeButton";
this.removeButton.Size = new System.Drawing.Size(75, 23);
this.removeButton.TabIndex = 2;
this.removeButton.Text = "Remove";
this.removeButton.UseVisualStyleBackColor = true;
this.removeButton.Click += new System.EventHandler(this.removeButton_Click);
//
// addButton
//
this.addButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.addButton.Location = new System.Drawing.Point(218, 185);
this.addButton.Name = "addButton";
this.addButton.Size = new System.Drawing.Size(75, 23);
this.addButton.TabIndex = 1;
this.addButton.Text = "Add";
this.addButton.UseVisualStyleBackColor = true;
this.addButton.Click += new System.EventHandler(this.addButton_Click);
//
// mainListView
//
this.mainListView.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.mainListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3});
this.mainListView.ContextMenuStrip = this.appContextMenuStrip;
this.mainListView.FullRowSelect = true;
this.mainListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.mainListView.Location = new System.Drawing.Point(6, 19);
this.mainListView.Name = "mainListView";
this.mainListView.Size = new System.Drawing.Size(368, 160);
this.mainListView.Sorting = System.Windows.Forms.SortOrder.Ascending;
this.mainListView.TabIndex = 0;
this.mainListView.UseCompatibleStateImageBehavior = false;
this.mainListView.View = System.Windows.Forms.View.Details;
this.mainListView.SelectedIndexChanged += new System.EventHandler(this.mainListView_SelectedIndexChanged);
//
// columnHeader1
//
this.columnHeader1.Text = "Name";
//
// columnHeader2
//
this.columnHeader2.Text = "Protocol";
//
// columnHeader3
//
this.columnHeader3.Text = "Command";
this.columnHeader3.Width = 223;
//
// appContextMenuStrip
//
this.appContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.editToolStripMenuItem,
this.runToolStripMenuItem,
this.removeToolStripMenuItem,
this.toolStripMenuItem1,
this.addToolStripMenuItem});
this.appContextMenuStrip.Name = "appContextMenuStrip";
this.appContextMenuStrip.Size = new System.Drawing.Size(118, 98);
this.appContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.appContextMenuStrip_Opening);
//
// editToolStripMenuItem
//
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(117, 22);
this.editToolStripMenuItem.Text = "&Edit...";
this.editToolStripMenuItem.Click += new System.EventHandler(this.editToolStripMenuItem_Click);
//
// runToolStripMenuItem
//
this.runToolStripMenuItem.Name = "runToolStripMenuItem";
this.runToolStripMenuItem.Size = new System.Drawing.Size(117, 22);
this.runToolStripMenuItem.Text = "R&un...";
this.runToolStripMenuItem.Click += new System.EventHandler(this.runToolStripMenuItem_Click);
//
// removeToolStripMenuItem
//
this.removeToolStripMenuItem.Name = "removeToolStripMenuItem";
this.removeToolStripMenuItem.Size = new System.Drawing.Size(117, 22);
this.removeToolStripMenuItem.Text = "&Remove";
this.removeToolStripMenuItem.Click += new System.EventHandler(this.removeButton_Click);
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(114, 6);
//
// addToolStripMenuItem
//
this.addToolStripMenuItem.Name = "addToolStripMenuItem";
this.addToolStripMenuItem.Size = new System.Drawing.Size(117, 22);
this.addToolStripMenuItem.Text = "&Add...";
this.addToolStripMenuItem.Click += new System.EventHandler(this.addButton_Click);
//
// CustomAppsForm
//
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(407, 315);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.okButton);
this.Controls.Add(this.cancelButton);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CustomAppsForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Custom Applications";
this.Load += new System.EventHandler(this.CustomAppsForm_Load);
this.groupBox1.ResumeLayout(false);
this.appContextMenuStrip.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button removeButton;
private System.Windows.Forms.Button addButton;
private System.Windows.Forms.ListView mainListView;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ContextMenuStrip appContextMenuStrip;
private System.Windows.Forms.ToolStripMenuItem runToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem removeToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;
private System.Windows.Forms.ToolStripMenuItem addToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
}
}

130
CustomAppsForm.cs Normal file
View File

@@ -0,0 +1,130 @@
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;
using System.Diagnostics;
namespace MeshCentralRouter
{
public partial class CustomAppsForm : Form
{
List<string[]> apps;
public CustomAppsForm(List<string[]> apps)
{
this.apps = apps;
InitializeComponent();
}
private void CustomAppsForm_Load(object sender, EventArgs e)
{
if (apps != null) { foreach (string[] app in apps) { mainListView.Items.Add(new ListViewItem(app)); } }
UpdateInfo();
}
public List<string[]> getApplications()
{
List<string[]> r = new List<string[]>();
foreach (ListViewItem l in mainListView.Items)
{
string[] x = new string[3];
x[0] = l.SubItems[0].Text;
x[1] = l.SubItems[1].Text.ToLower();
x[2] = l.SubItems[2].Text;
r.Add(x);
}
return r;
}
private void addButton_Click(object sender, EventArgs e)
{
CustomAppsAddForm f = new CustomAppsAddForm();
if (f.ShowDialog(this) == DialogResult.OK)
{
// Remove any matching protocol
List<ListViewItem> list = new List<ListViewItem>();
foreach (ListViewItem l in mainListView.Items) { if (l.SubItems[1].Text.ToLower() == f.appProtocol.ToLower()) { list.Add(l); } }
foreach (ListViewItem l in list) { mainListView.Items.Remove(l); }
// Add the new protocol
string[] x = new string[3];
x[0] = f.appName;
x[1] = f.appProtocol.ToLower();
x[2] = f.appCommand;
mainListView.Items.Add(new ListViewItem(x));
}
}
private void okButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
}
private void cancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
private void mainListView_SelectedIndexChanged(object sender, EventArgs e)
{
UpdateInfo();
}
private void UpdateInfo()
{
removeButton.Enabled = (mainListView.SelectedItems.Count > 0);
}
private void removeButton_Click(object sender, EventArgs e)
{
if (mainListView.SelectedItems.Count == 0) return;
List<ListViewItem> list = new List<ListViewItem>();
foreach (ListViewItem l in mainListView.SelectedItems) { list.Add(l); }
foreach (ListViewItem l in list) { mainListView.Items.Remove(l); }
}
private void appContextMenuStrip_Opening(object sender, CancelEventArgs e)
{
runToolStripMenuItem.Visible = (mainListView.SelectedItems.Count == 1);
removeToolStripMenuItem.Visible = toolStripMenuItem1.Visible = (mainListView.SelectedItems.Count > 0);
}
private void runToolStripMenuItem_Click(object sender, EventArgs e)
{
if (mainListView.SelectedItems.Count != 1) return;
ListViewItem i = mainListView.SelectedItems[0];
CustomAppsRunForm f = new CustomAppsRunForm(i.SubItems[2].Text);
if (f.ShowDialog(this) == DialogResult.OK) { Process.Start(f.getFinalCommand()); }
}
private void editToolStripMenuItem_Click(object sender, EventArgs e)
{
if (mainListView.SelectedItems.Count != 1) return;
ListViewItem i = mainListView.SelectedItems[0];
CustomAppsAddForm f = new CustomAppsAddForm();
f.appName = i.SubItems[0].Text;
f.appProtocol = i.SubItems[1].Text;
f.appCommand = i.SubItems[2].Text;
if (f.ShowDialog(this) == DialogResult.OK)
{
// Remove any matching protocol
List<ListViewItem> list = new List<ListViewItem>();
foreach (ListViewItem l in mainListView.Items) { if (l.SubItems[1].Text.ToLower() == f.appProtocol.ToLower()) { list.Add(l); } }
foreach (ListViewItem l in list) { mainListView.Items.Remove(l); }
// Add the new protocol
string[] x = new string[3];
x[0] = f.appName;
x[1] = f.appProtocol.ToLower();
x[2] = f.appCommand;
mainListView.Items.Add(new ListViewItem(x));
}
}
}
}

1818
CustomAppsForm.resx Normal file

File diff suppressed because it is too large Load Diff

192
CustomAppsRunForm.Designer.cs generated Normal file
View File

@@ -0,0 +1,192 @@
namespace MeshCentralRouter
{
partial class CustomAppsRunForm
{
/// <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(CustomAppsRunForm));
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.portTextBox = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.addressTextBox = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.commandTextBox = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.okButton = new System.Windows.Forms.Button();
this.cancelButton = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
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.portTextBox);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.addressTextBox);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.commandTextBox);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Location = new System.Drawing.Point(12, 49);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(382, 101);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Application Command Line";
//
// portTextBox
//
this.portTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.portTextBox.Location = new System.Drawing.Point(116, 71);
this.portTextBox.Name = "portTextBox";
this.portTextBox.Size = new System.Drawing.Size(260, 20);
this.portTextBox.TabIndex = 13;
this.portTextBox.Text = "1234";
this.portTextBox.TextChanged += new System.EventHandler(this.portTextBox_TextChanged);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(6, 74);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(26, 13);
this.label4.TabIndex = 12;
this.label4.Text = "Port";
//
// addressTextBox
//
this.addressTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.addressTextBox.Location = new System.Drawing.Point(116, 45);
this.addressTextBox.Name = "addressTextBox";
this.addressTextBox.Size = new System.Drawing.Size(260, 20);
this.addressTextBox.TabIndex = 11;
this.addressTextBox.Text = "127.0.0.1";
this.addressTextBox.TextChanged += new System.EventHandler(this.addressTextBox_TextChanged);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(6, 48);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(45, 13);
this.label3.TabIndex = 10;
this.label3.Text = "Address";
//
// commandTextBox
//
this.commandTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.commandTextBox.Location = new System.Drawing.Point(116, 19);
this.commandTextBox.Name = "commandTextBox";
this.commandTextBox.ReadOnly = true;
this.commandTextBox.Size = new System.Drawing.Size(260, 20);
this.commandTextBox.TabIndex = 9;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(6, 22);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(54, 13);
this.label2.TabIndex = 8;
this.label2.Text = "Command";
//
// 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(238, 156);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(75, 23);
this.okButton.TabIndex = 3;
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.Location = new System.Drawing.Point(319, 156);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 23);
this.cancelButton.TabIndex = 2;
this.cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true;
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label1.Location = new System.Drawing.Point(12, 11);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(382, 35);
this.label1.TabIndex = 4;
this.label1.Text = "Test that the application runs correctly by specifying and address and port and c" +
"lick ok to run the application.";
//
// CustomAppsRunForm
//
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(406, 191);
this.Controls.Add(this.label1);
this.Controls.Add(this.okButton);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.groupBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CustomAppsRunForm";
this.Text = "Test Application";
this.Load += new System.EventHandler(this.CustomAppsRunForm_Load);
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.Label label1;
private System.Windows.Forms.TextBox portTextBox;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox addressTextBox;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox commandTextBox;
private System.Windows.Forms.Label label2;
}
}

58
CustomAppsRunForm.cs Normal file
View File

@@ -0,0 +1,58 @@
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 CustomAppsRunForm : Form
{
private string command = null;
public CustomAppsRunForm(string command)
{
this.command = command;
InitializeComponent();
}
public string getFinalCommand()
{
return command.Replace("%L", addressTextBox.Text).Replace("%P", portTextBox.Text);
}
public void UpdateInfo()
{
commandTextBox.Text = getFinalCommand();
}
private void addressTextBox_TextChanged(object sender, EventArgs e)
{
UpdateInfo();
}
private void portTextBox_TextChanged(object sender, EventArgs e)
{
UpdateInfo();
}
private void CustomAppsRunForm_Load(object sender, EventArgs e)
{
UpdateInfo();
}
private void okButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
}
private void cancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
}
}

1815
CustomAppsRunForm.resx Normal file

File diff suppressed because it is too large Load Diff

22
MainForm.Designer.cs generated
View File

@@ -136,6 +136,8 @@
this.settingsToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.openMapFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveMapFileDialog = new System.Windows.Forms.SaveFileDialog();
this.customAppsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.customAppsToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.panel5.SuspendLayout();
this.mainPanel.SuspendLayout();
this.mainTabControl.SuspendLayout();
@@ -515,7 +517,8 @@
this.sortByNameToolStripMenuItem,
this.sortByGroupToolStripMenuItem,
this.toolStripMenuItem4,
this.settingsToolStripMenuItem});
this.settingsToolStripMenuItem,
this.customAppsToolStripMenuItem1});
this.mainContextMenuStrip.Name = "mainContextMenuStrip";
resources.ApplyResources(this.mainContextMenuStrip, "mainContextMenuStrip");
//
@@ -928,7 +931,8 @@
this.openMappingsToolStripMenuItem,
this.saveMappingsToolStripMenuItem,
this.toolStripMenuItem5,
this.settingsToolStripMenuItem1});
this.settingsToolStripMenuItem1,
this.customAppsToolStripMenuItem});
this.mappingsContextMenuStrip.Name = "mappingsContextMenuStrip";
resources.ApplyResources(this.mappingsContextMenuStrip, "mappingsContextMenuStrip");
//
@@ -965,6 +969,18 @@
this.saveMapFileDialog.DefaultExt = "mcrouter";
resources.ApplyResources(this.saveMapFileDialog, "saveMapFileDialog");
//
// customAppsToolStripMenuItem
//
this.customAppsToolStripMenuItem.Name = "customAppsToolStripMenuItem";
resources.ApplyResources(this.customAppsToolStripMenuItem, "customAppsToolStripMenuItem");
this.customAppsToolStripMenuItem.Click += new System.EventHandler(this.customAppsToolStripMenuItem_Click);
//
// customAppsToolStripMenuItem1
//
this.customAppsToolStripMenuItem1.Name = "customAppsToolStripMenuItem1";
resources.ApplyResources(this.customAppsToolStripMenuItem1, "customAppsToolStripMenuItem1");
this.customAppsToolStripMenuItem1.Click += new System.EventHandler(this.customAppsToolStripMenuItem_Click);
//
// MainForm
//
resources.ApplyResources(this, "$this");
@@ -1121,6 +1137,8 @@
private System.Windows.Forms.ToolStripMenuItem askConsentToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem privacyBarToolStripMenuItem;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.ToolStripMenuItem customAppsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem customAppsToolStripMenuItem1;
}
}

View File

@@ -123,7 +123,9 @@ namespace MeshCentralRouter
try { installProcess = System.Diagnostics.Process.Start(startInfo); } catch (Exception) { return; }
installTimer.Enabled = true;
installButton.Visible = false;
} else {
}
else
{
hookRouter();
installButton.Visible = !isRouterHooked();
}
@@ -145,8 +147,6 @@ namespace MeshCentralRouter
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
{
public int Compare(Object a, Object b)
@@ -177,7 +177,7 @@ namespace MeshCentralRouter
{
// Normal certificate check
if (chain.Build(new X509Certificate2(certificate)) == true) { meshcentral.certHash = webSocketClient.GetMeshKeyHash(certificate); return true; }
if ((meshcentral.okCertHash != null) && ((meshcentral.okCertHash == certificate.GetCertHashString()) || (meshcentral.okCertHash == webSocketClient.GetMeshKeyHash(certificate)) || (meshcentral.okCertHash == webSocketClient.GetMeshCertHash(certificate)))) { meshcentral.certHash = webSocketClient.GetMeshKeyHash(certificate); return true; }
if ((meshcentral.okCertHash != null) && ((meshcentral.okCertHash == certificate.GetCertHashString()) || (meshcentral.okCertHash == webSocketClient.GetMeshKeyHash(certificate)) || (meshcentral.okCertHash == webSocketClient.GetMeshCertHash(certificate)))) { meshcentral.certHash = webSocketClient.GetMeshKeyHash(certificate); return true; }
if ((meshcentral.okCertHash2 != null) && ((meshcentral.okCertHash2 == certificate.GetCertHashString()) || (meshcentral.okCertHash2 == webSocketClient.GetMeshKeyHash(certificate)) || (meshcentral.okCertHash2 == webSocketClient.GetMeshCertHash(certificate)))) { meshcentral.certHash = webSocketClient.GetMeshKeyHash(certificate); return true; }
meshcentral.certHash = null;
meshcentral.disconnectMsg = "cert";
@@ -214,10 +214,7 @@ namespace MeshCentralRouter
versionLabel.Text = "v" + version.Major + "." + version.Minor + "." + version.Build;
// Prevent edgecase where the hook priority can be on and the hook disabled causing havoc
if( !Settings.GetRegValue("Exp_KeyboardHook", false) )
{
Settings.SetRegValue("Exp_KeyboardHookPriority", false);
}
if (!Settings.GetRegValue("Exp_KeyboardHook", false)) { Settings.SetRegValue("Exp_KeyboardHookPriority", false); }
serverNameComboBox.Text = Settings.GetRegValue("ServerName", "");
userNameTextBox.Text = Settings.GetRegValue("UserName", "");
@@ -226,7 +223,8 @@ namespace MeshCentralRouter
int argflags = 0;
string update = null;
string delete = null;
foreach (string arg in this.args) {
foreach (string arg in this.args)
{
if (arg.ToLower() == "-oldstyle") { deviceListViewMode = false; }
if (arg.ToLower() == "-install") { hookRouter(); forceExit = true; return; }
if (arg.ToLower() == "-uninstall") { unHookRouter(); forceExit = true; return; }
@@ -249,7 +247,8 @@ namespace MeshCentralRouter
}
autoLogin = (argflags == 7);
if (update != null) {
if (update != null)
{
// New args
ArrayList args2 = new ArrayList();
foreach (string a in args) { if (a.StartsWith("-update:") == false) { args2.Add(a); } }
@@ -267,13 +266,15 @@ namespace MeshCentralRouter
if (delete != null) { try { System.Threading.Thread.Sleep(1000); File.Delete(delete); } catch (Exception) { } }
// Set automatic port map values
if (authLoginUrl != null) {
if (authLoginUrl != null)
{
string autoNodeId = null;
string autoRemoteIp = null;
int autoRemotePort = 0;
int autoLocalPort = 0;
int autoProtocol = 0;
int autoAppId = 0;
string autoAppIdStr = null;
bool autoExit = false;
try
{
@@ -282,13 +283,15 @@ namespace MeshCentralRouter
autoRemoteIp = getValueFromQueryString(authLoginUrl.Query, "remoteip");
int.TryParse(getValueFromQueryString(authLoginUrl.Query, "remoteport"), out autoRemotePort);
int.TryParse(getValueFromQueryString(authLoginUrl.Query, "protocol"), out autoProtocol);
int.TryParse(getValueFromQueryString(authLoginUrl.Query, "appid"), out autoAppId);
autoExit = (getValueFromQueryString(authLoginUrl.Query, "autoexit") == "1");
string localPortStr = getValueFromQueryString(authLoginUrl.Query, "localport");
if (localPortStr != null) { autoLocalPort = int.Parse(localPortStr); }
autoAppIdStr = getValueFromQueryString(authLoginUrl.Query, "appid");
int.TryParse(autoAppIdStr, out autoAppId);
}
catch (Exception) { }
if (((autoRemotePort != 0) && (autoProtocol != 0) && (autoNodeId != null)) || ((autoNodeId != null) && ((autoAppId == 6) || (autoAppId == 7)))) {
if (((autoRemotePort != 0) && (autoProtocol != 0) && (autoNodeId != null)) || ((autoNodeId != null) && ((autoAppId == 6) || (autoAppId == 7))))
{
Dictionary<string, object> map = new Dictionary<string, object>();
map.Add("nodeId", autoNodeId);
if (autoRemoteIp != null) { map.Add("remoteIP", autoRemoteIp); }
@@ -296,6 +299,7 @@ namespace MeshCentralRouter
map.Add("localPort", autoLocalPort);
map.Add("protocol", autoProtocol);
map.Add("appId", autoAppId);
map.Add("appIdStr", autoAppIdStr);
map.Add("autoExit", autoExit);
map.Add("launch", 1);
mappingsToSetup = new ArrayList();
@@ -375,10 +379,13 @@ namespace MeshCentralRouter
// Load registry settings
showGroupNamesToolStripMenuItem.Checked = (Settings.GetRegValue("Show Group Names", "1") == "1");
showOfflineDevicesToolStripMenuItem.Checked = (Settings.GetRegValue("Show Offline Devices", "1") == "1");
if (Settings.GetRegValue("Device Sort", "Name") == "Name") {
if (Settings.GetRegValue("Device Sort", "Name") == "Name")
{
sortByNameToolStripMenuItem.Checked = true;
sortByGroupToolStripMenuItem.Checked = false;
} else {
}
else
{
sortByNameToolStripMenuItem.Checked = false;
sortByGroupToolStripMenuItem.Checked = true;
}
@@ -525,16 +532,21 @@ namespace MeshCentralRouter
if ((twoFactorCookie != null) && (twoFactorCookie != "")) { twoFactorCookie = "cookie=" + twoFactorCookie; } else { twoFactorCookie = null; }
Uri serverurl = null;
if (authLoginUrl != null) {
try {
if (authLoginUrl != null)
{
try
{
meshcentral.okCertHash2 = getValueFromQueryString(authLoginUrl.Query, "t");
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);
} catch (Exception) { }
}
catch (Exception) { }
meshcentral.connect(serverurl, null, null, null);
} else {
}
else
{
int keyIndex = serverNameComboBox.Text.IndexOf("?key=");
if (keyIndex >= 0)
{
@@ -586,14 +598,17 @@ namespace MeshCentralRouter
meshcentral.okCertHash = lastBadConnectCert.GetCertHashString();
Uri serverurl = null;
if (authLoginUrl != null) {
if (authLoginUrl != null)
{
meshcentral.okCertHash2 = getValueFromQueryString(authLoginUrl.Query, "t");
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 {
}
else
{
// Load two factor cookie if present
string twoFactorCookie = Settings.GetRegValue("TwoFactorCookie", null);
if ((twoFactorCookie != null) && (twoFactorCookie != "")) { twoFactorCookie = "cookie=" + twoFactorCookie; } else { twoFactorCookie = null; }
@@ -676,16 +691,21 @@ namespace MeshCentralRouter
device.SubItems.Add(node.getStateString());
device.Tag = node;
node.listitem = device;
} else {
}
else
{
device = node.listitem;
device.SubItems[0].Text = node.name;
device.SubItems[1].Text = node.getStateString();
}
if ((node.meshid != null) && meshcentral.meshes.ContainsKey(node.meshid)) { node.mesh = (MeshClass)meshcentral.meshes[node.meshid]; }
if ((showGroupNamesToolStripMenuItem.Checked) && (node.mesh != null)) {
if ((showGroupNamesToolStripMenuItem.Checked) && (node.mesh != null))
{
device.SubItems[0].Text = node.mesh.name + " - " + node.name;
} else {
}
else
{
device.SubItems[0].Text = node.name;
}
@@ -702,7 +722,9 @@ namespace MeshCentralRouter
{
// Normal search
if (connVisible && ((search == "") || (device.SubItems[0].Text.ToLower().IndexOf(search) >= 0))) { controlsToAdd.Add(device); }
} else {
}
else
{
// User search
bool userSearchMatch = false;
if (node.users != null) { foreach (string user in node.users) { if (user.ToLower().IndexOf(userSearch) >= 0) { userSearchMatch = true; } } }
@@ -711,7 +733,8 @@ namespace MeshCentralRouter
}
// Add all controls at once to make it fast.
if (controlsToAdd.Count > 0) {
if (controlsToAdd.Count > 0)
{
devicesListView.Items.AddRange((ListViewItem[])controlsToAdd.ToArray(typeof(ListViewItem)));
}
}
@@ -832,31 +855,41 @@ namespace MeshCentralRouter
if (meshcentral == null) return;
if (this.InvokeRequired) { this.Invoke(new MeshCentralServer.onStateChangedHandler(Meshcentral_onStateChanged), state); return; }
if (state == 0) {
if (meshcentral.disconnectMsg == "tokenrequired") {
if (state == 0)
{
if (meshcentral.disconnectMsg == "tokenrequired")
{
emailTokenButton.Visible = (meshcentral.disconnectEmail2FA == true) && (meshcentral.disconnectEmail2FASent == false);
tokenEmailSentLabel.Visible = (meshcentral.disconnectEmail2FASent == true) || (meshcentral.disconnectSms2FASent == true);
smsTokenButton.Visible = ((meshcentral.disconnectSms2FA == true) && (meshcentral.disconnectSms2FASent == false));
if (meshcentral.disconnectEmail2FASent) { tokenEmailSentLabel.Text = Translate.T(Properties.Resources.EmailSent); }
if (meshcentral.disconnectSms2FASent) { tokenEmailSentLabel.Text = Translate.T(Properties.Resources.SmsSent); }
if ((meshcentral.disconnectEmail2FA == true) && (meshcentral.disconnectEmail2FASent == false)) {
if ((meshcentral.disconnectEmail2FA == true) && (meshcentral.disconnectEmail2FASent == false))
{
smsTokenButton.Left = emailTokenButton.Left + emailTokenButton.Width + 5;
} else {
}
else
{
smsTokenButton.Left = emailTokenButton.Left;
}
tokenTextBox.Text = "";
if (meshcentral.twoFactorCookieDays > 0) {
if (meshcentral.twoFactorCookieDays > 0)
{
tokenRememberCheckBox.Visible = true;
tokenRememberCheckBox.Text = string.Format(Translate.T(Properties.Resources.DontAskXDays), meshcentral.twoFactorCookieDays);
} else {
}
else
{
tokenRememberCheckBox.Visible = false;
}
setPanel(2);
tokenTextBox.Focus();
} else { setPanel(1); }
}
else { setPanel(1); }
if ((meshcentral.disconnectMsg != null) && meshcentral.disconnectMsg.StartsWith("noauth")) {
if ((meshcentral.disconnectMsg != null) && meshcentral.disconnectMsg.StartsWith("noauth"))
{
stateLabel.Text = Translate.T(Properties.Resources.InvalidUsernameOrPassword);
stateLabel.Visible = true;
stateClearTimer.Enabled = true;
@@ -876,7 +909,8 @@ namespace MeshCentralRouter
stateClearTimer.Enabled = true;
serverNameComboBox.Focus();
}
else if (meshcentral.disconnectMsg == "cert") {
else if (meshcentral.disconnectMsg == "cert")
{
lastBadConnectCert = meshcentral.disconnectCert;
certDetailsTextBox.Text = "---Issuer---\r\n" + lastBadConnectCert.Issuer.Replace(", ", "\r\n") + "\r\n\r\n---Subject---\r\n" + lastBadConnectCert.Subject.Replace(", ", "\r\n");
setPanel(3);
@@ -892,14 +926,16 @@ namespace MeshCentralRouter
this.Text = title;
// Clean up all mappings
foreach (Control c in mapPanel.Controls) {
foreach (Control c in mapPanel.Controls)
{
if (c.GetType() == typeof(MapUserControl)) { ((MapUserControl)c).Dispose(); }
}
mapPanel.Controls.Clear();
noMapLabel.Visible = true;
// Clean up all devices (old style)
foreach (Control c in devicesPanel.Controls) {
foreach (Control c in devicesPanel.Controls)
{
if (c.GetType() == typeof(DeviceUserControl)) { ((DeviceUserControl)c).Dispose(); }
}
remoteAllDeviceControls();
@@ -910,7 +946,8 @@ namespace MeshCentralRouter
noDevicesLabel.Visible = true;
if ((meshcentral != null) && (meshcentral.nodes != null))
{
foreach (NodeClass n in meshcentral.nodes.Values) {
foreach (NodeClass n in meshcentral.nodes.Values)
{
if (n.desktopViewer != null) { n.desktopViewer.Close(); }
if (n.fileViewer != null) { n.fileViewer.Close(); }
}
@@ -925,7 +962,9 @@ namespace MeshCentralRouter
meshcentral.onNodesChanged -= Meshcentral_onNodesChanged;
meshcentral = null;
authLoginUrl = null;
} else if (state == 1) {
}
else if (state == 1)
{
stateLabel.Visible = false;
//setPanel(1);
nextButton1.Enabled = false;
@@ -933,7 +972,9 @@ namespace MeshCentralRouter
userNameTextBox.Enabled = false;
passwordTextBox.Enabled = false;
cookieRefreshTimer.Enabled = false;
} else if (state == 2) {
}
else if (state == 2)
{
meshcentral.disconnectMsg = "connected";
stateLabel.Visible = false;
setPanel(4);
@@ -943,9 +984,12 @@ namespace MeshCentralRouter
Settings.SetRegValue("ServerName", serverNameComboBox.Text);
Settings.SetRegValue("UserName", userNameTextBox.Text);
}
if (meshcentral.username != null) {
if (meshcentral.username != null)
{
this.Text = title + " - " + meshcentral.username;
} else {
}
else
{
this.Text = title + " - " + userNameTextBox.Text;
}
cookieRefreshTimer.Enabled = true;
@@ -954,7 +998,8 @@ namespace MeshCentralRouter
if (tokenRememberCheckBox.Checked) { meshcentral.sendCommand("{\"action\":\"twoFactorCookie\"}"); }
// Setup single instance pipe server
if (authLoginUrl != null) {
if (authLoginUrl != null)
{
string urlstring = "wss://" + authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443) + authLoginUrl.LocalPath;
localPipeServer = new LocalPipeServer(Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(urlstring))); // + "" + meshcentral.certHash
localPipeServer.onArgs += LocalPipeServer_onArgs;
@@ -980,6 +1025,7 @@ namespace MeshCentralRouter
int autoLocalPort = 0;
int autoProtocol = 0;
int autoAppId = 0;
string autoAppIdStr = null;
bool autoExit = false;
try
{
@@ -988,7 +1034,8 @@ namespace MeshCentralRouter
autoRemoteIp = getValueFromQueryString(authLoginUrl2.Query, "remoteip");
int.TryParse(getValueFromQueryString(authLoginUrl2.Query, "remoteport"), out autoRemotePort);
int.TryParse(getValueFromQueryString(authLoginUrl2.Query, "protocol"), out autoProtocol);
int.TryParse(getValueFromQueryString(authLoginUrl2.Query, "appid"), out autoAppId);
autoAppIdStr = getValueFromQueryString(authLoginUrl2.Query, "appid");
int.TryParse(autoAppIdStr, out autoAppId);
autoExit = (getValueFromQueryString(authLoginUrl2.Query, "autoexit") == "1");
string localPortStr = getValueFromQueryString(authLoginUrl.Query, "localport");
if (localPortStr != null) { autoLocalPort = int.Parse(localPortStr); }
@@ -1003,6 +1050,7 @@ namespace MeshCentralRouter
map.Add("localPort", autoLocalPort);
map.Add("protocol", autoProtocol);
map.Add("appId", autoAppId);
map.Add("appIdStr", autoAppIdStr);
map.Add("autoExit", autoExit);
map.Add("launch", 1);
mappingsToSetup = new ArrayList();
@@ -1023,7 +1071,8 @@ namespace MeshCentralRouter
if ((map.protocol == 2) && (map.mapper.totalConnectCounter == 0))
{
// This is an unconnected UDP map, check if the target node is connected.
foreach (NodeClass n in meshcentral.nodes.Values) {
foreach (NodeClass n in meshcentral.nodes.Values)
{
if ((map.node == n) && ((n.conn & 1) != 0))
{
// Reconnect the UDP map
@@ -1087,6 +1136,7 @@ namespace MeshCentralRouter
map.localPort = (int)localPort;
map.remotePort = (int)remotePort;
map.appId = appId;
if (appId == 0) { map.appIdStr = x[3].ToLower(); }
map.node = node;
if (authLoginUrl != null) { map.host = authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443) + authLoginUrl.AbsolutePath.Replace("/control.ashx", ""); } else { map.host = serverNameComboBox.Text; }
map.certhash = meshcentral.wshash;
@@ -1148,6 +1198,7 @@ namespace MeshCentralRouter
map.remoteIP = remoteIp.ToString();
map.remotePort = (int)remotePort;
map.appId = appId;
if (appId == 0) { map.appIdStr = x[3].ToLower(); }
map.node = node;
if (authLoginUrl != null) { map.host = authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443) + authLoginUrl.AbsolutePath.Replace("/control.ashx", ""); } else { map.host = serverNameComboBox.Text; }
map.certhash = meshcentral.wshash;
@@ -1188,6 +1239,7 @@ namespace MeshCentralRouter
map.localPort = form.getLocalPort();
map.remotePort = form.getRemotePort();
map.appId = form.getAppId();
map.appIdStr = form.getAppIdStr();
map.node = form.getNode();
if (authLoginUrl != null) { map.host = authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443) + authLoginUrl.AbsolutePath.Replace("/control.ashx", ""); } else { map.host = serverNameComboBox.Text; }
map.certhash = meshcentral.wshash;
@@ -1221,12 +1273,15 @@ namespace MeshCentralRouter
openWebSiteButton.Visible = false;
Uri serverurl = null;
if (authLoginUrl != null) {
if (authLoginUrl != null)
{
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 {
}
else
{
int keyIndex = serverNameComboBox.Text.IndexOf("?key=");
if (keyIndex >= 0)
{
@@ -1244,9 +1299,12 @@ namespace MeshCentralRouter
meshcentral.debug = debug;
meshcentral.tlsdump = tlsdump;
meshcentral.ignoreCert = ignoreCert;
if (lastBadConnectCert != null) {
if (lastBadConnectCert != null)
{
meshcentral.okCertHash = lastBadConnectCert.GetCertHashString();
} else {
}
else
{
string ignoreCert = Settings.GetRegValue("IgnoreCert", null);
if (ignoreCert != null) { meshcentral.okCertHash = ignoreCert; }
}
@@ -1346,6 +1404,7 @@ namespace MeshCentralRouter
map.remotePort = form.getRemotePort();
map.remoteIP = form.getRemoteIP();
map.appId = form.getAppId();
map.appIdStr = form.getAppIdStr();
map.node = form.getNode();
if (authLoginUrl != null) { map.host = authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443) + authLoginUrl.AbsolutePath.Replace("/control.ashx", ""); } else { map.host = serverNameComboBox.Text; }
map.certhash = meshcentral.wshash;
@@ -1367,13 +1426,17 @@ namespace MeshCentralRouter
private void openWebSiteButton_Click(object sender, EventArgs e)
{
cancelAutoClose();
if (meshcentral.loginCookie != null) {
if (meshcentral.loginCookie != null)
{
Uri serverurl = null;
if (authLoginUrl != null) {
if (authLoginUrl != null)
{
string localPath = authLoginUrl.LocalPath;
if (localPath.EndsWith("/control.ashx")) { localPath = localPath.Substring(0, localPath.Length - 12); }
serverurl = new Uri("https://" + authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443) + localPath + "?login=" + meshcentral.loginCookie);
} else {
}
else
{
serverurl = new Uri("https://" + serverNameComboBox.Text + "?login=" + meshcentral.loginCookie);
}
System.Diagnostics.Process.Start(serverurl.ToString());
@@ -1413,11 +1476,14 @@ namespace MeshCentralRouter
if (f.ShowDialog(this) == DialogResult.OK)
{
inaddrany = f.BindAllInterfaces;
if (f.ShowSystemTray) {
if (f.ShowSystemTray)
{
notifyIcon.Visible = true;
this.ShowInTaskbar = false;
this.MinimizeBox = false;
} else {
}
else
{
notifyIcon.Visible = false;
this.ShowInTaskbar = true;
this.MinimizeBox = true;
@@ -1427,10 +1493,13 @@ namespace MeshCentralRouter
private void searchTextBox_TextChanged(object sender, EventArgs e)
{
if (deviceListViewMode) {
if (deviceListViewMode)
{
// Filter devices
updateDeviceList();
} else {
}
else
{
// Filter devices
int visibleDevices = 0;
int deviceCount = 0;
@@ -1464,9 +1533,12 @@ namespace MeshCentralRouter
{
cancelAutoClose();
searchTextBox.Visible = (devicesTabControl.SelectedIndex == 0);
if (devicesTabControl.SelectedIndex == 0) {
if (devicesTabControl.SelectedIndex == 0)
{
menuLabel.ContextMenuStrip = mainContextMenuStrip;
} else {
}
else
{
menuLabel.ContextMenuStrip = mappingsContextMenuStrip;
}
}
@@ -1502,6 +1574,44 @@ namespace MeshCentralRouter
map.localPort = 0; // Any
map.remotePort = port; // HTTP
map.appId = appId; // 0 = Custom, 1 = HTTP, 2 = HTTPS, 3 = RDP, 4 = PuTTY, 5 = WinSCP
map.appIdStr = null;
map.node = node;
if (authLoginUrl != null) { map.host = authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443) + authLoginUrl.AbsolutePath.Replace("/control.ashx", ""); } else { map.host = serverNameComboBox.Text; }
map.certhash = meshcentral.wshash;
map.parent = this;
map.Dock = DockStyle.Top;
map.Start();
mapPanel.Controls.Add(map);
noMapLabel.Visible = false;
map.appButton_Click(this, null);
}
public void QuickMap(int protocol, int port, string appIdStr, NodeClass node)
{
// See if we already have the right port mapping
foreach (Control c in mapPanel.Controls)
{
if (c.GetType() == typeof(MapUserControl))
{
MapUserControl cc = (MapUserControl)c;
if ((cc.protocol == protocol) && (cc.remotePort == port) && (cc.appIdStr == appIdStr) && (cc.node == node))
{
// Found a match
cc.appButton_Click(this, null);
return;
}
}
}
// Add a new port map
MapUserControl map = new MapUserControl();
map.xdebug = debug;
map.inaddrany = false; // Loopback only
map.protocol = protocol; // 1 = TCP, 2 = UDP
map.localPort = 0; // Any
map.remotePort = port; // HTTP
map.appId = 0; // 0 = Custom, 1 = HTTP, 2 = HTTPS, 3 = RDP, 4 = PuTTY, 5 = WinSCP
map.appIdStr = appIdStr;
map.node = node;
if (authLoginUrl != null) { map.host = authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443) + authLoginUrl.AbsolutePath.Replace("/control.ashx", ""); } else { map.host = serverNameComboBox.Text; }
map.certhash = meshcentral.wshash;
@@ -1535,7 +1645,7 @@ namespace MeshCentralRouter
private void tokenTextBox_KeyUp(object sender, KeyEventArgs e)
{
nextButton2.Enabled = (tokenTextBox.Text.Replace(" ","") != "");
nextButton2.Enabled = (tokenTextBox.Text.Replace(" ", "") != "");
}
private void tokenTextBox_TextChanged(object sender, EventArgs e)
@@ -1566,7 +1676,7 @@ namespace MeshCentralRouter
private void hideOfflineDevicesToolStripMenuItem_Click(object sender, EventArgs e)
{
showOfflineDevicesToolStripMenuItem.Checked = !showOfflineDevicesToolStripMenuItem.Checked;
Settings.SetRegValue("Show Offline Devices", showOfflineDevicesToolStripMenuItem.Checked?"1":"0");
Settings.SetRegValue("Show Offline Devices", showOfflineDevicesToolStripMenuItem.Checked ? "1" : "0");
updateDeviceList();
}
@@ -1626,7 +1736,8 @@ namespace MeshCentralRouter
if (jsonAction["mappings"] != null)
{
ArrayList mappings = (ArrayList)jsonAction["mappings"];
if (mappings.Count > 0) {
if (mappings.Count > 0)
{
mappingsToSetup = mappings;
if (mode == 2) { setupMappings(); }
}
@@ -1678,9 +1789,10 @@ namespace MeshCentralRouter
if (x.ContainsKey("remoteIP")) { map.remoteIP = (string)x["remoteIP"]; }
map.remotePort = (int)x["remotePort"];
map.appId = (int)x["appId"];
if (x["appIdStr"] != null) { map.appIdStr = (string)x["appIdStr"]; }
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) + authLoginUrl.AbsolutePath.Replace("/control.ashx",""); } else { map.host = serverNameComboBox.Text; }
if (authLoginUrl != null) { map.host = authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443) + authLoginUrl.AbsolutePath.Replace("/control.ashx", ""); } else { map.host = serverNameComboBox.Text; }
map.certhash = meshcentral.wshash;
map.parent = this;
map.Dock = DockStyle.Top;
@@ -1726,6 +1838,7 @@ namespace MeshCentralRouter
text += " \"meshId\": \"" + mapCtrl.node.meshid + "\",\r\n";
text += " \"nodeId\": \"" + mapCtrl.node.nodeid + "\",\r\n";
text += " \"appId\": " + mapCtrl.appId + ",\r\n";
if (mapCtrl.appIdStr != null) { text += " \"appIdStr\": \"" + mapCtrl.appIdStr + "\",\r\n"; }
text += " \"protocol\": " + map.protocol + ",\r\n";
text += " \"localPort\": " + map.localport + ",\r\n";
if (map.remoteip != null) { text += " \"remoteIP\": \"" + map.remoteip + "\",\r\n"; }
@@ -2003,6 +2116,14 @@ namespace MeshCentralRouter
cancelAutoClose();
}
private void customAppsToolStripMenuItem_Click(object sender, EventArgs e)
{
CustomAppsForm f = new CustomAppsForm(Settings.GetApplications());
if (f.ShowDialog(this) == DialogResult.OK) {
Settings.SetApplications(f.getApplications());
}
}
/*
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)

File diff suppressed because it is too large Load Diff

View File

@@ -31,6 +31,7 @@ namespace MeshCentralRouter
public string remoteIP = null;
public int remotePort;
public int appId;
public string appIdStr;
public NodeClass node;
public MainForm parent;
public MeshMapper mapper;
@@ -72,7 +73,7 @@ namespace MeshCentralRouter
public void Start()
{
routingStatusLabel.Text = Translate.T(Properties.Resources.Starting);
appButton.Enabled = (appId != 0);
appButton.Enabled = (appId != 0) || (appIdStr != null);
mapper = new MeshMapper();
mapper.xdebug = xdebug;
mapper.inaddrany = inaddrany;
@@ -110,7 +111,8 @@ namespace MeshCentralRouter
if (protocol == 2) {
statemsg = "UDP: " + statemsg;
} else {
if (appId == 1) { statemsg = "HTTP: " + statemsg; }
if ((appId == 0) && (appIdStr != null)) { statemsg = appIdStr + ": " + statemsg; }
else if (appId == 1) { statemsg = "HTTP: " + statemsg; }
else if (appId == 2) { statemsg = "HTTPS: " + statemsg; }
else if (appId == 3) { statemsg = "RDP: " + statemsg; }
else if (appId == 4) { statemsg = "PuTTY: " + statemsg; }
@@ -125,6 +127,28 @@ namespace MeshCentralRouter
bool shift = false;
if (Control.ModifierKeys == Keys.Shift) { shift = true; }
if (appId == 0)
{
if (appIdStr == null) return;
string appCmd = null;
List<String[]> apps = Settings.GetApplications();
foreach (String[] app in apps) { if (app[1].ToLower() == appIdStr.ToLower()) { appCmd = app[2]; } }
appCmd = appCmd.Replace("%P", mapper.localport.ToString()).Replace("%L", "127.0.0.1");
string appArgs = null;
int i = appCmd.IndexOf(' ');
if (i >= 0) { appArgs = appCmd.Substring(i + 1); appCmd = appCmd.Substring(0, i); }
if (appCmd != null)
{
// Launch the process
System.Diagnostics.Process proc = null;
try { proc = System.Diagnostics.Process.Start(appCmd, appArgs); } catch (System.ComponentModel.Win32Exception) { }
// Setup auto-exit
if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; }
autoexit = false;
}
return;
}
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)
@@ -153,6 +177,7 @@ namespace MeshCentralRouter
// Setup auto-exit
if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; }
autoexit = false;
}
if (appId == 4)
{
@@ -179,6 +204,7 @@ namespace MeshCentralRouter
// Setup auto-exit
if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; }
autoexit = false;
}
else
{
@@ -209,6 +235,7 @@ namespace MeshCentralRouter
// Setup auto-exit
if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; }
autoexit = false;
}
}
}
@@ -226,6 +253,7 @@ namespace MeshCentralRouter
// Setup auto-exit
if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; }
autoexit = false;
}
else
{
@@ -246,6 +274,7 @@ namespace MeshCentralRouter
// Setup auto-exit
if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; }
autoexit = false;
}
}
}

View File

@@ -94,6 +94,24 @@
<Compile Include="AddRelayMapForm.designer.cs">
<DependentUpon>AddRelayMapForm.cs</DependentUpon>
</Compile>
<Compile Include="CustomAppsAddForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="CustomAppsAddForm.Designer.cs">
<DependentUpon>CustomAppsAddForm.cs</DependentUpon>
</Compile>
<Compile Include="CustomAppsForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="CustomAppsForm.Designer.cs">
<DependentUpon>CustomAppsForm.cs</DependentUpon>
</Compile>
<Compile Include="CustomAppsRunForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="CustomAppsRunForm.Designer.cs">
<DependentUpon>CustomAppsRunForm.cs</DependentUpon>
</Compile>
<Compile Include="FileConfirmOverwriteForm.cs">
<SubType>Form</SubType>
</Compile>
@@ -274,6 +292,15 @@
<EmbeddedResource Include="AddRelayMapForm.resx">
<DependentUpon>AddRelayMapForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="CustomAppsAddForm.resx">
<DependentUpon>CustomAppsAddForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="CustomAppsForm.resx">
<DependentUpon>CustomAppsForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="CustomAppsRunForm.resx">
<DependentUpon>CustomAppsRunForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FileConfirmOverwriteForm.resx">
<DependentUpon>FileConfirmOverwriteForm.cs</DependentUpon>
</EmbeddedResource>

View File

@@ -15,6 +15,7 @@ limitations under the License.
*/
using Microsoft.Win32;
using System.Collections.Generic;
using System;
namespace MeshCentralRouter
@@ -53,5 +54,53 @@ namespace MeshCentralRouter
{
try { return bool.Parse(GetRegValue(name, value.ToString())); } catch (Exception) { return value; }
}
public static void SetApplications(List<string[]> apps)
{
ClearApplications();
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router\Applications", true))
{
foreach (string[] app in apps)
{
using (RegistryKey skey = key.CreateSubKey(app[0]))
{
skey.SetValue("Protocol", app[1]);
skey.SetValue("Command", app[2]);
}
}
}
}
public static List<string[]> GetApplications()
{
List<string[]> apps = new List<string[]>();
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router\Applications\", false))
{
string[] keys = key.GetSubKeyNames();
foreach (string k in keys)
{
using (RegistryKey key2 = Registry.CurrentUser.OpenSubKey(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router\Applications\" + k, false))
{
string protocol = (string)key2.GetValue("Protocol");
string command = (string)key2.GetValue("Command");
String[] a = new string[3];
a[0] = k;
a[1] = protocol;
a[2] = command;
apps.Add(a);
}
}
}
return apps;
}
//public static void DeleteSubKeyTree(RegistryKey key, string subkey) { if (key.OpenSubKey(subkey) == null) { return; } DeleteSubKeyTree(key, subkey); }
public static void ClearApplications()
{
RegistryKey key = Registry.CurrentUser.CreateSubKey(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router", true);
key.DeleteSubKeyTree("Applications");
key.Close();
}
}
}