openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.86k stars 3.58k forks source link

[tr064] Wrong regex check for IP address for parameter wanBlockByIP #12567

Closed HerbertHofmann closed 1 year ago

HerbertHofmann commented 2 years ago

Expected Behavior

IP addresses containing a 0 cannot be added due to wrong regex check in channels.xml pattern="([1-9]\d{0,2}.){3}[1-9]\d{0,2}(\s#.)*"

Current Behavior

When adding e.g. 192.168.0.20, following message in openhab.log file is entered: Removing 192.168.0.20, while processing wanBlockByIP, does not match pattern ([1-9]\d{0,2}.){3}[1-9]\d{0,2}(\s#.)*, check config.

Possible Solution

Change the pattern check to pattern="[1-9]\d{0,2}.([0-9]\d{0,2}.){2}[1-9]\d{0,2}(\s#.)*"

Steps to Reproduce (for Bugs)

  1. Install tr64 binding
  2. Add for Fritzbox device a wanBlockByIP entry e.g. 192.168.0.20

Context

The channel for the device that shall be blocked is not added to configuration

Your Environment

Openhab 3.2.0 on RPi 3B+

syntacrsc commented 2 years ago

I'm not an expert but shouldn't that rather be:

pattern="^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(.(?!$)|$)){4}$"

to also allow for IP-addresses such as e.g. 10.0.0.10 ??

HerbertHofmann commented 2 years ago

Checking with Google, I found: ^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3} (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

syntacrsc commented 2 years ago

I modified to pattern in channels.xml of the tr-064 binding to

pattern="([0-9]\d{0,2}.){3}[1-9]\d{0,2}(\s*#.)"

and could successfully setup wanBlockByIP for ip addresses inlcuding zeros such as e.g. 10.0.0.35

lsiepel commented 1 year ago

Duplicate from https://github.com/openhab/openhab-addons/issues/11909

A jar with a fix is available in that issue. could you please test that.

syntacrsc commented 1 year ago

Hi @lsiepel .

Thanks for the attempt to fix the issue – it does not seem to work though:

My log still shows messages such as “2022-12-10 07:59:23.935 [WARN ] [hab.binding.tr064.internal.util.Util] - Removing 10.0.0.51 while processing wanBlockByIP, does not match pattern ([1-9]\d{0,2}.){3}[1-9]\d{0,2}(\s#.)*, check config.” (see screen shot below)

Here’s how I tested:

I’m on OH 3.3.0 Release Build (not 3.4 !) 1) I removed the 3.3.0 TR-064 binding (via Administration->Settings->Bindings->tr-064->remove) 2) I’ve put your new JAR file into /usr/share/openhab/addons 3) Rebooted the openhab Server (twice) 4) Validated the new JAR file has been loaded thru console command bundle:list it shows 3.4.0 version is active: 320 │ Active │ 80 │ 3.4.0.202212091601 │ openHAB Add-ons :: Bundles :: TR-064 Binding (also: see screen shot below)

=> Log shows warnings for failed pattern check for WanBlockIp:

image

image