diff --git a/.gitignore b/.gitignore index cbbd0b5..3e16852 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ bin/ -obj/ \ No newline at end of file +obj/ +.vs/ \ No newline at end of file diff --git a/.vs/PteroController/FileContentIndex/476402de-0b51-4d1c-981e-81c780be36b2.vsidx b/.vs/PteroController/FileContentIndex/476402de-0b51-4d1c-981e-81c780be36b2.vsidx deleted file mode 100644 index ae1bd46..0000000 Binary files a/.vs/PteroController/FileContentIndex/476402de-0b51-4d1c-981e-81c780be36b2.vsidx and /dev/null differ diff --git a/.vs/PteroController/FileContentIndex/6a5337f4-dfdb-494c-8f37-5d04fa959dfa.vsidx b/.vs/PteroController/FileContentIndex/6a5337f4-dfdb-494c-8f37-5d04fa959dfa.vsidx deleted file mode 100644 index 9f27763..0000000 Binary files a/.vs/PteroController/FileContentIndex/6a5337f4-dfdb-494c-8f37-5d04fa959dfa.vsidx and /dev/null differ diff --git a/.vs/PteroController/FileContentIndex/821087c5-91db-47d4-81b8-0e5cd335bd03.vsidx b/.vs/PteroController/FileContentIndex/821087c5-91db-47d4-81b8-0e5cd335bd03.vsidx deleted file mode 100644 index e8e5d83..0000000 Binary files a/.vs/PteroController/FileContentIndex/821087c5-91db-47d4-81b8-0e5cd335bd03.vsidx and /dev/null differ diff --git a/.vs/PteroController/FileContentIndex/83b9d885-b924-4aeb-9be0-553f2d669dbb.vsidx b/.vs/PteroController/FileContentIndex/83b9d885-b924-4aeb-9be0-553f2d669dbb.vsidx deleted file mode 100644 index 3c196a1..0000000 Binary files a/.vs/PteroController/FileContentIndex/83b9d885-b924-4aeb-9be0-553f2d669dbb.vsidx and /dev/null differ diff --git a/.vs/PteroController/FileContentIndex/read.lock b/.vs/PteroController/FileContentIndex/read.lock deleted file mode 100644 index e69de29..0000000 diff --git a/.vs/PteroController/v17/.suo b/.vs/PteroController/v17/.suo deleted file mode 100644 index 05a173a..0000000 Binary files a/.vs/PteroController/v17/.suo and /dev/null differ diff --git a/FrmLogin.Designer.cs b/FrmLogin.Designer.cs index a994528..f0395bb 100644 --- a/FrmLogin.Designer.cs +++ b/FrmLogin.Designer.cs @@ -114,6 +114,7 @@ private void InitializeComponent() Name = "FrmLogin"; StartPosition = FormStartPosition.CenterScreen; Text = "PteroController"; + Load += FrmLogin_Load; ResumeLayout(false); PerformLayout(); } diff --git a/FrmLogin.cs b/FrmLogin.cs index 02395d9..0d7a120 100644 --- a/FrmLogin.cs +++ b/FrmLogin.cs @@ -1,5 +1,7 @@ using Newtonsoft.Json.Linq; +using Salaros.Configuration; using System.Net.Http.Headers; +using System.Text; namespace PteroController; @@ -16,6 +18,7 @@ public partial class FrmLogin : Form public static string? panel_admin; public static string panel_language = "en"; + public FrmLogin() { InitializeComponent(); @@ -45,6 +48,38 @@ private void Form1_Load(object sender, EventArgs e) { } + private string Encrypt(string plainText) + { + byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText); + string encryptedText = Convert.ToBase64String(plainTextBytes); + return encryptedText; + } + + private string Decrypt(string encryptedText) + { + byte[] encryptedTextBytes = Convert.FromBase64String(encryptedText); + string decryptedText = Encoding.UTF8.GetString(encryptedTextBytes); + return decryptedText; + } + private void CheckSession() + { + try + { + var account = new ConfigParser(Program.AppAccountInfo); + string panelUrl = Decrypt(account.GetValue("LOGIN", "panel_url")); + string panelAPI = Decrypt(account.GetValue("LOGIN", "api_key")); + string panelPass = Decrypt(account.GetValue("LOGIN", "panel_pwd")); + txtpanelurl.Text = panelUrl; + txtpanelapikey.Text = panelAPI; + txtpanelpwd.Text = panelPass; + btnlogin.PerformClick(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + private async Task GetUserInfo(string apiKey, Uri panelUri) { using (HttpClient client = new HttpClient()) @@ -83,7 +118,7 @@ private async void btnlogin_Click(object sender, EventArgs e) { string apiKey = txtpanelapikey.Text; string panelUrl = txtpanelurl.Text; - +#pragma warning disable if (!Uri.TryCreate(panelUrl, UriKind.Absolute, out Uri panelUri)) { MessageBox.Show("Invalid Pterodactyl Panel URL"); @@ -111,12 +146,25 @@ private async void btnlogin_Click(object sender, EventArgs e) MessageBox.Show("Faild to get your data please check the panel url"); } } +#pragma warning restore catch (Exception ex) { - MessageBox.Show(ex.ToString()); + MessageBox.Show(ex.Message); } panel_url = panelUrl; panel_api_key = apiKey; + try + { + var account = new ConfigParser(Program.AppAccountInfo); + account.SetValue("LOGIN", "panel_url", Encrypt(txtpanelurl.Text)); + account.SetValue("LOGIN", "api_key", Encrypt(txtpanelapikey.Text)); + account.SetValue("LOGIN", "panel_pwd", Encrypt(txtpanelpwd.Text)); + account.Save(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } FrmServerSelector x = new FrmServerSelector(); x.Show(); this.Hide(); @@ -125,4 +173,9 @@ private async void btnlogin_Click(object sender, EventArgs e) } } + + private void FrmLogin_Load(object sender, EventArgs e) + { + CheckSession(); + } } \ No newline at end of file diff --git a/FrmServerSelector.cs b/FrmServerSelector.cs index 4354ca2..60f5745 100644 --- a/FrmServerSelector.cs +++ b/FrmServerSelector.cs @@ -19,7 +19,7 @@ public FrmServerSelector() private void FrmServerSelector_Load(object sender, EventArgs e) { - label1.Text = FrmLogin.panel_admin + FrmLogin.panel_api_key + FrmLogin.panel_id + FrmLogin.panel_first_name; + } } } diff --git a/Program.cs b/Program.cs index f8e78a2..c820c0c 100644 --- a/Program.cs +++ b/Program.cs @@ -5,6 +5,8 @@ internal static class Program /// /// The main entry point for the application. /// + public static string AppSettings = Application.StartupPath + @"\settings.ini"; + public static string AppAccountInfo = Application.StartupPath + @"\account.ini"; [STAThread] static void Main() {