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