Search in sources :

Example 1 with FirmwareManager

use of de.janrufmonitor.fritzbox.firmware.FirmwareManager in project janrufmonitor by tbrandt77.

the class FritzBoxVoip method createFieldEditors.

protected void createFieldEditors() {
    StringFieldEditor sfe = null;
    BooleanFieldEditor bfe = new BooleanFieldEditor(getConfigNamespace() + SEPARATOR + "activemonitor", this.m_i18n.getString(this.getNamespace(), "activemonitor", "label", this.m_language), this.getFieldEditorParent());
    addField(bfe);
    if (isExpertMode()) {
        bfe = new BooleanFieldEditor(getConfigNamespace() + SEPARATOR + "outgoing", this.m_i18n.getString(this.getNamespace(), "outgoing", "label", this.m_language), this.getFieldEditorParent());
        addField(bfe);
        sfe = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "boxip", this.m_i18n.getString(this.getNamespace(), "boxip", "label", this.m_language), this.getFieldEditorParent());
        sfe.setEmptyStringAllowed(false);
        addField(sfe);
    }
    mode = new ComboFieldEditor(getConfigNamespace() + SEPARATOR + "boxloginmode", this.m_i18n.getString(this.getNamespace(), "boxloginmode", "label", this.m_language), new String[][] { { this.m_i18n.getString(this.getNamespace(), "userpassword", "label", this.m_language), "0" }, { this.m_i18n.getString(this.getNamespace(), "password_only", "label", this.m_language), "1" } }, this.getFieldEditorParent());
    addField(mode);
    this.user = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "boxuser", this.m_i18n.getString(this.getNamespace(), "boxuser", "label", this.m_language), this.getFieldEditorParent());
    addField(this.user);
    String state = this.getPreferenceStore().getString(getConfigNamespace() + SEPARATOR + "boxloginmode");
    if (state.equalsIgnoreCase("1")) {
        this.user.setEnabled(false, this.getFieldEditorParent());
        this.user.getTextControl(getFieldEditorParent()).setBackground(new Color(DisplayManager.getDefaultDisplay(), 190, 190, 190));
        this.user.setStringValue("");
    }
    sfe = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "boxpassword", this.m_i18n.getString(this.getNamespace(), "boxpassword", "label", this.m_language), this.getFieldEditorParent());
    sfe.getTextControl(this.getFieldEditorParent()).setEchoChar('*');
    addField(sfe);
    if (isExpertMode()) {
        IntegerFieldEditor ife = new IntegerFieldEditor(getConfigNamespace() + SEPARATOR + "retrymax", this.m_i18n.getString(this.getNamespace(), "retrymax", "label", this.m_language), this.getFieldEditorParent());
        ife.setTextLimit(3);
        addField(ife);
        ife = new IntegerFieldEditor(getConfigNamespace() + SEPARATOR + "retrytimeouts", this.m_i18n.getString(this.getNamespace(), "retrytimeouts", "label", this.m_language), this.getFieldEditorParent());
        ife.setTextLimit(3);
        addField(ife);
        bfe = new BooleanFieldEditor(getConfigNamespace() + SEPARATOR + "tr064off", this.m_i18n.getString(this.getNamespace(), "tr064off", "label", this.m_language), this.getFieldEditorParent());
        addField(bfe);
        new Label(this.getFieldEditorParent(), SWT.NULL);
        new Label(this.getFieldEditorParent(), SWT.NULL);
        ComboFieldEditor cfe = new ComboFieldEditor(getConfigNamespace() + SEPARATOR + "boxclickdial", this.m_i18n.getString(this.getNamespace(), "boxclickdial", "label", this.m_language), new String[][] { { this.m_i18n.getString(this.getNamespace(), "manual", "label", this.m_language), "0" }, { this.m_i18n.getString(this.getNamespace(), "all_analog", "label", this.m_language), "9" }, { this.m_i18n.getString(this.getNamespace(), "all_isdn", "label", this.m_language), "50" }, { "FON 1", "1" }, { "FON 2", "2" }, { "FON 3", "3" }, { "ISDN 1", "51" }, { "ISDN 2", "52" }, { "ISDN 3", "53" }, { "ISDN 4", "54" }, { "ISDN 5", "55" }, { "ISDN 6", "56" }, { "ISDN 7", "57" }, { "ISDN 8", "58" }, { "ISDN 9", "59" }, { "DECT 610", "60" }, { "DECT 611", "61" }, { "DECT 612", "62" }, { "DECT 613", "63" }, { "DECT 614", "64" }, { "DECT 615", "65" } }, this.getFieldEditorParent());
        addField(cfe);
        sfe = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "dialprefixes", this.m_i18n.getString(this.getNamespace(), "dialprefixes", "label", this.m_language), this.getFieldEditorParent());
        sfe.setEmptyStringAllowed(true);
        addField(sfe);
        new Label(this.getFieldEditorParent(), SWT.NULL);
        new Label(this.getFieldEditorParent(), SWT.NULL);
    }
    IMonitor fbMonitor = this.getRuntime().getMonitorListener().getMonitor("FritzBoxMonitor");
    if (fbMonitor != null) {
        String[] fbInfos = fbMonitor.getDescription();
        Label capi_label = new Label(this.getFieldEditorParent(), 0);
        capi_label.setText(this.m_i18n.getString(this.getNamespace(), "fbinfo", "label", this.m_language));
        for (int i = 0; i < fbInfos.length; i++) {
            if (fbInfos[i].trim().length() > 0) {
                Label capi = new Label(this.getFieldEditorParent(), SWT.NULL);
                capi.setText(fbInfos[i]);
                new Label(this.getFieldEditorParent(), SWT.NULL);
            }
        }
    }
    new Label(this.getFieldEditorParent(), SWT.NULL);
    Label statusl = new Label(this.getFieldEditorParent(), 0);
    statusl.setText(this.m_i18n.getString(this.getNamespace(), "status", "label", this.m_language));
    Label status_observer = new Label(this.getFieldEditorParent(), SWT.NULL);
    status_observer.setText(this.m_i18n.getString(this.getNamespace(), "statuso", "label", this.m_language) + ((fbMonitor != null && fbMonitor.isStarted()) ? "OK" : "---"));
    new Label(this.getFieldEditorParent(), SWT.NULL);
    FirmwareManager fwm = FirmwareManager.getInstance();
    fwm.startup();
    if (fwm.isLoggedIn() && !fwm.isInstance(TR064FritzBoxFirmware.class)) {
        Label status_sync = new Label(this.getFieldEditorParent(), SWT.NULL);
        status_sync.setText(this.m_i18n.getString(this.getNamespace(), "statuss", "label", this.m_language) + (fwm.isLoggedIn() ? "OK" : "---"));
        new Label(this.getFieldEditorParent(), SWT.NULL);
        if (fbMonitor != null && fbMonitor.isStarted() && fwm.isLoggedIn()) {
            // set icon to colored
            IService tray = this.getRuntime().getServiceFactory().getService("TrayIcon");
            try {
                Method m = tray.getClass().getMethod("setIconStateActive", new Class[] {});
                if (m != null) {
                    m.invoke(tray, new Object[] {});
                }
            } catch (Exception ex) {
            }
        }
        if ((fbMonitor == null || !fbMonitor.isStarted()) && !fwm.isLoggedIn()) {
            // set icon to colored
            IService tray = this.getRuntime().getServiceFactory().getService("TrayIcon");
            try {
                Method m = tray.getClass().getMethod("setIconStateInactive", new Class[] {});
                if (m != null) {
                    m.invoke(tray, new Object[] {});
                }
            } catch (Exception ex) {
            }
        }
    }
}
Also used : Color(org.eclipse.swt.graphics.Color) Label(org.eclipse.swt.widgets.Label) BooleanFieldEditor(de.janrufmonitor.ui.jface.configuration.controls.BooleanFieldEditor) Method(java.lang.reflect.Method) ComboFieldEditor(org.eclipse.jface.preference.ComboFieldEditor) IMonitor(de.janrufmonitor.framework.monitor.IMonitor) StringFieldEditor(org.eclipse.jface.preference.StringFieldEditor) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) IntegerFieldEditor(org.eclipse.jface.preference.IntegerFieldEditor) IService(de.janrufmonitor.service.IService)

