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