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