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