Browse Source

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/scm-ssi-hostage-v3

Alexander Brakowski 9 years ago
parent
commit
3abf150fae

+ 3 - 0
res/values/strings.xml

@@ -30,6 +30,7 @@
     <string name="not_rooted">Your device does not have root access. To unlock full functionality of HosTaGe, a rooted device is required.</string>
     <string name="help">Help</string>
     <string name="confirm">Confirm</string>
+	<string name="ok">OK</string>
     <string name="how">How?</string>
     <string name="portbinder">Portbinder</string>
     <string name="portbinder_tutorial">Video Tutorial</string>
@@ -256,4 +257,6 @@
     <string name="pref_sync_countries_desc">Only download attack data of these countries</string>
     <string name="pref_sync_countries">Countries</string>
     <string name="pref_download_server">Download server</string>
+	<string name="google_play_services_unavailable">Error: Google Play Services are unavailable.
+	</string>
 </resources>

+ 11 - 7
src/de/tudarmstadt/informatik/hostage/persistence/HostageDBOpenHelper.java

@@ -469,7 +469,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
             for (SyncDevice device : allDevices){
                 Long sync_id = deviceIDmap.get(device.getDeviceID());
                 long highestID = device.getHighest_attack_id();
-                if (sync_id != null) highestID = sync_id.longValue();
+                if (sync_id != null && highestID < sync_id) highestID = sync_id.longValue();
                 device.setHighest_attack_id(highestID);
             }
             this.updateSyncDevices(allDevices, db);
@@ -1848,9 +1848,11 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 
         String filterQuery = this.selectionQueryFromFilter(filter, AttackEntry.COLUMN_NAME_ATTACK_ID);
 
-        String attackPerESSID_Query = "SELECT " + NetworkEntry.COLUMN_NAME_SSID + " , " + "COUNT( " + AttackEntry.COLUMN_NAME_ATTACK_ID + "  ) " + " "
-                                    + " FROM " + AttackEntry.TABLE_NAME + " a " + " , " + NetworkEntry.TABLE_NAME
-                                    + " WHERE " + " a." + AttackEntry.COLUMN_NAME_ATTACK_ID + " IN " + " ( " + filterQuery + " ) "
+        filterQuery = filterQuery.split("GROUP BY")[0];
+
+        String attackPerESSID_Query = "SELECT " + NetworkEntry.COLUMN_NAME_SSID + " , " + "COUNT( " + " * " + "  ) " + " "
+                                    + " FROM "  +  AttackEntry.TABLE_NAME + " NATURAL JOIN " + NetworkEntry.TABLE_NAME //AttackEntry.TABLE_NAME + " a " + " , " + NetworkEntry.TABLE_NAME
+                                    + " WHERE " + AttackEntry.COLUMN_NAME_ATTACK_ID + " IN " + " ( " + filterQuery + " ) "
                                     + " GROUP BY " + NetworkEntry.TABLE_NAME+"."+NetworkEntry.COLUMN_NAME_SSID;
 
         SQLiteDatabase db = this.getReadableDatabase();
@@ -2093,10 +2095,12 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 
         String filterQuery = this.selectionQueryFromFilter(filter, AttackEntry.COLUMN_NAME_ATTACK_ID);
 
-        String attackPerBSSID_Query = "SELECT " + NetworkEntry.TABLE_NAME + "." + NetworkEntry.COLUMN_NAME_BSSID + " , " + "COUNT( " + AttackEntry.COLUMN_NAME_ATTACK_ID + "  ) " + " "
-                + " FROM " + AttackEntry.TABLE_NAME + " a " + " , " + NetworkEntry.TABLE_NAME
+        filterQuery = filterQuery.split("GROUP BY")[0];
+
+        String attackPerBSSID_Query = "SELECT " + AttackEntry.COLUMN_NAME_BSSID + " , " + "COUNT( " + "*" + "  ) " + " "
+                + " FROM " + AttackEntry.TABLE_NAME + " a "
                 + " WHERE " + " a." + AttackEntry.COLUMN_NAME_ATTACK_ID + " IN " + " ( " + filterQuery + " ) "
-                + " GROUP BY " + NetworkEntry.TABLE_NAME + "." + NetworkEntry.COLUMN_NAME_BSSID;
+                + " GROUP BY " + AttackEntry.COLUMN_NAME_BSSID;
 
         SQLiteDatabase db = this.getReadableDatabase();
         Cursor cursor = db.rawQuery(attackPerBSSID_Query, null);

+ 42 - 74
src/de/tudarmstadt/informatik/hostage/ui/adapter/ServicesListAdapter.java

