123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822 |
- package de.tudarmstadt.informatik.hostage.ui2.fragment;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Random;
- import android.annotation.SuppressLint;
- import android.app.FragmentManager;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.Menu;
- import android.view.MenuInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ExpandableListView;
- import android.widget.ImageButton;
- import com.google.android.gms.maps.model.LatLng;
- import de.tudarmstadt.informatik.hostage.R;
- import de.tudarmstadt.informatik.hostage.logging.AttackRecord;
- import de.tudarmstadt.informatik.hostage.logging.NetworkRecord;
- import de.tudarmstadt.informatik.hostage.logging.Record;
- import de.tudarmstadt.informatik.hostage.logging.MessageRecord;
- import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
- import de.tudarmstadt.informatik.hostage.ui.LogFilter;
- import de.tudarmstadt.informatik.hostage.ui.LogFilter.SortType;
- import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
- import de.tudarmstadt.informatik.hostage.ui2.adapter.RecordListAdapter;
- import de.tudarmstadt.informatik.hostage.ui2.dialog.ChecklistDialog;
- import de.tudarmstadt.informatik.hostage.ui2.dialog.DateTimeDialogFragment;
- import de.tudarmstadt.informatik.hostage.ui2.model.ExpandableListItem;
- import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopup;
- import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopupItem;
- import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupItem;
- import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupTable;
- import de.tudarmstadt.informatik.hostage.ui2.popup.SplitPopupItem;
- public class RecordOverviewFragment extends UpNavigatibleFragment implements ChecklistDialog.ChecklistDialogListener,
- DateTimeDialogFragment.DateTimeDialogFragmentListener {
- static final String FILTER_MENU_TITLE_BSSID = "BSSID";
- static final String FILTER_MENU_TITLE_ESSID = "ESSID";
- static final String FILTER_MENU_TITLE_PROTOCOLS = MainActivity.getContext().getString(R.string.rec_protocol);
- static final String FILTER_MENU_TITLE_TIMESTAMP_BELOW = MainActivity.getContext().getString(R.string.rec_latest);
- static final String FILTER_MENU_TITLE_TIMESTAMP_ABOVE = MainActivity.getContext().getString(R.string.rec_earliest);
- static final String FILTER_MENU_TITLE_SORTING = MainActivity.getContext().getString(R.string.rec_sortby);
- static final String FILTER_MENU_TITLE_REMOVE = MainActivity.getContext().getString(R.string.rec_reset_filter);
- static final String FILTER_MENU_TITLE_GROUP = MainActivity.getContext().getString(R.string.rec_group_by);
- static final String FILTER_MENU_POPUP_TITLE = MainActivity.getContext().getString(R.string.rec_filter_by);
- private boolean wasBelowTimePicker;
- private LogFilter filter;
- private boolean showFilterButton;
- private int mListPosition = -1;
- private int mItemPosition = -1;
- public String groupingKey;
- private ExpandableListView expListView;
- HostageDBOpenHelper dbh;
- private String sectionToOpen = "";
- private ArrayList<Integer> openSections;
- public void setFilter(LogFilter filter) {
- this.filter = filter;
- }
- public RecordOverviewFragment() {
- }
- public void setGroupKey(String key) {
- this.groupingKey = key;
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setHasOptionsMenu(true);
- }
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- getActivity().setTitle(getResources().getString(R.string.drawer_records));
- dbh = new HostageDBOpenHelper(this.getActivity().getBaseContext());
- // Get the message from the intent
- if (this.filter == null) {
- Intent intent = this.getActivity().getIntent();
- LogFilter filter = intent.getParcelableExtra(LogFilter.LOG_FILTER_INTENT_KEY);
- if (filter == null) {
- this.clearFilter();
- } else {
- this.filter = filter;
- }
- }
- if (this.groupingKey == null)
- this.groupingKey = this.groupingTitles().get(0);
- this.setShowFilterButton(!this.filter.isNotEditable());
- // this.addRecordToDB();
- View rootView = inflater.inflate(this.getLayoutId(), container, false);
- ExpandableListView mylist = (ExpandableListView) rootView.findViewById(R.id.loglistview);
- this.expListView = mylist;
- populateListViewFromDB(mylist);
- if (this.openSections != null && this.openSections.size() != 0) {
- for (int i = 0; i < this.openSections.size(); i++) {
- int index = this.openSections.get(i);
- this.expListView.expandGroup(index);
- }
- } else {
- this.openSections = new ArrayList<Integer>();
- }
- if (mListPosition != -1 && mItemPosition != -1)
- this.expListView.setSelectedChild(mListPosition, mItemPosition, true);
- mListPosition = -1;
- mItemPosition = -1;
- registerListClickCallback(mylist);
- ImageButton filterButton = (ImageButton) rootView.findViewById(R.id.FilterButton);
- filterButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- RecordOverviewFragment.this.openFilterPopupMenuOnView(v);
- }
- });
- filterButton.setVisibility(this.showFilterButton ? View.VISIBLE : View.INVISIBLE);
- ImageButton sortButton = (ImageButton) rootView.findViewById(R.id.SortButton);
- sortButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // Open SortMenu
- RecordOverviewFragment.this.openSortingDialog();
- }
- });
- ImageButton groupButton = (ImageButton) rootView.findViewById(R.id.GroupButton);
- groupButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // Open SortMenu
- RecordOverviewFragment.this.openGroupingDialog();
- }
- });
- return rootView;
- }
- public int getLayoutId() {
- return R.layout.fragment_record_list;
- }
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- super.onCreateOptionsMenu(menu, inflater);
- }
- public void onFilterMenuItemSelected(AbstractPopupItem item) {
- String title = item.getTitle();
- if (item instanceof SplitPopupItem) {
- SplitPopupItem splitItem = (SplitPopupItem) item;
- if (splitItem.wasRightTouch) {
- this.openTimestampToFilterDialog();
- } else {
- this.openTimestampFromFilterDialog();
- }
- return;
- }
- if (title != null) {
- if (title.equals(FILTER_MENU_TITLE_BSSID)) {
- this.openBSSIDFilterDialog();
- }
- if (title.equals(FILTER_MENU_TITLE_ESSID)) {
- this.openESSIDFilterDialog();
- }
- if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)) {
- this.openProtocolsFilterDialog();
- }
- if (title.equals(FILTER_MENU_TITLE_SORTING)) {
- this.openSortingDialog();
- }
- if (title.equals(FILTER_MENU_TITLE_REMOVE)) {
- this.clearFilter();
- this.populateListViewFromDB(this.expListView);
- }
- if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)) {
- this.openTimestampToFilterDialog();
- }
- if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)) {
- this.openTimestampFromFilterDialog();
- }
- }
- // return super.onOptionsItemSelected(item);
- }
- public void onStart() {
- super.onStart();
- // this.populateListViewFromDB(this.expListView);
- if (this.expListView.getExpandableListAdapter().getGroupCount() == 1) {
- this.expListView.expandGroup(0);
- } else {
- this.setSectionToOpen(this.sectionToOpen);
- }
- }
- /*****************************
- *
- * Public API
- *
- * ***************************/
- /**
- * Group records by SSID and expand given SSID
- *
- * @param SSID
- * the SSID
- */
- public void showDetailsForSSID(Context context, String SSID) {
- Log.e("RecordOverviewFragment", "Implement showDetailsForSSID!!");
- this.clearFilter();
- int ESSID_INDEX = 2;
- ArrayList<String> ssids = new ArrayList<String>();
- this.sectionToOpen = SSID;
- this.groupingKey = this.groupingTitles(context).get(ESSID_INDEX);
- }
- /*****************************
- * UglyDbHelper
- *
- * ListView Stuff
- *
- * ***************************/
- private void populateListViewFromDB(ExpandableListView mylist) {
- HashMap<String, ArrayList<ExpandableListItem>> sectionData = new HashMap<String, ArrayList<ExpandableListItem>>();
- ArrayList<Record> data = dbh.getRecordsForFilter(this.filter);
- // Adding Items to ListView
- String keys[] = new String[] { this.getString(R.string.RecordBSSID), this.getString(R.string.RecordSSID), this.getString(R.string.RecordProtocol),
- this.getString(R.string.RecordTimestamp) };
- int ids[] = new int[] { R.id.RecordTextFieldBSSID, R.id.RecordTextFieldSSID, R.id.RecordTextFieldProtocol, R.id.RecordTextFieldTimestamp };
- HashMap<String, Integer> mapping = new HashMap<String, Integer>();
- int i = 0;
- for (String key : keys) {
- mapping.put(key, ids[i]);
- i++;
- }
- ArrayList<String> groupTitle = new ArrayList<String>();
- for (Record val : data) {
- // DO GROUPING IN HERE
- HashMap<String, String> map = new HashMap<String, String>();
- map.put(this.getString(R.string.RecordBSSID), val.getBssid());
- map.put(this.getString(R.string.RecordSSID), val.getSsid());
- map.put(this.getString(R.string.RecordProtocol), val.getProtocol());
- map.put(this.getString(R.string.RecordTimestamp), this.getDateAsString(val.getTimestamp()));
- ExpandableListItem item = new ExpandableListItem();
- item.setData(map);
- item.setId_Mapping(mapping);
- item.setTag(val.getAttack_id());
- String groupID = this.getGroupValue(val);
- ArrayList<ExpandableListItem> items = sectionData.get(groupID);
- if (items == null) {
- items = new ArrayList<ExpandableListItem>();
- sectionData.put(groupID, items);
- groupTitle.add(groupID);
- }
- items.add(item);
- }
- Collections.sort(groupTitle, new Comparator<String>() {
- @Override
- public int compare(String s1, String s2) {
- return s1.compareToIgnoreCase(s2);
- }
- });
- RecordListAdapter adapter = new RecordListAdapter(this.getApplicationContext(), groupTitle, sectionData);
- mylist.setAdapter(adapter);
- }
- private void setSectionToOpen(String s) {
- this.sectionToOpen = s;
- if (this.sectionToOpen != null && this.sectionToOpen.length() != 0) {
- if (this.getGroupTitle().contains(this.sectionToOpen)) {
- int section = this.getGroupTitle().indexOf(this.sectionToOpen);
- this.expListView.expandGroup(section);
- this.sectionToOpen = "";
- }
- }
- }
- private Context getBaseContext() {
- return this.getActivity().getBaseContext();
- }
- private Context getApplicationContext() {
- return this.getActivity().getApplicationContext();
- }
- private void registerListClickCallback(ExpandableListView mylist) {
- mylist.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
- @Override
- public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i2, long l) {
- RecordListAdapter adapter = (RecordListAdapter) expandableListView.getExpandableListAdapter();
- ExpandableListItem item = (ExpandableListItem) adapter.getChild(i, i2);
- mListPosition = i;
- mItemPosition = i2;
- HostageDBOpenHelper dbh = new HostageDBOpenHelper(getBaseContext());
- Record rec = dbh.getRecordOfAttackId((int) item.getTag());
- RecordOverviewFragment.this.pushRecordDetailViewForRecord(rec);
- return true;
- }
- });
- mylist.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
- @Override
- public void onGroupExpand(int i) {
- RecordOverviewFragment.this.openSections.add(new Integer(i));
- }
- });
- mylist.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
- @Override
- public void onGroupCollapse(int i) {
- RecordOverviewFragment.this.openSections.remove(new Integer(i));
- }
- });
- }
- /*****************************
- *
- * Date Transform
- *
- * ***************************/
- @SuppressLint("SimpleDateFormat")
- private String getDateAsString(long timeStamp) {
- try {
- DateFormat sdf = new SimpleDateFormat("H:mm d.M.yy");
- Date netDate = (new Date(timeStamp));
- return sdf.format(netDate);
- } catch (Exception ex) {
- return "xx";
- }
- }
- /*****************************
- *
- * Getter / Setter
- *
- * ***************************/
- public boolean isShowFilterButton() {
- return showFilterButton;
- }
- public void setShowFilterButton(boolean showFilterButton) {
- this.showFilterButton = showFilterButton;
- }
- /*****************************
- *
- * Open Dialog Methods
- *
- * ***************************/
- private void openGroupingDialog() {
- ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_GROUP, this.groupingTitles(), this.selectedGroup(), false, this);
- newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_GROUP);
- }
- private void openBSSIDFilterDialog() {
- ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_BSSID, this.bssids(), this.selectedBSSIDs(), true, this);
- newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_BSSID);
- }
- private void openESSIDFilterDialog() {
- ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_ESSID, this.essids(), this.selectedESSIDs(), true, this);
- newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_ESSID);
- }
- private void openProtocolsFilterDialog() {
- ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_PROTOCOLS, this.protocolTitles(), this.selectedProtocols(), true, this);
- newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_PROTOCOLS);
- }
- private void openTimestampFromFilterDialog() {
- this.wasBelowTimePicker = false;
- DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
- newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
- if (this.filter.aboveTimestamp != Long.MIN_VALUE)
- newFragment.setDate(this.filter.aboveTimestamp);
- }
- private void openTimestampToFilterDialog() {
- this.wasBelowTimePicker = true;
- DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
- newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
- if (this.filter.belowTimestamp != Long.MAX_VALUE)
- newFragment.setDate(this.filter.belowTimestamp);
- }
- private void openSortingDialog() {
- ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_SORTING, this.sortTypeTiles(), this.selectedSorttype(), false, this);
- newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
- }
- /*****************************
- *
- * Grouping Stuff
- *
- * ***************************/
- public String getGroupValue(Record rec) {
- int index = this.groupingTitles().indexOf(this.groupingKey);
- switch (index) {
- case 0:
- return rec.getProtocol();
- case 1:
- return rec.getBssid();
- case 2:
- return rec.getSsid();
- default:
- return rec.getProtocol();
- }
- }
- public ArrayList<String> getGroupTitle() {
- int index = this.groupingTitles().indexOf(this.groupingKey);
- switch (index) {
- case 0:
- return this.protocolTitles();
- case 1:
- return this.bssids();
- case 2:
- return this.essids();
- default:
- return this.protocolTitles();
- }
- }
- /*****************************
- *
- * Filter Stuff
- *
- * ***************************/
- private void openFilterPopupMenuOnView(View v) {
- SimplePopupTable filterMenu = new SimplePopupTable(this.getActivity(), new AbstractPopup.OnPopupItemClickListener() {
- public void onItemClick(Object ob) {
- if (ob instanceof AbstractPopupItem) {
- AbstractPopupItem item = (AbstractPopupItem) ob;
- RecordOverviewFragment.this.onFilterMenuItemSelected(item);
- }
- }
- });
- filterMenu.setTitle(FILTER_MENU_POPUP_TITLE);
- for (String title : RecordOverviewFragment.this.filterMenuTitles()) {
- AbstractPopupItem item = null;
- if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW))
- continue;
- if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)) {
- item = new SplitPopupItem(this.getActivity());
- item.setValue(SplitPopupItem.RIGHT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_BELOW);
- item.setValue(SplitPopupItem.LEFT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
- if (this.filter.hasBelowTimestamp()) {
- item.setValue(SplitPopupItem.RIGHT_SUBTITLE, this.getDateAsString(this.filter.belowTimestamp));
- }
- if (this.filter.hasAboveTimestamp()) {
- item.setValue(SplitPopupItem.LEFT_SUBTITLE, this.getDateAsString(this.filter.aboveTimestamp));
- }
- } else {
- item = new SimplePopupItem(this.getActivity());
- item.setTitle(title);
- ((SimplePopupItem) item).setSelected(this.isFilterSetForTitle(title));
- }
- filterMenu.addItem(item);
- }
- filterMenu.showOnView(v);
- }
- private boolean isFilterSetForTitle(String title) {
- if (title.equals(FILTER_MENU_TITLE_BSSID)) {
- return this.filter.hasBSSIDs();
- }
- if (title.equals(FILTER_MENU_TITLE_ESSID)) {
- return this.filter.hasESSIDs();
- }
- if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)) {
- return this.filter.hasProtocols();
- }
- if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)) {
- return this.filter.hasBelowTimestamp();
- }
- if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)) {
- return this.filter.hasAboveTimestamp();
- }
- return false;
- }
- private void clearFilter() {
- if (filter == null)
- this.filter = new LogFilter();
- this.filter.clear();
- }
- public ArrayList<String> groupingTitles(Context context) {
- ArrayList<String> titles = new ArrayList<String>();
- for (String groupTitle : context.getResources().getStringArray(R.array.Grouping)) {
- titles.add(groupTitle);
- }
- return titles;
- }
- public ArrayList<String> groupingTitles() {
- ArrayList<String> titles = new ArrayList<String>();
- for (String groupTitle : this.getResources().getStringArray(R.array.Grouping)) {
- titles.add(groupTitle);
- }
- return titles;
- }
- public boolean[] selectedGroup() {
- ArrayList<String> groups = this.groupingTitles();
- boolean[] selected = new boolean[groups.size()];
- int i = 0;
- for (String group : groups) {
- selected[i] = (group.equals(this.groupingKey));
- i++;
- }
- return selected;
- }
- public ArrayList<String> protocolTitles() {
- ArrayList<String> titles = new ArrayList<String>();
- for (String protocol : this.getResources().getStringArray(R.array.protocols)) {
- titles.add(protocol);
- }
- return titles;
- }
- public boolean[] selectedProtocols() {
- ArrayList<String> protocols = this.protocolTitles();
- boolean[] selected = new boolean[protocols.size()];
- int i = 0;
- for (String protocol : protocols) {
- selected[i] = (this.filter.protocols.contains(protocol));
- i++;
- }
- return selected;
- }
- public ArrayList<String> sortTypeTiles() {
- ArrayList<String> titles = new ArrayList<String>();
- titles.add(MainActivity.getContext().getString(R.string.rec_time));
- titles.add(MainActivity.getContext().getString(R.string.rec_protocol));
- titles.add("BSSID");
- titles.add("ESSID");
- // titles.add("Remote Host Name");
- // titles.add("Local Host Name");
- // titles.add("Attack ID");
- // titles.add("ID");
- return titles;
- }
- public boolean[] selectedSorttype() {
- ArrayList<String> types = this.sortTypeTiles();
- boolean[] selected = new boolean[types.size()];
- int i = 0;
- for (String sorttype : types) {
- selected[i] = (this.filter.sorttype.toString().equals(sorttype));
- i++;
- }
- return selected;
- }
- public ArrayList<String> bssids() {
- ArrayList<String> records = dbh.getUniqueBSSIDRecords();
- return records;
- }
- public boolean[] selectedBSSIDs() {
- ArrayList<String> bssids = this.bssids();
- boolean[] selected = new boolean[bssids.size()];
- int i = 0;
- for (String bssid : bssids) {
- selected[i] = (this.filter.BSSIDs.contains(bssid));
- i++;
- }
- return selected;
- }
- public ArrayList<String> essids() {
- ArrayList<String> records = dbh.getUniqueESSIDRecords();
- return records;
- }
- public boolean[] selectedESSIDs() {
- ArrayList<String> essids = this.essids();
- boolean[] selected = new boolean[essids.size()];
- int i = 0;
- for (String essid : essids) {
- selected[i] = (this.filter.ESSIDs.contains(essid));
- i++;
- }
- return selected;
- }
- private ArrayList<String> filterMenuTitles() {
- ArrayList<String> titles = new ArrayList<String>();
- titles.add(FILTER_MENU_TITLE_BSSID);
- titles.add(FILTER_MENU_TITLE_ESSID);
- titles.add(FILTER_MENU_TITLE_PROTOCOLS);
- titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
- titles.add(FILTER_MENU_TITLE_TIMESTAMP_BELOW);
- if (this.filter.isSet())
- titles.add(FILTER_MENU_TITLE_REMOVE);
- return titles;
- }
- /*****************************
- *
- * Listener Actions
- *
- * ***************************/
- public void onDateTimePickerPositiveClick(DateTimeDialogFragment dialog) {
- if (this.wasBelowTimePicker) {
- this.filter.setBelowTimestamp(dialog.getDate());
- } else {
- this.filter.setAboveTimestamp(dialog.getDate());
- }
- this.populateListViewFromDB(this.expListView);
- }
- public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog) {
- if (this.wasBelowTimePicker) {
- this.filter.setBelowTimestamp(Long.MAX_VALUE);
- } else {
- this.filter.setAboveTimestamp(Long.MIN_VALUE);
- }
- }
- public void onDialogPositiveClick(ChecklistDialog dialog) {
- String title = dialog.getTitle();
- if (title.equals(FILTER_MENU_TITLE_BSSID)) {
- ArrayList<String> titles = dialog.getSelectedItemTitles();
- if (titles.size() == this.bssids().size()) {
- this.filter.setBSSIDs(new ArrayList<String>());
- } else {
- this.filter.setBSSIDs(titles);
- }
- }
- if (title.equals(FILTER_MENU_TITLE_ESSID)) {
- ArrayList<String> titles = dialog.getSelectedItemTitles();
- if (titles.size() == this.essids().size()) {
- this.filter.setESSIDs(new ArrayList<String>());
- } else {
- this.filter.setESSIDs(titles);
- }
- }
- if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)) {
- ArrayList<String> protocols = dialog.getSelectedItemTitles();
- if (protocols.size() == this.protocolTitles().size()) {
- this.filter.setProtocols(new ArrayList<String>());
- } else {
- this.filter.setProtocols(dialog.getSelectedItemTitles());
- }
- }
- if (title.equals(FILTER_MENU_TITLE_SORTING)) {
- ArrayList<String> titles = dialog.getSelectedItemTitles();
- if (titles.size() == 0)
- return;
- String t = titles.get(0);
- int sortType = this.sortTypeTiles().indexOf(t);
- this.filter.setSorttype(SortType.values()[sortType]);
- }
- if (title.equals(FILTER_MENU_TITLE_GROUP)) {
- ArrayList<String> titles = dialog.getSelectedItemTitles();
- if (titles.size() == 0)
- return;
- this.groupingKey = titles.get(0);
- }
- this.populateListViewFromDB(this.expListView);
- }
- public void onDialogNegativeClick(ChecklistDialog dialog) {
- }
- /*****************************
- *
- * TEST
- *
- * ***************************/
- private void addRecordToDB() {
- if ((dbh.getRecordCount() > 0))
- return;
- Calendar cal = Calendar.getInstance();
- int maxProtocolsIndex = this.getResources().getStringArray(R.array.protocols).length;
- Random random = new Random();
- LatLng tudarmstadtLoc = new LatLng(49.86923, 8.6632768);
- final int numSSIDs = 10;
- final int numUniqueSSIDs = 6;
- final double ssidRadius = 0.1;
- final double bssidRadius = 0.004;
- int id = 0; // global id
- for (int ssid = 0; ssid < numSSIDs; ssid++) {
- LatLng ssidLocation = new LatLng(tudarmstadtLoc.latitude - ssidRadius + 2.0 * ssidRadius * Math.random(), tudarmstadtLoc.longitude - ssidRadius
- + 2.0 * ssidRadius * Math.random());
- String ssidName = "WiFi" + ((ssid % numUniqueSSIDs) + 1);
- int numBSSIDs = (Math.abs(random.nextInt()) % 20) + 1;
- for (int bssid = 0; bssid < numBSSIDs; bssid++) {
- MessageRecord message = new MessageRecord();
- AttackRecord attack = new AttackRecord();
- NetworkRecord network = new NetworkRecord();
-
- message.setId(id);
- message.setAttack_id(id);
- message.setType(MessageRecord.TYPE.SEND);
- message.setTimestamp(cal.getTimeInMillis() + ((id * 60 * 60 * 60 * 24) * 1000));
-
- int index = id % maxProtocolsIndex;
- String protocolName = this.getResources().getStringArray(R.array.protocols)[index];
- attack.setAttack_id(id);
- attack.setProtocol(protocolName);
- attack.setLocalIP("127.0.0.1");
- attack.setBssid("BSSID" + id);
-
- network.setBssid("BSSID" + id);
- network.setSsid(ssidName);
- network.setLatitude(ssidLocation.latitude - bssidRadius + 2.0 * bssidRadius * Math.random());
- network.setLongitude(ssidLocation.longitude - bssidRadius + 2.0 * bssidRadius * Math.random());
- id++;
- dbh.updateNetworkInformation(network);
- dbh.addAttackRecord(attack);
- dbh.addMessageRecord(message);
- }
- }
- int countAllLogs = dbh.getAllRecords().size();
- int countRecords = dbh.getRecordCount();
- int countAttacks = dbh.getAttackCount();
- if ((countRecords == 0)) {
- Record rec = dbh.getRecordOfAttackId(0);
- Record rec2 = dbh.getRecord(0);
- System.out.println("" + "Could not create logs!");
- }
- }
- /* Navigation */
- private void pushRecordDetailViewForRecord(Record record) {
- FragmentManager fm = this.getActivity().getFragmentManager();
- if (fm != null) {
- RecordDetailFragment newFragment = new RecordDetailFragment();
- newFragment.setRecord(record);
- newFragment.setUpNavigatible(true);
- MainActivity.getInstance().injectFragment(newFragment);
- }
- }
- }
|