diff --git a/WebCallerID/ListExample.txt b/WebCallerID/ListExample.txt
new file mode 100644
index 0000000..4601f0a
--- /dev/null
+++ b/WebCallerID/ListExample.txt
@@ -0,0 +1,233 @@
+
+
+
+
+
+
+==============================================================
+
+
+--- login() --------------------------------------
+Username=admin&Password=NTM3OTUzMDY=
+Cookie: SessionID_R3=8UTiifjN86x
+Status: 200
+--- getList() --------------------------------------
+
+
+
+
+
+
+
+
+
+
+
+Speedport W 723V Konfigurationsprogramm
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+--- logout() --------------------------------------
diff --git a/WebCallerID/src/main/java/de/tilman/callerId/CallerIdClient.java b/WebCallerID/src/main/java/de/tilman/callerId/CallerIdClient.java
index 87d86c9..7529da7 100755
--- a/WebCallerID/src/main/java/de/tilman/callerId/CallerIdClient.java
+++ b/WebCallerID/src/main/java/de/tilman/callerId/CallerIdClient.java
@@ -1,20 +1,36 @@
package de.tilman.callerId;
import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import java.util.Scanner;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.ProtocolException;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.DefaultRedirectStrategy;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.EntityUtils;
public class CallerIdClient {
DefaultHttpClient httpclient = new DefaultHttpClient();
-
+
String password = com.sun.org.apache.xerces.internal.impl.dv.util.Base64.encode("53795306".getBytes());
String cookie;
@@ -22,19 +38,27 @@ public class CallerIdClient {
// com.sun.org.apache.xerces.internal.impl.dv.util.Base64.encode(null);
+ // plain Java
try {
login();
+ getList();
logout();
} catch (Exception e1) {
e1.printStackTrace();
}
+ // Apache http client
+ // try {
+ // apacheLogin();
+ // } catch (Exception e) {
+ // e.printStackTrace();
+ // }
+
}
private void login() throws Exception {
- System.out.println("Login:");
- String body = "Username=" + URLEncoder.encode("admin", "UTF-8") + "&"
- + "Password=" + password;
+ System.out.println("--- login() --------------------------------------");
+ String body = "Username=" + URLEncoder.encode("admin", "UTF-8") + "&" + "Password=" + password;
System.out.println(body);
URL url2 = new URL("https://speedport.ip/index/login.cgi");
@@ -55,42 +79,45 @@ public class CallerIdClient {
if (line.startsWith("SessionID_R3")) {
System.out.println("Cookie: " + line);
cookie = line.substring(13);
- }
- else {
+ } else {
System.out.println("Answer: " + line);
}
}
-
+
int status = connection.getResponseCode();
System.out.println("Status: " + status);
-
writer.close();
reader.close();
}
-
+
private void getList() throws Exception {
- // SessionID_R3=TGmoTck49mz
+ System.out.println("--- getList() --------------------------------------");
+ //https://speedport.ip/auth/hcti_status_telanrl.php?cookie=SessionID_R3,xctyNRvrwuh
+
+ URL u = new URL("https://speedport.ip/auth/hcti_status_telanrl.php?cookie=SessionID_R3," + cookie);
+ URLConnection urlConn = u.openConnection();
+ String cookieString = "SessionID_R3=" + cookie;
+ urlConn.setRequestProperty("Cookie", cookieString);
+ InputStream response = urlConn.getInputStream();
- URL u = new URL("https://speedport.ip/");
- String r = new Scanner(u.openStream()).useDelimiter("\\Z").next();
+ String r = new Scanner(response).useDelimiter("\\Z").next();
System.out.println(r);
-
}
-
+
private void logout() throws Exception {
-
+ System.out.println("--- logout() --------------------------------------");
URL myUrl = new URL("https://speedport.ip/auth/logout.cgi?RequestFile=/pub/top_beenden.php&cookie=SessionID_R3," + cookie);
URLConnection urlConn = myUrl.openConnection();
String cookieString = "SessionID_R3=" + cookie;
urlConn.setRequestProperty("Cookie", cookieString);
urlConn.connect();
-
-// URL u = new URL("https://speedport.ip/pub/top_beenden.php");
-// // https://speedport.ip/logout.cgi?RequestFile=/pub/top_beenden.php
-// String r = new Scanner(u.openStream()).useDelimiter("\\Z").next();
-// System.out.println("Logout:");
-// System.out.println(r);
+
+ // URL u = new URL("https://speedport.ip/pub/top_beenden.php");
+ // // https://speedport.ip/logout.cgi?RequestFile=/pub/top_beenden.php
+ // String r = new Scanner(u.openStream()).useDelimiter("\\Z").next();
+ // System.out.println("Logout:");
+ // System.out.println(r);
}
private void plainJava() throws Exception {
@@ -120,6 +147,65 @@ public class CallerIdClient {
}
+
+ private void apacheLogin() throws Exception {
+ httpclient.setRedirectStrategy(new DefaultRedirectStrategy() {
+ public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) {
+ boolean isRedirect = false;
+ try {
+ isRedirect = super.isRedirected(request, response, context);
+ } catch (ProtocolException e) {
+ e.printStackTrace();
+ }
+ if (!isRedirect) {
+ int responseCode = response.getStatusLine().getStatusCode();
+ if (responseCode == 301 || responseCode == 302) {
+ return true;
+ }
+ }
+ return isRedirect;
+ }
+ });
+
+ /*
+ * // Apache 1 HttpPost httpPost = new
+ * HttpPost("https://speedport.ip/index/login.cgi"); List
+ * nvps = new ArrayList(); nvps.add(new
+ * BasicNameValuePair("Username", "admin")); nvps.add(new
+ * BasicNameValuePair("Password", password)); httpPost.setEntity(new
+ * UrlEncodedFormEntity(nvps)); HttpResponse response2 =
+ * httpclient.execute(httpPost);
+ *
+ * try { System.out.println(response2.getStatusLine()); HttpEntity
+ * entity2 = response2.getEntity(); // do something useful with the
+ * response body // and ensure it is fully consumed
+ * EntityUtils.consume(entity2); } finally {
+ * httpPost.releaseConnection(); }
+ */
+
+ /*
+ * // Apache 2 PostMethod post = new
+ * PostMethod("https://speedport.ip/index/login.cgi"); NameValuePair[]
+ * data = { new NameValuePair("Username", "admin"), new
+ * NameValuePair("Password", password) }; post.setRequestBody(data);
+ *
+ * // post.setParameter("Cookie", "SessionID_R3=Rian5OU7Cuj");
+ * post.addRequestHeader("Referer", "https://speedport.ip/");
+ * post.addRequestHeader("Cookie", "SessionID_R3=Rian5OU7Cuj");
+ *
+ * try { int resp = client.executeMethod(post);
+ * System.out.println("Response Code: " + resp); } catch (HttpException
+ * e1) { e1.printStackTrace(); } catch (IOException e1) {
+ * e1.printStackTrace(); }
+ *
+ * // execute method and handle any error responses. try { InputStream
+ * in = post.getResponseBodyAsStream(); System.out.println("response: "
+ * + in); } catch (IOException e) { e.printStackTrace(); }
+ */
+
+ httpclient.getConnectionManager().shutdown();
+ }
+
/**
* @param args
*/