From d0e4f8f8a281d53bee88b8f47acfdaaed9bed7ba Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Wed, 20 Aug 2014 16:16:12 +0300 Subject: [PATCH] added support for execution of commands upon motion detection --- src/config.py | 14 +++++++++++++- static/js/main.js | 10 ++++++++++ templates/main.html | 13 +++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/config.py b/src/config.py index 3bbaaf7..2ea241a 100644 --- a/src/config.py +++ b/src/config.py @@ -719,6 +719,10 @@ def camera_ui_to_dict(ui): 'method': ui['web_hook_notifications_http_method'], 'url': url}) + if ui['command_notifications_enabled']: + commands = ui['command_notifications_exec'].split(';') + on_event_start += [c.strip() for c in commands] + if ui['working_schedule']: data['@working_schedule'] = ( ui['monday_from'] + '-' + ui['monday_to'] + '|' + @@ -940,6 +944,7 @@ def camera_dict_to_ui(data): ui['movie_quality'] = min(100, int(round(ffmpeg_bps * 100.0 / max_val))) + command_notifications = [] for e in on_event_start: if e.count('sendmail.py') and e.count('motion_start'): e = e.replace('"', '').split(' ') @@ -960,9 +965,16 @@ def camera_dict_to_ui(data): continue ui['web_hook_notifications_enabled'] = True - ui['web_hook_notifications_method'] = e[1] + ui['web_hook_notifications_http_method'] = e[1] ui['web_hook_notifications_url'] = e[2] + else: # custom command + command_notifications.append(e) + + if command_notifications: + ui['command_notifications_enabled'] = True + ui['command_notifications_exec'] = '; '.join(command_notifications) + working_schedule = data['@working_schedule'] if working_schedule: days = working_schedule.split('|') diff --git a/static/js/main.js b/static/js/main.js index bc6855e..c126853 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -218,6 +218,7 @@ function initUI() { makeTextValidator($('#smtpAccountEntry'), true); makeTextValidator($('#smtpPasswordEntry'), true); makeTextValidator($('#webHookUrlEntry'), true); + makeTextValidator($('#commandNotificationsEntry'), true); /* number validators */ makeNumberValidator($('#streamingPortEntry'), 1024, 65535, false, false, true); @@ -266,6 +267,7 @@ function initUI() { $('#preserveMoviesSelect').change(updateConfigUi); $('#emailNotificationsSwitch').change(updateConfigUi); $('#webHookNotificationsSwitch').change(updateConfigUi); + $('#commandNotificationsSwitch').change(updateConfigUi); $('#workingScheduleSwitch').change(updateConfigUi); $('#storageDeviceSelect').change(function () { @@ -488,6 +490,10 @@ function updateConfigUi() { $('#webHookHttpMethod').parents('tr:eq(0)').each(markHide); } + if (!$('#commandNotificationsSwitch').get(0).checked) { + $('#commandNotificationsEntry').parents('tr:eq(0)').each(markHide); + } + /* working schedule switch */ if (!$('#workingScheduleSwitch').get(0).checked) { $('#workingScheduleSwitch').parent().next('table.settings').find('tr.settings-item').each(markHide); @@ -673,6 +679,8 @@ function cameraUi2Dict() { 'web_hook_notifications_enabled': $('#webHookNotificationsSwitch')[0].checked, 'web_hook_notifications_url': $('#webHookUrlEntry').val(), 'web_hook_notifications_http_method': $('#webHookHttpMethod').val(), + 'command_notifications_enabled': $('#commandNotificationsSwitch')[0].checked, + 'command_notifications_exec': $('#commandNotificationsEntry').val(), /* working schedule */ 'working_schedule': $('#workingScheduleSwitch')[0].checked, @@ -852,6 +860,8 @@ function dict2CameraUi(dict) { $('#webHookNotificationsSwitch')[0].checked = dict['web_hook_notifications_enabled']; $('#webHookUrlEntry').val(dict['web_hook_notifications_url']); $('#webHookHttpMethod').val(dict['web_hook_notifications_http_method']); + $('#commandNotificationsSwitch')[0].checked = dict['command_notifications_enabled']; + $('#commandNotificationsEntry').val(dict['command_notifications_exec']); /* working schedule */ $('#workingScheduleSwitch')[0].checked = dict['working_schedule']; diff --git a/templates/main.html b/templates/main.html index 7f51e49..7ead947 100644 --- a/templates/main.html +++ b/templates/main.html @@ -480,6 +480,19 @@ ? + +
+ + + Run A Command + + ? + + + Command + + ? + -- 2.39.5