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