mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19: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
56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Configuration for Post-ERG thesis database
|
|
* Central location for database paths and environment settings
|
|
*/
|
|
|
|
// Database paths relative to repository root
|
|
define('DB_ROOT', __DIR__ . '/..');
|
|
|
|
// Test database (used in development)
|
|
define('DB_TEST_PATH', DB_ROOT . '/database/test.db');
|
|
|
|
// Production database (used on server)
|
|
define('DB_PROD_PATH', DB_ROOT . '/database/posterg.db');
|
|
|
|
/**
|
|
* Determine which database to use
|
|
* Checks environment variable DB_ENV, defaults to auto-detection
|
|
*
|
|
* Set DB_ENV in your environment:
|
|
* - export DB_ENV=test # Force test database
|
|
* - export DB_ENV=prod # Force production database
|
|
*
|
|
* Auto-detection logic:
|
|
* - If test.db exists, use it (development)
|
|
* - Otherwise use posterg.db (production)
|
|
*/
|
|
function getDatabasePath() {
|
|
// Allow explicit override via environment variable
|
|
$env = getenv('DB_ENV');
|
|
|
|
if ($env === 'test') {
|
|
return DB_TEST_PATH;
|
|
}
|
|
|
|
if ($env === 'prod') {
|
|
return DB_PROD_PATH;
|
|
}
|
|
|
|
// Auto-detect: prefer test database if it exists
|
|
if (file_exists(DB_TEST_PATH)) {
|
|
return DB_TEST_PATH;
|
|
}
|
|
|
|
// Default to production database
|
|
return DB_PROD_PATH;
|
|
}
|
|
|
|
/**
|
|
* Check if running in test/development mode
|
|
*/
|
|
function isTestMode() {
|
|
return getDatabasePath() === DB_TEST_PATH;
|
|
}
|