]>
git.ipfire.org Git - 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
52 open(FILE
, $xtaccessconfig) or die 'Unable to open config file.';
55 open(FILE1
, $aliasconfig) or die 'Unable to open config file.';
58 &General
::readhasharray
($inputfwconfig,\
%configinputfw);
60 foreach my $line (@current){
61 my ($a,$b,$c,$d,$e,$f) = split (",",$line);
70 if ($a eq 'tcp'){ $field12 ='TCP';}else{$field12='UDP';}
72 if ($b eq '0.0.0.0/0'){
73 $field3='std_net_src';
75 }elsif($b =~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
78 }elsif ($b =~ /^(.*?)\/(.*?
)$/) {
82 print "Regel konnte nicht konvertiert werden!\n";
88 foreach my $line (@alias){
89 my ($ip,$state,$aliasname) = split (",",$line);
91 $aliasname =~ s/\R//g;
99 if ($c =~ /^(\D)\:(\d+)$/) {
102 if ($c =~ /^(\d+)\:(\D)$/) {
106 my $key = &General
::findhasharraykey
(\
%configinputfw);
107 foreach my $i (0 .. 31) { $configinputfw{$key}[$i] = "";}
108 $configinputfw{$key}[0] = $field0;
109 $configinputfw{$key}[1] = $field1;
110 $configinputfw{$key}[2] = $field2;
111 $configinputfw{$key}[3] = $field3;
112 $configinputfw{$key}[4] = $field4;
113 $configinputfw{$key}[5] = $field5;
114 $configinputfw{$key}[6] = $field6;
115 $configinputfw{$key}[7] = '';
116 $configinputfw{$key}[8] = $field12;
117 $configinputfw{$key}[9] = '';
118 $configinputfw{$key}[10] = '';
119 $configinputfw{$key}[11] = $field11;
120 $configinputfw{$key}[12] = '';
121 $configinputfw{$key}[13] = '';
122 $configinputfw{$key}[14] = $field14;
123 $configinputfw{$key}[15] = $field15;
124 $configinputfw{$key}[16] = $field16;
125 $configinputfw{$key}[17] = '';
126 $configinputfw{$key}[18] = '';
127 $configinputfw{$key}[19] = '';
128 $configinputfw{$key}[20] = '';
129 $configinputfw{$key}[21] = '';
130 $configinputfw{$key}[22] = '';
131 $configinputfw{$key}[23] = '';
132 $configinputfw{$key}[24] = '';
133 $configinputfw{$key}[25] = '';
134 $configinputfw{$key}[26] = $field26;
135 $configinputfw{$key}[27] = $field27;
136 $configinputfw{$key}[28] = $field28;
137 $configinputfw{$key}[29] = $field29;
138 $configinputfw{$key}[30] = $field30;
139 $configinputfw{$key}[31] = $field31;
140 &General
::writehasharray
($inputfwconfig,\
%configinputfw);