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