1 package de.j32.avmfritz;
3 import java.io.ByteArrayOutputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.OutputStream;
8 import org.xml.sax.SAXException;
10 import de.j32.httplib.HttpGETRequest;
11 import de.j32.httplib.HttpPOSTRequest;
12 import de.j32.httplib.HttpRequest;
13 import de.j32.httplib.HttpResponse;
14 import de.j32.util.Util;
21 public FritzBox(String password, String url) throws SAXException,
26 HttpResponse response = null;
28 response = httpGet("cgi-bin/webcm").addParameter("getpage",
29 "../html/login_sid.xml").execute();
30 LoginXML loginxml = new LoginXML(response);
34 if (loginxml.iswriteaccess()) {
35 sid_ = loginxml.sid();
39 response = httpPost("cgi-bin/webcm")
40 .addParameter("getpage", "../html/login_sid.xml")
41 .addParameter("var:lang", "de")
42 .addParameter("login:command/response",
43 loginxml.response(password)).execute();
44 loginxml = new LoginXML(response);
48 if (!loginxml.iswriteaccess()) throw new RuntimeException(
49 "FritzBox login failed");
51 sid_ = loginxml.sid();
54 Util.nothrowClose(response);
59 public InputStream exportAddressbook() throws IOException
61 return httpPostMultipart("cgi-bin/firmwarecfg")
62 .addParameter("sid", sid_).addParameter("PhonebookId", "0")
63 .addParameter("PhonebookExportName", "Telefonbuch")
64 .addParameter("PhonebookExport", "").execute();
67 public OutputStream importAddressbook() throws IOException
69 return new ByteArrayOutputStream() {
70 public void close() throws IOException
72 httpPostMultipart("cgi-bin/firmwarecfg")
73 .addParameter("sid", sid_)
74 .addParameter("PhonebookId", "0")
75 .addParameter("PhonebookImportFile", toByteArray(),
76 "iso-8859-1").execute().close();
81 HttpRequest httpGet(String path)
83 return new HttpGETRequest(url_ + "/" + path);
86 HttpRequest httpPost(String path)
88 return new HttpPOSTRequest(url_ + "/" + path);
91 HttpRequest httpPostMultipart(String path)
93 return new HttpPOSTRequest(url_ + "/" + path).setMultipart(true);