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