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