|
@@ -0,0 +1,447 @@
|
|
|
+package de.tudarmstadt.informatik.hostage.ui2.fragment;
|
|
|
+
|
|
|
+import java.net.InetAddress;
|
|
|
+import java.net.UnknownHostException;
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.app.Fragment;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.Menu;
|
|
|
+import android.view.MenuInflater;
|
|
|
+import android.view.MenuItem;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.AdapterView;
|
|
|
+import android.widget.ListAdapter;
|
|
|
+import android.widget.ListView;
|
|
|
+import android.widget.SimpleAdapter;
|
|
|
+import android.widget.Toast;
|
|
|
+import de.tudarmstadt.informatik.hostage.R;
|
|
|
+import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
|
|
|
+import de.tudarmstadt.informatik.hostage.logging.Record;
|
|
|
+import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
|
|
|
+import de.tudarmstadt.informatik.hostage.ui.LogFilter;
|
|
|
+import de.tudarmstadt.informatik.hostage.ui.LogFilter.SortType;
|
|
|
+import de.tudarmstadt.informatik.hostage.ui2.dialog.ChecklistDialog;
|
|
|
+import de.tudarmstadt.informatik.hostage.ui2.dialog.DateTimeDialogFragment;
|
|
|
+
|
|
|
+public class RecordOverviewFragment extends Fragment implements ChecklistDialog.ChecklistDialogListener, DateTimeDialogFragment.DateTimeDialogFragmentListener {
|
|
|
+ static final String SELECTED_KEY = "Selected";
|
|
|
+ static final String OTHERS_KEY = "Other";
|
|
|
+
|
|
|
+ static final String FILTER_MENU_TITLE_BSSID = "BSSID";
|
|
|
+ static final String FILTER_MENU_TITLE_ESSID = "ESSID";
|
|
|
+ static final String FILTER_MENU_TITLE_PROTOCOLS = "Protocols";
|
|
|
+ static final String FILTER_MENU_TITLE_TIMESTAMP_BELOW = "To Date";
|
|
|
+ static final String FILTER_MENU_TITLE_TIMESTAMP_ABOVE = "From Date";
|
|
|
+ static final String FILTER_MENU_TITLE_SORTING = "Sort by";
|
|
|
+ static final String FILTER_MENU_TITLE_REMOVE = "Remove";
|
|
|
+
|
|
|
+ private boolean wasBelowTimePicker;
|
|
|
+
|
|
|
+ private LogFilter filter;
|
|
|
+ private ListView listView;
|
|
|
+ private boolean showFilterButton;
|
|
|
+ DatabaseHandler dbh;
|
|
|
+
|
|
|
+
|
|
|
+ public RecordOverviewFragment(){}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ setHasOptionsMenu(true);
|
|
|
+ }
|
|
|
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
+ Bundle savedInstanceState) {
|
|
|
+
|
|
|
+
|
|
|
+ dbh = new DatabaseHandler(this.getActivity().getBaseContext());
|
|
|
+ // Get the message from the intent
|
|
|
+ Intent intent = this.getActivity().getIntent();
|
|
|
+ LogFilter filter = intent.getParcelableExtra(LogFilter.LOG_FILTER_INTENT_KEY);
|
|
|
+
|
|
|
+ if(filter == null){
|
|
|
+ this.clearFilter();
|
|
|
+ } else {
|
|
|
+ this.filter = filter;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setShowFilterButton(!this.filter.isNotEditable());
|
|
|
+
|
|
|
+ this.addRecordToDB();
|
|
|
+
|
|
|
+ View rootView = inflater.inflate(R.layout.fragment_record_list, container, false);
|
|
|
+ ListView mylist = (ListView) rootView.findViewById(R.id.loglistview);
|
|
|
+ this.listView = mylist;
|
|
|
+ populateListViewFromDB(mylist);
|
|
|
+
|
|
|
+ registerListClickCallback(mylist);
|
|
|
+
|
|
|
+ return rootView;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void clearFilter(){
|
|
|
+ this.filter = new LogFilter();
|
|
|
+ this.filter.setProtocols(this.protocolTitles());
|
|
|
+ this.filter.setBSSIDs(this.bssids());
|
|
|
+ this.filter.setESSIDs(this.essids());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void populateListViewFromDB(ListView mylist) {
|
|
|
+
|
|
|
+ ArrayList<HashMap<String, String>> Items = new ArrayList<HashMap<String, String>>();
|
|
|
+
|
|
|
+ ArrayList<Record> data = dbh.getRecordsForFilter(this.filter);
|
|
|
+
|
|
|
+
|
|
|
+ for (Record val : data) {
|
|
|
+ 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()));
|
|
|
+ Items.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 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 };
|
|
|
+
|
|
|
+ ListAdapter adapter = new SimpleAdapter(this.getActivity(), Items, R.layout.loglist_row, keys, ids);
|
|
|
+
|
|
|
+ mylist.setAdapter(adapter);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Context getBaseContext(){
|
|
|
+ return this.getActivity().getBaseContext();
|
|
|
+ }
|
|
|
+
|
|
|
+ private Context getApplicationContext(){
|
|
|
+ return this.getActivity().getApplicationContext();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void registerListClickCallback(ListView mylist) {
|
|
|
+
|
|
|
+ mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ public void onItemClick(AdapterView<?> parent, View viewClicked,
|
|
|
+ int position, long idInDB) {
|
|
|
+ DatabaseHandler dbh = new DatabaseHandler(getBaseContext());
|
|
|
+ Record rec = dbh.getRecord((int) idInDB);
|
|
|
+ String message = createInformationStringFromRecord(rec);
|
|
|
+ Toast.makeText(getApplicationContext(), message,
|
|
|
+ Toast.LENGTH_LONG).show();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String createInformationStringFromRecord(Record rec) {
|
|
|
+ String message = "id: " + rec.getId() + "\n" + "attack_id: "
|
|
|
+ + rec.getAttack_id() + "\n" + "protocol: "
|
|
|
+ + rec.getProtocol() + "\n" + "type: " + rec.getType()
|
|
|
+ + "\n" + "externalIP: " + rec.getExternalIP() + "\n"
|
|
|
+ + "localIP: " + rec.getLocalIP() + "\n"
|
|
|
+ + "local port: " + rec.getLocalPort() + "\n"
|
|
|
+ + "remoteIP: " + rec.getRemoteIP() + "\n" + "BSSID: "
|
|
|
+ + rec.getBSSID() + "\n" + "SSID: " + rec.getSSID()
|
|
|
+ + "\n" + "latitude: " + rec.getLatitude() + "\n"
|
|
|
+ + "longitude: " + rec.getLongitude() + "\n"
|
|
|
+ + "accuracy: " + rec.getAccuracy() + "\n" + "packet: "
|
|
|
+ + rec.getPacket() + "\n"
|
|
|
+ + getDateAsString(rec.getTimestamp()) + "";
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("SimpleDateFormat")
|
|
|
+ private String getDateAsString(long timeStamp) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
|
|
+ Date netDate = (new Date(timeStamp));
|
|
|
+ return sdf.format(netDate);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ return "xx";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
+ super.onCreateOptionsMenu(menu, inflater);
|
|
|
+ if(this.showFilterButton){
|
|
|
+ for(String title : this.filterTitles()){
|
|
|
+ MenuItem item = menu.add(title);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
+ String title = item.getTitle().toString();
|
|
|
+
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
|
|
|
+ this.openTimestampToFilterDialog();
|
|
|
+ }
|
|
|
+ if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
|
|
|
+ this.openTimestampFromFilterDialog();
|
|
|
+ }
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void openBSSIDFilterDialog(){
|
|
|
+ Intent intent = this.getActivity().getIntent();
|
|
|
+ intent.putExtra(ChecklistDialog.DIALOG_TITLE_KEY, FILTER_MENU_TITLE_BSSID);
|
|
|
+ intent.putExtra(ChecklistDialog.DIALOG_IS_MULTIPLECHOICE_KEY, true);
|
|
|
+
|
|
|
+ intent.putStringArrayListExtra(ChecklistDialog.DIALOG_TITLE_ARRAY_KEY, this.bssids());
|
|
|
+ intent.putStringArrayListExtra(ChecklistDialog.DIALOG_MULTIPLECHOICE_SELECTED_KEY, this.selectedBSSIDs());
|
|
|
+
|
|
|
+ ChecklistDialog newFragment = new ChecklistDialog();
|
|
|
+ newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_BSSID);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void openESSIDFilterDialog(){
|
|
|
+
|
|
|
+ Intent intent = this.getActivity().getIntent();
|
|
|
+ intent.putExtra(ChecklistDialog.DIALOG_TITLE_KEY, FILTER_MENU_TITLE_ESSID);
|
|
|
+ intent.putExtra(ChecklistDialog.DIALOG_IS_MULTIPLECHOICE_KEY, true);
|
|
|
+
|
|
|
+ intent.putStringArrayListExtra(ChecklistDialog.DIALOG_TITLE_ARRAY_KEY, this.essids());
|
|
|
+ intent.putStringArrayListExtra(ChecklistDialog.DIALOG_MULTIPLECHOICE_SELECTED_KEY, this.selectedESSIDs());
|
|
|
+
|
|
|
+ ChecklistDialog newFragment = new ChecklistDialog();
|
|
|
+ newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_ESSID);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void openProtocolsFilterDialog(){
|
|
|
+ Intent intent = this.getActivity().getIntent();
|
|
|
+ intent.putExtra(ChecklistDialog.DIALOG_TITLE_KEY, FILTER_MENU_TITLE_PROTOCOLS);
|
|
|
+ intent.putExtra(ChecklistDialog.DIALOG_IS_MULTIPLECHOICE_KEY, true);
|
|
|
+
|
|
|
+ intent.putStringArrayListExtra(ChecklistDialog.DIALOG_TITLE_ARRAY_KEY, this.protocolTitles());
|
|
|
+ intent.putStringArrayListExtra(ChecklistDialog.DIALOG_MULTIPLECHOICE_SELECTED_KEY, this.selectedProtocols());
|
|
|
+
|
|
|
+ ChecklistDialog newFragment = new ChecklistDialog();
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void openTimestampToFilterDialog(){
|
|
|
+ this.wasBelowTimePicker = true;
|
|
|
+ DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
|
|
|
+ newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void openSortingDialog(){
|
|
|
+ Intent intent = this.getActivity().getIntent();
|
|
|
+ intent.putExtra(ChecklistDialog.DIALOG_TITLE_KEY, FILTER_MENU_TITLE_SORTING);
|
|
|
+ intent.putExtra(ChecklistDialog.DIALOG_IS_MULTIPLECHOICE_KEY, false);
|
|
|
+
|
|
|
+ intent.putStringArrayListExtra(ChecklistDialog.DIALOG_TITLE_ARRAY_KEY, this.sortTypeTtiles());
|
|
|
+ intent.putExtra(ChecklistDialog.DIALOG_SELECTED_INDEX_KEY, this.filter.sorttype.getValue());
|
|
|
+
|
|
|
+ ChecklistDialog newFragment = new ChecklistDialog();
|
|
|
+ newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void onDialogPositiveClick(ChecklistDialog dialog) {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ String title = dialog.getTitle();
|
|
|
+ if(title.equals(FILTER_MENU_TITLE_BSSID)){
|
|
|
+ this.filter.setBSSIDs(dialog.getSelectedItemTitles());
|
|
|
+ }
|
|
|
+ if(title.equals(FILTER_MENU_TITLE_ESSID)){
|
|
|
+ this.filter.setESSIDs(dialog.getSelectedItemTitles());
|
|
|
+ }
|
|
|
+ if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
|
|
|
+ this.filter.setProtocols(dialog.getSelectedItemTitles());
|
|
|
+ }
|
|
|
+ if(title.equals(FILTER_MENU_TITLE_SORTING)){
|
|
|
+ ArrayList<String> titles = dialog.getSelectedItemTitles();
|
|
|
+ String t = titles.get(0);
|
|
|
+ int sortType = this.sortTypeTtiles().indexOf(t);
|
|
|
+ this.filter.setSorttype(SortType.values()[sortType]);
|
|
|
+ }
|
|
|
+ this.populateListViewFromDB(this.listView);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onDialogNegativeClick(ChecklistDialog dialog) {
|
|
|
+ // nothing in here
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @SuppressLint("SimpleDateFormat")
|
|
|
+ private String getDateAsString(long timeStamp) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
|
|
+ Date netDate = (new Date(timeStamp));
|
|
|
+ return sdf.format(netDate);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ return "xx";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isShowFilterButton() {
|
|
|
+ return showFilterButton;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setShowFilterButton(boolean showFilterButton) {
|
|
|
+ this.showFilterButton = showFilterButton;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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 ArrayList<String> selectedProtocols(){
|
|
|
+ return this.filter.protocols;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ArrayList<String> sortTypeTtiles(){
|
|
|
+ ArrayList<String> titles = new ArrayList<String>();
|
|
|
+ titles.add("Time");
|
|
|
+ titles.add("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 ArrayList<String> bssids(){
|
|
|
+ ArrayList<String> titles = new ArrayList<String>();
|
|
|
+ ArrayList<String> records = dbh.getUniqueBSSIDRecords();
|
|
|
+
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+ public ArrayList<String> selectedBSSIDs(){
|
|
|
+ return this.filter.BSSIDs;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public ArrayList<String> essids(){
|
|
|
+ ArrayList<String> titles = new ArrayList<String>();
|
|
|
+ ArrayList<String> records = dbh.getUniqueESSIDRecords();
|
|
|
+
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+ public ArrayList<String> selectedESSIDs(){
|
|
|
+ return this.filter.ESSIDs;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private ArrayList<String> filterTitles(){
|
|
|
+ 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);
|
|
|
+ titles.add(FILTER_MENU_TITLE_SORTING);
|
|
|
+ titles.add(FILTER_MENU_TITLE_REMOVE);
|
|
|
+ return titles;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /*****************************
|
|
|
+ *
|
|
|
+ * TEST
|
|
|
+ *
|
|
|
+ * ***************************/
|
|
|
+
|
|
|
+ private void addRecordToDB() {
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+
|
|
|
+ int maxProtocolsIndex = this.getResources().getStringArray(
|
|
|
+ R.array.protocols).length;
|
|
|
+
|
|
|
+ int numberofRecords = (int) (Math.random() * (50 - 10));
|
|
|
+ for (int i = 0; i < numberofRecords; i++) {
|
|
|
+ Record record = new Record();
|
|
|
+ record.setBSSID("BSSID: " + i);
|
|
|
+ record.setSSID("SSID: w" + i);
|
|
|
+ record.setTimestamp(cal.getTimeInMillis()
|
|
|
+ + ((i * 60 * 60 * 60 * 24) * 1000));
|
|
|
+
|
|
|
+ int index = i % maxProtocolsIndex;
|
|
|
+ String protocolName = this.getResources().getStringArray(
|
|
|
+ R.array.protocols)[index];
|
|
|
+
|
|
|
+ record.setProtocol(protocolName);
|
|
|
+ record.setId(i);
|
|
|
+ record.setAttack_id(i);
|
|
|
+ try {
|
|
|
+ InetAddress localIP = InetAddress.getByAddress("Digga",
|
|
|
+ new byte[] { 127, 0, 0, 1 }); // .getByName("192.168.2.1");
|
|
|
+ record.setLocalIP(localIP);
|
|
|
+ record.setRemoteIP(InetAddress.getByAddress("Digga",
|
|
|
+ new byte[] { 127, 1, 1, 1 }));
|
|
|
+ record.setType(TYPE.SEND);
|
|
|
+ } catch (UnknownHostException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ dbh.addRecord(record);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onDateTimePickerPositiveClick(DateTimeDialogFragment dialog) {
|
|
|
+ if(this.wasBelowTimePicker){
|
|
|
+ this.filter.setBelowTimestamp(dialog.getDate());
|
|
|
+ } else {
|
|
|
+ this.filter.setAboveTimestamp(dialog.getDate());
|
|
|
+ }
|
|
|
+ this.populateListViewFromDB(listView);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog) {
|
|
|
+ // nothing in here
|
|
|
+ }
|
|
|
+
|
|
|
+}
|