Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions motioneye/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,8 +1219,10 @@ def motion_camera_ui_to_dict(ui, prev_config=None):
url = sub('\\s', '+', ui['web_hook_notifications_url'])

on_event_start.append(
"{script} '{method}' '{url}'".format(
"{script} {useragent} {accept} '{method}' '{url}'".format(
script=meyectl.find_command('webhook'),
useragent=f"'{ui['web_hook_notifications_user_agent']}'" if ui['web_hook_notifications_user_agent'] else '',
accept=f"'{ui['web_hook_notifications_accept']}'" if ui['web_hook_notifications_accept'] else '',
method=ui['web_hook_notifications_http_method'],
url=url,
)
Expand All @@ -1238,12 +1240,13 @@ def motion_camera_ui_to_dict(ui, prev_config=None):
url = sub(r'\s', '+', ui['web_hook_end_notifications_url'])

on_event_end.append(
"%(script)s '%(method)s' '%(url)s'"
% {
'script': meyectl.find_command('webhook'),
'method': ui['web_hook_end_notifications_http_method'],
'url': url,
}
"{script} {useragent} {accept} '{method}' '{url}'".format(
script=meyectl.find_command('webhook'),
useragent=f"'{ui['web_hook_end_notifications_user_agent']}'" if ui['web_hook_end_notifications_user_agent'] else '',
accept=f"'{ui['web_hook_end_notifications_accept']}'" if ui['web_hook_end_notifications_accept'] else '',
method=ui['web_hook_end_notifications_http_method'],
url=url,
)
)

if ui['command_end_notifications_enabled']:
Expand Down Expand Up @@ -1310,7 +1313,7 @@ def motion_camera_ui_to_dict(ui, prev_config=None):
return prev_config


def motion_camera_dict_to_ui(data):
def motion_camera_dict_to_ui(data): # noqa: C901
ui = {
# device
'name': data['camera_name'],
Expand Down Expand Up @@ -1720,13 +1723,20 @@ def motion_camera_dict_to_ui(data):
elif ' webhook ' in e:
e = split(e)

if len(e) < 3:
if len(e) < 7:
continue

ui['web_hook_notifications_enabled'] = True
ui['web_hook_notifications_http_method'] = e[-2]
ui['web_hook_notifications_url'] = e[-1]

# support pre-v0.43.0 configs
if len(e) < 9:
continue

ui['web_hook_notifications_accept'] = e[-3]
ui['web_hook_notifications_user_agent'] = e[-4]

elif 'relayevent' in e:
continue # ignore internal relay script

Expand All @@ -1747,13 +1757,20 @@ def motion_camera_dict_to_ui(data):
if ' webhook ' in e:
e = split(e)

if len(e) < 3:
if len(e) < 7:
continue

ui['web_hook_end_notifications_enabled'] = True
ui['web_hook_end_notifications_http_method'] = e[-2]
ui['web_hook_end_notifications_url'] = e[-1]

# support pre-v0.43.0 configs
if len(e) < 9:
continue

ui['web_hook_end_notifications_accept'] = e[-3]
ui['web_hook_end_notifications_user_agent'] = e[-4]

elif 'relayevent' in e or 'eventrelay.py' in e:
continue # ignore internal relay script

Expand Down
8 changes: 8 additions & 0 deletions motioneye/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2054,9 +2054,13 @@ function cameraUi2Dict() {
'web_hook_notifications_enabled': $('#webHookNotificationsEnabledSwitch')[0].checked,
'web_hook_notifications_url': $('#webHookNotificationsUrlEntry').val(),
'web_hook_notifications_http_method': $('#webHookNotificationsHttpMethodSelect').val(),
'web_hook_notifications_accept': $('#webHookNotificationsAcceptHeader').val(),
'web_hook_notifications_user_agent': $('#webHookNotificationsUserAgentHeader').val(),
'web_hook_end_notifications_enabled': $('#webHookEndNotificationsEnabledSwitch')[0].checked,
'web_hook_end_notifications_url': $('#webHookEndNotificationsUrlEntry').val(),
'web_hook_end_notifications_http_method': $('#webHookEndNotificationsHttpMethodSelect').val(),
'web_hook_end_notifications_accept': $('#webHookEndNotificationsAcceptHeader').val(),
'web_hook_end_notifications_user_agent': $('#webHookEndNotificationsUserAgentHeader').val(),
'command_notifications_enabled': $('#commandNotificationsEnabledSwitch')[0].checked,
'command_notifications_exec': $('#commandNotificationsEntry').val(),
'command_end_notifications_enabled': $('#commandEndNotificationsEnabledSwitch')[0].checked,
Expand Down Expand Up @@ -2436,10 +2440,14 @@ function dict2CameraUi(dict) {
$('#webHookNotificationsEnabledSwitch')[0].checked = dict['web_hook_notifications_enabled']; markHideIfNull('web_hook_notifications_enabled', 'webHookNotificationsEnabledSwitch');
$('#webHookNotificationsUrlEntry').val(dict['web_hook_notifications_url']);
$('#webHookNotificationsHttpMethodSelect').val(dict['web_hook_notifications_http_method']);
$('#webHookNotificationsAcceptHeader').val(dict['web_hook_notifications_accept']);
$('#webHookNotificationsUserAgentHeader').val(dict['web_hook_notifications_user_agent']);

$('#webHookEndNotificationsEnabledSwitch')[0].checked = dict['web_hook_end_notifications_enabled']; markHideIfNull('web_hook_end_notifications_enabled', 'webHookEndNotificationsEnabledSwitch');
$('#webHookEndNotificationsUrlEntry').val(dict['web_hook_end_notifications_url']);
$('#webHookEndNotificationsHttpMethodSelect').val(dict['web_hook_end_notifications_http_method']);
$('#webHookEndNotificationsAcceptHeader').val(dict['web_hook_end_notifications_accept']);
$('#webHookEndNotificationsUserAgentHeader').val(dict['web_hook_end_notifications_user_agent']);

$('#commandNotificationsEnabledSwitch')[0].checked = dict['command_notifications_enabled']; markHideIfNull('command_notifications_enabled', 'commandNotificationsEnabledSwitch');
$('#commandNotificationsEntry').val(dict['command_notifications_exec']);
Expand Down
20 changes: 20 additions & 0 deletions motioneye/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,16 @@
</td>
<td><span class="help-mark" title="{{ _("La HTTP-metodo por uzi kiam vi petas URL (la donitaj URL-parametroj estos transdonitaj kiel indikite ĉi tie).") }}">?</span></td>
</tr>
<tr class="settings-item" validate="^[^;\']*$" depends="webHookNotificationsEnabled motionDetectionEnabled" strip="true">
<td class="settings-item-label"><span class="settings-item-label">Accept Header</span></td>
<td class="settings-item-value"><input type="text" class="styled notifications camera-config" id="webHookNotificationsAcceptHeader" placeholder="e.g. */*"></td>
<td><span class="help-mark" title="If the webhook server would reject requests whose headers are missing Accept key, you can provide one here">?</span></td>
</tr>
<tr class="settings-item" validate="^[^;\']*$" depends="webHookNotificationsEnabled motionDetectionEnabled" strip="true">
<td class="settings-item-label"><span class="settings-item-label">User-Agent Header</span></td>
<td class="settings-item-value"><input type="text" class="styled notifications camera-config" id="webHookNotificationsUserAgentHeader" placeholder="e.g. curl/7.64.0"></td>
<td><span class="help-mark" title="If the webhook server would reject requests whose headers are missing User-Agent key, you can provide one here">?</span></td>
</tr>
<tr class="settings-item" depends="motionDetectionEnabled">
<td colspan="100"><div class="settings-item-separator"></div></td>
</tr>
Expand Down Expand Up @@ -1194,6 +1204,16 @@
</td>
<td><span class="help-mark" title="{{ _("La HTTP-metodo por uzi kiam vi petas URL (la donitaj URL-parametroj estos transdonitaj kiel indikite ĉi tie).") }}">?</span></td>
</tr>
<tr class="settings-item" validate="^[^;\']*$" depends="webHookEndNotificationsEnabled motionDetectionEnabled" strip="true">
<td class="settings-item-label"><span class="settings-item-label">Accept Header</span></td>
<td class="settings-item-value"><input type="text" class="styled notifications camera-config" id="webHookEndNotificationsAcceptHeader" placeholder="e.g. */*"></td>
<td><span class="help-mark" title="If the webhook server would reject requests whose headers are missing Accept key, you can provide one here">?</span></td>
</tr>
<tr class="settings-item" validate="^[^;\']*$" depends="webHookEndNotificationsEnabled motionDetectionEnabled" strip="true">
<td class="settings-item-label"><span class="settings-item-label">User-Agent Header</span></td>
<td class="settings-item-value"><input type="text" class="styled notifications camera-config" id="webHookEndNotificationsUserAgentHeader" placeholder="e.g. curl/7.64.0"></td>
<td><span class="help-mark" title="If the webhook server would reject requests whose headers are missing User-Agent key, you can provide one here">?</span></td>
</tr>
<tr class="settings-item" depends="motionDetectionEnabled">
<td colspan="100"><div class="settings-item-separator"></div></td>
</tr>
Expand Down
10 changes: 10 additions & 0 deletions motioneye/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@


def parse_options(parser, args):
parser.add_argument('useragent', help='the User Agent header for the request')
parser.add_argument('accept', help='the Accept header for the request')
parser.add_argument('method', help='the HTTP method to use')
parser.add_argument('url', help='the URL for the request')

Expand All @@ -40,12 +42,20 @@ def main(parser, args):

logging.debug('hello!')
logging.debug('method = %s' % options.method)
if 'accept' in options:
logging.debug('accept = %s' % options.accept)
if 'useragent' in options:
logging.debug('useragent = %s' % options.useragent)
logging.debug('url = %s' % options.url)

headers = {}
parts = urllib.parse.urlparse(options.url)
url = options.url
data = None
if 'accept' in options and options.accept:
headers['Accept'] = options.accept
if 'useragent' in options and options.useragent:
headers['User-Agent'] = options.useragent

if options.method == 'POST':
headers['Content-Type'] = 'text/plain'
Expand Down