zoneminder icon indicating copy to clipboard operation
zoneminder copied to clipboard

Added configuring of authentication for rstp cameras

Open parvit opened this issue 2 years ago • 8 comments

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.

parvit avatar Jul 22 '22 11:07 parvit

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!

jp-bennett avatar Aug 09 '22 20:08 jp-bennett

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?

parvit avatar Aug 09 '22 22:08 parvit

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.

jp-bennett avatar Aug 09 '22 23:08 jp-bennett

Just pulling this code as-is would break Janus.

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

parvit avatar Aug 09 '22 23:08 parvit

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.

jp-bennett avatar Aug 10 '22 15:08 jp-bennett

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

parvit avatar Aug 10 '22 16:08 parvit

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.

connortechnology avatar Aug 10 '22 22:08 connortechnology

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.

jp-bennett avatar Aug 10 '22 22:08 jp-bennett

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

parvit avatar Aug 14 '22 15:08 parvit

@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.

parvit avatar Aug 15 '22 16:08 parvit

"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 avatar Aug 15 '22 16:08 jp-bennett

Getting a crash with this code.

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

jp-bennett avatar Aug 15 '22 18:08 jp-bennett

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.

parvit avatar Aug 15 '22 18:08 parvit

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.

jp-bennett avatar Aug 15 '22 18:08 jp-bennett

Found, it was the backslashes at the end

parvit avatar Aug 15 '22 18:08 parvit

Found, it was the backslashes at the end

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

jp-bennett avatar Aug 15 '22 18:08 jp-bennett

ops forgot to add back the std:: prefix

parvit avatar Aug 15 '22 18:08 parvit

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.

jp-bennett avatar Aug 15 '22 19:08 jp-bennett

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

parvit avatar Aug 15 '22 20:08 parvit

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.

jp-bennett avatar Aug 15 '22 20:08 jp-bennett

@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:

  • Added the user and password fields to Remote type monitors
  • Edit of the path field will cause the local update of the user and password fields only if they were empty, moreover if they are equal it will update the corresponding field dynamically (ie. updating the username field in the url will cause the username form field to update)
  • On losing focus for any of the fields, a local sync of the values if performed, meaning that if the fields in both the url and the username/password are equal than they are removed from the url

On the backend side:

  • On update from the clientside and on loading of the monitors from the database, the same rules are enforced

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.

parvit avatar Aug 18 '22 09:08 parvit

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

jp-bennett avatar Aug 20 '22 00:08 jp-bennett

@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.

parvit avatar Aug 20 '22 15:08 parvit

@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 avatar Aug 20 '22 22:08 jp-bennett

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

jp-bennett avatar Aug 21 '22 20:08 jp-bennett

I'll take a look tonight

connortechnology avatar Aug 21 '22 21:08 connortechnology