diff --git a/.vs/Server Dashboard/DesignTimeBuild/.dtbcache.v2 b/.vs/Server Dashboard/DesignTimeBuild/.dtbcache.v2 index 69f145b..82db2c5 100644 Binary files a/.vs/Server Dashboard/DesignTimeBuild/.dtbcache.v2 and b/.vs/Server Dashboard/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/Server Dashboard/v16/.suo b/.vs/Server Dashboard/v16/.suo index ca68ac6..1a139e2 100644 Binary files a/.vs/Server Dashboard/v16/.suo and b/.vs/Server Dashboard/v16/.suo differ diff --git a/Server Dashboard Socket/bin/Debug/netcoreapp3.1/Server Dashboard Socket.dll b/Server Dashboard Socket/bin/Debug/netcoreapp3.1/Server Dashboard Socket.dll index 6f690f0..73421ca 100644 Binary files a/Server Dashboard Socket/bin/Debug/netcoreapp3.1/Server Dashboard Socket.dll and b/Server Dashboard Socket/bin/Debug/netcoreapp3.1/Server Dashboard Socket.dll differ diff --git a/Server Dashboard Socket/bin/Debug/netcoreapp3.1/Server Dashboard Socket.pdb b/Server Dashboard Socket/bin/Debug/netcoreapp3.1/Server Dashboard Socket.pdb index 2da7be4..5d8e128 100644 Binary files a/Server Dashboard Socket/bin/Debug/netcoreapp3.1/Server Dashboard Socket.pdb and b/Server Dashboard Socket/bin/Debug/netcoreapp3.1/Server Dashboard Socket.pdb differ diff --git a/Server Dashboard Socket/obj/Debug/netcoreapp3.1/Server Dashboard Socket.csprojAssemblyReference.cache b/Server Dashboard Socket/obj/Debug/netcoreapp3.1/Server Dashboard Socket.csprojAssemblyReference.cache index 80a6a34..cb6af33 100644 Binary files a/Server Dashboard Socket/obj/Debug/netcoreapp3.1/Server Dashboard Socket.csprojAssemblyReference.cache and b/Server Dashboard Socket/obj/Debug/netcoreapp3.1/Server Dashboard Socket.csprojAssemblyReference.cache differ diff --git a/Server Dashboard Socket/obj/Debug/netcoreapp3.1/Server Dashboard Socket.dll b/Server Dashboard Socket/obj/Debug/netcoreapp3.1/Server Dashboard Socket.dll index 6f690f0..73421ca 100644 Binary files a/Server Dashboard Socket/obj/Debug/netcoreapp3.1/Server Dashboard Socket.dll and b/Server Dashboard Socket/obj/Debug/netcoreapp3.1/Server Dashboard Socket.dll differ diff --git a/Server Dashboard Socket/obj/Debug/netcoreapp3.1/Server Dashboard Socket.pdb b/Server Dashboard Socket/obj/Debug/netcoreapp3.1/Server Dashboard Socket.pdb index 2da7be4..5d8e128 100644 Binary files a/Server Dashboard Socket/obj/Debug/netcoreapp3.1/Server Dashboard Socket.pdb and b/Server Dashboard Socket/obj/Debug/netcoreapp3.1/Server Dashboard Socket.pdb differ diff --git a/Server Dashboard/Assets/Images/AddIcon.png b/Server Dashboard/Assets/Images/AddIcon.png new file mode 100644 index 0000000..35e870f Binary files /dev/null and b/Server Dashboard/Assets/Images/AddIcon.png differ diff --git a/Server Dashboard/Assets/Images/AddIcon.svg b/Server Dashboard/Assets/Images/AddIcon.svg new file mode 100644 index 0000000..0dfd8c2 --- /dev/null +++ b/Server Dashboard/Assets/Images/AddIcon.svg @@ -0,0 +1,14 @@ + + + + + background + + + + Layer 1 + + + + + \ No newline at end of file diff --git a/Server Dashboard/Assets/Images/CodeMaid_v11.2.231.vsix b/Server Dashboard/Assets/Images/CodeMaid_v11.2.231.vsix new file mode 100644 index 0000000..335b819 Binary files /dev/null and b/Server Dashboard/Assets/Images/CodeMaid_v11.2.231.vsix differ diff --git a/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml b/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml index 1995673..7974b65 100644 --- a/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml +++ b/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml @@ -1,24 +1,24 @@  - + - - - - - - + + + + + + - + \ No newline at end of file diff --git a/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml.cs b/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml.cs index b23d1b9..5023996 100644 --- a/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml.cs +++ b/Server Dashboard/Controls/DoubleRoundProgressBar/DoubleRoundProgressBar.xaml.cs @@ -13,6 +13,7 @@ using System.Windows.Navigation; using System.Windows.Shapes; namespace Server_Dashboard.Controls.DoubleRoundProgressBar { + /// /// DependencyProperties /// @@ -20,6 +21,7 @@ namespace Server_Dashboard.Controls.DoubleRoundProgressBar { //Property for the ReadIndicatorBrush public static DependencyProperty ReadIndicatorBrushProperty = DependencyProperty.Register("ReadIndicatorBrush", typeof(Brush), typeof(DoubleRoundProgressBar)); + public Brush ReadIndicatorBrush { get { return (Brush)GetValue(ReadIndicatorBrushProperty); } set { SetValue(ReadIndicatorBrushProperty, value); } @@ -27,6 +29,7 @@ namespace Server_Dashboard.Controls.DoubleRoundProgressBar { //Property for the WriteIndicatorBrush public static DependencyProperty WriteIndicatorBrushProperty = DependencyProperty.Register("WriteIndicatorBrush", typeof(Brush), typeof(DoubleRoundProgressBar)); + public Brush WriteIndicatorBrush { get { return (Brush)GetValue(WriteIndicatorBrushProperty); } set { SetValue(WriteIndicatorBrushProperty, value); } @@ -34,6 +37,7 @@ namespace Server_Dashboard.Controls.DoubleRoundProgressBar { //Property for the BackgroundBrush public static DependencyProperty BackgroundBrushProperty = DependencyProperty.Register("BackgroundBrush", typeof(Brush), typeof(DoubleRoundProgressBar)); + public Brush BackgroundBrush { get { return (Brush)GetValue(BackgroundBrushProperty); } set { SetValue(BackgroundBrushProperty, value); } @@ -41,6 +45,7 @@ namespace Server_Dashboard.Controls.DoubleRoundProgressBar { //Property for the ProgressBorderBrush public static DependencyProperty ProgressBorderBrushProperty = DependencyProperty.Register("ProgressBorderBrush", typeof(Brush), typeof(DoubleRoundProgressBar)); + public Brush ProgressBorderBrush { get { return (Brush)GetValue(ProgressBorderBrushProperty); } set { SetValue(ProgressBorderBrushProperty, value); } @@ -48,6 +53,7 @@ namespace Server_Dashboard.Controls.DoubleRoundProgressBar { //Property for the Value Write public static DependencyProperty ValueWriteProperty = DependencyProperty.Register("ValueWrite", typeof(int), typeof(DoubleRoundProgressBar)); + public int ValueWrite { get { return (int)GetValue(ValueWriteProperty); } set { SetValue(ValueWriteProperty, value); } @@ -55,6 +61,7 @@ namespace Server_Dashboard.Controls.DoubleRoundProgressBar { //Property for the Value Read public static DependencyProperty ValueReadProperty = DependencyProperty.Register("ValueRead", typeof(int), typeof(DoubleRoundProgressBar)); + public int ValueRead { get { return (int)GetValue(ValueReadProperty); } set { SetValue(ValueReadProperty, value); } @@ -64,4 +71,4 @@ namespace Server_Dashboard.Controls.DoubleRoundProgressBar { InitializeComponent(); } } -} +} \ No newline at end of file diff --git a/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml b/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml index 4ef2d9c..3238cd1 100644 --- a/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml +++ b/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml @@ -1,19 +1,19 @@  - + - - - + + + - + \ No newline at end of file diff --git a/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml.cs b/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml.cs index 7d8bff0..f68b2f7 100644 --- a/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml.cs +++ b/Server Dashboard/Controls/HalfRoundProgressBar/HalfRoundProgressBar.xaml.cs @@ -13,13 +13,15 @@ using System.Windows.Navigation; using System.Windows.Shapes; namespace Server_Dashboard.Controls.HalfRoundProgressBar { + /// /// Dependency Properties /// public partial class HalfRoundProgressBar : UserControl { - + //Indicator Brush Property public static DependencyProperty IndicatorBrushProperty = DependencyProperty.Register("IndicatorBrush", typeof(Brush), typeof(HalfRoundProgressBar)); + public Brush IndicatorBrush { get { return (Brush)GetValue(IndicatorBrushProperty); } set { SetValue(IndicatorBrushProperty, value); } @@ -27,6 +29,7 @@ namespace Server_Dashboard.Controls.HalfRoundProgressBar { //Background Brush Property public static DependencyProperty BackgroundBrushProperty = DependencyProperty.Register("BackgroundBrush", typeof(Brush), typeof(HalfRoundProgressBar)); + public Brush BackgroundBrush { get { return (Brush)GetValue(BackgroundBrushProperty); } set { SetValue(BackgroundBrushProperty, value); } @@ -34,6 +37,7 @@ namespace Server_Dashboard.Controls.HalfRoundProgressBar { //ProgressBorder Property public static DependencyProperty ProgressBorderBrushProperty = DependencyProperty.Register("ProgressBorderBrush", typeof(Brush), typeof(HalfRoundProgressBar)); + public Brush ProgressBorderBrush { get { return (Brush)GetValue(ProgressBorderBrushProperty); } set { SetValue(ProgressBorderBrushProperty, value); } @@ -41,6 +45,7 @@ namespace Server_Dashboard.Controls.HalfRoundProgressBar { //Value public static DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(int), typeof(HalfRoundProgressBar)); + public int Value { get { return (int)GetValue(ValueProperty); } set { SetValue(ValueProperty, value); } @@ -50,4 +55,4 @@ namespace Server_Dashboard.Controls.HalfRoundProgressBar { InitializeComponent(); } } -} +} \ No newline at end of file diff --git a/Server Dashboard/Controls/LoadingIndicator/LoadingIndicator.xaml b/Server Dashboard/Controls/LoadingIndicator/LoadingIndicator.xaml index 9b08883..dd47991 100644 --- a/Server Dashboard/Controls/LoadingIndicator/LoadingIndicator.xaml +++ b/Server Dashboard/Controls/LoadingIndicator/LoadingIndicator.xaml @@ -2,45 +2,45 @@ x:Name="control" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Server_Dashboard.Controls" mc:Ignorable="d"> - + - + - + - - + + - + - + - + \ No newline at end of file diff --git a/Server Dashboard/Controls/LoadingIndicator/LoadingIndicator.xaml.cs b/Server Dashboard/Controls/LoadingIndicator/LoadingIndicator.xaml.cs index d150924..8a5d77b 100644 --- a/Server Dashboard/Controls/LoadingIndicator/LoadingIndicator.xaml.cs +++ b/Server Dashboard/Controls/LoadingIndicator/LoadingIndicator.xaml.cs @@ -12,12 +12,14 @@ using System.Windows.Navigation; using System.Windows.Shapes; namespace Server_Dashboard.Controls { + /// /// Interaction logic for LoadingIndicator.xaml /// public partial class LoadingIndicator : UserControl { + public LoadingIndicator() { InitializeComponent(); } } -} +} \ No newline at end of file diff --git a/Server Dashboard/Controls/ServerModules/ServerModule.xaml b/Server Dashboard/Controls/ServerModules/ServerModule.xaml index aa34d7e..2421fe8 100644 --- a/Server Dashboard/Controls/ServerModules/ServerModule.xaml +++ b/Server Dashboard/Controls/ServerModules/ServerModule.xaml @@ -1,45 +1,45 @@  - + - - + + - + - - - - + + + + - - + + - - + + - + - + @@ -48,86 +48,86 @@ - - + + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -135,37 +135,37 @@ - - + + - - + + - - - - + + + + - - + + - + - - + + - + - - + + - + \ No newline at end of file diff --git a/Server Dashboard/Controls/ServerModules/ServerModule.xaml.cs b/Server Dashboard/Controls/ServerModules/ServerModule.xaml.cs index 702692a..5a8bd76 100644 --- a/Server Dashboard/Controls/ServerModules/ServerModule.xaml.cs +++ b/Server Dashboard/Controls/ServerModules/ServerModule.xaml.cs @@ -12,12 +12,14 @@ using System.Windows.Navigation; using System.Windows.Shapes; namespace Server_Dashboard.Controls.ServerModules { + /// /// Interaktionslogik für ServerModule.xaml /// public partial class ServerModule : UserControl { + public ServerModule() { InitializeComponent(); } } -} +} \ No newline at end of file diff --git a/Server Dashboard/DashboardModules/DashboardModule.cs b/Server Dashboard/DashboardModules/DashboardModule.cs index 16d3259..d046943 100644 --- a/Server Dashboard/DashboardModules/DashboardModule.cs +++ b/Server Dashboard/DashboardModules/DashboardModule.cs @@ -1,26 +1,36 @@ using System; using System.Collections.Generic; using System.Text; +using System.Windows.Media.Imaging; namespace Server_Dashboard { + /// /// Dashboard Module class that holds all the information that gets displayed /// - class DashboardModule { + internal class DashboardModule { + //The name the user gives the module public string ModuleName { get; set; } + //The user who created it public string Creator { get; set; } + //All the information that the server had public ServerInformation ServerInfo { get; set; } + //The status indicator public string StatusIndicator { get; set; } + //The background color of the status indicator public string StatusIndicatorBG { get; set; } + //If the server is avaibale or not public bool ServerAvailable { get; set; } + //The Module icon the user give the server, defaults to a generic server symbol - public string ModuleIcon { get; set; } + public BitmapImage ModuleIcon { get; set; } + //Creation date with System.DateTime.Now public string CreationDate { get; set; } @@ -34,4 +44,4 @@ namespace Server_Dashboard { StatusIndicatorBG = ServerAvailable ? "#94eeb0" : "#ef9a9a"; } } -} +} \ No newline at end of file diff --git a/Server Dashboard/DashboardModules/NewModuleInformation.cs b/Server Dashboard/DashboardModules/NewModuleInformation.cs deleted file mode 100644 index e820a56..0000000 --- a/Server Dashboard/DashboardModules/NewModuleInformation.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Server_Dashboard.DashboardModules { - /// - /// The Information the user puts into the CreateNewModule form - /// - class NewModuleInformation { - //The Name of the Module - public string ModuleName { get; set; } - //The Name of the Server - public string ServerName { get; set; } - //The Username - public string Username { get; set; } - //IPv4 Adress - public string IPAdress { get; set; } - //Port, defaults to 22 - public int Port { get; set; } - } -} diff --git a/Server Dashboard/DashboardModules/ServerInformation.cs b/Server Dashboard/DashboardModules/ServerInformation.cs index 74cebbf..399e567 100644 --- a/Server Dashboard/DashboardModules/ServerInformation.cs +++ b/Server Dashboard/DashboardModules/ServerInformation.cs @@ -4,30 +4,41 @@ using System.Collections.ObjectModel; using System.Text; namespace Server_Dashboard { + /// /// Server information class, this will probably scale pretty big later on /// This will hold all the information the socket will gather /// - class ServerInformation { + internal class ServerInformation { + //The ServerName public string ServerName { get; set; } + //The unix or windows username public string OSUserName { get; set; } + //Cpu Temp in C public string CpuTemp { get; set; } + //Gpu Temp in C public string GpuTemp { get; set; } + //Server uptime public string Uptime { get; set; } + //When the server was first deployed public string DeployDate { get; set; } + //Public IPv4 Adress public string PublicIpAdress { get; set; } + //Private IP adress from the servers network public string PrivateIpAdress { get; set; } + //GPU usage in % public string GpuUsage { get; set; } + //CPU usage in % public string CpuUsage { get; set; } } -} +} \ No newline at end of file diff --git a/Server Dashboard/Database/DatabaseHandler.cs b/Server Dashboard/Database/DatabaseHandler.cs index a0b2e19..bdcc3e5 100644 --- a/Server Dashboard/Database/DatabaseHandler.cs +++ b/Server Dashboard/Database/DatabaseHandler.cs @@ -5,13 +5,17 @@ using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Reflection; +using System.Windows.Media.Imaging; namespace Server_Dashboard { + /// /// Database class to access the database /// public static class DatabaseHandler { + #region Public Methods + /// /// Checks the user credentials /// @@ -20,34 +24,119 @@ namespace Server_Dashboard { /// [0] is false, [1] is true, [2] connection error public static int CheckLogin(string uname, string passwd) { //Creates the database connection - using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString)) { - try { - //Open the connection - con.Open(); - //SQL Query - string query = "EXEC ValidateUserLogin @Username = @uname, @Password = @passwd, @Valid = @valid OUTPUT"; - //Creates a new command - using (SqlCommand com = new SqlCommand(query, con)) { - //For security reasons the values are added with this function - //this will avoid SQL Injections - com.Parameters.AddWithValue("@uname", uname); - com.Parameters.AddWithValue("@passwd", passwd); - com.Parameters.Add("@valid", SqlDbType.NVarChar, 250); - com.Parameters["@valid"].Direction = ParameterDirection.Output; - //Execute without a return value - com.ExecuteNonQuery(); - //The Return value from the SQL Stored Procedure will have the answer to life - return Convert.ToInt32(com.Parameters["@Valid"].Value); - } - //Catch any error - } catch (SqlException ex) { - return ex.Number; - } finally { - //Always close the connection - con.Close(); + using SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString); + try { + //Open the connection + con.Open(); + //SQL Query + string query = "EXEC ValidateUserLogin @Username = @uname, @Password = @passwd, @Valid = @valid OUTPUT"; + //Creates a new command + using SqlCommand com = new SqlCommand(query, con);//For security reasons the values are added with this function + //this will avoid SQL Injections + com.Parameters.AddWithValue("@uname", uname); + com.Parameters.AddWithValue("@passwd", passwd); + com.Parameters.Add("@valid", SqlDbType.NVarChar, 250); + com.Parameters["@valid"].Direction = ParameterDirection.Output; + //Execute query and return number of rows affected + int sqlResponse = com.ExecuteNonQuery(); + //Checks if there are any rows successful + //If the query returns 0 the query wasn't successful + //if its any number above 0 it was successfull + if (Convert.ToInt32(com.Parameters["@Valid"].Value) == 0) { + //Error, not successful + return 1; + } else { + //Successful + return 0; } + //Catch any error + } catch (SqlException ex) { + return ex.Number; + } finally { + //Always close the connection + con.Close(); } } + + public static DataTable GetUserData(string username) { + //Creates the database connection + using SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString); + try { + //Open the connection + con.Open(); + //SQL Query + string query = "SELECT UserID, Username, Email, CreationTime, ModuleName, MI.Image FROM UserData LEFT JOIN ModuleData MD on UserData.ID = MD.UserID LEFT JOIN ModuleIcon MI on MD.ID = MI.Module WHERE Username = @username"; + //Creates a new command + using SqlCommand com = new SqlCommand(query, con);//For security reasons the values are added with this function + //this will avoid SQL Injections + com.Parameters.AddWithValue("@username", username); + //Execute query and return number of rows affected + DataTable resultTable = new DataTable(); + using SqlDataAdapter sda = new SqlDataAdapter(com); + sda.Fill(resultTable); + return resultTable; + //Checks if there are any rows successful + //If the query returns 0 the query wasn't successful + //if its any number above 0 it was successfull + //Catch any error + } catch (SqlException ex) { + return null; + } finally { + //Always close the connection + con.Close(); + } + } + + /// + /// Creates a new Module for the current user + /// + /// Server IP Address + /// Module name, default is Module + /// Server name, default is Server + /// Username of the current user + /// module icon as byte[] + /// port, defalt ist 22 + /// + public static int CreateNewModule(string ipAdress, string moduleName, string serverName, string username, byte[] moduleIcon, string port = "22") { + //Creates the database connection + using SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString); + try { + //Open the connection + con.Open(); + //SQL Query + string query = "EXEC AddNewModuleToUser @UserName = @username, @DateTime = @time, @ModuleName = @moduleName, @ServerName = @serverName, @ModuleIcon = @moduleIcon, @IPAddress = @ipAdress, @Port = @port"; + //Creates a new command + using SqlCommand com = new SqlCommand(query, con); + //For security reasons the values are added with this function + //this will avoid SQL Injections + com.Parameters.AddWithValue("@username", username); + com.Parameters.AddWithValue("@time", DateTime.Now); + com.Parameters.AddWithValue("@moduleName", moduleName); + com.Parameters.AddWithValue("@serverName", serverName); + com.Parameters.Add("@moduleIcon", SqlDbType.VarBinary, int.MaxValue).Value = moduleIcon; + com.Parameters.AddWithValue("@ipAdress", ipAdress); + com.Parameters.AddWithValue("@port", port); + //Execute query and return number of rows affected + int sqlResponse = com.ExecuteNonQuery(); + //Checks if there are any rows successful + //If the query returns 0 the query wasn't successful + //if its any number above 0 it was successfull + if (sqlResponse == 0) { + //Error, not successful + return 1; + } else { + //Successful + return 0; + } + //Catch any error + } catch (SqlException ex) { + return ex.Number; + } finally { + //Always close the connection + con.Close(); + } + } + /// /// Currently obscolete, would check the Username and Cookie /// @@ -56,64 +145,79 @@ namespace Server_Dashboard { /// [0] is false, [1] is true, [2] connection error public static int CheckCookie(string cookie, string username) { //Creates the database connection - using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString)) { - try { - //Open the connection - con.Open(); - //SQL Query - string query = "EXEC CheckUserCookie @Cookie = @cookie, @UserName = @username, @Valid = @valid OUTPUT"; - //Creates a new command - using (SqlCommand com = new SqlCommand(query, con)) { - //For security reasons the values are added with this function - //this will avoid SQL Injections - com.Parameters.AddWithValue("@cookie", cookie); - com.Parameters.AddWithValue("@username", username); - com.Parameters.Add("@valid", SqlDbType.Bit); - com.Parameters["@valid"].Direction = ParameterDirection.Output; - //Execute without a return value - com.ExecuteNonQuery(); - //The Return value from the SQL Stored Procedure will have the answer to life - return Convert.ToInt32(com.Parameters["@Valid"].Value); - } - //Catch any error - } catch (SqlException ex) { - return ex.Number; - } finally { - //Always close the connection - con.Close(); + using SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString); + try { + //Open the connection + con.Open(); + //SQL Query + string query = "EXEC CheckUserCookie @Cookie = @cookie, @UserName = @username, @Valid = @valid OUTPUT"; + //Creates a new command + using SqlCommand com = new SqlCommand(query, con); + //For security reasons the values are added with this function + //this will avoid SQL Injections + com.Parameters.AddWithValue("@cookie", cookie); + com.Parameters.AddWithValue("@username", username); + com.Parameters.Add("@valid", SqlDbType.Bit); + com.Parameters["@valid"].Direction = ParameterDirection.Output; + //Execute query and return number of rows affected + int sqlResponse = com.ExecuteNonQuery(); + //Checks if there are any rows successful + //If the query returns 0 the query wasn't successful + //if its any number above 0 it was successfull + if ((int)com.Parameters["@Valid"].Value == 0) { + //Error, not successful + return 1; + } else { + //Successful + return 0; } + //Catch any error + } catch (SqlException ex) { + return ex.Number; + } finally { + //Always close the connection + con.Close(); } } + /// /// Deletes a the cookie from the given user /// /// User who doesnt deserve any delicious cookies :3 - public static void DeleteCookie(string username) { + public static int DeleteCookie(string username) { //Creates the database connection - using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString)) { - try { - //Open the connection - con.Open(); - //SQL Query - string query = "EXEC DeleteUserCookie @Username = @username, @ResponseMessage = @response OUTPUT"; - //Creates a new command - using (SqlCommand com = new SqlCommand(query, con)) { - //For security reasons the values are added with this function - //this will avoid SQL Injections - com.Parameters.AddWithValue("@username", username); - com.Parameters.Add("@response", SqlDbType.NVarChar, 250); - com.Parameters["@response"].Direction = ParameterDirection.Output; - //Execute without a return value - com.ExecuteNonQuery(); - } - //Catch any error, dont return them, why would you? - } catch { - } finally { - //Always close the connection - con.Close(); + using SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString); + try { + //Open the connection + con.Open(); + //SQL Query + string query = "EXEC DeleteUserCookie @Username = @username"; + //Creates a new command + using SqlCommand com = new SqlCommand(query, con); + //For security reasons the values are added with this function + //this will avoid SQL Injections + com.Parameters.AddWithValue("@username", username); + //Execute query and return number of rows affected + int sqlResponse = com.ExecuteNonQuery(); + //Checks if there are any rows successful + //If the query returns 0 the query wasn't successful + //if its any number above 0 it was successfull + if (sqlResponse == 0) { + //Error, not successful + return 1; + } else { + //Successful + return 0; } + //Catch any error + } catch (SqlException ex) { + return ex.Number; + } finally { + //Always close the connection + con.Close(); } } + /// /// Adds a new Cookie to a user /// @@ -122,34 +226,39 @@ namespace Server_Dashboard { /// [0] is false, [1] is true, [2] connection error public static int AddCookie(string cookie, string username) { //Creates the database connection - using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString)) { - try { - //Open the connection - con.Open(); - //SQL Query - string query = "EXEC AddCookieToUser @Cookie = @cookie, @UserName = @username, @ResponseMessage = @response OUTPUT"; - //Creates a new command - using (SqlCommand com = new SqlCommand(query, con)) { - //For security reasons the values are added with this function - //this will avoid SQL Injections - com.Parameters.AddWithValue("@cookie", cookie); - com.Parameters.AddWithValue("@username", username); - com.Parameters.Add("@response", SqlDbType.NVarChar, 250); - com.Parameters["@response"].Direction = ParameterDirection.Output; - //Execute without a return value - com.ExecuteNonQuery(); - //The Return value from the SQL Stored Procedure will have the answer to life - return Convert.ToInt32(com.Parameters["@ResponseMessage"].Value); - } - //Catch any error - } catch (SqlException ex) { - return ex.Number; - } finally { - //Always close connection - con.Close(); + using SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString); + try { + //Open the connection + con.Open(); + //SQL Query + string query = "EXEC AddCookieToUser @Cookie = @cookie, @UserName = @username"; + //Creates a new command + using SqlCommand com = new SqlCommand(query, con); + //For security reasons the values are added with this function + //this will avoid SQL Injections + com.Parameters.AddWithValue("@cookie", cookie); + com.Parameters.AddWithValue("@username", username); + //Execute query and return number of rows affected + int sqlResponse = com.ExecuteNonQuery(); + //Checks if there are any rows successful + //If the query returns 0 the query wasn't successful + //if its any number above 0 it was successfull + if (sqlResponse == 0) { + //Error, not successful + return 1; + } else { + //Successful + return 0; } + //Catch any error + } catch (SqlException ex) { + return ex.Number; + } finally { + //Always close the connection + con.Close(); } + + #endregion Public Methods } - #endregion } -} +} \ No newline at end of file diff --git a/Server Dashboard/LoginWindow.xaml b/Server Dashboard/LoginWindow.xaml index 6c6aeb0..4799434 100644 --- a/Server Dashboard/LoginWindow.xaml +++ b/Server Dashboard/LoginWindow.xaml @@ -31,11 +31,6 @@ - - - - - @@ -45,8 +40,14 @@ - + @@ -50,6 +53,8 @@ + + @@ -134,8 +139,59 @@ + + + + + + + + @@ -45,20 +43,20 @@ - + - - - - - + + + + + -