import django, os, sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'core.settings'
sys.path.insert(0, '/Users/junv/code/links')
django.setup()

from nginxmon.models import NginxSettings
from nginxmon.fetcher import auto_ban_php_scanners, auto_ban_404_flood, auto_ban_auth_scanners

settings = NginxSettings.get()
print("Running auto_ban_php_scanners...")
banned = auto_ban_php_scanners(settings)
print(f"  PHP scanners banned: {banned}")

print("Running auto_ban_404_flood...")
banned = auto_ban_404_flood(settings)
print(f"  404 flood banned: {banned}")

print("Running auto_ban_auth_scanners...")
banned = auto_ban_auth_scanners(settings)
print(f"  Auth probe banned: {banned}")

from nginxmon.models import BannedIP
print(f"\nTotal BannedIP records: {BannedIP.objects.count()}")
for b in BannedIP.objects.all():
    print(f"  {b.ip:20s}  [{b.get_ban_source_display()}]  {b.reason[:70]}")