Example 2 with FirmwareManager

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

Example 3 with FirmwareManager

use of de.janrufmonitor.fritzbox.firmware.FirmwareManager in project janrufmonitor by tbrandt77.

the class AbstractFritzBoxCall method getOutgoingState.

protected int getOutgoingState() {
    if (this.m_outgoingState == -1) {
        this.m_outgoingState = 4;
        FirmwareManager fwm = FirmwareManager.getInstance();
        if (fwm.isInstance(UnitymediaFirmware.class))
            this.m_outgoingState = 3;
        if (fwm.isInstance(SessionIDFritzBoxFirmware.class))
            this.m_outgoingState = 3;
        if (fwm.isInstance(PasswordFritzBoxFirmware.class))
            this.m_outgoingState = 3;
    }
    return this.m_outgoingState;
}
Also used : FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager)

Example 4 with FirmwareManager

use of de.janrufmonitor.fritzbox.firmware.FirmwareManager in project janrufmonitor by tbrandt77.

the class FritzBoxDialogPlugin method run.

public void run() {
    new SWTExecuter(this.getLabel()) {

        protected void execute() {
            ICaller o = m_dialog.getCall().getCaller();
            String dial = ((ICaller) o).getPhoneNumber().getTelephoneNumber();
            if (!((ICaller) o).getPhoneNumber().getIntAreaCode().equalsIgnoreCase(getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_INTAREA))) {
                dial = "00" + ((ICaller) o).getPhoneNumber().getIntAreaCode() + dial;
            }
            if (!dial.startsWith("0"))
                dial = "0" + dial;
            String text = getI18nManager().getString(getNamespaceDial(), "dial", "description", getLanguage());
            text = StringUtils.replaceString(text, "{%1}", dial);
            if (MessageDialog.openConfirm(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespaceDial(), "success", "label", getLanguage()), text)) {
                Properties config = getRuntime().getConfigManagerFactory().getConfigManager().getProperties(FritzBoxMonitor.NAMESPACE);
                FirmwareManager fwm = FirmwareManager.getInstance();
                try {
                    if (!fwm.isLoggedIn())
                        fwm.login();
                    fwm.doCall(dial, config.getProperty(CFG_CLICKDIAL, "50"));
                    text = getI18nManager().getString(getNamespaceDial(), "success", "description", getLanguage());
                    text = StringUtils.replaceString(text, "{%1}", dial);
                    MessageDialog.openInformation(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespaceDial(), "success", "label", getLanguage()), text);
                } catch (IOException e) {
                    m_logger.warning(e.toString());
                    PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespaceDial(), "faileddial", e));
                } catch (FritzBoxLoginException e) {
                    m_logger.warning(e.toString());
                    PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespaceDial(), "faileddial", e));
                } catch (DoCallException e) {
                    m_logger.warning(e.toString());
                    PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespaceDial(), "faileddial", e));
                }
            }
        }
    }.start();
}
Also used : DoCallException(de.janrufmonitor.fritzbox.firmware.exception.DoCallException) ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) Message(de.janrufmonitor.exception.Message) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) IOException(java.io.IOException) Properties(java.util.Properties) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter)

