|
@@ -1,14 +1,15 @@
|
|
|
package de.tudarmstadt.informatik.hostage.logging;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-
|
|
|
import android.content.ContentValues;
|
|
|
import android.content.Context;
|
|
|
import android.database.Cursor;
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
import android.database.sqlite.SQLiteOpenHelper;
|
|
|
import android.util.Log;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
|
|
|
import de.tudarmstadt.informatik.hostage.ui.LogFilter;
|
|
|
|
|
@@ -102,10 +103,15 @@ public class UglyDbHelper extends SQLiteOpenHelper {
|
|
|
|
|
|
// Creating Tables
|
|
|
@Override
|
|
|
- public void onCreate(SQLiteDatabase db) {
|
|
|
- db.execSQL(CREATE_BSSID_TABLE);
|
|
|
- db.execSQL(CREATE_ATTACK_INFO_TABLE);
|
|
|
- db.execSQL(CREATE_RECORD_TABLE);
|
|
|
+ public void onCreate(SQLiteDatabase db){
|
|
|
+ try{
|
|
|
+ db.execSQL(CREATE_BSSID_TABLE);
|
|
|
+ db.execSQL(CREATE_ATTACK_INFO_TABLE);
|
|
|
+ db.execSQL(CREATE_RECORD_TABLE);
|
|
|
+ }catch (android.database.SQLException e){
|
|
|
+ System.out.println(" " + "Could not create SQL Tables.");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// Upgrading database
|
|
@@ -148,7 +154,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
|
|
|
*/
|
|
|
public ArrayList<Record> getRecordsForFilter(LogFilter filter) {
|
|
|
ArrayList<Record> recordList = new ArrayList<Record>();
|
|
|
- String selectQuery = "SELECT * FROM " + TABLE_RECORDS + " NATURAL JOIN " + TABLE_ATTACK_INFO + " NATURAL JOIN " + TABLE_BSSIDS;
|
|
|
+ String selectQuery = "SELECT * FROM " + TABLE_RECORDS + " NATURAL JOIN " + TABLE_ATTACK_INFO + " NATURAL JOIN " + TABLE_BSSIDS;
|
|
|
|
|
|
// TIMESTAMPS
|
|
|
selectQuery = selectQuery + " WHERE " + KEY_TIME;
|
|
@@ -270,13 +276,22 @@ public class UglyDbHelper extends SQLiteOpenHelper {
|
|
|
recordValues.put(KEY_TIME, record.getTimestamp()); // Log Timestamp
|
|
|
recordValues.put(KEY_PACKET, record.getPacket()); // Log Packet
|
|
|
|
|
|
+
|
|
|
+ long e1=0;
|
|
|
+ long e2=0;
|
|
|
// Inserting Rows
|
|
|
- db.insertWithOnConflict(TABLE_ATTACK_INFO, null, attackValues,
|
|
|
- SQLiteDatabase.CONFLICT_REPLACE);
|
|
|
- db.insert(TABLE_RECORDS, null, recordValues);
|
|
|
- db.close(); // Closing database connection
|
|
|
- // Update Network Information
|
|
|
- updateNetworkInformation(bssidValues);
|
|
|
+ if (db != null) {
|
|
|
+ e1 = db.insertWithOnConflict(TABLE_ATTACK_INFO, null, attackValues,
|
|
|
+ SQLiteDatabase.CONFLICT_REPLACE);
|
|
|
+ e2 = db.insert(TABLE_RECORDS, null, recordValues);
|
|
|
+ db.close(); // Closing database connection
|
|
|
+ }
|
|
|
+ // Update Network Information
|
|
|
+ long e3 = updateNetworkInformation(bssidValues);
|
|
|
+
|
|
|
+ if (e1 ==-1 || e2 == -1 || e3 == -1){
|
|
|
+ System.out.println(""+"Could not insert Record");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -324,7 +339,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
|
|
|
public Record getRecord(int id) {
|
|
|
String selectQuery = "SELECT * FROM " + TABLE_RECORDS
|
|
|
+ " NATURAL JOIN " + TABLE_ATTACK_INFO
|
|
|
- + " NATURAL JOIN "+ TABLE_BSSIDS
|
|
|
+ + " NATURAL JOIN "+ TABLE_BSSIDS
|
|
|
+ " WHERE " + KEY_ID + " = " + id;
|
|
|
SQLiteDatabase db = this.getReadableDatabase();
|
|
|
|
|
@@ -348,11 +363,11 @@ public class UglyDbHelper extends SQLiteOpenHelper {
|
|
|
public ArrayList<Record> getAllRecords() {
|
|
|
ArrayList<Record> recordList = new ArrayList<Record>();
|
|
|
// Select All Query
|
|
|
- String selectQuery = "SELECT * FROM " + TABLE_RECORDS
|
|
|
- + " NATURAL JOIN " + TABLE_ATTACK_INFO
|
|
|
+ String selectQuery = "SELECT * FROM " + TABLE_RECORDS
|
|
|
+ + " NATURAL JOIN " + TABLE_ATTACK_INFO
|
|
|
+ " NATURAL JOIN " + TABLE_BSSIDS;
|
|
|
|
|
|
- SQLiteDatabase db = this.getWritableDatabase();
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
Cursor cursor = db.rawQuery(selectQuery, null);
|
|
|
|
|
|
Log.i("Database", "Start loop");
|
|
@@ -381,7 +396,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
|
|
|
public Record getRecordOfAttackId(long attack_id) {
|
|
|
String selectQuery = "SELECT * FROM " + TABLE_RECORDS
|
|
|
+ " NATURAL JOIN " + TABLE_ATTACK_INFO
|
|
|
- + " NATURAL JOIN " + TABLE_BSSIDS
|
|
|
+ + " NATURAL JOIN " + TABLE_BSSIDS
|
|
|
+ " WHERE " + KEY_ATTACK_ID + " = " + attack_id
|
|
|
+ " GROUP BY " + KEY_ATTACK_ID;
|
|
|
SQLiteDatabase db = this.getReadableDatabase();
|
|
@@ -756,7 +771,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
|
|
|
return networkInformation;
|
|
|
}
|
|
|
|
|
|
- public void updateNetworkInformation(
|
|
|
+ public long updateNetworkInformation(
|
|
|
HashMap<String, Object> networkInformation) {
|
|
|
SQLiteDatabase db = this.getReadableDatabase();
|
|
|
String bssid = (String) networkInformation.get(KEY_BSSID);
|
|
@@ -764,6 +779,9 @@ public class UglyDbHelper extends SQLiteOpenHelper {
|
|
|
+ KEY_BSSID + " = " + "'" + bssid + "'";
|
|
|
Cursor cursor = db.rawQuery(bssidQuery, null);
|
|
|
int result = cursor.getCount();
|
|
|
+
|
|
|
+ long errorCode = 0;
|
|
|
+
|
|
|
if (cursor != null
|
|
|
&& cursor.moveToFirst()
|
|
|
&& (result <= 0 || cursor.getLong(5) < (Long) networkInformation
|
|
@@ -781,11 +799,13 @@ public class UglyDbHelper extends SQLiteOpenHelper {
|
|
|
bssidValues.put(KEY_ACCURACY,
|
|
|
(float) (Float) networkInformation.get(KEY_ACCURACY));
|
|
|
bssidValues.put(KEY_TIME, (Long) networkInformation.get(KEY_TIME));
|
|
|
- db.insertWithOnConflict(TABLE_BSSIDS, null, bssidValues,
|
|
|
+ errorCode = db.insertWithOnConflict(TABLE_BSSIDS, null, bssidValues,
|
|
|
SQLiteDatabase.CONFLICT_REPLACE);
|
|
|
}
|
|
|
cursor.close();
|
|
|
db.close();
|
|
|
+
|
|
|
+ return errorCode;
|
|
|
}
|
|
|
|
|
|
public void updateNetworkInformation(
|