Search in sources :

Example 1 with FritzBoxDetectFirmwareException

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

the class AbstractFritzBoxFirmware method detectFritzBoxFirmware.

private FirmwareData detectFritzBoxFirmware() throws FritzBoxDetectFirmwareException {
    StringBuffer data = new StringBuffer();
    String urlstr = getProtocol() + this.m_address + ":" + this.m_port + getBaseURL();
    boolean detected = false;
    String[] access_method_postdata = this.getAccessMethodPOSTData();
    String[] detect_firmware_postdata = this.getDetectFirmwarePOSTData();
    for (int i = 0; i < (access_method_postdata).length; i++) {
        for (int j = 0; j < (detect_firmware_postdata).length; j++) {
            data = new StringBuffer();
            try {
                data.append(this.executeURL(urlstr, access_method_postdata[i] + detect_firmware_postdata[j] + URLEncoder.encode(getDetectFirmwareURLAuthenticator().getAuthenticationToken(), "ISO-8859-1"), 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(getLanguagePattern());
            Matcher m = p.matcher(data);
            if (m.find()) {
                this.m_language = "de";
                detected = true;
                break;
            }
            if (!detected) {
                p = Pattern.compile(PATTERN_DETECT_LANGUAGE_EN);
                m = p.matcher(data);
                if (m.find()) {
                    this.m_language = "en";
                    detected = true;
                    break;
                }
            }
        }
        if (detected)
            break;
    }
    if (!detected)
        throw new FritzBoxDetectFirmwareException("Unable to detect FritzBox firmware.");
    this.m_logger.info("Using firmware detection pattern: " + PATTERN_DETECT_FIRMWARE_3);
    Pattern p = Pattern.compile(PATTERN_DETECT_FIRMWARE_3);
    Matcher m = p.matcher(data);
    if (m.find()) {
        return new FirmwareData(m.group(1), m.group(2), m.group(3), m.group(4).trim());
    } else {
        this.m_logger.info("Using firmware detection pattern: " + PATTERN_DETECT_FIRMWARE);
        p = Pattern.compile(PATTERN_DETECT_FIRMWARE);
        m = p.matcher(data);
        if (m.find()) {
            return new FirmwareData(m.group(1), m.group(2), m.group(3), m.group(4).trim());
        } else {
            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 2 with FritzBoxDetectFirmwareException

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

the class FritzOS559Firmware 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) {
        if (e.isLaborFirmware())
            throw new FritzBoxInitializationException("FritzBox initialization failed: " + e.getMessage(), 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)

Example 3 with FritzBoxDetectFirmwareException

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

the class FritzOS559Firmware 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("I/O exception during detection of FRITZ!Box firmware: " + e.getMessage(), false);
    }
    Pattern p = Pattern.compile(PATTERN_DETECT_LANGUAGE_DE);
    Matcher m = p.matcher(data);
    if (m.find()) {
        this.m_language = "de";
        detected = true;
    }
    if (!detected) {
        p = Pattern.compile(PATTERN_DETECT_LANGUAGE_EN);
        m = p.matcher(data);
        if (m.find()) {
            this.m_language = "en";
            detected = true;
        }
    }
    if (!detected)
        throw new FritzBoxDetectFirmwareException("Pattern did not match FRITZ!Box firmware: " + PATTERN_DETECT_LANGUAGE_EN, false);
    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), "");
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("Firnware version detected: " + (fwd != null ? fwd.toString() : "[-]"));
        if (fwd.getMajor() == 6)
            is600 = true;
        if (((fwd.getMajor() == 5 && fwd.getMinor() >= 59)) || (fwd.getMajor() == 6 && fwd.getMinor() <= 30))
            return fwd;
        throw new FritzBoxDetectFirmwareException("FRITZ!Box firmware version < 5.59 or > 6.30", false);
    }
    throw new FritzBoxDetectFirmwareException("Could not detect FRITZ!Box firmware version.", true);
}
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 4 with FritzBoxDetectFirmwareException

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

the class FritzOSFirmware 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)

Example 5 with FritzBoxDetectFirmwareException

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

the class FritzOSFirmware 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 && fwd.getMinor() < 59)
            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)

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