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