forked from Letstream/redr.me
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 586e201
Showing
41 changed files
with
1,092 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*/__pycache__ | ||
*/*/__pycache__ | ||
venv | ||
db.sqlite3 | ||
*/.vscode/* | ||
.env | ||
*.code-workspace | ||
**/migrations/* | ||
app/.env | ||
temp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
## Redr.me | Open Source URL Redirection Service focused on Anonymity | ||
An Open Source and simple to Use Self Hosted Redirection Service made in Django focused on Anonymity. | ||
|
||
To use you can visit: https://redr.me/ | ||
|
||
## Requirements | ||
Make sure you have [Python](https://www.python.org/downloads/) and [Pip](https://pip.pypa.io/en/latest/installing/#installing-with-get-pip-py) installed. Python version >= 3.6 is required. | ||
|
||
The Project uses PostgreSQL >= 11 as Database Host. | ||
|
||
You also need Django, and other dependencies. These can be installed by running: | ||
|
||
``` | ||
pip install -r requirements.txt | ||
``` | ||
### Variables | ||
|
||
After you have installed the packages mentioned above, create an `.env` file at `app/settings/` or provide the following environment variables as available in `app/settings/sample.env` | ||
|
||
### Setting up Database | ||
|
||
After you have defined the variables mentioned above, navifate to your `app` folder with your terminal and run: | ||
``` | ||
python manage.py migrate | ||
python manage.py makemigrations | ||
python manage.py migrate | ||
``` | ||
### Running server | ||
Lastly, you can start the server by running: | ||
``` | ||
python manage.py runserver | ||
``` | ||
|
||
### Coming Soon | ||
|
||
- Deployment Configuration and Guidelines | ||
- Support to edit the Links | ||
- Link Stats Dashboard | ||
- Integration with LetStat (Launching soon) | ||
- API and Contribution Docs |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings') | ||
|
||
application = get_asgi_application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .local import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
import os | ||
|
||
import environ | ||
|
||
# Application Version | ||
APPLICATION_VERSION = "1.0.0" | ||
|
||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
root = environ.Path(__file__) - 1 | ||
env = environ.Env() | ||
environ.Env.read_env() | ||
|
||
DEBUG = True if env('DEVELOPMENT_MODE') == 'True' else False | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = env('DJANGO_SECRET') | ||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
'django.contrib.humanize', | ||
'django.contrib.postgres', | ||
|
||
# DRF Specific Libraries | ||
'rest_framework', | ||
'rest_framework.authtoken', | ||
'corsheaders', | ||
'django_filters', | ||
|
||
# Letstream Core Apps | ||
'apps.core', | ||
|
||
] | ||
|
||
MIDDLEWARE = [ | ||
'django.middleware.security.SecurityMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
|
||
'corsheaders.middleware.CorsMiddleware', | ||
|
||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
] | ||
|
||
ROOT_URLCONF = 'app.urls' | ||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [ | ||
os.path.join(BASE_DIR, '..', 'templates') | ||
], | ||
'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', | ||
'django.template.context_processors.request', | ||
'django.template.context_processors.media', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
WSGI_APPLICATION = 'app.wsgi.application' | ||
|
||
# Database | ||
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.postgresql', | ||
'NAME': env('DATABASE_NAME'), | ||
'USER': env('DATABASE_USER'), | ||
'PASSWORD': env('DATABASE_PASS'), | ||
'HOST': env('DATABASE_HOST'), | ||
'PORT': env('DATABASE_PORT') | ||
} | ||
} | ||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/2.0/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', | ||
}, | ||
] | ||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/2.0/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'Asia/Kolkata' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
STATICFILES_DIRS = [ | ||
os.path.join(BASE_DIR, "..", "static") | ||
] | ||
|
||
if not os.path.exists(os.path.join(BASE_DIR, "..", "temp")): | ||
os.makedirs(os.path.join(BASE_DIR, "..", 'temp')) | ||
TEMP_FILE_PATH = os.path.join(BASE_DIR, "..", 'temp') | ||
|
||
# DRF | ||
REST_FRAMEWORK = { | ||
'DEFAULT_AUTHENTICATION_CLASSES': ( | ||
'rest_framework.authentication.SessionAuthentication', | ||
'rest_framework.authentication.TokenAuthentication', | ||
), | ||
'DEFAULT_PERMISSION_CLASSES': ( | ||
'rest_framework.permissions.IsAuthenticated', | ||
), | ||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', | ||
'PAGE_SIZE': 20, | ||
} | ||
|
||
# CORS | ||
|
||
CORS_ORIGIN_REGEX_WHITELIST = [ | ||
r"^http(s)?:\/\/localhost(:[0-9]+)?\/?$", | ||
|
||
] | ||
CORS_ALLOW_CREDENTIALS = True | ||
|
||
APPEND_SLASH = False | ||
|
||
FILE_UPLOAD_PERMISSIONS = 0o644 | ||
|
||
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') | ||
|
||
CSRF_TRUSTED_ORIGINS = [ | ||
"localhost", | ||
] | ||
|
||
USE_SENTRY = True if env('USE_SENTRY') == 'True' else False | ||
|
||
if USE_SENTRY: | ||
import sentry_sdk | ||
from sentry_sdk.integrations.django import DjangoIntegration | ||
from sentry_sdk.integrations.celery import CeleryIntegration | ||
|
||
sentry_sdk.init( | ||
dsn=env('SENTRY_DSN'), | ||
integrations=[DjangoIntegration(), CeleryIntegration()], | ||
environment=env('ENVIRONMENT'), | ||
release=APPLICATION_VERSION, | ||
traces_sample_rate=1.0, | ||
|
||
# If you wish to associate users to errors (assuming you are using | ||
# django.contrib.auth) you may enable sending PII data. | ||
send_default_pii=True | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from .base import * | ||
|
||
DEBUG = True | ||
ALLOWED_HOSTS = ["*"] | ||
|
||
STATIC_ROOT = env('STATIC_ROOT') | ||
STATIC_URL = '/static/' | ||
|
||
MEDIA_ROOT = env('UPLOAD_ROOT') | ||
MEDIA_URL = '/uploads/' | ||
|
||
USE_AWS = False | ||
AWS_STATIC_LOCATION = None | ||
AWS_PUBLIC_MEDIA_LOCATION = None | ||
AWS_PRIVATE_MEDIA_LOCATION = None | ||
|
||
INTERNAL_IPS = ['127.0.0.1', 'localhost'] | ||
|
||
SESSION_COOKIE_DOMAIN = 'localhost' | ||
SESSION_COOKIE_SECURE = False | ||
|
||
CSRF_COOKIE_DOMAIN = 'localhost' | ||
CSRF_COOKIE_SECURE = False | ||
|
||
LOGIN_REDIRECT_URL = "/dashboard/" | ||
PORTAL_URL = "/dashboard/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from .base import * | ||
|
||
USE_AWS = True if env('USE_AWS') == 'True' else False | ||
|
||
if USE_AWS: | ||
# ADD S3 Storage | ||
INSTALLED_APPS.append('storages') | ||
|
||
# AWS_S3_ENDPOINT_URL = env('AWS_S3_ENDPOINT_URL') | ||
|
||
AWS_ACCESS_KEY_ID = env('AWS_ACCESS_KEY_ID') | ||
AWS_SECRET_ACCESS_KEY = env('AWS_SECRET_ACCESS_KEY') | ||
AWS_STORAGE_BUCKET_NAME = env('AWS_BUCKET_NAME') | ||
# AWS_S3_CUSTOM_DOMAIN = env('AWS_S3_CUSTOM_DOMAIN') | ||
|
||
|
||
# AWS_STATIC_LOCATION = env('AWS_STATIC_LOCATION') | ||
# AWS_S3_STATIC_CUSTOM_DOMAIN = env('AWS_S3_STATIC_CUSTOM_DOMAIN') | ||
AWS_STATIC_STORAGE_BUCKET_NAME = env('AWS_STATIC_BUCKET_NAME') | ||
AWS_S3_STATIC_ACCESS_KEY_ID = env('AWS_S3_STATIC_ACCESS_KEY_ID') | ||
AWS_S3_STATIC_SECRET_ACCESS_KEY = env('AWS_S3_STATIC_SECRET_ACCESS_KEY') | ||
|
||
# STATIC_URL = 'https://%s/%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_STATIC_STORAGE_BUCKET_NAME, AWS_STATIC_LOCATION) | ||
|
||
STATICFILES_STORAGE = 'app.storage_backends.StaticStorage' | ||
|
||
AWS_PUBLIC_MEDIA_LOCATION = "media/public" | ||
DEFAULT_FILE_STORAGE = "app.storage_backends.PublicMediaStorage" | ||
|
||
AWS_PRIVATE_MEDIA_LOCATION = "media/private" | ||
PRIVATE_FILE_STORAGE = "app.storage_backends.PrivateMediaStorage" | ||
|
||
AWS_S3_OBJECT_PARAMETERS = { | ||
'CacheControl': 'max-age=86400', | ||
} | ||
AWS_S3_SIGNATURE_VERSION = 's3v4' | ||
|
||
AWS_S3_REGION_NAME = "ap-south-1" | ||
else: | ||
STATIC_URL = '/static/' | ||
STATIC_ROOT = env('STATIC_ROOT') | ||
|
||
# # enable whitenoise | ||
# MIDDLEWARE.insert(1, 'whitenoise.middleware.WhiteNoiseMiddleware') | ||
# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' | ||
|
||
MEDIA_URL = '/uploads/' | ||
MEDIA_ROOT = env('UPLOAD_ROOT') | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = False | ||
|
||
ALLOWED_HOSTS = ["redr.me", ] # Change this for deployment | ||
|
||
SESSION_COOKIE_DOMAIN = 'redr.me' # Change this for Deployment | ||
SESSION_COOKIE_SECURE = True | ||
|
||
CSRF_COOKIE_DOMAIN = 'redr.me' # Change this for Deployment | ||
CSRF_COOKIE_SECURE = True | ||
|
||
LOGIN_REDIRECT_URL = "/dashboard/" | ||
PORTAL_URL = "/dashboard/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
DEVELOPMENT_MODE=True | ||
|
||
DATABASE_NAME=ENTER_VALUE_HERE | ||
DATABASE_USER=ENTER_VALUE_HERE | ||
DATABASE_PASSWORD=ENTER_VALUE_HERE | ||
DATABASE_HOST=localhost | ||
DATABASE_PORT=5432 | ||
|
||
DJANGO_SECRET=ENTER_A_RANDOM_STRING | ||
|
||
STATIC_ROOT=ABSOLUTE/PATH/TO/app/staticfiles | ||
UPLOAD_ROOT=ABSOLUTE/PATH/TO/app/uploads | ||
|
||
RECAPTCHA_PRIVATE_KEY=ENTER_VALUE_HERE | ||
RECAPTCHA_PUBLIC_KEY=ENTER_VALUE_HERE | ||
|
||
USE_SENTRY=True | ||
SENTRY_DSN=ENTER_VALUE_HERE | ||
ENVIRONMENT=development | ||
|
||
USE_CELERY=True | ||
|
||
USE_AWS=True | ||
AWS_ACCESS_KEY_ID=ENTER_VALUE_HERE | ||
AWS_SECRET_ACCESS_KEY=ENTER_VALUE_HERE | ||
AWS_BUCKET_NAME=ENTER_VALUE_HERE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from django.conf import settings | ||
from django.core.files.storage import default_storage | ||
from storages.backends.s3boto3 import S3Boto3Storage | ||
|
||
class StaticStorage(S3Boto3Storage): | ||
location = settings.AWS_STATIC_LOCATION | ||
|
||
def __init__(self, *args, **kwargs): | ||
|
||
super().__init__( | ||
access_key=settings.AWS_S3_STATIC_ACCESS_KEY_ID, | ||
secret_key=settings.AWS_S3_STATIC_SECRET_ACCESS_KEY, | ||
bucket_name=settings.AWS_STATIC_STORAGE_BUCKET_NAME, | ||
gzip=True, | ||
default_acl='public-read' | ||
) | ||
|
||
class PublicMediaStorage(S3Boto3Storage): | ||
location = settings.AWS_PUBLIC_MEDIA_LOCATION | ||
default_acl = 'public-read' | ||
file_overwrite = False | ||
|
||
class PrivateMediaStorage(S3Boto3Storage): | ||
location = settings.AWS_PRIVATE_MEDIA_LOCATION | ||
default_acl = 'private' | ||
file_overwrite = False | ||
custom_domain = False | ||
|
||
private_storage = default_storage if settings.DEBUG else PrivateMediaStorage() |
Oops, something went wrong.