Control Panel can now save multiple logins

This commit is contained in:
Cyberboss
2017-11-27 15:17:56 -05:00
parent 85abbb6aa7
commit bedcd75382
9 changed files with 244 additions and 165 deletions
-15
View File
@@ -26,24 +26,9 @@
<setting name="LastChatProvider" serializeAs="String">
<value>0</value>
</setting>
<setting name="RemoteIP" serializeAs="String">
<value />
</setting>
<setting name="RemoteUsername" serializeAs="String">
<value />
</setting>
<setting name="RemotePort" serializeAs="String">
<value>38607</value>
</setting>
<setting name="RemoteDefault" serializeAs="String">
<value>False</value>
</setting>
<setting name="RemotePassword" serializeAs="String">
<value />
</setting>
<setting name="RemoteEntropy" serializeAs="String">
<value />
</setting>
<setting name="GitHubAPIKey" serializeAs="String">
<value />
</setting>
+2 -3
View File
@@ -6,10 +6,9 @@ namespace TGS.ControlPanel
/// Calls <see cref="Application.Exit()"/> when all <see cref="CountedForm"/>s are <see cref="Form.Close"/>d
/// </summary>
#if !DEBUG
abstract class CountedForm : ServerOpForm
#else
class CountedForm : ServerOpForm
abstract
#endif
class CountedForm : ServerOpForm
{
/// <summary>
/// The current number of active <see cref="CountedForm"/>s
+40 -25
View File
@@ -31,16 +31,17 @@
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Login));
this.LocalLoginButton = new System.Windows.Forms.Button();
this.CurrentRevisionTitle = new System.Windows.Forms.Label();
this.IPTextBox = new System.Windows.Forms.TextBox();
this.UsernameTextBox = new System.Windows.Forms.TextBox();
this.PasswordTextBox = new System.Windows.Forms.TextBox();
this.RemoteLoginButton = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.AddressLabel = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.PortSelector = new System.Windows.Forms.NumericUpDown();
this.SavePasswordCheckBox = new System.Windows.Forms.CheckBox();
this.IPComboBox = new System.Windows.Forms.ComboBox();
this.DeleteLoginButton = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.PortSelector)).BeginInit();
this.SuspendLayout();
//
@@ -50,7 +51,7 @@
this.LocalLoginButton.Location = new System.Drawing.Point(102, 12);
this.LocalLoginButton.Name = "LocalLoginButton";
this.LocalLoginButton.Size = new System.Drawing.Size(157, 25);
this.LocalLoginButton.TabIndex = 13;
this.LocalLoginButton.TabIndex = 1;
this.LocalLoginButton.Text = "Connect to Local Service";
this.LocalLoginButton.UseVisualStyleBackColor = true;
this.LocalLoginButton.Click += new System.EventHandler(this.LocalLoginButton_Click);
@@ -67,13 +68,6 @@
this.CurrentRevisionTitle.Text = "Remote Login:";
this.CurrentRevisionTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// IPTextBox
//
this.IPTextBox.Location = new System.Drawing.Point(129, 99);
this.IPTextBox.Name = "IPTextBox";
this.IPTextBox.Size = new System.Drawing.Size(146, 20);
this.IPTextBox.TabIndex = 15;
//
// UsernameTextBox
//
this.UsernameTextBox.Location = new System.Drawing.Point(129, 132);
@@ -100,17 +94,17 @@
this.RemoteLoginButton.UseVisualStyleBackColor = true;
this.RemoteLoginButton.Click += new System.EventHandler(this.RemoteLoginButton_Click);
//
// label1
// AddressLabel
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242)))));
this.label1.Location = new System.Drawing.Point(9, 99);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(120, 18);
this.label1.TabIndex = 19;
this.label1.Text = "Address/Port:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.AddressLabel.AutoSize = true;
this.AddressLabel.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.AddressLabel.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242)))));
this.AddressLabel.Location = new System.Drawing.Point(9, 99);
this.AddressLabel.Name = "AddressLabel";
this.AddressLabel.Size = new System.Drawing.Size(80, 18);
this.AddressLabel.TabIndex = 19;
this.AddressLabel.Text = "Address:";
this.AddressLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
@@ -165,7 +159,7 @@
this.PortSelector.Size = new System.Drawing.Size(80, 20);
this.PortSelector.TabIndex = 16;
this.PortSelector.Value = new decimal(new int[] {
1,
38607,
0,
0,
0});
@@ -182,22 +176,42 @@
this.SavePasswordCheckBox.UseVisualStyleBackColor = true;
this.SavePasswordCheckBox.CheckedChanged += new System.EventHandler(this.SavePasswordCheckBox_CheckedChanged);
//
// IPComboBox
//
this.IPComboBox.FormattingEnabled = true;
this.IPComboBox.Location = new System.Drawing.Point(130, 98);
this.IPComboBox.Name = "IPComboBox";
this.IPComboBox.Size = new System.Drawing.Size(146, 21);
this.IPComboBox.TabIndex = 24;
//
// DeleteLoginButton
//
this.DeleteLoginButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.DeleteLoginButton.Location = new System.Drawing.Point(105, 98);
this.DeleteLoginButton.Name = "DeleteLoginButton";
this.DeleteLoginButton.Size = new System.Drawing.Size(19, 19);
this.DeleteLoginButton.TabIndex = 25;
this.DeleteLoginButton.Text = "x";
this.DeleteLoginButton.UseVisualStyleBackColor = true;
this.DeleteLoginButton.Click += new System.EventHandler(this.DeleteLoginButton_Click);
//
// Login
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(39)))), ((int)(((byte)(40)))), ((int)(((byte)(34)))));
this.ClientSize = new System.Drawing.Size(374, 237);
this.Controls.Add(this.DeleteLoginButton);
this.Controls.Add(this.IPComboBox);
this.Controls.Add(this.SavePasswordCheckBox);
this.Controls.Add(this.PortSelector);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.AddressLabel);
this.Controls.Add(this.RemoteLoginButton);
this.Controls.Add(this.PasswordTextBox);
this.Controls.Add(this.UsernameTextBox);
this.Controls.Add(this.IPTextBox);
this.Controls.Add(this.CurrentRevisionTitle);
this.Controls.Add(this.LocalLoginButton);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
@@ -216,15 +230,16 @@
private System.Windows.Forms.Button LocalLoginButton;
private System.Windows.Forms.Label CurrentRevisionTitle;
private System.Windows.Forms.TextBox IPTextBox;
private System.Windows.Forms.TextBox UsernameTextBox;
private System.Windows.Forms.TextBox PasswordTextBox;
private System.Windows.Forms.Button RemoteLoginButton;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label AddressLabel;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.NumericUpDown PortSelector;
private System.Windows.Forms.CheckBox SavePasswordCheckBox;
private System.Windows.Forms.ComboBox IPComboBox;
private System.Windows.Forms.Button DeleteLoginButton;
}
}
+114 -35
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections.Specialized;
using System.Windows.Forms;
using TGS.Interface;
@@ -7,58 +8,123 @@ namespace TGS.ControlPanel
sealed partial class Login : CountedForm
{
/// <summary>
/// Create a <see cref="Login"/> form
/// Currently selected saved <see cref="RemoteLoginInfo"/>
/// </summary>
RemoteLoginInfo currentLoginInfo;
bool updatingFields;
/// <summary>
/// Construct a <see cref="Login"/>
/// </summary>
public Login()
{
InitializeComponent();
var Config = Properties.Settings.Default;
IPTextBox.Text = Config.RemoteIP;
UsernameTextBox.Text = Config.RemoteUsername;
PortSelector.Value = Config.RemotePort;
AcceptButton = RemoteLoginButton;
if(Config.RemoteDefault)
RemoteLoginButton.TabIndex = 0; //make this the first thing selected when loading
var decrypted = Helpers.DecryptData(Config.RemotePassword, Config.RemoteEntropy);
if (decrypted != null)
IPComboBox.SelectedIndexChanged += IPComboBox_SelectedIndexChanged;
var loginInfo = Config.RemoteLoginInfo;
if (loginInfo != null)
{
PasswordTextBox.Text = decrypted;
SavePasswordCheckBox.Checked = true;
foreach(var I in loginInfo)
IPComboBox.Items.Add(new RemoteLoginInfo(I));
if (IPComboBox.Items.Count > 0)
IPComboBox.SelectedIndex = 0;
}
UsernameTextBox.TextChanged += (a, b) => ClearFields();
PortSelector.ValueChanged += (a, b) => ClearFields();
PasswordTextBox.TextChanged += (a, b) => ClearFields();
IPComboBox.TextChanged += (a, b) => ClearFields();
}
private void RemoteLoginButton_Click(object sender, EventArgs e)
void ClearFields()
{
IPTextBox.Text = IPTextBox.Text.Trim();
UsernameTextBox.Text = UsernameTextBox.Text.Trim();
using (var I = new ServerInterface(new RemoteLoginInfo(IPTextBox.Text, (ushort)PortSelector.Value, UsernameTextBox.Text, PasswordTextBox.Text)))
if (updatingFields || currentLoginInfo == null)
return;
updatingFields = true;
currentLoginInfo = null;
IPComboBox.Text = "";
PortSelector.Value = 38607;
UsernameTextBox.Text = "";
PasswordTextBox.Text = "";
updatingFields = false;
}
void IPComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
currentLoginInfo = IPComboBox.SelectedItem as RemoteLoginInfo;
//new thing
if (currentLoginInfo == null)
{
ClearFields();
return;
}
updatingFields = true;
IPComboBox.Text = currentLoginInfo.IP;
PortSelector.Value = currentLoginInfo.Port;
UsernameTextBox.Text = currentLoginInfo.Username;
SavePasswordCheckBox.Checked = currentLoginInfo.HasPassword;
if (currentLoginInfo.HasPassword)
PasswordTextBox.Text = "************";
else
PasswordTextBox.Text = "";
updatingFields = false;
}
void RemoteLoginButton_Click(object sender, EventArgs e)
{
if (String.IsNullOrWhiteSpace(PasswordTextBox.Text) || String.IsNullOrWhiteSpace(UsernameTextBox.Text) || String.IsNullOrWhiteSpace(IPComboBox.Text) || PortSelector.Value == 0)
return;
RemoteLoginInfo loginInfo;
if (currentLoginInfo == null)
{
loginInfo = new RemoteLoginInfo(IPComboBox.Text, (ushort)PortSelector.Value, UsernameTextBox.Text.Trim(), PasswordTextBox.Text);
}
else
{
loginInfo = (RemoteLoginInfo)IPComboBox.SelectedItem;
if (!loginInfo.HasPassword)
loginInfo.Password = PasswordTextBox.Text;
}
using (var I = new ServerInterface(loginInfo))
{
var Config = Properties.Settings.Default;
Config.RemoteIP = IPTextBox.Text;
Config.RemotePort = (ushort)PortSelector.Value;
Config.RemoteUsername = UsernameTextBox.Text;
if (SavePasswordCheckBox.Checked)
//This needs to be read here because V&C Closing us will corrupt the data
var savePassword = SavePasswordCheckBox.Checked;
if (VerifyAndConnect(I))
{
Config.RemotePassword = Helpers.EncryptData(PasswordTextBox.Text, out string entrop);
Config.RemoteEntropy = entrop;
Config.RemoteDefault = true;
if (!savePassword)
loginInfo.Password = null;
Config.RemoteLoginInfo = new StringCollection { loginInfo.ToJSON() };
foreach (RemoteLoginInfo info in IPComboBox.Items)
if (!info.Equals(loginInfo))
Config.RemoteLoginInfo.Add(info.ToJSON());
}
else
{
Config.RemotePassword = null;
Config.RemoteEntropy = null;
}
Config.RemoteDefault = true;
VerifyAndConnect(I);
}
}
private void LocalLoginButton_Click(object sender, EventArgs e)
void LocalLoginButton_Click(object sender, EventArgs e)
{
Properties.Settings.Default.RemoteDefault = false;
VerifyAndConnect(new ServerInterface());
}
void VerifyAndConnect(IServerInterface I)
/// <summary>
/// Attempts a connection on a given <see cref="IServerInterface"/>
/// </summary>
/// <param name="I">The <see cref="IServerInterface"/> to attempt a connection on</param>
/// <returns><see langword="true"/> if the connection was made and authenticated, <see langword="false"/> otherwise</returns>
bool VerifyAndConnect(IServerInterface I)
{
try
{
@@ -66,19 +132,20 @@ namespace TGS.ControlPanel
if (!res.HasFlag(ConnectivityLevel.Connected))
{
MessageBox.Show("Unable to connect to service! Error: " + error);
return;
return false;
}
if (!res.HasFlag(ConnectivityLevel.Authenticated))
{
MessageBox.Show("Authentication error: Username/password/windows identity is not authorized! Ensure you are a system administrator or in the correct Windows group on the service machine.");
return;
return false;
}
if (I.VersionMismatch(out error) && MessageBox.Show(error, "Warning", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
return;
return true;
new InstanceSelector(I).Show();
Close();
return true;
}
catch
{
@@ -87,14 +154,26 @@ namespace TGS.ControlPanel
}
}
private void SavePasswordCheckBox_CheckedChanged(object sender, EventArgs e)
void SavePasswordCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (!SavePasswordCheckBox.Checked)
if (!updatingFields && !SavePasswordCheckBox.Checked && currentLoginInfo != null)
{
var Config = Properties.Settings.Default;
Config.RemotePassword = null;
Config.RemoteEntropy = null;
currentLoginInfo = null;
PasswordTextBox.Text = "";
}
}
/// <summary>
/// Removes the selected item from <see cref="IPComboBox"/>
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The <see cref="EventArgs"/></param>
void DeleteLoginButton_Click(object sender, EventArgs e)
{
//make sure we're trying to delete a real item
if (IPComboBox.SelectedItem as RemoteLoginInfo == null)
return;
IPComboBox.Items.RemoveAt(IPComboBox.SelectedIndex);
}
}
}
+3 -52
View File
@@ -73,37 +73,12 @@ namespace TGS.ControlPanel.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string RemoteIP {
public global::System.Collections.Specialized.StringCollection RemoteLoginInfo {
get {
return ((string)(this["RemoteIP"]));
return ((global::System.Collections.Specialized.StringCollection)(this["RemoteLoginInfo"]));
}
set {
this["RemoteIP"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string RemoteUsername {
get {
return ((string)(this["RemoteUsername"]));
}
set {
this["RemoteUsername"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("38607")]
public ushort RemotePort {
get {
return ((ushort)(this["RemotePort"]));
}
set {
this["RemotePort"] = value;
this["RemoteLoginInfo"] = value;
}
}
@@ -119,30 +94,6 @@ namespace TGS.ControlPanel.Properties {
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string RemotePassword {
get {
return ((string)(this["RemotePassword"]));
}
set {
this["RemotePassword"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string RemoteEntropy {
get {
return ((string)(this["RemoteEntropy"]));
}
set {
this["RemoteEntropy"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
+1 -13
View File
@@ -14,24 +14,12 @@
<Setting Name="LastChatProvider" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="RemoteIP" Type="System.String" Scope="User">
<Setting Name="RemoteLoginInfo" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="RemoteUsername" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="RemotePort" Type="System.UInt16" Scope="User">
<Value Profile="(Default)">38607</Value>
</Setting>
<Setting Name="RemoteDefault" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="RemotePassword" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="RemoteEntropy" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="GitHubAPIKey" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
+2 -3
View File
@@ -8,10 +8,9 @@ namespace TGS.ControlPanel
/// Used to provide an ATP function for calls into an <see cref="TGS.Interface.IServerInterface"/>
/// </summary>
#if !DEBUG
abstract class ServerOpForm : Form
#else
class ServerOpForm : Form
abstract
#endif
class ServerOpForm : Form
{
/// <summary>
/// Used to wrap <see cref="TGS.Interface.IServerInterface"/> calls in a non-blocking fashion while disabling the <see cref="Form"/> and enabling the wait cursor