def icmp_term(self, ast): if ast == u'any': return {u'icmp_code': u'any', u'include': None, u'icmp_type': u'any'} if ast[u'include']: icmp_p = [] includes = [] object_name = 'objects/%s.icmp' % ast['include'] includes.append(object_name) for include in includes: try: file_h = open(include).read().splitlines() except IOError: print "ERROR: could not open file: %s" % include sys.exit(2) for line in file_h: if line.startswith('@'): include_name = 'objects/%s.icmp' \ % line.split('#')[0].strip()[1:] if include_name not in includes: includes.append(include_name) else: icmp_p.append(line.split('#')[0].strip()) icmp_types = "\n".join(set(icmp_p)) p = grammarParser(parseinfo=False, semantics=grammarSemantics()) ast = p.parse(icmp_types, 'icmp_term') return ast
def endpoint_expr(self, ast): # allow recursion in host expressions if ast[u'include']: hosts = [] includes = [] object_name = 'objects/%s.hosts' % ast['include'] includes.append(object_name) for include in includes: try: file_h = open(include).read().splitlines() except IOError: print "ERROR: could not open file: %s" % include import os print os.getcwd() sys.exit(2) for line in file_h: if line.startswith('@'): include_name = 'objects/%s.hosts' \ % line.split('#')[0].strip()[1:] if include_name not in includes: includes.append(include_name) else: hosts.append(line.split('#')[0]) hosts = "\n".join(set(hosts)) p = grammarParser(parseinfo=False, semantics=grammarSemantics()) ast = {'ip': p.parse(hosts, 'endpoint_list')} return ast
def port_term(self, ast): if ast[u'include']: ports = [] includes = [] object_name = 'objects/%s.ports' % ast['include'] includes.append(object_name) for include in includes: try: file_h = open(include).read().splitlines() except IOError: print "ERROR: could not open file: %s" % include sys.exit(2) for line in file_h: if line.startswith('@'): include_name = 'objects/%s.ports' \ % line.split('#')[0].strip()[1:] if include_name not in includes: includes.append(include_name) else: ports.append(line.split('#')[0]) ports = "\n".join(set(ports)) p = grammarParser(parseinfo=False, semantics=grammarSemantics()) ast = p.parse(ports, 'port_term') return ast