mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-07 03:29:19 +02:00
Phase 1: Consolidate shared infrastructure - Create shared/ directory for common code - Consolidate Database.php from front-backend and formulaire into unified shared/Database.php - Smart path detection for test.db vs posterg.db - Secure search with wildcard escaping and input validation - Support both singleton and direct instantiation patterns - Full CRUD methods for admin functionality - Move RateLimit.php to shared/ (30 requests/min) - Update all require paths across apps to use shared/ Phase 2: Reorganize directory structure - Rename front-backend/ → apps/public/ - Rename formulaire/ → apps/admin/ - Rename db/ → database/ - Update all file paths for new structure - Create root .gitignore excluding databases, cache, logs Implement secure search feature - Add apps/public/search.php with full-text search across theses - Search filters: query, year, orientation, AP program, keywords - Security features: - SQL injection prevention (prepared statements) - Wildcard injection prevention (escape % and _) - Input validation (max 200 chars, year range 1900-2100) - Rate limiting (30 req/min per IP) - Pagination limited to 100 results/page - XSS protection (htmlspecialchars on output) Add comprehensive test suite - Create apps/public/tests/ with proper structure - tests/Integration/SearchTest.php - 12 search scenarios - tests/Security/SecurityTest.php - vulnerability testing - tests/Unit/RateLimitTest.php - rate limit behavior - Create database/fixtures/CreateTestDatabase.php - Add apps/public/run-tests.php test runner - All tests passing (4/4 suites) Update deployment configuration - Rename justfile 'sync' recipe to 'deploy' - Create deploy group with separate deploy-public and deploy-admin - Add test-deploy recipe for test database - Exclude *.db, tests/, cache/, *.md from production deploy - Deploy shared/ to both public and admin locations Stats: +4482 insertions, -654 deletions across 72 files
179 lines
6.8 KiB
Makefile
179 lines
6.8 KiB
Makefile
# Default recipe - show available commands
|
|
default:
|
|
@just --list
|
|
|
|
# ============================================================================
|
|
# Deploy Group
|
|
# ============================================================================
|
|
# Note: Regular deploy recipes exclude test.db and all *.db files by default
|
|
# Use test-deploy explicitly to deploy the test database
|
|
|
|
[group('deploy')]
|
|
deploy-public:
|
|
rsync -vur --progress --exclude 'test.db' --exclude '*.db' --exclude 'tests/' --exclude 'cache/' --exclude '*.md' --exclude 'run-tests.php' ./apps/public/ posterg:/var/www/html/
|
|
rsync -vur --progress --exclude 'test.db' ./shared/ posterg:/var/www/html/shared/
|
|
|
|
[group('deploy')]
|
|
deploy-admin:
|
|
rsync -vur --progress --exclude 'test.db' --exclude '*.db' --exclude 'cache/' --exclude '*.md' ./apps/admin/ posterg:/var/www/html/formulaire/
|
|
rsync -vur --progress --exclude 'test.db' ./shared/ posterg:/var/www/html/shared/
|
|
|
|
[group('deploy')]
|
|
deploy: deploy-public deploy-admin
|
|
@echo ""
|
|
@echo "✅ Deployment complete (test.db excluded)"
|
|
@echo "To deploy test database, run: just test-deploy"
|
|
|
|
[group('deploy')]
|
|
deploy-database:
|
|
@echo "Deploying database directory (excludes test.db by default)..."
|
|
rsync -vur --progress --exclude 'test.db' --exclude '*.db-journal' ./database/ posterg:/var/www/html/database/
|
|
@echo "✅ Database directory deployed (schema, fixtures, docs only)"
|
|
|
|
[group('deploy')]
|
|
test-deploy:
|
|
@echo "⚠️ Deploying test database (will overwrite remote test.db)"
|
|
rsync -vur --progress ./database/test.db posterg:/var/www/html/database/test.db
|
|
@echo "✅ Test database deployed"
|
|
|
|
[group('deploy')]
|
|
deploy-nginx:
|
|
@echo "📋 Deploying nginx configuration..."
|
|
rsync -vur --progress ./nginx/posterg.conf posterg:/tmp/posterg.conf
|
|
@echo "⚠️ Configuration uploaded to /tmp/posterg.conf"
|
|
@echo ""
|
|
@echo "Next steps on the server:"
|
|
@echo " 1. sudo cp /tmp/posterg.conf /etc/nginx/sites-available/posterg"
|
|
@echo " 2. sudo ln -s /etc/nginx/sites-available/posterg /etc/nginx/sites-enabled/"
|
|
@echo " 3. sudo nginx -t"
|
|
@echo " 4. sudo systemctl reload nginx"
|
|
|
|
# ============================================================================
|
|
# Public Site Development
|
|
# ============================================================================
|
|
|
|
[group('public-dev')]
|
|
serve-public:
|
|
@echo "Starting public site on http://localhost:8000"
|
|
@echo "Press Ctrl+C to stop"
|
|
@cd apps/public && php -S 127.0.0.1:8000
|
|
|
|
[group('public-dev')]
|
|
test-public:
|
|
@echo "Testing public site..."
|
|
@cd apps/public && php test_db.php
|
|
|
|
[group('public-dev')]
|
|
test-public-all:
|
|
@echo "Running all public site tests..."
|
|
@cd apps/public && php run-tests.php
|
|
|
|
[group('public-dev')]
|
|
stats-public:
|
|
@echo "=== Public Database Statistics ==="
|
|
@sqlite3 database/test.db "SELECT COUNT(*) || ' total theses' FROM theses;"
|
|
@sqlite3 database/test.db "SELECT COUNT(*) || ' published theses' FROM theses WHERE is_published = 1;"
|
|
@sqlite3 database/test.db "SELECT COUNT(*) || ' authors' FROM authors;"
|
|
@sqlite3 database/test.db "SELECT COUNT(*) || ' keywords' FROM keywords;"
|
|
|
|
[group('public-dev')]
|
|
recent-public:
|
|
@echo "=== Recent Published Theses ==="
|
|
@sqlite3 -column -header database/test.db "SELECT id, title, year, authors FROM v_theses_public ORDER BY year DESC, title LIMIT 10;"
|
|
|
|
[group('public-dev')]
|
|
check-public:
|
|
@echo "Checking public site PHP syntax..."
|
|
@cd apps/public && find . -name "*.php" -not -path "./vendor/*" -not -path "./tests/*" -exec php -l {} \; | grep -v "No syntax errors"
|
|
@echo "✓ All files have valid syntax"
|
|
|
|
[group('public-dev')]
|
|
logs-public:
|
|
@if [ -f apps/public/error.log ]; then tail -n 50 apps/public/error.log; else echo "No error log found"; fi
|
|
|
|
# ============================================================================
|
|
# Admin Panel Development
|
|
# ============================================================================
|
|
|
|
[group('admin-dev')]
|
|
init-test-db:
|
|
@echo "Creating test database from schema..."
|
|
@sqlite3 database/test.db < database/schema.sql
|
|
@echo "✓ Test database created"
|
|
@sqlite3 database/test.db "SELECT COUNT(*) || ' tables created' FROM sqlite_master WHERE type='table';"
|
|
@sqlite3 database/test.db "SELECT COUNT(*) || ' orientations loaded' FROM orientations;"
|
|
@sqlite3 database/test.db "SELECT COUNT(*) || ' AP programs loaded' FROM ap_programs;"
|
|
|
|
[group('admin-dev')]
|
|
serve-admin: init-test-db
|
|
@echo "Starting admin panel on http://localhost:3000"
|
|
@echo "Press Ctrl+C to stop"
|
|
@cd apps/admin && php -S 127.0.0.1:3000
|
|
|
|
[group('admin-dev')]
|
|
serve-admin-only:
|
|
@echo "Starting admin panel on http://localhost:3000"
|
|
@echo "Press Ctrl+C to stop"
|
|
@cd apps/admin && php -S 127.0.0.1:3000
|
|
|
|
[group('admin-dev')]
|
|
cleanup-admin:
|
|
@echo "Cleaning up admin test files..."
|
|
@rm -f database/test.db
|
|
@rm -f apps/admin/error.log
|
|
@rm -rf apps/admin/data/theses/*
|
|
@rm -rf apps/admin/data/covers/*
|
|
@echo "✓ Cleanup complete"
|
|
|
|
[group('admin-dev')]
|
|
reset-admin: cleanup-admin init-test-db
|
|
@echo "✓ Admin test environment reset"
|
|
|
|
[group('admin-dev')]
|
|
stats-admin:
|
|
@echo "=== Admin Database Statistics ==="
|
|
@sqlite3 database/test.db "SELECT COUNT(*) || ' theses' FROM theses;"
|
|
@sqlite3 database/test.db "SELECT COUNT(*) || ' authors' FROM authors;"
|
|
@sqlite3 database/test.db "SELECT COUNT(*) || ' supervisors' FROM supervisors;"
|
|
@sqlite3 database/test.db "SELECT COUNT(*) || ' keywords' FROM keywords;"
|
|
@sqlite3 database/test.db "SELECT COUNT(*) || ' files uploaded' FROM thesis_files;"
|
|
|
|
[group('admin-dev')]
|
|
recent-admin:
|
|
@echo "=== Recent Submissions ==="
|
|
@sqlite3 -column -header database/test.db "SELECT identifier, title, year, submitted_at FROM theses ORDER BY submitted_at DESC LIMIT 5;"
|
|
|
|
[group('admin-dev')]
|
|
setup-dirs:
|
|
@mkdir -p apps/admin/data/theses
|
|
@mkdir -p apps/admin/data/covers
|
|
@mkdir -p apps/admin/data/yaml
|
|
@touch apps/admin/data/theses/.gitkeep
|
|
@touch apps/admin/data/covers/.gitkeep
|
|
@echo "✓ Data directories created"
|
|
|
|
[group('admin-dev')]
|
|
dev-admin: setup-dirs init-test-db serve-admin
|
|
|
|
# ============================================================================
|
|
# Database Operations
|
|
# ============================================================================
|
|
|
|
[group('database')]
|
|
query-db:
|
|
@sqlite3 database/test.db
|
|
|
|
[group('database')]
|
|
show-thesis id:
|
|
@sqlite3 -column -header database/test.db "SELECT * FROM v_theses_full WHERE id = {{id}};"
|
|
|
|
[group('database')]
|
|
dump-db:
|
|
@sqlite3 database/test.db .dump > database/backup_$(date +%Y%m%d_%H%M%S).sql
|
|
@echo "✓ Database dumped to database/backup_$(date +%Y%m%d_%H%M%S).sql"
|
|
|
|
[group('database')]
|
|
create-fixtures:
|
|
@echo "Creating test database with fixtures..."
|
|
@php database/fixtures/CreateTestDatabase.php
|