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