Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Done #42
  • Loading branch information
NaysKutzu committed Aug 22, 2023
1 parent 609bd20 commit e14b9c0
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 102 deletions.
9 changes: 7 additions & 2 deletions cli/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;


using YamlDotNet.Serialization;

namespace MythicalDash
{
Expand All @@ -27,6 +26,7 @@ __ __ _ _ _ _ _____ _
public static IConsole iconsole = new IConsole();
public static Database db = new Database();
public static Migrate mg = new Migrate();
public static SettingsHandler sh = new SettingsHandler();
public static void Main(string[] args)
{
Console.Clear();
Expand Down Expand Up @@ -206,6 +206,10 @@ public static void Main(string[] args)
mg.Now();
Environment.Exit(0x0);
}
else if (args.Contains("-config-setup")) {
sh.Setup();
Environment.Exit(0x0);
}
else if (args.Contains("-help")) {
Console.Clear();
Console.WriteLine("--------------------------------------------MythicalDash CLI-------------------------------------------------");
Expand All @@ -222,6 +226,7 @@ public static void Main(string[] args)
Console.WriteLine("| -disable-silent-debug | Shows the debug mode online status messages from being enabled. |");
Console.WriteLine("| -config-database | Add the database connection to your config file. |");
Console.WriteLine("| -migrate-database-now | Create and setup all tables in the database |");
Console.WriteLine("| -config-setup | This is a command to help you setup your dashboard! |");
Console.WriteLine("| -version | See the version / build version of the CLI. |");
Console.WriteLine("| |");
Console.WriteLine("-------------------------------------------------------------------------------------------------------------");
Expand Down
50 changes: 33 additions & 17 deletions cli/scripts/Migrate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,44 @@

namespace MythicalDash
{
public class Migrate {
public class Migrate
{
FileManager fm = new FileManager();
#pragma warning disable
#pragma warning disable
public static string connectionString;
#pragma warning restore
public void Now() {
#pragma warning restore
public void Now()
{
if (fm.MFolderExists() == true)
{
ExecuteScripts();
} else {
}
else
{
Program.logger.Log(LogType.Error, "It looks like you are missing some important core files; please redownload MythicalDash!!");
}
}
private void getConnection() {
if (fm.ConfigExists() == true) {
string filePath = "config.yml";
private void getConnection()
{
if (fm.ConfigExists() == true)
{
string filePath = "config.yml";
string yamlContent = File.ReadAllText(filePath);

var deserializer = new DeserializerBuilder().Build();
var yamlObject = deserializer.Deserialize(new StringReader(yamlContent));
#pragma warning disable
#pragma warning disable
var databaseSettings = (yamlObject as dynamic)["database"];
#pragma warning restore
#pragma warning restore
string dbHost = databaseSettings["host"];
string dbPort = databaseSettings["port"];
string dbUsername = databaseSettings["username"];
string dbPassword = databaseSettings["password"];
string dbName = databaseSettings["database"];
connectionString = $"Server={dbHost};Port={dbPort};User ID={dbUsername};Password={dbPassword};Database={dbName}";
} else {
}
else
{
Program.logger.Log(LogType.Error, "It looks like the config file does not exist!");
}
}
Expand All @@ -45,9 +53,12 @@ private void ExecuteScript(MySqlConnection connection, string scriptContent)
}
private void ExecuteScripts()
{
try {
try
{
getConnection();
string[] scriptFiles = Directory.GetFiles("migrate/", "*.sql");
string[] scriptFiles = Directory.GetFiles("migrate/", "*.sql")
.OrderBy(scriptFile => Convert.ToInt32(Path.GetFileNameWithoutExtension(scriptFile)))
.ToArray();

using (var connection = new MySqlConnection(connectionString))
{
Expand All @@ -56,13 +67,18 @@ private void ExecuteScripts()
foreach (string scriptFile in scriptFiles)
{
string scriptContent = File.ReadAllText(scriptFile);
Program.logger.Log(LogType.Info, "We executed: "+scriptFile);
Program.logger.Log(LogType.Info, "We executed: " + scriptFile);
ExecuteScript(connection, scriptContent);
}

connection.Close();
}
} catch (Exception ex) {
Program.logger.Log(LogType.Error,"Sorry but the migration trows this error: "+ex.Message);
}

}
catch (Exception ex)
{
Program.logger.Log(LogType.Error, "Sorry but the migration throws this error: " + ex.Message);
}
}
}
}
113 changes: 113 additions & 0 deletions cli/scripts/SettingsHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using MySqlConnector;
using YamlDotNet.Serialization;

namespace MythicalDash
{
public class SettingsHandler
{
FileManager fm = new FileManager();
#pragma warning disable
public static string connectionString;

public void Setup() {
if (fm.ConfigExists() == true) {
Program.logger.Log(LogType.Info,"Hi, and welcome to the automated installer for MythicalDash.");
Program.logger.Log(LogType.Info,"This installer will help you set up your dashboard with no problem and is easy to follow. \n");
Console.Write("Name [");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write($"MythicalSystems");
Console.ResetColor();
Console.Write("]: ");

string name = Console.ReadLine();
if (string.IsNullOrWhiteSpace(name))
{
name = "MythicalSystems";
}

Console.Write("Logo [");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write($"https://avatars.githubusercontent.com/u/117385445");
Console.ResetColor();
Console.Write("]: ");

string logo = Console.ReadLine();
if (string.IsNullOrWhiteSpace(logo))
{
logo = "https://avatars.githubusercontent.com/u/117385445";
}

Console.Write("Pterodactyl URL [");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write($"https://panel.yourhost.net");
Console.ResetColor();
Console.Write("]: ");

string panelurl = Console.ReadLine();
if (string.IsNullOrWhiteSpace(panelurl))
{
panelurl = "https://panel.yourhost.net";
}

Console.Write("Pterodactyl API [");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write($"ptla_000000000000000000000000000000000000000000");
Console.ResetColor();
Console.Write("]: ");

string panelkey = Console.ReadLine();
if (string.IsNullOrWhiteSpace(panelkey))
{
panelkey = "ptla_000000000000000000000000000000000000000000";
}
try {
getConnection();
using (var connection = new MySqlConnection(connectionString))
{
connection.Open();
ExecuteSQLScript(connection, "INSERT INTO `mythicaldash_settings` (`name`, `logo`, `PterodactylURL`, `PterodactylAPIKey`) VALUES ('"+name+"', '"+logo+"', '"+panelkey+"','"+panelkey+"');");
connection.Close();
}
} catch (Exception ex) {
Program.logger.Log(LogType.Error , "Sorry but the auto settings throws this error: "+ex.Message);
}

} else {
Program.logger.Log(LogType.Error, "It looks like the config file does not exist!");
}
}

private void ExecuteSQLScript(MySqlConnection connection, string scriptContent)
{
using (var command = new MySqlCommand(scriptContent, connection))
{
command.ExecuteNonQuery();
}
}
private void getConnection()
{
if (fm.ConfigExists() == true)
{
string filePath = "config.yml";
string yamlContent = File.ReadAllText(filePath);

var deserializer = new DeserializerBuilder().Build();
var yamlObject = deserializer.Deserialize(new StringReader(yamlContent));
#pragma warning disable
var databaseSettings = (yamlObject as dynamic)["database"];
#pragma warning restore
string dbHost = databaseSettings["host"];
string dbPort = databaseSettings["port"];
string dbUsername = databaseSettings["username"];
string dbPassword = databaseSettings["password"];
string dbName = databaseSettings["database"];
connectionString = $"Server={dbHost};Port={dbPort};User ID={dbUsername};Password={dbPassword};Database={dbName}";
}
else
{
Program.logger.Log(LogType.Error, "It looks like the config file does not exist!");
}
}
#pragma warning restore
}
}
84 changes: 1 addition & 83 deletions migrate/1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -184,86 +184,4 @@ CREATE TABLE `mythicaldash_users` (
`discord_global_username` text DEFAULT NULL,
`discord_email` text DEFAULT NULL,
`registred` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;


ALTER TABLE `mythicaldash_apikeys`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_eggs`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_locations`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_login_logs`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_logs`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_redeem`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_resetpasswords`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_servers`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_servers_queue`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_settings`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_tickets`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_tickets_messages`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_users`
ADD PRIMARY KEY (`id`);


ALTER TABLE `mythicaldash_apikeys`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `mythicaldash_eggs`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `mythicaldash_locations`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `mythicaldash_login_logs`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `mythicaldash_logs`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `mythicaldash_redeem`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `mythicaldash_resetpasswords`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `mythicaldash_servers`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `mythicaldash_servers_queue`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `mythicaldash_settings`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `mythicaldash_tickets`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `mythicaldash_tickets_messages`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `mythicaldash_users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
38 changes: 38 additions & 0 deletions migrate/2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
ALTER TABLE `mythicaldash_apikeys`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_eggs`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_locations`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_login_logs`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_logs`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_redeem`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_resetpasswords`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_servers`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_servers_queue`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_settings`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_tickets`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_tickets_messages`
ADD PRIMARY KEY (`id`);

ALTER TABLE `mythicaldash_users`
ADD PRIMARY KEY (`id`);
Loading

0 comments on commit e14b9c0

Please sign in to comment.