@@ -208,81 +208,49 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
      * @param holder ViewHolder which represents the item in the View
      */
     private void updateStatus(ServicesListItem item, ViewHolder holder) {
-        if(item.protocol.equals("GHOST")){
-            mProfile = ProfileManager.getInstance().getCurrentActivatedProfile();
-            mGhostPorts = mProfile.getGhostPorts();
+		boolean serviceIsActive = false;
+		// determine if service is active
+        if(item.protocol.equals("GHOST")) {
+			mProfile = ProfileManager.getInstance().getCurrentActivatedProfile();
+			mGhostPorts = mProfile.getGhostPorts();
+
+			for (Integer port : mGhostPorts) {
+				if (port != null && MainActivity.getInstance().getHostageService()
+						.isRunning("GHOST", port)) {
+					serviceIsActive = true;
+					break;
+				}
+			}
+		} else if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
+			serviceIsActive = true;
+		}
+
+		if (serviceIsActive){
+			if(!holder.activated.isChecked()) {
+				holder.activated.setChecked(true);
+			}
+
+			if (item.attacks == 0) {
+				setBackground(holder, R.drawable.services_circle_green);
+			} else { // attacks > 0 (will never be negative)
+				if (MainActivity.getInstance().getHostageService().hasProtocolActiveAttacks(item.protocol)) {
+					setBackground(holder, R.drawable.services_circle_red);
+				} else {
+					setBackground(holder, R.drawable.services_circle_yellow);
+				}
+			}
+		} else {
+			if(holder.activated.isChecked()) {
+				holder.activated.setChecked(false);
+			}
+
+			if (item.attacks > 0) {
+				setBackground(holder, R.drawable.services_circle_yellow);
+			} else {
+				setBackground(holder, R.drawable.services_circle);
+			}
+		}
 
-            boolean ghostActive = false;
-            if(mGhostPorts.length != 0) {
-                for (Integer port : mGhostPorts) {
-                    if(port != null){
-                        if (MainActivity.getInstance().getHostageService().isRunning("GHOST", port)) {
-                            ghostActive = true;
-                        }
-                    }
-                }
-            }
-            if(ghostActive){
-                if(!holder.activated.isChecked()) {
-                    holder.activated.setChecked(true);
-                }
-
-                if (!MainActivity.getInstance().getHostageService().hasProtocolActiveAttacks(item.protocol)) {
-                    if (item.attacks > 0) {
-                        setBackground(holder, R.drawable.services_circle_yellow);
-                    } else {
-                        setBackground(holder, R.drawable.services_circle_green);
-                    }
-
-                } else {
-                    if (MainActivity.getInstance().getHostageService().hasProtocolActiveAttacks(item.protocol)) {
-                        setBackground(holder, R.drawable.services_circle_red);
-                    }
-                }
-
-            } else if (item.attacks > 0) {
-                if(holder.activated.isChecked()) {
-                    holder.activated.setChecked(false);
-                }
-                setBackground(holder, R.drawable.services_circle_yellow);
-            } else {
-                if(holder.activated.isChecked()) {
-                    holder.activated.setChecked(false);
-                }
-                setBackground(holder, R.drawable.services_circle);
-            }
-
-
-
-
-        }
-        else if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
-            if(!holder.activated.isChecked()) {
-                holder.activated.setChecked(true);
-            }
-            if (!MainActivity.getInstance().getHostageService().hasProtocolActiveAttacks(item.protocol)) {
-                if (item.attacks > 0) {
-                    setBackground(holder, R.drawable.services_circle_yellow);
-                } else {
-                    setBackground(holder, R.drawable.services_circle_green);
-                }
-
-            } else {
-                if (MainActivity.getInstance().getHostageService().hasProtocolActiveAttacks(item.protocol)) {
-                    setBackground(holder, R.drawable.services_circle_red);
-                }
-            }
-        } else if (item.attacks > 0) {
-            if(holder.activated.isChecked()) {
-                holder.activated.setChecked(false);
-            }
-            setBackground(holder, R.drawable.services_circle_yellow);
-        } else {
-            if(holder.activated.isChecked()) {
-                holder.activated.setChecked(false);
-            }
-            setBackground(holder, R.drawable.services_circle);
-        }
         holder.recordedAttacks
                 .setText(String.format(MainActivity.getContext().getResources().getString(R.string.recorded_attacks) + "  %d", Integer.valueOf(item.attacks)));
     }

+ 13 - 0
src/de/tudarmstadt/informatik/hostage/ui/fragment/ThreatMapFragment.java

@@ -12,9 +12,11 @@ import android.app.AlertDialog;
 import android.app.Fragment;
 import android.app.FragmentManager;
 import android.content.DialogInterface;
+import android.content.SharedPreferences;
 import android.graphics.Color;
 import android.location.Location;
 import android.os.Bundle;
+import android.text.Html;
 import android.view.InflateException;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -353,6 +355,17 @@ public class ThreatMapFragment extends TrackerFragment implements GoogleMap.OnIn
 						sMap = mapFragment.getMap();
 					}
 				}
+			} else {
+				AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.getInstance());
+				builder.setMessage(Html.fromHtml(getString(R.string.google_play_services_unavailable)))
+						.setCancelable(false)
+						.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
+							public void onClick(DialogInterface dialog, int id) {
+								// :D-|< :D-/< :D-\<
+							}
+						});
+				AlertDialog alert = builder.create();
+				alert.show();
 			}
 		} catch (InflateException e) {
 			// map already exists