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