Difference between revisions of "Zms-inetd"

From ZoneMinder Wiki
Jump to navigationJump to search
Line 5: Line 5:
* '''Requirements''': bash, inetd
* '''Requirements''': bash, inetd
* '''License''': GNU General Public License, Version 2
* '''License''': GNU General Public License, Version 2


== Motivation ==
== Motivation ==

Revision as of 10:35, 31 May 2007

zms-inetd is an inetd-wrapper for the ZMS (Zoneminder Streaming Server), so ZMS can work "standalone".


Motivation

I'm using Zoneminder with Nginx Httpd, which doesnt support simple CGI (just FastCGI). So I needed a leightweight solution to make ZMS work without any extra software. This script depends only on inetd and bash.

Installation and Configuration

Installation

Just copy and paste the zms-inetd-script from below (Section "Script") into a text file and save it, for example, as /usr/local/bin/zms-inetd. Don't forget to make it executable (chmod 755 /usr/local/bin/zms-inetd).

/etc/services

As for every inetd-service you have to define a port number in /etc/services:

zms-inetd       85/tcp   # Zoneminder ZMS inetd-wrapper

/etc/inetd.conf

Of course also an entry in the inetd configuration is needed. Please adapt this to your needs (user [= www], path):

zms-inetd       stream tcp nowait    www   /usr/local/bin/zms-inetd  zms-inetd

Path to zm.conf

Set the ZMCONF variable in the shell-script appropriate.

Zoneminder-Configuration

The last step is to adjust the web path (URL) to ZMS. This is done through the ZM-Webinterface > Options > Paths > Web path to zms streaming server (ZM_PATH_ZMS). According to the configuration above this would be:

http://<server>:85/<anypath>

It doesn't matter which path you specifiy as zms-inetd will always proxy to the ZMS cgi-binary for security reasons.

Further thoughts

Make it transparent

In combination with Nginx its propably useful not to point ZM directly to the zms-inetd port, but masq it with a reverse proxy configuration in Nginx. That should avoid some problems if you want to reverse proxy the whole ZM installation (eg: from intranet to the internet).

Example:

 location /zm/zms-inetd {
   proxy_pass  http://127.0.0.1:85;
}

Of course you have to adjust the cgi-bin path (ZM_PATH_ZMS), for example, to /zm/zms-inetd.

Other use cases for zms-inetd

Another scenario where zms-inetd perhaps could also be used is a leightweight or embedded system, just running ZMS. For example the busybox multibinary offers an inetd and a shell. Due the fact that zms-inetd is not heavily integrated with bash it should not be to hard to adapt it to ash (default shell in busybox).

Script

<nowiki>#!/bin/bash
#
# Inetd-wrapper for ZMS (Zoneminder Streaming Server)
#
# Author:       Kurt Zankl <kz@xon.uni.cc>
# Inspiration:  http://www.debian-administration.org/articles/371
# Requirements: bash, inetd
# License:      GNU General Public License, Version 2
#
# /etc/services:
#   zms-inetd       85/tcp   # Zoneminder ZMS inetd-wrapper
#
# /etc/inetd.conf:
#   zms-inetd       stream tcp nowait    www-data   /usr/local/bin/zms-inetd  zms-inetd
#
# ZM Options / Paths / Web path to zms streaming server:
#   ZM_PATH_ZMS = http://<server>:85/<anypath>
#

# configuration
ZMCONF="/usr/local/etc/zm.conf"
CGIBIN="zms"

# error handler
function errormsg {
  echo "HTTP/1.1 200 OK"
  echo "Content-Type: text/html"
  echo
  echo "<h1>ERROR</h1>"
  echo -e "<pre>$1

"

 echo
 exit 1

}

  1. read ZM configuration

[ -r $ZMCONF ] || errormsg "Error reading Zoneminder configuration \"$ZMCONF\""; . $ZMCONF ZMS="$ZM_PATH_CGI/$CGIBIN" [ -x $ZMS ] || errormsg "Error finding ZMS executable \"$ZMS\"";

  1. get request

read REQUEST

  1. skip headers

HEADER="nothing"; while [ "$HEADER" != $'\r' -a -n "$HEADER" ]; do read HEADER; done

  1. check request

[ -z "$REQUEST" ] && errormsg "Request is empty"

  1. split request

URL="${REQUEST#GET }" URL="${URL% HTTP/*}" QUERY="${URL#*\?}" URL="${URL%%\?*}"

  1. check query

[ "$QUERY" == "$URL" ] && errormsg "Invalid query"

  1. execute ZMS

export QUERY_STRING="$QUERY" echo "HTTP/1.1 200 OK" "$ZMS" echo

exit 0</nowiki>