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