# ─── SMBEditor (user distribution) ──────────────────
# Drop this .htaccess + smbeditor.php into your site folder.
# Minimal — rewrite rules only, no FilesMatch/Options to avoid 403

RewriteEngine On

# If the requested file/directory doesn't exist, route to front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ smbeditor.php?page=$1 [L,QSA]

# Asset passthrough
RewriteRule ^(css|js|img)/ - [L]
RewriteRule ^(logo-white\.png|og-image\.png|overview\.jpg|file-view\.jpg|audit\.jpg|manage\.jpg) - [L]
RewriteRule ^(favicon\.ico)$ img/ico.png [L]

# Root → front controller (serves the site's existing index.html)
RewriteRule ^$ smbeditor.php?page=index.html [L,QSA]

# Protect cache
RewriteRule ^data/ - [F,L]

# ── Security hardening ──
# Block access to sensitive files
<FilesMatch "\.(log|tmp|bak|old|swp|env|md|sql)$">
  Require all denied
</FilesMatch>

# Block direct access to dotfiles (logs / caches)
<FilesMatch "^\.">
  Require all denied
</FilesMatch>

# Only the editor itself may run PHP here — blocks any injected .php
<FilesMatch "\.(php|phtml|php[0-9]|phar)$">
  Require all denied
</FilesMatch>
<Files "smbeditor.php">
  Require all granted
</Files>

# Prevent directory listing
Options -Indexes

# Security headers (Apache only — PHP also sets these)
<IfModule mod_headers.c>
  Header always set X-Content-Type-Options "nosniff"
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
  # Clear any host/server-injected CSP and allow all resources (admin edits own site)
  Header always unset Content-Security-Policy
  Header always set Content-Security-Policy "default-src * data: blob: 'unsafe-inline' 'unsafe-eval'; script-src * data: blob: 'unsafe-inline' 'unsafe-eval'; style-src * data: blob: 'unsafe-inline'; img-src * data: blob:; font-src * data: blob:; connect-src * data: blob:; frame-src * data: blob:; worker-src * data: blob:; child-src * data: blob:; media-src * data: blob:; object-src * data: blob:; manifest-src * data: blob:; form-action *; base-uri 'self'"
</IfModule>
