Browse Source

small bugfixes

Mihai Plasoianu 10 years ago
parent
commit
b7d729af19

+ 11 - 6
src/de/tudarmstadt/informatik/hostage/Hostage.java

@@ -41,7 +41,7 @@ import de.tudarmstadt.informatik.hostage.location.MyLocationManager;
 import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
 import de.tudarmstadt.informatik.hostage.protocol.HTTP;
 import de.tudarmstadt.informatik.hostage.protocol.Protocol;
-import de.tudarmstadt.informatik.hostage.ui.MainActivity;
+import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 
 /**
  * Background service running as long as at least one protocol is active.
@@ -344,7 +344,8 @@ public class Hostage extends Service {
 			if (listener.getProtocolName().equals(protocolName) && listener.getPort() == port) {
 				if (!listener.isRunning()) {
 					if (listener.start()) {
-						Toast.makeText(getApplicationContext(), protocolName + " SERVICE STARTED!", Toast.LENGTH_SHORT).show();
+						// Toast.makeText(getApplicationContext(), protocolName
+						// + " SERVICE STARTED!", Toast.LENGTH_SHORT).show();
 						return true;
 					}
 					Toast.makeText(getApplicationContext(), protocolName + " SERVICE COULD NOT BE STARTED!", Toast.LENGTH_SHORT).show();
@@ -356,7 +357,8 @@ public class Hostage extends Service {
 		Listener listener = createListener(protocolName, port);
 		if (listener != null) {
 			if (listener.start()) {
-				Toast.makeText(getApplicationContext(), protocolName + " SERVICE STARTED!", Toast.LENGTH_SHORT).show();
+				// Toast.makeText(getApplicationContext(), protocolName +
+				// " SERVICE STARTED!", Toast.LENGTH_SHORT).show();
 				return true;
 			}
 		}
@@ -373,7 +375,8 @@ public class Hostage extends Service {
 				listener.start();
 			}
 		}
-		Toast.makeText(getApplicationContext(), "SERVICES STARTED!", Toast.LENGTH_SHORT).show();
+		// Toast.makeText(getApplicationContext(), "SERVICES STARTED!",
+		// Toast.LENGTH_SHORT).show();
 	}
 
 	/**
@@ -402,7 +405,8 @@ public class Hostage extends Service {
 				}
 			}
 		}
-		Toast.makeText(getApplicationContext(), protocolName + " SERVICE STOPPED!", Toast.LENGTH_SHORT).show();
+		// Toast.makeText(getApplicationContext(), protocolName +
+		// " SERVICE STOPPED!", Toast.LENGTH_SHORT).show();
 	}
 
 	/**
@@ -414,7 +418,8 @@ public class Hostage extends Service {
 				listener.stop();
 			}
 		}
-		Toast.makeText(getApplicationContext(), "SERVICES STOPPED!", Toast.LENGTH_SHORT).show();
+		// Toast.makeText(getApplicationContext(), "SERVICES STOPPED!",
+		// Toast.LENGTH_SHORT).show();
 	}
 
 	/**

+ 20 - 22
src/de/tudarmstadt/informatik/hostage/deprecated/UglyDbHelper.java

@@ -33,36 +33,35 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 
 	// All Static variables
 	// Database Version
-	private static final int DATABASE_VERSION = 9;
+	private static final int DATABASE_VERSION = 1;
 
 	// Database Name
-	private static final String DATABASE_NAME = "recordManager";
+	private static final String DATABASE_NAME = "hostage.db";
 
 	// Contacts table names
-	private static final String TABLE_ATTACK_INFO = "attack_info";
-	private static final String TABLE_RECORDS = "records";
-	private static final String TABLE_BSSIDS = "bssids";
+	private static final String TABLE_ATTACK_INFO = "attack";
+	private static final String TABLE_RECORDS = "packet";
+	private static final String TABLE_BSSIDS = "network";
 	private static final String TABLE_PROFILES = "profiles";
 
 	// Contacts Table Columns names
 	public static final String KEY_ID = "_id";
 	public static final String KEY_ATTACK_ID = "_attack_id";
 	public static final String KEY_TYPE = "type";
-	public static final String KEY_TIME = "timestamp";
+	public static final String KEY_TIME = "packet_timestamp";
 	public static final String KEY_PACKET = "packet";
 	public static final String KEY_PROTOCOL = "protocol";
 	public static final String KEY_EXTERNAL_IP = "externalIP";
 	public static final String KEY_LOCAL_IP = "localIP";
-	public static final String KEY_LOCAL_HOSTNAME = "localHostName";
 	public static final String KEY_LOCAL_PORT = "localPort";
 	public static final String KEY_REMOTE_IP = "remoteIP";
-	public static final String KEY_REMOTE_HOSTNAME = "remoteHostName";
 	public static final String KEY_REMOTE_PORT = "remotePort";
 	public static final String KEY_BSSID = "_bssid";
 	public static final String KEY_SSID = "ssid";
 	public static final String KEY_LATITUDE = "latitude";
 	public static final String KEY_LONGITUDE = "longitude";
 	public static final String KEY_ACCURACY = "accuracy";
+	public static final String KEY_GEO_TIMESTAMP = "geo_timestamp";
 
 	public static final String KEY_PROFILE_ID = "_profile_id";
 	public static final String KEY_PROFILE_NAME = "profile_name";
@@ -82,12 +81,11 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 			+ TABLE_ATTACK_INFO + "(" + KEY_ATTACK_ID + ")," + "PRIMARY KEY(" + KEY_ID + ", " + KEY_ATTACK_ID + ")" + ")";
 
 	private static final String CREATE_ATTACK_INFO_TABLE = "CREATE TABLE " + TABLE_ATTACK_INFO + "(" + KEY_ATTACK_ID + " INTEGER PRIMARY KEY," + KEY_PROTOCOL
-			+ " TEXT," + KEY_EXTERNAL_IP + " TEXT," + KEY_LOCAL_IP + " BLOB," + KEY_LOCAL_HOSTNAME + " TEXT," + KEY_LOCAL_PORT + " INTEGER," + KEY_REMOTE_IP
-			+ " BLOB," + KEY_REMOTE_HOSTNAME + " TEXT," + KEY_REMOTE_PORT + " INTEGER," + KEY_BSSID + " TEXT," + "FOREIGN KEY(" + KEY_BSSID + ") REFERENCES "
-			+ TABLE_BSSIDS + "(" + KEY_BSSID + ")" + ")";
+			+ " TEXT," + KEY_EXTERNAL_IP + " TEXT," + KEY_LOCAL_IP + " BLOB," + KEY_LOCAL_PORT + " INTEGER," + KEY_REMOTE_IP + " BLOB," + KEY_REMOTE_PORT
+			+ " INTEGER," + KEY_BSSID + " TEXT," + "FOREIGN KEY(" + KEY_BSSID + ") REFERENCES " + TABLE_BSSIDS + "(" + KEY_BSSID + ")" + ")";
 
 	private static final String CREATE_BSSID_TABLE = "CREATE TABLE " + TABLE_BSSIDS + "(" + KEY_BSSID + " TEXT PRIMARY KEY," + KEY_SSID + " TEXT,"
-			+ KEY_LATITUDE + " INTEGER," + KEY_LONGITUDE + " INTEGER," + KEY_ACCURACY + " INTEGER," + KEY_TIME + " INTEGER" + ")";
+			+ KEY_LATITUDE + " INTEGER," + KEY_LONGITUDE + " INTEGER," + KEY_ACCURACY + " INTEGER," + KEY_GEO_TIMESTAMP + " INTEGER" + ")";
 
 	public UglyDbHelper(Context context) {
 		super(context, DATABASE_NAME, null, DATABASE_VERSION);
@@ -144,7 +142,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 
 		selectQuery = selectQuery + " GROUP BY " + TABLE_RECORDS + "." + KEY_ATTACK_ID;
 
-		if (filter.getSorttype() == LogFilter.SortType.timestamp) {
+		if (filter.getSorttype() == LogFilter.SortType.packet_timestamp) {
 			// DESC
 			selectQuery = selectQuery + " ORDER BY " + filter.getSorttype() + " DESC";
 		} else {
@@ -955,17 +953,17 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 		record.setExternalIP(cursor.getString(6));
 
 		record.setLocalIP(cursor.getString(7));
-		record.setLocalPort(Integer.parseInt(cursor.getString(9)));
+		record.setLocalPort(Integer.parseInt(cursor.getString(8)));
 
-		record.setRemoteIP(cursor.getString(10));
-		record.setRemotePort(Integer.parseInt(cursor.getString(12)));
+		record.setRemoteIP(cursor.getString(9));
+		record.setRemotePort(Integer.parseInt(cursor.getString(10)));
 
-		record.setBssid(cursor.getString(13));
-		record.setSsid(cursor.getString(14));
-		record.setLatitude(Double.parseDouble(cursor.getString(15)));
-		record.setLongitude(Double.parseDouble(cursor.getString(16)));
-		record.setAccuracy(Float.parseFloat(cursor.getString(17)));
-		record.setTimestampLocation(cursor.getLong(18));
+		record.setBssid(cursor.getString(11));
+		record.setSsid(cursor.getString(12));
+		record.setLatitude(Double.parseDouble(cursor.getString(13)));
+		record.setLongitude(Double.parseDouble(cursor.getString(14)));
+		record.setAccuracy(Float.parseFloat(cursor.getString(15)));
+		record.setTimestampLocation(cursor.getLong(16));
 
 		return record;
 	}

+ 177 - 159
src/de/tudarmstadt/informatik/hostage/ui/LogFilter.java

@@ -1,16 +1,15 @@
 package de.tudarmstadt.informatik.hostage.ui;
 
-import android.os.Parcel;
-import android.os.Parcelable;
-
 import java.util.ArrayList;
 import java.util.HashMap;
 
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class LogFilter implements Parcelable {
 
-public class LogFilter implements Parcelable{
-	
 	public final static String LOG_FILTER_INTENT_KEY = "de.tudarmstadt.informatik.hostage.logfilter";
-	
+
 	private static final String TIMESTAMP_BELOW_KEY = "de.tudarmstadt.informatik.hostage.logfilter.timestampbelow";
 	private static final String TIMESTAMP_ABOVE_KEY = "de.tudarmstadt.informatik.hostage.logfilter.timestampabove";
 	private static final String PROTOCOLS_KEY = "de.tudarmstadt.informatik.hostage.logfilter.protocols";
@@ -18,210 +17,229 @@ public class LogFilter implements Parcelable{
 	private static final String BSSID_KEY = "de.tudarmstadt.informatik.hostage.logfilter.bssid";
 	private static final String SORTTYPE_KEY = "de.tudarmstadt.informatik.hostage.logfilter.sorttype";
 
-	public enum SortType{
-				timestamp(0),
-				protocol(1),
-				_bssid(1),
-				ssid(3),
-				//remoteHostName(5),
-				//lcaolHostName(6),
-				_attack_id(7),
-				_id(8);
-		        private final int id;
-		        SortType(int id) {
-		        	this.id = id;
-		        }
-		        public int getValue() { 
-		        	return id; 
-		        }
-		    }
-	
+	public enum SortType {
+		packet_timestamp(0), protocol(1), _bssid(1), ssid(3), _attack_id(7), _id(8);
+		private final int id;
+
+		SortType(int id) {
+			this.id = id;
+		}
+
+		public int getValue() {
+			return id;
+		}
+	}
+
 	public ArrayList<String> BSSIDs;
 	public ArrayList<String> ESSIDs;
 	public ArrayList<String> protocols;
-	
+
 	public boolean isNotEditable;
-	
+
 	public SortType sorttype;
 
 	public long belowTimestamp;
 	public long aboveTimestamp;
-	
-	
-	public LogFilter(){
+
+	public LogFilter() {
 		this.clear();
 
 	}
 
-    public void clear(){
-        this.belowTimestamp = Long.MAX_VALUE;
-        this.aboveTimestamp = Long.MIN_VALUE;
-        this.sorttype = SortType.timestamp;
-        this.BSSIDs = new ArrayList<String>();
-        this.ESSIDs = new ArrayList<String>();
-        this.protocols = new ArrayList<String>();
-    }
-
-	    public int describeContents() {
-	        return 0;
-	    }
-
-	    // write your object's data to the passed-in Parcel
-	    public void writeToParcel(Parcel out, int flags) {
-	        HashMap<String, ArrayList<String>> values =new HashMap<String,  ArrayList<String>>();
-	        if(this.BSSIDs != null && this.BSSIDs.size() > 0){
-	        	values.put(BSSID_KEY , this.getBSSIDs() );
-	        }
-	        if(this.ESSIDs != null && this.ESSIDs.size() > 0){
-	        	values.put(ESSID_KEY , this.getESSIDs() );
-	        }
-	        if(this.protocols != null && this.protocols.size() > 0){
-	        	values.put(PROTOCOLS_KEY , this.getProtocols() );
-	        }
-	        long timeArray[] = new long[] {this.aboveTimestamp, this.belowTimestamp};
-
-	        out.writeMap(values);
-	        out.writeInt(this.sorttype.getValue());
-	        out.writeDouble(timeArray.length);
-	        out.writeLongArray(timeArray);
-	        out.writeString(this.isNotEditable? "true" : "false");
-	    }
-
-	    
-	    public static final Parcelable.Creator<LogFilter> CREATOR = new Parcelable.Creator<LogFilter>() {
-	        public LogFilter createFromParcel(Parcel in) {
-	            return new LogFilter(in);
-	        }
-
-	        public LogFilter[] newArray(int size) {
-	            return new LogFilter[size];
-	        }
-	    };
-
-	    // example constructor that takes a Parcel and gives you an object populated with it's values
-	    private LogFilter(Parcel in) {
-	        //mData = in.readInt();
-	    	HashMap<String, ArrayList<String>> values = new HashMap<String, ArrayList<String>>();
-	    	in.readMap(values, ArrayList.class.getClassLoader());
-	    	
-	    	this.BSSIDs = values.get(BSSID_KEY);
-	    	this.ESSIDs = values.get(ESSID_KEY);
-	    	this.protocols = values.get(protocols);
-	    	
-	    	if(this.BSSIDs == null) this.BSSIDs = new ArrayList<String>();
-	    	if(this.ESSIDs == null) this.ESSIDs = new ArrayList<String>();
-	    	if(this.protocols == null) this.protocols = new ArrayList<String>();
-	    	
-	    	this.sorttype = SortType.values()[Math.min(in.readInt(), SortType.values().length)];
-	    	
-	    	int size = (int)in.readDouble();
-	    	long timeArray[] = new long[size];
-	    	in.readLongArray(timeArray);
-	    	
-	    	this.belowTimestamp = timeArray[1];
-	    	this.aboveTimestamp = timeArray[0];
-	    	
-	    	String bool = in.readString();
-	    	if(bool.equals("true")) this.isNotEditable = true;
-	    }
-	    
-	public boolean isNotEditable(){
+	public void clear() {
+		this.belowTimestamp = Long.MAX_VALUE;
+		this.aboveTimestamp = Long.MIN_VALUE;
+		this.sorttype = SortType.packet_timestamp;
+		this.BSSIDs = new ArrayList<String>();
+		this.ESSIDs = new ArrayList<String>();
+		this.protocols = new ArrayList<String>();
+	}
+
+	public int describeContents() {
+		return 0;
+	}
+
+	// write your object's data to the passed-in Parcel
+	public void writeToParcel(Parcel out, int flags) {
+		HashMap<String, ArrayList<String>> values = new HashMap<String, ArrayList<String>>();
+		if (this.BSSIDs != null && this.BSSIDs.size() > 0) {
+			values.put(BSSID_KEY, this.getBSSIDs());
+		}
+		if (this.ESSIDs != null && this.ESSIDs.size() > 0) {
+			values.put(ESSID_KEY, this.getESSIDs());
+		}
+		if (this.protocols != null && this.protocols.size() > 0) {
+			values.put(PROTOCOLS_KEY, this.getProtocols());
+		}
+		long timeArray[] = new long[] { this.aboveTimestamp, this.belowTimestamp };
+
+		out.writeMap(values);
+		out.writeInt(this.sorttype.getValue());
+		out.writeDouble(timeArray.length);
+		out.writeLongArray(timeArray);
+		out.writeString(this.isNotEditable ? "true" : "false");
+	}
+
+	public static final Parcelable.Creator<LogFilter> CREATOR = new Parcelable.Creator<LogFilter>() {
+		public LogFilter createFromParcel(Parcel in) {
+			return new LogFilter(in);
+		}
+
+		public LogFilter[] newArray(int size) {
+			return new LogFilter[size];
+		}
+	};
+
+	// example constructor that takes a Parcel and gives you an object populated
+	// with it's values
+	private LogFilter(Parcel in) {
+		// mData = in.readInt();
+		HashMap<String, ArrayList<String>> values = new HashMap<String, ArrayList<String>>();
+		in.readMap(values, ArrayList.class.getClassLoader());
+
+		this.BSSIDs = values.get(BSSID_KEY);
+		this.ESSIDs = values.get(ESSID_KEY);
+		this.protocols = values.get(protocols);
+
+		if (this.BSSIDs == null)
+			this.BSSIDs = new ArrayList<String>();
+		if (this.ESSIDs == null)
+			this.ESSIDs = new ArrayList<String>();
+		if (this.protocols == null)
+			this.protocols = new ArrayList<String>();
+
+		this.sorttype = SortType.values()[Math.min(in.readInt(), SortType.values().length)];
+
+		int size = (int) in.readDouble();
+		long timeArray[] = new long[size];
+		in.readLongArray(timeArray);
+
+		this.belowTimestamp = timeArray[1];
+		this.aboveTimestamp = timeArray[0];
+
+		String bool = in.readString();
+		if (bool.equals("true"))
+			this.isNotEditable = true;
+	}
+
+	public boolean isNotEditable() {
 		return this.isNotEditable;
 	}
-	public SortType getSorttype(){
+
+	public SortType getSorttype() {
 		return this.sorttype;
 	}
-	public ArrayList<String> getBSSIDs(){
+
+	public ArrayList<String> getBSSIDs() {
 		return this.BSSIDs;
 	}
-	public ArrayList<String> getESSIDs(){
+
+	public ArrayList<String> getESSIDs() {
 		return this.ESSIDs;
 	}
-	public ArrayList<String> getProtocols(){
+
+	public ArrayList<String> getProtocols() {
 		return this.protocols;
 	}
-	public void setIsNotEditable(boolean b){
+
+	public void setIsNotEditable(boolean b) {
 		this.isNotEditable = b;
 	}
-	
-	public long getBelowTimestamp(){
+
+	public long getBelowTimestamp() {
 		return this.belowTimestamp;
 	}
-	public long getAboveTimestamp(){
+
+	public long getAboveTimestamp() {
 		return this.aboveTimestamp;
 	}
-	public void setProtocols(ArrayList<String> protocols){
+
+	public void setProtocols(ArrayList<String> protocols) {
 		this.protocols = protocols;
 	}
-	public void setBSSIDs(ArrayList<String> bssids){
+
+	public void setBSSIDs(ArrayList<String> bssids) {
 		this.BSSIDs = bssids;
 	}
-	public void setESSIDs(ArrayList<String> essids){
+
+	public void setESSIDs(ArrayList<String> essids) {
 		this.ESSIDs = essids;
 	}
-	public void setAboveTimestamp(long timestamp){
+
+	public void setAboveTimestamp(long timestamp) {
 		this.aboveTimestamp = timestamp;
 	}
-	public void setBelowTimestamp(long timestamp){
+
+	public void setBelowTimestamp(long timestamp) {
 		this.belowTimestamp = timestamp;
 	}
-	public void setSorttype(SortType type){
+
+	public void setSorttype(SortType type) {
 		this.sorttype = type;
 	}
-	
-	
-	public String getBSSIDQueryStatement(String tablename, String key){
+
+	public String getBSSIDQueryStatement(String tablename, String key) {
 		return this.convertArrayListToQueryString(this.BSSIDs, tablename, key);
 	}
-	public String getESSIDQueryStatement(String tablename, String key){
-		return this.convertArrayListToQueryString(this.ESSIDs,tablename ,key);
-	}
-	public String getProtocolsQueryStatement(String tablename, String key){
-		return this.convertArrayListToQueryString(this.protocols,tablename, key);
-	}
-
-    public boolean isSet(){
-        boolean hasTime = this.hasATimestamp();
-        boolean hasBSSIDs = this.hasBSSIDs();
-        boolean hasESSIDs =this.hasESSIDs();
-        boolean hasProtocols = this.hasProtocols();
-
-        return hasBSSIDs || hasESSIDs || hasProtocols | hasTime;
-    }
-
-    public boolean hasBSSIDs(){
-        return  this.getBSSIDs().size() > 0;
-    }
-    public boolean hasESSIDs(){
-        return  this.getESSIDs().size() > 0;
-    }
-    public boolean hasProtocols(){
-        return  this.getProtocols().size() > 0;
-    }
-    public boolean hasAboveTimestamp(){
-        return this.aboveTimestamp != Long.MIN_VALUE;
-    }
-    public boolean hasBelowTimestamp(){
-        return this.belowTimestamp != Long.MAX_VALUE;
-    }
-    public boolean hasATimestamp(){
-        return this.hasBelowTimestamp()|| this.hasAboveTimestamp();
-    }
-	public String convertArrayListToQueryString(ArrayList<String> list, String table,  String key){
+
+	public String getESSIDQueryStatement(String tablename, String key) {
+		return this.convertArrayListToQueryString(this.ESSIDs, tablename, key);
+	}
+
+	public String getProtocolsQueryStatement(String tablename, String key) {
+		return this.convertArrayListToQueryString(this.protocols, tablename, key);
+	}
+
+	public boolean isSet() {
+		boolean hasTime = this.hasATimestamp();
+		boolean hasBSSIDs = this.hasBSSIDs();
+		boolean hasESSIDs = this.hasESSIDs();
+		boolean hasProtocols = this.hasProtocols();
+
+		return hasBSSIDs || hasESSIDs || hasProtocols | hasTime;
+	}
+
+	public boolean hasBSSIDs() {
+		return this.getBSSIDs().size() > 0;
+	}
+
+	public boolean hasESSIDs() {
+		return this.getESSIDs().size() > 0;
+	}
+
+	public boolean hasProtocols() {
+		return this.getProtocols().size() > 0;
+	}
+
+	public boolean hasAboveTimestamp() {
+		return this.aboveTimestamp != Long.MIN_VALUE;
+	}
+
+	public boolean hasBelowTimestamp() {
+		return this.belowTimestamp != Long.MAX_VALUE;
+	}
+
+	public boolean hasATimestamp() {
+		return this.hasBelowTimestamp() || this.hasAboveTimestamp();
+	}
+
+	public String convertArrayListToQueryString(ArrayList<String> list, String table, String key) {
 		String statement = "";
-		if (list == null) return statement;
+		if (list == null)
+			return statement;
 		statement = " ( ";
 
 		int i = 0, max = list.size();
-		for (String element : list){
+		for (String element : list) {
 			i++;
 			statement = statement + table + "." + key + " = " + "'" + element + "'";
-			if (i == max) continue;
-			statement = statement +" OR ";
+			if (i == max)
+				continue;
+			statement = statement + " OR ";
 		}
 		statement = statement + " ) ";
 
 		return statement;
 	}
-	
+
 }

+ 0 - 21
src/de/tudarmstadt/informatik/hostage/ui/loader/CursorLoader.java

@@ -1,21 +0,0 @@
-package de.tudarmstadt.informatik.hostage.ui.loader;
-
-import android.content.Context;
-import android.support.v4.content.AsyncTaskLoader;
-import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
-
-public class CursorLoader extends AsyncTaskLoader<Boolean> {
-
-	private HostageDBOpenHelper mDbHelper;
-
-	public CursorLoader(Context context) {
-		super(context);
-		mDbHelper = new HostageDBOpenHelper(getContext());
-	}
-
-	@Override
-	public Boolean loadInBackground() {
-		return true;
-	}
-
-}