]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/fwhosts.cgi
Firewall: Renamed directory /var/ipfire/forward to /var/ipfire/firewall
[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 (!$errormessage){
745 my $key = &General::findhasharraykey (\%customservice);
746 foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";}
747 $customservice{$key}[0] = $fwhostsettings{'SRV_NAME'};
748 $customservice{$key}[1] = $fwhostsettings{'SRV_PORT'};
749 $customservice{$key}[2] = $fwhostsettings{'PROT'};
750 $customservice{$key}[3] = $ICMP;
751 $customservice{$key}[4] = 0;
752 &General::writehasharray("$configsrv", \%customservice );
753 #reset fields
754 $fwhostsettings{'SRV_NAME'}='';
755 $fwhostsettings{'SRV_PORT'}='';
756 $fwhostsettings{'PROT'}='';
757 $fwhostsettings{'ICMP_TYPES'}='';
758 }
759 &addservice;
760 }
761 if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
762 {
763 my $prot;
764 my $port;
765 my $count=0;
766 &General::readhasharray("$configsrvgrp", \%customservicegrp );
767 &General::readhasharray("$configsrv", \%customservice );
768 $errormessage=&checkservicegroup;
769 #check remark
770 if ($fwhostsettings{'SRVGRP_REMARK'} ne '' && !&validremark($fwhostsettings{'SRVGRP_REMARK'})){
771 $errormessage=$Lang::tr{'fwhost err remark'};
772 }
773 if (!$errormessage){
774 #on first save, we have to enter a dummy value
775 if ($fwhostsettings{'CUST_SRV'} eq ''){
776 $fwhostsettings{'CUST_SRV'}='none';
777 }
778 #on update, we have to delete the dummy entry
779 foreach my $key (keys %customservicegrp){
780 if ($customservicegrp{$key}[2] eq 'none'){
781 delete $customservicegrp{$key};
782 last;
783 }
784 }
785 &General::writehasharray("$configsrvgrp", \%customservicegrp );
786 #check if remark has also changed
787 if ($fwhostsettings{'SRVGRP_REMARK'} ne $fwhostsettings{'oldsrvgrpremark'} && $fwhostsettings{'updatesrvgrp'} eq 'on')
788 {
789 foreach my $key (keys %customservicegrp)
790 {
791 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvgrpremark'})
792 {
793 $customservicegrp{$key}[1]='';
794 $customservicegrp{$key}[1]=$fwhostsettings{'SRVGRP_REMARK'};
795 }
796 }
797 }
798 #get count used
799 foreach my $key (keys %customservicegrp)
800 {
801 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'})
802 {
803 $count=$customservicegrp{$key}[3];
804 last;
805 }
806 }
807 if ($count eq '' ){$count='0';}
808
809 foreach my $key (sort keys %customservice){
810 if($customservice{$key}[0] eq $fwhostsettings{'CUST_SRV'}){
811 $port=$customservice{$key}[1];
812 $prot=$customservice{$key}[2];
813 $customservice{$key}[4]++;
814 }
815 }
816 &General::writehasharray("$configsrv", \%customservice );
817 my $key = &General::findhasharraykey (\%customservicegrp);
818 foreach my $i (0 .. 3) { $customservice{$key}[$i] = "";}
819 $customservicegrp{$key}[0] = $fwhostsettings{'SRVGRP_NAME'};
820 $customservicegrp{$key}[1] = $fwhostsettings{'SRVGRP_REMARK'};
821 $customservicegrp{$key}[2] = $fwhostsettings{'CUST_SRV'};
822 $customservicegrp{$key}[3] = $count;
823 &General::writehasharray("$configsrvgrp", \%customservicegrp );
824 $fwhostsettings{'updatesrvgrp'}='on';
825 }
826 if ($count gt 0){
827 &General::firewall_config_changed();
828 }
829 &addservicegrp;
830 &viewtableservicegrp;
831 }
832 # edit
833 if ($fwhostsettings{'ACTION'} eq 'editnet')
834 {
835 &addnet;
836 &viewtablenet;
837 }
838 if ($fwhostsettings{'ACTION'} eq 'edithost')
839 {
840 &addhost;
841 &viewtablehost;
842 }
843 if ($fwhostsettings{'ACTION'} eq 'editgrp')
844 {
845 $fwhostsettings{'update'}='on';
846 &addgrp;
847 &viewtablegrp;
848 }
849 if ($fwhostsettings{'ACTION'} eq 'editservice')
850 {
851 $fwhostsettings{'updatesrv'}='on';
852 &addservice;
853 }
854 if ($fwhostsettings{'ACTION'} eq 'editservicegrp')
855 {
856 $fwhostsettings{'updatesrvgrp'} = 'on';
857 &addservicegrp;
858 &viewtableservicegrp;
859 }
860 # reset
861 if ($fwhostsettings{'ACTION'} eq 'resetnet')
862 {
863 $fwhostsettings{'HOSTNAME'} ="";
864 $fwhostsettings{'IP'} ="";
865 $fwhostsettings{'SUBNET'} ="";
866 &showmenu;
867 }
868 if ($fwhostsettings{'ACTION'} eq 'resethost')
869 {
870 $fwhostsettings{'HOSTNAME'} ="";
871 $fwhostsettings{'IP'} ="";
872 $fwhostsettings{'type'} ="";
873 &showmenu;
874 }
875 if ($fwhostsettings{'ACTION'} eq 'resetgrp')
876 {
877 $fwhostsettings{'grp_name'} ="";
878 $fwhostsettings{'remark'} ="";
879 &showmenu;
880 }
881 # delete
882 if ($fwhostsettings{'ACTION'} eq 'delnet')
883 {
884 &General::readhasharray("$confignet", \%customnetwork);
885 foreach my $key (keys %customnetwork) {
886 if($fwhostsettings{'key'} eq $customnetwork{$key}[0]){
887 delete $customnetwork{$key};
888 &General::writehasharray("$confignet", \%customnetwork);
889 last;
890 }
891 }
892 &addnet;
893 &viewtablenet;
894 }
895 if ($fwhostsettings{'ACTION'} eq 'delhost')
896 {
897 &General::readhasharray("$confighost", \%customhost);
898 foreach my $key (keys %customhost) {
899 if($fwhostsettings{'key'} eq $customhost{$key}[0]){
900 delete $customhost{$key};
901 &General::writehasharray("$confighost", \%customhost);
902 last;
903 }
904 }
905 &addhost;
906 &viewtablehost;
907 }
908 if ($fwhostsettings{'ACTION'} eq 'deletegrphost')
909 {
910 my $grpremark;
911 my $grpname;
912 &General::readhasharray("$configgrp", \%customgrp);
913 foreach my $key (keys %customgrp){
914 if($customgrp{$key}[0].",".$customgrp{$key}[1].",".$customgrp{$key}[2].",".$customgrp{$key}[3] eq $fwhostsettings{'delhost'}){
915 #decrease count from source host/net
916 if ($customgrp{$key}[3] eq 'Custom Network'){
917 &General::readhasharray("$confignet", \%customnetwork);
918 foreach my $key1 (keys %customnetwork){
919 if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){
920 $customnetwork{$key1}[4] = $customnetwork{$key1}[4]-1;
921 last;
922 }
923 }
924 &General::writehasharray("$confignet", \%customnetwork);
925 }
926 if ($customgrp{$key}[3] eq 'Custom Host'){
927 &General::readhasharray("$confighost", \%customhost);
928 foreach my $key1 (keys %customhost){
929 if ($customhost{$key1}[0] eq $customgrp{$key}[2]){
930 $customhost{$key1}[4] = $customhost{$key1}[4]-1;
931 last;
932 }
933 }
934 &General::writehasharray("$confighost", \%customhost);
935 }
936 $grpname=$customgrp{$key}[0];
937 $grpremark=$customgrp{$key}[1];
938 delete $customgrp{$key};
939 }
940 }
941 &General::writehasharray("$configgrp", \%customgrp);
942 if ($fwhostsettings{'grpcnt'} > 0){
943 &General::firewall_config_changed();
944 }
945 if ($fwhostsettings{'update'} eq 'on'){
946 $fwhostsettings{'remark'}= $grpremark;
947 $fwhostsettings{'grp_name'}=$grpname;
948 }
949 &addgrp;
950 &viewtablegrp;
951 }
952 if ($fwhostsettings{'ACTION'} eq 'delgrp')
953 {
954 &General::readhasharray("$configgrp", \%customgrp);
955 &decrease($fwhostsettings{'grp_name'});
956 foreach my $key (sort keys %customgrp)
957 {
958 if($customgrp{$key}[0] eq $fwhostsettings{'grp_name'})
959 {
960 delete $customgrp{$key};
961 }
962 }
963 &General::writehasharray("$configgrp", \%customgrp);
964 $fwhostsettings{'grp_name'}='';
965 &addgrp;
966 &viewtablegrp;
967 }
968 if ($fwhostsettings{'ACTION'} eq 'delservice')
969 {
970 &General::readhasharray("$configsrv", \%customservice);
971 foreach my $key (keys %customservice) {
972 if($customservice{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
973 #&deletefromgrp($customhost{$key}[0],$configgrp);
974 delete $customservice{$key};
975 &General::writehasharray("$configsrv", \%customservice);
976 last;
977 }
978 }
979 $fwhostsettings{'SRV_NAME'}='';
980 $fwhostsettings{'SRV_PORT'}='';
981 $fwhostsettings{'PROT'}='';
982 &addservice;
983 }
984 if ($fwhostsettings{'ACTION'} eq 'delservicegrp')
985 {
986 &General::readhasharray("$configsrvgrp", \%customservicegrp);
987 &decreaseservice($fwhostsettings{'SRVGRP_NAME'});
988 foreach my $key (sort keys %customservicegrp)
989 {
990 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'})
991 {
992 delete $customservicegrp{$key};
993 }
994 }
995 &General::writehasharray("$configsrvgrp", \%customservicegrp);
996 $fwhostsettings{'SRVGRP_NAME'}='';
997 &addservicegrp;
998 &viewtableservicegrp;
999 }
1000 if ($fwhostsettings{'ACTION'} eq 'delgrpservice')
1001 {
1002 my $grpname;
1003 my $grpremark;
1004 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1005 &General::readhasharray("$configsrv", \%customservice);
1006 foreach my $key (keys %customservicegrp){
1007 if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2].",".$customservicegrp{$key}[3] eq $fwhostsettings{'delsrvfromgrp'})
1008 {
1009 #decrease count from source service
1010 foreach my $key1 (sort keys %customservice){
1011 if($customservice{$key1}[0] eq $customservicegrp{$key}[2]){
1012 $customservice{$key1}[4]--;
1013 last;
1014 }
1015 }
1016 &General::writehasharray("$configsrv", \%customservice);
1017 $grpname=$customservicegrp{$key}[0];
1018 $grpremark=$customservicegrp{$key}[1];
1019 delete $customservicegrp{$key};
1020 }
1021 }
1022 &General::writehasharray("$configsrvgrp", \%customservicegrp);
1023 &General::firewall_config_changed();
1024 if ($fwhostsettings{'updatesrvgrp'} eq 'on'){
1025 $fwhostsettings{'SRVGRP_NAME'}=$grpname;
1026 $fwhostsettings{'SRVGRP_REMARK'}=$grpremark;
1027 }
1028 &addservicegrp;
1029 &viewtableservicegrp;
1030
1031 }
1032 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newnet'})
1033 {
1034 &addnet;
1035 &viewtablenet;
1036 }
1037 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newhost'})
1038 {
1039 &addhost;
1040 &viewtablehost;
1041 }
1042 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newgrp'})
1043 {
1044 &addgrp;
1045 &viewtablegrp;
1046 }
1047 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservice'})
1048 {
1049 &addservice;
1050 }
1051 if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservicegrp'})
1052 {
1053 &addservicegrp;
1054 &viewtableservicegrp;
1055 }
1056 if ($fwhostsettings{'ACTION'} eq 'changegrpremark')
1057 {
1058 &General::readhasharray("$configgrp", \%customgrp);
1059 if ($fwhostsettings{'oldrem'} ne $fwhostsettings{'newrem'} && (&validremark($fwhostsettings{'newrem'}) || $fwhostsettings{'newrem'} eq '')){
1060 foreach my $key (sort keys %customgrp)
1061 {
1062 if($customgrp{$key}[0] eq $fwhostsettings{'grp'} && $customgrp{$key}[1] eq $fwhostsettings{'oldrem'})
1063 {
1064 $customgrp{$key}[1]='';
1065 $customgrp{$key}[1]=$fwhostsettings{'newrem'};
1066 }
1067 }
1068 &General::writehasharray("$configgrp", \%customgrp);
1069 $fwhostsettings{'update'}='on';
1070 $fwhostsettings{'remark'}=$fwhostsettings{'newrem'};
1071 }else{
1072 $errormessage=$Lang::tr{'fwhost err remark'};
1073 $fwhostsettings{'remark'}=$fwhostsettings{'oldrem'};
1074 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1075 $fwhostsettings{'update'} = 'on';
1076 }
1077 $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'};
1078 &addgrp;
1079 &viewtablegrp;
1080 }
1081 if ($fwhostsettings{'ACTION'} eq 'changesrvgrpremark')
1082 {
1083 &General::readhasharray("$configsrvgrp", \%customservicegrp );
1084 if ($fwhostsettings{'oldsrvrem'} ne $fwhostsettings{'newsrvrem'} && (&validremark($fwhostsettings{'newsrvrem'}) || $fwhostsettings{'newsrvrem'} eq '')){
1085 foreach my $key (sort keys %customservicegrp)
1086 {
1087 if($customservicegrp{$key}[0] eq $fwhostsettings{'srvgrp'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvrem'})
1088 {
1089 $customservicegrp{$key}[1]='';
1090 $customservicegrp{$key}[1]=$fwhostsettings{'newsrvrem'};
1091 }
1092 }
1093 &General::writehasharray("$configsrvgrp", \%customservicegrp);
1094 $fwhostsettings{'updatesrvgrp'}='on';
1095 $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'newsrvrem'};
1096 }else{
1097 $errormessage=$Lang::tr{'fwhost err remark'};
1098 $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'oldsrvrem'};
1099 $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'};
1100 $fwhostsettings{'updatesrvgrp'} = 'on';
1101 }
1102 $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'};
1103 &addservicegrp;
1104 &viewtableservicegrp;
1105 }
1106 ### VIEW ###
1107 if($fwhostsettings{'ACTION'} eq '')
1108 {
1109 &showmenu;
1110 }
1111 ### FUNCTIONS ###
1112 sub showmenu {
1113 &Header::openbox('100%', 'left',$Lang::tr{'fwhost menu'});
1114 print "$Lang::tr{'fwhost welcome'}";
1115 print<<END;
1116 <br><br><table border='0' width='100%'>
1117 <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>
1118 <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>
1119 <tr><td colspan='6'><hr></td></tr></table>
1120 END
1121 &Header::closebox();
1122
1123 }
1124 # Add
1125 sub addnet
1126 {
1127 &error;
1128 &showmenu;
1129 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addnet'});
1130 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
1131 $fwhostsettings{'orgnetremark'}=$fwhostsettings{'NETREMARK'};
1132 print<<END;
1133 <table border='0' width='100%'>
1134 <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>
1135 <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>
1136 <tr><td>$Lang::tr{'netmask'}:</td><td><input type='TEXT' name='SUBNET' value='$fwhostsettings{'SUBNET'}' $fwhostsettings{'BLK_IP'} size='20' maxlength='15'></td></tr>
1137 <tr><td>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='NETREMARK' value='$fwhostsettings{'NETREMARK'}' style='width: 98.5%;'></td></tr>
1138 <tr><td colspan='6'><br><hr></td></tr><tr>
1139 END
1140 if ($fwhostsettings{'ACTION'} eq 'editnet' || $fwhostsettings{'error'} eq 'on')
1141 {
1142 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>";
1143 }else{
1144 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'>";
1145 }
1146 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>";
1147 &Header::closebox();
1148 }
1149 sub addhost
1150 {
1151 &error;
1152 &showmenu;
1153 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addhost'});
1154 $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};
1155 $fwhostsettings{'orgremark'}=$fwhostsettings{'HOSTREMARK'};
1156 print<<END;
1157 <table border='0' width='100%'>
1158 <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>
1159 <tr><td>IP/MAC:</td><td><input type='TEXT' name='IP' value='$fwhostsettings{'IP'}' $fwhostsettings{'BLK_IP'} size='20' maxlength='17'></td></tr>
1160 <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='HOSTREMARK' value='$fwhostsettings{'HOSTREMARK'}' style='width:98%;'></td></tr>
1161 <tr><td colspan='5'><hr></td></tr><tr>
1162 END
1163
1164 if ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'} eq 'on')
1165 {
1166
1167 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>";
1168 }else{
1169 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'>";
1170 }
1171 print " </form><form method='post' style='display:inline'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;' ><input type='hidden' name='ACTION' value='resethost'></form></td></tr></table>";
1172 &Header::closebox();
1173 }
1174 sub addgrp
1175 {
1176 &hint;
1177 &error;
1178 &showmenu;
1179 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addgrp'});
1180 &General::setup_default_networks(\%defaultNetworks);
1181 &General::readhasharray("$configccdnet", \%ccdnet);
1182 &General::readhasharray("$confignet", \%customnetwork);
1183 &General::readhasharray("$configccdhost", \%ccdhost);
1184 &General::readhasharray("$confighost", \%customhost);
1185 &General::readhasharray("$configipsec", \%ipsecconf);
1186
1187 my %checked=();
1188 my $show='';
1189 $checked{'check1'}{'off'} = '';
1190 $checked{'check1'}{'on'} = '';
1191 $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED';
1192 $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'};
1193 my $grp=$fwhostsettings{'grp_name'};
1194 my $rem=$fwhostsettings{'remark'};
1195 if ($fwhostsettings{'update'} eq ''){
1196 print<<END;
1197 <table width='100%' border='0'>
1198 <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>
1199 <tr><td width='10%'>$Lang::tr{'remark'}:</td><td ><input type='TEXT' name='remark' value='$fwhostsettings{'remark'}' style='width: 98%;'></td></tr>
1200 <tr><td colspan='2'><br><hr></td></tr></table>
1201 END
1202 }else{
1203 print<<END;
1204 <table width='100%' border='0'><form method='post' style='display:inline'>
1205 <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>
1206 <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>
1207 <hr>
1208 END
1209 }
1210 if ($fwhostsettings{'update'} eq 'on'){
1211 print<<END;
1212 <form method='post'><input type='hidden' name='remark' value='$rem'><input type='hidden' name='grp_name' value='$grp'>
1213 <table width='100%' border='0'>
1214 <tr><td width=50% valign='top'>
1215 <table width='100%' border='0'>
1216 <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;'>
1217 END
1218 foreach my $network (sort keys %defaultNetworks)
1219 {
1220 next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP");
1221 next if($defaultNetworks{$network}{'NAME'} eq "IPFire");
1222 print "<option value='$defaultNetworks{$network}{'NAME'}'";
1223 print " selected='selected'" if ($fwhostsettings{'DEFAULT_SRC_ADR'} eq $defaultNetworks{$network}{'NAME'});
1224 my $defnet="$defaultNetworks{$network}{'NAME'}_NETADDRESS";
1225 my $defsub="$defaultNetworks{$network}{'NAME'}_NETMASK";
1226 my $defsub1=&General::subtocidr($ownnet{$defsub});
1227 $ownnet{$defnet}='' if ($defaultNetworks{$network}{'NAME'} eq 'RED');
1228 if ($ownnet{$defnet}){
1229 print ">$network ($ownnet{$defnet}/$defsub1)</option>";
1230 }else{
1231 print ">$network</option>";
1232 }
1233 }
1234 print"</select></td></tr>";
1235 if (! -z $confignet){
1236 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;'>";
1237 foreach my $key (sort { ncmp($customnetwork{$a}[0],$customnetwork{$b}[0]) } keys %customnetwork) {
1238 print"<option>$customnetwork{$key}[0]</option>";
1239 }
1240 print"</select></td></tr>";
1241 }
1242 if (! -z $confighost){
1243 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;'>";
1244 foreach my $key (sort { ncmp($customhost{$a}[0],$customhost{$b}[0]) } keys %customhost) {
1245 print"<option>$customhost{$key}[0]</option>";
1246 }
1247 print"</select></td></tr>";
1248 }
1249 print"</table>";
1250 #Inner table right
1251 print"</td><td valign='top'><table width='100%' border='0'>";
1252 #OVPN networks
1253 if (! -z $configccdnet){
1254 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;'>";
1255 foreach my $key (sort { ncmp($ccdnet{$a}[0],$ccdnet{$b}[0]) } keys %ccdnet)
1256 {
1257 print"<option value='$ccdnet{$key}[0]'>$ccdnet{$key}[0]</option>";
1258 }
1259 print"</select></td></tr>";
1260 }
1261 #OVPN clients
1262 foreach my $key (sort { ncmp($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost)
1263 {
1264 if ($ccdhost{$key}[33] ne ''){
1265 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 '');
1266 $show='1';
1267 print"<option value='$ccdhost{$key}[1]'>$ccdhost{$key}[1]</option>";
1268 }
1269 }
1270 if ($show eq '1'){$show='';print"</select></td></tr>";}
1271 #OVPN n2n networks
1272 foreach my $key (sort { ncmp($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost) {
1273 if($ccdhost{$key}[3] eq 'net'){
1274 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 '');
1275 $show='1';
1276 print"<option>$ccdhost{$key}[1]</option>";
1277 }
1278 }
1279 if ($show eq '1'){$show='';print"</select></td></tr>";}
1280 #IPsec networks
1281 foreach my $key (sort { ncmp($ipsecconf{$a}[0],$ipsecconf{$b}[0]) } keys %ipsecconf) {
1282 if ($ipsecconf{$key}[3] eq 'net'){
1283 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 '');
1284 $show='1';
1285 print"<option value='$ipsecconf{$key}[1]'>$ipsecconf{$key}[1]</option>";
1286 }
1287 }
1288 if ($show eq '1'){$show='';print"</select></td></tr>";}
1289 print"</table>";
1290 print"</td></tr></table>";
1291 print"<br><br><hr>";
1292 }
1293 print"<table border='0' width='100%'>";
1294 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>";
1295 &Header::closebox();
1296 }
1297 sub addservice
1298 {
1299 &error;
1300 &showmenu;
1301 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservice'});
1302 if ($fwhostsettings{'updatesrv'} eq 'on')
1303 {
1304 $fwhostsettings{'oldsrvname'} = $fwhostsettings{'SRV_NAME'};
1305 $fwhostsettings{'oldsrvport'} = $fwhostsettings{'SRV_PORT'};
1306 $fwhostsettings{'oldsrvprot'} = $fwhostsettings{'PROT'};
1307 $fwhostsettings{'oldsrvicmp'} = $fwhostsettings{'ICMP'};
1308 }
1309 print<<END;
1310 <table width='100%' border='0'><form method='post'>
1311 <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>
1312 <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost prot'}:</td><td><select name='PROT' id='protocol' >
1313 END
1314 foreach ("TCP","UDP","ICMP")
1315 {
1316 if ($_ eq $fwhostsettings{'PROT'})
1317 {
1318 print"<option selected>$_</option>";
1319 }else{
1320 print"<option>$_</option>";
1321 }
1322 }
1323 print<<END;
1324 </select></td></tr></table>
1325 <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'>
1326 END
1327 &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
1328 print"<option value='All ICMP-Types'>$Lang::tr{'fwdfw all icmp'}</option>";
1329 foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
1330 if ($icmptypes{$key}[0] eq $fwhostsettings{'oldsrvicmp'}){
1331 print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1332 }else{
1333 print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
1334 }
1335 }
1336 print<<END;
1337 </select></td></tr></table></div>
1338 <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>
1339 <table width='100%' border='0'><tr><td colspan='6'><br><hr></td></tr>
1340 <tr><td colspan='6' align='right'>
1341 END
1342 if ($fwhostsettings{'updatesrv'} eq 'on')
1343 {
1344 print<<END;
1345 <input type='submit' value='$Lang::tr{'update'}'style='min-width:100px;' >
1346 <input type='hidden' name='ACTION' value='updateservice'>
1347 <input type='hidden' name='oldsrvname' value='$fwhostsettings{'oldsrvname'}'>
1348 <input type='hidden' name='oldsrvport' value='$fwhostsettings{'oldsrvport'}'>
1349 <input type='hidden' name='oldsrvprot' value='$fwhostsettings{'oldsrvprot'}'>
1350 <input type='hidden' name='oldsrvicmp' value='$fwhostsettings{'oldsrvicmp'}'>
1351 </form>
1352 END
1353 }else{
1354 print"<input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='saveservice'></form>";
1355 }
1356 print<<END;
1357 <form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></form></td></tr>
1358 </table></form>
1359 END
1360 &Header::closebox();
1361 &viewtableservice;
1362 }
1363 sub addservicegrp
1364 {
1365 &hint;
1366 &error;
1367 &showmenu;
1368 &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservicegrp'});
1369 $fwhostsettings{'oldsrvgrpremark'}=$fwhostsettings{'SRVGRP_REMARK'};
1370 if ($fwhostsettings{'updatesrvgrp'} eq ''){
1371 print<<END;
1372 <table width='100%' border='0'><form method='post'>
1373 <tr><td width='10%'>$Lang::tr{'fwhost addgrpname'}</td><td><input type='text' name='SRVGRP_NAME' value='$fwhostsettings{'SRVGRP_NAME'}' size='24'></td></tr>
1374 <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='text' name='SRVGRP_REMARK' value='$fwhostsettings{'SRVGRP_REMARK'}' style='width: 98%;'></td></tr>
1375 <tr><td colspan='2'><br><hr></tr>
1376 </table>
1377 END
1378 }else{
1379 print<<END;
1380 <table width='100%' border='0'><form method='post' style='display:inline'>
1381 <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>
1382 <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>
1383 <tr><td colspan='3'><br><hr></td></td></tr>
1384 </table></form>
1385 END
1386 }
1387 if($fwhostsettings{'updatesrvgrp'} eq 'on'){
1388 print<<END;
1389 <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%'>
1390 <tr><td width='1%' nowrap='nowrap'>$Lang::tr{'fwhost cust service'}</td><td><select name='CUST_SRV' style='min-width:185px;'>
1391 END
1392 &General::readhasharray("$configsrv", \%customservice);
1393 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice)
1394 {
1395 print "<option>$customservice{$key}[0]</option>";
1396 }
1397 print<<END;
1398 </select></td></tr>
1399 <tr><td colspan='4'><br><br></td></tr>
1400 <tr><td colspan='4'><hr></td></tr>
1401 </table>
1402 END
1403 }
1404 print<<END;
1405 <table width='100%' border='0'>
1406 <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>
1407 </table></form>
1408 END
1409 &Header::closebox();
1410 }
1411 # View
1412 sub viewtablenet
1413 {
1414 if(! -z $confignet){
1415 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust net'});
1416 &General::readhasharray("$confignet", \%customnetwork);
1417 if (!keys %customnetwork)
1418 {
1419 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1420 }else{
1421 print<<END;
1422 <table border='0' width='100%' cellspacing='0'>
1423 <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>
1424 END
1425 }
1426 my $count=0;
1427 foreach my $key (sort {ncmp($a,$b)} keys %customnetwork) {
1428 if ($fwhostsettings{'ACTION'} eq 'editnet' && $fwhostsettings{'HOSTNAME'} eq $customnetwork{$key}[0]) {
1429 print" <tr bgcolor='${Header::colouryellow}'>";
1430 }elsif ($count % 2)
1431 {
1432 print" <tr bgcolor='$color{'color22'}'>";
1433 }else
1434 {
1435 print" <tr bgcolor='$color{'color20'}'>";
1436 }
1437 my $colnet="$customnetwork{$key}[1]/".&General::subtocidr($customnetwork{$key}[2]);
1438 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>";
1439 print<<END;
1440 <td width='1%'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} />
1441 <input type='hidden' name='ACTION' value='editnet'>
1442 <input type='hidden' name='HOSTNAME' value='$customnetwork{$key}[0]' />
1443 <input type='hidden' name='IP' value='$customnetwork{$key}[1]' />
1444 <input type='hidden' name='SUBNET' value='$customnetwork{$key}[2]' />
1445 <input type='hidden' name='NETREMARK' value='$customnetwork{$key}[3]' />
1446 </td></form>
1447 END
1448 if($customnetwork{$key}[4] == '0')
1449 {
1450 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>";
1451 }else{
1452 print"<td></td></tr>";
1453 }
1454 $count++;
1455 }
1456 print"</table>";
1457 &Header::closebox();
1458 }
1459
1460 }
1461 sub getcolor
1462 {
1463 my $c=shift;
1464 #Check if IP is part of OpenVPN N2N subnet
1465 foreach my $key (sort keys %ccdhost){
1466 if ($ccdhost{$key}[3] eq 'net'){
1467 my ($a,$b) = split("/",$ccdhost{$key}[11]);
1468 if (&General::IpInSubnet($c,$a,$b)){
1469 $tdcolor="style='color:$Header::colourovpn ;'";
1470 return $tdcolor;
1471 }
1472 }
1473 }
1474 #Check if IP is part of OpenVPN dynamic subnet
1475 my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'});
1476 if (&General::IpInSubnet($c,$a,$b)){
1477 $tdcolor="style='color: $Header::colourovpn;'";
1478 return $tdcolor;
1479 }
1480 #Check if IP is part of OpenVPN static subnet
1481 foreach my $key (sort keys %ccdnet){
1482 my ($a,$b) = split("/",$ccdnet{$key}[1]);
1483 $b =&General::iporsubtodec($b);
1484 if (&General::IpInSubnet($c,$a,$b)){
1485 $tdcolor="style='color: $Header::colourovpn;'";
1486 return $tdcolor;
1487 }
1488 }
1489 #Check if IP is part of IPsec RW network
1490 if ($ipsecsettings{'RW_NET'} ne ''){
1491 my ($a,$b) = split("/",$ipsecsettings{'RW_NET'});
1492 $b=&General::iporsubtodec($b);
1493 if (&General::IpInSubnet($c,$a,$b)){
1494 $tdcolor="style='color: $Header::colourvpn;'";
1495 return $tdcolor;
1496 }
1497 }
1498 #Check if IP is part of a IPsec N2N network
1499 foreach my $key (sort keys %ipsecconf){
1500 my ($a,$b) = split("/",$ipsecconf{$key}[11]);
1501 if (&General::IpInSubnet($c,$a,$b)){
1502 $tdcolor="style='color: $Header::colourvpn;'";
1503 return $tdcolor;
1504 }
1505 }
1506 $tdcolor='';
1507 return $tdcolor;
1508 }
1509 sub viewtablehost
1510 {
1511 if (! -z $confighost){
1512 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust addr'});
1513 &General::readhasharray("$confighost", \%customhost);
1514 &General::readhasharray("$configccdnet", \%ccdnet);
1515 &General::readhasharray("$configccdhost", \%ccdhost);
1516 if (!keys %customhost)
1517 {
1518 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1519 }else{
1520 print<<END;
1521 <table border='0' width='100%' cellspacing='0'>
1522 <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>
1523 END
1524 }
1525 my $count=0;
1526 foreach my $key (sort { ncmp ($customhost{$a}[0],$customhost{$b}[0])} keys %customhost) {
1527 if ( ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'}) && $fwhostsettings{'HOSTNAME'} eq $customhost{$key}[0]) {
1528 print" <tr bgcolor='${Header::colouryellow}'>";
1529 }elsif ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";}
1530 else{ print" <tr bgcolor='$color{'color20'}'>";}
1531 my ($ip,$sub)=split(/\//,$customhost{$key}[2]);
1532 $customhost{$key}[4]=~s/\s+//g;
1533 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>";
1534 print<<END;
1535 <td width='1%'><form method='post'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} />
1536 <input type='hidden' name='ACTION' value='edithost' />
1537 <input type='hidden' name='HOSTNAME' value='$customhost{$key}[0]' />
1538 <input type='hidden' name='IP' value='$ip' />
1539 <input type='hidden' name='type' value='$customhost{$key}[1]' />
1540 <input type='hidden' name='HOSTREMARK' value='$customhost{$key}[3]' />
1541 </form></td>
1542 END
1543 if($customhost{$key}[4] == '0')
1544 {
1545 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>";
1546 }else{
1547 print"<td width='1%'></td></tr>";
1548 }
1549 $count++;
1550 }
1551 print"</table>";
1552 &Header::closebox();
1553 }
1554 }
1555 sub viewtablegrp
1556 {
1557 if(! -z "$configgrp"){
1558 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust grp'});
1559 &General::readhasharray("$configgrp", \%customgrp);
1560 &General::readhasharray("$configipsec", \%ipsecconf);
1561 &General::readhasharray("$configccdhost", \%ccdhost);
1562 &General::readhasharray("$configccdnet", \%ccdnet);
1563 &General::readhasharray("$confighost", \%customhost);
1564 &General::readhasharray("$confignet", \%customnetwork);
1565 my @grp=();
1566 my $helper='';
1567 my $count=1;
1568 my $grpname;
1569 my $remark;
1570 my $number;
1571 my $delflag;
1572 if (!keys %customgrp)
1573 {
1574 print "<center><b>$Lang::tr{'fwhost err emptytable'}</b>";
1575 }else{
1576 foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
1577 $count++;
1578 if ($helper ne $customgrp{$key}[0]){
1579 $delflag='0';
1580 foreach my $key1 (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){
1581 if ($customgrp{$key}[0] eq $customgrp{$key1}[0])
1582 {
1583 $delflag++;
1584 }
1585 if($delflag > 1){
1586 last;
1587 }
1588 }
1589 $number=1;
1590 if ($customgrp{$key}[2] eq "none"){$customgrp{$key}[2]=$Lang::tr{'fwhost err emptytable'};}
1591 $grpname=$customgrp{$key}[0];
1592 $remark="$customgrp{$key}[1]";
1593 if($count gt 1){ print"</table>";}
1594 print "<br><b><u>$grpname</u></b>&nbsp; &nbsp;";
1595 print " <b>$Lang::tr{'remark'}:</b>&nbsp $remark &nbsp " if ($remark ne '');
1596 print "<b>$Lang::tr{'used'}:</b> $customgrp{$key}[4]x";
1597 if($customgrp{$key}[4] == '0')
1598 {
1599 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>";
1600 }
1601 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>";
1602 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>";
1603 }
1604
1605 if ( ($fwhostsettings{'ACTION'} eq 'editgrp' || $fwhostsettings{'update'} ne '') && $fwhostsettings{'grp_name'} eq $customgrp{$key}[0]) {
1606 print" <tr bgcolor='${Header::colouryellow}'>";
1607 }elsif ($count %2 == 0){
1608 print"<tr bgcolor='$color{'color22'}'>";
1609 }else{
1610 print"<tr bgcolor='$color{'color20'}'>";
1611 }
1612 my $ip=&getipforgroup($customgrp{$key}[2],$customgrp{$key}[3]);
1613 if ($ip eq ''){print"<tr bgcolor='${Header::colouryellow}'>";}
1614 print "<td width='39%' align='left'>";
1615 if($customgrp{$key}[3] eq 'Standard Network'){
1616 print &get_name($customgrp{$key}[2])."</td>";
1617 }else{
1618 print "$customgrp{$key}[2]</td>";
1619 }
1620 if ($ip eq '' && $customgrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){
1621 print "<td align='center'>$Lang::tr{'fwhost deleted'}</td><td align='center'>$customgrp{$key}[3]</td><td width='1%'><form method='post'>";
1622 }else{
1623 my ($colip,$colsub) = split("/",$ip);
1624 $ip="$colip/".&General::subtocidr($colsub) if ($colsub);
1625 print"<td align='center' ".&getcolor($colip).">".&Header::colorize($ip)."</td><td align='center'>$customgrp{$key}[3]</td><td width='1%'><form method='post'>";
1626 }
1627 if ($delflag > '1' && $ip ne ''){
1628 print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />";
1629 }
1630 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>";
1631
1632 $helper=$customgrp{$key}[0];
1633 $number++;
1634 }
1635 print"</table>";
1636 }
1637 &Header::closebox();
1638 }
1639
1640 }
1641 sub viewtableservice
1642 {
1643 my $count=0;
1644 if(! -z "$configsrv")
1645 {
1646 &Header::openbox('100%', 'left', $Lang::tr{'fwhost services'});
1647 &General::readhasharray("$configsrv", \%customservice);
1648 print<<END;
1649 <table width='100%' border='0' cellspacing='0'>
1650 <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>
1651 END
1652 foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0])} keys %customservice)
1653 {
1654 $count++;
1655 if ( ($fwhostsettings{'updatesrv'} eq 'on' || $fwhostsettings{'error'}) && $fwhostsettings{'SRV_NAME'} eq $customservice{$key}[0]) {
1656 print" <tr bgcolor='${Header::colouryellow}'>";
1657 }elsif ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";}else{ print" <tr bgcolor='$color{'color20'}'>";}
1658 print<<END;
1659 <td>$customservice{$key}[0]</td><td align='center'>$customservice{$key}[2]</td><td align='center'>$customservice{$key}[1]</td><td align='center'>
1660 END
1661 if($customservice{$key}[3] eq 'All ICMP-Types'){print $Lang::tr{'fwdfw all icmp'};}
1662 elsif($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];}
1663 print<<END;
1664 </td><td align='center'>$customservice{$key}[4]x</td>
1665 <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' />
1666 <input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]' />
1667 <input type='hidden' name='SRV_PORT' value='$customservice{$key}[1]' />
1668 <input type='hidden' name='PROT' value='$customservice{$key}[2]' />
1669 <input type='hidden' name='ICMP' value='$customservice{$key}[3]' /></form></td>
1670 END
1671 if ($customservice{$key}[4] eq '0')
1672 {
1673 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>";
1674 }else{
1675 print"<td></td></tr>";
1676 }
1677 }
1678 print"</table>";
1679 &Header::closebox();
1680 }
1681 }
1682 sub viewtableservicegrp
1683 {
1684 my $count=0;
1685 my $grpname;
1686 my $remark;
1687 my $helper;
1688 my $port;
1689 my $protocol;
1690 my $delflag;
1691 if (! -z $configsrvgrp){
1692 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'});
1693 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1694 &General::readhasharray("$configsrv", \%customservice);
1695 my $number= keys %customservicegrp;
1696 foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){
1697 $count++;
1698 if ($helper ne $customservicegrp{$key}[0]){
1699 $delflag=0;
1700 foreach my $key1 (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) } keys %customservicegrp){
1701 if ($customservicegrp{$key}[0] eq $customservicegrp{$key1}[0])
1702 {
1703 $delflag++;
1704 }
1705 if($delflag > 1){
1706 last;
1707 }
1708 }
1709 $grpname=$customservicegrp{$key}[0];
1710 if ($customservicegrp{$key}[2] eq "none"){
1711 $customservicegrp{$key}[2]=$Lang::tr{'fwhost empty'};
1712 $port='';
1713 $protocol='';
1714 }
1715 $remark="$customservicegrp{$key}[1]";
1716 if($count >=2){print"</table>";}
1717 print "<br><b><u>$grpname</u></b>&nbsp; &nbsp; ";
1718 print "<b>$Lang::tr{'remark'}:</b>&nbsp; $remark " if ($remark ne '');
1719 print "&nbsp; <b>$Lang::tr{'used'}:</b> $customservicegrp{$key}[3]x";
1720 if($customservicegrp{$key}[3] == '0')
1721 {
1722 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>";
1723 }
1724 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>";
1725 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>";
1726 }
1727 if( $fwhostsettings{'SRVGRP_NAME'} eq $customservicegrp{$key}[0]) {
1728 print" <tr bgcolor='${Header::colouryellow}'>";
1729 }elsif ($count %2 == 0){
1730 print"<tr bgcolor='$color{'color22'}'>";
1731 }else{
1732 print"<tr bgcolor='$color{'color20'}'>";
1733 }
1734 print "<td width='39%'>$customservicegrp{$key}[2]</td>";
1735 foreach my $srv (sort keys %customservice){
1736 if ($customservicegrp{$key}[2] eq $customservice{$srv}[0]){
1737 $protocol=$customservice{$srv}[2];
1738 $port=$customservice{$srv}[1];
1739 last;
1740 }
1741 }
1742 print"<td align='center'>$port</td><td align='center'>$protocol</td><td width='1%'><form method='post'>";
1743 if ($delflag gt '1'){
1744 print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />";
1745 }
1746 print"<input type='hidden' name='ACTION' value='delgrpservice'><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'><input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2],$customservicegrp{$key}[3]'></form></td></tr>";
1747 $helper=$customservicegrp{$key}[0];
1748 }
1749 print"</table>";
1750 &Header::closebox();
1751 }
1752 }
1753 # Check
1754 sub checkname
1755 {
1756 my %hash=%{(shift)};
1757 foreach my $key (keys %hash) {
1758 if($hash{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
1759 return 0;
1760 }
1761 }
1762 return 1;
1763
1764 }
1765 sub checkgroup
1766 {
1767 my %hash=%{(shift)};
1768 my $name=shift;
1769 foreach my $key (keys %hash) {
1770 if($hash{$key}[0] eq $name){
1771 return 0;
1772 }
1773 }
1774 return 1;
1775 }
1776 sub checkip
1777 {
1778
1779 my %hash=%{(shift)};
1780 my $a=shift;
1781 foreach my $key (keys %hash) {
1782 if($hash{$key}[$a] eq $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'})){
1783 return 0;
1784 }
1785 }
1786 return 1;
1787 }
1788 sub checksubnet
1789 {
1790 my %hash=%{(shift)};
1791 &General::readhasharray("$confignet", \%hash);
1792 foreach my $key (keys %hash) {
1793 if(&General::IpInSubnet($fwhostsettings{'IP'},$hash{$key}[1],$hash{$key}[2]))
1794 {
1795 return 1;
1796 }
1797 }
1798 return 0;
1799 }
1800 sub checkservicegroup
1801 {
1802 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1803
1804
1805 #check name
1806 if ( ! &validhostname($fwhostsettings{'SRVGRP_NAME'}))
1807 {
1808 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1809 return $errormessage;
1810 }
1811 #check empty selectbox
1812 if (keys %customservice lt 1)
1813 {
1814 $errormessage.=$Lang::tr{'fwhost err groupempty'}."<br>";
1815 }
1816 #check if name already exists
1817 if ($fwhostsettings{'updatesrvgrp'} ne 'on'){
1818 foreach my $key (keys %customservicegrp) {
1819 if( $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} ){
1820 $errormessage.=$Lang::tr{'fwhost err grpexist'}."<br>";
1821
1822 }
1823 }
1824 }
1825 #check if service already exists in group
1826 foreach my $key (keys %customservicegrp) {
1827 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[2] eq $fwhostsettings{'CUST_SRV'} ){
1828 $errormessage.=$Lang::tr{'fwhost err srvexist'}."<br>";
1829 }
1830 }
1831 return $errormessage;
1832 }
1833 sub error
1834 {
1835 if ($errormessage) {
1836 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1837 print "<class name='base'>$errormessage\n";
1838 print "&nbsp;</class>\n";
1839 &Header::closebox();
1840 }
1841 }
1842 sub hint
1843 {
1844 if ($hint) {
1845 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
1846 print "<class name='base'>$hint\n";
1847 print "&nbsp;</class>\n";
1848 &Header::closebox();
1849 }
1850 }
1851 sub get_name
1852 {
1853 my $val=shift;
1854 &General::setup_default_networks(\%defaultNetworks);
1855 foreach my $network (sort keys %defaultNetworks)
1856 {
1857 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1858 }
1859 }
1860
1861 sub deletefromgrp
1862 {
1863 my $target=shift;
1864 my $config=shift;
1865 my %hash=();
1866 &General::readhasharray("$config",\%hash);
1867 foreach my $key (keys %hash) {
1868 $errormessage.="lese $hash{$key}[2] und $target<br>";
1869 if($hash{$key}[2] eq $target){
1870
1871 delete $hash{$key};
1872 $errormessage.="Habe $target aus Gruppe gelöscht!<br>";
1873 }
1874 }
1875 &General::writehasharray("$config",\%hash);
1876
1877 }
1878 sub plausicheck
1879 {
1880 my $edit=shift;
1881 #check hostname
1882 if (!&validhostname($fwhostsettings{'HOSTNAME'}))
1883 {
1884 $errormessage=$errormessage.$Lang::tr{'fwhost err name'};
1885 $fwhostsettings{'BLK_IP'}='readonly';
1886 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
1887 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1888 }
1889 #check if name collides with CCD Netname
1890 &General::readhasharray("$configccdnet", \%ccdnet);
1891 foreach my $key (keys %ccdnet) {
1892 if($ccdnet{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
1893 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdnet'};;
1894 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
1895 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1896 last;
1897 }
1898 }
1899 #check if IP collides with CCD NetIP
1900 if ($fwhostsettings{'type'} ne 'mac'){
1901 &General::readhasharray("$configccdnet", \%ccdnet);
1902 foreach my $key (keys %ccdnet) {
1903 my $test=(&General::getnetworkip($fwhostsettings{'IP'},&General::iporsubtocidr($fwhostsettings{'SUBNET'})))."/".$fwhostsettings{'SUBNET'};
1904 if($ccdnet{$key}[1] eq $test){
1905 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdipnet'};
1906 $fwhostsettings{'IP'} = $fwhostsettings{'orgip'};
1907 $fwhostsettings{'SUBNET'} = $fwhostsettings{'orgsubnet'};
1908 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1909 last;
1910 }
1911 }
1912 }
1913 #check if name collides with CCD Hostname
1914 &General::readhasharray("$configccdhost", \%ccdhost);
1915 foreach my $key (keys %ccdhost) {
1916 my ($ip,$sub)=split(/\//,$ccdhost{$key}[33]);
1917 if($ip eq $fwhostsettings{'IP'}){
1918 $errormessage=$Lang::tr{'fwhost err isccdiphost'};
1919 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1920 last;
1921 }
1922 }
1923 #check if IP collides with CCD HostIP (only hosts)
1924 if ($edit eq 'edithost')
1925 {
1926 foreach my $key (keys %ccdhost) {
1927 if($ccdhost{$key}[1] eq $fwhostsettings{'HOSTNAME'}){
1928 $errormessage=$Lang::tr{'fwhost err isccdhost'};
1929 $fwhostsettings{'IP'} = $fwhostsettings{'orgname'};
1930 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1931 last;
1932 }
1933 }
1934 }
1935 #check if network with this name already exists
1936 &General::readhasharray("$confignet", \%customnetwork);
1937 if (!&checkname(\%customnetwork))
1938 {
1939 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err netexist'};
1940 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
1941 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1942 }
1943 #check if network ip already exists
1944 if (!&checkip(\%customnetwork,1))
1945 {
1946 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err net'};
1947 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1948 }
1949 #check if host with this name already exists
1950 &General::readhasharray("$confighost", \%customhost);
1951 if (!&checkname(\%customhost))
1952 {
1953 $errormessage.="<br>".$Lang::tr{'fwhost err hostexist'};
1954 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
1955 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1956 }
1957 #check if host with this ip already exists
1958 if (!&checkip(\%customhost,2))
1959 {
1960 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err ipcheck'};
1961 }
1962 return;
1963 }
1964 sub getipforgroup
1965 {
1966 my $name=$_[0],
1967 my $type=$_[1];
1968 my $value;
1969
1970 #get address from IPSEC NETWORK
1971 if ($type eq 'IpSec Network'){
1972 foreach my $key (keys %ipsecconf) {
1973 if ($ipsecconf{$key}[1] eq $name){
1974 return $ipsecconf{$key}[11];
1975 }
1976 }
1977 &deletefromgrp($name,$configgrp);
1978 }
1979
1980 #get address from IPSEC HOST
1981 if ($type eq 'IpSec Host'){
1982 foreach my $key (keys %ipsecconf) {
1983 if ($ipsecconf{$key}[1] eq $name){
1984 return $ipsecconf{$key}[10];
1985 }
1986 }
1987 &deletefromgrp($name,$configgrp);
1988 }
1989
1990 #get address from ovpn ccd Net-2-Net
1991 if ($type eq 'OpenVPN N-2-N'){
1992 foreach my $key (keys %ccdhost) {
1993 if($ccdhost{$key}[1] eq $name){
1994 my ($a,$b) = split ("/",$ccdhost{$key}[11]);
1995 $b=&General::iporsubtodec($b);
1996 return "$a/$b";
1997 }
1998 }
1999 &deletefromgrp($name,$configgrp);
2000 }
2001
2002 #get address from ovpn ccd static host
2003 if ($type eq 'OpenVPN static host'){
2004 foreach my $key (keys %ccdhost) {
2005 if($ccdhost{$key}[1] eq $name){
2006 my ($a,$b) = split (/\//,$ccdhost{$key}[33]);
2007 $b=&General::iporsubtodec($b);
2008 return "$a/$b";
2009 }
2010 }
2011 &deletefromgrp($name,$configgrp);
2012 }
2013
2014 #get address from ovpn ccd static net
2015 if ($type eq 'OpenVPN static network'){
2016 foreach my $key (keys %ccdnet) {
2017 if ($ccdnet{$key}[0] eq $name){
2018 my ($a,$b) = split (/\//,$ccdnet{$key}[1]);
2019 $b=&General::iporsubtodec($b);
2020 return "$a/$b";
2021 }
2022 }
2023 }
2024
2025 #check custom addresses
2026 if ($type eq 'Custom Host'){
2027 foreach my $key (keys %customhost) {
2028 if ($customhost{$key}[0] eq $name){
2029 my ($ip,$sub) = split("/",$customhost{$key}[2]);
2030 return $ip;
2031 }
2032 }
2033 }
2034
2035 ##check custom networks
2036 if ($type eq 'Custom Network'){
2037 foreach my $key (keys %customnetwork) {
2038 if($customnetwork{$key}[0] eq $name){
2039 return $customnetwork{$key}[1]."/".$customnetwork{$key}[2];
2040 }
2041 }
2042 }
2043
2044 #check standard networks
2045 if ($type eq 'Standard Network'){
2046 if ($name =~ /OpenVPN/i){
2047 my %ovpn=();
2048 &General::readhash("${General::swroot}/ovpn/settings",\%ovpn);
2049 return $ovpn{'DOVPN_SUBNET'};
2050 }
2051 if ($name eq 'GREEN'){
2052 my %hash=();
2053 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
2054 return $hash{'GREEN_NETADDRESS'}."/".$hash{'GREEN_NETMASK'};
2055 }
2056 if ($name eq 'BLUE'){
2057 my %hash=();
2058 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
2059 return $hash{'BLUE_NETADDRESS'}."/".$hash{'BLUE_NETMASK'};
2060 }
2061 if ($name eq 'ORANGE'){
2062 my %hash=();
2063 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
2064 return $hash{'ORANGE_NETADDRESS'}."/".$hash{'ORANGE_NETMASK'};
2065 }
2066 if ($name eq 'ALL'){
2067 return "0.0.0.0/0.0.0.0";
2068 }
2069 if ($name =~ /IPsec/i){
2070 my %hash=();
2071 &General::readhash("${General::swroot}/vpn/settings",\%hash);
2072 return $hash{'RW_NET'};
2073 }
2074 }
2075 }
2076
2077 sub decrease {
2078 my $grp=$_[0];
2079 &General::readhasharray("$confignet", \%customnetwork);
2080 &General::readhasharray("$confighost", \%customhost);
2081 foreach my $key (sort keys %customgrp ){
2082 if ( ($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Network')){
2083 foreach my $key1 (sort keys %customnetwork){
2084 if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){
2085 $customnetwork{$key1}[4]=$customnetwork{$key1}[4]-1;
2086 last;
2087 }
2088 }
2089 }
2090
2091 if (($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Host')){
2092 foreach my $key2 (sort keys %customhost){
2093 if ($customhost{$key2}[0] eq $customgrp{$key}[2]){
2094 $customhost{$key2}[4]=$customhost{$key2}[4]-1;
2095 last;
2096 }
2097 }
2098
2099 }
2100 }
2101 &General::writehasharray("$confignet", \%customnetwork);
2102 &General::writehasharray("$confighost", \%customhost);
2103 }
2104 sub decreaseservice
2105 {
2106 my $grp=$_[0];
2107 &General::readhasharray("$configsrv", \%customservice);
2108 &General::readhasharray("$configsrvgrp", \%customservicegrp);
2109
2110 foreach my $key (sort keys %customservicegrp){
2111 if ($customservicegrp{$key}[0] eq $grp ){
2112 foreach my $key2 (sort keys %customservice){
2113 if ($customservice{$key2}[0] eq $customservicegrp{$key}[2]){
2114 $customservice{$key2}[4]--;
2115 }
2116 }
2117 }
2118 }
2119 &General::writehasharray("$configsrv", \%customservice);
2120
2121 }
2122 sub checkports
2123 {
2124
2125 my %hash=%{(shift)};
2126 #check empty fields
2127 if ($fwhostsettings{'SRV_NAME'} eq '' ){
2128 $errormessage=$Lang::tr{'fwhost err name1'};
2129 }
2130 if ($fwhostsettings{'SRV_PORT'} eq '' && $fwhostsettings{'PROT'} ne 'ICMP'){
2131 $errormessage=$Lang::tr{'fwhost err port'};
2132 }
2133 #check valid name
2134 if (! &validhostname($fwhostsettings{'SRV_NAME'})){
2135 $errormessage="<br>".$Lang::tr{'fwhost err name'};
2136 }
2137 #change dashes with :
2138 $fwhostsettings{'SRV_PORT'}=~ tr/-/:/;
2139
2140 if ($fwhostsettings{'SRV_PORT'} eq "*") {
2141 $fwhostsettings{'SRV_PORT'} = "1:65535";
2142 }
2143 if ($fwhostsettings{'SRV_PORT'} =~ /^(\D)\:(\d+)$/) {
2144 $fwhostsettings{'SRV_PORT'} = "1:$2";
2145 }
2146 if ($fwhostsettings{'SRV_PORT'} =~ /^(\d+)\:(\D)$/) {
2147 $fwhostsettings{'SRV_PORT'} = "$1:65535";
2148 }
2149 if($fwhostsettings{'PROT'} ne 'ICMP'){
2150 $errormessage = $errormessage.&General::validportrange($fwhostsettings{'SRV_PORT'}, 'src');
2151 }
2152 # a new service has to have a different name
2153 foreach my $key (keys %hash){
2154 if ($hash{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
2155 $errormessage = "<br>".$Lang::tr{'fwhost err srv exists'};
2156 last;
2157 }
2158 }
2159 return $errormessage;
2160 }
2161 sub validhostname
2162 {
2163 # Checks a hostname against RFC1035
2164 my $hostname = $_[0];
2165
2166 # Each part should be at least two characters in length
2167 # but no more than 63 characters
2168 if (length ($hostname) < 1 || length ($hostname) > 63) {
2169 return 0;}
2170 # Only valid characters are a-z, A-Z, 0-9 and -
2171 if ($hostname !~ /^[a-zA-ZäöüÖÄÜ0-9-_.;()\/\s]*$/) {
2172 return 0;}
2173 # First character can only be a letter or a digit
2174 if (substr ($hostname, 0, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) {
2175 return 0;}
2176 # Last character can only be a letter or a digit
2177 if (substr ($hostname, -1, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9()]*$/) {
2178 return 0;}
2179 return 1;
2180 }
2181 sub validremark
2182 {
2183 # Checks a hostname against RFC1035
2184 my $remark = $_[0];
2185 # Each part should be at least two characters in length
2186 # but no more than 63 characters
2187 if (length ($remark) < 1 || length ($remark) > 255) {
2188 return 0;}
2189 # Only valid characters are a-z, A-Z, 0-9 and -
2190 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) {
2191 return 0;}
2192 # First character can only be a letter or a digit
2193 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
2194 return 0;}
2195 # Last character can only be a letter or a digit
2196 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
2197 return 0;}
2198 return 1;
2199 }
2200 &Header::closebigbox();
2201 &Header::closepage();