]> git.ipfire.org Git - ipfire-2.x.git/blob - config/firewall/convert-xtaccess
fifteen: update diskspace and number of files.
[ipfire-2.x.git] / config / firewall / convert-xtaccess
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2013 Alexander Marx <amarx@ipfire.org> #
6 # #
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. #
11 # #
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. #
16 # #
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/>. #
19 # #
20 ###############################################################################
21 # #
22 #This script converts old xtaccess rules to new firewall #
23 #Logfiles are created under /var/log/converters #
24 # #
25 ###############################################################################
26 my @current=();
27 my @alias=();
28 my %configinputfw=();
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";
33 my $field0='ACCEPT';
34 my $field1='INPUTFW';
35 my $field2=''; #ON or emtpy
36 my $field3=''; #std_net_src or src_addr
37 my $field4=''; #ALL or IP-Address with /32
38 my $field5='ipfire';
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
46 my $field26='00:00';
47 my $field27='00:00';
48 my $field28 = '';
49 my $field29 = 'ALL';
50 my $field30 = '';
51 my $field31 = 'dnat';
52 open(FILE, $xtaccessconfig) or die 'Unable to open config file.';
53 my @current = <FILE>;
54 close(FILE);
55 open(FILE1, $aliasconfig) or die 'Unable to open config file.';
56 my @alias = <FILE1>;
57 close(FILE1);
58 &General::readhasharray($inputfwconfig,\%configinputfw);
59
60 foreach my $line (@current){
61 my ($a,$b,$c,$d,$e,$f) = split (",",$line);
62 $e =~ s/\R//g;
63 if ($f gt ''){
64 $f =~ s/\R//g;
65 $field16=$f;
66 }
67 #active or not
68 $field2=uc($d);
69 #get protocol
70 if ($a eq 'tcp'){ $field12 ='TCP';}else{$field12='UDP';}
71 #check source address
72 if ($b eq '0.0.0.0/0'){
73 $field3='std_net_src';
74 $field4='ALL';
75 }elsif($b =~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
76 $field3='src_addr';
77 $field4=$b."/32";
78 }elsif ($b =~ /^(.*?)\/(.*?)$/) {
79 $field3='src_addr';
80 $field4=$b;
81 }else{
82 print "Regel konnte nicht konvertiert werden!\n";
83 }
84 #check ipfire address
85 if ($e eq '0.0.0.0'){
86 $field6 = 'RED1';
87 }else{
88 foreach my $line (@alias){
89 my ($ip,$state,$aliasname) = split (",",$line);
90 if ($ip eq $e){
91 $aliasname =~ s/\R//g;
92 $field6 = $aliasname;
93 }
94 }
95 }
96 #get target port
97 $c=~ s/\R//g;
98 $c=~ tr/-/:/;
99 if ($c =~ /^(\D)\:(\d+)$/) {
100 $c = "1:$2";
101 }
102 if ($c =~ /^(\d+)\:(\D)$/) {
103 $c = "$1:65535";
104 }
105 $field15=$c;
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);
141 }