Quite funny, you call yourself objected, though you program in C#.
02-10-12
ObjectOriented
Re: [C#] Remote Administration Control Panel
How is that funny? C# is an object oriented language. I'm honestly kind of fed up with people dissing on C#. It's truly a great language and I could argue all night in it's defense, however it mostly comes down to preferences and the overall goals of the project.
02-10-12
MisterKid
Re: [C#] Remote Administration Control Panel
Quote:
Originally Posted by Langstra
Quite funny, you call yourself objected, though you program in C#.
catch
{
ErrorLog("Unable to compile the configurations and initialize the connection string to return. Please ensure you have all four elements needed.");
throw new Exception("Unable to compile configurations and create connection string.");
}
}
catch
{
Reader.Close();
ErrorLog("Unable to compile the configurations. Please ensure that your configuration file (" + conf_path + "\\conf.xml) is properly formatted.");
throw new Exception("Unable to compile configurations.");
}
}
catch
{
ErrorLog("Unable to read the configurations (" + conf_path + "\\conf.xml)! Ensure that the program has read privilages from the computer and that the file exists and is properly formatted.");
throw new Exception("Unable to read configurations.");
}
}
public string hash(string input)
{
MD5CryptoServiceProvider x = new MD5CryptoServiceProvider();
byte[] bs = Encoding.UTF8.GetBytes(pass_salt + input);
bs = x.ComputeHash(bs);
StringBuilder s = new StringBuilder();
foreach (byte b in bs)
{
s.Append(b.ToString("x2").ToLower());
}
return s.ToString();
}
}
}
Here's the code from the "Information" form. This form was responsible for showing and grouping the data for easy data updating and viewing.
Spoiler:
PHP Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace flyff_acp
{
public partial class Info : Form
{
private ArrayList sql_data;
private ArrayList sql_columns;
private string table_name;
private List<Label> labels = new List<Label>();
private List<TextBox> textboxes = new List<TextBox>();
private int left_constant_lbl = 13;
private int center_constant_lbl = 425;
private int right_constant_lbl = 219;
private int interval = 48;
private int left_constant_txt = 16;
private int center_constant_txt = 428;
private int right_constant_txt = 222;
private string current_side = "left";
private int new_y_lbl = 15;
private int new_y_txt = 31;
private int current_id = -1;
private string update;
private string where;
public Info(string tablename, ArrayList data, ArrayList columns)
{
InitializeComponent();
string query = "UPDATE " + table_name + " SET " + update + " WHERE " + where;
string con_string = Logs.ReadConfigs();
SqlConnection con = new SqlConnection(con_string);
try
{
con.Open();
}
catch
{
Logs.ErrorLog("Unable to create a connection to the SQL server on the Information form.");
throw new Exception("Unable to connect to the SQL server.");
}
SqlCommand cmd = new SqlCommand(query, con);
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Data updated!");
this.Close();
}
catch
{
Logs.ErrorLog("Unable to execute a query on the Information form. Query: " + query);
throw new Exception("Unable to execute query.");
}
}
}
}
04-10-12
ObjectOriented
Re: [C#] Remote Administration Control Panel
I suggest you go a little more advanced with it and use a server/client approach instead of a direct database connection.
04-10-12
ShadowDragon
Re: [C#] Remote Administration Control Panel
Quote:
Originally Posted by ObjectOriented
I suggest you go a little more advanced with it and use a server/client approach instead of a direct database connection.
I agree with this. Unless the database has good indexing setup (unlikely, since tutorials tend to use MSSQL Express) and the website is optimized when it comes to database access (for example, DB Query Caching), you'd just be adding 1 more thing contending for database access.
04-10-12
ObjectOriented
Re: [C#] Remote Administration Control Panel
Quote:
Originally Posted by ShadowDragon
I agree with this. Unless the database has good indexing setup (unlikely, since tutorials tend to use MSSQL Express) and the website is optimized when it comes to database access (for example, DB Query Caching), you'd just be adding 1 more thing contending for database access.
Well like Lethal mentioned in another thread, it really is best to have the database only accessible by the localhost for security reasons. On top of that it can help your database handle the load better if multiple administrators are using it. Not to mention C# is a managed language so unless your willing to pay some serious cash for some good obfuscation or a packer like themida you shouldn't let things like mssql connection strings go inside a program that the public could possibly get a hold of. In the case that the program were to get leaked the person who got a hold of it would still have no authentication.
04-10-12
Mootie
Re: [C#] Remote Administration Control Panel
Here's a link to the information on my remote server monitor.
It's generally for monitoring, but you can add commands to make the server do anything.
04-10-12
Objected
Re: [C#] Remote Administration Control Panel
All suggestions taken into consideration.
Considering that my C# isn't great to the point where I can make applications such as Mootie's, I'm sure my project won't go necessarily as far as monitoring servers and communicating with the server(such as sending packets to World or Certifier), but it can obviously do basics such as communicating with the database.
Do you think it may be more helpful and/or resource-friendly to have a server/client connection with queries running from client to server and the server sending back results?
04-10-12
ShadowDragon
Re: [C#] Remote Administration Control Panel
Quote:
Originally Posted by Objected
Do you think it may be more helpful and/or resource-friendly to have a server/client connection with queries running from client to server and the server sending back results?
Yes, this is what they were saying. This is because on the server program, you can manage the SQL connection in 1 place, allowing you to have better security on it (no outside access to db) and control the queries so that you don't have a lot of simultaneous db access.
05-10-12
ObjectOriented
Re: [C#] Remote Administration Control Panel
Also if you write this in a server/client you can do more than just send queries to be executed by the database.
For example if you set up a packaging system:
Let's say the first byte is going to be your packet header. Your packet header will tell the server or client what needs to be processed. Very recommended to specify constants for the packet headers like this:
Code:
public const byte
//[Client To Server]
DatabaseQueryRequest = 0x01,
CommandQueryRequest = 0x02,
//[Server To Client]
DatabaseQueryResponse = 0x03,
CommandQueryResponse = 0x04;
In your receive method you would read the first byte of the incoming data and throw it in a switch statement:
Code:
//Server Sided Receive
byte PacketHeader = ReceiveBuffer[0];
switch(PacketHeader)
{
case DatabaseQueryRequest: HandleDatabaseQuery(ReceiveBuffer, ClientSocket); break;
case CommandQueryRequest: HandleCommandQuery(ReceiveBuffer, ClientSocket); break;
//For example purposes I passed all of the data received into the method that
//would handle the packaged data. This is not recommended however I did not
//want to give too much information about the BG Data Packaging API away.
}
Your methods could than handle the rest of the data like so:
Code:
//Server Sided Handling Methods
public void HandleDatabaseQuery(byte[] ReceiveBuffer, Socket ClientSocket)
{
//Read the query from the byte array
//Clean the query if you want to
//Execute Query
//Create SendBuffer array to store response data.
//SendBuffer[0] = DatabaseQueryResponse;
//Fill the array with any data you would like to return.
//Send array to client socket.
}
This is where the data packaging api really comes in handy since with a little knowledge of memory and data conversion you can write methods to add or read data to a byte array. Using BG's api the code would look similar too:
Code:
public void HandleDatabaseQuery(ReceivePacket rp, Connection conn)
{
SendPacket sp = new SendPacket();
sp.Addbyte(DatabaseQueryResponse);
//There is a much better way of doing this but it goes past the scope of this
//example.
foreach(Result)
sp.Addstring(Result);
}
catch(Exception e)
{
sp.Addbool(false);
sp.Addstring(e.Message);
}
conn.Send(sp);
}
Package Class Example:
Code:
package PacketSystem;
/**
*
* @author Gage Orsburn
*/
public class Packet
{
private byte[] Data = null;
private int Position = 0;
private boolean BigEndian = true;
/*****************************************/
public Packet()
{
Data = new byte[2048];
}
public Packet(int Size)
{
Data = new byte[Size];
}
public Packet(byte[] b)
{
Data = b;
}
public Packet(Packet p)
{
Data = p.getData();
}
/*****************************************/
public Packet(boolean b)
{
Data = new byte[2048];
BigEndian = b;
}
public Packet(int Size, boolean b)
{
Data = new byte[Size];
BigEndian = b;
}
public Packet(byte[] b, boolean c)
{
Data = b;
BigEndian = c;
}
public Packet(Packet p, boolean b)
{
Data = p.getData();
BigEndian = b;
}
/*****************************************/
public byte[] getData()
{
return Data;
}
/*****************************************/
public void setBigEndian()
{
BigEndian = true;
}
public void setLittleEndian()
{
BigEndian = false;
}
/*****************************************/
public void addByte(byte b)
{
Data[Position] = b;
Position++;
}
public void addBoolean(boolean b)
{
Data[Position] = (byte)(b ? 1 : 0);
Position++;
}
public String readString()
{
String temp = "";
int Length = readInteger();
for(int i = 0; i < Length; i++)
temp += readCharacter();
return temp;
}
public byte[] readBytes()
{
int Length = readInteger();
byte[] temp = new byte[Length];
for(int i = 0; i < Length; i++)
temp[i] = readByte();
return temp;
}
}
05-10-12
Objected
Re: [C#] Remote Administration Control Panel
Alrighty then.
I'm going to currently be working on a new approach to redo the administration panel and have it communicate solely by server and client communications via tcp connection.
Are there any suggestions as to what I could add to this panel (feature wise)?
05-10-12
TheRealFoam
Re: [C#] Remote Administration Control Panel
Its a good idea, and it might be worth the work. BUT I'm crying when I look at the code snippets...
EDIT: Some "feature requests":
- use SSL-Sockets to make the connection a bit saver (you're working with sensitive data)
- You should use a database abstraction layer (linq2sql or Entity Framework) and pass the data from the server to the client ("no direct database connection"), this should prevent exploits and increase performance + its easier to code
- You should go for a nicer GUI (eg. Visual Studio like GUI would be nice (there are tutorials on the net for that))
- - Maybe even go for a web application using https...