46602f1933
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.
76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
"""Exercise https_manager.py exactly as deploy.sh does, inside a container-like env.
|
|
|
|
Overrides the Caddyfile path (the only host-only difference) to prove the
|
|
enable/status/disable flow and the resulting Caddyfile content.
|
|
"""
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
|
|
tmp = tempfile.mkdtemp()
|
|
os.environ['DATABASE_URL'] = f'sqlite:///{tmp}/t.db'
|
|
|
|
from app.app import create_app
|
|
from app.models.https_config import HTTPSConfig
|
|
from app.utils.caddy_manager import CaddyConfigGenerator
|
|
|
|
app = create_app('production')
|
|
with app.app_context():
|
|
from app.extensions import db
|
|
db.create_all()
|
|
|
|
# Redirect the Caddyfile write/read to a temp path (the only host difference).
|
|
_target = f'{tmp}/Caddyfile'
|
|
CaddyConfigGenerator.write_caddyfile = staticmethod(
|
|
lambda content, path=_target: (open(_target, 'w').write(content), True)[1])
|
|
CaddyConfigGenerator.reload_caddy = staticmethod(lambda: True)
|
|
|
|
sys.argv = ['https_manager.py', 'enable', 'digiserver', '',
|
|
'admin@example.com', '192.168.0.152', '8443']
|
|
|
|
import importlib.util
|
|
spec = importlib.util.spec_from_file_location('hm', '/home/scheianu/digiserver-v2/https_manager.py')
|
|
hm = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(hm)
|
|
|
|
print('=== ENABLE (empty domain -> internal CA) ===')
|
|
rc = hm.main()
|
|
print('exit code:', rc)
|
|
|
|
print()
|
|
print('=== resulting Caddyfile site blocks ===')
|
|
text = open(_target).read()
|
|
for ln in text.splitlines():
|
|
s = ln.strip()
|
|
if s.startswith(('http://', 'https://', ':80')) or 'tls internal' in s or 'redir' in s:
|
|
print(' ', s)
|
|
|
|
with app.app_context():
|
|
c = HTTPSConfig.get_config()
|
|
print()
|
|
print('=== stored config ===')
|
|
print(' https_enabled:', c.https_enabled)
|
|
print(' domain :', repr(c.domain))
|
|
print(' ip_address :', c.ip_address)
|
|
print(' port :', c.port)
|
|
assert c.https_enabled is True
|
|
assert not c.domain, 'domain must be empty for internal CA'
|
|
assert 'tls internal' in text, 'internal CA directive missing'
|
|
assert 'http://192.168.0.152' in text, 'HTTP fallback missing'
|
|
|
|
print()
|
|
print('ASSERT PASS: internal CA + HTTP fallback generated correctly')
|
|
|
|
print()
|
|
print('=== STATUS ===')
|
|
sys.argv = ['https_manager.py', 'status']
|
|
hm.main()
|
|
|
|
print()
|
|
print('=== DISABLE ===')
|
|
sys.argv = ['https_manager.py', 'disable']
|
|
hm.main()
|
|
with app.app_context():
|
|
c = HTTPSConfig.get_config()
|
|
print(' https_enabled after disable:', c.https_enabled)
|