{"id":188,"date":"2021-02-16T02:50:59","date_gmt":"2021-02-16T10:50:59","guid":{"rendered":"https:\/\/my.apolonio.tech\/?p=188"},"modified":"2021-02-16T02:51:00","modified_gmt":"2021-02-16T10:51:00","slug":"friend-of-zoneminder","status":"publish","type":"post","link":"https:\/\/my.apolonio.tech\/?p=188","title":{"rendered":"Friend Of Zoneminder"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">All it took was a single php page and a txt file with all the monitors I want to to display.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I wouldn&#8217;t call the code great or anything, but provided a very fast way to change displays.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Not sure if anyone else would be interested.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"545\" src=\"https:\/\/my.apolonio.tech\/wp-content\/uploads\/2021\/02\/2021-02-12_20-05-30-1024x545.jpg\" alt=\"\" data-id=\"189\" data-full-url=\"https:\/\/my.apolonio.tech\/wp-content\/uploads\/2021\/02\/2021-02-12_20-05-30.jpg\" data-link=\"https:\/\/my.apolonio.tech\/?attachment_id=189\" class=\"wp-image-189\" srcset=\"https:\/\/my.apolonio.tech\/wp-content\/uploads\/2021\/02\/2021-02-12_20-05-30-1024x545.jpg 1024w, https:\/\/my.apolonio.tech\/wp-content\/uploads\/2021\/02\/2021-02-12_20-05-30-300x160.jpg 300w, https:\/\/my.apolonio.tech\/wp-content\/uploads\/2021\/02\/2021-02-12_20-05-30-768x409.jpg 768w, https:\/\/my.apolonio.tech\/wp-content\/uploads\/2021\/02\/2021-02-12_20-05-30.jpg 1054w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/li><\/ul><figcaption class=\"blocks-gallery-caption\">Enabling AUTH_HASH_IPS<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">With that said, you should really create a user with view only access for use of this php script.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"159\" src=\"https:\/\/my.apolonio.tech\/wp-content\/uploads\/2021\/02\/2021-02-12_20-03-00-1024x159.jpg\" alt=\"\" class=\"wp-image-190\" srcset=\"https:\/\/my.apolonio.tech\/wp-content\/uploads\/2021\/02\/2021-02-12_20-03-00-1024x159.jpg 1024w, https:\/\/my.apolonio.tech\/wp-content\/uploads\/2021\/02\/2021-02-12_20-03-00-300x47.jpg 300w, https:\/\/my.apolonio.tech\/wp-content\/uploads\/2021\/02\/2021-02-12_20-03-00-768x119.jpg 768w, https:\/\/my.apolonio.tech\/wp-content\/uploads\/2021\/02\/2021-02-12_20-03-00-1536x239.jpg 1536w, https:\/\/my.apolonio.tech\/wp-content\/uploads\/2021\/02\/2021-02-12_20-03-00.jpg 1577w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Create View only user<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In the screen shot above I have API enabled, it is not needed.  I was testing some other things.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;HTML>\n &lt;?php\n \/\/\n \/\/ Friend of Zoneminder\n \/\/ v 0.1\n \/\/ By Larry Apolonio\n \/\/\n \/\/ This software is a simple php page that presents you\n \/\/ with a simple page for zoneminder.\n \/\/\n \/\/ The defaults below should present to you a simple\n \/\/ that is quick to load\n \/\/\n \/\/ Read the FriendOfZM document\n \/\/ or check out https:\/\/my.apolonio.tech for more details\n\n \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n \/\/ Here are generic values you can get from zm.conf\n \/\/ On some installs it is located in \/etc\/zm\/zm.conf\n $ZM_DB_HOST=\"localhost\";\n $ZM_DB_USER=\"zmuser\";\n $ZM_DB_PASS=\"zmpass\";\n $ZM_DB_NAME=\"zm\";\n $ZM_USER=\"viewer\";\n \/\/ This is a text file with a list of monitors in this view\n $CAMERAFILE=\"monitors.txt\";\n \/\/ This can be blank if this resides on the same server as ZM\n $SERVERURL=\"\";\n \/\/ This is the refresh rate in seconds, the default here is 1 year\n $REFRESH=31536000;\n $REFRESH=5;\n \/\/ These two values show if a video or still is displayed\n $REFMODE=\"jpeg\";\n $SRCMODE=\"single\";\n \/\/ This is how man columns across of the image is in the view\n $COLS=5;\n \/\/ Dimensions of the image or video displayed\n $WIDTH=320;\n $HEIGHT=240;\n \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\n \/\/ Create connection\n $conn = mysqli_connect($ZM_DB_HOST, $ZM_DB_USER, $ZM_DB_PASS, $ZM_DB_NAME);\n \/\/ Check connection\n if (!$conn) {\n   die(\"Connection failed: \" . mysqli_connect_error());\n }\n\n \/\/ Get ZM_AUTH_HASH_SECRET from mysql database\n $hashsql = \"select Name,Value from Config where Name=\\\"ZM_AUTH_HASH_SECRET\\\"\";\n $hashresult = mysqli_query($conn, $hashsql);\n $hashinfo = mysqli_fetch_assoc($hashresult);\n\n \/\/ Get password for zmlogin user\n $usersql = \"select Username, Password from Users where Username=\\\"\".$ZM_USER.\"\\\"\";\n $userresult = mysqli_query($conn, $usersql);\n $userinfo = mysqli_fetch_assoc($userresult);\n\n \/\/ Get the time\n $time = localtime();\n\n \/\/ Generate Authentication key with ZM_AUTH_HASH_SECRET, user, user password and time\n $authKey = $hashinfo&#91;\"Value\"] . $ZM_USER . $userinfo&#91;\"Password\"] . $time&#91;2] . $time&#91;3] . $time&#91;4] . $time&#91;5];\n $authHash = md5($authKey);\n\n \/\/ Open the camera list file\n $cameralist = file($CAMERAFILE, FILE_IGNORE_NEW_LINES);\n\n ?>\n\n\n&lt;HEAD>\n&lt;meta http-equiv=\"refresh\" content=\"&lt;?php echo $REFRESH; ?>;\">\n&lt;TITLE>Home Cameras&lt;\/TITLE>\n&lt;\/HEAD>\n&lt;BODY>\n&lt;H1>Home Cameras&lt;\/H1>\n&lt;HR>\n&lt;TABLE>\n&lt;?php\n   $x=0;\n   foreach($cameralist as $camera){\n      if (($x % $COLS) == 0) {\n         echo \"\\n&lt;TR>\";\n      };\n      $x = $x + 1;\n      echo \"\\n\\t&lt;TD>\";\n      $sql = \"SELECT Name,Path from Monitors where id=$camera\";\n      $result = mysqli_query($conn, $sql);\n      $row = mysqli_fetch_assoc($result);\n      echo $camera . \" - \" .$row&#91;\"Name\"]. \"&lt;BR>\";\n      echo \"&lt;a href=\\\"\".$SERVERURL.\"\/cgi-bin-zm\/nph-zms?mode=$REFMODE&amp;monitor=$camera&amp;auth=$authHash\\\" target=_blank>\";\n      echo \"&lt;img src=\\\"\".$SERVERURL.\"\/cgi-bin-zm\/nph-zms?mode=$SRCMODE&amp;monitor=$camera&amp;auth=$authHash\\\" WIDTH=\\\"$WIDTH\\\" HEIGHT=\\\"$HEIGHT\\\">\";\n      echo \"&lt;\/a>\";\n      echo \"&lt;\/TD>\";\n      if (($x % $COLS) == 0) {\n         echo \"\\n&lt;\/TR>\\n\\n\";\n      };\n   }\n   if (($x % $COLS) != 0) {\n      echo \"\\n&lt;\/TR>\\n\\n\";\n   };\n \/\/ Close the MYSQL Connection\n   mysqli_close($conn);\n?>\n&lt;\/TABLE>\n\n&lt;\/BODY>\n&lt;\/HTML>\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then create a simple monitors.txt file with the list of monitors you want to display on each line<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\n2\n3\n4<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">One change you may have to make is <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>      echo \"&lt;a href=\\\"\".$SERVERURL.\"\/zm\/cgi-bin\/nph-zms?mode=$REFMODE&amp;monitor=$camera&amp;auth=$authHash\\\" target=_blank>\";\r\n      echo \"&lt;img src=\\\"\".$SERVERURL.\"\/zm\/cgi-bin\/nph-zms?mode=$SRCMODE&amp;monitor=$camera&amp;auth=$authHash\\\" WIDTH=\\\"$WIDTH\\\" HEIGHT=\\\"$HEIGHT\\\">\";\r\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">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).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Will post more if I advance this little project.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-188","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/my.apolonio.tech\/index.php?rest_route=\/wp\/v2\/posts\/188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/my.apolonio.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/my.apolonio.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/my.apolonio.tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/my.apolonio.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=188"}],"version-history":[{"count":1,"href":"https:\/\/my.apolonio.tech\/index.php?rest_route=\/wp\/v2\/posts\/188\/revisions"}],"predecessor-version":[{"id":191,"href":"https:\/\/my.apolonio.tech\/index.php?rest_route=\/wp\/v2\/posts\/188\/revisions\/191"}],"wp:attachment":[{"href":"https:\/\/my.apolonio.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/my.apolonio.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/my.apolonio.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}