aiwaf 0.1.9.1.7__py3-none-any.whl → 0.1.9.1.9__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 +1 -1
- aiwaf/management/commands/aiwaf_reset.py +58 -17
- aiwaf/management/commands/clear_blacklist.py +66 -0
- aiwaf/storage.py +49 -0
- {aiwaf-0.1.9.1.7.dist-info → aiwaf-0.1.9.1.9.dist-info}/METADATA +1 -1
- {aiwaf-0.1.9.1.7.dist-info → aiwaf-0.1.9.1.9.dist-info}/RECORD +9 -8
- {aiwaf-0.1.9.1.7.dist-info → aiwaf-0.1.9.1.9.dist-info}/WHEEL +0 -0
- {aiwaf-0.1.9.1.7.dist-info → aiwaf-0.1.9.1.9.dist-info}/licenses/LICENSE +0 -0
- {aiwaf-0.1.9.1.7.dist-info → aiwaf-0.1.9.1.9.dist-info}/top_level.txt +0 -0
aiwaf/__init__.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from django.core.management.base import BaseCommand
|
|
2
2
|
from aiwaf.storage import get_blacklist_store, get_exemption_store
|
|
3
|
+
import sys
|
|
3
4
|
|
|
4
5
|
class Command(BaseCommand):
|
|
5
6
|
help = 'Reset AI-WAF by clearing all blacklist and exemption (whitelist) entries'
|
|
@@ -26,12 +27,29 @@ class Command(BaseCommand):
|
|
|
26
27
|
exemptions_only = options['exemptions_only']
|
|
27
28
|
confirm = options['confirm']
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
try:
|
|
31
|
+
blacklist_store = get_blacklist_store()
|
|
32
|
+
exemption_store = get_exemption_store()
|
|
33
|
+
except Exception as e:
|
|
34
|
+
self.stdout.write(self.style.ERROR(f'Error initializing stores: {e}'))
|
|
35
|
+
return
|
|
31
36
|
|
|
32
|
-
# Count current entries
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
# Count current entries safely
|
|
38
|
+
try:
|
|
39
|
+
blacklist_entries = blacklist_store.get_all()
|
|
40
|
+
blacklist_count = len(blacklist_entries)
|
|
41
|
+
except Exception as e:
|
|
42
|
+
self.stdout.write(self.style.WARNING(f'Warning: Could not count blacklist entries: {e}'))
|
|
43
|
+
blacklist_count = 0
|
|
44
|
+
blacklist_entries = []
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
exemption_entries = exemption_store.get_all()
|
|
48
|
+
exemption_count = len(exemption_entries)
|
|
49
|
+
except Exception as e:
|
|
50
|
+
self.stdout.write(self.style.WARNING(f'Warning: Could not count exemption entries: {e}'))
|
|
51
|
+
exemption_count = 0
|
|
52
|
+
exemption_entries = []
|
|
35
53
|
|
|
36
54
|
if blacklist_only and exemptions_only:
|
|
37
55
|
self.stdout.write(self.style.ERROR('Cannot use both --blacklist-only and --exemptions-only flags'))
|
|
@@ -55,29 +73,47 @@ class Command(BaseCommand):
|
|
|
55
73
|
self.stdout.write(f"AI-WAF Reset: {action}")
|
|
56
74
|
|
|
57
75
|
if not confirm:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
76
|
+
try:
|
|
77
|
+
response = input("Are you sure you want to proceed? [y/N]: ")
|
|
78
|
+
if response.lower() not in ['y', 'yes']:
|
|
79
|
+
self.stdout.write(self.style.WARNING('Operation cancelled'))
|
|
80
|
+
return
|
|
81
|
+
except (EOFError, KeyboardInterrupt):
|
|
82
|
+
self.stdout.write(self.style.WARNING('\nOperation cancelled'))
|
|
61
83
|
return
|
|
62
84
|
|
|
63
85
|
# Perform the reset
|
|
64
|
-
deleted_counts = {'blacklist': 0, 'exemptions': 0}
|
|
86
|
+
deleted_counts = {'blacklist': 0, 'exemptions': 0, 'errors': []}
|
|
65
87
|
|
|
66
88
|
if clear_blacklist:
|
|
67
89
|
# Clear blacklist entries
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
90
|
+
try:
|
|
91
|
+
for entry in blacklist_entries:
|
|
92
|
+
try:
|
|
93
|
+
blacklist_store.remove_ip(entry['ip_address'])
|
|
94
|
+
deleted_counts['blacklist'] += 1
|
|
95
|
+
except Exception as e:
|
|
96
|
+
deleted_counts['errors'].append(f"Error removing blacklist IP {entry.get('ip_address', 'unknown')}: {e}")
|
|
97
|
+
except Exception as e:
|
|
98
|
+
deleted_counts['errors'].append(f"Error clearing blacklist: {e}")
|
|
72
99
|
|
|
73
100
|
if clear_exemptions:
|
|
74
101
|
# Clear exemption entries
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
102
|
+
try:
|
|
103
|
+
for entry in exemption_entries:
|
|
104
|
+
try:
|
|
105
|
+
exemption_store.remove_ip(entry['ip_address'])
|
|
106
|
+
deleted_counts['exemptions'] += 1
|
|
107
|
+
except Exception as e:
|
|
108
|
+
deleted_counts['errors'].append(f"Error removing exemption IP {entry.get('ip_address', 'unknown')}: {e}")
|
|
109
|
+
except Exception as e:
|
|
110
|
+
deleted_counts['errors'].append(f"Error clearing exemptions: {e}")
|
|
79
111
|
|
|
80
112
|
# Report results
|
|
113
|
+
if deleted_counts['errors']:
|
|
114
|
+
for error in deleted_counts['errors']:
|
|
115
|
+
self.stdout.write(self.style.WARNING(f"⚠️ {error}"))
|
|
116
|
+
|
|
81
117
|
if clear_blacklist and clear_exemptions:
|
|
82
118
|
self.stdout.write(
|
|
83
119
|
self.style.SUCCESS(
|
|
@@ -93,3 +129,8 @@ class Command(BaseCommand):
|
|
|
93
129
|
self.stdout.write(
|
|
94
130
|
self.style.SUCCESS(f"✅ Exemptions cleared: Deleted {deleted_counts['exemptions']} entries")
|
|
95
131
|
)
|
|
132
|
+
|
|
133
|
+
if deleted_counts['errors']:
|
|
134
|
+
self.stdout.write(
|
|
135
|
+
self.style.WARNING(f"⚠️ Completed with {len(deleted_counts['errors'])} errors (see above)")
|
|
136
|
+
)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from django.core.management.base import BaseCommand
|
|
2
|
+
from aiwaf.storage import get_blacklist_store
|
|
3
|
+
|
|
4
|
+
class Command(BaseCommand):
|
|
5
|
+
help = 'Clear all blacklist entries (fast method)'
|
|
6
|
+
|
|
7
|
+
def add_arguments(self, parser):
|
|
8
|
+
parser.add_argument(
|
|
9
|
+
'--confirm',
|
|
10
|
+
action='store_true',
|
|
11
|
+
help='Skip confirmation prompt'
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
def handle(self, *args, **options):
|
|
15
|
+
confirm = options['confirm']
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
blacklist_store = get_blacklist_store()
|
|
19
|
+
except Exception as e:
|
|
20
|
+
self.stdout.write(self.style.ERROR(f'Error initializing blacklist store: {e}'))
|
|
21
|
+
return
|
|
22
|
+
|
|
23
|
+
# Count current entries safely
|
|
24
|
+
try:
|
|
25
|
+
blacklist_entries = blacklist_store.get_all()
|
|
26
|
+
blacklist_count = len(blacklist_entries)
|
|
27
|
+
except Exception as e:
|
|
28
|
+
self.stdout.write(self.style.WARNING(f'Warning: Could not count blacklist entries: {e}'))
|
|
29
|
+
# Try to get count using clear_all method which returns count
|
|
30
|
+
blacklist_count = "unknown number of"
|
|
31
|
+
|
|
32
|
+
# Show what will be cleared
|
|
33
|
+
self.stdout.write(f"Clear Blacklist: Will remove {blacklist_count} blacklist entries")
|
|
34
|
+
|
|
35
|
+
if not confirm:
|
|
36
|
+
try:
|
|
37
|
+
response = input("Are you sure you want to proceed? [y/N]: ")
|
|
38
|
+
if response.lower() not in ['y', 'yes']:
|
|
39
|
+
self.stdout.write(self.style.WARNING('Operation cancelled'))
|
|
40
|
+
return
|
|
41
|
+
except (EOFError, KeyboardInterrupt):
|
|
42
|
+
self.stdout.write(self.style.WARNING('\nOperation cancelled'))
|
|
43
|
+
return
|
|
44
|
+
|
|
45
|
+
# Perform the reset using clear_all for better performance
|
|
46
|
+
try:
|
|
47
|
+
if hasattr(blacklist_store, 'clear_all'):
|
|
48
|
+
deleted_count = blacklist_store.clear_all()
|
|
49
|
+
self.stdout.write(
|
|
50
|
+
self.style.SUCCESS(f"✅ Blacklist cleared: Deleted {deleted_count} entries")
|
|
51
|
+
)
|
|
52
|
+
else:
|
|
53
|
+
# Fallback to individual deletion
|
|
54
|
+
deleted_count = 0
|
|
55
|
+
for entry in blacklist_entries:
|
|
56
|
+
try:
|
|
57
|
+
blacklist_store.remove_ip(entry['ip_address'])
|
|
58
|
+
deleted_count += 1
|
|
59
|
+
except Exception as e:
|
|
60
|
+
self.stdout.write(self.style.WARNING(f"⚠️ Error removing IP {entry.get('ip_address', 'unknown')}: {e}"))
|
|
61
|
+
|
|
62
|
+
self.stdout.write(
|
|
63
|
+
self.style.SUCCESS(f"✅ Blacklist cleared: Deleted {deleted_count} entries")
|
|
64
|
+
)
|
|
65
|
+
except Exception as e:
|
|
66
|
+
self.stdout.write(self.style.ERROR(f'Error clearing blacklist: {e}'))
|
aiwaf/storage.py
CHANGED
|
@@ -132,6 +132,31 @@ class ModelBlacklistStore:
|
|
|
132
132
|
except Exception:
|
|
133
133
|
return []
|
|
134
134
|
|
|
135
|
+
@staticmethod
|
|
136
|
+
def get_all():
|
|
137
|
+
"""Get all blacklist entries as dictionaries"""
|
|
138
|
+
_import_models()
|
|
139
|
+
if BlacklistEntry is None:
|
|
140
|
+
return []
|
|
141
|
+
try:
|
|
142
|
+
return list(BlacklistEntry.objects.values('ip_address', 'reason', 'created_at'))
|
|
143
|
+
except Exception:
|
|
144
|
+
return []
|
|
145
|
+
|
|
146
|
+
@staticmethod
|
|
147
|
+
def clear_all():
|
|
148
|
+
"""Clear all blacklist entries"""
|
|
149
|
+
_import_models()
|
|
150
|
+
if BlacklistEntry is None:
|
|
151
|
+
return 0
|
|
152
|
+
try:
|
|
153
|
+
count = BlacklistEntry.objects.count()
|
|
154
|
+
BlacklistEntry.objects.all().delete()
|
|
155
|
+
return count
|
|
156
|
+
except Exception as e:
|
|
157
|
+
print(f"Error clearing all blacklist entries: {e}")
|
|
158
|
+
return 0
|
|
159
|
+
|
|
135
160
|
class ModelExemptionStore:
|
|
136
161
|
@staticmethod
|
|
137
162
|
def is_exempted(ip):
|
|
@@ -170,6 +195,16 @@ class ModelExemptionStore:
|
|
|
170
195
|
except Exception as e:
|
|
171
196
|
print(f"Error removing exemption for IP {ip}: {e}")
|
|
172
197
|
|
|
198
|
+
@staticmethod
|
|
199
|
+
def remove_ip(ip):
|
|
200
|
+
"""Remove IP from exemption list (alias for remove_exemption)"""
|
|
201
|
+
ModelExemptionStore.remove_exemption(ip)
|
|
202
|
+
|
|
203
|
+
@staticmethod
|
|
204
|
+
def add_ip(ip, reason="Manual exemption"):
|
|
205
|
+
"""Add IP to exemption list (alias for add_exemption)"""
|
|
206
|
+
ModelExemptionStore.add_exemption(ip, reason)
|
|
207
|
+
|
|
173
208
|
@staticmethod
|
|
174
209
|
def get_all_exempted_ips():
|
|
175
210
|
"""Get all exempted IPs"""
|
|
@@ -192,6 +227,20 @@ class ModelExemptionStore:
|
|
|
192
227
|
except Exception:
|
|
193
228
|
return []
|
|
194
229
|
|
|
230
|
+
@staticmethod
|
|
231
|
+
def clear_all():
|
|
232
|
+
"""Clear all exemption entries"""
|
|
233
|
+
_import_models()
|
|
234
|
+
if IPExemption is None:
|
|
235
|
+
return 0
|
|
236
|
+
try:
|
|
237
|
+
count = IPExemption.objects.count()
|
|
238
|
+
IPExemption.objects.all().delete()
|
|
239
|
+
return count
|
|
240
|
+
except Exception as e:
|
|
241
|
+
print(f"Error clearing all exemption entries: {e}")
|
|
242
|
+
return 0
|
|
243
|
+
|
|
195
244
|
class ModelKeywordStore:
|
|
196
245
|
@staticmethod
|
|
197
246
|
def add_keyword(keyword, count=1):
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
aiwaf/__init__.py,sha256=
|
|
1
|
+
aiwaf/__init__.py,sha256=BGGn_OwueGmxbbWRV-PwE7HGpzB5Ol61jhYI6z4tHug,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
|
|
5
5
|
aiwaf/middleware.py,sha256=EMAQA_Gnz0jv4nevlognT921ZeBEro13J_DSv_mQ3Dw,15482
|
|
6
6
|
aiwaf/middleware_logger.py,sha256=LWZVDAnjh6CGESirA8eMbhGgJKB7lVDGRQqVroH95Lo,4742
|
|
7
7
|
aiwaf/models.py,sha256=vQxgY19BDVMjoO903UNrTZC1pNoLltMU6wbyWPoAEns,2719
|
|
8
|
-
aiwaf/storage.py,sha256=
|
|
8
|
+
aiwaf/storage.py,sha256=vswojWT8KEH5h24TQ9wwYCsxRUOjaAKudtFJnFxNHKk,9914
|
|
9
9
|
aiwaf/trainer.py,sha256=1RPjWVOdGQ3qSrjFopw8HKu7THVTMvF4nNYouij6i_A,10685
|
|
10
10
|
aiwaf/utils.py,sha256=BJk5vJCYdGPl_4QQiknjhCbkzv5HZCXgFcBJDMJpHok,3390
|
|
11
11
|
aiwaf/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -14,8 +14,9 @@ aiwaf/management/commands/add_exemption.py,sha256=U_ByfJw1EstAZ8DaSoRb97IGwYzXs0
|
|
|
14
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
|
-
aiwaf/management/commands/aiwaf_reset.py,sha256=
|
|
17
|
+
aiwaf/management/commands/aiwaf_reset.py,sha256=wG7EcdPqkxmjF2ivQOmZ7swuvHVJ_OVLgOEijGLvmFs,5586
|
|
18
18
|
aiwaf/management/commands/check_dependencies.py,sha256=GOZl00pDwW2cJjDvIaCeB3yWxmeYcJDRTIpmOTLvy2c,37204
|
|
19
|
+
aiwaf/management/commands/clear_blacklist.py,sha256=Tisedg0EVlc3E01mA3hBZQorwMzc5j1cns-oYshja0g,2770
|
|
19
20
|
aiwaf/management/commands/clear_cache.py,sha256=cdnuTgxkhKLqT_6k6yTcEBlREovNRQxAE51ceXlGYMA,647
|
|
20
21
|
aiwaf/management/commands/debug_csv.py,sha256=Lddqp37mIn0zdvHf4GbuNTWYyJ5h8bumDcGmFSAioi0,6801
|
|
21
22
|
aiwaf/management/commands/detect_and_train.py,sha256=-o-LZ7QZ5GeJPCekryox1DGXKMmFEkwwrcDsiM166K0,269
|
|
@@ -27,8 +28,8 @@ aiwaf/management/commands/test_exemption_fix.py,sha256=ngyGaHUCmQQ6y--6j4q1viZJt
|
|
|
27
28
|
aiwaf/resources/model.pkl,sha256=5t6h9BX8yoh2xct85MXOO60jdlWyg1APskUOW0jZE1Y,1288265
|
|
28
29
|
aiwaf/templatetags/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
30
|
aiwaf/templatetags/aiwaf_tags.py,sha256=XXfb7Tl4DjU3Sc40GbqdaqOEtKTUKELBEk58u83wBNw,357
|
|
30
|
-
aiwaf-0.1.9.1.
|
|
31
|
-
aiwaf-0.1.9.1.
|
|
32
|
-
aiwaf-0.1.9.1.
|
|
33
|
-
aiwaf-0.1.9.1.
|
|
34
|
-
aiwaf-0.1.9.1.
|
|
31
|
+
aiwaf-0.1.9.1.9.dist-info/licenses/LICENSE,sha256=Ir8PX4dxgAcdB0wqNPIkw84fzIIRKE75NoUil9RX0QU,1069
|
|
32
|
+
aiwaf-0.1.9.1.9.dist-info/METADATA,sha256=YeyuawG8pPFTBrOOBp8MayiGxCdyywAFvKKMY8dIk-M,22145
|
|
33
|
+
aiwaf-0.1.9.1.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
34
|
+
aiwaf-0.1.9.1.9.dist-info/top_level.txt,sha256=kU6EyjobT6UPCxuWpI_BvcHDG0I2tMgKaPlWzVxe2xI,6
|
|
35
|
+
aiwaf-0.1.9.1.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|