Compare commits
	
		
			No commits in common. "main" and "repo-hiding" have entirely different histories.
		
	
	
		
			main
			...
			repo-hidin
		
	
		
|  | @ -1,63 +0,0 @@ | ||||||
| # Generated by Django 4.0.6 on 2022-10-05 18:27 |  | ||||||
| 
 |  | ||||||
| from django.db import migrations, models |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| class Migration(migrations.Migration): |  | ||||||
| 
 |  | ||||||
|     dependencies = [ |  | ||||||
|         ('borg', '0003_label_visible'), |  | ||||||
|     ] |  | ||||||
| 
 |  | ||||||
|     operations = [ |  | ||||||
|         migrations.AlterField( |  | ||||||
|             model_name='archive', |  | ||||||
|             name='compressed_size', |  | ||||||
|             field=models.BigIntegerField(), |  | ||||||
|         ), |  | ||||||
|         migrations.AlterField( |  | ||||||
|             model_name='archive', |  | ||||||
|             name='deduplicated_size', |  | ||||||
|             field=models.BigIntegerField(), |  | ||||||
|         ), |  | ||||||
|         migrations.AlterField( |  | ||||||
|             model_name='archive', |  | ||||||
|             name='file_count', |  | ||||||
|             field=models.BigIntegerField(), |  | ||||||
|         ), |  | ||||||
|         migrations.AlterField( |  | ||||||
|             model_name='archive', |  | ||||||
|             name='original_size', |  | ||||||
|             field=models.BigIntegerField(), |  | ||||||
|         ), |  | ||||||
|         migrations.AlterField( |  | ||||||
|             model_name='cache', |  | ||||||
|             name='total_chunks', |  | ||||||
|             field=models.BigIntegerField(), |  | ||||||
|         ), |  | ||||||
|         migrations.AlterField( |  | ||||||
|             model_name='cache', |  | ||||||
|             name='total_csize', |  | ||||||
|             field=models.BigIntegerField(), |  | ||||||
|         ), |  | ||||||
|         migrations.AlterField( |  | ||||||
|             model_name='cache', |  | ||||||
|             name='total_size', |  | ||||||
|             field=models.BigIntegerField(), |  | ||||||
|         ), |  | ||||||
|         migrations.AlterField( |  | ||||||
|             model_name='cache', |  | ||||||
|             name='total_unique_chunks', |  | ||||||
|             field=models.BigIntegerField(), |  | ||||||
|         ), |  | ||||||
|         migrations.AlterField( |  | ||||||
|             model_name='cache', |  | ||||||
|             name='unique_csize', |  | ||||||
|             field=models.BigIntegerField(), |  | ||||||
|         ), |  | ||||||
|         migrations.AlterField( |  | ||||||
|             model_name='cache', |  | ||||||
|             name='unique_size', |  | ||||||
|             field=models.BigIntegerField(), |  | ||||||
|         ), |  | ||||||
|     ] |  | ||||||
|  | @ -8,9 +8,9 @@ class Archive(models.Model): | ||||||
|     name = models.TextField() |     name = models.TextField() | ||||||
|     start = models.DateTimeField() |     start = models.DateTimeField() | ||||||
|     end = models.DateTimeField() |     end = models.DateTimeField() | ||||||
|     file_count = models.BigIntegerField() |     file_count = models.IntegerField() | ||||||
|     original_size = models.BigIntegerField() |     original_size = models.IntegerField() | ||||||
|     compressed_size = models.BigIntegerField() |     compressed_size = models.IntegerField() | ||||||
|     deduplicated_size = models.BigIntegerField() |     deduplicated_size = models.IntegerField() | ||||||
|     cache = models.OneToOneField(Cache, on_delete=models.CASCADE) |     cache = models.OneToOneField(Cache, on_delete=models.CASCADE) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,9 +2,9 @@ from django.db import models | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Cache(models.Model): | class Cache(models.Model): | ||||||
|     total_chunks = models.BigIntegerField() |     total_chunks = models.IntegerField() | ||||||
|     total_csize = models.BigIntegerField() |     total_csize = models.IntegerField() | ||||||
|     total_size = models.BigIntegerField() |     total_size = models.IntegerField() | ||||||
|     total_unique_chunks = models.BigIntegerField() |     total_unique_chunks = models.IntegerField() | ||||||
|     unique_csize = models.BigIntegerField() |     unique_csize = models.IntegerField() | ||||||
|     unique_size = models.BigIntegerField() |     unique_size = models.IntegerField() | ||||||
|  |  | ||||||
|  | @ -102,7 +102,7 @@ class Repo(models.Model): | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def series_csize(archives, units=None): |     def series_csize(archives, units=None): | ||||||
|         return [convert_bytes(archive.cache.unique_csize, units)[0] |         return [convert_bytes(archive.cache.unique_csize, units)[0] | ||||||
|                 if archive is not None else 0 for archive in archives] |                 if archive is not None else None for archive in archives] | ||||||
| 
 | 
 | ||||||
