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