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

Added messaging 2FA support.

This commit is contained in:
Ylian Saint-Hilaire
2022-10-24 07:05:55 -07:00
parent a885efc4cf
commit f049ff6094
6 changed files with 474 additions and 181 deletions

View File

@@ -610,6 +610,15 @@ namespace MeshCentralRouter.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Message Sent.
/// </summary>
internal static string MessageSent {
get {
return ResourceManager.GetString("MessageSent", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to MQTT.
/// </summary>
@@ -845,6 +854,15 @@ namespace MeshCentralRouter.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Send token to registered messaging application?.
/// </summary>
internal static string SendTokenMSG {
get {
return ResourceManager.GetString("SendTokenMSG", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Send token to registered phone number?.
/// </summary>

View File

@@ -472,4 +472,10 @@
<data name="None" xml:space="preserve">
<value>None</value>
</data>
<data name="MessageSent" xml:space="preserve">
<value>Message Sent</value>
</data>
<data name="SendTokenMSG" xml:space="preserve">
<value>Send token to registered messaging application?</value>
</data>
</root>

View File

@@ -52,6 +52,7 @@
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.panel2 = new System.Windows.Forms.Panel();
this.msgTokenButton = new System.Windows.Forms.Button();
this.tokenRememberCheckBox = new System.Windows.Forms.CheckBox();
this.emailTokenButton = new System.Windows.Forms.Button();
this.smsTokenButton = new System.Windows.Forms.Button();
@@ -331,6 +332,7 @@
//
// panel2
//
this.panel2.Controls.Add(this.msgTokenButton);
this.panel2.Controls.Add(this.tokenRememberCheckBox);
this.panel2.Controls.Add(this.emailTokenButton);
this.panel2.Controls.Add(this.smsTokenButton);
@@ -345,6 +347,13 @@
resources.ApplyResources(this.panel2, "panel2");
this.panel2.Name = "panel2";
//
// msgTokenButton
//
resources.ApplyResources(this.msgTokenButton, "msgTokenButton");
this.msgTokenButton.Name = "msgTokenButton";
this.msgTokenButton.UseVisualStyleBackColor = true;
this.msgTokenButton.Click += new System.EventHandler(this.msgTokenButton_Click);
//
// tokenRememberCheckBox
//
resources.ApplyResources(this.tokenRememberCheckBox, "tokenRememberCheckBox");
@@ -1149,6 +1158,7 @@
private System.Windows.Forms.Button connectionSettings;
private System.Windows.Forms.ToolStripMenuItem customAppsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem customAppsToolStripMenuItem1;
private System.Windows.Forms.Button msgTokenButton;
}
}

View File

@@ -51,6 +51,7 @@ namespace MeshCentralRouter
public bool forceExit = false;
public bool sendEmailToken = false;
public bool sendSMSToken = false;
public bool sendMsgToken = false;
public bool allowUpdates = Settings.GetRegValue("CheckForUpdates", true);
public bool collapseDeviceGroup = Settings.GetRegValue("CollapseDeviceGroups", true);
public Uri authLoginUrl = null;
@@ -990,10 +991,12 @@ namespace MeshCentralRouter
if (meshcentral.disconnectMsg == "tokenrequired")
{
emailTokenButton.Visible = (meshcentral.disconnectEmail2FA == true) && (meshcentral.disconnectEmail2FASent == false);
tokenEmailSentLabel.Visible = (meshcentral.disconnectEmail2FASent == true) || (meshcentral.disconnectSms2FASent == true);
tokenEmailSentLabel.Visible = (meshcentral.disconnectEmail2FASent == true) || (meshcentral.disconnectSms2FASent == true) || (meshcentral.disconnectMsg2FASent == true);
smsTokenButton.Visible = ((meshcentral.disconnectSms2FA == true) && (meshcentral.disconnectSms2FASent == false));
msgTokenButton.Visible = ((meshcentral.disconnectMsg2FA == true) && (meshcentral.disconnectMsg2FASent == false));
if (meshcentral.disconnectEmail2FASent) { tokenEmailSentLabel.Text = Translate.T(Properties.Resources.EmailSent); }
if (meshcentral.disconnectSms2FASent) { tokenEmailSentLabel.Text = Translate.T(Properties.Resources.SmsSent); }
if (meshcentral.disconnectMsg2FASent) { tokenEmailSentLabel.Text = Translate.T(Properties.Resources.MessageSent); }
if ((meshcentral.disconnectEmail2FA == true) && (meshcentral.disconnectEmail2FASent == false))
{
smsTokenButton.Left = emailTokenButton.Left + emailTokenButton.Width + 5;
@@ -1406,7 +1409,7 @@ namespace MeshCentralRouter
private void nextButton2_Click(object sender, EventArgs e)
{
if ((tokenTextBox.Text.Replace(" ", "") == "") && (sendEmailToken == false) && (sendSMSToken == false)) return;
if ((tokenTextBox.Text.Replace(" ", "") == "") && (sendEmailToken == false) && (sendSMSToken == false) && (sendMsgToken == false)) return;
// Attempt to login with token
addButton.Enabled = false;
@@ -1465,6 +1468,11 @@ namespace MeshCentralRouter
sendSMSToken = false;
meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, "**sms**", getClientAuthCertificate());
}
else if (sendMsgToken == true)
{
sendMsgToken = false;
meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, "**msg**", getClientAuthCertificate());
}
else
{
meshcentral.connect(serverurl, userNameTextBox.Text, passwordTextBox.Text, tokenTextBox.Text.Replace(" ", ""), getClientAuthCertificate());
@@ -1779,6 +1787,7 @@ namespace MeshCentralRouter
{
sendEmailToken = true;
sendSMSToken = false;
sendMsgToken = false;
nextButton2_Click(this, null);
}
}
@@ -1789,6 +1798,18 @@ namespace MeshCentralRouter
{
sendEmailToken = false;
sendSMSToken = true;
sendMsgToken = false;
nextButton2_Click(this, null);
}
}
private void msgTokenButton_Click(object sender, EventArgs e)
{
if (MessageBox.Show(this, Translate.T(Properties.Resources.SendTokenMSG), Translate.T(Properties.Resources.TwoFactorAuthentication), MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
sendEmailToken = false;
sendSMSToken = false;
sendMsgToken = true;
nextButton2_Click(this, null);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -46,6 +46,8 @@ namespace MeshCentralRouter
public bool disconnectEmail2FASent = false;
public bool disconnectSms2FA = false;
public bool disconnectSms2FASent = false;
public bool disconnectMsg2FA = false;
public bool disconnectMsg2FASent = false;
public X509Certificate2 disconnectCert;
public string authCookie = null;
public string rauthCookie = null;
@@ -247,6 +249,8 @@ namespace MeshCentralRouter
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; }
if (jsonAction.ContainsKey("msg2fa")) { disconnectMsg2FA = (bool)jsonAction["msg2fa"]; } else { disconnectMsg2FA = false; }
if (jsonAction.ContainsKey("msg2fasent")) { disconnectMsg2FASent = (bool)jsonAction["msg2fasent"]; } else { disconnectMsg2FASent = false; }
if (jsonAction.ContainsKey("twoFactorCookieDays") && (jsonAction["twoFactorCookieDays"].GetType() == typeof(int))) { twoFactorCookieDays = (int)jsonAction["twoFactorCookieDays"]; }
break;
}