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