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