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