Search in sources :

Example 1 with FritzBoxInitializationException

use of de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException 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));
}
Also used : FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) Message(de.janrufmonitor.exception.Message) InvalidSessionIDException(de.janrufmonitor.fritzbox.firmware.exception.InvalidSessionIDException) FritzBoxInitializationException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException) FritzBoxNotFoundException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException)

Example 2 with FritzBoxInitializationException

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

the class FirmwareManager method createFirmwareInstance.

private synchronized void createFirmwareInstance() throws FritzBoxInitializationException, FritzBoxNotFoundException, InvalidSessionIDException {
    do {
        try {
            Thread.sleep(250);
            if (this.m_logger.isLoggable(Level.INFO))
                this.m_logger.info("Firmware is beeing created. Sleeping thread: " + Thread.currentThread().getName());
        } catch (InterruptedException e) {
        }
    } while (this.m_isCreatingFirmware);
    this.m_isCreatingFirmware = true;
    if (this.m_fw == null) {
        this.m_fw = new TR064FritzBoxFirmware(getFritzBoxAddress(), getFritzBoxPort(), getFritzBoxPassword(), getFritzBoxUser());
        try {
            if (this.m_fw == null)
                throw new FritzBoxInitializationException("Instantiation of TR064 firmware instance failed.");
            if (!((TR064FritzBoxFirmware) this.m_fw).isTR064Enabled())
                throw new FritzBoxInitializationException("TR064 is not supported or TR064 support disabled by this FRITZ!Box " + this.getFritzBoxAddress());
            if (!this.m_fw.isPasswordValid())
                throw new InvalidSessionIDException("Invalid user/password combination: " + this.getFritzBoxUser() + "/" + this.getFritzBoxPassword());
            this.m_fw.init();
            if (this.m_logger.isLoggable(Level.INFO))
                this.m_logger.info("Detected TR064 Firmware: " + this.m_fw.toString());
        } catch (FritzBoxInitializationException e6) {
            if (this.m_logger.isLoggable(Level.INFO))
                this.m_logger.log(Level.INFO, "No TR064 Firmware detected.", e6);
            this.m_fw = new FritzOS559Firmware(getFritzBoxAddress(), getFritzBoxPort(), getFritzBoxPassword(), getFritzBoxUser(), getFritzBoxUseHttps());
            try {
                if (this.m_fw == null)
                    throw new FritzBoxInitializationException("Instantiation of Fritz!OS 05.59+ firmware instance failed.");
                this.m_fw.init();
                if (this.m_logger.isLoggable(Level.INFO))
                    this.m_logger.info("Detected Fritz!OS 05.59+ firmware: " + this.m_fw.toString());
            } catch (FritzBoxInitializationException e5) {
                if (e5.isUnsupportedFirmware()) {
                    this.m_isCreatingFirmware = false;
                    throw e5;
                }
                if (this.m_logger.isLoggable(Level.INFO))
                    this.m_logger.info("No Fritz!OS 05.59+ Firmware detected.");
                this.m_fw = new FritzOSFirmware(getFritzBoxAddress(), getFritzBoxPort(), getFritzBoxPassword(), getFritzBoxUser(), getFritzBoxUseHttps());
                try {
                    if (this.m_fw == null)
                        throw new FritzBoxInitializationException("Instantiation of Fritz!OS 05.50+ firmware instance failed.");
                    this.m_fw.init();
                    if (this.m_logger.isLoggable(Level.INFO))
                        this.m_logger.info("Detected Fritz!OS 05.50+ firmware: " + this.m_fw.toString());
                } catch (FritzBoxInitializationException e4) {
                    if (this.m_logger.isLoggable(Level.INFO))
                        this.m_logger.info("No Fritz!OS 05.50+ Firmware detected.");
                    this.m_fw = new SessionIDFritzBoxFirmware(getFritzBoxAddress(), getFritzBoxPort(), getFritzBoxPassword(), getFritzBoxUseHttps());
                    try {
                        if (this.m_fw == null)
                            throw new FritzBoxInitializationException("Invalid Session ID firmware instance failed.");
                        this.m_fw.init();
                        if (this.m_logger.isLoggable(Level.INFO))
                            this.m_logger.info("Detected FritzBox Session ID firmware: " + this.m_fw.toString());
                    } catch (FritzBoxInitializationException e3) {
                        if (this.m_logger.isLoggable(Level.INFO))
                            this.m_logger.info("No Session ID Firmware detected.");
                        this.m_fw = new UnitymediaFirmware(getFritzBoxAddress(), getFritzBoxPort(), getFritzBoxPassword(), getFritzBoxUser(), getFritzBoxUseHttps());
                        try {
                            if (this.m_fw == null)
                                throw new FritzBoxInitializationException("Instantiation of Unitymedia firmware instance failed.");
                            this.m_fw.init();
                            if (this.m_logger.isLoggable(Level.INFO))
                                this.m_logger.info("Detected Unitymedia firmware: " + this.m_fw.toString());
                        } catch (FritzBoxInitializationException e2) {
                            if (this.m_logger.isLoggable(Level.INFO))
                                this.m_logger.info("No Unitymedia Firmware detected.");
                            this.m_fw = new PasswordFritzBoxFirmware(getFritzBoxAddress(), getFritzBoxPort(), getFritzBoxPassword());
                            try {
                                if (this.m_fw == null)
                                    throw new FritzBoxInitializationException("Instantiation of standard firmware instance failed.");
                                this.m_fw.init();
                                if (this.m_logger.isLoggable(Level.INFO))
                                    this.m_logger.info("Detected FritzBox standard firmware (password protected): " + this.m_fw.toString());
                            } catch (FritzBoxInitializationException e1) {
                                if (this.m_logger.isLoggable(Level.INFO))
                                    this.m_logger.info("No FritzBox standard Firmware detected.");
                                this.m_fw = null;
                                this.m_isCreatingFirmware = false;
                                throw new InvalidSessionIDException(e1.getMessage());
                            }
                        }
                    }
                }
            }
        } finally {
            this.m_isCreatingFirmware = false;
        }
        if (this.m_fw != null) {
            if (this.m_fw.getFirmwareTimeout() > 0) {
                if (this.m_logger.isLoggable(Level.INFO))
                    this.m_logger.info("FritzBox timeout thread started.");
                this.launchTimeoutThread();
            }
        }
        if (this.m_fw != null) {
            if (this.m_logger.isLoggable(Level.INFO))
                this.m_logger.info("FritzBox restarted thread started.");
            this.launchRestartedThread();
        }
    }
    this.m_isCreatingFirmware = false;
}
Also used : InvalidSessionIDException(de.janrufmonitor.fritzbox.firmware.exception.InvalidSessionIDException) FritzBoxInitializationException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException)

