Search in sources :

Example 1 with CreateSessionIDException

use of de.janrufmonitor.fritzbox.firmware.exception.CreateSessionIDException 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 2 with CreateSessionIDException

use of de.janrufmonitor.fritzbox.firmware.exception.CreateSessionIDException 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.");
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) FritzBoxNotFoundException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CreateSessionIDException(de.janrufmonitor.fritzbox.firmware.exception.CreateSessionIDException) IOException(java.io.IOException) Socket(java.net.Socket) ConnectException(java.net.ConnectException)

Example 3 with CreateSessionIDException

use of de.janrufmonitor.fritzbox.firmware.exception.CreateSessionIDException 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.");
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) FritzBoxNotFoundException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException) CreateSessionIDException(de.janrufmonitor.fritzbox.firmware.exception.CreateSessionIDException) IOException(java.io.IOException) ConnectException(java.net.ConnectException)

Example 4 with CreateSessionIDException

use of de.janrufmonitor.fritzbox.firmware.exception.CreateSessionIDException 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.");
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) FritzBoxNotFoundException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException) CreateSessionIDException(de.janrufmonitor.fritzbox.firmware.exception.CreateSessionIDException) IOException(java.io.IOException) ConnectException(java.net.ConnectException)

Example 5 with CreateSessionIDException

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

the class FritzOS559Firmware 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 FRITZ!Box challenge code: " + challenge);
        this.m_response = FritzBoxMD5Handler.getResponse(challenge, this.m_password);
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("Calculated FRITZ!Box 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 FRITZ!Box.");
        }
        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 FRITZ!Box.");
        }
    } else {
        throw new CreateSessionIDException("Could not generate challenge code for FRITZ!Box password.");
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) FritzBoxNotFoundException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CreateSessionIDException(de.janrufmonitor.fritzbox.firmware.exception.CreateSessionIDException) IOException(java.io.IOException) Socket(java.net.Socket) ConnectException(java.net.ConnectException)

Aggregations

CreateSessionIDException (de.janrufmonitor.fritzbox.firmware.exception.CreateSessionIDException)7 FritzBoxNotFoundException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException)4 IOException (java.io.IOException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ConnectException (java.net.ConnectException)4 FritzBoxDetectFirmwareException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxDetectFirmwareException)3 FritzBoxInitializationException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException)3 Socket (java.net.Socket)2 UnknownHostException (java.net.UnknownHostException)2