|     def hourly_archive_string(self): |     def hourly_archive_string(self): | ||||||
|         return ''.join(['H' if archive is not None else '-' for archive in self.hourly_archives(8)]) |         return ''.join(['H' if archive is not None else '-' for archive in self.hourly_archives(8)]) | ||||||
|  |  | ||||||
|  | @ -3,14 +3,10 @@ from django.http import HttpResponseRedirect | ||||||
| 
 | 
 | ||||||
| from django.urls import reverse | from django.urls import reverse | ||||||
| from django.contrib.auth.decorators import permission_required | from django.contrib.auth.decorators import permission_required | ||||||
| from django.core.cache import cache as django_cache | from django.core.cache import cache | ||||||
| from ..models import Repo, Label, Archive, Cache, Error, Location | from ..models import Repo, Label, Archive, Cache, Error, Location | ||||||
| from ..forms import RepoForm, ArchiveForm, ErrorForm, LocationForm, ToggleVisibility | from ..forms import RepoForm, ArchiveForm, ErrorForm, LocationForm, ToggleVisibility | ||||||
| 
 | 
 | ||||||
| import logging |  | ||||||
| 
 |  | ||||||
| logger = logging.getLogger(__file__) |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| @permission_required("borg.change_repo") | @permission_required("borg.change_repo") | ||||||
| def toggle_visibility(request): | def toggle_visibility(request): | ||||||
|  | @ -24,7 +20,7 @@ def toggle_visibility(request): | ||||||
|             label.visible = not label.visible |             label.visible = not label.visible | ||||||
| 
 | 
 | ||||||
|             label.save() |             label.save() | ||||||
|             django_cache.clear() |             cache.clear() | ||||||
| 
 | 
 | ||||||
|             return HttpResponseRedirect(reverse('index')) |             return HttpResponseRedirect(reverse('index')) | ||||||
|     else: |     else: | ||||||
|  | @ -53,7 +49,7 @@ def post_repo(request): | ||||||
|                                                                         'last_modified': cdata['last_modified'], |                                                                         'last_modified': cdata['last_modified'], | ||||||
|                                                                         'label': label}) |                                                                         'label': label}) | ||||||
|             repo.save() |             repo.save() | ||||||
|             django_cache.clear() |             cache.clear() | ||||||
| 
 | 
 | ||||||
|             return HttpResponseRedirect(reverse('index')) |             return HttpResponseRedirect(reverse('index')) | ||||||
|     else: |     else: | ||||||
|  | @ -67,7 +63,6 @@ def post_archive(request): | ||||||
|     if request.method == 'POST': |     if request.method == 'POST': | ||||||
|         form = ArchiveForm(request.POST) |         form = ArchiveForm(request.POST) | ||||||
|         if form.is_valid(): |         if form.is_valid(): | ||||||
|             try: |  | ||||||
|             cdata = form.cleaned_data |             cdata = form.cleaned_data | ||||||
| 
 | 
 | ||||||
|             repo = get_object_or_404(Repo, label__label=cdata['label']) |             repo = get_object_or_404(Repo, label__label=cdata['label']) | ||||||
|  | @ -83,9 +78,7 @@ def post_archive(request): | ||||||
| 
 | 
 | ||||||
