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.");
}
}
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;
}
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¤t_rule=¤t_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.");
}
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¤t_rule=¤t_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.");
}
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¤t_rule=¤t_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.");
}
Aggregations