Revision ab02d61c flowspec/forms.py
b/flowspec/forms.py | ||
---|---|---|
49 | 49 |
else: |
50 | 50 |
return self.cleaned_data["source"] |
51 | 51 |
except Exception: |
52 |
error_text = 'Invalid network address format'
|
|
52 |
error_text = _('Invalid network address format')
|
|
53 | 53 |
if private_error: |
54 |
error_text = 'Private addresses not allowed'
|
|
54 |
error_text = _('Private addresses not allowed')
|
|
55 | 55 |
if protected_error: |
56 |
error_text = 'You have no authority on this subnet'
|
|
56 |
error_text = _('You have no authority on this subnet')
|
|
57 | 57 |
raise forms.ValidationError(error_text) |
58 | 58 |
|
59 | 59 |
def clean_destination(self): |
... | ... | |
74 | 74 |
settings.NOTIFY_ADMIN_MAILS, fail_silently=True) |
75 | 75 |
raise Exception |
76 | 76 |
if address.prefixlen < settings.PREFIX_LENGTH: |
77 |
error = "Currently no prefix lengths < %s are allowed" %settings.PREFIX_LENGTH
|
|
77 |
error = _("Currently no prefix lengths < %s are allowed") %settings.PREFIX_LENGTH
|
|
78 | 78 |
raise Exception |
79 | 79 |
return self.cleaned_data["destination"] |
80 | 80 |
except Exception: |
81 |
error_text = 'Invalid network address format'
|
|
81 |
error_text = _('Invalid network address format')
|
|
82 | 82 |
if error: |
83 | 83 |
error_text = error |
84 | 84 |
if protected_error: |
85 |
error_text = 'You have no authority on this subnet'
|
|
85 |
error_text = _('You have no authority on this subnet')
|
|
86 | 86 |
raise forms.ValidationError(error_text) |
87 | 87 |
|
88 | 88 |
def clean_expires(self): |
... | ... | |
96 | 96 |
|
97 | 97 |
def clean(self): |
98 | 98 |
if self.errors: |
99 |
raise forms.ValidationError('Errors in form. Please review and fix them')
|
|
99 |
raise forms.ValidationError(_('Errors in form. Please review and fix them'))
|
|
100 | 100 |
name = self.cleaned_data.get('name', None) |
101 | 101 |
source = self.cleaned_data.get('source', None) |
102 | 102 |
sourceports = self.cleaned_data.get('sourceport', None) |
... | ... | |
116 | 116 |
if IPNetwork(destination) in net: |
117 | 117 |
mynetwork = True |
118 | 118 |
if not mynetwork: |
119 |
raise forms.ValidationError('Destination address/network should belong to your administrative address space. Check My Profile to review your networks')
|
|
119 |
raise forms.ValidationError(_('Destination address/network should belong to your administrative address space. Check My Profile to review your networks'))
|
|
120 | 120 |
if (sourceports and ports): |
121 |
raise forms.ValidationError('Cannot create rule for source ports and ports at the same time. Select either ports or source ports')
|
|
121 |
raise forms.ValidationError(_('Cannot create rule for source ports and ports at the same time. Select either ports or source ports'))
|
|
122 | 122 |
if (destinationports and ports): |
123 |
raise forms.ValidationError('Cannot create rule for destination ports and ports at the same time. Select either ports or destination ports')
|
|
123 |
raise forms.ValidationError(_('Cannot create rule for destination ports and ports at the same time. Select either ports or destination ports'))
|
|
124 | 124 |
if sourceports and not source: |
125 |
raise forms.ValidationError('Once source port is matched, source has to be filled as well. Either deselect source port or fill source address')
|
|
125 |
raise forms.ValidationError(_('Once source port is matched, source has to be filled as well. Either deselect source port or fill source address'))
|
|
126 | 126 |
if destinationports and not destination: |
127 |
raise forms.ValidationError('Once destination port is matched, destination has to be filled as well. Either deselect destination port or fill destination address')
|
|
127 |
raise forms.ValidationError(_('Once destination port is matched, destination has to be filled as well. Either deselect destination port or fill destination address'))
|
|
128 | 128 |
if not (source or sourceports or ports or destination or destinationports): |
129 |
raise forms.ValidationError('Fill at least a Rule Match Condition')
|
|
129 |
raise forms.ValidationError(_('Fill at least a Rule Match Condition'))
|
|
130 | 130 |
if not user.is_superuser and then[0].action not in settings.UI_USER_THEN_ACTIONS: |
131 |
raise forms.ValidationError('This action "%s" is not permitted' %(then[0].action))
|
|
131 |
raise forms.ValidationError(_('This action "%s" is not permitted') %(then[0].action))
|
|
132 | 132 |
existing_routes = Route.objects.exclude(status='EXPIRED').exclude(status='ERROR').exclude(status='ADMININACTIVE') |
133 | 133 |
existing_routes = existing_routes.filter(applier__userprofile__peer=peer) |
134 | 134 |
if source: |
... | ... | |
180 | 180 |
try: |
181 | 181 |
assert(int(action_value)) |
182 | 182 |
if int(action_value) < 50: |
183 |
raise forms.ValidationError('Rate-limiting cannot be < 50kbps')
|
|
183 |
raise forms.ValidationError(_('Rate-limiting cannot be < 50kbps'))
|
|
184 | 184 |
return "%s" %self.cleaned_data["action_value"] |
185 | 185 |
except: |
186 |
raise forms.ValidationError('Rate-limiting should be an integer < 50')
|
|
186 |
raise forms.ValidationError(_('Rate-limiting should be an integer < 50'))
|
|
187 | 187 |
else: |
188 |
raise forms.ValidationError('Cannot be empty')
|
|
188 |
raise forms.ValidationError(_('Cannot be empty'))
|
|
189 | 189 |
|
190 | 190 |
def clean_action(self): |
191 | 191 |
action = self.cleaned_data['action'] |
192 | 192 |
if action != 'rate-limit': |
193 |
raise forms.ValidationError('Cannot select something other than rate-limit')
|
|
193 |
raise forms.ValidationError(_('Cannot select something other than rate-limit'))
|
|
194 | 194 |
else: |
195 | 195 |
return self.cleaned_data["action"] |
196 | 196 |
|
... | ... | |
207 | 207 |
assert(int(port)) |
208 | 208 |
return "%s" %self.cleaned_data["port"] |
209 | 209 |
except: |
210 |
raise forms.ValidationError('Port should be an integer')
|
|
210 |
raise forms.ValidationError(_('Port should be an integer'))
|
|
211 | 211 |
else: |
212 |
raise forms.ValidationError('Cannot be empty')
|
|
212 |
raise forms.ValidationError(_('Cannot be empty'))
|
|
213 | 213 |
|
214 | 214 |
def value_list_to_list(valuelist): |
215 | 215 |
vl = [] |
Also available in: Unified diff