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