RecordOverviewFragment.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. package de.tudarmstadt.informatik.hostage.ui2.fragment;
  2. import android.annotation.SuppressLint;
  3. import android.app.Fragment;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.view.LayoutInflater;
  8. import android.view.Menu;
  9. import android.view.MenuInflater;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import android.widget.AdapterView;
  13. import android.widget.ExpandableListView;
  14. import android.widget.ImageButton;
  15. import android.widget.Toast;
  16. import com.google.android.gms.maps.model.LatLng;
  17. import java.text.DateFormat;
  18. import java.text.SimpleDateFormat;
  19. import java.util.ArrayList;
  20. import java.util.Calendar;
  21. import java.util.Collections;
  22. import java.util.Comparator;
  23. import java.util.Date;
  24. import java.util.HashMap;
  25. import java.util.Random;
  26. import de.tudarmstadt.informatik.hostage.R;
  27. import de.tudarmstadt.informatik.hostage.logging.Record;
  28. import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
  29. import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
  30. import de.tudarmstadt.informatik.hostage.ui.LogFilter;
  31. import de.tudarmstadt.informatik.hostage.ui.LogFilter.SortType;
  32. import de.tudarmstadt.informatik.hostage.ui2.adapter.RecordListAdapter;
  33. import de.tudarmstadt.informatik.hostage.ui2.dialog.ChecklistDialog;
  34. import de.tudarmstadt.informatik.hostage.ui2.dialog.DateTimeDialogFragment;
  35. import de.tudarmstadt.informatik.hostage.ui2.model.ExpandableListItem;
  36. import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopup;
  37. import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopupItem;
  38. import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupItem;
  39. import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupTable;
  40. import de.tudarmstadt.informatik.hostage.ui2.popup.SplitPopupItem;
  41. public class RecordOverviewFragment extends Fragment implements ChecklistDialog.ChecklistDialogListener, DateTimeDialogFragment.DateTimeDialogFragmentListener {
  42. static final String SELECTED_KEY = "Selected";
  43. static final String OTHERS_KEY = "Other";
  44. static final String FILTER_MENU_TITLE_BSSID = "BSSID";
  45. static final String FILTER_MENU_TITLE_ESSID = "ESSID";
  46. static final String FILTER_MENU_TITLE_PROTOCOLS = "Protocol";
  47. static final String FILTER_MENU_TITLE_TIMESTAMP_BELOW = "Latest";
  48. static final String FILTER_MENU_TITLE_TIMESTAMP_ABOVE = "Earliest";
  49. static final String FILTER_MENU_TITLE_SORTING = "Sort by";
  50. static final String FILTER_MENU_TITLE_REMOVE = "Reset Filter";
  51. static final String FILTER_MENU_TITLE_GROUP = "Group by";
  52. static final String FILTER_MENU_POPUP_TITLE = "Filter by";
  53. private boolean wasBelowTimePicker;
  54. private LogFilter filter;
  55. private boolean showFilterButton;
  56. public String groupingKey;
  57. private ExpandableListView expListView;
  58. UglyDbHelper dbh;
  59. public RecordOverviewFragment(){}
  60. @Override
  61. public void onCreate(Bundle savedInstanceState) {
  62. super.onCreate(savedInstanceState);
  63. setHasOptionsMenu(true);
  64. }
  65. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  66. Bundle savedInstanceState) {
  67. dbh = new UglyDbHelper(this.getActivity().getBaseContext());
  68. // Get the message from the intent
  69. if (this.filter == null){
  70. Intent intent = this.getActivity().getIntent();
  71. LogFilter filter = intent.getParcelableExtra(LogFilter.LOG_FILTER_INTENT_KEY);
  72. if(filter == null){
  73. this.clearFilter();
  74. } else {
  75. this.filter = filter;
  76. }
  77. }
  78. if (this.groupingKey == null) this.groupingKey = this.groupingTitles().get(0);
  79. this.setShowFilterButton(!this.filter.isNotEditable());
  80. this.addRecordToDB();
  81. View rootView = inflater.inflate(R.layout.fragment_record_list, container, false);
  82. ExpandableListView mylist = (ExpandableListView) rootView.findViewById(R.id.loglistview);
  83. this.expListView = mylist;
  84. populateListViewFromDB(mylist);
  85. registerListClickCallback(mylist);
  86. ImageButton filterButton = (ImageButton) rootView.findViewById(R.id.FilterButton);
  87. filterButton.setOnClickListener(new View.OnClickListener() {
  88. public void onClick(View v) {
  89. RecordOverviewFragment.this.openFilterPopupMenuOnView(v);
  90. }
  91. });
  92. filterButton.setVisibility(this.showFilterButton? View.VISIBLE : View.INVISIBLE);
  93. ImageButton sortButton = (ImageButton) rootView.findViewById(R.id.SortButton);
  94. sortButton.setOnClickListener(new View.OnClickListener() {
  95. public void onClick(View v) {
  96. // Open SortMenu
  97. RecordOverviewFragment.this.openSortingDialog();
  98. }
  99. });
  100. ImageButton groupButton = (ImageButton) rootView.findViewById(R.id.GroupButton);
  101. groupButton.setOnClickListener(new View.OnClickListener() {
  102. public void onClick(View v) {
  103. // Open SortMenu
  104. RecordOverviewFragment.this.openGroupingDialog();
  105. }
  106. });
  107. return rootView;
  108. }
  109. public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  110. super.onCreateOptionsMenu(menu, inflater);
  111. }
  112. public void onFilterMenuItemSelected(AbstractPopupItem item) {
  113. String title = item.getTitle();
  114. if (item instanceof SplitPopupItem){
  115. SplitPopupItem splitItem = (SplitPopupItem)item;
  116. if (splitItem.wasRightTouch){
  117. this.openTimestampToFilterDialog();
  118. } else {
  119. this.openTimestampFromFilterDialog();
  120. }
  121. return;
  122. }
  123. if (title != null){
  124. if(title.equals(FILTER_MENU_TITLE_BSSID)){
  125. this.openBSSIDFilterDialog();
  126. }
  127. if(title.equals(FILTER_MENU_TITLE_ESSID)){
  128. this.openESSIDFilterDialog();
  129. }
  130. if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  131. this.openProtocolsFilterDialog();
  132. }
  133. if(title.equals(FILTER_MENU_TITLE_SORTING)){
  134. this.openSortingDialog();
  135. }
  136. if(title.equals(FILTER_MENU_TITLE_REMOVE)){
  137. this.clearFilter();
  138. this.populateListViewFromDB(this.expListView);
  139. }
  140. if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
  141. this.openTimestampToFilterDialog();
  142. }
  143. if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  144. this.openTimestampFromFilterDialog();
  145. }
  146. }
  147. //return super.onOptionsItemSelected(item);
  148. }
  149. /*****************************
  150. *
  151. * ListView Stuff
  152. *
  153. * ***************************/
  154. private void populateListViewFromDB(ExpandableListView mylist) {
  155. HashMap<String, ArrayList<ExpandableListItem>> sectionData = new HashMap<String, ArrayList<ExpandableListItem>>();
  156. ArrayList<Record> data = dbh.getRecordsForFilter(this.filter);
  157. // Adding Items to ListView
  158. String keys[] = new String[] { this.getString(R.string.RecordBSSID), this.getString(R.string.RecordSSID), this.getString(R.string.RecordProtocol), this.getString(R.string.RecordTimestamp)};
  159. int ids[] = new int[] {R.id.RecordTextFieldBSSID, R.id.RecordTextFieldSSID, R.id.RecordTextFieldProtocol, R.id.RecordTextFieldTimestamp };
  160. HashMap<String, Integer> mapping = new HashMap<String, Integer>();
  161. int i = 0;
  162. for(String key : keys){
  163. mapping.put(key, ids[i]);
  164. i++;
  165. }
  166. ArrayList<String>groupTitle = new ArrayList<String>();
  167. for (Record val : data) {
  168. // DO GROUPING IN HERE
  169. HashMap<String, String> map = new HashMap<String, String>();
  170. map.put(this.getString(R.string.RecordBSSID), val.getBssid());
  171. map.put(this.getString(R.string.RecordSSID), val.getSsid());
  172. map.put(this.getString(R.string.RecordProtocol), val.getProtocol());
  173. map.put(this.getString(R.string.RecordTimestamp),
  174. this.getDateAsString(val.getTimestamp()));
  175. ExpandableListItem item = new ExpandableListItem();
  176. item.setData(map);
  177. item.setId_Mapping(mapping);
  178. String groupID = this.getGroupValue(val);
  179. ArrayList<ExpandableListItem> items = sectionData.get(groupID);
  180. if (items == null) {
  181. items = new ArrayList<ExpandableListItem>();
  182. sectionData.put(groupID, items);
  183. groupTitle.add(groupID);
  184. }
  185. items.add(item);
  186. }
  187. Collections.sort(groupTitle, new Comparator<String>() {
  188. @Override
  189. public int compare(String s1, String s2) {
  190. return s1.compareToIgnoreCase(s2);
  191. }
  192. });
  193. RecordListAdapter adapter = new RecordListAdapter(this.getApplicationContext(), groupTitle, sectionData);
  194. mylist.setAdapter(adapter);
  195. }
  196. private Context getBaseContext(){
  197. return this.getActivity().getBaseContext();
  198. }
  199. private Context getApplicationContext(){
  200. return this.getActivity().getApplicationContext();
  201. }
  202. private void registerListClickCallback(ExpandableListView mylist) {
  203. mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  204. public void onItemClick(AdapterView<?> parent, View viewClicked,
  205. int position, long idInDB) {
  206. UglyDbHelper dbh = new UglyDbHelper(getBaseContext());
  207. Record rec = dbh.getRecord((int) idInDB);
  208. String message = createInformationStringFromRecord(rec);
  209. Toast.makeText(getApplicationContext(), message,
  210. Toast.LENGTH_LONG).show();
  211. }
  212. private String createInformationStringFromRecord(Record rec) {
  213. String message = "id: " + rec.getId() + "\n" + "attack_id: "
  214. + rec.getAttack_id() + "\n" + "protocol: "
  215. + rec.getProtocol() + "\n" + "type: " + rec.getType()
  216. + "\n" + "externalIP: " + rec.getExternalIP() + "\n"
  217. + "localIP: " + rec.getLocalIP() + "\n"
  218. + "local port: " + rec.getLocalPort() + "\n"
  219. + "remoteIP: " + rec.getRemoteIP() + "\n" + "BSSID: "
  220. + rec.getBssid() + "\n" + "SSID: " + rec.getSsid()
  221. + "\n" + "latitude: " + rec.getLatitude() + "\n"
  222. + "longitude: " + rec.getLongitude() + "\n"
  223. + "accuracy: " + rec.getAccuracy() + "\n" + "packet: "
  224. + rec.getPacket() + "\n"
  225. + getDateAsString(rec.getTimestamp()) + "";
  226. return message;
  227. }
  228. });
  229. }
  230. /*****************************
  231. *
  232. * Date Transform
  233. *
  234. * ***************************/
  235. @SuppressLint("SimpleDateFormat")
  236. private String getDateAsString(long timeStamp) {
  237. try {
  238. DateFormat sdf = new SimpleDateFormat("H:mm dd/MM/yyyy");
  239. Date netDate = (new Date(timeStamp));
  240. return sdf.format(netDate);
  241. } catch (Exception ex) {
  242. return "xx";
  243. }
  244. }
  245. /*****************************
  246. *
  247. * Getter / Setter
  248. *
  249. * ***************************/
  250. public boolean isShowFilterButton() {
  251. return showFilterButton;
  252. }
  253. public void setShowFilterButton(boolean showFilterButton) {
  254. this.showFilterButton = showFilterButton;
  255. }
  256. /*****************************
  257. *
  258. * Open Dialog Methods
  259. *
  260. * ***************************/
  261. private void openGroupingDialog(){
  262. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_GROUP, this.groupingTitles(), this.selectedGroup(), false , this);
  263. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_GROUP);
  264. }
  265. private void openBSSIDFilterDialog(){
  266. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_BSSID,this.bssids(), this.selectedBSSIDs(), true , this);
  267. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_BSSID);
  268. }
  269. private void openESSIDFilterDialog(){
  270. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_ESSID,this.essids(), this.selectedESSIDs(), true , this);
  271. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_ESSID);
  272. }
  273. private void openProtocolsFilterDialog(){
  274. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_PROTOCOLS,this.protocolTitles(), this.selectedProtocols(), true , this);
  275. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_PROTOCOLS);
  276. }
  277. private void openTimestampFromFilterDialog(){
  278. this.wasBelowTimePicker = false;
  279. DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
  280. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
  281. if (this.filter.aboveTimestamp != Long.MIN_VALUE)newFragment.setDate(this.filter.aboveTimestamp);
  282. }
  283. private void openTimestampToFilterDialog(){
  284. this.wasBelowTimePicker = true;
  285. DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
  286. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
  287. if (this.filter.belowTimestamp != Long.MAX_VALUE) newFragment.setDate(this.filter.belowTimestamp);
  288. }
  289. private void openSortingDialog(){
  290. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_SORTING,this.sortTypeTiles(), this.selectedSorttype(), false , this);
  291. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
  292. }
  293. /*****************************
  294. *
  295. * Grouping Stuff
  296. *
  297. * ***************************/
  298. public String getGroupValue(Record rec){
  299. int index = this.groupingTitles().indexOf(this.groupingKey);
  300. switch (index){
  301. case 0:
  302. return rec.getProtocol();
  303. case 1:
  304. return rec.getBssid();
  305. case 2:
  306. return rec.getSsid();
  307. default:
  308. return rec.getProtocol();
  309. }
  310. }
  311. public ArrayList<String> getGroupTitle(){
  312. int index = this.groupingTitles().indexOf(this.groupingKey);
  313. switch (index){
  314. case 0:
  315. return this.protocolTitles();
  316. case 1:
  317. return this.bssids();
  318. case 2:
  319. return this.essids();
  320. default:
  321. return this.protocolTitles();
  322. }
  323. }
  324. /*****************************
  325. *
  326. * Filter Stuff
  327. *
  328. * ***************************/
  329. private void openFilterPopupMenuOnView(View v){
  330. SimplePopupTable filterMenu = new SimplePopupTable(this.getActivity(), new AbstractPopup.OnPopupItemClickListener() {
  331. public void onItemClick(Object ob) {
  332. if (ob instanceof AbstractPopupItem){
  333. AbstractPopupItem item = (AbstractPopupItem) ob;
  334. RecordOverviewFragment.this.onFilterMenuItemSelected(item);
  335. }
  336. }
  337. });
  338. filterMenu.setTitle(FILTER_MENU_POPUP_TITLE);
  339. for(String title : RecordOverviewFragment.this.filterMenuTitles()){
  340. AbstractPopupItem item = null;
  341. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)) continue;
  342. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  343. item = new SplitPopupItem(this.getActivity());
  344. item.setValue(SplitPopupItem.RIGHT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_BELOW);
  345. item.setValue(SplitPopupItem.LEFT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
  346. if (this.filter.hasBelowTimestamp()){
  347. item.setValue(SplitPopupItem.RIGHT_SUBTITLE, this.getDateAsString(this.filter.belowTimestamp));
  348. }
  349. if (this.filter.hasAboveTimestamp()){
  350. item.setValue(SplitPopupItem.LEFT_SUBTITLE, this.getDateAsString(this.filter.aboveTimestamp));
  351. }
  352. } else {
  353. item = new SimplePopupItem(this.getActivity());
  354. item.setTitle(title);
  355. ((SimplePopupItem)item).setSelected(this.isFilterSetForTitle(title));
  356. }
  357. filterMenu.addItem(item);
  358. }
  359. filterMenu.showOnView(v);
  360. }
  361. private boolean isFilterSetForTitle(String title){
  362. if (title.equals(FILTER_MENU_TITLE_BSSID)){
  363. return this.filter.hasBSSIDs();
  364. }
  365. if (title.equals(FILTER_MENU_TITLE_ESSID)){
  366. return this.filter.hasESSIDs();
  367. }
  368. if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  369. return this.filter.hasProtocols();
  370. }
  371. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
  372. return this.filter.hasBelowTimestamp();
  373. }
  374. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  375. return this.filter.hasAboveTimestamp();
  376. }
  377. return false;
  378. }
  379. private void clearFilter(){
  380. if(filter == null) this.filter = new LogFilter();
  381. this.filter.clear();
  382. }
  383. public ArrayList<String> groupingTitles(){
  384. ArrayList<String> titles = new ArrayList<String>();
  385. for (String groupTitle : this.getResources().getStringArray(
  386. R.array.Grouping)) {
  387. titles.add(groupTitle);
  388. }
  389. return titles;
  390. }
  391. public boolean[] selectedGroup(){
  392. ArrayList<String> groups = this.groupingTitles();
  393. boolean[] selected = new boolean[groups.size()];
  394. int i = 0;
  395. for(String group : groups){
  396. selected[i] =(group.equals(this.groupingKey));
  397. i++;
  398. }
  399. return selected;
  400. }
  401. public ArrayList<String> protocolTitles(){
  402. ArrayList<String> titles = new ArrayList<String>();
  403. for (String protocol : this.getResources().getStringArray(
  404. R.array.protocols)) {
  405. titles.add(protocol);
  406. }
  407. return titles;
  408. }
  409. public boolean[] selectedProtocols(){
  410. ArrayList<String> protocols = this.protocolTitles();
  411. boolean[] selected = new boolean[protocols.size()];
  412. int i = 0;
  413. for(String protocol : protocols){
  414. selected[i] =(this.filter.protocols.contains(protocol));
  415. i++;
  416. }
  417. return selected;
  418. }
  419. public ArrayList<String> sortTypeTiles(){
  420. ArrayList<String> titles = new ArrayList<String>();
  421. titles.add("Time");
  422. titles.add("Protocol");
  423. titles.add("BSSID");
  424. titles.add("ESSID");
  425. //titles.add("Remote Host Name");
  426. //titles.add("Local Host Name");
  427. //titles.add("Attack ID");
  428. //titles.add("ID");
  429. return titles;
  430. }
  431. public boolean[] selectedSorttype(){
  432. ArrayList<String> types = this.sortTypeTiles();
  433. boolean[] selected = new boolean[types.size()];
  434. int i = 0;
  435. for(String sorttype : types){
  436. selected[i] =(this.filter.sorttype.toString().equals(sorttype));
  437. i++;
  438. }
  439. return selected;
  440. }
  441. public ArrayList<String> bssids(){
  442. ArrayList<String> records = dbh.getUniqueBSSIDRecords();
  443. return records;
  444. }
  445. public boolean[] selectedBSSIDs(){
  446. ArrayList<String> bssids = this.bssids();
  447. boolean[] selected = new boolean[bssids.size()];
  448. int i = 0;
  449. for(String bssid : bssids){
  450. selected[i] =(this.filter.BSSIDs.contains(bssid));
  451. i++;
  452. }
  453. return selected;
  454. }
  455. public ArrayList<String> essids(){
  456. ArrayList<String> records = dbh.getUniqueESSIDRecords();
  457. return records;
  458. }
  459. public boolean[] selectedESSIDs(){
  460. ArrayList<String> essids = this.essids();
  461. boolean[] selected = new boolean[essids.size()];
  462. int i = 0;
  463. for(String essid : essids){
  464. selected[i] =(this.filter.ESSIDs.contains(essid));
  465. i++;
  466. }
  467. return selected;
  468. }
  469. private ArrayList<String> filterMenuTitles(){
  470. ArrayList<String> titles = new ArrayList<String>();
  471. titles.add(FILTER_MENU_TITLE_BSSID);
  472. titles.add(FILTER_MENU_TITLE_ESSID);
  473. titles.add(FILTER_MENU_TITLE_PROTOCOLS);
  474. titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
  475. titles.add(FILTER_MENU_TITLE_TIMESTAMP_BELOW);
  476. if (this.filter.isSet())titles.add(FILTER_MENU_TITLE_REMOVE);
  477. return titles;
  478. }
  479. /*****************************
  480. *
  481. * Listener Actions
  482. *
  483. * ***************************/
  484. public void onDateTimePickerPositiveClick(DateTimeDialogFragment dialog) {
  485. if(this.wasBelowTimePicker){
  486. this.filter.setBelowTimestamp(dialog.getDate());
  487. } else {
  488. this.filter.setAboveTimestamp(dialog.getDate());
  489. }
  490. this.populateListViewFromDB(this.expListView);
  491. }
  492. public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog) {
  493. if(this.wasBelowTimePicker){
  494. this.filter.setBelowTimestamp(Long.MAX_VALUE);
  495. } else {
  496. this.filter.setAboveTimestamp(Long.MIN_VALUE);
  497. }
  498. }
  499. public void onDialogPositiveClick(ChecklistDialog dialog) {
  500. String title = dialog.getTitle();
  501. if(title.equals(FILTER_MENU_TITLE_BSSID)){
  502. ArrayList<String> titles =dialog.getSelectedItemTitles();
  503. if (titles.size() == this.bssids().size()){
  504. this.filter.setBSSIDs(new ArrayList<String>());
  505. } else {
  506. this.filter.setBSSIDs(titles);
  507. }
  508. }
  509. if(title.equals(FILTER_MENU_TITLE_ESSID)){
  510. ArrayList<String> titles =dialog.getSelectedItemTitles();
  511. if (titles.size() == this.essids().size()){
  512. this.filter.setESSIDs(new ArrayList<String>());
  513. } else {
  514. this.filter.setESSIDs(titles);
  515. }
  516. }
  517. if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  518. ArrayList<String> protocols = dialog.getSelectedItemTitles();
  519. if (protocols.size() == this.protocolTitles().size()){
  520. this.filter.setProtocols(new ArrayList<String>());
  521. } else {
  522. this.filter.setProtocols(dialog.getSelectedItemTitles());
  523. }
  524. }
  525. if(title.equals(FILTER_MENU_TITLE_SORTING)){
  526. ArrayList<String> titles = dialog.getSelectedItemTitles();
  527. if (titles.size() == 0) return;
  528. String t = titles.get(0);
  529. int sortType = this.sortTypeTiles().indexOf(t);
  530. this.filter.setSorttype(SortType.values()[sortType]);
  531. }
  532. if (title.equals(FILTER_MENU_TITLE_GROUP)){
  533. ArrayList<String> titles = dialog.getSelectedItemTitles();
  534. if (titles.size() == 0) return;
  535. this.groupingKey = titles.get(0);
  536. }
  537. this.populateListViewFromDB(this.expListView);
  538. }
  539. public void onDialogNegativeClick(ChecklistDialog dialog) {
  540. }
  541. /*****************************
  542. *
  543. * TEST
  544. *
  545. * ***************************/
  546. private void addRecordToDB() {
  547. if ((dbh.getRecordCount() > 0)) return;
  548. Calendar cal = Calendar.getInstance();
  549. int maxProtocolsIndex = this.getResources().getStringArray(
  550. R.array.protocols).length;
  551. Random random = new Random();
  552. LatLng tudarmstadtLoc = new LatLng(49.86923, 8.6632768);
  553. int numberofRecords = (int) (Math.random() * (50 - 10));
  554. for (int i = 0; i < numberofRecords; i++) {
  555. Record record = new Record();
  556. record.setId(i);
  557. record.setAttack_id(i);
  558. record.setBssid("BSSID: " + i);
  559. record.setSsid("SSID: w" + i);
  560. record.setTimestamp(cal.getTimeInMillis()
  561. + ((i * 60 * 60 * 60 * 24) * 1000));
  562. int index = i % maxProtocolsIndex;
  563. String protocolName = this.getResources().getStringArray(
  564. R.array.protocols)[index];
  565. record.setProtocol(protocolName);
  566. record.setLocalIP("127.0.0.1");
  567. record.setType(TYPE.SEND);
  568. record.setLatitude(tudarmstadtLoc.latitude + -0.01 + 0.02 * random.nextDouble());
  569. record.setLongitude(tudarmstadtLoc.longitude + -0.01 + 0.02 * random.nextDouble());
  570. dbh.addRecord(record);
  571. }
  572. int countAllLogs = dbh.getAllRecords().size();
  573. int countRecords = dbh.getRecordCount();
  574. int countAttacks = dbh.getAttackCount();
  575. if ((countRecords == 0)) {
  576. Record rec = dbh.getRecordOfAttackId(0);
  577. Record rec2 = dbh.getRecord(0);
  578. System.out.println("" + "Could not create logs!");
  579. }
  580. }
  581. }