示例#1
0
def getByPort(port, proto):
    for x in service_list:
        id = getPortID(port)
        name = getServiceName(port, proto)
        if (id, proto) in x.ports or (str(id), proto) in x.ports or \
               (name, proto) in x.ports:
            return x
    return None        
示例#2
0
def convertToServices(config):
    if len(config.services) > 0:
        return

    print _("Converting %s") % config.filename
    services = config.services
    ports = [ ]
    matched = [ ]
    for svc in fw_services.service_list:
        _matched = [ ]
        if config.ports:
            all_matched = True
            for (port, proto) in svc.ports:
                id = getPortID(port)
                name = getServiceName(port, proto)
                if ((id,), proto) in config.ports:
                    _matched.append(((id,), proto))
                elif ((port,), proto) in config.ports:
                    _matched.append(((port,), proto))
                elif ((name,), proto) in config.ports:
                    _matched.append(((name,), proto))
                else:
                    all_matched = False
        else:
            all_matched = False
        if all_matched:
            services.append(svc.key)
            matched.extend(_matched)
        del _matched
    if config.ports:
        for entry in config.ports:
            if entry in matched:
                continue
            ports.append(entry)
    del matched

    if not hasattr(config, "no_ipsec") or not config.no_ipsec:
        if not "ipsec" in services:
            services.append("ipsec")
    else:
        delattr(config, "no_ipsec")
    if not hasattr(config, "no_mdns") or not config.no_mdns:
        if not "mdns" in services:
            services.append("mdns")
    else:
        delattr(config, "no_mdns")
    if not hasattr(config, "no_ipp") or not config.no_ipp:
        if not "ipp" in services:
            services.append("ipp")
    else:
        delattr(config, "no_ipp")

    config.ports = ports