Sanitize codebase, reorganize docs, and add missing deploy files

Remove dead code identified in docs/SANITIZATION-REVIEW.md:
- app/blueprints/content_old.py and app/blueprints/playlist.py
- app/models/group.py, app/utils/nginx_config_reader.py
- orphaned templates (content_list, edit_content, upload_content,
  player_page) and the related group/Template references

Result: 6 blueprints, 82 routes, no dead modules or orphan templates.

Add files that deploy.sh and docker-entrypoint.sh already require but
which were never tracked:
- https_manager.py       (referenced by deploy.sh, migrate_network.sh,
                          docker-entrypoint.sh)
- Caddyfile.example      (seeded by deploy.sh; its absence aborts deploy)

Relocate generated Graphify artifacts from graphify-out/ to
docs/graphify-out/ (110 files, no content change) and archive the
superseded docs under docs/.

Ignore hygiene:
- ignore ad-hoc .env backups (.env.bak*) — they contain live secrets
- keep the pre-sanitization snapshots (docs/legacy code/,
  docs/old_code_documentation/) on disk but out of the repo

Fix .env.example: drop a duplicated config block, genericize the
hardcoded host IP, and document HOSTNAME_INTERNAL.
This commit is contained in:
2026-09-11 12:18:34 +03:00
parent 1c5186463a
commit 46602f1933
226 changed files with 3999 additions and 15737 deletions
+53 -36
View File
@@ -25,7 +25,18 @@ fi
NEW_IP="$1"
HOSTNAME="${2:-digiserver}"
EMAIL="${EMAIL:-admin@example.com}"
PORT="${PORT:-443}"
HTTP_PORT="${HTTP_PORT:-80}"
HTTPS_PORT="${HTTPS_PORT:-443}"
# Accept either the modern compose plugin or the standalone v1 binary.
if docker compose version &> /dev/null; then
COMPOSE="docker compose"
elif command -v docker-compose &> /dev/null; then
COMPOSE="docker-compose"
else
echo -e "${RED}❌ docker compose not found!${NC}"
exit 1
fi
# Validate IP format
if ! [[ "$NEW_IP" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
@@ -42,43 +53,34 @@ echo -e "${BLUE}Migration Settings:${NC}"
echo " New IP Address: $NEW_IP"
echo " Hostname: $HOSTNAME"
echo " Email: $EMAIL"
echo " Port: $PORT"
echo " HTTP port: $HTTP_PORT"
echo " HTTPS port: $HTTPS_PORT"
echo ""
# Check if containers are running
echo -e "${YELLOW}🔍 [1/4] Checking containers...${NC}"
if ! docker compose ps | grep -q "digiserver-app"; then
echo -e "${RED}❌ digiserver-app container not running!${NC}"
echo "Please start containers with: docker compose up -d"
if ! $COMPOSE ps | grep -q "digiserver-v2"; then
echo -e "${RED}❌ digiserver-v2 container not running!${NC}"
echo "Please start containers with: $COMPOSE up -d"
exit 1
fi
echo -e "${GREEN}✅ Containers are running${NC}"
echo ""
# Step 1: Regenerate SSL certificates for new IP
echo -e "${YELLOW}🔐 [2/4] Regenerating SSL certificates for new IP...${NC}"
echo " Generating self-signed certificate for $NEW_IP..."
# Step 1: Update HTTPS configuration for the new IP
# NOTE: Caddy manages its own certificates (internal CA or ACME), so no manual
# cert generation is needed. Setting the IP in HTTPSConfig and re-applying the
# config is enough — Caddy issues a new certificate for the new address.
echo -e "${YELLOW}🔐 [2/4] Updating TLS configuration for the new IP...${NC}"
echo " Caddy will issue a certificate for $NEW_IP automatically."
CERT_DIR="./data/nginx-ssl"
mkdir -p "$CERT_DIR"
openssl req -x509 -nodes -days 365 \
-newkey rsa:2048 \
-keyout "$CERT_DIR/key.pem" \
-out "$CERT_DIR/cert.pem" \
-subj "/CN=$NEW_IP/O=DigiServer/C=US" >/dev/null 2>&1
chmod 644 "$CERT_DIR/cert.pem"
chmod 600 "$CERT_DIR/key.pem"
echo -e " ${GREEN}${NC} Certificates regenerated for $NEW_IP"
echo -e "${GREEN}✅ SSL certificates updated${NC}"
echo -e "${GREEN}✅ TLS handled by Caddy (no manual certificates)${NC}"
echo ""
# Step 2: Update HTTPS configuration in database
echo -e "${YELLOW}🔧 [3/4] Updating HTTPS configuration in database...${NC}"
docker compose exec -T digiserver-app python << EOF
$COMPOSE exec -T digiserver-app python << EOF
from app.app import create_app
from app.models.https_config import HTTPSConfig
from app.extensions import db
@@ -87,13 +89,13 @@ app = create_app('production')
with app.app_context():
# Update or create HTTPS config for the new IP
https_config = HTTPSConfig.query.first()
if https_config:
https_config.hostname = '$HOSTNAME'
https_config.ip_address = '$NEW_IP'
https_config.email = '$EMAIL'
https_config.port = $PORT
https_config.enabled = True
https_config.port = $HTTPS_PORT
https_config.https_enabled = True
db.session.commit()
print(f" ✓ HTTPS configuration updated")
print(f" Hostname: {https_config.hostname}")
@@ -104,18 +106,23 @@ with app.app_context():
print(" This will be created on next app startup")
EOF
# Re-apply so Caddy picks up the new address and issues a certificate for it.
$COMPOSE exec -T -e HOSTNAME_INTERNAL="$HOSTNAME" -e HOST_IP="$NEW_IP" \
-e HTTPS_PORT="$HTTPS_PORT" \
digiserver-app python /app/https_manager.py bootstrap
echo -e "${GREEN}✅ Database configuration updated${NC}"
echo ""
# Step 3: Restart containers
echo -e "${YELLOW}🔄 [4/4] Restarting containers...${NC}"
docker compose restart nginx digiserver-app
$COMPOSE restart caddy digiserver-app
sleep 3
if ! docker compose ps | grep -q "Up"; then
if ! $COMPOSE ps | grep -q "Up"; then
echo -e "${RED}❌ Containers failed to restart!${NC}"
docker compose logs | tail -20
$COMPOSE logs | tail -20
exit 1
fi
@@ -126,10 +133,13 @@ echo ""
echo -e "${YELLOW}🔍 Verifying HTTPS connectivity...${NC}"
sleep 2
if curl -s -k -I https://$NEW_IP 2>/dev/null | grep -q "HTTP"; then
_https_port_suffix=""
[ "$HTTPS_PORT" != "443" ] && _https_port_suffix=":$HTTPS_PORT"
if curl -s -k -o /dev/null -m 8 "https://$NEW_IP$_https_port_suffix/" 2>/dev/null; then
echo -e "${GREEN}✅ HTTPS connection verified${NC}"
else
echo -e "${YELLOW}⚠️ HTTPS verification pending (containers warming up)${NC}"
echo -e "${YELLOW}⚠️ HTTPS verification pending (containers warming up, or Caddy is still issuing the certificate)${NC}"
fi
echo ""
@@ -138,15 +148,22 @@ echo -e "${GREEN}║ ✅ Network Migration Complete!
echo -e "${GREEN}╚════════════════════════════════════════════════════════════════╝${NC}"
echo ""
_http_url="http://$NEW_IP"
[ "$HTTP_PORT" != "80" ] && _http_url="http://$NEW_IP:$HTTP_PORT"
_https_url="https://$NEW_IP"
[ "$HTTPS_PORT" != "443" ] && _https_url="https://$NEW_IP:$HTTPS_PORT"
echo -e "${BLUE}📍 New Access Points:${NC}"
echo " 🔒 https://$NEW_IP"
echo " 🔒 https://$HOSTNAME.local (if mDNS enabled)"
echo " 🌐 $_http_url"
echo " 🔒 $_https_url"
echo " 🔒 https://$HOSTNAME (needs DNS or an /etc/hosts entry)"
echo ""
echo -e "${BLUE}📋 Changes Made:${NC}"
echo "SSL certificates regenerated for $NEW_IP"
echo " ✓ Database HTTPS config updated"
echo " ✓ Nginx and app containers restarted"
echo "HTTPS configuration updated for $NEW_IP"
echo " ✓ Caddy re-applied (internal CA certificate reissued for the new address)"
echo " ✓ Caddy and app containers restarted"
echo ""
echo -e "${YELLOW}⏳ Allow 30 seconds for containers to become fully healthy${NC}"