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