|
@@ -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();
|
|
|
}
|
|
|
}
|