]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - config/forwardfw/convert-xtaccess
Forward Firewall: changed /etc/init.d/firewall. deleted stop routine and rearranged...
[people/teissler/ipfire-2.x.git] / config / forwardfw / convert-xtaccess
CommitLineData
27f4a6b1
AM
1#!/usr/bin/perl
2my @current=();
3my @alias=();
4my %configinputfw=();
5require '/var/ipfire/general-functions.pl';
6my $xtaccessconfig = "${General::swroot}/xtaccess/config";
7my $inputfwconfig = "${General::swroot}/forward/input";
8my $aliasconfig = "${General::swroot}/ethernet/aliases";
9my $field0='ACCEPT';
10my $field1='INPUTFW';
11my $field2=''; #ON or emtpy
12my $field3=''; #std_net_src or src_addr
13my $field4=''; #ALL or IP-Address with /32
14my $field5='ipfire';
15my $field6=''; #Default IP or alias name
16my $field11='ON'; #use target port
17my $field12=''; #TCP or UDP
18my $field13='All ICMP-Types';
19my $field14='TGT_PORT';
20my $field15=''; #Port Number
21my $field16=''; #remark
22my $field26='00:00';
23my $field27='00:00';
24open(FILE, $xtaccessconfig) or die 'Unable to open config file.';
25my @current = <FILE>;
26close(FILE);
27open(FILE1, $aliasconfig) or die 'Unable to open config file.';
28my @alias = <FILE1>;
29close(FILE1);
30&General::readhasharray($inputfwconfig,\%configinputfw);
31
32foreach 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'){
fb0ce575 58 $field6 = 'RED1';
27f4a6b1
AM
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;
27f4a6b1
AM
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}