LogFilter.java 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package de.tudarmstadt.informatik.hostage.ui;
  2. import android.os.Parcel;
  3. import android.os.Parcelable;
  4. import java.util.ArrayList;
  5. import java.util.HashMap;
  6. public class LogFilter implements Parcelable{
  7. public final static String LOG_FILTER_INTENT_KEY = "de.tudarmstadt.informatik.hostage.logfilter";
  8. private static final String TIMESTAMP_BELOW_KEY = "de.tudarmstadt.informatik.hostage.logfilter.timestampbelow";
  9. private static final String TIMESTAMP_ABOVE_KEY = "de.tudarmstadt.informatik.hostage.logfilter.timestampabove";
  10. private static final String PROTOCOLS_KEY = "de.tudarmstadt.informatik.hostage.logfilter.protocols";
  11. private static final String ESSID_KEY = "de.tudarmstadt.informatik.hostage.logfilter.essid";
  12. private static final String BSSID_KEY = "de.tudarmstadt.informatik.hostage.logfilter.bssid";
  13. private static final String SORTTYPE_KEY = "de.tudarmstadt.informatik.hostage.logfilter.sorttype";
  14. public enum SortType{
  15. timestamp(0),
  16. protocol(1),
  17. _bssid(1),
  18. ssid(3),
  19. //remoteHostName(5),
  20. //lcaolHostName(6),
  21. _attack_id(7),
  22. _id(8);
  23. private final int id;
  24. SortType(int id) {
  25. this.id = id;
  26. }
  27. public int getValue() {
  28. return id;
  29. }
  30. }
  31. public ArrayList<String> BSSIDs;
  32. public ArrayList<String> ESSIDs;
  33. public ArrayList<String> protocols;
  34. public boolean isNotEditable;
  35. public SortType sorttype;
  36. public long belowTimestamp;
  37. public long aboveTimestamp;
  38. public LogFilter(){
  39. this.clear();
  40. }
  41. public void clear(){
  42. this.belowTimestamp = Long.MAX_VALUE;
  43. this.aboveTimestamp = Long.MIN_VALUE;
  44. this.sorttype = SortType.timestamp;
  45. this.BSSIDs = new ArrayList<String>();
  46. this.ESSIDs = new ArrayList<String>();
  47. this.protocols = new ArrayList<String>();
  48. }
  49. public int describeContents() {
  50. return 0;
  51. }
  52. // write your object's data to the passed-in Parcel
  53. public void writeToParcel(Parcel out, int flags) {
  54. HashMap<String, ArrayList<String>> values =new HashMap<String, ArrayList<String>>();
  55. if(this.BSSIDs != null && this.BSSIDs.size() > 0){
  56. values.put(BSSID_KEY , this.getBSSIDs() );
  57. }
  58. if(this.ESSIDs != null && this.ESSIDs.size() > 0){
  59. values.put(ESSID_KEY , this.getESSIDs() );
  60. }
  61. if(this.protocols != null && this.protocols.size() > 0){
  62. values.put(PROTOCOLS_KEY , this.getProtocols() );
  63. }
  64. long timeArray[] = new long[] {this.aboveTimestamp, this.belowTimestamp};
  65. out.writeMap(values);
  66. out.writeInt(this.sorttype.getValue());
  67. out.writeDouble(timeArray.length);
  68. out.writeLongArray(timeArray);
  69. out.writeString(this.isNotEditable? "true" : "false");
  70. }
  71. public static final Parcelable.Creator<LogFilter> CREATOR = new Parcelable.Creator<LogFilter>() {
  72. public LogFilter createFromParcel(Parcel in) {
  73. return new LogFilter(in);
  74. }
  75. public LogFilter[] newArray(int size) {
  76. return new LogFilter[size];
  77. }
  78. };
  79. // example constructor that takes a Parcel and gives you an object populated with it's values
  80. private LogFilter(Parcel in) {
  81. //mData = in.readInt();
  82. HashMap<String, ArrayList<String>> values = new HashMap<String, ArrayList<String>>();
  83. in.readMap(values, ArrayList.class.getClassLoader());
  84. this.BSSIDs = values.get(BSSID_KEY);
  85. this.ESSIDs = values.get(ESSID_KEY);
  86. this.protocols = values.get(protocols);
  87. if(this.BSSIDs == null) this.BSSIDs = new ArrayList<String>();
  88. if(this.ESSIDs == null) this.ESSIDs = new ArrayList<String>();
  89. if(this.protocols == null) this.protocols = new ArrayList<String>();
  90. this.sorttype = SortType.values()[Math.min(in.readInt(), SortType.values().length)];
  91. int size = (int)in.readDouble();
  92. long timeArray[] = new long[size];
  93. in.readLongArray(timeArray);
  94. this.belowTimestamp = timeArray[1];
  95. this.aboveTimestamp = timeArray[0];
  96. String bool = in.readString();
  97. if(bool.equals("true")) this.isNotEditable = true;
  98. }
  99. public boolean isNotEditable(){
  100. return this.isNotEditable;
  101. }
  102. public SortType getSorttype(){
  103. return this.sorttype;
  104. }
  105. public ArrayList<String> getBSSIDs(){
  106. return this.BSSIDs;
  107. }
  108. public ArrayList<String> getESSIDs(){
  109. return this.ESSIDs;
  110. }
  111. public ArrayList<String> getProtocols(){
  112. return this.protocols;
  113. }
  114. public void setIsNotEditable(boolean b){
  115. this.isNotEditable = b;
  116. }
  117. public long getBelowTimestamp(){
  118. return this.belowTimestamp;
  119. }
  120. public long getAboveTimestamp(){
  121. return this.aboveTimestamp;
  122. }
  123. public void setProtocols(ArrayList<String> protocols){
  124. this.protocols = protocols;
  125. }
  126. public void setBSSIDs(ArrayList<String> bssids){
  127. this.BSSIDs = bssids;
  128. }
  129. public void setESSIDs(ArrayList<String> essids){
  130. this.ESSIDs = essids;
  131. }
  132. public void setAboveTimestamp(long timestamp){
  133. this.aboveTimestamp = timestamp;
  134. }
  135. public void setBelowTimestamp(long timestamp){
  136. this.belowTimestamp = timestamp;
  137. }
  138. public void setSorttype(SortType type){
  139. this.sorttype = type;
  140. }
  141. public String getBSSIDQueryStatement(String tablename, String key){
  142. return this.convertArrayListToQueryString(this.BSSIDs, tablename, key);
  143. }
  144. public String getESSIDQueryStatement(String tablename, String key){
  145. return this.convertArrayListToQueryString(this.ESSIDs,tablename ,key);
  146. }
  147. public String getProtocolsQueryStatement(String tablename, String key){
  148. return this.convertArrayListToQueryString(this.protocols,tablename, key);
  149. }
  150. public boolean isSet(){
  151. boolean hasTime = this.hasATimestamp();
  152. boolean hasBSSIDs = this.hasBSSIDs();
  153. boolean hasESSIDs =this.hasESSIDs();
  154. boolean hasProtocols = this.hasProtocols();
  155. return hasBSSIDs || hasESSIDs || hasProtocols | hasTime;
  156. }
  157. public boolean hasBSSIDs(){
  158. return this.getBSSIDs().size() > 0;
  159. }
  160. public boolean hasESSIDs(){
  161. return this.getESSIDs().size() > 0;
  162. }
  163. public boolean hasProtocols(){
  164. return this.getProtocols().size() > 0;
  165. }
  166. public boolean hasAboveTimestamp(){
  167. return this.aboveTimestamp != Long.MIN_VALUE;
  168. }
  169. public boolean hasBelowTimestamp(){
  170. return this.belowTimestamp != Long.MAX_VALUE;
  171. }
  172. public boolean hasATimestamp(){
  173. return this.hasBelowTimestamp()|| this.hasAboveTimestamp();
  174. }
  175. public String convertArrayListToQueryString(ArrayList<String> list, String table, String key){
  176. String statement = "";
  177. if (list == null) return statement;
  178. statement = " ( ";
  179. int i = 0, max = list.size();
  180. for (String element : list){
  181. i++;
  182. statement = statement + table + "." + key + " = " + "'" + element + "'";
  183. if (i == max) continue;
  184. statement = statement +" OR ";
  185. }
  186. statement = statement + " ) ";
  187. return statement;
  188. }
  189. }