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