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

Added SMS 2FA support.

This commit is contained in:
Ylian Saint-Hilaire
2020-04-22 21:06:37 -07:00
parent 503ed7bf08
commit 579c93c6c9
11 changed files with 2093 additions and 1670 deletions

View File

@@ -116,6 +116,7 @@
this.deviceImageList.Images.SetKeyName(4, "icons05.png");
this.deviceImageList.Images.SetKeyName(5, "icons06.png");
this.deviceImageList.Images.SetKeyName(6, "icons07.png");
this.deviceImageList.Images.SetKeyName(7, "icons08.png");
//
// disabledDeviceImageList
//
@@ -128,6 +129,7 @@
this.disabledDeviceImageList.Images.SetKeyName(4, "icons05t.png");
this.disabledDeviceImageList.Images.SetKeyName(5, "icons06t.png");
this.disabledDeviceImageList.Images.SetKeyName(6, "icons07t.png");
this.disabledDeviceImageList.Images.SetKeyName(7, "icons08t.png");
//
// httpsButton
//
@@ -146,7 +148,7 @@
this.altPortContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItem1});
this.altPortContextMenuStrip.Name = "rdpContextMenuStrip";
this.altPortContextMenuStrip.Size = new System.Drawing.Size(179, 48);
this.altPortContextMenuStrip.Size = new System.Drawing.Size(179, 26);
//
// toolStripMenuItem1
//

View File

