8c3bb56a00706f48f3b81f5539311f8094d91d2a
[people/teissler/ipfire-2.x.git] / config / forwardfw / convert-xtaccess
1 #!/usr/bin/perl
2 my @current=();
3 my @alias=();
4 my %configinputfw=();
5 require '/var/ipfire/general-functions.pl';
6 my $xtaccessconfig = "${General::swroot}/xtaccess/config";
7 my $inputfwconfig = "${General::swroot}/forward/input";
8 my $aliasconfig = "${General::swroot}/ethernet/aliases";
9 my $field0='ACCEPT';
10 my $field1='INPUTFW';
11 my $field2=''; #ON or emtpy
12 my $field3=''; #std_net_src or src_addr
13 my $field4=''; #ALL or IP-Address with /32
14 my $field5='ipfire';
15 my $field6=''; #Default IP or alias name
16 my $field11='ON'; #use target port
17 my $field12=''; #TCP or UDP
18 my $field13='All ICMP-Types';
19 my $field14='TGT_PORT';
20 my $field15=''; #Port Number
21 my $field16=''; #remark
22 my $field26='00:00';
23 my $field27='00:00';
24 my $field28 = '';
25 my $field29 = 'ALL';
26 my $field30 = '';
27 my $field31 = 'dnat';
28 open(FILE, $xtaccessconfig) or die 'Unable to open config file.';
29 my @current = <FILE>;
30 close(FILE);
31 open(FILE1, $aliasconfig) or die 'Unable to open config file.';
32 my @alias = <FILE1>;
33 close(FILE1);
34 &General::readhasharray($inputfwconfig,\%configinputfw);
35
36 foreach my $line (@current){
37 my ($a,$b,$c,$d,$e,$f) = split (",",$line);
38 $e =~ s/\R//g;
39 if ($f gt ''){
40 $f =~ s/\R//g;
41 $field16=$f;
42 }
43 #active or not
44 $field2=uc($d);
45 #get protocol
46 if ($a eq 'tcp'){ $field12 ='TCP';}else{$field12='UDP';}
47 #check source address
48 if ($b eq '0.0.0.0/0'){
49 $field3='std_net_src';
50 $field4='ALL';
51 }elsif($b =~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
52 $field3='src_addr';
53 $field4=$b."/32";
54 }elsif ($b =~ /^(.*?)\/(.*?)$/) {
55 $field3='src_addr';
56 $field4=$b;
57 }else{
58 print "Regel konnte nicht konvertiert werden!\n";
59 }
60 #check ipfire address
61 if ($e eq '0.0.0.0'){
62 $field6 = 'RED1';
63 }else{
64 foreach my $line (@alias){
65 my ($ip,$state,$aliasname) = split (",",$line);
66 if ($ip eq $e){
67 $aliasname =~ s/\R//g;
68 $field6 = $aliasname;
69 }
70 }
71 }
72 #get target port
73 $c=~ s/\R//g;
74 $c=~ tr/-/:/;
75 if ($c =~ /^(\D)\:(\d+)$/) {
76 $c = "1:$2";
77 }
78 if ($c =~ /^(\d+)\:(\D)$/) {
79 $c = "$1:65535";
80 }
81 $field15=$c;
82 my $key = &General::findhasharraykey (\%configinputfw);
83 foreach my $i (0 .. 31) { $configinputfw{$key}[$i] = "";}
84 $configinputfw{$key}[0] = $field0;
85 $configinputfw{$key}[1] = $field1;
86 $configinputfw{$key}[2] = $field2;
87 $configinputfw{$key}[3] = $field3;
88 $configinputfw{$key}[4] = $field4;
89 $configinputfw{$key}[5] = $field5;
90 $configinputfw{$key}[6] = $field6;
91 $configinputfw{$key}[7] = '';
92 $configinputfw{$key}[8] = '';
93 $configinputfw{$key}[9] = '';
94 $configinputfw{$key}[10] = '';
95 $configinputfw{$key}[11] = $field11;
96 $configinputfw{$key}[12] = $field12;
97 $configinputfw{$key}[13] = $field13;
98 $configinputfw{$key}[14] = $field14;
99 $configinputfw{$key}[15] = $field15;
100 $configinputfw{$key}[16] = $field16;
101 $configinputfw{$key}[17] = '';
102 $configinputfw{$key}[18] = '';
103 $configinputfw{$key}[19] = '';
104 $configinputfw{$key}[20] = '';
105 $configinputfw{$key}[21] = '';
106 $configinputfw{$key}[22] = '';
107 $configinputfw{$key}[23] = '';
108 $configinputfw{$key}[24] = '';
109 $configinputfw{$key}[25] = '';
110 $configinputfw{$key}[26] = $field26;
111 $configinputfw{$key}[27] = $field27;
112 $configinputfw{$key}[28] = $field28;
113 $configinputfw{$key}[29] = $field29;
114 $configinputfw{$key}[30] = $field30;
115 $configinputfw{$key}[31] = $field31;
116 &General::writehasharray($inputfwconfig,\%configinputfw);
117 }