]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/firewall/convert-xtaccess
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 ###############################################################################
22 #This script converts old xtaccess rules to new firewall #
23 #Logfiles are created under /var/log/converters #
25 ###############################################################################
29 require '/var/ipfire/general-functions.pl';
30 my $xtaccessconfig = "${General::swroot}/xtaccess/config";
31 my $inputfwconfig = "${General::swroot}/firewall/input";
32 my $aliasconfig = "${General::swroot}/ethernet/aliases";
35 my $field2=''; #ON or emtpy
36 my $field3=''; #std_net_src or src_addr
37 my $field4=''; #ALL or IP-Address with /32
39 my $field6=''; #Default IP or alias name
40 my $field11='ON'; #use target port
41 my $field12=''; #TCP or UDP
42 my $field13='All ICMP-Types';
43 my $field14='TGT_PORT';
44 my $field15=''; #Port Number
45 my $field16=''; #remark
53 if (! -e
"$xtaccessconfig") {
54 print "Config file for external access not found. Exiting!\n";
58 if (! -s
"$xtaccessconfig") {
59 print "Empty external access configuration file. Nothing to do. Exiting...\n";
63 open(FILE
, $xtaccessconfig) or die 'Unable to open config file.';
66 open(FILE1
, $aliasconfig) or die 'Unable to open config file.';
69 &General
::readhasharray
($inputfwconfig,\
%configinputfw);
71 foreach my $line (@current){
72 my ($a,$b,$c,$d,$e,$f) = split (",",$line);
81 if ($a eq 'tcp'){ $field12 ='TCP';}else{$field12='UDP';}
83 if ($b eq '0.0.0.0/0'){
84 $field3='std_net_src';
86 }elsif($b =~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
89 }elsif ($b =~ /^(.*?)\/(.*?
)$/) {
93 print "Regel konnte nicht konvertiert werden!\n";
99 foreach my $line (@alias){
100 my ($ip,$state,$aliasname) = split (",",$line);
102 $aliasname =~ s/\R//g;
103 $field6 = $aliasname;
110 if ($c =~ /^(\D)\:(\d+)$/) {
113 if ($c =~ /^(\d+)\:(\D)$/) {
117 my $key = &General
::findhasharraykey
(\
%configinputfw);
118 foreach my $i (0 .. 31) { $configinputfw{$key}[$i] = "";}
119 $configinputfw{$key}[0] = $field0;
120 $configinputfw{$key}[1] = $field1;
121 $configinputfw{$key}[2] = $field2;
122 $configinputfw{$key}[3] = $field3;
123 $configinputfw{$key}[4] = $field4;
124 $configinputfw{$key}[5] = $field5;
125 $configinputfw{$key}[6] = $field6;
126 $configinputfw{$key}[7] = '';
127 $configinputfw{$key}[8] = $field12;
128 $configinputfw{$key}[9] = '';
129 $configinputfw{$key}[10] = '';
130 $configinputfw{$key}[11] = $field11;
131 $configinputfw{$key}[12] = '';
132 $configinputfw{$key}[13] = '';
133 $configinputfw{$key}[14] = $field14;
134 $configinputfw{$key}[15] = $field15;
135 $configinputfw{$key}[16] = $field16;
136 $configinputfw{$key}[17] = '';
137 $configinputfw{$key}[18] = '';
138 $configinputfw{$key}[19] = '';
139 $configinputfw{$key}[20] = '';
140 $configinputfw{$key}[21] = '';
141 $configinputfw{$key}[22] = '';
142 $configinputfw{$key}[23] = '';
143 $configinputfw{$key}[24] = '';
144 $configinputfw{$key}[25] = '';
145 $configinputfw{$key}[26] = $field26;
146 $configinputfw{$key}[27] = $field27;
147 $configinputfw{$key}[28] = $field28;
148 $configinputfw{$key}[29] = $field29;
149 $configinputfw{$key}[30] = $field30;
150 $configinputfw{$key}[31] = $field31;
151 &General
::writehasharray
($inputfwconfig,\
%configinputfw);