Browse Source

Upload to TraCINg fixed

lp-tu 10 years ago
parent
commit
c7c2993b53

+ 2 - 2
src/de/tudarmstadt/informatik/hostage/logging/Record.java

@@ -6,8 +6,8 @@ import java.net.InetAddress;
  * This class defines the attributes of a record.<br>
  * A Record is a single message exchanged between the application and an attacker.<br>
  * The class has no own functionality except for getter and setter methods.
- * To change the logging mechanism you have to to change the logger in {@link de.tudarmstadt.informatik.hostage.HoneyService} and 
- * {@link de.tudarmstadt.informatik.hostage.ui.ViewLog}
+ * To change the logging mechanism you have to to change the logger in {@link de.tudarmstadt.informatik.hostage.HoneyService HoneyService} and 
+ * {@link de.tudarmstadt.informatik.hostage.ui.ViewLog ViewLog}
  * @author Mihai Plasoianu 
  * @author Lars Pandikow
  */

+ 22 - 3
src/de/tudarmstadt/informatik/hostage/ui/ViewLog.java

@@ -2,6 +2,7 @@ package de.tudarmstadt.informatik.hostage.ui;
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.net.InetAddress;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -158,7 +159,8 @@ public class ViewLog extends Activity {
 	
 	/**
 	 * Uploads a JSON Representation of each attack to a server, specified in the preferences.<br>
-	 * The method only uploads information about attacks that have net been uploaded yet.
+	 * The method only uploads information about attacks that have net been uploaded yet.<br>
+	 * The local and remote IP of each record will be replaced with the external IP of then device at the time of the upload.
 	 * For the Upload it uses a HttpPost with a HttpsClient, which does not validate any certificates.<br>
 	 * The Upload runs in its own Thread.<br>
 	 * While uploading the method also creates a notification to inform the user about the status of the upload.
@@ -204,10 +206,17 @@ public class ViewLog extends Activity {
 					final int progressMax = recordList.size();		
 					Log.i("SQLLogger", "Logs to upload: " + progressMax);	
 							HttpPost httppost;
+							String externalIPString = HelperUtils.getExternalIP(getBaseContext());
 							int progressBarStatus = 0;
-							for(Record record: recordList){
+							int retry_counter = 0;
+							while(progressBarStatus < progressMax){
 								Log.i("SQLLogger", "Uploading log: " + progressBarStatus);
+								Record record = recordList.get(progressBarStatus);
 								try {
+								// Set the IP to your external IP
+								InetAddress external = InetAddress.getByName(externalIPString);
+								record.setLocalIP(external);
+								record.setRemoteIP(external);
 								// Create HttpPost
 								httppost = new HttpPost(pref.getString("pref_upload", "https://ssi.cased.de"));
 								// Create JSON String of Record
@@ -217,13 +226,23 @@ public class ViewLog extends Activity {
 								HttpResponse response = httpclient.execute(httppost);
 								Log.i("SQLLogger", "Statuscode of log "  + progressBarStatus + ": " + " " + response.getStatusLine().getReasonPhrase());	
 								Log.i("SQLLogger", "Statuscode of log "  + progressBarStatus + ": " + " " + response.getStatusLine().getStatusCode());	
+								retry_counter = 0;
 								// Update Notification progress bar
 								progressBarStatus++;								
 								builder.setProgress(progressMax, progressBarStatus, false);
 			                     // Update the progress bar
 								mNotifyManager.notify(2, builder.build());
 								} catch (Exception e) {
-									Log.i("SQLLogger", "Failed");
+
+									retry_counter++;
+									if(retry_counter == 3){
+										retry_counter = 0;
+										progressBarStatus++;
+										Log.i("SQLLogger", "Upload of log " + progressBarStatus + " failed. Continue with next log");
+									} else {
+										Log.i("SQLLogger", "Upload of log " + progressBarStatus + " failed...retry");
+									}
+
 									e.printStackTrace();
 								}
 							}