Dec 30

Over the holidays, I rebuild my CCTV server. Rather than trying to reuse the installation from the previous disk, I thought it’d be easier just to install everything fresh. Hence, I followed the instructions on the ZoneMinder Wiki.

Following on from this rebuild, I was tidying up my custom viewers which had hard-coded monitor IDs. Of course the correct way to do this would be via an API. Is there an API in ZoneMinder? Well according to the “latest” docs, it should be included since 1.27.

[code lang=”bash”]curl http://wiggum/zm/api/monitors.json
…404 Not Found…[/code]

So I checked if it was actually there or not:

[code lang=”bash”]iain@wiggum:~$ ls /usr/share/zoneminder/
ajax  cgi-bin  css  db  events  graphics  images  includes  index.php  js  lang  skins  sounds  temp  tools  views[/code]

Nope.

Not sure why it’s not there, you can see it on GitHub, but here’s how I solved it until the package is updated properly. (I’m omitting the use of sudo where needed.)

[code lang=”bash”]cd /usr/src
git clone https://github.com/ZoneMinder/ZoneMinder.git –branch release-1.28 zoneminder-1.28
mkdir zoneminder-1.28/web/api/app/tmp
chown www-data:www-data zoneminder-1.28/web/api/app/tmp[/code]

[code lang=”bash”]vi zoneminder-1.28/web/api/.htaccess[/code]
Add: RewriteBase /zm/api

[code lang=”bash”]vi zoneminder-1.28/web/api/app/webroot/.htaccess[/code]
Add: RewriteBase /zm/api

[code lang=”bash”]cd zoneminder-1.28/web/api/app/Config/
cp core.php.default core.php
cp database.php.default database.php
vi database.php[/code]
Change the database settings (host, login, database, password) to match: /etc/zm/zm.conf

[code lang=”bash”]vi /etc/apache2/conf-available/zoneminder-api.conf[/code]
Add the following:
[code]Alias /zm/api /usr/src/zoneminder-1.28/web/api
<Directory /usr/src/zoneminder-1.28/web/api>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>[/code]

Enable the conf, restart apache and you’re done:
[code lang=”bash”]a2enconf zoneminder-api
apachectl graceful[/code]

Don’t forget to enable mod_rewrite if it isn’t already:
[code lang=”bash”]a2enmod rewrite[/code]

5 Responses to “ZoneMinder 1.28 API”

  1. Mickael says:

    Thank you very much.

    I was asking myself the same question 😉

    Did follow your How-To and it worked perfectly.

    Thanks again for sharing !!

  2. asker says:

    Hi Iain, I installed the APIs using your recommendation and it works well. The only problem is it does not tie into Zoneminder’s authentication (If I enable it with OPT_AUTH) – so its always responding with details to any one making HTTP requests on the API which is quite a security problem because the RTSP urls for the cameras include passwords.

    Would you know how to go about ensuring it ties into zomeminder’s authentication?

    thanks

  3. Iain says:

    With respect to the authentication, I didn’t worry about that as I use Basic Auth.

    It will need to be built into the API module and has already been raised… have a look here: https://github.com/ZoneMinder/ZoneMinder/issues/8

    Iain

  4. Jeronimo says:

    The command:

    git clone https://github.com/ZoneMinder/ZoneMinder.git –branch release-1.28 zoneminder-1.28

    returns:

    # git clone https://github.com/ZoneMinder/ZoneMinder.git –branch release-1.28 zoneminder-1.28
    Cloning into ‘zoneminder-1.28’…
    fatal: Remote branch release-1.28 not found in upstream origin

    Can you help me?

  5. Iain says:

    I don’t see that branch there anymore:
    https://github.com/ZoneMinder/ZoneMinder/branches/all?query=1.28

    Try release-1.28.2 instead.

    Iain

Leave a Reply

preload preload preload