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