Exemple #1
0
 def get_flowspace(self,FS_Object):
     cleaned_data = self.saved_cleaned_data
     if self._errors:
         return None
     
     return FS_Object(
         mac_src_s = mac_to_int(cleaned_data.get("mac_from_s")),
         mac_src_e = mac_to_int(cleaned_data.get("mac_from_e")),
         mac_dst_s = mac_to_int(cleaned_data.get("mac_to_s")),
         mac_dst_e = mac_to_int(cleaned_data.get("mac_to_e")),
         eth_type_s = int(cleaned_data.get("eth_type_s")),
         eth_type_e = int(cleaned_data.get("eth_type_e")),
         vlan_id_s = int(cleaned_data.get("vlan_id_s")),
         vlan_id_e = int(cleaned_data.get("vlan_id_e")),
         ip_src_s = dotted_ip_to_int(cleaned_data.get("ip_from_s")),
         ip_src_e = dotted_ip_to_int(cleaned_data.get("ip_from_e")),
         ip_dst_s = dotted_ip_to_int(cleaned_data.get("ip_to_s")),
         ip_dst_e = dotted_ip_to_int(cleaned_data.get("ip_to_e")),
         ip_proto_s = int(cleaned_data.get("ip_proto_s")),
         ip_proto_e = int(cleaned_data.get("ip_proto_e")),
         tp_src_s = int(cleaned_data.get("tp_from_s")),
         tp_src_e = int(cleaned_data.get("tp_from_e")),
         tp_dst_s = int(cleaned_data.get("tp_to_s")),
         tp_dst_e = int(cleaned_data.get("tp_to_e")),
     ) 
Exemple #2
0
    def get_flowspace(self, FS_Object):
        cleaned_data = self.saved_cleaned_data
        if self._errors:
            return None

        return FS_Object(
            mac_src_s=mac_to_int(cleaned_data.get("mac_from_s")),
            mac_src_e=mac_to_int(cleaned_data.get("mac_from_e")),
            mac_dst_s=mac_to_int(cleaned_data.get("mac_to_s")),
            mac_dst_e=mac_to_int(cleaned_data.get("mac_to_e")),
            eth_type_s=int(cleaned_data.get("eth_type_s")),
            eth_type_e=int(cleaned_data.get("eth_type_e")),
            vlan_id_s=int(cleaned_data.get("vlan_id_s")),
            vlan_id_e=int(cleaned_data.get("vlan_id_e")),
            ip_src_s=dotted_ip_to_int(cleaned_data.get("ip_from_s")),
            ip_src_e=dotted_ip_to_int(cleaned_data.get("ip_from_e")),
            ip_dst_s=dotted_ip_to_int(cleaned_data.get("ip_to_s")),
            ip_dst_e=dotted_ip_to_int(cleaned_data.get("ip_to_e")),
            ip_proto_s=int(cleaned_data.get("ip_proto_s")),
            ip_proto_e=int(cleaned_data.get("ip_proto_e")),
            tp_src_s=int(cleaned_data.get("tp_from_s")),
            tp_src_e=int(cleaned_data.get("tp_from_e")),
            tp_dst_s=int(cleaned_data.get("tp_to_s")),
            tp_dst_e=int(cleaned_data.get("tp_to_e")),
        )
def cidr_ip_to_range(cidr_ip): 
    ip, mask = cidr_ip['value'].split('/')
    ip_int = dotted_ip_to_int(ip)
    addresses = (2**(32-int(mask)))-1
    final_ip_int = ip_int + addresses
    dotted_ip = int_to_dotted_ip(final_ip_int)
    return ip,dotted_ip
Exemple #4
0
 def cidr_ip_to_range(cidr_ip):
     ip, mask = cidr_ip.split('/')
     ip_int = dotted_ip_to_int(ip)
     addresses = (2**(32-int(mask)))-1
     final_ip_int = ip_int + addresses
     dotted_ip = int_to_dotted_ip(final_ip_int)
     return ip_int,final_ip_int
