|
@@ -6,6 +6,7 @@ import android.content.Context;
|
|
|
import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.content.IntentFilter;
|
|
|
+import android.content.SharedPreferences;
|
|
|
import android.net.wifi.WifiManager;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
|
@@ -13,11 +14,15 @@ import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.widget.CompoundButton;
|
|
|
+import android.widget.ImageView;
|
|
|
import android.widget.Switch;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
|
import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
|
+import de.tudarmstadt.informatik.hostage.dao.ProfileManager;
|
|
|
+import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
|
|
|
+import de.tudarmstadt.informatik.hostage.model.Profile;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.fragment.opengl.ThreatIndicatorGLRenderer;
|
|
|
|
|
@@ -34,6 +39,7 @@ public class HomeFragment extends Fragment {
|
|
|
private TextView mHomeTextAttacks;
|
|
|
private TextView mHomeTextProfile;
|
|
|
private TextView mHomeTextProfileHeader;
|
|
|
+ private ImageView mHomeProfileImage;
|
|
|
|
|
|
private View rootView;
|
|
|
private BroadcastReceiver mReceiver;
|
|
@@ -41,6 +47,12 @@ public class HomeFragment extends Fragment {
|
|
|
private CompoundButton.OnCheckedChangeListener switchChangeListener = null;
|
|
|
|
|
|
private int defaultTextColor;
|
|
|
+ private ProfileManager mProfileManager;
|
|
|
+
|
|
|
+ private SharedPreferences mConnectionInfo;
|
|
|
+ private UglyDbHelper dbh;
|
|
|
+
|
|
|
+ private static int DANGER_LEVEL= 0;
|
|
|
|
|
|
private void assignViews() {
|
|
|
mHomeSwitchConnection = (Switch) rootView.findViewById(R.id.home_switch_connection);
|
|
@@ -49,6 +61,7 @@ public class HomeFragment extends Fragment {
|
|
|
mHomeTextAttacks = (TextView) rootView.findViewById(R.id.home_text_attacks);
|
|
|
mHomeTextProfile = (TextView) rootView.findViewById(R.id.home_text_profile);
|
|
|
mHomeTextProfileHeader = (TextView) rootView.findViewById(R.id.home_text_profile_header);
|
|
|
+ mHomeProfileImage = (ImageView) rootView.findViewById(R.id.home_image_profile);
|
|
|
}
|
|
|
|
|
|
private void registerBroadcastReceiver(){
|
|
@@ -66,45 +79,44 @@ public class HomeFragment extends Fragment {
|
|
|
//}
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
- /*IntentFilter intentFilter = new IntentFilter();
|
|
|
- intentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
|
|
|
- intentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
|
|
|
- intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
|
|
- intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);*/
|
|
|
-
|
|
|
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, new IntentFilter(getString(R.string.broadcast)));
|
|
|
- //getActivity().registerReceiver(mReceiver, intentFilter);
|
|
|
}
|
|
|
|
|
|
public HomeFragment(){}
|
|
|
|
|
|
- public void setStateNotActive(){
|
|
|
+ public void setStateNotActive(boolean initial){
|
|
|
mHomeTextName.setTextColor(getResources().getColor(R.color.light_grey));
|
|
|
mHomeTextSecurity.setTextColor(getResources().getColor(R.color.light_grey));
|
|
|
mHomeTextAttacks.setTextColor(getResources().getColor(R.color.light_grey));
|
|
|
mHomeTextProfile.setTextColor(getResources().getColor(R.color.light_grey));
|
|
|
mHomeTextProfileHeader.setTextColor(getResources().getColor(R.color.light_grey));
|
|
|
-
|
|
|
- ThreatIndicatorGLRenderer.setThreatLevel(ThreatIndicatorGLRenderer.kThreatLevelNotMonitoring);
|
|
|
+
|
|
|
+ if(!initial){
|
|
|
+ ThreatIndicatorGLRenderer.setThreatLevel(ThreatIndicatorGLRenderer.kThreatLevelNotMonitoring);
|
|
|
+ }
|
|
|
|
|
|
mHomeSwitchConnection.setChecked(false);
|
|
|
}
|
|
|
|
|
|
+ public void setStateNotActive(){
|
|
|
+ setStateNotActive(false);
|
|
|
+ }
|
|
|
+
|
|
|
public void setStateActive(){
|
|
|
- mHomeTextAttacks.setText("0 attacks recorded");
|
|
|
- mHomeTextSecurity.setText("Secure");
|
|
|
- mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_dark_green));
|
|
|
- mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_dark_green));
|
|
|
+ setStateActive(false);
|
|
|
+ }
|
|
|
|
|
|
+ public void setStateActive(boolean initial){
|
|
|
mHomeTextAttacks.setVisibility(View.VISIBLE);
|
|
|
mHomeTextSecurity.setVisibility(View.VISIBLE);
|
|
|
|
|
|
mHomeTextName.setTextColor(defaultTextColor);
|
|
|
mHomeTextProfile.setTextColor(defaultTextColor);
|
|
|
mHomeTextProfileHeader.setTextColor(defaultTextColor);
|
|
|
-
|
|
|
- ThreatIndicatorGLRenderer.setThreatLevel(ThreatIndicatorGLRenderer.kThreatLevelNoThreat);
|
|
|
+
|
|
|
+ if(!initial){
|
|
|
+ ThreatIndicatorGLRenderer.setThreatLevel(ThreatIndicatorGLRenderer.kThreatLevelNoThreat);
|
|
|
+ }
|
|
|
|
|
|
mHomeSwitchConnection.setChecked(true);
|
|
|
}
|
|
@@ -124,14 +136,76 @@ public class HomeFragment extends Fragment {
|
|
|
}
|
|
|
|
|
|
public void updateUI(){
|
|
|
- if(!HelperUtils.isWifiConnected(getActivity())){
|
|
|
+ Profile profile = mProfileManager.getCurrentActivatedProfile();
|
|
|
+ if(profile != null){
|
|
|
+ mHomeTextProfile.setText(profile.mLabel);
|
|
|
+ mHomeProfileImage.setImageBitmap(profile.getIconBitmap());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(HelperUtils.isWifiConnected(getActivity())){
|
|
|
+ setStateConnected();
|
|
|
+ mHomeTextName.setText(mConnectionInfo.getString(getString(R.string.connection_info_ssid), ""));
|
|
|
+ }
|
|
|
+
|
|
|
+ int dangerLevel = 0;
|
|
|
+ boolean hasActiveListeners = false;
|
|
|
+ int totalAttacks = 0;
|
|
|
+ int totalLogged = 0;
|
|
|
+
|
|
|
+ if(MainActivity.getInstance().isServiceBound()){
|
|
|
+ for(String protocol: getResources().getStringArray(R.array.protocols)){
|
|
|
+ if(MainActivity.getInstance().getHoneyService().isRunning(protocol)){
|
|
|
+ hasActiveListeners = true;
|
|
|
+ int attacks = MainActivity.getInstance().getHoneyService().getNumberOfActiveConnections(protocol);
|
|
|
+
|
|
|
+ if(attacks == 0){
|
|
|
+ int log_attacks = dbh.numBssidSeen(protocol, mConnectionInfo.getString(getString(R.string.connection_info_bssid), null));
|
|
|
+ totalLogged += log_attacks;
|
|
|
+
|
|
|
+ if(log_attacks > 0){
|
|
|
+ DANGER_LEVEL = Math.max(1, DANGER_LEVEL);
|
|
|
+ } else {
|
|
|
+ DANGER_LEVEL = Math.max(0, DANGER_LEVEL);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ totalAttacks += attacks;
|
|
|
+ DANGER_LEVEL = Math.max(2, DANGER_LEVEL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(hasActiveListeners){
|
|
|
+ setStateActive(true);
|
|
|
+
|
|
|
+ if(DANGER_LEVEL == 0){
|
|
|
+ mHomeTextAttacks.setText("0 attacks recorded");
|
|
|
+ mHomeTextSecurity.setText("Secure");
|
|
|
+ mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_dark_green));
|
|
|
+ mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_dark_green));
|
|
|
+ } else if(DANGER_LEVEL == 1){
|
|
|
+ mHomeTextAttacks.setText(totalLogged + (totalLogged == 1 ? " attack" : " attacks") + " logged");
|
|
|
+ mHomeTextSecurity.setText("Insecure");
|
|
|
+ mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_yellow));
|
|
|
+ mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_yellow));
|
|
|
+ } else if(DANGER_LEVEL == 2){
|
|
|
+ mHomeTextAttacks.setText(totalAttacks + (totalAttacks == 1 ? " attack" : " attacks") + " recorded");
|
|
|
+ mHomeTextSecurity.setText("Insecure");
|
|
|
+ mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_red));
|
|
|
+ mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_red));
|
|
|
+ }
|
|
|
+
|
|
|
+ ThreatIndicatorGLRenderer.setThreatLevel(DANGER_LEVEL + 1);
|
|
|
+ } else {
|
|
|
mHomeSwitchConnection.setOnCheckedChangeListener(null);
|
|
|
- setStateNotConnected();
|
|
|
setStateNotActive();
|
|
|
+ DANGER_LEVEL = 0;
|
|
|
+
|
|
|
+ if(!HelperUtils.isWifiConnected(getActivity())){
|
|
|
+ setStateNotConnected();
|
|
|
+ }
|
|
|
+
|
|
|
mHomeSwitchConnection.setOnCheckedChangeListener(switchChangeListener);
|
|
|
- } else {
|
|
|
- setStateConnected();
|
|
|
- mHomeTextName.setText(HelperUtils.getSSID(getActivity()));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -141,12 +215,17 @@ public class HomeFragment extends Fragment {
|
|
|
|
|
|
super.onCreateView(inflater, container, savedInstanceState);
|
|
|
|
|
|
+ dbh = new UglyDbHelper(getActivity());
|
|
|
+
|
|
|
+ mProfileManager = ProfileManager.getInstance();
|
|
|
+ mConnectionInfo = getActivity().getSharedPreferences(getString(R.string.connection_info), Context.MODE_PRIVATE);
|
|
|
+
|
|
|
rootView = inflater.inflate(R.layout.fragment_home, container, false);
|
|
|
assignViews();
|
|
|
|
|
|
defaultTextColor = mHomeTextName.getCurrentTextColor();
|
|
|
|
|
|
- setStateNotActive();
|
|
|
+ setStateNotActive(true);
|
|
|
setStateNotConnected();
|
|
|
|
|
|
registerBroadcastReceiver();
|
|
@@ -155,17 +234,6 @@ public class HomeFragment extends Fragment {
|
|
|
|
|
|
final String[] protocols = getResources().getStringArray(R.array.protocols);
|
|
|
|
|
|
- if(MainActivity.getInstance().getHoneyService() == null){
|
|
|
- // do nothing
|
|
|
- }
|
|
|
- else {
|
|
|
- for(String protocol: protocols){
|
|
|
- if (MainActivity.getInstance().getHoneyService().isRunning(protocol)) {
|
|
|
- setStateActive();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
mHomeSwitchConnection = (Switch) rootView.findViewById(R.id.home_switch_connection);
|
|
|
|
|
|
if(switchChangeListener == null){
|