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