phpubuntu-16.04zoneminder

Trying to create web page links that will launch a Perl script


I am using a Ubuntu server with Apache2 and Zoneminder (a security camera program). I have one camera (but eventually will be three) that has pan tilt and zoom (PTZ). In the Zoneminder program (PHP web based interface), through navigation through the pages you can get a window that has a control for the PTZ. It uses a bunch of calls to different PHP pages to create this page and you can click a preset button and have the camera go to the location on set to the preset.

The cameras I will have set up will have two locations that will be used that I will call Security and Open. I want to create links that I can click and it will send the command without having to go through navigating to the control window.

I have found that when you get to the proper area in zoneminder for the camera's PTZ and press the "1" button the website sends the command

/usr/bin/zmcontrol.pl --preset=1 --command=presetGoto --id=3

which can be run from a terminal on the Ubuntu server and does set the camera to the proper location.

UPDATE EDIT 3: (This is what I am going with now so I removed all the data from the other attempts to clean up this post)

Trying something completely different and I have almost got it to work the way I want. I created two new files called security.pl and open.pl .. now in the /usr/lib/zoneminder/cgi-bin.. this is what I have so far for security.pl (open.pl is identical but with the different preset of course):

#!/usr/bin/perl

my @command1 = ("/usr/bin/zmcontrol.pl", "--preset=1", "--command=presetGoto", "--id=3");
print "Content-type: text/html\n\n";
print "<br><br><center><a href=javascript:history.back()>BACK</a></center>";
system(@command1);

and in the montage.php and console.php the links I add to make this function is:

<a href="cgi-bin/security.pl">Security</a>

This approach works and does change camera locations on one click the only problem I'm having now is this will leave a blank page with a back link showing the direct link to the perl script in the address bar.

This will work for me but ultimately I would like the security/open.pl script to automatically run the "back" link so it would run the command and return to the page that was clicked.

I have tried print redirect(-url => 'javascript:history.back()'); in place of the <a href=javascript:history.back()> line but that just leaves me with a blank page and the camera does not move

Sorry about all this crazyness... but I'm close... The way its set up now does work and should be easily expanded if I add additional cameras, it would just be improved if I didn't have the blank page with a back link and it would just automatically return to the page (without having to hardcode the address because it will be linked in different pages and sometimes accessed from a local address and sometimes from an internet address).

I also notice one 'security' issue with this approach.. if you know the name and location of the script.. it bypasses the zoneminder login so anyone can change camera locations (lol guess I wont be using the names I used in this post just in case)

For my situation... the risk is low and it was hard enough for me to come up with this much.. I'm sure figuring out how to have it check to see if the user clicking that link is authorized to do so in Zoneminder.. so that anyone entering the link in a browser without already being logged into zoneminder would fail to function..would be even more difficult.

I suppose I will have to dig into the PHP and find out what the "controls" php has that checks this before it allows it and then figure out the way to properly add it to the perl script to make it load a page that does the proper check then if it passes runs the command. But that's for another time.


Solution

  • OK.. I was finally able to get what I wanted so I figured with as much time spent I should relay the information

    I got it to work by using the following perl script for security.pl and open.pl placed in /usr/lib/zoneminder/cgi-bin ..as for my post I will only put the security.pl here because open.pl is the same thing with the preset changed.

    security.pl:

     #!/usr/bin/perl
     my @command1 = ("/usr/bin/zmcontrol.pl", "--preset=1", "--command=presetGoto", "--id=3");
     print "Content-type: text/html\n\n";
     system(@command1);
     print qq!<script>
     window.close()
     </script>!;
    

    and the links I added to montage.php and console.php:

     <a href="cgi-bin/open.pl" target="popup">open</a>
     <a href="cgi-bin/security.pl" target="popup">Security</a>
    

    this will launch a popup window and run the needed command then close the window leaving the montage/console screen untouched so no need for "back"

    Its been a long road .. there is still the security issue I have to deal with in the future but as of now this is functioning as I wanted... eventually I will be able to figure out the rest :D thanks @Ricardo for your try