Exemple #5
0
    def clean(self):
        if self._errors:
            return self.cleaned_data
        cleaned_data = self.cleaned_data
        self.saved_cleaned_data = cleaned_data
        mac_from_s = cleaned_data.get("mac_from_s")
        mac_from_e = cleaned_data.get("mac_from_e")
        mac_to_s = cleaned_data.get("mac_to_s")
        mac_to_e = cleaned_data.get("mac_to_e")
        eth_type_s = cleaned_data.get("eth_type_s")
        eth_type_e = cleaned_data.get("eth_type_e")
        vlan_id_s = cleaned_data.get("vlan_id_s")
        vlan_id_e = cleaned_data.get("vlan_id_e")
        ip_from_s = cleaned_data.get("ip_from_s")
        ip_from_e = cleaned_data.get("ip_from_e")
        ip_to_s = cleaned_data.get("ip_to_s")
        ip_to_e = cleaned_data.get("ip_to_e")
        ip_proto_s = cleaned_data.get("ip_proto_s")
        ip_proto_e = cleaned_data.get("ip_proto_e")
        tp_from_s = cleaned_data.get("tp_from_s")
        tp_from_e = cleaned_data.get("tp_from_e")
        tp_to_s = cleaned_data.get("tp_to_s")
        tp_to_e = cleaned_data.get("tp_to_e")
        if (mac_to_int(mac_from_s) > mac_to_int(mac_from_e)):
            raise forms.ValidationError("Empty Source MAC Range")
        if (mac_to_int(mac_to_s) > mac_to_int(mac_to_e)):
            raise forms.ValidationError("Empty Destination MAC Range")
        if (eth_type_s > eth_type_e):
            raise forms.ValidationError("Empty Ethernet Type Range")
        if (vlan_id_s > vlan_id_e):
            raise forms.ValidationError("Empty VLAN Range")
        if (dotted_ip_to_int(ip_from_s) > dotted_ip_to_int(ip_from_e)):
            raise forms.ValidationError("Empty Source IP Range")
        if (dotted_ip_to_int(ip_to_s) > dotted_ip_to_int(ip_to_e)):
            raise forms.ValidationError("Empty Destination IP Range")
        if (ip_proto_s > ip_proto_e):
            raise forms.ValidationError("Empty IP Protocol Range")
        if (tp_from_s > tp_from_e):
            raise forms.ValidationError("Empty Source Transport Port Range")
        if (tp_to_s > tp_to_e):
            raise forms.ValidationError(
                "Empty Destination Transport Port Range")

        return cleaned_data
Exemple #6
0
 def clean(self):
     if self._errors:
         return self.cleaned_data
     cleaned_data = self.cleaned_data
     self.saved_cleaned_data = cleaned_data
     mac_from_s = cleaned_data.get("mac_from_s")
     mac_from_e = cleaned_data.get("mac_from_e")
     mac_to_s = cleaned_data.get("mac_to_s")
     mac_to_e = cleaned_data.get("mac_to_e")
     eth_type_s = cleaned_data.get("eth_type_s")
     eth_type_e = cleaned_data.get("eth_type_e")
     vlan_id_s = cleaned_data.get("vlan_id_s")
     vlan_id_e = cleaned_data.get("vlan_id_e")
     ip_from_s = cleaned_data.get("ip_from_s")
     ip_from_e = cleaned_data.get("ip_from_e")
     ip_to_s = cleaned_data.get("ip_to_s")
     ip_to_e = cleaned_data.get("ip_to_e")
     ip_proto_s = cleaned_data.get("ip_proto_s")
     ip_proto_e = cleaned_data.get("ip_proto_e")
     tp_from_s = cleaned_data.get("tp_from_s")
     tp_from_e = cleaned_data.get("tp_from_e")
     tp_to_s = cleaned_data.get("tp_to_s")
     tp_to_e = cleaned_data.get("tp_to_e")
     if (mac_to_int(mac_from_s) > mac_to_int(mac_from_e)):
         raise forms.ValidationError("Empty Source MAC Range")
     if (mac_to_int(mac_to_s) > mac_to_int(mac_to_e)):
         raise forms.ValidationError("Empty Destination MAC Range")
     if (eth_type_s > eth_type_e):
         raise forms.ValidationError("Empty Ethernet Type Range")
     if (vlan_id_s > vlan_id_e):
         raise forms.ValidationError("Empty VLAN Range")
     if (dotted_ip_to_int(ip_from_s) > dotted_ip_to_int(ip_from_e)):
         raise forms.ValidationError("Empty Source IP Range")
     if (dotted_ip_to_int(ip_to_s) > dotted_ip_to_int(ip_to_e)):
         raise forms.ValidationError("Empty Destination IP Range")
     if (ip_proto_s > ip_proto_e):
         raise forms.ValidationError("Empty IP Protocol Range")
     if (tp_from_s > tp_from_e):
         raise forms.ValidationError("Empty Source Transport Port Range")
     if (tp_to_s > tp_to_e):
         raise forms.ValidationError("Empty Destination Transport Port Range")
         
     return cleaned_data