mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 11:09:18 +02:00
refactor: rename database → storage
More semantically accurate: contains SQLite files, schema, fixtures, test data. Updated all references in code, scripts, docs.
This commit is contained in:
@@ -16,7 +16,7 @@ The Post-ERG website is now successfully deployed with production-ready nginx co
|
||||
| **Public Site** | ✅ Working | https://posterg.erg.be/ → 200 OK |
|
||||
| **SSL/TLS** | ✅ Working | HTTPS with valid certificate |
|
||||
| **Admin Panel** | ✅ Protected | /formulaire/ → 401 (requires password) |
|
||||
| **Database Protection** | ✅ Blocked | /database/ → 403 Forbidden |
|
||||
| **Database Protection** | ✅ Blocked | /storage/ → 403 Forbidden |
|
||||
| **Sensitive Files** | ✅ Blocked | .md, .sql files → 403 Forbidden |
|
||||
| **Shared Directory** | ✅ Blocked | /shared/ → 403 Forbidden |
|
||||
| **Security Headers** | ✅ Present | X-Frame-Options, CSP, etc. |
|
||||
@@ -96,7 +96,7 @@ find /var/www/html -type f -exec chmod 640 {} \;
|
||||
- Admin panel: 10 requests/minute (burst: 5)
|
||||
|
||||
**Protected Paths:**
|
||||
- `/database/` - Database files (403)
|
||||
- `/storage/` - Database files (403)
|
||||
- `/shared/` - PHP libraries (403)
|
||||
- `/data/` - Upload directories (403)
|
||||
- `*.db` files - Database files (403)
|
||||
@@ -174,7 +174,7 @@ curl -I http://localhost/ # Should: 200 OK
|
||||
curl -I http://localhost/formulaire/ # Should: 401 Unauthorized
|
||||
|
||||
# Test security
|
||||
curl -I http://localhost/database/posterg.db # Should: 403 Forbidden
|
||||
curl -I http://localhost/storage/posterg.db # Should: 403 Forbidden
|
||||
curl -I http://localhost/README.md # Should: 403 Forbidden
|
||||
curl -I http://localhost/shared/Database.php # Should: 403 Forbidden
|
||||
```
|
||||
@@ -345,7 +345,7 @@ ssh posterg "cd /var/www/html && sed -i \"s|__DIR__ . '/../../shared/|__DIR__ .
|
||||
- **Deployment Issues:** Check logs first
|
||||
- **Nginx Config:** `/etc/nginx/sites-available/posterg`
|
||||
- **PHP Config:** `/etc/php/8.4/fpm/pool.d/www.conf`
|
||||
- **Database:** `/var/www/html/database/posterg.db`
|
||||
- **Database:** `/var/www/html/storage/posterg.db`
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ The new configuration adds:
|
||||
✅ **File Protection**
|
||||
- Database files (`.db`) → 403 Forbidden
|
||||
- Sensitive files (`.md`, `.sql`, `.txt`) → 403 Forbidden
|
||||
- `/database/` directory → 403 Forbidden
|
||||
- `/storage/` directory → 403 Forbidden
|
||||
- `/shared/` directory → 403 Forbidden
|
||||
- `/data/` directory → 403 Forbidden
|
||||
- Hidden files (`.git`, `.env`) → 403 Forbidden
|
||||
@@ -119,7 +119,7 @@ curl http://localhost/index.php | head -n 20
|
||||
curl -I http://localhost/formulaire/
|
||||
|
||||
# Database should be blocked (403)
|
||||
curl -I http://localhost/database/posterg.db
|
||||
curl -I http://localhost/storage/posterg.db
|
||||
|
||||
# Sensitive files should be blocked (403)
|
||||
curl -I http://localhost/README.md
|
||||
|
||||
@@ -88,8 +88,8 @@ sudo chmod 775 /var/www/html/formulaire/data/theses
|
||||
sudo chmod 775 /var/www/html/formulaire/data/covers
|
||||
|
||||
# Protect database
|
||||
sudo chmod 640 /var/www/html/database/posterg.db
|
||||
sudo chown www-data:posterg /var/www/html/database/posterg.db
|
||||
sudo chmod 640 /var/www/html/storage/posterg.db
|
||||
sudo chown www-data:posterg /var/www/html/storage/posterg.db
|
||||
```
|
||||
|
||||
### Step 2: Deploy Nginx Config
|
||||
@@ -148,7 +148,7 @@ curl -u admin:your_password http://localhost/formulaire/
|
||||
|
||||
```bash
|
||||
# These should all return 403 Forbidden
|
||||
curl -I http://localhost/database/posterg.db
|
||||
curl -I http://localhost/storage/posterg.db
|
||||
curl -I http://localhost/README.md
|
||||
curl -I http://localhost/shared/Database.php
|
||||
curl -I http://localhost/.git/config
|
||||
@@ -217,9 +217,9 @@ ls -la /etc/nginx/.htpasswd-posterg
|
||||
|
||||
**Fix database permissions:**
|
||||
```bash
|
||||
sudo chown www-data:posterg /var/www/html/database/posterg.db
|
||||
sudo chmod 640 /var/www/html/database/posterg.db
|
||||
sudo chmod 755 /var/www/html/database/
|
||||
sudo chown www-data:posterg /var/www/html/storage/posterg.db
|
||||
sudo chmod 640 /var/www/html/storage/posterg.db
|
||||
sudo chmod 755 /var/www/html/storage/
|
||||
```
|
||||
|
||||
### Can't Write Uploaded Files
|
||||
|
||||
@@ -122,7 +122,7 @@ done
|
||||
|
||||
```bash
|
||||
# Should return 403
|
||||
curl -I https://posterg.erg.be/database/posterg.db
|
||||
curl -I https://posterg.erg.be/storage/posterg.db
|
||||
curl -I https://posterg.erg.be/shared/Database.php
|
||||
curl -I https://posterg.erg.be/.env
|
||||
```
|
||||
@@ -217,7 +217,7 @@ sudo cp /etc/nginx/.htpasswd-posterg /etc/nginx/.htpasswd-posterg.backup.$(date
|
||||
|
||||
- [ ] Admin password set: `sudo ls -l /etc/nginx/.htpasswd-posterg`
|
||||
- [ ] SSL enabled: `curl -I https://posterg.erg.be/`
|
||||
- [ ] Database blocked: `curl -I https://posterg.erg.be/database/posterg.db`
|
||||
- [ ] Database blocked: `curl -I https://posterg.erg.be/storage/posterg.db`
|
||||
- [ ] Shared directory blocked: `curl -I https://posterg.erg.be/shared/Database.php`
|
||||
- [ ] Rate limiting working: Test with curl loop
|
||||
- [ ] Security headers present: `curl -I https://posterg.erg.be/ | grep X-`
|
||||
|
||||
@@ -95,7 +95,7 @@ Test your configuration:
|
||||
curl -I https://posterg.erg.be/formulaire/
|
||||
|
||||
# Test file protection
|
||||
curl -I https://posterg.erg.be/database/posterg.db
|
||||
curl -I https://posterg.erg.be/storage/posterg.db
|
||||
|
||||
# Test security headers
|
||||
curl -I https://posterg.erg.be/ | grep -E "X-|Strict-Transport"
|
||||
|
||||
@@ -150,8 +150,8 @@ sudo chmod 775 /var/www/html/formulaire/data/theses
|
||||
sudo chmod 775 /var/www/html/formulaire/data/covers
|
||||
|
||||
# Protect database
|
||||
sudo chmod 600 /var/www/html/database/posterg.db
|
||||
sudo chown www-data:www-data /var/www/html/database/posterg.db
|
||||
sudo chmod 600 /var/www/html/storage/posterg.db
|
||||
sudo chown www-data:www-data /var/www/html/storage/posterg.db
|
||||
```
|
||||
|
||||
## Security Features Implemented
|
||||
@@ -216,7 +216,7 @@ for i in {1..50}; do curl -I https://posterg.erg.be/ 2>&1 | grep HTTP; done
|
||||
|
||||
```bash
|
||||
# Should return 403 Forbidden
|
||||
curl -I https://posterg.erg.be/database/posterg.db
|
||||
curl -I https://posterg.erg.be/storage/posterg.db
|
||||
curl -I https://posterg.erg.be/shared/Database.php
|
||||
curl -I https://posterg.erg.be/README.md
|
||||
```
|
||||
|
||||
@@ -11,7 +11,7 @@ just test-deploy
|
||||
```
|
||||
|
||||
This automatically:
|
||||
1. ✅ Creates `/var/www/html/database/` directory
|
||||
1. ✅ Creates `/var/www/html/storage/` directory
|
||||
2. ✅ Uploads `test.db` to the server
|
||||
3. ✅ Sets correct group ownership (`posterg`)
|
||||
4. ✅ Sets correct permissions (775 for dir, 660 for file)
|
||||
@@ -100,8 +100,8 @@ php -r "require_once '/var/www/html/shared/Database.php'; echo 'Using: ' . Datab
|
||||
```
|
||||
|
||||
Output will be:
|
||||
- `/var/www/html/database/test.db` (test mode)
|
||||
- `/var/www/html/database/posterg.db` (production mode)
|
||||
- `/var/www/html/storage/test.db` (test mode)
|
||||
- `/var/www/html/storage/posterg.db` (production mode)
|
||||
|
||||
### 5. Switch Back to Production
|
||||
|
||||
@@ -109,7 +109,7 @@ Simply remove the test database:
|
||||
|
||||
```bash
|
||||
ssh posterg
|
||||
rm /var/www/html/database/test.db
|
||||
rm /var/www/html/storage/test.db
|
||||
```
|
||||
|
||||
The site automatically switches to production database.
|
||||
@@ -121,7 +121,7 @@ The site automatically switches to production database.
|
||||
### Directory Permissions
|
||||
|
||||
```
|
||||
drwxrwxr-x theophile posterg /var/www/html/database/
|
||||
drwxrwxr-x theophile posterg /var/www/html/storage/
|
||||
```
|
||||
|
||||
- **775**: Owner and group can read/write/execute, others can read/execute
|
||||
@@ -165,11 +165,11 @@ sudo systemctl restart php8.4-fpm
|
||||
```bash
|
||||
ssh posterg
|
||||
# Fix group ownership
|
||||
chgrp posterg /var/www/html/database /var/www/html/database/test.db
|
||||
chgrp posterg /var/www/html/database /var/www/html/storage/test.db
|
||||
|
||||
# Fix permissions
|
||||
chmod 775 /var/www/html/database
|
||||
chmod 660 /var/www/html/database/test.db
|
||||
chmod 660 /var/www/html/storage/test.db
|
||||
```
|
||||
|
||||
### "SQLSTATE[HY000]: General error: 8 attempt to write a readonly database"
|
||||
@@ -185,9 +185,9 @@ chmod 775 /var/www/html/database
|
||||
**Clear SQLite cache:**
|
||||
```bash
|
||||
ssh posterg
|
||||
rm -f /var/www/html/database/test.db-journal
|
||||
rm -f /var/www/html/database/test.db-shm
|
||||
rm -f /var/www/html/database/test.db-wal
|
||||
rm -f /var/www/html/storage/test.db-journal
|
||||
rm -f /var/www/html/storage/test.db-shm
|
||||
rm -f /var/www/html/storage/test.db-wal
|
||||
```
|
||||
|
||||
Then redeploy:
|
||||
@@ -239,7 +239,7 @@ just test-deploy
|
||||
|
||||
```bash
|
||||
ssh posterg
|
||||
sqlite3 /var/www/html/database/test.db
|
||||
sqlite3 /var/www/html/storage/test.db
|
||||
# ... make changes ...
|
||||
```
|
||||
|
||||
@@ -281,7 +281,7 @@ Before deploying test database, backup production if needed:
|
||||
|
||||
```bash
|
||||
ssh posterg
|
||||
cp /var/www/html/database/posterg.db /var/www/html/database/posterg.db.backup.$(date +%Y%m%d)
|
||||
cp /var/www/html/storage/posterg.db /var/www/html/storage/posterg.db.backup.$(date +%Y%m%d)
|
||||
```
|
||||
|
||||
---
|
||||
@@ -325,7 +325,7 @@ cp /var/www/html/database/posterg.db /var/www/html/database/posterg.db.backup.$(
|
||||
|
||||
After running `just test-deploy`, verify:
|
||||
|
||||
- [ ] Database file exists: `ssh posterg "ls -la /var/www/html/database/test.db"`
|
||||
- [ ] Database file exists: `ssh posterg "ls -la /var/www/html/storage/test.db"`
|
||||
- [ ] Correct permissions: `-rw-rw---- theophile posterg`
|
||||
- [ ] Directory writable: `drwxrwxr-x theophile posterg`
|
||||
- [ ] Site loads: Visit https://posterg.erg.be/
|
||||
@@ -346,7 +346,7 @@ When working correctly:
|
||||
|
||||
To switch back to production, just:
|
||||
```bash
|
||||
ssh posterg "rm /var/www/html/database/test.db"
|
||||
ssh posterg "rm /var/www/html/storage/test.db"
|
||||
```
|
||||
|
||||
Site automatically uses `posterg.db` again! 🚀
|
||||
|
||||
@@ -42,9 +42,9 @@ if [ -d "/var/www/posterg/database" ]; then
|
||||
fi
|
||||
|
||||
# Fix database file permissions
|
||||
if [ -f "/var/www/posterg/database/test.db" ]; then
|
||||
chmod 660 /var/www/posterg/database/test.db
|
||||
chown www-data:posterg /var/www/posterg/database/test.db
|
||||
if [ -f "/var/www/posterg/storage/test.db" ]; then
|
||||
chmod 660 /var/www/posterg/storage/test.db
|
||||
chown www-data:posterg /var/www/posterg/storage/test.db
|
||||
echo "✓ Fixed database file permissions (660)"
|
||||
fi
|
||||
|
||||
@@ -102,4 +102,4 @@ echo ""
|
||||
echo "After reload, verify:"
|
||||
echo " • https://posterg.erg.be/"
|
||||
echo " • https://posterg.erg.be/admin/"
|
||||
echo " • https://posterg.erg.be/database/test.db (should 404)"
|
||||
echo " • https://posterg.erg.be/storage/test.db (should 404)"
|
||||
|
||||
@@ -42,9 +42,9 @@ if [ -d "/var/www/html/formulaire/data/theses" ]; then
|
||||
fi
|
||||
|
||||
# Protect database if it exists
|
||||
if [ -f "/var/www/html/database/posterg.db" ]; then
|
||||
chmod 660 /var/www/html/database/posterg.db
|
||||
chown www-data:posterg /var/www/html/database/posterg.db
|
||||
if [ -f "/var/www/html/storage/posterg.db" ]; then
|
||||
chmod 660 /var/www/html/storage/posterg.db
|
||||
chown www-data:posterg /var/www/html/storage/posterg.db
|
||||
echo "✓ Protected database file"
|
||||
fi
|
||||
|
||||
@@ -174,7 +174,7 @@ echo " • Access log: tail -f /var/log/nginx/posterg_access.log"
|
||||
echo " • Error log: tail -f /var/log/nginx/posterg_error.log"
|
||||
echo ""
|
||||
echo "🔒 Security Checks:"
|
||||
echo " • Database blocked: curl -I http://localhost/database/posterg.db"
|
||||
echo " • Database blocked: curl -I http://localhost/storage/posterg.db"
|
||||
echo " • MD files blocked: curl -I http://localhost/README.md"
|
||||
echo " • Shared blocked: curl -I http://localhost/shared/Database.php"
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user