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