#
#---------------------------------------------------------
# DO NOT MODIFY THIS FILE! It is updated automatically 
# by the naat/backend. Modify the template file instead
# in /usr/share/naat/templates/etc/shorewall
#---------------------------------------------------------
#
# Copyright (C) 2002 Mandrakesoft
# Author Florin Grad
#
#---------------------------------------------------------
{

my $shorewall = backend::util::shorewall_hash;
my @list;
my @new_list;
my $string = "";
my $separator = "";
my $new_separator = "";
my $file_name = "interfaces";
my $coloumns = backend::util::shorewall_infos($shorewall, "coloumns", "$file_name", "");
$OUT .= "\# Shorewall /etc/shorewall/$file_name\n";
$OUT .= "\n\n";

	if (eval('$'."\u$file_name"."List")) {
	foreach ( split( ',', eval('$'."\u$file_name"."List")) ) {
		my ($item, $attr_list) = /(\S+)\s*\((.*)\)/;
		if ($attr_list) { 
			my @vals = split (' ', $attr_list);
			my $parent_position = 0;
			my $child_position = 0;
			foreach $val (@vals) {
				my ($attr, $value) = split ('\s*=\s*', $val);
				my $position = backend::util::shorewall_infos($shorewall, "position", "$file_name", "$attr");
				if ($position <= 10) {
					$list[ $position - 1 ][0] =  $value ;
					$list[ $position - 1 ][1] =  "" ;
					$list[ $position - 1 ][2] =  "" ;
				} else {
					$position =~ m/([^+])(.*)/; #21 -> 2.1 
					$parent_position = $1; # 2
					$child_position = $2; # 1
					$list[ $parent_position -1 ][$child_position -1 ] = $value;	
				};
			};
		};
		
		for (my $i = 0 ; $i <= scalar(@list) -1 ;++$i) {
			$separator = "";
			my $var = "";
			for (my $j = 0 ; $j <= 2 ; ++$j) {
				if ($j == 0) {
					$var .= $separator.$list[$i][$j] if ($list[$i][$j]); 
					$separator = ":";
				} else {
					$var .= $separator.$list[$i][$j] if ($list[$i][$j] && ($list[$i][$j] ne "-") && ($list[$i][$j] ne "---")); 
					$separator = ":";
				}
			};
			$new_list[$i] = $var; 	
		}
	
		#Replace the - and --- with blancs
		#$OUT .= "final $string\n"; 

		for (my $i = 0 ; $i <= scalar(@new_list) -1 ;++$i) {
			if (($i + 1) % $coloumns == 0) {
				if (($new_list[$i] eq "-") || ($new_list[$i] eq "---")) {
					$string .= $new_separator."";
					$new_separator = "\n";
				} else {
					$new_list[$i] =~  s/\+/\,/g;
					$string .= $new_separator.$new_list[$i];			
					$new_separator = "\n";
				};
			} elsif ($new_list[$i] eq "---") {
				$string .= $new_separator."-";			
				$new_separator = "\t";
			} else {
				$string .= $new_separator.$new_list[$i];
				$new_separator = "\t";
			};	
		};
	};
	};
	
	# coloumn titles entries
	$OUT .="\#"; 
	$separator = "";

	for (my $i = 0; $i <= $coloumns -1 ; ++$i) {
		$OUT .= $separator.backend::util::shorewall_infos($shorewall, "label", "$file_name", $i+1);
		$separator = "\t";
	};
	
	$OUT .="\n"; 
	
	$OUT .= $string; 
				
}
#LAST LINE - ADD YOUR ENTRIES ABOVE THIS ONE - DO NOT REMOVE
