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