From: Calin Crisan Date: Sat, 2 Jul 2016 09:31:53 +0000 (+0300) Subject: rtsp network cameras: added support for basic authentication X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=c3f900a1412698568c13f81cee3ed24a18070e19;p=motioneye-debian rtsp network cameras: added support for basic authentication --- diff --git a/motioneye/templates/main.html b/motioneye/templates/main.html index a920f3d..19c7d43 100644 --- a/motioneye/templates/main.html +++ b/motioneye/templates/main.html @@ -586,7 +586,7 @@ - ? + ? {% endif %} diff --git a/motioneye/utils.py b/motioneye/utils.py index bb7b995..36ffbb0 100644 --- a/motioneye/utils.py +++ b/motioneye/utils.py @@ -473,13 +473,22 @@ def test_rtsp_url(data, callback): logging.debug('connected to rtsp netcam') - stream.write('\r\n'.join([ + lines = [ 'OPTIONS %s RTSP/1.0' % url.encode('utf8'), 'CSeq: 1', - 'User-Agent: motionEye', + 'User-Agent: motionEye' + ] + + if data['username']: + auth_header = 'Authorization: ' + build_basic_header(data['username'], data['password']) + lines.append(auth_header) + + lines += [ '', '' - ])) + ] + + stream.write('\r\n'.join(lines)) seek_rtsp() @@ -497,6 +506,9 @@ def test_rtsp_url(data, callback): if data.endswith('200 '): seek_server() + elif data.endswith('401 '): + handle_error('authentication failed') + else: handle_error('rtsp netcam returned erroneous response: %s' % data)