-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainForm.cs
More file actions
1080 lines (878 loc) · 37.6 KB
/
Copy pathMainForm.cs
File metadata and controls
1080 lines (878 loc) · 37.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.IO;
using System.Linq;
using System.Text;
using MaterialSkin;
using System.Threading;
using System.Windows.Forms;
using MaterialSkin.Controls;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Net.NetworkInformation;
using System.Diagnostics;
namespace UtilityLauncher
{
public partial class MainForm : MaterialForm
{
Random rnd = new Random();
Account thisAccount = null;
MaterialSkinManager materialSkinManager;
private string userEncryptPassword = "";
private string HeidiPath = "";
private string PuttyPath = "";
private string WinScpPath = "";
private string FilezillaPath = "";
private bool isEditing = false;
private bool showPassword = false;
private List<Account> accounts = new List<Account>();
public MainForm()
{
InitializeComponent();
materialSkinManager = MaterialSkinManager.Instance;
materialSkinManager.AddFormToManage(this);
materialSkinManager.Theme = MaterialSkinManager.Themes.DARK;
materialSkinManager.ColorScheme = new ColorScheme(Primary.Yellow700, Primary.Yellow800, Primary.Yellow500, Accent.Yellow400, TextShade.WHITE);
rb_putty.Enabled = false;
rb_heidi.Enabled = false;
rb_winscp.Enabled = false;
rb_filezilla.Enabled = false;
txt_port.Visible = false;
comb_accounts.Width = 602;
txt_pass.Password = true;
comb_accounts.Items.Add("Select an account");
comb_accounts.SelectedItem = "Select an account";
loadConfig();
loadAccounts();
}
private void loadAccounts()
{
string basePath = AppDomain.CurrentDomain.BaseDirectory + "/data";
if (Directory.Exists(basePath))
{
foreach (var fileName in Directory.GetFiles(basePath, "*"))
{
AccountDecrypt(File.ReadAllText(fileName), fileName);
}
}
}
private void loadConfig()
{
string basePath = AppDomain.CurrentDomain.BaseDirectory + "/other.ulfs";
if (File.Exists(basePath))
{
try
{
string password = MD5Hash(GetMacAdress());
// Create sha256 hash
SHA256 mySHA256 = SHA256Managed.Create();
byte[] key = mySHA256.ComputeHash(Encoding.ASCII.GetBytes(password));
// Create secret IV
byte[] iv = new byte[16] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
string decrypt = Aes_Decrypt(File.ReadAllText(basePath), key, iv);
Dictionary<string, string> Settings = jsonToDictionary(decrypt);
userEncryptPassword = Settings["userEncryptPassword"];
HeidiPath = Settings["HeidiPath"];
PuttyPath = Settings["PuttyPath"];
WinScpPath = Settings["WinScpPath"];
FilezillaPath = Settings["FilezillaPath"];
txt_filesPass.Text = userEncryptPassword;
txt_filesPass.Enabled = false;
txt_heidiPath.Text = HeidiPath;
txt_puttyPath.Text = PuttyPath;
txt_winscpPath.Text = WinScpPath;
txt_filezillaPath.Text = FilezillaPath;
}
catch(Exception err)
{
MessageBox.Show(err.ToString(), "Parse file error", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("Error while tring to read saved settings", "Parse file error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txt_filesPass.Text = "";
txt_puttyPath.Text = "";
txt_heidiPath.Text = "";
txt_winscpPath.Text = "";
txt_filezillaPath.Text = "";
}
}
else
{
txt_filesPass.Text = "";
txt_puttyPath.Text = "";
txt_heidiPath.Text = "";
txt_winscpPath.Text = "";
txt_filezillaPath.Text = "";
}
}
//////////////////////////
// Dictionary Functions //
/////////////////////////
public string DictionaryToJson(Dictionary<string, string> dictionary)
{
var kvs = dictionary.Select(kvp => string.Format("\"{0}\":\"{1}\"", kvp.Key, kvp.Value));
return string.Concat("{", string.Join(",", kvs), "}");
}
public Dictionary<string, string> jsonToDictionary(string json)
{
string[] keyValueArray = json.Replace("{", string.Empty).Replace("}", string.Empty).Replace("\"", string.Empty).Split(',');
return keyValueArray.ToDictionary(item => item.Split(':')[0], item => item.Substring(item.Split(':')[0].Length + 1));
}
/////////////////////////
// Encryptation System //
/////////////////////////
private void AccountEncrypt(string AccountHost, string AccountName, string AccountUser, string AccountPassword, bool ssh, bool ftp, bool sftp, bool sql)
{
try
{
string basePath = AppDomain.CurrentDomain.BaseDirectory + "/data";
if (!AccountName.Contains($"{AccountUser}@{AccountHost}"))
{
AccountName = AccountName + $" ({AccountUser}@{AccountHost})";
}
for (int i = 0; i < 9999; i++)
{
if (File.Exists($"{basePath}/{AccountName}.ulfs"))
{
AccountName = $"[0{i}] " + AccountName;
}
else
{
break;
}
}
var keyValues = new Dictionary<string, string> // Se crea un diccionario donde se pondra una structura Key Value para ser codificada a Json
{
{"AccountHost", AccountHost},
{"AccountName", AccountName},
{"AccountUser", AccountUser},
{"AccountPassword", AccountPassword},
{"ssh", ssh.ToString()},
{"ftp", ftp.ToString()},
{"sftp", sftp.ToString()},
{"sql", sql.ToString()}
};
string json = DictionaryToJson(keyValues);
string password = MD5Hash(userEncryptPassword.Substring(0, 16) + userEncryptPassword.ToString() + userEncryptPassword.Substring(16));
// Create sha256 hash
SHA256 mySHA256 = SHA256Managed.Create();
byte[] key = mySHA256.ComputeHash(Encoding.ASCII.GetBytes(MD5Hash(password)));
// Create secret IV
byte[] iv = new byte[16] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
string encrypted = Aes_Encrypt(json, key, iv);
if (!Directory.Exists(basePath))
{
Directory.CreateDirectory(basePath);
}
File.WriteAllText(Path.GetFullPath($"{basePath}/{AccountName}.ulfs"), encrypted);
Account tempData = new Account
{
index = (accounts.Count + 1).ToString(),
path = $"{basePath}/{AccountName}.ulfs",
name = keyValues["AccountName"],
host = keyValues["AccountHost"],
username = keyValues["AccountUser"],
password = keyValues["AccountPassword"],
putty = ssh,
heidi = sql,
winscp = sftp,
filezilla = ftp
};
accounts.Add(tempData);
comb_accounts.Items.Add(AccountName);
MessageBox.Show("Account Saved", "Information saved!", MessageBoxButtons.OK, MessageBoxIcon.Information);
chk_ssh.Checked = false;
chk_ftp.Checked = false;
chk_sftp.Checked = false;
chk_mysql.Checked = false;
showPassword = false;
txt_pass.Password = true;
txt_name.Text = "";
txt_user.Text = "";
txt_pass.Text = "";
txt_host.Text = "";
}
catch(Exception err)
{
MessageBox.Show("An error occurred while saving account data\n\nError:"+err.Message, "Save error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
private void AccountDecrypt(string AES, string filePath)
{
try
{
string password = MD5Hash(userEncryptPassword.Substring(0, 16) + userEncryptPassword.ToString() + userEncryptPassword.Substring(16));
// Create sha256 hash
SHA256 mySHA256 = SHA256Managed.Create();
byte[] key = mySHA256.ComputeHash(Encoding.ASCII.GetBytes(MD5Hash(password)));
// Create secret IV
byte[] iv = new byte[16] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
string decrypt = Aes_Decrypt(AES, key, iv);
Dictionary<string, string> keyValues = jsonToDictionary(decrypt);
Account tempData = new Account
{
index = (accounts.Count + 1).ToString(),
path = filePath,
name = keyValues["AccountName"],
host = keyValues["AccountHost"],
username = keyValues["AccountUser"],
password = keyValues["AccountPassword"],
putty = bool.Parse(keyValues["ssh"]),
heidi = bool.Parse(keyValues["sql"]),
winscp = bool.Parse(keyValues["sftp"]),
filezilla = bool.Parse(keyValues["ftp"])
};
accounts.Add(tempData);
comb_accounts.Items.Add(keyValues["AccountName"]);
}
catch
{
//
}
}
///////////////////////////
// Encryptation Function //
///////////////////////////
public string Aes_Encrypt(string plainText, byte[] key, byte[] iv)
{
// Instantiate a new Aes object to perform string symmetric encryption
Aes encryptor = Aes.Create();
encryptor.Mode = CipherMode.CBC;
//encryptor.KeySize = 256;
//encryptor.BlockSize = 128;
//encryptor.Padding = PaddingMode.Zeros;
// Set key and IV
encryptor.Key = key;
encryptor.IV = iv;
// Instantiate a new MemoryStream object to contain the encrypted bytes
MemoryStream memoryStream = new MemoryStream();
// Instantiate a new encryptor from our Aes object
ICryptoTransform aesEncryptor = encryptor.CreateEncryptor();
// Instantiate a new CryptoStream object to process the data and write it to the
// memory stream
CryptoStream cryptoStream = new CryptoStream(memoryStream, aesEncryptor, CryptoStreamMode.Write);
// Convert the plainText string into a byte array
byte[] plainBytes = Encoding.ASCII.GetBytes(plainText);
// Encrypt the input plaintext string
cryptoStream.Write(plainBytes, 0, plainBytes.Length);
// Complete the encryption process
cryptoStream.FlushFinalBlock();
// Convert the encrypted data from a MemoryStream to a byte array
byte[] cipherBytes = memoryStream.ToArray();
// Close both the MemoryStream and the CryptoStream
memoryStream.Close();
cryptoStream.Close();
// Convert the encrypted byte array to a base64 encoded string
string cipherText = Convert.ToBase64String(cipherBytes, 0, cipherBytes.Length);
// Return the encrypted data as a string
return cipherText;
}
public string Aes_Decrypt(string cipherText, byte[] key, byte[] iv)
{
// Instantiate a new Aes object to perform string symmetric encryption
Aes encryptor = Aes.Create();
encryptor.Mode = CipherMode.CBC;
//encryptor.KeySize = 256;
//encryptor.BlockSize = 128;
//encryptor.Padding = PaddingMode.Zeros;
// Set key and IV
encryptor.Key = key;
encryptor.IV = iv;
// Instantiate a new MemoryStream object to contain the encrypted bytes
MemoryStream memoryStream = new MemoryStream();
// Instantiate a new encryptor from our Aes object
ICryptoTransform aesDecryptor = encryptor.CreateDecryptor();
// Instantiate a new CryptoStream object to process the data and write it to the
// memory stream
CryptoStream cryptoStream = new CryptoStream(memoryStream, aesDecryptor, CryptoStreamMode.Write);
// Will contain decrypted plaintext
string plainText = String.Empty;
try
{
// Convert the ciphertext string into a byte array
byte[] cipherBytes = Convert.FromBase64String(cipherText);
// Decrypt the input ciphertext string
cryptoStream.Write(cipherBytes, 0, cipherBytes.Length);
// Complete the decryption process
cryptoStream.FlushFinalBlock();
// Convert the decrypted data from a MemoryStream to a byte array
byte[] plainBytes = memoryStream.ToArray();
// Convert the decrypted byte array to string
plainText = Encoding.ASCII.GetString(plainBytes, 0, plainBytes.Length);
}
finally
{
// Close both the MemoryStream and the CryptoStream
memoryStream.Close();
cryptoStream.Close();
}
// Return the decrypted data as a string
return plainText;
}
public string MD5Hash(string text)
{
MD5 md5 = new MD5CryptoServiceProvider();
//compute hash from the bytes of text
md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(text));
//get hash result after compute it
byte[] result = md5.Hash;
StringBuilder strBuilder = new StringBuilder();
for (int i = 0; i < result.Length; i++)
{
//change it into 2 hexadecimal digits
//for each byte
strBuilder.Append(result[i].ToString("x2"));
}
return strBuilder.ToString();
}
/////////////////////
// Other Functions //
/////////////////////
public string GetMacAdress()
{
string mac = "NULL";
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.OperationalStatus == OperationalStatus.Up && (!nic.Description.Contains("Virtual") && !nic.Description.Contains("Pseudo")))
{
if (nic.GetPhysicalAddress().ToString() != "")
{
mac = nic.GetPhysicalAddress().ToString();
break;
}
}
}
return mac;
}
private void SaveSettings(bool ExistingConfig)
{
string mac = GetMacAdress();
if (mac == "NULL")
{
MessageBox.Show("An error ocurred while trying to get the Mac Adress", "Mac Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Dictionary<string, string> keyValues = null;
if (ExistingConfig)
{
keyValues = new Dictionary<string, string> // Se crea un diccionario donde se pondra una structura Key Value para ser codificada a Json
{
{ "userEncryptPassword", txt_filesPass.Text},
{ "HeidiPath", txt_heidiPath.Text},
{ "PuttyPath", txt_puttyPath.Text},
{ "WinScpPath", txt_winscpPath.Text},
{ "FilezillaPath", txt_filezillaPath.Text}
};
}
else
{
keyValues = new Dictionary<string, string> // Se crea un diccionario donde se pondra una structura Key Value para ser codificada a Json
{
{ "userEncryptPassword", MD5Hash(txt_filesPass.Text)},
{ "HeidiPath", txt_heidiPath.Text},
{ "PuttyPath", txt_puttyPath.Text},
{ "WinScpPath", txt_winscpPath.Text},
{ "FilezillaPath", txt_filezillaPath.Text}
};
}
string json = DictionaryToJson(keyValues);
string password = MD5Hash(mac);
// Create sha256 hash
SHA256 mySHA256 = SHA256Managed.Create();
byte[] key = mySHA256.ComputeHash(Encoding.ASCII.GetBytes(password));
// Create secret IV
byte[] iv = new byte[16] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
string encrypted = Aes_Encrypt(json, key, iv);
string basePath = AppDomain.CurrentDomain.BaseDirectory + "/other.ulfs";
File.WriteAllText(basePath, encrypted);
}
//////////////////
// Apps Install //
//////////////////
private void btn_filezillaInstall_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://filezilla-project.org/");
}
private void btn_winscpInstall_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://winscp.net/eng/download.php");
}
private void btn_puttyInstall_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html");
}
private void btn_heidiInstall_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://www.heidisql.com/download.php?download=installer");
}
/////////////////
// Search Apps //
/////////////////
private void btn_filezillaSearch_Click(object sender, EventArgs e)
{
try
{
ofd_searchApps.Title = "Open Filezilla executable";
ofd_searchApps.FileName = "filezilla.exe";
ofd_searchApps.ShowDialog();
string path = ofd_searchApps.FileName;
if (Path.GetFileName(path) == "filezilla.exe")
{
if (File.ReadAllText(path).Contains("MZ"))
{
txt_filezillaPath.Text = path;
}
else
{
MessageBox.Show("Please, Select a valid filezilla executable.", "Invalid Program", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else if (path != "")
{
MessageBox.Show("Please, Select a valid filezilla executable.", "Invalid Program", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch
{
//
}
}
private void btn_winscpSearch_Click(object sender, EventArgs e)
{
try
{
ofd_searchApps.Title = "Open WinSCP executable";
ofd_searchApps.FileName = "WinSCP.exe";
ofd_searchApps.ShowDialog();
string path = ofd_searchApps.FileName;
if (Path.GetFileName(path) == "WinSCP.exe")
{
if (File.ReadAllText(path).Contains("MZ"))
{
txt_winscpPath.Text = path;
}
else
{
MessageBox.Show("Please, Select a valid WinSCP executable.", "Invalid Program", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else if (path != "")
{
MessageBox.Show("Please, Select a valid WinSCP executable.", "Invalid Program", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch
{
//
}
}
private void btn_puttySearch_Click(object sender, EventArgs e)
{
try
{
ofd_searchApps.Title = "Open Putty executable";
ofd_searchApps.FileName = "putty.exe";
ofd_searchApps.ShowDialog();
string path = ofd_searchApps.FileName;
if (Path.GetFileName(path) == "putty.exe")
{
if (File.ReadAllText(path).Contains("MZ"))
{
txt_puttyPath.Text = path;
}
else
{
MessageBox.Show("Please, Select a valid Putty executable.", "Invalid Program", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else if (path != "")
{
MessageBox.Show("Please, Select a valid Putty executable.", "Invalid Program", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch
{
//
}
}
private void btn_heidiSearch_Click(object sender, EventArgs e)
{
try
{
ofd_searchApps.Title = "Open HeidiSQL executable";
ofd_searchApps.FileName = "heidisql.exe";
ofd_searchApps.ShowDialog();
string path = ofd_searchApps.FileName;
if (Path.GetFileName(path) == "heidisql.exe")
{
if (File.ReadAllText(path).Contains("MZ"))
{
txt_heidiPath.Text = path;
}
else
{
MessageBox.Show("Please, Select a valid HeidiSQL executable.", "Invalid Program", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else if (path != "")
{
MessageBox.Show("Please, Select a valid HeidiSQL executable.", "Invalid Program", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch
{
//
}
}
//////////////////////
// Settings Buttons //
//////////////////////
private void btn_cfg_cancel_Click(object sender, EventArgs e)
{
if ((userEncryptPassword != "" && userEncryptPassword != " ")
|| (HeidiPath != "" && HeidiPath != " ")
|| (PuttyPath != "" && PuttyPath != " ")
|| (WinScpPath != "" && WinScpPath != " ")
|| (FilezillaPath != "" && FilezillaPath != " "))
{
txt_filesPass.Text = userEncryptPassword;
txt_heidiPath.Text = HeidiPath;
txt_puttyPath.Text = PuttyPath;
txt_winscpPath.Text = WinScpPath;
txt_filezillaPath.Text = FilezillaPath;
}
else
{
txt_filesPass.Text = "";
txt_puttyPath.Text = "";
txt_heidiPath.Text = "";
txt_winscpPath.Text = "";
txt_filezillaPath.Text = "";
}
}
private void btn_cfg_save_Click(object sender, EventArgs e)
{
if (txt_filesPass.Text.Replace(" ", "") == "")
{
MessageBox.Show("You can't set an empty password for the files", "Invalid Setting", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string basePath = AppDomain.CurrentDomain.BaseDirectory + "/other.ulfs";
if (File.Exists(basePath))
{
DialogResult answer = MessageBox.Show("Your old settings will be rewritten if you continue, Do you want to continue?", "Existing Settings", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (answer == DialogResult.Yes)
{
SaveSettings(true);
}
}
else
{
SaveSettings(false);
}
MessageBox.Show("Setting saved successfully", "Settings Saved!", MessageBoxButtons.OK, MessageBoxIcon.Information);
loadConfig();
}
////////////////////
// Debug Function //
////////////////////
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
Environment.Exit(-1);
}
///////////////////////////////
// Account Creator Functions //
///////////////////////////////
private void btn_swithPass_Click(object sender, EventArgs e)
{
txt_pass.Focus();
if (showPassword == true)
{
txt_pass.Focus();
txt_pass.Password = true;
}
else
{
txt_pass.Focus();
txt_pass.Password = false;
}
showPassword = !showPassword;
}
private void btn_clear_Click(object sender, EventArgs e)
{
if (isEditing)
{
isEditing = false;
btn_clear.Text = "Clear";
btn_add_update.Text = "Add";
btn_clear.Left = 565;
btn_add_update.Left = 640;
btn_add_update.Width = 50;
}
rb_putty.Checked = false;
rb_heidi.Checked = false;
rb_winscp.Checked = false;
rb_filezilla.Checked = false;
comb_accounts.SelectedItem = "Select an account";
chk_ssh.Checked = false;
chk_ftp.Checked = false;
chk_sftp.Checked = false;
chk_mysql.Checked = false;
showPassword = false;
txt_pass.Password = true;
txt_name.Text = "";
txt_user.Text = "";
txt_pass.Text = "";
txt_host.Text = "";
}
private void btn_add_update_Click(object sender, EventArgs e)
{
if (userEncryptPassword == "" || userEncryptPassword == null)
{
MessageBox.Show("You need to set a password in the configs before save an account", "No password", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (txt_host.Text.Replace(" ", "") == "" || txt_name.Text.Replace(" ", "") == "" || txt_user.Text.Replace(" ", "") == "")
{
MessageBox.Show("There are empty fields, Please complete all fields", "Empty fields", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (chk_ssh.Checked == false && chk_ftp.Checked == false && chk_sftp.Checked == false && chk_mysql.Checked == false)
{
MessageBox.Show("You need to select the available connect methods for this new account", "No methods selected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (isEditing == true)
{
DialogResult res = MessageBox.Show($"Are you sure do you want to update \"{thisAccount.name}\" Account?", "Update account", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (res != DialogResult.Yes)
{
return;
}
comb_accounts.Items.Remove(thisAccount.name);
if (File.Exists(thisAccount.path))
{
File.Delete(thisAccount.path);
}
accounts.Remove(thisAccount);
thisAccount = null;
AccountEncrypt(txt_host.Text, txt_name.Text, txt_user.Text, txt_pass.Text, chk_ssh.Checked, chk_ftp.Checked, chk_sftp.Checked, chk_mysql.Checked);
comb_accounts.SelectedItem = "Select an account";
isEditing = false;
btn_clear.Text = "Clear";
btn_add_update.Text = "Add";
btn_clear.Left = 565;
btn_add_update.Left = 640;
btn_add_update.Width = 50;
}
else
{
AccountEncrypt(txt_host.Text, txt_name.Text, txt_user.Text, txt_pass.Text, chk_ssh.Checked, chk_ftp.Checked, chk_sftp.Checked, chk_mysql.Checked);
}
}
private void comb_accounts_SelectedIndexChanged(object sender, EventArgs e)
{
rb_putty.Checked = false;
rb_heidi.Checked = false;
rb_winscp.Checked = false;
rb_filezilla.Checked = false;
if (comb_accounts.SelectedItem.ToString() == "Select an account")
{
txt_port.Visible = false;
comb_accounts.Width = 602;
rb_putty.Enabled = false;
rb_heidi.Enabled = false;
rb_winscp.Enabled = false;
rb_filezilla.Enabled = false;
btn_open.Enabled = false;
btn_edit.Enabled = false;
btn_delete.Enabled = false;
thisAccount = null;
return;
}
btn_open.Enabled = false;
btn_edit.Enabled = true;
btn_delete.Enabled = true;
txt_port.Visible = true;
comb_accounts.Width = 505;
bool finded = false;
foreach (var account in accounts)
{
if (account.name == comb_accounts.SelectedItem.ToString())
{
finded = true;
thisAccount = account;
break;
}
}
if (finded && thisAccount != null)
{
rb_putty.Enabled = thisAccount.putty;
rb_heidi.Enabled = thisAccount.heidi;
rb_winscp.Enabled = thisAccount.winscp;
rb_filezilla.Enabled = thisAccount.filezilla;
}
}
///////////////////
// Radio Buttons //
///////////////////
private void rb_putty_CheckedChanged(object sender, EventArgs e)
{
if (rb_putty.Checked == true)
{
btn_open.Enabled = true;
txt_port.Text = "22";
}
}
private void rb_filezilla_CheckedChanged(object sender, EventArgs e)
{
if (rb_filezilla.Checked == true)
{
btn_open.Enabled = true;
txt_port.Text = "21";
}
}
private void rb_winscp_CheckedChanged(object sender, EventArgs e)
{
if (rb_winscp.Checked == true)
{
btn_open.Enabled = true;
txt_port.Text = "22";
}
}
private void rb_heidi_CheckedChanged(object sender, EventArgs e)
{
if (rb_heidi.Checked == true)
{
btn_open.Enabled = true;
txt_port.Text = "3306";
}
}
/////////////////////////////
// Account Creator Manager //
/////////////////////////////
private void btn_open_Click(object sender, EventArgs e)
{
if (comb_accounts.SelectedItem.ToString() == "Select an account")
{
return;
}
if (txt_port.Text.Replace(" ", "") == "")
{
MessageBox.Show("There are empty fields, Please complete all fields", "Empty fields", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (rb_putty.Checked == false && rb_filezilla.Checked == false && rb_winscp.Checked == false && rb_heidi.Checked == false)
{
MessageBox.Show("You need to select the connect method", "No method selected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string Port = txt_port.Text;
Thread OpenThread = new Thread(() =>
{
ProcessStartInfo startInfo = new ProcessStartInfo();
if (rb_putty.Checked)
{
if (PuttyPath == "" || PuttyPath == null)
{
MessageBox.Show("Please, Set the putty.exe path in the configuration", "No Path", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
startInfo.FileName = PuttyPath;
startInfo.Arguments = string.Format("{0}@{1} -pw {2} -P {3}", thisAccount.username, thisAccount.host, thisAccount.password, Port);
}
if (rb_filezilla.Checked)
{
if (FilezillaPath == "" || FilezillaPath == null)
{
MessageBox.Show("Please, Set the filezilla.exe path in the configuration", "No Path", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
startInfo.FileName = FilezillaPath;
startInfo.Arguments = string.Format("ftp://{0}:{1}@{2}:{3}", thisAccount.username, thisAccount.password, thisAccount.host, Port);
}
if (rb_winscp.Checked)
{
if (WinScpPath == "" || WinScpPath == null)
{
MessageBox.Show("Please, Set the WinSCP.exe path in the configuration", "No Path", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
startInfo.FileName = WinScpPath;
startInfo.Arguments = string.Format("sftp://{0}:{1}@{2}:{3}", thisAccount.username, thisAccount.password, thisAccount.host, Port);
}
if (rb_heidi.Checked)
{
if (HeidiPath == "" || HeidiPath == null)
{
MessageBox.Show("Please, Set the heidisql.exe path in the configuration", "No Path", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
startInfo.FileName = HeidiPath;
startInfo.Arguments = string.Format("--host={0} --user={1} --password={2} --port={3}", thisAccount.host, thisAccount.username, thisAccount.password, Port);
}
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
});
OpenThread.Start();