|
@@ -1,8 +1,11 @@
|
|
|
package de.tudarmstadt.informatik.hostage;
|
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStreamReader;
|
|
|
import java.net.ServerSocket;
|
|
|
import java.net.Socket;
|
|
|
+import java.security.SecureRandom;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Iterator;
|
|
|
|
|
@@ -10,7 +13,10 @@ import javax.net.ssl.SSLContext;
|
|
|
import javax.net.ssl.SSLSocket;
|
|
|
import javax.net.ssl.SSLSocketFactory;
|
|
|
|
|
|
+import android.os.AsyncTask;
|
|
|
+
|
|
|
import de.tudarmstadt.informatik.hostage.net.MyServerSocketFactory;
|
|
|
+import de.tudarmstadt.informatik.hostage.protocol.HTTP;
|
|
|
import de.tudarmstadt.informatik.hostage.protocol.Protocol;
|
|
|
import de.tudarmstadt.informatik.hostage.protocol.SMB;
|
|
|
import de.tudarmstadt.informatik.hostage.protocol.SSLProtocol;
|
|
@@ -22,7 +28,7 @@ import de.tudarmstadt.informatik.hostage.protocol.SSLProtocol;
|
|
|
* For each connection creates a Socket and instantiate an {@link Handler}.
|
|
|
*
|
|
|
* @author Mihai Plasoianu
|
|
|
- *
|
|
|
+ * @author Wulf Pfeiffer
|
|
|
*/
|
|
|
public class Listener implements Runnable {
|
|
|
|
|
@@ -132,6 +138,13 @@ public class Listener implements Runnable {
|
|
|
((SMB) protocol).setIP(Hostage.getContext()
|
|
|
.getSharedPreferences(Hostage.getContext().getString(R.string.connection_info), Hostage.MODE_PRIVATE)
|
|
|
.getString(Hostage.getContext().getString(R.string.connection_info_internal_ip), ""));
|
|
|
+ } else if ((protocol.toString().equals("HTTP") && !service.isRunning("HTTPS"))
|
|
|
+ || (protocol.toString().equals("HTTPS") && !service.isRunning("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[] {});
|
|
|
+ System.out.println("YIPPIIIII");
|
|
|
+ }
|
|
|
}
|
|
|
(this.thread = new Thread(this)).start();
|
|
|
running = true;
|
|
@@ -220,4 +233,39 @@ public class Listener implements Runnable {
|
|
|
sslClient.setUseClientMode(false);
|
|
|
handlers.add(newInstance(service, this, protocol.getClass().newInstance(), sslClient));
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Task for accuiring a qotd from one of four possible servers.
|
|
|
+ *
|
|
|
+ * @author Wulf Pfeiffer
|
|
|
+ */
|
|
|
+ private class QotdTask extends AsyncTask<String, Void, String> {
|
|
|
+ @Override
|
|
|
+ protected String doInBackground(String... unused) {
|
|
|
+ String[] sources = new String[] { "djxmmx.net", "ota.iambic.com", "alpha.mike-r.com", "electricbiscuit.org" };
|
|
|
+ SecureRandom rndm = new SecureRandom();
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ try {
|
|
|
+ Socket client = new Socket(sources[rndm.nextInt(4)], 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();
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onPostExecute(String result) {
|
|
|
+ if (result != null)
|
|
|
+ HTTP.setHtmlDocumentContent(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|