|             archive = Archive(**archive_dict, repo=repo, cache=cache) |             archive = Archive(**archive_dict, repo=repo, cache=cache) | ||||||
|             archive.save() |             archive.save() | ||||||
|                 django_cache.clear() |             cache.clear() | ||||||
|             except Exception: |  | ||||||
|                 logger.exception("Archive post failed") |  | ||||||
| 
 | 
 | ||||||
|             return HttpResponseRedirect(reverse('index')) |             return HttpResponseRedirect(reverse('index')) | ||||||
|     else: |     else: | ||||||
|  | @ -104,7 +97,7 @@ def post_error(request): | ||||||
| 
 | 
 | ||||||
|             error = Error(label=label, error=cdata['error'], time=cdata['time']) |             error = Error(label=label, error=cdata['error'], time=cdata['time']) | ||||||
|             error.save() |             error.save() | ||||||
|             django_cache.clear() |             cache.clear() | ||||||
| 
 | 
 | ||||||
|             return HttpResponseRedirect(reverse('index')) |             return HttpResponseRedirect(reverse('index')) | ||||||
|     else: |     else: | ||||||
|  | @ -122,7 +115,7 @@ def post_location(request): | ||||||
|             label, _ = Location.objects.get_or_create(label=cdata['label'], |             label, _ = Location.objects.get_or_create(label=cdata['label'], | ||||||
|                                                       defaults={"path": cdata["path"]}) |                                                       defaults={"path": cdata["path"]}) | ||||||
|             label.save() |             label.save() | ||||||
|             django_cache.clear() |             cache.clear() | ||||||
| 
 | 
 | ||||||
|             return HttpResponseRedirect(reverse('index')) |             return HttpResponseRedirect(reverse('index')) | ||||||
|     else: |     else: | ||||||
|  |  | ||||||
|  | @ -1 +1 @@ | ||||||
| from .secrets import SECRET_KEY, DATABASE_PASSWORD | from .secrets import SECRET_KEY | ||||||
|  |  | ||||||
|  | @ -2,7 +2,6 @@ import os | ||||||
| from pathlib import Path | from pathlib import Path | ||||||
| 
 | 
 | ||||||
| from . import SECRET_KEY as __SECRET_KEY | from . import SECRET_KEY as __SECRET_KEY | ||||||
| from . import DATABASE_PASSWORD as __DATABASE_PASSWORD |  | ||||||
| 
 | 
 | ||||||
| BASE_DIR = Path(__file__).resolve().parent.parent | BASE_DIR = Path(__file__).resolve().parent.parent | ||||||
| 
 | 
 | ||||||
|  | @ -10,11 +9,9 @@ SECRET_KEY = __SECRET_KEY | ||||||
| 
 | 
 | ||||||
| DEBUG = False | DEBUG = False | ||||||
| 
 | 
 | ||||||
| AXES_META_PRECEDENCE_ORDER = ('HTTP_X_FORWARDED_FOR', 'X_FORWARDED_FOR', 'REMOTE_ADDR') |  | ||||||
| 
 |  | ||||||
| AXES_LOCKOUT_CALLABLE = "borg.views.axes" | AXES_LOCKOUT_CALLABLE = "borg.views.axes" | ||||||
| 
 | 
 | ||||||
| ALLOWED_HOSTS = ['127.0.0.1', 'borg.george.ooo', 'george.ooo', 'www.george.ooo', '10.10.10.100', 'proxy.george.ooo'] | ALLOWED_HOSTS = ['127.0.0.1', 'borg.george.ooo', 'george.ooo', 'www.george.ooo'] | ||||||
| 
 | 
 | ||||||
