Commit c4631b07 by Bach Dániel

firewall: remove Rule.r_type

parent c1c44020
...@@ -49,7 +49,7 @@ class RuleAdmin(admin.ModelAdmin): ...@@ -49,7 +49,7 @@ class RuleAdmin(admin.ModelAdmin):
list_display = ('r_type', 'color_desc', 'owner', 'extra', 'direction', list_display = ('r_type', 'color_desc', 'owner', 'extra', 'direction',
'accept', 'proto', 'sport', 'dport', 'nat', 'accept', 'proto', 'sport', 'dport', 'nat',
'nat_dport', 'used_in') 'nat_dport', 'used_in')
list_filter = ('r_type', 'vlan', 'owner', 'direction', 'accept', list_filter = ('vlan', 'owner', 'direction', 'accept',
'proto', 'nat') 'proto', 'nat')
def color_desc(self, instance): def color_desc(self, instance):
......
...@@ -62,10 +62,6 @@ class Rule(models.Model): ...@@ -62,10 +62,6 @@ class Rule(models.Model):
verbose_name=_("owner"), verbose_name=_("owner"),
help_text=_("The user responsible for " help_text=_("The user responsible for "
"this rule.")) "this rule."))
r_type = models.CharField(max_length=10, verbose_name=_("Rule type"),
choices=CHOICES_type,
help_text=_("The type of entity the rule "
"belongs to."))
nat = models.BooleanField(default=False, verbose_name=_("NAT"), nat = models.BooleanField(default=False, verbose_name=_("NAT"),
help_text=_("If network address translation " help_text=_("If network address translation "
"shoud be done.")) "shoud be done."))
...@@ -129,6 +125,15 @@ class Rule(models.Model): ...@@ -129,6 +125,15 @@ class Rule(models.Model):
(("dport=%s " % self.dport) if self.dport else '')), (("dport=%s " % self.dport) if self.dport else '')),
'desc': self.description} 'desc': self.description}
@property
def r_type(self):
fields = [self.vlan, self.vlangroup, self.host, self.hostgroup,
self.firewall]
for field in fields:
if field is not None:
return field.__class__.__name__.lower()
return None
@models.permalink @models.permalink
def get_absolute_url(self): def get_absolute_url(self):
return ('network.rule', None, {'pk': self.pk}) return ('network.rule', None, {'pk': self.pk})
...@@ -137,7 +142,6 @@ class Rule(models.Model): ...@@ -137,7 +142,6 @@ class Rule(models.Model):
verbose_name = _("rule") verbose_name = _("rule")
verbose_name_plural = _("rules") verbose_name_plural = _("rules")
ordering = ( ordering = (
'r_type',
'direction', 'direction',
'proto', 'proto',
'sport', 'sport',
...@@ -495,11 +499,11 @@ class Host(models.Model): ...@@ -495,11 +499,11 @@ class Host(models.Model):
if public < 1024: if public < 1024:
raise ValidationError(_("Only ports above 1024 can be used.")) raise ValidationError(_("Only ports above 1024 can be used."))
rule = Rule(direction='1', owner=self.owner, dport=public, rule = Rule(direction='1', owner=self.owner, dport=public,
proto=proto, nat=True, accept=True, r_type="host", proto=proto, nat=True, accept=True,
nat_dport=private, host=self, foreign_network=vg) nat_dport=private, host=self, foreign_network=vg)
else: else:
rule = Rule(direction='1', owner=self.owner, dport=public, rule = Rule(direction='1', owner=self.owner, dport=public,
proto=proto, nat=False, accept=True, r_type="host", proto=proto, nat=False, accept=True,
host=self, foreign_network=vg) host=self, foreign_network=vg)
rule.full_clean() rule.full_clean()
......
...@@ -166,7 +166,6 @@ class RuleForm(ModelForm): ...@@ -166,7 +166,6 @@ class RuleForm(ModelForm):
'extra', 'extra',
'accept', 'accept',
'owner', 'owner',
'r_type',
'nat', 'nat',
'nat_dport', 'nat_dport',
), ),
......
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