コード例 #1
0
ファイル: forms.py プロジェクト: HalasNet/felix
 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")),
     ) 
コード例 #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")),
        )
コード例 #3
0
def get_ranges(packet_field, mac_dl=False, integer=False):

    ints = list()
    params = packet_field['value'].split(',')
    if mac_dl == True:
        for param in params: 
            ints.append(mac_to_int(param))
    elif integer == True:
        for param in params:
            ints.append(int(param))
    else:
	for param in params:
	    ints.append(int(param,16)) # all params should be in hexadecimal format
             
    ints.sort()
    ranges = list()
    current_range = list()
    for i,intn in enumerate(ints):
	if not len(current_range) > 0 or current_range[-1] == (intn -1):
	    current_range.append(intn)
        if not (current_range[-1] == (intn -1)) or i == len(ints)-1:
            if mac_dl == True:
                ranges.append((int_to_mac(current_range[0]),int_to_mac(current_range[-1])))
            elif integer == False:
                ranges.append((hex(current_range[0]),hex(current_range[-1])))
	    else:
		ranges.append((current_range[0],current_range[-1]))
	    current_range = []
    return ranges
コード例 #4
0
 def get_ranges(packet_field, mac_dl=False, integer=False):
 
     ints = list()
     params = packet_field.split(',')
     if not type(params) == list:
         params = [params]
     if mac_dl == True:
         for param in params: 
             ints.append(mac_to_int(param))
     elif integer == True:
         for param in params:
             try:
                 ints.append(int(param))
             except Exception as e:
                 ints.append(int(param,16))
                 
     else:
 	    for param in params:
 	        ints.append(int(param,16)) # all params should be in hexadecimal format
              
     ints.sort()
     ranges = list()
     current_range = list()
     for i,intn in enumerate(ints):
 	    if not len(current_range) > 0 or current_range[-1] == (intn -1):
 	        current_range.append(intn)
         if not (current_range[-1] == (intn -1)) or i == len(ints)-1:
             if mac_dl == True:
                 ranges.append((int_to_mac(current_range[0]),int_to_mac(current_range[-1])))
             elif integer == False:
                 ranges.append((hex(current_range[0]),hex(current_range[-1])))
 	        else:
 		    ranges.append((current_range[0],current_range[-1]))
 	    current_range = []
     return ranges
コード例 #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
コード例 #6
0
ファイル: forms.py プロジェクト: HalasNet/felix
 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