Example #1
0
def get_services():
    conf = ShorewallPluginConfig('shorewall')
    services = [ os.path.basename(m)[6:] for m in glob.glob(os.path.join(conf.macros_path, 'macro.*')) ] + \
               [ os.path.basename(m)[6:] for m in glob.glob(os.path.join(conf.path, '/macro.*')) ]
    services.sort()
    # Remove not allowed macros from the list
    if len(conf.macros_list) > 0:
        for service in services[:]:
            if not service in conf.macros_list:
                services.remove(service)
    return services
Example #2
0
def get_internal_interfaces():
    """
    Return string with all the internal interfaces separated by a space
    Something like: "eth1 eth2"

    @rtype str
    @return Names of internal interfaces
    """
    shorewall_config = ShorewallPluginConfig("shorewall")
    interfaces = get_zones_interfaces(shorewall_config.internal_zones_names)
    if not interfaces:
        raise Exception("No internal networks detected")
    return " ".join([interface[1] for interface in interfaces])
Example #3
0
def activate():
    conf = ShorewallPluginConfig('shorewall')

    if conf.disabled:
        logger.warning("Plugin shorewall: disabled by configuration.")
        return False

    files = ['zones', 'interfaces', 'rules', 'policy']
    for file in files:
        path = os.path.join(conf.path, file)
        if not os.path.exists(path):
            logger.error("%s doesn't exists" % path)
            return False

    if len(get_zones(conf.external_zones_names)) == 0 and \
       len(get_zones(conf.internal_zones_names)) == 0:
        logger.error("No external or internal zone defined.")
        return False

    return True
Example #4
0
def get_zones_types():
    conf = ShorewallPluginConfig('shorewall')
    return (conf.internal_zones_names, conf.external_zones_names)
Example #5
0
 def __init__(self):
     self.config = ShorewallPluginConfig("shorewall")
     ServiceManager.__init__(self, self.config.service["pid"],
                             self.config.service["init"])
Example #6
0
 def __init__(self, file, pattern, output_format=None):
     self.conf = ShorewallPluginConfig('shorewall')
     self.path = os.path.join(self.conf.path, file)
     self.pattern = pattern
     self.output_format = output_format
     self.file = []