Browse Source

solved merge conflicts

Daniel Lazar 9 years ago
parent
commit
4c95529fc9

+ 3 - 3
src/de/tudarmstadt/informatik/hostage/Hostage.java

@@ -38,7 +38,7 @@ import android.support.v4.content.LocalBroadcastManager;
 import android.util.Log;
 import android.widget.Toast;
 
-import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.location.MyLocationManager;
 import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
 import de.tudarmstadt.informatik.hostage.protocol.Protocol;
@@ -412,8 +412,8 @@ public class Hostage extends Service {
 	private void attackNotification() {
 		SharedPreferences defaultPref = PreferenceManager.getDefaultSharedPreferences(this);
 		String strRingtonePreference = defaultPref.getString("pref_notification_sound", "content://settings/system/notification_sound");
-		builder = new NotificationCompat.Builder(this).setContentTitle(getString(R.string.app_name)).setTicker("Honeypot under attack!")
-				.setContentText("Honeypot under attack!").setSmallIcon(R.drawable.ic_service_red).setAutoCancel(true).setWhen(System.currentTimeMillis())
+		builder = new NotificationCompat.Builder(this).setContentTitle(getString(R.string.app_name)).setTicker(getString(R.string.honeypot_live_threat))
+				.setContentText(getString(R.string.honeypot_live_threat)).setSmallIcon(R.drawable.ic_service_red).setAutoCancel(true).setWhen(System.currentTimeMillis())
 				.setSound(Uri.parse(strRingtonePreference));
 		Intent launchIntent = new Intent(getApplicationContext(), MainActivity.class);
 		TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

+ 52 - 47
src/de/tudarmstadt/informatik/hostage/sync/android/SyncUtils.java

@@ -5,6 +5,8 @@ import android.accounts.AccountManager;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.SharedPreferences;
+import android.location.Address;
+import android.location.Geocoder;
 import android.location.Location;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
@@ -47,6 +49,7 @@ import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 import de.tudarmstadt.informatik.hostage.location.MyLocationManager;
@@ -146,30 +149,30 @@ public class SyncUtils {
     public static void appendRecordToStringWriter(Record record, Writer stream){
         try {
             stream.append(
-            "{" +
-                "\"sensor\":{" +
-                    "\"name\":\"HosTaGe\"," +
-                    "\"type\":\"Honeypot\"" +
-                "}," +
-                "\"src\":{" +
-                    "\"ip\":\"" + record.getRemoteIP() + "\"," +
-                    "\"port\":" + record.getRemotePort() +
-                "}," +
-                "\"dst\":{" +
-                    "\"ip\":\"" + record.getLocalIP() + "\"," +
-                    "\"port\":" + record.getLocalPort() +
-                "}," +
-                "\"type\":" + (protocolsTypeMap.containsKey(record.getProtocol()) ? protocolsTypeMap.get(record.getProtocol()) : 0) + "," +
-                "\"log\":\"" + record.getProtocol() + "\"," +
-                "\"md5sum\":\"\"," +
-                "\"date\":" + (int)(record.getTimestamp() / 1000) + "," +
-                "\"bssid\":\"" + record.getBssid() + "\"," +
-                "\"ssid\":\"" + record.getSsid() + "\"," +
-                "\"device\":\"" + record.getDevice() + "\"," +
-                "\"sync_id\":\"" + record.getSync_id() + "\"," +
-                "\"internal_attack\":\"" + record.getWasInternalAttack() + "\"," +
-                "\"external_ip\":\"" + record.getExternalIP() + "\"" +
-             "}\n"
+                    "{" +
+                            "\"sensor\":{" +
+                            "\"name\":\"HosTaGe\"," +
+                            "\"type\":\"Honeypot\"" +
+                            "}," +
+                            "\"src\":{" +
+                            "\"ip\":\"" + record.getRemoteIP() + "\"," +
+                            "\"port\":" + record.getRemotePort() +
+                            "}," +
+                            "\"dst\":{" +
+                            "\"ip\":\"" + record.getLocalIP() + "\"," +
+                            "\"port\":" + record.getLocalPort() +
+                            "}," +
+                            "\"type\":" + (protocolsTypeMap.containsKey(record.getProtocol()) ? protocolsTypeMap.get(record.getProtocol()) : 0) + "," +
+                            "\"log\":\"" + record.getProtocol() + "\"," +
+                            "\"md5sum\":\"\"," +
+                            "\"date\":" + (int)(record.getTimestamp() / 1000) + "," +
+                            "\"bssid\":\"" + record.getBssid() + "\"," +
+                            "\"ssid\":\"" + record.getSsid() + "\"," +
+                            "\"device\":\"" + record.getDevice() + "\"," +
+                            "\"sync_id\":\"" + record.getSync_id() + "\"," +
+                            "\"internal_attack\":\"" + record.getWasInternalAttack() + "\"," +
+                            "\"external_ip\":\"" + record.getExternalIP() + "\"" +
+                            "}\n"
             );
         } catch (IOException e) {
             e.printStackTrace();
@@ -263,40 +266,42 @@ public class SyncUtils {
 
             JSONObject condition = new JSONObject();
 
-            /**if(fromTime > 0){
-             Calendar calendar = GregorianCalendar.getInstance();
-             calendar.setTimeInMillis(fromTime);
+            if(fromTime > 0){
+                Calendar calendar = GregorianCalendar.getInstance();
+                calendar.setTimeInMillis(fromTime);
 
-             condition.put("date", fromCalendar(calendar));
-             }**/
+                condition.put("date", fromCalendar(calendar));
+            }
+
+            String country = null;
+
+            Location location = MyLocationManager.getNewestLocation();
 
-            Location location = null;
-            /**
-             TODO(alex): UNCOMMENT THIS AGAIN, WHEN WE ARE SURE ABOUT USING LOCATIONS THIS WAY.
-             =======================================================================
-            location = MyLocationManager.getNewestLocation();
-             */
             if(location != null){
-                JSONArray ll = new JSONArray();
-                ll.put(location.getLongitude());
-                ll.put(location.getLatitude());
+                Geocoder geocoder = new Geocoder(context, Locale.getDefault());
+                List<Address> fromLocation = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
+
+                if(fromLocation.size() > 0){
+                    Address address = fromLocation.get(0);
+                    country = address.getCountryCode();
+                }
+            }
 
-                condition.put("location", ll);
-                condition.put("distance", 500);
-            } else {
+            if(country == null){
                 // We could not get the gps coordinates, try to retrieve the country code from the SIM card
                 TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
-                String countryCodeValue = tm.getNetworkCountryIso();
-                /**
-                 TODO(julien): COMMENT THIS OUT, TO GET ALL SYNC DATA FROM TRACING.
-                 */
-                condition.put("country", countryCodeValue);
+                country = tm.getNetworkCountryIso();
             }
 
+            if(country == null || country.trim().isEmpty()) country = Locale.getDefault().getCountry();
+
+            condition.put("country", country);
+
             JSONObject req = new JSONObject();
             req.put("condition", condition);
             req.put("info", deviceMap);
 
+
             StringEntity se = new StringEntity(req.toString());
             httppost.addHeader("content-type", "application/json");
             httppost.setEntity(se);
@@ -520,4 +525,4 @@ public class SyncUtils {
             return new DefaultHttpClient();
         }
     }
-}
+}

+ 1 - 0
src/de/tudarmstadt/informatik/hostage/ui/fragment/RecordOverviewFragment.java

@@ -475,6 +475,7 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
                     private RecordOverviewFragment recordOverviewFragment = null;
                     public void onClick(DialogInterface dialog, int id) {
                         recordOverviewFragment.deleteFilteredAttacks();
+                        MainActivity.getInstance().getHostageService().notifyUI(Handler.class.toString(), null);
                     }
                     public DialogInterface.OnClickListener init(RecordOverviewFragment rf){
                         this.recordOverviewFragment = rf;