Using API to setup cams

Forum for questions and support relating to the 1.28.x releases only.
BiloxiGeek
Posts: 271
Joined: Tue Feb 11, 2014 2:04 pm

Re: Using API to setup cams

Post by BiloxiGeek »

Starting to work on some perl code to see what I might be able to come up with for useless yet geeky things for zoneminder. Having never used some of these modules I'm kind of stuck at the initial login to ZM.

Code: Select all

#!/usr/bin/perl

use HTTP::Cookies;
use LWP;
use LWP::UserAgent;

$url = 'https://localhost/zm/index.php';
$user = 'username';
$pass = 'password';

$cookie_jar = HTTP::Cookies->new(
file => "$ENV{'HOME'}/lwp_cookies.dat",
    autosave => 1,
);

my $browser = LWP::UserAgent->new;
$browser->cookie_jar($cookie_jar);

my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
$ua->agent("USER/AGENT/IDENTIFICATION");

$request = HTTP::Request->new(GET => $url);
$request->authorization_basic($user, $pass);

$response = $ua->request($request);

$content = $response->content();

print $content;
I expected to get back the html from the main page but only got:

Code: Select all

Can't connect to localhost:443
My goal here is to use perl to grab monitor and zone configs via API, save the json output and then use that as a sort of backup. And eventually be able to wipe those configs and rebuild if it becomes necessary or if I just want to reorganize. Wish I had a much cooler goal here, but I'm just playing with this stuff to get my head filled with more perl goodness.
BiloxiGeek
Posts: 271
Joined: Tue Feb 11, 2014 2:04 pm

Re: Using API to setup cams

Post by BiloxiGeek »

Added "(ssl_opts => { verify_hostname => 0 })" to the the LWP::UserAgent and I can get login page. Now I just to work out how to get it to login. Would WWW::Mechanize be a better way to go?

If any devs think I'm headed down a useless path let me know please. If I can automate the login and cookie stuff over ssl I'd like to start doing a somewhat cleaner point of entry to the json stuff. Get away from curl commands and do all this strictly in perl.
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Using API to setup cams

Post by asker »

WWW:Mechanize is fine to use - its an easy to use library. You can also do an HTTP/S POST directly:

Here is how I login (I am using a direct HTTP/S Post https://github.com/pliablepixels/zmNinj ... pp.js#L487)
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Locked