| AUTHENTICATION_BACKENDS = [ | AUTHENTICATION_BACKENDS = [ | ||||||
|     'axes.backends.AxesBackend', |     'axes.backends.AxesBackend', | ||||||
|  | @ -68,12 +65,8 @@ WSGI_APPLICATION = 'borgweb.wsgi.application' | ||||||
| 
 | 
 | ||||||
| DATABASES = { | DATABASES = { | ||||||
|     'default': { |     'default': { | ||||||
|         'ENGINE': 'django.db.backends.postgresql_psycopg2', |         'ENGINE': 'django.db.backends.sqlite3', | ||||||
|         'NAME': 'borgweb', |         'NAME': "/home/web/sites/db/borg.db", | ||||||
|         'USER': 'borgweb', |  | ||||||
|         'PASSWORD': __DATABASE_PASSWORD, |  | ||||||
|         'HOST': 'db.george.ooo', |  | ||||||
|         'PORT': '5432', |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -127,7 +120,7 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' | ||||||
| CACHES = { | CACHES = { | ||||||
|     "default": { |     "default": { | ||||||
|         "BACKEND": "django_redis.cache.RedisCache", |         "BACKEND": "django_redis.cache.RedisCache", | ||||||
|         "LOCATION": "redis://cache.george.ooo:6379/1", |         "LOCATION": "redis://127.0.0.1:6379/1", | ||||||
|         "OPTIONS": { |         "OPTIONS": { | ||||||
|             "CLIENT_CLASS": "django_redis.client.DefaultClient" |             "CLIENT_CLASS": "django_redis.client.DefaultClient" | ||||||
|         }, |         }, | ||||||
|  | @ -135,36 +128,6 @@ CACHES = { | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| LOGGING = { |  | ||||||
|     "version": 1, |  | ||||||
|     "disable_existing_loggers": False, |  | ||||||
|     "root": {"level": "INFO", "handlers": ["file"]}, |  | ||||||
|     "handlers": { |  | ||||||
|         "file": { |  | ||||||
|             "level": "INFO", |  | ||||||
|             "class": "logging.FileHandler", |  | ||||||
|             "filename": "/var/log/django/borgweb.log", |  | ||||||
|             "formatter": "app", |  | ||||||
|         }, |  | ||||||
|     }, |  | ||||||
|     "loggers": { |  | ||||||
|         "django": { |  | ||||||
|             "handlers": ["file"], |  | ||||||
|             "level": "INFO", |  | ||||||
|             "propagate": True |  | ||||||
|         }, |  | ||||||
|     }, |  | ||||||
|     "formatters": { |  | ||||||
|         "app": { |  | ||||||
|             "format": ( |  | ||||||
|                 u"%(asctime)s [%(levelname)-8s] " |  | ||||||
|                 "(%(module)s.%(funcName)s) %(message)s" |  | ||||||
|             ), |  | ||||||
|             "datefmt": "%Y-%m-%d %H:%M:%S", |  | ||||||
|         }, |  | ||||||
|     }, |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| # security | # security | ||||||
| SESSION_COOKIE_SECURE = True | SESSION_COOKIE_SECURE = True | ||||||
| SECURE_SSL_REDIRECT = True | SECURE_SSL_REDIRECT = True | ||||||
|  |  | ||||||
|  | @ -35,7 +35,7 @@ print_action "Installing pip packages, this may take a while..." | ||||||
| 
 | 
 | ||||||
| # install required pip packages | # install required pip packages | ||||||
| yes | python -m pip install --upgrade wheel | yes | python -m pip install --upgrade wheel | ||||||
| yes | python -m pip install django gunicorn django-libsass django-compressor django-axes django-redis psycopg2-binary | yes | python -m pip install django gunicorn django-libsass django-compressor django-axes django-redis | ||||||
| 
 | 
 | ||||||
| print_action "Setting up static files and database" | print_action "Setting up static files and database" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,9 +0,0 @@ | ||||||
| #!/usr/bin/env bash |  | ||||||
| 
 |  | ||||||
| cd "${0%/*}" |  | ||||||
| 
 |  | ||||||
| source ./venv/bin/activate |  | ||||||
| python ./manage.py collectstatic --noinput |  | ||||||
| python ./manage.py compress |  | ||||||
| python ./manage.py migrate --noinput |  | ||||||
| deactivate |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user