Search in sources :

Example 1 with DoBlockException

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

the class AbstractFritzBoxFirmware method doBlock.

public void doBlock(String number) throws DoBlockException, IOException {
    if (!this.isInitialized())
        throw new DoBlockException("Could not block number " + number + " on FritzBox: FritzBox firmware not initialized.");
    if (this.getBlockPOSTData().trim().length() > 0) {
        int count = this.getBlockCount();
        String urlstr = getProtocol() + this.m_address + ":" + this.m_port + getBaseURL();
        String postdata = (this.m_language.equalsIgnoreCase("en") ? getAccessMethodPOSTData()[1] : getAccessMethodPOSTData()[0]) + this.getBlockPOSTData().replaceAll("\\$LANG", this.m_language).replaceAll("\\$NUMBER", number).replaceAll("\\$COUNT", Integer.toString(count)) + this.getBlockURLAuthenticator().getAuthenticationToken();
        executeURL(urlstr, postdata, false);
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("Successfully added numer " + number + " to FritzBox block list.");
    } else {
        if (this.m_logger.isLoggable(Level.WARNING))
            this.m_logger.warning("Block list is not supported by this FritzBox firmware.");
    }
}
Also used : DoBlockException(de.janrufmonitor.fritzbox.firmware.exception.DoBlockException)

Example 2 with DoBlockException

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

the class AbstractFritzBoxFirmware method getBlockedList.

public List getBlockedList() throws IOException, GetBlockedListException {
    if (!this.isInitialized())
        throw new GetBlockedListException("Could not get blocked list from FritzBox: FritzBox firmware not initialized.");
    InputStream in = null;
    try {
        in = this.getBlockedListAsStream();
    } catch (IOException e) {
        throw new GetBlockedListException(e.getMessage());
    } catch (DoBlockException e) {
        throw new GetBlockedListException(e.getMessage());
    }
    if (in == null)
        return new ArrayList(0);
    List result = new ArrayList();
    StringBuffer parseBuffer = new StringBuffer();
    InputStreamReader inr = new InputStreamReader(in);
    BufferedReader bufReader = new BufferedReader(inr);
    // drop header
    String line = bufReader.readLine();
    // fasten the processing
    bufReader.skip(4096);
    while (bufReader.ready()) {
        line = bufReader.readLine();
        parseBuffer.append(line);
        parseBuffer.append(IJAMConst.CRLF);
    }
    bufReader.close();
    in.close();
    Pattern p = Pattern.compile(PATTERN_DETECT_BLOCKED_LIST, Pattern.UNICODE_CASE);
    Matcher m = p.matcher(parseBuffer);
    while (m.find() && m.groupCount() == 1) {
        result.add(m.group(1).trim());
    }
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info("Blocked list from FritzBox successfully fetched. List size: " + result.size());
    return result;
}
Also used : Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) GetBlockedListException(de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) DoBlockException(de.janrufmonitor.fritzbox.firmware.exception.DoBlockException)

Example 3 with DoBlockException

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

the class FritzOS559Firmware method doBlock.

public void doBlock(String number) throws DoBlockException, IOException {
    if (!this.isInitialized())
        throw new DoBlockException("Could not block number " + number + " on FritzBox: FritzBox firmware not initialized.");
    String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/fon_num/sperre_edit.lua";
    String postdata = ("mode_call=_in&rule_kind=rufnummer&rule_number=$NUMBER&current_rule=&current_mode=_new&backend_validation=false&apply=&sid=".replaceAll("\\$NUMBER", number) + this.m_sid);
    executeURL(urlstr, postdata, false);
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info("Successfully added number " + number + " to FritzBox block list.");
}
Also used : DoBlockException(de.janrufmonitor.fritzbox.firmware.exception.DoBlockException)

Example 4 with DoBlockException

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

the class FritzOSFirmware method doBlock.

public void doBlock(String number) throws DoBlockException, IOException {
    if (!this.isInitialized())
        throw new DoBlockException("Could not block number " + number + " on FritzBox: FritzBox firmware not initialized.");
    String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/fon_num/sperre_edit.lua";
    String postdata = ("mode_call=_in&rule_kind=rufnummer&rule_number=$NUMBER&current_rule=&current_mode=_new&backend_validation=false&apply=&sid=".replaceAll("\\$NUMBER", number) + this.m_sid);
    executeURL(urlstr, postdata, false);
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info("Successfully added numer " + number + " to FritzBox block list.");
}
Also used : DoBlockException(de.janrufmonitor.fritzbox.firmware.exception.DoBlockException)

Example 5 with DoBlockException

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

the class TR064FritzBoxFirmware method doBlock.

public void doBlock(String number) throws DoBlockException, IOException {
    if (!this.isInitialized())
        throw new DoBlockException("Could not block number " + number + " on FritzBox: FritzBox firmware not initialized.");
    String u = "http://" + this.m_server + ":" + this.m_port + "/fon_num/sperre_edit.lua";
    String body = "mode_call=_in&rule_kind=rufnummer&rule_number=" + number + "&name=jAnrufmonitor+Sperre&current_rule=&current_mode=_new&backend_validation=false&apply=&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"));
    doHttpCall(u, "POST", body, new String[][] { { "Content-Length", Integer.toString(body.length()) } });
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info("Successfully added number " + number + " to FritzBox block list.");
}
Also used : DoBlockException(de.janrufmonitor.fritzbox.firmware.exception.DoBlockException)

Aggregations

DoBlockException (de.janrufmonitor.fritzbox.firmware.exception.DoBlockException)9 IOException (java.io.IOException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 BufferedReader (java.io.BufferedReader)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Message (de.janrufmonitor.exception.Message)1 FirmwareManager (de.janrufmonitor.fritzbox.firmware.FirmwareManager)1 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)1 GetBlockedListException (de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Shell (org.eclipse.swt.widgets.Shell)1