dnsmasq: Import more patches from upstream
[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
26 use Sort::Naturally;
27 use CGI::Carp 'fatalsToBrowser';
28 no warnings 'uninitialized';
29 require '/var/ipfire/general-functions.pl';
30 require "${General::swroot}/lang.pl";
31 require "${General::swroot}/header.pl";
32
33 my %fwhostsettings=();
34 my %customnetwork=();
35 my %customhost=();
36 my %customgrp=();
37 my %customservice=();
38 my %customservicegrp=();
39 my %ccdnet=();
40 my %ccdhost=();
41 my %ipsecconf=();
42 my %icmptypes=();
43 my %color=();
44 my %defaultNetworks=();
45 my %mainsettings=();
46 my %ownnet=();
47 my %ipsecsettings=();
48 my %fwfwd=();
49 my %fwinp=();
50 my %fwout=();
51 my %ovpnsettings=();
52 my %netsettings=();
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}/firewall/config";
66 my $fwconfiginp = "${General::swroot}/firewall/input";
67 my $fwconfigout = "${General::swroot}/firewall/outgoing";
68 my $configovpn = "${General::swroot}/ovpn/settings";
69 my $configipsecrw = "${General::swroot}/vpn/settings";
70
71 unless (-e $confignet) { system("touch $confignet"); }
72 unless (-e $confighost) { system("touch $confighost"); }
73 unless (-e $configgrp) { system("touch $configgrp"); }
74 unless (-e $configsrv) { system("touch $configsrv"); }
75 unless (-e $configsrvgrp) { system("touch $configsrvgrp"); }
76
77 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
78 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
79 &General::readhash("${General::swroot}/ethernet/settings", \%ownnet);
80 &General::readhash("$configovpn", \%ovpnsettings);
81 &General::readhasharray("$configipsec", \%ipsecconf);
82 &General::readhash("$configipsecrw", \%ipsecsettings);
83 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
84 &Header::getcgihash(\%fwhostsettings);
85
86 &Header::showhttpheaders();
87 &Header::openpage($Lang::tr{'fwhost menu'}, 1, '');
88 &Header::openbigbox('100%', 'center');
89
90 #### JAVA SCRIPT ####
91 print<<END;
92 <script>
93 var PROTOCOLS_WITH_PORTS = ["TCP", "UDP"];
94 var update_protocol = function() {
95 var protocol = \$("#protocol").val();
96
97 if (protocol === undefined)
98 return;
99
100 // Check if we are dealing with a protocol, that knows ports.
101 if (\$.inArray(protocol, PROTOCOLS_WITH_PORTS) >= 0) {
102 \$("#PORT").show();
103 \$("#PROTOKOLL").hide();
104 } else {
105 \$("#PORT").hide();
106 \$("#PROTOKOLL").show();
107 }
108 };
109
110 \$(document).ready(function() {
111 var protocol = \$("#protocol").val();
112 \$("#protocol").change(update_protocol);
113 update_protocol();
114 // Automatically select radio buttons when corresponding
115 // dropdown menu changes.
116 \$("select").change(function() {
117 var id = \$(this).attr("name");
118 \$('#' + id).prop("checked", true);
119 });
120 });
121 </script>
122 END
123
124 ## ACTION ####
125 # Update
126 if ($fwhostsettings{'ACTION'} eq 'updatenet' )
127 {
128 &General::readhasharray("$confignet", \%customnetwork);
129 foreach my $key (keys %customnetwork)
130 {
131 if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'})
132 {
133 $fwhostsettings{'orgname'} = $customnetwork{$key}[0];
134 $fwhostsettings{'orgip'} = $customnetwork{$key}[1];
135 $fwhostsettings{'orgsub'} = $customnetwork{$key}[2];
136 $fwhostsettings{'netremark'} = $customnetwork{$key}[3];
137 $fwhostsettings{'count'} = $customnetwork{$key}[4];
138 delete $customnetwork{$key};
139
140 }
141 }
142 &General::writehasharray("$confignet", \%customnetwork);
143 $fwhostsettings{'actualize'} = 'on';
144 $fwhostsettings{'ACTION'} = 'savenet';
145 }
146 if ($fwhostsettings{'ACTION'} eq 'updatehost')
147 {
148 my ($ip,$subnet);
149 &General::readhasharray("$confighost", \%customhost);
150 foreach my $key (keys %customhost)
151 {
152 if($customhost{$key}[0] eq $fwhostsettings{'orgname'})
153 {
154 if ($customhost{$key}[1] eq 'ip'){
155 ($ip,$subnet) = split (/\//,$customhost{$key}[2]);
156 }else{
157 $ip = $customhost{$key}[2];
158 }
159 $fwhostsettings{'orgip'} = $ip;
160 $fwhostsettings{'count'} = $customhost{$key}[4];
161 delete $customhost{$key};
162 &General::writehasharray("$confighost", \%customhost);
163 }
164 }
165 $fwhostsettings{'actualize'} = 'on';
166 if($fwhostsettings{'orgip'}){
167 $fwhostsettings{'ACTION'} = 'savehost';
168 }else{
169 $fwhostsettings{'ACTION'} = $Lang::tr{'fwhost newhost'};
170 }
171 }
172 if ($fwhostsettings{'ACTION'} eq 'updateservice')
173 {
174 my $count=0;
175 my $needrules=0;
176 $errormessage=&checkports(\%customservice);
177 if ($fwhostsettings{'oldsrvname'} ne $fwhostsettings{'SRV_NAME'} && !&checkgroup($fwhostsettings{'SRV_NAME'})){
178 $errormessage=$Lang::tr{'fwhost err grpexist'};
179 }
180 if (!$errormessage){
181 &General::readhasharray("$configsrv", \%customservice);
182 foreach my $key (keys %customservice)
183 {
184 if ($customservice{$key}[0] eq $fwhostsettings{'oldsrvname'})
185 {
186 delete $customservice{$key};
187 &General::writehasharray("$configsrv", \%customservice);
188 last;
189 }
190 }
191 if ($fwhostsettings{'PROT'} ne 'ICMP'){
192 $fwhostsettings{'ICMP_TYPES'}='BLANK';
193 }
194 my $key1 = &General::findhasharraykey(\%customservice);
195 #find out short ICMP-TYPE
196 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
197 foreach my $key (keys %icmptypes){
198 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwhostsettings{'ICMP_TYPES'}){
199 $fwhostsettings{'ICMP_TYPES'}=$icmptypes{$key}[0];
200 }
201 }
202 foreach my $i (0 .. 4) { $customservice{$key1}[$i] = "";}
203 $customservice{$key1}[0] = $fwhostsettings{'SRV_NAME'};
204 $customservice{$key1}[1] = $fwhostsettings{'SRV_PORT'};
205 $customservice{$key1}[2] = $fwhostsettings{'PROT'};
206 $customservice{$key1}[3] = $fwhostsettings{'ICMP_TYPES'};
207 &General::writehasharray("$configsrv", \%customservice);
208 #check if we need to update firewallrules
209 if ($fwhostsettings{'SRV_NAME'} ne $fwhostsettings{'oldsrvname'}){
210 if ( ! -z $fwconfigfwd ){
211 &General::readhasharray("$fwconfigfwd", \%fwfwd);
212 foreach my $key (sort keys %fwfwd){
213 if ($fwfwd{$key}[15] eq $fwhostsettings{'oldsrvname'}){
214 $fwfwd{$key}[15] = $fwhostsettings{'SRV_NAME'};
215 }
216 }
217 &General::writehasharray("$fwconfigfwd", \%fwfwd);
218 }
219 if ( ! -z $fwconfiginp ){
220 &General::readhasharray("$fwconfiginp", \%fwinp);
221 foreach my $line (sort keys %fwinp){
222 if ($fwfwd{$line}[15] eq $fwhostsettings{'oldsrvname'}){
223 $fwfwd{$line}[15] = $fwhostsettings{'SRV_NAME'};
224 }
225 }
226 &General::writehasharray("$fwconfiginp", \%fwinp);
227 }
228 if ( ! -z $fwconfigout ){
229 &General::readhasharray("$fwconfigout", \%fwout);
230 foreach my $line (sort keys %fwout){
231 if ($fwout{$line}[15] eq $fwhostsettings{'oldsrvname'}){
232 $fwout{$line}[15] = $fwhostsettings{'SRV_NAME'};
233 }
234 }
235 &General::writehasharray("$fwconfigout", \%fwout);
236 }
237 #check if we need to update groups
238 &General::readhasharray("$configsrvgrp", \%customservicegrp);
239 foreach my $key (sort keys %customservicegrp){
240 if($customservicegrp{$key}[2] eq $fwhostsettings{'oldsrvname'}){
241 $customservicegrp{$key}[2] = $fwhostsettings{'SRV_NAME'};
242 &checkrulereload($customservicegrp{$key}[0]);
243 }
244 }
245 &General::writehasharray("$configsrvgrp", \%customservicegrp);
246 }
247 &checkrulereload($fwhostsettings{'SRV_NAME'});
248 $fwhostsettings{'SRV_NAME'} = '';
249 $fwhostsettings{'SRV_PORT'} = '';
250 $fwhostsettings{'PROT'} = '';
251 $fwhostsettings{'ICMP'} = '';
252 $fwhostsettings{'oldsrvicmp'} = '';
253 $fwhostsettings{'updatesrv'} = '';
254 }else{
255 $fwhostsettings{'SRV_NAME'} = $fwhostsettings{'oldsrvname'};
256 $fwhostsettings{'SRV_PORT'} = $fwhostsettings{'oldsrvport'};
257 $fwhostsettings{'PROT'} = $fwhostsettings{'oldsrvprot'};
258 $fwhostsettings{'ICMP'} = $fwhostsettings{'oldsrvicmp'};
259 $fwhostsettings{'updatesrv'}= 'on';
260 }
261 &addservice;
262 }
263 # save
264 if ($fwhostsettings{'ACTION'} eq 'savenet' )
265 {
266 my $needrules=0;
267 if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
268 #check if all fields are set
269 if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
270 {
271 $errormessage=$errormessage.$Lang::tr{'fwhost err empty'};
272 &addnet;
273 &viewtablenet;
274 }else{
275 #check valid ip
276 if (!&General::validipandmask($fwhostsettings{'IP'}."/".$fwhostsettings{'SUBNET'}))
277 {
278 $errormessage=$errormessage.$Lang::tr{'fwhost err addr'};
279 $fwhostsettings{'BLK_HOST'} ='readonly';
280 $fwhostsettings{'NOCHECK'} ='false';
281 $fwhostsettings{'error'} ='on';
282 }
283 #check remark
284 if ($fwhostsettings{'NETREMARK'} ne '' && !&validremark($fwhostsettings{'NETREMARK'})){
285 $errormessage=$Lang::tr{'fwhost err remark'};
286 $fwhostsettings{'error'} ='on';
287 }
288 #check if subnet is sigle host
289 if(&General::iporsubtocidr($fwhostsettings{'SUBNET'}) eq '32')
290 {
291 $errormessage=$errormessage.$Lang::tr{'fwhost err sub32'};
292 }
293 if($fwhostsettings{'error'} ne 'on'){
294 my $fullip="$fwhostsettings{'IP'}/".&General::iporsubtocidr($fwhostsettings{'SUBNET'});
295 $errormessage=$errormessage.&General::checksubnets($fwhostsettings{'HOSTNAME'},$fullip,"");
296 }
297 #only check plausi when no error till now
298 if (!$errormessage){
299 &plausicheck("editnet");
300 }
301 if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newnet'} ne 'on' && $errormessage)
302 {
303 $fwhostsettings{'actualize'} = '';
304 my $key = &General::findhasharraykey (\%customnetwork);
305 foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";}
306 $customnetwork{$key}[0] = $fwhostsettings{'orgname'} ;
307 $customnetwork{$key}[1] = $fwhostsettings{'orgip'} ;
308 $customnetwork{$key}[2] = $fwhostsettings{'orgsub'};
309 $customnetwork{$key}[3] = $fwhostsettings{'orgnetremark'};
310 &General::writehasharray("$confignet", \%customnetwork);
311 undef %customnetwork;
312 }
313 if (!$errormessage){
314 &General::readhasharray("$confignet", \%customnetwork);
315 if ($fwhostsettings{'ACTION'} eq 'updatenet'){
316 if ($fwhostsettings{'update'} == '0'){
317 foreach my $key (keys %customnetwork) {
318 if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'}){
319 delete $customnetwork{$key};
320 last;
321 }
322 }
323 }
324 }
325 #get count if actualize is 'on'
326 if($fwhostsettings{'actualize'} eq 'on'){
327 $fwhostsettings{'actualize'} = '';
328 #check if we need to reload rules
329 if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'}){
330 $needrules='on';
331 }
332 if ($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){
333 #check if we need to update groups
334 &General::readhasharray("$configgrp", \%customgrp);
335 foreach my $key (sort keys %customgrp){
336 if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){
337 $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'};
338 last;
339 }
340 }
341 &General::writehasharray("$configgrp", \%customgrp);
342 #check if we need to update firewallrules
343 if ( ! -z $fwconfigfwd ){
344 &General::readhasharray("$fwconfigfwd", \%fwfwd);
345 foreach my $line (sort keys %fwfwd){
346 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
347 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
348 }
349 if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){
350 $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'};
351 }
352 }
353 &General::writehasharray("$fwconfigfwd", \%fwfwd);
354 }
355 if ( ! -z $fwconfiginp ){
356 &General::readhasharray("$fwconfiginp", \%fwinp);
357 foreach my $line (sort keys %fwinp){
358 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
359 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
360 }
361 }
362 &General::writehasharray("$fwconfiginp", \%fwinp);
363 }
364 }
365 }
366 my $key = &General::findhasharraykey (\%customnetwork);
367 foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";}
368 $fwhostsettings{'SUBNET'} = &General::iporsubtocidr($fwhostsettings{'SUBNET'});
369 $customnetwork{$key}[0] = $fwhostsettings{'HOSTNAME'};
370 #convert ip when leading '0' in byte
371 $fwhostsettings{'IP'} =&General::ip2dec($fwhostsettings{'IP'});
372 $fwhostsettings{'IP'} =&General::dec2ip($fwhostsettings{'IP'});
373 $customnetwork{$key}[1] = &General::getnetworkip($fwhostsettings{'IP'},$fwhostsettings{'SUBNET'}) ;
374 $customnetwork{$key}[2] = &General::iporsubtodec($fwhostsettings{'SUBNET'}) ;
375 $customnetwork{$key}[3] = $fwhostsettings{'NETREMARK'};
376 &General::writehasharray("$confignet", \%customnetwork);
377 $fwhostsettings{'IP'}=$fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
378 undef %customnetwork;
379 $fwhostsettings{'HOSTNAME'}='';
380 $fwhostsettings{'IP'}='';
381 $fwhostsettings{'SUBNET'}='';
382 $fwhostsettings{'NETREMARK'}='';
383 #check if an edited net affected groups and need to reload rules
384 if ($needrules eq 'on'){
385 &General::firewall_config_changed();
386 }
387 &addnet;
388 &viewtablenet;
389 }else{
390 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
391 &addnet;
392 &viewtablenet;
393 }
394 }
395 }
396 if ($fwhostsettings{'ACTION'} eq 'savehost')
397 {
398 my $needrules=0;
399 if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
400 $fwhostsettings{'SUBNET'}='32';
401 #check if all fields are set
402 if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
403 {
404 $errormessage=$errormessage.$Lang::tr{'fwhost err empty'};
405 $fwhostsettings{'ACTION'} = 'edithost';
406 }else{
407 if($fwhostsettings{'IP'}=~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/){
408 $fwhostsettings{'type'} = 'mac';
409 }elsif($fwhostsettings{'IP'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
410 $fwhostsettings{'type'} = 'ip';
411 }else{
412 $fwhostsettings{'type'} = '';
413 $errormessage=$Lang::tr{'fwhost err ipmac'};
414 }
415 #check remark
416 if ($fwhostsettings{'HOSTREMARK'} ne '' && !&validremark($fwhostsettings{'HOSTREMARK'})){
417 $errormessage=$Lang::tr{'fwhost err remark'};
418 }
419 #CHECK IP-PART
420 if ($fwhostsettings{'type'} eq 'ip'){
421 #check for subnet
422 if (rindex($fwhostsettings{'IP'},'/') eq '-1' ){
423 if($fwhostsettings{'type'} eq 'ip' && !&General::validipandmask($fwhostsettings{'IP'}."/32"))
424 {
425 $errormessage.=$errormessage.$Lang::tr{'fwhost err ip'};
426 $fwhostsettings{'error'}='on';
427 }
428 }elsif(rindex($fwhostsettings{'IP'},'/') ne '-1' ){
429 $errormessage=$errormessage.$Lang::tr{'fwhost err ipwithsub'};
430 $fwhostsettings{'error'}='on';
431 }
432 #check if net or broadcast
433 my @tmp= split (/\./,$fwhostsettings{'IP'});
434 if (($tmp[3] eq "0") || ($tmp[3] eq "255")){
435 $errormessage=$Lang::tr{'fwhost err hostip'};
436 }
437 }
438 #only check plausi when no error till now
439 if (!$errormessage){
440 &plausicheck("edithost");
441 }
442 if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newhost'} ne 'on' && $errormessage){
443 $fwhostsettings{'actualize'} = '';
444 my $key = &General::findhasharraykey (\%customhost);
445 foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";}
446 $customhost{$key}[0] = $fwhostsettings{'orgname'} ;
447 $customhost{$key}[1] = $fwhostsettings{'type'} ;
448 if($customhost{$key}[1] eq 'ip'){
449 $customhost{$key}[2] = $fwhostsettings{'orgip'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
450 }else{
451 $customhost{$key}[2] = $fwhostsettings{'orgip'};
452 }
453 $customhost{$key}[3] = $fwhostsettings{'orgremark'};
454 &General::writehasharray("$confighost", \%customhost);
455 undef %customhost;
456 }
457 if (!$errormessage){
458 #get count if host was edited
459 if($fwhostsettings{'actualize'} eq 'on'){
460 if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'}){
461 $needrules='on';
462 }
463 if($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){
464 #check if we need to update groups
465 &General::readhasharray("$configgrp", \%customgrp);
466 foreach my $key (sort keys %customgrp){
467 if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){
468 $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'};
469 }
470 }
471 &General::writehasharray("$configgrp", \%customgrp);
472 #check if we need to update firewallrules
473 if ( ! -z $fwconfigfwd ){
474 &General::readhasharray("$fwconfigfwd", \%fwfwd);
475 foreach my $line (sort keys %fwfwd){
476 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
477 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
478 }
479 if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){
480 $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'};
481 }
482 }
483 &General::writehasharray("$fwconfigfwd", \%fwfwd);
484 }
485 if ( ! -z $fwconfiginp ){
486 &General::readhasharray("$fwconfiginp", \%fwinp);
487 foreach my $line (sort keys %fwinp){
488 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
489 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
490 }
491 }
492 &General::writehasharray("$fwconfiginp", \%fwinp);
493 }
494 }
495 }
496 my $key = &General::findhasharraykey (\%customhost);
497 foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";}
498 $customhost{$key}[0] = $fwhostsettings{'HOSTNAME'} ;
499 $customhost{$key}[1] = $fwhostsettings{'type'} ;
500 if ($fwhostsettings{'type'} eq 'ip'){
501 #convert ip when leading '0' in byte
502 $fwhostsettings{'IP'}=&General::ip2dec($fwhostsettings{'IP'});
503 $fwhostsettings{'IP'}=&General::dec2ip($fwhostsettings{'IP'});
504 $customhost{$key}[2] = $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
505 }else{
506 $customhost{$key}[2] = $fwhostsettings{'IP'};
507 }
508 $customhost{$key}[3] = $fwhostsettings{'HOSTREMARK'};
509 &General::writehasharray("$confighost", \%customhost);
510 undef %customhost;
511 $fwhostsettings{'HOSTNAME'}='';
512 $fwhostsettings{'IP'}='';
513 $fwhostsettings{'type'}='';
514 $fwhostsettings{'HOSTREMARK'}='';
515 #check if we need to update rules while host was edited
516 if($needrules eq 'on'){
517 &General::firewall_config_changed();
518 }
519 &addhost;
520 &viewtablehost;
521 }else{
522 &addhost;
523 &viewtablehost;
524 }
525 }
526 }
527 if ($fwhostsettings{'ACTION'} eq 'savegrp')
528 {
529 my $grp=$fwhostsettings{'grp_name'};
530 my $rem=$fwhostsettings{'remark'};
531 my $count;
532 my $type;
533 my $updcounter='off';
534 my @target;
535 my @newgrp;
536 &General::readhasharray("$configgrp", \%customgrp);
537 &General::readhasharray("$confignet", \%customnetwork);
538 &General::readhasharray("$confighost", \%customhost);
539 &General::readhasharray("$fwconfigfwd", \%fwfwd);
540 &General::readhasharray("$fwconfiginp", \%fwinp);
541 &General::readhasharray("$fwconfigout", \%fwout);
542 #check name
543 if (!&validhostname($grp)){$errormessage.=$Lang::tr{'fwhost err name'};}
544 #check existing name
545 if (!&checkgroup($grp) && $fwhostsettings{'update'} ne 'on'){$errormessage.=$Lang::tr{'fwhost err grpexist'};}
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 #create array with new lines
647 foreach my $line (@target){
648 push (@newgrp,"$grp,$rem,$line");
649 }
650 #append new entries
651 my $key = &General::findhasharraykey (\%customgrp);
652 foreach my $line (@newgrp){
653 foreach my $i (0 .. 3) { $customgrp{$key}[$i] = "";}
654 my ($a,$b,$c,$d) = split (",",$line);
655 $customgrp{$key}[0] = $a;
656 $customgrp{$key}[1] = $b;
657 $customgrp{$key}[2] = $c;
658 $customgrp{$key}[3] = $type;
659 }
660 &General::writehasharray("$configgrp", \%customgrp);
661 #update counter in Host/Net
662 $fwhostsettings{'update'}='on';
663 }
664 #check if ruleupdate is needed
665 my $netgrpcount=0;
666 $netgrpcount=&getnetcount($grp);
667 if($netgrpcount > 0 )
668 {
669 &General::firewall_config_changed();
670 }
671 &addgrp;
672 &viewtablegrp;
673 }
674 if ($fwhostsettings{'ACTION'} eq 'saveservice')
675 {
676 my $ICMP;
677 &General::readhasharray("$configsrv", \%customservice );
678 &General::readhasharray("$configgrp", \%customgrp);
679 $errormessage=&checkports(\%customservice);
680 if ($fwhostsettings{'PROT'} eq 'ICMP'){
681 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
682 foreach my $key (keys %icmptypes){
683 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwhostsettings{'ICMP_TYPES'}){
684 $ICMP=$icmptypes{$key}[0];
685 }
686 }
687 }
688 if($ICMP eq ''){$ICMP=$fwhostsettings{'ICMP_TYPES'};}
689 if ($fwhostsettings{'PROT'} ne 'ICMP'){$ICMP='BLANK';}
690 #Check if a group with the same name already exists
691 if (!&checkgroup($fwhostsettings{'SRV_NAME'})){
692 $errormessage = $Lang::tr{'fwhost err grpexist'};
693 }
694 if (!$errormessage){
695 my $key = &General::findhasharraykey (\%customservice);
696 foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";}
697 $customservice{$key}[0] = $fwhostsettings{'SRV_NAME'};
698 $customservice{$key}[1] = $fwhostsettings{'SRV_PORT'};
699 $customservice{$key}[2] = $fwhostsettings{'PROT'};
700 $customservice{$key}[3] = $ICMP;
701 &General::writehasharray("$configsrv", \%customservice );
702 #reset fields
703 $fwhostsettings{'SRV_NAME'}='';
704 $fwhostsettings{'SRV_PORT'}='';
705 $fwhostsettings{'PROT'}='';
706 $fwhostsettings{'ICMP_TYPES'}='';
707 }
708 &addservice;
709 }
710 if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
711 {
712 my $prot;
713 my $port;
714 my $tcpcounter=0;
715 my $udpcounter=0;
716 &General::readhasharray("$configsrvgrp", \%customservicegrp );
717 &General::readhasharray("$configsrv", \%customservice );
718 $errormessage=&checkservicegroup;
719 #Check if we have more than 15 services from one Protocol in the group
720 #iptables can only handle 15 ports/portranges via multiport
721 foreach my $key (keys %customservicegrp){
722 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}){
723 foreach my $key1 (keys %customservice){
724 $tcpcounter++ if $customservice{$key1}[2] eq 'TCP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0];
725 $tcpcounter++ if $customservice{$key1}[2] eq 'TCP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0] && $customservice{$key1}[1] =~m/:/i;
726 $udpcounter++ if $customservice{$key1}[2] eq 'UDP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0];
727 $udpcounter++ if $customservice{$key1}[2] eq 'UDP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0] && $customservice{$key1}[1] =~m/:/i;
728 }
729 }
730 }
731 if ($tcpcounter > 14){
732 $errormessage=$Lang::tr{'fwhost err maxservicetcp'};
733 }
734 if ($udpcounter > 14){
735 $errormessage=$Lang::tr{'fwhost err maxserviceudp'};
736 }
737 $tcpcounter=0;
738 $udpcounter=0;
739 #check remark
740 if ($fwhostsettings{'SRVGRP_REMARK'} ne '' && !&validremark($fwhostsettings{'SRVGRP_REMARK'})){
741 $errormessage .= $Lang::tr{'fwhost err remark'};
742 }
743 #Check if there is already a service with the same name
744 if(!&checkservice($fwhostsettings{'SRVGRP_NAME'})){
745 $errormessage .= $Lang::tr{'fwhost err srv exists'};
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' && $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}){
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 my $key = &General::findhasharraykey (\%customservicegrp);
773 foreach my $i (0 .. 2) { $customservice{$key}[$i] = "";}
774 $customservicegrp{$key}[0] = $fwhostsettings{'SRVGRP_NAME'};
775 $customservicegrp{$key}[1] = $fwhostsettings{'SRVGRP_REMARK'};
776 $customservicegrp{$key}[2] = $fwhostsettings{'CUST_SRV'};
777 &General::writehasharray("$configsrvgrp", \%customservicegrp );
778 $fwhostsettings{'updatesrvgrp'}='on';
779 }
780 &checkrulereload($fwhostsettings{'SRVGRP_NAME'});
781 &addservicegrp;
782 &viewtableservicegrp;
783 }
784 # edit
785 if ($fwhostsettings{'ACTION'} eq 'editnet')
786 {
787 &addnet;
788 &viewtablenet;
789 }
790 if ($fwhostsettings{'ACTION'} eq 'edithost')
791 {
792 &addhost;
793 &viewtablehost;
794 }
795 if ($fwhostsettings{'ACTION'} eq 'editgrp')
796 {
797 $fwhostsettings{'update'}='on';
798 &addgrp;
799 &viewtablegrp;
800 }
801 if ($fwhostsettings{'ACTION'} eq 'editservice')
802 {
803 $fwhostsettings{'updatesrv'}='on';
804 &addservice;
805 }
806 if ($fwhostsettings{'ACTION'} eq 'editservicegrp')
807 {
808 $fwhostsettings{'updatesrvgrp'} = 'on';
809 &addservicegrp;
810 &viewtableservicegrp;
811 }
812 # reset
813 if ($fwhostsettings{'ACTION'} eq 'resetnet')
814 {
815 $fwhostsettings{'HOSTNAME'} ="";
816 $fwhostsettings{'IP'} ="";
817 $fwhostsettings{'SUBNET'} ="";
818 &showmenu;
819 }
820 if ($fwhostsettings{'ACTION'} eq 'resethost')
821 {
822 $fwhostsettings{'HOSTNAME'} ="";
823 $fwhostsettings{'IP'} ="";
824 $fwhostsettings{'type'} ="";
825 &showmenu;
826 }
827 if ($fwhostsettings{'ACTION'} eq 'resetgrp')
828 {
829 $fwhostsettings{'grp_name'} ="";
830 $fwhostsettings{'remark'} ="";
831 &showmenu;
832 }
833 # delete
834 if ($fwhostsettings{'ACTION'} eq 'delnet')
835 {
836 &General::readhasharray("$confignet", \%customnetwork);
837 foreach my $key (keys %customnetwork) {
838 if($fwhostsettings{'key'} eq $customnetwork{$key}[0]){
839 delete $customnetwork{$key};
840 &General::writehasharray("$confignet", \%customnetwork);
841 last;
842 }
843 }
844 &addnet;
845 &viewtablenet;
846 }
847 if ($fwhostsettings{'ACTION'} eq 'delhost')
848 {
849 &General::readhasharray("$confighost", \%customhost);
850 foreach my $key (keys %customhost) {
851 if($fwhostsettings{'key'} eq $customhost{$key}[0]){
852 delete $customhost{$key};
853 &General::writehasharray("$confighost", \%customhost);
854 last;
855 }
856 }
857 &addhost;
858 &viewtablehost;
859 }
860 if ($fwhostsettings{'ACTION'} eq 'deletegrphost')
861 {
862 my $grpremark;
863 my $grpname;
864 &General::readhasharray("$configgrp", \%customgrp);
865 foreach my $key (keys %customgrp){
866 if($customgrp{$key}[0].",".$customgrp{$key}[1].",".$customgrp{$key}[2].",".$customgrp{$key}[3] eq $fwhostsettings{'delhost'}){
867 $grpname=$customgrp{$key}[0];
868 $grpremark=$customgrp{$key}[1];
869 #check if we delete the last entry, then generate dummy
870 if ($fwhostsettings{'last'} eq 'on'){
871 $customgrp{$key}[1] = '';
872 $customgrp{$key}[2] = 'none';
873 $customgrp{$key}[3] = '';
874 $fwhostsettings{'last'}='';
875 last;
876 }else{
877 delete $customgrp{$key};
878 }
879 }
880 }
881 &General::writehasharray("$configgrp", \%customgrp);
882 &General::firewall_config_changed();
883 if ($fwhostsettings{'update'} eq 'on'){
884 $fwhostsettings{'remark'}= $grpremark;
885 $fwhostsettings{'grp_name'}=$grpname;
886 }
887 &addgrp;
888 &viewtablegrp;
889 }
890 if ($fwhostsettings{'ACTION'} eq 'delgrp')
891 {
892 &General::readhasharray("$configgrp", \%customgrp);
893 &decrease($fwhostsettings{'grp_name'});
894 foreach my $key (sort keys %customgrp)
895 {
896 if($customgrp{$key}[0] eq $fwhostsettings{'grp_name'})
897 {
898 delete $customgrp{$key};
899 }
900 }
901 &General::writehasharray("$configgrp", \%customgrp);
902 $fwhostsettings{'grp_name'}='';
903 &addgrp;
904 &viewtablegrp;
905 }
906 if ($fwhostsettings{'ACTION'} eq 'delservice')
907 {
908 &General::readhasharray("$configsrv", \%customservice);
909 foreach my $key (keys %customservice) {
910 if($customservice{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
911 delete $customservice{$key};
912 &General::writehasharray("$configsrv", \%customservice);
913 last;
914 }
915 }
916 $fwhostsettings{'SRV_NAME'}='';
917 $fwhostsettings{'SRV_PORT'}='';
918 $fwhostsettings{'PROT'}='';
919 &addservice;
920 }
921 if ($fwhostsettings{'ACTION'} eq 'delservicegrp')
922 {
923 &General::readhasharray("$configsrvgrp", \%customservicegrp);
924 &decreaseservice($fwhostsettings{'SRVGRP_NAME'});
925 foreach my $key (sort keys %customservicegrp)
926 {
927 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'})
928 {
929 delete $customservicegrp{$key};
930 }
931 }
932 &General::writehasharray("$configsrvgrp", \%customservicegrp);
933 $fwhostsettings{'SRVGRP_NAME'}='';
934 &addservicegrp;
935 &viewtableservicegrp;
936 }
937 if ($fwhostsettings{'ACTION'} eq 'delgrpservice')
938 {
939 my $grpname;
940 my $grpremark;
941 &General::readhasharray("$configsrvgrp", \%customservicegrp);
942 foreach my $key (keys %customservicegrp){
943 if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2] eq $fwhostsettings{'delsrvfromgrp'})
944 {
945 $grpname=$customservicegrp{$key}[0];
946 $grpremark=$customservicegrp{$key}[1];
947 if($fwhostsettings{'last'} eq 'on'){
948 $customservicegrp{$key}[2] = 'none';
949 $fwhostsettings{'last'} = '';
950 last;
951 }else{
952 delete $customservicegrp{$key};
953 }
954 }
955 }
956 &General::writehasharray("$configsrvgrp", \%customservicegrp);
957 &General::firewall_config_changed();
958 if ($fwhostsettings{'updatesrvgrp'} eq 'on'){
959 $fwhostsettings{'SRVGRP_NAME'}=$grpname;
960 $fwhostsettings{'SRVGRP_REMARK'}=$grpremark;
961 }
962 &addservicegrp;
963 &viewtableservicegrp;
964 }
965 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newnet'})
966 {
967 &addnet;
968 &viewtablenet;
969 }
970 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newhost'})
971 {
972 &addhost;
973 &viewtablehost;
974 }
975 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newgrp'})
976 {
977 &addgrp;
978 &viewtablegrp;
979 }
980 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservice'})
981 {
982 &addservice;
983 }
984 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservicegrp'})
985 {
986 &addservicegrp;
987 &viewtableservicegrp;
988 }
989 if ($fwhostsettings{'ACTION'} eq 'changegrpremark')
990 {
991 &General::readhasharray("$configgrp", \%customgrp);
992 if ($fwhostsettings{'oldrem'} ne $fwhostsettings{'newrem'} && (&validremark($fwhostsettings{'newrem'}) || $fwhostsettings{'newrem'} eq '')){
993 foreach my $key (sort keys %customgrp)
994 {
995 if($customgrp{$key}[0] eq $fwhostsettings{'grp'} && $customgrp{$key}[1] eq $fwhostsettings{'oldrem'})
996 {
997 $customgrp{$key}[1]='';
998 $customgrp{$key}[1]=$fwhostsettings{'newrem'};
999 }
1000 }
1001 &General::writehasharray("$configgrp", \%customgrp);
1002 $fwhostsettings{'update'}='on';
1003 $fwhostsettings{'remark'}=$fwhostsettings{'newrem'};
1004 }else{
1005 $errormessage=$Lang::tr{'fwhost err remark'};
1006 $fwhostsettings{'remark'}=$fwhostsettings{'oldrem'};
1007 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1008 $fwhostsettings{'update'} = 'on';
1009 }
1010 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1011 &addgrp;
1012 &viewtablegrp;
1013 }
1014 if ($fwhostsettings{'ACTION'} eq 'changesrvgrpremark')
1015 {
1016 &General::readhasharray("$configsrvgrp", \%customservicegrp );
1017 if ($fwhostsettings{'oldsrvrem'} ne $fwhostsettings{'newsrvrem'} && (&validremark($fwhostsettings{'newsrvrem'}) || $fwhostsettings{'newsrvrem'} eq '')){
1018 foreach my $key (sort keys %customservicegrp)
1019 {
1020 if($customservicegrp{$key}[0] eq $fwhostsettings{'srvgrp'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvrem'})
1021 {
1022 $customservicegrp{$key}[1]='';
1023 $customservicegrp{$key}[1]=$fwhostsettings{'newsrvrem'};
1024 }
1025 }
1026 &General::writehasharray("$configsrvgrp", \%customservicegrp);
1027 $fwhostsettings{'updatesrvgrp'}='on';
1028 $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'newsrvrem'};
1029 }elsif($fwhostsettings{'oldsrvrem'} eq $fwhostsettings{'newsrvrem'}){
1030 &addservicegrp;
1031 &viewtableservicegrp;
1032 }else{
1033 $errormessage=$Lang::tr{'fwhost err remark'};
1034 $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'oldsrvrem'};
1035 $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'};
1036 $fwhostsettings{'updatesrvgrp'} = 'on';
1037 }
1038 $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'};
1039 &addservicegrp;
1040 &viewtableservicegrp;
1041 }
1042 if ($fwhostsettings{'ACTION'} eq 'changesrvgrpname')
1043 {
1044 &General::readhasharray("$configsrvgrp", \%customservicegrp );
1045 if ($fwhostsettings{'oldsrvgrpname'} ne $fwhostsettings{'srvgrp'}){
1046 #Check new groupname
1047 if (!&validhostname($fwhostsettings{'srvgrp'})){
1048 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1049 }
1050 if (!$errormessage){
1051 #Rename group in customservicegroup
1052 foreach my $key (keys %customservicegrp) {
1053 if($customservicegrp{$key}[0] eq $fwhostsettings{'oldsrvgrpname'}){
1054 $customservicegrp{$key}[0]=$fwhostsettings{'srvgrp'};
1055 }
1056 }
1057 &General::writehasharray("$configsrvgrp", \%customservicegrp );
1058 #change name in FW Rules
1059 &changenameinfw($fwhostsettings{'oldsrvgrpname'},$fwhostsettings{'srvgrp'},15);
1060 }
1061 }
1062 &addservicegrp;
1063 &viewtableservicegrp;
1064 }
1065 if ($fwhostsettings{'ACTION'} eq 'changegrpname')
1066 {
1067 &General::readhasharray("$configgrp", \%customgrp );
1068 if ($fwhostsettings{'oldgrpname'} ne $fwhostsettings{'grp'}){
1069 #Check new groupname
1070 if (!&validhostname($fwhostsettings{'grp'})){
1071 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1072 }
1073 if (!$errormessage){
1074 #Rename group in customservicegroup
1075 foreach my $key (keys %customgrp) {
1076 if($customgrp{$key}[0] eq $fwhostsettings{'oldgrpname'}){
1077 $customgrp{$key}[0]=$fwhostsettings{'grp'};
1078 }
1079 }
1080 &General::writehasharray("$configgrp", \%customgrp );
1081 #change name in FW Rules
1082 &changenameinfw($fwhostsettings{'oldgrpname'},$fwhostsettings{'grp'},6);
1083 }
1084 }
1085 &addgrp;
1086 &viewtablegrp;
1087 }
1088 ### VIEW ###
1089 if($fwhostsettings{'ACTION'} eq '')
1090 {
1091 &showmenu;
1092 }
1093 ### FUNCTIONS ###
1094 sub showmenu {
1095 &Header::openbox('100%', 'left',);
1096 print "$Lang::tr{'fwhost welcome'}";
1097 print<<END;
1098 <br><br><table border='0' width='100%'>
1099 <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>
1100 <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>
1101 <tr><td colspan='6'></td></tr></table>
1102 END
1103 &Header::closebox();
1104
1105 }
1106 # Add
1107 sub addnet
1108 {
1109 &error;
1110 &showmenu;
1111 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addnet'});
1112 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
1113 $fwhostsettings{'orgnetremark'}=$fwhostsettings{'NETREMARK'};
1114 print<<END;
1115 <table border='0' width='100%' >
1116 <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>
1117 <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>
1118 <tr><td>$Lang::tr{'netmask'}:</td><td><input type='TEXT' name='SUBNET' value='$fwhostsettings{'SUBNET'}' $fwhostsettings{'BLK_IP'} size='20' maxlength='15'></td></tr>
1119 <tr><td>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='NETREMARK' value='$fwhostsettings{'NETREMARK'}' style='width: 98.5%;'></td></tr>
1120 <tr><td colspan='6'><br></td></tr><tr>
1121 END
1122 if ($fwhostsettings{'ACTION'} eq 'editnet' || $fwhostsettings{'error'} eq 'on')
1123 {
1124 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'}'>";
1125 }else{
1126 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'>";
1127 }
1128 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>";
1129 &Header::closebox();
1130 }
1131 sub addhost
1132 {
1133 &error;
1134 &showmenu;
1135 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addhost'});
1136 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
1137 $fwhostsettings{'orgremark'}=$fwhostsettings{'HOSTREMARK'};
1138 print<<END;
1139 <table width='100%'>
1140 <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>
1141 <tr><td>IP/MAC:</td><td><input type='TEXT' name='IP' value='$fwhostsettings{'IP'}' $fwhostsettings{'BLK_IP'} size='20' maxlength='17'></td></tr>
1142 <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='HOSTREMARK' value='$fwhostsettings{'HOSTREMARK'}' style='width:98%;'></td></tr>
1143 <tr><td colspan='5'><br></td></tr><tr>
1144 END
1145
1146 if ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'} eq 'on')
1147 {
1148
1149 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>";
1150 }else{
1151 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'>";
1152 }
1153 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>";
1154 &Header::closebox();
1155 }
1156 sub addgrp
1157 {
1158 &hint;
1159 &error;
1160 &showmenu;
1161 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addgrp'});
1162 &General::setup_default_networks(\%defaultNetworks);
1163 &General::readhasharray("$configccdnet", \%ccdnet);
1164 &General::readhasharray("$confignet", \%customnetwork);
1165 &General::readhasharray("$configccdhost", \%ccdhost);
1166 &General::readhasharray("$confighost", \%customhost);
1167 &General::readhasharray("$configipsec", \%ipsecconf);
1168
1169 my %checked=();
1170 my $show='';
1171 $checked{'check1'}{'off'} = '';
1172 $checked{'check1'}{'on'} = '';
1173 $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED';
1174 $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'};
1175 $fwhostsettings{'oldgrpname'}=$fwhostsettings{'grp_name'};
1176 my $grp=$fwhostsettings{'grp_name'};
1177 my $rem=$fwhostsettings{'remark'};
1178 if ($fwhostsettings{'update'} eq ''){
1179 print<<END;
1180 <table width='100%' border='0'>
1181 <tr>
1182 <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td>
1183 <td><form method='post'><input type='TEXT' name='grp_name' value='$fwhostsettings{'grp_name'}' size='30'></td>
1184 </tr>
1185 <tr>
1186 <td>$Lang::tr{'remark'}:</td>
1187 <td ><input type='TEXT' name='remark' value='$fwhostsettings{'remark'}' style='width: 99%;'></td>
1188 </tr>
1189 <tr>
1190 <td colspan='2'><br></td>
1191 </tr>
1192 </table>
1193 END
1194 }else{
1195 print<<END;
1196 <table width='100%' border='0'><form method='post'>
1197 <tr>
1198 <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td>
1199 <td style='width:30%;'><input type='TEXT' name='grp' value='$fwhostsettings{'grp_name'}' size='30'></td>
1200 <td><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldgrpname' value='$fwhostsettings{'oldgrpname'}'><input type='hidden' name='ACTION' value='changegrpname'></td>
1201 <td></td></form>
1202 </tr>
1203 <tr><form method='post' style='display:inline'>
1204 <td>$Lang::tr{'remark'}:</td>
1205 <td colspan='2' style='width:98%;'><input type='TEXT' name='newrem' value='$fwhostsettings{'remark'}' style='width:98%;'></td>
1206 <td align='right'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='grp' value='$fwhostsettings{'grp_name'}'><input type='hidden' name='oldrem' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='ACTION' value='changegrpremark' ></td>
1207 </tr>
1208 </table></form>
1209 <br><br>
1210 END
1211 }
1212 if ($fwhostsettings{'update'} eq 'on'){
1213 print<<END;
1214 <form method='post'><input type='hidden' name='remark' value='$rem'><input type='hidden' name='grp_name' value='$grp'>
1215 <table width='100%' border='0'>
1216 <tr><td width=50% valign='top'>
1217 <table width='90%' border='0'>
1218 <tr>
1219 <td style='width:15em;'>
1220 <label>
1221 <input type='radio' name='grp2' value='std_net' id='DEFAULT_SRC_ADR' checked>
1222 $Lang::tr{'fwhost stdnet'}
1223 </label>
1224 </td>
1225 <td style='text-align:right;'>
1226 <select name='DEFAULT_SRC_ADR' style='width:16em;'>
1227 END
1228 foreach my $network (sort keys %defaultNetworks)
1229 {
1230 next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP");
1231 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
1232 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1233 print " selected='selected'" if ($fwhostsettings{'DEFAULT_SRC_ADR'} eq $defaultNetworks{$network}{'NAME'});
1234 my $defnet="$defaultNetworks{$network}{'NAME'}_NETADDRESS";
1235 my $defsub="$defaultNetworks{$network}{'NAME'}_NETMASK";
1236 my $defsub1=&General::subtocidr($ownnet{$defsub});
1237 $ownnet{$defnet}='' if ($defaultNetworks{$network}{'NAME'} eq 'RED');
1238 if ($ownnet{$defnet}){
1239 print ">$network ($ownnet{$defnet}/$defsub1)</option>";
1240 }else{
1241 print ">$network</option>";
1242 }
1243 }
1244 print"</select></td></tr>";
1245 if (! -z $confignet){
1246 print<<END;
1247 <tr>
1248 <td>
1249 <label>
1250 <input type='radio' name='grp2' id='CUST_SRC_NET' value='cust_net' $checked{'grp2'}{'cust_net'}>
1251 $Lang::tr{'fwhost cust net'}:
1252 </label>
1253 </td>
1254 <td style='text-align:right;'>
1255 <select name='CUST_SRC_NET' style='width:16em;'>";
1256 END
1257 foreach my $key (sort { ncmp($customnetwork{$a}[0],$customnetwork{$b}[0]) } keys %customnetwork) {
1258 print"<option>$customnetwork{$key}[0]</option>";
1259 }
1260 print"</select></td></tr>";
1261 }
1262 if (! -z $confighost){
1263 print<<END;
1264 <tr>
1265 <td valign='top'>
1266 <label>
1267 <input type='radio' name='grp2' id='CUST_SRC_HOST' value='cust_host' $checked{'grp2'}{'cust_host'}>
1268 $Lang::tr{'fwhost cust addr'}:
1269 </label>
1270 </td>
1271 <td style='text-align:right;'>
1272 <select name='CUST_SRC_HOST' style='width:16em;'>";
1273 END
1274 foreach my $key (sort { ncmp($customhost{$a}[0],$customhost{$b}[0]) } keys %customhost) {
1275 print"<option>$customhost{$key}[0]</option>";
1276 }
1277 print"</select></td></tr>";
1278 }
1279 print"</table>";
1280 #Inner table right
1281 print"</td><td align='right' style='vertical-align:top;'><table width='90%' border='0'>";
1282 #OVPN networks
1283 if (! -z $configccdnet){
1284 print<<END;
1285 <td style='width:15em;'>
1286 <label>
1287 <input type='radio' name='grp2' id='OVPN_CCD_NET' value='ovpn_net' $checked{'grp2'}{'ovpn_net'}>
1288 $Lang::tr{'fwhost ccdnet'}
1289 </label>
1290 </td>
1291 <td style='text-align:right;'>
1292 <select name='OVPN_CCD_NET' style='width:16em;'>";
1293 END
1294 foreach my $key (sort { ncmp($ccdnet{$a}[0],$ccdnet{$b}[0]) } keys %ccdnet)
1295 {
1296 print"<option value='$ccdnet{$key}[0]'>$ccdnet{$key}[0]</option>";
1297 }
1298 print"</select></td></tr>";
1299 }
1300 #OVPN clients
1301 my @ovpn_clients=();
1302 foreach my $key (sort { ncmp($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost)
1303 {
1304 if ($ccdhost{$key}[33] ne ''){
1305 $show='1';
1306 push (@ovpn_clients,$ccdhost{$key}[1]);
1307 }
1308 }
1309 if ($show eq '1'){
1310 $show='';
1311 print<<END;
1312 <td style='width:15em;'>
1313 <label>
1314 <input type='radio' name='grp2' value='ovpn_host' $checked{'grp2'}{'ovpn_host'}>
1315 $Lang::tr{'fwhost ccdhost'}
1316 </label>
1317 </td>
1318 <td style='text-align:right;'>
1319 <select name='OVPN_CCD_HOST' style='width:16em;'>" if ($show eq '');
1320 END
1321 foreach(@ovpn_clients){
1322 print"<option value='$_'>$_</option>";
1323 }
1324 print"</select></td></tr>";
1325 }
1326 #OVPN n2n networks
1327 my @OVPN_N2N=();
1328 foreach my $key (sort { ncmp($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost) {
1329 if($ccdhost{$key}[3] eq 'net'){
1330 $show='1';
1331 push (@OVPN_N2N,$ccdhost{$key}[1]);
1332 }
1333 }
1334 if ($show eq '1'){
1335 $show='';
1336 print<<END;
1337 <td style='width:15em;'>
1338 <label>
1339 <input type='radio' name='grp2' id='OVPN_N2N' value='ovpn_n2n' $checked{'grp2'}{'ovpn_n2n'}>
1340 $Lang::tr{'fwhost ovpn_n2n'}:
1341 </label>
1342 </td>
1343 <td style='text-align:right;'>
1344 <select name='OVPN_N2N' style='width:16em;'>"
1345 END
1346 foreach(@OVPN_N2N){
1347 print"<option>$_</option>";
1348 }
1349 print"</select></td></tr>";
1350 }
1351 #IPsec networks
1352 my @IPSEC_N2N=();
1353 foreach my $key (sort { ncmp($ipsecconf{$a}[0],$ipsecconf{$b}[0]) } keys %ipsecconf) {
1354 if ($ipsecconf{$key}[3] eq 'net'){
1355 $show='1';
1356 push (@IPSEC_N2N,$ipsecconf{$key}[1]);
1357 }
1358 }
1359 if ($show eq '1'){
1360 $show='';
1361 print<<END;
1362 <td style='width:15em;'>
1363 <label>
1364 <input type='radio' name='grp2' id='IPSEC_NET' value='ipsec_net' $checked{'grp2'}{'ipsec_net'}>
1365 $Lang::tr{'fwhost ipsec net'}
1366 </label>
1367 </td>
1368 <td style='text-align:right;'>
1369 <select name='IPSEC_NET' style='width:16em;'>"
1370 END
1371 foreach(@IPSEC_N2N){
1372 print"<option value='$_'>$_</option>";
1373 }
1374 }
1375 print"</select></td></tr>";
1376 print"</table>";
1377 print"</td></tr></table>";
1378 print"<br><br>";
1379 }
1380 print"<table width='100%'>";
1381 print"<tr><td style='text-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>";
1382 &Header::closebox();
1383 }
1384 sub addservice
1385 {
1386 &error;
1387 &showmenu;
1388 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservice'});
1389 if ($fwhostsettings{'updatesrv'} eq 'on')
1390 {
1391 $fwhostsettings{'oldsrvname'} = $fwhostsettings{'SRV_NAME'};
1392 $fwhostsettings{'oldsrvport'} = $fwhostsettings{'SRV_PORT'};
1393 $fwhostsettings{'oldsrvprot'} = $fwhostsettings{'PROT'};
1394 $fwhostsettings{'oldsrvicmp'} = $fwhostsettings{'ICMP'};
1395 }
1396 print<<END;
1397 <table width='100%' border='0'><form method='post'>
1398 <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>
1399 <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost prot'}:</td><td><select name='PROT' id='protocol' >
1400 END
1401 foreach ("TCP","UDP","ICMP")
1402 {
1403 if ($_ eq $fwhostsettings{'PROT'})
1404 {
1405 print"<option selected>$_</option>";
1406 }else{
1407 print"<option>$_</option>";
1408 }
1409 }
1410 print<<END;
1411 </select></td></tr></table>
1412 <div id='PROTOKOLL' class='noscript'><table width=100%' border='0'><tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost icmptype'}</td><td><select name='ICMP_TYPES'>
1413 END
1414 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1415 print"<option value='All ICMP-Types'>$Lang::tr{'fwdfw all icmp'}</option>";
1416 foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
1417 if ($icmptypes{$key}[0] eq $fwhostsettings{'oldsrvicmp'}){
1418 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1419 }else{
1420 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1421 }
1422 }
1423 print<<END;
1424 </select></td></tr></table></div>
1425 <div id='PORT' class='noscript'><table width='100%' border='0'><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></table></div>
1426 <table width='100%' border='0'><tr><td colspan='6'><br></td></tr>
1427 <tr><td colspan='6' align='right'>
1428 END
1429 if ($fwhostsettings{'updatesrv'} eq 'on')
1430 {
1431 print<<END;
1432 <input type='submit' value='$Lang::tr{'update'}'style='min-width:100px;' >
1433 <input type='hidden' name='ACTION' value='updateservice'>
1434 <input type='hidden' name='oldsrvname' value='$fwhostsettings{'oldsrvname'}'>
1435 <input type='hidden' name='oldsrvport' value='$fwhostsettings{'oldsrvport'}'>
1436 <input type='hidden' name='oldsrvprot' value='$fwhostsettings{'oldsrvprot'}'>
1437 <input type='hidden' name='oldsrvicmp' value='$fwhostsettings{'oldsrvicmp'}'>
1438 </form>
1439 END
1440 }else{
1441 print"<input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='saveservice'></form>";
1442 }
1443 print<<END;
1444 <form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></form></td></tr>
1445 </table></form>
1446 END
1447 &Header::closebox();
1448 &viewtableservice;
1449 }
1450 sub addservicegrp
1451 {
1452 &hint;
1453 &error;
1454 &showmenu;
1455 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservicegrp'});
1456 $fwhostsettings{'oldsrvgrpremark'}=$fwhostsettings{'SRVGRP_REMARK'};
1457 $fwhostsettings{'oldsrvgrpname'}=$fwhostsettings{'SRVGRP_NAME'};
1458 if ($fwhostsettings{'updatesrvgrp'} eq ''){
1459 print<<END;
1460 <table width='100%' border='0'><form method='post'>
1461 <tr><td width='10%'>$Lang::tr{'fwhost addgrpname'}</td><td><input type='text' name='SRVGRP_NAME' value='$fwhostsettings{'SRVGRP_NAME'}' size='24'></td></tr>
1462 <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='text' name='SRVGRP_REMARK' value='$fwhostsettings{'SRVGRP_REMARK'}' style='width: 98%;'></td></tr>
1463 <tr><td colspan='2'><br></tr>
1464 </table>
1465 END
1466 }else{
1467 print<<END;
1468 <table width='100%'><form method='post' style='display:inline'>
1469 <tr><td width='10%'>$Lang::tr{'fwhost addgrpname'}</td><td width='20%'><input type='text' name='srvgrp' value='$fwhostsettings{'SRVGRP_NAME'}' size='14'></td><td align='left'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldsrvgrpname' value='$fwhostsettings{'oldsrvgrpname'}'><input type='hidden' name='ACTION' value='changesrvgrpname'></td><td width='3%'></td></form></tr>
1470 <tr>
1471 <form method='post'>
1472 <td width='10%'>
1473 $Lang::tr{'remark'}:
1474 </td>
1475 <td colspan='2'>
1476 <input type='text' name='newsrvrem' value='$fwhostsettings{'SRVGRP_REMARK'}' style='width:98%;'>
1477 </td>
1478 <td align='right'>
1479 <input type='submit' value='$Lang::tr{'fwhost change'}'>
1480 <input type='hidden' name='oldsrvrem' value='$fwhostsettings{'oldsrvgrpremark'}'>
1481 <input type='hidden' name='srvgrp' value='$fwhostsettings{'SRVGRP_NAME'}'>
1482 <input type='hidden' name='ACTION' value='changesrvgrpremark' >
1483 </td>
1484 </tr>
1485 <tr>
1486 <td colspan='4'>
1487 <br>
1488 </td>
1489 </tr>
1490 </table>
1491 </form>
1492 END
1493 }
1494 if($fwhostsettings{'updatesrvgrp'} eq 'on'){
1495 print<<END;
1496 <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%'>
1497 <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'add'}: </td><td><select name='CUST_SRV' style='min-width:185px;'>
1498 END
1499 &General::readhasharray("$configsrv", \%customservice);
1500 #Protocols for use in servicegroups
1501 print "<optgroup label='$Lang::tr{'fwhost cust service'}'>";
1502 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice)
1503 {
1504 print "<option>$customservice{$key}[0]</option>";
1505 }
1506 print "</optgroup>";
1507 print "<optgroup label='$Lang::tr{'protocol'}'>";
1508 print "<option>GRE</option>";
1509 print "<option>AH</option>";
1510 print "<option>ESP</option>";
1511 print "<option>IGMP</option>";
1512 print "<option>IPIP</option>";
1513 print "<option value='IPV6'>IPv6 encap</option>";
1514 print "</optgroup>";
1515 print<<END;
1516 </select></td></tr>
1517 <tr><td colspan='4'><br><br></td></tr>
1518 <tr><td colspan='4'></td></tr>
1519 </table>
1520 END
1521 }
1522 print<<END;
1523 <table width='100%'>
1524 <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>
1525 </table></form>
1526 END
1527 &Header::closebox();
1528 }
1529 # View
1530 sub viewtablenet
1531 {
1532 if(! -z $confignet){
1533 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust net'});
1534 &General::readhasharray("$confignet", \%customnetwork);
1535 &General::readhasharray("$configgrp", \%customgrp);
1536 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1537 &General::readhasharray("$fwconfiginp", \%fwinp);
1538 &General::readhasharray("$fwconfigout", \%fwout);
1539
1540 if (!keys %customnetwork)
1541 {
1542 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1543 }else{
1544 print<<END;
1545 <table width='100%' cellspacing='0' class='tbl'>
1546 <tr><th align='center'><b>$Lang::tr{'name'}</b></th><th align='center'><b>$Lang::tr{'fwhost netaddress'}</b></th><th align='center'><b>$Lang::tr{'remark'}</b></th><th align='center'><b>$Lang::tr{'used'}</b></th><th></th><th width='3%'></th></tr>
1547 END
1548 }
1549 my $count=0;
1550 my $col='';
1551 foreach my $key (sort {ncmp($a,$b)} keys %customnetwork) {
1552 if ($fwhostsettings{'ACTION'} eq 'editnet' && $fwhostsettings{'HOSTNAME'} eq $customnetwork{$key}[0]) {
1553 print" <tr>";
1554 $col="bgcolor='${Header::colouryellow}'";
1555 }elsif ($count % 2)
1556 {
1557 $col="bgcolor='$color{'color20'}'";
1558 print" <tr>";
1559 }else
1560 {
1561 $col="bgcolor='$color{'color22'}'";
1562 print" <tr>";
1563 }
1564 my $colnet="$customnetwork{$key}[1]/".&General::subtocidr($customnetwork{$key}[2]);
1565 my $netcount=&getnetcount($customnetwork{$key}[0]);
1566 print"<td width='20%' $col><form method='post'>$customnetwork{$key}[0]</td><td width='15%' align='center' $col>".&getcolor($colnet)."</td><td width='40%' $col>$customnetwork{$key}[3]</td><td align='center' $col>$netcount x</td>";
1567 print<<END;
1568 <td width='1%' $col><input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
1569 <input type='hidden' name='ACTION' value='editnet'>
1570 <input type='hidden' name='HOSTNAME' value='$customnetwork{$key}[0]' />
1571 <input type='hidden' name='IP' value='$customnetwork{$key}[1]' />
1572 <input type='hidden' name='SUBNET' value='$customnetwork{$key}[2]' />
1573 <input type='hidden' name='NETREMARK' value='$customnetwork{$key}[3]' />
1574 </td></form>
1575 END
1576 if($netcount == '0')
1577 {
1578 print"<td width='1%' $col><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>";
1579 }else{
1580 print"<td $col></td></tr>";
1581 }
1582 $count++;
1583 }
1584 print"</table>";
1585 &Header::closebox();
1586 }
1587
1588 }
1589 sub getcolor
1590 {
1591 my $c=shift;
1592 my $sip;
1593 my $scidr;
1594 my $tdcolor='';
1595 #Check if MAC
1596 if (&General::validmac($c)){ return $c;}
1597
1598 #Check if we got a full IP with subnet then split it
1599 if($c =~ /^(.*?)\/(.*?)$/){
1600 ($sip,$scidr) = split ("/",$c);
1601 }else{
1602 $sip=$c;
1603 }
1604
1605 #Now check if IP is part of ORANGE,BLUE or GREEN
1606 if ( &Header::orange_used() && &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1607 $tdcolor="<font style='color: $Header::colourorange;'>$c</font>";
1608 return $tdcolor;
1609 }
1610 if ( &General::IpInSubnet($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){
1611 $tdcolor="<font style='color: $Header::colourgreen;'>$c</font>";
1612 return $tdcolor;
1613 }
1614 if ( &Header::blue_used() && &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
1615 $tdcolor="<font style='color: $Header::colourblue;'>$c</font>";
1616 return $tdcolor;
1617 }
1618 if ("$sip/$scidr" eq "0.0.0.0/0"){
1619 $tdcolor="<font style='color: $Header::colourred;'>$c</font>";
1620 return $tdcolor;
1621 }
1622 #Check if IP is part of OpenVPN N2N subnet
1623 foreach my $key (sort keys %ccdhost){
1624 if ($ccdhost{$key}[3] eq 'net'){
1625 my ($a,$b) = split("/",$ccdhost{$key}[11]);
1626 if (&General::IpInSubnet($sip,$a,$b)){
1627 $tdcolor="<font style='color:$Header::colourovpn ;'>$c</font>";
1628 return $tdcolor;
1629 }
1630 }
1631 }
1632
1633 #Check if IP is part of OpenVPN dynamic subnet
1634 my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'});
1635 if (&General::IpInSubnet($sip,$a,$b)){
1636 $tdcolor="<font style='color: $Header::colourovpn;'>$c</font>";
1637 return $tdcolor;
1638 }
1639
1640 #Check if IP is part of OpenVPN static subnet
1641 foreach my $key (sort keys %ccdnet){
1642 my ($a,$b) = split("/",$ccdnet{$key}[1]);
1643 $b =&General::iporsubtodec($b);
1644 if (&General::IpInSubnet($sip,$a,$b)){
1645 $tdcolor="<font style='color: $Header::colourovpn;'>$c</font>";
1646 return $tdcolor;
1647 }
1648 }
1649
1650 #Check if IP is part of IPsec RW network
1651 if ($ipsecsettings{'RW_NET'} ne ''){
1652 my ($a,$b) = split("/",$ipsecsettings{'RW_NET'});
1653 $b=&General::iporsubtodec($b);
1654 if (&General::IpInSubnet($sip,$a,$b)){
1655 $tdcolor="<font style='color: $Header::colourvpn;'>$c</font>";
1656 return $tdcolor;
1657 }
1658 }
1659
1660 #Check if IP is part of a IPsec N2N network
1661 foreach my $key (sort keys %ipsecconf){
1662 if ($ipsecconf{$key}[11]){
1663 my ($a,$b) = split("/",$ipsecconf{$key}[11]);
1664 $b=&General::iporsubtodec($b);
1665 if (&General::IpInSubnet($sip,$a,$b)){
1666 $tdcolor="<font style='color: $Header::colourvpn;'>$c</font>";
1667 return $tdcolor;
1668 }
1669 }
1670 }
1671 return "$c";
1672 }
1673 sub viewtablehost
1674 {
1675 if (! -z $confighost){
1676 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust addr'});
1677 &General::readhasharray("$confighost", \%customhost);
1678 &General::readhasharray("$configccdnet", \%ccdnet);
1679 &General::readhasharray("$configccdhost", \%ccdhost);
1680 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1681 &General::readhasharray("$fwconfiginp", \%fwinp);
1682 &General::readhasharray("$fwconfigout", \%fwout);
1683 &General::readhasharray("$configgrp", \%customgrp);
1684 if (!keys %customhost)
1685 {
1686 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1687 }else{
1688 print<<END;
1689 <table width='100%' cellspacing='0' class='tbl'>
1690 <tr><th align='center'><b>$Lang::tr{'name'}</b></th><th align='center'><b>$Lang::tr{'fwhost ip_mac'}</b></th><th align='center'><b>$Lang::tr{'remark'}</b></th><th align='center'><b>$Lang::tr{'used'}</b></th><th></th><th width='3%'></th></tr>
1691 END
1692 }
1693 my $count=0;
1694 my $col='';
1695 foreach my $key (sort { ncmp ($customhost{$a}[0],$customhost{$b}[0])} keys %customhost) {
1696 if ( ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'}) && $fwhostsettings{'HOSTNAME'} eq $customhost{$key}[0]) {
1697 print" <tr>";
1698 $col="bgcolor='${Header::colouryellow}'";
1699 }elsif ($count % 2){
1700 print" <tr>";
1701 $col="bgcolor='$color{'color20'}'";
1702 }else{
1703 $col="bgcolor='$color{'color22'}'";
1704 print" <tr>";
1705 }
1706 my ($ip,$sub)=split(/\//,$customhost{$key}[2]);
1707 $customhost{$key}[4]=~s/\s+//g;
1708 my $hostcount=0;
1709 $hostcount=&gethostcount($customhost{$key}[0]);
1710 print"<td width='20%' $col>$customhost{$key}[0]</td><td width='20%' align='center' $col >".&getcolor($ip)."</td><td width='50%' align='left' $col>$customhost{$key}[3]</td><td align='center' $col>$hostcount x</td>";
1711 print<<END;
1712 <td width='1%' $col><form method='post'><input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
1713 <input type='hidden' name='ACTION' value='edithost' />
1714 <input type='hidden' name='HOSTNAME' value='$customhost{$key}[0]' />
1715 <input type='hidden' name='IP' value='$ip' />
1716 <input type='hidden' name='type' value='$customhost{$key}[1]' />
1717 <input type='hidden' name='HOSTREMARK' value='$customhost{$key}[3]' />
1718 </form></td>
1719 END
1720 if($hostcount == '0')
1721 {
1722 print"<td width='1%' $col><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>";
1723 }else{
1724 print"<td width='1%' $col></td></tr>";
1725 }
1726 $count++;
1727 }
1728 print"</table>";
1729 &Header::closebox();
1730 }
1731 }
1732 sub viewtablegrp
1733 {
1734 if(! -z "$configgrp"){
1735 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust grp'});
1736 &General::readhasharray("$configgrp", \%customgrp);
1737 &General::readhasharray("$configipsec", \%ipsecconf);
1738 &General::readhasharray("$configccdhost", \%ccdhost);
1739 &General::readhasharray("$configccdnet", \%ccdnet);
1740 &General::readhasharray("$confighost", \%customhost);
1741 &General::readhasharray("$confignet", \%customnetwork);
1742 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1743 &General::readhasharray("$fwconfiginp", \%fwinp);
1744 &General::readhasharray("$fwconfigout", \%fwout);
1745 my @grp=();
1746 my $helper='';
1747 my $count=1;
1748 my $grpname;
1749 my $remark;
1750 my $number;
1751 my $delflag;
1752 my @counter;
1753 my %hash;
1754 if (!keys %customgrp)
1755 {
1756 print "<center><b>$Lang::tr{'fwhost err emptytable'}</b>";
1757 }else{
1758 #get all groups in a hash
1759 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
1760 push (@counter,$customgrp{$key}[0]);
1761 }
1762 foreach my $key1 (@counter) {
1763 $hash{$key1}++ ;
1764 }
1765 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
1766 $count++;
1767 if ($helper ne $customgrp{$key}[0]){
1768 $delflag='0';
1769 foreach my $key1 (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
1770 if ($customgrp{$key}[0] eq $customgrp{$key1}[0])
1771 {
1772 $delflag++;
1773 }
1774 if($delflag > 1){
1775 last;
1776 }
1777 }
1778 $number=1;
1779 if ($customgrp{$key}[2] eq "none"){$customgrp{$key}[2]=$Lang::tr{'fwhost err emptytable'};}
1780 $grpname=$customgrp{$key}[0];
1781 $remark="$customgrp{$key}[1]";
1782 if($count gt 1){ print"</table>";$count=1;}
1783 print "<br><b><u>$grpname</u></b>&nbsp; &nbsp;";
1784 print " <b>$Lang::tr{'remark'}:</b>&nbsp $remark &nbsp " if ($remark ne '');
1785 my $netgrpcount=&getnetcount($grpname);
1786 print "<b>$Lang::tr{'used'}:</b> $netgrpcount x";
1787 if($netgrpcount == '0')
1788 {
1789 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>";
1790 }
1791 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>";
1792 print"<table width='100%' cellspacing='0' class='tbl'><tr><th align='center'><b>$Lang::tr{'name'}</b></th><th align='center'><b>$Lang::tr{'fwhost ip_mac'}</b></th><th align='center' width='25%'><b>$Lang::tr{'fwhost type'}</th><th></th></tr>";
1793 }
1794 my $col='';
1795 if ( ($fwhostsettings{'ACTION'} eq 'editgrp' || $fwhostsettings{'update'} ne '') && $fwhostsettings{'grp_name'} eq $customgrp{$key}[0]) {
1796 print" <tr>";
1797 $col="bgcolor='${Header::colouryellow}'";
1798 }elsif ($count %2 == 0){
1799 print"<tr>";
1800 $col="bgcolor='$color{'color20'}'";
1801 }else{
1802 print"<tr>";
1803 $col="bgcolor='$color{'color22'}'";
1804 }
1805 my $ip=&getipforgroup($customgrp{$key}[2],$customgrp{$key}[3]);
1806 if ($ip eq ''){
1807 print"<tr>";
1808 $col="bgcolor='${Header::colouryellow}'";
1809 }
1810 print "<td width='39%' align='left' $col>";
1811 if($customgrp{$key}[3] eq 'Standard Network'){
1812 print &get_name($customgrp{$key}[2])."</td>";
1813 }else{
1814 print "$customgrp{$key}[2]</td>";
1815 }
1816 if ($ip eq '' && $customgrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){
1817 print "<td align='center' $col>$Lang::tr{'fwhost deleted'}</td><td align='center' $col>$Lang::tr{'fwhost '.$customgrp{$key}[3]}</td><td width='1%' $col><form method='post'>";
1818 }else{
1819 my ($colip,$colsub) = split("/",$ip);
1820 $ip="$colip/".&General::iporsubtocidr($colsub) if ($colsub);
1821 print"<td align='center' $col>".&getcolor($ip)."</td><td align='center' $col>$Lang::tr{'fwhost '.$customgrp{$key}[3]}</td><td width='1%' $col><form method='post'>";
1822 }
1823 if ($delflag > 0 && $ip ne ''){
1824 print"<input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' />";
1825 #check if this group has only one entry
1826 foreach my $key2 (keys %hash) {
1827 if ($hash{$key2}<2 && $key2 eq $customgrp{$key}[0]){
1828 print "<input type='hidden' name='last' value='on'>" ;
1829 }
1830 }
1831 }
1832 print"<input type='hidden' name='ACTION' value='deletegrphost'><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>";
1833 $helper=$customgrp{$key}[0];
1834 $number++;
1835 }
1836 print"</table>";
1837 }
1838 &Header::closebox();
1839 }
1840
1841 }
1842 sub viewtableservice
1843 {
1844 my $count=0;
1845 my $srvcount;
1846 if(! -z "$configsrv")
1847 {
1848 &Header::openbox('100%', 'left', $Lang::tr{'fwhost services'});
1849 &General::readhasharray("$configsrv", \%customservice);
1850 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1851 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1852 &General::readhasharray("$fwconfiginp", \%fwinp);
1853 &General::readhasharray("$fwconfigout", \%fwout);
1854 print<<END;
1855 <table width='100%' cellspacing='0' class='tbl'>
1856 <tr><th align='center'><b>$Lang::tr{'fwhost srv_name'}</b></th><th align='center'><b>$Lang::tr{'fwhost prot'}</b></th><th align='center'><b>$Lang::tr{'fwhost port'}</b></th><th align='center'><b>ICMP</b></th><th align='center'><b>$Lang::tr{'fwhost used'}</b></th><th></th><th width='3%'></th></tr>
1857 END
1858 my $col='';
1859 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0])} keys %customservice)
1860 {
1861 $count++;
1862 if ( ($fwhostsettings{'updatesrv'} eq 'on' || $fwhostsettings{'error'}) && $fwhostsettings{'SRV_NAME'} eq $customservice{$key}[0]) {
1863 print" <tr>";
1864 $col="bgcolor='${Header::colouryellow}'";
1865 }elsif ($count % 2){
1866 print" <tr>";
1867 $col="bgcolor='$color{'color22'}'";
1868 }else{
1869 print" <tr>";
1870 $col="bgcolor='$color{'color20'}'";
1871 }
1872 print<<END;
1873 <td $col>$customservice{$key}[0]</td><td align='center' $col>$customservice{$key}[2]</td><td align='center' $col>$customservice{$key}[1]</td><td align='center' $col>
1874 END
1875 #Neuer count
1876 $srvcount=&getsrvcount($customservice{$key}[0]);
1877 if($customservice{$key}[3] eq 'All ICMP-Types'){print $Lang::tr{'fwdfw all icmp'};}
1878 elsif($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];}
1879 print<<END;
1880 </td><td align='center' $col>$srvcount x</td>
1881 <td width='1%' $col><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' />
1882 <input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]' />
1883 <input type='hidden' name='SRV_PORT' value='$customservice{$key}[1]' />
1884 <input type='hidden' name='PROT' value='$customservice{$key}[2]' />
1885 <input type='hidden' name='ICMP' value='$customservice{$key}[3]' /></form></td>
1886 END
1887 if ($srvcount eq '0')
1888 {
1889 print"<td width='1%' $col><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>";
1890 }else{
1891 print"<td $col></td></tr>";
1892 }
1893 }
1894 print"</table>";
1895 &Header::closebox();
1896 }
1897 }
1898 sub viewtableservicegrp
1899 {
1900 my $count=0;
1901 my $grpname;
1902 my $remark;
1903 my $helper;
1904 my $helper1;
1905 my $port;
1906 my $protocol;
1907 my $delflag;
1908 my $grpcount=0;
1909 my $col='';
1910 my $lastentry=0;
1911 my @counter;
1912 my %hash;
1913 if (! -z $configsrvgrp){
1914 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'});
1915 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1916 &General::readhasharray("$configsrv", \%customservice);
1917 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1918 &General::readhasharray("$fwconfiginp", \%fwinp);
1919 &General::readhasharray("$fwconfigout", \%fwout);
1920 my $number= keys %customservicegrp;
1921 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) }keys %customservicegrp){
1922 push (@counter,$customservicegrp{$key}[0]);
1923 }
1924 foreach my $key1 (@counter) {
1925 $hash{$key1}++ ;
1926 }
1927 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) }keys %customservicegrp){
1928 $count++;
1929 if ($helper ne $customservicegrp{$key}[0]){
1930 #Get used groupcounter
1931 $grpcount=&getsrvcount($customservicegrp{$key}[0]);
1932 $delflag=0;
1933 foreach my $key1 (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) } keys %customservicegrp){
1934 if ($customservicegrp{$key}[0] eq $customservicegrp{$key1}[0])
1935 {
1936 $delflag++;
1937 }
1938 if($delflag > 1){
1939 last;
1940 }
1941 }
1942 $grpname=$customservicegrp{$key}[0];
1943 if ($customservicegrp{$key}[2] eq "none"){
1944 $customservicegrp{$key}[2]=$Lang::tr{'fwhost err emptytable'};
1945 $port='';
1946 $protocol='';
1947 }
1948 $remark="$customservicegrp{$key}[1]";
1949 if($count >0){print"</table>";$count=1;}
1950 print "<br><b><u>$grpname</u></b>&nbsp; &nbsp; ";
1951 print "<b>$Lang::tr{'remark'}:</b>&nbsp; $remark " if ($remark ne '');
1952 print "&nbsp; <b>$Lang::tr{'used'}:</b> $grpcount x";
1953 if($grpcount == '0')
1954 {
1955 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>";
1956 }
1957 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>";
1958 print"<table width='100%' cellspacing='0' class='tbl'><tr><th align='center'><b>Name</b></th><th align='center'><b>$Lang::tr{'port'}</b></th><th align='center' width='25%'><b>$Lang::tr{'fwhost prot'}</th><th></th></tr>";
1959 }
1960 if( $fwhostsettings{'SRVGRP_NAME'} eq $customservicegrp{$key}[0]) {
1961 print"<tr>";
1962 $col="bgcolor='${Header::colouryellow}'";
1963 }elsif ($count %2 == 0){
1964 print"<tr>";
1965 $col="bgcolor='$color{'color20'}'";
1966 }else{
1967 print"<tr>";
1968 $col="bgcolor='$color{'color22'}'";
1969 }
1970 #make lines yellow if it is a dummy entry
1971 if ($customservicegrp{$key}[2] eq $Lang::tr{'fwhost err emptytable'}){
1972 print"<tr>";
1973 $col="bgcolor='${Header::colouryellow}'";
1974 }
1975 #Set fields if we use protocols in servicegroups
1976 if ($customservicegrp{$key}[2] ne 'TCP' || $customservicegrp{$key}[2] ne 'UDP' || $customservicegrp{$key}[2] ne 'ICMP'){
1977 $port='-';
1978 }
1979 if ($customservicegrp{$key}[2] eq 'GRE'){$protocol='GRE';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} GRE";}
1980 if ($customservicegrp{$key}[2] eq 'ESP'){$protocol='ESP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} ESP";}
1981 if ($customservicegrp{$key}[2] eq 'AH'){$protocol='AH';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} AH";}
1982 if ($customservicegrp{$key}[2] eq 'IGMP'){$protocol='IGMP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IGMP";}
1983 if ($customservicegrp{$key}[2] eq 'IPIP'){$protocol='IPIP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPIP";}
1984 if ($customservicegrp{$key}[2] eq 'IPV6'){$protocol='IPV6';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPv6 encapsulation";}
1985 print "<td width='39%' $col>$customservicegrp{$key}[2]</td>";
1986 foreach my $srv (sort keys %customservice){
1987 if ($customservicegrp{$key}[2] eq $customservice{$srv}[0]){
1988 $protocol=$customservice{$srv}[2];
1989 $port=$customservice{$srv}[1];
1990 last;
1991 }
1992 }
1993 print"<td align='center' $col>$port</td><td align='center' $col>$protocol</td><td width='1%' $col><form method='post'>";
1994 if ($delflag gt '0'){
1995 if ($customservicegrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){
1996 print"<input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title=$Lang::tr{'delete'} />";
1997 }
1998 #check if this group has only one entry
1999 foreach my $key2 (keys %hash) {
2000 if ($hash{$key2}<2 && $key2 eq $customservicegrp{$key}[0]){
2001 print "<input type='hidden' name='last' value='on'>" ;
2002 }
2003 }
2004 }
2005 print"<input type='hidden' name='ACTION' value='delgrpservice'><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'>";
2006 if($protocol eq 'TCP' || $protocol eq 'UDP' || $protocol eq 'ICMP'){
2007 print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2]'></form></td></tr>";
2008 }else{
2009 print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$protocol'></form></td></tr>";
2010 }
2011 $helper=$customservicegrp{$key}[0];
2012 }
2013 print"</table>";
2014 &Header::closebox();
2015 }
2016 }
2017 # Check
2018 sub checkname
2019 {
2020 my %hash=%{(shift)};
2021 foreach my $key (keys %hash) {
2022 if($hash{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
2023 return 0;
2024 }
2025 }
2026 return 1;
2027
2028 }
2029 sub checkgroup
2030 {
2031 &General::readhasharray("$configgrp", \%customgrp );
2032 my $name=shift;
2033 foreach my $key (keys %customservicegrp) {
2034 if($customservicegrp{$key}[0] eq $name){
2035 return 0;
2036 }
2037 }
2038 return 1;
2039 }
2040 sub checkservice
2041 {
2042 &General::readhasharray("$configsrv", \%customservice );
2043 my $name=shift;
2044 foreach my $key (keys %customservice) {
2045 if($customservice{$key}[0] eq $name){
2046 return 0;
2047 }
2048 }
2049 return 1;
2050 }
2051 sub checkip
2052 {
2053
2054 my %hash=%{(shift)};
2055 my $a=shift;
2056 foreach my $key (keys %hash) {
2057 if($hash{$key}[$a] eq $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'})){
2058 return 0;
2059 }
2060 }
2061 return 1;
2062 }
2063 sub checksubnet
2064 {
2065 my %hash=%{(shift)};
2066 &General::readhasharray("$confignet", \%hash);
2067 foreach my $key (keys %hash) {
2068 if(&General::IpInSubnet($fwhostsettings{'IP'},$hash{$key}[1],$hash{$key}[2]))
2069 {
2070 return 1;
2071 }
2072 }
2073 return 0;
2074 }
2075 sub checkservicegroup
2076 {
2077 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2078 #check name
2079 if ( ! &validhostname($fwhostsettings{'SRVGRP_NAME'}))
2080 {
2081 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
2082 return $errormessage;
2083 }
2084 #check empty selectbox
2085 if (keys %customservice lt 1)
2086 {
2087 $errormessage.=$Lang::tr{'fwhost err groupempty'}."<br>";
2088 }
2089 #check if name already exists
2090 if ($fwhostsettings{'updatesrvgrp'} ne 'on'){
2091 foreach my $key (keys %customservicegrp) {
2092 if( $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} ){
2093 $errormessage.=$Lang::tr{'fwhost err grpexist'}."<br>";
2094
2095 }
2096 }
2097 }
2098 #check if service already exists in group
2099 foreach my $key (keys %customservicegrp) {
2100 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[2] eq $fwhostsettings{'CUST_SRV'} ){
2101 $errormessage.=$Lang::tr{'fwhost err srvexist'}."<br>";
2102 }
2103 }
2104 return $errormessage;
2105 }
2106 sub checkrulereload
2107 {
2108 my $search=shift;
2109 &General::readhasharray("$fwconfigfwd", \%fwfwd);
2110 &General::readhasharray("$fwconfiginp", \%fwinp);
2111 &General::readhasharray("$fwconfigout", \%fwout);
2112
2113 #check if service or servicegroup is used in rules
2114 foreach my $key (keys %fwfwd){
2115 if($search eq $fwfwd{$key}[15]){
2116 &General::firewall_config_changed();
2117 return;
2118 }
2119 }
2120 foreach my $key (keys %fwinp){
2121 if($search eq $fwinp{$key}[15]){
2122 &General::firewall_config_changed();
2123 return;
2124 }
2125 }
2126 foreach my $key (keys %fwout){
2127 if($search eq $fwout{$key}[15]){
2128 &General::firewall_config_changed();
2129 return;
2130 }
2131 }
2132 }
2133 sub error
2134 {
2135 if ($errormessage) {
2136 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
2137 print "<class name='base'>$errormessage\n";
2138 print "&nbsp;</class>\n";
2139 &Header::closebox();
2140 }
2141 }
2142 sub hint
2143 {
2144 if ($hint) {
2145 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
2146 print "<class name='base'>$hint\n";
2147 print "&nbsp;</class>\n";
2148 &Header::closebox();
2149 }
2150 }
2151 sub get_name
2152 {
2153 my $val=shift;
2154 &General::setup_default_networks(\%defaultNetworks);
2155 foreach my $network (sort keys %defaultNetworks)
2156 {
2157 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
2158 }
2159 }
2160 sub gethostcount
2161 {
2162 my $searchstring=shift;
2163 my $srvcounter=0;
2164 #Count services used in servicegroups
2165 foreach my $key (keys %customgrp) {
2166 if($customgrp{$key}[2] eq $searchstring){
2167 $srvcounter++;
2168 }
2169 }
2170 #Count services used in firewall - config
2171 foreach my $key1 (keys %fwfwd) {
2172 if($fwfwd{$key1}[4] eq $searchstring){
2173 $srvcounter++;
2174 }
2175 if($fwfwd{$key1}[6] eq $searchstring){
2176 $srvcounter++;
2177 }
2178 }
2179 #Count services used in firewall - input
2180 foreach my $key2 (keys %fwinp) {
2181 if($fwinp{$key2}[4] eq $searchstring){
2182 $srvcounter++;
2183 }
2184 if($fwinp{$key2}[6] eq $searchstring){
2185 $srvcounter++;
2186 }
2187 }
2188 #Count services used in firewall - outgoing
2189 foreach my $key3 (keys %fwout) {
2190 if($fwout{$key3}[4] eq $searchstring){
2191 $srvcounter++;
2192 }
2193 if($fwout{$key3}[6] eq $searchstring){
2194 $srvcounter++;
2195 }
2196 }
2197 return $srvcounter;
2198 }
2199 sub getnetcount
2200 {
2201 my $searchstring=shift;
2202 my $srvcounter=0;
2203 #Count services used in servicegroups
2204 foreach my $key (keys %customgrp) {
2205 if($customgrp{$key}[2] eq $searchstring){
2206 $srvcounter++;
2207 }
2208 }
2209 #Count services used in firewall - config
2210 foreach my $key1 (keys %fwfwd) {
2211 if($fwfwd{$key1}[4] eq $searchstring){
2212 $srvcounter++;
2213 }
2214 if($fwfwd{$key1}[6] eq $searchstring){
2215 $srvcounter++;
2216 }
2217 }
2218 #Count services used in firewall - input
2219 foreach my $key2 (keys %fwinp) {
2220 if($fwinp{$key2}[4] eq $searchstring){
2221 $srvcounter++;
2222 }
2223 if($fwinp{$key2}[6] eq $searchstring){
2224 $srvcounter++;
2225 }
2226 }
2227 #Count services used in firewall - outgoing
2228 foreach my $key3 (keys %fwout) {
2229 if($fwout{$key3}[4] eq $searchstring){
2230 $srvcounter++;
2231 }
2232 if($fwout{$key3}[6] eq $searchstring){
2233 $srvcounter++;
2234 }
2235 }
2236 return $srvcounter;
2237 }
2238 sub getsrvcount
2239 {
2240 my $searchstring=shift;
2241 my $srvcounter=0;
2242 #Count services used in servicegroups
2243 foreach my $key (keys %customservicegrp) {
2244 if($customservicegrp{$key}[2] eq $searchstring){
2245 $srvcounter++;
2246 }
2247 }
2248 #Count services used in firewall - config
2249 foreach my $key1 (keys %fwfwd) {
2250 if($fwfwd{$key1}[15] eq $searchstring){
2251 $srvcounter++;
2252 }
2253 }
2254 #Count services used in firewall - input
2255 foreach my $key2 (keys %fwinp) {
2256 if($fwinp{$key2}[15] eq $searchstring){
2257 $srvcounter++;
2258 }
2259 }
2260 #Count services used in firewall - outgoing
2261 foreach my $key3 (keys %fwout) {
2262 if($fwout{$key3}[15] eq $searchstring){
2263 $srvcounter++;
2264 }
2265 }
2266 return $srvcounter;
2267 }
2268 sub deletefromgrp
2269 {
2270 my $target=shift;
2271 my $config=shift;
2272 my %hash=();
2273 &General::readhasharray("$config",\%hash);
2274 foreach my $key (keys %hash) {
2275 if($hash{$key}[2] eq $target){
2276 delete $hash{$key};
2277 }
2278 }
2279 &General::writehasharray("$config",\%hash);
2280
2281 }
2282 sub plausicheck
2283 {
2284 my $edit=shift;
2285 #check hostname
2286 if (!&validhostname($fwhostsettings{'HOSTNAME'}))
2287 {
2288 $errormessage=$errormessage.$Lang::tr{'fwhost err name'};
2289 $fwhostsettings{'BLK_IP'}='readonly';
2290 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2291 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2292 }
2293 #check if name collides with CCD Netname
2294 &General::readhasharray("$configccdnet", \%ccdnet);
2295 foreach my $key (keys %ccdnet) {
2296 if($ccdnet{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
2297 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdnet'};;
2298 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2299 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2300 last;
2301 }
2302 }
2303 #check if IP collides with CCD NetIP
2304 if ($fwhostsettings{'type'} ne 'mac'){
2305 &General::readhasharray("$configccdnet", \%ccdnet);
2306 foreach my $key (keys %ccdnet) {
2307 my $test=(&General::getnetworkip($fwhostsettings{'IP'},&General::iporsubtocidr($fwhostsettings{'SUBNET'})))."/".$fwhostsettings{'SUBNET'};
2308 if($ccdnet{$key}[1] eq $test){
2309 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdipnet'};
2310 $fwhostsettings{'IP'} = $fwhostsettings{'orgip'};
2311 $fwhostsettings{'SUBNET'} = $fwhostsettings{'orgsubnet'};
2312 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2313 last;
2314 }
2315 }
2316 }
2317 #check if name collides with CCD Hostname
2318 &General::readhasharray("$configccdhost", \%ccdhost);
2319 foreach my $key (keys %ccdhost) {
2320 my ($ip,$sub)=split(/\//,$ccdhost{$key}[33]);
2321 if($ip eq $fwhostsettings{'IP'}){
2322 $errormessage=$Lang::tr{'fwhost err isccdiphost'};
2323 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2324 last;
2325 }
2326 }
2327 #check if IP collides with CCD HostIP (only hosts)
2328 if ($edit eq 'edithost')
2329 {
2330 foreach my $key (keys %ccdhost) {
2331 if($ccdhost{$key}[1] eq $fwhostsettings{'HOSTNAME'}){
2332 $errormessage=$Lang::tr{'fwhost err isccdhost'};
2333 $fwhostsettings{'IP'} = $fwhostsettings{'orgname'};
2334 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2335 last;
2336 }
2337 }
2338 }
2339 #check if network with this name already exists
2340 &General::readhasharray("$confignet", \%customnetwork);
2341 if (!&checkname(\%customnetwork))
2342 {
2343 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err netexist'};
2344 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2345 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2346 }
2347 #check if network ip already exists
2348 if (!&checkip(\%customnetwork,1))
2349 {
2350 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err net'};
2351 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2352 }
2353 #check if host with this name already exists
2354 &General::readhasharray("$confighost", \%customhost);
2355 if (!&checkname(\%customhost))
2356 {
2357 $errormessage.="<br>".$Lang::tr{'fwhost err hostexist'};
2358 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2359 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2360 }
2361 #check if host with this ip already exists
2362 if (!&checkip(\%customhost,2))
2363 {
2364 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err ipcheck'};
2365 }
2366 return;
2367 }
2368 sub getipforgroup
2369 {
2370 my $name=$_[0],
2371 my $type=$_[1];
2372 my $value;
2373
2374 #get address from IPSEC NETWORK
2375 if ($type eq 'IpSec Network'){
2376 foreach my $key (keys %ipsecconf) {
2377 if ($ipsecconf{$key}[1] eq $name){
2378 return $ipsecconf{$key}[11];
2379 }
2380 }
2381 &deletefromgrp($name,$configgrp);
2382 }
2383
2384 #get address from IPSEC HOST
2385 if ($type eq 'IpSec Host'){
2386 foreach my $key (keys %ipsecconf) {
2387 if ($ipsecconf{$key}[1] eq $name){
2388 return $ipsecconf{$key}[10];
2389 }
2390 }
2391 &deletefromgrp($name,$configgrp);
2392 }
2393
2394 #get address from ovpn ccd Net-2-Net
2395 if ($type eq 'OpenVPN N-2-N'){
2396 foreach my $key (keys %ccdhost) {
2397 if($ccdhost{$key}[1] eq $name){
2398 my ($a,$b) = split ("/",$ccdhost{$key}[11]);
2399 $b=&General::iporsubtodec($b);
2400 return "$a/$b";
2401 }
2402 }
2403 &deletefromgrp($name,$configgrp);
2404 }
2405
2406 #get address from ovpn ccd static host
2407 if ($type eq 'OpenVPN static host'){
2408 foreach my $key (keys %ccdhost) {
2409 if($ccdhost{$key}[1] eq $name){
2410 my ($a,$b) = split (/\//,$ccdhost{$key}[33]);
2411 $b=&General::iporsubtodec($b);
2412 return "$a/$b";
2413 }
2414 }
2415 &deletefromgrp($name,$configgrp);
2416 }
2417
2418 #get address from ovpn ccd static net
2419 if ($type eq 'OpenVPN static network'){
2420 foreach my $key (keys %ccdnet) {
2421 if ($ccdnet{$key}[0] eq $name){
2422 my ($a,$b) = split (/\//,$ccdnet{$key}[1]);
2423 $b=&General::iporsubtodec($b);
2424 return "$a/$b";
2425 }
2426 }
2427 }
2428
2429 #check custom addresses
2430 if ($type eq 'Custom Host'){
2431 foreach my $key (keys %customhost) {
2432 if ($customhost{$key}[0] eq $name){
2433 my ($ip,$sub) = split("/",$customhost{$key}[2]);
2434 return $ip;
2435 }
2436 }
2437 }
2438
2439 ##check custom networks
2440 if ($type eq 'Custom Network'){
2441 foreach my $key (keys %customnetwork) {
2442 if($customnetwork{$key}[0] eq $name){
2443 return $customnetwork{$key}[1]."/".$customnetwork{$key}[2];
2444 }
2445 }
2446 }
2447
2448 #check standard networks
2449 if ($type eq 'Standard Network'){
2450 if ($name =~ /OpenVPN/i){
2451 my %ovpn=();
2452 &General::readhash("${General::swroot}/ovpn/settings",\%ovpn);
2453 return $ovpn{'DOVPN_SUBNET'};
2454 }
2455 if ($name eq 'GREEN'){
2456 my %hash=();
2457 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
2458 return $hash{'GREEN_NETADDRESS'}."/".$hash{'GREEN_NETMASK'};
2459 }
2460 if ($name eq 'BLUE'){
2461 my %hash=();
2462 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
2463 return $hash{'BLUE_NETADDRESS'}."/".$hash{'BLUE_NETMASK'};
2464 }
2465 if ($name eq 'ORANGE'){
2466 my %hash=();
2467 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
2468 return $hash{'ORANGE_NETADDRESS'}."/".$hash{'ORANGE_NETMASK'};
2469 }
2470 if ($name eq 'ALL'){
2471 return "0.0.0.0/0.0.0.0";
2472 }
2473 if ($name =~ /IPsec/i){
2474 my %hash=();
2475 &General::readhash("${General::swroot}/vpn/settings",\%hash);
2476 return $hash{'RW_NET'};
2477 }
2478 if ($name eq 'RED'){
2479 return "0.0.0.0/0";
2480 }
2481 }
2482 }
2483 sub decrease
2484 {
2485 my $grp=$_[0];
2486 &General::readhasharray("$confignet", \%customnetwork);