forked from MythicalLTD/Pterodactyl-Desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrmServerController.cs
727 lines (653 loc) · 28.9 KB
/
FrmServerController.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
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
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RestSharp;
using Salaros.Configuration;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.WebSockets;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PteroController
{
public partial class FrmServerController : Form
{
public static string ServerId;
public static string authToken;
public static string wsuri;
public static string sftp_ip;
public static string ipAlias;
public static string svmport;
public static string sftp_port;
private static string settings = Application.StartupPath + @"\settings.ini";
private static string accountinfo = Application.StartupPath + @"\account.ini";
private ClientWebSocket webSocket;
private CancellationTokenSource cancellationTokenSource;
private string serverIdentifier;
private HttpClient httpClient;
private DataTable datatable;
public FrmServerController(string serverIdentifier)
{
InitializeComponent();
commandTextBox.KeyPress += commandTextBox_KeyPress;
this.serverIdentifier = serverIdentifier;
ServerId = serverIdentifier;
httpClient = new HttpClient();
datatable = new DataTable();
AddColumnsToDataTable();
dataTable.DataSource = datatable;
}
private async void loadWebsocket()
{
timer1.Stop();
timer1.Start();
try
{
var client = new RestClient(FrmLogin.panel_url);
var request = new RestRequest($"/api/client/servers/{ServerId}/websocket", Method.Get);
request.AddHeader("Authorization", $"Bearer {FrmLogin.user_api_key}");
request.AddHeader("Accept", "Application/vnd.pterodactyl.v1+json");
var response = client.Execute(request);
if (response.IsSuccessful)
{
var serverInfo = JObject.Parse(response.Content);
string token = serverInfo["data"]["token"].ToString();
string socket = serverInfo["data"]["socket"].ToString();
wsuri = socket;
authToken = token;
}
else
{
MessageBox.Show($"Failed to fetch server information. Error: {response.Content}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
webSocket = new ClientWebSocket();
webSocket.Options.SetRequestHeader("Origin", FrmLogin.panel_url);
await webSocket.ConnectAsync(new Uri(wsuri), CancellationToken.None);
cancellationTokenSource = new CancellationTokenSource();
await AuthenticateWebSocket();
await ReceiveConsoleOutput(cancellationTokenSource.Token);
}
catch (Exception ex)
{
MessageBox.Show("[WEBSOCKET LOADER] Failed to connect to the websocket: " + ex.Message);
Console.WriteLine("[WEBSOCKET LOADER] Failed to connect to the websocket: " + ex.Message);
}
}
private void loadSettings()
{
var cfg = new ConfigParser(settings);
string allontop = cfg.GetValue("CONFIG", "always_on_top");
if (allontop == "true")
{
this.TopMost = true;
}
}
private void isMcSv()
{
string url = "https://api.mcsrvstat.us/2/" + ipAlias + ":" + svmport;
string json = new WebClient().DownloadString(url);
JObject data = JObject.Parse(json);
bool isOnline = (bool)data["online"];
if (isOnline)
{
string imageDataUri = (string)data["icon"];
if (imageDataUri != null)
{
string base64Data = imageDataUri.Split(',')[1];
byte[] imageData = Convert.FromBase64String(base64Data);
using (MemoryStream ms = new MemoryStream(imageData))
{
Image image = Image.FromStream(ms);
pcsvimg.Image = image;
}
}
else
{
}
}
}
private void loadServerInfo()
{
try
{
var client = new RestClient(FrmLogin.panel_url);
var request = new RestRequest($"/api/client/servers/{ServerId}", Method.Get);
request.AddHeader("Authorization", $"Bearer {FrmLogin.user_api_key}");
request.AddHeader("Accept", "Application/vnd.pterodactyl.v1+json");
var response = client.Execute(request);
if (response.IsSuccessful)
{
var serverInfo = JObject.Parse(response.Content);
string serverName = serverInfo["attributes"]["name"].ToString();
string serverNode = serverInfo["attributes"]["node"].ToString();
string serverDescription = serverInfo["attributes"]["description"].ToString();
string servermaxram = serverInfo["attributes"]["limits"]["memory"].ToString();
string servermaxdisk = serverInfo["attributes"]["limits"]["disk"].ToString();
string servermaxcpu = serverInfo["attributes"]["limits"]["cpu"].ToString();
if (servermaxram == "0")
{
lblram.Text = "Ram: Unlimited";
}
else
{
lblram.Text = "Ram: " + servermaxram;
}
if (servermaxdisk == "0")
{
lbldisk.Text = "Disk: Unlimited";
}
else
{
lbldisk.Text = "Disk: " + servermaxdisk;
}
if (servermaxcpu == "0")
{
lblcpu.Text = "Cpu: Unlimited";
}
else
{
lblcpu.Text = "Cpu: " + servermaxcpu;
}
sftp_port = serverInfo["attributes"]["sftp_details"]["port"].ToString();
sftp_ip = serverInfo["attributes"]["sftp_details"]["ip"].ToString();
svname.Text = "Name: " + serverName;
svnode.Text = "Node: " + serverNode;
var allocations = serverInfo["attributes"]["relationships"]["allocations"]["data"];
foreach (var allocation in allocations)
{
if (allocation["attributes"]["is_default"].ToObject<bool>())
{
ipAlias = allocation["attributes"]["ip_alias"].ToString();
svmport = allocation["attributes"]["port"].ToString();
lblsvip.Text = "IP: " + (string.IsNullOrEmpty(ipAlias) ? "N/A" : ipAlias) + ":" + (string.IsNullOrEmpty(svmport) ? "N/A" : svmport);
break;
}
}
}
else
{
MessageBox.Show($"Failed to fetch server information. Error: {response.Content}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred while fetching server information. Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private async void FrmMain_Load(object sender, EventArgs e)
{
Pages.TabSize = new Size(0, 0);
loadWebsocket();
timer1.Interval = 840000;
timer1.Tick += timer1_Tick;
timer1.Start();
loadSettings();
timer1.Start();
Pages.SelectedPage = tab1;
loadServerInfo();
isMcSv();
await LoadDatabases();
}
private void AddColumnsToDataTable()
{
datatable.Columns.Add("ID", typeof(string));
datatable.Columns.Add("Name", typeof(string));
datatable.Columns.Add("Username", typeof(string));
datatable.Columns.Add("Host Address", typeof(string));
datatable.Columns.Add("Host Port", typeof(int));
}
private JObject ExtractJsonFromHtml(string html)
{
var startIndex = html.IndexOf('{');
var endIndex = html.LastIndexOf('}');
if (startIndex != -1 && endIndex != -1)
{
var jsonData = html.Substring(startIndex, endIndex - startIndex + 1);
return JObject.Parse(jsonData);
}
return null;
}
private async Task LoadDatabases()
{
try
{
var apiUrl = $"{FrmLogin.panel_url}/api/client/servers/{ServerId}/databases?include=password";
var request = new HttpRequestMessage(HttpMethod.Get, apiUrl);
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", $"Bearer {FrmLogin.user_api_key}");
var response = await httpClient.SendAsync(request);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var jsonData = ExtractJsonFromHtml(content);
if (jsonData != null && jsonData.ContainsKey("data"))
{
var data = jsonData["data"];
datatable.Columns.Clear();
datatable.Rows.Clear();
datatable.Columns.Add("DB Name", typeof(string));
datatable.Columns.Add("DB Username", typeof(string));
datatable.Columns.Add("DB Password", typeof(string));
datatable.Columns.Add("DB Address", typeof(string));
datatable.Columns.Add("DB Port", typeof(int));
datatable.Columns.Add("Allowed IP'S", typeof(string));
foreach (var database in data)
{
var attributes = database["attributes"];
var passwordAttributes = attributes["relationships"]["password"]["attributes"];
string id = attributes["connections_from"]?.ToString();
string name = attributes["name"]?.ToString();
string username = attributes["username"]?.ToString();
string password = passwordAttributes["password"]?.ToString();
string hostAddress = attributes["host"]?["address"]?.ToString();
int hostPort = attributes["host"]?["port"]?.Value<int>() ?? 0;
datatable.Rows.Add(name, username, password, hostAddress, hostPort, id);
}
}
else
{
MessageBox.Show("Failed to parse JSON from response.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
var errorResponse = await response.Content.ReadAsStringAsync();
MessageBox.Show($"Failed to load databases. Response: {errorResponse}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine(errorResponse);
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine(ex.Message);
}
}
private async Task AuthenticateWebSocket()
{
var authPayload = new
{
@event = "auth",
args = new object[] { authToken }
};
var jsonPayload = JsonConvert.SerializeObject(authPayload);
var authBytes = Encoding.UTF8.GetBytes(jsonPayload);
await webSocket.SendAsync(new ArraySegment<byte>(authBytes), WebSocketMessageType.Text, true, CancellationToken.None);
}
private async Task ReceiveConsoleOutput(CancellationToken cancellationToken)
{
try
{
var buffer = new byte[1024];
while (!cancellationToken.IsCancellationRequested && webSocket.State == WebSocketState.Open)
{
var receiveResult = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), cancellationToken);
if (receiveResult.MessageType == WebSocketMessageType.Text)
{
var consoleOutput = Encoding.UTF8.GetString(buffer, 0, receiveResult.Count);
UpdateConsoleOutput(consoleOutput);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void UpdateConsoleOutput(string consoleOutput)
{
if (consoleTextBox.InvokeRequired)
{
consoleTextBox.Invoke(new Action<string>(UpdateConsoleOutput), consoleOutput);
}
else
{
try
{
var cleanOutput = RemoveEscapeSequences(consoleOutput);
var payload = JObject.Parse(cleanOutput);
if (payload.ContainsKey("event") && payload["event"].ToString() == "console output")
{
var args = payload["args"];
if (args != null && args.Count() > 0)
{
var output = args[0].ToString();
var cleanedOutput = RemoveEscapeSequences(output);
consoleTextBox.AppendText(cleanedOutput + Environment.NewLine);
consoleTextBox.SelectionStart = consoleTextBox.Text.Length;
consoleTextBox.ScrollToCaret();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
MessageBox.Show("Sorry we can't handle this console output please do not use this command or please wait for a bug fix");
FrmServerController x = new FrmServerController(ServerId);
x.Show();
this.Hide();
}
}
}
private string RemoveEscapeSequences(string input)
{
var excludedPatterns = new List<string>
{
@"[m",
@"[38;2;255;255;255m",
@"[38;2;255;170;0m",
@"[38;2;255;255;85m",
@"[38;2;170;170;170m",
@"[[0;34;22m",
@">[2K",
@"[0;30;22m",
@"[0;31;22m[21m[4m",
@"[0;37;22m",
@"[0;31;1m",
@"[0;31;1m[21m",
@"[2K",
@"[0;37;1m",
@"[21m",
@"[",
@"1m33mcontainer@pterodactyl~ 0mjava -version",
@"1m33m",
@"0m",
@"33m1m",
@"39m",
@"38;2;255;170;",
@"38;2;170;170;17",
@"33m",
@"0;33;1m",
@"0;33;22m",
@"0;32;1m",
@"0;32;22m",
@"0;30;1m",
@"0;36;1m",
@"0;36;22m",
@"39;",
@"0;31;22m",
@";8eeab68",
@"32;22m",
@"33;1m",
@"1m",
@"38;2;85;255;255m",
@"38;2;85;255;85m",
@"*",
@"0;31;"
};
foreach (var pattern in excludedPatterns)
{
input = Regex.Replace(input, Regex.Escape(pattern), string.Empty);
}
return input;
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
cancellationTokenSource?.Cancel();
webSocket?.Dispose();
base.OnFormClosing(e);
}
private void timer1_Tick(object sender, EventArgs e)
{
Alert("Your time is out!", FrmAlert.enmType.Warning);
FrmMain x = new FrmMain();
x.Show();
this.Hide();
}
private void commandTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
MessageBox.Show("This thing dose not work yet so please click on the button to send the cmd to the server console!");
}
}
private void label3_Click(object sender, EventArgs e)
{
OnFormClosing(null);
Environment.Exit(0x0);
Application.Exit();
}
private void lblexit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void lblmin_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void btnlogin_Click(object sender, EventArgs e)
{
FrmProfile x = new FrmProfile();
x.Show();
this.Hide();
}
private void pictureBox4_Click(object sender, EventArgs e)
{
FrmProfile x = new FrmProfile();
x.Show();
this.Hide();
}
private void pictureBox3_Click(object sender, EventArgs e)
{
FrmSettings x = new FrmSettings();
x.Show();
this.Hide();
}
private void pictureBox2_Click(object sender, EventArgs e)
{
var cfg = new ConfigParser(accountinfo);
cfg.SetValue("LOGIN", "remember_me", "false");
cfg.Save();
FrmLogin x = new FrmLogin();
x.Show();
this.Hide();
}
static bool IsWinSCPInstalled()
{
string winscpPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "WinSCP", "WinSCP.exe");
return File.Exists(winscpPath);
}
private void Alert(string msg, FrmAlert.enmType type)
{
FrmAlert frm = new FrmAlert();
frm.showAlert(msg, type);
}
private void guna2Button3_Click(object sender, EventArgs e)
{
bool isWinSCPInstalled = IsWinSCPInstalled();
if (isWinSCPInstalled)
{
string command = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "WinSCP", "WinSCP.exe");
string arguments = @"sftp://" + FrmLogin.username + "." + ServerId + ":" + FrmLogin.panel_pwd + "@" + sftp_ip + ":" + sftp_port + "";
ProcessStartInfo processInfo = new ProcessStartInfo(command, arguments);
processInfo.RedirectStandardOutput = true;
processInfo.UseShellExecute = false;
Process process = Process.Start(processInfo);
}
else
{
Alert("WinSCP is not installed please install it to use this", FrmAlert.enmType.Warning);
}
}
private void btnsend_Click(object sender, EventArgs e)
{
if (commandTextBox.Text == "")
{
MessageBox.Show("What cmd do you want to execute?");
}
try
{
var client = new RestClient(FrmLogin.panel_url);
var request = new RestRequest($"/api/client/servers/{ServerId}/command", Method.Post);
request.AddHeader("Authorization", $"Bearer {FrmLogin.user_api_key}");
request.AddHeader("Accept", "Application/vnd.pterodactyl.v1+json");
request.AddParameter("command", commandTextBox.Text);
var response = client.Execute(request);
if (!response.IsSuccessful)
{
MessageBox.Show($"Failed to send command. Error: {response.Content}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred while sending the command. Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
commandTextBox.Text = string.Empty;
}
private void guna2Button1_Click(object sender, EventArgs e)
{
FrmMain x = new FrmMain();
x.Show();
this.Hide();
}
private void svshutdown_Click(object sender, EventArgs e)
{
try
{
var client = new RestClient(FrmLogin.panel_url);
var request = new RestRequest($"/api/client/servers/{ServerId}/power", Method.Post);
request.AddHeader("Authorization", $"Bearer {FrmLogin.user_api_key}");
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Accept", "Application/vnd.pterodactyl.v1+json");
request.AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36");
request.AddParameter("application/json", "{ \"signal\": \"stop\" }", ParameterType.RequestBody);
var response = client.Execute(request);
if (response.IsSuccessful)
{
MessageBox.Show("Server shutdown request sent successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show($"Failed to send server shutdown request. Error: {response.Content}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine($"{response.Content}");
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred while sending the server shutdown request. Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine($"An error occurred while sending the server shutdown request. Error: {ex.Message}");
}
}
private void svstart_Click(object sender, EventArgs e)
{
try
{
var client = new RestClient(FrmLogin.panel_url);
var request = new RestRequest($"/api/client/servers/{ServerId}/power", Method.Post);
request.AddHeader("Authorization", $"Bearer {FrmLogin.user_api_key}");
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Accept", "Application/vnd.pterodactyl.v1+json");
request.AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36");
request.AddParameter("application/json", "{ \"signal\": \"start\" }", ParameterType.RequestBody);
var response = client.Execute(request);
if (response.IsSuccessful)
{
MessageBox.Show("Server start request sent successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show($"Failed to send server start request. Error: {response.Content}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine($"{response.Content}");
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred while sending the server start request. Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine($"An error occurred while sending the server start request. Error: {ex.Message}");
}
}
private void svrestart_Click(object sender, EventArgs e)
{
try
{
var client = new RestClient(FrmLogin.panel_url);
var request = new RestRequest($"/api/client/servers/{ServerId}/power", Method.Post);
request.AddHeader("Authorization", $"Bearer {FrmLogin.user_api_key}");
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Accept", "Application/vnd.pterodactyl.v1+json");
request.AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36");
request.AddParameter("application/json", "{ \"signal\": \"restart\" }", ParameterType.RequestBody);
var response = client.Execute(request);
if (response.IsSuccessful)
{
MessageBox.Show("Server restart request sent successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show($"Failed to send server restart request. Error: {response.Content}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine($"{response.Content}");
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred while sending the server restart request. Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine($"An error occurred while sending the server restart request. Error: {ex.Message}");
}
}
private void svkill_Click(object sender, EventArgs e)
{
try
{
var client = new RestClient(FrmLogin.panel_url);
var request = new RestRequest($"/api/client/servers/{ServerId}/power", Method.Post);
request.AddHeader("Authorization", $"Bearer {FrmLogin.user_api_key}");
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Accept", "Application/vnd.pterodactyl.v1+json");
request.AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36");
request.AddParameter("application/json", "{ \"signal\": \"kill\" }", ParameterType.RequestBody);
var response = client.Execute(request);
if (response.IsSuccessful)
{
MessageBox.Show("Server kill request sent successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show($"Failed to send server kill request. Error: {response.Content}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine($"{response.Content}");
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred while sending the server kill request. Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine($"An error occurred while sending the server kill request. Error: {ex.Message}");
}
}
private void guna2Button2_Click(object sender, EventArgs e)
{
Pages.SelectedPage = tab1;
btndbs.FillColor = Color.FromArgb(34, 39, 57);
btnconsole.FillColor = Color.FromArgb(27, 28, 46);
}
private void btndbs_Click(object sender, EventArgs e)
{
Pages.SelectedPage = tab2;
btndbs.FillColor = Color.FromArgb(27, 28, 46);
btnconsole.FillColor = Color.FromArgb(34, 39, 57);
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void dataTable_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
}
private void dataTable_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
{
var cellValue = dataTable.Rows[e.RowIndex].Cells[e.ColumnIndex].Value?.ToString();
if (!string.IsNullOrEmpty(cellValue))
{
Clipboard.SetText(cellValue);
}
}
}
}
}