]>
git.ipfire.org Git - ipfire-2.x.git/blob - config/outgoingfw/outgoingfw.pl
5 # This code is distributed under the terms of the GPL
9 # Michael Tremer - mitch@ipfire.org
10 # Christian Schmidt - maniacikarus@ipfire.org
14 # enable only the following on debugging purpose
17 require '/var/ipfire/general-functions.pl';
19 my %outfwsettings = ();
23 my $errormessage = "";
36 my $configfile = "/var/ipfire/outgoing/rules";
37 my $p2pfile = "/var/ipfire/outgoing/p2protocols";
39 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
41 ### Values that have to be initialized
42 $outfwsettings{'ACTION'} = '';
43 $outfwsettings{'VALID'} = 'yes';
44 $outfwsettings{'EDIT'} = 'no';
45 $outfwsettings{'NAME'} = '';
46 $outfwsettings{'SNET'} = '';
47 $outfwsettings{'SIP'} = '';
48 $outfwsettings{'SPORT'} = '';
49 $outfwsettings{'SMAC'} = '';
50 $outfwsettings{'DIP'} = '';
51 $outfwsettings{'DPORT'} = '';
52 $outfwsettings{'PROT'} = '';
53 $outfwsettings{'STATE'} = '';
54 $outfwsettings{'DISPLAY_DIP'} = '';
55 $outfwsettings{'DISPLAY_DPORT'} = '';
56 $outfwsettings{'DISPLAY_SMAC'} = '';
57 $outfwsettings{'DISPLAY_SIP'} = '';
58 $outfwsettings{'POLICY'} = 'MODE0';
69 &General
::readhash
("${General::swroot}/outgoing/settings", \
%outfwsettings);
70 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
72 open( FILE
, "< $configfile" ) or die "Unable to read $configfile";
76 if ( $outfwsettings{'POLICY'} eq 'MODE1' ) {
77 $outfwsettings{'STATE'} = "ALLOW";
80 } elsif ( $outfwsettings{'POLICY'} eq 'MODE2' ) {
81 $outfwsettings{'STATE'} = "DENY";
86 ### Initialize IPTables
87 system("/sbin/iptables --flush OUTGOINGFW >/dev/null 2>&1");
88 system("/sbin/iptables --delete-chain OUTGOINGFW >/dev/null 2>&1");
89 system("/sbin/iptables -N OUTGOINGFW >/dev/null 2>&1");
91 if ( $outfwsettings{'POLICY'} eq 'MODE0' ) {
95 if ( $outfwsettings{'POLICY'} eq 'MODE1' ) {
96 $CMD = "/sbin/iptables -A OUTGOINGFW -m state --state ESTABLISHED,RELATED -j RETURN";
97 if ($DEBUG) { print "$CMD\n"; } else { system("$CMD"); }
98 $CMD = "/sbin/iptables -A OUTGOINGFW -p icmp -j RETURN";
99 if ($DEBUG) { print "$CMD\n"; } else { system("$CMD"); }
102 foreach $configentry (sort @configs)
110 @configline = split( /\;/, $configentry );
111 if ($outfwsettings{'STATE'} eq $configline[0]) {
112 if ($configline[2] eq 'green') {
113 $SOURCE = "$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}";
114 $DEV = $netsettings{'GREEN_DEV'};
115 } elsif ($configline[2] eq 'blue') {
116 $SOURCE = "$netsettings{'BLUE_NETADDRESS'}/$netsettings{'BLUE_NETMASK'}";
117 $DEV = $netsettings{'BLUE_DEV'};
118 } elsif ($configline[2] eq 'orange') {
119 $SOURCE = "$netsettings{'ORANGE_NETADDRESS'}/$netsettings{'ORANGE_NETMASK'}";
120 $DEV = $netsettings{'ORANGE_DEV'};
121 } elsif ($configline[2] eq 'ip') {
122 $SOURCE = "$configline[5]";
129 if ($configline[7]) { $DESTINATION = "$configline[7]"; } else { $DESTINATION = "0/0"; }
131 if ($configline[3] eq 'tcp') {
133 } elsif ($configline[3] eq 'udp') {
136 @proto = ("tcp", "udp");
139 foreach $PROTO (@proto) {
140 $CMD = "/sbin/iptables -A OUTGOINGFW -s $SOURCE -d $DESTINATION -p $PROTO";
142 if ($configline[8]) {
143 $DPORT = "$configline[8]";
144 $CMD = "$CMD --dport $DPORT";
148 $CMD = "$CMD -i $DEV";
151 if ($configline[6]) {
152 $MAC = "$configline[6]";
153 $CMD = "$CMD -m mac --mac-source $MAC";
156 $CMD = "$CMD -o $netsettings{'RED_DEV'}";
158 print "$CMD -j $DO\n";
160 system("$CMD -j $DO");
163 if ($configline[9] eq "log") {
165 print "$CMD -m state --state NEW -j LOG --log-prefix 'OUTGOINGFW '\n";
167 system("$CMD -m state --state NEW -j LOG --log-prefix 'OUTGOINGFW '");
174 ### Do the P2P-Stuff here
175 open( FILE
, "< $p2pfile" ) or die "Unable to read $p2pfile";
179 $CMD = "/sbin/iptables -A OUTGOINGFW -m ipp2p";
181 foreach $p2pentry (sort @p2ps)
183 @p2pline = split( /\;/, $p2pentry );
184 if ( $outfwsettings{'POLICY'} eq 'MODE2' ) {
186 if ("$p2pline[2]" eq "off") {
187 $P2PSTRING = "$P2PSTRING --$p2pline[1]";
191 if ("$p2pline[2]" eq "on") {
192 $P2PSTRING = "$P2PSTRING --$p2pline[1]";
198 print "$CMD $P2PSTRING -j $DO\n";
200 system("$CMD $P2PSTRING -j $DO");
204 if ( $outfwsettings{'POLICY'} eq 'MODE1' ) {
205 $CMD = "/sbin/iptables -A OUTGOINGFW -j DROP";