|
@@ -4,10 +4,12 @@ import java.util.ArrayList;
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
import android.app.Activity;
|
|
|
+import android.app.AlertDialog;
|
|
|
import android.app.Fragment;
|
|
|
import android.app.FragmentManager;
|
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.content.IntentFilter;
|
|
|
import android.content.SharedPreferences;
|
|
@@ -25,7 +27,6 @@ import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
|
import de.tudarmstadt.informatik.hostage.dao.ProfileManager;
|
|
|
import de.tudarmstadt.informatik.hostage.model.Profile;
|
|
|
import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
|
|
|
-import de.tudarmstadt.informatik.hostage.sync.tracing.TracingSyncActivity;
|
|
|
import de.tudarmstadt.informatik.hostage.ui.LogFilter;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.fragment.opengl.ThreatIndicatorGLRenderer;
|
|
@@ -262,91 +263,78 @@ public class HomeFragment extends Fragment {
|
|
|
if (switchChangeListener == null) {
|
|
|
switchChangeListener = new CompoundButton.OnCheckedChangeListener() {
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
- startActivity(new Intent(getActivity(), TracingSyncActivity.class));
|
|
|
- // if (!HelperUtils.isWifiConnected(getActivity())) {
|
|
|
- // new
|
|
|
- // AlertDialog.Builder(getActivity()).setTitle(R.string.information).setMessage(R.string.wifi_not_connected_msg)
|
|
|
- // .setPositiveButton(android.R.string.ok, new
|
|
|
- // DialogInterface.OnClickListener() {
|
|
|
- // public void onClick(DialogInterface dialog, int which) {
|
|
|
- //
|
|
|
- // }
|
|
|
- // }).setIcon(android.R.drawable.ic_dialog_info).show();
|
|
|
- //
|
|
|
- // setStateNotActive();
|
|
|
- // setStateNotConnected();
|
|
|
- // } else {
|
|
|
- // if (isChecked) {
|
|
|
- // boolean protocolActivated = false;
|
|
|
- // if
|
|
|
- // (ProfileManager.getInstance().getCurrentActivatedProfile()
|
|
|
- // == null) {
|
|
|
- // for (String protocol :
|
|
|
- // getResources().getStringArray(R.array.protocols)) {
|
|
|
- // if
|
|
|
- // (!MainActivity.getInstance().getHostageService().isRunning(protocol))
|
|
|
- // {
|
|
|
- // MainActivity.getInstance().getHostageService().startListener(protocol);
|
|
|
- // protocolActivated = true;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // } else {
|
|
|
- // ProfileManager profileManager =
|
|
|
- // ProfileManager.getInstance();
|
|
|
- //
|
|
|
- // if (profileManager.isRandomActive()) {
|
|
|
- // profileManager.randomizeProtocols(profileManager.getRandomProfile());
|
|
|
- // }
|
|
|
- //
|
|
|
- // for (String protocol :
|
|
|
- // profileManager.getCurrentActivatedProfile().getActiveProtocols())
|
|
|
- // {
|
|
|
- // if (protocol.equals("GHOST"))
|
|
|
- // continue;
|
|
|
- //
|
|
|
- // if
|
|
|
- // (!MainActivity.getInstance().getHostageService().isRunning(protocol))
|
|
|
- // {
|
|
|
- // MainActivity.getInstance().getHostageService().startListener(protocol);
|
|
|
- // protocolActivated = true;
|
|
|
- // }
|
|
|
- // }
|
|
|
- //
|
|
|
- // Profile currentProfile =
|
|
|
- // profileManager.getCurrentActivatedProfile();
|
|
|
- //
|
|
|
- // if (currentProfile.mGhostActive) {
|
|
|
- // for (int port : currentProfile.getGhostPorts()) {
|
|
|
- // MainActivity.getInstance().getHostageService().startListener("GHOST",
|
|
|
- // port);
|
|
|
- // protocolActivated = true;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- //
|
|
|
- // if (protocolActivated) {
|
|
|
- // setStateActive();
|
|
|
- // } else {
|
|
|
- // new
|
|
|
- // AlertDialog.Builder(getActivity()).setTitle(R.string.information).setMessage(R.string.profile_no_services_msg)
|
|
|
- // .setPositiveButton(android.R.string.ok, new
|
|
|
- // DialogInterface.OnClickListener() {
|
|
|
- // public void onClick(DialogInterface dialog, int which) {
|
|
|
- //
|
|
|
- // }
|
|
|
- // }).setIcon(android.R.drawable.ic_dialog_info).show();
|
|
|
- //
|
|
|
- // setStateNotActive();
|
|
|
- // }
|
|
|
- // } else {
|
|
|
- // if (MainActivity.getInstance().getHostageService() !=
|
|
|
- // null) {
|
|
|
- // MainActivity.getInstance().getHostageService().stopListeners();
|
|
|
- // MainActivity.getInstance().stopAndUnbind();
|
|
|
- // }
|
|
|
- // setStateNotActive();
|
|
|
- // }
|
|
|
- // }
|
|
|
+
|
|
|
+ // SYNC TEST
|
|
|
+ // startActivity(new Intent(getActivity(),
|
|
|
+ // TracingSyncActivity.class));
|
|
|
+
|
|
|
+ if (!HelperUtils.isWifiConnected(getActivity())) {
|
|
|
+ new AlertDialog.Builder(getActivity()).setTitle(R.string.information).setMessage(R.string.wifi_not_connected_msg)
|
|
|
+ .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }).setIcon(android.R.drawable.ic_dialog_info).show();
|
|
|
+
|
|
|
+ setStateNotActive();
|
|
|
+ setStateNotConnected();
|
|
|
+ } else {
|
|
|
+ if (isChecked) {
|
|
|
+ boolean protocolActivated = false;
|
|
|
+ if (ProfileManager.getInstance().getCurrentActivatedProfile() == null) {
|
|
|
+ for (String protocol : getResources().getStringArray(R.array.protocols)) {
|
|
|
+ if (!MainActivity.getInstance().getHostageService().isRunning(protocol)) {
|
|
|
+ MainActivity.getInstance().getHostageService().startListener(protocol);
|
|
|
+ protocolActivated = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ProfileManager profileManager = ProfileManager.getInstance();
|
|
|
+
|
|
|
+ if (profileManager.isRandomActive()) {
|
|
|
+ profileManager.randomizeProtocols(profileManager.getRandomProfile());
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String protocol : profileManager.getCurrentActivatedProfile().getActiveProtocols()) {
|
|
|
+ if (protocol.equals("GHOST"))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (!MainActivity.getInstance().getHostageService().isRunning(protocol)) {
|
|
|
+ MainActivity.getInstance().getHostageService().startListener(protocol);
|
|
|
+ protocolActivated = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Profile currentProfile = profileManager.getCurrentActivatedProfile();
|
|
|
+
|
|
|
+ if (currentProfile.mGhostActive) {
|
|
|
+ for (int port : currentProfile.getGhostPorts()) {
|
|
|
+ MainActivity.getInstance().getHostageService().startListener("GHOST", port);
|
|
|
+ protocolActivated = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (protocolActivated) {
|
|
|
+ setStateActive();
|
|
|
+ } else {
|
|
|
+ new AlertDialog.Builder(getActivity()).setTitle(R.string.information).setMessage(R.string.profile_no_services_msg)
|
|
|
+ .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }).setIcon(android.R.drawable.ic_dialog_info).show();
|
|
|
+
|
|
|
+ setStateNotActive();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (MainActivity.getInstance().getHostageService() != null) {
|
|
|
+ MainActivity.getInstance().getHostageService().stopListeners();
|
|
|
+ MainActivity.getInstance().stopAndUnbind();
|
|
|
+ }
|
|
|
+ setStateNotActive();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
}
|