Friend Of Zoneminder
I am posting this sooner then I wanted, but wanted to get something up before I get too bored with this project and move on.
Friend of Zoneminder (FOZM) was initially a project to connect more than 6 cameras with zoneminder. I have not solved that problem, but a curious thing happened. Because the site was plain, it performed fast. Also I could create different groups of monitors easily.
All it took was a single php page and a txt file with all the monitors I want to to display.
I wouldn’t call the code great or anything, but provided a very fast way to change displays.
Not sure if anyone else would be interested.
Before you can use this script you have to have a working zoneminder install. This script also uses hashes to log in. One of the security holes in this is that the URL contains a token valid for two hours, so anyone with that token can access the video streams.
With that said, you should really create a user with view only access for use of this php script.
In the screen shot above I have API enabled, it is not needed. I was testing some other things.
Once you have that simply make a dir in /var/www/html like fozm and in that directory create index.php with the following contents
<HTML>
<?php
//
// Friend of Zoneminder
// v 0.1
// By Larry Apolonio
//
// This software is a simple php page that presents you
// with a simple page for zoneminder.
//
// The defaults below should present to you a simple
// that is quick to load
//
// Read the FriendOfZM document
// or check out https://my.apolonio.tech for more details
//////////////////////////////////////////////////////////
// Here are generic values you can get from zm.conf
// On some installs it is located in /etc/zm/zm.conf
$ZM_DB_HOST="localhost";
$ZM_DB_USER="zmuser";
$ZM_DB_PASS="zmpass";
$ZM_DB_NAME="zm";
$ZM_USER="viewer";
// This is a text file with a list of monitors in this view
$CAMERAFILE="monitors.txt";
// This can be blank if this resides on the same server as ZM
$SERVERURL="";
// This is the refresh rate in seconds, the default here is 1 year
$REFRESH=31536000;
$REFRESH=5;
// These two values show if a video or still is displayed
$REFMODE="jpeg";
$SRCMODE="single";
// This is how man columns across of the image is in the view
$COLS=5;
// Dimensions of the image or video displayed
$WIDTH=320;
$HEIGHT=240;
//////////////////////////////////////////////////////////
// Create connection
$conn = mysqli_connect($ZM_DB_HOST, $ZM_DB_USER, $ZM_DB_PASS, $ZM_DB_NAME);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Get ZM_AUTH_HASH_SECRET from mysql database
$hashsql = "select Name,Value from Config where Name=\"ZM_AUTH_HASH_SECRET\"";
$hashresult = mysqli_query($conn, $hashsql);
$hashinfo = mysqli_fetch_assoc($hashresult);
// Get password for zmlogin user
$usersql = "select Username, Password from Users where Username=\"".$ZM_USER."\"";
$userresult = mysqli_query($conn, $usersql);
$userinfo = mysqli_fetch_assoc($userresult);
// Get the time
$time = localtime();
// Generate Authentication key with ZM_AUTH_HASH_SECRET, user, user password and time
$authKey = $hashinfo["Value"] . $ZM_USER . $userinfo["Password"] . $time[2] . $time[3] . $time[4] . $time[5];
$authHash = md5($authKey);
// Open the camera list file
$cameralist = file($CAMERAFILE, FILE_IGNORE_NEW_LINES);
?>
<HEAD>
<meta http-equiv="refresh" content="<?php echo $REFRESH; ?>;">
<TITLE>Home Cameras</TITLE>
</HEAD>
<BODY>
<H1>Home Cameras</H1>
<HR>
<TABLE>
<?php
$x=0;
foreach($cameralist as $camera){
if (($x % $COLS) == 0) {
echo "\n<TR>";
};
$x = $x + 1;
echo "\n\t<TD>";
$sql = "SELECT Name,Path from Monitors where id=$camera";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
echo $camera . " - " .$row["Name"]. "<BR>";
echo "<a href=\"".$SERVERURL."/cgi-bin-zm/nph-zms?mode=$REFMODE&monitor=$camera&auth=$authHash\" target=_blank>";
echo "<img src=\"".$SERVERURL."/cgi-bin-zm/nph-zms?mode=$SRCMODE&monitor=$camera&auth=$authHash\" WIDTH=\"$WIDTH\" HEIGHT=\"$HEIGHT\">";
echo "</a>";
echo "</TD>";
if (($x % $COLS) == 0) {
echo "\n</TR>\n\n";
};
}
if (($x % $COLS) != 0) {
echo "\n</TR>\n\n";
};
// Close the MYSQL Connection
mysqli_close($conn);
?>
</TABLE>
</BODY>
</HTML>
Then create a simple monitors.txt file with the list of monitors you want to display on each line
1
2
3
4
One change you may have to make is
echo "<a href=\"".$SERVERURL."/zm/cgi-bin/nph-zms?mode=$REFMODE&monitor=$camera&auth=$authHash\" target=_blank>";
echo "<img src=\"".$SERVERURL."/zm/cgi-bin/nph-zms?mode=$SRCMODE&monitor=$camera&auth=$authHash\" WIDTH=\"$WIDTH\" HEIGHT=\"$HEIGHT\">";
Or to whatever your Zoneminder refers cgi-bin to. This version above is the one to use if you are following this blog, the one below is if you are using a popular Zoneminder docker container (which was recently deprecated).
Will post more if I advance this little project.