Example 5 with FirmwareManager

use of de.janrufmonitor.fritzbox.firmware.FirmwareManager in project janrufmonitor by tbrandt77.

the class InitFritzBoxVariantPage method performFinish.

public boolean performFinish() {
    if (m_boxip == null || m_boxip.trim().length() == 0) {
        try {
            Thread.sleep(550);
        } catch (InterruptedException e) {
            m_logger.log(Level.SEVERE, e.getMessage(), e);
        }
        return true;
    }
    getRuntime().getConfigManagerFactory().getConfigManager().setProperty(FritzBoxMonitor.NAMESPACE, "boxip", m_boxip);
    getRuntime().getConfigManagerFactory().getConfigManager().setProperty(FritzBoxMonitor.NAMESPACE, "boxpassword", m_boxpassword);
    getRuntime().getConfigManagerFactory().getConfigManager().setProperty(FritzBoxMonitor.NAMESPACE, "boxuser", m_boxuser);
    getRuntime().getConfigManagerFactory().getConfigManager().setProperty(FritzBoxMonitor.NAMESPACE, "activemonitor", (m_active ? "true" : "false"));
    getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
        return false;
    }
    getRuntime().getConfigurableNotifier().notifyByNamespace(FritzBoxMonitor.NAMESPACE);
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
        return false;
    }
    if (m_active && !getRuntime().getMonitorListener().isRunning()) {
        getRuntime().getMonitorListener().start();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            m_logger.log(Level.SEVERE, e.getMessage(), e);
            return false;
        }
        ICommand c = PIMRuntime.getInstance().getCommandFactory().getCommand("Activator");
        if (c != null) {
            try {
                Map m = new HashMap();
                IMonitor mon = getRuntime().getMonitorListener().getDefaultMonitor();
                m.put("status", (mon.isStarted() ? "revert" : "invert"));
                // this method executes the command as well !!
                c.setParameters(m);
            } catch (Exception e) {
                m_logger.log(Level.SEVERE, e.toString(), e);
            }
        }
    }
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
        return false;
    }
    // save MSN settings
    if (m_usemsns) {
        FirmwareManager fwm = FirmwareManager.getInstance();
        fwm.startup();
        try {
            if (!fwm.isLoggedIn())
                fwm.login();
            Map msns = fwm.getMSNMap();
            if (msns != null && msns.size() > 0) {
                StringBuffer list = new StringBuffer();
                Iterator i = msns.keySet().iterator();
                String msn = null;
                while (i.hasNext()) {
                    msn = (String) i.next();
                    list.append(msn);
                    list.append(",");
                    getRuntime().getConfigManagerFactory().getConfigManager().setProperty("manager.MsnManager", msn + "_msn", msn);
                    getRuntime().getConfigManagerFactory().getConfigManager().setProperty("manager.MsnManager", msn + "_label", (String) msns.get(msn));
                }
                getRuntime().getConfigManagerFactory().getConfigManager().setProperty("manager.MsnManager", "list", list.toString());
                getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
            }
        } catch (IOException e) {
            m_logger.log(Level.SEVERE, e.toString(), e);
        } catch (FritzBoxLoginException e) {
            m_logger.log(Level.SEVERE, e.toString(), e);
        }
    }
    return true;
}
Also used : FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) HashMap(java.util.HashMap) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) ICommand(de.janrufmonitor.framework.command.ICommand) Iterator(java.util.Iterator) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) IMonitor(de.janrufmonitor.framework.monitor.IMonitor) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) IOException(java.io.IOException)

Aggregations

FirmwareManager (de.janrufmonitor.fritzbox.firmware.FirmwareManager)19 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)14 IOException (java.io.IOException)14 Message (de.janrufmonitor.exception.Message)6 Properties (java.util.Properties)5 Shell (org.eclipse.swt.widgets.Shell)5 ICall (de.janrufmonitor.framework.ICall)4 ICallerList (de.janrufmonitor.framework.ICallerList)3 DoCallException (de.janrufmonitor.fritzbox.firmware.exception.DoCallException)3 SWTExecuter (de.janrufmonitor.ui.swt.SWTExecuter)3 File (java.io.File)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 SQLException (java.sql.SQLException)3 Map (java.util.Map)3 ICaller (de.janrufmonitor.framework.ICaller)2 IMonitor (de.janrufmonitor.framework.monitor.IMonitor)2 IPhonebookEntry (de.janrufmonitor.fritzbox.IPhonebookEntry)2 DeleteCallListException (de.janrufmonitor.fritzbox.firmware.exception.DeleteCallListException)2 GetAddressbooksException (de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException)2 HashMap (java.util.HashMap)2