ZoneMinder / zoneminder

ZoneMinder is a free, open source Closed-circuit television software application developed for Linux which supports IP, USB and Analog cameras.
http://www.zoneminder.com/
GNU General Public License v2.0
4.9k stars 1.2k forks source link

Added configuring of authentication for rstp cameras #3537

Closed parvit closed 1 year ago

parvit commented 1 year ago

This responds to #695.

The change is not too complex and builds on support that was already present in the code. It simply introduces the required fields in the monitor edit page to allow to specify the user and password for the camera. The values are already handled and saved/loaded by the backing php monitor code.

At this moment I have not inserted any explicit validation seen that the authentication is mediated by rtsp headers and not in the url so any value should be allowed.

I've tested this on my local machine with a "remote" type camera and it seems to authenticate correctly with the correct username/password containing special characters not allowed in url (without encoding).

Please review and test.

jp-bennett commented 1 year ago

This changeset should also update how Janus gets username and password for RTSP streams: https://github.com/ZoneMinder/zoneminder/blob/master/src/zm_monitor_janus.cpp#L44

Good to see this being worked on!

parvit commented 1 year ago

This changeset should also update how Janus gets username and password for RTSP streams: https://github.com/ZoneMinder/zoneminder/blob/master/src/zm_monitor_janus.cpp#L44

Good to see this being worked on!

Thanks, i have not seen the part for janus, but doesn't your change split the data in url? So it would fail all the same with special characters, or maybe i'm missing something?

jp-bennett commented 1 year ago

but doesn't your change split the data in url?

Yes. We currently split username/password out of the given URL so Janus can authenticate. When we pull this changeset, and switch to using a username and password, the Janus code should drop the URL parsing and just use user and pass. Just pulling this code as-is would break Janus.

parvit commented 1 year ago

Just pulling this code as-is would break Janus.

Should i then investigate this kind of integration with the janus straming too?

jp-bennett commented 1 year ago

Should i then investigate this kind of integration with the Janus streaming too?

Yes please. It should be straightforward to drop the URL parsing code, and set the user/pass sent to Janus using the new options.

parvit commented 1 year ago

Sure i'll look into it as soon as i can.

connortechnology commented 1 year ago

The way that I was going to go was to actually change the Source tab UI to sync it up between remote and ffmpeg types. Because we don't want to be able to actually see the password so the idea is you could either cutnpaste a full url and it would auto populate the split out parts (scheme, username, password, host, path, query etc). Because when you switch between ffmpeg and remote they use the parts differently It would be nice to be able to switch back and forth.

jp-bennett commented 1 year ago

cutnpaste a full url and it would auto populate the split out parts (scheme, username, password, host, path, query etc).

Would be nice to have that capability anyway, to transition from the old all-in-one URL to the new split-out interface.

parvit commented 1 year ago

@connortechnology @jp-bennett I'll check the janus integration first than i'll check how to implement the (browser-side) sync.

parvit commented 1 year ago

@jp-bennett I was trying to test my change with janus, but i'm getting an error that the "javascript/janus/janus.js" library is not found when opening the live view, can you point me to where can i find / how to generate that lib?

Also would it be correct to assume that the user and password to be used for janus monitor are the same as the parent monitor?

thank you for the support.

jp-bennett commented 1 year ago

"javascript/janus/janus.js" library is not found when opening the live view, can you point me to where can i find / how to generate that lib?

It depends on what distro you're using, but for Ubuntu, installing libjs-janus will get the javascript library in place (Might require an a2enconf, can't remember). It's contained in the Janus source (https://github.com/meetecho/janus-gateway/blob/master/html/janus.js) but the js lib needs to match the version of the Janus binary.

Also would it be correct to assume that the user and password to be used for janus monitor are the same as the parent monitor?

Yes. What this is doing is sending the proper credentials to Janus, so Janus can connect to the camera directly.

jp-bennett commented 1 year ago

Getting a crash with this code.

terminate called after throwing an instance of 'std::regex_error'
  what(): Unexpected end of regex when escaping.
parvit commented 1 year ago

Thanks for testing i'm having serious trouble setting up janus (something about the ICE servers not being defined), i'll check now the cause of the error.

jp-bennett commented 1 year ago

Thanks for testing i'm having serious trouble setting up janus (something about the ICE servers not being defined), i'll check now the cause of the error.

That's a misleading error. You don't need ICE servers. It's a pain to set up the first time, that's true. What's worse, browsers have this habit of not playing the streams if they're not specifically h264 baseline. I'm also trying to figure out exactly what regex is complaining about.

parvit commented 1 year ago

Found, it was the backslashes at the end

jp-bennett commented 1 year ago

Found, it was the backslashes at the end

I think we figured that out at the same moment. =)

parvit commented 1 year ago

ops forgot to add back the std:: prefix

jp-bennett commented 1 year ago

That part looks good. Now we just need to get the bits wired up for ffmpeg and vlc capture. And it would be really slick to have a database update that pulls any auth strings out of the source path, and populates username/password.

parvit commented 1 year ago

Should the url auth parsing happen only when the fields are empty? because otherwise you might accidentally overwrite the user values.

jp-bennett commented 1 year ago

Should the url auth parsing happen only when the fields are empty? because otherwise you might accidentally overwrite the user values.

That sounds reasonable. If either field is populated, leave everything as-is. If they are empty and the URL appears to have a username and/or password, extract to the appropriate fields.

parvit commented 1 year ago

@jp-bennett @connortechnology Hi all, i've integrated the request for updating dynamically from the db and ui the update of the path, user and password values.

On the UI side:

On the backend side:

So this means for example that loading a path value already in the db with both username and password set will populate the corresponding fields and remove them from url

I hope i've interpreted correctly what was requested.

Is there anything else that should be included? thanks.

jp-bennett commented 1 year ago

Is there anything else that should be included?

The only other thing I know of is that ffmpeg cameras should use the username/pass fields, too. That's how most users set up for RTSP. It's likely a simple pair of options to set in https://github.com/ZoneMinder/zoneminder/blob/master/src/zm_ffmpeg_camera.cpp

parvit commented 1 year ago

@jp-bennett I've added the ffmpeg and the libvlc support for the auth.

Please check if everything necessary for the feature is present and test it if you can.

jp-bennett commented 1 year ago

@jp-bennett I've added the ffmpeg and the libvlc support for the auth.

Please check if everything necessary for the feature is present and test it if you can.

I'll give it a thorough test over the weekend. Excited to get this pulled in.

jp-bennett commented 1 year ago

Tested and working here. @connortechnology you see any problems with this? I'm inclined to pull it.

connortechnology commented 1 year ago

I'll take a look tonight