From 4056b2024980969b33af28ab9d258f9f5f927521 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sun, 27 Aug 2023 19:17:04 -0400 Subject: [PATCH] Attachment filesize limit can be set via environment variable (#131) --- README.md | 3 ++- apprise_api/api/utils.py | 3 +++ apprise_api/core/settings/__init__.py | 3 +++ apprise_api/etc/nginx.conf | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fc23324..5e13f12 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ The following architectures are supported: `amd64`, `arm/v7`, and `arm64`. The f ## Apprise URLs -📣 In order to trigger a notification, you first need to define one or more [Apprise URLs](https://github.com/caronc/apprise/wiki) to support the services you wish to leverage. Apprise supports over 80+ notification services today and is always expanding to add support for more! Visit to see the ever-growing list of the services supported today. +📣 In order to trigger a notification, you first need to define one or more [Apprise URLs](https://github.com/caronc/apprise/wiki) to support the services you wish to leverage. Apprise supports over 90+ notification services today and is always expanding to add support for more! Visit to see the ever-growing list of the services supported today. ## API Details @@ -276,6 +276,7 @@ The use of environment variables allow you to provide over-rides to default sett |--------------------- | ----------- | | `APPRISE_CONFIG_DIR` | Defines an (optional) persistent store location of all configuration files saved. By default:
- 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:
- 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. | `APPRISE_STATELESS_URLS` | For a non-persistent solution, you can take advantage of this global variable. Use this to define a default set of Apprise URLs to notify when using API calls to `/notify`. If no `{KEY}` is defined when calling `/notify` then the URLs defined here are used instead. By default, nothing is defined for this variable. | `APPRISE_STATEFUL_MODE` | This can be set to the following possible modes:
📌 **hash**: This is also the default. It stores the server configuration in a hash formatted that can be easily indexed and compressed.
📌 **simple**: Configuration is written straight to disk using the `{KEY}.cfg` (if `TEXT` based) and `{KEY}.yml` (if `YAML` based).
📌 **disabled**: Straight up deny any read/write queries to the servers stateful store. Effectively turn off the Apprise Stateful feature completely. | `APPRISE_CONFIG_LOCK` | Locks down your API hosting so that you can no longer delete/update/access stateful information. Your configuration is still referenced when stateful calls are made to `/notify`. The idea of this switch is to allow someone to set their (Apprise) configuration up and then as an added security tactic, they may choose to lock their configuration down (in a read-only state). Those who use the Apprise CLI tool may still do it, however the `--config` (`-c`) switch will not successfully reference this access point anymore. You can however use the `apprise://` plugin without any problem ([see here for more details](https://github.com/caronc/apprise/wiki/Notify_apprise_api)). This defaults to `no` and can however be set to `yes` by simply defining the global variable as such. diff --git a/apprise_api/api/utils.py b/apprise_api/api/utils.py index cc016ca..1d9fd33 100644 --- a/apprise_api/api/utils.py +++ b/apprise_api/api/utils.py @@ -101,6 +101,9 @@ class Attachment(apprise.attachment.AttachFile): # Prepare our item super().__init__(path=self._path, name=filename) + # Update our file size based on the settings value + self.max_file_size = settings.APPRISE_ATTACH_SIZE + @property def filename(self): return self._filename diff --git a/apprise_api/core/settings/__init__.py b/apprise_api/core/settings/__init__.py index 0b0407a..1adba1d 100644 --- a/apprise_api/core/settings/__init__.py +++ b/apprise_api/core/settings/__init__.py @@ -128,6 +128,9 @@ APPRISE_CONFIG_DIR = os.environ.get( APPRISE_ATTACH_DIR = os.environ.get( 'APPRISE_ATTACH_DIR', os.path.join(BASE_DIR, 'var', 'attach')) +# The file attachment size allowed by the API +APPRISE_ATTACH_SIZE = int(os.environ.get('APPRISE_ATTACH_SIZE', 200)) * 1048576 + # When set Apprise API Locks itself down so that future (configuration) # changes can not be made or accessed. It disables access to: # - the configuration screen: /cfg/{token} diff --git a/apprise_api/etc/nginx.conf b/apprise_api/etc/nginx.conf index 9a68697..b183e2e 100644 --- a/apprise_api/etc/nginx.conf +++ b/apprise_api/etc/nginx.conf @@ -20,7 +20,7 @@ http { ## # Upload Restriction ## - client_max_body_size 100M; + client_max_body_size 500M; ## # Logging Settings