private void btnSave_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(tbxSourceINI.Text)) { m_iniFile.SaveSettings(); } }
private void btnAccept_Click(object sender, EventArgs e) { m_settings.Set("[Default]", "DEFAULTNODENAME", tbxDefaultNodeName.Text); m_settings.Set("[Default]", "DEFAULTFILENAME", tbxDefaultFilename.Text); m_settings.Set("[Default]", "OUTPUTFOLDER", tbxOutputFolder.Text); m_settings.SaveSettings(); this.DialogResult = DialogResult.OK; this.Hide(); }
private void btnSaveSettings_Click(object sender, EventArgs e) { try { if (String.IsNullOrEmpty(txtOnionAddress.Text)) { throw new Exception("Onion Address is not provided."); } if (String.IsNullOrEmpty(txtOnionPort.Text)) { throw new Exception("Onion Port is not provided."); } if (String.IsNullOrEmpty(txtUsername.Text)) { throw new Exception("Auth Username is not provided."); } if (String.IsNullOrEmpty(txtPassword.Text)) { throw new Exception("Auth Password is not provided."); } if (String.IsNullOrEmpty(txtTorIPAddress.Text)) { throw new Exception("Tor IP is not provided."); } if (String.IsNullOrEmpty(txtTorPort.Text)) { throw new Exception("Tor Port is not provided."); } Int32 iOnionPort = -1; if (Int32.TryParse(txtOnionPort.Text, out iOnionPort) == false) { throw new Exception("Onion Port is invalid."); } Int32 iTorPort = -1; if (Int32.TryParse(txtTorPort.Text, out iTorPort) == false) { throw new Exception("Tor Port is invalid."); } //Set Config Program.ControllerConfig.OnionAddress = txtOnionAddress.Text; Program.ControllerConfig.OnionPort = iOnionPort; Program.ControllerConfig.AdminUsername = txtUsername.Text; Program.ControllerConfig.AdminPassword = txtPassword.Text; Program.ControllerConfig.Tor_Host = txtTorIPAddress.Text; Program.ControllerConfig.Tor_Port = iTorPort; //Set Values for Settings CSettings.SetValue("OnionAddress", Program.ControllerConfig.OnionAddress); CSettings.SetValue("OnionPort", Program.ControllerConfig.OnionPort); CSettings.SetValue("TorIP", Program.ControllerConfig.Tor_Host); CSettings.SetValue("TorPort", Program.ControllerConfig.Tor_Port); CSettings.SetValue("AdminUsername", Program.ControllerConfig.AdminUsername); CSettings.SetValue("AdminPassword", Program.ControllerConfig.AdminPassword); //Save Settings if (CSettings.SaveSettings()) { MessageBox.Show("Settings saved."); } else { MessageBox.Show("Failed saving Settings. Controller will still work."); } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
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; } } }