Skip to content

Commit

Permalink
Config Generator and CSS/Doc Improvements (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Nov 18, 2023
1 parent 843685c commit 9ee3fd6
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ __pycache__/

# Distribution / packaging / virtualenv
.Python
.bash_history
env/
build/
develop-eggs/
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ curl -X POST -d '{"tag":"leaders teamA, leaders teamB", "body":"meeting now"}' \
### API Notes

- `{KEY}` must be 1-128 alphanumeric characters in length. In addition to this, the underscore (`_`) and dash (`-`) are also accepted.
- Consider using keys like `sha1`, `sha512`, `uuid`, etc to secure shared namespaces if you wish to open your platform to others. Or keep it simple in a controlled environment and just use the default string `apprise` as your key (and as illustrated in the examples above).
- Consider using keys like `sha1`, `sha512`, `uuid`, etc to secure shared namespaces if you wish to open your platform to others. Or keep it simple in a controlled environment and just use the default string `apprise` as your key (and as illustrated in the examples above). You can over-ride this default value by setting the `APPRISE_DEFAULT_CONFIG_ID`(see below).
- Specify the `Content-Type` of `application/json` to use the JSON support otherwise the default expected format is `application/x-www-form-urlencoded` (whether it is specified or not).
- There is no authentication (or SSL encryption) required to use this API; this is by design. The intention here is to be a light-weight and fast micro-service.
- There are no additional dependencies (such as database requirements, etc) should you choose to use the optional persistent store (mounted as `/config`).
Expand All @@ -287,6 +287,7 @@ The use of environment variables allow you to provide over-rides to default sett
| Variable | Description |
|--------------------- | ----------- |
| `APPRISE_DEFAULT_THEME` | Can be set to `light` or `dark`; it defaults to `light` if not otherwise provided. The theme can be toggled from within the website as well.
| `APPRISE_DEFAULT_CONFIG_ID` | Defaults to `apprise`. This is the presumed configuration ID you always default to when accessing the configuration manager via the website.
| `APPRISE_CONFIG_DIR` | Defines an (optional) persistent store location of all configuration files saved. By default:<br/> - Configuration is written to the `apprise_api/var/config` directory when just using the _Django_ `manage runserver` script. However for the path for the container is `/config`.
| `APPRISE_ATTACH_DIR` | The directory the uploaded attachments are placed in. By default:<br/> - Attachments are written to the `apprise_api/var/attach` directory when just using the _Django_ `manage runserver` script. However for the path for the container is `/attach`.
| `APPRISE_ATTACH_SIZE` | Over-ride the attachment size (defined in MB). By default it is set to `200` (Megabytes). You can set this up to a maximum value of `500` which is the restriction in place for NginX (internal hosting ervice) at this time. If you set this to zero (`0`) then attachments will not be passed along even if provided.
Expand Down
15 changes: 15 additions & 0 deletions apprise_api/api/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# 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 gen_unique_config_id
from .utils import ConfigCache
from django.conf import settings
import apprise
Expand All @@ -46,3 +47,17 @@ def apprise_version(request):
Returns the current version of apprise loaded under the hood
"""
return {'APPRISE_VERSION': apprise.__version__}


def default_config_id(request):
"""
Returns a unique config identifier
"""
return {'DEFAULT_CONFIG_ID': settings.APPRISE_DEFAULT_CONFIG_ID}


def unique_config_id(request):
"""
Returns a unique config identifier
"""
return {'UNIQUE_CONFIG_ID': gen_unique_config_id()}
6 changes: 4 additions & 2 deletions apprise_api/api/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<h1>{% trans "Apprise API" %}</h1>
<ul>
<li>APPRISE v{{APPRISE_VERSION}}</li>
<li class="theme"><a href="{{ request.path }}?theme={{request.next_theme}}"><span class="tiny material-icons">invert_colors</span></a></li>
<li class="theme"><a href="{{ request.path }}?theme={{request.next_theme}}"><i class="material-icons">invert_colors</i></a></li>
</ul>
</div>
</div>
Expand All @@ -46,8 +46,10 @@ <h1>{% trans "Apprise API" %}</h1>
<div class="col s3" style="width:20em">
{% if STATEFUL_MODE != 'disabled' %}
<ul class="collection z-depth-1">
<a class="collection-item" href="{% url 'config' 'apprise' %}"><i class="material-icons">settings</i>
<a class="collection-item" href="{% url 'config' DEFAULT_CONFIG_ID %}"><i class="material-icons">settings</i>
{% trans "Configuration Manager" %}</a>
<a class="collection-item" href="{% url 'config' UNIQUE_CONFIG_ID %}"><i class="material-icons">refresh</i>
{% trans "New Configuration" %}</a>
</ul>
{% endif %}
<ul class="collection z-depth-1">
Expand Down
25 changes: 22 additions & 3 deletions apprise_api/api/templates/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load i18n %}
{% block body %}
{% if STATEFUL_MODE != 'disabled' %}
<h4>{% trans "Management for:" %} <em>{{ key }}</em></h4>
<h4>{% trans "Management for Config ID:" %} <em>{{ key }}</em></h4>
<div class="row">
<div class="col s12">
<ul class="tabs config-overview">
Expand Down Expand Up @@ -75,12 +75,11 @@ <h5>{% trans "Apprise Configuration is Locked" %}</h5>
<div class="has-config">
<div class="section">
<h5>{% trans "Working Remotely With Your Configuration" %}</h5>
<h6>{% trans "Using The Apprise CLI" %}</h6>
<p>
{% blocktrans %}The following command would cause apprise to directly notify all of your services:{% endblocktrans %}
<br />
<pre><code class="bash">apprise --body="Test Message" \<br/>
&nbsp;&nbsp;&nbsp;&nbsp;apprise{% if request.is_secure %}s{% endif %}://{{request.META.HTTP_HOST}}{{BASE_URL}}/<em>{{key}}</em>/?tags=all</code></pre>
<br />
{% blocktrans %}Send one or more attachments like this:{% endblocktrans %}
<pre><code class="bash">apprise --body="Test Message" \<br/>
&nbsp;&nbsp;&nbsp;&nbsp;apprise{% if request.is_secure %}s{% endif %}://{{request.META.HTTP_HOST}}{{BASE_URL}}/<em>{{key}}</em>/?tags=all \<br/>
Expand All @@ -95,8 +94,28 @@ <h5>{% trans "Working Remotely With Your Configuration" %}</h5>
<br />
<pre><code class="bash">apprise --body="Test Message" --tag=all \<br/>
&nbsp;&nbsp;&nbsp;&nbsp;--config={{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/get/<em>{{key}}</em></code></pre>
{% blocktrans %}You may also create an <a href="https://github.com/caronc/apprise/wiki/config#cli" target="_blank">Apprise configuration file</a> that contains this line somewhere in it:{% endblocktrans %}
<pre><code class="bash">include {{request.scheme}}://{{request.META.HTTP_HOST}}{{BASE_URL}}/get/<em>{{key}}</em></code></pre>
{% blocktrans %}By leveraging the <em>include</em> directive, it will automatically be referenced for future calls to the <code>apprise</code> tool. All future calls using Apprise now simplify to:{% endblocktrans %}
<pre><code class="bash">apprise --body="Test Message" --tag=all</em></code></pre>
</p>

{% endif %}
<h6>{% trans "Using CURL" %}</h6>
<p>
{% blocktrans %}The following command would cause the apprise api to notify all of your services:{% endblocktrans %}
<pre><code class="bash">curl&nbsp;-X&nbsp;POST \<br/>
&nbsp;&nbsp;&nbsp;&nbsp;-F "body=Test Message" \<br/>
&nbsp;&nbsp;&nbsp;&nbsp;-F "tags=all" \<br/>
&nbsp;&nbsp;&nbsp;&nbsp;http{% if request.is_secure %}s{% endif %}://{{request.META.HTTP_HOST}}{{BASE_URL}}/notify/<em>{{key}}</em></code></pre>
{% blocktrans %}Send one or more attachments like this:{% endblocktrans %}
<pre><code class="bash">curl&nbsp;-X&nbsp;POST \<br/>
&nbsp;&nbsp;&nbsp;&nbsp;-F "tags=all" \<br/>
&nbsp;&nbsp;&nbsp;&nbsp;-F "body=Test Message" \<br/>
&nbsp;&nbsp;&nbsp;&nbsp;-F [email protected] \<br/>
&nbsp;&nbsp;&nbsp;&nbsp;-F attach2=@/my/path/to/Apprise.doc \<br/>
&nbsp;&nbsp;&nbsp;&nbsp;http{% if request.is_secure %}s{% endif %}://{{request.META.HTTP_HOST}}{{BASE_URL}}/notify/<em>{{key}}</em></code></pre>
</p>
</div>
<div class="section">
<h5>{% trans "Loaded Configuration" %}</h5>
Expand Down
12 changes: 12 additions & 0 deletions apprise_api/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import requests
from json import dumps
from django.conf import settings
from datetime import datetime

# import the logging library
import logging
Expand Down Expand Up @@ -588,6 +589,17 @@ def apply_global_filters():
' ignoring.', name)


def gen_unique_config_id():
"""
Generates a unique configuration ID
"""
# our key to use
h = hashlib.sha256()
h.update(datetime.now().strftime('%Y%m%d%H%M%S%f').encode('utf-8'))
h.update(settings.SECRET_KEY.encode('utf-8'))
return h.hexdigest()


def send_webhook(payload):
"""
POST our webhook results
Expand Down
6 changes: 6 additions & 0 deletions apprise_api/core/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
'context_processors': [
'django.template.context_processors.request',
'core.context_processors.base_url',
'api.context_processors.default_config_id',
'api.context_processors.unique_config_id',
'api.context_processors.stateful_mode',
'api.context_processors.config_lock',
'api.context_processors.apprise_version',
Expand Down Expand Up @@ -120,6 +122,10 @@
# The default value is to be a single slash
BASE_URL = os.environ.get('BASE_URL', '')

# Define our default configuration ID to use
APPRISE_DEFAULT_CONFIG_ID = \
os.environ.get('APPRISE_DEFAULT_CONFIG_ID', 'apprise')

# Static files relative path (CSS, JavaScript, Images)
STATIC_URL = BASE_URL + '/s/'

Expand Down
15 changes: 15 additions & 0 deletions apprise_api/static/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ td, th {
margin-bottom: 0;
}

h4 em {
font-size: 2.0rem;
display: inline-block;
margin: 0;
padding: 0;
word-break: break-all;
line-height: 1.0em;
}

em {
color: #004d40;
font-weight:bold;
Expand Down Expand Up @@ -164,3 +173,9 @@ ul.logs li.log_ERROR {
.url-disabled {
color: #8B0000;
}
h6 {
font-weight: bold;
}
#overview pre {
margin-left: 2.0rem
}
2 changes: 1 addition & 1 deletion apprise_api/static/css/dark/highlight.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apprise_api/static/css/dark/materialize.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apprise_api/static/css/light/highlight.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9ee3fd6

Please sign in to comment.