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