From a713b4afaa7441fc3b03463a2caef933a3de647e Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sat, 5 Aug 2017 15:40:40 +0300 Subject: [PATCH] add support for password hook external program --- motioneye/config.py | 18 ++++++++++++++++++ motioneye/settings.py | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/motioneye/config.py b/motioneye/config.py index c606673..2a8be05 100644 --- a/motioneye/config.py +++ b/motioneye/config.py @@ -645,6 +645,20 @@ def main_ui_to_dict(ui): '@normal_username': ui['normal_username'] } + def call_hook(u, p): + if settings.PASSWORD_HOOK: + env = { + 'MEYE_USERNAME': u, + 'MEYE_PASSWORD': p + } + + try: + subprocess.check_output(settings.PASSWORD_HOOK, env=env, stderr=subprocess.STDOUT) + logging.debug('password hook exec succeeded') + + except Exception as e: + logging.error('password hook exec failed: %s' % e) + if ui.get('admin_password') is not None: if ui['admin_password']: data['@admin_password'] = hashlib.sha1(ui['admin_password']).hexdigest() @@ -652,6 +666,8 @@ def main_ui_to_dict(ui): else: data['@admin_password'] = '' + call_hook(ui['admin_username'], ui['admin_password']) + if ui.get('normal_password') is not None: if ui['normal_password']: data['@normal_password'] = hashlib.sha1(ui['normal_password']).hexdigest() @@ -659,6 +675,8 @@ def main_ui_to_dict(ui): else: data['@normal_password'] = '' + call_hook(ui['normal_username'], ui['normal_password']) + # additional configs for name, value in ui.iteritems(): if not name.startswith('_'): diff --git a/motioneye/settings.py b/motioneye/settings.py index 4478661..10d32f4 100644 --- a/motioneye/settings.py +++ b/motioneye/settings.py @@ -124,3 +124,7 @@ ADD_REMOVE_CAMERAS = True # enable HTTPS certificate validation VALIDATE_CERTS = True + +# an external program to be executed whenever a password changes; +# the program will be invoked with environment variables MEYE_USERNAME and MEYE_PASSWORD +PASSWORD_HOOK = None -- 2.39.5