aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--requirements.txt1
-rwxr-xr-xrunserver.sh69
-rw-r--r--thatcomputerscientist/settings.py4
4 files changed, 73 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 3033efe2..64847e5d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -143,3 +143,4 @@ dump.rdb
# credentials JSON files
credentials-*.json
+SSL
diff --git a/requirements.txt b/requirements.txt
index 236ff635..96ed972e 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -27,3 +27,4 @@ akismet
google-cloud-translate
django-hosts
apscheduler
+django-sslserver \ No newline at end of file
diff --git a/runserver.sh b/runserver.sh
index 48583d3b..5a84a06c 100755
--- a/runserver.sh
+++ b/runserver.sh
@@ -1,3 +1,70 @@
#!/bin/bash
-lt -p 8000 -s thatcomputerscientist & python3 manage.py runserver && fg \ No newline at end of file
+# Function to check if mkcert is installed
+check_mkcert_installed() {
+ if ! command -v mkcert &> /dev/null; then
+ echo "mkcert is not installed. Installing mkcert..."
+ brew install mkcert # Assuming you're using Homebrew to install mkcert
+ fi
+}
+
+# Function to check if the mkcert local CA is installed and install it if not present
+check_and_install_local_ca() {
+ if ! mkcert -CAROOT &> /dev/null; then
+ echo "Installing mkcert local CA..."
+ mkcert -install
+ fi
+}
+
+# Function to set the DOMAIN value in the .env file
+set_domain_in_env() {
+ domain=$1
+ sed -i "" "s/^DOMAIN=.*/DOMAIN='.${domain}'/" .env
+}
+
+# Function to run the development server
+run_dev_server() {
+ domain=$1
+ cert_file="SSL/${domain}+1.pem"
+ key_file="SSL/${domain}+1-key.pem"
+
+ if [[ -f "$cert_file" && -f "$key_file" ]]; then
+ set_domain_in_env "$domain"
+ sudo python3 manage.py runsslserver 127.0.0.1:443 --certificate "$cert_file" --key "$key_file"
+ else
+ echo "Certificate files not found. Generating self-signed certificate..."
+ mkdir -p SSL && cd SSL
+ mkcert "${domain}" "*.${domain}"
+ cd ..
+ set_domain_in_env "$domain"
+ sudo python3 manage.py runsslserver 127.0.0.1:443 --certificate "$cert_file" --key "$key_file"
+ fi
+}
+
+# Main script
+
+# Check if mkcert is installed and install if not present
+check_mkcert_installed
+
+# Present options to the user
+echo "Choose an option:"
+echo "[1]: (*).[peek].shi.foo"
+echo "[2]: (*).[peek].thatcomputerscientist.com"
+read -p "Enter your choice (1 or 2): " choice
+
+case $choice in
+ 1)
+ domain="peek.shi.foo"
+ check_and_install_local_ca
+ run_dev_server "$domain"
+ ;;
+ 2)
+ domain="peek.thatcomputerscientist.com"
+ check_and_install_local_ca
+ run_dev_server "$domain"
+ ;;
+ *)
+ echo "Invalid choice. Exiting..."
+ exit 1
+ ;;
+esac
diff --git a/thatcomputerscientist/settings.py b/thatcomputerscientist/settings.py
index 8f9c2220..d21b491e 100644
--- a/thatcomputerscientist/settings.py
+++ b/thatcomputerscientist/settings.py
@@ -39,8 +39,9 @@ DEBUG = True if os.getenv('ENVIRONMENT') == 'development' else False
ALLOWED_HOSTS = ["*"]
CSRF_TRUSTED_ORIGINS = ['https://*.thatcomputerscientist.com', 'http://*.thatcomputerscientist.com', 'https://*.shi.foo']
DOMAIN_NAME = "shi.foo"
-SESSION_COOKIE_DOMAIN = ".domain.internal" if os.getenv('ENVIRONMENT') == 'development' else ".shi.foo"
+SESSION_COOKIE_DOMAIN = os.getenv('DOMAIN') if os.getenv('ENVIRONMENT') == 'development' else ".shi.foo"
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
+SECURE_SSL_REDIRECT = True
ROOT_HOSTCONF = 'thatcomputerscientist.hosts'
ROOT_URLCONF = 'thatcomputerscientist.urls'
DEFAULT_HOST = 'default'
@@ -58,6 +59,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.sitemaps',
+ 'sslserver',
'thatcomputerscientist',
'haystack',
'django_hosts',