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