Search in sources :

Example 6 with FritzBoxDetectFirmwareException

use of de.janrufmonitor.fritzbox.firmware.exception.FritzBoxDetectFirmwareException in project janrufmonitor by tbrandt77.

the class UnitymediaFirmware method detectFritzBoxFirmware.

private FirmwareData detectFritzBoxFirmware() throws FritzBoxDetectFirmwareException {
    StringBuffer data = new StringBuffer();
    String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/home/pp_fbos.lua?sid=" + this.m_sid;
    boolean detected = false;
    try {
        data.append(this.executeURL(urlstr, null, true).trim());
    } catch (UnsupportedEncodingException e) {
        this.m_logger.log(Level.WARNING, e.getMessage(), e);
    } catch (IOException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        throw new FritzBoxDetectFirmwareException("Could not detect fritzbox firmware: " + e.getMessage());
    }
    Pattern p = Pattern.compile(PATTERN_DETECT_LANGUAGE);
    Matcher m = p.matcher(data);
    if (m.find()) {
        this.m_language = "de";
        detected = true;
    }
    if (!detected)
        throw new FritzBoxDetectFirmwareException("Unable to detect FritzBox firmware.");
    this.m_logger.info("Using firmware detection pattern: " + PATTERN_DETECT_FIRMWARE);
    p = Pattern.compile(PATTERN_DETECT_FIRMWARE);
    m = p.matcher(data);
    if (m.find()) {
        FirmwareData fwd = new FirmwareData(m.group(1), m.group(2), m.group(3), m.group(4).trim());
        if (fwd.getMajor() >= 5 && fwd.getMinor() < 50)
            return fwd;
    }
    throw new FritzBoxDetectFirmwareException("Could not detect FRITZ!Box firmware version.");
}
Also used : FritzBoxDetectFirmwareException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxDetectFirmwareException) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 7 with FritzBoxDetectFirmwareException

use of de.janrufmonitor.fritzbox.firmware.exception.FritzBoxDetectFirmwareException in project janrufmonitor by tbrandt77.

the class UnitymediaFirmware method init.

public void init() throws FritzBoxInitializationException, FritzBoxNotFoundException, InvalidSessionIDException {
    try {
        this.createSessionID();
        this.m_firmware = this.detectFritzBoxFirmware();
    } catch (CreateSessionIDException e) {
        throw new FritzBoxInitializationException("FritzBox initialization failed: " + e.getMessage());
    } catch (FritzBoxDetectFirmwareException e) {
        throw new FritzBoxInitializationException("FritzBox initialization failed: " + e.getMessage());
    }
}
Also used : FritzBoxDetectFirmwareException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxDetectFirmwareException) FritzBoxInitializationException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException) CreateSessionIDException(de.janrufmonitor.fritzbox.firmware.exception.CreateSessionIDException)

Aggregations

FritzBoxDetectFirmwareException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxDetectFirmwareException)7 IOException (java.io.IOException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 CreateSessionIDException (de.janrufmonitor.fritzbox.firmware.exception.CreateSessionIDException)3 FritzBoxInitializationException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException)3