commit c1b827fba3aa45d91c3eb2c68288cd4af6a717c9 Author: bel Date: Tue Sep 14 06:20:35 2021 -0600 archive diff --git a/2try b/2try new file mode 100755 index 0000000..5fd1328 --- /dev/null +++ b/2try @@ -0,0 +1,5 @@ +https://firefly-iii.readthedocs.io/en/latest/installation/docker.html +https://github.com/gugoan/economizzer#live-demo +http://www.economizzer.org +https://github.com/beancount/fava + diff --git a/fava/fava.sh b/fava/fava.sh new file mode 100755 index 0000000..a8fb1d0 --- /dev/null +++ b/fava/fava.sh @@ -0,0 +1,10 @@ +#! /bin/bash + +function clean() { + docker rm -f $(docker ps -a | grep fava | awk '{print $NF}') +} +trap clean EXIT + +echo 'touch /any.bean && fava -d --host 0.0.0.0 /any.bean' | docker run --rm -i -p 5000:5000 yegle/fava sh > /dev/null 2>&1 & +sleep 5 +docker logs --follow $(docker ps -a | grep fava | awk '{print $NF}') diff --git a/ff3-to-ledger/ff3.csv.tar b/ff3-to-ledger/ff3.csv.tar new file mode 100644 index 0000000..974671e Binary files /dev/null and b/ff3-to-ledger/ff3.csv.tar differ diff --git a/ff3-to-ledger/to_ledger.py b/ff3-to-ledger/to_ledger.py new file mode 100755 index 0000000..8a54c80 --- /dev/null +++ b/ff3-to-ledger/to_ledger.py @@ -0,0 +1,111 @@ +#! /bin/python3 + +class FireflyIIITransaction(dict) : + def __init__(self, keys, line) : + for k, v in { keys[i]:line[i] for i in range(len(keys)) }.items() : + if not k in dir(self) : + setattr(self, k, v) + self.keys = keys[:] + dict.__init__(self, self.__dict__()) + + def __dict__(self) : + keys = [ + "user_id", + "group_id", + "journal_id", + "created_at", + "updated_at", + "group_title", + "type", + "amount", + "foreign_amount", + "currency_code", + "foreign_currency_code", + "description", + "date", + "source_name", + "source_iban", + "source_type", + "destination_name", + "destination_iban", + "destination_type", + "reconciled", + "category", + "budget", + "bill", + "tags", + ] + keys = [ + "type", + "amount", + "date", + "source_name", + "source_type", + "destination_name", + "destination_type", + "category", + "description", + ] + return { k:getattr(self, k) for k in keys if k in self.keys } + + def __str__(self) : + return self.ledger() + + def ledger(self) : + date = self.date.split("T")[0] + description = getattr(self, "description" if self.description and self.description != "(null)" else "source_name" if self.type in ["Withdrawl", "Transfer"] else "destination_name") + amount = float("{:0.2f}".format(float(self.amount)).strip("-")) + local = "" + remote = "" + if self.type.startswith("Withdraw") : + amount = -1.0 * amount + local = ":".join([self.source_type, self.source_name]).title().replace(" ", "") + remote = ":".join([self.type, self.category, self.destination_name]).title().replace(" ", "") + elif self.type == "Transfer" : + local = ":".join([self.destination_type, self.destination_name]).title().replace(" ", "") + remote = ":".join([self.source_type, self.source_name]).title().replace(" ", "") + elif self.type == "Deposit" : + local = ":".join([self.destination_type, self.destination_name]).title().replace(" ", "") + remote = ":".join([self.type, self.category, self.source_name]).title().replace(" ", "") + else : + raise Exception("unknown type: "+self.type) + return "\n".join([i for i in [ j for j in f'''{date} {description} + {"{:100s}".format(remote)} ${"{:0.2f}".format(-1.0 * amount)} + {"{:100s}".format(local)} ${"{:0.2f}".format(amount)} + '''.split("\n") if j.strip() ]]) + + +class FireflyIII() : + def __init__(self, path) : + import csv + lines = [ i for i in csv.reader(open(path)) ] + keys = lines[0] + lines = lines[1:] + self.transactions = [ FireflyIIITransaction(keys, i) for i in lines ] + + def __str__(self) : + import json + return json.dumps(self.transactions, indent=" ") + + def __getitem__(self, k) : + return self.transactions[k] + + def ledger(self) : + return sorted([i.ledger() for i in self.transactions]) + +def main(args) : + if not args : + args.append("./ff3.csv") + ff3 = FireflyIII(args[0]) + print(ff3) + print(ff3[0]) + print("\n".join(ff3.ledger())) + f = open("./ledger.dat", "w") + for ledger in ff3.ledger() : + f.write(ledger) + f.write("\n") + f.close() + +if __name__ == "__main__" : + from sys import argv + main(argv[1:]) diff --git a/firefly/compose-old/firefly-compose.yml b/firefly/compose-old/firefly-compose.yml new file mode 100755 index 0000000..3cd8234 --- /dev/null +++ b/firefly/compose-old/firefly-compose.yml @@ -0,0 +1,46 @@ +--- +networks: + firefly_iii_net: + driver: bridge +services: + firefly_iii_app: + environment: + - FF_DB_HOST=firefly_iii_db + - FF_DB_NAME=firefly + - FF_DB_USER=firefly + - FF_DB_PASSWORD=firefly + - FF_APP_KEY=S0m3R@nd0mStr1ngOf32Ch@rsEx@ctly + - FF_APP_ENV=local + - FF_DB_CONNECTION=pgsql + - TZ=Europe/Amsterdam + - APP_LOG_LEVEL=debug + image: jc5x/firefly-iii + links: + - firefly_iii_db + networks: + - firefly_iii_net + ports: + - "80:80" + #volumes: + # - + # source: firefly_iii_export + # target: /var/www/firefly-iii/storage/export + # type: volume + # - + # source: firefly_iii_upload + # target: /var/www/firefly-iii/storage/upload + # type: volume + firefly_iii_db: + environment: + - POSTGRES_PASSWORD=firefly + - POSTGRES_USER=firefly + image: "postgres:10" + networks: + - firefly_iii_net + #volumes: + # - "firefly_iii_db:/var/lib/postgresql/data" +version: "3.2" +#volumes: +# firefly_iii_db: ~ +# firefly_iii_export: ~ +# firefly_iii_upload: ~ diff --git a/firefly/compose-old/firefly.sh b/firefly/compose-old/firefly.sh new file mode 100755 index 0000000..eee37a9 --- /dev/null +++ b/firefly/compose-old/firefly.sh @@ -0,0 +1,25 @@ +#! /bin/bash + +cd "$(dirname "${BASH_SOURCE[0]}")" + +function clean() { + docker-compose -f firefly-compose.yml rm + docker rm -f $(docker ps -a | grep firefly | awk '{print $NF}') 2> /dev/null +} +trap clean EXIT + +docker-compose -f firefly-compose.yml up -d +sleep 20 +docker-compose -f firefly-compose.yml exec firefly_iii_app php artisan migrate --seed +sleep 5 +docker-compose -f firefly-compose.yml exec firefly_iii_app php artisan firefly:upgrade-database +sleep 5 +docker-compose -f firefly-compose.yml exec firefly_iii_app php artisan firefly:verify +sleep 5 +docker-compose -f firefly-compose.yml exec firefly_iii_app php artisan passport:install +sleep 5 +docker-compose -f firefly-compose.yml exec firefly_iii_app php artisan cache:clear +sleep 5 + +docker logs --follow $(docker ps -a | grep firefly | head -n 1 | awk '{print $NF}') + diff --git a/firefly/postgres/.dockerignore b/firefly/postgres/.dockerignore new file mode 100755 index 0000000..a9a5aec --- /dev/null +++ b/firefly/postgres/.dockerignore @@ -0,0 +1 @@ +tmp diff --git a/firefly/postgres/Dockerfile b/firefly/postgres/Dockerfile new file mode 100755 index 0000000..fd0c620 --- /dev/null +++ b/firefly/postgres/Dockerfile @@ -0,0 +1,75 @@ +FROM ubuntu:18.04 + +### APT +RUN apt -y update \ + && DEBIAN_FRONTEND=noninteractive apt -y install tzdata \ + && apt -y install locales language-pack-en-base \ + && echo '127.0.0.1 firefly-iii-domain.com firefly-iii localhost' >> /etc/hosts \ + && apt -y install \ + postgresql postgresql-contrib \ + nginx \ + php-fpm php7.3-pgsql php-curl php-gd php-bcmath php-zip php-intl php-mbstring php-xml php-ldap \ + curl \ + gcc \ + cron \ + rsync \ + sudo \ + && rm /etc/nginx/sites-enabled/default \ + && touch /etc/nginx/sites-available/firefly-iii.conf \ + && ln -s /etc/nginx/sites-available/firefly-iii.conf /etc/nginx/sites-enabled/firefly-iii.conf \ + && openssl dhparam 2048 > /etc/nginx/dhparam.pem + +USER postgres +RUN service postgresql start && sleep 5 \ + && psql --command "CREATE DATABASE fireflyiii WITH ENCODING 'UTF8' TEMPLATE='template0';" \ + && psql --command "CREATE USER ffly WITH SUPERUSER PASSWORD 'pwd';" \ + && psql --command "GRANT ALL PRIVILEGES ON DATABASE fireflyiii TO ffly;" \ + && service postgresql stop && sleep 5 + + #&& sed 's/^password .*/password = pwd/' /etc/mysql/debian.cnf > /tmp/cnf \ + #&& mv /tmp/cnf /etc/mysql/debian.cnf \ + #&& echo 'create database fireflyiii character set utf8 collate utf8_bin; ' \ + # 'grant all privileges on fireflyiii.* to fireflyiii@localhost identified by '"'"'pwd'"'"'; ' \ + # | mysql --user=root --password=pwd mysql && echo made fireflyiii +USER root + +### PHP +RUN service postgresql start && sleep 10 \ + && curl -sS https://getcomposer.org/installer \ + | php -- --install-dir=/usr/local/bin --filename=composer \ + && cd /opt \ + && composer create-project grumpydictator/firefly-iii --no-dev --prefer-dist firefly-iii 5.0.1 +COPY ./env /opt/firefly-iii/.env +RUN service postgresql start && sleep 10 \ + && cd /opt/firefly-iii \ + && php artisan migrate:refresh --seed \ + && php artisan passport:install \ + && chown -R www-data:www-data /opt/firefly-iii \ + && mkdir -p /run/php + +### WAIT +COPY ./pause /xfer/ +RUN cd /xfer && gcc main.c -o /xfer/pauser + +### CONFIG +COPY ./env /opt/firefly-iii/.env +COPY ./firefly-iii.conf /etc/nginx/sites-enabled/ + +RUN apt -y autoremove \ + && apt -y purge --auto-remove gcc curl \ + && rm -rf /var/lib/apt \ + && apt clean + +### CRON +RUN true \ + && echo '0 4,8,12,16,20 * * * bash /backup.sh >> /var/log/cronj.log 2>&1' > /etc/cron.d/backups \ + && echo '' >> /etc/cron.d/backups \ + && chmod 0644 /etc/cron.d/backups \ + && crontab /etc/cron.d/backups \ + && touch /var/log/cronj.log + +### COPY +COPY ./backup.sh ./restore.sh ./entrypoint.sh / + +### on enter/exit, rsync to/from /var/lib/mysql and /mnt +ENTRYPOINT bash /entrypoint.sh diff --git a/firefly/postgres/backup.sh b/firefly/postgres/backup.sh new file mode 100755 index 0000000..3965323 --- /dev/null +++ b/firefly/postgres/backup.sh @@ -0,0 +1,21 @@ +#! /bin/bash + +set -e +set -x +service postgresql start +thisback="/mnt/back/$(date -u +%Y%m%d%H%M%S).dump" +rm -rf "$thisback" || true +mkdir -p "$(dirname "$thisback")" +pg_dump postgres://ffly:pwd@localhost/fireflyiii --clean > "$thisback" +service postgresql start +n=$(ls /mnt/back | wc -l) +if ((n<=25)); then + echo "No old backups to purge" >&2 + exit 0 +fi +((m=n-25)) +stale=($(find /mnt/back/ -mindepth 1 -maxdepth 1 | sort | head -n $m)) +echo "Purging: rm -rf ${stale[@]}" >&2 +rm -rf "${stale[@]}" +remaining=($(find /mnt/back/ -mindepth 1 -maxdepth 1 | sort)) +echo "Remains: ${remaining[@]}" >&2 diff --git a/firefly/postgres/build.sh b/firefly/postgres/build.sh new file mode 100755 index 0000000..24bbacf --- /dev/null +++ b/firefly/postgres/build.sh @@ -0,0 +1,15 @@ +#! /bin/bash + +set -e + +mkdir -p $(pwd)/tmp + +docker build -t dev:dev . +docker run \ + --rm \ + -it \ + -p 9031:9031 \ + -v $PWD/tmp:/mnt \ + dev:dev + + # -v $(pwd)/tmp:/mnt \ diff --git a/firefly/postgres/entrypoint.sh b/firefly/postgres/entrypoint.sh new file mode 100755 index 0000000..951c75e --- /dev/null +++ b/firefly/postgres/entrypoint.sh @@ -0,0 +1,16 @@ +#! /bin/bash + +set -e + +echo " : servicing" >&2 +for s in postgresql nginx php7.3-fpm cron; do + service $s restart +done +echo " : restoring" >&2 +bash /restore.sh $i +echo " : backing" >&2 +bash /backup.sh +echo " : sleeping" >&2 +sleep 10 +echo " : pausering" >&2 +exec /xfer/pauser diff --git a/firefly/postgres/env b/firefly/postgres/env new file mode 100755 index 0000000..59ef944 --- /dev/null +++ b/firefly/postgres/env @@ -0,0 +1,102 @@ +# You can leave this on "local". If you change it to production most console commands will ask for extra confirmation. +# Never set it to "testing". +APP_ENV=local + +# Set to true if you want to see debug information in error screens. +APP_DEBUG=true + +# This should be your email address +SITE_OWNER=admin@email.com + +# The encryption key for your database and sessions. Keep this very secure. +# If you generate a new one all existing data must be considered LOST. +# Change it to a string of exactly 32 chars or use command `php artisan key:generate` to generate it +APP_KEY=11111111111111111111111111111111 + +# Change this value to your preferred time zone. +# Example: Europe/Amsterdam +TZ=America/Chicago + +# APP_URL and TRUSTED_PROXIES are useful when using Docker and/or a reverse proxy. +APP_URL=http://localhost +TRUSTED_PROXIES= + +# The log channel defines where your log entries go to. +LOG_CHANNEL=daily + +# Database credentials. Make sure the database exists. I recommend a dedicated user for Firefly III +# For other database types, please see the FAQ: http://firefly-iii.readthedocs.io/en/latest/support/faq.html +DB_CONNECTION=pgsql +DB_HOST=127.0.0.1 +DB_PORT=5432 +DB_DATABASE=fireflyiii +DB_USERNAME=ffly +DB_PASSWORD=pwd + +# 'daily' is the default logging mode giving you 5 daily rotated log files in /storage/logs/. +# Several other options exist. You can use 'single' for one big fat error log (not recommended). +# Also available are 'syslog' and 'errorlog' which will log to the system itself. +APP_LOG=daily + +# Log level. You can set this from least severe to most severe: +# debug, info, notice, warning, error, critical, alert, emergency +# If you set it to debug your logs will grow large, and fast. If you set it to emergency probably +# nothing will get logged, ever. +APP_LOG_LEVEL=notice + +# If you're looking for performance improvements, you could install memcached. +CACHE_DRIVER=file +SESSION_DRIVER=file + +# Cookie settings. Should not be necessary to change these. +COOKIE_PATH="/" +COOKIE_DOMAIN= +COOKIE_SECURE=false + +# If you want Firefly III to mail you, update these settings +MAIL_DRIVER=smtp +MAIL_HOST=smtp.server.com +MAIL_PORT=587 +MAIL_FROM= +MAIL_USERNAME= +MAIL_PASSWORD= +MAIL_ENCRYPTION=tls + +# Firefly III can send you the following messages +SEND_REGISTRATION_MAIL=true +SEND_ERROR_MESSAGE=true + +# Set a Mapbox API key here (see mapbox.com) so there might be a map available at various places. +MAPBOX_API_KEY= + +# Set a Fixer IO API key here (see https://fixer.io) to enable live currency exchange rates. +# Please note that this will only work for paid fixer.io accounts because they severly limited +# the free API up to the point where you might as well offer nothing. +FIXER_API_KEY= + +# If you wish to track your own behavior over Firefly III, set a valid analytics tracker ID here. +ANALYTICS_ID= + +# Most parts of the database are encrypted by default, but you can turn this off if you want to. +# This makes it easier to migrate your database. Not that some fields will never be decrypted. +USE_ENCRYPTION=true + +# Leave the following configuration vars as is. +# Unless you like to tinker and know what you're doing. +APP_NAME=FireflyIII +BROADCAST_DRIVER=log +QUEUE_DRIVER=sync +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 +CACHE_PREFIX=firefly +SEARCH_RESULT_LIMIT=50 +PUSHER_KEY= +PUSHER_SECRET= +PUSHER_ID= +DEMO_USERNAME= +DEMO_PASSWORD= +IS_DOCKER=true +IS_SANDSTORM=false +BUNQ_USE_SANDBOX=false +IS_HEROKU=false diff --git a/firefly/postgres/firefly-iii.conf b/firefly/postgres/firefly-iii.conf new file mode 100755 index 0000000..9a52dc2 --- /dev/null +++ b/firefly/postgres/firefly-iii.conf @@ -0,0 +1,29 @@ +server { + listen 9031; + listen [::]:9031; + + root /opt/firefly-iii/public; + + # Add index.php to the list if you are using PHP + client_max_body_size 300M; + index index.html index.htm index.php; + + # Load configuration files for the default server block. + include /etc/nginx/default.d/*.conf; + location ~ \.php$ { + try_files $uri =404; + fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + + } + + index index.php index.htm index.html; + + location / { + try_files $uri $uri/ /index.php?$query_string; + autoindex on; + sendfile off; + } +} diff --git a/firefly/postgres/pause/main.c b/firefly/postgres/pause/main.c new file mode 100755 index 0000000..e9f68c7 --- /dev/null +++ b/firefly/postgres/pause/main.c @@ -0,0 +1,20 @@ +#include +#include +#include + +int main() { + int stat; + int sig; + sigset_t set; + sigemptyset(&set); + printf("add signal SIGINT: %i\n", sigaddset(&set, SIGINT)); + printf("add signal SIGKILL: %i\n", sigaddset(&set, SIGKILL)); + printf("add signal SIGTERM: %i\n", sigaddset(&set, SIGTERM)); + sigprocmask(SIG_BLOCK, &set, NULL); + printf("Waiting...\n"); + stat = sigwait(&set, &sig); + printf("Wait complete: %i (%i)\n", sig, stat); + printf("Backed: %i\n", system("bash /backup.sh")); + printf("Bye-bye!\n"); + return 0; +} diff --git a/firefly/postgres/restore.sh b/firefly/postgres/restore.sh new file mode 100755 index 0000000..e1c0452 --- /dev/null +++ b/firefly/postgres/restore.sh @@ -0,0 +1,38 @@ +#! /bin/bash + +skip=${1:-0} +set -x +set -e +backups="$(find /mnt/back/ -maxdepth 1 -mindepth 1 | grep -v '\/\.' | sort -r)" +if [ -z "${backups}" ]; then + echo "ERR: no backups to restore" >&2 + exit 0 +fi +tried=0 +echo Trying backups ${backups}... >&2 +for lastback in ${backups}; do + ((tried+=1)) + if ((tried<=skip)); then + continue + fi + if ( + echo Trying backup from $lastback >&2 + set -e + service postgresql start + psql postgres://ffly:pwd@localhost/fireflyiii < "$lastback" + service postgresql start + n=0 + until service postgresql status || ((n>10)); do + sleep 5 + ((n+=1)) + done + until service postgresql status | grep -E 'down|online'; do + sleep 5 + done + service postgresql status | grep online + ); then + exit 0 + fi +done +echo "ERR: could not load any backup" >&2 +exit 1 diff --git a/firefly/postgres/script.sh b/firefly/postgres/script.sh new file mode 100755 index 0000000..0437b2b --- /dev/null +++ b/firefly/postgres/script.sh @@ -0,0 +1,50 @@ +#! /bin/bash + +set -e +set -u + +apt -y update && apt -y upgrade && apt -y autoremove +DEBIAN_FRONTEND=noninteractive apt -y install tzdata +apt -y install vim locales language-pack-en-base + +echo '127.0.0.1 firefly-iii-domain.com firefly-iii localhost' >> /etc/hosts + +apt -y install fail2ban + +apt -y install mariadb-server nginx php-fpm php7.3-mysql php-curl php-gd php-bcmath php-zip php-intl php-mbstring php-xml + +service mysql start +echo 'FLUSH PRIVILEGES; ' \ + 'USE mysql; ' \ + 'UPDATE user SET authentication_string=PASSWORD("pwd") WHERE User='"'"'root'"'"'; ' \ + 'UPDATE user SET plugin="mysql_native_password" WHERE User='"'"'root'"'"'; ' \ + | mysql -u root || true +service mysql restart +sleep 5 + +echo 'create database fireflyiii character set utf8 collate utf8_bin; ' \ + 'grant all privileges on fireflyiii.* to fireflyiii@localhost identified by '"'"'pwd'"'"'; ' \ + | mysql -uroot -ppwd +service mysql restart + +apt -y install curl +curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + +cd /opt +composer create-project grumpydictator/firefly-iii --no-dev --prefer-dist firefly-iii 4.7.4 + +cp /copied/env /opt/firefly-iii/.env + +cd firefly-iii +php artisan migrate:refresh --seed +php artisan passport:install + +chown -R www-data:www-data /opt/firefly-iii/ + +rm /etc/nginx/sites-enabled/default +touch /etc/nginx/sites-available/firefly-iii.conf +ln -s /etc/nginx/sites-available/firefly-iii.conf /etc/nginx/sites-enabled/firefly-iii.conf +openssl dhparam 2048 > /etc/nginx/dhparam.pem +cp /copied/firefly-iii.conf /etc/nginx/sites-enabled/firefly-iii.conf + +mkdir -p /run/php diff --git a/firefly/ubuntu-old/Dockerfile b/firefly/ubuntu-old/Dockerfile new file mode 100755 index 0000000..2c75ba8 --- /dev/null +++ b/firefly/ubuntu-old/Dockerfile @@ -0,0 +1,107 @@ +FROM ubuntu:18.10 + +### APT +RUN apt -y update \ + && DEBIAN_FRONTEND=noninteractive apt -y install tzdata \ + && apt -y install locales language-pack-en-base \ + && echo '127.0.0.1 firefly-iii-domain.com firefly-iii localhost' >> /etc/hosts \ + && apt -y install \ + mariadb-server \ + nginx \ + php-fpm php7.2-mysql php-curl php-gd php-bcmath php-zip php-intl php-mbstring php-xml \ + curl \ + gcc \ + cron \ + && rm /etc/nginx/sites-enabled/default \ + && touch /etc/nginx/sites-available/firefly-iii.conf \ + && ln -s /etc/nginx/sites-available/firefly-iii.conf /etc/nginx/sites-enabled/firefly-iii.conf \ + && openssl dhparam 2048 > /etc/nginx/dhparam.pem \ + && service mysql start && sleep 5 \ + && echo 'FLUSH PRIVILEGES; ' \ + 'USE mysql; ' \ + 'UPDATE user SET authentication_string=PASSWORD("pwd") WHERE User='"'"'root'"'"'; ' \ + 'UPDATE user SET plugin="mysql_native_password" WHERE User='"'"'root'"'"'; ' \ + | mysql --user=root mysql || true && echo made user \ + && service mysql stop && sleep 5 \ + && sed 's/^password .*/password = pwd/' /etc/mysql/debian.cnf > /tmp/cnf \ + && mv /tmp/cnf /etc/mysql/debian.cnf \ + && service mysql start && sleep 5 \ + && echo 'create database fireflyiii character set utf8 collate utf8_bin; ' \ + 'grant all privileges on fireflyiii.* to fireflyiii@localhost identified by '"'"'pwd'"'"'; ' \ + | mysql --user=root --password=pwd mysql && echo made fireflyiii + +### PHP +RUN service mysql start && sleep 10 \ + && curl -sS https://getcomposer.org/installer \ + | php -- --install-dir=/usr/local/bin --filename=composer \ + && cd /opt \ + && composer create-project grumpydictator/firefly-iii --no-dev --prefer-dist firefly-iii 4.7.4 +COPY ./env /opt/firefly-iii/.env +RUN service mysql start && sleep 10 \ + && cd /opt/firefly-iii \ + && php artisan migrate:refresh --seed \ + && php artisan passport:install \ + && chown -R www-data:www-data /opt/firefly-iii \ + && mkdir -p /run/php + +### WAIT +COPY ./pause /xfer/ +RUN cd /xfer && gcc main.c -o /xfer/pauser + +### CONFIG +COPY ./env /opt/firefly-iii/.env +COPY ./firefly-iii.conf /etc/nginx/sites-enabled/ + +RUN apt -y autoremove \ + && apt -y purge --auto-remove gcc curl \ + && rm -rf /var/lib/apt \ + && apt clean + +### CRON +RUN echo \ + 'lastback="$(find /mnt/back/ -maxdepth 1 -mindepth 1 | sort | tail -n 1)"; ' \ + 'mkdir -p $lastback/inc; ' \ + 'thisback="$lastback/inc/$(date -u +%Y%m%d%H%M)/"; ' \ + 'rm -rf $thisback; ' \ + 'mariabackup --backup --target-dir="$thisback" --user root --password=pwd --incremental-basedir $lastback/full; ' \ + > /backup-inc.sh \ + && echo \ + 'set -e; ' \ + 'service mysql start; ' \ + 'thisback="/mnt/back/$(date -u +%Y%m%d)"/full; ' \ + 'mkdir -p $thisback; ' \ + 'rm -rf "$(dirname "$thisback")"; ' \ + 'mkdir -p "$(dirname "$thisback")"; ' \ + 'mariabackup --backup --target-dir="$thisback" --user=root --password=pwd; ' \ + > /backup.sh \ + && echo \ + 'set -e; ' \ + 'rm -rf /var/lib/mysql-old; ' \ + 'mkdir -p /mnt/back; ' \ + 'lastback="$(find /mnt/back/ -maxdepth 1 -mindepth 1 | sort | tail -n 1)"; ' \ + 'if [ -z "$lastback" ]; then exit 0; fi; ' \ + 'service mysql stop || true; ' \ + 'restoring=/tmp/restoring; ' \ + 'cp -r "${lastback}/full" "$restoring"; ' \ + 'mariabackup --prepare --target-dir="$restoring" --user=root --password=pwd --apply-log-only || true; ' \ + 'inc_back="$(find $lastback/inc/ -maxdepth 1 -mindepth 1 | sort | tail -n 1)"; ' \ + 'echo --- inc restore $inc_back ---; ' \ + 'mariabackup --prepare --target-dir="$restoring" --user=root --password=pwd --incremental-dir "$inc_back" --apply-log-only || true; ' \ + 'mv /var/lib/mysql /var/lib/mysql-old; ' \ + 'mariabackup --copy-back --target-dir="$restoring" --user=root --password=pwd; ' \ + 'rm -rf "$restoring"; ' \ + 'chown -R mysql:mysql /var/lib/mysql; ' \ + 'service mysql start; ' \ + > /restore.sh \ + && echo '0 * * * * bash /backup-inc.sh >> /var/log/cronj.log 2>&1' > /etc/cron.d/backups \ + && echo '' >> /etc/cron.d/backups \ + && chmod 0644 /etc/cron.d/backups \ + && crontab /etc/cron.d/backups \ + && touch /var/log/cronj.log + +### on enter/exit, rsync to/from /var/lib/mysql and /mnt +ENTRYPOINT true \ + && bash /restore.sh \ + && bash /backup.sh \ + && for s in mysql nginx php7.2-fpm cron; do service $s restart ; done && sleep 10 \ + && exec /xfer/pauser diff --git a/firefly/ubuntu-old/build.sh b/firefly/ubuntu-old/build.sh new file mode 100755 index 0000000..261a8e0 --- /dev/null +++ b/firefly/ubuntu-old/build.sh @@ -0,0 +1,6 @@ +#! /bin/bash + +set -e + +docker build -t dev:dev . +docker run --rm -it -p 8031:8031 dev:dev diff --git a/firefly/ubuntu-old/env b/firefly/ubuntu-old/env new file mode 100755 index 0000000..98f8a5a --- /dev/null +++ b/firefly/ubuntu-old/env @@ -0,0 +1,102 @@ +# You can leave this on "local". If you change it to production most console commands will ask for extra confirmation. +# Never set it to "testing". +APP_ENV=local + +# Set to true if you want to see debug information in error screens. +APP_DEBUG=true + +# This should be your email address +SITE_OWNER=admin@email.com + +# The encryption key for your database and sessions. Keep this very secure. +# If you generate a new one all existing data must be considered LOST. +# Change it to a string of exactly 32 chars or use command `php artisan key:generate` to generate it +APP_KEY=11111111111111111111111111111111 + +# Change this value to your preferred time zone. +# Example: Europe/Amsterdam +TZ=America/Chicago + +# APP_URL and TRUSTED_PROXIES are useful when using Docker and/or a reverse proxy. +APP_URL=http://localhost +TRUSTED_PROXIES= + +# The log channel defines where your log entries go to. +LOG_CHANNEL=daily + +# Database credentials. Make sure the database exists. I recommend a dedicated user for Firefly III +# For other database types, please see the FAQ: http://firefly-iii.readthedocs.io/en/latest/support/faq.html +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=fireflyiii +DB_USERNAME=fireflyiii +DB_PASSWORD=pwd + +# 'daily' is the default logging mode giving you 5 daily rotated log files in /storage/logs/. +# Several other options exist. You can use 'single' for one big fat error log (not recommended). +# Also available are 'syslog' and 'errorlog' which will log to the system itself. +APP_LOG=daily + +# Log level. You can set this from least severe to most severe: +# debug, info, notice, warning, error, critical, alert, emergency +# If you set it to debug your logs will grow large, and fast. If you set it to emergency probably +# nothing will get logged, ever. +APP_LOG_LEVEL=notice + +# If you're looking for performance improvements, you could install memcached. +CACHE_DRIVER=file +SESSION_DRIVER=file + +# Cookie settings. Should not be necessary to change these. +COOKIE_PATH="/" +COOKIE_DOMAIN= +COOKIE_SECURE=false + +# If you want Firefly III to mail you, update these settings +MAIL_DRIVER=smtp +MAIL_HOST=smtp.server.com +MAIL_PORT=587 +MAIL_FROM= +MAIL_USERNAME= +MAIL_PASSWORD= +MAIL_ENCRYPTION=tls + +# Firefly III can send you the following messages +SEND_REGISTRATION_MAIL=true +SEND_ERROR_MESSAGE=true + +# Set a Mapbox API key here (see mapbox.com) so there might be a map available at various places. +MAPBOX_API_KEY= + +# Set a Fixer IO API key here (see https://fixer.io) to enable live currency exchange rates. +# Please note that this will only work for paid fixer.io accounts because they severly limited +# the free API up to the point where you might as well offer nothing. +FIXER_API_KEY= + +# If you wish to track your own behavior over Firefly III, set a valid analytics tracker ID here. +ANALYTICS_ID= + +# Most parts of the database are encrypted by default, but you can turn this off if you want to. +# This makes it easier to migrate your database. Not that some fields will never be decrypted. +USE_ENCRYPTION=true + +# Leave the following configuration vars as is. +# Unless you like to tinker and know what you're doing. +APP_NAME=FireflyIII +BROADCAST_DRIVER=log +QUEUE_DRIVER=sync +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 +CACHE_PREFIX=firefly +SEARCH_RESULT_LIMIT=50 +PUSHER_KEY= +PUSHER_SECRET= +PUSHER_ID= +DEMO_USERNAME= +DEMO_PASSWORD= +IS_DOCKER=true +IS_SANDSTORM=false +BUNQ_USE_SANDBOX=false +IS_HEROKU=false diff --git a/firefly/ubuntu-old/firefly-iii.conf b/firefly/ubuntu-old/firefly-iii.conf new file mode 100755 index 0000000..5ef095f --- /dev/null +++ b/firefly/ubuntu-old/firefly-iii.conf @@ -0,0 +1,29 @@ +server { + listen 8031; + listen [::]:8031; + + root /opt/firefly-iii/public; + + # Add index.php to the list if you are using PHP + client_max_body_size 300M; + index index.html index.htm index.php; + + # Load configuration files for the default server block. + include /etc/nginx/default.d/*.conf; + location ~ \.php$ { + try_files $uri =404; + fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + + } + + index index.php index.htm index.html; + + location / { + try_files $uri $uri/ /index.php?$query_string; + autoindex on; + sendfile off; + } +} diff --git a/firefly/ubuntu-old/pause/main.c b/firefly/ubuntu-old/pause/main.c new file mode 100755 index 0000000..3528e94 --- /dev/null +++ b/firefly/ubuntu-old/pause/main.c @@ -0,0 +1,20 @@ +#include +#include +#include + +int main() { + int stat; + int sig; + sigset_t set; + sigemptyset(&set); + printf("add signal SIGINT: %i\n", sigaddset(&set, SIGINT)); + printf("add signal SIGKILL: %i\n", sigaddset(&set, SIGKILL)); + printf("add signal SIGTERM: %i\n", sigaddset(&set, SIGTERM)); + sigprocmask(SIG_BLOCK, &set, NULL); + printf("Waiting...\n"); + stat = sigwait(&set, &sig); + printf("Wait complete: %i (%i)\n", sig, stat); + printf("Backed incremental: %i\n", system("bash /backup-inc.sh")); + printf("Stopped mysql: %i\n", system("mysqladmin shutdown -ppwd")); + return 0; +} diff --git a/firefly/ubuntu-old/script.sh b/firefly/ubuntu-old/script.sh new file mode 100755 index 0000000..4d3adb2 --- /dev/null +++ b/firefly/ubuntu-old/script.sh @@ -0,0 +1,50 @@ +#! /bin/bash + +set -e +set -u + +apt -y update && apt -y upgrade && apt -y autoremove +DEBIAN_FRONTEND=noninteractive apt -y install tzdata +apt -y install vim locales language-pack-en-base + +echo '127.0.0.1 firefly-iii-domain.com firefly-iii localhost' >> /etc/hosts + +apt -y install fail2ban + +apt -y install mariadb-server nginx php-fpm php7.2-mysql php-curl php-gd php-bcmath php-zip php-intl php-mbstring php-xml + +service mysql start +echo 'FLUSH PRIVILEGES; ' \ + 'USE mysql; ' \ + 'UPDATE user SET authentication_string=PASSWORD("pwd") WHERE User='"'"'root'"'"'; ' \ + 'UPDATE user SET plugin="mysql_native_password" WHERE User='"'"'root'"'"'; ' \ + | mysql -u root || true +service mysql restart +sleep 5 + +echo 'create database fireflyiii character set utf8 collate utf8_bin; ' \ + 'grant all privileges on fireflyiii.* to fireflyiii@localhost identified by '"'"'pwd'"'"'; ' \ + | mysql -uroot -ppwd +service mysql restart + +apt -y install curl +curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + +cd /opt +composer create-project grumpydictator/firefly-iii --no-dev --prefer-dist firefly-iii 4.7.4 + +cp /copied/env /opt/firefly-iii/.env + +cd firefly-iii +php artisan migrate:refresh --seed +php artisan passport:install + +chown -R www-data:www-data /opt/firefly-iii/ + +rm /etc/nginx/sites-enabled/default +touch /etc/nginx/sites-available/firefly-iii.conf +ln -s /etc/nginx/sites-available/firefly-iii.conf /etc/nginx/sites-enabled/firefly-iii.conf +openssl dhparam 2048 > /etc/nginx/dhparam.pem +cp /copied/firefly-iii.conf /etc/nginx/sites-enabled/firefly-iii.conf + +mkdir -p /run/php diff --git a/ledger/cli/Dockerfile b/ledger/cli/Dockerfile new file mode 100755 index 0000000..b31e69e --- /dev/null +++ b/ledger/cli/Dockerfile @@ -0,0 +1,6 @@ +FROM dcycle/ledger:1 + +RUN touch /tmp/test + +#CMD [] +#ENTRYPOINT ["./ledger", "-f", "/tmp/test", "reg"] diff --git a/mizzer/economizzer b/mizzer/economizzer new file mode 100755 index 0000000..6efa10d --- /dev/null +++ b/mizzer/economizzer @@ -0,0 +1,23 @@ +FROM centos:7.5.1804 + +RUN yum install -y epel-release yum-utils \ + && yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm \ + && yum-config-manager --enable remi-php72 \ + && yum install -y php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd + +RUN yum install -y libapache2-mod-php php-mbstring php-xml git unzip + +RUN cd / \ + && curl -sS https://getcomposer.org/installer \ + | php + +RUN yum install -y php-pecl-zip + +RUN cd / \ + && git clone https://github.com/gugoan/economizzer.git \ + && ls \ + && cd /economizzer \ + && php /composer.phar global require "fxp/composer-asset-plugin:^1.3.1" phpoffice/phpspreadsheet ext-zip kartik-v/yii2-export \ + && php /composer.phar install + +ENTRYPOINT ["bash"] diff --git a/mizzer/economizzer-build.sh b/mizzer/economizzer-build.sh new file mode 100755 index 0000000..c4243ca --- /dev/null +++ b/mizzer/economizzer-build.sh @@ -0,0 +1,3 @@ +#! /bin/bash +cd "$(dirname "${BASH_SOURCE[0]}")" +docker build -f economizzer -t dev:dev . diff --git a/silverstrike/.Dockerfile b/silverstrike/.Dockerfile new file mode 100755 index 0000000..a1b4edd --- /dev/null +++ b/silverstrike/.Dockerfile @@ -0,0 +1,46 @@ +FROM ubuntu:18.04 as builder + +### SYS +RUN export DEBIAN_FRONTEND=noninteractive; \ + apt -y update || true; \ + apt -y install tzdata; \ + ln -fs /usr/share/zoneinfo/America/Denver /etc/localtime; \ + dpkg-reconfigure --frontend noninteractive tzdata; \ + apt -y install \ + curl \ + rsync \ + cron \ + postgresql postgresql-contrib \ + && mkdir -p /mnt/save + +### APP +RUN \ + apt install nginx postgresql uwsgi uwsgi-plugin-python3 python3-venv git + +### POSTGRES +RUN useradd -d /home/postgres -ms /bin/bash -g postgres -G sudo postgres +USER postgres +RUN service postgresql start && sleep 10 \ + && psql --command "CREATE USER ss WITH SUPERUSER PASSWORD 'ss';" \ + && createdb -O ss ss \ + && psql --command "CREATE DATABASE silverstrikedb;" \ + && psql --command "GRANT ALL PRIVILEGES ON DATABASE silverstrikedb TO ss;" +USER root + +### CRON BACKUPS +RUN true \ + && echo 'b=$(date +%Y%m%d%H%M%S) && mkdir -p /mnt/save/$b && pg_dump $DATABASE_URL --clean > /mnt/save/$b/pg.dump' > /backup.sh \ + && echo 'b=$(find /mnt/save -type f | sort | tail -n 1); if [ -n "$b" ]; then echo restoring $b; psql $DATABASE_URL < "$b"; fi && service postgresql start;' > /restore.sh \ + && echo '0 4,8,12,16,20 * * * bash /backup.sh >> /var/log/cronj.log 2>&1' > /etc/cron.d/backups \ + && echo '' >> /etc/cron.d/backups \ + && chmod 0644 /etc/cron.d/backups \ + && touch /var/log/cronj.log + +### FINAL +ENV DATABASE_URL=postgres://ss:ss@localhost/silverstrikedb?sslmode=disable +ENV SECRET_KEY=AimmBfzjdWcVN3rQs8YawbUowv5R8Eex +ENV ALLOWED_HOSTS=* +ENTRYPOINT \ + until psql $DATABASE_URL < /dev/null; do sleep 5; done \ + && bash /restore.sh \ + && sleep 5 && python manage.py migrate && exec uwsgi diff --git a/silverstrike/fork/.dockerignore b/silverstrike/fork/.dockerignore new file mode 100755 index 0000000..a6ca656 --- /dev/null +++ b/silverstrike/fork/.dockerignore @@ -0,0 +1,2 @@ +Dockerfile +**/*.sw* diff --git a/silverstrike/fork/Dockerfile b/silverstrike/fork/Dockerfile new file mode 100755 index 0000000..580658c --- /dev/null +++ b/silverstrike/fork/Dockerfile @@ -0,0 +1,42 @@ +FROM ubuntu:18.04 + +# Copy the code +ADD . /code +WORKDIR /code + +# install deps +RUN apt-get update && apt-get install -y gcc libmariadbclient-dev python3-dev python3-pip && \ + pip3 install --no-cache-dir -r requirements.txt && \ + apt-get remove -y gcc && apt-get autoremove -y + +# configure django +ENV DJANGO_SETTINGS_MODULE=settings + +# configure uwsgi +ENV UWSGI_WSGI_FILE=wsgi.py UWSGI_HTTP=:8000 UWSGI_MASTER=1 UWSGI_WORKERS=2 UWSGI_THREADS=8 UWSGI_UID=1000 UWSGI_GID=2000 UWSGI_LAZY_APPS=1 UWSGI_WSGI_ENV_BEHAVIOR=holy + +# collect static files +RUN python3 manage.py collectstatic + +#### POSTGRES +RUN \ + apt -y install \ + curl \ + rsync \ + cron \ + postgresql postgresql-contrib \ + sudo \ + && mkdir -p /mnt/save \ + && service postgresql start +USER postgres +RUN service postgresql start \ + && psql --command "CREATE USER ss WITH SUPERUSER PASSWORD 'ss';" \ + && psql --command "CREATE DATABASE silverstrikedb;" \ + && psql --command "GRANT ALL PRIVILEGES ON DATABASE silverstrikedb TO ss;" +USER root + +ENV ALLOWED_HOSTS=* +ENV DATABASE_URL=postgres://ss:ss@localhost/silverstrikedb +ENV SECRET_KEY=AimmBfzjdWcVN3rQs8YawbUowv5R8Eex + +CMD service postgresql start && (until psql $DATABASE_URL < /dev/null; do sleep 5; done) && python3 manage.py migrate && uwsgi diff --git a/silverstrike/fork/LICENSE b/silverstrike/fork/LICENSE new file mode 100755 index 0000000..b5430f8 --- /dev/null +++ b/silverstrike/fork/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 - 2018 Simon Hanna + +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. diff --git a/silverstrike/fork/docker-compose.yml b/silverstrike/fork/docker-compose.yml new file mode 100755 index 0000000..4b97573 --- /dev/null +++ b/silverstrike/fork/docker-compose.yml @@ -0,0 +1,21 @@ +--- +version: "3.2" +services: + app: + environment: + - ALLOWED_HOSTS='*' + - DATABASE_URL=postgres://silverstrike:secretpass@database/silverstrikedb + - SECRET_KEY=PLprXpLzxemgLD57GPQQ84SBZdLVKFYg + image: simhnna/silverstrike + links: + - database:database + ports: + - 8000:8000 + database: + environment: + POSTGRES_DB: silverstrikedb + POSTGRES_USER: silverstrike + POSTGRES_PASSWORD: secretpass + image: postgres:10.3 + volumes: + - ./silverstrikedb:/var/lib/postgresql/data diff --git a/silverstrike/fork/manage.py b/silverstrike/fork/manage.py new file mode 100755 index 0000000..7646e46 --- /dev/null +++ b/silverstrike/fork/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/silverstrike/fork/master.zip b/silverstrike/fork/master.zip new file mode 100755 index 0000000..c021b41 Binary files /dev/null and b/silverstrike/fork/master.zip differ diff --git a/silverstrike/fork/requirements.txt b/silverstrike/fork/requirements.txt new file mode 100755 index 0000000..3580b94 --- /dev/null +++ b/silverstrike/fork/requirements.txt @@ -0,0 +1,6 @@ +silverstrike +whitenoise +uwsgi +psycopg2-binary +dj-database-url +mysqlclient diff --git a/silverstrike/fork/settings.py b/silverstrike/fork/settings.py new file mode 100755 index 0000000..90059c2 --- /dev/null +++ b/silverstrike/fork/settings.py @@ -0,0 +1,163 @@ +""" +Django settings for demo project. + +Generated by 'django-admin startproject' using Django 1.10.3. + +For more information on this file, see +https://docs.djangoproject.com/en/1.10/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.10/ref/settings/ +""" + +import os + +import dj_database_url + + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = os.environ.get('SECRET_KEY', 'PLprXpLzxemgLD57GPQQ84SBZdLVKFYg') + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = False + +ALLOWED_HOSTS = ['*'] + +SITE_ID = 1 + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.humanize', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'django.contrib.sites', + 'widget_tweaks', + 'silverstrike', + 'allauth', + 'allauth.account', + 'rest_framework', + 'rest_framework.authtoken' +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.locale.LocaleMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.10/ref/settings/#databases + +DATABASES = { + 'default': dj_database_url.config(conn_max_age=600) +} + + + +# Password validation +# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + +AUTHENTICATION_BACKENDS = ( + 'django.contrib.auth.backends.ModelBackend', + 'allauth.account.auth_backends.AuthenticationBackend', +) + + +# Internationalization +# https://docs.djangoproject.com/en/1.10/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.10/howto/static-files/ + +STATIC_URL = '/static/' +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' +STATIC_ROOT = os.path.join(BASE_DIR, 'static') + + +LOGIN_REDIRECT_URL = 'index' +LOGIN_URL = 'account_login' +LOGOUT_URL = 'account_logout' +ACCOUNT_LOGOUT_REDIRECT_URL = 'account_login' +ACCOUNT_ADAPTER = 'signupadapter.SignupDisabledAdapter' + +# Uncomment to prevent signup +# ACCOUNT_ADAPTER = 'silverstrike.models.SignupDisabledAdapter' + +REST_FRAMEWORK = { + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.IsAuthenticated' + ], + 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', + 'PAGE_SIZE': 10, + 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework.authentication.BasicAuthentication', + 'rest_framework.authentication.SessionAuthentication', + 'rest_framework.authentication.TokenAuthentication' + ) +} + diff --git a/silverstrike/fork/signupadapter.py b/silverstrike/fork/signupadapter.py new file mode 100755 index 0000000..bf2baad --- /dev/null +++ b/silverstrike/fork/signupadapter.py @@ -0,0 +1,6 @@ +from allauth.account.adapter import DefaultAccountAdapter + + +class SignupDisabledAdapter(DefaultAccountAdapter): + def is_open_for_signup(self, request): + return False diff --git a/silverstrike/fork/urls.py b/silverstrike/fork/urls.py new file mode 100755 index 0000000..ab0cfd3 --- /dev/null +++ b/silverstrike/fork/urls.py @@ -0,0 +1,9 @@ +from django.contrib import admin +from django.urls import path, include +from django.views.generic import RedirectView + + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('silverstrike.urls')), +] diff --git a/silverstrike/fork/wsgi.py b/silverstrike/fork/wsgi.py new file mode 100755 index 0000000..51ec7e3 --- /dev/null +++ b/silverstrike/fork/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for demo project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") + +application = get_wsgi_application() diff --git a/silverstrike/scratch/Dockerfile b/silverstrike/scratch/Dockerfile new file mode 100755 index 0000000..dbe3a6f --- /dev/null +++ b/silverstrike/scratch/Dockerfile @@ -0,0 +1,66 @@ +FROM ubuntu:18.04 as builder + +### SYS +RUN export DEBIAN_FRONTEND=noninteractive; \ + apt -y update || true; \ + apt -y install tzdata; \ + ln -fs /usr/share/zoneinfo/America/Denver /etc/localtime; \ + dpkg-reconfigure --frontend noninteractive tzdata; \ + apt -y install \ + curl \ + rsync \ + cron \ + postgresql postgresql-contrib \ + && mkdir -p /mnt/save + +### POSTGRES +RUN apt -y install sudo \ + && service postgresql start +USER postgres +RUN service postgresql start \ + && createuser www-data \ + && createdb -O www-data silverstrikedb + + #&& psql --command "CREATE USER ss WITH SUPERUSER PASSWORD 'ss';" \ + #&& psql --command "CREATE DATABASE silverstrikedb;" \ + #&& psql --command "GRANT ALL PRIVILEGES ON DATABASE silverstrikedb TO ss;" + +USER root + +### APP +RUN \ + apt -y install nginx postgresql uwsgi uwsgi-plugin-python git python-pip python python-psycopg2 libpq-dev python-dev \ + && pip install venv \ + && mkdir -p /srv/webapps \ + && cd /srv/webapps \ + && git clone https://github.com/agstrike/production-project silverstrike \ + && cd silverstrike \ + && python -m venv env \ + && . env/bin/activate \ + && pip3 install silverstrike psycopg2 django +COPY settings.py /srv/webapps/silverstrike/ +RUN \ + cd /srv/webapps/silverstrike \ + && service postgresql start \ + && python manage.py migrate \ + && python manage.py collectstatic \ + && ln -s /srv/webapps/silverstrike/uwsgi.ini /etc/uwsgi/apps-enabled/silverstrike.ini \ + && service uwsgi start + +### CRON BACKUPS +RUN true \ + && echo 'b=$(date +%Y%m%d%H%M%S) && mkdir -p /mnt/save/$b && pg_dump $DATABASE_URL --clean > /mnt/save/$b/pg.dump' > /backup.sh \ + && echo 'b=$(find /mnt/save -type f | sort | tail -n 1); if [ -n "$b" ]; then echo restoring $b; psql $DATABASE_URL < "$b"; fi && service postgresql start;' > /restore.sh \ + && echo '0 4,8,12,16,20 * * * bash /backup.sh >> /var/log/cronj.log 2>&1' > /etc/cron.d/backups \ + && echo '' >> /etc/cron.d/backups \ + && chmod 0644 /etc/cron.d/backups \ + && touch /var/log/cronj.log + +### FINAL +ENV DATABASE_URL=postgres://www-data:password@localhost/silverstrikedb?sslmode=disable +ENV SECRET_KEY=AimmBfzjdWcVN3rQs8YawbUowv5R8Eex +ENV ALLOWED_HOSTS=* +ENTRYPOINT \ + until psql $DATABASE_URL < /dev/null; do sleep 5; done \ + && bash /restore.sh \ + && sleep 5 && python manage.py migrate && exec uwsgi diff --git a/silverstrike/scratch/settings.py b/silverstrike/scratch/settings.py new file mode 100755 index 0000000..4b51dcd --- /dev/null +++ b/silverstrike/scratch/settings.py @@ -0,0 +1,178 @@ +""" +Django settings for SilverStrike. + +Generated by 'django-admin startproject' using Django 1.10.3. + +For more information on this file, see +https://docs.djangoproject.com/en/1.10/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.10/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'AimmBfzjdWcVN3rQs8YawbUowv5R8Eex' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [ + "192.168.0.86", + "firefly2.scratch.com", + "silverstrike.scratch.com", +] + +SITE_ID = 1 + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.humanize', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'django.contrib.sites', + 'widget_tweaks', + 'silverstrike', + 'allauth', + 'allauth.account', + 'allauth.socialaccount', + 'rest_framework', + 'rest_framework.authtoken', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.locale.LocaleMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.10/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } + #'default': { + # 'ENGINE': 'django.db.backends.postgresql_psycopg2', + # 'NAME': 'silverstrikedb', + # 'USER': 'www-data', + # 'PASSWORD': 'password', + #} + #'default': { + # 'ENGINE': 'django.db.backends.mysql', + # 'NAME': 'silverstrikedb', + # 'USER': 'silverstrike', + # 'PASSWORD': 'password', + #} +} + + +# Password validation +# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + +AUTHENTICATION_BACKENDS = ( + 'django.contrib.auth.backends.ModelBackend', + 'allauth.account.auth_backends.AuthenticationBackend', +) + + +# Internationalization +# https://docs.djangoproject.com/en/1.10/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.10/howto/static-files/ + +STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'public', 'static') + + +LOGIN_REDIRECT_URL = 'index' +LOGIN_URL = 'account_login' +LOGOUT_URL = 'account_logout' +ACCOUNT_LOGOUT_REDIRECT_URL = 'account_login' + +ACCOUNT_ADAPTER = 'signupadapter.SignupDisabledAdapter' + +LOGGING = { + 'version': 1, + 'filters': { + 'require_debug_true': { + '()': 'django.utils.log.RequireDebugTrue', + } + }, + 'handlers': { + 'console': { + 'level': 'DEBUG', + 'filters': ['require_debug_true'], + 'class': 'logging.StreamHandler', + } + } +} + diff --git a/silverstrike/scratch/try b/silverstrike/scratch/try new file mode 100755 index 0000000..9bdfcac --- /dev/null +++ b/silverstrike/scratch/try @@ -0,0 +1 @@ +docker build -t bel/silverstrike:v0.0 -f Dockerfile . && docker run --rm -it --name ss -p 51131:8000 --entrypoint bash bel/silverstrike:v0.0