|
@@ -3,6 +3,7 @@ package de.tudarmstadt.informatik.hostage.ui;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
+import java.util.Calendar;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
|
|
@@ -12,6 +13,8 @@ import de.tudarmstadt.informatik.hostage.logging.SQLLogger;
|
|
import android.annotation.SuppressLint;
|
|
import android.annotation.SuppressLint;
|
|
import android.app.Activity;
|
|
import android.app.Activity;
|
|
import android.app.AlertDialog;
|
|
import android.app.AlertDialog;
|
|
|
|
+import android.app.DatePickerDialog;
|
|
|
|
+import android.app.Dialog;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.content.DialogInterface;
|
|
import android.content.DialogInterface;
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
@@ -25,16 +28,19 @@ import android.view.Gravity;
|
|
import android.view.Menu;
|
|
import android.view.Menu;
|
|
import android.view.MenuItem;
|
|
import android.view.MenuItem;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
|
+import android.widget.DatePicker;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TableLayout;
|
|
import android.widget.TableLayout;
|
|
import android.widget.TableRow;
|
|
import android.widget.TableRow;
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
|
+import android.widget.TimePicker;
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
|
|
|
|
public class ViewLog extends Activity {
|
|
public class ViewLog extends Activity {
|
|
|
|
|
|
DatabaseHandler dbh;
|
|
DatabaseHandler dbh;
|
|
- private final Context context = this;
|
|
|
|
|
|
+ private final Context context = this;
|
|
|
|
+ private final SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
|
|
|
|
|
|
@Override
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@@ -49,126 +55,240 @@ public class ViewLog extends Activity {
|
|
getMenuInflater().inflate(R.menu.main, menu);
|
|
getMenuInflater().inflate(R.menu.main, menu);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
- // Handle item selection
|
|
|
|
- switch (item.getItemId()) {
|
|
|
|
- case R.id.action_settings:
|
|
|
|
- startActivity(new Intent(this, SettingsActivity.class));
|
|
|
|
- default:
|
|
|
|
- return super.onOptionsItemSelected(item);
|
|
|
|
- }
|
|
|
|
|
|
+ // Handle item selection
|
|
|
|
+ switch (item.getItemId()) {
|
|
|
|
+ case R.id.action_settings:
|
|
|
|
+ startActivity(new Intent(this, SettingsActivity.class));
|
|
|
|
+ default:
|
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- public void exportDatabase(View view){
|
|
|
|
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
- builder.setTitle(R.string.export_dialog_title);
|
|
|
|
- builder.setItems(R.array.format, new DialogInterface.OnClickListener() {
|
|
|
|
- public void onClick(DialogInterface dialog, int position) {
|
|
|
|
- SQLLogger logger = new SQLLogger(context);
|
|
|
|
- logger.exportDatabase(position);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- builder.create();
|
|
|
|
- builder.show();
|
|
|
|
|
|
+ public void exportDatabase(View view) {
|
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
+ builder.setTitle(R.string.export_dialog_title);
|
|
|
|
+ builder.setItems(R.array.format, new DialogInterface.OnClickListener() {
|
|
|
|
+ public void onClick(DialogInterface dialog, int position) {
|
|
|
|
+ SQLLogger logger = new SQLLogger(context);
|
|
|
|
+ logger.exportDatabase(position);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ builder.create();
|
|
|
|
+ builder.show();
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void uploadDatabase(View view){
|
|
|
|
|
|
+
|
|
|
|
+ public void uploadDatabase(View view) {
|
|
SQLLogger log = new SQLLogger(this);
|
|
SQLLogger log = new SQLLogger(this);
|
|
log.uploadDatabase();
|
|
log.uploadDatabase();
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void showLog(View view){
|
|
|
|
|
|
+
|
|
|
|
+ public void showLog(View view) {
|
|
startActivity(new Intent(this, ViewLogTable.class));
|
|
startActivity(new Intent(this, ViewLogTable.class));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@SuppressLint("NewApi")
|
|
@SuppressLint("NewApi")
|
|
- public void deleteLog(View view){
|
|
|
|
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
-
|
|
|
|
- builder.setMessage(R.string.dialog_clear_database)
|
|
|
|
- .setPositiveButton(R.string.clear, new DialogInterface.OnClickListener() {
|
|
|
|
- public void onClick(DialogInterface dialog, int id) {
|
|
|
|
- // Clear all Data
|
|
|
|
- dbh.clearData();
|
|
|
|
- SharedPreferences pref = getSharedPreferences(MainActivity.SESSION_DATA, Context.MODE_PRIVATE);
|
|
|
|
- Editor editor = pref.edit();
|
|
|
|
- editor.clear();
|
|
|
|
- editor.commit();
|
|
|
|
- Toast.makeText(getApplicationContext(), "Database cleared!", Toast.LENGTH_SHORT).show();
|
|
|
|
- // Recreate the activity
|
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
- recreate();
|
|
|
|
- } else{
|
|
|
|
- Intent intent = getIntent();
|
|
|
|
- finish();
|
|
|
|
- startActivity(intent);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
- public void onClick(DialogInterface dialog, int id) {
|
|
|
|
- // User cancelled the dialog
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- // Create the AlertDialog object
|
|
|
|
- builder.create();
|
|
|
|
- builder.show();
|
|
|
|
|
|
+ public void deleteLog(View view) {
|
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
+
|
|
|
|
+ builder.setTitle(R.string.delete_dialog_title);
|
|
|
|
+ builder.setItems(R.array.delete_criteria,
|
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
|
+ public void onClick(DialogInterface dialog, int position) {
|
|
|
|
+ switch (position) {
|
|
|
|
+ case 0:
|
|
|
|
+ deleteByBSSID();
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ deleteByDate();
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ deleteAll();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ builder.create();
|
|
|
|
+ builder.show();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void deleteByDate() {
|
|
|
|
+ showDialog(0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private DatePickerDialog.OnDateSetListener pDateSetListener = new DatePickerDialog.OnDateSetListener() {
|
|
|
|
+
|
|
|
|
+ public void onDateSet(DatePicker view, int year, int monthOfYear,
|
|
|
|
+ int dayOfMonth) {
|
|
|
|
+ deleteByDate(year, monthOfYear, dayOfMonth);
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected Dialog onCreateDialog(int id) {
|
|
|
|
+ switch (id) {
|
|
|
|
+ case 0:
|
|
|
|
+ final Calendar cal = Calendar.getInstance();
|
|
|
|
+ int pYear = cal.get(Calendar.YEAR);
|
|
|
|
+ int pMonth = cal.get(Calendar.MONTH);
|
|
|
|
+ int pDay = cal.get(Calendar.DAY_OF_MONTH);
|
|
|
|
+ return new DatePickerDialog(this, pDateSetListener, pYear, pMonth,
|
|
|
|
+ pDay);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void deleteByDate(int year, int monthOfYear, int dayOfMonth) {
|
|
|
|
+ TimePicker timePicker = new TimePicker(context);
|
|
|
|
+ final Calendar calendar = Calendar.getInstance();
|
|
|
|
+ calendar.set(year, monthOfYear, dayOfMonth,
|
|
|
|
+ timePicker.getCurrentHour(), timePicker.getCurrentMinute(), 0);
|
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
+ builder.setTitle(R.string.dialog_clear_database_date)
|
|
|
|
+ .setMessage(sdf.format(calendar.getTime()))
|
|
|
|
+ .setPositiveButton(R.string.delete,
|
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
|
+ @SuppressLint("NewApi")
|
|
|
|
+ public void onClick(DialogInterface dialog, int id) {
|
|
|
|
+ long time = calendar.getTimeInMillis();
|
|
|
|
+ // Delete Data
|
|
|
|
+ dbh.deleteByDate(time);
|
|
|
|
+ Toast.makeText(getApplicationContext(),
|
|
|
|
+ "Data sets deleted!",
|
|
|
|
+ Toast.LENGTH_SHORT).show();
|
|
|
|
+ // Recreate the activity
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
+ recreate();
|
|
|
|
+ } else {
|
|
|
|
+ Intent intent = getIntent();
|
|
|
|
+ finish();
|
|
|
|
+ startActivity(intent);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .setNegativeButton(R.string.cancel,
|
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
|
+ public void onClick(DialogInterface dialog, int id) {
|
|
|
|
+ // User cancelled the dialog
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ // Create the AlertDialog object
|
|
|
|
+ builder.create();
|
|
|
|
+ builder.show();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void deleteByBSSID() {
|
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
+ final String[] bssidArray = dbh.getAllBSSIDS();
|
|
|
|
+ builder.setTitle(R.string.delete_dialog_title);
|
|
|
|
+ builder.setItems(bssidArray, new DialogInterface.OnClickListener() {
|
|
|
|
+ @SuppressLint("NewApi")
|
|
|
|
+ public void onClick(DialogInterface dialog, int position) {
|
|
|
|
+ dbh.deleteByBSSID(bssidArray[position]);
|
|
|
|
+ Toast.makeText(
|
|
|
|
+ getApplicationContext(),
|
|
|
|
+ "All entries with bssid '" + bssidArray[position]
|
|
|
|
+ + "' deleted.", Toast.LENGTH_SHORT).show();
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
+ recreate();
|
|
|
|
+ } else {
|
|
|
|
+ Intent intent = getIntent();
|
|
|
|
+ finish();
|
|
|
|
+ startActivity(intent);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ builder.create();
|
|
|
|
+ builder.show();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void deleteAll() {
|
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
+ builder.setMessage(R.string.dialog_clear_database)
|
|
|
|
+ .setPositiveButton(R.string.clear,
|
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
|
+ @SuppressLint("NewApi")
|
|
|
|
+ public void onClick(DialogInterface dialog, int id) {
|
|
|
|
+ // Clear all Data
|
|
|
|
+ dbh.clearData();
|
|
|
|
+ Toast.makeText(getApplicationContext(),
|
|
|
|
+ "Database cleared!", Toast.LENGTH_SHORT)
|
|
|
|
+ .show();
|
|
|
|
+ // Recreate the activity
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
+ recreate();
|
|
|
|
+ } else {
|
|
|
|
+ Intent intent = getIntent();
|
|
|
|
+ finish();
|
|
|
|
+ startActivity(intent);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .setNegativeButton(R.string.cancel,
|
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
|
+ public void onClick(DialogInterface dialog, int id) {
|
|
|
|
+ // User cancelled the dialog
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ // Create the AlertDialog object
|
|
|
|
+ builder.create();
|
|
|
|
+ builder.show();
|
|
}
|
|
}
|
|
|
|
|
|
private void initStatistic() {
|
|
private void initStatistic() {
|
|
TableLayout table = (TableLayout) findViewById(R.id.layoutContainer);
|
|
TableLayout table = (TableLayout) findViewById(R.id.layoutContainer);
|
|
|
|
|
|
-
|
|
|
|
ArrayList<String> protocols = new ArrayList<String>();
|
|
ArrayList<String> protocols = new ArrayList<String>();
|
|
protocols.add("Total");
|
|
protocols.add("Total");
|
|
protocols.addAll(Arrays.asList(getResources().getStringArray(
|
|
protocols.addAll(Arrays.asList(getResources().getStringArray(
|
|
R.array.protocols)));
|
|
R.array.protocols)));
|
|
-
|
|
|
|
|
|
+
|
|
TableRow tableHeader = new TableRow(this);
|
|
TableRow tableHeader = new TableRow(this);
|
|
TableRow tableContent = new TableRow(this);
|
|
TableRow tableContent = new TableRow(this);
|
|
tableHeader.setBackgroundResource(R.color.dark_grey);
|
|
tableHeader.setBackgroundResource(R.color.dark_grey);
|
|
tableContent.setBackgroundResource(R.color.light_grey);
|
|
tableContent.setBackgroundResource(R.color.light_grey);
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
for (String protocol : protocols) {
|
|
for (String protocol : protocols) {
|
|
TextView protocolName = new TextView(this);
|
|
TextView protocolName = new TextView(this);
|
|
protocolName.setText(protocol);
|
|
protocolName.setText(protocol);
|
|
- protocolName.setTextAppearance(this, android.R.style.TextAppearance_Medium);
|
|
|
|
|
|
+ protocolName.setTextAppearance(this,
|
|
|
|
+ android.R.style.TextAppearance_Medium);
|
|
protocolName.setPadding(3, 0, 3, 0);
|
|
protocolName.setPadding(3, 0, 3, 0);
|
|
tableHeader.addView(protocolName);
|
|
tableHeader.addView(protocolName);
|
|
TextView value = new TextView(this);
|
|
TextView value = new TextView(this);
|
|
value.setTextAppearance(this, android.R.style.TextAppearance_Medium);
|
|
value.setTextAppearance(this, android.R.style.TextAppearance_Medium);
|
|
value.setGravity(Gravity.CENTER);
|
|
value.setGravity(Gravity.CENTER);
|
|
tableContent.addView(value);
|
|
tableContent.addView(value);
|
|
- if(protocol.equals("Total")){
|
|
|
|
|
|
+ if (protocol.equals("Total")) {
|
|
value.setText("" + dbh.getAttackCount());
|
|
value.setText("" + dbh.getAttackCount());
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
value.setText("" + dbh.getAttackPerProtokolCount(protocol));
|
|
value.setText("" + dbh.getAttackPerProtokolCount(protocol));
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
table.addView(tableHeader);
|
|
table.addView(tableHeader);
|
|
- table.addView(tableContent);
|
|
|
|
-
|
|
|
|
|
|
+ table.addView(tableContent);
|
|
|
|
+
|
|
setFirstAndLastAttack();
|
|
setFirstAndLastAttack();
|
|
}
|
|
}
|
|
-
|
|
|
|
- private void setFirstAndLastAttack(){
|
|
|
|
|
|
+
|
|
|
|
+ private void setFirstAndLastAttack() {
|
|
int attackCount = dbh.getRecordCount();
|
|
int attackCount = dbh.getRecordCount();
|
|
- if(attackCount > 0){
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
|
|
|
|
- Date resultdate = new Date(dbh.getRecordOfAttackId(0).getTimestamp());
|
|
|
|
- TextView text = (TextView) findViewById(R.id.textFirstAttackValue);
|
|
|
|
- text.setText(sdf.format(resultdate));
|
|
|
|
- text = (TextView) findViewById(R.id.textLastAttackValue);
|
|
|
|
- resultdate = new Date(dbh.getRecordOfAttackId(dbh.getAttackCount() - 1).getTimestamp());
|
|
|
|
- text.setText(sdf.format(resultdate));
|
|
|
|
|
|
+ if (attackCount > 0) {
|
|
|
|
+
|
|
|
|
+ Date resultdate = new Date(dbh.getRecordOfAttackId(0)
|
|
|
|
+ .getTimestamp());
|
|
|
|
+ TextView text = (TextView) findViewById(R.id.textFirstAttackValue);
|
|
|
|
+ text.setText(sdf.format(resultdate));
|
|
|
|
+ text = (TextView) findViewById(R.id.textLastAttackValue);
|
|
|
|
+ resultdate = new Date(dbh.getRecordOfAttackId(
|
|
|
|
+ dbh.getAttackCount() - 1).getTimestamp());
|
|
|
|
+ text.setText(sdf.format(resultdate));
|
|
} else {
|
|
} else {
|
|
- TextView text = (TextView) findViewById(R.id.textFirstAttackValue);
|
|
|
|
- text.setText("-");
|
|
|
|
- text = (TextView) findViewById(R.id.textLastAttackValue);
|
|
|
|
- text.setText("-");
|
|
|
|
|
|
+ TextView text = (TextView) findViewById(R.id.textFirstAttackValue);
|
|
|
|
+ text.setText("-");
|
|
|
|
+ text = (TextView) findViewById(R.id.textLastAttackValue);
|
|
|
|
+ text.setText("-");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|