Search in sources :

Example 1 with FritzBoxLoginException

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

the class AbstractFritzBoxFirmware method doCall.

public void doCall(String number, String extension) throws DoCallException, IOException {
    try {
        login();
        number = number.replaceAll("\\+", "00");
        String portStr = "";
        if (extension.equals("Fon 1")) {
            portStr = "1";
        } else if (extension.equals("Fon 2")) {
            portStr = "2";
        } else if (extension.equals("Fon 3")) {
            portStr = "3";
        } else if (extension.equals("analog_telephones_all")) {
            portStr = "9";
        } else if (extension.equals("ISDN Alle")) {
            portStr = "50";
        } else if (extension.equals("ISDN 1")) {
            portStr = "51";
        } else if (extension.equals("ISDN 2")) {
            portStr = "52";
        } else if (extension.equals("ISDN 3")) {
            portStr = "53";
        } else if (extension.equals("ISDN 4")) {
            portStr = "54";
        } else if (extension.equals("ISDN 5")) {
            portStr = "55";
        } else if (extension.equals("ISDN 6")) {
            portStr = "56";
        } else if (extension.equals("ISDN 7")) {
            portStr = "57";
        } else if (extension.equals("ISDN 8")) {
            portStr = "58";
        } else if (extension.equals("ISDN 9")) {
            portStr = "59";
        } else {
            portStr = extension;
        }
        String postdata = getCallPOSTData().replaceAll("\\$PASSWORT", URLEncoder.encode(getCallURLAuthenticator().getAuthenticationToken(), "ISO-8859-1"));
        postdata = postdata.replaceAll("\\$NUMMER", number);
        postdata = postdata.replaceAll("\\$NEBENSTELLE", portStr);
        postdata = (this.m_language.equalsIgnoreCase("en") ? getAccessMethodPOSTData()[1] : getAccessMethodPOSTData()[0]) + postdata;
        String urlstr = getProtocol() + this.m_address + ":" + this.m_port + getBaseURL();
        this.executeURL(urlstr, postdata, false);
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("Call with FritzBox succuessfully triggered.");
    } catch (UnsupportedEncodingException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (FritzBoxLoginException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        throw new DoCallException("Dialing of number " + number + " failed: " + e.getMessage());
    }
}
Also used : DoCallException(de.janrufmonitor.fritzbox.firmware.exception.DoCallException) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with FritzBoxLoginException

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

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

the class FirmwareManager method reconnect.

private void reconnect(long timeout) {
    if (this.m_isReconnecting) {
        if (m_logger.isLoggable(Level.INFO))
            m_logger.info("Re-connecting already in progress. Exiting thread " + Thread.currentThread().getName());
        return;
    }
    while (this.m_isReconnecting) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
        }
    }
    this.m_isReconnecting = true;
    IMonitorListener ml = PIMRuntime.getInstance().getMonitorListener();
    if (ml != null && ml.isRunning()) {
        if (m_logger.isLoggable(Level.INFO))
            m_logger.info("Disconnecting FritzBox monitor on port 1012.");
        ml.stop();
    }
    ICommand c = PIMRuntime.getInstance().getCommandFactory().getCommand("Activator");
    if (c != null) {
        try {
            Map m = new HashMap();
            m.put("status", "delay");
            // this method executes the command as well !!
            c.setParameters(m);
        } catch (Exception e) {
            m_logger.log(Level.SEVERE, e.toString(), e);
        }
    }
    if (m_logger.isLoggable(Level.INFO))
        m_logger.info("Disconnecting FritzBox sync on port 80 and 49443/49000.");
    if (m_restartedThread != null && m_restartedThread.isAlive()) {
        m_restartedThread.interrupt();
    }
    if (m_timeoutThread != null && m_timeoutThread.isAlive()) {
        m_timeoutThread.interrupt();
    }
    if (this.m_fw != null) {
        this.m_fw.destroy();
    }
    this.m_fw = null;
    if (getFritzBoxAutoReconnect() && m_retryCount < getFritzBoxMaxRetryCount()) {
        m_retryCount++;
        try {
            Thread.sleep(7000);
        } catch (InterruptedException e1) {
        }
        if (m_logger.isLoggable(Level.INFO))
            m_logger.info("Re-connecting is configured. Retry counter = " + m_retryCount);
        PropagationFactory.getInstance().fire(new Message(Message.INFO, "fritzbox.firmware.hardware", "reconnect", new String[] { getFritzBoxAddress(), Integer.toString(m_retryCount) }, new Exception("Reconnecting to FRITZ!Box " + getFritzBoxAddress()), false), "Tray");
        try {
            if (m_logger.isLoggable(Level.INFO))
                m_logger.info("Sleeping " + timeout + " ms before re-connect try.");
            Thread.sleep(timeout);
        } catch (InterruptedException e) {
        }
        try {
            this.login();
            if (m_logger.isLoggable(Level.INFO))
                m_logger.info("Automatic re-connect to FritzBox done...");
        } catch (FritzBoxLoginException e) {
            // check for reason
            m_logger.log(Level.WARNING, e.getMessage(), e);
            if (m_logger.isLoggable(Level.INFO))
                m_logger.info("Automatic re-connect to FritzBox failed...");
        }
        Thread t = new Thread(new Runnable() {

            public void run() {
                IMonitorListener ml = PIMRuntime.getInstance().getMonitorListener();
                if (ml != null && !ml.isRunning()) {
                    ml.start();
                    ICommand c = PIMRuntime.getInstance().getCommandFactory().getCommand("Activator");
                    if (c != null) {
                        try {
                            Map m = new HashMap();
                            m.put("status", "delay");
                            // this method executes the command as well !!
                            c.setParameters(m);
                        } catch (Exception e) {
                            m_logger.log(Level.SEVERE, e.toString(), e);
                        }
                    }
                }
            }
        });
        t.setName("JAM-FritzBoxFirmwareRestartMonitor-Thread-(daemon)");
        t.setDaemon(true);
        t.start();
    } else if (getFritzBoxAutoReconnect() && m_retryCount >= getFritzBoxMaxRetryCount()) {
        PropagationFactory.getInstance().fire(new Message(Message.INFO, "fritzbox.firmware.hardware", "maxreconnect", new String[] { Integer.toString((m_retryCount > getFritzBoxMaxRetryCount() ? getFritzBoxMaxRetryCount() : m_retryCount)) }, new Exception("Maximum retry count reached " + m_retryCount), false), "Tray");
    }
    this.m_isReconnecting = false;
}
Also used : IMonitorListener(de.janrufmonitor.framework.monitor.IMonitorListener) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) Message(de.janrufmonitor.exception.Message) HashMap(java.util.HashMap) ICommand(de.janrufmonitor.framework.command.ICommand) HashMap(java.util.HashMap) Map(java.util.Map) DeleteCallListException(de.janrufmonitor.fritzbox.firmware.exception.DeleteCallListException) GetCallerListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException) GetBlockedListException(de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException) 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) GetCallListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallListException) GetCallerImageException(de.janrufmonitor.fritzbox.firmware.exception.GetCallerImageException) FritzBoxNotFoundException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxNotFoundException) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) DoBlockException(de.janrufmonitor.fritzbox.firmware.exception.DoBlockException) IOException(java.io.IOException) SetCallerException(de.janrufmonitor.fritzbox.firmware.exception.SetCallerException) DeleteCallerException(de.janrufmonitor.fritzbox.firmware.exception.DeleteCallerException)

