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