-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindowAuthToken.xaml.cs
101 lines (88 loc) · 2.96 KB
/
WindowAuthToken.xaml.cs
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
using LibKaseya;
using System;
using System.Collections.Generic;
using System.Windows;
namespace KLC_Ex {
/// <summary>
/// Interaction logic for WindowAuthToken.xaml
/// </summary>
public partial class WindowAuthToken : Window
{
public string ReturnAddress;
public string ReturnToken;
public WindowAuthToken()
{
InitializeComponent();
foreach (KeyValuePair<string, KaseyaVSA> vsa in Kaseya.VSA)
{
cmbAddress.Items.Add(vsa.Key);
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
if (cmbAddress.Items.Count > 0)
{
cmbAddress.SelectedIndex = 0;
RefreshToken();
}
}
private void OKButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
//if (cmbAddress.SelectedIndex == -1)
//return;
ReturnAddress = cmbAddress.SelectedItem.ToString().Trim();
ReturnToken = txtAuthToken.Password.Trim();
if (ReturnAddress.Length > 0 && ReturnToken.Length > 0)
{
this.DialogResult = true;
this.Close();
}
}
private void btnAuthCopy_Click(object sender, RoutedEventArgs e)
{
Clipboard.SetDataObject(txtAuthToken.Password);
}
private void btnAuthGetFromKLC_Click(object sender, RoutedEventArgs e)
{
/* //Not .NET 6 compatible
ManagementClass mngmtClass = new ManagementClass("Win32_Process");
foreach (ManagementObject o in mngmtClass.GetInstances())
{
if (o["Name"].Equals("KaseyaLiveConnect.exe"))
{
string find = "liveconnect:///";
string commandline = (string)o["CommandLine"];
int pos = commandline.IndexOf(find);
if (pos > 0)
{
string base64 = commandline.Substring(pos + find.Length);
KLCCommand command = KLCCommand.NewFromBase64(base64);
txtAuthToken.Password = command.payload.auth.Token;
return;
}
}
}
*/
}
private void RefreshToken()
{
foreach (KeyValuePair<string, KaseyaVSA> vsa in Kaseya.VSA)
{
if (vsa.Key == cmbAddress.Text)
{
txtAuthToken.Password = vsa.Value.Token;
return;
}
}
txtAuthToken.Password = "";
}
private void cmbAddress_DropDownClosed(object sender, EventArgs e)
{
RefreshToken();
}
private void cmbAddress_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
RefreshToken();
}
}
}