예제 #1
0
파일: _csv.py 프로젝트: rloza08/NSMK-Code
    def validate_port(self, entry, field, line_count):
        item = entry.get(field)
        items = item.split(",")
        item_count = 0
        for item in items:
            item_count += 1
            # Is it a port range
            if item == "any":
                if len(items)==1:
                    return True
            elif item.find("-") > 0:
                if len(items)==1:
                    range = item.split("-")
                    if len(range) == 2:
                        if is_numeric_in_range(range[0], 1, 65535) and \
                                is_numeric_in_range(range[1], 1, 65535):
                            return True
            else:
                # It has to be a valid port
                if is_numeric_in_range(item, 1, 65535):
                    return True
            str = "line #:{} - invalid {} : {}".format(line_count, field, item)
            l.message_user(str)

        return False
예제 #2
0
파일: _csv.py 프로젝트: rloza08/NSMK-Code
 def validate_four_octets(self, four_octets):
     octets = four_octets.split(".")
     if len(octets) != 4:
         l.message_user(str)
         return False
     # Review if first octect has to be non-zero
     for octet in octets:
         if is_numeric_in_range(octet, 0, 255) is False:
             l.message_user(str)
             return False
     return True
예제 #3
0
파일: _csv.py 프로젝트: rloza08/NSMK-Code
 def validate_ip_item(self, comment, line_count, it, field):
     success=False
     if it.find("/") > 0:
         aux = it.split("/")
         four_octets = aux[0]
         mask = aux[1]
         if is_numeric_in_range(mask, 1, 32) is False:
             str = "ref: {}\nline #:{} - invalid mask {}\n{}".format(comment, line_count, it, field)
             l.message_user(str)
             return False
     elif it.find(" mask ") > 0:
         aux = it.split(" mask ")
         four_octets = aux[0]
         mask = aux[1]
         if not self.validate_four_octets(mask):
             str = "ref: {}\nline #:{} - invalid mask {}\n{}".format(comment, line_count, it, field)
             l.message_user(str)
             return False
     elif it == "any":
         return True
     elif it == "":
         str = "ref: {}\nline #:{} - inconsistent mask {}\n,{}".format(comment, line_count, it, field)
         l.message_user(str)
         return False
     else:
         str = "ref: {}\nline #:{} - invalid {}\n,{}".format(comment, line_count, it, field)
         l.message_user(str)
         return False
     if self.validate_four_octets(four_octets) is False:
         return False
     return True
예제 #4
0
파일: _csv.py 프로젝트: rloza08/NSMK-Code
    def validate_vlan_and_ip(self, entry, field, line_count):
        item = entry[field]
        items = item.split(",")
        item_count = 0
        for it in items:
            item_count += 1
            if self.validate_vlan_item(it) is False:
                if field == "srcCidr":
                    if it == "any":
                        continue
                    octet = it.split(".")
                    # Upgrade logic with three octets and mask check
                    if octet[0] == "192" and octet[1] == "168":
                        continue
                elif field == "destCidr":
                    comment=entry["comment"]
                    if self.validate_ip_item(comment, line_count, it, field):
                        continue
                str = "line #:{} item:{}- invalid {} item: {}".format(line_count, item_count, field, item)
                l.message_user(str)
                continue

        return True