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