|
@@ -28,13 +28,11 @@ import de.tudarmstadt.informatik.hostage.wrapper.Packet;
|
|
|
public class HTTP implements Protocol {
|
|
|
|
|
|
public HTTP() {
|
|
|
- boolean useQotd = Hostage.getContext().getSharedPreferences(Hostage.getContext().getString(R.string.shared_preference_path), Hostage.MODE_PRIVATE).getBoolean("useQotd", true);
|
|
|
- if (useQotd) {
|
|
|
- new QotdTask().execute(new String[] {});
|
|
|
- }
|
|
|
+
|
|
|
+ checkProfile();
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
+ /**
|
|
|
* Get the current time in html header format.
|
|
|
*
|
|
|
* @return the formatted server time.
|
|
@@ -73,7 +71,7 @@ public class HTTP implements Protocol {
|
|
|
private String initServerVersion() {
|
|
|
SecureRandom rndm = new SecureRandom();
|
|
|
int majorVersion = rndm.nextInt(possibleHttpVersions.length);
|
|
|
-
|
|
|
+ checkProfile();
|
|
|
String version;
|
|
|
String sharedPreferencePath = Hostage.getContext().getString(
|
|
|
R.string.shared_preference_path);
|
|
@@ -100,6 +98,8 @@ public class HTTP implements Protocol {
|
|
|
|
|
|
private static String htmlDocumentContent = HelperUtils.getRandomString(32, false);
|
|
|
|
|
|
+ private static String htmlTitleContent = HelperUtils.getRandomString(32, false);
|
|
|
+
|
|
|
// request codes
|
|
|
private static final String OPTIONS = "OPTIONS";
|
|
|
|
|
@@ -121,8 +121,11 @@ public class HTTP implements Protocol {
|
|
|
*
|
|
|
* @param htmlDocumentContent
|
|
|
*/
|
|
|
- public static void setHtmlDocumentContent(String htmlDocumentContent) {
|
|
|
- HTTP.htmlDocumentContent = htmlDocumentContent;
|
|
|
+ public static void setHtmlDocumentContent(String htmlDocumentContent,String htmlTitleContent) {
|
|
|
+
|
|
|
+ HTTP.htmlDocumentContent= htmlDocumentContent;
|
|
|
+ HTTP.htmlTitleContent = htmlTitleContent;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// html header pre and suffix
|
|
@@ -135,7 +138,7 @@ public class HTTP implements Protocol {
|
|
|
// html website
|
|
|
private String htmlDocument = "<!doctype html>\n" + "<html lang=\"en\">\n"
|
|
|
+ "<head>\n" + "<meta charset=\"UTF-8\">\n" + "<title>"
|
|
|
- + htmlDocumentContent + "</title>\n" + "<body>"
|
|
|
+ + htmlTitleContent + "</title>\n" + "<body>"
|
|
|
+ htmlDocumentContent + "</body>\n" + "</head>\n" + "</html>";
|
|
|
|
|
|
// html error pre and suffix
|
|
@@ -171,18 +174,24 @@ public class HTTP implements Protocol {
|
|
|
if (request.startsWith("G")) {
|
|
|
//weird if clause but required for https
|
|
|
responsePackets.add(buildPacket(STATUS_CODE_200, GET));
|
|
|
+ checkProfile();
|
|
|
} else if (!request.contains(httpVersion)) {
|
|
|
responsePackets.add(buildPacket(STATUS_CODE_505, ""));
|
|
|
+ checkProfile();
|
|
|
} else if (request.contains(GET)) {
|
|
|
+ checkProfile();
|
|
|
responsePackets.add(buildPacket(STATUS_CODE_200, GET));
|
|
|
} else if (request.contains(HEAD)) {
|
|
|
responsePackets.add(buildPacket(STATUS_CODE_200, HEAD));
|
|
|
+ checkProfile();
|
|
|
} else if (request.contains(TRACE)) {
|
|
|
responsePackets.add(buildPacket(STATUS_CODE_200, TRACE));
|
|
|
+ checkProfile();
|
|
|
} else if (request.contains(OPTIONS)) {
|
|
|
responsePackets.add(buildPacket(STATUS_CODE_400, OPTIONS));
|
|
|
} else if (request.contains(POST)) {
|
|
|
responsePackets.add(buildPacket(STATUS_CODE_200, POST));
|
|
|
+
|
|
|
} else if (request.contains(PUT)) {
|
|
|
responsePackets.add(buildPacket(STATUS_CODE_400, PUT));
|
|
|
} else if (request.contains(DELETE)) {
|
|
@@ -193,13 +202,40 @@ public class HTTP implements Protocol {
|
|
|
responsePackets.add(buildPacket(STATUS_CODE_400, ""));
|
|
|
}
|
|
|
|
|
|
- boolean useQotd = Hostage.getContext().getSharedPreferences(Hostage.getContext().getString(R.string.shared_preference_path), Hostage.MODE_PRIVATE).getBoolean("useQotd", true);
|
|
|
- if (useQotd) {
|
|
|
- new QotdTask().execute(new String[] {});
|
|
|
- }
|
|
|
+ checkProfile();
|
|
|
+
|
|
|
return responsePackets;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void checkProfile() {
|
|
|
+
|
|
|
+ String sharedPreferencePath = Hostage.getContext().getString(
|
|
|
+ R.string.shared_preference_path);
|
|
|
+ String profile = Hostage
|
|
|
+ .getContext()
|
|
|
+ .getSharedPreferences(sharedPreferencePath,
|
|
|
+ Context.MODE_PRIVATE).getString("os", "");
|
|
|
+ if (profile.equals("Nuclear Power Plant")) {
|
|
|
+
|
|
|
+ htmlDocumentContent = "<font color="+"\"339966\""+">"+" <b>Welcome to Siemens Simatic S7 200 Portal</b>\n"+"<img src="+"" + "\"http://jewishbusinessnews.com/wp-content/uploads/2014/04/siemens-logo.jpg\""+"alt="+"\"Siemens Logo\""+">";
|
|
|
+ htmlTitleContent="Siemens Simatic S7 200 Home";
|
|
|
+
|
|
|
+ HTTP.setHtmlDocumentContent(htmlDocumentContent,htmlTitleContent);
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ boolean useQotd = Hostage.getContext().getSharedPreferences(Hostage.getContext().getString(R.string.shared_preference_path), Hostage.MODE_PRIVATE).getBoolean("useQotd", true);
|
|
|
+ if (useQotd) {
|
|
|
+ new QotdTask().execute(new String[]{});
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public String toString() {
|
|
|
return "HTTP";
|
|
@@ -242,32 +278,54 @@ public class HTTP implements Protocol {
|
|
|
*/
|
|
|
private class QotdTask extends AsyncTask<String, Void, String> {
|
|
|
@Override
|
|
|
+
|
|
|
+
|
|
|
protected String doInBackground(String... unused) {
|
|
|
- String[] sources = new String[] { "djxmmx.net", "alpha.mike-r.com"};
|
|
|
- SecureRandom rndm = new SecureRandom();
|
|
|
+
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
- try {
|
|
|
- Socket client = new Socket(sources[rndm.nextInt(sources.length)], 17);
|
|
|
- BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
|
|
|
- while (!in.ready())
|
|
|
- ;
|
|
|
- while (in.ready()) {
|
|
|
- sb.append(in.readLine());
|
|
|
+
|
|
|
+ String sharedPreferencePath = Hostage.getContext().getString(
|
|
|
+ R.string.shared_preference_path);
|
|
|
+ String profile = Hostage
|
|
|
+ .getContext()
|
|
|
+ .getSharedPreferences(sharedPreferencePath,
|
|
|
+ Context.MODE_PRIVATE).getString("os", "");
|
|
|
+
|
|
|
+
|
|
|
+ String[] sources = new String[]{"djxmmx.net", "alpha.mike-r.com"};
|
|
|
+ SecureRandom rndm = new SecureRandom();
|
|
|
+
|
|
|
+ try {
|
|
|
+ sb.equals("");
|
|
|
+ Socket client = new Socket(sources[rndm.nextInt(sources.length)], 17);
|
|
|
+ BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
|
|
|
+ while (!in.ready())
|
|
|
+ ;
|
|
|
+ while (in.ready()) {
|
|
|
+ sb.append(in.readLine());
|
|
|
+ }
|
|
|
+ in.close();
|
|
|
+ client.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- in.close();
|
|
|
- client.close();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
return sb.toString();
|
|
|
- }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
protected void onPostExecute(String result) {
|
|
|
+
|
|
|
+
|
|
|
+ checkProfile();
|
|
|
if (result != null)
|
|
|
- HTTP.setHtmlDocumentContent(result);
|
|
|
+
|
|
|
+ HTTP.setHtmlDocumentContent(result,result);
|
|
|
else
|
|
|
- HTTP.setHtmlDocumentContent(HelperUtils.getRandomString(32, false));
|
|
|
+ HTTP.setHtmlDocumentContent(HelperUtils.getRandomString(32, false),HelperUtils.getRandomString(32, false));
|
|
|
}
|
|
|
}
|
|
|
}
|