]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/forwardfw.cgi
2e783ce46dcad6cca84e8e90c40fd52268214e66
[people/teissler/ipfire-2.x.git] / html / cgi-bin / forwardfw.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 #
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 # Hi folks! I hope this code is useful for all. I needed something to handle #
23 # my VPN Connections in a comfortable way. As a prerequisite i needed #
24 # something that makes sure the vpn roadwarrior are able to have a fixed #
25 # ip-address. So i developed the ccd extension for the vpn server. #
26 # #
27 # Now that the ccd extension is ready i am able to develop the main request. #
28 # Any feedback is appreciated. #
29 # #
30 # #
31 ###############################################################################
32
33 use strict;
34 no warnings 'uninitialized';
35 # enable only the following on debugging purpose
36 #use warnings;
37 #use CGI::Carp 'fatalsToBrowser';
38
39 require '/var/ipfire/general-functions.pl';
40 require "${General::swroot}/lang.pl";
41 require "${General::swroot}/header.pl";
42 require "${General::swroot}/forward/bin/firewall-lib.pl";
43
44 unless (-d "${General::swroot}/forward") { system("mkdir ${General::swroot}/forward"); }
45 unless (-e "${General::swroot}/forward/settings") { system("touch ${General::swroot}/forward/settings"); }
46 unless (-e "${General::swroot}/forward/config") { system("touch ${General::swroot}/forward/config"); }
47 unless (-e "${General::swroot}/forward/input") { system("touch ${General::swroot}/forward/input"); }
48
49 my %fwdfwsettings=();
50 my %selected=() ;
51 my %defaultNetworks=();
52 my %netsettings=();
53 my %customhost=();
54 my %customgrp=();
55 my %customnetworks=();
56 my %customservice=();
57 my %customservicegrp=();
58 my %ccdnet=();
59 my %customnetwork=();
60 my %ccdhost=();
61 my %configfwdfw=();
62 my %configinputfw=();
63 my %ipsecconf=();
64 my %color=();
65 my %mainsettings=();
66 my %checked=();
67 my %icmptypes=();
68 my %ovpnsettings=();
69 my %ipsecsettings=();
70 my %aliases=();
71 my @p2ps = ();
72 my $color;
73 my $confignet = "${General::swroot}/fwhosts/customnetworks";
74 my $confighost = "${General::swroot}/fwhosts/customhosts";
75 my $configgrp = "${General::swroot}/fwhosts/customgroups";
76 my $configsrv = "${General::swroot}/fwhosts/customservices";
77 my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
78 my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
79 my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
80 my $configipsec = "${General::swroot}/vpn/config";
81 my $configipsecrw = "${General::swroot}/vpn/settings";
82 my $configfwdfw = "${General::swroot}/forward/config";
83 my $configinput = "${General::swroot}/forward/input";
84 my $configovpn = "${General::swroot}/ovpn/settings";
85 my $p2pfile = "${General::swroot}/forward/p2protocols";
86 my $errormessage='';
87 my $hint='';
88 my $ipgrp="${General::swroot}/outgoing/groups";
89
90
91 &General::readhash("${General::swroot}/forward/settings", \%fwdfwsettings);
92 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
93 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
94
95 &Header::showhttpheaders();
96 &Header::getcgihash(\%fwdfwsettings);
97 &Header::openpage($Lang::tr{'fwdfw menu'}, 1, '');
98 &Header::openbigbox('100%', 'center',$errormessage);
99 #### ACTION #####
100
101 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'save'})
102 {
103 my $MODE = $fwdfwsettings{'POLICY'};
104 %fwdfwsettings = ();
105 $fwdfwsettings{'POLICY'} = "$MODE";
106 &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings);
107 &reread_rules;
108 }
109 if ($fwdfwsettings{'ACTION'} eq 'saverule')
110 {
111 &General::readhasharray("$configfwdfw", \%configfwdfw);
112 &General::readhasharray("$configinput", \%configinputfw);
113 $errormessage=&checksource;
114 if(!$errormessage){&checktarget;}
115 if(!$errormessage){&checkrule;}
116 #check if we change an forward rule to an external access
117 if( $fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{'oldgrp2a'} ne 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
118 $fwdfwsettings{'updatefwrule'}='';
119 $fwdfwsettings{'config'}=$configfwdfw;
120 $fwdfwsettings{'nobase'}='on';
121 &deleterule;
122 &checkcounter(0,0,$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
123 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
124 }
125 #check if we change an external access rule to an forward
126 if( $fwdfwsettings{'grp2'} ne 'ipfire' && $fwdfwsettings{'oldgrp2a'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){
127 $fwdfwsettings{'updatefwrule'}='';
128 $fwdfwsettings{'config'}=$configinput;
129 $fwdfwsettings{'nobase'}='on';
130 &deleterule;
131 &checkcounter(0,0,$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
132 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
133 }
134 #INPUT part
135 if($fwdfwsettings{'grp2'} eq 'ipfire'){
136 $fwdfwsettings{'config'}=$configinput;
137 $fwdfwsettings{'chain'} = 'INPUTFW';
138 my $maxkey=&General::findhasharraykey(\%configinputfw);
139 #check if we have an identical rule already
140 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
141 foreach my $key (sort keys %configinputfw){
142 if ("$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'}"
143 eq "$configinputfw{$key}[0],$configinputfw{$key}[2],$configinputfw{$key}[3],$configinputfw{$key}[4],$configinputfw{$key}[5],$configinputfw{$key}[6],$configinputfw{$key}[7],$configinputfw{$key}[8],$configinputfw{$key}[9],$configinputfw{$key}[10],$configinputfw{$key}[11],$configinputfw{$key}[12],$configinputfw{$key}[13],$configinputfw{$key}[14],$configinputfw{$key}[15],$configinputfw{$key}[17],$configinputfw{$key}[18],$configinputfw{$key}[19],$configinputfw{$key}[20],$configinputfw{$key}[21],$configinputfw{$key}[22],$configinputfw{$key}[23],$configinputfw{$key}[24],$configinputfw{$key}[25],$configinputfw{$key}[26],$configinputfw{$key}[27]"){
144 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
145 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && &validremark($fwdfwsettings{'ruleremark'})){
146 $errormessage='';
147 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && !&validremark($fwdfwsettings{'ruleremark'})){
148 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
149 }
150 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
151 $fwdfwsettings{'nosave'} = 'on';
152 }
153 }
154 }
155 }
156 #check Rulepos on new Rule
157 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
158 $fwdfwsettings{'oldrulenumber'}=$maxkey;
159 foreach my $key (sort keys %configinputfw){
160 if ("$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'}"
161 eq "$configinputfw{$key}[0],$configinputfw{$key}[2],$configinputfw{$key}[3],$configinputfw{$key}[4],$configinputfw{$key}[5],$configinputfw{$key}[6],$configinputfw{$key}[7],$configinputfw{$key}[8],$configinputfw{$key}[9],$configinputfw{$key}[10],$configinputfw{$key}[11],$configinputfw{$key}[12],$configinputfw{$key}[13],$configinputfw{$key}[14],$configinputfw{$key}[15],$configinputfw{$key}[17],$configinputfw{$key}[18],$configinputfw{$key}[19],$configinputfw{$key}[20],$configinputfw{$key}[21],$configinputfw{$key}[22],$configinputfw{$key}[23],$configinputfw{$key}[24],$configinputfw{$key}[25],$configinputfw{$key}[26],$configinputfw{$key}[27]"){
162 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
163 }
164 }
165 }
166 #check if we just close a rule
167 if( $fwdfwsettings{'oldgrp1a'} eq $fwdfwsettings{'grp1'} && $fwdfwsettings{'oldgrp1b'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'oldgrp2a'} eq $fwdfwsettings{'grp2'} && $fwdfwsettings{'oldgrp2b'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'oldgrp3a'} eq $fwdfwsettings{'grp3'} && $fwdfwsettings{'oldgrp3b'} eq $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} ) {
168 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
169 $errormessage='';
170 $fwdfwsettings{'nosave2'} = 'on';
171 }
172 }
173 &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
174 if ($fwdfwsettings{'nobase'} ne 'on'){
175 &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
176 }
177 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
178 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
179 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
180 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
181 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
182 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
183 }
184 if($fwdfwsettings{'nosave2'} ne 'on'){
185 &saverule(\%configinputfw,$configinput);
186 }
187 #print "Source: $fwdfwsettings{'grp1'} -> $fwdfwsettings{$fwdfwsettings{'grp1'}}<br>";
188 #print "Sourceport: $fwdfwsettings{'USE_SRC_PORT'}, $fwdfwsettings{'PROT'}, $fwdfwsettings{'ICMP_TYPES'}, $fwdfwsettings{'SRC_PORT'}<br>";
189 #print "Target: $fwdfwsettings{'grp2'} -> $fwdfwsettings{$fwdfwsettings{'grp2'}}<br>";
190 #print "Dienst: $fwdfwsettings{'USESRV'}, $fwdfwsettings{'grp3'} -> $fwdfwsettings{$fwdfwsettings{'grp3'}}<br>";
191 #print "BEMERKUNG: $fwdfwsettings{'ruleremark'}<br>";
192 #print " Regel AKTIV: $fwdfwsettings{'ACTIVE'}<br>";
193 #print " Regel LOG: $fwdfwsettings{'LOG'}<br>";
194 #print " ZEITRAHMEN: $fwdfwsettings{'TIME'}<br>";
195 #print " MO: $fwdfwsettings{'TIME_MON'}<br>";
196 #print " DI: $fwdfwsettings{'TIME_TUE'}<br>";
197 #print " MI: $fwdfwsettings{'TIME_WED'}<br>";
198 #print " DO: $fwdfwsettings{'TIME_THU'}<br>";
199 #print " FR: $fwdfwsettings{'TIME_FRI'}<br>";
200 #print " SA: $fwdfwsettings{'TIME_SAT'}<br>";
201 #print " SO: $fwdfwsettings{'TIME_SUN'}<br>";
202 #print " VON: $fwdfwsettings{'TIME_FROM'} bis $fwdfwsettings{'TIME_TO'}<br>";
203 #print "<br>";
204 #print"ALT: $fwdfwsettings{'oldgrp1a'} $fwdfwsettings{'oldgrp1b'} NEU: $fwdfwsettings{'grp1'} $fwdfwsettings{$fwdfwsettings{'grp1'}}<br>";
205 #print"ALT: $fwdfwsettings{'oldgrp2a'} $fwdfwsettings{'oldgrp2b'} NEU: $fwdfwsettings{'grp2'} $fwdfwsettings{$fwdfwsettings{'grp2'}}<br>";
206 #print"ALT: $fwdfwsettings{'oldgrp3a'} $fwdfwsettings{'oldgrp3b'} NEU: $fwdfwsettings{'grp3'} $fwdfwsettings{$fwdfwsettings{'grp3'}}<br>";
207 #print"DIENSTE Checkalt:$fwdfwsettings{'oldusesrv'} DIENSTE Checkneu:$fwdfwsettings{'USESRV'} DIENST ALT:$fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'} DIENST NEU:$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}}<br>";
208 }else{
209 #FORWARD PART
210 $fwdfwsettings{'config'}=$configfwdfw;
211 $fwdfwsettings{'chain'} = 'FORWARDFW';
212 my $maxkey=&General::findhasharraykey(\%configfwdfw);
213 if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){
214 #check if we have an identical rule already
215 foreach my $key (sort keys %configfwdfw){
216 if ("$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'}"
217 eq "$configfwdfw{$key}[0],$configfwdfw{$key}[2],$configfwdfw{$key}[3],$configfwdfw{$key}[4],$configfwdfw{$key}[5],$configfwdfw{$key}[6],$configfwdfw{$key}[7],$configfwdfw{$key}[8],$configfwdfw{$key}[9],$configfwdfw{$key}[10],$configfwdfw{$key}[11],$configfwdfw{$key}[12],$configfwdfw{$key}[13],$configfwdfw{$key}[14],$configfwdfw{$key}[15],$configfwdfw{$key}[17],$configfwdfw{$key}[18],$configfwdfw{$key}[19],$configfwdfw{$key}[20],$configfwdfw{$key}[21],$configfwdfw{$key}[22],$configfwdfw{$key}[23],$configfwdfw{$key}[24],$configfwdfw{$key}[25],$configfwdfw{$key}[26],$configfwdfw{$key}[27]"){
218 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
219 if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && &validremark($fwdfwsettings{'ruleremark'})){
220 $errormessage='';
221 }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && !&validremark($fwdfwsettings{'ruleremark'})){
222 $errormessage=$Lang::tr{'fwdfw err remark'}."<br>";
223 }
224 if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){
225 $fwdfwsettings{'nosave'} = 'on';
226 }
227 }
228 }
229 }
230 #check Rulepos on new Rule
231 if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){
232 $fwdfwsettings{'oldrulenumber'}=$maxkey;
233 foreach my $key (sort keys %configfwdfw){
234 if ("$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'}"
235 eq "$configfwdfw{$key}[0],$configfwdfw{$key}[2],$configfwdfw{$key}[3],$configfwdfw{$key}[4],$configfwdfw{$key}[5],$configfwdfw{$key}[6],$configfwdfw{$key}[7],$configfwdfw{$key}[8],$configfwdfw{$key}[9],$configfwdfw{$key}[10],$configfwdfw{$key}[11],$configfwdfw{$key}[12],$configfwdfw{$key}[13],$configfwdfw{$key}[14],$configfwdfw{$key}[15],$configfwdfw{$key}[17],$configfwdfw{$key}[18],$configfwdfw{$key}[19],$configfwdfw{$key}[20],$configfwdfw{$key}[21],$configfwdfw{$key}[22],$configfwdfw{$key}[23],$configfwdfw{$key}[24],$configfwdfw{$key}[25],$configfwdfw{$key}[26],$configfwdfw{$key}[27]"){
236 $errormessage.=$Lang::tr{'fwdfw err ruleexists'};
237 }
238 }
239 }
240 #check if we just close a rule
241 if( $fwdfwsettings{'oldgrp1a'} eq $fwdfwsettings{'grp1'} && $fwdfwsettings{'oldgrp1b'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'oldgrp2a'} eq $fwdfwsettings{'grp2'} && $fwdfwsettings{'oldgrp2b'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'oldgrp3a'} eq $fwdfwsettings{'grp3'} && $fwdfwsettings{'oldgrp3b'} eq $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'} ) {
242 if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){
243 $fwdfwsettings{'nosave2'} = 'on';
244 $errormessage='';
245 }
246 }
247 #increase counters
248 &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
249 &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
250 if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
251 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
252 }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
253 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
254 }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
255 &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
256 }
257 if ($fwdfwsettings{'nobase'} eq 'on'){
258 &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
259 }
260 if ($fwdfwsettings{'nosave2'} ne 'on'){
261 &saverule(\%configfwdfw,$configfwdfw);
262 }
263 #print "Source: $fwdfwsettings{'grp1'} -> $fwdfwsettings{$fwdfwsettings{'grp1'}}<br>";
264 #print "Sourceport: $fwdfwsettings{'USE_SRC_PORT'}, $fwdfwsettings{'PROT'}, $fwdfwsettings{'ICMP_TYPES'}, $fwdfwsettings{'SRC_PORT'}<br>";
265 #print "Target: $fwdfwsettings{'grp2'} -> $fwdfwsettings{$fwdfwsettings{'grp2'}}<br>";
266 #print "Dienst: $fwdfwsettings{'USESRV'}, $fwdfwsettings{'grp3'} -> $fwdfwsettings{$fwdfwsettings{'grp3'}}<br>";
267 #print "BEMERKUNG: $fwdfwsettings{'ruleremark'}<br>";
268 #print " Regel AKTIV: $fwdfwsettings{'ACTIVE'}<br>";
269 #print " Regel LOG: $fwdfwsettings{'LOG'}<br>";
270 #print " ZEITRAHMEN: $fwdfwsettings{'TIME'}<br>";
271 #print " MO: $fwdfwsettings{'TIME_MON'}<br>";
272 #print " DI: $fwdfwsettings{'TIME_TUE'}<br>";
273 #print " MI: $fwdfwsettings{'TIME_WED'}<br>";
274 #print " DO: $fwdfwsettings{'TIME_THU'}<br>";
275 #print " FR: $fwdfwsettings{'TIME_FRI'}<br>";
276 #print " SA: $fwdfwsettings{'TIME_SAT'}<br>";
277 #print " SO: $fwdfwsettings{'TIME_SUN'}<br>";
278 #print " VON: $fwdfwsettings{'TIME_FROM'} bis $fwdfwsettings{'TIME_TO'}<br>";
279 #print "<br>";
280 #print"ALT: $fwdfwsettings{'oldgrp1a'} $fwdfwsettings{'oldgrp1b'} NEU: $fwdfwsettings{'grp1'} $fwdfwsettings{$fwdfwsettings{'grp1'}}<br>";
281 #print"ALT: $fwdfwsettings{'oldgrp2a'} $fwdfwsettings{'oldgrp2b'} NEU: $fwdfwsettings{'grp2'} $fwdfwsettings{$fwdfwsettings{'grp2'}}<br>";
282 #print"ALT: $fwdfwsettings{'oldgrp3a'} $fwdfwsettings{'oldgrp3b'} NEU: $fwdfwsettings{'grp3'} $fwdfwsettings{$fwdfwsettings{'grp3'}}<br>";
283 #print"DIENSTE Checkalt:$fwdfwsettings{'oldusesrv'} DIENSTE Checkneu:$fwdfwsettings{'USESRV'} DIENST ALT:$fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'} DIENST NEU:$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}}<br>";
284 }
285 if ($errormessage){
286 &newrule;
287 }else{
288 if($fwdfwsettings{'nosave2'} ne 'on'){
289 &rules;
290 }
291 &base;
292 }
293 }
294 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'reset'})
295 {
296 &General::readhasharray("$configfwdfw", \%configfwdfw);
297 foreach my $key (sort keys %configfwdfw){
298 &checkcounter($configfwdfw{$key}[3],$configfwdfw{$key}[4],,);
299 &checkcounter($configfwdfw{$key}[5],$configfwdfw{$key}[6],,);
300 &checkcounter($configfwdfw{$key}[14],$configfwdfw{$key}[15],,);
301 }
302 &General::readhasharray("$configinput", \%configinputfw);
303 foreach my $key (sort keys %configinputfw){
304 &checkcounter($configinputfw{$key}[3],$configinputfw{$key}[4],,);
305 &checkcounter($configinputfw{$key}[5],$configinputfw{$key}[6],,);
306 &checkcounter($configinputfw{$key}[14],$configinputfw{$key}[15],,);
307 }
308
309 system("rm ${General::swroot}/forward/config");
310 system("rm ${General::swroot}/forward/input");
311 &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings);
312 unless (-e "${General::swroot}/forward/config") { system("touch ${General::swroot}/forward/config"); }
313 unless (-e "${General::swroot}/forward/input") { system("touch ${General::swroot}/forward/input"); }
314 %fwdfwsettings = ();
315 $fwdfwsettings{'POLICY'}='MODE2';
316 &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings);
317 &reread_rules;
318
319 }
320 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw newrule'})
321 {
322 &newrule;
323 }
324 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw toggle'})
325 {
326 my %togglehash=();
327 &General::readhasharray($fwdfwsettings{'config'}, \%togglehash);
328 foreach my $key (sort keys %togglehash){
329 if ($key eq $fwdfwsettings{'key'}){
330 if ($togglehash{$key}[2] eq 'ON'){$togglehash{$key}[2]='';}else{$togglehash{$key}[2]='ON';}
331 }
332 }
333 &General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
334 &rules;
335 &base;
336 }
337 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw togglelog'})
338 {
339 my %togglehash=();
340 &General::readhasharray($fwdfwsettings{'config'}, \%togglehash);
341 foreach my $key (sort keys %togglehash){
342 if ($key eq $fwdfwsettings{'key'}){
343 if ($togglehash{$key}[17] eq 'ON'){$togglehash{$key}[17]='';}else{$togglehash{$key}[17]='ON';}
344 }
345 }
346 &General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
347 &rules;
348 &base;
349 }
350 if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
351 {
352 &reread_rules;
353 &base;
354 }
355 if ($fwdfwsettings{'ACTION'} eq 'editrule')
356 {
357 $fwdfwsettings{'updatefwrule'}='on';
358 &newrule;
359 }
360 if ($fwdfwsettings{'ACTION'} eq 'deleterule')
361 {
362 &deleterule;
363 }
364 if ($fwdfwsettings{'ACTION'} eq 'moveup')
365 {
366 &pos_up;
367 &base;
368 }
369 if ($fwdfwsettings{'ACTION'} eq 'movedown')
370 {
371 &pos_down;
372 &base;
373 }
374 if ($fwdfwsettings{'ACTION'} eq 'copyrule')
375 {
376 $fwdfwsettings{'copyfwrule'}='on';
377 #$fwdfwsettings{'updatefwrule'}='on';
378 &newrule;
379 }
380 if ($fwdfwsettings{'ACTION'} eq 'togglep2p')
381 {
382 #$errormessage="Toggle $fwdfwsettings{'P2PROT'}<br>";
383 open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
384 @p2ps = <FILE>;
385 close FILE;
386 open( FILE, "> $p2pfile" ) or die "Unable to write $p2pfile";
387 foreach my $p2pentry (sort @p2ps)
388 {
389 my @p2pline = split( /\;/, $p2pentry );
390 if ($p2pline[1] eq $fwdfwsettings{'P2PROT'}) {
391 if($p2pline[2] eq 'on'){
392 $p2pline[2]='off';
393 }else{
394 $p2pline[2]='on';
395 }
396 }
397 print FILE "$p2pline[0];$p2pline[1];$p2pline[2];\n";
398 }
399 close FILE;
400 &rules;
401 &base;
402 }
403 if ($fwdfwsettings{'ACTION'} eq '')
404 {
405 &base;
406 }
407 ### Functions ####
408 sub pos_up
409 {
410 my %uphash=();
411 my %tmp=();
412 &General::readhasharray($fwdfwsettings{'config'}, \%uphash);
413 foreach my $key (sort keys %uphash){
414 if ($key eq $fwdfwsettings{'key'}) {
415 my $last = $key -1;
416 if (exists $uphash{$last}){
417 #save rule last
418 foreach my $y (0 .. $#{$uphash{$last}}) {
419 $tmp{0}[$y] = $uphash{$last}[$y];
420 }
421 #copy active rule to last
422 foreach my $i (0 .. $#{$uphash{$last}}) {
423 $uphash{$last}[$i] = $uphash{$key}[$i];
424 }
425 #copy saved rule to actual position
426 foreach my $x (0 .. $#{$tmp{0}}) {
427 $uphash{$key}[$x] = $tmp{0}[$x];
428 }
429 }
430 }
431 }
432 &General::writehasharray($fwdfwsettings{'config'}, \%uphash);
433 &rules;
434 }
435 sub pos_down
436 {
437 my %downhash=();
438 my %tmp=();
439 &General::readhasharray($fwdfwsettings{'config'}, \%downhash);
440 foreach my $key (sort keys %downhash){
441 if ($key eq $fwdfwsettings{'key'}) {
442 my $next = $key + 1;
443 if (exists $downhash{$next}){
444 #save rule next
445 foreach my $y (0 .. $#{$downhash{$next}}) {
446 $tmp{0}[$y] = $downhash{$next}[$y];
447 }
448 #copy active rule to next
449 foreach my $i (0 .. $#{$downhash{$next}}) {
450 $downhash{$next}[$i] = $downhash{$key}[$i];
451 }
452 #copy saved rule to actual position
453 foreach my $x (0 .. $#{$tmp{0}}) {
454 $downhash{$key}[$x] = $tmp{0}[$x];
455 }
456 }
457 }
458 }
459 &General::writehasharray($fwdfwsettings{'config'}, \%downhash);
460 &rules;
461 }
462 sub checkcounter
463 {
464 my ($base1,$val1,$base2,$val2) = @_;
465
466 if($base1 eq 'cust_net_src' || $base1 eq 'cust_net_tgt'){
467 &dec_counter($confignet,\%customnetwork,$val1);
468 }elsif($base1 eq 'cust_host_src' || $base1 eq 'cust_host_tgt'){
469 &dec_counter($confighost,\%customhost,$val1);
470 }elsif($base1 eq 'cust_grp_src' || $base1 eq 'cust_grp_tgt'){
471 &dec_counter($configgrp,\%customgrp,$val1);
472 }elsif($base1 eq 'cust_srv'){
473 &dec_counter($configsrv,\%customservice,$val1);
474 }elsif($base1 eq 'cust_srvgrp'){
475 &dec_counter($configsrvgrp,\%customservicegrp,$val1);
476 }
477
478 if($base2 eq 'cust_net_src' || $base2 eq 'cust_net_tgt'){
479 &inc_counter($confignet,\%customnetwork,$val2);
480 }elsif($base2 eq 'cust_host_src' || $base2 eq 'cust_host_tgt'){
481 &inc_counter($confighost,\%customhost,$val2);
482 }elsif($base2 eq 'cust_grp_src' || $base2 eq 'cust_grp_tgt'){
483 &inc_counter($configgrp,\%customgrp,$val2);
484 }elsif($base2 eq 'cust_srv'){
485 &inc_counter($configsrv,\%customservice,$val2);
486 }elsif($base2 eq 'cust_srvgrp'){
487 &inc_counter($configsrvgrp,\%customservicegrp,$val2);
488 }
489 }
490 sub inc_counter
491 {
492 my $config=shift;
493 my %hash=%{(shift)};
494 my $val=shift;
495 my $pos;
496
497 &General::readhasharray($config, \%hash);
498 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
499 if($hash{$key}[0] eq $val){
500 $pos=$#{$hash{$key}};
501 $hash{$key}[$pos] = $hash{$key}[$pos]+1;
502 }
503 }
504 &General::writehasharray($config, \%hash);
505 }
506 sub dec_counter
507 {
508 my $config=shift;
509 my %hash=%{(shift)};
510 my $val=shift;
511 my $pos;
512 #$errormessage.="ALT:config: $config , verringert wird $val <br>";
513 &General::readhasharray($config, \%hash);
514 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
515 if($hash{$key}[0] eq $val){
516 $pos=$#{$hash{$key}};
517 $hash{$key}[$pos] = $hash{$key}[$pos]-1;
518 }
519 }
520 &General::writehasharray($config, \%hash);
521 }
522 sub base
523 {
524 if ($fwdfwsettings{'POLICY'} eq 'MODE1'){ $selected{'POLICY'}{'MODE1'} = 'selected'; } else { $selected{'POLICY'}{'MODE1'} = ''; }
525 if ($fwdfwsettings{'POLICY'} eq 'MODE2'){ $selected{'POLICY'}{'MODE2'} = 'selected'; } else { $selected{'POLICY'}{'MODE2'} = ''; }
526 &hint;
527 &addrule;
528 &p2pblock;
529 &Header::openbox('100%', 'center', $Lang::tr{'fwdfw pol title'});
530 print <<END;
531 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
532 <table width='100%' border='0'>
533 <tr><td colspan='3'>$Lang::tr{'fwdfw pol text'}</td></tr>
534
535 <tr><td colspan='3'><hr /></td></tr>
536 <tr><td width='15%' align='left'> <select name='POLICY' style="width: 100px">
537 <option value='MODE1' $selected{'POLICY'}{'MODE1'}>$Lang::tr{'fwdfw pol block'}</option>
538 <option value='MODE2' $selected{'POLICY'}{'MODE2'}>$Lang::tr{'fwdfw pol allow'}</option></select>
539 <td width='45%' align='left'><input type='submit' name='ACTION' value=$Lang::tr{'save'} />
540 <td width='45%' align='left'>
541 END
542 print "$Lang::tr{'outgoing firewall reset'}: <input type='submit' name='ACTION' value='$Lang::tr{'reset'}' />";
543 print "</table></form>";
544 &Header::closebox();
545 }
546 sub addrule
547 {
548 &error;
549 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'});
550
551 print "<form method='post'>";
552 print "<table border='0'>";
553 print "<tr><td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw newrule'}'></td>";
554 if (-f "${General::swroot}/forward/reread"){
555 print "<td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}' style='font-face: Comic Sans MS; color: red; font-weight: bold;'>$Lang::tr{'fwhost reread'}</td>";
556 }
557 print"</tr></table></form><hr>";
558
559 &Header::closebox();
560 &viewtablerule;
561 }
562 sub deleterule
563 {
564 my %delhash=();
565 &General::readhasharray($fwdfwsettings{'config'}, \%delhash);
566 foreach my $key (sort {$a <=> $b} keys %delhash){
567 if ($key == $fwdfwsettings{'key'}){
568 #check hosts/net and groups
569 &checkcounter($delhash{$key}[3],$delhash{$key}[4],,);
570 &checkcounter($delhash{$key}[5],$delhash{$key}[6],,);
571 #check services and groups
572 if ($delhash{$key}[11] eq 'ON'){
573 &checkcounter($delhash{$key}[14],$delhash{$key}[15],,);
574 }
575 }
576 if ($key >= $fwdfwsettings{'key'}) {
577 my $next = $key + 1;
578 if (exists $delhash{$next}) {
579 foreach my $i (0 .. $#{$delhash{$next}}) {
580 $delhash{$key}[$i] = $delhash{$next}[$i];
581 }
582 }
583 }
584 }
585 # Remove the very last entry.
586 my $last_key = (sort {$a <=> $b} keys %delhash)[-1];
587 delete $delhash{$last_key};
588
589 &General::writehasharray($fwdfwsettings{'config'}, \%delhash);
590 &rules;
591
592 if($fwdfwsettings{'nobase'} ne 'on'){
593 &base;
594 }
595 }
596 sub disable_rule
597 {
598 my $key1=shift;
599 &General::readhasharray("$configfwdfw", \%configfwdfw);
600 foreach my $key (sort keys %configfwdfw){
601 if ($key eq $key1 ){
602 if ($configfwdfw{$key}[2] eq 'ON'){$configfwdfw{$key}[2]='';}
603 }
604 }
605 &General::writehasharray("$configfwdfw", \%configfwdfw);
606 &rules;
607 }
608 sub checksource
609 {
610 my ($ip,$subnet);
611
612 #check ip-address if manual
613 if ($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} ne ''){
614 #check if ip with subnet
615 if ($fwdfwsettings{'src_addr'} =~ /^(.*?)\/(.*?)$/) {
616 ($ip,$subnet)=split (/\//,$fwdfwsettings{'src_addr'});
617 $subnet = &General::iporsubtocidr($subnet);
618 $fwdfwsettings{'isip'}='on';
619 }
620 #check if only ip
621 if($fwdfwsettings{'src_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
622 $ip=$fwdfwsettings{'src_addr'};
623 $subnet = '32';
624 $fwdfwsettings{'isip'}='on';
625 }
626
627 if ($fwdfwsettings{'isip'} ne 'on'){
628 if (&General::validmac($fwdfwsettings{'src_addr'})){$fwdfwsettings{'ismac'}='on';}
629 }
630 if ($fwdfwsettings{'isip'} eq 'on'){
631 #check and form valid IP
632 $ip=&General::ip2dec($ip);
633 $ip=&General::dec2ip($ip);
634 #check if net or broadcast
635 my @tmp= split (/\./,$ip);
636 if (($tmp[3] eq "0") || ($tmp[3] eq "255"))
637 {
638 $errormessage=$Lang::tr{'fwhost err hostip'}."<br>";
639 }
640 $fwdfwsettings{'src_addr'}="$ip/$subnet";
641
642 if(!&General::validipandmask($fwdfwsettings{'src_addr'})){
643 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
644 }
645 }
646 if ($fwdfwsettings{'isip'} ne 'on' && $fwdfwsettings{'ismac'} ne 'on'){
647 $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
648 }
649 }elsif($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} eq ''){
650 $errormessage.=$Lang::tr{'fwdfw err nosrcip'};
651 return $errormessage;
652 }
653
654 #check empty fields
655 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err nosrc'}."<br>";}
656 #check icmp source
657 if ($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ICMP'){
658 $fwdfwsettings{'SRC_PORT'}='';
659 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
660 foreach my $key (keys %icmptypes){
661 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0] ($icmptypes{$key}[1])"){
662 $fwdfwsettings{'ICMP_TYPES'}="$icmptypes{$key}[0]";
663 }
664 }
665 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'GRE'){
666 $fwdfwsettings{'SRC_PORT'}='';
667 $fwdfwsettings{'ICMP_TYPES'}='';
668 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ESP'){
669 $fwdfwsettings{'SRC_PORT'}='';
670 $fwdfwsettings{'ICMP_TYPES'}='';
671 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'AH'){
672 $fwdfwsettings{'SRC_PORT'}='';
673 $fwdfwsettings{'ICMP_TYPES'}='';
674 }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} ne 'ICMP'){
675 $fwdfwsettings{'ICMP_TYPES'}='';
676 }else{
677 $fwdfwsettings{'ICMP_TYPES'}='';
678 $fwdfwsettings{'SRC_PORT'}='';
679 $fwdfwsettings{'PROT'}='';
680 }
681
682 if($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'SRC_PORT'} ne ''){
683 my @parts=split(",",$fwdfwsettings{'SRC_PORT'});
684 my @values=();
685 foreach (@parts){
686 chomp($_);
687 if ($_ =~ /^(\d+)\:(\d+)$/) {
688 my $check;
689 #change dashes with :
690 $_=~ tr/-/:/;
691 if ($_ eq "*") {
692 push(@values,"1:65535");
693 $check='on';
694 }
695 if ($_ =~ /^(\D)\:(\d+)$/) {
696 push(@values,"1:$2");
697 $check='on';
698 }
699 if ($_ =~ /^(\d+)\:(\D)$/) {
700 push(@values,"$1:65535");
701 $check='on'
702 }
703 $errormessage .= &General::validportrange($_, 'destination');
704 if(!$check){
705 push (@values,$_);
706 }
707 }else{
708 if (&General::validport($_)){
709 push (@values,$_);
710 }else{
711
712 }
713 }
714 }
715 $fwdfwsettings{'SRC_PORT'}=join("|",@values);
716 return $errormessage;
717 }
718 }
719 sub checktarget
720 {
721 my ($ip,$subnet);
722
723 if ($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} ne ''){
724 #check if ip with subnet
725 if ($fwdfwsettings{'tgt_addr'} =~ /^(.*?)\/(.*?)$/) {
726 ($ip,$subnet)=split (/\//,$fwdfwsettings{'tgt_addr'});
727 $subnet = &General::iporsubtocidr($subnet);
728 }
729 #check if only ip
730 if($fwdfwsettings{'tgt_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
731 $ip=$fwdfwsettings{'tgt_addr'};
732 $subnet='32';
733 }
734 #check and form valid IP
735 $ip=&General::ip2dec($ip);
736 $ip=&General::dec2ip($ip);
737
738 ##check if net or broadcast
739 #my @tmp= split (/\./,$ip);
740 #if ($tmp[3] eq "0" || ($tmp[3] eq "255"))
741 #{
742 #$errormessage=$Lang::tr{'fwhost err hostip'}."<br>";
743 #}
744 $fwdfwsettings{'tgt_addr'}="$ip/$subnet";
745
746 if(!&General::validipandmask($fwdfwsettings{'tgt_addr'})){
747 $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>";
748 }
749
750 }elsif($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} eq ''){
751 $errormessage.=$Lang::tr{'fwdfw err notgtip'};
752 return $errormessage;
753 }
754
755 #check empty fields
756 if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err notgt'}."<br>";}
757
758 #check tgt services
759 if ($fwdfwsettings{'USESRV'} eq 'ON'){
760 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
761 $fwdfwsettings{'TGT_PROT'}='';
762 $fwdfwsettings{'ICMP_TGT'}='';
763 }
764 if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){
765 $fwdfwsettings{'TGT_PROT'}='';
766 $fwdfwsettings{'ICMP_TGT'}='';
767 #check target service
768 if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq ''){
769 $errormessage.=$Lang::tr{'fwdfw err tgt_grp'};
770 }
771 }
772 if ($fwdfwsettings{'grp3'} eq 'TGT_PORT'){
773 if ($fwdfwsettings{'TGT_PROT'} eq 'TCP' || $fwdfwsettings{'TGT_PROT'} eq 'UDP'){
774 if ($fwdfwsettings{'TGT_PORT'} ne ''){
775 my @parts=split(",",$fwdfwsettings{'TGT_PORT'});
776 my @values=();
777 foreach (@parts){
778 chomp($_);
779 if ($_ =~ /^(\d+)\:(\d+)$/) {
780 my $check;
781 #change dashes with :
782 $_=~ tr/-/:/;
783 if ($_ eq "*") {
784 push(@values,"1:65535");
785 $check='on';
786 }
787 if ($_ =~ /^(\D)\:(\d+)$/) {
788 push(@values,"1:$2");
789 $check='on';
790 }
791 if ($_ =~ /^(\d+)\:(\D)$/) {
792 push(@values,"$1:65535");
793 $check='on'
794 }
795 $errormessage .= &General::validportrange($_, 'destination');
796 if(!$check){
797 push (@values,$_);
798 }
799 }else{
800 if (&General::validport($_)){
801 push (@values,$_);
802 }else{
803
804 }
805 }
806 }
807 $fwdfwsettings{'TGT_PORT'}=join("|",@values);
808 }
809 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'GRE'){
810 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
811 $fwdfwsettings{'TGT_PORT'} = '';
812 $fwdfwsettings{'ICMP_TGT'} = '';
813 }elsif($fwdfwsettings{'TGT_PROT'} eq 'ESP'){
814 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
815 $fwdfwsettings{'TGT_PORT'} = '';
816 $fwdfwsettings{'ICMP_TGT'}='';
817 }elsif($fwdfwsettings{'TGT_PROT'} eq 'AH'){
818 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
819 $fwdfwsettings{'TGT_PORT'} = '';
820 $fwdfwsettings{'ICMP_TGT'}='';
821 }elsif ($fwdfwsettings{'TGT_PROT'} eq 'ICMP'){
822 $fwdfwsettings{$fwdfwsettings{'grp3'}} = '';
823 $fwdfwsettings{'TGT_PORT'} = '';
824 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
825 foreach my $key (keys %icmptypes){
826
827 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwdfwsettings{'ICMP_TGT'}){
828 $fwdfwsettings{'ICMP_TGT'}=$icmptypes{$key}[0];
829 }
830 }
831 }
832 }
833 }
834
835 #check targetport
836 if ($fwdfwsettings{'USESRV'} ne 'ON'){
837 $fwdfwsettings{'grp3'}='';
838 $fwdfwsettings{$fwdfwsettings{'grp3'}}='';
839 $fwdfwsettings{'TGT_PROT'}='';
840 $fwdfwsettings{'ICMP_TGT'}='';
841 }
842 #check timeframe
843 if($fwdfwsettings{'TIME'} eq 'ON'){
844 if($fwdfwsettings{'TIME_MON'} eq '' && $fwdfwsettings{'TIME_TUE'} eq '' && $fwdfwsettings{'TIME_WED'} eq '' && $fwdfwsettings{'TIME_THU'} eq '' && $fwdfwsettings{'TIME_FRI'} eq '' && $fwdfwsettings{'TIME_SAT'} eq '' && $fwdfwsettings{'TIME_SUN'} eq ''){
845 $errormessage=$Lang::tr{'fwdfw err time'};
846 }
847 }
848 return $errormessage;
849 }
850 sub checkrule
851 {
852 #check valid remark
853 if ($fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){
854 $errormessage.=$Lang::tr{'fwdfw err remark'}."<br>";
855 }
856 #check if source and target identical
857 if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ALL'){
858 $errormessage.=$Lang::tr{'fwdfw err same'};
859 return $errormessage;
860 }
861
862 #get source and targetip address if possible
863 my ($sip,$scidr,$tip,$tcidr);
864 ($sip,$scidr)=&get_ip("src","grp1");
865 ($tip,$tcidr)=&get_ip("tgt","grp2");
866
867 #check same iprange in source and target
868 if ($sip ne '' && $scidr ne '' && $tip ne '' && $tcidr ne ''){
869 my $networkip1=&General::getnetworkip($sip,$scidr);
870 my $networkip2=&General::getnetworkip($tip,$tcidr);
871 if ($scidr gt $tcidr){
872 if ( &General::IpInSubnet($networkip1,$tip,&General::iporsubtodec($tcidr))){
873 $errormessage.=$Lang::tr{'fwdfw err samesub'};
874 }
875 }elsif($scidr eq $tcidr && $scidr eq '32'){
876 my ($sbyte1,$sbyte2,$sbyte3,$sbyte4)=split(/\./,$networkip1);
877 my ($tbyte1,$tbyte2,$tbyte3,$tbyte4)=split(/\./,$networkip2);
878 if ($sbyte1 eq $tbyte1 && $sbyte2 eq $tbyte2 && $sbyte3 eq $tbyte3){
879 $hint=$Lang::tr{'fwdfw hint ip1'}."<br>";
880 $hint.=$Lang::tr{'fwdfw hint ip2'}." Source: $networkip1/$scidr Target: $networkip2/$tcidr<br>";
881 }
882 }else{
883 if ( &General::IpInSubnet($networkip2,$sip,&General::iporsubtodec($scidr)) ){
884 $errormessage.=$Lang::tr{'fwdfw err samesub'};
885 }
886 }
887 }
888
889 #check source and destination protocol if manual
890 if( $fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'USESRV'} eq 'ON'){
891 if($fwdfwsettings{'PROT'} ne $fwdfwsettings{'TGT_PROT'} && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
892 $errormessage.=$Lang::tr{'fwdfw err prot'};
893 }
894 #check source and destination protocol if source manual and dest servicegrp
895 if ($fwdfwsettings{'grp3'} eq 'cust_srv'){
896 &General::readhasharray("$configsrv", \%customservice);
897 foreach my $key (sort keys %customservice){
898 if($customservice{$key}[0] eq $fwdfwsettings{$fwdfwsettings{'grp3'}}){
899 if ($customservice{$key}[2] ne $fwdfwsettings{'PROT'}){
900 $errormessage.=$Lang::tr{'fwdfw err prot'};
901 last;
902 }
903 }
904 }
905 }
906 }
907 }
908 sub get_ip
909 {
910 my $val=shift;
911 my $grp =shift;
912 my $a;
913 my $b;
914 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
915 if ($fwdfwsettings{$grp} ne $Lang::tr{'fwhost any'}){
916 if ($fwdfwsettings{$grp} eq $val.'_addr'){
917 ($a,$b) = split (/\//, $fwdfwsettings{$fwdfwsettings{$grp}});
918 }elsif($fwdfwsettings{$grp} eq 'std_net_'.$val){
919 if ($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Gr/i){
920 $a=$netsettings{'GREEN_NETADDRESS'};
921 $b=&General::iporsubtocidr($netsettings{'GREEN_NETMASK'});
922 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Ora/i){
923 $a=$netsettings{'ORANGE_NETADDRESS'};
924 $b=&General::iporsubtocidr($netsettings{'ORANGE_NETMASK'});
925 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Bl/i){
926 $a=$netsettings{'BLUE_NETADDRESS'};
927 $b=&General::iporsubtocidr($netsettings{'BLUE_NETMASK'});
928 }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /OpenVPN/i){
929 &General::readhash("$configovpn",\%ovpnsettings);
930 ($a,$b) = split (/\//, $ovpnsettings{'DOVPN_SUBNET'});
931 $b=&General::iporsubtocidr($b);
932 }
933 }elsif($fwdfwsettings{$grp} eq 'cust_net_'.$val){
934 &General::readhasharray("$confignet", \%customnetwork);
935 foreach my $key (keys %customnetwork){
936 if($customnetwork{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
937 $a=$customnetwork{$key}[1];
938 $b=&General::iporsubtocidr($customnetwork{$key}[2]);
939 }
940 }
941 }elsif($fwdfwsettings{$grp} eq 'cust_host_'.$val){
942 &General::readhasharray("$confighost", \%customhost);
943 foreach my $key (keys %customhost){
944 if($customhost{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){
945 if ($customhost{$key}[1] eq 'ip'){
946 ($a,$b)=split (/\//,$customhost{$key}[2]);
947 $b=&General::iporsubtocidr($b);
948 }else{
949 if ($grp eq 'grp2'){
950 $errormessage=$Lang::tr{'fwdfw err tgt_mac'};
951 }
952 }
953 }
954 }
955 }
956 }
957 return $a,$b;
958 }
959 sub newrule
960 {
961 &error;
962 &General::setup_default_networks(\%defaultNetworks);
963 #read all configfiles
964 &General::readhasharray("$configccdnet", \%ccdnet);
965 &General::readhasharray("$confignet", \%customnetwork);
966 &General::readhasharray("$configccdhost", \%ccdhost);
967 &General::readhasharray("$confighost", \%customhost);
968 &General::readhasharray("$configccdhost", \%ccdhost);
969 &General::readhasharray("$configgrp", \%customgrp);
970 &General::readhasharray("$configipsec", \%ipsecconf);
971 &General::get_aliases(\%aliases);
972 my %checked=();
973 my $helper;
974 my $sum=0;
975 if($fwdfwsettings{'config'} eq ''){$fwdfwsettings{'config'}=$configfwdfw;}
976 my $config=$fwdfwsettings{'config'};
977 my %hash=();
978 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
979 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
980 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
981 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
982 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
983 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
984 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
985 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
986 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
987 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
988 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
989 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
990 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
991 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
992 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
993 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
994 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
995 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
996 #check if update and get values
997 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on' && !$errormessage){
998 &General::readhasharray("$config", \%hash);
999 foreach my $key (sort keys %hash){
1000 $sum++;
1001 if ($key eq $fwdfwsettings{'key'}){
1002 $fwdfwsettings{'oldrulenumber'} = $fwdfwsettings{'key'};
1003 $fwdfwsettings{'RULE_ACTION'} = $hash{$key}[0];
1004 $fwdfwsettings{'ACTIVE'} = $hash{$key}[2];
1005 $fwdfwsettings{'grp1'} = $hash{$key}[3];
1006 $fwdfwsettings{$fwdfwsettings{'grp1'}} = $hash{$key}[4];
1007 $fwdfwsettings{'grp2'} = $hash{$key}[5];
1008 $fwdfwsettings{$fwdfwsettings{'grp2'}} = $hash{$key}[6];
1009 $fwdfwsettings{'USE_SRC_PORT'} = $hash{$key}[7];
1010 $fwdfwsettings{'PROT'} = $hash{$key}[8];
1011 $fwdfwsettings{'ICMP_TYPES'} = $hash{$key}[9];
1012 $fwdfwsettings{'SRC_PORT'} = $hash{$key}[10];
1013 $fwdfwsettings{'USESRV'} = $hash{$key}[11];
1014 $fwdfwsettings{'TGT_PROT'} = $hash{$key}[12];
1015 $fwdfwsettings{'ICMP_TGT'} = $hash{$key}[13];
1016 $fwdfwsettings{'grp3'} = $hash{$key}[14];
1017 $fwdfwsettings{$fwdfwsettings{'grp3'}} = $hash{$key}[15];
1018 $fwdfwsettings{'ruleremark'} = $hash{$key}[16];
1019 $fwdfwsettings{'LOG'} = $hash{$key}[17];
1020 $fwdfwsettings{'TIME'} = $hash{$key}[18];
1021 $fwdfwsettings{'TIME_MON'} = $hash{$key}[19];
1022 $fwdfwsettings{'TIME_TUE'} = $hash{$key}[20];
1023 $fwdfwsettings{'TIME_WED'} = $hash{$key}[21];
1024 $fwdfwsettings{'TIME_THU'} = $hash{$key}[22];
1025 $fwdfwsettings{'TIME_FRI'} = $hash{$key}[23];
1026 $fwdfwsettings{'TIME_SAT'} = $hash{$key}[24];
1027 $fwdfwsettings{'TIME_SUN'} = $hash{$key}[25];
1028 $fwdfwsettings{'TIME_FROM'} = $hash{$key}[26];
1029 $fwdfwsettings{'TIME_TO'} = $hash{$key}[27];
1030 $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED';
1031 $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED';
1032 $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED';
1033 $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED';
1034 $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED';
1035 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1036 $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED';
1037 $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED';
1038 $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED';
1039 $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED';
1040 $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED';
1041 $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED';
1042 $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED';
1043 $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED';
1044 $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED';
1045 $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected';
1046 $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected';
1047 $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected';
1048 }
1049 }
1050 $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'};
1051 $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}};
1052 $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'};
1053 $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}};
1054 $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'};
1055 $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}};
1056 $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'};
1057 $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'};
1058 }else{
1059 $fwdfwsettings{'ACTIVE'}='ON';
1060 $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED';
1061 }
1062
1063 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'});
1064
1065 print <<END;
1066 <form method="post">
1067 <table border='0'>
1068 <tr><td nowrap>$Lang::tr{'fwdfw rule action'}</td><td><select name='RULE_ACTION'>
1069 END
1070 foreach ("ACCEPT","DROP","REJECT")
1071 {
1072 if($fwdfwsettings{'updatefwrule'} eq 'on'){
1073 print"<option ";
1074 print "selected='selected'" if ($fwdfwsettings{'RULE_ACTION'} eq $_);
1075 print">$_</option>";
1076 }else{
1077 if($fwdfwsettings{'POLICY'} eq 'MODE2'){
1078 $fwdfwsettings{'RULE_ACTION'} = 'DROP';
1079 }
1080
1081 if ($_ eq $fwdfwsettings{'RULE_ACTION'})
1082 {
1083 print"<option selected>$_</option>";
1084 }else{
1085 print"<option>$_</option>";
1086 }
1087 }
1088 }
1089 print"</select></td></tr></table><hr>";
1090
1091 &Header::closebox();
1092 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw source'});
1093 #------SOURCE-------------------------------------------------------
1094 print<<END;
1095 <table width='100%' border='0'>
1096 <tr><td width='1%'><input type='radio' name='grp1' value='src_addr' checked></td><td colspan='5'>$Lang::tr{'fwdfw sourceip'}<input type='TEXT' name='src_addr' value='$fwdfwsettings{'src_addr'}' ></td></tr>
1097 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr>
1098 <tr><td width='1%'><input type='radio' name='grp1' value='std_net_src' $checked{'grp1'}{'std_net_src'}></td><td nowrap='nowrap' width='12%'>$Lang::tr{'fwhost stdnet'}</td><td width='13%'><select name='std_net_src' style='min-width:185px;'>
1099 END
1100 foreach my $network (sort keys %defaultNetworks)
1101 {
1102 next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP");
1103 next if($defaultNetworks{$network}{'NAME'} eq "RED");
1104 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1105 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $defaultNetworks{$network}{'NAME'});
1106 print ">$network</option>";
1107 }
1108 print<<END;
1109 </select></td><td width='1%'><input type='radio' name='grp1' value='ovpn_net_src' $checked{'grp1'}{'ovpn_net_src'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_net_src' style='min-width:185px;'>
1110 END
1111 &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{'grp1'}});
1112 print<<END;
1113 </select></td></tr>
1114 <tr><td><input type='radio' name='grp1' value='cust_net_src' $checked{'grp1'}{'cust_net_src'}></td><td>$Lang::tr{'fwhost cust net'}</td><td><select name='cust_net_src' style='min-width:185px;'>
1115 END
1116 &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{'grp1'}});
1117 print<<END;
1118 </select></td><td width='1%'><input type='radio' name='grp1' value='ovpn_host_src' $checked{'grp1'}{'ovpn_host_src'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_host_src' style='min-width:185px;'>
1119 END
1120 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost)
1121 {
1122 if ($ccdhost{$key}[33] ne ''){
1123
1124 print "<option value='$ccdhost{$key}[1]'";
1125 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ccdhost{$key}[1]);
1126 print ">$ccdhost{$key}[1]</option>";
1127 }
1128 }
1129 print<<END;
1130 </select></td></tr>
1131 <tr><td valign='top'><input type='radio' name='grp1' value='cust_host_src' $checked{'grp1'}{'cust_host_src'}></td><td>$Lang::tr{'fwhost cust addr'}</td><td><select name='cust_host_src' style='min-width:185px;'>
1132 END
1133 &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{'grp1'}});
1134 print<<END;
1135 </select></td><td width='1%'><input type='radio' name='grp1' value='ovpn_n2n_src' $checked{'grp1'}{'ovpn_n2n_src'}></td><td >$Lang::tr{'fwhost ovpn_n2n'}</td><td colspan='3'><select name='ovpn_n2n_src' style='min-width:185px;'>
1136 END
1137 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) {
1138 if($ccdhost{$key}[3] eq 'net'){
1139 print"<option ";
1140 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ccdhost{$key}[1]);
1141 print ">$ccdhost{$key}[1]</option>";
1142 }
1143 }
1144 print<<END;
1145 </select></td></tr>
1146
1147 <tr><td valign='top'><input type='radio' name='grp1' value='cust_grp_src' $checked{'grp1'}{'cust_grp_src'}></td><td >$Lang::tr{'fwhost cust grp'}</td><td><select name='cust_grp_src' style='min-width:185px;'>
1148 END
1149 foreach my $key (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } keys %customgrp) {
1150 if($helper ne $customgrp{$key}[0]){
1151 print"<option ";
1152 print "selected='selected' " if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $customgrp{$key}[0]);
1153 print ">$customgrp{$key}[0]</option>";
1154 }
1155 $helper=$customgrp{$key}[0];
1156 }
1157 print<<END;
1158 </select></td>
1159 <td valign='top'><input type='radio' name='grp1' value='ipsec_net_src' $checked{'grp1'}{'ipsec_net_src'}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td><select name='ipsec_net_src' style='min-width:185px;'>
1160 END
1161 foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1162 if ($ipsecconf{$key}[3] eq 'net'){
1163 print "<option ";
1164 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ipsecconf{$key}[1]);
1165 print ">$ipsecconf{$key}[1]</option>";
1166 }
1167 }
1168 #sourceport
1169 print<<END;
1170 </select></td></tr>
1171 END
1172
1173 # <td valign='top'><input type='radio' name='grp1' value='ipsec_host_src' $checked{'grp1'}{'ipsec_host_src'}></td><td >$Lang::tr{'fwhost ipsec host'}</td><td><select name='ipsec_host_src' style='min-width:185px;'>
1174 #END
1175 # foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1176 # if ($ipsecconf{$key}[3] eq 'host'){
1177 # print "<option ";
1178 # print "selected='selected'" if($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ipsecconf{$key}[1]);
1179 # print ">$ipsecconf{$key}[1]</option>";
1180 # }
1181 # }
1182 print<<END;
1183 <tr><td colspan='8'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table>
1184 <table width='100%' border='0'>
1185 <tr><td width='1%'><input type='checkbox' name='USE_SRC_PORT' value='ON' $checked{'USE_SRC_PORT'}{'ON'}></td><td width='51%' colspan='3'>$Lang::tr{'fwdfw use srcport'}</td>
1186 <td width='15%' nowrap='nowrap'>$Lang::tr{'fwdfw man port'}</td><td><select name='PROT'>
1187 END
1188 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
1189 {
1190 if ($_ eq $fwdfwsettings{'PROT'})
1191 {
1192 print"<option selected>$_</option>";
1193 }else{
1194 print"<option>$_</option>";
1195 }
1196 }
1197 $fwdfwsettings{'SRC_PORT'}=~ s/\|/,/g;
1198 print<<END;
1199 </select></td><td align='right'><input type='text' name='SRC_PORT' value='$fwdfwsettings{'SRC_PORT'}' maxlength='20' size='18' ></td></tr>
1200 <tr><td></td><td></td><td></td><td></td><td nowrap='nowrap'>$Lang::tr{'fwhost icmptype'}</td><td colspan='2'><select name='ICMP_TYPES'>
1201 END
1202 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1203 print"<option>All ICMP-Types</option>";
1204 foreach my $key (sort { uc($icmptypes{$a}[0]) cmp uc($icmptypes{$b}[0]) } keys %icmptypes){
1205 if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0]"){
1206 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1207 }else{
1208 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1209 }
1210 }
1211 print<<END;
1212 </select></td></tr></table><hr>
1213 END
1214 &Header::closebox();
1215
1216 #---TARGET------------------------------------------------------
1217 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw target'});
1218 print<<END;
1219 <table width='100%' border='0'>
1220 <tr><td width='1%'><input type='radio' name='grp2' value='tgt_addr' checked></td><td colspan='2'>$Lang::tr{'fwdfw targetip'}<input type='TEXT' name='tgt_addr' value='$fwdfwsettings{'tgt_addr'}' size='16'><td><input type='radio' name='grp2' value='ipfire' $checked{'grp2'}{'ipfire'}></td><td><b>IPFire ($Lang::tr{'external access'})</b></td><td><select name='ipfire' style='min-width:185px;'>
1221 END
1222 print "<option value='Default IP' $selected{'ipfire'}{'Default IP'}>Default IP</option>";
1223
1224 foreach my $alias (sort keys %aliases)
1225 {
1226 print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias</option>";
1227 }
1228
1229 print<<END;
1230 </td></tr>
1231 <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr>
1232 <tr><td width='1%'><input type='radio' name='grp2' value='std_net_tgt' $checked{'grp2'}{'std_net_tgt'}></td><td nowrap='nowrap' width='12%'>$Lang::tr{'fwhost stdnet'}</td><td width='13%'><select name='std_net_tgt' style='min-width:185px;'>
1233 END
1234 foreach my $network (sort keys %defaultNetworks)
1235 {
1236 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1237 print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $defaultNetworks{$network}{'NAME'});
1238 print ">$network</option>";
1239 }
1240 print<<END;
1241 </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_net_tgt' $checked{'grp2'}{'ovpn_net_tgt'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_net_tgt' style='min-width:185px;'>
1242 END
1243 &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{'grp2'}});
1244 print<<END;
1245 </select></td></tr>
1246 <tr><td><input type='radio' name='grp2' value='cust_net_tgt' $checked{'grp2'}{'cust_net_tgt'}></td><td>$Lang::tr{'fwhost cust net'}</td><td><select name='cust_net_tgt' style='min-width:185px;'>
1247 END
1248 &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{'grp2'}});
1249 print<<END;
1250 </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_host_tgt' $checked{'grp2'}{'ovpn_host_tgt'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_host_tgt' style='min-width:185px;'>
1251 END
1252 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost)
1253 {
1254 if ($ccdhost{$key}[33] ne ''){
1255 print "<option value='$ccdhost{$key}[1]' ";
1256 print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ccdhost{$key}[33]);
1257 print ">$ccdhost{$key}[1]</option>";
1258 }
1259 }
1260 print<<END;
1261 </select></td></tr>
1262 <tr><td valign='top'><input type='radio' name='grp2' value='cust_host_tgt' $checked{'grp2'}{'cust_host_tgt'}></td><td>$Lang::tr{'fwhost cust addr'}</td><td><select name='cust_host_tgt' style='min-width:185px;'>
1263 END
1264 &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{'grp2'}});
1265 print<<END;
1266 </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_n2n_tgt' $checked{'grp2'}{'ovpn_n2n_tgt'}></td><td >$Lang::tr{'fwhost ovpn_n2n'}</td><td colspan='3'><select name='ovpn_n2n_tgt' style='min-width:185px;'>
1267 END
1268 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) {
1269 if($ccdhost{$key}[3] eq 'net'){
1270 print "<option ";
1271 print "selected='selected'" if($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ccdhost{$key}[1]);
1272 print ">$ccdhost{$key}[1]</option>";
1273 }
1274 }
1275 print<<END;
1276 </select></td></tr>
1277 <tr><td valign='top'><input type='radio' name='grp2' value='cust_grp_tgt' $checked{'grp2'}{'cust_grp_tgt'}></td><td >$Lang::tr{'fwhost cust grp'}</td><td><select name='cust_grp_tgt' style='min-width:185px;'>
1278 END
1279 $helper='';
1280 foreach my $key (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } keys %customgrp) {
1281 if($helper ne $customgrp{$key}[0]){
1282 print"<option ";
1283 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $customgrp{$key}[0]);
1284 print">$customgrp{$key}[0]</option>";
1285 }
1286 $helper=$customgrp{$key}[0];
1287 }
1288 print<<END;
1289 </select></td>
1290 <td valign='top'><input type='radio' name='grp2' value='ipsec_net_tgt' $checked{'grp2'}{'ipsec_net_tgt'}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td><select name='ipsec_net_tgt' style='min-width:185px;'>
1291 END
1292 foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1293 if ($ipsecconf{$key}[3] eq 'net'){
1294 print"<option ";
1295 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ipsecconf{$key}[1]);
1296 print">$ipsecconf{$key}[1]</option>";
1297 }
1298 }
1299 print<<END;
1300 </select></td></tr>
1301 END
1302 # <td valign='top'><input type='radio' name='grp2' value='ipsec_host_tgt' $checked{'grp2'}{'ipsec_host_tgt'}></td><td >$Lang::tr{'fwhost ipsec host'}</td><td><select name='ipsec_host_tgt' style='min-width:185px;'>
1303 #END
1304 # foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) {
1305 # if ($ipsecconf{$key}[3] eq 'host'){
1306 # print"<option ";
1307 # print"selected='Selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ipsecconf{$key}[1]);
1308 # print">$ipsecconf{$key}[1]</option>";
1309 # }
1310 # }
1311 print<<END;
1312 </table>
1313 <b>$Lang::tr{'fwhost attention'}:</b><br>
1314 $Lang::tr{'fwhost macwarn'}<br><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; '></hr><br>
1315
1316 <table width='100%' border='0'>
1317 <tr><td width='1%'><input type='checkbox' name='USESRV' value='ON' $checked{'USESRV'}{'ON'} ></td><td width='48%'>$Lang::tr{'fwdfw use srv'}</td><td width='1%'><input type='radio' name='grp3' value='cust_srv' checked></td><td nowrap='nowrap'>$Lang::tr{'fwhost cust service'}</td><td width='1%' colspan='2'><select name='cust_srv'style='min-width:230px;' >
1318 END
1319 &General::readhasharray("$configsrv", \%customservice);
1320 foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
1321 print"<option ";
1322 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]);
1323 print"value='$customservice{$key}[0]'>$customservice{$key}[0]</option>";
1324 }
1325 print<<END;
1326 </select></td></tr>
1327 <tr><td colspan='2'></td><td><input type='radio' name='grp3' value='cust_srvgrp' $checked{'grp3'}{'cust_srvgrp'}></td><td nowrap='nowrap'>$Lang::tr{'fwhost cust srvgrp'}:</td><td colspan='2'><select name='cust_srvgrp'style='min-width:230px;' >
1328 END
1329 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1330 my $helper;
1331 foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0]) } keys %customservicegrp){
1332 if ($helper ne $customservicegrp{$key}[0]){
1333 print"<option ";
1334 print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservicegrp{$key}[0]);
1335 print">$customservicegrp{$key}[0]</option>";
1336 }
1337 $helper=$customservicegrp{$key}[0];
1338 }
1339 print<<END;
1340 </select></td></tr>
1341 <tr><td colspan='2'></td><td><input type='radio' name='grp3' value='TGT_PORT' $checked{'grp3'}{'TGT_PORT'}></td><td>$Lang::tr{'fwdfw man port'}</td><td><select name='TGT_PROT'>
1342 END
1343 foreach ("TCP","UDP","GRE","ESP","AH","ICMP")
1344 {
1345 if ($_ eq $fwdfwsettings{'TGT_PROT'})
1346 {
1347 print"<option selected>$_</option>";
1348 }else{
1349 print"<option>$_</option>";
1350 }
1351 }
1352 $fwdfwsettings{'TGT_PORT'} =~ s/\|/,/g;
1353 print<<END;
1354 </select></td><td align='right'><input type='text' name='TGT_PORT' value='$fwdfwsettings{'TGT_PORT'}' maxlength='20' size='18' ></td></tr>
1355 <tr><td colspan='2'></td><td></td><td>$Lang::tr{'fwhost icmptype'}</td><td colspan='2'><select name='ICMP_TGT'>
1356 END
1357 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1358 print"<option>All ICMP-Types</option>";
1359 foreach my $key (sort { uc($icmptypes{$a}[0]) cmp uc($icmptypes{$b}[0]) }keys %icmptypes){
1360 if($fwdfwsettings{'ICMP_TGT'} eq "$icmptypes{$key}[0]"){
1361 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1362 }else{
1363 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1364 }
1365 }
1366 print<<END;
1367 </select></td></tr>
1368 </table><hr><br><br>
1369
1370 END
1371 #---Activate/logging/remark-------------------------------------
1372 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw additional'});
1373 print<<END;
1374 <table width='100%' border='0'>
1375 <tr><td width='12%'>$Lang::tr{'remark'}:</td><td align='left'><input type='text' name='ruleremark' size='40' maxlength='255' value='$fwdfwsettings{'ruleremark'}'></td></tr>
1376 END
1377 if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on'){
1378 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><select name='rulepos' >";
1379 for (my $count =1; $count <= $sum; $count++){
1380 print"<option value='$count' ";
1381 print"selected='selected'" if($fwdfwsettings{'oldrulenumber'} eq $count);
1382 print">$count</option>";
1383 }
1384 print"</select></td></tr>";
1385 }else{
1386 print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><input type='text' name='rulepos' size='2'></td></tr>";
1387 }
1388
1389 print<<END;
1390 </table><table width='100%'>
1391 <tr><td width='1%'><input type='checkbox' name='ACTIVE' value='ON' $checked{'ACTIVE'}{'ON'}></td><td>$Lang::tr{'fwdfw rule activate'}</td></tr>
1392 <tr><td width='1%'><input type='checkbox' name='LOG' value='ON' $checked{'LOG'}{'ON'} ></td><td>$Lang::tr{'fwdfw log rule'}</td></tr>
1393 </table><hr><br>
1394 END
1395 &Header::closebox();
1396 #---ADD TIMEFRAME-----------------------------------------------
1397 &Header::openbox('100%', 'left', $Lang::tr{'fwdfw timeframe'});
1398 print<<END;
1399 <table width='70%' border='0'>
1400 <tr><td width='1%'><input type='checkbox' name='TIME' value='ON' $checked{'TIME'}{'ON'}></td><td colspan='4'>$Lang::tr{'fwdfw timeframe'}</td></tr>
1401 <tr><td colspan='7'>&nbsp</td></tr>
1402 <tr>
1403 <td align='left'>$Lang::tr{'time'}:</td>
1404 <td width='30%' align='left'>$Lang::tr{'advproxy monday'} $Lang::tr{'advproxy tuesday'} $Lang::tr{'advproxy wednesday'} $Lang::tr{'advproxy thursday'} $Lang::tr{'advproxy friday'} $Lang::tr{'advproxy saturday'} $Lang::tr{'advproxy sunday'}</td>
1405 <td width='15%' align='left'>$Lang::tr{'advproxy from'}</td>
1406 <td width='15%' align='left'>$Lang::tr{'advproxy to'}</td>
1407 </tr>
1408 <tr>
1409 <td align='right'></td>
1410 <td width='30%' align='left'>
1411 <input type='checkbox' name='TIME_MON' value='on' $checked{'TIME_MON'}{'on'} />
1412 <input type='checkbox' name='TIME_TUE' value='on' $checked{'TIME_TUE'}{'on'} />
1413 <input type='checkbox' name='TIME_WED' value='on' $checked{'TIME_WED'}{'on'} />
1414 <input type='checkbox' name='TIME_THU' value='on' $checked{'TIME_THU'}{'on'} />
1415 <input type='checkbox' name='TIME_FRI' value='on' $checked{'TIME_FRI'}{'on'} />
1416 <input type='checkbox' name='TIME_SAT' value='on' $checked{'TIME_SAT'}{'on'} />
1417 <input type='checkbox' name='TIME_SUN' value='on' $checked{'TIME_SUN'}{'on'} />
1418 </td>
1419 <td><select name='TIME_FROM'>
1420 END
1421 for (my $i=0;$i<=23;$i++) {
1422 $i = sprintf("%02s",$i);
1423 for (my $j=0;$j<=45;$j+=15) {
1424 $j = sprintf("%02s",$j);
1425 my $time = $i.":".$j;
1426 print "\t\t\t\t\t<option $selected{'TIME_FROM'}{$time}>$i:$j</option>\n";
1427 }
1428 }
1429 print<<END;
1430 </select></td>
1431 <td><select name='TIME_TO'>
1432 END
1433 for (my $i=0;$i<=23;$i++) {
1434 $i = sprintf("%02s",$i);
1435 for (my $j=0;$j<=45;$j+=15) {
1436 $j = sprintf("%02s",$j);
1437 my $time = $i.":".$j;
1438 print "\t\t\t\t\t<option $selected{'TIME_TO'}{$time}>$i:$j</option>\n";
1439 }
1440 }
1441 print<<END;
1442 </select></td></tr>
1443 </table><hr>
1444 END
1445 &Header::closebox();
1446 #---ACTION------------------------------------------------------
1447 if($fwdfwsettings{'updatefwrule'} ne 'on'){
1448 print<<END;
1449 <table border='0' width='100%'>
1450 <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' />
1451 <input type='hidden' name='config' value='$config' >
1452 <input type='hidden' name='ACTION' value='saverule' >
1453 </form><form method='post' style='display:inline'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'><input type='hidden' name='ACTION' value'reset'></td></td>
1454 </table></form>
1455 END
1456 }else{
1457 print<<END;
1458 <table border='0' width='100%'>
1459 <tr><td align='right'><input type='submit' value='$Lang::tr{'fwdfw change'}' style='min-width:100px;' /><input type='hidden' name='updatefwrule' value='$fwdfwsettings{'updatefwrule'}'><input type='hidden' name='key' value='$fwdfwsettings{'key'}'>
1460 <input type='hidden' name='oldgrp1a' value='$fwdfwsettings{'oldgrp1a'}' />
1461 <input type='hidden' name='oldgrp1b' value='$fwdfwsettings{'oldgrp1b'}' />
1462 <input type='hidden' name='oldgrp2a' value='$fwdfwsettings{'oldgrp2a'}' />
1463 <input type='hidden' name='oldgrp2b' value='$fwdfwsettings{'oldgrp2b'}' />
1464 <input type='hidden' name='oldgrp3a' value='$fwdfwsettings{'oldgrp3a'}' />
1465 <input type='hidden' name='oldgrp3b' value='$fwdfwsettings{'oldgrp3b'}' />
1466 <input type='hidden' name='oldusesrv' value='$fwdfwsettings{'oldusesrv'}' />
1467 <input type='hidden' name='oldrulenumber' value='$fwdfwsettings{'oldrulenumber'}' />
1468 <input type='hidden' name='rulenumber' value='$fwdfwsettings{'rulepos'}' />
1469 <input type='hidden' name='oldruleremark' value='$fwdfwsettings{'oldruleremark'}' />
1470 <input type='hidden' name='ACTION' value='saverule' ></form><form method='post' style='display:inline'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'><input type='hidden' name='ACTION' value'reset'></td></td>
1471 </table></form>
1472 END
1473 }
1474 &Header::closebox();
1475 }
1476 sub saverule
1477 {
1478 my $hash=shift;
1479 my $config=shift;
1480 &General::readhasharray("$config", $hash);
1481 if (!$errormessage){
1482 if ($fwdfwsettings{'updatefwrule'} ne 'on'){
1483 my $key = &General::findhasharraykey ($hash);
1484 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
1485 $$hash{$key}[1] = $fwdfwsettings{'chain'};
1486 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
1487 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
1488 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
1489 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
1490 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
1491 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
1492 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
1493 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
1494 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
1495 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
1496 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
1497 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
1498 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
1499 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
1500 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
1501 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
1502 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
1503 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
1504 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
1505 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
1506 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
1507 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
1508 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
1509 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
1510 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
1511 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
1512 &General::writehasharray("$config", $hash);
1513 }else{
1514 foreach my $key (sort {$a <=> $b} keys %$hash){
1515 if($key eq $fwdfwsettings{'key'}){
1516 $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'};
1517 $$hash{$key}[1] = $fwdfwsettings{'chain'};
1518 $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'};
1519 $$hash{$key}[3] = $fwdfwsettings{'grp1'};
1520 $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}};
1521 $$hash{$key}[5] = $fwdfwsettings{'grp2'};
1522 $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}};
1523 $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'};
1524 $$hash{$key}[8] = $fwdfwsettings{'PROT'};
1525 $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'};
1526 $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'};
1527 $$hash{$key}[11] = $fwdfwsettings{'USESRV'};
1528 $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'};
1529 $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'};
1530 $$hash{$key}[14] = $fwdfwsettings{'grp3'};
1531 $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}};
1532 $$hash{$key}[16] = $fwdfwsettings{'ruleremark'};
1533 $$hash{$key}[17] = $fwdfwsettings{'LOG'};
1534 $$hash{$key}[18] = $fwdfwsettings{'TIME'};
1535 $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'};
1536 $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'};
1537 $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'};
1538 $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'};
1539 $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'};
1540 $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'};
1541 $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'};
1542 $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'};
1543 $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'};
1544 last;
1545 }
1546 }
1547 }
1548 &General::writehasharray("$config", $hash);
1549 if($fwdfwsettings{'oldrulenumber'} > $fwdfwsettings{'rulepos'}){
1550 my %tmp=();
1551 my $val=$fwdfwsettings{'oldrulenumber'}-$fwdfwsettings{'rulepos'};
1552 for (my $z=0;$z<$val;$z++){
1553 foreach my $key (sort {$a <=> $b} keys %$hash){
1554 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
1555 my $last = $key -1;
1556 if (exists $$hash{$last}){
1557 #save rule last
1558 foreach my $y (0 .. $#{$$hash{$last}}) {
1559 $tmp{0}[$y] = $$hash{$last}[$y];
1560 }
1561 #copy active rule to last
1562 foreach my $i (0 .. $#{$$hash{$last}}) {
1563 $$hash{$last}[$i] = $$hash{$key}[$i];
1564 }
1565 #copy saved rule to actual position
1566 foreach my $x (0 .. $#{$tmp{0}}) {
1567 $$hash{$key}[$x] = $tmp{0}[$x];
1568 }
1569 }
1570 }
1571 }
1572 $fwdfwsettings{'oldrulenumber'}--;
1573 }
1574 &General::writehasharray("$config", $hash);
1575 &rules;
1576 }elsif($fwdfwsettings{'rulepos'} > $fwdfwsettings{'oldrulenumber'}){
1577 my %tmp=();
1578 my $val=$fwdfwsettings{'rulepos'}-$fwdfwsettings{'oldrulenumber'};
1579 for (my $z=0;$z<$val;$z++){
1580 foreach my $key (sort {$a <=> $b} keys %$hash){
1581 if ($key eq $fwdfwsettings{'oldrulenumber'}) {
1582 my $next = $key + 1;
1583 if (exists $$hash{$next}){
1584 #save rule next
1585 foreach my $y (0 .. $#{$$hash{$next}}) {
1586 $tmp{0}[$y] = $$hash{$next}[$y];
1587 }
1588 #copy active rule to next
1589 foreach my $i (0 .. $#{$$hash{$next}}) {
1590 $$hash{$next}[$i] = $$hash{$key}[$i];
1591 }
1592 #copy saved rule to actual position
1593 foreach my $x (0 .. $#{$tmp{0}}) {
1594 $$hash{$key}[$x] = $tmp{0}[$x];
1595 }
1596 }
1597 }
1598 }
1599 $fwdfwsettings{'oldrulenumber'}++;
1600 }
1601 &General::writehasharray("$config", $hash);
1602 &rules;
1603 }
1604 }
1605 }
1606 sub error
1607 {
1608 if ($errormessage) {
1609 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1610 print "<class name='base'>$errormessage\n";
1611 print "&nbsp;</class>\n";
1612 &Header::closebox();
1613 print"<hr>";
1614 }
1615 }
1616 sub hint
1617 {
1618 if ($hint) {
1619 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
1620 print "<class name='base'>$hint\n";
1621 print "&nbsp;</class>\n";
1622 &Header::closebox();
1623 print"<hr>";
1624 }
1625 }
1626 sub get_name
1627 {
1628 my $val=shift;
1629 &General::setup_default_networks(\%defaultNetworks);
1630 foreach my $network (sort keys %defaultNetworks)
1631 {
1632 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1633 }
1634 }
1635 sub validremark
1636 {
1637 # Checks a hostname against RFC1035
1638 my $remark = $_[0];
1639
1640 # Each part should be at least two characters in length
1641 # but no more than 63 characters
1642 if (length ($remark) < 1 || length ($remark) > 255) {
1643 return 0;}
1644 # Only valid characters are a-z, A-Z, 0-9 and -
1645 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:_\/\s]*$/) {
1646 return 0;}
1647 # First character can only be a letter or a digit
1648 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
1649 return 0;}
1650 # Last character can only be a letter or a digit
1651 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.]*$/) {
1652 return 0;}
1653 return 1;
1654 }
1655 sub getsrcport
1656 {
1657 my %hash=%{(shift)};
1658 my $key=shift;
1659 if($hash{$key}[7] eq 'ON' && $hash{$key}[8] ne '' && $hash{$key}[10]){
1660 $hash{$key}[10]=~ s/\|/,/g;
1661 print": $hash{$key}[10]";
1662 }elsif($hash{$key}[7] eq 'ON' && $hash{$key}[8] eq 'ICMP'){
1663 print": <br>$hash{$key}[9] ";
1664 }
1665 }
1666 sub gettgtport
1667 {
1668 my %hash=%{(shift)};
1669 my $key=shift;
1670 my $service;
1671 my $prot;
1672 if($hash{$key}[11] eq 'ON' && $hash{$key}[12] ne 'ICMP'){
1673 if($hash{$key}[14] eq 'cust_srv'){
1674 &General::readhasharray("$configsrv", \%customservice);
1675 foreach my $i (sort keys %customservice){
1676 if($customservice{$i}[0] eq $hash{$key}[15]){
1677 $service = $customservice{$i}[0];
1678 }
1679 }
1680 }elsif($hash{$key}[14] eq 'cust_srvgrp'){
1681 $service=$hash{$key}[15];
1682 }elsif($hash{$key}[14] eq 'TGT_PORT'){
1683 $hash{$key}[15]=~ s/\|/,/g;
1684 $service=$hash{$key}[15];
1685 }
1686 if($service){
1687 print": $service";
1688 }
1689 }elsif($hash{$key}[11] eq 'ON' && $hash{$key}[12] eq 'ICMP'){
1690 print":<br>$hash{$key}[13]";
1691 }
1692 }
1693 sub get_serviceports
1694 {
1695 my $type=shift;
1696 my $name=shift;
1697 &General::readhasharray("$configsrv", \%customservice);
1698 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1699 my $protocols;
1700 my $tcp;
1701 my $udp;
1702 if($type eq 'service'){
1703 foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
1704 if ($customservice{$key}[0] eq $name){
1705 $protocols=$customservice{$key}[2];
1706 }
1707 }
1708 }elsif($type eq 'group'){
1709 foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0]) } keys %customservicegrp){
1710 if ($customservicegrp{$key}[0] eq $name){
1711 foreach my $key1 (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){
1712 if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
1713 if($customservice{$key1}[2] eq 'TCP'){$tcp='TCP';}else{$udp='UDP';}
1714 }
1715 }
1716 }
1717 }
1718 }
1719 if($tcp && $udp){$protocols="TCP,UDP";
1720 }elsif($tcp){$protocols.="TCP";
1721 }elsif($udp){$protocols.="UDP";}
1722 return $protocols;
1723 }
1724 sub viewtablerule
1725 {
1726
1727 &viewtablenew(\%configfwdfw,$configfwdfw,$Lang::tr{'fwdfw rules'},"Forward" );
1728 &viewtablenew(\%configfwdfw,$configfwdfw,'',"DMZ" );
1729 &viewtablenew(\%configfwdfw,$configfwdfw,'',"WLAN" );
1730 &viewtablenew(\%configinputfw,$configinput,"",$Lang::tr{'external access'} );
1731 }
1732 sub viewtablenew
1733 {
1734 my $hash=shift;
1735 my $config=shift;
1736 my $title=shift;
1737 my $title1=shift;
1738 my $go='';
1739 &General::readhasharray("$config", $hash);
1740 #check if there are DMZ entries
1741 if ($title1 eq 'DMZ'){
1742 foreach my $key (keys %$hash){
1743 if ($$hash{$key}[4] eq 'ORANGE'){$go='on';last}
1744 }
1745 }elsif($title1 eq 'WLAN'){
1746 foreach my $key (keys %$hash){
1747 if ($$hash{$key}[4] eq 'BLUE'){$go='on';last}
1748 }
1749 }elsif($title1 eq 'Forward'){
1750 foreach my $key (keys %$hash){
1751 if (($$hash{$key}[4] ne 'ORANGE' && $$hash{$key}[4] ne 'BLUE')){$go='on';last}
1752 }
1753 }elsif( ! -z $config){
1754 $go='on';
1755 }
1756 if($go ne ''){
1757 &Header::openbox('100%', 'left',$title);
1758 my $count=0;
1759 my ($gif,$log);
1760 my $ruletype;
1761 my $rulecolor;
1762 my $tooltip;
1763 my @tmpsrc=();
1764 my $coloryellow='';
1765 print"<b>$title1</b><br>";
1766 print"<table width='100%' border='0' cellspacing='1' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;'>";
1767 print"<tr><td align='center' width='1%'><b>#</td><td width='1%'></td><td align='center' ><b>$Lang::tr{'fwdfw source'}</td><td width='1%'><b>Log</td><td align='center' width='20%'><b>$Lang::tr{'fwdfw target'}</td><td align='center'><b>$Lang::tr{'protocol'}</b></td><td align='center' width='70%'><b>$Lang::tr{'remark'}</td><td align='center' colspan='3' width='1%'><b>$Lang::tr{'fwdfw action'}</td></tr>";
1768 foreach my $key (sort {$a <=> $b} keys %$hash){
1769 #check if we have a FORWARDFW OR DMZ RULE
1770 if ($title1 eq 'DMZ' && ($$hash{$key}[4] ne 'ORANGE')){next;}
1771 if ($title1 eq 'WLAN' && ($$hash{$key}[4] ne 'BLUE')){next;}
1772 if ($title1 eq 'Forward' && ($$hash{$key}[4] eq 'ORANGE' || $$hash{$key}[4] eq 'BLUE')){next;}
1773 @tmpsrc=();
1774 #check if vpn hosts/nets have been deleted
1775 if($$hash{$key}[3] =~ /ipsec/i || $$hash{$key}[3] =~ /ovpn/i){
1776 push (@tmpsrc,$$hash{$key}[4]);
1777 }
1778 if($$hash{$key}[5] =~ /ipsec/i || $$hash{$key}[5] =~ /ovpn/i){
1779 push (@tmpsrc,$$hash{$key}[6]);
1780 }
1781 foreach my $host (@tmpsrc){
1782 if($$hash{$key}[3] eq 'ipsec_net_src' || $$hash{$key}[5] eq 'ipsec_net_tgt'){
1783 if(&fwlib::get_ipsec_net_ip($host,11) eq ''){
1784 $coloryellow='on';
1785 &disable_rule($key);
1786 $$hash{$key}[2]='';
1787 }
1788 }elsif($$hash{$key}[3] eq 'ovpn_net_src' || $$hash{$key}[5] eq 'ovpn_net_tgt'){
1789 if(&fwlib::get_ovpn_net_ip($host,1) eq ''){
1790 $coloryellow='on';
1791 &disable_rule($key);
1792 $$hash{$key}[2]='';
1793 }
1794 }elsif($$hash{$key}[3] eq 'ovpn_n2n_src' || $$hash{$key}[5] eq 'ovpn_n2n_tgt'){
1795 if(&fwlib::get_ovpn_n2n_ip($host,27) eq ''){
1796 $coloryellow='on';
1797 &disable_rule($key);
1798 $$hash{$key}[2]='';
1799 }
1800 }elsif($$hash{$key}[3] eq 'ovpn_host_src' || $$hash{$key}[5] eq 'ovpn_host_tgt'){
1801 if(&fwlib::get_ovpn_host_ip($host,33) eq ''){
1802 $coloryellow='on';
1803 &disable_rule($key);
1804 $$hash{$key}[2]='';
1805 }
1806 }
1807 $$hash{$key}[3]='';
1808 $$hash{$key}[5]='';
1809 }
1810 $$hash{'ACTIVE'}=$$hash{$key}[2];
1811 $count++;
1812 if($coloryellow eq 'on'){
1813 print"<tr bgcolor='$color{'color14'}' >";
1814 $coloryellow='';
1815 }elsif($coloryellow eq ''){
1816 if ($count % 2){
1817 print"<tr bgcolor='$color{'color22'}' >";
1818 }
1819 else{
1820 print"<tr bgcolor='$color{'color20'}' >";
1821 }
1822 }
1823 print<<END;
1824 <td align='right'>$key</td>
1825 END
1826 if ($$hash{$key}[0] eq 'ACCEPT'){
1827 $ruletype='A';
1828 $tooltip='ACCEPT';
1829 $rulecolor=$color{'color17'};
1830 }elsif($$hash{$key}[0] eq 'DROP'){
1831 $ruletype='D';
1832 $tooltip='DROP';
1833 $rulecolor=$color{'color25'};
1834 }elsif($$hash{$key}[0] eq 'REJECT'){
1835 $ruletype='R';
1836 $tooltip='REJECT';
1837 $rulecolor=$color{'color16'};
1838 }
1839 print"<td bgcolor='$rulecolor' width='2%' align='center'><span title='$tooltip'><b>$ruletype</b></span></td>";
1840 print"<td align='center' nowrap='nowrap'>";
1841 if ($$hash{$key}[3] eq 'std_net_src'){
1842 print &get_name($$hash{$key}[4]);
1843 }else{
1844 print $$hash{$key}[4];
1845 }
1846 &getsrcport(\%$hash,$key);
1847 if ($$hash{$key}[17] eq 'ON'){
1848 $log="/images/on.gif";
1849 }else{
1850 $log="/images/off.gif";
1851 }
1852 print<<END;
1853 </td>
1854 <form method='post'>
1855 <td width='1%' align='left'><input type='image' img src='$log' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw togglelog'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;'/>
1856 <input type='hidden' name='key' value='$key' />
1857 <input type='hidden' name='config' value='$config' />
1858 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw togglelog'}' />
1859 </td></form>
1860 END
1861 print<<END;
1862 <td align='center' nowrap='nowrap'>
1863 END
1864 if ($$hash{$key}[5] eq 'std_net_tgt'){
1865 print &get_name($$hash{$key}[6]);
1866 }else{
1867 print $$hash{$key}[6];
1868 }
1869 &gettgtport(\%$hash,$key);
1870 ################################################################################
1871 print"</td>";
1872 #Get Protocol
1873 my $prot;
1874 if ($$hash{$key}[12]){ #target prot if manual
1875 $prot=$$hash{$key}[12];
1876 }elsif($$hash{$key}[8]){ #source prot if manual
1877 $prot=$$hash{$key}[8];
1878 }elsif($$hash{$key}[14] eq 'cust_srv'){
1879 $prot=&get_serviceports("service",$$hash{$key}[15]);
1880 }elsif($$hash{$key}[14] eq 'cust_srvgrp'){
1881 $prot=&get_serviceports("group",$$hash{$key}[15]);
1882 }else{
1883 $prot=$Lang::tr{'all'};
1884 }
1885 print"<td align='center'>$prot</td>";
1886
1887 print"<td width='20%'>$$hash{$key}[16]</td>";
1888
1889 if($$hash{$key}[2] eq 'ON'){
1890 $gif="/images/on.gif"
1891
1892 }else{
1893 $gif="/images/off.gif"
1894 }
1895 print<<END;
1896 <form method='post'>
1897 <td width='1%'><input type='image' img src='$gif' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw toggle'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
1898 <input type='hidden' name='key' value='$key' />
1899 <input type='hidden' name='config' value='$config' />
1900 <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw toggle'}' />
1901 </td></form>
1902 <form method='post'>
1903 <td width='1%' ><input type='image' img src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'fwdfw edit'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
1904 <input type='hidden' name='key' value='$key' />
1905 <input type='hidden' name='config' value='$config' />
1906 <input type='hidden' name='ACTION' value='editrule' />
1907 </td></form></td>
1908 <form method='post'>
1909 <td width='1%'><input type='image' img src='/images/addblue.gif' alt='$Lang::tr{'fwdfw copy'}' title='$Lang::tr{'fwdfw copy'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
1910 <input type='hidden' name='key' value='$key' />
1911 <input type='hidden' name='config' value='$config' />
1912 <input type='hidden' name='ACTION' value='copyrule' />
1913 </td></form></td>
1914 <form method='post'>
1915 <td width='1%' ><input type='image' img src='/images/delete.gif' alt='$Lang::tr{'delete'}' title='$Lang::tr{'fwdfw delete'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
1916 <input type='hidden' name='key' value='$key' />
1917 <input type='hidden' name='config' value='$config' />
1918 <input type='hidden' name='ACTION' value='deleterule' />
1919 </td></form></td>
1920 END
1921 if (exists $$hash{$key-1}){
1922 print<<END;
1923 <form method='post'>
1924 <td width='1%'><input type='image' img src='/images/up.gif' alt='$Lang::tr{'fwdfw moveup'}' title='$Lang::tr{'fwdfw moveup'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
1925 <input type='hidden' name='key' value='$key' />
1926 <input type='hidden' name='config' value='$config' />
1927 <input type='hidden' name='ACTION' value='moveup' />
1928 </td></form></td>
1929 END
1930 }else{
1931 print"<td></td>";
1932 }
1933 if (exists $$hash{$key+1}){
1934 print<<END;
1935 <form method='post'>
1936 <td width='1%' ><input type='image' img src='/images/down.gif' alt='$Lang::tr{'fwdfw movedown'}' title='$Lang::tr{'fwdfw movedown'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' />
1937 <input type='hidden' name='key' value='$key' />
1938 <input type='hidden' name='config' value='$config' />
1939 <input type='hidden' name='ACTION' value='movedown' />
1940 </td></form></td></tr>
1941 END
1942 }else{
1943 print"<td></td></tr>";
1944 }
1945 #if timeframe set, print new line in table
1946 if ($$hash{$key}[18] eq 'ON'){
1947 my @days=();
1948 if($$hash{$key}[19] ne ''){push (@days,$Lang::tr{'fwdfw wd_mon'});}
1949 if($$hash{$key}[20] ne ''){push (@days,$Lang::tr{'fwdfw wd_tue'});}
1950 if($$hash{$key}[21] ne ''){push (@days,$Lang::tr{'fwdfw wd_wed'});}
1951 if($$hash{$key}[22] ne ''){push (@days,$Lang::tr{'fwdfw wd_thu'});}
1952 if($$hash{$key}[23] ne ''){push (@days,$Lang::tr{'fwdfw wd_fri'});}
1953 if($$hash{$key}[24] ne ''){push (@days,$Lang::tr{'fwdfw wd_sat'});}
1954 if($$hash{$key}[25] ne ''){push (@days,$Lang::tr{'fwdfw wd_sun'});}
1955 my $weekdays=join(",",@days);
1956 if (@days){
1957 print"<tr bgcolor='#FFE4B5'><td colspan='6'>$Lang::tr{'fwdfw time'} ";
1958 print"$weekdays";
1959 print "&nbsp $Lang::tr{'fwdfw from'} $$hash{$key}[26] &nbsp $Lang::tr{'fwdfw till'} $$hash{$key}[27]</td><td colspan='8'></d></tr>";
1960 }
1961 }
1962 }
1963 print"</table>";
1964 &Header::closebox();
1965 }
1966 }
1967 sub p2pblock
1968 {
1969 my $gif;
1970 open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
1971 @p2ps = <FILE>;
1972 close FILE;
1973 &Header::openbox('100%', 'center', 'P2P-Block');
1974 print <<END;
1975 <table width='35%' border='0'>
1976 <tr bgcolor='$color{'color22'}'><td align=center colspan='2' ><b>$Lang::tr{'protocol'}</b></td><td align='center'><b>$Lang::tr{'status'}</b></td></tr>
1977 END
1978 foreach my $p2pentry (sort @p2ps)
1979 {
1980 my @p2pline = split( /\;/, $p2pentry );
1981 if($p2pline[2] eq 'on'){
1982 $gif="/images/on.gif"
1983 }else{
1984 $gif="/images/off.gif"
1985 }
1986 print <<END;
1987 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1988 <tr bgcolor='$color{'color20'}'>
1989 <td align='center' colspan='2' >$p2pline[0]:</td><td align='center'><input type='hidden' name='P2PROT' value='$p2pline[1]' /><input type='image' img src='$gif' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw toggle'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' ><input type='hidden' name='ACTION' value='togglep2p'></td></tr></form>
1990 END
1991 }
1992 print"<tr><td><img src='/images/on.gif'></td><td align='left'>$Lang::tr{'outgoing firewall p2p allow'}</td></tr>";
1993 print"<tr><td><img src='/images/off.gif'></td><td align='left'>$Lang::tr{'outgoing firewall p2p deny'}</td></tr></table>";
1994 &Header::closebox();
1995 }
1996 sub fillselect
1997 {
1998 my %hash=%{(shift)};
1999 my $val=shift;
2000 my $key;
2001 foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
2002 if($hash{$key}[0] eq $val){
2003 print"<option value='$hash{$key}[0]' selected>$hash{$key}[0]</option>";
2004 }else{
2005 print"<option value='$hash{$key}[0]'>$hash{$key}[0]</option>";
2006 }
2007 }
2008 }
2009 sub rules
2010 {
2011 if (!-f "${General::swroot}/forward/reread"){
2012 system("touch ${General::swroot}/forward/reread");
2013 }
2014 }
2015 sub reread_rules
2016 {
2017 system("/usr/local/bin/forwardfwctrl");
2018 if ( -f "${General::swroot}/forward/reread"){
2019 system("rm ${General::swroot}/forward/reread");
2020 }
2021 }
2022 &Header::closebigbox();
2023 &Header::closepage();