#this file is generated by EOLE, don't modify this file
µµµµµµµµµµ
µµµµµµµµµµ
µµµµµµµµµµ build restrictions dictionary used to limit access to a service
µµµµµµµµµµ
%if %%activer_firewall == 'non'
ALL:ALL
%else

%if %%mode_conteneur_actif == "oui"
ALL:%%adresse_network_br0/%%adresse_netmask_br0
%end if
%set global %%restrictions = dict()
%def add_restriction(%%service, %%container, %%ip, %%netmask, %%interface)
    %if %%netmask != '255.255.255.255'
        %set %%ip_restriction = %%ip + '/' + %%netmask
    %else
        %set %%ip_restriction = %%ip
    %end if
    %silent %%restrictions.setdefault(%%service, {}).setdefault(%%container, {}).setdefault(%%interface, []).append(%%ip_restriction)
%end def
%for %%restriction in %%creole_client.get_service_restrictions()
    %set %%container = %%restriction['container_group']
    %set %%service = %%restriction['service']
    %set %%interface=%%restriction.get('interface', None)
    %if 'activate' in  %%restriction and 'name' in %%restriction
        %if %%isinstance(%%restriction['name'], list)
            %set %%netmask = %%restriction['netmask']
            %for %%idx, %%rest in %%enumerate(%%restriction['name'])
                %if %%isinstance(%%interface, list)
                    %set %%l_interface = %%interface[idx]
                %else
                    %set %%l_interface = %%interface
                %end if
	            %if %%restriction['name'] == []
                   %silent %%restrictions.setdefault(%%service, {}).setdefault(%%container, {}).setdefault(%%l_interface, []).append(None)
	            %end if
                %if %%restriction['name'][idx] is None
                    %silent %%restrictions.setdefault(%%service, {}).setdefault(%%container, {}).setdefault(%%l_interface, []).append(None)
                    %continue
                %end if
                %if %%isinstance(%%netmask, list)
                   %set %%l_netmask = %%netmask[idx]
                %else
                   %set %%l_netmask = %%netmask
                %end if
                %silent %%add_restriction(%%service, %%container, %%restriction['name'][idx], %%l_netmask, %%l_interface)
            %end for
        %else
            %if %%restriction['name'] is None
                %silent %%restrictions.setdefault(%%service, {}).setdefault(%%container, {}).setdefault(%%interface, []).append(None)
                %continue
            %end if
            %silent %%add_restriction(%%service, %%container, %%restriction['name'], %%restriction['netmask'], %%interface)
        %end if
    %else
        %silent %%restrictions.setdefault(%%service, {}).setdefault(%%container, {}).setdefault(%%interface, []).append(None)
    %end if
%end for

%for access in %%creole_client.get_service_accesss()
    %if 'activate' in %%access and 'name' in %%access and %%access['node_name'] == 'tcpwrapper'
        %set %%container_ip = %%getVar('container_ip_' + %%access['container'])
        %set %%container_name = %%access['container_group']
        %if %%mode_conteneur_actif == "oui" and %%current_container['name'] != %%container_name
#desactived not in this container %slurp
        %end if
        %set %%sources = %%restrictions.get(%%access['service'], {}).get(%%container_name, {'all': ['0.0.0.0/0.0.0.0']})
        %for %%source in %%sources
            %for %%interface in %%sources[%%source]
                %if %%interface == None
                    %continue
                %end if
%%access['name']:%%interface
            %end for
        %end for
    %end if
%end for

%end if
