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