diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..758238e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM php:latest +RUN apt-get update && apt-get install cron -y +COPY autosave.php /srv/autosave.php +COPY autosave.cron /srv/autosave.cron +COPY entrypoint.sh /srv/entrypoint.sh +RUN chmod 0600 /srv/autosave.cron +RUN chmod 0700 /srv/entrypoint.sh +RUN crontab /srv/autosave.cron +WORKDIR /srv +RUN docker-php-ext-install bcmath +RUN printenv | grep -v "no_proxy" >> /etc/environment +ENTRYPOINT /srv/entrypoint.sh diff --git a/autosave.cron b/autosave.cron new file mode 100644 index 0000000..09bbf7e --- /dev/null +++ b/autosave.cron @@ -0,0 +1,3 @@ +#!/bin/sh + +0 * * * * /usr/local/bin/php /srv/autosave.php --account=$SRC_ACCOUNT --destination=$DST_ACCOUNT --amount=$AMOUNT --days=$DAYS > /proc/1/fd/1 2>/proc/1/fd/2 diff --git a/autosave.php b/autosave.php index b32f6c8..f67af30 100644 --- a/autosave.php +++ b/autosave.php @@ -29,8 +29,9 @@ bcscale(12); * Keep in mind that running this script is entirely AT YOUR OWN RISK with ZERO GUARANTEES. */ -const EXCLUDED_TAGS = 'Direct debit'; -const FIREFLY_III_TOKEN = 'ey...'; +define('EXCLUDED_TAGS', (string)((getenv('EXCLUDED_TAGS') !== false) ? getenv('EXCLUDED_TAGS') : '')); +define('FIREFLY_III_TOKEN', (string)((getenv('FIREFLY_III_TOKEN') !== false) ? getenv('FIREFLY_III_TOKEN') : 'ey...')); +define('FIREFLY_III_URL', (string)((getenv('FIREFLY_III_URL') !== false) ? getenv('FIREFLY_III_URL') : 'https://firefly-iii.org')); /* * HERE BE MONSTERS @@ -136,6 +137,7 @@ function createAutoSaveTransaction(array $group, array $arguments): void )); return; } + // create transaction: $submission = [ 'transactions' => [ @@ -151,6 +153,7 @@ function createAutoSaveTransaction(array $group, array $arguments): void ], ], ]; + // submit: $result = postCurlRequest('/api/v1/transactions', $submission); $groupId = $result['data']['id']; @@ -285,7 +288,7 @@ function getTransactions(int $accountId): array $tags = $transaction['tags']; $noExcludedTags = true; foreach (explode(";", EXCLUDED_TAGS) as $excludedTag) { - if (in_array($tags, $excludedTag)) { + if (in_array($excludedTag, $tags)) { $noExcludedTags = false; } } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..746db0b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3.3' +services: + php-cron: + image: fireflyiii-autosave-cron + build: . + environment: + FIREFLY_III_TOKEN: 'ey...' + FIREFLY_III_URL: 'https://firefly-iii.org' + EXCLUDED_TAGS: + SRC_ACCOUNT: 1 + DST_ACCOUNT: 2 + AMOUNT: 1 + DAYS: 1 \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..b6d1c52 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +printenv | grep -v "no_proxy" >> /etc/environment +cron -f