@@ -24,7 +24,7 @@ namespace MeshCentralRouter
public void UpdateInfo()
{
if (parent.getShowGroupNames() && (mesh != null)) { deviceNameLabel.Text = mesh.name + ", " + node.name; } else { deviceNameLabel.Text = node.name; }
if (node.icon > 1)
if ((node.icon > 0) && (node.icon <= disabledDeviceImageList.Images.Count))
{
if (node.conn == 0)
{

File diff suppressed because it is too large Load Diff

152
MainForm.Designer.cs generated
View File

@@ -70,6 +70,13 @@
this.pictureBox5 = new System.Windows.Forms.PictureBox();
this.tabPage5 = new System.Windows.Forms.TabPage();
this.panel4 = new System.Windows.Forms.Panel();
this.menuLabel = new System.Windows.Forms.Label();
this.mainContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.showGroupNamesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.showOfflineDevicesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
this.sortByNameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.sortByGroupToolStripMenuItem = 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();
@@ -95,13 +102,7 @@
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuLabel = new System.Windows.Forms.Label();
this.mainContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.showGroupNamesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.showOfflineDevicesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
this.sortByNameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.sortByGroupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.smsTokenButton = new System.Windows.Forms.Button();
this.panel5.SuspendLayout();
this.mainPanel.SuspendLayout();
this.mainTabControl.SuspendLayout();
@@ -118,6 +119,7 @@
((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).BeginInit();
this.tabPage5.SuspendLayout();
this.panel4.SuspendLayout();
this.mainContextMenuStrip.SuspendLayout();
this.devicesTabControl.SuspendLayout();
this.devicesTabPage.SuspendLayout();
this.devicesPanel.SuspendLayout();
@@ -128,7 +130,6 @@
((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.trayIconContextMenuStrip.SuspendLayout();
this.mainContextMenuStrip.SuspendLayout();
this.SuspendLayout();
//
// panel5
@@ -362,6 +363,7 @@
//
// panel2
//
this.panel2.Controls.Add(this.smsTokenButton);
this.panel2.Controls.Add(this.tokenEmailSentLabel);
this.panel2.Controls.Add(this.emailTokenButton);
this.panel2.Controls.Add(this.label3);
@@ -609,6 +611,68 @@
this.panel4.Size = new System.Drawing.Size(484, 322);
this.panel4.TabIndex = 8;
//
// menuLabel
//
this.menuLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.menuLabel.AutoSize = true;
this.menuLabel.ContextMenuStrip = this.mainContextMenuStrip;
this.menuLabel.Cursor = System.Windows.Forms.Cursors.Hand;
this.menuLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.menuLabel.Location = new System.Drawing.Point(454, 2);
this.menuLabel.Name = "menuLabel";
this.menuLabel.Size = new System.Drawing.Size(25, 25);
this.menuLabel.TabIndex = 6;
this.menuLabel.Text = "≡";
this.menuLabel.Click += new System.EventHandler(this.menuLabel_Click);
//
// mainContextMenuStrip
//
this.mainContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.showGroupNamesToolStripMenuItem,
this.showOfflineDevicesToolStripMenuItem,
this.toolStripMenuItem2,
this.sortByNameToolStripMenuItem,
this.sortByGroupToolStripMenuItem});
this.mainContextMenuStrip.Name = "mainContextMenuStrip";
this.mainContextMenuStrip.Size = new System.Drawing.Size(186, 98);
//
// showGroupNamesToolStripMenuItem
//
this.showGroupNamesToolStripMenuItem.Checked = true;
this.showGroupNamesToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this.showGroupNamesToolStripMenuItem.Name = "showGroupNamesToolStripMenuItem";
this.showGroupNamesToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.showGroupNamesToolStripMenuItem.Text = "Show &Group Names";
this.showGroupNamesToolStripMenuItem.Click += new System.EventHandler(this.showGroupNamesToolStripMenuItem_Click);
//
// showOfflineDevicesToolStripMenuItem
//
this.showOfflineDevicesToolStripMenuItem.Name = "showOfflineDevicesToolStripMenuItem";
this.showOfflineDevicesToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.showOfflineDevicesToolStripMenuItem.Text = "Show &Offline Devices";
this.showOfflineDevicesToolStripMenuItem.Click += new System.EventHandler(this.hideOfflineDevicesToolStripMenuItem_Click);
//
// toolStripMenuItem2
//
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
this.toolStripMenuItem2.Size = new System.Drawing.Size(182, 6);
//
// sortByNameToolStripMenuItem
//
this.sortByNameToolStripMenuItem.Checked = true;
this.sortByNameToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this.sortByNameToolStripMenuItem.Name = "sortByNameToolStripMenuItem";
this.sortByNameToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.sortByNameToolStripMenuItem.Text = "Sort by &Name";
this.sortByNameToolStripMenuItem.Click += new System.EventHandler(this.sortByNameToolStripMenuItem_Click);
//
// sortByGroupToolStripMenuItem
//
this.sortByGroupToolStripMenuItem.Name = "sortByGroupToolStripMenuItem";
this.sortByGroupToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.sortByGroupToolStripMenuItem.Text = "Sort by G&roup";
this.sortByGroupToolStripMenuItem.Click += new System.EventHandler(this.sortByGroupToolStripMenuItem_Click);
//
// searchTextBox
//
this.searchTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
@@ -875,67 +939,16 @@
this.exitToolStripMenuItem.Text = "E&xit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click_1);
//
// menuLabel
// smsTokenButton
//
this.menuLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.menuLabel.AutoSize = true;
this.menuLabel.ContextMenuStrip = this.mainContextMenuStrip;
this.menuLabel.Cursor = System.Windows.Forms.Cursors.Hand;
this.menuLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.menuLabel.Location = new System.Drawing.Point(454, 2);
this.menuLabel.Name = "menuLabel";
this.menuLabel.Size = new System.Drawing.Size(25, 25);
this.menuLabel.TabIndex = 6;
this.menuLabel.Text = "≡";
this.menuLabel.Click += new System.EventHandler(this.menuLabel_Click);
//
// mainContextMenuStrip
//
this.mainContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.showGroupNamesToolStripMenuItem,
this.showOfflineDevicesToolStripMenuItem,
this.toolStripMenuItem2,
this.sortByNameToolStripMenuItem,
this.sortByGroupToolStripMenuItem});
this.mainContextMenuStrip.Name = "mainContextMenuStrip";
this.mainContextMenuStrip.Size = new System.Drawing.Size(186, 120);
//
// showGroupNamesToolStripMenuItem
//
this.showGroupNamesToolStripMenuItem.Checked = true;
this.showGroupNamesToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this.showGroupNamesToolStripMenuItem.Name = "showGroupNamesToolStripMenuItem";
this.showGroupNamesToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.showGroupNamesToolStripMenuItem.Text = "Show &Group Names";
this.showGroupNamesToolStripMenuItem.Click += new System.EventHandler(this.showGroupNamesToolStripMenuItem_Click);
//
// showOfflineDevicesToolStripMenuItem
//
this.showOfflineDevicesToolStripMenuItem.Name = "showOfflineDevicesToolStripMenuItem";
this.showOfflineDevicesToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.showOfflineDevicesToolStripMenuItem.Text = "Show &Offline Devices";
this.showOfflineDevicesToolStripMenuItem.Click += new System.EventHandler(this.hideOfflineDevicesToolStripMenuItem_Click);
//
// toolStripMenuItem2
//
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
this.toolStripMenuItem2.Size = new System.Drawing.Size(182, 6);
//
// sortByNameToolStripMenuItem
//
this.sortByNameToolStripMenuItem.Checked = true;
this.sortByNameToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this.sortByNameToolStripMenuItem.Name = "sortByNameToolStripMenuItem";
this.sortByNameToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.sortByNameToolStripMenuItem.Text = "Sort by &Name";
this.sortByNameToolStripMenuItem.Click += new System.EventHandler(this.sortByNameToolStripMenuItem_Click);
//
// sortByGroupToolStripMenuItem
//
this.sortByGroupToolStripMenuItem.Name = "sortByGroupToolStripMenuItem";
this.sortByGroupToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.sortByGroupToolStripMenuItem.Text = "Sort by G&roup";
this.sortByGroupToolStripMenuItem.Click += new System.EventHandler(this.sortByGroupToolStripMenuItem_Click);
this.smsTokenButton.Location = new System.Drawing.Point(322, 177);
this.smsTokenButton.Name = "smsTokenButton";
this.smsTokenButton.Size = new System.Drawing.Size(75, 23);
this.smsTokenButton.TabIndex = 22;
this.smsTokenButton.Text = "SMS";
this.smsTokenButton.UseVisualStyleBackColor = true;
this.smsTokenButton.Visible = false;
this.smsTokenButton.Click += new System.EventHandler(this.smsTokenButton_Click);
//
// MainForm
//
@@ -971,6 +984,7 @@
this.tabPage5.ResumeLayout(false);
this.panel4.ResumeLayout(false);
this.panel4.PerformLayout();
this.mainContextMenuStrip.ResumeLayout(false);
this.devicesTabControl.ResumeLayout(false);
this.devicesTabPage.ResumeLayout(false);
this.devicesPanel.ResumeLayout(false);
@@ -981,7 +995,6 @@
((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.trayIconContextMenuStrip.ResumeLayout(false);
this.mainContextMenuStrip.ResumeLayout(false);
this.ResumeLayout(false);
}
@@ -1059,6 +1072,7 @@
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
private System.Windows.Forms.ToolStripMenuItem sortByNameToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem sortByGroupToolStripMenuItem;
private System.Windows.Forms.Button smsTokenButton;
}
}

View File

@@ -39,6 +39,7 @@ namespace MeshCentralRouter
public bool inaddrany = false;
public bool forceExit = false;
public bool sendEmailToken = false;
public bool sendSMSToken = false;
public void setRegValue(string name, string value) {
try { Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router", name, value); } catch (Exception) { }
@@ -391,12 +392,33 @@ namespace MeshCentralRouter
if (state == 0) {
if (meshcentral.disconnectMsg == "tokenrequired") {
emailTokenButton.Visible = (meshcentral.disconnectEmail2FA == true) && (meshcentral.disconnectEmail2FASent == false);
tokenEmailSentLabel.Visible = (meshcentral.disconnectEmail2FASent == true);
tokenEmailSentLabel.Visible = (meshcentral.disconnectEmail2FASent == true) || (meshcentral.disconnectSms2FASent == true);
smsTokenButton.Visible = ((meshcentral.disconnectSms2FA == true) && (meshcentral.disconnectSms2FASent == false));
if (meshcentral.disconnectEmail2FASent) { tokenEmailSentLabel.Text = "Email sent"; }
if (meshcentral.disconnectSms2FASent) { tokenEmailSentLabel.Text = "SMS sent"; }
if ((meshcentral.disconnectEmail2FA == true) && (meshcentral.disconnectEmail2FASent == false)) {
smsTokenButton.Left = emailTokenButton.Left + emailTokenButton.Width + 5;
} else {
smsTokenButton.Left = emailTokenButton.Left;
}
tokenTextBox.Text = "";
setPanel(2);
tokenTextBox.Focus();
} else { setPanel(1); }
if ((meshcentral.disconnectMsg != null) && meshcentral.disconnectMsg.StartsWith("noauth")) { stateLabel.Text = "Invalid username or password"; stateLabel.Visible = true; stateClearTimer.Enabled = true; serverNameComboBox.Focus(); }
if ((meshcentral.disconnectMsg != null) && meshcentral.disconnectMsg.StartsWith("noauth")) {
stateLabel.Text = "Invalid username or password";
stateLabel.Visible = true;
stateClearTimer.Enabled = true;
serverNameComboBox.Focus();
}
else if ((meshcentral.disconnectMsg != null) && meshcentral.disconnectMsg.StartsWith("emailvalidationrequired"))
{
stateLabel.Text = "Email verification required";
stateLabel.Visible = true;
stateClearTimer.Enabled = true;
serverNameComboBox.Focus();
}
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");
@@ -642,7 +664,7 @@ namespace MeshCentralRouter
private void nextButton2_Click(object sender, EventArgs e)
{
if ((tokenTextBox.Text.Replace(" ", "") == "") && (sendEmailToken == false)) return;
if ((tokenTextBox.Text.Replace(" ", "") == "") && (sendEmailToken == false) && (sendSMSToken == false)) return;
// Attempt to login with token
addButton.Enabled = false;
@@ -660,6 +682,11 @@ namespace MeshCentralRouter
sendEmailToken = false;
meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, "**email**");
}
else if (sendSMSToken == true)
{
sendSMSToken = false;
meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, "**sms**");
}
else
{
meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, tokenTextBox.Text.Replace(" ", ""));
@@ -868,6 +895,17 @@ namespace MeshCentralRouter
if (MessageBox.Show(this, "Send token to registered email address?", "Two-factor Authentication", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
sendEmailToken = true;
sendSMSToken = false;
nextButton2_Click(this, null);
}
}
private void smsTokenButton_Click(object sender, EventArgs e)
{
if (MessageBox.Show(this, "Send token to registered phone number?", "Two-factor Authentication", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
sendEmailToken = false;
sendSMSToken = true;
nextButton2_Click(this, null);
}
}

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>

View File

@@ -102,6 +102,7 @@
this.deviceImageList.Images.SetKeyName(4, "icons05.png");
this.deviceImageList.Images.SetKeyName(5, "icons06.png");
this.deviceImageList.Images.SetKeyName(6, "icons07.png");
this.deviceImageList.Images.SetKeyName(7, "icons08.png");
//
// MapUserControl
//

File diff suppressed because it is too large Load Diff

View File

@@ -47,6 +47,8 @@ namespace MeshCentralRouter
public string disconnectMsg = null;
public bool disconnectEmail2FA = false;
public bool disconnectEmail2FASent = false;
public bool disconnectSms2FA = false;
public bool disconnectSms2FASent = false;
public X509Certificate2 disconnectCert;
public string authCookie = null;
public string loginCookie = null;
@@ -185,6 +187,8 @@ namespace MeshCentralRouter
disconnectMsg = jsonAction["msg"].ToString();
if (jsonAction.ContainsKey("email2fa")) { disconnectEmail2FA = (bool)jsonAction["email2fa"]; } else { disconnectEmail2FA = false; }
if (jsonAction.ContainsKey("email2fasent")) { disconnectEmail2FASent = (bool)jsonAction["email2fasent"]; } else { disconnectEmail2FASent = false; }
if (jsonAction.ContainsKey("sms2fa")) { disconnectSms2FA = (bool)jsonAction["sms2fa"]; } else { disconnectSms2FA = false; }
if (jsonAction.ContainsKey("sms2fasent")) { disconnectSms2FASent = (bool)jsonAction["sms2fasent"]; } else { disconnectSms2FASent = false; }
break;
}
case "serverinfo":
@@ -330,7 +334,7 @@ namespace MeshCentralRouter
MeshClass m = new MeshClass();
m.meshid = (string)mesh["_id"];
m.name = (string)mesh["name"];
m.desc = (string)mesh["desc"];
if (mesh.ContainsKey("desc")) { m.desc = (string)mesh["desc"]; }
m.rights = 0;
Dictionary<string, object> links = ((Dictionary<string, object>)mesh["links"]);

BIN
Resources/icons08.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
Resources/icons08t.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB