ZoneMinder Binding in Marketplace (Beta)

Does anybody have this working on Zoneminder 1.33.x ?

I have followed all above and couldn’t get the thing to cone online.

Same here. I tried everything


I even tried with no Auth enabled. The JSON is just fine when I make a API request. But OpenHab2 wouldn’t still connect.

Should this binding work with ZM 1.32.3? If so then can I have some pointers as I can’t seem to get this working.

After assessing load on our OH server, which also runs ZM, I’ve removed this binding. With 5 cameras and 5s polling to quickly get motion alerts, the load was just too high. Before the binding, I had used ZM filters to send REST API calls for turning on and off Items for motion detection. Unfortunately, it seems ZM changed the filters so that this solution would not work for us. Here is some detail on ZM filters. Currently, we are using SQL triggers to make the REST API calls and it’s been working great… https://www.rushworth.us/lisa/?p=5470. Motion detection is immediate and the load is significantly improved. Using this, there’s no dependency on the changing ZM API or an OH binding. You can do more than motion detection too. It’s not in the example, but there’s also a shell script called in the SQL trigger that that emails an image of the 25th alarm frame.

doesn’t seem to work for me on zm 1.32.3

bundle:list | grep ZoneMinder
233 │ Active │ 80 │ 2.5.0.M1 │ ZoneMinder Binding

I can see the OH connecting to the ZM, and the traffic is being exchanged, but the binding claims the wrong user credentials were specified.

openhab> smarthome:things list | grep zone
zoneminder:server:ZoneMinderHome (Type=Bridge, Status=OFFLINE (CONFIGURATION_ERROR): Cannot access ZoneMinder Server. Check provided usercredentials, Label=ZoneMinder Server, Bridge=null)

Here is a tcpdump of the connection
GET /zm/index.php HTTP/1.1
User-Agent: Mozilla/5.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: en-US,en;q=0.5
Cache-Control: no-cache
Pragma: no-cache
Host: homenas.kos.home
Connection: keep-alive

HTTP/1.1 200 OK
Date: Sat, 31 Aug 2019 06:05:36 GMT
Server: Apache
Set-Cookie: ZMSESSID=p1l3jvtjd8u8sn6notbkrrltco; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: zmSkin=classic; expires=Mon, 09-Jul-2029 06:05:37 GMT; Max-Age=311040000
Set-Cookie: zmCSS=base; expires=Mon, 09-Jul-2029 06:05:37 GMT; Max-Age=311040000
Vary: Accept-Encoding
Content-Length: 5564
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

SKIP

This topic is about the updated version of the binding in the marketplace. I don’t think the production version of the binding has been updated for a very long time. But the marketplace version will not function on newer versions of ZM without the workarounds I’ve posted.

1 Like

I recently upgrade Zoneminder to 1.33.14, and some new problem arises.

I first reapplied the previous steps:

  • Lisa Rushworh tuning of zoneminder/www/includes/config.php, line 170, change define( $row['Name'], $row['Value'] ); to
170:      if ( strcmp($row['Name'],'ZM_PATH_ZMS') != 0) {
171-        define( $row['Name'], $row['Value'] );
172-      }
  • Lisa Rushwoth-based mysql update:
mysql -u zmuser -p # Default password is zmpass, defined in /etc/zm/zm.conf at line 50 (approx.)
use zm; #Assuming your zoneminder database is actually named zm
INSERT INTO `Config` VALUES (1225,'ZM_PATH_ZMS','/cgi-bin/nph-zms','string','/cgi-bin/nph-zms','relative/path/to/somewhere','(?^:^((?:[^/].*)?)/?$)',' $1 ','Web path to zms streaming server',' The ZoneMinder streaming server is required to send streamed images to your browser. It will be installed into the cgi-bin path given at configuration time. This option determines what the web path to the server is rather than the local path on your machine. Ordinarily the streaming server runs in parser-header mode however if you experience problems with streaming you can change this to non-parsed-header (nph) mode by changing \'zms\' to \'nph-zms\'. ','hidden',0,NULL);
INSERT INTO `Config` VALUES (1226,'ZM_OPT_FRAME_SERVER','0','boolean','no','yes|no','(?^i:^([yn]))',' ($1 =~ /^y/) ? \"yes\" : \"no\" ','Should analysis farm out the writing of images to disk',' In some circumstances it is possible for a slow disk to take so long writing images to disk that it causes the analysis daemon to fall behind especially during high frame rate events. Setting this option to yes enables a frame server daemon (zmf) which will be sent the images from the analysis daemon and will do the actual writing of images itself freeing up the analysis daemon to get on with other things. Should this transmission fail or other permanent or transient error occur, this function will fall back to the analysis daemon. ','system',0,NULL);

