use of de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException in project janrufmonitor by tbrandt77.
the class FirmwareManager method login.
public void login() throws FritzBoxLoginException {
boolean dnl = Boolean.parseBoolean(System.getProperty("jam.fritzbox.session.donotlogin", "false"));
if (dnl)
return;
while (this.m_isLoggingIn) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
this.m_isLoggingIn = true;
if (this.m_fw == null) {
this.promptPassword();
try {
this.createFirmwareInstance();
} catch (FritzBoxInitializationException e) {
this.m_fw = null;
if (e.isUnsupportedFirmware()) {
if (this.m_broker != null)
this.m_broker.send(this, this.m_broker.createEvent(IEventConst.EVENT_TYPE_HARDWARE_UNSUPPORTED));
}
throw new FritzBoxLoginException(e.getMessage());
} catch (FritzBoxNotFoundException e) {
this.m_fw = null;
if (this.m_broker != null)
this.m_broker.send(this, this.m_broker.createEvent(IEventConst.EVENT_TYPE_HARDWARE_UNKNOWN_HOST));
throw new FritzBoxLoginException(e.getMessage());
} catch (InvalidSessionIDException e) {
this.m_fw = null;
if (e.getMessage().indexOf("user/password combination") > 0) {
System.setProperty("jam.fritzbox.session.password", "");
if (this.getFritzBoxPassword().trim().length() == 0) {
this.m_isLoggingIn = false;
this.login();
return;
}
}
PropagationFactory.getInstance().fire(new Message(Message.ERROR, "fritzbox.firmware.login", "loginfailed", e, true));
throw new FritzBoxLoginException(e.getMessage());
} finally {
this.m_isLoggingIn = false;
}
}
this.m_isLoggingIn = false;
if (this.m_fw == null)
throw new FritzBoxLoginException("Login failed due to invalid firmware.");
this.m_fw.login();
if (this.m_broker != null)
this.m_broker.send(this, this.m_broker.createEvent(IEventConst.EVENT_TYPE_HARDWARE_RECONNECTED_SUCCESS));
}
use of de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException in project janrufmonitor by tbrandt77.
the class FritzOSFirmware method createSessionID.
private void createSessionID() throws CreateSessionIDException, FritzBoxNotFoundException, InvalidSessionIDException {
try {
Socket fb_socket = new Socket(this.m_address, Integer.parseInt(this.m_port));
fb_socket.close();
} catch (NumberFormatException e) {
throw new FritzBoxNotFoundException(this.m_address, this.m_port);
} catch (UnknownHostException e) {
throw new FritzBoxNotFoundException(this.m_address, this.m_port);
} catch (IOException e) {
throw new FritzBoxNotFoundException(this.m_address, this.m_port);
}
final String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/login_sid.lua";
StringBuffer data = new StringBuffer();
try {
data.append(this.executeURL(urlstr, null, true).trim());
} catch (UnsupportedEncodingException e) {
this.m_logger.warning(e.getMessage());
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
if (e.getCause() instanceof ConnectException) {
throw new FritzBoxNotFoundException(this.m_address, this.m_port);
}
throw new CreateSessionIDException("Could not get a valid challenge code from the FritzBox.");
}
String challenge = find(Pattern.compile(PATTERN_DETECT_CHALLENGE, Pattern.UNICODE_CASE), data);
if (challenge != null) {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Detected FritzBox challenge code: " + challenge);
this.m_response = FritzBoxMD5Handler.getResponse(challenge, this.m_password);
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Calculated FritzBox response code: " + this.m_response);
data = new StringBuffer();
try {
data.append(this.executeURL(urlstr, "username=" + ((this.m_user != null && this.m_user.length() > 0) ? URLEncoder.encode(this.m_user, "ISO-8859-1") : "") + "&response=" + URLEncoder.encode(this.m_response, "ISO-8859-1"), true).trim());
} catch (UnsupportedEncodingException e) {
this.m_logger.warning(e.getMessage());
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
throw new CreateSessionIDException("Could not get a valid Session ID from the FritzBox.");
}
String sid = find(Pattern.compile(PATTERN_DETECT_SID, Pattern.UNICODE_CASE), data);
if (sid != null) {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Detected FritzBox SID: " + sid);
if (sid.equalsIgnoreCase("0000000000000000")) {
throw new CreateSessionIDException("Session ID is 0000000000000000.");
}
this.m_sid = sid;
} else {
throw new CreateSessionIDException("Could not get session ID from FritzBox.");
}
} else {
throw new CreateSessionIDException("Could not generate challenge code for FritzBox password.");
}
}
use of de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException in project janrufmonitor by tbrandt77.
the class TR064FritzBoxFirmware method init.
public void init() throws FritzBoxInitializationException, FritzBoxNotFoundException, InvalidSessionIDException {
try {
if (!this.isTR064Enabled())
throw new FritzBoxInitializationException("FRITZ!Box " + this.m_server + " does not support TR064 or TR064 is disabled.");
this.m_useHttp = Boolean.parseBoolean(System.getProperty("jam.fritzbox.useHttp", "false"));
String version = FritzBoxTR064Manager.getInstance().getFirmwareVersion(this.m_user, this.m_password, this.m_server, (this.m_useHttp ? FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064Port() : FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064SecurePort(this.m_server)), (this.m_useHttp ? "http" : "https"));
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("FritzBox firmware version string: " + version);
if (version != null && version.length() > 0) {
StringTokenizer st = new StringTokenizer(version, ".");
if (st.countTokens() == 3) {
this.m_firmware = new FirmwareData(st.nextToken(), st.nextToken(), st.nextToken());
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Initializing of FritzBox firmware succuessfully finished: " + this.m_firmware.toString());
this.m_loginUptime = FritzBoxTR064Manager.getInstance().getUptime(this.m_user, this.m_password, this.m_server, (this.m_useHttp ? FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064Port() : FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064SecurePort(this.m_server)), (this.m_useHttp ? "http" : "https"));
if (this.m_loginUptime == -1L) {
throw new FritzBoxInitializationException("FritzBox did not provide uptime attribute: " + this.m_loginUptime);
}
} else {
throw new FritzBoxInitializationException("FritzBox version string is invalid: " + version);
}
} else
throw new InvalidSessionIDException("FritzBox could not receive firmware version. Invalid Login data.");
} catch (IOException e) {
if (this.m_logger.isLoggable(Level.SEVERE))
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
if (e.getMessage().indexOf("DH keypair") > 0) {
if (OSUtils.isMacOSX()) {
System.setProperty("jam.fritzbox.useHttp", "true");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("SSL over HTTPS not possible on this Mac. Using HTTP. Set jam.fritzbox.useHttp=true");
this.init();
return;
}
PropagationFactory.getInstance().fire(new Message(Message.ERROR, "fritzbox.firmware.hardware", "sslerror", new String[] { this.m_server, System.getProperty("java.runtime.version", "-") }, new Exception("SSL Handshake failed for server: " + this.m_server), true));
}
throw new FritzBoxInitializationException("FritzBox initializing failed: " + e.getMessage());
}
}
use of de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException in project janrufmonitor by tbrandt77.
the class SessionIDFritzBoxFirmware method createSessionID.
private void createSessionID() throws CreateSessionIDException, FritzBoxNotFoundException, InvalidSessionIDException {
final String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/cgi-bin/webcm";
StringBuffer data = new StringBuffer();
try {
data.append(this.executeURL(urlstr, getAccessMethodPOSTData()[0] + getDetectFirmwarePOSTData()[0] + URLEncoder.encode(this.m_password, "ISO-8859-1"), true).trim());
} catch (UnsupportedEncodingException e) {
this.m_logger.warning(e.getMessage());
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
if (e.getCause() instanceof ConnectException) {
throw new FritzBoxNotFoundException(this.m_address, this.m_port);
}
throw new CreateSessionIDException("Could not get a valid challenge code from the FritzBox.");
}
String challenge = find(Pattern.compile(PATTERN_DETECT_CHALLENGE, Pattern.UNICODE_CASE), data);
if (challenge != null) {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Detected FritzBox challenge code: " + challenge);
this.m_response = FritzBoxMD5Handler.getResponse(challenge, this.m_password);
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Calculated FritzBox response code: " + this.m_response);
data = new StringBuffer();
try {
data.append(this.executeURL(urlstr, getAccessMethodPOSTData()[0] + "&login%3Acommand%2Fresponse=" + URLEncoder.encode(this.m_response, "ISO-8859-1"), true).trim());
} catch (UnsupportedEncodingException e) {
this.m_logger.warning(e.getMessage());
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
throw new CreateSessionIDException("Could not get a valid Session ID from the FritzBox.");
}
String sid = find(Pattern.compile(PATTERN_DETECT_SID, Pattern.UNICODE_CASE), data);
if (sid != null) {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Detected FritzBox SID: " + sid);
if (sid.equalsIgnoreCase("0000000000000000")) {
throw new CreateSessionIDException("Session ID is 0000000000000000.");
}
this.m_sid = sid;
} else {
throw new CreateSessionIDException("Could not get session ID from FritzBox.");
}
} else {
throw new CreateSessionIDException("Could not generate challenge code for FritzBox password.");
}
}
use of de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException in project janrufmonitor by tbrandt77.
the class UnitymediaFirmware method createSessionID.
private void createSessionID() throws CreateSessionIDException, InvalidSessionIDException, FritzBoxNotFoundException {
final String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/cgi-bin/webcm";
StringBuffer data = new StringBuffer();
try {
data.append(this.executeURL(urlstr, getAccessMethodPOSTData()[0] + getDetectFirmwarePOSTData()[0] + URLEncoder.encode(this.m_password, "ISO-8859-1"), true).trim());
} catch (UnsupportedEncodingException e) {
this.m_logger.warning(e.getMessage());
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
if (e.getCause() instanceof ConnectException) {
throw new FritzBoxNotFoundException(this.m_address, this.m_port);
}
throw new CreateSessionIDException("Could not get a valid challenge code from the FritzBox.");
}
String challenge = find(Pattern.compile(PATTERN_DETECT_CHALLENGE, Pattern.UNICODE_CASE), data);
if (challenge != null) {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Detected FritzBox challenge code: " + challenge);
this.m_response = FritzBoxMD5Handler.getResponse(challenge, this.m_password);
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Calculated FritzBox response code: " + this.m_response);
data = new StringBuffer();
try {
data.append(this.executeURL(urlstr, getAccessMethodPOSTData()[0] + "&login%3Acommand%2Fresponse=" + URLEncoder.encode(this.m_response, "ISO-8859-1"), true).trim());
} catch (UnsupportedEncodingException e) {
this.m_logger.warning(e.getMessage());
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
throw new CreateSessionIDException("Could not get a valid Session ID from the FritzBox.");
}
String sid = find(Pattern.compile(PATTERN_DETECT_SID, Pattern.UNICODE_CASE), data);
if (sid != null) {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Detected FritzBox SID: " + sid);
if (sid.equalsIgnoreCase("0000000000000000")) {
throw new CreateSessionIDException("Session ID is 0000000000000000.");
}
this.m_sid = sid;
} else {
throw new CreateSessionIDException("Could not get session ID from FritzBox.");
}
} else {
throw new CreateSessionIDException("Could not generate challenge code for FritzBox password.");
}
}
Aggregations