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