Revision d4e660c4
b/flowspec/forms.py | ||
---|---|---|
63 | 63 |
data = self.cleaned_data['source'] |
64 | 64 |
private_error = False |
65 | 65 |
protected_error = False |
66 |
networkaddr_error = False |
|
67 |
broadcast_error = False |
|
66 | 68 |
if data: |
67 | 69 |
try: |
68 | 70 |
address = IPNetwork(data) |
... | ... | |
77 | 79 |
if address.is_private: |
78 | 80 |
private_error = True |
79 | 81 |
raise Exception |
80 |
else: |
|
81 |
return self.cleaned_data["source"] |
|
82 |
if address.version == 4 and int(address.prefixlen) == 32: |
|
83 |
if int(address.network.compressed.split('.')[-1]) == 0: |
|
84 |
broadcast_error = True |
|
85 |
raise Exception |
|
86 |
elif int(address.network.compressed.split('.')[-1]) == 255: |
|
87 |
networkaddr_error = True |
|
88 |
raise Exception |
|
89 |
return self.cleaned_data["source"] |
|
82 | 90 |
except Exception: |
83 | 91 |
error_text = _('Invalid network address format') |
84 | 92 |
if private_error: |
85 | 93 |
error_text = _('Private addresses not allowed') |
94 |
if networkaddr_error: |
|
95 |
error_text = _('Malformed address format. Cannot be ...255/32') |
|
96 |
if broadcast_error: |
|
97 |
error_text = _('Malformed address format. Cannot be ...0/32') |
|
86 | 98 |
if protected_error: |
87 | 99 |
error_text = _('You have no authority on this subnet') |
88 | 100 |
raise forms.ValidationError(error_text) |
... | ... | |
93 | 105 |
data = self.cleaned_data['destination'] |
94 | 106 |
error = None |
95 | 107 |
protected_error = False |
108 |
networkaddr_error = False |
|
109 |
broadcast_error = False |
|
96 | 110 |
if data: |
97 | 111 |
try: |
98 | 112 |
address = IPNetwork(data) |
... | ... | |
107 | 121 |
if address.prefixlen < settings.PREFIX_LENGTH: |
108 | 122 |
error = _("Currently no prefix lengths < %s are allowed") %settings.PREFIX_LENGTH |
109 | 123 |
raise Exception |
124 |
if address.version == 4 and int(address.prefixlen) == 32: |
|
125 |
if int(address.network.compressed.split('.')[-1]) == 0: |
|
126 |
broadcast_error = True |
|
127 |
raise Exception |
|
128 |
elif int(address.network.compressed.split('.')[-1]) == 255: |
|
129 |
networkaddr_error = True |
|
130 |
raise Exception |
|
110 | 131 |
return self.cleaned_data["destination"] |
111 | 132 |
except Exception: |
112 | 133 |
error_text = _('Invalid network address format') |
... | ... | |
114 | 135 |
error_text = error |
115 | 136 |
if protected_error: |
116 | 137 |
error_text = _('You have no authority on this subnet') |
138 |
if networkaddr_error: |
|
139 |
error_text = _('Malformed address format. Cannot be ...255/32') |
|
140 |
if broadcast_error: |
|
141 |
error_text = _('Malformed address format. Cannot be ...0/32') |
|
117 | 142 |
raise forms.ValidationError(error_text) |
118 | 143 |
|
119 | 144 |
def clean_expires(self): |
... | ... | |
243 | 268 |
port = self.cleaned_data['port'] |
244 | 269 |
if port: |
245 | 270 |
try: |
246 |
assert(int(port)) |
|
271 |
p = int(port) |
|
272 |
if int(port) > 65535 or int(port) < 0: |
|
273 |
raise forms.ValidationError(_('')) |
|
247 | 274 |
return "%s" %self.cleaned_data["port"] |
275 |
except forms.ValidationError: |
|
276 |
raise forms.ValidationError(_('Port should be < 65535 and >= 0')) |
|
248 | 277 |
except: |
249 | 278 |
raise forms.ValidationError(_('Port should be an integer')) |
250 | 279 |
else: |
Also available in: Unified diff