]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/firewall/rules.pl
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2013 Alexander Marx <amarx@ipfire.org> #
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 no warnings
'uninitialized' ;
26 # enable only the following on debugging purpose
28 #use CGI::Carp 'fatalsToBrowser';
31 my %defaultNetworks =();
41 my %configoutgoingfw =();
46 require '/var/ipfire/general-functions.pl' ;
47 require "${General::swroot}/lang.pl" ;
48 require "/usr/lib/firewall/firewall-lib.pl" ;
50 my $configfwdfw = "${General::swroot}/firewall/config" ;
51 my $configinput = "${General::swroot}/firewall/input" ;
52 my $configoutgoing = "${General::swroot}/firewall/outgoing" ;
53 my $p2pfile = "${General::swroot}/firewall/p2protocols" ;
54 my $configgrp = "${General::swroot}/fwhosts/customgroups" ;
55 my $netsettings = "${General::swroot}/ethernet/settings" ;
56 my $errormessage = '' ;
60 my ( $TYPE , $PROT , $SPROT , $DPROT , $SPORT , $DPORT , $TIME , $TIMEFROM , $TIMETILL , $SRC_TGT );
61 my $CHAIN = "FORWARDFW" ;
62 my $conexists = 'off' ;
63 my $command = 'iptables --wait -A' ;
67 & General
:: readhash
( "${General::swroot}/firewall/settings" , \
%fwdfwsettings );
68 & General
:: readhash
( " $netsettings " , \
%defaultNetworks );
69 & General
:: readhasharray
( $configfwdfw , \
%configfwdfw );
70 & General
:: readhasharray
( $configinput , \
%configinputfw );
71 & General
:: readhasharray
( $configoutgoing , \
%configoutgoingfw );
72 & General
:: readhasharray
( $configgrp , \
%customgrp );
73 & General
:: get_aliases
( \
%aliases );
75 #check if we have an internetconnection
76 open ( CONN
, "/var/ipfire/red/iface" );
79 if (- f
"/var/ipfire/red/active" ){
82 open ( CONN1
, "/var/ipfire/red/local-ipaddress" );
88 my $MODE = 0 ; # 0 - normal operation
89 # 1 - print configline and rules to console
94 if ( $param eq 'flush' ){
96 print " Flushing chains... \n " ;
101 print " Flushing chains... \n " ;
105 print " Preparing rules... \n " ;
109 if ( $fwdfwsettings { 'POLICY' } eq 'MODE1' ){
111 system ( "/usr/sbin/firewall-policy" );
112 } elsif ( $fwdfwsettings { 'POLICY' } eq 'MODE2' ){
114 system ( "/usr/sbin/firewall-policy" );
115 system ( "/etc/sysconfig/firewall.local reload" );
121 system ( "iptables --wait -F FORWARDFW" );
122 system ( "iptables --wait -F INPUTFW" );
123 system ( "iptables --wait -F OUTGOINGFW" );
124 system ( "iptables --wait -t nat -F NAT_DESTINATION" );
125 system ( "iptables --wait -t nat -F NAT_SOURCE" );
129 if (! - z
"${General::swroot}/firewall/config" ){
130 & buildrules
( \
%configfwdfw );
132 if (! - z
"${General::swroot}/firewall/input" ){
133 & buildrules
( \
%configinputfw );
135 if (! - z
"${General::swroot}/firewall/outgoing" ){
136 & buildrules
( \
%configoutgoingfw );
150 foreach my $key ( sort { $a <=> $b } keys % $hash ){
151 next if (($ $hash { $key }[ 6 ] eq 'RED' || $ $hash { $key }[ 6 ] eq 'RED1' ) && $conexists eq 'off' );
152 $command = "iptables --wait -A" ;
153 if ($ $hash { $key }[ 28 ] eq 'ON' ){
154 $command = 'iptables --wait -t nat -A' ;
155 $natip =& get_nat_ip
($ $hash { $key }[ 29 ],$ $hash { $key }[ 31 ]);
156 if ($ $hash { $key }[ 31 ] eq 'dnat' ){
158 if ($ $hash { $key }[ 30 ] =~ /\|/ ){
159 $ $hash { $key }[ 30 ]=~ tr/|/,/ ;
160 $fireport = '-m multiport --dport ' .$ $hash { $key }[ 30 ];
162 $fireport = '--dport ' .$ $hash { $key }[ 30 ] if ($ $hash { $key }[ 30 ]> 0 );
169 if ($ $hash { $key }[ 2 ] eq 'ON' ){
171 if ($ $hash { $key }[ 3 ] eq 'cust_grp_src' ){
172 foreach my $grp ( sort { $a <=> $b } keys %customgrp ){
173 if ( $customgrp { $grp }[ 0 ] eq $ $hash { $key }[ 4 ]){
174 & get_address
( $customgrp { $grp }[ 3 ], $customgrp { $grp }[ 2 ], "src" );
178 & get_address
($ $hash { $key }[ 3 ],$ $hash { $key }[ 4 ], "src" );
181 if ($ $hash { $key }[ 5 ] eq 'cust_grp_tgt' ){
182 foreach my $grp ( sort { $a <=> $b } keys %customgrp ){
183 if ( $customgrp { $grp }[ 0 ] eq $ $hash { $key }[ 6 ]){
184 & get_address
( $customgrp { $grp }[ 3 ], $customgrp { $grp }[ 2 ], "tgt" );
187 } elsif ($ $hash { $key }[ 5 ] eq 'ipfire' ){
188 if ($ $hash { $key }[ 6 ] eq 'GREEN' ){
189 $targethash { $key }[ 0 ]= $defaultNetworks { 'GREEN_ADDRESS' };
191 if ($ $hash { $key }[ 6 ] eq 'BLUE' ){
192 $targethash { $key }[ 0 ]= $defaultNetworks { 'BLUE_ADDRESS' };
194 if ($ $hash { $key }[ 6 ] eq 'ORANGE' ){
195 $targethash { $key }[ 0 ]= $defaultNetworks { 'ORANGE_ADDRESS' };
197 if ($ $hash { $key }[ 6 ] eq 'ALL' ){
198 $targethash { $key }[ 0 ]= '0.0.0.0/0' ;
200 if ($ $hash { $key }[ 6 ] eq 'RED' || $ $hash { $key }[ 6 ] eq 'RED1' ){
201 open ( FILE
, "/var/ipfire/red/local-ipaddress" ) or die "Couldn't open local-ipaddress" ;
202 $targethash { $key }[ 0 ]= < FILE
>;
205 foreach my $alias ( sort keys %aliases ){
206 if ($ $hash { $key }[ 6 ] eq $alias ){
207 $targethash { $key }[ 0 ]= $aliases { $alias }{ 'IPT' };
212 & get_address
($ $hash { $key }[ 5 ],$ $hash { $key }[ 6 ], "tgt" );
214 ##get source prot and port
216 $SPORT = & get_port
( $hash , $key );
219 ##get target prot and port
220 $DPROT =& get_prot
( $hash , $key );
222 if ( $DPROT eq '' ){ $DPROT = ' ' ;}
223 @DPROT = split ( "," , $DPROT );
226 if ($ $hash { $key }[ 18 ] eq 'ON' ){
227 my ( $time1 , $time2 , $daylight );
228 my $daylight =$ $hash { $key }[ 28 ];
229 $time1 =& get_time
($ $hash { $key }[ 26 ], $daylight );
230 $time2 =& get_time
($ $hash { $key }[ 27 ], $daylight );
231 if ($ $hash { $key }[ 19 ] ne '' ){ push ( @timeframe , "Mon" );}
232 if ($ $hash { $key }[ 20 ] ne '' ){ push ( @timeframe , "Tue" );}
233 if ($ $hash { $key }[ 21 ] ne '' ){ push ( @timeframe , "Wed" );}
234 if ($ $hash { $key }[ 22 ] ne '' ){ push ( @timeframe , "Thu" );}
235 if ($ $hash { $key }[ 23 ] ne '' ){ push ( @timeframe , "Fri" );}
236 if ($ $hash { $key }[ 24 ] ne '' ){ push ( @timeframe , "Sat" );}
237 if ($ $hash { $key }[ 25 ] ne '' ){ push ( @timeframe , "Sun" );}
238 $TIME = join ( "," , @timeframe );
240 $TIMEFROM = "--timestart $time1 " ;
241 $TIMETILL = "--timestop $time2 " ;
242 $TIME = "-m time --weekdays $TIME $TIMEFROM $TIMETILL " ;
246 foreach my $i ( 0 .. $ #{$$hash{$key}}){
247 print " $i : $ $hash { $key }[ $i ] " ;
250 print "################################## \n " ;
251 #print rules to console
252 foreach my $DPROT ( @DPROT ){
253 $DPORT = & get_port
( $hash , $key , $DPROT );
254 if ( $DPROT ne 'TCP' && $DPROT ne 'UDP' && $DPROT ne 'ICMP' ){
258 $PROT = "-p $PROT " if ( $PROT ne '' && $PROT ne ' ' );
259 foreach my $a ( sort keys %sourcehash ){
260 foreach my $b ( sort keys %targethash ){
261 if (! $sourcehash { $a }[ 0 ] || ! $targethash { $b }[ 0 ] || ( $natip eq '-d ' && $ $hash { $key }[ 28 ] eq 'ON' ) || (! $natip && $ $hash { $key }[ 28 ] eq 'ON' )){
262 #Skip rules when no RED IP is set (DHCP,DSL)
265 next if ( $targethash { $b }[ 0 ] eq 'none' );
267 if ( $sourcehash { $a }[ 0 ] ne $targethash { $b }[ 0 ] && $targethash { $b }[ 0 ] ne 'none' || $sourcehash { $a }[ 0 ] eq '0.0.0.0/0.0.0.0' ){
269 if ( substr ( $sourcehash { $a }[ 0 ], 3 , 3 ) ne 'mac' && $sourcehash { $a }[ 0 ] ne '' ){ $STAG = "-s" ;}
271 if ( substr ( $DPORT , 2 , 4 ) eq 'icmp' ){
272 my @icmprule = split ( "," , substr ( $DPORT , 12 ,));
274 $icmptype = "--icmp-type " ;
279 if ($ $hash { $key }[ 17 ] eq 'ON' ){
280 print " $command $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $icmptype $_ $TIME -j LOG \n " ;
282 print " $command $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $icmptype $_ $TIME -j $ $hash { $key }[0] \n " ;
284 #PROCESS DNAT RULE (Portforward)
285 } elsif ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'dnat' ){
286 $natchain = 'NAT_DESTINATION' ;
287 if ($ $hash { $key }[ 17 ] eq 'ON' ){
288 print " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT $natip $fireport $TIME -j LOG --log-prefix 'DNAT' \n " ;
290 my ( $ip , $sub ) = split ( "/" , $targethash { $b }[ 0 ]);
291 #Process NAT with servicegroup used
292 if ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'dnat' && $ $hash { $key }[ 14 ] eq 'cust_srvgrp' ){
293 print " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT $natip $fireport $TIME -j $nat --to-destination $ip $DPORT \n " ;
294 $fwaccessdport = $DPORT ;
296 print " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT $natip $fireport $TIME -j $nat --to-destination $ip $DPORT \n " ;
299 $fwaccessdport = "--dport " . substr ( $DPORT , 1 ,);
300 } elsif (! $DPORT && $ $hash { $key }[ 30 ] ne '' ){
301 if ($ $hash { $key }[ 30 ]=~ m/|/i ){
302 $ $hash { $key }[ 30 ] =~ s/\|/,/g ;
303 $fwaccessdport = "-m multiport --dport $ $hash { $key }[30]" ;
305 $fwaccessdport = "--dport $ $hash { $key }[30]" ;
309 print "iptables --wait -A FORWARDFW $PROT $STAG $sourcehash { $a }[0] -d $ip $fwaccessdport $TIME -j $ $hash { $key }[0] \n " ;
312 } elsif ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'snat' ){
313 $natchain = 'NAT_SOURCE' ;
314 if ($ $hash { $key }[ 17 ] eq 'ON' ){
315 print " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j LOG --log-prefix 'SNAT' \n " ;
317 print " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j $nat --to-source $natip \n " ;
319 #PROCESS EVERY OTHER RULE (If NOT ICMP, else the rule would be applied double)
320 if ( $PROT ne '-p ICMP' ){
321 if ($ $hash { $key }[ 17 ] eq 'ON' && $ $hash { $key }[ 28 ] ne 'ON' ){
322 print " $command $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j LOG \n " ;
324 print "iptables --wait -A $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j $ $hash { $key }[0] \n " ;
326 #PROCESS Prot ICMP and type = All ICMP-Types
327 if ( $PROT eq '-p ICMP' && $ $hash { $key }[ 9 ] eq 'All ICMP-Types' ){
328 if ($ $hash { $key }[ 17 ] eq 'ON' && $ $hash { $key }[ 28 ] ne 'ON' ){
329 print " $command $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j LOG \n " ;
331 print "iptables --wait -A $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j $ $hash { $key }[0] \n " ;
339 } elsif ( $MODE eq '0' ){
340 foreach my $DPROT ( @DPROT ){
341 $DPORT = & get_port
( $hash , $key , $DPROT );
343 $PROT = "-p $PROT " if ( $PROT ne '' && $PROT ne ' ' );
344 if ( $DPROT ne 'TCP' && $DPROT ne 'UDP' && $DPROT ne 'ICMP' ){
347 foreach my $a ( sort keys %sourcehash ){
348 foreach my $b ( sort keys %targethash ){
349 if (! $sourcehash { $a }[ 0 ] || ! $targethash { $b }[ 0 ] || $natip eq '-d ' || ! $natip ){
350 #Skip rules when no RED IP is set (DHCP,DSL)
353 next if ( $targethash { $b }[ 0 ] eq 'none' );
355 if ( $sourcehash { $a }[ 0 ] ne $targethash { $b }[ 0 ] && $targethash { $b }[ 0 ] ne 'none' || $sourcehash { $a }[ 0 ] eq '0.0.0.0/0.0.0.0' ){
357 if ( substr ( $sourcehash { $a }[ 0 ], 3 , 3 ) ne 'mac' && $sourcehash { $a }[ 0 ] ne '' ){ $STAG = "-s" ;}
359 if ( substr ( $DPORT , 2 , 4 ) eq 'icmp' ){
360 my @icmprule = split ( "," , substr ( $DPORT , 12 ,));
362 $icmptype = "--icmp-type " ;
367 if ($ $hash { $key }[ 17 ] eq 'ON' ){
368 system ( " $command $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $icmptype $_ $TIME -j LOG" );
370 system ( " $command $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $icmptype $_ $TIME -j $ $hash { $key }[0]" );
372 #PROCESS DNAT RULE (Portforward)
373 } elsif ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'dnat' ){
374 $natchain = 'NAT_DESTINATION' ;
375 if ($ $hash { $key }[ 17 ] eq 'ON' ){
376 system " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT $natip $fireport $TIME -j LOG --log-prefix 'DNAT' \n " ;
378 my ( $ip , $sub ) = split ( "/" , $targethash { $b }[ 0 ]);
379 #Process NAT with servicegroup used
380 if ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'dnat' && $ $hash { $key }[ 14 ] eq 'cust_srvgrp' ){
381 system " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT $natip $fireport $TIME -j $nat --to-destination $ip $DPORT \n " ;
382 $fwaccessdport = $DPORT ;
384 system " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT $natip $fireport $TIME -j $nat --to-destination $ip $DPORT \n " ;
387 $fwaccessdport = "--dport " . substr ( $DPORT , 1 ,);
388 } elsif (! $DPORT && $ $hash { $key }[ 30 ] ne '' ){
389 if ($ $hash { $key }[ 30 ]=~ m/|/i ){
390 $ $hash { $key }[ 30 ] =~ s/\|/,/g ;
391 $fwaccessdport = "-m multiport --dport $ $hash { $key }[30]" ;
393 $fwaccessdport = "--dport $ $hash { $key }[30]" ;
397 system "iptables --wait -A FORWARDFW $PROT $STAG $sourcehash { $a }[0] -d $ip $fwaccessdport $TIME -j $ $hash { $key }[0] \n " ;
400 } elsif ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'snat' ){
401 $natchain = 'NAT_SOURCE' ;
402 if ($ $hash { $key }[ 17 ] eq 'ON' ){
403 system " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j LOG --log-prefix 'SNAT' \n " ;
405 system " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j $nat --to-source $natip \n " ;
407 #PROCESS EVERY OTHER RULE (If NOT ICMP, else the rule would be applied double)
408 if ( $PROT ne '-p ICMP' ){
409 if ($ $hash { $key }[ 17 ] eq 'ON' && $ $hash { $key }[ 28 ] ne 'ON' ){
410 system " $command $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j LOG \n " ;
412 system "iptables --wait -A $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j $ $hash { $key }[0] \n " ;
414 #PROCESS Prot ICMP and type = All ICMP-Types
415 if ( $PROT eq '-p ICMP' && $ $hash { $key }[ 9 ] eq 'All ICMP-Types' ){
416 if ($ $hash { $key }[ 17 ] eq 'ON' && $ $hash { $key }[ 28 ] ne 'ON' ){
417 system " $command $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j LOG \n " ;
419 system "iptables --wait -A $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j $ $hash { $key }[0] \n " ;
441 if ( $val eq 'RED' || $val eq 'GREEN' || $val eq 'ORANGE' || $val eq 'BLUE' ){
442 $result = $defaultNetworks { $val . '_ADDRESS' };
443 } elsif ( $val eq 'ALL' ){
445 } elsif ( $val eq 'Default IP' && $type eq 'dnat' ){
446 $result = '-d ' . $redip ;
447 } elsif ( $val eq 'Default IP' && $type eq 'snat' ){
450 foreach my $al ( sort keys %aliases ){
451 if ( $val eq $al && $type eq 'dnat' ){
452 $result = '-d ' . $aliases { $al }{ 'IPT' };
453 } elsif ( $val eq $al && $type eq 'snat' ){
454 $result = $aliases { $al }{ 'IPT' };
467 $minutes = & utcmin
( $val );
468 $ruletime = $minutes + & time_get_utc
( $val );
469 if ( $ruletime < 0 ){ $ruletime += 1440 ;}
470 if ( $ruletime > 1440 ){ $ruletime -= 1440 ;}
471 $time = sprintf " %02d : %02d " , $ruletime / 60 , $ruletime % 60 ;
476 # Calculates the UTCtime from a given time
478 my @localtime = localtime ( time );
479 my @gmtime = gmtime ( time );
480 my $diff = ( $gmtime [ 2 ]* 60 + $gmtime [ 1 ] %60 )-( $localtime [ 2 ]* 60 + $localtime [ 1 ] %60 );
486 my ( $hrs , $min ) = split ( ":" , $ruletime );
487 my $newtime = $hrs * 60 + $min ;
494 open ( FILE
, "< $p2pfile " ) or die "Unable to read $p2pfile " ;
497 my $CMD = "-m ipp2p" ;
498 foreach my $p2pentry ( sort @p2ps ) {
499 my @p2pline = split ( /\;/ , $p2pentry );
500 if ( $fwdfwsettings { 'POLICY' } eq 'MODE1' ) {
502 if ( " $p2pline [2]" eq "on" ) {
503 $P2PSTRING = " $P2PSTRING -- $p2pline [1]" ;
507 if ( " $p2pline [2]" eq "off" ) {
508 $P2PSTRING = " $P2PSTRING -- $p2pline [1]" ;
514 print "/sbin/iptables --wait -A FORWARDFW $CMD $P2PSTRING -j $DO \n " ;
518 system ( "/sbin/iptables --wait -A FORWARDFW $CMD $P2PSTRING -j $DO " );
524 my $base = shift ; #source of checking ($configfwdfw{$key}[x] or groupkey
526 my $type = shift ; #src or tgt
533 my $key = & General
:: findhasharraykey
( $hash );
534 if ( $base eq 'src_addr' || $base eq 'tgt_addr' ){
535 if (& General
:: validmac
( $base2 )){
536 $ $hash { $key }[ 0 ] = "-m mac --mac-source $base2 " ;
538 $ $hash { $key }[ 0 ] = $base2 ;
540 } elsif ( $base eq 'std_net_src' || $base eq 'std_net_tgt' || $base eq 'Standard Network' ){
541 $ $hash { $key }[ 0 ]=& fwlib
:: get_std_net_ip
( $base2 , $con );
542 } elsif ( $base eq 'cust_net_src' || $base eq 'cust_net_tgt' || $base eq 'Custom Network' ){
543 $ $hash { $key }[ 0 ]=& fwlib
:: get_net_ip
( $base2 );
544 } elsif ( $base eq 'cust_host_src' || $base eq 'cust_host_tgt' || $base eq 'Custom Host' ){
545 $ $hash { $key }[ 0 ]=& fwlib
:: get_host_ip
( $base2 , $type );
546 } elsif ( $base eq 'ovpn_net_src' || $base eq 'ovpn_net_tgt' || $base eq 'OpenVPN static network' ){
547 $ $hash { $key }[ 0 ]=& fwlib
:: get_ovpn_net_ip
( $base2 , 1 );
548 } elsif ( $base eq 'ovpn_host_src' || $base eq 'ovpn_host_tgt' || $base eq 'OpenVPN static host' ){
549 $ $hash { $key }[ 0 ]=& fwlib
:: get_ovpn_host_ip
( $base2 , 33 );
550 } elsif ( $base eq 'ovpn_n2n_src' || $base eq 'ovpn_n2n_tgt' || $base eq 'OpenVPN N-2-N' ){
551 $ $hash { $key }[ 0 ]=& fwlib
:: get_ovpn_n2n_ip
( $base2 , 11 );
552 } elsif ( $base eq 'ipsec_net_src' || $base eq 'ipsec_net_tgt' || $base eq 'IpSec Network' ){
553 $ $hash { $key }[ 0 ]=& fwlib
:: get_ipsec_net_ip
( $base2 , 11 );
554 } elsif ( $base eq 'ipfire_src' ){
555 if ( $base2 eq 'GREEN' ){
556 $ $hash { $key }[ 0 ]= $defaultNetworks { 'GREEN_ADDRESS' };
558 if ( $base2 eq 'BLUE' ){
559 $ $hash { $key }[ 0 ]= $defaultNetworks { 'BLUE_ADDRESS' };
561 if ( $base2 eq 'ORANGE' ){
562 $ $hash { $key }[ 0 ]= $defaultNetworks { 'ORANGE_ADDRESS' };
565 $ $hash { $key }[ 0 ]= '0.0.0.0/0' ;
567 if ( $base2 eq 'RED' || $base2 eq 'RED1' ){
568 open ( FILE
, "/var/ipfire/red/local-ipaddress" );
569 $ $hash { $key }[ 0 ]= < FILE
>;
572 foreach my $alias ( sort keys %aliases ){
573 if ( $base2 eq $alias ){
574 $ $hash { $key }[ 0 ]= $aliases { $alias }{ 'IPT' };
584 #check AH,GRE,ESP or ICMP
585 if ($ $hash { $key }[ 7 ] ne 'ON' && $ $hash { $key }[ 11 ] ne 'ON' ){
586 return "$ $hash { $key }[8]" ;
588 if ($ $hash { $key }[ 7 ] eq 'ON' || $ $hash { $key }[ 11 ] eq 'ON' ){
589 #check if servicegroup or service
590 if ($ $hash { $key }[ 14 ] eq 'cust_srv' ){
591 return & fwlib
:: get_srv_prot
($ $hash { $key }[ 15 ]);
592 } elsif ($ $hash { $key }[ 14 ] eq 'cust_srvgrp' ){
593 return & fwlib
:: get_srvgrp_prot
($ $hash { $key }[ 15 ]);
594 } elsif (($ $hash { $key }[ 10 ] ne '' || $ $hash { $key }[ 15 ] ne '' ) && $ $hash { $key }[ 8 ] eq '' ){ #when ports are used and prot set to "all"
596 } elsif (($ $hash { $key }[ 10 ] ne '' || $ $hash { $key }[ 15 ] ne '' ) && ($ $hash { $key }[ 8 ] eq 'TCP' || $ $hash { $key }[ 8 ] eq 'UDP' )){ #when ports are used and prot set to "tcp" or "udp"
597 return "$ $hash { $key }[8]" ;
598 } elsif (($ $hash { $key }[ 10 ] eq '' && $ $hash { $key }[ 15 ] eq '' ) && $ $hash { $key }[ 8 ] ne 'ICMP' ){ #when ports are NOT used and prot NOT set to "ICMP"
599 return "$ $hash { $key }[8]" ;
601 return "$ $hash { $key }[8]" ;
605 if ( $SRC_TGT eq '' && $ $hash { $key }[ 31 ] eq 'dnat' && $ $hash { $key }[ 11 ] eq '' && $ $hash { $key }[ 12 ] ne '' ){
606 return "$ $hash { $key }[8]" ;
614 #Get manual defined Ports from SOURCE
615 if ($ $hash { $key }[ 7 ] eq 'ON' && $SRC_TGT eq 'SRC' ){
616 if ($ $hash { $key }[ 10 ] ne '' ){
617 $ $hash { $key }[ 10 ] =~ s/\|/,/g ;
618 if ( index ($ $hash { $key }[ 10 ], "," ) > 0 ){
619 return "-m multiport --sport $ $hash { $key }[10] " ;
621 if ($ $hash { $key }[ 28 ] ne 'ON' || ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'snat' ) ||($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'dnat' ) ){
622 return "--sport $ $hash { $key }[10] " ;
624 return ":$ $hash { $key }[10]" ;
628 #Get manual ports from TARGET
629 } elsif ($ $hash { $key }[ 11 ] eq 'ON' && $SRC_TGT eq '' ){
630 if ($ $hash { $key }[ 14 ] eq 'TGT_PORT' ){
631 if ($ $hash { $key }[ 15 ] ne '' ){
632 $ $hash { $key }[ 15 ] =~ s/\|/,/g ;
633 if ( index ($ $hash { $key }[ 15 ], "," ) > 0 ){
634 return "-m multiport --dport $ $hash { $key }[15] " ;
636 if ($ $hash { $key }[ 28 ] ne 'ON' || ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'snat' ) ){
637 return "--dport $ $hash { $key }[15] " ;
639 $ $hash { $key }[ 15 ] =~ s/\:/-/g ;
640 return ":$ $hash { $key }[15]" ;
644 #Get ports defined in custom Service (firewall-groups)
645 } elsif ($ $hash { $key }[ 14 ] eq 'cust_srv' ){
646 if ( $prot ne 'ICMP' ){
647 if ($ $hash { $key }[ 31 ] eq 'dnat' && $ $hash { $key }[ 28 ] eq 'ON' ){
648 my $ports =& fwlib
:: get_srv_port
($ $hash { $key }[ 15 ], 1 , $prot );
652 return "--dport " .& fwlib
:: get_srv_port
($ $hash { $key }[ 15 ], 1 , $prot );
654 } elsif ( $prot eq 'ICMP' && $ $hash { $key }[ 11 ] eq 'ON' ){ #When PROT is ICMP and "use targetport is checked, this is an icmp-service
655 return "--icmp-type " .& fwlib
:: get_srv_port
($ $hash { $key }[ 15 ], 3 , $prot );
657 #Get ports from services which are used in custom servicegroups (firewall-groups)
658 } elsif ($ $hash { $key }[ 14 ] eq 'cust_srvgrp' ){
659 if ( $prot ne 'ICMP' ){
660 return & fwlib
:: get_srvgrp_port
($ $hash { $key }[ 15 ], $prot );
662 elsif ( $prot eq 'ICMP' ){
663 return & fwlib
:: get_srvgrp_port
($ $hash { $key }[ 15 ], $prot );
668 if ($ $hash { $key }[ 7 ] ne 'ON' && $ $hash { $key }[ 11 ] ne 'ON' && $SRC_TGT eq '' ){
669 if ($ $hash { $key }[ 9 ] ne '' && $ $hash { $key }[ 9 ] ne 'All ICMP-Types' ){
670 return "--icmp-type $ $hash { $key }[9] " ;
671 } elsif ($ $hash { $key }[ 9 ] eq 'All ICMP-Types' ){