Search in sources :

Example 1 with DoCallException

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

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

the class FritzOSFirmware method doCall.

public void doCall(String number, String extension) throws DoCallException, IOException {
    if (!this.isInitialized())
        throw new DoCallException("Could not dial number on FritzBox: FritzBox firmware not initialized.");
    StringBuffer data = new StringBuffer();
    if (number.endsWith("#"))
        number = number.substring(0, number.length() - 1);
    // 2013/02/05: removed dial via wahlhilfe only
    // String urlstr = getProtocol() + this.m_address +":" + this.m_port + "/fon_num/fonbook_list.lua?sid="+this.m_sid+"&dial="+number+"&xhr=1";
    String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/cgi-bin/webcm";
    try {
        data.append(this.executeURL(urlstr, "&sid=" + this.m_sid + "telcfg:settings/UseClickToDial=1&telcfg:settings/DialPort=" + extension + "&telcfg:command/Dial=" + number, 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 DoCallException("Could not dial numer on FritzBox: " + e.getMessage());
    }
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info("Data after call initialization: " + data.toString());
}
Also used : DoCallException(de.janrufmonitor.fritzbox.firmware.exception.DoCallException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 3 with DoCallException

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

the class TR064FritzBoxFirmware method doCall.

public void doCall(String number, String extension) throws DoCallException, IOException {
    if (!this.isInitialized())
        throw new DoCallException("Could not dial number on FritzBox: FritzBox firmware not initialized.");
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info("dial number: " + number + ", extension: " + extension);
    StringBuffer data = new StringBuffer();
    if (number.endsWith("#"))
        number = number.substring(0, number.length() - 1);
    String u = "http://" + this.m_server + ":" + this.m_port;
    if (this.m_firmware != null && this.m_firmware.getMajor() >= 6 && this.m_firmware.getMinor() >= 30) {
        try {
            String body = "sid=" + FritzBoxTR064Manager.getInstance().getSID(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")) + "&clicktodial=on&port=" + extension + "&btn_apply=";
            if (this.m_logger.isLoggable(Level.INFO))
                this.m_logger.info("Set up extension for dialing: " + body);
            data.append(doHttpCall(u + "/fon_num/dial_foncalls.lua", "POST", body, new String[][] { { "Content-Length", Integer.toString(body.length()) } }));
            String dial_u = u + "/fon_num/fonbook_list.lua?sid=" + FritzBoxTR064Manager.getInstance().getSID(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")) + "&dial=" + StringUtils.urlEncode(number);
            if (this.m_logger.isLoggable(Level.INFO))
                this.m_logger.info("Dial URL: " + dial_u);
            data.append(doHttpCall(dial_u, "GET", null, new String[][] {}));
        } 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 DoCallException("Could not dial numer on FritzBox: " + e.getMessage());
        }
    } else {
        try {
            String body = "&sid=" + FritzBoxTR064Manager.getInstance().getSID(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")) + "&telcfg:settings/UseClickToDial=1&telcfg:settings/DialPort=" + extension + "&telcfg:command/Dial=" + number;
            data.append(doHttpCall(u + "/cgi-bin/webcm", "POST", body, new String[][] { { "Content-Length", Integer.toString(body.length()) } }));
        } 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 DoCallException("Could not dial number on FritzBox: " + e.getMessage());
        }
    }
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info("Data after call initialization: " + data.toString());
}
Also used : DoCallException(de.janrufmonitor.fritzbox.firmware.exception.DoCallException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 4 with DoCallException

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

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

the class UnitymediaFirmware method doCall.

public void doCall(String number, String extension) throws DoCallException, IOException {
    if (!this.isInitialized())
        throw new DoCallException("Could not dial number on FritzBox: FritzBox firmware not initialized.");
    StringBuffer data = new StringBuffer();
    if (number.endsWith("#"))
        number = number.substring(0, number.length() - 1);
    // 2013/02/05: removed dial via wahlhilfe only
    // String urlstr = getProtocol() + this.m_address +":" + this.m_port + "/fon_num/fonbook_list.lua?sid="+this.m_sid+"&dial="+number+"&xhr=1";
    String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/cgi-bin/webcm";
    try {
        data.append(this.executeURL(urlstr, "&sid=" + this.m_sid + "telcfg:settings/UseClickToDial=1&telcfg:settings/DialPort=" + extension + "&telcfg:command/Dial=" + number, 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 DoCallException("Could not dial numer on FritzBox: " + e.getMessage());
    }
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info("Data after call initialization: " + data.toString());
}
Also used : DoCallException(de.janrufmonitor.fritzbox.firmware.exception.DoCallException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Aggregations

DoCallException (de.janrufmonitor.fritzbox.firmware.exception.DoCallException)8 IOException (java.io.IOException)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)4 Message (de.janrufmonitor.exception.Message)3 FirmwareManager (de.janrufmonitor.fritzbox.firmware.FirmwareManager)3 Properties (java.util.Properties)3 ICaller (de.janrufmonitor.framework.ICaller)2 Shell (org.eclipse.swt.widgets.Shell)2 ICall (de.janrufmonitor.framework.ICall)1 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)1 ITreeItemCallerData (de.janrufmonitor.ui.jface.application.ITreeItemCallerData)1 DialerDialog (de.janrufmonitor.ui.jface.application.dialer.DialerDialog)1 SWTExecuter (de.janrufmonitor.ui.swt.SWTExecuter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Viewer (org.eclipse.jface.viewers.Viewer)1