]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/fwhosts.cgi
fwhosts.cgi: properly fetch configured IPsec N2N subnets
[people/pmueller/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 '/var/ipfire/network-functions.pl';
31 require "/var/ipfire/location-functions.pl";
32 require "/usr/lib/firewall/firewall-lib.pl";
33 require "${General::swroot}/lang.pl";
34 require "${General::swroot}/header.pl";
35
36 my %fwhostsettings=();
37 my %customnetwork=();
38 my %customhost=();
39 my %customgrp=();
40 my %customservice=();
41 my %customservicegrp=();
42 my %customlocationgrp=();
43 my %ccdnet=();
44 my %ccdhost=();
45 my %ipsecconf=();
46 my %icmptypes=();
47 my %color=();
48 my %defaultNetworks=();
49 my %mainsettings=();
50 my %ownnet=();
51 my %ipsecsettings=();
52 my %fwfwd=();
53 my %fwinp=();
54 my %fwout=();
55 my %ovpnsettings=();
56 my %netsettings=();
57 my %optionsfw=();
58
59 my $errormessage;
60 my $hint;
61 my $update=0;
62 my $confignet = "${General::swroot}/fwhosts/customnetworks";
63 my $confighost = "${General::swroot}/fwhosts/customhosts";
64 my $configgrp = "${General::swroot}/fwhosts/customgroups";
65 my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
66 my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
67 my $configipsec = "${General::swroot}/vpn/config";
68 my $configsrv = "${General::swroot}/fwhosts/customservices";
69 my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
70 my $configlocationgrp = "${General::swroot}/fwhosts/customlocationgrp";
71 my $fwconfigfwd = "${General::swroot}/firewall/config";
72 my $fwconfiginp = "${General::swroot}/firewall/input";
73 my $fwconfigout = "${General::swroot}/firewall/outgoing";
74 my $fwoptions = "${General::swroot}/optionsfw/settings";
75 my $configovpn = "${General::swroot}/ovpn/settings";
76 my $configipsecrw = "${General::swroot}/vpn/settings";
77
78 unless (-e $confignet) { &General::system("touch", "$confignet"); }
79 unless (-e $confighost) { &General::system("touch", "$confighost"); }
80 unless (-e $configgrp) { &General::system("touch", "$configgrp"); }
81 unless (-e $configsrv) { &General::system("touch", "$configsrv"); }
82 unless (-e $configsrvgrp) { &General::system("touch", "$configsrvgrp"); }
83 unless (-e $configlocationgrp) { &General::system("touch $configlocationgrp"); }
84
85 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
86 &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color);
87 &General::readhash("${General::swroot}/ethernet/settings", \%ownnet);
88 &General::readhash("$configovpn", \%ovpnsettings);
89 &General::readhasharray("$configipsec", \%ipsecconf);
90 &General::readhash("$configipsecrw", \%ipsecsettings);
91 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
92 &General::readhash($fwoptions, \%optionsfw);
93
94 &Header::getcgihash(\%fwhostsettings);
95 &Header::showhttpheaders();
96 &Header::openpage($Lang::tr{'fwhost menu'}, 1, '');
97 &Header::openbigbox('100%', 'center');
98
99 #### JAVA SCRIPT ####
100 print<<END;
101 <script>
102 var PROTOCOLS_WITH_PORTS = ["TCP", "UDP"];
103 var update_protocol = function() {
104 var protocol = \$("#protocol").val();
105
106 if (protocol === undefined)
107 return;
108
109 // Check if we are dealing with a protocol, that knows ports.
110 if (\$.inArray(protocol, PROTOCOLS_WITH_PORTS) >= 0) {
111 \$("#PORT").show();
112 \$("#PROTOKOLL").hide();
113 } else {
114 \$("#PORT").hide();
115 \$("#PROTOKOLL").show();
116 }
117 };
118
119 \$(document).ready(function() {
120 var protocol = \$("#protocol").val();
121 \$("#protocol").change(update_protocol);
122 update_protocol();
123 // Automatically select radio buttons when corresponding
124 // dropdown menu changes.
125 \$("select").change(function() {
126 var id = \$(this).attr("name");
127 \$('#' + id).prop("checked", true);
128 });
129 });
130 </script>
131 END
132
133 ## ACTION ####
134 # Update
135 if ($fwhostsettings{'ACTION'} eq 'updatenet' )
136 {
137 &General::readhasharray("$confignet", \%customnetwork);
138 foreach my $key (keys %customnetwork)
139 {
140 if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'})
141 {
142 $fwhostsettings{'orgname'} = $customnetwork{$key}[0];
143 $fwhostsettings{'orgip'} = $customnetwork{$key}[1];
144 $fwhostsettings{'orgsub'} = $customnetwork{$key}[2];
145 $fwhostsettings{'netremark'} = $customnetwork{$key}[3];
146 $fwhostsettings{'count'} = $customnetwork{$key}[4];
147 delete $customnetwork{$key};
148
149 }
150 }
151 &General::writehasharray("$confignet", \%customnetwork);
152 $fwhostsettings{'actualize'} = 'on';
153 $fwhostsettings{'ACTION'} = 'savenet';
154 }
155 if ($fwhostsettings{'ACTION'} eq 'updatehost')
156 {
157 my ($ip,$subnet);
158 &General::readhasharray("$confighost", \%customhost);
159 foreach my $key (keys %customhost)
160 {
161 if($customhost{$key}[0] eq $fwhostsettings{'orgname'})
162 {
163 if ($customhost{$key}[1] eq 'ip'){
164 ($ip,$subnet) = split (/\//,$customhost{$key}[2]);
165 }else{
166 $ip = $customhost{$key}[2];
167 }
168 $fwhostsettings{'orgip'} = $ip;
169 $fwhostsettings{'count'} = $customhost{$key}[4];
170 delete $customhost{$key};
171 &General::writehasharray("$confighost", \%customhost);
172 }
173 }
174 $fwhostsettings{'actualize'} = 'on';
175 if($fwhostsettings{'orgip'}){
176 $fwhostsettings{'ACTION'} = 'savehost';
177 }else{
178 $fwhostsettings{'ACTION'} = $Lang::tr{'fwhost newhost'};
179 }
180 }
181 if ($fwhostsettings{'ACTION'} eq 'updateservice')
182 {
183 my $count=0;
184 my $needrules=0;
185 $errormessage=&checkports(\%customservice);
186 if ($fwhostsettings{'oldsrvname'} ne $fwhostsettings{'SRV_NAME'} && !&checkgroup($fwhostsettings{'SRV_NAME'})){
187 $errormessage=$Lang::tr{'fwhost err grpexist'};
188 }
189 if (!$errormessage){
190 &General::readhasharray("$configsrv", \%customservice);
191 foreach my $key (keys %customservice)
192 {
193 if ($customservice{$key}[0] eq $fwhostsettings{'oldsrvname'})
194 {
195 delete $customservice{$key};
196 &General::writehasharray("$configsrv", \%customservice);
197 last;
198 }
199 }
200 if ($fwhostsettings{'PROT'} ne 'ICMP'){
201 $fwhostsettings{'ICMP_TYPES'}='BLANK';
202 }
203 my $key1 = &General::findhasharraykey(\%customservice);
204 #find out short ICMP-TYPE
205 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
206 foreach my $key (keys %icmptypes){
207 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwhostsettings{'ICMP_TYPES'}){
208 $fwhostsettings{'ICMP_TYPES'}=$icmptypes{$key}[0];
209 }
210 }
211 foreach my $i (0 .. 4) { $customservice{$key1}[$i] = "";}
212 $customservice{$key1}[0] = $fwhostsettings{'SRV_NAME'};
213 $customservice{$key1}[1] = $fwhostsettings{'SRV_PORT'};
214 $customservice{$key1}[2] = $fwhostsettings{'PROT'};
215 $customservice{$key1}[3] = $fwhostsettings{'ICMP_TYPES'};
216 &General::writehasharray("$configsrv", \%customservice);
217 #check if we need to update firewallrules
218 if ($fwhostsettings{'SRV_NAME'} ne $fwhostsettings{'oldsrvname'}){
219 if ( ! -z $fwconfigfwd ){
220 &General::readhasharray("$fwconfigfwd", \%fwfwd);
221 foreach my $key (sort keys %fwfwd){
222 if ($fwfwd{$key}[15] eq $fwhostsettings{'oldsrvname'}){
223 $fwfwd{$key}[15] = $fwhostsettings{'SRV_NAME'};
224 }
225 }
226 &General::writehasharray("$fwconfigfwd", \%fwfwd);
227 }
228 if ( ! -z $fwconfiginp ){
229 &General::readhasharray("$fwconfiginp", \%fwinp);
230 foreach my $line (sort keys %fwinp){
231 if ($fwfwd{$line}[15] eq $fwhostsettings{'oldsrvname'}){
232 $fwfwd{$line}[15] = $fwhostsettings{'SRV_NAME'};
233 }
234 }
235 &General::writehasharray("$fwconfiginp", \%fwinp);
236 }
237 if ( ! -z $fwconfigout ){
238 &General::readhasharray("$fwconfigout", \%fwout);
239 foreach my $line (sort keys %fwout){
240 if ($fwout{$line}[15] eq $fwhostsettings{'oldsrvname'}){
241 $fwout{$line}[15] = $fwhostsettings{'SRV_NAME'};
242 }
243 }
244 &General::writehasharray("$fwconfigout", \%fwout);
245 }
246 #check if we need to update groups
247 &General::readhasharray("$configsrvgrp", \%customservicegrp);
248 foreach my $key (sort keys %customservicegrp){
249 if($customservicegrp{$key}[2] eq $fwhostsettings{'oldsrvname'}){
250 $customservicegrp{$key}[2] = $fwhostsettings{'SRV_NAME'};
251 &checkrulereload($customservicegrp{$key}[0]);
252 }
253 }
254 &General::writehasharray("$configsrvgrp", \%customservicegrp);
255 }
256 &checkrulereload($fwhostsettings{'SRV_NAME'});
257 $fwhostsettings{'SRV_NAME'} = '';
258 $fwhostsettings{'SRV_PORT'} = '';
259 $fwhostsettings{'PROT'} = '';
260 $fwhostsettings{'ICMP'} = '';
261 $fwhostsettings{'oldsrvicmp'} = '';
262 $fwhostsettings{'updatesrv'} = '';
263 }else{
264 $fwhostsettings{'SRV_NAME'} = $fwhostsettings{'oldsrvname'};
265 $fwhostsettings{'SRV_PORT'} = $fwhostsettings{'oldsrvport'};
266 $fwhostsettings{'PROT'} = $fwhostsettings{'oldsrvprot'};
267 $fwhostsettings{'ICMP'} = $fwhostsettings{'oldsrvicmp'};
268 $fwhostsettings{'updatesrv'}= 'on';
269 }
270 &addservice;
271 }
272 # save
273 if ($fwhostsettings{'ACTION'} eq 'savenet' )
274 {
275 my $needrules=0;
276 if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
277 #check if all fields are set
278 if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
279 {
280 $errormessage=$errormessage.$Lang::tr{'fwhost err empty'};
281 &addnet;
282 &viewtablenet;
283 }else{
284 #convert ip if leading '0' exists
285 $fwhostsettings{'IP'} = &Network::ip_remove_zero($fwhostsettings{'IP'});
286
287 #check valid ip
288 if (!&General::validipandmask($fwhostsettings{'IP'}."/".$fwhostsettings{'SUBNET'}))
289 {
290 $errormessage=$errormessage.$Lang::tr{'fwhost err addr'};
291 $fwhostsettings{'BLK_HOST'} ='readonly';
292 $fwhostsettings{'NOCHECK'} ='false';
293 $fwhostsettings{'error'} ='on';
294 }
295 #check remark
296 if ($fwhostsettings{'NETREMARK'} ne '' && !&validremark($fwhostsettings{'NETREMARK'})){
297 $errormessage=$Lang::tr{'fwhost err remark'};
298 $fwhostsettings{'error'} ='on';
299 }
300 #check if subnet is sigle host
301 if(&General::iporsubtocidr($fwhostsettings{'SUBNET'}) eq '32')
302 {
303 $errormessage=$errormessage.$Lang::tr{'fwhost err sub32'};
304 }
305 if($fwhostsettings{'error'} ne 'on'){
306 my $fullip="$fwhostsettings{'IP'}/".&General::iporsubtocidr($fwhostsettings{'SUBNET'});
307 $errormessage=$errormessage.&General::checksubnets($fwhostsettings{'HOSTNAME'},$fullip,"","exact");
308 }
309 #only check plausi when no error till now
310 if (!$errormessage){
311 &plausicheck("editnet");
312 }
313 if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newnet'} ne 'on' && $errormessage)
314 {
315 $fwhostsettings{'actualize'} = '';
316 my $key = &General::findhasharraykey (\%customnetwork);
317 foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";}
318 $customnetwork{$key}[0] = $fwhostsettings{'orgname'} ;
319 $customnetwork{$key}[1] = $fwhostsettings{'orgip'} ;
320 $customnetwork{$key}[2] = $fwhostsettings{'orgsub'};
321 $customnetwork{$key}[3] = $fwhostsettings{'orgnetremark'};
322 &General::writehasharray("$confignet", \%customnetwork);
323 undef %customnetwork;
324 }
325 if (!$errormessage){
326 &General::readhasharray("$confignet", \%customnetwork);
327 if ($fwhostsettings{'ACTION'} eq 'updatenet'){
328 if ($fwhostsettings{'update'} == '0'){
329 foreach my $key (keys %customnetwork) {
330 if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'}){
331 delete $customnetwork{$key};
332 last;
333 }
334 }
335 }
336 }
337 #get count if actualize is 'on'
338 if($fwhostsettings{'actualize'} eq 'on'){
339 $fwhostsettings{'actualize'} = '';
340 #check if we need to reload rules
341 if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'}){
342 $needrules='on';
343 }
344 if ($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){
345 #check if we need to update groups
346 &General::readhasharray("$configgrp", \%customgrp);
347 foreach my $key (sort keys %customgrp){
348 if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){
349 $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'};
350 last;
351 }
352 }
353 &General::writehasharray("$configgrp", \%customgrp);
354 #check if we need to update firewallrules
355 if ( ! -z $fwconfigfwd ){
356 &General::readhasharray("$fwconfigfwd", \%fwfwd);
357 foreach my $line (sort keys %fwfwd){
358 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
359 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
360 }
361 if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){
362 $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'};
363 }
364 }
365 &General::writehasharray("$fwconfigfwd", \%fwfwd);
366 }
367 if ( ! -z $fwconfiginp ){
368 &General::readhasharray("$fwconfiginp", \%fwinp);
369 foreach my $line (sort keys %fwinp){
370 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
371 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
372 }
373 }
374 &General::writehasharray("$fwconfiginp", \%fwinp);
375 }
376 }
377 }
378 my $key = &General::findhasharraykey (\%customnetwork);
379 foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";}
380 $fwhostsettings{'SUBNET'} = &General::iporsubtocidr($fwhostsettings{'SUBNET'});
381 $customnetwork{$key}[0] = $fwhostsettings{'HOSTNAME'};
382 $customnetwork{$key}[1] = &General::getnetworkip($fwhostsettings{'IP'},$fwhostsettings{'SUBNET'}) ;
383 $customnetwork{$key}[2] = &General::iporsubtodec($fwhostsettings{'SUBNET'}) ;
384 $customnetwork{$key}[3] = $fwhostsettings{'NETREMARK'};
385 &General::writehasharray("$confignet", \%customnetwork);
386 $fwhostsettings{'IP'}=$fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
387 undef %customnetwork;
388 $fwhostsettings{'HOSTNAME'}='';
389 $fwhostsettings{'IP'}='';
390 $fwhostsettings{'SUBNET'}='';
391 $fwhostsettings{'NETREMARK'}='';
392 #check if an edited net affected groups and need to reload rules
393 if ($needrules eq 'on'){
394 &General::firewall_config_changed();
395 }
396 &addnet;
397 &viewtablenet;
398 }else{
399 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
400 &addnet;
401 &viewtablenet;
402 }
403 }
404 }
405 if ($fwhostsettings{'ACTION'} eq 'savehost')
406 {
407 my $needrules=0;
408 if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
409 $fwhostsettings{'SUBNET'}='32';
410 #check if all fields are set
411 if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
412 {
413 $errormessage=$errormessage.$Lang::tr{'fwhost err empty'};
414 $fwhostsettings{'ACTION'} = 'edithost';
415 }else{
416 if($fwhostsettings{'IP'}=~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/){
417 $fwhostsettings{'type'} = 'mac';
418 }elsif($fwhostsettings{'IP'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
419 $fwhostsettings{'type'} = 'ip';
420 }else{
421 $fwhostsettings{'type'} = '';
422 $errormessage=$Lang::tr{'fwhost err ipmac'};
423 }
424 #check remark
425 if ($fwhostsettings{'HOSTREMARK'} ne '' && !&validremark($fwhostsettings{'HOSTREMARK'})){
426 $errormessage=$Lang::tr{'fwhost err remark'};
427 }
428 #CHECK IP-PART
429 if ($fwhostsettings{'type'} eq 'ip'){
430 #convert ip if leading '0' exists
431 $fwhostsettings{'IP'} = &Network::ip_remove_zero($fwhostsettings{'IP'});
432
433 #check for subnet
434 if (rindex($fwhostsettings{'IP'},'/') eq '-1' ){
435 if($fwhostsettings{'type'} eq 'ip' && !&General::validipandmask($fwhostsettings{'IP'}."/32"))
436 {
437 $errormessage.=$errormessage.$Lang::tr{'fwhost err ip'};
438 $fwhostsettings{'error'}='on';
439 }
440 }elsif(rindex($fwhostsettings{'IP'},'/') ne '-1' ){
441 $errormessage=$errormessage.$Lang::tr{'fwhost err ipwithsub'};
442 $fwhostsettings{'error'}='on';
443 }
444 #check if net or broadcast
445 my @tmp= split (/\./,$fwhostsettings{'IP'});
446 if (($tmp[3] eq "0") || ($tmp[3] eq "255")){
447 $errormessage=$Lang::tr{'fwhost err hostip'};
448 }
449 }
450 #only check plausi when no error till now
451 if (!$errormessage){
452 &plausicheck("edithost");
453 }
454 if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newhost'} ne 'on' && $errormessage){
455 $fwhostsettings{'actualize'} = '';
456 my $key = &General::findhasharraykey (\%customhost);
457 foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";}
458 $customhost{$key}[0] = $fwhostsettings{'orgname'} ;
459 $customhost{$key}[1] = $fwhostsettings{'type'} ;
460 if($customhost{$key}[1] eq 'ip'){
461 $customhost{$key}[2] = $fwhostsettings{'orgip'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
462 }else{
463 $customhost{$key}[2] = $fwhostsettings{'orgip'};
464 }
465 $customhost{$key}[3] = $fwhostsettings{'orgremark'};
466 &General::writehasharray("$confighost", \%customhost);
467 undef %customhost;
468 }
469 if (!$errormessage){
470 #get count if host was edited
471 if($fwhostsettings{'actualize'} eq 'on'){
472 if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'}){
473 $needrules='on';
474 }
475 if($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){
476 #check if we need to update groups
477 &General::readhasharray("$configgrp", \%customgrp);
478 foreach my $key (sort keys %customgrp){
479 if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){
480 $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'};
481 }
482 }
483 &General::writehasharray("$configgrp", \%customgrp);
484 #check if we need to update firewallrules
485 if ( ! -z $fwconfigfwd ){
486 &General::readhasharray("$fwconfigfwd", \%fwfwd);
487 foreach my $line (sort keys %fwfwd){
488 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
489 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
490 }
491 if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){
492 $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'};
493 }
494 }
495 &General::writehasharray("$fwconfigfwd", \%fwfwd);
496 }
497 if ( ! -z $fwconfiginp ){
498 &General::readhasharray("$fwconfiginp", \%fwinp);
499 foreach my $line (sort keys %fwinp){
500 if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){
501 $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'};
502 }
503 }
504 &General::writehasharray("$fwconfiginp", \%fwinp);
505 }
506 }
507 }
508 my $key = &General::findhasharraykey (\%customhost);
509 foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";}
510 $customhost{$key}[0] = $fwhostsettings{'HOSTNAME'} ;
511 $customhost{$key}[1] = $fwhostsettings{'type'} ;
512 if ($fwhostsettings{'type'} eq 'ip'){
513 $customhost{$key}[2] = $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
514 }else{
515 $customhost{$key}[2] = $fwhostsettings{'IP'};
516 }
517 $customhost{$key}[3] = $fwhostsettings{'HOSTREMARK'};
518 &General::writehasharray("$confighost", \%customhost);
519 undef %customhost;
520 $fwhostsettings{'HOSTNAME'}='';
521 $fwhostsettings{'IP'}='';
522 $fwhostsettings{'type'}='';
523 $fwhostsettings{'HOSTREMARK'}='';
524 #check if we need to update rules while host was edited
525 if($needrules eq 'on'){
526 &General::firewall_config_changed();
527 }
528 &addhost;
529 &viewtablehost;
530 }else{
531 &addhost;
532 &viewtablehost;
533 }
534 }
535 }
536 if ($fwhostsettings{'ACTION'} eq 'savegrp')
537 {
538 my $grp=$fwhostsettings{'grp_name'};
539 my $rem=$fwhostsettings{'remark'};
540 my $count;
541 my $type;
542 my $updcounter='off';
543 my @target;
544 my @newgrp;
545 &General::readhasharray("$configgrp", \%customgrp);
546 &General::readhasharray("$confignet", \%customnetwork);
547 &General::readhasharray("$confighost", \%customhost);
548 &General::readhasharray("$fwconfigfwd", \%fwfwd);
549 &General::readhasharray("$fwconfiginp", \%fwinp);
550 &General::readhasharray("$fwconfigout", \%fwout);
551 #check name
552 if (!&validhostname($grp)){$errormessage.=$Lang::tr{'fwhost err name'};}
553 #check existing name
554 if (!&checkgroup($grp) && $fwhostsettings{'update'} ne 'on'){$errormessage.=$Lang::tr{'fwhost err grpexist'};}
555 #check remark
556 if ($rem ne '' && !&validremark($rem) && $fwhostsettings{'update'} ne 'on'){
557 $errormessage.=$Lang::tr{'fwhost err remark'};
558 }
559 if ($fwhostsettings{'update'} eq 'on'){
560 #check standard networks
561 if ($fwhostsettings{'grp2'} eq 'std_net'){
562 @target=$fwhostsettings{'DEFAULT_SRC_ADR'};
563 $type='Standard Network';
564 }
565 #check custom networks
566 if ($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} ne ''){
567 @target=$fwhostsettings{'CUST_SRC_NET'};
568 $updcounter='net';
569 $type='Custom Network';
570 }elsif($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} eq ''){
571 $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>";
572 $fwhostsettings{'grp_name'}='';
573 $fwhostsettings{'remark'}='';
574 }
575 #check custom addresses
576 if ($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} ne ''){
577 @target=$fwhostsettings{'CUST_SRC_HOST'};
578 $updcounter='host';
579 $type='Custom Host';
580 }elsif($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} eq ''){
581 $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>";
582 $fwhostsettings{'grp_name'}='';
583 $fwhostsettings{'remark'}='';
584 }
585 #get address from ovpn ccd static net
586 if ($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} ne ''){
587 @target=$fwhostsettings{'OVPN_CCD_NET'};
588 $type='OpenVPN static network';
589 }elsif($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} eq ''){
590 $errormessage=$Lang::tr{'fwhost err groupempty'};
591 $fwhostsettings{'grp_name'}='';
592 $fwhostsettings{'remark'}='';
593 }
594 #get address from ovpn ccd static host
595 if ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} ne ''){
596 @target=$fwhostsettings{'OVPN_CCD_HOST'};
597 $type='OpenVPN static host';
598 }elsif ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} eq ''){
599 $errormessage=$Lang::tr{'fwhost err groupempty'};
600 }
601 #get address from ovpn ccd Net-2-Net
602 if ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} ne ''){
603 @target=$fwhostsettings{'OVPN_N2N'};
604 $type='OpenVPN N-2-N';
605 }elsif ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} eq ''){
606 $errormessage=$Lang::tr{'fwhost err groupempty'};
607 $fwhostsettings{'grp_name'}='';
608 $fwhostsettings{'remark'}='';
609 }
610 #get address from IPSEC HOST
611 if ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} ne ''){
612 @target=$fwhostsettings{'IPSEC_HOST'};
613 $type='IpSec Host';
614 }elsif ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} eq ''){
615 $errormessage=$Lang::tr{'fwhost err groupempty'};
616 $fwhostsettings{'grp_name'}='';
617 $fwhostsettings{'remark'}='';
618 }
619 #get address from IPSEC NETWORK
620 if ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} ne ''){
621 @target=$fwhostsettings{'IPSEC_NET'};
622 $type='IpSec Network';
623 }elsif ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} eq ''){
624 $errormessage=$Lang::tr{'fwhost err groupempty'};
625 $fwhostsettings{'grp_name'}='';
626 $fwhostsettings{'remark'}='';
627 }
628 #check if host/net exists in grp
629
630 my $test="$grp,$fwhostsettings{'oldremark'},@target,$type";
631 foreach my $key (keys %customgrp) {
632 my $test1="$customgrp{$key}[0],$customgrp{$key}[1],$customgrp{$key}[2],$customgrp{$key}[3]";
633 if ($test1 eq $test){
634 $errormessage=$Lang::tr{'fwhost err isingrp'};
635 $fwhostsettings{'update'} = 'on';
636 }
637 }
638 }
639
640 if (!$errormessage){
641 #on first save, we have an empty @target, so fill it with nothing
642 my $targetvalues=@target;
643 if ($targetvalues == '0'){
644 @target="none";
645 }
646 #on update, we have to delete the dummy entry
647 foreach my $key (keys %customgrp){
648 if ($customgrp{$key}[0] eq $grp && $customgrp{$key}[2] eq "none"){
649 delete $customgrp{$key};
650 last;
651 }
652 }
653 &General::writehasharray("$configgrp", \%customgrp);
654 &General::readhasharray("$configgrp", \%customgrp);
655 #create array with new lines
656 foreach my $line (@target){
657 push (@newgrp,"$grp,$rem,$line");
658 }
659 #append new entries
660 my $key = &General::findhasharraykey (\%customgrp);
661 foreach my $line (@newgrp){
662 foreach my $i (0 .. 3) { $customgrp{$key}[$i] = "";}
663 my ($a,$b,$c,$d) = split (",",$line);
664 $customgrp{$key}[0] = $a;
665 $customgrp{$key}[1] = $b;
666 $customgrp{$key}[2] = $c;
667 $customgrp{$key}[3] = $type;
668 }
669 &General::writehasharray("$configgrp", \%customgrp);
670 #update counter in Host/Net
671 $fwhostsettings{'update'}='on';
672 }
673 #check if ruleupdate is needed
674 my $netgrpcount=0;
675 $netgrpcount=&getnetcount($grp);
676 if($netgrpcount > 0 )
677 {
678 &General::firewall_config_changed();
679 }
680 &addgrp;
681 &viewtablegrp;
682 }
683 if ($fwhostsettings{'ACTION'} eq 'savelocationgrp')
684 {
685 my $grp=$fwhostsettings{'grp_name'};
686 my $rem=$fwhostsettings{'remark'};
687 my $count;
688 my $type;
689 my @target;
690 my @newgrp;
691 &General::readhasharray("$configlocationgrp", \%customlocationgrp);
692 &General::readhasharray("$fwconfigfwd", \%fwfwd);
693 &General::readhasharray("$fwconfiginp", \%fwinp);
694 &General::readhasharray("$fwconfigout", \%fwout);
695
696 # Check for existing group name.
697 if (!&checkgroup($grp) && $fwhostsettings{'update'} ne 'on'){
698 $errormessage = $Lang::tr{'fwhost err grpexist'};
699 }
700
701 # Check remark.
702 if ($rem ne '' && !&validremark($rem) && $fwhostsettings{'update'} ne 'on'){
703 $errormessage = $Lang::tr{'fwhost err remark'};
704 }
705
706 if ($fwhostsettings{'update'} eq 'on'){
707 @target=$fwhostsettings{'COUNTRY_CODE'};
708 $type='Location Group';
709
710 #check if host/net exists in grp
711 my $test="$grp,$fwhostsettings{'oldremark'},@target";
712 foreach my $key (keys %customlocationgrp) {
713 my $test1="$customlocationgrp{$key}[0],$customlocationgrp{$key}[1],$customlocationgrp{$key}[2]";
714 if ($test1 eq $test){
715 $errormessage=$Lang::tr{'fwhost err isingrp'};
716 $fwhostsettings{'update'} = 'on';
717 }
718 }
719 }
720
721 if (!$errormessage){
722 #on first save, we have an empty @target, so fill it with nothing
723 my $targetvalues=@target;
724 if ($targetvalues == '0'){
725 @target="none";
726 }
727 #on update, we have to delete the dummy entry
728 foreach my $key (keys %customlocationgrp){
729 if ($customlocationgrp{$key}[0] eq $grp && $customlocationgrp{$key}[2] eq "none"){
730 delete $customlocationgrp{$key};
731 last;
732 }
733 }
734 &General::writehasharray("$configlocationgrp", \%customlocationgrp);
735 &General::readhasharray("$configlocationgrp", \%customlocationgrp);
736 #create array with new lines
737 foreach my $line (@target){
738 push (@newgrp,"$grp,$rem,$line");
739 }
740 #append new entries
741 my $key = &General::findhasharraykey (\%customlocationgrp);
742 foreach my $line (@newgrp){
743 foreach my $i (0 .. 3) { $customlocationgrp{$key}[$i] = "";}
744 my ($a,$b,$c,$d) = split (",",$line);
745 $customlocationgrp{$key}[0] = $a;
746 $customlocationgrp{$key}[1] = $b;
747 $customlocationgrp{$key}[2] = $c;
748 $customlocationgrp{$key}[3] = $type;
749 }
750 &General::writehasharray("$configlocationgrp", \%customlocationgrp);
751 #update counter in Host/Net
752 $fwhostsettings{'update'}='on';
753 }
754 #check if ruleupdate is needed
755 my $locationgrpcount=0;
756 $locationgrpcount=&getlocationcount($grp);
757 if($locationgrpcount > 0 )
758 {
759 &General::firewall_config_changed();
760 }
761 &addlocationgrp;
762 &viewtablelocationgrp;
763 }
764 if ($fwhostsettings{'ACTION'} eq 'saveservice')
765 {
766 my $ICMP;
767 &General::readhasharray("$configsrv", \%customservice );
768 &General::readhasharray("$configgrp", \%customgrp);
769 $errormessage=&checkports(\%customservice);
770 if ($fwhostsettings{'PROT'} eq 'ICMP'){
771 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
772 foreach my $key (keys %icmptypes){
773 if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwhostsettings{'ICMP_TYPES'}){
774 $ICMP=$icmptypes{$key}[0];
775 }
776 }
777 }
778 if($ICMP eq ''){$ICMP=$fwhostsettings{'ICMP_TYPES'};}
779 if ($fwhostsettings{'PROT'} ne 'ICMP'){$ICMP='BLANK';}
780 #Check if a group with the same name already exists
781 if (!&checkgroup($fwhostsettings{'SRV_NAME'})){
782 $errormessage = $Lang::tr{'fwhost err grpexist'};
783 }
784 if (!$errormessage){
785 my $key = &General::findhasharraykey (\%customservice);
786 foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";}
787 $customservice{$key}[0] = $fwhostsettings{'SRV_NAME'};
788 $customservice{$key}[1] = $fwhostsettings{'SRV_PORT'};
789 $customservice{$key}[2] = $fwhostsettings{'PROT'};
790 $customservice{$key}[3] = $ICMP;
791 &General::writehasharray("$configsrv", \%customservice );
792 #reset fields
793 $fwhostsettings{'SRV_NAME'}='';
794 $fwhostsettings{'SRV_PORT'}='';
795 $fwhostsettings{'PROT'}='';
796 $fwhostsettings{'ICMP_TYPES'}='';
797 }
798 &addservice;
799 }
800 if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
801 {
802 my $prot;
803 my $port;
804 my $tcpcounter=0;
805 my $udpcounter=0;
806 &General::readhasharray("$configsrvgrp", \%customservicegrp );
807 &General::readhasharray("$configsrv", \%customservice );
808 $errormessage=&checkservicegroup;
809 #Check if we have more than 15 services from one Protocol in the group
810 #iptables can only handle 15 ports/portranges via multiport
811 foreach my $key (keys %customservicegrp){
812 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}){
813 foreach my $key1 (keys %customservice){
814 $tcpcounter++ if $customservice{$key1}[2] eq 'TCP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0];
815 $tcpcounter++ if $customservice{$key1}[2] eq 'TCP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0] && $customservice{$key1}[1] =~m/:/i;
816 $udpcounter++ if $customservice{$key1}[2] eq 'UDP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0];
817 $udpcounter++ if $customservice{$key1}[2] eq 'UDP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0] && $customservice{$key1}[1] =~m/:/i;
818 }
819 }
820 }
821 if ($tcpcounter > 14){
822 $errormessage=$Lang::tr{'fwhost err maxservicetcp'};
823 }
824 if ($udpcounter > 14){
825 $errormessage=$Lang::tr{'fwhost err maxserviceudp'};
826 }
827 $tcpcounter=0;
828 $udpcounter=0;
829 #check remark
830 if ($fwhostsettings{'SRVGRP_REMARK'} ne '' && !&validremark($fwhostsettings{'SRVGRP_REMARK'})){
831 $errormessage .= $Lang::tr{'fwhost err remark'};
832 }
833 #Check if there is already a service with the same name
834 if(!&checkservice($fwhostsettings{'SRVGRP_NAME'})){
835 $errormessage .= $Lang::tr{'fwhost err srv exists'};
836 }
837 if (!$errormessage){
838 #on first save, we have to enter a dummy value
839 if ($fwhostsettings{'CUST_SRV'} eq ''){
840 $fwhostsettings{'CUST_SRV'}='none';
841 }
842 #on update, we have to delete the dummy entry
843 foreach my $key (keys %customservicegrp){
844 if ($customservicegrp{$key}[2] eq 'none' && $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}){
845 delete $customservicegrp{$key};
846 last;
847 }
848 }
849 &General::writehasharray("$configsrvgrp", \%customservicegrp );
850 #check if remark has also changed
851 if ($fwhostsettings{'SRVGRP_REMARK'} ne $fwhostsettings{'oldsrvgrpremark'} && $fwhostsettings{'updatesrvgrp'} eq 'on')
852 {
853 foreach my $key (keys %customservicegrp)
854 {
855 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvgrpremark'})
856 {
857 $customservicegrp{$key}[1]='';
858 $customservicegrp{$key}[1]=$fwhostsettings{'SRVGRP_REMARK'};
859 }
860 }
861 }
862 my $key = &General::findhasharraykey (\%customservicegrp);
863 foreach my $i (0 .. 2) { $customservice{$key}[$i] = "";}
864 $customservicegrp{$key}[0] = $fwhostsettings{'SRVGRP_NAME'};
865 $customservicegrp{$key}[1] = $fwhostsettings{'SRVGRP_REMARK'};
866 $customservicegrp{$key}[2] = $fwhostsettings{'CUST_SRV'};
867 &General::writehasharray("$configsrvgrp", \%customservicegrp );
868 $fwhostsettings{'updatesrvgrp'}='on';
869 }
870 &checkrulereload($fwhostsettings{'SRVGRP_NAME'});
871 &addservicegrp;
872 &viewtableservicegrp;
873 }
874 # edit
875 if ($fwhostsettings{'ACTION'} eq 'editnet')
876 {
877 &addnet;
878 &viewtablenet;
879 }
880 if ($fwhostsettings{'ACTION'} eq 'edithost')
881 {
882 &addhost;
883 &viewtablehost;
884 }
885 if ($fwhostsettings{'ACTION'} eq 'editgrp')
886 {
887 $fwhostsettings{'update'}='on';
888 &addgrp;
889 &viewtablegrp;
890 }
891 if ($fwhostsettings{'ACTION'} eq 'editlocationgrp')
892 {
893 $fwhostsettings{'update'}='on';
894 &addlocationgrp;
895 &viewtablelocationgrp;
896 }
897 if ($fwhostsettings{'ACTION'} eq 'editservice')
898 {
899 $fwhostsettings{'updatesrv'}='on';
900 &addservice;
901 }
902 if ($fwhostsettings{'ACTION'} eq 'editservicegrp')
903 {
904 $fwhostsettings{'updatesrvgrp'} = 'on';
905 &addservicegrp;
906 &viewtableservicegrp;
907 }
908 # reset
909 if ($fwhostsettings{'ACTION'} eq 'resetnet')
910 {
911 $fwhostsettings{'HOSTNAME'} ="";
912 $fwhostsettings{'IP'} ="";
913 $fwhostsettings{'SUBNET'} ="";
914 &showmenu;
915 }
916 if ($fwhostsettings{'ACTION'} eq 'resethost')
917 {
918 $fwhostsettings{'HOSTNAME'} ="";
919 $fwhostsettings{'IP'} ="";
920 $fwhostsettings{'type'} ="";
921 &showmenu;
922 }
923 if ($fwhostsettings{'ACTION'} eq 'resetgrp')
924 {
925 $fwhostsettings{'grp_name'} ="";
926 $fwhostsettings{'remark'} ="";
927 &showmenu;
928 }
929 if ($fwhostsettings{'ACTION'} eq 'resetlocationgrp')
930 {
931 $fwhostsettings{'grp_name'} ="";
932 $fwhostsettings{'remark'} ="";
933 &showmenu;
934 }
935 # delete
936 if ($fwhostsettings{'ACTION'} eq 'delnet')
937 {
938 &General::readhasharray("$confignet", \%customnetwork);
939 foreach my $key (keys %customnetwork) {
940 if($fwhostsettings{'key'} eq $customnetwork{$key}[0]){
941 delete $customnetwork{$key};
942 &General::writehasharray("$confignet", \%customnetwork);
943 last;
944 }
945 }
946 &addnet;
947 &viewtablenet;
948 }
949 if ($fwhostsettings{'ACTION'} eq 'delhost')
950 {
951 &General::readhasharray("$confighost", \%customhost);
952 foreach my $key (keys %customhost) {
953 if($fwhostsettings{'key'} eq $customhost{$key}[0]){
954 delete $customhost{$key};
955 &General::writehasharray("$confighost", \%customhost);
956 last;
957 }
958 }
959 &addhost;
960 &viewtablehost;
961 }
962 if ($fwhostsettings{'ACTION'} eq 'deletegrphost')
963 {
964 my $grpremark;
965 my $grpname;
966 &General::readhasharray("$configgrp", \%customgrp);
967 foreach my $key (keys %customgrp){
968 if($customgrp{$key}[0].",".$customgrp{$key}[1].",".$customgrp{$key}[2].",".$customgrp{$key}[3] eq $fwhostsettings{'delhost'}){
969 $grpname=$customgrp{$key}[0];
970 $grpremark=$customgrp{$key}[1];
971 #check if we delete the last entry, then generate dummy
972 if ($fwhostsettings{'last'} eq 'on'){
973 $customgrp{$key}[1] = '';
974 $customgrp{$key}[2] = 'none';
975 $customgrp{$key}[3] = '';
976 $fwhostsettings{'last'}='';
977 last;
978 }else{
979 delete $customgrp{$key};
980 }
981 }
982 }
983 &General::writehasharray("$configgrp", \%customgrp);
984 &General::firewall_config_changed();
985 if ($fwhostsettings{'update'} eq 'on'){
986 $fwhostsettings{'remark'}= $grpremark;
987 $fwhostsettings{'grp_name'}=$grpname;
988 }
989 &addgrp;
990 &viewtablegrp;
991 }
992 if ($fwhostsettings{'ACTION'} eq 'deletelocationgrpentry')
993 {
994 my $grpremark;
995 my $grpname;
996 &General::readhasharray("$configlocationgrp", \%customlocationgrp);
997 foreach my $key (keys %customlocationgrp){
998 if($customlocationgrp{$key}[0].",".$customlocationgrp{$key}[1].",".$customlocationgrp{$key}[2].",".$customlocationgrp{$key}[3] eq $fwhostsettings{'delentry'}){
999 $grpname=$customlocationgrp{$key}[0];
1000 $grpremark=$customlocationgrp{$key}[1];
1001 #check if we delete the last entry, then generate dummy
1002 if ($fwhostsettings{'last'} eq 'on'){
1003 $customlocationgrp{$key}[1] = '';
1004 $customlocationgrp{$key}[2] = 'none';
1005 $customlocationgrp{$key}[3] = '';
1006 $fwhostsettings{'last'}='';
1007 last;
1008 }else{
1009 delete $customlocationgrp{$key};
1010 }
1011 }
1012 }
1013 &General::writehasharray("$configlocationgrp", \%customlocationgrp);
1014 &General::firewall_config_changed();
1015 if ($fwhostsettings{'update'} eq 'on'){
1016 $fwhostsettings{'remark'}= $grpremark;
1017 $fwhostsettings{'grp_name'}=$grpname;
1018 }
1019 &addlocationgrp;
1020 &viewtablelocationgrp;
1021 }
1022
1023 if ($fwhostsettings{'ACTION'} eq 'delgrp')
1024 {
1025 &General::readhasharray("$configgrp", \%customgrp);
1026 &decrease($fwhostsettings{'grp_name'});
1027 foreach my $key (sort keys %customgrp)
1028 {
1029 if($customgrp{$key}[0] eq $fwhostsettings{'grp_name'})
1030 {
1031 delete $customgrp{$key};
1032 }
1033 }
1034 &General::writehasharray("$configgrp", \%customgrp);
1035 $fwhostsettings{'grp_name'}='';
1036 &addgrp;
1037 &viewtablegrp;
1038 }
1039 if ($fwhostsettings{'ACTION'} eq 'dellocationgrp')
1040 {
1041 &General::readhasharray("$configlocationgrp", \%customlocationgrp);
1042 &decrease($fwhostsettings{'grp_name'});
1043 foreach my $key (sort keys %customlocationgrp)
1044 {
1045 if($customlocationgrp{$key}[0] eq $fwhostsettings{'grp_name'})
1046 {
1047 delete $customlocationgrp{$key};
1048 }
1049 }
1050 &General::writehasharray("$configlocationgrp", \%customlocationgrp);
1051 $fwhostsettings{'grp_name'}='';
1052 &addlocationgrp;
1053 &viewtablelocationgrp;
1054 }
1055 if ($fwhostsettings{'ACTION'} eq 'delservice')
1056 {
1057 &General::readhasharray("$configsrv", \%customservice);
1058 foreach my $key (keys %customservice) {
1059 if($customservice{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
1060 delete $customservice{$key};
1061 &General::writehasharray("$configsrv", \%customservice);
1062 last;
1063 }
1064 }
1065 $fwhostsettings{'SRV_NAME'}='';
1066 $fwhostsettings{'SRV_PORT'}='';
1067 $fwhostsettings{'PROT'}='';
1068 &addservice;
1069 }
1070 if ($fwhostsettings{'ACTION'} eq 'delservicegrp')
1071 {
1072 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1073 &decreaseservice($fwhostsettings{'SRVGRP_NAME'});
1074 foreach my $key (sort keys %customservicegrp)
1075 {
1076 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'})
1077 {
1078 delete $customservicegrp{$key};
1079 }
1080 }
1081 &General::writehasharray("$configsrvgrp", \%customservicegrp);
1082 $fwhostsettings{'SRVGRP_NAME'}='';
1083 &addservicegrp;
1084 &viewtableservicegrp;
1085 }
1086 if ($fwhostsettings{'ACTION'} eq 'delgrpservice')
1087 {
1088 my $grpname;
1089 my $grpremark;
1090 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1091 foreach my $key (keys %customservicegrp){
1092 if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2] eq $fwhostsettings{'delsrvfromgrp'})
1093 {
1094 $grpname=$customservicegrp{$key}[0];
1095 $grpremark=$customservicegrp{$key}[1];
1096 if($fwhostsettings{'last'} eq 'on'){
1097 $customservicegrp{$key}[2] = 'none';
1098 $fwhostsettings{'last'} = '';
1099 last;
1100 }else{
1101 delete $customservicegrp{$key};
1102 }
1103 }
1104 }
1105 &General::writehasharray("$configsrvgrp", \%customservicegrp);
1106 &General::firewall_config_changed();
1107 if ($fwhostsettings{'updatesrvgrp'} eq 'on'){
1108 $fwhostsettings{'SRVGRP_NAME'}=$grpname;
1109 $fwhostsettings{'SRVGRP_REMARK'}=$grpremark;
1110 }
1111 &addservicegrp;
1112 &viewtableservicegrp;
1113 }
1114 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newnet'})
1115 {
1116 &addnet;
1117 &viewtablenet;
1118 }
1119 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newhost'})
1120 {
1121 &addhost;
1122 &viewtablehost;
1123 }
1124 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newgrp'})
1125 {
1126 &addgrp;
1127 &viewtablegrp;
1128 }
1129 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newlocationgrp'})
1130 {
1131 &addlocationgrp;
1132 &viewtablelocationgrp;
1133 }
1134 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservice'})
1135 {
1136 &addservice;
1137 }
1138 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservicegrp'})
1139 {
1140 &addservicegrp;
1141 &viewtableservicegrp;
1142 }
1143 if ($fwhostsettings{'ACTION'} eq 'changegrpremark')
1144 {
1145 &General::readhasharray("$configgrp", \%customgrp);
1146 if ($fwhostsettings{'oldrem'} ne $fwhostsettings{'newrem'} && (&validremark($fwhostsettings{'newrem'}) || $fwhostsettings{'newrem'} eq '')){
1147 foreach my $key (sort keys %customgrp)
1148 {
1149 if($customgrp{$key}[0] eq $fwhostsettings{'grp'} && $customgrp{$key}[1] eq $fwhostsettings{'oldrem'})
1150 {
1151 $customgrp{$key}[1]='';
1152 $customgrp{$key}[1]=$fwhostsettings{'newrem'};
1153 }
1154 }
1155 &General::writehasharray("$configgrp", \%customgrp);
1156 $fwhostsettings{'update'}='on';
1157 $fwhostsettings{'remark'}=$fwhostsettings{'newrem'};
1158 }else{
1159 $errormessage=$Lang::tr{'fwhost err remark'};
1160 $fwhostsettings{'remark'}=$fwhostsettings{'oldrem'};
1161 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1162 $fwhostsettings{'update'} = 'on';
1163 }
1164 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1165 &addgrp;
1166 &viewtablegrp;
1167 }
1168 if ($fwhostsettings{'ACTION'} eq 'changelocationgrpremark')
1169 {
1170 &General::readhasharray("$configlocationgrp", \%customlocationgrp);
1171 if ($fwhostsettings{'oldrem'} ne $fwhostsettings{'newrem'} && (&validremark($fwhostsettings{'newrem'}) || $fwhostsettings{'newrem'} eq '')){
1172 foreach my $key (sort keys %customlocationgrp)
1173 {
1174 if($customlocationgrp{$key}[0] eq $fwhostsettings{'grp'} && $customlocationgrp{$key}[1] eq $fwhostsettings{'oldrem'})
1175 {
1176 $customlocationgrp{$key}[1]='';
1177 $customlocationgrp{$key}[1]=$fwhostsettings{'newrem'};
1178 }
1179 }
1180 &General::writehasharray("$configlocationgrp", \%customlocationgrp);
1181 $fwhostsettings{'update'}='on';
1182 $fwhostsettings{'remark'}=$fwhostsettings{'newrem'};
1183 }else{
1184 $errormessage=$Lang::tr{'fwhost err remark'};
1185 $fwhostsettings{'remark'}=$fwhostsettings{'oldrem'};
1186 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1187 $fwhostsettings{'update'} = 'on';
1188 }
1189 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1190 &addlocationgrp;
1191 &viewtablelocationgrp;
1192 }
1193 if ($fwhostsettings{'ACTION'} eq 'changesrvgrpremark')
1194 {
1195 &General::readhasharray("$configsrvgrp", \%customservicegrp );
1196 if ($fwhostsettings{'oldsrvrem'} ne $fwhostsettings{'newsrvrem'} && (&validremark($fwhostsettings{'newsrvrem'}) || $fwhostsettings{'newsrvrem'} eq '')){
1197 foreach my $key (sort keys %customservicegrp)
1198 {
1199 if($customservicegrp{$key}[0] eq $fwhostsettings{'srvgrp'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvrem'})
1200 {
1201 $customservicegrp{$key}[1]='';
1202 $customservicegrp{$key}[1]=$fwhostsettings{'newsrvrem'};
1203 }
1204 }
1205 &General::writehasharray("$configsrvgrp", \%customservicegrp);
1206 $fwhostsettings{'updatesrvgrp'}='on';
1207 $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'newsrvrem'};
1208 }elsif($fwhostsettings{'oldsrvrem'} eq $fwhostsettings{'newsrvrem'}){
1209 &addservicegrp;
1210 &viewtableservicegrp;
1211 }else{
1212 $errormessage=$Lang::tr{'fwhost err remark'};
1213 $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'oldsrvrem'};
1214 $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'};
1215 $fwhostsettings{'updatesrvgrp'} = 'on';
1216 }
1217 $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'};
1218 &addservicegrp;
1219 &viewtableservicegrp;
1220 }
1221 if ($fwhostsettings{'ACTION'} eq 'changesrvgrpname')
1222 {
1223 &General::readhasharray("$configsrvgrp", \%customservicegrp );
1224 if ($fwhostsettings{'oldsrvgrpname'} ne $fwhostsettings{'srvgrp'}){
1225 #Check new groupname
1226 if (!&validhostname($fwhostsettings{'srvgrp'})){
1227 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1228 }
1229 if (!$errormessage){
1230 #Rename group in customservicegroup
1231 foreach my $key (keys %customservicegrp) {
1232 if($customservicegrp{$key}[0] eq $fwhostsettings{'oldsrvgrpname'}){
1233 $customservicegrp{$key}[0]=$fwhostsettings{'srvgrp'};
1234 }
1235 }
1236 &General::writehasharray("$configsrvgrp", \%customservicegrp );
1237 #change name in FW Rules
1238 &changenameinfw($fwhostsettings{'oldsrvgrpname'},$fwhostsettings{'srvgrp'},15);
1239 }
1240 }
1241 &addservicegrp;
1242 &viewtableservicegrp;
1243 }
1244 if ($fwhostsettings{'ACTION'} eq 'changegrpname')
1245 {
1246 &General::readhasharray("$configgrp", \%customgrp );
1247 if ($fwhostsettings{'oldgrpname'} ne $fwhostsettings{'grp'}){
1248 #Check new groupname
1249 if (!&validhostname($fwhostsettings{'grp'})){
1250 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1251 }
1252 if (!$errormessage){
1253 #Rename group in customservicegroup
1254 foreach my $key (keys %customgrp) {
1255 if($customgrp{$key}[0] eq $fwhostsettings{'oldgrpname'}){
1256 $customgrp{$key}[0]=$fwhostsettings{'grp'};
1257 }
1258 }
1259 &General::writehasharray("$configgrp", \%customgrp );
1260 #change name in FW Rules
1261 &changenameinfw($fwhostsettings{'oldgrpname'},$fwhostsettings{'grp'},4);
1262 &changenameinfw($fwhostsettings{'oldgrpname'},$fwhostsettings{'grp'},6);
1263 }
1264 }
1265 &addgrp;
1266 &viewtablegrp;
1267 }
1268 if ($fwhostsettings{'ACTION'} eq 'changelocationgrpname')
1269 {
1270 &General::readhasharray("$configlocationgrp", \%customlocationgrp );
1271 if ($fwhostsettings{'oldgrpname'} ne $fwhostsettings{'grp'}){
1272 #Check new groupname
1273 if (!&validhostname($fwhostsettings{'grp'})){
1274 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1275 }
1276 if (!$errormessage){
1277 # Rename group.
1278 foreach my $key (keys %customlocationgrp) {
1279 if($customlocationgrp{$key}[0] eq $fwhostsettings{'oldgrpname'}){
1280 $customlocationgrp{$key}[0]=$fwhostsettings{'grp'};
1281 }
1282 }
1283 &General::writehasharray("$configlocationgrp", \%customlocationgrp );
1284 #change name in FW Rules
1285 &changenameinfw($fwhostsettings{'oldgrpname'},$fwhostsettings{'grp'},4,"location");
1286 &changenameinfw($fwhostsettings{'oldgrpname'},$fwhostsettings{'grp'},6,"location");
1287 }
1288 }
1289 &addlocationgrp;
1290 &viewtablelocationgrp;
1291 }
1292 ### VIEW ###
1293 if($fwhostsettings{'ACTION'} eq '')
1294 {
1295 &showmenu;
1296 }
1297 ### FUNCTIONS ###
1298 sub showmenu {
1299 &Header::openbox('100%', 'left',);
1300 print "$Lang::tr{'fwhost welcome'}";
1301 print<<END;
1302 <br><br><table border='0' width='100%'>
1303 <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'}' ><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newlocationgrp'}' ></form></td>
1304 <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>
1305 <tr><td colspan='6'></td></tr></table>
1306 END
1307 &Header::closebox();
1308
1309 }
1310 # Add
1311 sub addnet
1312 {
1313 &error;
1314 &showmenu;
1315 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addnet'});
1316 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
1317 $fwhostsettings{'orgnetremark'}=$fwhostsettings{'NETREMARK'};
1318 print<<END;
1319 <table border='0' width='100%' >
1320 <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>
1321 <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>
1322 <tr><td>$Lang::tr{'netmask'}:</td><td><input type='TEXT' name='SUBNET' value='$fwhostsettings{'SUBNET'}' $fwhostsettings{'BLK_IP'} size='20' maxlength='15'></td></tr>
1323 <tr><td>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='NETREMARK' value='$fwhostsettings{'NETREMARK'}' style='width: 98.5%;'></td></tr>
1324 <tr><td colspan='6'><br></td></tr><tr>
1325 END
1326 if ($fwhostsettings{'ACTION'} eq 'editnet' || $fwhostsettings{'error'} eq 'on')
1327 {
1328 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'}'>";
1329 }else{
1330 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'>";
1331 }
1332 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>";
1333 &Header::closebox();
1334 }
1335 sub addhost
1336 {
1337 &error;
1338 &showmenu;
1339 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addhost'});
1340 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
1341 $fwhostsettings{'orgremark'}=$fwhostsettings{'HOSTREMARK'};
1342 print<<END;
1343 <table width='100%'>
1344 <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>
1345 <tr><td>IP/MAC:</td><td><input type='TEXT' name='IP' value='$fwhostsettings{'IP'}' $fwhostsettings{'BLK_IP'} size='20' maxlength='17'></td></tr>
1346 <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='HOSTREMARK' value='$fwhostsettings{'HOSTREMARK'}' style='width:98%;'></td></tr>
1347 <tr><td colspan='5'><br></td></tr><tr>
1348 END
1349
1350 if ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'} eq 'on')
1351 {
1352
1353 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>";
1354 }else{
1355 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'>";
1356 }
1357 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>";
1358 &Header::closebox();
1359 }
1360 sub addgrp
1361 {
1362 &hint;
1363 &error;
1364 &showmenu;
1365 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addgrp'});
1366 &General::setup_default_networks(\%defaultNetworks);
1367 &General::readhasharray("$configccdnet", \%ccdnet);
1368 &General::readhasharray("$confignet", \%customnetwork);
1369 &General::readhasharray("$configccdhost", \%ccdhost);
1370 &General::readhasharray("$confighost", \%customhost);
1371 &General::readhasharray("$configipsec", \%ipsecconf);
1372
1373 my %checked=();
1374 my $show='';
1375 $checked{'check1'}{'off'} = '';
1376 $checked{'check1'}{'on'} = '';
1377 $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED';
1378 $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'};
1379 $fwhostsettings{'oldgrpname'}=$fwhostsettings{'grp_name'};
1380 my $grp=$fwhostsettings{'grp_name'};
1381 my $rem=$fwhostsettings{'remark'};
1382 if ($fwhostsettings{'update'} eq ''){
1383 print<<END;
1384 <table width='100%' border='0'>
1385 <tr>
1386 <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td>
1387 <td><form method='post'><input type='TEXT' name='grp_name' value='$fwhostsettings{'grp_name'}' size='30'></td>
1388 </tr>
1389 <tr>
1390 <td>$Lang::tr{'remark'}:</td>
1391 <td ><input type='TEXT' name='remark' value='$fwhostsettings{'remark'}' style='width: 99%;'></td>
1392 </tr>
1393 <tr>
1394 <td colspan='2'><br></td>
1395 </tr>
1396 </table>
1397 END
1398 }else{
1399 print<<END;
1400 <table width='100%' border='0'><form method='post'>
1401 <tr>
1402 <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td>
1403 <td style='width:30%;'><input type='TEXT' name='grp' value='$fwhostsettings{'grp_name'}' size='30'></td>
1404 <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>
1405 <td></td></form>
1406 </tr>
1407 <tr><form method='post' style='display:inline'>
1408 <td>$Lang::tr{'remark'}:</td>
1409 <td colspan='2' style='width:98%;'><input type='TEXT' name='newrem' value='$fwhostsettings{'remark'}' style='width:98%;'></td>
1410 <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>
1411 </tr>
1412 </table></form>
1413 <br><br>
1414 END
1415 }
1416 if ($fwhostsettings{'update'} eq 'on'){
1417 print<<END;
1418 <form method='post'><input type='hidden' name='remark' value='$rem'><input type='hidden' name='grp_name' value='$grp'>
1419 <table width='100%' border='0'>
1420 <tr><td width=50% valign='top'>
1421 <table width='90%' border='0'>
1422 <tr>
1423 <td style='width:15em;'>
1424 <label>
1425 <input type='radio' name='grp2' value='std_net' id='DEFAULT_SRC_ADR' checked>
1426 $Lang::tr{'fwhost stdnet'}
1427 </label>
1428 </td>
1429 <td style='text-align:right;'>
1430 <select name='DEFAULT_SRC_ADR' style='width:16em;'>
1431 END
1432 foreach my $network (sort keys %defaultNetworks)
1433 {
1434 next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP");
1435 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
1436 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1437 print " selected='selected'" if ($fwhostsettings{'DEFAULT_SRC_ADR'} eq $defaultNetworks{$network}{'NAME'});
1438 my $defnet="$defaultNetworks{$network}{'NAME'}_NETADDRESS";
1439 my $defsub="$defaultNetworks{$network}{'NAME'}_NETMASK";
1440 my $defsub1=&General::subtocidr($ownnet{$defsub});
1441 $ownnet{$defnet}='' if ($defaultNetworks{$network}{'NAME'} eq 'RED');
1442 if ($ownnet{$defnet}){
1443 print ">$network ($ownnet{$defnet}/$defsub1)</option>";
1444 }else{
1445 print ">$network</option>";
1446 }
1447 }
1448 print"</select></td></tr>";
1449 if (! -z $confignet){
1450 print<<END;
1451 <tr>
1452 <td>
1453 <label>
1454 <input type='radio' name='grp2' id='CUST_SRC_NET' value='cust_net' $checked{'grp2'}{'cust_net'}>
1455 $Lang::tr{'fwhost cust net'}:
1456 </label>
1457 </td>
1458 <td style='text-align:right;'>
1459 <select name='CUST_SRC_NET' style='width:16em;'>";
1460 END
1461 foreach my $key (sort { ncmp($customnetwork{$a}[0],$customnetwork{$b}[0]) } keys %customnetwork) {
1462 print"<option>$customnetwork{$key}[0]</option>";
1463 }
1464 print"</select></td></tr>";
1465 }
1466 if (! -z $confighost){
1467 print<<END;
1468 <tr>
1469 <td valign='top'>
1470 <label>
1471 <input type='radio' name='grp2' id='CUST_SRC_HOST' value='cust_host' $checked{'grp2'}{'cust_host'}>
1472 $Lang::tr{'fwhost cust addr'}:
1473 </label>
1474 </td>
1475 <td style='text-align:right;'>
1476 <select name='CUST_SRC_HOST' style='width:16em;'>";
1477 END
1478 foreach my $key (sort { ncmp($customhost{$a}[0],$customhost{$b}[0]) } keys %customhost) {
1479 print"<option>$customhost{$key}[0]</option>";
1480 }
1481 print"</select></td></tr>";
1482 }
1483 print"</table>";
1484 #Inner table right
1485 print"</td><td align='right' style='vertical-align:top;'><table width='90%' border='0'>";
1486 #OVPN networks
1487 if (! -z $configccdnet){
1488 print<<END;
1489 <td style='width:15em;'>
1490 <label>
1491 <input type='radio' name='grp2' id='OVPN_CCD_NET' value='ovpn_net' $checked{'grp2'}{'ovpn_net'}>
1492 $Lang::tr{'fwhost ccdnet'}
1493 </label>
1494 </td>
1495 <td style='text-align:right;'>
1496 <select name='OVPN_CCD_NET' style='width:16em;'>";
1497 END
1498 foreach my $key (sort { ncmp($ccdnet{$a}[0],$ccdnet{$b}[0]) } keys %ccdnet)
1499 {
1500 print"<option value='$ccdnet{$key}[0]'>$ccdnet{$key}[0]</option>";
1501 }
1502 print"</select></td></tr>";
1503 }
1504 #OVPN clients
1505 my @ovpn_clients=();
1506 foreach my $key (sort { ncmp($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost)
1507 {
1508 if ($ccdhost{$key}[33] ne ''){
1509 $show='1';
1510 push (@ovpn_clients,$ccdhost{$key}[1]);
1511 }
1512 }
1513 if ($show eq '1'){
1514 $show='';
1515 print<<END;
1516 <td style='width:15em;'>
1517 <label>
1518 <input type='radio' name='grp2' value='ovpn_host' $checked{'grp2'}{'ovpn_host'}>
1519 $Lang::tr{'fwhost ccdhost'}
1520 </label>
1521 </td>
1522 <td style='text-align:right;'>
1523 <select name='OVPN_CCD_HOST' style='width:16em;'>" if ($show eq '');
1524 END
1525 foreach(@ovpn_clients){
1526 print"<option value='$_'>$_</option>";
1527 }
1528 print"</select></td></tr>";
1529 }
1530 #OVPN n2n networks
1531 my @OVPN_N2N=();
1532 foreach my $key (sort { ncmp($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost) {
1533 if($ccdhost{$key}[3] eq 'net'){
1534 $show='1';
1535 push (@OVPN_N2N,$ccdhost{$key}[1]);
1536 }
1537 }
1538 if ($show eq '1'){
1539 $show='';
1540 print<<END;
1541 <td style='width:15em;'>
1542 <label>
1543 <input type='radio' name='grp2' id='OVPN_N2N' value='ovpn_n2n' $checked{'grp2'}{'ovpn_n2n'}>
1544 $Lang::tr{'fwhost ovpn_n2n'}:
1545 </label>
1546 </td>
1547 <td style='text-align:right;'>
1548 <select name='OVPN_N2N' style='width:16em;'>"
1549 END
1550 foreach(@OVPN_N2N){
1551 print"<option>$_</option>";
1552 }
1553 print"</select></td></tr>";
1554 }
1555 #IPsec networks
1556
1557 foreach my $key (sort { ncmp($ipsecconf{$a}[0],$ipsecconf{$b}[0]) } keys %ipsecconf) {
1558 if ($ipsecconf{$key}[3] eq 'net' || ($optionsfw{'SHOWDROPDOWN'} eq 'on' && $ipsecconf{$key}[3] ne 'host')){
1559 print "<td style='width:15em;'><label><input type='radio' name='grp2' id='IPSEC_NET' value='ipsec_net' $checked{'grp2'}{'ipsec_net'}>$Lang::tr{'fwhost ipsec net'}</label></td><td style='text-align:right;'><select name='IPSEC_NET' style='width:16em;'>" if $show eq '';
1560 $show=1;
1561 #Check if we have more than one REMOTE subnet in config
1562 my @arr1 = split /\|/, $ipsecconf{$key}[11];
1563 my $cnt1 += @arr1;
1564
1565 print"<option value=$ipsecconf{$key}[1]>";
1566 print"$ipsecconf{$key}[1]";
1567 print" ($Lang::tr{'fwdfw all subnets'})" if $cnt1 > 1; #If this Conenction has more than one subnet, print one option for all subnets
1568 print"</option>";
1569
1570 if ($cnt1 > 1){
1571 foreach my $val (@arr1){
1572 #normalize subnet to cidr notation
1573 my ($val1,$val2) = split /\//, $val;
1574 my $val3 = &General::iporsubtocidr($val2);
1575 print "<option ";
1576 print "value='$ipsecconf{$key}[1]|$val1/$val3'";
1577 print ">$ipsecconf{$key}[1] ($val1/$val3)</option>";
1578 }
1579 }
1580 }
1581 }
1582 print"</select></td></tr>";
1583 print"</table>";
1584 print"</td></tr></table>";
1585 print"<br><br>";
1586 }
1587 print"<table width='100%'>";
1588 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>";
1589 &Header::closebox();
1590 }
1591 sub addlocationgrp
1592 {
1593 &hint;
1594 &error;
1595 &showmenu;
1596 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addlocationgrp'});
1597
1598 my %checked=();
1599 my $show='';
1600 $checked{'check1'}{'off'} = '';
1601 $checked{'check1'}{'on'} = '';
1602 $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED';
1603 $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'};
1604 $fwhostsettings{'oldgrpname'}=$fwhostsettings{'grp_name'};
1605 my $grp=$fwhostsettings{'grp_name'};
1606 my $rem=$fwhostsettings{'remark'};
1607 if ($fwhostsettings{'update'} eq ''){
1608 print<<END;
1609 <table width='100%' border='0'>
1610 <tr>
1611 <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td>
1612 <td><form method='post'><input type='TEXT' name='grp_name' value='$fwhostsettings{'grp_name'}' size='30'></td>
1613 </tr>
1614 <tr>
1615 <td>$Lang::tr{'remark'}:</td>
1616 <td ><input type='TEXT' name='remark' value='$fwhostsettings{'remark'}' style='width: 99%;'></td>
1617 </tr>
1618 <tr>
1619 <td colspan='2'><br></td>
1620 </tr>
1621 </table>
1622 END
1623 } else {
1624 print<<END;
1625 <table width='100%' border='0'>
1626 <form method='post'><tr>
1627 <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td>
1628 <td style='width:30%;'><input type='TEXT' name='grp' value='$fwhostsettings{'grp_name'}' size='30'></td>
1629 <td>
1630 <input type='submit' value='$Lang::tr{'fwhost change'}'>
1631 <input type='hidden' name='oldgrpname' value='$fwhostsettings{'oldgrpname'}'>
1632 <input type='hidden' name='ACTION' value='changelocationgrpname'>
1633 </td>
1634 <td></td>
1635 </tr></form>
1636 <tr><form method='post' style='display:inline'>
1637 <td>$Lang::tr{'remark'}:</td>
1638 <td colspan='2' style='width:98%;'>
1639 <input type='TEXT' name='newrem' value='$fwhostsettings{'remark'}' style='width:98%;'>
1640 </td>
1641 <td align='right'>
1642 <input type='submit' value='$Lang::tr{'fwhost change'}'>
1643 <input type='hidden' name='grp' value='$fwhostsettings{'grp_name'}'>
1644 <input type='hidden' name='oldrem' value='$fwhostsettings{'oldremark'}'>
1645 <input type='hidden' name='ACTION' value='changelocationgrpremark'>
1646 </td>
1647 </tr></form>
1648 </table>
1649 <br><br>
1650 END
1651 }
1652 if ($fwhostsettings{'update'} eq 'on') {
1653 my @location_locations = &fwlib::get_locations();
1654
1655 print<<END;
1656 <form method='post'>
1657 <input type='hidden' name='remark' value='$rem'>
1658 <input type='hidden' name='grp_name' value='$grp'>
1659
1660 <table width='100%' border='0'>
1661 <tr>
1662 <td style='text-align:left;'>
1663 <select name='COUNTRY_CODE' style='width:16em;'>";
1664 END
1665 foreach my $location (@location_locations) {
1666 # Get full country name.
1667 my $fullname = &Location::Functions::get_full_country_name($location);
1668
1669 print"<option value='$location'>$location - $fullname</option>\n";
1670 }
1671 print <<END;
1672 </select>
1673 </td>
1674 </tr>
1675 </table>
1676 <br><br>
1677 END
1678 }
1679 print <<END;
1680 <table width='100%'>
1681 <tr><td style='text-align:right;'>
1682 <input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' />
1683 <input type='hidden' name='oldremark' value='$fwhostsettings{'oldremark'}'>
1684 <input type='hidden' name='update' value=\"$fwhostsettings{'update'}\">
1685 <input type='hidden' name='ACTION' value='savelocationgrp' >
1686 </form>
1687
1688 <form method='post' style='display:inline'>
1689
1690 <input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'>
1691 <input type='hidden' name='ACTION' value='resetlocationgrp'>
1692
1693 </form>
1694 </td></tr></table>
1695 END
1696 &Header::closebox();
1697 }
1698 sub addservice
1699 {
1700 &error;
1701 &showmenu;
1702 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservice'});
1703 if ($fwhostsettings{'updatesrv'} eq 'on')
1704 {
1705 $fwhostsettings{'oldsrvname'} = $fwhostsettings{'SRV_NAME'};
1706 $fwhostsettings{'oldsrvport'} = $fwhostsettings{'SRV_PORT'};
1707 $fwhostsettings{'oldsrvprot'} = $fwhostsettings{'PROT'};
1708 $fwhostsettings{'oldsrvicmp'} = $fwhostsettings{'ICMP'};
1709 }
1710 print<<END;
1711 <table width='100%' border='0'><form method='post'>
1712 <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>
1713 <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost prot'}:</td><td><select name='PROT' id='protocol' >
1714 END
1715 foreach ("TCP","UDP","ICMP")
1716 {
1717 if ($_ eq $fwhostsettings{'PROT'})
1718 {
1719 print"<option selected>$_</option>";
1720 }else{
1721 print"<option>$_</option>";
1722 }
1723 }
1724 print<<END;
1725 </select></td></tr></table>
1726 <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'>
1727 END
1728 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1729 print"<option value='All ICMP-Types'>$Lang::tr{'fwdfw all icmp'}</option>";
1730 foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
1731 if ($icmptypes{$key}[0] eq $fwhostsettings{'oldsrvicmp'}){
1732 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1733 }else{
1734 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1735 }
1736 }
1737 print<<END;
1738 </select></td></tr></table></div>
1739 <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>
1740 <table width='100%' border='0'><tr><td colspan='6'><br></td></tr>
1741 <tr><td colspan='6' align='right'>
1742 END
1743 if ($fwhostsettings{'updatesrv'} eq 'on')
1744 {
1745 print<<END;
1746 <input type='submit' value='$Lang::tr{'update'}'style='min-width:100px;' >
1747 <input type='hidden' name='ACTION' value='updateservice'>
1748 <input type='hidden' name='oldsrvname' value='$fwhostsettings{'oldsrvname'}'>
1749 <input type='hidden' name='oldsrvport' value='$fwhostsettings{'oldsrvport'}'>
1750 <input type='hidden' name='oldsrvprot' value='$fwhostsettings{'oldsrvprot'}'>
1751 <input type='hidden' name='oldsrvicmp' value='$fwhostsettings{'oldsrvicmp'}'>
1752 </form>
1753 END
1754 }else{
1755 print"<input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='saveservice'></form>";
1756 }
1757 print<<END;
1758 <form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></form></td></tr>
1759 </table></form>
1760 END
1761 &Header::closebox();
1762 &viewtableservice;
1763 }
1764 sub addservicegrp
1765 {
1766 &hint;
1767 &error;
1768 &showmenu;
1769 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservicegrp'});
1770 $fwhostsettings{'oldsrvgrpremark'}=$fwhostsettings{'SRVGRP_REMARK'};
1771 $fwhostsettings{'oldsrvgrpname'}=$fwhostsettings{'SRVGRP_NAME'};
1772 if ($fwhostsettings{'updatesrvgrp'} eq ''){
1773 print<<END;
1774 <table width='100%' border='0'><form method='post'>
1775 <tr><td width='10%'>$Lang::tr{'fwhost addgrpname'}</td><td><input type='text' name='SRVGRP_NAME' value='$fwhostsettings{'SRVGRP_NAME'}' size='24'></td></tr>
1776 <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='text' name='SRVGRP_REMARK' value='$fwhostsettings{'SRVGRP_REMARK'}' style='width: 98%;'></td></tr>
1777 <tr><td colspan='2'><br></tr>
1778 </table>
1779 END
1780 }else{
1781 print<<END;
1782 <table width='100%'><form method='post' style='display:inline'>
1783 <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>
1784 <tr>
1785 <form method='post'>
1786 <td width='10%'>
1787 $Lang::tr{'remark'}:
1788 </td>
1789 <td colspan='2'>
1790 <input type='text' name='newsrvrem' value='$fwhostsettings{'SRVGRP_REMARK'}' style='width:98%;'>
1791 </td>
1792 <td align='right'>
1793 <input type='submit' value='$Lang::tr{'fwhost change'}'>
1794 <input type='hidden' name='oldsrvrem' value='$fwhostsettings{'oldsrvgrpremark'}'>
1795 <input type='hidden' name='srvgrp' value='$fwhostsettings{'SRVGRP_NAME'}'>
1796 <input type='hidden' name='ACTION' value='changesrvgrpremark' >
1797 </td>
1798 </tr>
1799 <tr>
1800 <td colspan='4'>
1801 <br>
1802 </td>
1803 </tr>
1804 </table>
1805 </form>
1806 END
1807 }
1808 if($fwhostsettings{'updatesrvgrp'} eq 'on'){
1809 print<<END;
1810 <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%'>
1811 <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'add'}: </td><td><select name='CUST_SRV' style='min-width:185px;'>
1812 END
1813 &General::readhasharray("$configsrv", \%customservice);
1814 #Protocols for use in servicegroups
1815 print "<optgroup label='$Lang::tr{'fwhost cust service'}'>";
1816 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice)
1817 {
1818 print "<option>$customservice{$key}[0]</option>";
1819 }
1820 print "</optgroup>";
1821 print "<optgroup label='$Lang::tr{'protocol'}'>";
1822 print "<option>GRE</option>";
1823 print "<option>AH</option>";
1824 print "<option>ESP</option>";
1825 print "<option>IGMP</option>";
1826 print "<option>IPIP</option>";
1827 print "<option value='IPV6'>IPv6 encap</option>";
1828 print "</optgroup>";
1829 print<<END;
1830 </select></td></tr>
1831 <tr><td colspan='4'><br><br></td></tr>
1832 <tr><td colspan='4'></td></tr>
1833 </table>
1834 END
1835 }
1836 print<<END;
1837 <table width='100%'>
1838 <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>
1839 </table></form>
1840 END
1841 &Header::closebox();
1842 }
1843 # View
1844 sub viewtablenet
1845 {
1846 if(! -z $confignet){
1847 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust net'});
1848 &General::readhasharray("$confignet", \%customnetwork);
1849 &General::readhasharray("$configgrp", \%customgrp);
1850 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1851 &General::readhasharray("$fwconfiginp", \%fwinp);
1852 &General::readhasharray("$fwconfigout", \%fwout);
1853
1854 if (!keys %customnetwork)
1855 {
1856 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1857 }else{
1858 print<<END;
1859 <table width='100%' cellspacing='0' class='tbl'>
1860 <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>
1861 END
1862 }
1863 my $count=0;
1864 my $col='';
1865 foreach my $key (sort {ncmp($a,$b)} keys %customnetwork) {
1866 if ($fwhostsettings{'ACTION'} eq 'editnet' && $fwhostsettings{'HOSTNAME'} eq $customnetwork{$key}[0]) {
1867 print" <tr>";
1868 $col="bgcolor='${Header::colouryellow}'";
1869 }elsif ($count % 2)
1870 {
1871 $col="bgcolor='$color{'color20'}'";
1872 print" <tr>";
1873 }else
1874 {
1875 $col="bgcolor='$color{'color22'}'";
1876 print" <tr>";
1877 }
1878 my $colnet="$customnetwork{$key}[1]/".&General::subtocidr($customnetwork{$key}[2]);
1879 my $netcount=&getnetcount($customnetwork{$key}[0]);
1880 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>";
1881 print<<END;
1882 <td width='1%' $col><input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
1883 <input type='hidden' name='ACTION' value='editnet'>
1884 <input type='hidden' name='HOSTNAME' value='$customnetwork{$key}[0]' />
1885 <input type='hidden' name='IP' value='$customnetwork{$key}[1]' />
1886 <input type='hidden' name='SUBNET' value='$customnetwork{$key}[2]' />
1887 <input type='hidden' name='NETREMARK' value='$customnetwork{$key}[3]' />
1888 </td></form>
1889 END
1890 if($netcount == '0')
1891 {
1892 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>";
1893 }else{
1894 print"<td $col></td></tr>";
1895 }
1896 $count++;
1897 }
1898 print"</table>";
1899 &Header::closebox();
1900 }
1901
1902 }
1903 sub getcolor
1904 {
1905 my $c=shift;
1906 my $sip;
1907 my $scidr;
1908 my $tdcolor='';
1909 #Check if MAC
1910 if (&General::validmac($c)){ return $c;}
1911
1912 #Check if we got a full IP with subnet then split it
1913 if($c =~ /^(.*?)\/(.*?)$/){
1914 ($sip,$scidr) = split ("/",$c);
1915 }else{
1916 $sip=$c;
1917 }
1918
1919 #Now check if IP is part of ORANGE,BLUE or GREEN
1920 if ( &Header::orange_used() && &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
1921 $tdcolor="<font style='color: $Header::colourorange;'>$c</font>";
1922 return $tdcolor;
1923 }
1924 if ( &General::IpInSubnet($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){
1925 $tdcolor="<font style='color: $Header::colourgreen;'>$c</font>";
1926 return $tdcolor;
1927 }
1928 if ( &Header::blue_used() && &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
1929 $tdcolor="<font style='color: $Header::colourblue;'>$c</font>";
1930 return $tdcolor;
1931 }
1932 if ("$sip/$scidr" eq "0.0.0.0/0"){
1933 $tdcolor="<font style='color: $Header::colourred;'>$c</font>";
1934 return $tdcolor;
1935 }
1936 #Check if IP is part of OpenVPN N2N subnet
1937 foreach my $key (sort keys %ccdhost){
1938 if ($ccdhost{$key}[3] eq 'net'){
1939 my ($a,$b) = split("/",$ccdhost{$key}[11]);
1940 if (&General::IpInSubnet($sip,$a,$b)){
1941 $tdcolor="<font style='color:$Header::colourovpn ;'>$c</font>";
1942 return $tdcolor;
1943 }
1944 }
1945 }
1946
1947 #Check if IP is part of OpenVPN dynamic subnet
1948 my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'});
1949 if (&General::IpInSubnet($sip,$a,$b)){
1950 $tdcolor="<font style='color: $Header::colourovpn;'>$c</font>";
1951 return $tdcolor;
1952 }
1953
1954 #Check if IP is part of OpenVPN static subnet
1955 foreach my $key (sort keys %ccdnet){
1956 my ($a,$b) = split("/",$ccdnet{$key}[1]);
1957 $b =&General::iporsubtodec($b);
1958 if (&General::IpInSubnet($sip,$a,$b)){
1959 $tdcolor="<font style='color: $Header::colourovpn;'>$c</font>";
1960 return $tdcolor;
1961 }
1962 }
1963
1964 #Check if IP is part of IPsec RW network
1965 if ($ipsecsettings{'RW_NET'} ne ''){
1966 my ($a,$b) = split("/",$ipsecsettings{'RW_NET'});
1967 $b=&General::iporsubtodec($b);
1968 if (&General::IpInSubnet($sip,$a,$b)){
1969 $tdcolor="<font style='color: $Header::colourvpn;'>$c</font>";
1970 return $tdcolor;
1971 }
1972 }
1973
1974 #Check if IP is part of a IPsec N2N network
1975 foreach my $key (sort keys %ipsecconf){
1976 if ($ipsecconf{$key}[11]){
1977 foreach my $ipsecsubitem (split(/\|/, $ipsecconf{$key}[11])) {
1978 my ($a,$b) = split("/",$ipsecsubitem);
1979 $b=&General::iporsubtodec($b);
1980 if (&General::IpInSubnet($sip,$a,$b)){
1981 $tdcolor="<font style='color: $Header::colourvpn;'>$c</font>";
1982 return $tdcolor;
1983 }
1984 }
1985 }
1986 }
1987 return "$c";
1988 }
1989 sub viewtablehost
1990 {
1991 if (! -z $confighost){
1992 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust addr'});
1993 &General::readhasharray("$confighost", \%customhost);
1994 &General::readhasharray("$configccdnet", \%ccdnet);
1995 &General::readhasharray("$configccdhost", \%ccdhost);
1996 &General::readhasharray("$fwconfigfwd", \%fwfwd);
1997 &General::readhasharray("$fwconfiginp", \%fwinp);
1998 &General::readhasharray("$fwconfigout", \%fwout);
1999 &General::readhasharray("$configgrp", \%customgrp);
2000 if (!keys %customhost)
2001 {
2002 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
2003 }else{
2004 print<<END;
2005 <table width='100%' cellspacing='0' class='tbl'>
2006 <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>
2007 END
2008 }
2009 my $count=0;
2010 my $col='';
2011 foreach my $key (sort { ncmp ($customhost{$a}[0],$customhost{$b}[0])} keys %customhost) {
2012 if ( ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'}) && $fwhostsettings{'HOSTNAME'} eq $customhost{$key}[0]) {
2013 print" <tr>";
2014 $col="bgcolor='${Header::colouryellow}'";
2015 }elsif ($count % 2){
2016 print" <tr>";
2017 $col="bgcolor='$color{'color20'}'";
2018 }else{
2019 $col="bgcolor='$color{'color22'}'";
2020 print" <tr>";
2021 }
2022 my ($ip,$sub)=split(/\//,$customhost{$key}[2]);
2023 $customhost{$key}[4]=~s/\s+//g;
2024 my $hostcount=0;
2025 $hostcount=&gethostcount($customhost{$key}[0]);
2026 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>";
2027 print<<END;
2028 <td width='1%' $col><form method='post'><input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
2029 <input type='hidden' name='ACTION' value='edithost' />
2030 <input type='hidden' name='HOSTNAME' value='$customhost{$key}[0]' />
2031 <input type='hidden' name='IP' value='$ip' />
2032 <input type='hidden' name='type' value='$customhost{$key}[1]' />
2033 <input type='hidden' name='HOSTREMARK' value='$customhost{$key}[3]' />
2034 </form></td>
2035 END
2036 if($hostcount == '0')
2037 {
2038 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>";
2039 }else{
2040 print"<td width='1%' $col></td></tr>";
2041 }
2042 $count++;
2043 }
2044 print"</table>";
2045 &Header::closebox();
2046 }
2047 }
2048 sub viewtablegrp
2049 {
2050 if(! -z "$configgrp"){
2051 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust grp'});
2052 &General::readhasharray("$configgrp", \%customgrp);
2053 &General::readhasharray("$configipsec", \%ipsecconf);
2054 &General::readhasharray("$configccdhost", \%ccdhost);
2055 &General::readhasharray("$configccdnet", \%ccdnet);
2056 &General::readhasharray("$confighost", \%customhost);
2057 &General::readhasharray("$confignet", \%customnetwork);
2058 &General::readhasharray("$fwconfigfwd", \%fwfwd);
2059 &General::readhasharray("$fwconfiginp", \%fwinp);
2060 &General::readhasharray("$fwconfigout", \%fwout);
2061 my @grp=();
2062 my $helper='';
2063 my $count=1;
2064 my $grpname;
2065 my $remark;
2066 my $number;
2067 my $delflag;
2068 my @counter;
2069 my %hash;
2070 if (!keys %customgrp)
2071 {
2072 print "<center><b>$Lang::tr{'fwhost err emptytable'}</b>";
2073 }else{
2074 #get all groups in a hash
2075 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
2076 push (@counter,$customgrp{$key}[0]);
2077 }
2078 foreach my $key1 (@counter) {
2079 $hash{$key1}++ ;
2080 }
2081 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
2082 $count++;
2083 if ($helper ne $customgrp{$key}[0]){
2084 $delflag='0';
2085 foreach my $key1 (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
2086 if ($customgrp{$key}[0] eq $customgrp{$key1}[0])
2087 {
2088 $delflag++;
2089 }
2090 if($delflag > 1){
2091 last;
2092 }
2093 }
2094 $number=1;
2095 if ($customgrp{$key}[2] eq "none"){$customgrp{$key}[2]=$Lang::tr{'fwhost err emptytable'};}
2096 $grpname=$customgrp{$key}[0];
2097 $remark="$customgrp{$key}[1]";
2098 if($count gt 1){ print"</table>";$count=1;}
2099 print "<br><b><u>$grpname</u></b>&nbsp; &nbsp;";
2100 print " <b>$Lang::tr{'remark'}:</b>&nbsp $remark &nbsp " if ($remark ne '');
2101 my $netgrpcount=&getnetcount($grpname);
2102 print "<b>$Lang::tr{'used'}:</b> $netgrpcount x";
2103 if($netgrpcount == '0')
2104 {
2105 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>";
2106 }
2107 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>";
2108 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>";
2109 }
2110 my $col='';
2111 if ( ($fwhostsettings{'ACTION'} eq 'editgrp' || $fwhostsettings{'update'} ne '') && $fwhostsettings{'grp_name'} eq $customgrp{$key}[0]) {
2112 print" <tr>";
2113 $col="bgcolor='${Header::colouryellow}'";
2114 }elsif ($count %2 == 0){
2115 print"<tr>";
2116 $col="bgcolor='$color{'color20'}'";
2117 }else{
2118 print"<tr>";
2119 $col="bgcolor='$color{'color22'}'";
2120 }
2121 my $ip=&getipforgroup($customgrp{$key}[2],$customgrp{$key}[3]);
2122 if ($ip eq ''){
2123 print"<tr>";
2124 $col="bgcolor='${Header::colouryellow}'";
2125 }
2126 print "<td width='39%' align='left' $col>";
2127 if($customgrp{$key}[3] eq 'Standard Network'){
2128 print &get_name($customgrp{$key}[2])."</td>";
2129 }elsif($customgrp{$key}[3] eq "IpSec Network" && $customgrp{$key}[2] =~ /\|/){
2130 my ($a,$b) = split /\|/, $customgrp{$key}[2];
2131 print "$a</td>";
2132 }else{
2133 print "$customgrp{$key}[2]</td>";
2134 }
2135 if ($ip eq '' && $customgrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){
2136 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'>";
2137 }else{
2138 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'>";
2139 }
2140 if ($delflag > 0 && $ip ne ''){
2141 print"<input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' />";
2142 #check if this group has only one entry
2143 foreach my $key2 (keys %hash) {
2144 if ($hash{$key2}<2 && $key2 eq $customgrp{$key}[0]){
2145 print "<input type='hidden' name='last' value='on'>" ;
2146 }
2147 }
2148 }
2149 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>";
2150 $helper=$customgrp{$key}[0];
2151 $number++;
2152 }
2153 print"</table>";
2154 }
2155 &Header::closebox();
2156 }
2157
2158 }
2159 sub viewtablelocationgrp
2160 {
2161 # If our filesize is "zero" there is nothing to read-in.
2162 if (-z "$configlocationgrp") {
2163 return;
2164 }
2165
2166 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust locationgrp'});
2167 &General::readhasharray("$configlocationgrp", \%customlocationgrp);
2168 &General::readhasharray("$fwconfigfwd", \%fwfwd);
2169 &General::readhasharray("$fwconfiginp", \%fwinp);
2170 &General::readhasharray("$fwconfigout", \%fwout);
2171 my @grp=();
2172 my $helper='';
2173 my $count=1;
2174 my $country_code;
2175 my $grpname;
2176 my $remark;
2177 my $number;
2178 my $delflag;
2179 my @counter;
2180 my %hash;
2181
2182 # If there are no groups we are finished here.
2183 if (!keys %customlocationgrp) {
2184 print "<center><b>$Lang::tr{'fwhost err emptytable'}</b>";
2185 return;
2186 }
2187
2188 # Put all groups in a hash.
2189 foreach my $key (sort { ncmp($customlocationgrp{$a}[0],$customlocationgrp{$b}[0]) }
2190 sort { ncmp($customlocationgrp{$a}[2],$customlocationgrp{$b}[2]) } keys %customlocationgrp) {
2191 push (@counter,$customlocationgrp{$key}[0]);
2192 }
2193
2194 # Increase current used key.
2195 foreach my $key1 (@counter) {
2196 $hash{$key1}++ ;
2197 }
2198
2199 # Sort hash.
2200 foreach my $key (sort { ncmp($customlocationgrp{$a}[0],$customlocationgrp{$b}[0]) }
2201 sort { ncmp($customlocationgrp{$a}[2],$customlocationgrp{$b}[2]) } keys %customlocationgrp) {
2202 $count++;
2203 if ($helper ne $customlocationgrp{$key}[0]) {
2204 $delflag='0';
2205
2206 foreach my $key1 (sort { ncmp($customlocationgrp{$a}[0],$customlocationgrp{$b}[0]) }
2207 sort { ncmp($customlocationgrp{$a}[2],$customlocationgrp{$b}[2]) } keys %customlocationgrp) {
2208
2209 if ($customlocationgrp{$key}[0] eq $customlocationgrp{$key1}[0])
2210 {
2211 $delflag++;
2212 }
2213 if($delflag > 1){
2214 last;
2215 }
2216 }
2217
2218 $number=1;
2219
2220 # Groupname.
2221 $grpname=$customlocationgrp{$key}[0];
2222
2223 # Group remark.
2224 $remark="$customlocationgrp{$key}[1]";
2225
2226 # Country code.
2227 $country_code="$customlocationgrp{$key}[2]";
2228
2229 if ($count gt 1){
2230 print"</table>";
2231 $count=1;
2232 }
2233
2234 # Display groups header.
2235 print "<br><b><u>$grpname</u></b>&nbsp; &nbsp;\n";
2236 print "<b>$Lang::tr{'remark'}:</b>&nbsp $remark &nbsp\n" if ($remark ne '');
2237
2238 # Get group count.
2239 my $locationgrpcount=&getlocationcount($grpname);
2240 print "<b>$Lang::tr{'used'}:</b> $locationgrpcount x";
2241
2242 # Only display delete icon, if the group is not used by a firewall rule.
2243 if($locationgrpcount == '0') {
2244 print"<form method='post' style='display:inline'>\n";
2245 print"<input type='image' src='/images/delete.gif' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' align='right' />\n";
2246 print"<input type='hidden' name='grp_name' value='$grpname' >\n";
2247 print"<input type='hidden' name='ACTION' value='dellocationgrp'>\n";
2248 print"</form>";
2249 }
2250
2251 # Icon for group editing.
2252 print <<END;
2253 <form method='post' style='display:inline'>
2254 <input type='image' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' align='right'/>
2255 <input type='hidden' name='grp_name' value='$grpname' >
2256 <input type='hidden' name='remark' value='$remark' >
2257 <input type='hidden' name='ACTION' value='editlocationgrp'>
2258 </form>
2259
2260 <table width='100%' cellspacing='0' class='tbl'>
2261 END
2262 # Display headlines if the group contains any entries.
2263 if ($country_code ne "none") {
2264 print <<END;
2265 <tr>
2266 <td width='10%' align='center'>
2267 <b>$Lang::tr{'flag'}</b>
2268 </td>
2269
2270 <td width='10%'align='center'>
2271 <b>$Lang::tr{'countrycode'}</b>
2272 </td>
2273
2274 <td width='70%'align='left'>
2275 <b>$Lang::tr{'country'}</b>
2276 </td>
2277
2278 <td width='10%' align='right'></td>
2279 </tr>
2280 END
2281 }
2282 }
2283
2284 # Check if our group contains any entries.
2285 if ($country_code eq "none") {
2286 print "<tr><td>$Lang::tr{'fwhost err emptytable'}</td></tr>\n";
2287 } else {
2288 # Check if we are currently editing a group and assign column backgound colors.
2289 my $col='';
2290 if ( ($fwhostsettings{'ACTION'} eq 'editlocationgrp' || $fwhostsettings{'update'} ne '')
2291 && $fwhostsettings{'grp_name'} eq $customlocationgrp{$key}[0]) {
2292 $col="bgcolor='${Header::colouryellow}'";
2293 } elsif ($count %2 == 0){
2294 $col="bgcolor='$color{'color20'}'";
2295 } else {
2296 $col="bgcolor='$color{'color22'}'";
2297 }
2298
2299 # Get country flag.
2300 my $icon = &Location::Functions::get_flag_icon($customlocationgrp{$key}[2]);
2301
2302 # Print column with flag icon.
2303 my $col_content;
2304 if ($icon) {
2305 $col_content = "<img src='$icon' alt='$customlocationgrp{$key}[2]' title='$customlocationgrp{$key}[2]'>";
2306 } else {
2307 $col_content = "<b>N/A</b>";
2308 }
2309
2310 print "<td align='center' $col>$col_content</td>\n";
2311
2312 # Print column with country code.
2313 print "<td align='center' $col>$customlocationgrp{$key}[2]</td>\n";
2314
2315 # Print column with full country name.
2316 my $country_name = &Location::Functions::get_full_country_name($customlocationgrp{$key}[2]);
2317 print "<td align='left' $col>$country_name</td>\n";
2318
2319 # Generate from for removing entries from a group.
2320 print "<td align='right' width='1%' $col><form method='post'>\n";
2321
2322 if ($delflag > 0){
2323 print"<input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}'/>\n";
2324
2325 # Check if this group only has a single entry.
2326 foreach my $key2 (keys %hash) {
2327 if ($hash{$key2}<2 && $key2 eq $customlocationgrp{$key}[0]){
2328 print "<input type='hidden' name='last' value='on'>" ;
2329 }
2330 }
2331 }
2332
2333 print "<input type='hidden' name='ACTION' value='deletelocationgrpentry'>\n";
2334 print "<input type='hidden' name='update' value='$fwhostsettings{'update'}'>\n";
2335 print "<input type='hidden' name='delentry' value='$grpname,$remark,$customlocationgrp{$key}[2],$customlocationgrp{$key}[3]'>\n";
2336 print "</form>\n";
2337 print "</td>\n";
2338 print "</tr>\n";
2339 }
2340
2341 $helper=$customlocationgrp{$key}[0];
2342 $number++;
2343 }
2344
2345 print"</table>\n";
2346 &Header::closebox();
2347 }
2348 sub viewtableservice
2349 {
2350 my $count=0;
2351 my $srvcount;
2352 if(! -z "$configsrv")
2353 {
2354 &Header::openbox('100%', 'left', $Lang::tr{'fwhost services'});
2355 &General::readhasharray("$configsrv", \%customservice);
2356 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2357 &General::readhasharray("$fwconfigfwd", \%fwfwd);
2358 &General::readhasharray("$fwconfiginp", \%fwinp);
2359 &General::readhasharray("$fwconfigout", \%fwout);
2360 print<<END;
2361 <table width='100%' cellspacing='0' class='tbl'>
2362 <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>
2363 END
2364 my $col='';
2365 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0])} keys %customservice)
2366 {
2367 $count++;
2368 if ( ($fwhostsettings{'updatesrv'} eq 'on' || $fwhostsettings{'error'}) && $fwhostsettings{'SRV_NAME'} eq $customservice{$key}[0]) {
2369 print" <tr>";
2370 $col="bgcolor='${Header::colouryellow}'";
2371 }elsif ($count % 2){
2372 print" <tr>";
2373 $col="bgcolor='$color{'color22'}'";
2374 }else{
2375 print" <tr>";
2376 $col="bgcolor='$color{'color20'}'";
2377 }
2378 print<<END;
2379 <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>
2380 END
2381 #Neuer count
2382 $srvcount=&getsrvcount($customservice{$key}[0]);
2383 if($customservice{$key}[3] eq 'All ICMP-Types'){print $Lang::tr{'fwdfw all icmp'};}
2384 elsif($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];}
2385 print<<END;
2386 </td><td align='center' $col>$srvcount x</td>
2387 <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' />
2388 <input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]' />
2389 <input type='hidden' name='SRV_PORT' value='$customservice{$key}[1]' />
2390 <input type='hidden' name='PROT' value='$customservice{$key}[2]' />
2391 <input type='hidden' name='ICMP' value='$customservice{$key}[3]' /></form></td>
2392 END
2393 if ($srvcount eq '0')
2394 {
2395 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>";
2396 }else{
2397 print"<td $col></td></tr>";
2398 }
2399 }
2400 print"</table>";
2401 &Header::closebox();
2402 }
2403 }
2404 sub viewtableservicegrp
2405 {
2406 my $count=0;
2407 my $grpname;
2408 my $remark;
2409 my $helper;
2410 my $helper1;
2411 my $port;
2412 my $protocol;
2413 my $delflag;
2414 my $grpcount=0;
2415 my $col='';
2416 my $lastentry=0;
2417 my @counter;
2418 my %hash;
2419 if (! -z $configsrvgrp){
2420 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'});
2421 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2422 &General::readhasharray("$configsrv", \%customservice);
2423 &General::readhasharray("$fwconfigfwd", \%fwfwd);
2424 &General::readhasharray("$fwconfiginp", \%fwinp);
2425 &General::readhasharray("$fwconfigout", \%fwout);
2426 my $number= keys %customservicegrp;
2427 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) }keys %customservicegrp){
2428 push (@counter,$customservicegrp{$key}[0]);
2429 }
2430 foreach my $key1 (@counter) {
2431 $hash{$key1}++ ;
2432 }
2433 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) }keys %customservicegrp){
2434 $count++;
2435 if ($helper ne $customservicegrp{$key}[0]){
2436 #Get used groupcounter
2437 $grpcount=&getsrvcount($customservicegrp{$key}[0]);
2438 $delflag=0;
2439 foreach my $key1 (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) } keys %customservicegrp){
2440 if ($customservicegrp{$key}[0] eq $customservicegrp{$key1}[0])
2441 {
2442 $delflag++;
2443 }
2444 if($delflag > 1){
2445 last;
2446 }
2447 }
2448 $grpname=$customservicegrp{$key}[0];
2449 if ($customservicegrp{$key}[2] eq "none"){
2450 $customservicegrp{$key}[2]=$Lang::tr{'fwhost err emptytable'};
2451 $port='';
2452 $protocol='';
2453 }
2454 $remark="$customservicegrp{$key}[1]";
2455 if($count >0){print"</table>";$count=1;}
2456 print "<br><b><u>$grpname</u></b>&nbsp; &nbsp; ";
2457 print "<b>$Lang::tr{'remark'}:</b>&nbsp; $remark " if ($remark ne '');
2458 print "&nbsp; <b>$Lang::tr{'used'}:</b> $grpcount x";
2459 if($grpcount == '0')
2460 {
2461 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>";
2462 }
2463 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>";
2464 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>";
2465 }
2466 if( $fwhostsettings{'SRVGRP_NAME'} eq $customservicegrp{$key}[0]) {
2467 print"<tr>";
2468 $col="bgcolor='${Header::colouryellow}'";
2469 }elsif ($count %2 == 0){
2470 print"<tr>";
2471 $col="bgcolor='$color{'color20'}'";
2472 }else{
2473 print"<tr>";
2474 $col="bgcolor='$color{'color22'}'";
2475 }
2476 #make lines yellow if it is a dummy entry
2477 if ($customservicegrp{$key}[2] eq $Lang::tr{'fwhost err emptytable'}){
2478 print"<tr>";
2479 $col="bgcolor='${Header::colouryellow}'";
2480 }
2481 #Set fields if we use protocols in servicegroups
2482 if ($customservicegrp{$key}[2] ne 'TCP' || $customservicegrp{$key}[2] ne 'UDP' || $customservicegrp{$key}[2] ne 'ICMP'){
2483 $port='-';
2484 }
2485 if ($customservicegrp{$key}[2] eq 'GRE'){$protocol='GRE';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} GRE";}
2486 if ($customservicegrp{$key}[2] eq 'ESP'){$protocol='ESP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} ESP";}
2487 if ($customservicegrp{$key}[2] eq 'AH'){$protocol='AH';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} AH";}
2488 if ($customservicegrp{$key}[2] eq 'IGMP'){$protocol='IGMP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IGMP";}
2489 if ($customservicegrp{$key}[2] eq 'IPIP'){$protocol='IPIP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPIP";}
2490 if ($customservicegrp{$key}[2] eq 'IPV6'){$protocol='IPV6';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPv6 encapsulation";}
2491 print "<td width='39%' $col>$customservicegrp{$key}[2]</td>";
2492 foreach my $srv (sort keys %customservice){
2493 if ($customservicegrp{$key}[2] eq $customservice{$srv}[0]){
2494 $protocol=$customservice{$srv}[2];
2495 $port=$customservice{$srv}[1];
2496 last;
2497 }
2498 }
2499 print"<td align='center' $col>$port</td><td align='center' $col>$protocol</td><td width='1%' $col><form method='post'>";
2500 if ($delflag gt '0'){
2501 if ($customservicegrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){
2502 print"<input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title=$Lang::tr{'delete'} />";
2503 }
2504 #check if this group has only one entry
2505 foreach my $key2 (keys %hash) {
2506 if ($hash{$key2}<2 && $key2 eq $customservicegrp{$key}[0]){
2507 print "<input type='hidden' name='last' value='on'>" ;
2508 }
2509 }
2510 }
2511 print"<input type='hidden' name='ACTION' value='delgrpservice'><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'>";
2512 if($protocol eq 'TCP' || $protocol eq 'UDP' || $protocol eq 'ICMP'){
2513 print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2]'></form></td></tr>";
2514 }else{
2515 print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$protocol'></form></td></tr>";
2516 }
2517 $helper=$customservicegrp{$key}[0];
2518 }
2519 print"</table>";
2520 &Header::closebox();
2521 }
2522 }
2523 # Check
2524 sub checkname
2525 {
2526 my %hash=%{(shift)};
2527 foreach my $key (keys %hash) {
2528 if($hash{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
2529 return 0;
2530 }
2531 }
2532 return 1;
2533
2534 }
2535 sub checkgroup
2536 {
2537 &General::readhasharray("$configgrp", \%customgrp );
2538 my $name=shift;
2539 foreach my $key (keys %customservicegrp) {
2540 if($customservicegrp{$key}[0] eq $name){
2541 return 0;
2542 }
2543 }
2544 return 1;
2545 }
2546 sub checkservice
2547 {
2548 &General::readhasharray("$configsrv", \%customservice );
2549 my $name=shift;
2550 foreach my $key (keys %customservice) {
2551 if($customservice{$key}[0] eq $name){
2552 return 0;
2553 }
2554 }
2555 return 1;
2556 }
2557 sub checkip
2558 {
2559
2560 my %hash=%{(shift)};
2561 my $a=shift;
2562 foreach my $key (keys %hash) {
2563 if($hash{$key}[$a] eq $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'})){
2564 return 0;
2565 }
2566 }
2567 return 1;
2568 }
2569 sub checkservicegroup
2570 {
2571 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2572 #check name
2573 if ( ! &validhostname($fwhostsettings{'SRVGRP_NAME'}))
2574 {
2575 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
2576 return $errormessage;
2577 }
2578 #check empty selectbox
2579 if (keys %customservice lt 1)
2580 {
2581 $errormessage.=$Lang::tr{'fwhost err groupempty'}."<br>";
2582 }
2583 #check if name already exists
2584 if ($fwhostsettings{'updatesrvgrp'} ne 'on'){
2585 foreach my $key (keys %customservicegrp) {
2586 if( $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} ){
2587 $errormessage.=$Lang::tr{'fwhost err grpexist'}."<br>";
2588
2589 }
2590 }
2591 }
2592 #check if service already exists in group
2593 foreach my $key (keys %customservicegrp) {
2594 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[2] eq $fwhostsettings{'CUST_SRV'} ){
2595 $errormessage.=$Lang::tr{'fwhost err srvexist'}."<br>";
2596 }
2597 }
2598 return $errormessage;
2599 }
2600 sub checkrulereload
2601 {
2602 my $search=shift;
2603 &General::readhasharray("$fwconfigfwd", \%fwfwd);
2604 &General::readhasharray("$fwconfiginp", \%fwinp);
2605 &General::readhasharray("$fwconfigout", \%fwout);
2606
2607 #check if service or servicegroup is used in rules
2608 foreach my $key (keys %fwfwd){
2609 if($search eq $fwfwd{$key}[15]){
2610 &General::firewall_config_changed();
2611 return;
2612 }
2613 }
2614 foreach my $key (keys %fwinp){
2615 if($search eq $fwinp{$key}[15]){
2616 &General::firewall_config_changed();
2617 return;
2618 }
2619 }
2620 foreach my $key (keys %fwout){
2621 if($search eq $fwout{$key}[15]){
2622 &General::firewall_config_changed();
2623 return;
2624 }
2625 }
2626 }
2627 sub error
2628 {
2629 if ($errormessage) {
2630 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
2631 print "<class name='base'>$errormessage\n";
2632 print "&nbsp;</class>\n";
2633 &Header::closebox();
2634 }
2635 }
2636 sub hint
2637 {
2638 if ($hint) {
2639 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
2640 print "<class name='base'>$hint\n";
2641 print "&nbsp;</class>\n";
2642 &Header::closebox();
2643 }
2644 }
2645 sub get_name
2646 {
2647 my $val=shift;
2648 &General::setup_default_networks(\%defaultNetworks);
2649 foreach my $network (sort keys %defaultNetworks)
2650 {
2651 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
2652 }
2653 }
2654 sub gethostcount
2655 {
2656 my $searchstring=shift;
2657 my $srvcounter=0;
2658 #Count services used in servicegroups
2659 foreach my $key (keys %customgrp) {
2660 if($customgrp{$key}[2] eq $searchstring){
2661 $srvcounter++;
2662 }
2663 }
2664 #Count services used in firewall - config
2665 foreach my $key1 (keys %fwfwd) {
2666 if($fwfwd{$key1}[4] eq $searchstring){
2667 $srvcounter++;
2668 }
2669 if($fwfwd{$key1}[6] eq $searchstring){
2670 $srvcounter++;
2671 }
2672 }
2673 #Count services used in firewall - input
2674 foreach my $key2 (keys %fwinp) {
2675 if($fwinp{$key2}[4] eq $searchstring){
2676 $srvcounter++;
2677 }
2678 if($fwinp{$key2}[6] eq $searchstring){
2679 $srvcounter++;
2680 }
2681 }
2682 #Count services used in firewall - outgoing
2683 foreach my $key3 (keys %fwout) {
2684 if($fwout{$key3}[4] eq $searchstring){
2685 $srvcounter++;
2686 }
2687 if($fwout{$key3}[6] eq $searchstring){
2688 $srvcounter++;
2689 }
2690 }
2691 return $srvcounter;
2692 }
2693 sub getlocationcount
2694 {
2695 my $groupname=shift;
2696 my $counter=0;
2697
2698 # Location groups are stored as "group:groupname" in the
2699 # firewall settings files.
2700 my $searchstring = join(':', "group",$groupname);
2701
2702 # Count services used in firewall - forward
2703 foreach my $key1 (keys %fwfwd) {
2704 if($fwfwd{$key1}[4] eq $searchstring){
2705 $counter++;
2706 }
2707 if($fwfwd{$key1}[6] eq $searchstring){
2708 $counter++;
2709 }
2710 }
2711 #Count services used in firewall - input
2712 foreach my $key2 (keys %fwinp) {
2713 if($fwinp{$key2}[4] eq $searchstring){
2714 $counter++;
2715 }
2716 if($fwinp{$key2}[6] eq $searchstring){
2717 $counter++;
2718 }
2719 }
2720 #Count services used in firewall - outgoing
2721 foreach my $key3 (keys %fwout) {
2722 if($fwout{$key3}[4] eq $searchstring){
2723 $counter++;
2724 }
2725 if($fwout{$key3}[6] eq $searchstring){
2726 $counter++;
2727 }
2728 }
2729 return $counter;
2730 }
2731 sub getnetcount
2732 {
2733 my $searchstring=shift;
2734 my $srvcounter=0;
2735 #Count services used in servicegroups
2736 foreach my $key (keys %customgrp) {
2737 if($customgrp{$key}[2] eq $searchstring){
2738 $srvcounter++;
2739 }
2740 }
2741 #Count services used in firewall - config
2742 foreach my $key1 (keys %fwfwd) {
2743 if($fwfwd{$key1}[4] eq $searchstring){
2744 $srvcounter++;
2745 }
2746 if($fwfwd{$key1}[6] eq $searchstring){
2747 $srvcounter++;
2748 }
2749 }
2750 #Count services used in firewall - input
2751 foreach my $key2 (keys %fwinp) {
2752 if($fwinp{$key2}[4] eq $searchstring){
2753 $srvcounter++;
2754 }
2755 if($fwinp{$key2}[6] eq $searchstring){
2756 $srvcounter++;
2757 }
2758 }
2759 #Count services used in firewall - outgoing
2760 foreach my $key3 (keys %fwout) {
2761 if($fwout{$key3}[4] eq $searchstring){
2762 $srvcounter++;
2763 }
2764 if($fwout{$key3}[6] eq $searchstring){
2765 $srvcounter++;
2766 }
2767 }
2768 return $srvcounter;
2769 }
2770 sub getsrvcount
2771 {
2772 my $searchstring=shift;
2773 my $srvcounter=0;
2774 #Count services used in servicegroups
2775 foreach my $key (keys %customservicegrp) {
2776 if($customservicegrp{$key}[2] eq $searchstring){
2777 $srvcounter++;
2778 }
2779 }
2780 #Count services used in firewall - config
2781 foreach my $key1 (keys %fwfwd) {
2782 if($fwfwd{$key1}[15] eq $searchstring){
2783 $srvcounter++;
2784 }
2785 }
2786 #Count services used in firewall - input
2787 foreach my $key2 (keys %fwinp) {
2788 if($fwinp{$key2}[15] eq $searchstring){
2789 $srvcounter++;
2790 }
2791 }
2792 #Count services used in firewall - outgoing
2793 foreach my $key3 (keys %fwout) {
2794 if($fwout{$key3}[15] eq $searchstring){
2795 $srvcounter++;
2796 }
2797 }
2798 return $srvcounter;
2799 }
2800 sub deletefromgrp
2801 {
2802 my $target=shift;
2803 my $config=shift;
2804 my %hash=();
2805 &General::readhasharray("$config",\%hash);
2806 foreach my $key (keys %hash) {
2807 if($hash{$key}[2] eq $target){
2808 delete $hash{$key};
2809 }
2810 }
2811 &General::writehasharray("$config",\%hash);
2812
2813 }
2814 sub plausicheck
2815 {
2816 my $edit=shift;
2817 #check hostname
2818 if (!&validhostname($fwhostsettings{'HOSTNAME'}))
2819 {
2820 $errormessage=$errormessage.$Lang::tr{'fwhost err name'};
2821 $fwhostsettings{'BLK_IP'}='readonly';
2822 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2823 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2824 }
2825 #check if name collides with CCD Netname
2826 &General::readhasharray("$configccdnet", \%ccdnet);
2827 foreach my $key (keys %ccdnet) {
2828 if($ccdnet{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
2829 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdnet'};;
2830 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2831 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2832 last;
2833 }
2834 }
2835 #check if IP collides with CCD NetIP
2836 if ($fwhostsettings{'type'} ne 'mac'){
2837 &General::readhasharray("$configccdnet", \%ccdnet);
2838 foreach my $key (keys %ccdnet) {
2839 my $test=(&General::getnetworkip($fwhostsettings{'IP'},&General::iporsubtocidr($fwhostsettings{'SUBNET'})))."/".$fwhostsettings{'SUBNET'};
2840 if($ccdnet{$key}[1] eq $test){
2841 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdipnet'};
2842 $fwhostsettings{'IP'} = $fwhostsettings{'orgip'};
2843 $fwhostsettings{'SUBNET'} = $fwhostsettings{'orgsubnet'};
2844 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2845 last;
2846 }
2847 }
2848 }
2849 #check if name collides with CCD Hostname
2850 &General::readhasharray("$configccdhost", \%ccdhost);
2851 foreach my $key (keys %ccdhost) {
2852 my ($ip,$sub)=split(/\//,$ccdhost{$key}[33]);
2853 if($ip eq $fwhostsettings{'IP'}){
2854 $errormessage=$Lang::tr{'fwhost err isccdiphost'};
2855 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2856 last;
2857 }
2858 }
2859 #check if IP collides with CCD HostIP (only hosts)
2860 if ($edit eq 'edithost')
2861 {
2862 foreach my $key (keys %ccdhost) {
2863 if($ccdhost{$key}[1] eq $fwhostsettings{'HOSTNAME'}){
2864 $errormessage=$Lang::tr{'fwhost err isccdhost'};
2865 $fwhostsettings{'IP'} = $fwhostsettings{'orgname'};
2866 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2867 last;
2868 }
2869 }
2870 }
2871 #check if network with this name already exists
2872 &General::readhasharray("$confignet", \%customnetwork);
2873 if (!&checkname(\%customnetwork))
2874 {
2875 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err netexist'};
2876 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2877 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2878 }
2879 #check if network ip already exists
2880 if (!&checkip(\%customnetwork,1))
2881 {
2882 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err net'};
2883 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2884 }
2885 #check if host with this name already exists
2886 &General::readhasharray("$confighost", \%customhost);
2887 if (!&checkname(\%customhost))
2888 {
2889 $errormessage.="<br>".$Lang::tr{'fwhost err hostexist'};
2890 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
2891 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
2892 }
2893 #check if host with this ip already exists
2894 if (!&checkip(\%customhost,2))
2895 {
2896 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err ipcheck'};
2897 }
2898 return;
2899 }
2900 sub getipforgroup
2901 {
2902 my $name=$_[0],
2903 my $type=$_[1];
2904 my $value;
2905
2906 #get address from IPSEC NETWORK
2907 if ($type eq 'IpSec Network'){
2908 foreach my $key (keys %ipsecconf) {
2909 if ($ipsecconf{$key}[1] eq $name){
2910 if ($ipsecconf{$key}[11] =~ /\|/) {
2911 my $string;
2912 my @parts = split /\|/ , $ipsecconf{$key}[11];
2913 foreach my $key1 (@parts){
2914 my ($val1,$val2) = split (/\//, $key1);
2915 my $val3 = &Network::convert_netmask2prefix($val2) || $val2;
2916 $string .= "$val1/$val3<br>";
2917 }
2918 return $string;
2919 }else{
2920 return $ipsecconf{$key}[11];
2921 }
2922 }else{
2923 if ($name =~ /\|/) {
2924 my ($a,$b) = split /\|/, $name;
2925 return $b;
2926 }
2927 }
2928 }
2929 &deletefromgrp($name,$configgrp);
2930 }
2931
2932 #get address from IPSEC HOST
2933 if ($type eq 'IpSec Host'){
2934 foreach my $key (keys %ipsecconf) {
2935 if ($ipsecconf{$key}[1] eq $name){
2936 return $ipsecconf{$key}[10];
2937 }
2938 }
2939 &deletefromgrp($name,$configgrp);
2940 }
2941
2942 #get address from ovpn ccd Net-2-Net
2943 if ($type eq 'OpenVPN N-2-N'){
2944 foreach my $key (keys %ccdhost) {
2945 if($ccdhost{$key}[1] eq $name){
2946 my ($a,$b) = split ("/",$ccdhost{$key}[11]);
2947 $b=&Network::convert_netmask2prefix($b) || ($b);
2948 return "$a/$b";
2949 }
2950 }
2951 &deletefromgrp($name,$configgrp);
2952 }
2953
2954 #get address from ovpn ccd static host
2955 if ($type eq 'OpenVPN static host'){
2956 foreach my $key (keys %ccdhost) {
2957 if($ccdhost{$key}[1] eq $name){
2958 my ($a,$b) = split (/\//,$ccdhost{$key}[33]);
2959 $b=&Network::convert_netmask2prefix($b) || ($b) ;
2960 return "$a/$b";
2961 }
2962 }
2963 &deletefromgrp($name,$configgrp);
2964 }
2965
2966 #get address from ovpn ccd static net
2967 if ($type eq 'OpenVPN static network'){
2968 foreach my $key (keys %ccdnet) {
2969 if ($ccdnet{$key}[0] eq $name){
2970 my ($a,$b) = split (/\//,$ccdnet{$key}[1]);
2971 $b=&Network::convert_netmask2prefix($b) || ($b);
2972 return "$a/$b";
2973 }
2974 }
2975 }
2976
2977 #check custom addresses
2978 if ($type eq 'Custom Host'){
2979 foreach my $key (keys %customhost) {
2980 if ($customhost{$key}[0] eq $name){
2981 my ($ip,$sub) = split("/",$customhost{$key}[2]);
2982 return $ip;
2983 }
2984 }
2985 }
2986
2987 ##check custom networks
2988 if ($type eq 'Custom Network'){
2989 foreach my $key (keys %customnetwork) {
2990 if($customnetwork{$key}[0] eq $name){
2991 return $customnetwork{$key}[1]."/".&Network::convert_netmask2prefix($customnetwork{$key}[2]) || $customnetwork{$key}[2];
2992 }
2993 }
2994 }
2995
2996 #check standard networks
2997 if ($type eq 'Standard Network'){
2998 if ($name =~ /OpenVPN/i){
2999 my %ovpn=();
3000 &General::readhash("${General::swroot}/ovpn/settings",\%ovpn);
3001 return $ovpn{'DOVPN_SUBNET'};
3002 }
3003 if ($name eq 'GREEN'){
3004 my %hash=();
3005 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
3006 return $hash{'GREEN_NETADDRESS'}."/".&Network::convert_netmask2prefix($hash{'GREEN_NETMASK'}) || $hash{'GREEN_NETMASK'};
3007 }
3008 if ($name eq 'BLUE'){
3009 my %hash=();
3010 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
3011 return $hash{'BLUE_NETADDRESS'}."/".&Network::convert_netmask2prefix($hash{'BLUE_NETMASK'}) || $hash{'BLUE_NETMASK'};
3012 }
3013 if ($name eq 'ORANGE'){
3014 my %hash=();
3015 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
3016 return $hash{'ORANGE_NETADDRESS'}."/".&Network::convert_netmask2prefix($hash{'ORANGE_NETMASK'}) || $hash{'ORANGE_NETMASK'};
3017 }
3018 if ($name eq 'ALL'){
3019 return "0.0.0.0/0";
3020 }
3021 if ($name =~ /IPsec/i){
3022 my %hash=();
3023 &General::readhash("${General::swroot}/vpn/settings",\%hash);
3024 return $hash{'RW_NET'};
3025 }
3026 if ($name eq 'RED'){
3027 return "0.0.0.0/0";
3028 }
3029 }
3030 }
3031 sub decrease
3032 {
3033 my $grp=$_[0];
3034 &General::readhasharray("$confignet", \%customnetwork);
3035 &General::readhasharray("$confighost", \%customhost);
3036 foreach my $key (sort keys %customgrp ){
3037 if ( ($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Network')){
3038 foreach my $key1 (sort keys %customnetwork){
3039 if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){
3040 $customnetwork{$key1}[4]=$customnetwork{$key1}[4]-1;
3041 last;
3042 }
3043 }
3044 }
3045
3046 if (($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Host')){
3047 foreach my $key2 (sort keys %customhost){
3048 if ($customhost{$key2}[0] eq $customgrp{$key}[2]){
3049 $customhost{$key2}[4]=$customhost{$key2}[4]-1;
3050 last;
3051 }
3052 }
3053
3054 }
3055 }
3056 &General::writehasharray("$confignet", \%customnetwork);
3057 &General::writehasharray("$confighost", \%customhost);
3058 }
3059 sub decreaseservice
3060 {
3061 my $grp=$_[0];
3062 &General::readhasharray("$configsrv", \%customservice);
3063 &General::readhasharray("$configsrvgrp", \%customservicegrp);
3064
3065 foreach my $key (sort keys %customservicegrp){
3066 if ($customservicegrp{$key}[0] eq $grp ){
3067 foreach my $key2 (sort keys %customservice){
3068 if ($customservice{$key2}[0] eq $customservicegrp{$key}[2]){
3069 $customservice{$key2}[4]--;
3070 }
3071 }
3072 }
3073 }
3074 &General::writehasharray("$configsrv", \%customservice);
3075
3076 }
3077 sub changenameinfw
3078 {
3079 my $old=shift;
3080 my $new=shift;
3081 my $fld=shift;
3082 my $type=shift;
3083
3084 if ($type eq 'location'){
3085 $old="group:$old";
3086 $new="group:$new";
3087 }
3088 &General::readhasharray("$fwconfigfwd", \%fwfwd);
3089 &General::readhasharray("$fwconfiginp", \%fwinp);
3090 &General::readhasharray("$fwconfigout", \%fwout);
3091 #Rename group in Firewall-CONFIG
3092 foreach my $key1 (keys %fwfwd) {
3093 if($fwfwd{$key1}[$fld] eq $old){
3094 $fwfwd{$key1}[$fld]=$new;
3095 }
3096 }
3097 &General::writehasharray("$fwconfigfwd", \%fwfwd );
3098 #Rename group in Firewall-INPUT
3099 foreach my $key2 (keys %fwinp) {
3100 if($fwinp{$key2}[$fld] eq $old){
3101 $fwinp{$key2}[$fld]=$new;
3102 }
3103 }
3104 &General::writehasharray("$fwconfiginp", \%fwinp );
3105 #Rename group in Firewall-OUTGOING
3106 foreach my $key3 (keys %fwout) {
3107 if($fwout{$key3}[$fld] eq $old){
3108 $fwout{$key3}[$fld]=$new;
3109 }
3110 }
3111 &General::writehasharray("$fwconfigout", \%fwout );
3112 }
3113 sub checkports
3114 {
3115
3116 my %hash=%{(shift)};
3117 #check empty fields
3118 if ($fwhostsettings{'SRV_NAME'} eq '' ){
3119 $errormessage=$Lang::tr{'fwhost err name1'};
3120 }
3121 if ($fwhostsettings{'SRV_PORT'} eq '' && $fwhostsettings{'PROT'} ne 'ICMP'){
3122 $errormessage=$Lang::tr{'fwhost err port'};
3123 }
3124 #check valid name
3125 if (! &validhostname($fwhostsettings{'SRV_NAME'})){
3126 $errormessage="<br>".$Lang::tr{'fwhost err name'};
3127 }
3128 #change dashes with :
3129 $fwhostsettings{'SRV_PORT'}=~ tr/-/:/;
3130
3131 if ($fwhostsettings{'SRV_PORT'} eq "*") {
3132 $fwhostsettings{'SRV_PORT'} = "1:65535";
3133 }
3134 if ($fwhostsettings{'SRV_PORT'} =~ /^(\D)\:(\d+)$/) {
3135 $fwhostsettings{'SRV_PORT'} = "1:$2";
3136 }
3137 if ($fwhostsettings{'SRV_PORT'} =~ /^(\d+)\:(\D)$/) {
3138 $fwhostsettings{'SRV_PORT'} = "$1:65535";
3139 }
3140 if($fwhostsettings{'PROT'} ne 'ICMP'){
3141 $errormessage = $errormessage.&General::validportrange($fwhostsettings{'SRV_PORT'}, 'src');
3142 }
3143 # a new service has to have a different name
3144 foreach my $key (keys %hash){
3145 if ($hash{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
3146 $errormessage = "<br>".$Lang::tr{'fwhost err srv exists'};
3147 last;
3148 }
3149 }
3150 return $errormessage;
3151 }
3152 sub validhostname
3153 {
3154 # Checks a hostname against RFC1035
3155 my $hostname = $_[0];
3156
3157 # Each part should be at least two characters in length
3158 # but no more than 63 characters
3159 if (length ($hostname) < 1 || length ($hostname) > 63) {
3160 return 0;}
3161 # Only valid characters are a-z, A-Z, 0-9 and -
3162 if ($hostname !~ /^[a-zA-ZäöüÖÄÜ0-9-_.;()\/\s]*$/) {
3163 return 0;}
3164 # First character can only be a letter or a digit
3165 if (substr ($hostname, 0, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) {
3166 return 0;}
3167 # Last character can only be a letter or a digit
3168 if (substr ($hostname, -1, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9()]*$/) {
3169 return 0;}
3170 return 1;
3171 }
3172 sub validremark
3173 {
3174 # Checks a hostname against RFC1035
3175 my $remark = $_[0];
3176 # Each part should be at least two characters in length
3177 # but no more than 63 characters
3178 if (length ($remark) < 1 || length ($remark) > 255) {
3179 return 0;}
3180 # Only valid characters are a-z, A-Z, 0-9 and -
3181 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) {
3182 return 0;}
3183 # First character can only be a letter or a digit
3184 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
3185 return 0;}
3186 # Last character can only be a letter or a digit
3187 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
3188 return 0;}
3189 return 1;
3190 }
3191 &Header::closebigbox();
3192 &Header::closepage();