Example 3 with FritzBoxInitializationException

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

use of de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException 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());
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Message(de.janrufmonitor.exception.Message) InvalidSessionIDException(de.janrufmonitor.fritzbox.firmware.exception.InvalidSessionIDException) FritzBoxInitializationException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException) IOException(java.io.IOException) GetCallerListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException) DoCallException(de.janrufmonitor.fritzbox.firmware.exception.DoCallException) GetAddressbooksException(de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException) InvalidSessionIDException(de.janrufmonitor.fritzbox.firmware.exception.InvalidSessionIDException) FritzBoxInitializationException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException) ParseException(java.text.ParseException) FritzBoxNotFoundException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException) DoBlockException(de.janrufmonitor.fritzbox.firmware.exception.DoBlockException) SetCallerException(de.janrufmonitor.fritzbox.firmware.exception.SetCallerException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DeleteCallListException(de.janrufmonitor.fritzbox.firmware.exception.DeleteCallListException) GetBlockedListException(de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException) GetCallListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallListException) GetCallerImageException(de.janrufmonitor.fritzbox.firmware.exception.GetCallerImageException) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DeleteCallerException(de.janrufmonitor.fritzbox.firmware.exception.DeleteCallerException)

Example 5 with FritzBoxInitializationException

use of de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException 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)

Aggregations

FritzBoxInitializationException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException)6 CreateSessionIDException (de.janrufmonitor.fritzbox.firmware.exception.CreateSessionIDException)3 FritzBoxDetectFirmwareException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxDetectFirmwareException)3 InvalidSessionIDException (de.janrufmonitor.fritzbox.firmware.exception.InvalidSessionIDException)3 Message (de.janrufmonitor.exception.Message)2 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)2 FritzBoxNotFoundException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException)2 DeleteCallListException (de.janrufmonitor.fritzbox.firmware.exception.DeleteCallListException)1 DeleteCallerException (de.janrufmonitor.fritzbox.firmware.exception.DeleteCallerException)1 DoBlockException (de.janrufmonitor.fritzbox.firmware.exception.DoBlockException)1 DoCallException (de.janrufmonitor.fritzbox.firmware.exception.DoCallException)1 GetAddressbooksException (de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException)1 GetBlockedListException (de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException)1 GetCallListException (de.janrufmonitor.fritzbox.firmware.exception.GetCallListException)1 GetCallerImageException (de.janrufmonitor.fritzbox.firmware.exception.GetCallerImageException)1 GetCallerListException (de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException)1 SetCallerException (de.janrufmonitor.fritzbox.firmware.exception.SetCallerException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ParseException (java.text.ParseException)1