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