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