]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/outgoingfw/outgoingfw.pl
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
24 # enable only the following on debugging purpose
27 require '/var/ipfire/general-functions.pl';
29 my %outfwsettings = ();
33 my $errormessage = "";
46 my $configfile = "/var/ipfire/outgoing/rules";
47 my $p2pfile = "/var/ipfire/outgoing/p2protocols";
49 ### Values that have to be initialized
50 $outfwsettings{'ACTION'} = '';
51 $outfwsettings{'VALID'} = 'yes';
52 $outfwsettings{'EDIT'} = 'no';
53 $outfwsettings{'NAME'} = '';
54 $outfwsettings{'SNET'} = '';
55 $outfwsettings{'SIP'} = '';
56 $outfwsettings{'SPORT'} = '';
57 $outfwsettings{'SMAC'} = '';
58 $outfwsettings{'DIP'} = '';
59 $outfwsettings{'DPORT'} = '';
60 $outfwsettings{'PROT'} = '';
61 $outfwsettings{'STATE'} = '';
62 $outfwsettings{'DISPLAY_DIP'} = '';
63 $outfwsettings{'DISPLAY_DPORT'} = '';
64 $outfwsettings{'DISPLAY_SMAC'} = '';
65 $outfwsettings{'DISPLAY_SIP'} = '';
66 $outfwsettings{'POLICY'} = 'MODE0';
77 &General
::readhash
("${General::swroot}/outgoing/settings", \
%outfwsettings);
78 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
80 $netsettings{'RED_DEV'}=`cat /var/ipfire/red/iface`;
82 open( FILE
, "< $configfile" ) or die "Unable to read $configfile";
86 if ( $outfwsettings{'POLICY'} eq 'MODE1' ) {
87 $outfwsettings{'STATE'} = "ALLOW";
90 } elsif ( $outfwsettings{'POLICY'} eq 'MODE2' ) {
91 $outfwsettings{'STATE'} = "DENY";
93 $DO = "DROP -m comment --comment 'DROP_OUTGOINGFW'";
96 ### Initialize IPTables
97 system("/sbin/iptables --flush OUTGOINGFW >/dev/null 2>&1");
98 system("/sbin/iptables --delete-chain OUTGOINGFW >/dev/null 2>&1");
99 system("/sbin/iptables -N OUTGOINGFW >/dev/null 2>&1");
101 if ( $outfwsettings{'POLICY'} eq 'MODE0' ) {
105 if ( $outfwsettings{'POLICY'} eq 'MODE1' ) {
106 $CMD = "/sbin/iptables -A OUTGOINGFW -m state --state ESTABLISHED,RELATED -j ACCEPT";
107 if ($DEBUG) { print "$CMD\n"; } else { system("$CMD"); }
108 $CMD = "/sbin/iptables -A OUTGOINGFW -p icmp -j ACCEPT";
109 if ($DEBUG) { print "$CMD\n"; } else { system("$CMD"); }
112 foreach $configentry (sort @configs)
120 @configline = split( /\;/, $configentry );
121 if ($outfwsettings{'STATE'} eq $configline[0]) {
122 if ($configline[2] eq 'green') {
123 $SOURCE = "$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}";
124 $DEV = $netsettings{'GREEN_DEV'};
125 } elsif ($configline[2] eq 'blue') {
126 $SOURCE = "$netsettings{'BLUE_NETADDRESS'}/$netsettings{'BLUE_NETMASK'}";
127 $DEV = $netsettings{'BLUE_DEV'};
128 } elsif ($configline[2] eq 'orange') {
129 $SOURCE = "$netsettings{'ORANGE_NETADDRESS'}/$netsettings{'ORANGE_NETMASK'}";
130 $DEV = $netsettings{'ORANGE_DEV'};
131 } elsif ($configline[2] eq 'ip') {
132 $SOURCE = "$configline[5]";
139 if ($configline[7]) { $DESTINATION = "$configline[7]"; } else { $DESTINATION = "0/0"; }
141 if ($configline[3] eq 'tcp') {
143 } elsif ($configline[3] eq 'udp') {
146 @proto = ("tcp", "udp");
149 foreach $PROTO (@proto) {
150 $CMD = "/sbin/iptables -A OUTGOINGFW -s $SOURCE -d $DESTINATION -p $PROTO";
152 if ($configline[8]) {
153 $DPORT = "$configline[8]";
154 $CMD = "$CMD --dport $DPORT";
158 $CMD = "$CMD -i $DEV";
161 if ($configline[6]) {
162 $MAC = "$configline[6]";
163 $CMD = "$CMD -m mac --mac-source $MAC";
166 $CMD = "$CMD -o $netsettings{'RED_DEV'}";
168 if ($configline[9] eq "aktiv") {
170 print "$CMD -m limit --limit 10/minute -j LOG --log-prefix 'OUTGOINGFW '\n";
172 system("$CMD -m limit --limit 10/minute -j LOG --log-prefix 'OUTGOINGFW '");
177 print "$CMD -j $DO\n";
179 system("$CMD -j $DO");
185 ### Do the P2P-Stuff here
186 open( FILE
, "< $p2pfile" ) or die "Unable to read $p2pfile";
190 $CMD = "/sbin/iptables -A OUTGOINGFW -m ipp2p";
192 foreach $p2pentry (sort @p2ps)
194 @p2pline = split( /\;/, $p2pentry );
195 if ( $outfwsettings{'POLICY'} eq 'MODE2' ) {
197 if ("$p2pline[2]" eq "off") {
198 $P2PSTRING = "$P2PSTRING --$p2pline[1]";
202 if ("$p2pline[2]" eq "on") {
203 $P2PSTRING = "$P2PSTRING --$p2pline[1]";
209 print "$CMD $P2PSTRING -j $DO\n";
211 system("$CMD $P2PSTRING -j $DO");
215 if ( $outfwsettings{'POLICY'} eq 'MODE1' ) {
216 if ( $outfwsettings{'MODE1LOG'} eq 'on' ) {
217 $CMD = "/sbin/iptables -A OUTGOINGFW -o $netsettings{'RED_DEV'} -m limit --limit 10/minute -j LOG --log-prefix 'OUTGOINGFW '";
225 $CMD = "/sbin/iptables -A OUTGOINGFW -o $netsettings{'RED_DEV'} -j DROP -m comment --comment 'DROP_OUTGOINGFW'";