Example 4 with FritzBoxLoginException

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

the class PasswordFritzBoxFirmware method login.

public void login() throws FritzBoxLoginException {
    super.login();
    try {
        String postdata = POSTDATA_LOGIN.replaceAll("\\$PASSWORT", URLEncoder.encode(this.m_password, "ISO-8859-1"));
        postdata = (this.m_language.equalsIgnoreCase("en") ? getAccessMethodPOSTData()[1] : getAccessMethodPOSTData()[0]) + postdata;
        String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/cgi-bin/webcm";
        executeURL(urlstr, postdata, true);
    } catch (UnsupportedEncodingException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (IOException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        throw new FritzBoxLoginException("Login to FritzBox failed. Please check password.");
    }
}
Also used : FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 5 with FritzBoxLoginException

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

the class FritzBoxPhonebookManager method startup.

public void startup() {
    super.startup();
    if (this.isActive()) {
        int counter = 0;
        do {
            try {
                counter++;
                FirmwareManager fwm = FirmwareManager.getInstance();
                fwm.startup();
                if (!fwm.isLoggedIn())
                    fwm.login();
                m_loggedin = true;
            } catch (FritzBoxLoginException e) {
                this.m_logger.log(Level.SEVERE, "Login to fritzbox trial #" + counter + " failed. Retrying.", e);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e1) {
                }
            }
        } while (!m_loggedin && counter < 5);
        if (m_loggedin) {
            Thread t = new Thread(new Runnable() {

                Logger m_logger;

                public void run() {
                    this.m_logger = LogManager.getLogManager().getLogger(IJAMConst.DEFAULT_LOGGER);
                    if (this.m_logger.isLoggable(Level.FINE))
                        this.m_logger.fine("Starting JAM-FritzBoxPhonebookHashChecker-Thread");
                    do {
                        FirmwareManager fwm = FirmwareManager.getInstance();
                        try {
                            if (this.m_logger.isLoggable(Level.INFO))
                                this.m_logger.info("FritzBox Firmware created.");
                            fwm.login();
                            if (this.m_logger.isLoggable(Level.INFO))
                                this.m_logger.info("Login to FritzBox successfull.");
                            // check if phonebook is configured
                            String abId = getConfiguration().getProperty(CFG_ADDRESSBOOK, "0");
                            if (this.m_logger.isLoggable(Level.INFO))
                                this.m_logger.info("Getting FritzBox phonebook ID: #" + abId);
                            int id = Integer.parseInt(abId);
                            String newAbHash = fwm.getAddressbookModificationHash(id);
                            if (newAbHash != null && !newAbHash.equals(m_lastAbHash)) {
                                m_lastAbHash = newAbHash;
                                createCallerListFromFritzBoxPhonebook();
                            }
                        } catch (FritzBoxLoginException e2) {
                            this.m_logger.log(Level.SEVERE, e2.getMessage(), e2);
                        } catch (IOException e) {
                            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                        } catch (Throwable e) {
                            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                        }
                        try {
                            Thread.sleep(getSyncInterval());
                        } catch (InterruptedException e) {
                        }
                    } while (m_loggedin);
                }
            });
            t.setDaemon(true);
            t.setName("JAM-FritzBoxPhonebookHashChecker-Thread-(deamon)");
            t.start();
        }
    }
}
Also used : FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) IOException(java.io.IOException) Logger(java.util.logging.Logger)

