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