|
@@ -15,14 +15,12 @@ import android.widget.TextView;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
-import de.tudarmstadt.informatik.hostage.HoneyService;
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
|
import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
|
-import de.tudarmstadt.informatik.hostage.protocol.FTP;
|
|
|
+import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.adapter.ServicesListAdapter;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
|
|
|
|
|
|
-import static de.tudarmstadt.informatik.hostage.HoneyService.*;
|
|
|
|
|
|
|
|
|
* Created by Daniel Lazar on 05.02.14.
|
|
@@ -37,6 +35,7 @@ public class ServicesFragment extends Fragment{
|
|
|
private CompoundButton.OnCheckedChangeListener switchChangeListener = null;
|
|
|
|
|
|
|
|
|
+
|
|
|
private void assignViews(){
|
|
|
mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
|
|
|
mServicesTextName = (TextView) rootView.findViewById(R.id.services_text_name);
|
|
@@ -54,7 +53,7 @@ public class ServicesFragment extends Fragment{
|
|
|
}
|
|
|
|
|
|
|
|
|
- if(!HoneyService.isRunning(protocols[1])){
|
|
|
+ if(!MainActivity.getInstance().getHoneyService().isRunning(protocols[1])){
|
|
|
mServicesSwitchFTP.setOnCheckedChangeListener(null);
|
|
|
}
|
|
|
else {
|
|
@@ -74,16 +73,22 @@ public class ServicesFragment extends Fragment{
|
|
|
updateUI();
|
|
|
|
|
|
ListView list = (ListView) rootView.findViewById(R.id.services_list_view);
|
|
|
- String[] protocols = getResources().getStringArray(R.array.protocols);
|
|
|
+
|
|
|
+ final String[] protocols = getResources().getStringArray(R.array.protocols);
|
|
|
ArrayList<ServicesListItem> protocolList= new ArrayList<ServicesListItem>();
|
|
|
|
|
|
for(String protocol: protocols){
|
|
|
protocolList.add(new ServicesListItem(protocol));
|
|
|
+ if(MainActivity.getInstance().getHoneyService().isRunning(protocol)){
|
|
|
+ setStateActive();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
ServicesListAdapter adapter = new ServicesListAdapter(getActivity().getBaseContext(), protocolList);
|
|
|
list.setAdapter(adapter);
|
|
|
|
|
|
+ mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
|
|
|
+
|
|
|
if(switchChangeListener == null){
|
|
|
switchChangeListener = new CompoundButton.OnCheckedChangeListener() {
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
@@ -104,20 +109,34 @@ public class ServicesFragment extends Fragment{
|
|
|
setStateNotConnected();
|
|
|
} else {
|
|
|
if(isChecked){
|
|
|
+ for(String protocol: protocols){
|
|
|
+ if(MainActivity.getInstance().getHoneyService().isRunning(protocol)){
|
|
|
+
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ MainActivity.getInstance().getHoneyService().startListener(protocol);
|
|
|
+ }
|
|
|
+ }
|
|
|
setStateActive();
|
|
|
} else {
|
|
|
+ MainActivity.getInstance().getHoneyService().stopListeners();
|
|
|
+ MainActivity.getInstance().stopAndUnbind();
|
|
|
setStateNotActive();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
+ mServicesSwitchService.setOnCheckedChangeListener(switchChangeListener);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
return rootView;
|
|
|
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
private void setStateActive() {
|
|
|
-
|
|
|
+ mServicesSwitchService.setChecked(true);
|
|
|
}
|
|
|
|
|
|
private void setStateNotConnected() {
|
|
@@ -125,6 +144,7 @@ public class ServicesFragment extends Fragment{
|
|
|
}
|
|
|
|
|
|
private void setStateNotActive() {
|
|
|
+ mServicesSwitchService.setChecked(false);
|
|
|
|
|
|
}
|
|
|
|