mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-24 21:46:52 +01:00
Merge pull request #223 from Cyberboss/master
Control Panel login screen improvements
This commit is contained in:
@@ -35,6 +35,15 @@
|
||||
<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>
|
||||
</TGControlPanel.Properties.Settings>
|
||||
<TGControlPanel.Properties.Settings1>
|
||||
<setting name="LastPageIndex" serializeAs="String">
|
||||
|
||||
Generated
+21
-6
@@ -40,15 +40,16 @@
|
||||
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();
|
||||
((System.ComponentModel.ISupportInitialize)(this.PortSelector)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// LocalLoginButton
|
||||
//
|
||||
this.LocalLoginButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.LocalLoginButton.Location = new System.Drawing.Point(87, 12);
|
||||
this.LocalLoginButton.Location = new System.Drawing.Point(102, 12);
|
||||
this.LocalLoginButton.Name = "LocalLoginButton";
|
||||
this.LocalLoginButton.Size = new System.Drawing.Size(188, 25);
|
||||
this.LocalLoginButton.Size = new System.Drawing.Size(157, 25);
|
||||
this.LocalLoginButton.TabIndex = 13;
|
||||
this.LocalLoginButton.Text = "Connect to Local Service";
|
||||
this.LocalLoginButton.UseVisualStyleBackColor = true;
|
||||
@@ -91,9 +92,9 @@
|
||||
// RemoteLoginButton
|
||||
//
|
||||
this.RemoteLoginButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.RemoteLoginButton.Location = new System.Drawing.Point(87, 200);
|
||||
this.RemoteLoginButton.Location = new System.Drawing.Point(102, 200);
|
||||
this.RemoteLoginButton.Name = "RemoteLoginButton";
|
||||
this.RemoteLoginButton.Size = new System.Drawing.Size(188, 25);
|
||||
this.RemoteLoginButton.Size = new System.Drawing.Size(157, 25);
|
||||
this.RemoteLoginButton.TabIndex = 18;
|
||||
this.RemoteLoginButton.Text = "Connect to Remote Service";
|
||||
this.RemoteLoginButton.UseVisualStyleBackColor = true;
|
||||
@@ -162,12 +163,24 @@
|
||||
0});
|
||||
this.PortSelector.Name = "PortSelector";
|
||||
this.PortSelector.Size = new System.Drawing.Size(80, 20);
|
||||
this.PortSelector.TabIndex = 23;
|
||||
this.PortSelector.TabIndex = 16;
|
||||
this.PortSelector.Value = new decimal(new int[] {
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// SavePasswordCheckBox
|
||||
//
|
||||
this.SavePasswordCheckBox.AutoSize = true;
|
||||
this.SavePasswordCheckBox.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242)))));
|
||||
this.SavePasswordCheckBox.Location = new System.Drawing.Point(265, 205);
|
||||
this.SavePasswordCheckBox.Name = "SavePasswordCheckBox";
|
||||
this.SavePasswordCheckBox.Size = new System.Drawing.Size(100, 17);
|
||||
this.SavePasswordCheckBox.TabIndex = 23;
|
||||
this.SavePasswordCheckBox.Text = "Save Password";
|
||||
this.SavePasswordCheckBox.UseVisualStyleBackColor = true;
|
||||
this.SavePasswordCheckBox.CheckedChanged += new System.EventHandler(this.SavePasswordCheckBox_CheckedChanged);
|
||||
//
|
||||
// Login
|
||||
//
|
||||
@@ -175,6 +188,7 @@
|
||||
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.SavePasswordCheckBox);
|
||||
this.Controls.Add(this.PortSelector);
|
||||
this.Controls.Add(this.label4);
|
||||
this.Controls.Add(this.label3);
|
||||
@@ -211,5 +225,6 @@
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Label label4;
|
||||
private System.Windows.Forms.NumericUpDown PortSelector;
|
||||
}
|
||||
private System.Windows.Forms.CheckBox SavePasswordCheckBox;
|
||||
}
|
||||
}
|
||||
+34
-3
@@ -9,11 +9,19 @@ namespace TGControlPanel
|
||||
public Login()
|
||||
{
|
||||
InitializeComponent();
|
||||
IPTextBox.Text = Properties.Settings.Default.RemoteIP;
|
||||
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)
|
||||
{
|
||||
PasswordTextBox.Text = decrypted;
|
||||
SavePasswordCheckBox.Checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoteLoginButton_Click(object sender, EventArgs e)
|
||||
@@ -21,14 +29,27 @@ namespace TGControlPanel
|
||||
IPTextBox.Text = IPTextBox.Text.Trim();
|
||||
UsernameTextBox.Text = UsernameTextBox.Text.Trim();
|
||||
Server.SetRemoteLoginInformation(IPTextBox.Text, (ushort)PortSelector.Value, UsernameTextBox.Text, PasswordTextBox.Text);
|
||||
Properties.Settings.Default.RemoteIP = IPTextBox.Text;
|
||||
Properties.Settings.Default.RemoteUsername = UsernameTextBox.Text;
|
||||
var Config = Properties.Settings.Default;
|
||||
Config.RemoteIP = IPTextBox.Text;
|
||||
Config.RemoteUsername = UsernameTextBox.Text;
|
||||
if (SavePasswordCheckBox.Checked)
|
||||
{
|
||||
Config.RemotePassword = Helpers.EncryptData(PasswordTextBox.Text, out string entrop);
|
||||
Config.RemoteEntropy = entrop;
|
||||
}
|
||||
else
|
||||
{
|
||||
Config.RemotePassword = null;
|
||||
Config.RemoteEntropy = null;
|
||||
}
|
||||
Config.RemoteDefault = true;
|
||||
VerifyAndConnect();
|
||||
}
|
||||
|
||||
private void LocalLoginButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Server.MakeLocalConnection();
|
||||
Properties.Settings.Default.RemoteDefault = false;
|
||||
VerifyAndConnect();
|
||||
}
|
||||
|
||||
@@ -49,5 +70,15 @@ namespace TGControlPanel
|
||||
new Main().ShowDialog();
|
||||
Close();
|
||||
}
|
||||
|
||||
private void SavePasswordCheckBox_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!SavePasswordCheckBox.Checked)
|
||||
{
|
||||
var Config = Properties.Settings.Default;
|
||||
Config.RemotePassword = null;
|
||||
Config.RemoteEntropy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+36
@@ -106,5 +106,41 @@ namespace TGControlPanel.Properties {
|
||||
this["RemotePort"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("False")]
|
||||
public bool RemoteDefault {
|
||||
get {
|
||||
return ((bool)(this["RemoteDefault"]));
|
||||
}
|
||||
set {
|
||||
this["RemoteDefault"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,5 +23,14 @@
|
||||
<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>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
@@ -167,9 +167,7 @@ namespace TGServerService
|
||||
var rawdata = new JavaScriptSerializer().Serialize(infosList);
|
||||
var Config = Properties.Settings.Default;
|
||||
|
||||
byte[] plaintext = Encoding.UTF8.GetBytes(rawdata);
|
||||
|
||||
Config.ChatProviderData = Program.EncryptData(plaintext, out string entrp);
|
||||
Config.ChatProviderData = Helpers.EncryptData(rawdata, out string entrp);
|
||||
Config.ChatProviderEntropy = entrp;
|
||||
}
|
||||
|
||||
@@ -191,12 +189,12 @@ namespace TGServerService
|
||||
if (rawdata == "NEEDS INITIALIZING")
|
||||
return new List<TGChatSetupInfo>() { new TGIRCSetupInfo(), new TGDiscordSetupInfo() };
|
||||
|
||||
byte[] plaintext;
|
||||
string plaintext;
|
||||
try
|
||||
{
|
||||
plaintext = Program.DecryptData(rawdata, Config.ChatProviderEntropy);
|
||||
plaintext = Helpers.DecryptData(rawdata, Config.ChatProviderEntropy);
|
||||
|
||||
var lists = new JavaScriptSerializer().Deserialize<List<List<string>>>(Encoding.UTF8.GetString(plaintext));
|
||||
var lists = new JavaScriptSerializer().Deserialize<List<List<string>>>(plaintext);
|
||||
var output = new List<TGChatSetupInfo>(lists.Count);
|
||||
var foundirc = 0;
|
||||
var founddiscord = 0;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace TGServerService
|
||||
{
|
||||
@@ -61,24 +60,6 @@ namespace TGServerService
|
||||
}
|
||||
}
|
||||
|
||||
public static string EncryptData(byte[] data, out string sentropy)
|
||||
{
|
||||
// Generate additional entropy (will be used as the Initialization vector)
|
||||
byte[] entropy = new byte[20];
|
||||
using (var rng = new RNGCryptoServiceProvider())
|
||||
rng.GetBytes(entropy);
|
||||
|
||||
byte[] ciphertext = ProtectedData.Protect(data, entropy, DataProtectionScope.CurrentUser);
|
||||
|
||||
sentropy = Convert.ToBase64String(entropy, 0, entropy.Length);
|
||||
return Convert.ToBase64String(ciphertext, 0, ciphertext.Length);
|
||||
}
|
||||
|
||||
public static byte[] DecryptData(string data, string entropy)
|
||||
{
|
||||
return ProtectedData.Unprotect(Convert.FromBase64String(data), Convert.FromBase64String(entropy), DataProtectionScope.CurrentUser);
|
||||
}
|
||||
|
||||
public static void CopyDirectory(string sourceDirName, string destDirName, IList<string> ignore = null, bool ignoreIfNotExists = false)
|
||||
{
|
||||
// If the destination directory doesn't exist, create it.
|
||||
|
||||
@@ -71,7 +71,6 @@
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Security" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace TGServiceInterface
|
||||
{
|
||||
public static class Helpers
|
||||
{
|
||||
public static string EncryptData(string data, out string sentropy)
|
||||
{
|
||||
// Generate additional entropy (will be used as the Initialization vector)
|
||||
byte[] entropy = new byte[20];
|
||||
using (var rng = new RNGCryptoServiceProvider())
|
||||
rng.GetBytes(entropy);
|
||||
|
||||
byte[] ciphertext = ProtectedData.Protect(Encoding.UTF8.GetBytes(data), entropy, DataProtectionScope.CurrentUser);
|
||||
|
||||
sentropy = Convert.ToBase64String(entropy, 0, entropy.Length);
|
||||
return Convert.ToBase64String(ciphertext, 0, ciphertext.Length);
|
||||
}
|
||||
|
||||
public static string DecryptData(string data, string entropy)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Encoding.UTF8.GetString(ProtectedData.Unprotect(Convert.FromBase64String(data), Convert.FromBase64String(entropy), DataProtectionScope.CurrentUser));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Security" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
</ItemGroup>
|
||||
@@ -52,6 +53,7 @@
|
||||
<Compile Include="Connectivity.cs" />
|
||||
<Compile Include="DreamDaemon.cs" />
|
||||
<Compile Include="Chat.cs" />
|
||||
<Compile Include="Helpers.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Repository.cs" />
|
||||
<Compile Include="Server.cs" />
|
||||
|
||||
Reference in New Issue
Block a user