aiwaf 0.1.9.0.6__py3-none-any.whl → 0.1.9.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of aiwaf might be problematic. Click here for more details.

aiwaf/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  default_app_config = "aiwaf.apps.AiwafConfig"
2
2
 
3
- __version__ = "0.1.9.0.6"
3
+ __version__ = "0.1.9.0.7"
4
4
 
5
5
  # Note: Middleware classes are available from aiwaf.middleware
6
6
  # Import them only when needed to avoid circular imports during Django app loading
@@ -17,7 +17,7 @@ class Command(BaseCommand):
17
17
  if store.is_exempted(ip):
18
18
  self.stdout.write(self.style.WARNING(f'IP {ip} is already exempted.'))
19
19
  else:
20
- store.add_ip(ip, reason)
20
+ store.add_exemption(ip, reason)
21
21
  self.stdout.write(self.style.SUCCESS(f'IP {ip} added to exemption list.'))
22
22
  if reason:
23
23
  self.stdout.write(self.style.SUCCESS(f'Reason: {reason}'))
@@ -0,0 +1,155 @@
1
+ from django.core.management.base import BaseCommand
2
+ import os
3
+ import csv
4
+
5
+ class Command(BaseCommand):
6
+ help = 'Debug and fix AI-WAF CSV functionality'
7
+
8
+ def add_arguments(self, parser):
9
+ parser.add_argument(
10
+ '--test-ip',
11
+ type=str,
12
+ help='Test IP address to add to exemption list',
13
+ default='127.0.0.1'
14
+ )
15
+ parser.add_argument(
16
+ '--fix',
17
+ action='store_true',
18
+ help='Attempt to fix identified issues',
19
+ )
20
+
21
+ def handle(self, *args, **options):
22
+ self.stdout.write(self.style.HTTP_INFO("🔍 AI-WAF CSV Debug & Fix"))
23
+ self.stdout.write("")
24
+
25
+ # Check storage mode
26
+ from django.conf import settings
27
+ storage_mode = getattr(settings, 'AIWAF_STORAGE_MODE', 'models')
28
+ csv_dir = getattr(settings, 'AIWAF_CSV_DATA_DIR', 'aiwaf_data')
29
+
30
+ self.stdout.write(f"Storage Mode: {storage_mode}")
31
+ self.stdout.write(f"CSV Directory: {csv_dir}")
32
+ self.stdout.write("")
33
+
34
+ # Check middleware logging
35
+ middleware_logging = getattr(settings, 'AIWAF_MIDDLEWARE_LOGGING', False)
36
+ middleware_log = getattr(settings, 'AIWAF_MIDDLEWARE_LOG', 'aiwaf_requests.log')
37
+
38
+ self.stdout.write(f"Middleware Logging: {middleware_logging}")
39
+ self.stdout.write(f"Middleware Log File: {middleware_log}")
40
+ self.stdout.write("")
41
+
42
+ # Check if CSV directory exists
43
+ if os.path.exists(csv_dir):
44
+ self.stdout.write(self.style.SUCCESS(f"✅ CSV directory exists: {csv_dir}"))
45
+ else:
46
+ self.stdout.write(self.style.ERROR(f"❌ CSV directory missing: {csv_dir}"))
47
+ if options['fix']:
48
+ os.makedirs(csv_dir, exist_ok=True)
49
+ self.stdout.write(self.style.SUCCESS(f"✅ Created CSV directory: {csv_dir}"))
50
+
51
+ # Check CSV files
52
+ csv_files = ['blacklist.csv', 'exemptions.csv', 'keywords.csv']
53
+ for filename in csv_files:
54
+ filepath = os.path.join(csv_dir, filename)
55
+ if os.path.exists(filepath):
56
+ # Count entries
57
+ try:
58
+ with open(filepath, 'r', newline='', encoding='utf-8') as f:
59
+ reader = csv.reader(f)
60
+ rows = list(reader)
61
+ entry_count = len(rows) - 1 if rows else 0 # Subtract header
62
+ self.stdout.write(self.style.SUCCESS(f"✅ {filename}: {entry_count} entries"))
63
+ except Exception as e:
64
+ self.stdout.write(self.style.ERROR(f"❌ {filename}: Error reading - {e}"))
65
+ else:
66
+ self.stdout.write(self.style.WARNING(f"⚠️ {filename}: Not found"))
67
+
68
+ self.stdout.write("")
69
+
70
+ # Test storage functionality
71
+ self.stdout.write(self.style.HTTP_INFO("🧪 Testing Storage Functions"))
72
+
73
+ try:
74
+ from aiwaf.storage import get_exemption_store, get_blacklist_store, get_keyword_store
75
+
76
+ # Test exemption store
77
+ exemption_store = get_exemption_store()
78
+ self.stdout.write(f"Exemption Store: {exemption_store.__name__}")
79
+
80
+ # Test blacklist store
81
+ blacklist_store = get_blacklist_store()
82
+ self.stdout.write(f"Blacklist Store: {blacklist_store.__name__}")
83
+
84
+ # Test keyword store
85
+ keyword_store = get_keyword_store()
86
+ self.stdout.write(f"Keyword Store: {keyword_store.__name__}")
87
+
88
+ except Exception as e:
89
+ self.stdout.write(self.style.ERROR(f"❌ Storage import failed: {e}"))
90
+ return
91
+
92
+ self.stdout.write("")
93
+
94
+ # Test exemption functionality
95
+ test_ip = options['test_ip']
96
+ self.stdout.write(f"🧪 Testing exemption with IP: {test_ip}")
97
+
98
+ try:
99
+ # Check if already exempted
100
+ is_exempted_before = exemption_store.is_exempted(test_ip)
101
+ self.stdout.write(f"Before: IP {test_ip} exempted = {is_exempted_before}")
102
+
103
+ # Add to exemption
104
+ exemption_store.add_exemption(test_ip, "Test exemption from debug command")
105
+ self.stdout.write(f"✅ Added {test_ip} to exemption list")
106
+
107
+ # Check if now exempted
108
+ is_exempted_after = exemption_store.is_exempted(test_ip)
109
+ self.stdout.write(f"After: IP {test_ip} exempted = {is_exempted_after}")
110
+
111
+ if is_exempted_after:
112
+ self.stdout.write(self.style.SUCCESS("✅ Exemption functionality working!"))
113
+ else:
114
+ self.stdout.write(self.style.ERROR("❌ Exemption functionality not working!"))
115
+
116
+ # List all exemptions
117
+ all_exemptions = exemption_store.get_all()
118
+ self.stdout.write(f"Total exemptions: {len(all_exemptions)}")
119
+
120
+ for exemption in all_exemptions:
121
+ self.stdout.write(f" - {exemption.get('ip_address', exemption)}")
122
+
123
+ except Exception as e:
124
+ self.stdout.write(self.style.ERROR(f"❌ Exemption test failed: {e}"))
125
+
126
+ self.stdout.write("")
127
+
128
+ # Check middleware logger file
129
+ csv_log_file = middleware_log.replace('.log', '.csv')
130
+ if os.path.exists(csv_log_file):
131
+ try:
132
+ with open(csv_log_file, 'r', newline='', encoding='utf-8') as f:
133
+ reader = csv.reader(f)
134
+ rows = list(reader)
135
+ entry_count = len(rows) - 1 if rows else 0
136
+ self.stdout.write(self.style.SUCCESS(f"✅ Middleware CSV log: {entry_count} entries"))
137
+ except Exception as e:
138
+ self.stdout.write(self.style.ERROR(f"❌ Middleware CSV log error: {e}"))
139
+ else:
140
+ self.stdout.write(self.style.WARNING(f"⚠️ Middleware CSV log not found: {csv_log_file}"))
141
+ self.stdout.write(" Make some requests to generate log entries")
142
+
143
+ # Recommendations
144
+ self.stdout.write("")
145
+ self.stdout.write(self.style.HTTP_INFO("💡 Recommendations:"))
146
+
147
+ if storage_mode != 'csv':
148
+ self.stdout.write("1. Set AIWAF_STORAGE_MODE = 'csv' in settings.py")
149
+
150
+ if not middleware_logging:
151
+ self.stdout.write("2. Set AIWAF_MIDDLEWARE_LOGGING = True in settings.py")
152
+
153
+ self.stdout.write("3. Add AIWAFLoggerMiddleware to MIDDLEWARE in settings.py")
154
+ self.stdout.write("4. Make some requests to generate log data")
155
+ self.stdout.write("5. Run 'python manage.py detect_and_train' to train with data")
@@ -63,7 +63,7 @@ class Command(BaseCommand):
63
63
 
