From: Calin Crisan Date: Sun, 24 Aug 2014 17:16:38 +0000 (+0300) Subject: fixed remote motioneye camera management X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=90b2aff8758d2f0bc8cf1dc20f416ebd306b784b;p=motioneye-debian fixed remote motioneye camera management --- diff --git a/src/config.py b/src/config.py index 4219e9c..d9ce121 100644 --- a/src/config.py +++ b/src/config.py @@ -615,7 +615,7 @@ def camera_ui_to_dict(ui): # device data['netcam_url'] = ui['proto'] + '://' + ui['host'] if ui['port']: - data['netcam_url'] += ':' + ui['port'] + data['netcam_url'] += ':' + str(ui['port']) data['netcam_url'] += ui['uri'] diff --git a/src/handlers.py b/src/handlers.py index f295218..55de7ba 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -247,11 +247,22 @@ class ConfigHandler(BaseHandler): local_config = config.get_camera(camera_id) if utils.local_camera(local_config): + # certain parameters cannot be changed via ui_config; + # we must preserve existing values for those params + local_ui_config = config.camera_dict_to_ui(local_config) + ui_config.setdefault('enabled', local_ui_config['enabled']) + ui_config['proto'] = local_ui_config['proto'] + ui_config['host'] = local_ui_config['host'] + ui_config['port'] = local_ui_config['port'] + ui_config['uri'] = local_ui_config['uri'] + ui_config['username'] = local_ui_config['username'] + ui_config['password'] = local_ui_config['password'] + local_config = config.camera_ui_to_dict(ui_config) config.set_camera(camera_id, local_config) on_finish(None, True) # (no error, motion needs restart) - + else: # remote camera # update the camera locally local_config['@enabled'] = ui_config['enabled'] @@ -262,7 +273,6 @@ class ConfigHandler(BaseHandler): if ui_config.has_key('name'): # never disable a remote camera on the remote host itself - del ui_config['enabled'] def on_finish_wrapper(error=None): return on_finish(error, False) @@ -935,3 +945,10 @@ class UpdateHandler(BaseHandler): result = update.perform_update(version) self.finish_json(result) + + +class VersionHandler(BaseHandler): + def get(self): + self.render('version.html', + version=update.get_version(), + hostname=socket.gethostname()) diff --git a/src/remote.py b/src/remote.py index bf791f8..8bc29a6 100644 --- a/src/remote.py +++ b/src/remote.py @@ -144,12 +144,21 @@ def get_config(local_config, callback): def set_config(local_config, ui_config, callback): - host = local_config.get('@host', local_config.get('host')) - port = local_config.get('@port', local_config.get('port')) - username = local_config.get('@username', local_config.get('username')) - password = local_config.get('@password', local_config.get('password')) - uri = local_config.get('@uri', local_config.get('uri')) or '' - camera_id = local_config.get('@remote_camera_id', local_config.get('remote_camera_id')) + host = local_config.get('@host') + port = local_config.get('@port') + username = local_config.get('@username') + password = local_config.get('@password') + uri = local_config.get('@uri') or '' + camera_id = local_config.get('@remote_camera_id') + + # make sure these values never get to the remote instance + local_config.pop('enabled', None) + local_config.pop('proto', None) + local_config.pop('host', None) + local_config.pop('port', None) + local_config.pop('uri', None) + local_config.pop('username', None) + local_config.pop('password', None) logging.debug('setting config for remote camera %(id)s on %(url)s' % { 'id': camera_id, diff --git a/src/server.py b/src/server.py index 70e42b4..209c0a1 100644 --- a/src/server.py +++ b/src/server.py @@ -49,6 +49,7 @@ application = Application( (r'^/movie/(?P\d+)/(?Plist)/?$', handlers.MovieHandler), (r'^/movie/(?P\d+)/(?Pdownload|preview)/(?P.+)/?$', handlers.MovieHandler), (r'^/update/?$', handlers.UpdateHandler), + (r'^/version/?$', handlers.VersionHandler), (r'^.*$', handlers.NotFoundHandler), ], debug=False, diff --git a/src/utils.py b/src/utils.py index 62d496a..f287f17 100644 --- a/src/utils.py +++ b/src/utils.py @@ -229,6 +229,14 @@ def net_camera(config): def test_netcam_url(data, callback): + data = dict(data) + data.setdefault('proto', 'http') + data.setdefault('host', '127.0.0.1') + data.setdefault('port', '80') + data.setdefault('uri', '') + data.setdefault('username', None) + data.setdefault('password', None) + url = '%(proto)s://%(host)s%(port)s%(uri)s' % { 'proto': data['proto'], 'host': data['host'],