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