mirror of
https://github.com/caronc/apprise-api.git
synced 2024-12-13 10:21:14 +01:00
BASE_URL environment variable added (#26)
This commit is contained in:
parent
466aa8271e
commit
907743fb8c
@ -153,6 +153,7 @@ The use of environment variables allow you to provide over-rides to default sett
|
||||
| `APPRISE_STATEFUL_MODE` | This can be set to the following possible modes:<br/>📌 **hash**: This is also the default. It stores the server configuration in a hash formatted that can be easily indexed and compressed.<br/>📌 **simple**: Configuration is written straight to disk using the `{KEY}.cfg` (if `TEXT` based) and `{KEY}.yml` (if `YAML` based).<br/>📌 **disabled**: Straight up deny any read/write queries to the servers stateful store. Effectively turn off the Apprise Stateful feature completely.
|
||||
| `SECRET_KEY` | A Django variable acting as a *salt* for most things that require security. This API uses it for the hash sequences when writing the configuration files to disk (`hash` mode only).
|
||||
| `ALLOWED_HOSTS` | A list of strings representing the host/domain names that this API can serve. This is a security measure to prevent HTTP Host header attacks, which are possible even under many seemingly-safe web server configurations. By default this is set to `*` allowing any host. Use space to delimit more than one host.
|
||||
| `BASE_URL` | Those who are hosting the API behind a proxy that requires a subpath to gain access to this API should specify this path here as well. By default this is not set at all.
|
||||
| `DEBUG` | This defaults to `False` however can be set to `True` if defined with a non-zero value (such as `1`).
|
||||
|
||||
|
||||
|
32
apprise_api/api/context_processors.py
Normal file
32
apprise_api/api/context_processors.py
Normal file
@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2020 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 .utils import ConfigCache
|
||||
|
||||
|
||||
def stateful_mode(request):
|
||||
"""
|
||||
Returns our loaded Stateful Mode
|
||||
"""
|
||||
return {'STATEFUL_MODE': ConfigCache.mode}
|
@ -40,10 +40,12 @@
|
||||
<div class="row">
|
||||
|
||||
<div class="col s3">
|
||||
{% if STATEFUL_MODE != 'disabled' %}
|
||||
<ul class="collection z-depth-1">
|
||||
<a class="collection-item" href="{% url 'config' 'apprise' %}"><i class="tiny material-icons">settings</i>
|
||||
{% trans "Configuration Manager" %}</a>
|
||||
</ul>
|
||||
{% endif %}
|
||||
<ul class="collection z-depth-1">
|
||||
<a class="collection-item" target="_blank"
|
||||
href="https://github.com/caronc/apprise/wiki#notification-services">📣
|
||||
|
@ -1,6 +1,7 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
{% block body %}
|
||||
{% if STATEFUL_MODE != 'disabled' %}
|
||||
<h4>{% trans "Management for:" %} <em>{{ key }}</em></h4>
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
@ -35,7 +36,7 @@
|
||||
In the future you can return to this configuration screen at any time by placing the following into your
|
||||
browser:
|
||||
{% endblocktrans %}
|
||||
<code>{{request.scheme}}://{{request.META.HTTP_HOST}}{{request.path}}</code>
|
||||
<code>{{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/config/{{key}}</code>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
@ -56,7 +57,7 @@
|
||||
send a test notification to all of your added services:{% endblocktrans %}
|
||||
<br />
|
||||
<pre><code class="bash">apprise --body="Test Message" --tag=all \<br/>
|
||||
--config={{request.scheme}}://{{request.META.HTTP_HOST}}{% url "get" key %}</code></pre>
|
||||
--config={{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/get/{{key}}</code></pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h5>{% trans "Loaded Configuration" %}</h5>
|
||||
@ -92,6 +93,12 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="section">
|
||||
<h4>{% trans "Persistent Store Endpoints" %}</h4>
|
||||
<p>{% blocktrans %}The administrator of this system has disabled persistent storage.{% endblocktrans %}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block jsfooter %}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block body %}
|
||||
<h4>{% trans "The Apprise API" %}</h4>
|
||||
<p>
|
||||
@ -31,7 +32,7 @@
|
||||
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>/notify/</code></td>
|
||||
<td><code>{{BASE_URL}}/notify/</code></td>
|
||||
<td>
|
||||
{% blocktrans %}Used to notify one one or more specified Apprise URLs. See the <a target="_blank"
|
||||
href="https://github.com/caronc/apprise/wiki#notification-services">Apprise Wiki</a> if you need help
|
||||
@ -88,7 +89,7 @@
|
||||
# {% blocktrans %}Notifies an email address{% endblocktrans %}<br/>
|
||||
curl -X POST -d '{"urls":"mailto://user:pass@gmail.com","body":"test body","title":"test title"}' \<br/>
|
||||
-H "Content-Type: application/json" \<br/>
|
||||
http://localhost:8000/notify/</code></pre>
|
||||
{{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/notify/</code></pre>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
@ -105,7 +106,7 @@
|
||||
}<br/>
|
||||
<br/># The URL<br/>
|
||||
req = Request(<br/>
|
||||
"http://localhost:8000/notify/",<br/>
|
||||
"{{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/notify/",<br/>
|
||||
json.dumps(payload).encode('utf-8'),<br/>
|
||||
{"Content-Type": "application/json"},<br/>
|
||||
method='POST',<br/>
|
||||
@ -119,7 +120,7 @@
|
||||
<pre><code class="php"><?php<br/>
|
||||
<br/>
|
||||
// The URL<br/>
|
||||
$url = 'http://localhost:8000/notify/';<br/>
|
||||
$url = '{{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/notify/';<br/>
|
||||
<br/>
|
||||
//Initiate cURL.<br/>
|
||||
$ch = curl_init($url);<br/>
|
||||
@ -155,6 +156,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% if STATEFUL_MODE != 'disabled' %}
|
||||
<div class="section">
|
||||
<h4>{% trans "Persistent Store Endpoints" %}</h4>
|
||||
<p>{% blocktrans %}Those wishing to use the persistent store may do so. This section is a set it and forget it type
|
||||
@ -176,7 +178,7 @@
|
||||
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>/add/<em>{% trans "KEY" %}</em></code></td>
|
||||
<td><code>{{BASE_URL}}/add/<em>{% trans "KEY" %}</em></code></td>
|
||||
<td>
|
||||
{% blocktrans %}Used to add a new Apprise configuration or a set of URLs and associates them with the
|
||||
specified <em>KEY</em>. See the <a target="_blank"
|
||||
@ -233,12 +235,12 @@
|
||||
# {% blocktrans %}Load a single URL and assign it to the <em>KEY</em> of abc123{% endblocktrans %}<br/>
|
||||
curl -X POST -d '{"urls":"mailto://user:pass@gmail.com"}' \<br/>
|
||||
-H "Content-Type: application/json" \<br/>
|
||||
http://localhost:8000/add/<em>abc123</em></code></pre>
|
||||
{{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/add/<em>abc123</em></code></pre>
|
||||
<pre><code class="bash">
|
||||
# {% blocktrans %}Load a simple TEXT config entry <em>KEY</em> abc123{% endblocktrans %}<br/>
|
||||
curl -X POST -d '{"format":"text","config":"devops=mailto://user:pass@gmail.com"}' \<br/>
|
||||
-H "Content-Type: application/json" \<br/>
|
||||
http://localhost:8000/add/abc123/
|
||||
{{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/add/abc123/
|
||||
</code></pre>
|
||||
</div>
|
||||
</li>
|
||||
@ -254,7 +256,7 @@
|
||||
}<br/>
|
||||
<br/># The URL if the key was <em>abc123</em><br/>
|
||||
req = Request(<br/>
|
||||
"http://localhost:8000/add/<em>abc123</em>",<br/>
|
||||
"{{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/add/<em>abc123</em>",<br/>
|
||||
json.dumps(payload).encode('utf-8'),<br/>
|
||||
{"Content-Type": "application/json"},<br/>
|
||||
method='POST',<br/>
|
||||
@ -268,7 +270,7 @@
|
||||
<pre><code class="php"><?php<br/>
|
||||
<br/>
|
||||
// The URL if the key was <em>abc123</em><br/>
|
||||
$url = 'http://localhost:8000/add/<em>abc123</em>';<br/>
|
||||
$url = '{{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/add/<em>abc123</em>';<br/>
|
||||
<br/>
|
||||
//Initiate cURL.<br/>
|
||||
$ch = curl_init($url);<br/>
|
||||
@ -300,7 +302,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>/del/<em>{% trans "KEY" %}</em></code></td>
|
||||
<td><code>{{BASE_URL}}/del/<em>{% trans "KEY" %}</em></code></td>
|
||||
<td>{% blocktrans %}There are no arguments required. If the <em>KEY</em> exists and has data associated with
|
||||
it,
|
||||
it will be removed.{% endblocktrans %}
|
||||
@ -310,7 +312,7 @@
|
||||
<div class="collapsible-body">
|
||||
<pre><code class="bash">
|
||||
# {% blocktrans %}Remove previously loaded configuration associated with the <em>KEY</em> of abc123{% endblocktrans %}<br/>
|
||||
curl -X POST http://localhost:8000/del/<em>abc123</em></code></pre>
|
||||
curl -X POST {{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/del/<em>abc123</em></code></pre>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
@ -321,7 +323,7 @@
|
||||
from urllib.request import Request<br/>
|
||||
<br/># The request if the key was <em>abc123</em><br/>
|
||||
req = Request(<br/>
|
||||
"http://localhost:8000/del/<em>abc123</em>",<br/>
|
||||
"{{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/del/<em>abc123</em>",<br/>
|
||||
json.dumps(payload).encode('utf-8'),<br/>
|
||||
{"Content-Type": "application/json"},<br/>
|
||||
method='POST',<br/>
|
||||
@ -335,7 +337,7 @@
|
||||
<pre><code class="php"><?php<br/>
|
||||
<br/>
|
||||
// The URL if the key was <em>abc123</em><br/>
|
||||
$url = 'http://localhost:8000/del/<em>abc123</em>';<br/>
|
||||
$url = '{{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/del/<em>abc123</em>';<br/>
|
||||
<br/>
|
||||
//Initiate cURL.<br/>
|
||||
$ch = curl_init($url);<br/>
|
||||
@ -352,16 +354,16 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>/get/<em>{% trans "KEY" %}</em></code></td>
|
||||
<td><code>{{BASE_URL}}/get/<em>{% trans "KEY" %}</em></code></td>
|
||||
<td>{% blocktrans %}This feature can be used by Apprise itself. It provides a means of remotely fetching it's
|
||||
configuration.{% endblocktrans %}<br />
|
||||
<pre><code lang="bash"># Use Apprise to retrieve your configuration:<br/>
|
||||
apprise --body="test message" --config={{ request.scheme }}://{{request.META.HTTP_HOST}}{{ request.path }}<em>{% trans "KEY" %}</em></code></pre>
|
||||
apprise --body="test message" --config={{ request.scheme }}://{{request.META.HTTP_HOST}}{{BASE_URL}}/get/<em>{% trans "KEY" %}</em></code></pre>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>/notify/<em>{% trans "KEY" %}</em></code></td>
|
||||
<td><code>{{BASE_URL}}/notify/<em>{% trans "KEY" %}</em></code></td>
|
||||
<td>{% blocktrans %}Notifies the URLs associated with the specified <em>KEY</em>.{% endblocktrans %}
|
||||
<div class="section">
|
||||
<table>
|
||||
@ -415,7 +417,7 @@
|
||||
# {% blocktrans %}Notifies all URLs assigned the <em>devops</em> tag{% endblocktrans %}<br/>
|
||||
curl -X POST -d '{"tag":"devops","body":"test body","title":"test title"}' \<br/>
|
||||
-H "Content-Type: application/json" \<br/>
|
||||
http://localhost:8000/notify/<em>KEY</em></code></pre>
|
||||
{{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/notify/<em>KEY</em></code></pre>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
@ -432,7 +434,7 @@
|
||||
}<br/>
|
||||
<br/># The URL if the key was <em>abc123</em><br/>
|
||||
req = Request(<br/>
|
||||
"http://localhost:8000/notify/<em>abc123</em>",<br/>
|
||||
"{{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/notify/<em>abc123</em>",<br/>
|
||||
json.dumps(payload).encode('utf-8'),<br/>
|
||||
{"Content-Type": "application/json"},<br/>
|
||||
method='POST',<br/>
|
||||
@ -446,7 +448,7 @@
|
||||
<pre><code class="php"><?php<br/>
|
||||
<br/>
|
||||
// The URL if the key was <em>abc123</em><br/>
|
||||
$url = 'http://localhost:8000/notify/<em>abc123</em>';<br/>
|
||||
$url = '{{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/notify/<em>abc123</em>';<br/>
|
||||
<br/>
|
||||
//Initiate cURL.<br/>
|
||||
$ch = curl_init($url);<br/>
|
||||
@ -495,4 +497,10 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% else %}
|
||||
<div class="section">
|
||||
<h4>{% trans "Persistent Store Endpoints" %}</h4>
|
||||
<p>{% blocktrans %}The administrator of this system has disabled persistent storage.{% endblocktrans %}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
32
apprise_api/core/context_processors.py
Normal file
32
apprise_api/core/context_processors.py
Normal file
@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2020 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.conf import settings
|
||||
|
||||
|
||||
def base_url(request):
|
||||
"""
|
||||
Returns our defined BASE_URL object
|
||||
"""
|
||||
return {'BASE_URL': settings.BASE_URL}
|
@ -70,6 +70,8 @@ TEMPLATES = [
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.request',
|
||||
'core.context_processors.base_url',
|
||||
'api.context_processors.stateful_mode',
|
||||
],
|
||||
},
|
||||
},
|
||||
@ -77,8 +79,12 @@ TEMPLATES = [
|
||||
|
||||
WSGI_APPLICATION = 'core.wsgi.application'
|
||||
|
||||
# Define our base URL
|
||||
# The default value is to be a single slash
|
||||
BASE_URL = os.environ.get('BASE_URL', '')
|
||||
|
||||
# Static files relative path (CSS, JavaScript, Images)
|
||||
STATIC_URL = '/s/'
|
||||
STATIC_URL = BASE_URL + '/s/'
|
||||
|
||||
# The location to store Apprise configuration files
|
||||
APPRISE_CONFIG_DIR = os.environ.get(
|
||||
|
Loading…
Reference in New Issue
Block a user