From: Calin Crisan <ccrisan@gmail.com>
Date: Sat, 5 Aug 2017 12:40:40 +0000 (+0300)
Subject: add support for password hook external program
X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=a713b4afaa7441fc3b03463a2caef933a3de647e;p=motioneye-debian

add support for password hook external program
---

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