Commit de7816ad by Őry Máté

firewall: describe Rule model

parent d0ae883e
...@@ -13,12 +13,13 @@ import re ...@@ -13,12 +13,13 @@ import re
import random import random
settings = django.conf.settings.FIREWALL_SETTINGS settings = django.conf.settings.FIREWALL_SETTINGS
class Rule(models.Model): class Rule(models.Model):
""" """
Common firewall rule A rule of a packet filter, changing the behavior of a host, vlan or firewall.
Rule can be applied to: Host, Firewall, Vlan
Some rules accept or deny packets matching some criteria.
Others set address translation or other free-form iptables parameters.
""" """
CHOICES_type = (('host', 'host'), ('firewall', 'firewall'), CHOICES_type = (('host', 'host'), ('firewall', 'firewall'),
('vlan', 'vlan')) ('vlan', 'vlan'))
...@@ -26,35 +27,53 @@ class Rule(models.Model): ...@@ -26,35 +27,53 @@ class Rule(models.Model):
CHOICES_dir = (('0', 'out'), ('1', 'in')) CHOICES_dir = (('0', 'out'), ('1', 'in'))
direction = models.CharField(max_length=1, choices=CHOICES_dir, direction = models.CharField(max_length=1, choices=CHOICES_dir,
blank=False) blank=False, verbose_name=_("direction"),
description = models.TextField(blank=True) help_text=_("If the rule matches egress or ingress packets."))
foreign_network = models.ForeignKey('VlanGroup', description = models.TextField(blank=True,
related_name="ForeignRules") help_text=_("Why is the rule needed, or how does it work."))
dport = models.IntegerField(blank=True, null=True, foreign_network = models.ForeignKey('VlanGroup', verbose_name=_("foreign network"),
validators=[MinValueValidator(1), MaxValueValidator(65535)]) help_text=_("The group of vlans the matching packet goes to (direction out) or from (in)."),
sport = models.IntegerField(blank=True, null=True, related_name="ForeignRules")
validators=[MinValueValidator(1), MaxValueValidator(65535)]) dport = models.IntegerField(blank=True, null=True, verbose_name=_("dest. port"),
validators=[MinValueValidator(1), MaxValueValidator(65535)],
help_text=_("Destination port number of packets that match."))
sport = models.IntegerField(blank=True, null=True, verbose_name=_("source port"),
validators=[MinValueValidator(1), MaxValueValidator(65535)],
help_text=_("Source port number of packets that match."))
proto = models.CharField(max_length=10, choices=CHOICES_proto, proto = models.CharField(max_length=10, choices=CHOICES_proto,
blank=True, null=True) blank=True, null=True, verbose_name=_("protocol"),
extra = models.TextField(blank=True) help_text=_("Protocol of packets that match."))
accept = models.BooleanField(default=False) extra = models.TextField(blank=True, verbose_name=_("extra arguments"),
owner = models.ForeignKey(User, blank=True, null=True) help_text=_("Additional arguments passed literally to the iptables-rule."))
r_type = models.CharField(max_length=10, choices=CHOICES_type) accept = models.BooleanField(default=False, verbose_name=_("accept"),
nat = models.BooleanField(default=False) help_text=_("Accept the matching packets (or deny if not checked)."))
owner = models.ForeignKey(User, blank=True, null=True,
verbose_name=_("owner"),
help_text=_("The user responsible for 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"),
help_text=_("If network address translation shoud be done."))
nat_dport = models.IntegerField(blank=True, null=True, nat_dport = models.IntegerField(blank=True, null=True,
validators=[MinValueValidator(1), MaxValueValidator(65535)]) help_text=_("Rewrite destination port number to."),
created_at = models.DateTimeField(auto_now_add=True) validators=[MinValueValidator(1),
modified_at = models.DateTimeField(auto_now=True) MaxValueValidator(65535)])
created_at = models.DateTimeField(auto_now_add=True, verbose_name=_("created at"))
modified_at = models.DateTimeField(auto_now=True, verbose_name=_("modified at"))
vlan = models.ForeignKey('Vlan', related_name="rules", blank=True, vlan = models.ForeignKey('Vlan', related_name="rules", blank=True,
null=True) null=True, verbose_name=_("vlan"),
help_text=_("Vlan the rule applies to (if type is vlan)."))
vlangroup = models.ForeignKey('VlanGroup', related_name="rules", vlangroup = models.ForeignKey('VlanGroup', related_name="rules",
blank=True, null=True) blank=True, null=True, verbose_name=_("vlan group"),
help_text=_("Group of vlans the rule applies to (if type is vlan)."))
host = models.ForeignKey('Host', related_name="rules", blank=True, host = models.ForeignKey('Host', related_name="rules", blank=True,
null=True) verbose_name=_('host'), null=True, help_text=_("Host the rule applies to (if type is host)."))
hostgroup = models.ForeignKey('Group', related_name="rules", hostgroup = models.ForeignKey('Group', related_name="rules", verbose_name=_("host group"),
blank=True, null=True) blank=True, null=True, help_text=_("Group of hosts the rule applies to (if type is host)."))
firewall = models.ForeignKey('Firewall', related_name="rules", firewall = models.ForeignKey('Firewall', related_name="rules", verbose_name=_("firewall"),
help_text=_("Firewall the rule applies to (if type is firewall)."),
blank=True, null=True) blank=True, null=True)
def __unicode__(self): def __unicode__(self):
...@@ -79,6 +98,11 @@ class Rule(models.Model): ...@@ -79,6 +98,11 @@ 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}
class Meta:
verbose_name = _("rule")
verbose_name_plural = _("rules")
ordering = ('r_type', 'direction', 'proto', 'sport', 'dport', 'nat_dport', 'host', )
class Vlan(models.Model): class Vlan(models.Model):
vid = models.IntegerField(unique=True) vid = models.IntegerField(unique=True)
name = models.CharField(max_length=20, unique=True, name = models.CharField(max_length=20, unique=True,
......
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