64
64
  # Create the exemption
65
65
  try:
66
- exemption_store.add_ip(test_ip, "Test exemption from debug")
66
+ exemption_store.add_exemption(test_ip, "Test exemption from debug")
67
67
  self.stdout.write(self.style.SUCCESS("✅ Created test exemption"))
68
68
  except Exception as e:
69
69
  self.stdout.write(self.style.ERROR(f"❌ Failed to create exemption: {e}"))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aiwaf
3
- Version: 0.1.9.0.6
3
+ Version: 0.1.9.0.7
4
4
  Summary: AI-powered Web Application Firewall
5
5
  Home-page: https://github.com/aayushgauba/aiwaf
6
6
  Author: Aayush Gauba
@@ -1,4 +1,4 @@
1
- aiwaf/__init__.py,sha256=CaCYDiHa_an8eS3dgJs0d6bCNQN7KUMc2sJBLEXNt8I,220
1
+ aiwaf/__init__.py,sha256=5uH_XGymeTFxegNihwozJE8d-Y70jvwpKhXvzZ9HkQI,220
2
2
  aiwaf/apps.py,sha256=nCez-Ptlv2kaEk5HenA8b1pATz1VfhrHP1344gwcY1A,142
3
3
  aiwaf/blacklist_manager.py,sha256=LYCeKFB-7e_C6Bg2WeFJWFIIQlrfRMPuGp30ivrnhQY,1196
