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