Aggregations

FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)19 IOException (java.io.IOException)16 FirmwareManager (de.janrufmonitor.fritzbox.firmware.FirmwareManager)14 Message (de.janrufmonitor.exception.Message)9 DoCallException (de.janrufmonitor.fritzbox.firmware.exception.DoCallException)6 Shell (org.eclipse.swt.widgets.Shell)5 ICall (de.janrufmonitor.framework.ICall)4 DeleteCallListException (de.janrufmonitor.fritzbox.firmware.exception.DeleteCallListException)4 GetAddressbooksException (de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException)4 Map (java.util.Map)4 Properties (java.util.Properties)4 ICallerList (de.janrufmonitor.framework.ICallerList)3 ICommand (de.janrufmonitor.framework.command.ICommand)3 DeleteCallerException (de.janrufmonitor.fritzbox.firmware.exception.DeleteCallerException)3 DoBlockException (de.janrufmonitor.fritzbox.firmware.exception.DoBlockException)3 FritzBoxInitializationException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxInitializationException)3 GetCallListException (de.janrufmonitor.fritzbox.firmware.exception.GetCallListException)3 GetCallerListException (de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException)3 SetCallerException (de.janrufmonitor.fritzbox.firmware.exception.SetCallerException)3 SWTExecuter (de.janrufmonitor.ui.swt.SWTExecuter)3