Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Fix app start loop
-> Finish add database option
  • Loading branch information
NaysKutzu committed Oct 6, 2023
1 parent 6421a09 commit 2c497d2
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 68 deletions.
40 changes: 38 additions & 2 deletions Forms/Controller/NewDatabase.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
using System;
using RestSharp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace Pterodactyl.Forms.Controller
{
public partial class NewDatabase : Form
{
public NewDatabase()
private string ServerId;
public NewDatabase(string Serverid)
{
InitializeComponent();
this.ServerId = Serverid;
}

private void lblclose_Click(object sender, EventArgs e)
Expand All @@ -31,7 +36,38 @@ private void btnadddb_Click(object sender, EventArgs e)
{
if (txtpanelname.Text == "" && txtconfrom.Text == "")
{
Program.Alert("Please fill in all the required information", FrmAlert.enmType.Warning);
}
else
{
try
{
var client = new RestClient(Pterodactyl.User.Info.panel_url);
var request = new RestRequest($"/api/client/servers/" + ServerId + "/databases", Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", $"Bearer {Pterodactyl.User.Info.panel_api_key}");
string requestBody = $"{{\"database\":\"{txtpanelname.Text}\",\"remote\":\"{txtconfrom.Text}\"}}";

request.AddParameter("application/json", requestBody, ParameterType.RequestBody);

var response = client.Execute(request);

if (response.StatusCode == HttpStatusCode.OK)
{
Program.Alert("Database created successfully!", FrmAlert.enmType.Succes);
this.Close();
}
else
{
Program.Alert("Error while creating your database!", FrmAlert.enmType.Error);
Program.logger.Log(Managers.LogType.Error, "[Forms.Controller.NewDatabase.cs]: " + response.ErrorMessage);
}
}
catch (Exception ex)
{
Program.logger.Log(Managers.LogType.Error, "[Forms.Controller.NewDatabase.cs]: "+ex.Message);
}
}
}
}
Expand Down
91 changes: 46 additions & 45 deletions Forms/FrmServerController.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Forms/FrmServerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,5 +477,10 @@ private void btnnewdb_Click(object sender, EventArgs e)
{

}

private void PageDatabases_Click(object sender, EventArgs e)
{

}
}
}
21 changes: 0 additions & 21 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Pterodactyl.Forms;
using Pterodactyl.Managers;
using System.Diagnostics;
using System.Security.Principal;

namespace Pterodactyl
{
Expand All @@ -24,25 +22,6 @@ _____ _ _____ _ _ _
[STAThread]
public static void Main()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
{
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.Verb = "runas";
processInfo.FileName = Application.ExecutablePath;

try
{
Process.Start(processInfo);
}
catch (Exception)
{
MessageBox.Show("We are sorry, but we require administrator access to use some app functions. Please allow us to start with UAC.", "Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Application.Exit();
return;
}
ApplicationConfiguration.Initialize();
if (!OperatingSystem.IsWindows())
{
Expand Down

0 comments on commit 2c497d2

Please sign in to comment.