]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/forwardfw/firewall-lib.pl
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
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 ###############################################################################
21 # Author: Alexander Marx (amarx@ipfire.org) #
22 ###############################################################################
25 no warnings
'uninitialized';
33 my %customservicegrp=();
41 require '/var/ipfire/general-functions.pl';
43 my $confignet = "${General::swroot}/fwhosts/customnetworks";
44 my $confighost = "${General::swroot}/fwhosts/customhosts";
45 my $configgrp = "${General::swroot}/fwhosts/customgroups";
46 my $configsrv = "${General::swroot}/fwhosts/customservices";
47 my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
48 my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
49 my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
50 my $configipsec = "${General::swroot}/vpn/config";
51 my $configovpn = "${General::swroot}/ovpn/settings";
55 &General
::readhash
("/var/ipfire/ethernet/settings", \
%netsettings);
56 &General
::readhash
("${General::swroot}/ovpn/settings", \
%ovpnsettings);
57 &General
::readhash
("${General::swroot}/vpn/settings", \
%ipsecsettings);
60 &General
::readhasharray
("$confignet", \
%customnetwork);
61 &General
::readhasharray
("$confighost", \
%customhost);
62 &General
::readhasharray
("$configgrp", \
%customgrp);
63 &General
::readhasharray
("$configccdnet", \
%ccdnet);
64 &General
::readhasharray
("$configccdhost", \
%ccdhost);
65 &General
::readhasharray
("$configipsec", \
%ipsecconf);
66 &General
::readhasharray
("$configsrv", \
%customservice);
67 &General
::readhasharray
("$configsrvgrp", \
%customservicegrp);
72 foreach my $key (sort {$a <=> $b} keys %customservice){
73 if($customservice{$key}[0] eq $val){
74 if ($customservice{$key}[0] eq $val){
75 return $customservice{$key}[2];
87 foreach my $key (sort {$a <=> $b} keys %customservicegrp){
88 if($customservicegrp{$key}[0] eq $val){
89 if (&get_srv_prot
($customservicegrp{$key}[2]) eq 'TCP'){
91 }elsif(&get_srv_prot
($customservicegrp{$key}[2]) eq 'UDP'){
93 }elsif(&get_srv_prot
($customservicegrp{$key}[2]) eq 'ICMP'){
98 if ($tcp eq '1'){push (@ips,'TCP');}
99 if ($udp eq '1'){push (@ips,'UDP');}
100 if ($icmp eq '1'){push (@ips,'ICMP');}
101 my $back=join(",",@ips);
112 foreach my $key (sort {$a <=> $b} keys %customservice){
113 if($customservice{$key}[0] eq $val){
114 if($customservice{$key}[2] eq $prot){
115 return $customservice{$key}[$field];
127 foreach my $key (sort {$a <=> $b} keys %customservicegrp){
128 if($customservicegrp{$key}[0] eq $val){
129 if ($prot ne 'ICMP'){
130 $value=&get_srv_port
($customservicegrp{$key}[2],1,$prot);
131 }elsif ($prot eq 'ICMP'){
132 $value=&get_srv_port
($customservicegrp{$key}[2],3,$prot);
134 push (@ips,$value) if ($value ne '') ;
138 if ($#ips gt 0){$back="-m multiport --dports ";}else{$back="--dport ";}
139 }elsif ($prot eq 'ICMP'){
140 $back="--icmp-type ";
143 $back.=join(",",@ips);
150 foreach my $key (sort {$a <=> $b} keys %ipsecconf){
151 if($ipsecconf{$key}[1] eq $val){
152 return $ipsecconf{$key}[$field];
156 sub get_ipsec_host_ip
160 foreach my $key (sort {$a <=> $b} keys %ipsecconf){
161 if($ipsecconf{$key}[1] eq $val){
162 return $ipsecconf{$key}[$field];
170 foreach my $key (sort {$a <=> $b} keys %ccdhost){
171 if($ccdhost{$key}[1] eq $val){
172 return $ccdhost{$key}[$field];
180 foreach my $key (sort {$a <=> $b} keys %ccdhost){
181 if($ccdhost{$key}[1] eq $val){
182 return $ccdhost{$key}[$field];
191 foreach my $key (sort {$a <=> $b} keys %ccdnet){
192 if($ccdnet{$key}[0] eq $val){
193 return $ccdnet{$key}[$field];
201 foreach my $key (sort {$a <=> $b} keys %customgrp){
202 if ($customgrp{$key}[0] eq $val){
203 &get_address
($customgrp{$key}[3],$src);
213 return "0.0.0.0/0.0.0.0";
214 }elsif($val eq 'GREEN'){
215 return "$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}";
216 }elsif($val eq 'ORANGE'){
217 return "$netsettings{'ORANGE_NETADDRESS'}/$netsettings{'ORANGE_NETMASK'}";
218 }elsif($val eq 'BLUE'){
219 return "$netsettings{'BLUE_NETADDRESS'}/$netsettings{'BLUE_NETMASK'}";
220 }elsif($val eq 'RED'){
221 return "0.0.0.0/0 -o $con";
222 }elsif($val =~ /OpenVPN/i){
223 return "$ovpnsettings{'DOVPN_SUBNET'}";
224 }elsif($val =~ /IPsec/i){
225 return "$ipsecsettings{'RW_NET'}";
226 }elsif($val eq 'IPFire'){
233 foreach my $key (sort {$a <=> $b} keys %customnetwork){
234 if($customnetwork{$key}[0] eq $val){
235 return "$customnetwork{$key}[1]/$customnetwork{$key}[2]";
243 foreach my $key (sort {$a <=> $b} keys %customhost){
244 if($customhost{$key}[0] eq $val){
245 if ($customhost{$key}[1] eq 'mac' && $src eq 'src'){
246 return "-m mac --mac-source $customhost{$key}[2]";
247 }elsif($customhost{$key}[1] eq 'ip' && $src eq 'src'){
248 return "$customhost{$key}[2]";
249 }elsif($customhost{$key}[1] eq 'ip' && $src eq 'tgt'){
250 return "$customhost{$key}[2]";
251 }elsif($customhost{$key}[1] eq 'mac' && $src eq 'tgt'){