Then i still faced an authentication problem.
Whatever has changed between 1.33.10 & 1.33.14 is preventing a user to get authenticated with the “old-style” way of first posting the credentials.

So, i got an idea, remove authentication. But wait, anyone could then log and see anything ? Not if i added an http authentication layer at RP level, and bypass RP only for openhab… But then i couldn’t see the streams from ZMninja.

I needed the following:

  • Authenticate users from Internet
  • Authenticate only with ZM builtin auth
  • Do not authenticate OpenHab

Thats were i looked into ZM code to see how authentication is done.

  • First, i edited zoneminder/www/includes/auth.php and updated the following on line 267, in place of if ( ZM_OPT_USE_AUTH ):
267:if ( $_SERVER['REMOTE_ADDR'] == '<OpenHab_IP>' ) {
268-  $user = $defaultUser;
269-} else if ( ZM_OPT_USE_AUTH ) {
  • If the source IP is my openhab server ip address, i just use a defaultUser, as when authentication is completely disabled. That was working for accessing any pages, like the console, but not for the API.
  • Then, i edited the zoneminder/www/api/app/Controller/HostController.php and added this before if ( !ZM_OPT_USE_AUTH ) on line 111:
111:    if ( $_SERVER['REMOTE_ADDR'] == "<OpenHab_IP>" )
112-      return;
113-
114-    if ( !ZM_OPT_USE_AUTH )
  • I want this module to behave the same when the client IP is openhab, than when auth is disabled. Same player, try again. API still gives 401 to openhab.
  • I finally edited zoneminder/www/api/app/Controller/AppController.php and updated line 70 from if ( ZM_OPT_USE_AUTH ) to if ( ZM_OPT_USE_AUTH && $_SERVER['REMOTE_ADDR'] != '<OpenHab_IP>' ), as i wanted the App to handle my request this way only when the auth is enabled and for any host except OpenHab.

Now, openhab still try to authenticate to ZM with this POST request, but it does not need any form of authentication to access the API and do its job.
Moreover, this new trick will improve the stability, as there will not be any more Authentication timeout issues every few hours.

Downside is, whoever is connected to the openhab server has full access to zoneminder.

@mhilbush and @5iver, did you find time to make progress on the code? My update on the fix is far from perfect, and I may have some side effects that I don’t understand.

I no longer use the binding…

I gave up on it. I just didn’t have the time to invest, as I have quite a few other projects higher up on the priority list.

Could you share your latest code? I would like to try working on it myself.

https://github.com/mhilbush/openhab2-addons/tree/zoneminder-checkpoint-2

1 Like

Hello,

Are any plans to update Zoneminder binding to work new version Zoneminder 1.33 or 1.34 ?
What is last version Zoneminder which works correctly without implement too much tricks/workarounds ?
Thank you, Slawek

Interested as well…

I’m using zoneminder 1.32.3, I’m willing to try my hand at fixing the binding without having to resort to workarounds in zm. I noticed that in this proposed pull request (https://github.com/openhab/openhab-addons/pull/3583), the zoneminder4j version was changed from 0.9.7 to 0.9.8, but there’s no tags in https://github.com/Mr-Eskildsen/zoneminder4j that I can follow. Does anyone know where the most recent code for zoneminder4j resides?

Ok, apparently the repository has the 0.9.8 code, I’m going to fiddle with it and possibly create a pull request, but I don’t know who publishes the library (@mr_eskildsen probably?)

You are right, the library was made as an attempt to create a more clean interface to ZoneMinder. It was started while I was trying to find out how ZoneMinder was working, so it is pretty cluttered. Meanwhile the dev team at ZM has started to clean the API, so that has also changed a lot. If you are planning on updating / rewriting ZM addon, you can use the lib for inspiration. Especially login to ZoneMinder via API has improved (it was really rubbish up to 1.30). So a lot of trial and error in the login process can be avoided. Feel free to ask, I might remember why things was done in a specific way .-)

I’m sure willing to test your fixup. I’m on Zoneminder 1.35 (1.35.0~20200226094305-bionic).

Feel free to contact.

Regards,
Zsolt.

HI Mark
Today I’ve tried to configure new ZM 2.5.3 binding taken from


with using fresh new Zoneminder 1.34
but received information “Cannot get version information”
however
http://hostname_or_ip/zm/api/host/getVersion.json
shows
{
“version”: “1.34.0”,
“apiversion”: “2.0”
}

would you please advise where can be problem
Thank you, Regards,
Slawek

41 posts were split to a new topic: New Zoneminder Binding