Esempio n. 1
0
        public SQLRecord ReturnQuery(string query)
        {
            Dictionary <int, Dictionary <string, string> > retStruct = new Dictionary <int, Dictionary <string, string> >();

            if (_connected)
            {
                SQLiteCommand cmd = new SQLiteCommand(query, connection);
                DataTable     dt  = new DataTable();
                dt.Load(cmd.ExecuteReader());


                for (int row = 0; row < dt.Rows.Count; row++)
                {
                    for (int column = 0; column < dt.Columns.Count; column++)
                    {
                        if (!retStruct.ContainsKey(row))
                        {
                            retStruct.Add(row, new Dictionary <string, string>());
                        }

                        retStruct[row].Add(dt.Columns[column].ToString(), dt.Rows[row][column].ToString());
                    }
                }
            }

            SQLRecord ret = new SQLRecord(retStruct);

            return(ret);
        }
Esempio n. 2
0
        private void Start_Routine()
        {
            main = this;
            LogAction(LOG_STATE.INFO, "Initializing database");
            if (!sql.IsConnected())
            {
                LogAction(LOG_STATE.ERROR, "Couldnt create .sqlite-Database! Application could not start.");
            }
            else
            {
                sql.ReturnQuery("CREATE TABLE IF NOT EXISTS settings (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), val VARCHAR(50));");
                sql.ReturnQuery("CREATE TABLE IF NOT EXISTS logs (id INTEGER PRIMARY KEY AUTOINCREMENT, ip VARCHAR(39), requesttime BIGINT(10));");
                sql.ReturnQuery("CREATE TABLE IF NOT EXISTS bans (id INTEGER PRIMARY KEY AUTOINCREMENT, ip VARCHAR(39));");

                LogAction(LOG_STATE.INFO, "Loaded .sqlite-Database!");

                SQLRecord record = sql.ReturnQuery("SELECT * FROM settings");
                for (int row = 0; row < record.NumRows(); row++)
                {
                    string val = record.GetValue(row, "val");

                    switch (record.GetValue(row, "name"))
                    {
                    case "autoban_enabled":
                        metroToggle1.Checked = (val == "1") ? true : false;
                        break;

                    case "apicheck":
                        metroCheckBox1.Checked = (val == "1") ? true : false;
                        break;

                    case "apikey":
                        metroTextBox_APIKEY.Text = val;
                        break;

                    case "banattempts":
                        numericUpDown_BanAttempts.Value = decimal.Parse(val);
                        oldBanAttempts = decimal.Parse(val);
                        break;

                    case "attemptminutes":
                        numericUpDown_AttemptObserve.Value = decimal.Parse(val);
                        oldAttemptMinutes = decimal.Parse(val);
                        break;

                    case "banduration":
                        numericUpDown_BanDuration.Value = decimal.Parse(val);
                        oldBanDuration = decimal.Parse(val);
                        break;
                    }
                }

                eventInstance = new Events();
            }
        }
Esempio n. 3
0
 private static bool AlreadyReported(string ip)
 {
     try
     {
         SQLRecord record = Form1.sql.ReturnQuery("SELECT * FROM bans WHERE ip = '" + ip + "' LIMIT 1");
         return(record.NumRows() == 1);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 4
0
        public SQLRecord Select(string table, bool where = false, Dictionary <string, string> conditions = null)
        {
            string query = "SELECT * FROM " + table;
            Dictionary <int, Dictionary <string, string> > retStruct = new Dictionary <int, Dictionary <string, string> >();

            if (where)
            {
                query += " WHERE ";
                for (int i = 0; i < conditions.Count; i++)
                {
                    string column = conditions.Keys.ElementAt(i);
                    query += column + "='" + conditions[column] + "'";

                    if (i != conditions.Count - 1)
                    {
                        query += " AND ";
                    }
                }
            }

            if (_connected)
            {
                SQLiteCommand cmd = new SQLiteCommand(query, connection);
                DataTable     dt  = new DataTable();
                dt.Load(cmd.ExecuteReader());


                for (int row = 0; row < dt.Rows.Count; row++)
                {
                    for (int column = 0; column < dt.Columns.Count; column++)
                    {
                        if (!retStruct.ContainsKey(row))
                        {
                            retStruct.Add(row, new Dictionary <string, string>());
                        }

                        retStruct[row].Add(dt.Columns[column].ToString(), dt.Rows[row][column].ToString());
                    }
                }
            }

            SQLRecord ret = new SQLRecord(retStruct);

            return(ret);
        }
Esempio n. 5
0
        private static string GET_AbuseIPDB_KEY()
        {
            try
            {
                string apiKey = "";

                SQLRecord record = Form1.sql.ReturnQuery("SELECT * FROM settings WHERE name = 'apikey' LIMIT 1");
                if (record.NumRows() == 1)
                {
                    apiKey = record.GetValue(0, "val");
                }

                return(apiKey);
            }
            catch
            {
                Form1.main.LogAction(Form1.LOG_STATE.ERROR, "Could not retrieve APIKEY from database");
                return("");
            }
        }