4
4
  aiwaf/decorators.py,sha256=IUKOdM_gdroffImRZep1g1wT6gNqD10zGwcp28hsJCs,825
@@ -11,22 +11,23 @@ aiwaf/utils.py,sha256=BJk5vJCYdGPl_4QQiknjhCbkzv5HZCXgFcBJDMJpHok,3390
11
11
  aiwaf/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  aiwaf/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  aiwaf/management/commands/add_exemption.py,sha256=U_ByfJw1EstAZ8DaSoRb97IGwYzXs0DBJkVAqeN4Wak,1128
14
- aiwaf/management/commands/add_ipexemption.py,sha256=srgdVPDJtF7G9GGIqaZ7L3qTuNheoS_uwlhlRO4W2bc,945
14
+ aiwaf/management/commands/add_ipexemption.py,sha256=sSf3d9hGK9RqqlBYkCrnrd8KZWGT-derSpoWnEY4H60,952
15
15
  aiwaf/management/commands/aiwaf_diagnose.py,sha256=nXFRhq66N4QC3e4scYJ2sUngJce-0yDxtBO3R2BllRM,6134
16
16
  aiwaf/management/commands/aiwaf_logging.py,sha256=FCIqULn2tii2vD9VxL7vk3PV4k4vr7kaA00KyaCExYY,7692
17
17
  aiwaf/management/commands/aiwaf_reset.py,sha256=0FIBqpZS8xgFFvAKJ-0zAC_-QNQwRkOHpXb8N-OdFr8,3740
18
18
  aiwaf/management/commands/clear_cache.py,sha256=cdnuTgxkhKLqT_6k6yTcEBlREovNRQxAE51ceXlGYMA,647
19
+ aiwaf/management/commands/debug_csv.py,sha256=Lddqp37mIn0zdvHf4GbuNTWYyJ5h8bumDcGmFSAioi0,6801
19
20
  aiwaf/management/commands/detect_and_train.py,sha256=-o-LZ7QZ5GeJPCekryox1DGXKMmFEkwwrcDsiM166K0,269
20
21
  aiwaf/management/commands/diagnose_blocking.py,sha256=HKb_FdN4b6QdyqNDf54B08I5jyWfrv9Mh-SFBrr3LbU,4140
21
22
  aiwaf/management/commands/regenerate_model.py,sha256=SUy7TCTTDJy4kRZNAbTIVBxSmljUaAC6ms0JTfSO6BE,3445
22
23
  aiwaf/management/commands/setup_models.py,sha256=JzuxwAqO3e-8L4PdFlXkyEQmOA8EGCXBfaOwfCNv1Gg,1678
23
- aiwaf/management/commands/test_exemption.py,sha256=qX7GMnpGFhRzC8cTtJMVN7pvjXziEWJ934cyOLN3cqs,5511
24
+ aiwaf/management/commands/test_exemption.py,sha256=ENmWFMJE8iQyzJGAPdw_5PUPknLajE8JjwHgH8DCFsE,5518
24
25
  aiwaf/management/commands/test_exemption_fix.py,sha256=ngyGaHUCmQQ6y--6j4q1viZJtR-RvI526yDqvEaEXPs,2553
25
26
  aiwaf/resources/model.pkl,sha256=5t6h9BX8yoh2xct85MXOO60jdlWyg1APskUOW0jZE1Y,1288265
26
27
  aiwaf/templatetags/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
28
  aiwaf/templatetags/aiwaf_tags.py,sha256=XXfb7Tl4DjU3Sc40GbqdaqOEtKTUKELBEk58u83wBNw,357
28
- aiwaf-0.1.9.0.6.dist-info/licenses/LICENSE,sha256=Ir8PX4dxgAcdB0wqNPIkw84fzIIRKE75NoUil9RX0QU,1069
29
- aiwaf-0.1.9.0.6.dist-info/METADATA,sha256=xhkKJlK7aW0mObUkrIboi4E4GTP1aLpyoo_I0QUJs4E,13763
30
- aiwaf-0.1.9.0.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
- aiwaf-0.1.9.0.6.dist-info/top_level.txt,sha256=kU6EyjobT6UPCxuWpI_BvcHDG0I2tMgKaPlWzVxe2xI,6
32
- aiwaf-0.1.9.0.6.dist-info/RECORD,,
29
+ aiwaf-0.1.9.0.7.dist-info/licenses/LICENSE,sha256=Ir8PX4dxgAcdB0wqNPIkw84fzIIRKE75NoUil9RX0QU,1069
30
+ aiwaf-0.1.9.0.7.dist-info/METADATA,sha256=rFNbBTlRRki2Prz5URgHw8yYmWTTSsxxBTeE5evUabE,13763
31
+ aiwaf-0.1.9.0.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
32
+ aiwaf-0.1.9.0.7.dist-info/top_level.txt,sha256=kU6EyjobT6UPCxuWpI_BvcHDG0I2tMgKaPlWzVxe2xI,6
33
+ aiwaf-0.1.9.0.7.dist-info/RECORD,,