]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/fwhosts.cgi
Forward Firewall: when editing a group the rules where not read correctly, because...
[people/teissler/ipfire-2.x.git] / html / cgi-bin / fwhosts.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2011 IPFire Team <info@ipfire.org> #
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 # New function for forwarding firewall. To make it comfortable to create #
22 # rules, we need "spelling names" for single Hosts. If you have any questions #
23 # <amarx@ipfire.org> #
24 ###############################################################################
25 use strict;
26
27 # enable only the following on debugging purpose
28 use warnings;
29 use CGI::Carp 'fatalsToBrowser';
30 no warnings 'uninitialized';
31 require '/var/ipfire/general-functions.pl';
32 require "${General::swroot}/lang.pl";
33 require "${General::swroot}/header.pl";
34
35 my %fwhostsettings=();
36 my %customnetwork=();
37 my %customhost=();
38 my %customgrp=();
39 my %customservice=();
40 my %customservicegrp=();
41 my %ccdnet=();
42 my %ccdhost=();
43 my %ipsecconf=();
44 my %icmptypes=();
45 my %color=();
46 my %defaultNetworks=();
47 my %mainsettings=();
48 my %ownnet=();
49 my %ipsecsettings=();
50 my %fwfwd=();
51 my %fwinp=();
52
53 my $errormessage;
54 my $hint;
55 my $update=0;
56 my $confignet = "${General::swroot}/fwhosts/customnetworks";
57 my $confighost = "${General::swroot}/fwhosts/customhosts";
58 my $configgrp = "${General::swroot}/fwhosts/customgroups";
59 my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
60 my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
61 my $configipsec = "${General::swroot}/vpn/config";
62 my $configsrv = "${General::swroot}/fwhosts/customservices";
63 my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
64 my $fwconfigfwd = "${General::swroot}/forward/config";
65 my $fwconfiginp = "${General::swroot}/forward/input";
66
67 unless (-e $confignet) { system("touch $confignet"); }
68 unless (-e $confighost) { system("touch $confighost"); }
69 unless (-e $configgrp) { system("touch $configgrp"); }
70 unless (-e $configsrv) { system("touch $configsrv"); }
71 unless (-e $configsrvgrp) { system("touch $configsrvgrp"); }
72
73 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
74 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
75 &General::readhash("${General::swroot}/ethernet/settings", \%ownnet);
76 &Header::getcgihash(\%fwhostsettings);
77
78 &Header::showhttpheaders();
79 &Header::openpage($Lang::tr{'fwhost hosts'}, 1, '');
80 &Header::openbigbox('100%', 'center');
81
82 ## ACTION ####
83 # Update
84 if ($fwhostsettings{'ACTION'} eq 'updatenet' )
85 {
86 &General::readhasharray("$confignet", \%customnetwork);
87 foreach my $key (keys %customnetwork)
88 {
89 if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'})
90 {
91 $fwhostsettings{'orgname'} = $customnetwork{$key}[0];
92 $fwhostsettings{'orgip'} = $customnetwork{$key}[1];
93 $fwhostsettings{'orgsub'} = $customnetwork{$key}[2];
94 $fwhostsettings{'count'} = $customnetwork{$key}[3];
95 delete $customnetwork{$key};
96
97 }
98 }
99 &General::writehasharray("$confignet", \%customnetwork);
100 $fwhostsettings{'actualize'} = 'on';
101 $fwhostsettings{'ACTION'} = 'savenet';
102 }
103 if ($fwhostsettings{'ACTION'} eq 'updatehost')
104 {
105 my ($ip,$subnet);
106 &General::readhasharray("$confighost", \%customhost);
107 foreach my $key (keys %customhost)
108 {
109 if($customhost{$key}[0] eq $fwhostsettings{'orgname'})
110 {
111 if ($customhost{$key}[1] eq 'ip'){
112 ($ip,$subnet) = split (/\//,$customhost{$key}[2]);
113 }else{
114 $ip = $customhost{$key}[2];
115 }
116 $fwhostsettings{'orgip'} = $ip;
117 $fwhostsettings{'count'} = $customhost{$key}[3];
118 delete $customhost{$key};
119 &General::writehasharray("$confighost", \%customhost);
120 }
121 }
122 $fwhostsettings{'actualize'} = 'on';
123 if($fwhostsettings{'orgip'}){
124 $fwhostsettings{'ACTION'} = 'savehost';
125 }else{
126 $fwhostsettings{'ACTION'} = $Lang::tr{'fwhost newhost'};
127 }
128 }
129 if ($fwhostsettings{'ACTION'} eq 'updateservice')
130 {
131 my $count=0;
132 my $needrules=0;
133 $errormessage=&checkports(\%customservice);
134 if (!$errormessage){
135 &General::readhasharray("$configsrv", \%customservice);
136 foreach my $key (keys %customservice)
137 {
138 if ($customservice{$key}[0] eq $fwhostsettings{'oldsrvname'})
139 {
140 $count=$customservice{$key}[4];
141 delete $customservice{$key};
142 &General::writehasharray("$configsrv", \%customservice);
143 last;
144 }
145 }
146 if ($fwhostsettings{'PROT'} ne 'ICMP'){
147 $fwhostsettings{'ICMP_TYPES'}='BLANK';
148 }
149 my $key1 = &General::findhasharraykey(\%customservice);
150 foreach my $i (0 .. 4) { $customservice{$key1}[$i] = "";}
151 $customservice{$key1}[0] = $fwhostsettings{'SRV_NAME'};
152 $customservice{$key1}[1] = $fwhostsettings{'SRV_PORT'};
153 $customservice{$key1}[2] = $fwhostsettings{'PROT'};
154 $customservice{$key1}[3] = $fwhostsettings{'ICMP_TYPES'};
155 $customservice{$key1}[4] = $count;
156 &General::writehasharray("$configsrv", \%customservice);
157 #check if we need to update firewallrules
158 if ($fwhostsettings{'SRV_NAME'} ne $fwhostsettings{'oldsrvname'}){
159 if ( ! -z $fwconfigfwd ){
160 &General::readhasharray("$fwconfigfwd", \%fwfwd);
161 foreach my $key (sort keys %fwfwd){
162 if ($fwfwd{$key}[15] eq $fwhostsettings{'oldsrvname'}){
163 $fwfwd{$key}[15] = $fwhostsettings{'SRV_NAME'};
164 }
165 }
166 &General::writehasharray("$fwconfigfwd", \%fwfwd);
167 }
168 if ( ! -z $fwconfiginp ){
169 &General::readhasharray("$fwconfiginp", \%fwinp);
170 foreach my $line (sort keys %fwinp){
171 if ($fwfwd{$line}[15] eq $fwhostsettings{'oldsrvname'}){
172 $fwfwd{$line}[15] = $fwhostsettings{'SRV_NAME'};
173 }
174 }
175 &General::writehasharray("$fwconfiginp", \%fwinp);
176 }
177 #check if we need to update groups
178 &General::readhasharray("$configsrvgrp", \%customservicegrp);
179 foreach my $key (sort keys %customservicegrp){
180 if($customservicegrp{$key}[2] eq $fwhostsettings{'oldsrvname'}){
181 $customservicegrp{$key}[2] = $fwhostsettings{'SRV_NAME'};
182 }
183 }
184 &General::writehasharray("$configsrvgrp", \%customservicegrp);
185
186 $needrules='on';
187 }
188
189
190 if($count gt 0 && $fwhostsettings{'oldsrvport'} ne $fwhostsettings{'SRV_PORT'} ){
191 $needrules='on';
192 }
193 if($count gt 0 && $fwhostsettings{'oldsrvprot'} ne $fwhostsettings{'PROT'} ){
194 $needrules='on';
195 }
196
197 $fwhostsettings{'SRV_NAME'} = '';
198 $fwhostsettings{'SRV_PORT'} = '';
199 $fwhostsettings{'PROT'} = '';
200 }else{
201 $fwhostsettings{'SRV_NAME'} = $fwhostsettings{'oldsrvname'};
202 $fwhostsettings{'SRV_PORT'} = $fwhostsettings{'oldsrvport'};
203 $fwhostsettings{'PROT'} = $fwhostsettings{'oldsrvprot'};
204 $fwhostsettings{'updatesrv'}= 'on';
205 }
206 if($needrules eq 'on'){
207 &rules;
208 }
209 &addservice;
210 }
211 # save
212 if ($fwhostsettings{'ACTION'} eq 'savenet' )
213 {
214 my $count=0;
215 my $needrules=0;
216 if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
217 #check if all fields are set
218 if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
219 {
220 $errormessage=$errormessage.$Lang::tr{'fwhost err empty'};
221 &addnet;
222 &viewtablenet;
223 }else{
224 #check valid ip
225 if (!&General::validipandmask($fwhostsettings{'IP'}."/".$fwhostsettings{'SUBNET'}))
226 {
227 $errormessage=$errormessage.$Lang::tr{'fwhost err addr'};
228 $fwhostsettings{'BLK_HOST'} ='readonly';
229 $fwhostsettings{'NOCHECK'} ='false';
230 $fwhostsettings{'error'} ='on';
231 }
232 #check if subnet is sigle host
233 if(&General::iporsubtocidr($fwhostsettings{'SUBNET'}) eq '32')
234 {
235 $errormessage=$errormessage.$Lang::tr{'fwhost err sub32'};
236 }
237 if($fwhostsettings{'error'} ne 'on'){
238 #check if we use one of ipfire's networks (green,orange,blue)
239 if (($ownnet{'GREEN_NETADDRESS'} ne '' && $ownnet{'GREEN_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'GREEN_NETADDRESS'},$ownnet{'GREEN_NETMASK'}))
240 {
241 $errormessage=$errormessage.$Lang::tr{'ccd err green'}."<br>";
242 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
243 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';}
244 }
245 if (($ownnet{'ORANGE_NETADDRESS'} ne '' && $ownnet{'ORANGE_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'ORANGE_NETADDRESS'},$ownnet{'ORANGE_NETMASK'}))
246 {
247 $errormessage=$errormessage.$Lang::tr{'ccd err orange'}."<br>";
248 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
249 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';}
250 }
251 if (($ownnet{'BLUE_NETADDRESS'} ne '' && $ownnet{'BLUE_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'BLUE_NETADDRESS'},$ownnet{'BLUE_NETMASK'}))
252 {
253 $errormessage=$errormessage.$Lang::tr{'ccd err blue'}."<br>";
254 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
255 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';}
256 }
257 if (($ownnet{'RED_NETADDRESS'} ne '' && $ownnet{'RED_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'RED_NETADDRESS'},$ownnet{'RED_NETMASK'}))
258 {
259 $errormessage=$errormessage.$Lang::tr{'ccd err red'}."<br>";
260 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
261 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';}
262 }
263 }
264 #only check plausi when no error till now
265 if (!$errormessage){
266 &plausicheck("editnet");
267 }
268 #check if network ip is part of an already used one
269 if(&checksubnet(\%customnetwork))
270 {
271 $errormessage=$errormessage.$Lang::tr{'fwhost err partofnet'};
272 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
273 }
274 if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newnet'} ne 'on' && $errormessage)
275 {
276 $fwhostsettings{'actualize'} = '';
277 my $key = &General::findhasharraykey (\%customnetwork);
278 foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";}
279 $customnetwork{$key}[0] = $fwhostsettings{'orgname'} ;
280 $customnetwork{$key}[1] = $fwhostsettings{'orgip'} ;
281 $customnetwork{$key}[2] = $fwhostsettings{'orgsub'};
282 $customnetwork{$key}[3] = $fwhostsettings{'count'};
283 &General::writehasharray("$confignet", \%customnetwork);
284 undef %customnetwork;
285 }
286 if (!$errormessage){
287 &General::readhasharray("$confignet", \%customnetwork);
288 if ($fwhostsettings{'ACTION'} eq 'updatenet'){
289 if ($fwhostsettings{'update'} == '0'){
290 foreach my $key (keys %customnetwork) {
291 if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'}){
292 $count=$customnetwork{$key}[3];
293 delete $customnetwork{$key};
294 last;
295 }
296 }
297 }
298 }
299 #get count if actualize is 'on'
300 if($fwhostsettings{'actualize'} eq 'on'){
301 $fwhostsettings{'actualize'} = '';
302 $count=$fwhostsettings{'count'};
303 #check if we need to reload rules
304 if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'} && $count gt '0'){
305 $needrules='on';
306 }
307 if ($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){
308 #check if we need to update groups
309 &General::readhasharray("$configgrp", \%customgrp);
310 foreach my $key (sort keys %customgrp){
311 if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){
312 $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'};
313 last;
314 }
315 }
316 &General::writehasharray("$configgrp", \%customgrp);
317 #check if we need to update firewallrules
318 if ( ! -z $fwconfigfwd ){
319 &General::readhasharray("$fwconfigfwd", \%fwfwd);
320 foreach my $line (sort keys %fwfwd){
321 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
322 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
323 }
324 if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){
325 $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'};
326 }
327 }
328 &General::writehasharray("$fwconfigfwd", \%fwfwd);
329 }
330 if ( ! -z $fwconfiginp ){
331 &General::readhasharray("$fwconfiginp", \%fwinp);
332 foreach my $line (sort keys %fwinp){
333 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
334 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
335 }
336 }
337 &General::writehasharray("$fwconfiginp", \%fwinp);
338 }
339 }
340 }
341 my $key = &General::findhasharraykey (\%customnetwork);
342 foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";}
343 $fwhostsettings{'SUBNET'} = &General::iporsubtocidr($fwhostsettings{'SUBNET'});
344 $customnetwork{$key}[0] = $fwhostsettings{'HOSTNAME'};
345 #convert ip when leading '0' in byte
346 $fwhostsettings{'IP'}=&General::ip2dec($fwhostsettings{'IP'});
347 $fwhostsettings{'IP'}=&General::dec2ip($fwhostsettings{'IP'});
348 $customnetwork{$key}[1] = &General::getnetworkip($fwhostsettings{'IP'},$fwhostsettings{'SUBNET'}) ;
349 $customnetwork{$key}[2] = &General::iporsubtodec($fwhostsettings{'SUBNET'}) ;
350 if($fwhostsettings{'newnet'} eq 'on'){$count=0;}
351 $customnetwork{$key}[3] = $count;
352 &General::writehasharray("$confignet", \%customnetwork);
353 $fwhostsettings{'IP'}=$fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
354 undef %customnetwork;
355 $fwhostsettings{'HOSTNAME'}='';
356 $fwhostsettings{'IP'}='';
357 $fwhostsettings{'SUBNET'}='';
358 #check if an edited net affected groups and need to reload rules
359 if ($needrules eq 'on'){
360 &rules;
361 }
362 &addnet;
363 &viewtablenet;
364 }else
365 {
366 &addnet;
367 &viewtablenet;
368 }
369 }
370 }
371 if ($fwhostsettings{'ACTION'} eq 'savehost')
372 {
373 my $count=0;
374 my $needrules=0;
375 if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
376 $fwhostsettings{'SUBNET'}='32';
377 #check if all fields are set
378 if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
379 {
380 $errormessage=$errormessage.$Lang::tr{'fwhost err empty'};
381 $fwhostsettings{'ACTION'} = 'edithost';
382 }else{
383 if($fwhostsettings{'type'} eq 'ip' && $fwhostsettings{'IP'}=~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/){
384 $fwhostsettings{'type'} = 'mac';
385 }elsif($fwhostsettings{'type'} eq 'mac' && $fwhostsettings{'IP'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
386 $fwhostsettings{'type'} = 'ip';
387 }elsif($fwhostsettings{'type'} eq 'mac' && $fwhostsettings{'IP'}=~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/){
388 $fwhostsettings{'type'} = 'mac';
389 }elsif($fwhostsettings{'type'} eq 'ip' && $fwhostsettings{'IP'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
390 $fwhostsettings{'type'} = 'ip';
391 }else{
392 $fwhostsettings{'type'} = '';
393 $errormessage=$Lang::tr{'fwhost err ipmac'};
394 }
395 if($fwhostsettings{'type'} eq 'mac' )
396 {
397 if ($fwhostsettings{'IP'}!~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/ )
398 {
399 $errormessage=$Lang::tr{'fwhost err mac'};
400 }
401 }
402 #CHECK IP-PART
403 if ($fwhostsettings{'type'} eq 'ip'){
404 #check for subnet
405 if (rindex($fwhostsettings{'IP'},'/') eq '-1' ){
406 if($fwhostsettings{'type'} eq 'ip' && !&General::validipandmask($fwhostsettings{'IP'}."/32"))
407 {
408 $errormessage.=$errormessage.$Lang::tr{'fwhost err ip'};
409 $fwhostsettings{'error'}='on';
410 }
411 }elsif(rindex($fwhostsettings{'IP'},'/') ne '-1' ){
412 $errormessage=$errormessage.$Lang::tr{'fwhost err ipwithsub'};
413 $fwhostsettings{'error'}='on';
414 }
415 #check if net or broadcast
416 my @tmp= split (/\./,$fwhostsettings{'IP'});
417 if (($tmp[3] eq "0") || ($tmp[3] eq "255")){
418 $errormessage=$Lang::tr{'fwhost err hostip'};
419 }
420 }
421 #only check plausi when no error till now
422 if (!$errormessage){
423 &plausicheck("edithost");
424 }
425 if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newhost'} ne 'on' && $errormessage){
426 $fwhostsettings{'actualize'} = '';
427 my $key = &General::findhasharraykey (\%customhost);
428 foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";}
429 $customhost{$key}[0] = $fwhostsettings{'orgname'} ;
430 $customhost{$key}[1] = $fwhostsettings{'type'} ;
431 if($customhost{$key}[1] eq 'ip'){
432 $customhost{$key}[2] = $fwhostsettings{'orgip'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
433 }else{
434 $customhost{$key}[2] = $fwhostsettings{'orgip'};
435 }
436 $customhost{$key}[3] = $fwhostsettings{'count'};
437 &General::writehasharray("$confighost", \%customhost);
438 undef %customhost;
439 }
440 if (!$errormessage){
441 #get count if host was edited
442 if($fwhostsettings{'actualize'} eq 'on'){
443 $count=$fwhostsettings{'count'};
444 if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'} && $count gt '0' ){
445 $needrules='on';
446 }
447 if($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){
448 #check if we need to update groups
449 &General::readhasharray("$configgrp", \%customgrp);
450 foreach my $key (sort keys %customgrp){
451 if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){
452 $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'};
453 last;
454 }
455 }
456 &General::writehasharray("$configgrp", \%customgrp);
457 #check if we need to update firewallrules
458 if ( ! -z $fwconfigfwd ){
459 &General::readhasharray("$fwconfigfwd", \%fwfwd);
460 foreach my $line (sort keys %fwfwd){
461 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
462 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
463 }
464 if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){
465 $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'};
466 }
467 }
468 &General::writehasharray("$fwconfigfwd", \%fwfwd);
469 }
470 if ( ! -z $fwconfiginp ){
471 &General::readhasharray("$fwconfiginp", \%fwinp);
472 foreach my $line (sort keys %fwinp){
473 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
474 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
475 }
476 }
477 &General::writehasharray("$fwconfiginp", \%fwinp);
478 }
479 }
480 }
481 my $key = &General::findhasharraykey (\%customhost);
482 foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";}
483 $customhost{$key}[0] = $fwhostsettings{'HOSTNAME'} ;
484 $customhost{$key}[1] = $fwhostsettings{'type'} ;
485 if ($fwhostsettings{'type'} eq 'ip'){
486 #convert ip when leading '0' in byte
487 $fwhostsettings{'IP'}=&General::ip2dec($fwhostsettings{'IP'});
488 $fwhostsettings{'IP'}=&General::dec2ip($fwhostsettings{'IP'});
489 $customhost{$key}[2] = $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
490 }else{
491 $customhost{$key}[2] = $fwhostsettings{'IP'};
492 }
493 if($fwhostsettings{'newhost'} eq 'on'){$count=0;}
494 $customhost{$key}[3] = $count;
495 &General::writehasharray("$confighost", \%customhost);
496 undef %customhost;
497 $fwhostsettings{'HOSTNAME'}='';
498 $fwhostsettings{'IP'}='';
499 $fwhostsettings{'type'}='';
500 #check if we need to update rules while host was edited
501 if($needrules eq 'on'){
502 &rules;
503 }
504 &addhost;
505 &viewtablehost;
506 }else{
507 &addhost;
508 &viewtablehost;
509 }
510 }
511 }
512 if ($fwhostsettings{'ACTION'} eq 'savegrp')
513 {
514 my $grp;
515 my $rem=$fwhostsettings{'remark'};
516 my $count;
517 my $type;
518 my $updcounter='off';
519 my @target;
520 my @newgrp;
521 &General::readhasharray("$configgrp", \%customgrp);
522 &General::readhasharray("$confignet", \%customnetwork);
523 &General::readhasharray("$confighost", \%customhost);
524 $grp=$fwhostsettings{'grp_name'};
525 if (!&validhostname($grp)){$errormessage=$errormessage.$Lang::tr{'fwhost err name'};}
526 ###check standard networks
527 if ($fwhostsettings{'grp2'} eq 'std_net'){
528 @target=$fwhostsettings{'DEFAULT_SRC_ADR'};
529 $type='Standard Network';
530 }
531 ##check custom networks
532 if ($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} ne ''){
533 @target=$fwhostsettings{'CUST_SRC_NET'};
534 $updcounter='net';
535 $type='Custom Network';
536 }elsif($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} eq ''){
537 $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>";
538 $fwhostsettings{'grp_name'}='';
539 $fwhostsettings{'remark'}='';
540 }
541 #check custom addresses
542 if ($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} ne ''){
543 @target=$fwhostsettings{'CUST_SRC_HOST'};
544 $updcounter='host';
545 $type='Custom Host';
546 }elsif($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} eq ''){
547 $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>";
548 $fwhostsettings{'grp_name'}='';
549 $fwhostsettings{'remark'}='';
550 }
551 #get address from ovpn ccd static net
552 if ($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} ne ''){
553 @target=$fwhostsettings{'OVPN_CCD_NET'};
554 $type='OpenVPN static network';
555 }elsif($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} eq ''){
556 $errormessage=$Lang::tr{'fwhost err groupempty'};
557 $fwhostsettings{'grp_name'}='';
558 $fwhostsettings{'remark'}='';
559 }
560 #get address from ovpn ccd static host
561 if ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} ne ''){
562 @target=$fwhostsettings{'OVPN_CCD_HOST'};
563 $type='OpenVPN static host';
564 }elsif ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} eq ''){
565 $errormessage=$Lang::tr{'fwhost err groupempty'};
566 }
567 #get address from ovpn ccd Net-2-Net
568 if ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} ne ''){
569 @target=$fwhostsettings{'OVPN_N2N'};
570 $type='OpenVPN N-2-N';
571 }elsif ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} eq ''){
572 $errormessage=$Lang::tr{'fwhost err groupempty'};
573 $fwhostsettings{'grp_name'}='';
574 $fwhostsettings{'remark'}='';
575 }
576 #get address from IPSEC HOST
577 if ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} ne ''){
578 @target=$fwhostsettings{'IPSEC_HOST'};
579 $type='IpSec Host';
580 }elsif ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} eq ''){
581 $errormessage=$Lang::tr{'fwhost err groupempty'};
582 $fwhostsettings{'grp_name'}='';
583 $fwhostsettings{'remark'}='';
584 }
585 #get address from IPSEC NETWORK
586 if ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} ne ''){
587 @target=$fwhostsettings{'IPSEC_NET'};
588 $type='IpSec Network';
589 }elsif ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} eq ''){
590 $errormessage=$Lang::tr{'fwhost err groupempty'};
591 $fwhostsettings{'grp_name'}='';
592 $fwhostsettings{'remark'}='';
593 }
594 #check if host/net exists in grp
595 my $test="$grp,$fwhostsettings{'oldremark'},@target";
596 foreach my $key (keys %customgrp) {
597 my $test1="$customgrp{$key}[0],$customgrp{$key}[1],$customgrp{$key}[2]";
598 if ($test1 eq $test){
599 $errormessage=$Lang::tr{'fwhost err isingrp'};
600 $fwhostsettings{'update'} = 'on';
601 }
602 }
603 if (!$errormessage){
604 #on first save, we have an empty @target, so fill it with nothing
605 my $targetvalues=@target;
606 if ($targetvalues == '0'){
607 @target=$Lang::tr{'fwhost empty'};
608 }
609 #on update, we have to delete the dummy entry
610 foreach my $key (keys %customgrp){
611 if ($customgrp{$key}[0] eq $grp && $customgrp{$key}[2] eq $Lang::tr{'fwhost empty'}){
612 delete $customgrp{$key};
613 last;
614 }
615 }
616 &General::writehasharray("$configgrp", \%customgrp);
617 &General::readhasharray("$configgrp", \%customgrp);
618 #get count used
619 foreach my $key (keys %customgrp)
620 {
621 if($customgrp{$key}[0] eq $grp)
622 {
623 $count=$customgrp{$key}[4];
624 last;
625 }
626 }
627 if ($count eq '' ){$count='0';}
628
629 #create array with new lines
630 foreach my $line (@target){
631 push (@newgrp,"$grp,$rem,$line");
632 }
633 #append new entries
634 my $key = &General::findhasharraykey (\%customgrp);
635 foreach my $line (@newgrp){
636 foreach my $i (0 .. 4) { $customgrp{$key}[$i] = "";}
637 my ($a,$b,$c,$d) = split (",",$line);
638 $customgrp{$key}[0] = $a;
639 $customgrp{$key}[1] = $b;
640 $customgrp{$key}[2] = $c;
641 $customgrp{$key}[3] = $type;
642 $customgrp{$key}[4] = $count;
643 }
644 &General::writehasharray("$configgrp", \%customgrp);
645 #update counter in Host/Net
646 if($updcounter eq 'net'){
647 foreach my $key (keys %customnetwork) {
648 if($customnetwork{$key}[0] eq $fwhostsettings{'CUST_SRC_NET'}){
649 $customnetwork{$key}[3] = $customnetwork{$key}[3]+1;
650 last;
651 }
652 }
653 &General::writehasharray("$confignet", \%customnetwork);
654 }elsif($updcounter eq 'host'){
655 foreach my $key (keys %customhost) {
656 if ($customhost{$key}[0] eq $fwhostsettings{'CUST_SRC_HOST'}){
657 $customhost{$key}[3]=$customhost{$key}[3]+1;
658 }
659 }
660 &General::writehasharray("$confighost", \%customhost);
661 }
662 $fwhostsettings{'update'}='on';
663 }
664 if ($fwhostsettings{'remark'} ne $fwhostsettings{'oldremark'} )
665 {
666 foreach my $key (sort keys %customgrp)
667 {
668 if($customgrp{$key}[0] eq $grp && $customgrp{$key}[1] eq $fwhostsettings{'oldremark'})
669 {
670 $customgrp{$key}[1]='';
671 $customgrp{$key}[1]=$rem;
672 }
673 }
674 &General::writehasharray("$configgrp", \%customgrp);
675 $errormessage='';
676 $fwhostsettings{'update'}='on';
677 }
678 #check if ruleupdate is needed
679 if($count > 0 )
680 {
681 &rules;
682 }
683 &addgrp;
684 &viewtablegrp;
685 }
686 if ($fwhostsettings{'ACTION'} eq 'saveservice')
687 {
688 my $ICMP;
689 &General::readhasharray("$configsrv", \%customservice );
690 $errormessage=&checkports(\%customservice);
691 if ($fwhostsettings{'PROT'} eq 'ICMP'){
692 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
693 foreach my $key (keys %icmptypes){
694 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwhostsettings{'ICMP_TYPES'}){
695 $ICMP=$icmptypes{$key}[0];
696 }
697 }
698 }
699 if($ICMP eq ''){$ICMP='BLANK';}
700 if (!$errormessage){
701 my $key = &General::findhasharraykey (\%customservice);
702 foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";}
703 $customservice{$key}[0] = $fwhostsettings{'SRV_NAME'};
704 $customservice{$key}[1] = $fwhostsettings{'SRV_PORT'};
705 $customservice{$key}[2] = $fwhostsettings{'PROT'};
706 $customservice{$key}[3] = $ICMP;
707 $customservice{$key}[4] = 0;
708 &General::writehasharray("$configsrv", \%customservice );
709 #reset fields
710 $fwhostsettings{'SRV_NAME'}='';
711 $fwhostsettings{'SRV_PORT'}='';
712 $fwhostsettings{'PROT'}='';
713 $fwhostsettings{'ICMP_TYPES'}='';
714 }
715 &addservice;
716 }
717 if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
718 {
719 my $prot;
720 my $port;
721 my $count=0;
722 &General::readhasharray("$configsrvgrp", \%customservicegrp );
723 &General::readhasharray("$configsrv", \%customservice );
724 $errormessage=&checkservicegroup;
725 if (!$errormessage){
726 #on first save, we have to enter a dummy value
727 if ($fwhostsettings{'CUST_SRV'} eq ''){$fwhostsettings{'CUST_SRV'}=$Lang::tr{'fwhost empty'};}
728 #on update, we have to delete the dummy entry
729 foreach my $key (keys %customservicegrp){
730 if ($customservicegrp{$key}[2] eq $Lang::tr{'fwhost empty'}){
731 delete $customservicegrp{$key};
732 last;
733 }
734 }
735 &General::writehasharray("$configsrvgrp", \%customservicegrp );
736 #check if remark has also changed
737 if ($fwhostsettings{'SRVGRP_REMARK'} ne $fwhostsettings{'oldsrvgrpremark'} && $fwhostsettings{'updatesrvgrp'} eq 'on')
738 {
739 foreach my $key (keys %customservicegrp)
740 {
741 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvgrpremark'})
742 {
743 $customservicegrp{$key}[1]='';
744 $customservicegrp{$key}[1]=$fwhostsettings{'SRVGRP_REMARK'};
745 }
746 }
747 }
748 #get count used
749 foreach my $key (keys %customservicegrp)
750 {
751 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'})
752 {
753 $count=$customservicegrp{$key}[3];
754 last;
755 }
756 }
757 if ($count eq '' ){$count='0';}
758
759 foreach my $key (sort keys %customservice){
760 if($customservice{$key}[0] eq $fwhostsettings{'CUST_SRV'}){
761 $port=$customservice{$key}[1];
762 $prot=$customservice{$key}[2];
763 $customservice{$key}[4]++;
764 }
765 }
766 &General::writehasharray("$configsrv", \%customservice );
767 my $key = &General::findhasharraykey (\%customservicegrp);
768 foreach my $i (0 .. 3) { $customservice{$key}[$i] = "";}
769 $customservicegrp{$key}[0] = $fwhostsettings{'SRVGRP_NAME'};
770 $customservicegrp{$key}[1] = $fwhostsettings{'SRVGRP_REMARK'};
771 $customservicegrp{$key}[2] = $fwhostsettings{'CUST_SRV'};
772 $customservicegrp{$key}[3] = $count;
773 &General::writehasharray("$configsrvgrp", \%customservicegrp );
774 $fwhostsettings{'updatesrvgrp'}='on';
775 }
776 if ($fwhostsettings{'SRVGRP_REMARK'} ne $fwhostsettings{'oldsrvgrpremark'} && $errormessage){
777 foreach my $key (keys %customservicegrp)
778 {
779 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvgrpremark'})
780 {
781 $customservicegrp{$key}[1]='';
782 $customservicegrp{$key}[1]=$fwhostsettings{'SRVGRP_REMARK'};
783 }
784 }
785 &General::writehasharray("$configsrvgrp", \%customservicegrp);
786 $errormessage='';
787 $hint=$Lang::tr{'fwhost changeremark'};
788 $fwhostsettings{'update'}='on';
789 }
790 if ($count gt 0){
791 &rules;
792 }
793 &addservicegrp;
794 &viewtableservicegrp;
795 }
796 # edit
797 if ($fwhostsettings{'ACTION'} eq 'editnet')
798 {
799 &addnet;
800 &viewtablenet;
801 }
802 if ($fwhostsettings{'ACTION'} eq 'edithost')
803 {
804 &addhost;
805 &viewtablehost;
806 }
807 if ($fwhostsettings{'ACTION'} eq 'editgrp')
808 {
809 $fwhostsettings{'update'}='on';
810 &addgrp;
811 &viewtablegrp;
812 }
813 if ($fwhostsettings{'ACTION'} eq 'editservice')
814 {
815 $fwhostsettings{'updatesrv'}='on';
816 &addservice;
817 }
818 if ($fwhostsettings{'ACTION'} eq 'editservicegrp')
819 {
820 $fwhostsettings{'updatesrvgrp'} = 'on';
821 &addservicegrp;
822 &viewtableservicegrp;
823 }
824 # reset
825 if ($fwhostsettings{'ACTION'} eq 'resetnet')
826 {
827 $fwhostsettings{'HOSTNAME'} ="";
828 $fwhostsettings{'IP'} ="";
829 $fwhostsettings{'SUBNET'} ="";
830 &showmenu;
831 }
832 if ($fwhostsettings{'ACTION'} eq 'resethost')
833 {
834 $fwhostsettings{'HOSTNAME'} ="";
835 $fwhostsettings{'IP'} ="";
836 $fwhostsettings{'type'} ="";
837 &showmenu;
838 }
839 # delete
840 if ($fwhostsettings{'ACTION'} eq 'delnet')
841 {
842 &General::readhasharray("$confignet", \%customnetwork);
843 foreach my $key (keys %customnetwork) {
844 if($fwhostsettings{'key'} eq $customnetwork{$key}[0]){
845 delete $customnetwork{$key};
846 &General::writehasharray("$confignet", \%customnetwork);
847 last;
848 }
849 }
850 &addnet;
851 &viewtablenet;
852 }
853 if ($fwhostsettings{'ACTION'} eq 'delhost')
854 {
855 &General::readhasharray("$confighost", \%customhost);
856 foreach my $key (keys %customhost) {
857 if($fwhostsettings{'key'} eq $customhost{$key}[0]){
858 delete $customhost{$key};
859 &General::writehasharray("$confighost", \%customhost);
860 last;
861 }
862 }
863 &addhost;
864 &viewtablehost;
865 }
866 if ($fwhostsettings{'ACTION'} eq 'deletegrphost')
867 {
868 &General::readhasharray("$configgrp", \%customgrp);
869 foreach my $key (keys %customgrp){
870 if($customgrp{$key}[0].",".$customgrp{$key}[1].",".$customgrp{$key}[2].",".$customgrp{$key}[3] eq $fwhostsettings{'delhost'}){
871 #decrease count from source host/net
872 if ($customgrp{$key}[3] eq 'Custom Network'){
873 &General::readhasharray("$confignet", \%customnetwork);
874 foreach my $key1 (keys %customnetwork){
875 if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){
876 $customnetwork{$key1}[3] = $customnetwork{$key1}[3]-1;
877 last;
878 }
879 }
880 &General::writehasharray("$confignet", \%customnetwork);
881 }
882 if ($customgrp{$key}[3] eq 'Custom Host'){
883 &General::readhasharray("$confighost", \%customhost);
884 foreach my $key1 (keys %customhost){
885 if ($customhost{$key1}[0] eq $customgrp{$key}[2]){
886 $customhost{$key1}[3] = $customhost{$key1}[3]-1;
887 last;
888 }
889 }
890 &General::writehasharray("$confighost", \%customhost);
891 }
892 delete $customgrp{$key};
893 }
894 }
895 &General::writehasharray("$configgrp", \%customgrp);
896 &rules;
897 &addgrp;
898 &viewtablegrp;
899 }
900 if ($fwhostsettings{'ACTION'} eq 'delgrp')
901 {
902 &General::readhasharray("$configgrp", \%customgrp);
903 &decrease($fwhostsettings{'grp_name'});
904 foreach my $key (sort keys %customgrp)
905 {
906 if($customgrp{$key}[0] eq $fwhostsettings{'grp_name'})
907 {
908 delete $customgrp{$key};
909 }
910 }
911 &General::writehasharray("$configgrp", \%customgrp);
912 $fwhostsettings{'grp_name'}='';
913 &addgrp;
914 &viewtablegrp;
915 }
916 if ($fwhostsettings{'ACTION'} eq 'delservice')
917 {
918 &General::readhasharray("$configsrv", \%customservice);
919 foreach my $key (keys %customservice) {
920 if($customservice{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
921 #&deletefromgrp($customhost{$key}[0],$configgrp);
922 delete $customservice{$key};
923 &General::writehasharray("$configsrv", \%customservice);
924 last;
925 }
926 }
927 $fwhostsettings{'SRV_NAME'}='';
928 $fwhostsettings{'SRV_PORT'}='';
929 $fwhostsettings{'PROT'}='';
930 &addservice;
931 }
932 if ($fwhostsettings{'ACTION'} eq 'delservicegrp')
933 {
934 &General::readhasharray("$configsrvgrp", \%customservicegrp);
935 &decreaseservice($fwhostsettings{'SRVGRP_NAME'});
936 foreach my $key (sort keys %customservicegrp)
937 {
938 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'})
939 {
940 delete $customservicegrp{$key};
941 }
942 }
943 &General::writehasharray("$configsrvgrp", \%customservicegrp);
944 $fwhostsettings{'SRVGRP_NAME'}='';
945 &addservicegrp;
946 &viewtableservicegrp;
947 }
948 if ($fwhostsettings{'ACTION'} eq 'delgrpservice')
949 {
950 &General::readhasharray("$configsrvgrp", \%customservicegrp);
951 &General::readhasharray("$configsrv", \%customservice);
952 foreach my $key (keys %customservicegrp){
953 if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2].",".$customservicegrp{$key}[3] eq $fwhostsettings{'delsrvfromgrp'})
954 {
955 #decrease count from source service
956 foreach my $key1 (sort keys %customservice){
957 if($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
958 $customservice{$key1}[4]--;
959 last;
960 }
961 }
962 &General::writehasharray("$configsrv", \%customservice);
963 delete $customservicegrp{$key}
964 }
965 }
966 &General::writehasharray("$configsrvgrp", \%customservicegrp);
967 &rules;
968 &addservicegrp;
969 &viewtableservicegrp;
970
971 }
972 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newnet'})
973 {
974 &addnet;
975 &viewtablenet;
976 }
977 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newhost'})
978 {
979 &addhost;
980 &viewtablehost;
981 }
982 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newgrp'})
983 {
984 &addgrp;
985 &viewtablegrp;
986 }
987 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservice'})
988 {
989 &addservice;
990 }
991 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservicegrp'})
992 {
993 &addservicegrp;
994 &viewtableservicegrp;
995 }
996 ### VIEW ###
997 if($fwhostsettings{'ACTION'} eq '')
998 {
999 &showmenu;
1000 }
1001 ### FUNCTIONS ###
1002 sub showmenu
1003 {
1004
1005 &Header::openbox('100%', 'left',$Lang::tr{'fwhost menu'});
1006 print<<END;
1007 <table border='0' width='100%'><form method='post'>
1008 <tr><td><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newnet'}' /><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newhost'}' /><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newgrp'}' /></td>
1009 <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newservice'}' /><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newservicegrp'}' /></td></tr>
1010 <tr><td colspan='6'><hr></hr></td></tr></table></form>
1011 END
1012
1013 &Header::closebox();
1014
1015 }
1016 # Add
1017 sub addnet
1018 {
1019 &error;
1020 &showmenu;
1021 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addnet'});
1022 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
1023 print<<END;
1024 <table border='0' width='100%'><form method='post' style='display:inline' >
1025 <tr><td>$Lang::tr{'name'}:</td><td><input type='TEXT' name='HOSTNAME' id='textbox1' value='$fwhostsettings{'HOSTNAME'}' $fwhostsettings{'BLK_HOST'}><script>document.getElementById('textbox1').focus()</script></td><td>$Lang::tr{'fwhost netaddress'}</td><td><input type='TEXT' name='IP' value='$fwhostsettings{'IP'}' $fwhostsettings{'BLK_IP'} size='14'></td><td align='right'>$Lang::tr{'netmask'}:</td><td align='right'><input type='TEXT' name='SUBNET' value='$fwhostsettings{'SUBNET'}' $fwhostsettings{'BLK_IP'} size='14'></td></tr>
1026 <tr><td colspan='6'><hr></hr></td></tr><tr>
1027 END
1028 if ($fwhostsettings{'ACTION'} eq 'editnet' || $fwhostsettings{'error'} eq 'on')
1029 {
1030 print "<td colspan='6' align='right' ><input type='submit' value='$Lang::tr{'update'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='updatenet'><input type='hidden' name='orgname' value='$fwhostsettings{'orgname'}' ><input type='hidden' name='update' value='on'><input type='hidden' name='newnet' value='$fwhostsettings{'newnet'}'>";
1031 }else{
1032 print "<td colspan='6' align='right'><input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'/><input type='hidden' name='ACTION' value='savenet'><input type='hidden' name='newnet' value='on'>";
1033 }
1034 print "</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='resetnet'></td></tr></table></form>";
1035 &Header::closebox();
1036 }
1037 sub addhost
1038 {
1039 &error;
1040 &showmenu;
1041 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addhost'});
1042 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
1043 print<<END;
1044 <table border='0' width='100%'><form method='post' style='display:inline'>
1045 <tr><td>$Lang::tr{'name'}:</td><td width='35%'><input type='TEXT' name='HOSTNAME' id='textbox1' value='$fwhostsettings{'HOSTNAME'}' $fwhostsettings{'BLK_HOST'} ><script>document.getElementById('textbox1').focus()</script></td><td><select name='type'>
1046 END
1047 if ($fwhostsettings{'type'} eq 'ip'){print "<option value='ip' selected >IP</option>";}else{print "<option value='ip' >IP</option>";}
1048 if ($fwhostsettings{'type'} eq 'mac'){print "<option value='mac' selected >MAC</option>";}else{print "<option value='mac' >MAC</option>";}
1049 print<<END;
1050 </option></select></td><td align='right' width='15%'>IP/MAC:</td><td align='right'><input type='TEXT' name='IP' value='$fwhostsettings{'IP'}' $fwhostsettings{'BLK_IP'} ></td></tr>
1051 <tr><td colspan='7'><br><br><b>$Lang::tr{'fwhost attention'}</b><br>$Lang::tr{'fwhost macwarn'}</td></tr>
1052 <tr><td colspan='7'><hr></hr></td></tr>
1053 END
1054
1055 if ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'} eq 'on')
1056 {
1057
1058 print " <td colspan='6' align='right'><input type='submit' value='$Lang::tr{'update'}' style='min-width:100px;'/><input type='hidden' name='ACTION' value='updatehost'><input type='hidden' name='orgname' value='$fwhostsettings{'orgname'}' ><input type='hidden' name='update' value='on'><input type='hidden' name='newhost' value='$fwhostsettings{'newhost'}'></form>";
1059 }else{
1060 print " <td colspan='6' align='right'><input type='submit' name='savehost' value='$Lang::tr{'save'}'style='min-width:100px;' /><input type='hidden' name='ACTION' value='savehost' /><input type='hidden' name='newhost' value='on'>";
1061 }
1062 print " </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='resethost'></td></tr></table></form>";
1063 &Header::closebox();
1064 }
1065 sub addgrp
1066 {
1067 &hint;
1068 &error;
1069 &showmenu;
1070 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addgrp'});
1071 &General::setup_default_networks(\%defaultNetworks);
1072 my %checked=();
1073 $checked{'check1'}{'off'} = '';
1074 $checked{'check1'}{'on'} = '';
1075 $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED';
1076 $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'};
1077
1078 if ($fwhostsettings{'update'} eq ''){
1079 print<<END;
1080 <table width='100%' border='0'><form method='post'>
1081 <tr><td>$Lang::tr{'fwhost addgrpname'}</td><td><input type='TEXT' name='grp_name' value='$fwhostsettings{'grp_name'}'></td><td>$Lang::tr{'remark'}:</td><td width='1%'><input type='TEXT' name='remark' size='35' value='$fwhostsettings{'remark'}'></tr>
1082 <tr><td colspan='5'><hr></td></tr></table>
1083 END
1084 }else{
1085 print<<END;
1086 <table width='100%' border='0'><form method='post'>
1087 <tr><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost addgrpname'}</td><td><input type='TEXT' name='grp_name' value='$fwhostsettings{'grp_name'}' readonly ></td><td>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='remark' size='35' value='$fwhostsettings{'remark'}'></tr>
1088 <tr><td colspan='5'><hr></td></tr></table>
1089 END
1090
1091 }
1092 if ($fwhostsettings{'update'} eq 'on'){
1093
1094
1095 print<<END;
1096 <table width='100%' border='0'><tr><td width='1%'><input type='radio' name='grp2' value='std_net' checked></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost stdnet'}</td><td><select name='DEFAULT_SRC_ADR' style='min-width:185px;'>
1097
1098 END
1099 foreach my $network (sort keys %defaultNetworks)
1100 {
1101 next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP");
1102 next if($defaultNetworks{$network}{'NAME'} eq "RED");
1103 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1104 print " selected='selected'" if ($fwhostsettings{'DEFAULT_SRC_ADR'} eq $defaultNetworks{$network}{'NAME'});
1105 print ">$network</option>";
1106 }
1107
1108 print<<END;
1109 </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_net' $checked{'grp2'}{'ovpn_net'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%'><select name='OVPN_CCD_NET' style='min-width:185px;'>
1110 END
1111 &General::readhasharray("$configccdnet", \%ccdnet);
1112 foreach my $key (sort { uc($ccdnet{$a}[0]) cmp uc($ccdnet{$b}[0]) } keys %ccdnet)
1113 {
1114 print"<option value='$ccdnet{$key}[0]'>$ccdnet{$key}[0]</option>";
1115 }
1116
1117 print<<END;
1118 </select></td></tr>
1119 <tr><td><input type='radio' name='grp2' value='cust_net' $checked{'grp2'}{'cust_net'}></td><td>$Lang::tr{'fwhost cust net'}</td><td><select name='CUST_SRC_NET' style='min-width:185px;'>
1120 END
1121 &General::readhasharray("$confignet", \%customnetwork);
1122 foreach my $key (sort { uc($customnetwork{$a}[0]) cmp uc($customnetwork{$b}[0]) } keys %customnetwork) {
1123 print"<option>$customnetwork{$key}[0]</option>";
1124 }
1125
1126 print<<END;
1127 </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_host' $checked{'grp2'}{'ovpn_host'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%'><select name='OVPN_CCD_HOST' style='min-width:185px;'>
1128 END
1129 &General::readhasharray("$configccdhost", \%ccdhost);
1130 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost)
1131 {
1132 if ($ccdhost{$key}[33] ne ''){
1133 print"<option value='$ccdhost{$key}[1]'>$ccdhost{$key}[1]</option>";
1134 }
1135 }
1136
1137 print<<END;
1138 </select></td></tr>
1139 <tr><td valign='top'><input type='radio' name='grp2' value='cust_host' $checked{'grp2'}{'cust_host'}></td><td valign='top'>$Lang::tr{'fwhost cust addr'}</td><td><select name='CUST_SRC_HOST' style='min-width:185px;'>
1140 END
1141 &General::readhasharray("$confighost", \%customhost);
1142 foreach my $key (sort { uc($customhost{$a}[0]) cmp uc($customhost{$b}[0]) } keys %customhost) {
1143 print"<option>$customhost{$key}[0]</option>";
1144 }
1145 print<<END;
1146 </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_n2n' $checked{'grp2'}{'ovpn_n2n'}></td><td valign='top'>$Lang::tr{'fwhost ovpn_n2n'}</td><td colspan='3'><select name='OVPN_N2N' style='min-width:185px;'>
1147 END
1148 &General::readhasharray("$configccdhost", \%ccdhost);
1149 foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) {
1150 if($ccdhost{$key}[3] eq 'net'){
1151 print"<option>$ccdhost{$key}[1]</option>";
1152 }
1153 }
1154 print<<END;
1155 </select></td></tr>
1156 <tr><td colspan='3'></td><td valign='top'><input type='radio' name='grp2' value='ipsec_net' $checked{'grp2'}{'ipsec_net'}></td><td valign='top'>$Lang::tr{'fwhost ipsec net'}</td><td><select name='IPSEC_NET' style='min-width:185px;'>
1157 END
1158 &General::readhasharray("$configipsec", \%ipsecconf);
1159 foreach my $key (sort { uc($ipsecconf{$a}[0]) cmp uc($ipsecconf{$b}[0]) } keys %ipsecconf) {
1160 if ($ipsecconf{$key}[3] eq 'net'){
1161 print"<option value='$ipsecconf{$key}[1]'>$ipsecconf{$key}[1]</option>";
1162 }
1163 }
1164 print<<END;
1165 </select></td></tr></table>
1166 END
1167 # <td colspan='3'></td><td valign='top'><input type='radio' name='grp2' value='ipsec_host' $checked{'grp2'}{'ipsec_host'}></td><td valign='top'>$Lang::tr{'fwhost ipsec host'}</td><td><select name='IPSEC_HOST' style='min-width:185px;'>
1168 #END
1169 # &General::readhasharray("$configipsec", \%ipsecconf);
1170 # foreach my $key (sort { uc($ipsecconf{$a}[0]) cmp uc($ipsecconf{$b}[0]) } keys %ipsecconf) {
1171 # if ($ipsecconf{$key}[3] eq 'host'){
1172 # print"<option>$ipsecconf{$key}[1]</option>";
1173 # }
1174 # }
1175 # print<<END;
1176 # </select></td></tr>
1177 # <tr>
1178 print<<END;
1179 <br><br><br>
1180 <b>$Lang::tr{'fwhost attention'}:</b><br>
1181 $Lang::tr{'fwhost macwarn'}<br><hr>
1182 END
1183 }
1184 print<<END;
1185 <table border='0' width='100%'>
1186 <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' /><input type='hidden' name='oldremark' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='ACTION' value='savegrp' ></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>
1187 </table></form>
1188 END
1189
1190 &Header::closebox();
1191 }
1192 sub addservice
1193 {
1194 &error;
1195 &showmenu;
1196 &Header::openbox('100%', 'left', $Lang::tr{'fwhost newservice'});
1197 if ($fwhostsettings{'updatesrv'} eq 'on')
1198 {
1199 $fwhostsettings{'oldsrvname'} = $fwhostsettings{'SRV_NAME'};
1200 $fwhostsettings{'oldsrvport'} = $fwhostsettings{'SRV_PORT'};
1201 $fwhostsettings{'oldsrvprot'} = $fwhostsettings{'PROT'};
1202 }
1203 print<<END;
1204 <table width='100%' border='0'><form method='post'>
1205 <tr><td width='1%' nowrap='nowrap'>$Lang::tr{'fwhost srv_name'}:</td><td width='1%' nowrap='nowrap'><input type='text' name='SRV_NAME' id='textbox1' value='$fwhostsettings{'SRV_NAME'}'><script>document.getElementById('textbox1').focus()</script></td><td width='1%' nowrap='nowrap'>$Lang::tr{'fwhost prot'}:</td><td><select name='PROT'>
1206 END
1207 foreach ("TCP","UDP","ICMP")
1208 {
1209 if ($_ eq $fwhostsettings{'PROT'})
1210 {
1211 print"<option selected>$_</option>";
1212 }else{
1213 print"<option>$_</option>";
1214 }
1215 }
1216 print<<END;
1217 </select></td><td>$Lang::tr{'fwhost port'}:</td><td><input type='text' name='SRV_PORT' value='$fwhostsettings{'SRV_PORT'}' maxlength='11' size='9'></td></tr>
1218 <tr><td></td><td></td><td nowrap='nowrap'>$Lang::tr{'fwhost icmptype'}</td><td colspan='4'><select name='ICMP_TYPES'>
1219 END
1220 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1221 print"<option>All ICMP-Types</option>";
1222 foreach my $key (sort { uc($icmptypes{$a}[0]) cmp uc($icmptypes{$b}[0]) }keys %icmptypes){
1223 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1224 }
1225
1226 print<<END;
1227 </select></td>
1228 <tr><td colspan='6'><hr></td></tr>
1229 <tr><td colspan='6' align='right'>
1230 END
1231 if ($fwhostsettings{'updatesrv'} eq 'on')
1232 {
1233 print<<END;
1234 <input type='submit' value='$Lang::tr{'update'}'style='min-width:100px;' >
1235 <input type='hidden' name='ACTION' value='updateservice'>
1236 <input type='hidden' name='oldsrvname' value='$fwhostsettings{'oldsrvname'}'>
1237 <input type='hidden' name='oldsrvport' value='$fwhostsettings{'oldsrvport'}'>
1238 <input type='hidden' name='oldsrvprot' value='$fwhostsettings{'oldsrvprot'}'></form>
1239 END
1240
1241 }else{
1242 print"<input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='saveservice'></form>";
1243 }
1244 print<<END;
1245 <form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></form></td></tr>
1246 </table></form>
1247
1248
1249 END
1250 &Header::closebox();
1251 &viewtableservice;
1252 }
1253 sub addservicegrp
1254 {
1255 &hint;
1256 &error;
1257 &showmenu;
1258 &Header::openbox('100%', 'left', $Lang::tr{'fwhost newservicegrp'});
1259 $fwhostsettings{'oldsrvgrpremark'}=$fwhostsettings{'SRVGRP_REMARK'};
1260
1261 if ($fwhostsettings{'updatesrvgrp'} eq ''){
1262 print<<END;
1263 <table width='100%' border='0'><form method='post'>
1264 <tr><td>$Lang::tr{'fwhost addgrpname'}</td><td><input type='text' name='SRVGRP_NAME' value='$fwhostsettings{'SRVGRP_NAME'}'></td><td>$Lang::tr{'remark'}:</td><td width='1%'><input type='text' name='SRVGRP_REMARK' size='35' value='$fwhostsettings{'SRVGRP_REMARK'}'></td></tr>
1265 <tr><td colspan='4'><hr></td></td></tr>
1266 </table>
1267 END
1268 }else{
1269 print<<END;
1270 <table width='100%' border='0'><form method='post'>
1271 <tr><td>$Lang::tr{'fwhost addgrpname'}</td><td><input type='text' name='SRVGRP_NAME' value='$fwhostsettings{'SRVGRP_NAME'}' readonly ></td><td>$Lang::tr{'remark'}:</td><td width='1%'><input type='text' name='SRVGRP_REMARK' size='35' value='$fwhostsettings{'SRVGRP_REMARK'}'></td></tr>
1272 <tr><td colspan='4'><hr></td></td></tr>
1273 </table>
1274 END
1275 }
1276 if($fwhostsettings{'updatesrvgrp'} eq 'on'){
1277 print<<END;
1278 <table border='0' width='100%'>
1279 <tr><td width='1%' nowrap='nowrap'>$Lang::tr{'fwhost cust service'}</td><td><select name='CUST_SRV' style='min-width:185px;'>
1280 END
1281 &General::readhasharray("$configsrv", \%customservice);
1282 foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0])|| $a <=> $b } keys %customservice)
1283 {
1284 print "<option>$customservice{$key}[0]</option>";
1285 }
1286 print<<END;
1287 </select></td></tr>
1288 <tr><td colspan='4'><br><br><br></td></tr>
1289 <tr><td colspan='4'><hr></td></tr>
1290 </table>
1291 END
1292 }
1293 print<<END;
1294 <table width='100%' border='0'>
1295 <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' /><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'><input type='hidden' name='oldsrvgrpremark' value='$fwhostsettings{'oldsrvgrpremark'}'><input type='hidden' name='ACTION' value='saveservicegrp' ></form><form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></td></tr>
1296 </table></form>
1297 END
1298
1299 &Header::closebox();
1300 }
1301 # View
1302 sub viewtablenet
1303 {
1304 if(! -z $confignet){
1305 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust net'});
1306 &General::readhasharray("$confignet", \%customnetwork);
1307 if (!keys %customnetwork)
1308 {
1309 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1310 }else{
1311 print<<END;
1312 <table border='0' width='100%'>
1313 <tr><td align='center'><b>$Lang::tr{'name'}</td><td align='center'><b>$Lang::tr{'fwhost netaddress'}</td><td align='center'><b>$Lang::tr{'netmask'}</td><td align='center'><b>$Lang::tr{'used'}</td><td></td><td width='3%'></td></tr>
1314 END
1315 }
1316 my $count=0;
1317 foreach my $key (sort {$a <=> $b} keys %customnetwork) {
1318 if ($fwhostsettings{'ACTION'} eq 'editnet' && $fwhostsettings{'HOSTNAME'} eq $customnetwork{$key}[0]) {
1319 print" <tr bgcolor='${Header::colouryellow}'>";
1320 }elsif ($count % 2)
1321 {
1322 print" <tr bgcolor='$color{'color22'}'>";
1323 }else
1324 {
1325 print" <tr bgcolor='$color{'color20'}'>";
1326 }
1327 print<<END;
1328 <td width='40%'><form method='post'>$customnetwork{$key}[0]</td><td width=25%'>$customnetwork{$key}[1]</td><td width='25%'>$customnetwork{$key}[2]</td><td align='center'>$customnetwork{$key}[3]x</td>
1329 <td width='1%'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} />
1330 <input type='hidden' name='ACTION' value='editnet'>
1331 <input type='hidden' name='HOSTNAME' value='$customnetwork{$key}[0]' />
1332 <input type='hidden' name='IP' value='$customnetwork{$key}[1]' />
1333 <input type='hidden' name='SUBNET' value='$customnetwork{$key}[2]' />
1334 </td></form>
1335 END
1336 if($customnetwork{$key}[3] == '0')
1337 {
1338 print"<td width='1%'><form method='post'><input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} /><input type='hidden' name='ACTION' value='delnet' /><input type='hidden' name='key' value='$customnetwork{$key}[0]' /></td></form></tr>";
1339 }else{
1340 print"<td></td></form></tr>";
1341 }
1342 $count++;
1343 }
1344 print"</table>";
1345 &Header::closebox();
1346 }
1347
1348 }
1349 sub viewtablehost
1350 {
1351 if (! -z $confighost){
1352 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust addr'});
1353 &General::readhasharray("$confighost", \%customhost);
1354 if (!keys %customhost)
1355 {
1356 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1357 }else{
1358 print<<END;
1359 <table border='0' width='100%'>
1360 <tr><td align='center'><b>$Lang::tr{'name'}</td><td align='center'><b>$Lang::tr{'fwhost ip_mac'}</td><td align='center'><b>$Lang::tr{'used'}</td><td></td><td width='3%'></td></tr>
1361 END
1362 }
1363 my $count=0;
1364 foreach my $key (sort { uc($customhost{$a}[0]) cmp uc($customhost{$b}[0])|| $a <=> $b } keys %customhost) {
1365 if ( ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'}) && $fwhostsettings{'HOSTNAME'} eq $customhost{$key}[0]) {
1366 print" <tr bgcolor='${Header::colouryellow}'>";
1367 }elsif ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";}
1368 else{ print" <tr bgcolor='$color{'color20'}'>";}
1369 my ($ip,$sub)=split(/\//,$customhost{$key}[2]);
1370 print<<END;
1371 <td width='40%'><form method='post'>$customhost{$key}[0]</td><td width='50%'>$ip</td><td align='center'>$customhost{$key}[3]x</td>
1372 <td width='1%'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} />
1373 <input type='hidden' name='ACTION' value='edithost' />
1374 <input type='hidden' name='HOSTNAME' value='$customhost{$key}[0]' />
1375 <input type='hidden' name='IP' value='$ip' />
1376 <input type='hidden' name='type' value='$customhost{$key}[1]' />
1377 </td></form>
1378 END
1379 if($customhost{$key}[3] == '0')
1380 {
1381 print"<td width='1%'><form method='post'><input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} /><input type='hidden' name='ACTION' value='delhost' /><input type='hidden' name='key' value='$customhost{$key}[0]' /></td></form></tr>";
1382 }else{
1383 print"<td width='1%'></td></tr>";
1384 }
1385 $count++;
1386 }
1387 print"</table>";
1388 &Header::closebox();
1389 }
1390 }
1391 sub viewtablegrp
1392 {
1393 if(! -z "$configgrp"){
1394 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust grp'});
1395 &General::readhasharray("$configgrp", \%customgrp);
1396 &General::readhasharray("$configipsec", \%ipsecconf);
1397 &General::readhasharray("$configccdhost", \%ccdhost);
1398 &General::readhasharray("$configccdnet", \%ccdnet);
1399 &General::readhasharray("$confighost", \%customhost);
1400 &General::readhasharray("$confignet", \%customnetwork);
1401 my @grp=();
1402 my $helper='';
1403 my $count=0;
1404 my $grpname;
1405 my $remark;
1406 my $number=keys %customgrp;
1407 if (!keys %customgrp)
1408 {
1409 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1410 }else{
1411 foreach my $key (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } sort { uc($customgrp{$a}[2]) cmp uc($customgrp{$b}[2]) } keys %customgrp){
1412
1413 $count++;
1414 if ($helper ne $customgrp{$key}[0]){
1415 $grpname=$customgrp{$key}[0];
1416 $remark=$customgrp{$key}[1];
1417 if($count >=2){print"</table>";}
1418 print "<br><b><u>$grpname</u></b> &nbsp &nbsp";
1419 print " <b>$Lang::tr{'remark'}:</b>&nbsp $remark &nbsp " if ($remark ne '');
1420 print "<b>$Lang::tr{'used'}:</b> $customgrp{$key}[4]x";
1421 if($customgrp{$key}[4] == '0')
1422 {
1423 print"<form method='post' style='display:inline'><input type='image' src='/images/delete.gif' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} align='right' /><input type='hidden' name='grp_name' value='$grpname' ><input type='hidden' name='ACTION' value='delgrp'></form>";
1424 }
1425 print"<form method='post' style='display:inline'><input type='image' src='/images/edit.gif' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} align='right' /><input type='hidden' name='grp_name' value='$grpname' ><input type='hidden' name='remark' value='$remark' ><input type='hidden' name='ACTION' value='editgrp'></form>";
1426 print"<table width='100%' style='border: 1px solid #000000;' rules='none' ><tr><td align='center'><b>Name</b></td><td align='center'><b>$Lang::tr{'ip address'}</b></td><td align='center' width='25%'><b>$Lang::tr{'fwhost type'}</td></tr>";
1427 }
1428 if ( ($fwhostsettings{'ACTION'} eq 'editgrp' || $fwhostsettings{'update'} ne '') && $fwhostsettings{'grp_name'} eq $customgrp{$key}[0]) {
1429 print" <tr bgcolor='${Header::colouryellow}'>";
1430 }elsif ($count %2 == 0){print"<tr bgcolor='$color{'color22'}'>";}else{print"<tr bgcolor='$color{'color20'}'>";}
1431 my $ip=&getipforgroup($customgrp{$key}[2],$customgrp{$key}[3]);
1432 if ($ip eq ''){print"<tr bgcolor='${Header::colouryellow}'>";}
1433
1434
1435 print "<td width='39%'>";
1436 if($customgrp{$key}[3] eq 'Standard Network'){
1437 print &get_name($customgrp{$key}[2])."</td>";
1438 }else{
1439 print "$customgrp{$key}[2]</td>";
1440 }
1441 if ($ip eq '' && $customgrp{$key}[2] ne $Lang::tr{'fwhost empty'}){
1442 print "<td align='center'>$Lang::tr{'fwhost deleted'}</td><td>$customgrp{$key}[3]</td><td width='1%'><form method='post'>";
1443 }else{
1444 print"<td>$ip</td><td>$customgrp{$key}[3]</td><td width='1%'><form method='post'>";
1445 }
1446 if ($number gt '1' && $ip ne ''){
1447 print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />";
1448 }
1449 print"<input type='hidden' name='ACTION' value='deletegrphost'><input type='hidden' name='delhost' value='$grpname,$remark,$customgrp{$key}[2],$customgrp{$key}[3]'></form></td></tr>";
1450
1451 $helper=$customgrp{$key}[0];
1452 }
1453 print"</table>";
1454
1455 }
1456 &Header::closebox();
1457 }
1458
1459 }
1460 sub viewtableservice
1461 {
1462 my $count=0;
1463 if(! -z "$configsrv")
1464 {
1465 &Header::openbox('100%', 'left', $Lang::tr{'fwhost services'});
1466 &General::readhasharray("$configsrv", \%customservice);
1467 print<<END;
1468 <table width='100%' border='0'>
1469 <tr><td align='center'><b>$Lang::tr{'fwhost srv_name'}</td><td align='center'><b>$Lang::tr{'fwhost prot'}</td><td align='center'><b>$Lang::tr{'fwhost port'}</td><td align='center'><b>ICMP</td><td align='center'><b>$Lang::tr{'fwhost used'}</td><td></td><td width='3%'></td></tr>
1470 END
1471 foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0])|| $a <=> $b } keys %customservice)
1472 {
1473 $count++;
1474 if ( ($fwhostsettings{'updatesrv'} eq 'on' || $fwhostsettings{'error'}) && $fwhostsettings{'SRV_NAME'} eq $customservice{$key}[0]) {
1475 print" <tr bgcolor='${Header::colouryellow}'>";
1476 }elsif ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";}else{ print" <tr bgcolor='$color{'color20'}'>";}
1477 print<<END;
1478 <td>$customservice{$key}[0]</td><td align='center'>$customservice{$key}[2]</td><td align='center'>$customservice{$key}[1]</td><td align='center'>
1479 END
1480 if($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];}
1481
1482 print<<END;
1483 </td><td align='center'>$customservice{$key}[4]x</td>
1484 <td width='1%'><form method='post'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} /><input type='hidden' name='ACTION' value='editservice' />
1485 <input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]' />
1486 <input type='hidden' name='SRV_PORT' value='$customservice{$key}[1]' />
1487 <input type='hidden' name='PROT' value='$customservice{$key}[2]' /></form></td>
1488 END
1489 if ($customservice{$key}[4] eq '0')
1490 {
1491 print"<td width='1%'><form method='post'><input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} /><input type='hidden' name='ACTION' value='delservice' /><input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]'></td></tr></form>";
1492 }else{
1493 print"<td></td></tr>";
1494 }
1495 }
1496 print"</table>";
1497 &Header::closebox();
1498 }
1499 }
1500 sub viewtableservicegrp
1501 {
1502 my $count=0;
1503 my $grpname;
1504 my $remark;
1505 my $helper;
1506 my $port;
1507 my $protocol;
1508 if (! -z $configsrvgrp){
1509 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'});
1510 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1511 &General::readhasharray("$configsrv", \%customservice);
1512 my $number= keys %customservicegrp;
1513 foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0])|| $a <=> $b } keys %customservicegrp){
1514 $count++;
1515 if ($helper ne $customservicegrp{$key}[0]){
1516 $grpname=$customservicegrp{$key}[0];
1517 $remark=$customservicegrp{$key}[1];
1518 if($count >=2){print"</table>";}
1519 print "<br><b><u>$grpname</u></b> &nbsp &nbsp ";
1520 print "<b>$Lang::tr{'remark'}:</b>&nbsp $remark " if ($remark ne '');
1521 print "&nbsp <b>$Lang::tr{'used'}:</b> $customservicegrp{$key}[3]x";
1522 if($customservicegrp{$key}[3] == '0')
1523 {
1524 print"<form method='post' style='display:inline'><input type='image' src='/images/delete.gif' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} align='right' /><input type='hidden' name='SRVGRP_NAME' value='$grpname' ><input type='hidden' name='ACTION' value='delservicegrp'></form>";
1525 }
1526 print"<form method='post' style='display:inline'><input type='image' src='/images/edit.gif' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} align='right' /><input type='hidden' name='SRVGRP_NAME' value='$grpname' ><input type='hidden' name='SRVGRP_REMARK' value='$remark' ><input type='hidden' name='ACTION' value='editservicegrp'></form>";
1527 print"<table width='100%' style='border: 1px solid #000000;' rules='none' ><tr><td align='center'><b>Name</b></td><td align='center'><b>$Lang::tr{'port'}</b></td><td align='center' width='25%'><b>$Lang::tr{'fwhost prot'}</td></tr>";
1528 }
1529 if( $fwhostsettings{'SRVGRP_NAME'} eq $customservicegrp{$key}[0]) {
1530 print" <tr bgcolor='${Header::colouryellow}'>";
1531 }
1532 if ($count %2 == 0){
1533 print"<tr bgcolor='$color{'color22'}'>";
1534 }else{
1535 print"<tr bgcolor='$color{'color20'}'>";
1536 }
1537 print "<td width='39%'>$customservicegrp{$key}[2]</td>";
1538 foreach my $srv (sort keys %customservice){
1539 if ($customservicegrp{$key}[2] eq $customservice{$srv}[0]){
1540 $protocol=$customservice{$srv}[2];
1541 $port=$customservice{$srv}[1];
1542 last;
1543 }
1544 }
1545 print"<td align='center'>$port</td><td align='center'>$protocol</td><td width='1%'><form method='post'>";
1546 if ($number gt '1'){
1547 print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />";
1548 }
1549 print"<input type='hidden' name='ACTION' value='delgrpservice'><input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2],$customservicegrp{$key}[3]'></form></td></tr>";
1550 $helper=$customservicegrp{$key}[0];
1551 }
1552 print"</table>";
1553 &Header::closebox();
1554 }
1555 }
1556 # Check
1557 sub checkname
1558 {
1559 my %hash=%{(shift)};
1560 foreach my $key (keys %hash) {
1561 if($hash{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
1562 return 0;
1563 }
1564 }
1565 return 1;
1566
1567 }
1568 sub checkip
1569 {
1570
1571 my %hash=%{(shift)};
1572 my $a=shift;
1573 foreach my $key (keys %hash) {
1574 if($hash{$key}[$a] eq $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'})){
1575 return 0;
1576 }
1577 }
1578 return 1;
1579 }
1580 sub checksubnet
1581 {
1582
1583 my %hash=%{(shift)};
1584 &General::readhasharray("$confignet", \%hash);
1585 foreach my $key (keys %hash) {
1586 if(&General::IpInSubnet($fwhostsettings{'IP'},$hash{$key}[1],$hash{$key}[2]))
1587 {
1588 return 1;
1589 }
1590 }
1591 return 0;
1592 }
1593 sub checkservicegroup
1594 {
1595 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1596
1597
1598 #check name
1599 if ( ! &validhostname($fwhostsettings{'SRVGRP_NAME'}))
1600 {
1601 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1602 return $errormessage;
1603 }
1604 #check remark
1605 if ( ($fwhostsettings{'SRVGRP_REMARK'} ne '') && (! &validhostname($fwhostsettings{'SRVGRP_REMARK'})))
1606 {
1607 $errormessage.=$Lang::tr{'fwhost err remark'}."<br>";
1608 }
1609 #check empty selectbox
1610 if (keys %customservice lt 1)
1611 {
1612 $errormessage.=$Lang::tr{'fwhost err groupempty'}."<br>";
1613 }
1614 #check if name already exists
1615 if ($fwhostsettings{'updatesrvgrp'} ne 'on'){
1616 foreach my $key (keys %customservicegrp) {
1617 if( $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} ){
1618 $errormessage.=$Lang::tr{'fwhost err grpexist'}."<br>";
1619
1620 }
1621 }
1622 }
1623 #check if service already exists in group
1624 foreach my $key (keys %customservicegrp) {
1625 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[2] eq $fwhostsettings{'CUST_SRV'} ){
1626 $errormessage.=$Lang::tr{'fwhost err srvexist'}."<br>";
1627 }
1628 }
1629 return $errormessage;
1630 }
1631 sub error
1632 {
1633 if ($errormessage) {
1634 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1635 print "<class name='base'>$errormessage\n";
1636 print "&nbsp;</class>\n";
1637 &Header::closebox();
1638 }
1639 }
1640 sub hint
1641 {
1642 if ($hint) {
1643 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
1644 print "<class name='base'>$hint\n";
1645 print "&nbsp;</class>\n";
1646 &Header::closebox();
1647 }
1648 }
1649 sub get_name
1650 {
1651 my $val=shift;
1652 &General::setup_default_networks(\%defaultNetworks);
1653 foreach my $network (sort keys %defaultNetworks)
1654 {
1655 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1656 }
1657 }
1658 sub deletefromgrp
1659 {
1660 my $target=shift;
1661 my $config=shift;
1662 my %hash=();
1663 &General::readhasharray("$config",\%hash);
1664 foreach my $key (keys %hash) {
1665 $errormessage.="lese $hash{$key}[2] und $target<br>";
1666 if($hash{$key}[2] eq $target){
1667
1668 delete $hash{$key};
1669 $errormessage.="Habe $target aus Gruppe gelöscht!<br>";
1670 }
1671 }
1672 &General::writehasharray("$config",\%hash);
1673
1674 }
1675 sub plausicheck
1676 {
1677
1678 my $edit=shift;
1679 #check hostname
1680 if (!&General::validhostname($fwhostsettings{'HOSTNAME'}))
1681 {
1682 $errormessage=$errormessage.$Lang::tr{'fwhost err name'};
1683 $fwhostsettings{'BLK_IP'}='readonly';
1684 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
1685 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1686 }
1687 #check if name collides with CCD Netname
1688
1689 &General::readhasharray("$configccdnet", \%ccdnet);
1690 foreach my $key (keys %ccdnet) {
1691 if($ccdnet{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
1692 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdnet'};;
1693 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
1694 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1695 last;
1696 }
1697 }
1698
1699 #check if IP collides with CCD NetIP
1700 if ($fwhostsettings{'type'} ne 'mac'){
1701 &General::readhasharray("$configccdnet", \%ccdnet);
1702 foreach my $key (keys %ccdnet) {
1703 my $test=(&General::getnetworkip($fwhostsettings{'IP'},&General::iporsubtocidr($fwhostsettings{'SUBNET'})))."/".$fwhostsettings{'SUBNET'};
1704 if($ccdnet{$key}[1] eq $test){
1705 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdipnet'};
1706 $fwhostsettings{'IP'} = $fwhostsettings{'orgip'};
1707 $fwhostsettings{'SUBNET'} = $fwhostsettings{'orgsubnet'};
1708 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1709 last;
1710 }
1711 }
1712 }
1713
1714
1715
1716 #check if name collides with CCD Hostname
1717 &General::readhasharray("$configccdhost", \%ccdhost);
1718 foreach my $key (keys %ccdhost) {
1719 my ($ip,$sub)=split(/\//,$ccdhost{$key}[33]);
1720 if($ip eq $fwhostsettings{'IP'}){
1721 $errormessage=$Lang::tr{'fwhost err isccdiphost'};
1722 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1723 last;
1724 }
1725 }
1726 #check if IP collides with CCD HostIP (only hosts)
1727 if ($edit eq 'edithost')
1728 {
1729 foreach my $key (keys %ccdhost) {
1730 if($ccdhost{$key}[1] eq $fwhostsettings{'HOSTNAME'}){
1731 $errormessage=$Lang::tr{'fwhost err isccdhost'};
1732 $fwhostsettings{'IP'} = $fwhostsettings{'orgname'};
1733 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1734 last;
1735 }
1736 }
1737 }
1738 #check if network with this name already exists
1739 &General::readhasharray("$confignet", \%customnetwork);
1740 if (!&checkname(\%customnetwork))
1741 {
1742 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err netexist'};
1743 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
1744 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1745 }
1746 #check if network ip already exists
1747 if (!&checkip(\%customnetwork,1))
1748 {
1749 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err net'};
1750 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1751 }
1752 #check if host with this name already exists
1753 &General::readhasharray("$confighost", \%customhost);
1754 if (!&checkname(\%customhost))
1755 {
1756 $errormessage.="<br>".$Lang::tr{'fwhost err hostexist'};
1757 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
1758 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1759 }
1760 #check if host with this ip already exists
1761 if (!&checkip(\%customhost,2))
1762 {
1763 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err ipcheck'};
1764 }
1765
1766
1767 return;
1768 }
1769 sub getipforgroup
1770 {
1771 my $name=$_[0],
1772 my $type=$_[1];
1773 my $value;
1774
1775 #get address from IPSEC NETWORK
1776 if ($type eq 'IpSec Network'){
1777 foreach my $key (keys %ipsecconf) {
1778 if ($ipsecconf{$key}[1] eq $name){
1779 return $ipsecconf{$key}[11];
1780 }
1781 }
1782 &deletefromgrp($name,$configgrp);
1783 }
1784
1785 #get address from IPSEC HOST
1786 if ($type eq 'IpSec Host'){
1787 foreach my $key (keys %ipsecconf) {
1788 if ($ipsecconf{$key}[1] eq $name){
1789 return $ipsecconf{$key}[10];
1790 }
1791 }
1792 &deletefromgrp($name,$configgrp);
1793 }
1794
1795 #get address from ovpn ccd Net-2-Net
1796 if ($type eq 'OpenVPN N-2-N'){
1797 foreach my $key (keys %ccdhost) {
1798 if($ccdhost{$key}[1] eq $name){
1799 my ($a,$b) = split ("/",$ccdhost{$key}[11]);
1800 $b=&General::iporsubtodec($b);
1801 return "$a/$b";
1802 }
1803 }
1804 &deletefromgrp($name,$configgrp);
1805 }
1806
1807 #get address from ovpn ccd static host
1808 if ($type eq 'OpenVPN static host'){
1809 foreach my $key (keys %ccdhost) {
1810 if($ccdhost{$key}[1] eq $name){
1811 my ($a,$b) = split (/\//,$ccdhost{$key}[33]);
1812 $b=&General::iporsubtodec($b);
1813 return "$a/$b";
1814 }
1815 }
1816 &deletefromgrp($name,$configgrp);
1817 }
1818
1819 #get address from ovpn ccd static net
1820 if ($type eq 'OpenVPN static network'){
1821 foreach my $key (keys %ccdnet) {
1822 if ($ccdnet{$key}[0] eq $name){
1823 my ($a,$b) = split (/\//,$ccdnet{$key}[1]);
1824 $b=&General::iporsubtodec($b);
1825 return "$a/$b";
1826 }
1827 }
1828 }
1829
1830 #check custom addresses
1831 if ($type eq 'Custom Host'){
1832 foreach my $key (keys %customhost) {
1833 if ($customhost{$key}[0] eq $name){
1834 return $customhost{$key}[2];
1835 }
1836 }
1837 }
1838
1839 ##check custom networks
1840 if ($type eq 'Custom Network'){
1841 foreach my $key (keys %customnetwork) {
1842 if($customnetwork{$key}[0] eq $name){
1843 return $customnetwork{$key}[1]."/".$customnetwork{$key}[2];
1844 }
1845 }
1846 }
1847
1848 #check standard networks
1849 if ($type eq 'Standard Network'){
1850 if ($name =~ /OpenVPN/i){
1851 my %ovpn=();
1852 &General::readhash("${General::swroot}/ovpn/settings",\%ovpn);
1853 return $ovpn{'DOVPN_SUBNET'};
1854 }
1855 if ($name eq 'GREEN'){
1856 my %hash=();
1857 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
1858 return $hash{'GREEN_NETADDRESS'}."/".$hash{'GREEN_NETMASK'};
1859 }
1860 if ($name eq 'BLUE'){
1861 my %hash=();
1862 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
1863 return $hash{'BLUE_NETADDRESS'}."/".$hash{'BLUE_NETMASK'};
1864 }
1865 if ($name eq 'ORANGE'){
1866 my %hash=();
1867 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
1868 return $hash{'ORANGE_NETADDRESS'}."/".$hash{'ORANGE_NETMASK'};
1869 }
1870 if ($name eq 'ALL'){
1871 return "0.0.0.0/0.0.0.0";
1872 }
1873 if ($name =~ /IPsec/i){
1874 my %hash=();
1875 &General::readhash("${General::swroot}/vpn/settings",\%hash);
1876 return $hash{'RW_NET'};
1877 }
1878 }
1879 }
1880 sub rules
1881 {
1882 system ("/usr/local/bin/forwardfwctrl");
1883 system("rm ${General::swroot}/forward/reread");
1884 }
1885 sub decrease
1886 {
1887 my $grp=$_[0];
1888 &General::readhasharray("$confignet", \%customnetwork);
1889 &General::readhasharray("$confighost", \%customhost);
1890 foreach my $key (sort keys %customgrp ){
1891 if ( ($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Network')){
1892 foreach my $key1 (sort keys %customnetwork){
1893 if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){
1894 $customnetwork{$key1}[3]=$customnetwork{$key1}[3]-1;
1895 last;
1896 }
1897 }
1898 }
1899
1900 if (($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Host')){
1901 foreach my $key2 (sort keys %customhost){
1902 if ($customhost{$key2}[0] eq $customgrp{$key}[2]){
1903 $customhost{$key2}[3]=$customhost{$key2}[3]-1;
1904 last;
1905 }
1906 }
1907
1908 }
1909 }
1910 &General::writehasharray("$confignet", \%customnetwork);
1911 &General::writehasharray("$confighost", \%customhost);
1912 }
1913 sub decreaseservice
1914 {
1915 my $grp=$_[0];
1916 &General::readhasharray("$configsrv", \%customservice);
1917 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1918
1919 foreach my $key (sort keys %customservicegrp){
1920 if ($customservicegrp{$key}[0] eq $grp ){
1921 foreach my $key2 (sort keys %customservice){
1922 if ($customservice{$key2}[0] eq $customservicegrp{$key}[2]){
1923 $customservice{$key2}[4]--;
1924 }
1925 }
1926 }
1927 }
1928 &General::writehasharray("$configsrv", \%customservice);
1929
1930 }
1931 sub checkports
1932 {
1933
1934 my %hash=%{(shift)};
1935 #check empty fields
1936 if ($fwhostsettings{'SRV_NAME'} eq '' ){
1937 $errormessage=$Lang::tr{'fwhost err name1'};
1938 }
1939 if ($fwhostsettings{'SRV_PORT'} eq '' && $fwhostsettings{'PROT'} ne 'ICMP'){
1940 $errormessage=$Lang::tr{'fwhost err port'};
1941 }
1942 #check valid name
1943 if (! &validhostname($fwhostsettings{'SRV_NAME'})){
1944 $errormessage="<br>".$Lang::tr{'fwhost err name'};
1945 }
1946 #change dashes with :
1947 $fwhostsettings{'SRV_PORT'}=~ tr/-/:/;
1948
1949 if ($fwhostsettings{'SRV_PORT'} eq "*") {
1950 $fwhostsettings{'SRV_PORT'} = "1:65535";
1951 }
1952 if ($fwhostsettings{'SRV_PORT'} =~ /^(\D)\:(\d+)$/) {
1953 $fwhostsettings{'SRV_PORT'} = "1:$2";
1954 }
1955 if ($fwhostsettings{'SRV_PORT'} =~ /^(\d+)\:(\D)$/) {
1956 $fwhostsettings{'SRV_PORT'} = "$1:65535";
1957 }
1958 if($fwhostsettings{'PROT'} ne 'ICMP'){
1959 $errormessage = $errormessage.&General::validportrange($fwhostsettings{'SRV_PORT'}, 'src');
1960 }
1961 # a new service has to have a different name
1962 foreach my $key (keys %hash){
1963 if ($hash{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
1964 $errormessage = "<br>".$Lang::tr{'fwhost err srv exists'};
1965 last;
1966 }
1967 }
1968 return $errormessage;
1969 }
1970 sub validhostname
1971 {
1972 # Checks a hostname against RFC1035
1973 my $hostname = $_[0];
1974
1975 # Each part should be at least two characters in length
1976 # but no more than 63 characters
1977 if (length ($hostname) < 1 || length ($hostname) > 63) {
1978 return 0;}
1979 # Only valid characters are a-z, A-Z, 0-9 and -
1980 if ($hostname !~ /^[a-zA-ZäöüÖÄÜ0-9-_()\/\s]*$/) {
1981 return 0;}
1982 # First character can only be a letter or a digit
1983 if (substr ($hostname, 0, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) {
1984 return 0;}
1985 # Last character can only be a letter or a digit
1986 if (substr ($hostname, -1, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9()]*$/) {
1987 return 0;}
1988 return 1;
1989 }
1990
1991 &Header::closebigbox();
1992 &Header::closepage();