###############################################
# OJS 3 — SECURITY with EXTENDED JUDOL + BOT BLOCKLIST (FIXED)
###############################################

<IfModule mod_rewrite.c>
RewriteEngine On


###############################################
# 0. WHITELIST — IZINKAN DASHBOARD & PLUGIN OJS 3
###############################################

# Dashboard OJS
RewriteCond %{REQUEST_URI} "^/index\.php/.*/management" [NC,OR]

# Plugin Import / Export
RewriteCond %{REQUEST_URI} "^/index\.php/.*/importexport" [NC,OR]

# API dipakai AJAX OJS
RewriteCond %{REQUEST_URI} "^/index\.php/.*/api" [NC,OR]

# Submission internal routing
RewriteCond %{REQUEST_URI} "^/index\.php/.*/submissions" [NC]

RewriteRule ^ - [L]


###############################################
# 0.1 WHITELIST — IZINKAN BROWSER NORMAL
###############################################
RewriteCond %{HTTP_USER_AGENT} "(Chrome|Firefox|Safari|Edge|OPR|MSIE)" [NC]
RewriteRule ^ - [L]


# -------------------------------
# REMOVE index.php (default OJS3)
# -------------------------------
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [L]


###########################################################
# 1. ANTI JUDI ONLINE — EXTENDED BLOCKLIST
# HANYA BLOK REFERER (aman untuk OJS)
###########################################################

RewriteCond %{HTTP_REFERER} "(judi|judol|slot|slots|casino|togel|toto|pkv|poker|bandar|bet|betting|sabung ayam|slot88)" [NC,OR]
RewriteCond %{HTTP_REFERER} "(gacor|maxwin|max-win|max win|rtp|jackpot|scatter|spin gratis|spin-gratis|boslot|bonus new member|bonus member baru|slot gacor)" [NC,OR]
RewriteCond %{HTTP_REFERER} "(pragmatic|pgsoft|pg soft|habanero|joker123|joker gaming|idnplay|idnpoker|idnslot|microgaming|spadegaming|cq9|rtgslots|ttg|playtech)" [NC,OR]
RewriteCond %{HTTP_REFERER} "(88|777|303|168|188|388|138|5000|899|558|365|808|8899|6699)" [NC,OR]
RewriteCond %{HTTP_REFERER} "(slotmania|slotpulsa|slotdeposit|sultanslot|situsgacor|agenjudi|kingslot|zeusslot|mahadewa|vivoslot|viralbet|rajajudi|luxury138)" [NC]
RewriteRule ^ - [F]


###########################################################
# 2. BLOK USER AGENT SPAMMER / BOT JUDOL (AMAN UNTUK OJS)
###########################################################

RewriteCond %{HTTP_USER_AGENT} "(curl|wget|python|phpcrawl|masscan|nmap|sqlmap|acunetix|nikto|dirbuster|gobuster|openvas|skipfish|wpscan)" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "(Ahrefs|Semrush|MJ12bot|DotBot|BLEXBot|SEOkicks|MegaIndex|Majestic|Exabot)" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "(HTTrack|SiteSucker|WebZip|Teleport|WebCopier|PageGrabber|Grabber|WebBandit)" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "(slot|judi|togel|casino|gacor|maxwin|rtp|betting)" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "(FakeGooglebot|FakeBot|EvilBot|BadBot|BlackWidow)" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "(libwww|httpclient|axios|okhttp|Go-http-client|Java/1|python-requests)" [NC]
RewriteRule ^ - [F]

</IfModule>


###############################################
# 3. PROTECT SENSITIVE FILES
###############################################
<FilesMatch "(composer\.json|composer\.lock|package\.json|package-lock\.json|config\.inc\.php|db\.php|phpinfo\.php)">
  Order allow,deny
  Deny from all
</FilesMatch>


###############################################
# 4. DISABLE DIRECTORY LISTING
###############################################
Options -Indexes


###############################################
# 5. DISABLE EXECUTION OF PHP IN PUBLIC UPLOADS
###############################################
<Directory "public">
  <FilesMatch "\.(php|php5|phtml)$">
    Deny from all
  </FilesMatch>
</Directory>


###############################################
# 6. REQUEST SIZE LIMIT
###############################################
LimitRequestBody 10485760

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php74” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
