aufgeräumt
This commit is contained in:
+3
-5
@@ -11,11 +11,9 @@
|
|||||||
<version>1.2.17</version>
|
<version>1.2.17</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>commons-codec</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-codec</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>20041127.091804</version>
|
||||||
<type>jar</type>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@@ -1,17 +1,14 @@
|
|||||||
package de.tilman.callerId;
|
package de.tilman.callerId;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.ConsoleAppender;
|
import org.apache.log4j.ConsoleAppender;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@@ -21,213 +18,109 @@ public class CallerIdClient {
|
|||||||
|
|
||||||
private final static Logger log = Logger.getLogger(CallerIdClient.class);
|
private final static Logger log = Logger.getLogger(CallerIdClient.class);
|
||||||
|
|
||||||
String password = com.sun.org.apache.xerces.internal.impl.dv.util.Base64.encode("53795306".getBytes());
|
String password;
|
||||||
String cookie;
|
String cookie = null;
|
||||||
|
|
||||||
public CallerIdClient() {
|
public CallerIdClient(String routerPassword) {
|
||||||
BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%d{ISO8601} - %m%n")));
|
BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%d{ISO8601} - %m%n")));
|
||||||
|
this.password = new String(Base64.encodeBase64(routerPassword.getBytes()));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
login();
|
postUrl("https://speedport.ip/index/login.cgi", "Username=" + URLEncoder.encode("admin", "UTF-8") + "&" + "Password="
|
||||||
getList();
|
+ password);
|
||||||
// plainJava();
|
getUrl("https://speedport.ip/auth/hcti_status_telanrl.php?cookie=SessionID_R3," + cookie);
|
||||||
logout();
|
postUrl("https://speedport.ip/auth/logout.cgi?RequestFile=/pub/top_beenden.php&cookie=SessionID_R3," + cookie, "");
|
||||||
} catch (Exception e1) {
|
} catch (Exception e) {
|
||||||
e1.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void login() throws Exception {
|
|
||||||
log.info("login()");
|
|
||||||
String body = "Username=" + URLEncoder.encode("admin", "UTF-8") + "&" + "Password=" + password;
|
|
||||||
log.info(body);
|
|
||||||
|
|
||||||
URL url2 = new URL("https://speedport.ip/index/login.cgi");
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url2.openConnection();
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
connection.setDoInput(true);
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
connection.setUseCaches(false);
|
|
||||||
connection.setRequestProperty("Content-Length", String.valueOf(body.length()));
|
|
||||||
|
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
|
|
||||||
writer.write(body);
|
|
||||||
writer.flush();
|
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
||||||
|
|
||||||
for (String line; (line = reader.readLine()) != null;) {
|
|
||||||
if (line.startsWith("SessionID_R3")) {
|
|
||||||
System.out.println("Cookie: " + line);
|
|
||||||
cookie = line.substring(13);
|
|
||||||
} else {
|
|
||||||
System.out.println("Answer: " + line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int status = connection.getResponseCode();
|
|
||||||
System.out.println("Status: " + status);
|
|
||||||
|
|
||||||
writer.close();
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getList() throws Exception {
|
|
||||||
log.info("getList()");
|
|
||||||
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();
|
|
||||||
|
|
||||||
String r = new Scanner(response).useDelimiter("\\Z").next();
|
|
||||||
log.info(r);
|
|
||||||
|
|
||||||
response.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void logout() throws Exception {
|
|
||||||
log.info("logout()");
|
|
||||||
|
|
||||||
getUrl("https://speedport.ip/pub/info_status_de.xml");
|
|
||||||
|
|
||||||
|
|
||||||
URL url = new URL("https://speedport.ip/auth/logout.cgi?RequestFile=/pub/top_beenden.php&cookie=SessionID_R3," + cookie);
|
|
||||||
|
|
||||||
// URLConnection urlConn = url.openConnection();
|
|
||||||
// int statusA = urlConn.get
|
|
||||||
|
|
||||||
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
connection.setInstanceFollowRedirects(false);
|
|
||||||
connection.setDoInput(true);
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
connection.setUseCaches(false);
|
|
||||||
connection.setRequestProperty("Content-Length", "0");
|
|
||||||
connection.setRequestProperty("Cookie", "SessionID_R3=" + cookie);
|
|
||||||
connection.setRequestProperty("Referer", "https://speedport.ip/auth/hcti_status_telanrl.php?cookie=SessionID_R3," + cookie);
|
|
||||||
|
|
||||||
for (int i=0; ; i++) {
|
|
||||||
String headerName = connection.getHeaderFieldKey(i);
|
|
||||||
String headerValue = connection.getHeaderField(i);
|
|
||||||
|
|
||||||
if (headerName == null && headerValue == null) {
|
|
||||||
// No more headers
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (headerName == null) {
|
|
||||||
// The header value contains the server's HTTP version
|
|
||||||
log.info("Server HTTP version, Response code: " + headerValue);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
log.info("Header: " + headerName + ", Value: " + headerValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
||||||
|
|
||||||
for (String line; (line = reader.readLine()) != null;) {
|
|
||||||
System.out.println("Answer: " + line);
|
|
||||||
}
|
|
||||||
|
|
||||||
int status = connection.getResponseCode();
|
|
||||||
log.info("POST Status: " + status);
|
|
||||||
|
|
||||||
reader.close();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// URL myUrl = new URL("https://speedport.ip/auth/logout.cgi?RequestFile=/pub/top_beenden.php&cookie=SessionID_R3," + cookie);
|
|
||||||
//// URL myUrl = new URL("https://speedport.ip/auth/logout.cgi?cookie=SessionID_R3," + cookie);
|
|
||||||
// String cookieString = "SessionID_R3=" + cookie;
|
|
||||||
// URLConnection urlConn = myUrl.openConnection();
|
|
||||||
// urlConn.setRequestProperty("Cookie", cookieString);
|
|
||||||
// urlConn.setRequestProperty("Referer", "https://speedport.ip/auth/hcti_status_telanrl.php?cookie=SessionID_R3," + cookie);
|
|
||||||
// urlConn.connect();
|
|
||||||
// showStatus(urlConn);
|
|
||||||
//
|
|
||||||
URL myUrl = new URL("https://speedport.ip/");
|
|
||||||
URLConnection urlConn = myUrl.openConnection();
|
|
||||||
urlConn.setRequestProperty("Cookie", "SessionID_R3=" + cookie);
|
|
||||||
urlConn.setRequestProperty("Referer", "https://speedport.ip/auth/hcti_status_telanrl.php?cookie=SessionID_R3," + cookie);
|
|
||||||
urlConn.connect();
|
|
||||||
showStatus(urlConn);
|
|
||||||
|
|
||||||
getUrl("https://speedport.ip/pub/js_top_25.js");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getUrl(String urlString) throws Exception {
|
private void getUrl(String urlString) throws Exception {
|
||||||
log.info("getUrl(" + urlString + ")");
|
log.info("getUrl(" + urlString + ")");
|
||||||
|
|
||||||
URL url = new URL(urlString);
|
URL url = new URL(urlString);
|
||||||
URLConnection conn = url.openConnection();
|
URLConnection connection = url.openConnection();
|
||||||
for (int i = 0; ; i++) {
|
|
||||||
String headerName = conn.getHeaderFieldKey(i);
|
showHeaders(connection);
|
||||||
String headerValue = conn.getHeaderField(i);
|
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
String line;
|
||||||
|
|
||||||
|
while ((line = in.readLine()) != null) {
|
||||||
|
if (line.startsWith("var in_call_list")) {
|
||||||
|
// TODO get list
|
||||||
|
}
|
||||||
|
// log.info(" " + line);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void postUrl(String urlString, String payload) throws Exception {
|
||||||
|
log.info("postUrl(" + urlString + ", " + payload + ")");
|
||||||
|
|
||||||
|
URL url = new URL(urlString);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.setInstanceFollowRedirects(false);
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
connection.setUseCaches(false);
|
||||||
|
connection.setRequestProperty("Content-Length", String.valueOf(payload.length()));
|
||||||
|
|
||||||
|
if (cookie != null) {
|
||||||
|
connection.setRequestProperty("Cookie", "SessionID_R3=" + cookie);
|
||||||
|
}
|
||||||
|
// connection.setRequestProperty("Referer", "https://speedport.ip/auth/hcti_status_telanrl.php?cookie=SessionID_R3," + cookie);
|
||||||
|
|
||||||
|
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
|
||||||
|
if (payload.length() > 0) {
|
||||||
|
writer.write(payload);
|
||||||
|
}
|
||||||
|
writer.flush();
|
||||||
|
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
|
||||||
|
for (String line; (line = reader.readLine()) != null;) {
|
||||||
|
if (line.startsWith("SessionID_R3")) {
|
||||||
|
cookie = line.substring(13);
|
||||||
|
} else {
|
||||||
|
log.info(" Received unexpected response: " + line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.close();
|
||||||
|
reader.close();
|
||||||
|
|
||||||
|
showHeaders(connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showHeaders(URLConnection connection) {
|
||||||
|
for (int i = 0;; i++) {
|
||||||
|
String headerName = connection.getHeaderFieldKey(i);
|
||||||
|
String headerValue = connection.getHeaderField(i);
|
||||||
|
|
||||||
if (headerName == null && headerValue == null) {
|
if (headerName == null && headerValue == null) {
|
||||||
|
// No more headers
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (headerName == null) {
|
if (headerName == null) {
|
||||||
|
// The header value contains the server's HTTP version
|
||||||
log.info(" Server HTTP version, Response code: " + headerValue);
|
log.info(" Server HTTP version, Response code: " + headerValue);
|
||||||
}
|
|
||||||
else {
|
|
||||||
log.info(" " + headerName + "=" + headerValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// URL url = new URL(urlString);
|
|
||||||
// URLConnection urlConn = url.openConnection();
|
|
||||||
// String cookieString = "SessionID_R3=" + cookie;
|
|
||||||
// urlConn.setRequestProperty("Cookie", cookieString);
|
|
||||||
// InputStream response = urlConn.getInputStream();
|
|
||||||
// String r = new Scanner(response).useDelimiter("\\Z").next();
|
|
||||||
// log.info(r);
|
|
||||||
// response.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void showStatus(URLConnection connection) throws IOException {
|
|
||||||
HttpURLConnection httpConnection = (HttpURLConnection) connection;
|
|
||||||
log.info("HTTP Status " + httpConnection.getResponseCode() + " - " + httpConnection.getURL());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void plainJava() throws Exception {
|
|
||||||
|
|
||||||
URL url = new URL("https://speedport.ip/auth/logout.cgi?RequestFile=/pub/top_beenden.php&cookie=SessionID_R3," + cookie);
|
|
||||||
URLConnection conn = url.openConnection();
|
|
||||||
|
|
||||||
for (int i = 0;; i++) {
|
|
||||||
String name = conn.getHeaderFieldKey(i);
|
|
||||||
String value = conn.getHeaderField(i);
|
|
||||||
if (name == null && value == null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (name == null) {
|
|
||||||
System.out.println("Server HTTP version, Response code:");
|
|
||||||
System.out.println(value);
|
|
||||||
System.out.print("\n");
|
|
||||||
} else {
|
} else {
|
||||||
System.out.println(name + "=" + value);
|
log.info(" Header: " + headerName + ", Value: " + headerValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Startseite
|
|
||||||
URL u = new URL("https://speedport.ip/");
|
|
||||||
String r = new Scanner(u.openStream()).useDelimiter("\\Z").next();
|
|
||||||
System.out.println(r);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args
|
* @param args
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new CallerIdClient();
|
if (args.length != 1)
|
||||||
|
System.out.println("usage: CallerIdClient <Speedport password>");
|
||||||
|
else
|
||||||
|
new CallerIdClient(args[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user