]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/outgoingfw/outgoingfw.pl
1 ###############################################################################
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 ###############################################################################
23 # enable only the following on debugging purpose
26 require '/var/ipfire/general-functions.pl';
28 my %outfwsettings = ();
32 my $errormessage = "";
45 my $configfile = "/var/ipfire/outgoing/rules";
46 my $p2pfile = "/var/ipfire/outgoing/p2protocols";
48 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
50 ### Values that have to be initialized
51 $outfwsettings{'ACTION'} = '';
52 $outfwsettings{'VALID'} = 'yes';
53 $outfwsettings{'EDIT'} = 'no';
54 $outfwsettings{'NAME'} = '';
55 $outfwsettings{'SNET'} = '';
56 $outfwsettings{'SIP'} = '';
57 $outfwsettings{'SPORT'} = '';
58 $outfwsettings{'SMAC'} = '';
59 $outfwsettings{'DIP'} = '';
60 $outfwsettings{'DPORT'} = '';
61 $outfwsettings{'PROT'} = '';
62 $outfwsettings{'STATE'} = '';
63 $outfwsettings{'DISPLAY_DIP'} = '';
64 $outfwsettings{'DISPLAY_DPORT'} = '';
65 $outfwsettings{'DISPLAY_SMAC'} = '';
66 $outfwsettings{'DISPLAY_SIP'} = '';
67 $outfwsettings{'POLICY'} = 'MODE0';
78 &General
::readhash
("${General::swroot}/outgoing/settings", \
%outfwsettings);
79 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
81 open( FILE
, "< $configfile" ) or die "Unable to read $configfile";
85 if ( $outfwsettings{'POLICY'} eq 'MODE1' ) {
86 $outfwsettings{'STATE'} = "ALLOW";
89 } elsif ( $outfwsettings{'POLICY'} eq 'MODE2' ) {
90 $outfwsettings{'STATE'} = "DENY";
95 ### Initialize IPTables
96 system("/sbin/iptables --flush OUTGOINGFW >/dev/null 2>&1");
97 system("/sbin/iptables --delete-chain OUTGOINGFW >/dev/null 2>&1");
98 system("/sbin/iptables -N OUTGOINGFW >/dev/null 2>&1");
100 if ( $outfwsettings{'POLICY'} eq 'MODE0' ) {
104 if ( $outfwsettings{'POLICY'} eq 'MODE1' ) {
105 $CMD = "/sbin/iptables -A OUTGOINGFW -m state --state ESTABLISHED,RELATED -j ACCEPT";
106 if ($DEBUG) { print "$CMD\n"; } else { system("$CMD"); }
107 $CMD = "/sbin/iptables -A OUTGOINGFW -p icmp -j ACCEPT";
108 if ($DEBUG) { print "$CMD\n"; } else { system("$CMD"); }
111 foreach $configentry (sort @configs)
119 @configline = split( /\;/, $configentry );
120 if ($outfwsettings{'STATE'} eq $configline[0]) {
121 if ($configline[2] eq 'green') {
122 $SOURCE = "$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}";
123 $DEV = $netsettings{'GREEN_DEV'};
124 } elsif ($configline[2] eq 'blue') {
125 $SOURCE = "$netsettings{'BLUE_NETADDRESS'}/$netsettings{'BLUE_NETMASK'}";
126 $DEV = $netsettings{'BLUE_DEV'};
127 } elsif ($configline[2] eq 'orange') {
128 $SOURCE = "$netsettings{'ORANGE_NETADDRESS'}/$netsettings{'ORANGE_NETMASK'}";
129 $DEV = $netsettings{'ORANGE_DEV'};
130 } elsif ($configline[2] eq 'ip') {
131 $SOURCE = "$configline[5]";
138 if ($configline[7]) { $DESTINATION = "$configline[7]"; } else { $DESTINATION = "0/0"; }
140 if ($configline[3] eq 'tcp') {
142 } elsif ($configline[3] eq 'udp') {
145 @proto = ("tcp", "udp");
148 foreach $PROTO (@proto) {
149 $CMD = "/sbin/iptables -A OUTGOINGFW -s $SOURCE -d $DESTINATION -p $PROTO";
151 if ($configline[8]) {
152 $DPORT = "$configline[8]";
153 $CMD = "$CMD --dport $DPORT";
157 $CMD = "$CMD -i $DEV";
160 if ($configline[6]) {
161 $MAC = "$configline[6]";
162 $CMD = "$CMD -m mac --mac-source $MAC";
165 $CMD = "$CMD -o $netsettings{'RED_DEV'}";
167 if ($configline[9] eq "aktiv") {
169 print "$CMD -m state --state NEW -m limit --limit 10/minute -j LOG --log-prefix 'OUTGOINGFW '\n";
171 system("$CMD -m state --state NEW -m limit --limit 10/minute -j LOG --log-prefix 'OUTGOINGFW '");
176 print "$CMD -j $DO\n";
178 system("$CMD -j $DO");
184 ### Do the P2P-Stuff here
185 open( FILE
, "< $p2pfile" ) or die "Unable to read $p2pfile";
189 $CMD = "/sbin/iptables -A OUTGOINGFW -m ipp2p";
191 foreach $p2pentry (sort @p2ps)
193 @p2pline = split( /\;/, $p2pentry );
194 if ( $outfwsettings{'POLICY'} eq 'MODE2' ) {
196 if ("$p2pline[2]" eq "off") {
197 $P2PSTRING = "$P2PSTRING --$p2pline[1]";
201 if ("$p2pline[2]" eq "on") {
202 $P2PSTRING = "$P2PSTRING --$p2pline[1]";
208 print "$CMD $P2PSTRING -j $DO\n";
210 system("$CMD $P2PSTRING -j $DO");
214 if ( $outfwsettings{'POLICY'} eq 'MODE1' ) {
215 $CMD = "/sbin/iptables -A OUTGOINGFW -o $netsettings{'RED_DEV'} -j DROP";