]> www.vanbest.org Git - motioneye-debian/commitdiff
added support for execution of commands upon motion detection
authorCalin Crisan <ccrisan@gmail.com>
Wed, 20 Aug 2014 13:16:12 +0000 (16:16 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Wed, 20 Aug 2014 13:16:12 +0000 (16:16 +0300)
src/config.py
static/js/main.js
templates/main.html

index 3bbaaf72f6c84fd3f3deac9e0bf4c0b9b26f4526..2ea241a25b1d86499cd4a2559e88e7968ab6aed4 100644 (file)
@@ -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('|')
index bc6855e0e952f7813223cfe0466d0fc98ffcce69..c12685375a459b10dd49e99d8ce30f50657c1614 100644 (file)
@@ -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'];
index 7f51e496ca54cd4f7377cec1e805a6dc7a63d4c7..7ead94723284a8ce339128ae1a3822c3f0664323 100644 (file)
                         </td>
                         <td><span class="help-mark" title="the HTTP method to use when requesting the web hook URL">?</span></td>
                     </tr>
+                    <tr class="settings-item advanced-setting">
+                        <td colspan="100"><div class="settings-item-separator"></div></td>
+                    </tr>
+                    <tr class="settings-item advanced-setting">
+                        <td class="settings-item-label"><span class="settings-item-label">Run A Command</span></td>
+                        <td class="settings-item-value"><input type="checkbox" class="styled notifications" id="commandNotificationsSwitch"></td>
+                        <td><span class="help-mark" title="enable this if you want to execute a command whenever a motion event is detected">?</span></td>
+                    </tr>
+                    <tr class="settings-item advanced-setting">
+                        <td class="settings-item-label"><span class="settings-item-label">Command</span></td>
+                        <td class="settings-item-value"><input type="text" class="styled notifications" id="commandNotificationsEntry" placeholder="command..."></td>
+                        <td><span class="help-mark" title="a command to be executed when motion is detected; multiple commands can be separated by a semicolon; the following special tokens are accepted: %Y = year, %m = month, %d = date, %H = hour, %M = minute, %S = second, %q = frame number">?</span></td>
+                    </tr>
                 </table>
 
                 <div class="settings-section-title hidden"><input type="checkbox" class="styled section working-schedule" id="workingScheduleSwitch">Working Schedule</div>