2019-10-27 04:53:40 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright (C) 2019 Chris Caron <lead2gold@gmail.com>
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This code is licensed under the MIT License.
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files(the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions :
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
# THE SOFTWARE.
|
|
|
|
from django.shortcuts import render
|
|
|
|
from django.http import HttpResponse
|
2020-01-06 00:19:09 +01:00
|
|
|
from django.http import JsonResponse
|
2019-10-27 04:53:40 +01:00
|
|
|
from django.views import View
|
2019-10-29 02:54:51 +01:00
|
|
|
from django.conf import settings
|
2021-01-01 23:10:44 +01:00
|
|
|
from django.utils.html import escape
|
2019-10-27 04:53:40 +01:00
|
|
|
from django.utils.decorators import method_decorator
|
|
|
|
from django.views.decorators.cache import never_cache
|
|
|
|
from django.views.decorators.gzip import gzip_page
|
2020-01-04 21:50:00 +01:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-01-06 00:19:09 +01:00
|
|
|
from django.core.serializers.json import DjangoJSONEncoder
|
|
|
|
|
2023-05-15 23:10:15 +02:00
|
|
|
from .utils import parse_attachments
|
2019-10-27 04:53:40 +01:00
|
|
|
from .utils import ConfigCache
|
2023-02-26 16:33:14 +01:00
|
|
|
from .utils import apply_global_filters
|
2023-10-15 22:21:13 +02:00
|
|
|
from .utils import send_webhook
|
2019-10-27 04:53:40 +01:00
|
|
|
from .forms import AddByUrlForm
|
|
|
|
from .forms import AddByConfigForm
|
|
|
|
from .forms import NotifyForm
|
2019-10-29 02:54:51 +01:00
|
|
|
from .forms import NotifyByUrlForm
|
2020-09-02 23:42:17 +02:00
|
|
|
from .forms import CONFIG_FORMATS
|
|
|
|
from .forms import AUTO_DETECT_CONFIG_KEYWORD
|
2019-10-27 04:53:40 +01:00
|
|
|
|
2023-10-15 22:21:13 +02:00
|
|
|
import logging
|
2019-10-27 04:53:40 +01:00
|
|
|
import apprise
|
|
|
|
import json
|
|
|
|
import re
|
|
|
|
|
2021-12-02 03:28:02 +01:00
|
|
|
# Get an instance of a logger
|
|
|
|
logger = logging.getLogger('django')
|
|
|
|
|
2019-10-27 04:53:40 +01:00
|
|
|
# Content-Type Parsing
|
2019-10-28 00:41:02 +01:00
|
|
|
# application/x-www-form-urlencoded
|
|
|
|
# application/x-www-form-urlencoded
|
|
|
|
# multipart/form-data
|
|
|
|
MIME_IS_FORM = re.compile(
|
|
|
|
r'(multipart|application)/(x-www-)?form-(data|urlencoded)', re.I)
|
|
|
|
|
|
|
|
# Support JSON formats
|
|
|
|
# text/json
|
|
|
|
# text/x-json
|
|
|
|
# application/json
|
|
|
|
# application/x-json
|
|
|
|
MIME_IS_JSON = re.compile(
|
|
|
|
r'(text|application)/(x-)?json', re.I)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
2023-02-26 17:01:23 +01:00
|
|
|
# Tags separated by space , &, or + are and'ed together
|
|
|
|
# Tags separated by commas (even commas wrapped in spaces) are "or'ed" together
|
|
|
|
# We start with a regular expression used to clean up provided tags
|
|
|
|
TAG_VALIDATION_RE = re.compile(r'^\s*[a-z0-9\s| ,_-]+\s*$', re.IGNORECASE)
|
|
|
|
|
|
|
|
# In order to separate our tags only by comma's or '|' entries found
|
|
|
|
TAG_DETECT_RE = re.compile(
|
|
|
|
r'\s*([a-z0-9\s_&+-]+)(?=$|\s*[|,]\s*[a-z0-9\s&+_-|,])', re.I)
|
|
|
|
|
|
|
|
# Break apart our objects anded together
|
|
|
|
TAG_AND_DELIM_RE = re.compile(r'[\s&+]+')
|
|
|
|
|
|
|
|
MIME_IS_JSON = re.compile(
|
|
|
|
r'(text|application)/(x-)?json', re.I)
|
|
|
|
|
2019-10-27 04:53:40 +01:00
|
|
|
|
2020-01-06 00:19:09 +01:00
|
|
|
class JSONEncoder(DjangoJSONEncoder):
|
|
|
|
"""
|
|
|
|
A wrapper to the DjangoJSONEncoder to support
|
|
|
|
sets() (converting them to lists).
|
|
|
|
"""
|
|
|
|
def default(self, obj):
|
|
|
|
if isinstance(obj, set):
|
|
|
|
return list(obj)
|
2023-02-26 16:33:14 +01:00
|
|
|
|
|
|
|
elif isinstance(obj, apprise.AppriseLocale.LazyTranslation):
|
|
|
|
return str(obj)
|
|
|
|
|
2020-01-06 00:19:09 +01:00
|
|
|
return super().default(obj)
|
|
|
|
|
|
|
|
|
2019-10-27 04:53:40 +01:00
|
|
|
class ResponseCode(object):
|
|
|
|
"""
|
|
|
|
These codes are based on those provided by the requests object
|
|
|
|
"""
|
|
|
|
okay = 200
|
|
|
|
no_content = 204
|
|
|
|
bad_request = 400
|
2021-11-06 22:21:41 +01:00
|
|
|
no_access = 403
|
2019-10-27 04:53:40 +01:00
|
|
|
not_found = 404
|
|
|
|
method_not_allowed = 405
|
2021-12-02 03:46:53 +01:00
|
|
|
method_not_accepted = 406
|
2020-03-17 17:08:06 +01:00
|
|
|
failed_dependency = 424
|
2019-10-27 04:53:40 +01:00
|
|
|
internal_server_error = 500
|
|
|
|
|
|
|
|
|
|
|
|
class WelcomeView(View):
|
|
|
|
"""
|
|
|
|
A simple welcome/index page
|
|
|
|
"""
|
|
|
|
template_name = 'welcome.html'
|
|
|
|
|
|
|
|
def get(self, request):
|
2023-05-15 23:10:15 +02:00
|
|
|
default_key = 'KEY'
|
|
|
|
key = request.GET.get('key', default_key).strip()
|
|
|
|
return render(request, self.template_name, {
|
|
|
|
'secure': request.scheme[-1].lower() == 's',
|
|
|
|
'key': key if key else default_key,
|
|
|
|
})
|
2019-10-27 04:53:40 +01:00
|
|
|
|
|
|
|
|
2023-02-26 16:33:14 +01:00
|
|
|
@method_decorator((gzip_page, never_cache), name='dispatch')
|
|
|
|
class DetailsView(View):
|
|
|
|
"""
|
|
|
|
A Django view used to list all supported endpoints
|
|
|
|
"""
|
|
|
|
|
|
|
|
template_name = 'details.html'
|
|
|
|
|
|
|
|
def get(self, request):
|
|
|
|
"""
|
|
|
|
Handle a GET request
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Detect the format our response should be in
|
|
|
|
json_response = \
|
|
|
|
MIME_IS_JSON.match(
|
|
|
|
request.content_type
|
|
|
|
if request.content_type
|
|
|
|
else request.headers.get(
|
|
|
|
'accept', request.headers.get(
|
|
|
|
'content-type', ''))) is not None
|
|
|
|
|
|
|
|
# Show All flag
|
|
|
|
# Support 'yes', '1', 'true', 'enable', 'active', and +
|
|
|
|
show_all = request.GET.get('all', 'no')[0].lower() in (
|
2023-05-20 01:12:03 +02:00
|
|
|
'a', 'y', '1', 't', 'e', '+')
|
2023-02-26 16:33:14 +01:00
|
|
|
|
|
|
|
# Our status
|
|
|
|
status = ResponseCode.okay
|
|
|
|
|
|
|
|
#
|
|
|
|
# Apply Any Global Filters (if identified)
|
|
|
|
#
|
|
|
|
apply_global_filters()
|
|
|
|
|
|
|
|
# Create an Apprise Object
|
|
|
|
a_obj = apprise.Apprise()
|
|
|
|
|
|
|
|
# Load our details
|
|
|
|
details = a_obj.details(show_disabled=show_all)
|
|
|
|
|
|
|
|
# Sort our result set
|
|
|
|
details['schemas'] = sorted(
|
2023-11-18 21:20:30 +01:00
|
|
|
details['schemas'], key=lambda i: str(i['service_name']).upper())
|
2023-02-26 16:33:14 +01:00
|
|
|
|
|
|
|
# Return our content
|
|
|
|
return render(request, self.template_name, {
|
|
|
|
'show_all': show_all,
|
|
|
|
'details': details,
|
2023-05-20 01:12:03 +02:00
|
|
|
}, status=status) if not json_response else \
|
2023-02-26 16:33:14 +01:00
|
|
|
JsonResponse(
|
2023-05-20 01:12:03 +02:00
|
|
|
details,
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status)
|
2023-02-26 16:33:14 +01:00
|
|
|
|
|
|
|
|
2019-10-27 04:53:40 +01:00
|
|
|
@method_decorator(never_cache, name='dispatch')
|
|
|
|
class ConfigView(View):
|
|
|
|
"""
|
|
|
|
A Django view used to manage configuration
|
|
|
|
"""
|
|
|
|
template_name = 'config.html'
|
|
|
|
|
|
|
|
def get(self, request, key):
|
|
|
|
"""
|
|
|
|
Handle a GET request
|
|
|
|
"""
|
|
|
|
return render(request, self.template_name, {
|
|
|
|
'key': key,
|
|
|
|
'form_url': AddByUrlForm(),
|
|
|
|
'form_cfg': AddByConfigForm(),
|
|
|
|
'form_notify': NotifyForm(),
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(never_cache, name='dispatch')
|
|
|
|
class AddView(View):
|
|
|
|
"""
|
|
|
|
A Django view used to store Apprise configuration
|
|
|
|
"""
|
|
|
|
|
|
|
|
def post(self, request, key):
|
|
|
|
"""
|
|
|
|
Handle a POST request
|
|
|
|
"""
|
2021-11-06 22:21:41 +01:00
|
|
|
# Detect the format our response should be in
|
2023-02-26 16:33:14 +01:00
|
|
|
json_response = \
|
|
|
|
MIME_IS_JSON.match(
|
|
|
|
request.content_type
|
|
|
|
if request.content_type
|
|
|
|
else request.headers.get(
|
|
|
|
'accept', request.headers.get(
|
|
|
|
'content-type', ''))) is not None
|
2021-11-06 22:21:41 +01:00
|
|
|
|
|
|
|
if settings.APPRISE_CONFIG_LOCK:
|
|
|
|
# General Access Control
|
|
|
|
msg = _('The site has been configured to deny this request.')
|
|
|
|
status = ResponseCode.no_access
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
|
|
|
)
|
|
|
|
|
2019-10-27 04:53:40 +01:00
|
|
|
# our content
|
|
|
|
content = {}
|
2019-10-28 00:41:02 +01:00
|
|
|
if MIME_IS_FORM.match(request.content_type):
|
2019-10-27 04:53:40 +01:00
|
|
|
content = {}
|
|
|
|
form = AddByConfigForm(request.POST)
|
|
|
|
if form.is_valid():
|
2019-10-28 00:41:02 +01:00
|
|
|
content.update(form.cleaned_data)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
|
|
|
form = AddByUrlForm(request.POST)
|
|
|
|
if form.is_valid():
|
2019-10-28 00:41:02 +01:00
|
|
|
content.update(form.cleaned_data)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
2021-11-06 22:21:41 +01:00
|
|
|
elif json_response:
|
2019-10-27 04:53:40 +01:00
|
|
|
# Prepare our default response
|
|
|
|
try:
|
|
|
|
# load our JSON content
|
2020-01-04 21:50:00 +01:00
|
|
|
content = json.loads(request.body.decode('utf-8'))
|
2019-10-27 04:53:40 +01:00
|
|
|
|
|
|
|
except (AttributeError, ValueError):
|
|
|
|
# could not parse JSON response...
|
2021-11-06 22:21:41 +01:00
|
|
|
return JsonResponse({
|
2023-05-20 01:12:03 +02:00
|
|
|
'error': _('Invalid JSON specified.'),
|
|
|
|
},
|
2021-11-06 22:21:41 +01:00
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=ResponseCode.bad_request,
|
|
|
|
)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
|
|
|
if not content:
|
2021-11-06 22:21:41 +01:00
|
|
|
# No information was posted
|
|
|
|
msg = _('The message format is not supported.')
|
|
|
|
status = ResponseCode.bad_request
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
|
|
|
)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
|
|
|
# Create ourselves an apprise object to work with
|
|
|
|
a_obj = apprise.Apprise()
|
|
|
|
if 'urls' in content:
|
|
|
|
# Load our content
|
|
|
|
a_obj.add(content['urls'])
|
|
|
|
if not len(a_obj):
|
|
|
|
# No URLs were loaded
|
2021-11-06 22:21:41 +01:00
|
|
|
msg = _('No valid URLs were found.')
|
|
|
|
status = ResponseCode.bad_request
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
2020-01-06 00:19:09 +01:00
|
|
|
)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
|
|
|
if not ConfigCache.put(
|
|
|
|
key, '\r\n'.join([s.url() for s in a_obj]),
|
|
|
|
apprise.ConfigFormat.TEXT):
|
|
|
|
|
2021-11-06 22:21:41 +01:00
|
|
|
msg = _('The configuration could not be saved.')
|
|
|
|
status = ResponseCode.internal_server_error
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
2019-10-27 04:53:40 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
elif 'config' in content:
|
|
|
|
fmt = content.get('format', '').lower()
|
2020-09-02 23:42:17 +02:00
|
|
|
if fmt not in [i[0] for i in CONFIG_FORMATS]:
|
2019-10-27 04:53:40 +01:00
|
|
|
# Format must be one supported by apprise
|
2021-11-06 22:21:41 +01:00
|
|
|
msg = _('The format specified is invalid.')
|
|
|
|
status = ResponseCode.bad_request
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
2020-01-06 00:19:09 +01:00
|
|
|
)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
|
|
|
# prepare our apprise config object
|
|
|
|
ac_obj = apprise.AppriseConfig()
|
|
|
|
|
2020-09-02 23:42:17 +02:00
|
|
|
if fmt == AUTO_DETECT_CONFIG_KEYWORD:
|
|
|
|
# By setting format to None, it is automatically detected from
|
|
|
|
# within the add_config() call
|
|
|
|
fmt = None
|
|
|
|
|
|
|
|
# Load our configuration
|
|
|
|
if not ac_obj.add_config(content['config'], format=fmt):
|
|
|
|
# The format could not be detected
|
2021-11-06 22:21:41 +01:00
|
|
|
msg = _('The configuration format could not be detected.')
|
|
|
|
status = ResponseCode.bad_request
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
2020-01-06 00:19:09 +01:00
|
|
|
)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
2020-09-02 23:42:17 +02:00
|
|
|
# Add our configuration
|
|
|
|
a_obj.add(ac_obj)
|
|
|
|
|
|
|
|
if not len(a_obj):
|
|
|
|
# No specified URL(s) were loaded due to
|
|
|
|
# mis-configuration on the caller's part
|
2021-11-06 22:21:41 +01:00
|
|
|
msg = _('No valid URL(s) were specified.')
|
|
|
|
status = ResponseCode.bad_request
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
2020-09-02 23:42:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
if not ConfigCache.put(
|
|
|
|
key, content['config'], fmt=ac_obj[0].config_format):
|
2019-10-27 04:53:40 +01:00
|
|
|
# Something went very wrong; return 500
|
2021-11-06 22:21:41 +01:00
|
|
|
msg = _('An error occured saving configuration.')
|
|
|
|
status = ResponseCode.internal_server_error
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
2019-10-27 04:53:40 +01:00
|
|
|
)
|
2021-11-06 22:21:41 +01:00
|
|
|
|
2019-10-27 04:53:40 +01:00
|
|
|
else:
|
|
|
|
# No configuration specified; we're done
|
2021-11-06 22:21:41 +01:00
|
|
|
msg = _('No configuration specified.')
|
|
|
|
status = ResponseCode.bad_request
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
2023-05-20 01:12:03 +02:00
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
|
|
|
)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
|
|
|
# If we reach here; we successfully loaded the configuration so we can
|
|
|
|
# go ahead and write it to disk and alert our caller of the success.
|
|
|
|
return HttpResponse(
|
|
|
|
_('Successfully saved configuration.'),
|
2020-01-06 00:19:09 +01:00
|
|
|
status=ResponseCode.okay,
|
|
|
|
)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(never_cache, name='dispatch')
|
|
|
|
class DelView(View):
|
|
|
|
"""
|
|
|
|
A Django view for removing content associated with a key
|
|
|
|
"""
|
|
|
|
def post(self, request, key):
|
|
|
|
"""
|
|
|
|
Handle a POST request
|
|
|
|
"""
|
2021-11-06 22:21:41 +01:00
|
|
|
# Detect the format our response should be in
|
2023-02-26 16:33:14 +01:00
|
|
|
json_response = \
|
|
|
|
MIME_IS_JSON.match(
|
|
|
|
request.content_type
|
|
|
|
if request.content_type
|
|
|
|
else request.headers.get(
|
|
|
|
'accept', request.headers.get(
|
|
|
|
'content-type', ''))) is not None
|
2021-11-06 22:21:41 +01:00
|
|
|
|
|
|
|
if settings.APPRISE_CONFIG_LOCK:
|
|
|
|
# General Access Control
|
|
|
|
msg = _('The site has been configured to deny this request.')
|
|
|
|
status = ResponseCode.no_access
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
|
|
|
)
|
|
|
|
|
2019-10-27 04:53:40 +01:00
|
|
|
# Clear the key
|
|
|
|
result = ConfigCache.clear(key)
|
|
|
|
if result is None:
|
2021-11-06 22:21:41 +01:00
|
|
|
msg = _('There was no configuration to remove.')
|
|
|
|
status = ResponseCode.no_content
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
2019-10-27 04:53:40 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
elif result is False:
|
|
|
|
# There was a failure at the os level
|
2021-11-06 22:21:41 +01:00
|
|
|
msg = _('The configuration could not be removed.')
|
|
|
|
status = ResponseCode.internal_server_error
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
2019-10-27 04:53:40 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Removed content
|
|
|
|
return HttpResponse(
|
|
|
|
_('Successfully removed configuration.'),
|
|
|
|
status=ResponseCode.okay,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@method_decorator((gzip_page, never_cache), name='dispatch')
|
|
|
|
class GetView(View):
|
|
|
|
"""
|
|
|
|
A Django view used to retrieve previously stored Apprise configuration
|
|
|
|
"""
|
|
|
|
def post(self, request, key):
|
|
|
|
"""
|
|
|
|
Handle a POST request
|
|
|
|
"""
|
|
|
|
|
2020-09-02 23:42:17 +02:00
|
|
|
# Detect the format our response should be in
|
2023-02-26 16:33:14 +01:00
|
|
|
json_response = \
|
|
|
|
MIME_IS_JSON.match(
|
|
|
|
request.content_type
|
|
|
|
if request.content_type
|
|
|
|
else request.headers.get(
|
|
|
|
'accept', request.headers.get(
|
|
|
|
'content-type', ''))) is not None
|
2020-09-02 23:42:17 +02:00
|
|
|
|
2021-11-06 22:21:41 +01:00
|
|
|
if settings.APPRISE_CONFIG_LOCK:
|
|
|
|
# General Access Control
|
2024-01-14 04:11:34 +01:00
|
|
|
msg = _('The site has been configured to deny this request.')
|
|
|
|
status = ResponseCode.no_access
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse(
|
|
|
|
{'error': msg},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status)
|
2021-11-06 22:21:41 +01:00
|
|
|
|
2019-10-27 04:53:40 +01:00
|
|
|
config, format = ConfigCache.get(key)
|
|
|
|
if config is None:
|
|
|
|
# The returned value of config and format tell a rather cryptic
|
|
|
|
# story; this portion could probably be updated in the future.
|
|
|
|
# but for now it reads like this:
|
|
|
|
# config == None and format == None: We had an internal error
|
|
|
|
# config == None and format != None: we simply have no data
|
|
|
|
# config != None: we simply have no data
|
|
|
|
if format is not None:
|
|
|
|
# no content to return
|
2024-01-14 04:11:34 +01:00
|
|
|
msg = _('There was no configuration found.')
|
|
|
|
status = ResponseCode.no_content
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse(
|
|
|
|
{'error': msg},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
|
|
|
# Something went very wrong; return 500
|
2021-11-06 22:21:41 +01:00
|
|
|
msg = _('An error occured accessing configuration.')
|
|
|
|
status = ResponseCode.internal_server_error
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
2020-09-02 23:42:17 +02:00
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
2021-11-06 22:21:41 +01:00
|
|
|
status=status,
|
2019-10-27 04:53:40 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Our configuration was retrieved; now our response varies on whether
|
|
|
|
# we are a YAML configuration or a TEXT based one. This allows us to
|
|
|
|
# be compatible with those using the AppriseConfig() library or the
|
2020-01-06 00:19:09 +01:00
|
|
|
# reference to it through the --config (-c) option in the CLI.
|
|
|
|
content_type = 'text/yaml; charset=utf-8' \
|
|
|
|
if format == apprise.ConfigFormat.YAML \
|
|
|
|
else 'text/html; charset=utf-8'
|
2019-10-27 04:53:40 +01:00
|
|
|
|
|
|
|
# Return our retrieved content
|
|
|
|
return HttpResponse(
|
2020-01-06 00:19:09 +01:00
|
|
|
config,
|
|
|
|
content_type=content_type,
|
|
|
|
status=ResponseCode.okay,
|
2020-09-02 23:42:17 +02:00
|
|
|
) if not json_response else JsonResponse({
|
2023-05-20 01:12:03 +02:00
|
|
|
'format': format,
|
|
|
|
'config': config},
|
2020-09-02 23:42:17 +02:00
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=ResponseCode.okay,
|
2020-01-06 00:19:09 +01:00
|
|
|
)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
@method_decorator((gzip_page, never_cache), name='dispatch')
|
|
|
|
class NotifyView(View):
|
|
|
|
"""
|
2023-10-15 22:21:13 +02:00
|
|
|
A Django view for sending a notification in a stateful manner
|
2019-10-27 04:53:40 +01:00
|
|
|
"""
|
|
|
|
def post(self, request, key):
|
|
|
|
"""
|
|
|
|
Handle a POST request
|
|
|
|
"""
|
2021-11-06 22:21:41 +01:00
|
|
|
# Detect the format our response should be in
|
2023-02-26 16:33:14 +01:00
|
|
|
json_response = \
|
|
|
|
MIME_IS_JSON.match(
|
|
|
|
request.content_type
|
|
|
|
if request.content_type
|
|
|
|
else request.headers.get(
|
|
|
|
'accept', request.headers.get(
|
|
|
|
'content-type', ''))) is not None
|
2021-11-06 22:21:41 +01:00
|
|
|
|
2019-10-27 04:53:40 +01:00
|
|
|
# our content
|
|
|
|
content = {}
|
2019-10-28 00:41:02 +01:00
|
|
|
if MIME_IS_FORM.match(request.content_type):
|
2023-05-15 23:10:15 +02:00
|
|
|
form = NotifyForm(data=request.POST, files=request.FILES)
|
2019-10-27 04:53:40 +01:00
|
|
|
if form.is_valid():
|
2019-10-28 00:41:02 +01:00
|
|
|
content.update(form.cleaned_data)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
2021-11-06 22:21:41 +01:00
|
|
|
elif json_response:
|
2019-10-27 04:53:40 +01:00
|
|
|
# Prepare our default response
|
|
|
|
try:
|
|
|
|
# load our JSON content
|
2020-01-04 21:50:00 +01:00
|
|
|
content = json.loads(request.body.decode('utf-8'))
|
2019-10-27 04:53:40 +01:00
|
|
|
|
|
|
|
except (AttributeError, ValueError):
|
|
|
|
# could not parse JSON response...
|
2024-01-14 04:11:34 +01:00
|
|
|
logger.warning(
|
|
|
|
'NOTIFY - %s - Invalid JSON Payload provided',
|
|
|
|
request.META['REMOTE_ADDR'])
|
|
|
|
|
2021-11-06 22:21:41 +01:00
|
|
|
return JsonResponse(
|
2024-01-14 04:11:34 +01:00
|
|
|
_('Invalid JSON provided.'),
|
2021-11-06 22:21:41 +01:00
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
2019-10-27 04:53:40 +01:00
|
|
|
status=ResponseCode.bad_request)
|
|
|
|
|
|
|
|
if not content:
|
|
|
|
# We could not handle the Content-Type
|
2024-01-14 04:11:34 +01:00
|
|
|
logger.warning(
|
|
|
|
'NOTIFY - %s - Invalid FORM Payload provided',
|
|
|
|
request.META['REMOTE_ADDR'])
|
|
|
|
|
|
|
|
msg = _('Bad FORM Payload provided.')
|
2021-11-06 22:21:41 +01:00
|
|
|
status = ResponseCode.bad_request
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
2024-01-14 04:11:34 +01:00
|
|
|
status=status
|
2021-11-06 22:21:41 +01:00
|
|
|
)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
2023-05-15 23:10:15 +02:00
|
|
|
# Handle Attachments
|
|
|
|
attach = None
|
2024-02-18 03:39:11 +01:00
|
|
|
if not content.get('attachment'):
|
|
|
|
if 'attachment' in request.POST:
|
|
|
|
# Acquire attachments to work with them
|
|
|
|
content['attachment'] = request.POST.getlist('attachment')
|
|
|
|
|
|
|
|
elif 'attach' in request.POST:
|
|
|
|
# Acquire kw (alias) attach to work with them
|
|
|
|
content['attachment'] = request.POST.getlist('attach')
|
|
|
|
|
|
|
|
elif content.get('attach'):
|
|
|
|
# Acquire kw (alias) attach from payload to work with
|
|
|
|
content['attachment'] = content['attach']
|
|
|
|
del content['attach']
|
2024-01-14 19:27:14 +01:00
|
|
|
|
2023-10-15 22:21:13 +02:00
|
|
|
if 'attachment' in content or request.FILES:
|
|
|
|
try:
|
|
|
|
attach = parse_attachments(
|
|
|
|
content.get('attachment'), request.FILES)
|
|
|
|
|
2024-03-13 13:47:00 +01:00
|
|
|
except (TypeError, ValueError) as e:
|
2024-01-14 04:11:34 +01:00
|
|
|
# Invalid entry found in list
|
|
|
|
logger.warning(
|
2024-03-13 13:47:00 +01:00
|
|
|
'NOTIFY - %s - Bad attachment: %s',
|
|
|
|
request.META['REMOTE_ADDR'], str(e))
|
2024-01-14 04:11:34 +01:00
|
|
|
|
2023-10-15 22:21:13 +02:00
|
|
|
return HttpResponse(
|
|
|
|
_('Bad attachment'),
|
|
|
|
status=ResponseCode.bad_request)
|
2023-05-15 23:10:15 +02:00
|
|
|
|
2022-06-27 12:31:56 +02:00
|
|
|
#
|
|
|
|
# Allow 'tag' value to be specified as part of the URL parameters
|
|
|
|
# if not found otherwise defined.
|
|
|
|
#
|
2024-02-18 02:21:42 +01:00
|
|
|
tag = content.get('tag') if content.get('tag') else content.get('tags')
|
2024-01-14 04:11:34 +01:00
|
|
|
if not tag:
|
|
|
|
# Allow GET parameter over-rides
|
|
|
|
if 'tag' in request.GET:
|
|
|
|
tag = request.GET['tag']
|
|
|
|
|
|
|
|
elif 'tags' in request.GET:
|
|
|
|
tag = request.GET['tags']
|
|
|
|
|
|
|
|
# Validation - Tag Logic:
|
|
|
|
# "TagA" : TagA
|
|
|
|
# "TagA, TagB" : TagA OR TagB
|
|
|
|
# "TagA TagB" : TagA AND TagB
|
|
|
|
# "TagA TagC, TagB" : (TagA AND TagC) OR TagB
|
|
|
|
# ['TagA', 'TagB'] : TagA OR TagB
|
|
|
|
# [('TagA', 'TagC'), 'TagB'] : (TagA AND TagC) OR TagB
|
|
|
|
# [('TagB', 'TagC')] : TagB AND TagC
|
|
|
|
if tag:
|
2023-03-17 19:23:47 +01:00
|
|
|
if isinstance(tag, (list, set, tuple)):
|
|
|
|
# Assign our tags as they were provided
|
2024-01-14 04:11:34 +01:00
|
|
|
content['tag'] = tag
|
2023-03-17 19:23:47 +01:00
|
|
|
|
|
|
|
elif isinstance(tag, str):
|
2024-01-14 04:11:34 +01:00
|
|
|
if not TAG_VALIDATION_RE.match(tag):
|
|
|
|
# Invalid entry found in list
|
|
|
|
logger.warning(
|
|
|
|
'NOTIFY - %s - Ignored invalid tag specified '
|
|
|
|
'(type %s): %s', request.META['REMOTE_ADDR'],
|
|
|
|
str(type(tag)), str(tag)[:12])
|
|
|
|
|
2023-03-17 19:23:47 +01:00
|
|
|
msg = _('Unsupported characters found in tag definition.')
|
|
|
|
status = ResponseCode.bad_request
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
|
|
|
)
|
|
|
|
|
|
|
|
# If we get here, our specified tag was valid
|
|
|
|
tags = []
|
2024-01-14 04:11:34 +01:00
|
|
|
for _tag in TAG_DETECT_RE.findall(tag):
|
2023-03-17 19:23:47 +01:00
|
|
|
tag = _tag.strip()
|
|
|
|
if not tag:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Disect our results
|
|
|
|
group = TAG_AND_DELIM_RE.split(tag)
|
|
|
|
if len(group) > 1:
|
|
|
|
tags.append(tuple(group))
|
|
|
|
else:
|
|
|
|
tags.append(tag)
|
2023-02-26 17:01:23 +01:00
|
|
|
|
2024-01-14 04:11:34 +01:00
|
|
|
# Assign our tags
|
|
|
|
content['tag'] = tags
|
|
|
|
|
|
|
|
else: # Could be int, float or some other unsupported type
|
|
|
|
logger.warning(
|
|
|
|
'NOTIFY - %s - Ignored invalid tag specified (type %s): '
|
|
|
|
'%s', request.META['REMOTE_ADDR'],
|
|
|
|
str(type(tag)), str(tag)[:12])
|
2023-02-26 17:01:23 +01:00
|
|
|
|
2024-01-14 04:11:34 +01:00
|
|
|
msg = _('Unsupported characters found in tag definition.')
|
|
|
|
status = ResponseCode.bad_request
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
|
|
|
)
|
2022-06-27 12:31:56 +02:00
|
|
|
#
|
|
|
|
# Allow 'format' value to be specified as part of the URL
|
|
|
|
# parameters if not found otherwise defined.
|
|
|
|
#
|
|
|
|
if not content.get('format') and 'format' in request.GET:
|
|
|
|
content['format'] = request.GET['format']
|
|
|
|
|
|
|
|
#
|
|
|
|
# Allow 'type' value to be specified as part of the URL parameters
|
|
|
|
# if not found otherwise defined.
|
|
|
|
#
|
|
|
|
if not content.get('type') and 'type' in request.GET:
|
|
|
|
content['type'] = request.GET['type']
|
|
|
|
|
|
|
|
#
|
|
|
|
# Allow 'title' value to be specified as part of the URL parameters
|
|
|
|
# if not found otherwise defined.
|
|
|
|
#
|
|
|
|
if not content.get('title') and 'title' in request.GET:
|
|
|
|
content['title'] = request.GET['title']
|
|
|
|
|
2019-10-27 04:53:40 +01:00
|
|
|
# Some basic error checking
|
2023-12-23 20:35:10 +01:00
|
|
|
if not content.get('body') and not attach or \
|
2019-10-27 04:53:40 +01:00
|
|
|
content.get('type', apprise.NotifyType.INFO) \
|
|
|
|
not in apprise.NOTIFY_TYPES:
|
|
|
|
|
2024-01-14 04:11:34 +01:00
|
|
|
logger.warning(
|
|
|
|
'NOTIFY - %s - Payload lacks minimum requirements',
|
|
|
|
request.META['REMOTE_ADDR'])
|
|
|
|
|
2021-11-06 22:21:41 +01:00
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
2024-01-14 04:11:34 +01:00
|
|
|
'error': _('Payload lacks minimum requirements.'),
|
2021-11-06 22:21:41 +01:00
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
2024-01-14 04:11:34 +01:00
|
|
|
status=ResponseCode.bad_request,
|
2021-11-06 22:21:41 +01:00
|
|
|
)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
2020-12-31 19:00:23 +01:00
|
|
|
# Acquire our body format (if identified)
|
|
|
|
body_format = content.get('format', apprise.NotifyFormat.TEXT)
|
|
|
|
if body_format and body_format not in apprise.NOTIFY_FORMATS:
|
2024-01-14 04:11:34 +01:00
|
|
|
logger.warning(
|
|
|
|
'NOTIFY - %s - Format parameter contains an unsupported '
|
|
|
|
'value (%s)', request.META['REMOTE_ADDR'], str(body_format))
|
|
|
|
|
2021-11-06 22:21:41 +01:00
|
|
|
msg = _('An invalid body input format was specified.')
|
|
|
|
status = ResponseCode.bad_request
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
|
|
|
)
|
2020-12-31 19:00:23 +01:00
|
|
|
|
2019-10-27 04:53:40 +01:00
|
|
|
# If we get here, we have enough information to generate a notification
|
|
|
|
# with.
|
|
|
|
config, format = ConfigCache.get(key)
|
|
|
|
if config is None:
|
|
|
|
# The returned value of config and format tell a rather cryptic
|
|
|
|
# story; this portion could probably be updated in the future.
|
|
|
|
# but for now it reads like this:
|
|
|
|
# config == None and format == None: We had an internal error
|
|
|
|
# config == None and format != None: we simply have no data
|
|
|
|
# config != None: we simply have no data
|
|
|
|
if format is not None:
|
|
|
|
# no content to return
|
2024-01-14 04:11:34 +01:00
|
|
|
logger.debug(
|
|
|
|
'NOTIFY - %s - Empty configuration found using KEY: %s',
|
|
|
|
request.META['REMOTE_ADDR'], key)
|
2021-11-06 22:21:41 +01:00
|
|
|
msg = _('There was no configuration found.')
|
|
|
|
status = ResponseCode.no_content
|
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
2019-10-27 04:53:40 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Something went very wrong; return 500
|
2021-11-06 22:21:41 +01:00
|
|
|
msg = _('An error occured accessing configuration.')
|
|
|
|
status = ResponseCode.internal_server_error
|
2024-01-14 04:11:34 +01:00
|
|
|
logger.error(
|
|
|
|
'NOTIFY - %s - I/O error accessing configuration '
|
|
|
|
'using KEY: %s', request.META['REMOTE_ADDR'], key)
|
2021-11-06 22:21:41 +01:00
|
|
|
return HttpResponse(msg, status=status) \
|
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
2019-10-27 04:53:40 +01:00
|
|
|
)
|
|
|
|
|
2021-12-02 03:46:53 +01:00
|
|
|
# Prepare our keyword arguments (to be passed into an AppriseAsset
|
|
|
|
# object)
|
2023-05-16 00:27:42 +02:00
|
|
|
kwargs = {
|
|
|
|
'plugin_paths': settings.APPRISE_PLUGIN_PATHS,
|
|
|
|
}
|
2021-12-02 03:46:53 +01:00
|
|
|
|
|
|
|
if body_format:
|
|
|
|
# Store our defined body format
|
|
|
|
kwargs['body_format'] = body_format
|
|
|
|
|
|
|
|
# Acquire our recursion count (if defined)
|
2024-01-14 04:11:34 +01:00
|
|
|
recursion = request.headers.get('X-Apprise-Recursion-Count', 0)
|
2021-12-02 03:46:53 +01:00
|
|
|
try:
|
2024-01-14 04:11:34 +01:00
|
|
|
recursion = int(recursion)
|
2021-12-02 03:46:53 +01:00
|
|
|
|
|
|
|
if recursion < 0:
|
|
|
|
# We do not accept negative numbers
|
|
|
|
raise TypeError("Invalid Recursion Value")
|
|
|
|
|
|
|
|
if recursion > settings.APPRISE_RECURSION_MAX:
|
2024-01-14 04:11:34 +01:00
|
|
|
logger.warning(
|
|
|
|
'NOTIFY - %s - Recursion limit reached (%d > %d)',
|
|
|
|
request.META['REMOTE_ADDR'], recursion,
|
|
|
|
settings.APPRISE_RECURSION_MAX)
|
2021-12-02 03:46:53 +01:00
|
|
|
return HttpResponse(
|
|
|
|
_('The recursion limit has been reached.'),
|
|
|
|
status=ResponseCode.method_not_accepted)
|
|
|
|
|
|
|
|
# Store our recursion value for our AppriseAsset() initialization
|
|
|
|
kwargs['_recursion'] = recursion
|
|
|
|
|
|
|
|
except (TypeError, ValueError):
|
2024-01-14 04:11:34 +01:00
|
|
|
logger.warning(
|
|
|
|
'NOTIFY - %s - Invalid recursion value (%s) provided',
|
|
|
|
request.META['REMOTE_ADDR'], str(recursion))
|
2021-12-02 03:46:53 +01:00
|
|
|
return HttpResponse(
|
|
|
|
_('An invalid recursion value was specified.'),
|
|
|
|
status=ResponseCode.bad_request)
|
|
|
|
|
|
|
|
# Acquire our unique identifier (if defined)
|
|
|
|
uid = request.headers.get('X-Apprise-ID', '').strip()
|
|
|
|
if uid:
|
|
|
|
kwargs['_uid'] = uid
|
|
|
|
|
2023-05-16 00:27:42 +02:00
|
|
|
#
|
|
|
|
# Apply Any Global Filters (if identified)
|
|
|
|
#
|
|
|
|
apply_global_filters()
|
|
|
|
|
2020-12-31 16:27:11 +01:00
|
|
|
# Prepare ourselves a default Asset
|
2023-05-16 00:27:42 +02:00
|
|
|
asset = apprise.AppriseAsset(**kwargs)
|
2020-12-31 16:27:11 +01:00
|
|
|
|
2019-10-27 04:53:40 +01:00
|
|
|
# Prepare our apprise object
|
2020-12-31 16:27:11 +01:00
|
|
|
a_obj = apprise.Apprise(asset=asset)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
|
|
|
# Create an apprise config object
|
|
|
|
ac_obj = apprise.AppriseConfig()
|
|
|
|
|
2020-09-02 23:42:17 +02:00
|
|
|
# Load our configuration
|
|
|
|
ac_obj.add_config(config, format=format)
|
|
|
|
|
|
|
|
# Add our configuration
|
|
|
|
a_obj.add(ac_obj)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
2021-01-01 23:10:44 +01:00
|
|
|
# Our return content type can be controlled by the Accept keyword
|
|
|
|
# If it includes /* or /html somewhere then we return html, otherwise
|
|
|
|
# we return the logs as they're processed in their text format.
|
|
|
|
# The HTML response type has a bit of overhead where as it's not
|
|
|
|
# the case with text/plain
|
|
|
|
content_type = \
|
|
|
|
'text/html' if re.search(r'text\/(\*|html)',
|
|
|
|
request.headers.get('Accept', ''),
|
|
|
|
re.IGNORECASE) \
|
|
|
|
else 'text/plain'
|
|
|
|
|
|
|
|
# Acquire our log level from headers if defined, otherwise use
|
|
|
|
# the global one set in the settings
|
|
|
|
level = request.headers.get(
|
|
|
|
'X-Apprise-Log-Level',
|
|
|
|
settings.LOGGING['loggers']['apprise']['level']).upper()
|
2023-10-15 22:21:13 +02:00
|
|
|
if level not in (
|
|
|
|
'CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'TRACE'):
|
|
|
|
level = settings.LOGGING['loggers']['apprise']['level'].upper()
|
2021-01-01 23:10:44 +01:00
|
|
|
|
2023-10-15 22:21:13 +02:00
|
|
|
# Convert level to it's integer value
|
|
|
|
if level == 'CRITICAL':
|
|
|
|
level = logging.CRITICAL
|
2021-01-01 23:10:44 +01:00
|
|
|
|
2023-10-15 22:21:13 +02:00
|
|
|
elif level == 'ERROR':
|
|
|
|
level = logging.ERROR
|
2021-01-01 23:10:44 +01:00
|
|
|
|
2023-10-15 22:21:13 +02:00
|
|
|
elif level == 'WARNING':
|
|
|
|
level = logging.WARNING
|
2021-01-01 23:10:44 +01:00
|
|
|
|
2023-10-15 22:21:13 +02:00
|
|
|
elif level == 'INFO':
|
|
|
|
level = logging.INFO
|
2021-01-01 23:10:44 +01:00
|
|
|
|
2023-10-15 22:21:13 +02:00
|
|
|
elif level == 'DEBUG':
|
|
|
|
level = logging.DEBUG
|
2021-01-01 23:10:44 +01:00
|
|
|
|
2023-10-15 22:21:13 +02:00
|
|
|
elif level == 'TRACE':
|
|
|
|
level = logging.DEBUG - 1
|
|
|
|
|
|
|
|
# Initialize our response object
|
|
|
|
response = None
|
|
|
|
|
|
|
|
esc = '<!!-!ESC!-!!>'
|
|
|
|
|
|
|
|
# Format is only updated if the content_type is html
|
|
|
|
fmt = '<li class="log_%(levelname)s">' \
|
|
|
|
'<div class="log_time">%(asctime)s</div>' \
|
|
|
|
'<div class="log_level">%(levelname)s</div>' \
|
|
|
|
f'<div class="log_msg">{esc}%(message)s{esc}</div></li>' \
|
|
|
|
if content_type == 'text/html' else \
|
|
|
|
settings.LOGGING['formatters']['standard']['format']
|
|
|
|
|
|
|
|
# Now specify our format (and over-ride the default):
|
|
|
|
with apprise.LogCapture(level=level, fmt=fmt) as logs:
|
|
|
|
# Perform our notification at this point
|
2021-01-01 23:10:44 +01:00
|
|
|
result = a_obj.notify(
|
|
|
|
content.get('body'),
|
|
|
|
title=content.get('title', ''),
|
|
|
|
notify_type=content.get('type', apprise.NotifyType.INFO),
|
|
|
|
tag=content.get('tag'),
|
2023-05-15 23:10:15 +02:00
|
|
|
attach=attach,
|
2021-01-01 23:10:44 +01:00
|
|
|
)
|
2020-03-17 17:08:06 +01:00
|
|
|
|
2023-10-15 22:21:13 +02:00
|
|
|
if content_type == 'text/html':
|
|
|
|
# Iterate over our entries so that we can prepare to escape
|
|
|
|
# things to be presented as HTML
|
|
|
|
esc = re.escape(esc)
|
|
|
|
entries = re.findall(
|
|
|
|
r'(?P<head><li .+?){}(?P<to_escape>.*?)'
|
|
|
|
r'{}(?P<tail>.+li>$)(?=$|<li .+{})'.format(
|
|
|
|
esc, esc, esc), logs.getvalue(),
|
|
|
|
re.DOTALL)
|
|
|
|
|
|
|
|
# Wrap logs in `<ul>` tag and escape our message body:
|
|
|
|
response = '<ul class="logs">{}</ul>'.format(
|
|
|
|
''.join([e[0] + escape(e[1]) + e[2] for e in entries]))
|
|
|
|
|
|
|
|
else: # content_type == 'text/plain'
|
|
|
|
response = logs.getvalue()
|
|
|
|
|
|
|
|
if settings.APPRISE_WEBHOOK_URL:
|
|
|
|
webhook_payload = {
|
|
|
|
'source': request.META['REMOTE_ADDR'],
|
|
|
|
'status': 0 if result else 1,
|
|
|
|
'output': response,
|
|
|
|
}
|
|
|
|
|
|
|
|
# Send our webhook (pass or fail)
|
|
|
|
send_webhook(webhook_payload)
|
|
|
|
|
2020-09-02 23:42:17 +02:00
|
|
|
if not result:
|
|
|
|
# If at least one notification couldn't be sent; change up
|
|
|
|
# the response to a 424 error code
|
2021-11-06 22:21:41 +01:00
|
|
|
msg = _('One or more notification could not be sent.')
|
|
|
|
status = ResponseCode.failed_dependency
|
2024-01-14 04:11:34 +01:00
|
|
|
logger.warning(
|
|
|
|
'NOTIFY - %s - One or more notifications not '
|
|
|
|
'sent%s using KEY: %s', request.META['REMOTE_ADDR'],
|
|
|
|
'' if not tag else f' (Tags: {tag})', key)
|
2021-12-02 03:28:02 +01:00
|
|
|
return HttpResponse(response if response else msg, status=status) \
|
2021-11-06 22:21:41 +01:00
|
|
|
if not json_response else JsonResponse({
|
|
|
|
'error': msg,
|
|
|
|
},
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=status,
|
|
|
|
)
|
2019-10-27 04:53:40 +01:00
|
|
|
|
2024-01-14 04:11:34 +01:00
|
|
|
logger.info(
|
2024-01-14 19:27:14 +01:00
|
|
|
'NOTIFY - %s - Delivered Notification(s) - %sKEY: %s',
|
|
|
|
request.META['REMOTE_ADDR'],
|
|
|
|
'' if not tag else f'Tags: {tag}, ', key)
|
2024-01-14 04:11:34 +01:00
|
|
|
|
2019-10-27 04:53:40 +01:00
|
|
|
# Return our retrieved content
|
|
|
|
return HttpResponse(
|
2021-01-01 23:10:44 +01:00
|
|
|
response if response is not None else
|
2019-10-27 04:53:40 +01:00
|
|
|
_('Notification(s) sent.'),
|
2021-01-01 23:10:44 +01:00
|
|
|
content_type=content_type,
|
|
|
|
status=ResponseCode.okay,
|
2020-01-06 00:19:09 +01:00
|
|
|
)
|
2019-10-29 02:54:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
@method_decorator((gzip_page, never_cache), name='dispatch')
|
|
|
|
class StatelessNotifyView(View):
|
|
|
|
"""
|
|
|
|
A Django view for sending a stateless notification
|
|
|
|
"""
|
|
|
|
def post(self, request):
|
|
|
|
"""
|
|
|
|
Handle a POST request
|
|
|
|
"""
|
|
|
|
# our content
|
|
|
|
content = {}
|
|
|
|
if MIME_IS_FORM.match(request.content_type):
|
|
|
|
content = {}
|
2023-05-15 23:10:15 +02:00
|
|
|
form = NotifyByUrlForm(request.POST, request.FILES)
|
2019-10-29 02:54:51 +01:00
|
|
|
if form.is_valid():
|
|
|
|
content.update(form.cleaned_data)
|
|
|
|
|
|
|
|
elif MIME_IS_JSON.match(request.content_type):
|
|
|
|
# Prepare our default response
|
|
|
|
try:
|
|
|
|
# load our JSON content
|
2020-01-04 21:50:00 +01:00
|
|
|
content = json.loads(request.body.decode('utf-8'))
|
2019-10-29 02:54:51 +01:00
|
|
|
|
|
|
|
except (AttributeError, ValueError):
|
|
|
|
# could not parse JSON response...
|
2024-01-14 19:27:14 +01:00
|
|
|
logger.warning(
|
|
|
|
'NOTIFY - %s - Invalid JSON Payload provided',
|
|
|
|
request.META['REMOTE_ADDR'])
|
|
|
|
|
2019-10-29 02:54:51 +01:00
|
|
|
return HttpResponse(
|
|
|
|
_('Invalid JSON specified.'),
|
|
|
|
status=ResponseCode.bad_request)
|
|
|
|
|
|
|
|
if not content:
|
|
|
|
# We could not handle the Content-Type
|
2024-01-14 19:27:14 +01:00
|
|
|
logger.warning(
|
|
|
|
'NOTIFY - %s - Invalid FORM Payload provided',
|
|
|
|
request.META['REMOTE_ADDR'])
|
2024-02-18 03:39:11 +01:00
|
|
|
|
2019-10-29 02:54:51 +01:00
|
|
|
return HttpResponse(
|
2024-01-14 19:27:14 +01:00
|
|
|
_('Bad FORM Payload provided.'),
|
2019-10-29 02:54:51 +01:00
|
|
|
status=ResponseCode.bad_request)
|
|
|
|
|
|
|
|
if not content.get('urls') and settings.APPRISE_STATELESS_URLS:
|
|
|
|
# fallback to settings.APPRISE_STATELESS_URLS if no urls were
|
|
|
|
# defined
|
|
|
|
content['urls'] = settings.APPRISE_STATELESS_URLS
|
|
|
|
|
2024-01-27 20:05:07 +01:00
|
|
|
#
|
|
|
|
# Allow 'format' value to be specified as part of the URL
|
|
|
|
# parameters if not found otherwise defined.
|
|
|
|
#
|
|
|
|
if not content.get('format') and 'format' in request.GET:
|
|
|
|
content['format'] = request.GET['format']
|
|
|
|
|
|
|
|
#
|
|
|
|
# Allow 'type' value to be specified as part of the URL parameters
|
|
|
|
# if not found otherwise defined.
|
|
|
|
#
|
|
|
|
if not content.get('type') and 'type' in request.GET:
|
|
|
|
content['type'] = request.GET['type']
|
|
|
|
|
|
|
|
#
|
|
|
|
# Allow 'title' value to be specified as part of the URL parameters
|
|
|
|
# if not found otherwise defined.
|
|
|
|
#
|
|
|
|
if not content.get('title') and 'title' in request.GET:
|
|
|
|
content['title'] = request.GET['title']
|
|
|
|
|
2019-10-29 02:54:51 +01:00
|
|
|
# Some basic error checking
|
|
|
|
if not content.get('body') or \
|
|
|
|
content.get('type', apprise.NotifyType.INFO) \
|
|
|
|
not in apprise.NOTIFY_TYPES:
|
|
|
|
|
2024-01-14 19:27:14 +01:00
|
|
|
logger.warning(
|
|
|
|
'NOTIFY - %s - Payload lacks minimum requirements',
|
|
|
|
request.META['REMOTE_ADDR'])
|
|
|
|
|
2019-10-29 02:54:51 +01:00
|
|
|
return HttpResponse(
|
2024-01-14 19:27:14 +01:00
|
|
|
_('Payload lacks minimum requirements.'),
|
2019-10-29 02:54:51 +01:00
|
|
|
status=ResponseCode.bad_request)
|
|
|
|
|
2020-12-31 19:00:23 +01:00
|
|
|
# Acquire our body format (if identified)
|
|
|
|
body_format = content.get('format', apprise.NotifyFormat.TEXT)
|
|
|
|
if body_format and body_format not in apprise.NOTIFY_FORMATS:
|
2024-01-14 19:27:14 +01:00
|
|
|
logger.warning(
|
|
|
|
'NOTIFY - %s - Format parameter contains an unsupported '
|
|
|
|
'value (%s)', request.META['REMOTE_ADDR'], str(body_format))
|
2020-12-31 19:00:23 +01:00
|
|
|
return HttpResponse(
|
2024-01-14 19:27:14 +01:00
|
|
|
_('An invalid body input format was specified.'),
|
2020-12-31 19:00:23 +01:00
|
|
|
status=ResponseCode.bad_request)
|
|
|
|
|
2021-12-02 03:46:53 +01:00
|
|
|
# Prepare our keyword arguments (to be passed into an AppriseAsset
|
|
|
|
# object)
|
2023-05-16 00:27:42 +02:00
|
|
|
kwargs = {
|
|
|
|
'plugin_paths': settings.APPRISE_PLUGIN_PATHS,
|
|
|
|
}
|
2021-12-02 03:46:53 +01:00
|
|
|
|
|
|
|
if body_format:
|
|
|
|
# Store our defined body format
|
|
|
|
kwargs['body_format'] = body_format
|
|
|
|
|
|
|
|
# Acquire our recursion count (if defined)
|
2024-01-14 19:27:14 +01:00
|
|
|
recursion = request.headers.get('X-Apprise-Recursion-Count', 0)
|
2021-12-02 03:46:53 +01:00
|
|
|
try:
|
2024-01-14 19:27:14 +01:00
|
|
|
recursion = int(recursion)
|
2021-12-02 03:46:53 +01:00
|
|
|
|
|
|
|
if recursion < 0:
|
|
|
|
# We do not accept negative numbers
|
|
|
|
raise TypeError("Invalid Recursion Value")
|
|
|
|
|
|
|
|
if recursion > settings.APPRISE_RECURSION_MAX:
|
2024-01-14 19:27:14 +01:00
|
|
|
logger.warning(
|
|
|
|
'NOTIFY - %s - Recursion limit reached (%d > %d)',
|
|
|
|
request.META['REMOTE_ADDR'], recursion,
|
|
|
|
settings.APPRISE_RECURSION_MAX)
|
2021-12-02 03:46:53 +01:00
|
|
|
return HttpResponse(
|
|
|
|
_('The recursion limit has been reached.'),
|
|
|
|
status=ResponseCode.method_not_accepted)
|
|
|
|
|
|
|
|
# Store our recursion value for our AppriseAsset() initialization
|
|
|
|
kwargs['_recursion'] = recursion
|
|
|
|
|
|
|
|
except (TypeError, ValueError):
|
2024-01-14 19:27:14 +01:00
|
|
|
logger.warning(
|
|
|
|
'NOTIFY - %s - Invalid recursion value (%s) provided',
|
|
|
|
request.META['REMOTE_ADDR'], str(recursion))
|
2021-12-02 03:46:53 +01:00
|
|
|
return HttpResponse(
|
|
|
|
_('An invalid recursion value was specified.'),
|
|
|
|
status=ResponseCode.bad_request)
|
|
|
|
|
|
|
|
# Acquire our unique identifier (if defined)
|
|
|
|
uid = request.headers.get('X-Apprise-ID', '').strip()
|
|
|
|
if uid:
|
|
|
|
kwargs['_uid'] = uid
|
|
|
|
|
2021-12-02 03:28:02 +01:00
|
|
|
#
|
|
|
|
# Apply Any Global Filters (if identified)
|
|
|
|
#
|
2023-02-26 16:33:14 +01:00
|
|
|
apply_global_filters()
|
2021-12-02 03:28:02 +01:00
|
|
|
|
2023-05-16 00:27:42 +02:00
|
|
|
# Prepare ourselves a default Asset
|
|
|
|
asset = apprise.AppriseAsset(**kwargs)
|
|
|
|
|
2019-10-29 02:54:51 +01:00
|
|
|
# Prepare our apprise object
|
2020-12-31 16:27:11 +01:00
|
|
|
a_obj = apprise.Apprise(asset=asset)
|
2019-10-29 02:54:51 +01:00
|
|
|
|
|
|
|
# Add URLs
|
|
|
|
a_obj.add(content.get('urls'))
|
|
|
|
if not len(a_obj):
|
|
|
|
return HttpResponse(
|
|
|
|
_('There was no services to notify.'),
|
|
|
|
status=ResponseCode.no_content,
|
|
|
|
)
|
|
|
|
|
2023-05-15 23:10:15 +02:00
|
|
|
# Handle Attachments
|
|
|
|
attach = None
|
2024-02-18 03:39:11 +01:00
|
|
|
if not content.get('attachment'):
|
|
|
|
if 'attachment' in request.POST:
|
|
|
|
# Acquire attachments to work with them
|
|
|
|
content['attachment'] = request.POST.getlist('attachment')
|
|
|
|
|
|
|
|
elif 'attach' in request.POST:
|
|
|
|
# Acquire kw (alias) attach to work with them
|
|
|
|
content['attachment'] = request.POST.getlist('attach')
|
|
|
|
|
|
|
|
elif content.get('attach'):
|
|
|
|
# Acquire kw (alias) attach from payload to work with
|
|
|
|
content['attachment'] = content['attach']
|
|
|
|
del content['attach']
|
2024-01-14 19:27:14 +01:00
|
|
|
|
2023-10-15 22:21:13 +02:00
|
|
|
if 'attachment' in content or request.FILES:
|
|
|
|
try:
|
|
|
|
attach = parse_attachments(
|
|
|
|
content.get('attachment'), request.FILES)
|
|
|
|
|
2024-03-13 13:47:00 +01:00
|
|
|
except (TypeError, ValueError) as e:
|
2024-02-18 03:39:11 +01:00
|
|
|
# Invalid entry found in list
|
|
|
|
logger.warning(
|
2024-03-13 13:47:00 +01:00
|
|
|
'NOTIFY - %s - Bad attachment: %s',
|
|
|
|
request.META['REMOTE_ADDR'], str(e))
|
2024-02-18 03:39:11 +01:00
|
|
|
|
2023-10-15 22:21:13 +02:00
|
|
|
return HttpResponse(
|
|
|
|
_('Bad attachment'),
|
|
|
|
status=ResponseCode.bad_request)
|
|
|
|
|
|
|
|
# Acquire our log level from headers if defined, otherwise use
|
|
|
|
# the global one set in the settings
|
|
|
|
level = request.headers.get(
|
|
|
|
'X-Apprise-Log-Level',
|
|
|
|
settings.LOGGING['loggers']['apprise']['level']).upper()
|
|
|
|
if level not in (
|
|
|
|
'CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'TRACE'):
|
|
|
|
level = settings.LOGGING['loggers']['apprise']['level'].upper()
|
|
|
|
|
|
|
|
# Convert level to it's integer value
|
|
|
|
if level == 'CRITICAL':
|
|
|
|
level = logging.CRITICAL
|
|
|
|
|
|
|
|
elif level == 'ERROR':
|
|
|
|
level = logging.ERROR
|
|
|
|
|
|
|
|
elif level == 'WARNING':
|
|
|
|
level = logging.WARNING
|
|
|
|
|
|
|
|
elif level == 'INFO':
|
|
|
|
level = logging.INFO
|
|
|
|
|
|
|
|
elif level == 'DEBUG':
|
|
|
|
level = logging.DEBUG
|
|
|
|
|
|
|
|
elif level == 'TRACE':
|
|
|
|
level = logging.DEBUG - 1
|
|
|
|
|
|
|
|
if settings.APPRISE_WEBHOOK_URL:
|
|
|
|
fmt = settings.LOGGING['formatters']['standard']['format']
|
|
|
|
with apprise.LogCapture(level=level, fmt=fmt) as logs:
|
|
|
|
# Perform our notification at this point
|
|
|
|
result = a_obj.notify(
|
|
|
|
content.get('body'),
|
|
|
|
title=content.get('title', ''),
|
|
|
|
notify_type=content.get('type', apprise.NotifyType.INFO),
|
|
|
|
tag='all',
|
|
|
|
attach=attach,
|
|
|
|
)
|
|
|
|
|
|
|
|
response = logs.getvalue()
|
|
|
|
|
|
|
|
webhook_payload = {
|
|
|
|
'source': request.META['REMOTE_ADDR'],
|
|
|
|
'status': 0 if result else 1,
|
|
|
|
'output': response,
|
|
|
|
}
|
|
|
|
|
|
|
|
# Send our webhook (pass or fail)
|
|
|
|
send_webhook(webhook_payload)
|
|
|
|
|
|
|
|
else:
|
|
|
|
# Perform our notification at this point
|
|
|
|
result = a_obj.notify(
|
|
|
|
content.get('body'),
|
|
|
|
title=content.get('title', ''),
|
|
|
|
notify_type=content.get('type', apprise.NotifyType.INFO),
|
|
|
|
tag='all',
|
|
|
|
attach=attach,
|
|
|
|
)
|
2019-10-29 02:54:51 +01:00
|
|
|
|
2020-03-17 17:08:06 +01:00
|
|
|
if not result:
|
|
|
|
# If at least one notification couldn't be sent; change up the
|
|
|
|
# response to a 424 error code
|
|
|
|
return HttpResponse(
|
|
|
|
_('One or more notification could not be sent.'),
|
|
|
|
status=ResponseCode.failed_dependency)
|
|
|
|
|
2024-01-14 19:27:14 +01:00
|
|
|
logger.info(
|
|
|
|
'NOTIFY - %s - Delivered Stateless Notification(s)',
|
|
|
|
request.META['REMOTE_ADDR'])
|
|
|
|
|
2019-10-29 02:54:51 +01:00
|
|
|
# Return our retrieved content
|
|
|
|
return HttpResponse(
|
|
|
|
_('Notification(s) sent.'),
|
2020-01-06 00:19:09 +01:00
|
|
|
status=ResponseCode.okay,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@method_decorator((gzip_page, never_cache), name='dispatch')
|
|
|
|
class JsonUrlView(View):
|
|
|
|
"""
|
|
|
|
A Django view that lists all loaded tags and URLs for a given key
|
|
|
|
"""
|
|
|
|
def get(self, request, key):
|
|
|
|
"""
|
|
|
|
Handle a POST request
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Now build our tag response that identifies all of the tags
|
|
|
|
# and the URL's they're associated with
|
|
|
|
# {
|
|
|
|
# "tags": ["tag1', "tag2", "tag3"],
|
|
|
|
# "urls": [
|
|
|
|
# {
|
|
|
|
# "url": "windows://",
|
|
|
|
# "tags": [],
|
|
|
|
# },
|
|
|
|
# {
|
|
|
|
# "url": "mailto://user:pass@gmail.com"
|
|
|
|
# "tags": ["tag1", "tag2", "tag3"]
|
|
|
|
# }
|
|
|
|
# ]
|
|
|
|
# }
|
|
|
|
response = {
|
|
|
|
'tags': set(),
|
|
|
|
'urls': [],
|
|
|
|
}
|
|
|
|
|
2020-01-19 02:26:40 +01:00
|
|
|
# Privacy flag
|
2021-01-01 23:32:33 +01:00
|
|
|
# Support 'yes', '1', 'true', 'enable', 'active', and +
|
2021-11-06 22:21:41 +01:00
|
|
|
privacy = settings.APPRISE_CONFIG_LOCK or \
|
2023-02-26 16:33:14 +01:00
|
|
|
request.GET.get('privacy', 'no')[0].lower() in (
|
2021-11-06 22:21:41 +01:00
|
|
|
'a', 'y', '1', 't', 'e', '+')
|
2021-01-01 23:32:33 +01:00
|
|
|
|
|
|
|
# Optionally filter on tags. Use comma to identify more then one
|
|
|
|
tag = request.GET.get('tag', 'all')
|
2020-01-19 02:26:40 +01:00
|
|
|
|
2020-01-06 00:19:09 +01:00
|
|
|
config, format = ConfigCache.get(key)
|
|
|
|
if config is None:
|
|
|
|
# The returned value of config and format tell a rather cryptic
|
|
|
|
# story; this portion could probably be updated in the future.
|
|
|
|
# but for now it reads like this:
|
|
|
|
# config == None and format == None: We had an internal error
|
|
|
|
# config == None and format != None: we simply have no data
|
|
|
|
# config != None: we simply have no data
|
|
|
|
if format is not None:
|
|
|
|
# no content to return
|
|
|
|
return JsonResponse(
|
|
|
|
response,
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=ResponseCode.no_content,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Something went very wrong; return 500
|
|
|
|
response['error'] = _('There was no configuration found.')
|
|
|
|
return JsonResponse(
|
|
|
|
response,
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=ResponseCode.internal_server_error,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Prepare our apprise object
|
|
|
|
a_obj = apprise.Apprise()
|
|
|
|
|
|
|
|
# Create an apprise config object
|
|
|
|
ac_obj = apprise.AppriseConfig()
|
|
|
|
|
2020-09-02 23:42:17 +02:00
|
|
|
# Load our configuration
|
|
|
|
ac_obj.add_config(config, format=format)
|
|
|
|
|
|
|
|
# Add our configuration
|
|
|
|
a_obj.add(ac_obj)
|
|
|
|
|
2021-01-01 23:32:33 +01:00
|
|
|
for notification in a_obj.find(tag):
|
2020-09-02 23:42:17 +02:00
|
|
|
# Set Notification
|
|
|
|
response['urls'].append({
|
|
|
|
'url': notification.url(privacy=privacy),
|
|
|
|
'tags': notification.tags,
|
|
|
|
})
|
|
|
|
|
|
|
|
# Store Tags
|
|
|
|
response['tags'] |= notification.tags
|
2020-01-06 00:19:09 +01:00
|
|
|
|
|
|
|
# Return our retrieved content
|
|
|
|
return JsonResponse(
|
|
|
|
response,
|
|
|
|
encoder=JSONEncoder,
|
|
|
|
safe=False,
|
|
|
|
status=ResponseCode.okay
|
|
|
|
)
|