Commit bc37daf9 by Dudás Ádám

guideline enforcement

parent 0689cfbd
...@@ -21,9 +21,10 @@ class HostAdmin(admin.ModelAdmin): ...@@ -21,9 +21,10 @@ class HostAdmin(admin.ModelAdmin):
inlines = (AliasInline, RuleInline) inlines = (AliasInline, RuleInline)
def groups_l(self, instance): def groups_l(self, instance):
"""Returns instance's groups' names as a comma-separated list."""
retval = [] retval = []
for i in instance.groups.all(): for group in instance.groups.all():
retval.append(i.name) retval.append(group.name)
return u', '.join(retval) return u', '.join(retval)
class HostInline(contrib.admin.TabularInline): class HostInline(contrib.admin.TabularInline):
...@@ -44,25 +45,34 @@ class RuleAdmin(admin.ModelAdmin): ...@@ -44,25 +45,34 @@ class RuleAdmin(admin.ModelAdmin):
'proto', 'nat') 'proto', 'nat')
def color_desc(self, instance): def color_desc(self, instance):
"""Returns a colorful description of the instance."""
para = '</span>' para = '</span>'
if(instance.dport): if instance.dport:
para = "dport=%s %s" % (instance.dport, para) para = 'dport=%s %s' % (instance.dport, para)
if(instance.sport): if instance.sport:
para = "sport=%s %s" % (instance.sport, para) para = 'sport=%s %s' % (instance.sport, para)
if(instance.proto): if instance.proto:
para = "proto=%s %s" % (instance.proto, para) para = 'proto=%s %s' % (instance.proto, para)
para= u'<span style="color: #00FF00;">' + para para = u'<span style="color: #00FF00;">' + para
return u'<span style="color: #FF0000;">[' + instance.r_type + u']</span> ' + (instance.foreign_network.name + u'<span style="color: #0000FF;"> ▸ </span>' + instance.r_type if instance.direction=='1' else instance.r_type + u'<span style="color: #0000FF;"> ▸ </span>' + instance.foreign_network.name) + ' ' + para + ' ' + instance.description return (
u'<span style="color: #FF0000;">[%s]</span> ' % instance.r_type +
(u'%s<span style="color: #0000FF;"> ▸ </span>%s' %
((instance.foreign_network.name, instance.r_type)
if instance.direction == '1' else
(instance.r_type, instance.foreign_network.name))) +
' ' + para + ' ' + instance.description)
color_desc.allow_tags = True color_desc.allow_tags = True
def vlan_l(self, instance): def vlan_l(self, instance):
"""Returns instance's VLANs' names as a comma-separated list."""
retval = [] retval = []
for vl in instance.foreign_network.vlans.all(): for vlan in instance.foreign_network.vlans.all():
retval.append(vl.name) retval.append(vlan.name)
return u', '.join(retval) return u', '.join(retval)
def used_in(self, instance): def used_in(self, instance):
for field in [instance.vlan, instance.vlangroup, instance.host, instance.hostgroup, instance.firewall]: for field in [instance.vlan, instance.vlangroup, instance.host,
instance.hostgroup, instance.firewall]:
if field is not None: if field is not None:
return unicode(field) + ' ' + field._meta.object_name return unicode(field) + ' ' + field._meta.object_name
......
...@@ -34,17 +34,19 @@ class MACAddressField(models.Field): ...@@ -34,17 +34,19 @@ class MACAddressField(models.Field):
add_introspection_rules([], ["firewall\.fields\.MACAddressField"]) add_introspection_rules([], ["firewall\.fields\.MACAddressField"])
def val_alfanum(value): def val_alfanum(value):
"""Check whether the parameter is a valid alphanumeric value."""
if alfanum_re.search(value) is None: if alfanum_re.search(value) is None:
raise ValidationError( raise ValidationError(
_(u'%s - only letters, numbers, underscores and hyphens are ' _(u'%s - only letters, numbers, underscores and hyphens are '
'allowed!') % value) 'allowed!') % value)
def val_domain(value): def val_domain(value):
"""Check wheter the parameter is a valid domin."""
if domain_re.search(value) is None: if domain_re.search(value) is None:
raise ValidationError(_(u'%s - invalid domain') % value) raise ValidationError(_(u'%s - invalid domain') % value)
def ipv4_2_ipv6(ipv4): def ipv4_2_ipv6(ipv4):
"""Convert IPv4 addr. string to IPv6 addr. string.""" """Convert IPv4 address string to IPv6 address string."""
m = ipv4_re.match(ipv4) m = ipv4_re.match(ipv4)
if m is None: if m is None:
raise ValidationError(_(u'%s - not an IPv4 address') % ipv4) raise ValidationError(_(u'%s - not an IPv4 address') % ipv4)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment