scottlamb / moonfire-nvr

Moonfire NVR, a security camera network video recorder
Other
1.19k stars 138 forks source link

API: Samples or Demos? #262

Open jlpoolen opened 1 year ago

jlpoolen commented 1 year ago

I'm trying to utilize the API and running into cross-domain issues if I create an HTML file with a JavaScript file on my laptop trying to send an xmlhttp request to my moonfire-nvr instance (server identified by IP) running on a raspberry pi server. I've used APIs in the past when I have had to, but here I'm getting tripped up by things like

 CORS header 'Access-Control-Allow-Origin' missing  

While I'm slogging through trying to get over the CORS issues, I finally decided to install an instance of moonfire-nvr on my laptop so the moonfire instance is on the same "localhost" machine and hopefully doesn't trigger all the glorious protection devices built into Firefox to save me from malicious machinations. All this is leading to a request here in this Issue of possibly sharing some demonstration files of HTML and JavaScript which illustrate the API. I was thinking of trying to have a sample set for each API call so someone doesn't really have to think or be fully aware of all the security ramifications when testing the API.

Lastly, I'm an Apache fan and the fact the moonfire-nvr runs on something other than Apache, nginx?, just adds another technology I have to become slightly familiar with in order to just deploy a test HTML file. So, any pointers such as "place your test html files here" within the server's directory structure would go a long way. I'm also a Perl fan and suppose cgi-bin in frowned upon, but if it is a simple matter to stage Perl scripts under the moonfire server as I would on Apache under cgi-bin, knowing how to do so would really be helpful. I feel like I'm speaking one language in a foreign jurisdiction and making requests to have someone in my native tongue.

jlpoolen commented 1 year ago

I'll add why now I'm focused on the API. I've got the Google Coral libraries supporting the USB unit to work in Gentoo LInux. Now I'm focusing on gstreamer (which I recommend you build outside of Gentoo's portage system which, in my opinion, just complicates and breaks up gstreamer into countless units -- much like Gentoo's implementation of thousands of Perl packages) and the next step is to try and harness mining videos directly from moonfire-nvr for edge detection [classifying objects such as people, cars, bicyclists]. So I thought I would try the API to see if I can identify videos and then pull them out for analysis.

jlpoolen commented 1 year ago

I'm making progress, albeit using the command "curl". I do not know if I should document here, or perhaps start a wiki page on using curl for the API.

jlpoolen commented 1 year ago

Below needs to be run on the same box as the moonfire-nvr instance.

# below works, have the cookie returned by the server stored locally by curl using "--cookie-jar" parameter
curl -i -X POST --json '{"username": "jlpoole", "password":"XXXXXXXX"}' --cookie-jar cookies.txt localhost:8080/api/login

# below works, note the final forward slash "/" after "api", ommission of this character is fatal
curl -i -X GET --cookie cookies.txt http://localhost:8080/api/
jlpoolen commented 1 year ago

I think I have some Perl scripts that let you pull specific videos, If they are of interest and useful, what is the best way to share them?