85ad1c8d0c4c8ea2fe112b1f17530a8cb83cdd22
[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 open(FILE, $xtaccessconfig) or die 'Unable to open config file.';
25 my @current = <FILE>;
26 close(FILE);
27 open(FILE1, $aliasconfig) or die 'Unable to open config file.';
28 my @alias = <FILE1>;
29 close(FILE1);
30 &General::readhasharray($inputfwconfig,\%configinputfw);
31
32 foreach my $line (@current){
33 my ($a,$b,$c,$d,$e,$f) = split (",",$line);
34 $e =~ s/\R//g;
35 if ($f gt ''){
36 $f =~ s/\R//g;
37 $field16=$f;
38 }
39 #active or not
40 $field2=uc($d);
41 #get protocol
42 if ($a eq 'tcp'){ $field12 ='TCP';}else{$field12='UDP';}
43 #check source address
44 if ($b eq '0.0.0.0/0'){
45 $field3='std_net_src';
46 $field4='ALL';
47 }elsif($b =~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
48 $field3='src_addr';
49 $field4=$b."/32";
50 }elsif ($b =~ /^(.*?)\/(.*?)$/) {
51 $field3='src_addr';
52 $field4=$b;
53 }else{
54 print "Regel konnte nicht konvertiert werden!\n";
55 }
56 #check ipfire address
57 if ($e eq '0.0.0.0'){
58 $field6 = 'RED1';
59 }else{
60 foreach my $line (@alias){
61 my ($ip,$state,$aliasname) = split (",",$line);
62 if ($ip eq $e){
63 $aliasname =~ s/\R//g;
64 $field6 = $aliasname;
65 }
66 }
67 }
68 #get target port
69 $c=~ s/\R//g;
70 $c=~ tr/-/:/;
71 if ($c =~ /^(\D)\:(\d+)$/) {
72 $c = "1:$2";
73 }
74 if ($c =~ /^(\d+)\:(\D)$/) {
75 $c = "$1:65535";
76 }
77 $field15=$c;
78 my $key = &General::findhasharraykey (\%configinputfw);
79 foreach my $i (0 .. 27) { $configinputfw{$key}[$i] = "";}
80 $configinputfw{$key}[0] = $field0;
81 $configinputfw{$key}[1] = $field1;
82 $configinputfw{$key}[2] = $field2;
83 $configinputfw{$key}[3] = $field3;
84 $configinputfw{$key}[4] = $field4;
85 $configinputfw{$key}[5] = $field5;
86 $configinputfw{$key}[6] = $field6;
87 $configinputfw{$key}[7] = '';
88 $configinputfw{$key}[8] = '';
89 $configinputfw{$key}[9] = '';
90 $configinputfw{$key}[10] = '';
91 $configinputfw{$key}[11] = $field11;
92 $configinputfw{$key}[12] = $field12;
93 $configinputfw{$key}[13] = $field13;
94 $configinputfw{$key}[14] = $field14;
95 $configinputfw{$key}[15] = $field15;
96 $configinputfw{$key}[16] = $field16;
97 $configinputfw{$key}[17] = '';
98 $configinputfw{$key}[18] = '';
99 $configinputfw{$key}[19] = '';
100 $configinputfw{$key}[20] = '';
101 $configinputfw{$key}[21] = '';
102 $configinputfw{$key}[22] = '';
103 $configinputfw{$key}[23] = '';
104 $configinputfw{$key}[24] = '';
105 $configinputfw{$key}[25] = '';
106 $configinputfw{$key}[26] = $field26;
107 $configinputfw{$key}[27] = $field27;
108 &General::writehasharray($inputfwconfig,\%configinputfw);
109 }